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.matches;
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 ShowStatsCommandProvider}.
27 public class ShowStatsCommandProviderTest extends AbstractKarafTest {
29 private ShowStatsCommandProvider showStatsCommandProvider;
30 private MessageIntelligenceAgency messageIntelligenceAgency;
32 private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = new Function<String, Boolean>() {
35 public Boolean apply(String input) {
36 return input.endsWith(": no activity detected");
41 public void doSetUp() {
42 showStatsCommandProvider = new ShowStatsCommandProvider();
43 messageIntelligenceAgency = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency();
44 messageIntelligenceAgency.resetStatistics();
48 public void tearDown() throws Exception {
49 // Pattern.DOTALL is set inline via "(?s)" at the beginning
50 Mockito.verify(console).print(matches("(?s).+"));
51 messageIntelligenceAgency.resetStatistics();
55 * Test for {@link ShowEventTimesComandProvider#doExecute()} when no stats were touched before.
58 public void testDoExecute_clean() throws Exception {
59 Assert.assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
60 showStatsCommandProvider.execute(cmdSession);
61 Assert.assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
65 * Test for {@link ShowEventTimesComandProvider#doExecute()} when stats were touched before.
68 public void testDoExecute_dirty() throws Exception {
69 Assert.assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
71 messageIntelligenceAgency.spyMessage(OfHeader.class, MessageSpy.StatisticsGroup.FROM_SWITCH);
72 Assert.assertFalse(checkNoActivity(messageIntelligenceAgency.provideIntelligence(),
73 CHECK_NO_ACTIVITY_FUNCTION));
75 showStatsCommandProvider.execute(cmdSession);
76 Assert.assertFalse(checkNoActivity(messageIntelligenceAgency.provideIntelligence(),
77 CHECK_NO_ACTIVITY_FUNCTION));