BUG-4328: TransactionChainManager state
[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
9 package org.opendaylight.openflowplugin.impl.karaf;
10
11 import com.google.common.base.Function;
12 import javax.annotation.Nullable;
13 import org.junit.After;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.mockito.Matchers;
17 import org.mockito.Mockito;
18 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.SessionStatistics;
19
20 /**
21  * Test for {@link ResetSessionStatsComandProvider}
22  */
23 public class ResetSessionStatsComandProviderTest extends AbstractKarafTest {
24
25     private ResetSessionStatsComandProvider resetSessionStatsComandProvider;
26     private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = new Function<String, Boolean>() {
27         @Nullable
28         @Override
29         public Boolean apply(String input) {
30             return input.isEmpty();
31         }
32     };
33
34     @Override
35
36     public void doSetUp() {
37         resetSessionStatsComandProvider = new ResetSessionStatsComandProvider();
38         SessionStatistics.resetAllCounters();
39     }
40
41     @After
42     public void tearDown() {
43         Mockito.verify(console).print(Matchers.anyString());
44         SessionStatistics.resetAllCounters();
45     }
46
47     /**
48      * test for {@link ResetSessionStatsComandProvider#doExecute()} when no stats were touched before
49      *
50      * @throws Exception
51      */
52     @Test
53     public void testDoExecute_clean() throws Exception {
54         Assert.assertTrue(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
55         resetSessionStatsComandProvider.execute(cmdSession);
56         Assert.assertTrue(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
57     }
58
59     /**
60      * test for {@link ResetSessionStatsComandProvider#doExecute()} when stats were touched before
61      *
62      * @throws Exception
63      */
64     @Test
65     public void testDoExecute_dirty() throws Exception {
66         final String dummySessionId = "junitSessionId";
67         Assert.assertTrue(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
68
69         SessionStatistics.countEvent(dummySessionId, SessionStatistics.ConnectionStatus.CONNECTION_CREATED);
70         Assert.assertFalse(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
71
72         resetSessionStatsComandProvider.execute(cmdSession);
73         Assert.assertTrue(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
74     }
75 }