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 com.google.common.base.Function;
14 import javax.annotation.Nullable;
15 import org.junit.After;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.mockito.Mockito;
19 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
20 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
21 import org.opendaylight.openflowplugin.impl.OpenFlowPluginProviderImpl;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
25 * Test for {@link ClearStatsCommandProvider}.
27 public class ClearStatsCommandProviderTest extends AbstractKarafTest {
29 private ClearStatsCommandProvider clearStatsCommandProvider;
30 private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = new Function<String, Boolean>() {
33 public Boolean apply(String input) {
34 return input.endsWith(": no activity detected");
37 private MessageIntelligenceAgency mi5;
40 public void doSetUp() {
41 clearStatsCommandProvider = new ClearStatsCommandProvider();
42 mi5 = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency();
43 mi5.resetStatistics();
44 Mockito.when(cmdSession.getConsole()).thenReturn(console);
48 public void tearDown() {
49 Mockito.verify(console).print(anyString());
50 mi5.resetStatistics();
54 * Test for {@link ClearStatsCommandProvider#doExecute()} when no stats were touched before.
57 public void testDoExecute_clean() throws Exception {
58 Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
59 clearStatsCommandProvider.execute(cmdSession);
61 Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
65 * Test for {@link ClearStatsCommandProvider#doExecute()} when stats were touched before.
68 public void testDoExecute_dirty() throws Exception {
69 mi5 = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency();
70 Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
71 mi5.spyMessage(OfHeader.class, MessageSpy.StatisticsGroup.FROM_SWITCH);
72 Assert.assertFalse(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
74 clearStatsCommandProvider.execute(cmdSession);
75 Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));