SONAR TD - Group actions redundancy
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / karaf / ShowEventTimesComandProviderTest.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.api.openflow.statistics.ofpspecific.EventIdentifier;
19 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter;
20
21 /**
22  * Test for {@link ShowEventTimesComandProvider}
23  */
24 public class ShowEventTimesComandProviderTest extends AbstractKarafTest {
25
26     private ShowEventTimesComandProvider showEventTimesComandProvider;
27     private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = new Function<String, Boolean>() {
28         @Nullable
29         @Override
30         public Boolean apply(String input) {
31             return input.isEmpty();
32         }
33     };
34
35     @Override
36
37     public void doSetUp() {
38         showEventTimesComandProvider = new ShowEventTimesComandProvider();
39         EventsTimeCounter.resetAllCounters();
40     }
41
42     @After
43     public void tearDown() {
44         EventsTimeCounter.resetAllCounters();
45     }
46
47     /**
48      * test for {@link ShowEventTimesComandProvider#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(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
55         showEventTimesComandProvider.execute(cmdSession);
56         Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
57         Mockito.verify(console).print("");
58     }
59
60     /**
61      * test for {@link ShowEventTimesComandProvider#doExecute()} when stats were touched before
62      *
63      * @throws Exception
64      */
65     @Test
66     public void testDoExecute_dirty() throws Exception {
67         final EventIdentifier dummyEvent = new EventIdentifier("junit", "junitDevice");
68         Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
69
70         EventsTimeCounter.markStart(dummyEvent);
71         EventsTimeCounter.markEnd(dummyEvent);
72         Assert.assertFalse(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
73
74         showEventTimesComandProvider.execute(cmdSession);
75         Assert.assertFalse(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
76         Mockito.verify(console).print(Matchers.contains("junitDevice"));
77     }
78 }