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
9 package org.opendaylight.openflowplugin.impl.karaf;
11 import static org.mockito.ArgumentMatchers.anyString;
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.impl.statistics.ofpspecific.SessionStatistics;
21 * Test for {@link ResetSessionStatsComandProvider}.
23 public class ResetSessionStatsComandProviderTest extends AbstractKarafTest {
25 private ResetSessionStatsComandProvider resetSessionStatsComandProvider;
26 private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = String::isEmpty;
29 public void doSetUp() {
30 resetSessionStatsComandProvider = new ResetSessionStatsComandProvider();
31 SessionStatistics.resetAllCounters();
35 public void tearDown() {
36 Mockito.verify(console).print(anyString());
37 SessionStatistics.resetAllCounters();
41 * Test for {@link ResetSessionStatsComandProvider#doExecute()} when no stats were touched before.
44 public void testDoExecute_clean() throws Exception {
45 Assert.assertTrue(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
46 resetSessionStatsComandProvider.execute(cmdSession);
47 Assert.assertTrue(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
51 * Test for {@link ResetSessionStatsComandProvider#doExecute()} when stats were touched before.
54 public void testDoExecute_dirty() throws Exception {
55 final String dummySessionId = "junitSessionId";
56 Assert.assertTrue(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
58 SessionStatistics.countEvent(dummySessionId, SessionStatistics.ConnectionStatus.CONNECTION_CREATED);
59 Assert.assertFalse(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
61 resetSessionStatsComandProvider.execute(cmdSession);
62 Assert.assertTrue(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));