2cd8b0f7e3fe8f252a5b1429f8fc9308532de7e6
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / karaf / ShowEventTimesComandProviderTest.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech s.r.o. 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.ArgumentMatchers.contains;
12 import static org.mockito.Mockito.never;
13 import static org.mockito.Mockito.verify;
14
15 import java.util.function.Function;
16 import org.junit.jupiter.api.Test;
17 import org.mockito.InjectMocks;
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 class ShowEventTimesComandProviderTest extends AbstractKarafTest {
25     private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = String::isEmpty;
26
27     @InjectMocks
28     private ShowEventTimesComandProvider showEventTimesCommand;
29
30     @Override
31     protected void doBeforeEach() {
32         EventsTimeCounter.resetAllCounters();
33         assertNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION);
34     }
35
36     /**
37      * Test for {@link ShowEventTimesComandProvider#execute()} when no stats were touched before.
38      */
39     @Test
40     void showNoActivity() {
41         showEventTimesCommand.execute();
42         verify(console, never()).println(anyString());
43         assertNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION);
44     }
45
46     /**
47      * Test for {@link ShowEventTimesComandProvider#execute()} when stats were touched before.
48      */
49     @Test
50     void showHavingActivity() {
51         final var dummyEvent = new EventIdentifier("junit", "junitDevice");
52         EventsTimeCounter.markStart(dummyEvent);
53         EventsTimeCounter.markEnd(dummyEvent);
54         assertHasActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION);
55
56         showEventTimesCommand.execute();
57         verify(console).println(contains("junitDevice"));
58     }
59 }