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 com.google.common.base.Function;
12 import javax.annotation.Nullable;
13 import org.junit.After;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.mockito.Matchers;
17 import org.mockito.Mockito;
18 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.SessionStatistics;
21 * Test for {@link ShowSessionStatsCommandProvider}.
23 public class ShowSessionStatsCommandProviderTest extends AbstractKarafTest {
25 private ShowSessionStatsCommandProvider showSessionStatsCommandProvider;
26 private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = new Function<String, Boolean>() {
29 public Boolean apply(String input) {
30 return input.isEmpty();
36 public void doSetUp() {
37 showSessionStatsCommandProvider = new ShowSessionStatsCommandProvider();
38 SessionStatistics.resetAllCounters();
42 public void tearDown() {
43 SessionStatistics.resetAllCounters();
47 * Test for {@link ShowEventTimesComandProvider#doExecute()} when no stats were touched before.
50 public void testDoExecute_clean() throws Exception {
51 Assert.assertTrue(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
52 showSessionStatsCommandProvider.execute(cmdSession);
53 Assert.assertTrue(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
54 Mockito.verify(console).print("");
58 * Test for {@link ShowEventTimesComandProvider#doExecute()} when stats were touched before.
61 public void testDoExecute_dirty() throws Exception {
62 final String dummySessionId = "junitSessionId";
63 Assert.assertTrue(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
65 SessionStatistics.countEvent(dummySessionId, SessionStatistics.ConnectionStatus.CONNECTION_CREATED);
66 Assert.assertFalse(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
68 showSessionStatsCommandProvider.execute(cmdSession);
69 Assert.assertFalse(checkNoActivity(SessionStatistics.provideStatistics(), CHECK_NO_ACTIVITY_FUNCTION));
70 Mockito.verify(console).print(Matchers.contains(dummySessionId));