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.contains;
12 import java.util.function.Function;
13 import org.junit.After;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.mockito.Mockito;
17 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
18 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter;
21 * Test for {@link ShowEventTimesComandProvider}.
23 public class ShowEventTimesComandProviderTest extends AbstractKarafTest {
25 private ShowEventTimesComandProvider showEventTimesComandProvider;
26 private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = String::isEmpty;
30 public void doSetUp() {
31 showEventTimesComandProvider = new ShowEventTimesComandProvider();
32 EventsTimeCounter.resetAllCounters();
36 public void tearDown() {
37 EventsTimeCounter.resetAllCounters();
41 * Test for {@link ShowEventTimesComandProvider#doExecute()} when no stats were touched before.
44 public void testDoExecute_clean() throws Exception {
45 Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
46 showEventTimesComandProvider.execute(cmdSession);
47 Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
48 Mockito.verify(console).print("");
52 * Test for {@link ShowEventTimesComandProvider#doExecute()} when stats were touched before.
55 public void testDoExecute_dirty() throws Exception {
56 final EventIdentifier dummyEvent = new EventIdentifier("junit", "junitDevice");
57 Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
59 EventsTimeCounter.markStart(dummyEvent);
60 EventsTimeCounter.markEnd(dummyEvent);
61 Assert.assertFalse(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
63 showEventTimesComandProvider.execute(cmdSession);
64 Assert.assertFalse(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
65 Mockito.verify(console).print(contains("junitDevice"));