2 * Copyright (c) 2015 Cisco Systems, Inc. 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.Mockito.atLeastOnce;
12 import static org.mockito.Mockito.verify;
14 import java.util.function.Function;
15 import org.junit.jupiter.api.Test;
16 import org.mockito.InjectMocks;
17 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.SessionStatistics;
20 * Test for {@link ResetSessionStatsComandProvider}.
22 class ResetSessionStatsComandProviderTest extends AbstractKarafTest {
24 private ResetSessionStatsComandProvider resetSessionStatsCommand;
25 private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = String::isEmpty;
28 protected void doBeforeEach() {
29 SessionStatistics.resetAllCounters();
30 assertNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION);
34 * Test for {@link ResetSessionStatsComandProvider#execute()} when no stats were touched before.
37 void resetNoActivity() {
38 resetSessionStatsCommand.execute();
39 verify(console, atLeastOnce()).println(anyString());
40 assertNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION);
44 * Test for {@link ResetSessionStatsComandProvider#execute()} when stats were touched before.
47 void resetHavingActivity() {
48 final String dummySessionId = "junitSessionId";
49 SessionStatistics.countEvent(dummySessionId, SessionStatistics.ConnectionStatus.CONNECTION_CREATED);
50 assertHasActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION);
52 resetSessionStatsCommand.execute();
53 verify(console, atLeastOnce()).println(anyString());
54 assertNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION);