Eliminate blueprint for openflowplugins-impl karaf commands
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / karaf / ResetSessionStatsComandProviderTest.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.atLeastOnce;
12 import static org.mockito.Mockito.verify;
13
14 import java.util.function.Function;
15 import org.junit.jupiter.api.Test;
16 import org.mockito.InjectMocks;
17 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.SessionStatistics;
18
19 /**
20  * Test for {@link ResetSessionStatsComandProvider}.
21  */
22 class ResetSessionStatsComandProviderTest extends AbstractKarafTest {
23     @InjectMocks
24     private ResetSessionStatsComandProvider resetSessionStatsCommand;
25     private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = String::isEmpty;
26
27     @Override
28     protected void doBeforeEach() {
29         SessionStatistics.resetAllCounters();
30         assertNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION);
31     }
32
33     /**
34      * Test for {@link ResetSessionStatsComandProvider#execute()} when no stats were touched before.
35      */
36     @Test
37     void resetNoActivity() {
38         resetSessionStatsCommand.execute();
39         verify(console, atLeastOnce()).println(anyString());
40         assertNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION);
41     }
42
43     /**
44      * Test for {@link ResetSessionStatsComandProvider#execute()} when stats were touched before.
45      */
46     @Test
47     void resetHavingActivity() {
48         final String dummySessionId = "junitSessionId";
49         SessionStatistics.countEvent(dummySessionId, SessionStatistics.ConnectionStatus.CONNECTION_CREATED);
50         assertHasActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION);
51
52         resetSessionStatsCommand.execute();
53         verify(console, atLeastOnce()).println(anyString());
54         assertNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION);
55     }
56 }