OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[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 static org.mockito.ArgumentMatchers.contains;
12
13 import com.google.common.base.Function;
14 import javax.annotation.Nullable;
15 import org.junit.After;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.mockito.Mockito;
19 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
20 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter;
21
22 /**
23  * Test for {@link ShowEventTimesComandProvider}.
24  */
25 public class ShowEventTimesComandProviderTest extends AbstractKarafTest {
26
27     private ShowEventTimesComandProvider showEventTimesComandProvider;
28     private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = new Function<String, Boolean>() {
29         @Nullable
30         @Override
31         public Boolean apply(String input) {
32             return input.isEmpty();
33         }
34     };
35
36     @Override
37
38     public void doSetUp() {
39         showEventTimesComandProvider = new ShowEventTimesComandProvider();
40         EventsTimeCounter.resetAllCounters();
41     }
42
43     @After
44     public void tearDown() {
45         EventsTimeCounter.resetAllCounters();
46     }
47
48     /**
49      * Test for {@link ShowEventTimesComandProvider#doExecute()} when no stats were touched before.
50      */
51     @Test
52     public void testDoExecute_clean() throws Exception {
53         Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
54         showEventTimesComandProvider.execute(cmdSession);
55         Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
56         Mockito.verify(console).print("");
57     }
58
59     /**
60      * Test for {@link ShowEventTimesComandProvider#doExecute()} when stats were touched before.
61      */
62     @Test
63     public void testDoExecute_dirty() throws Exception {
64         final EventIdentifier dummyEvent = new EventIdentifier("junit", "junitDevice");
65         Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
66
67         EventsTimeCounter.markStart(dummyEvent);
68         EventsTimeCounter.markEnd(dummyEvent);
69         Assert.assertFalse(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
70
71         showEventTimesComandProvider.execute(cmdSession);
72         Assert.assertFalse(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
73         Mockito.verify(console).print(contains("junitDevice"));
74     }
75 }