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.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 ShowStatsCommandProvider}.
26 public class ShowStatsCommandProviderTest extends AbstractKarafTest {
28 private ShowStatsCommandProvider showStatsCommandProvider;
29 private MessageIntelligenceAgency messageIntelligenceAgency;
31 private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = new Function<String, Boolean>() {
34 public Boolean apply(String input) {
35 return input.endsWith(": no activity detected");
40 public void doSetUp() {
41 showStatsCommandProvider = new ShowStatsCommandProvider();
42 messageIntelligenceAgency = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency();
43 messageIntelligenceAgency.resetStatistics();
47 public void tearDown() throws Exception {
48 // Pattern.DOTALL is set inline via "(?s)" at the beginning
49 Mockito.verify(console).print(Matchers.matches("(?s).+"));
50 messageIntelligenceAgency.resetStatistics();
54 * test for {@link ShowEventTimesComandProvider#doExecute()} when no stats were touched before
59 public void testDoExecute_clean() throws Exception {
60 Assert.assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
61 showStatsCommandProvider.execute(cmdSession);
62 Assert.assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
66 * test for {@link ShowEventTimesComandProvider#doExecute()} when stats were touched before
71 public void testDoExecute_dirty() throws Exception {
72 Assert.assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
74 messageIntelligenceAgency.spyMessage(OfHeader.class, MessageSpy.STATISTIC_GROUP.FROM_SWITCH);
75 Assert.assertFalse(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
77 showStatsCommandProvider.execute(cmdSession);
78 Assert.assertFalse(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));