02315e81251c7ac77b638aa47a49bc90bcc0dd02
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / karaf / ResetEventTimesComandProviderTest.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.anyString;
12
13 import java.util.function.Function;
14 import org.junit.After;
15 import org.junit.Assert;
16 import org.junit.Test;
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  ResetEventTimesComandProvider}.
23  */
24 public class ResetEventTimesComandProviderTest extends AbstractKarafTest {
25
26     private ResetEventTimesComandProvider resetEventTimesComandProvider;
27     private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = String::isEmpty;
28
29     @Override
30     public void doSetUp() {
31         resetEventTimesComandProvider = new ResetEventTimesComandProvider();
32         EventsTimeCounter.resetAllCounters();
33     }
34
35     @After
36     public void tearDown() {
37         Mockito.verify(console).print(anyString());
38         EventsTimeCounter.resetAllCounters();
39     }
40
41     /**
42      * Test for {@link ResetEventTimesComandProvider#doExecute()} when no stats were touched before.
43      */
44     @Test
45     public void testDoExecute_clean() throws Exception {
46         Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
47         resetEventTimesComandProvider.execute(cmdSession);
48         Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
49     }
50
51     /**
52      * Test for {@link ResetEventTimesComandProvider#doExecute()} when stats were touched before.
53      */
54     @Test
55     public void testDoExecute_dirty() throws Exception {
56         final EventIdentifier dummyEvent = new EventIdentifier("junit", "junitDevice");
57         Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
58
59         EventsTimeCounter.markStart(dummyEvent);
60         EventsTimeCounter.markEnd(dummyEvent);
61         Assert.assertFalse(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
62
63         resetEventTimesComandProvider.execute(cmdSession);
64         Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
65     }
66 }