2 * Copyright (c) 2024 PANTHEON.tech s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.impl.karaf;
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;
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;
22 * Test for {@link ShowEventTimesComandProvider}.
24 class ShowEventTimesComandProviderTest extends AbstractKarafTest {
25 private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = String::isEmpty;
28 private ShowEventTimesComandProvider showEventTimesCommand;
31 protected void doBeforeEach() {
32 EventsTimeCounter.resetAllCounters();
33 assertNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION);
37 * Test for {@link ShowEventTimesComandProvider#execute()} when no stats were touched before.
40 void showNoActivity() {
41 showEventTimesCommand.execute();
42 verify(console, never()).println(anyString());
43 assertNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION);
47 * Test for {@link ShowEventTimesComandProvider#execute()} when stats were touched before.
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);
56 showEventTimesCommand.execute();
57 verify(console).println(contains("junitDevice"));