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.EventIdentifier;
19 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter;
22 * Test for {@link ResetEventTimesComandProvider}.
24 public class ResetEventTimesComandProviderTest extends AbstractKarafTest {
26 private ResetEventTimesComandProvider resetEventTimesComandProvider;
27 private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = new Function<String, Boolean>() {
30 public Boolean apply(String input) {
31 return input.isEmpty();
37 public void doSetUp() {
38 resetEventTimesComandProvider = new ResetEventTimesComandProvider();
39 EventsTimeCounter.resetAllCounters();
43 public void tearDown() {
44 Mockito.verify(console).print(Matchers.anyString());
45 EventsTimeCounter.resetAllCounters();
49 * Test for {@link ResetEventTimesComandProvider#doExecute()} when no stats were touched before.
52 public void testDoExecute_clean() throws Exception {
53 Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
54 resetEventTimesComandProvider.execute(cmdSession);
55 Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
59 * Test for {@link ResetEventTimesComandProvider#doExecute()} when stats were touched before.
62 public void testDoExecute_dirty() throws Exception {
63 final EventIdentifier dummyEvent = new EventIdentifier("junit", "junitDevice");
64 Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
66 EventsTimeCounter.markStart(dummyEvent);
67 EventsTimeCounter.markEnd(dummyEvent);
68 Assert.assertFalse(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
70 resetEventTimesComandProvider.execute(cmdSession);
71 Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));