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.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
19 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
20 import org.opendaylight.openflowplugin.impl.OpenFlowPluginProviderImpl;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
24 * Test for {@link ClearStatsCommandProvider}.
26 public class ClearStatsCommandProviderTest extends AbstractKarafTest {
28 private ClearStatsCommandProvider clearStatsCommandProvider;
29 private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION =
30 input -> input.endsWith(": no activity detected");
31 private MessageIntelligenceAgency mi5;
34 public void doSetUp() {
35 clearStatsCommandProvider = new ClearStatsCommandProvider();
36 mi5 = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency();
37 mi5.resetStatistics();
38 Mockito.when(cmdSession.getConsole()).thenReturn(console);
42 public void tearDown() {
43 Mockito.verify(console).print(anyString());
44 mi5.resetStatistics();
48 * Test for {@link ClearStatsCommandProvider#doExecute()} when no stats were touched before.
51 public void testDoExecute_clean() throws Exception {
52 Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
53 clearStatsCommandProvider.execute(cmdSession);
55 Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
59 * Test for {@link ClearStatsCommandProvider#doExecute()} when stats were touched before.
62 public void testDoExecute_dirty() throws Exception {
63 mi5 = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency();
64 Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
65 mi5.spyMessage(OfHeader.class, MessageSpy.StatisticsGroup.FROM_SWITCH);
66 Assert.assertFalse(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
68 clearStatsCommandProvider.execute(cmdSession);
69 Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));