Eliminate blueprint for openflowplugins-impl karaf commands
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / karaf / ClearStatsCommandTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.impl.karaf;
9
10 import static org.mockito.ArgumentMatchers.anyString;
11 import static org.mockito.Mockito.verify;
12
13 import java.util.function.Function;
14 import org.junit.jupiter.api.Test;
15 import org.mockito.InjectMocks;
16 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
17 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
18 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.MessageIntelligenceAgencyImpl;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
20
21 /**
22  * Test for {@link ClearStatsCommand}.
23  */
24 class ClearStatsCommandTest extends AbstractCommandTest {
25     private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION =
26         input -> input.endsWith(": no activity detected");
27
28     private final MessageIntelligenceAgency messageIntelligenceAgency = new MessageIntelligenceAgencyImpl();
29
30     @InjectMocks
31     private ClearStatsCommand clearStatsCommand;
32
33     @Override
34     protected void doBeforeEach() {
35         clearStatsCommand.messageIntelligenceAgency = messageIntelligenceAgency;
36         messageIntelligenceAgency.resetStatistics();
37         assertNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION);
38     }
39
40     /**
41      * Test for {@link ClearStatsCommand#execute()} when no stats were touched before.
42      */
43     @Test
44     void clearNoActivity() {
45         clearStatsCommand.execute();
46         verify(console).println(anyString());
47         assertNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION);
48     }
49
50     /**
51      * Test for {@link ClearStatsCommand#execute()} when stats were touched before.
52      */
53     @Test
54     void clearHavingActivity() {
55         messageIntelligenceAgency.spyMessage(OfHeader.class, MessageSpy.StatisticsGroup.FROM_SWITCH);
56         assertHasActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION);
57         clearStatsCommand.execute();
58         verify(console).println(anyString());
59         assertNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION);
60     }
61 }