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
8 package org.opendaylight.openflowplugin.impl.karaf;
10 import static org.mockito.ArgumentMatchers.anyString;
11 import static org.mockito.Mockito.verify;
13 import java.util.function.Function;
14 import org.junit.jupiter.api.Test;
15 import org.mockito.InjectMocks;
16 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
17 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
18 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.MessageIntelligenceAgencyImpl;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
22 * Test for {@link ClearStatsCommand}.
24 class ClearStatsCommandTest extends AbstractCommandTest {
25 private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION =
26 input -> input.endsWith(": no activity detected");
28 private final MessageIntelligenceAgency messageIntelligenceAgency = new MessageIntelligenceAgencyImpl();
31 private ClearStatsCommand clearStatsCommand;
34 protected void doBeforeEach() {
35 clearStatsCommand.messageIntelligenceAgency = messageIntelligenceAgency;
36 messageIntelligenceAgency.resetStatistics();
37 assertNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION);
41 * Test for {@link ClearStatsCommand#execute()} when no stats were touched before.
44 void clearNoActivity() {
45 clearStatsCommand.execute();
46 verify(console).println(anyString());
47 assertNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION);
51 * Test for {@link ClearStatsCommand#execute()} when stats were touched before.
54 void clearHavingActivity() {
55 messageIntelligenceAgency.spyMessage(OfHeader.class, MessageSpy.StatisticsGroup.FROM_SWITCH);
56 assertHasActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION);
57 clearStatsCommand.execute();
58 verify(console).println(anyString());
59 assertNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION);