7cab3e3e617ac2c0bf9f96d2343bdb69d876b96e
[genius.git] / itm / itm-impl / src / test / java / org / opendaylight / genius / itm / tests / ItmTest.java
1 /*
2  * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.genius.itm.tests;
9
10 import javax.inject.Inject;
11 import org.junit.After;
12 import org.junit.Before;
13 import org.junit.Rule;
14 import org.junit.Test;
15 import org.junit.rules.MethodRule;
16 import org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorEventsWaiter;
17 import org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorTestModule;
18 import org.opendaylight.genius.datastoreutils.testutils.TestableDataTreeChangeListenerModule;
19 import org.opendaylight.genius.itm.impl.ItmTestUtils;
20 import org.opendaylight.genius.utils.cache.CacheTestUtil;
21 import org.opendaylight.infrautils.caches.testutils.CacheModule;
22 import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule;
23 import org.opendaylight.infrautils.testutils.LogCaptureRule;
24 import org.opendaylight.infrautils.testutils.LogRule;
25
26 /**
27  * Component tests for ITM.
28  */
29 public class ItmTest {
30
31     public @Rule LogRule logRule = new LogRule();
32     public @Rule LogCaptureRule logCaptureRule = new LogCaptureRule();
33     public @Rule MethodRule guice = new GuiceRule(ItmTestModule.class, TestableDataTreeChangeListenerModule.class,
34             JobCoordinatorTestModule.class, CacheModule.class);
35
36     private @Inject JobCoordinatorEventsWaiter coordinatorEventsWaiter;
37
38     @Before
39     public void before() {
40         // so that any @Test methods here which do something real
41         // are isolated from any other test that run before this ItmTest
42         clearCaches();
43     }
44
45     @After
46     public void after() {
47         // so that any other *Test which will run after us has a clean slate again
48         clearCaches();
49     }
50
51     private void clearCaches() {
52         // Explicitly clear stupid static caches
53         // (TODO which really need to be de-static-ified instead of doing this..)
54         ItmTestUtils.clearAllItmCaches();
55         CacheTestUtil.clearAllCaches();
56     }
57
58     @Test
59     public void testWiring() {
60         // wait for default-TZ creation task (which runs on start-up) to get completed
61         coordinatorEventsWaiter.awaitEventsConsumption();
62         // do nothing; still valuable to check that ItmTestModule works and everything comes up
63     }
64 }