Cleaning up intent tests setup/teardown to avoid cascading failures
with respect to binding ID generator.
Change-Id: Ia4778f16ff5a3ecb26062e7d7b2c36493081140d
diff --git a/core/api/src/main/java/org/onosproject/net/intent/Intent.java b/core/api/src/main/java/org/onosproject/net/intent/Intent.java
index 12dad21..8f4ab6f 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/Intent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/Intent.java
@@ -22,11 +22,8 @@
import org.onosproject.net.ResourceGroup;
import java.util.Collection;
-import java.util.Objects;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Preconditions.*;
/**
* Abstraction of an application level intent.
@@ -286,7 +283,7 @@
* @param oldIdGenerator the current id generator
*/
public static void unbindIdGenerator(IdGenerator oldIdGenerator) {
- if (Objects.equals(idGenerator, oldIdGenerator)) {
+ if (idGenerator == oldIdGenerator) {
idGenerator = null;
}
}
diff --git a/core/api/src/test/java/org/onosproject/net/intent/AbstractIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/AbstractIntentTest.java
index c4e5f9f..2999da5 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/AbstractIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/AbstractIntentTest.java
@@ -17,20 +17,20 @@
import org.junit.After;
import org.junit.Before;
-import org.onosproject.core.IdGenerator;
+/**
+ * Basis for all intent-related tests. It cleanly binds and unbinds a
+ * deterministic mock generator as part of set-up and tear-down.
+ */
public abstract class AbstractIntentTest {
- protected IdGenerator idGenerator = new MockIdGenerator();
-
@Before
- public void setUp() throws Exception {
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ public void setUp() {
+ MockIdGenerator.cleanBind();
}
@After
public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
+ MockIdGenerator.unbind();
}
}
diff --git a/core/api/src/test/java/org/onosproject/net/intent/IntentDataTest.java b/core/api/src/test/java/org/onosproject/net/intent/IntentDataTest.java
index de215c6..f7bb7a3 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/IntentDataTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/IntentDataTest.java
@@ -15,14 +15,12 @@
*/
package org.onosproject.net.intent;
-import org.junit.After;
+import com.google.common.testing.EqualsTester;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.core.IdGenerator;
import org.onosproject.store.Timestamp;
-import com.google.common.testing.EqualsTester;
-
import static junit.framework.TestCase.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@@ -33,7 +31,7 @@
/**
* Unit tests for intent data objects.
*/
-public class IntentDataTest {
+public class IntentDataTest extends AbstractIntentTest {
private Timestamp timestamp1;
private Timestamp timestamp2;
@@ -53,10 +51,8 @@
IdGenerator idGenerator;
@Before
- public void setUpTest() {
- idGenerator = new MockIdGenerator();
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ public void setUp() {
+ super.setUp();
timestamp1 = new MockTimestamp(1);
timestamp2 = new MockTimestamp(2);
@@ -74,11 +70,6 @@
data3Copy = new IntentData(intent3, IntentState.INSTALLED, timestamp3);
}
- @After
- public void tearDownTest() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
/**
* Checks that intent data objects are properly constructed.
*/
diff --git a/core/api/src/test/java/org/onosproject/net/intent/IntentServiceTest.java b/core/api/src/test/java/org/onosproject/net/intent/IntentServiceTest.java
index 1bafca8..2ae87fb 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/IntentServiceTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/IntentServiceTest.java
@@ -18,7 +18,6 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onosproject.core.IdGenerator;
import java.util.ArrayList;
import java.util.Arrays;
@@ -32,7 +31,7 @@
/**
* Suite of tests for the intent service contract.
*/
-public class IntentServiceTest {
+public class IntentServiceTest extends AbstractIntentTest {
public static final int IID = 123;
public static final int INSTALLABLE_IID = 234;
@@ -41,20 +40,18 @@
protected TestableIntentService service;
protected TestListener listener = new TestListener();
- protected IdGenerator idGenerator = new MockIdGenerator();
@Before
public void setUp() {
+ super.setUp();
service = createIntentService();
service.addListener(listener);
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
}
@After
public void tearDown() {
service.removeListener(listener);
- Intent.unbindIdGenerator(idGenerator);
+ super.tearDown();
}
/**
diff --git a/core/api/src/test/java/org/onosproject/net/intent/MockIdGenerator.java b/core/api/src/test/java/org/onosproject/net/intent/MockIdGenerator.java
index 2059cfc..ecf6cb7 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/MockIdGenerator.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/MockIdGenerator.java
@@ -22,18 +22,38 @@
/**
* Mock id generator for testing.
*/
-public class MockIdGenerator implements IdGenerator {
+public final class MockIdGenerator implements IdGenerator {
+
+ public static final MockIdGenerator INSTANCE = new MockIdGenerator();
private static boolean generatorIsBound = false;
- private static MockIdGenerator idGenerator;
- public static void bindNewGenerator() {
+
+ // Ban public construction
+ private MockIdGenerator() {
+ }
+
+ /**
+ * Binds clean mock generator to the intent.
+ */
+ public static synchronized void cleanBind() {
+ INSTANCE.nextId = new AtomicLong(0);
if (!generatorIsBound) {
generatorIsBound = true;
- idGenerator = new MockIdGenerator();
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ Intent.unbindIdGenerator(INSTANCE);
+ Intent.bindIdGenerator(INSTANCE);
}
}
+
+ /**
+ * Unbinds mock generator from the intent.
+ */
+ public static synchronized void unbind() {
+ if (generatorIsBound) {
+ generatorIsBound = false;
+ Intent.unbindIdGenerator(INSTANCE);
+ }
+ }
+
private AtomicLong nextId = new AtomicLong(0);
@Override
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/InstallCoordinatorTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/InstallCoordinatorTest.java
index 2bdf200..165f096 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/InstallCoordinatorTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/InstallCoordinatorTest.java
@@ -24,16 +24,15 @@
import org.onlab.junit.TestTools;
import org.onosproject.TestApplicationId;
import org.onosproject.core.ApplicationId;
-import org.onosproject.core.IdGenerator;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.FilteredConnectPoint;
+import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentInstaller;
import org.onosproject.net.intent.IntentOperationContext;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.Key;
-import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.TestInstallableIntent;
import org.onosproject.store.intent.impl.IntentStoreAdapter;
@@ -43,15 +42,15 @@
import java.util.Optional;
import java.util.stream.IntStream;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
/**
* Tests for install coordinator.
*/
-public class InstallCoordinatorTest {
+public class InstallCoordinatorTest extends AbstractIntentTest {
private static final int INSTALL_DELAY = 100;
private static final int INSTALL_DURATION = 1000;
- private static final IdGenerator ID_GENERATOR = new MockIdGenerator();
private InstallCoordinator installCoordinator;
private InstallerRegistry installerRegistry;
@@ -61,8 +60,7 @@
@Before
public void setup() {
- Intent.unbindIdGenerator(ID_GENERATOR);
- Intent.bindIdGenerator(ID_GENERATOR);
+ super.setUp();
installerRegistry = new InstallerRegistry();
intentStore = new TestIntentStore();
intentInstaller = new TestIntentInstaller();
@@ -74,7 +72,7 @@
@After
public void tearDown() {
installerRegistry.unregisterInstaller(TestInstallableIntent.class);
- Intent.unbindIdGenerator(ID_GENERATOR);
+ super.tearDown();
}
/**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentAccumulatorTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentAccumulatorTest.java
index 8914f17..5be9e65 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentAccumulatorTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentAccumulatorTest.java
@@ -15,24 +15,21 @@
*/
package org.onosproject.net.intent.impl;
-import java.util.Collection;
-import java.util.List;
-
+import com.google.common.collect.ImmutableList;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onosproject.core.IdGenerator;
+import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentBatchDelegate;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.IntentTestsMocks.MockIntent;
import org.onosproject.net.intent.IntentTestsMocks.MockTimestamp;
-import org.onosproject.net.intent.MockIdGenerator;
-import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
@@ -40,12 +37,11 @@
/**
* Unit tests for the intent accumulator.
*/
-public class IntentAccumulatorTest {
+public class IntentAccumulatorTest extends AbstractIntentTest {
Intent intent1;
Intent intent2;
Intent intent3;
- IdGenerator mockGenerator;
private static IntentDataMatcher containsIntent(Intent intent) {
return new IntentDataMatcher(intent);
@@ -55,10 +51,8 @@
* Creates mock intents used by the test.
*/
@Before
- public void localSetup() {
- mockGenerator = new MockIdGenerator();
- Intent.unbindIdGenerator(mockGenerator);
- Intent.bindIdGenerator(mockGenerator);
+ public void setUp() {
+ super.setUp();
intent1 = new MockIntent(1L);
intent2 = new MockIntent(2L);
@@ -66,14 +60,6 @@
}
/**
- * Removes id generator from the Intent class.
- */
- @After
- public void localTearDown() {
- Intent.unbindIdGenerator(mockGenerator);
- }
-
- /**
* Hamcrest matcher to check that a collection of intent data objects
* contains an entry for a given intent.
*/
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentCleanupTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentCleanupTest.java
index 25f8953..c5f0941 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentCleanupTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentCleanupTest.java
@@ -21,14 +21,13 @@
import org.junit.Ignore;
import org.junit.Test;
import org.onosproject.cfg.ComponentConfigAdapter;
-import org.onosproject.core.IdGenerator;
+import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentEvent;
import org.onosproject.net.intent.IntentServiceAdapter;
import org.onosproject.net.intent.IntentStore;
import org.onosproject.net.intent.IntentStoreDelegate;
-import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.store.Timestamp;
import org.onosproject.store.trivial.SimpleIntentStore;
import org.onosproject.store.trivial.SystemClockTimestamp;
@@ -41,12 +40,11 @@
/**
* Test intent cleanup.
*/
-public class IntentCleanupTest {
+public class IntentCleanupTest extends AbstractIntentTest {
private IntentCleanup cleanup;
private MockIntentService service;
private IntentStore store;
- protected IdGenerator idGenerator; // global or one per test? per test for now.
private static class MockIntentService extends IntentServiceAdapter {
@@ -78,7 +76,8 @@
service = new MockIntentService();
store = new SimpleIntentStore();
cleanup = new IntentCleanup();
- idGenerator = new MockIdGenerator();
+
+ super.setUp();
cleanup.cfgService = new ComponentConfigAdapter();
cleanup.service = service;
@@ -89,15 +88,12 @@
assertTrue("store should be empty",
Sets.newHashSet(cleanup.store.getIntents()).isEmpty());
-
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
}
@After
public void tearDown() {
cleanup.deactivate();
- Intent.unbindIdGenerator(idGenerator);
+ super.tearDown();
}
/**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentCleanupTestMock.java b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentCleanupTestMock.java
index 40efded..ac7f043 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/IntentCleanupTestMock.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/IntentCleanupTestMock.java
@@ -21,14 +21,13 @@
import org.junit.Ignore;
import org.junit.Test;
import org.onosproject.cfg.ComponentConfigAdapter;
-import org.onosproject.core.IdGenerator;
+import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentEvent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentStore;
import org.onosproject.net.intent.IntentStoreDelegate;
-import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.store.Timestamp;
import org.onosproject.store.trivial.SimpleIntentStore;
import org.onosproject.store.trivial.SystemClockTimestamp;
@@ -42,19 +41,17 @@
* Test intent cleanup using Mocks.
* FIXME remove this or IntentCleanupTest
*/
-public class IntentCleanupTestMock {
+public class IntentCleanupTestMock extends AbstractIntentTest {
private IntentCleanup cleanup;
private IntentService service;
private IntentStore store;
- protected IdGenerator idGenerator; // global or one per test? per test for now.
@Before
public void setUp() {
service = createMock(IntentService.class);
store = new SimpleIntentStore();
cleanup = new IntentCleanup();
- idGenerator = new MockIdGenerator();
service.addListener(cleanup);
expectLastCall().once();
@@ -73,8 +70,7 @@
assertTrue("store should be empty",
Sets.newHashSet(cleanup.store.getIntents()).isEmpty());
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
}
@After
@@ -88,7 +84,7 @@
verify(service);
reset(service);
- Intent.unbindIdGenerator(idGenerator);
+ super.tearDown();
}
/**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/ObjectiveTrackerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/ObjectiveTrackerTest.java
index 6ed50af..bd12884 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/ObjectiveTrackerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/ObjectiveTrackerTest.java
@@ -15,18 +15,13 @@
*/
package org.onosproject.net.intent.impl;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import org.onlab.junit.TestUtils.TestUtilsException;
-import org.onosproject.core.IdGenerator;
import org.onosproject.event.Event;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
@@ -35,9 +30,8 @@
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
-import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Key;
-import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.resource.ResourceEvent;
import org.onosproject.net.resource.ResourceListener;
@@ -46,23 +40,22 @@
import org.onosproject.net.topology.TopologyEvent;
import org.onosproject.net.topology.TopologyListener;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import static org.easymock.EasyMock.createMock;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
-import static org.onosproject.net.resource.ResourceEvent.Type.*;
-import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.NetTestTools.device;
-import static org.onosproject.net.NetTestTools.link;
+import static org.hamcrest.Matchers.*;
+import static org.onosproject.net.NetTestTools.*;
+import static org.onosproject.net.resource.ResourceEvent.Type.RESOURCE_ADDED;
/**
* Tests for the objective tracker.
*/
-public class ObjectiveTrackerTest {
+public class ObjectiveTrackerTest extends AbstractIntentTest {
private static final int WAIT_TIMEOUT_SECONDS = 2;
private Topology topology;
private ObjectiveTracker tracker;
@@ -71,7 +64,6 @@
private TopologyListener listener;
private DeviceListener deviceListener;
private ResourceListener resourceListener;
- private IdGenerator mockGenerator;
/**
* Initialization shared by all test cases.
@@ -79,7 +71,7 @@
* @throws TestUtilsException if any filed look ups fail
*/
@Before
- public void setUp() throws TestUtilsException {
+ public void setUp() {
topology = createMock(Topology.class);
tracker = new ObjectiveTracker();
delegate = new TestTopologyChangeDelegate();
@@ -88,9 +80,7 @@
listener = TestUtils.getField(tracker, "listener");
deviceListener = TestUtils.getField(tracker, "deviceListener");
resourceListener = TestUtils.getField(tracker, "resourceListener");
- mockGenerator = new MockIdGenerator();
- Intent.unbindIdGenerator(mockGenerator);
- Intent.bindIdGenerator(mockGenerator);
+ super.setUp();
}
/**
@@ -99,7 +89,7 @@
@After
public void tearDown() {
tracker.unsetDelegate(delegate);
- Intent.unbindIdGenerator(mockGenerator);
+ super.tearDown();
}
/**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/AbstractLinkCollectionTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/AbstractLinkCollectionTest.java
index 32dc47f..f0f1d29 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/AbstractLinkCollectionTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/AbstractLinkCollectionTest.java
@@ -20,7 +20,6 @@
import org.onosproject.TestApplicationId;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
-import org.onosproject.core.IdGenerator;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
@@ -30,10 +29,10 @@
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.LinkCollectionIntent;
-import org.onosproject.net.intent.MockIdGenerator;
import java.util.Collection;
import java.util.List;
@@ -41,13 +40,12 @@
import java.util.stream.Collectors;
import static org.onosproject.net.NetTestTools.*;
-import static org.onosproject.net.NetTestTools.macDstTreatment;
/**
* Abstract class to hold the common variables and pieces
* of code.
*/
-class AbstractLinkCollectionTest {
+abstract class AbstractLinkCollectionTest extends AbstractIntentTest {
static final String LABEL_SELECTION = "FIRST_FIT";
static final String LABEL = "1";
@@ -155,7 +153,6 @@
DomainService domainService;
IntentExtensionService intentExtensionService;
IntentConfigurableRegistrator registrator;
- IdGenerator idGenerator = new MockIdGenerator();
LinkCollectionIntent intent;
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
index a0104a1..52c1d11 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
@@ -102,7 +102,7 @@
@Override
@Before
- public void setUp() throws Exception {
+ public void setUp() {
super.setUp();
Host hostOne = createMock(Host.class);
expect(hostOne.mac()).andReturn(new MacAddress(HOST_ONE_MAC.getBytes())).anyTimes();
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java
index 55c1d9b..267d19e 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionEncapIntentCompilerTest.java
@@ -17,7 +17,6 @@
package org.onosproject.net.intent.impl.compiler;
import com.google.common.collect.ImmutableSet;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ethernet;
@@ -45,19 +44,14 @@
import java.util.List;
import java.util.stream.Collectors;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.core.Is.is;
import static org.onlab.packet.EthType.EtherType.IPV4;
import static org.onosproject.net.NetTestTools.APP_ID;
import static org.onosproject.net.domain.DomainId.LOCAL;
-import static org.onosproject.net.flow.criteria.Criterion.Type.IN_PORT;
-import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL;
-import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID;
+import static org.onosproject.net.flow.criteria.Criterion.Type.*;
import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
/**
@@ -77,8 +71,7 @@
expect(domainService.getDomain(anyObject(DeviceId.class))).andReturn(LOCAL).anyTimes();
sut.domainService = domainService;
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
intentExtensionService = createMock(IntentExtensionService.class);
intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut);
@@ -98,11 +91,6 @@
replay(coreService, domainService, intentExtensionService);
}
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
/**
* We test the proper compilation of mp2Sp1 with the VLAN
* encapsulation, trivial selector.
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerDomainP2PTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerDomainP2PTest.java
index 1b726f7..0c9374d 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerDomainP2PTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerDomainP2PTest.java
@@ -18,7 +18,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.cfg.ComponentConfigAdapter;
@@ -40,9 +39,7 @@
import java.util.Collections;
import java.util.List;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
@@ -74,8 +71,7 @@
expect(domainService.getDomain(d3Id)).andReturn(LOCAL).anyTimes();
sut.domainService = domainService;
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
intentExtensionService = createMock(IntentExtensionService.class);
intentExtensionService
@@ -96,11 +92,6 @@
replay(coreService, domainService, intentExtensionService);
}
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
/**
* We test the proper compilation of one domain device.
*/
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerP2PTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerP2PTest.java
index 2b93ce9..6f23873 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerP2PTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerP2PTest.java
@@ -18,7 +18,6 @@
import com.google.common.collect.ImmutableSet;
import org.hamcrest.core.Is;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ethernet;
@@ -45,10 +44,7 @@
import java.util.List;
import java.util.stream.Collectors;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.core.Is.is;
@@ -76,8 +72,7 @@
expect(domainService.getDomain(anyObject(DeviceId.class))).andReturn(LOCAL).anyTimes();
sut.domainService = domainService;
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
intentExtensionService = createMock(IntentExtensionService.class);
intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut);
@@ -97,11 +92,6 @@
replay(coreService, domainService, intentExtensionService);
}
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
/**
* We test the proper compilation of p2p with
* trivial selector and trivial treatment.
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
index d5aea2c..7acdbcf 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
@@ -17,7 +17,6 @@
import com.google.common.collect.ImmutableSet;
import org.hamcrest.core.Is;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.MacAddress;
@@ -51,24 +50,17 @@
import java.util.Set;
import java.util.stream.Collectors;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.*;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.everyItem;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.*;
import static org.onlab.packet.EthType.EtherType.IPV4;
import static org.onosproject.net.Link.Type.DIRECT;
import static org.onosproject.net.NetTestTools.APP_ID;
import static org.onosproject.net.NetTestTools.PID;
import static org.onosproject.net.domain.DomainId.LOCAL;
-import static org.onosproject.net.flow.criteria.Criterion.Type.IN_PORT;
-import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL;
-import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID;
+import static org.onosproject.net.flow.criteria.Criterion.Type.*;
import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
/**
@@ -89,8 +81,7 @@
expect(domainService.getDomain(anyObject(DeviceId.class))).andReturn(LOCAL).anyTimes();
sut.domainService = domainService;
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
intent = LinkCollectionIntent.builder()
.appId(APP_ID)
@@ -120,12 +111,6 @@
}
- @After
- public void tearDown() {
-
- Intent.unbindIdGenerator(idGenerator);
- }
-
/**
* We test the proper compilation of a simple link collection intent
* with connect points, trivial treatment and trivial selector.
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompilerTest.java
index 2c77956..88b2118 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentObjectiveCompilerTest.java
@@ -17,7 +17,6 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.MacAddress;
@@ -52,16 +51,11 @@
import java.util.List;
import java.util.Set;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.*;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.Matchers.*;
import static org.onosproject.net.Link.Type.DIRECT;
import static org.onosproject.net.NetTestTools.PID;
import static org.onosproject.net.domain.DomainId.LOCAL;
@@ -93,7 +87,7 @@
expect(domainService.getDomain(anyObject(DeviceId.class))).andReturn(LOCAL).anyTimes();
compiler.domainService = domainService;
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
intentExtensionService = createMock(IntentExtensionService.class);
intentExtensionService.registerCompiler(LinkCollectionIntent.class, compiler);
@@ -114,11 +108,6 @@
}
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
/**
* We test the proper compilation of a simple link collection intent
* with connect points, empty trivial treatment and empty trivial selector.
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionOptimizationTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionOptimizationTest.java
index 93b83fa..5f3ee74 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionOptimizationTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionOptimizationTest.java
@@ -17,7 +17,6 @@
package org.onosproject.net.intent.impl.compiler;
import com.google.common.collect.ImmutableSet;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ethernet;
@@ -44,10 +43,7 @@
import java.util.List;
import java.util.stream.Collectors;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.core.Is.is;
@@ -76,8 +72,7 @@
expect(domainService.getDomain(anyObject(DeviceId.class))).andReturn(LOCAL).anyTimes();
sut.domainService = domainService;
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
intentExtensionService = createMock(IntentExtensionService.class);
intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut);
@@ -100,11 +95,6 @@
replay(coreService, domainService, intentExtensionService);
}
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
/**
* We test the proper optimization of sp2mp with dec tll
* and dec mpls ttl.
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
index 2ddca7d..5bdb0ee 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompilerTest.java
@@ -15,20 +15,12 @@
*/
package org.onosproject.net.intent.impl.compiler;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.MplsLabel;
import org.onosproject.TestApplicationId;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
-import org.onosproject.core.IdGenerator;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.DefaultPath;
@@ -38,26 +30,28 @@
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.FlowRuleIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.MplsPathIntent;
import org.onosproject.net.resource.MockResourceService;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+import static org.easymock.EasyMock.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.NetTestTools.PID;
-import static org.onosproject.net.NetTestTools.connectPoint;
+import static org.onosproject.net.NetTestTools.*;
-public class MplsPathIntentCompilerTest {
+public class MplsPathIntentCompilerTest extends AbstractIntentTest {
private final ApplicationId appId = new TestApplicationId("test");
@@ -83,8 +77,6 @@
createEdgeLink(d3pe, false)
);
- private IdGenerator idGenerator = new MockIdGenerator();
-
private final int hops = links.size() - 1;
private MplsPathIntent intent;
private MplsPathIntentCompiler sut;
@@ -98,8 +90,7 @@
sut.coreService = coreService;
sut.resourceService = new MockResourceService();
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
intent = MplsPathIntent.builder()
.appId(APP_ID)
@@ -119,11 +110,6 @@
replay(coreService, intentExtensionService);
}
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
@Test
public void testCompile() {
sut.activate();
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
index e616a23..cef9275 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
@@ -16,7 +16,6 @@
package org.onosproject.net.intent.impl.compiler;
import com.google.common.collect.ImmutableList;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.Ethernet;
@@ -26,7 +25,6 @@
import org.onosproject.cfg.ComponentConfigAdapter;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
-import org.onosproject.core.IdGenerator;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.DefaultPath;
@@ -40,10 +38,10 @@
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.flow.instructions.L2ModificationInstruction;
+import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.FlowRuleIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.constraint.EncapsulationConstraint;
import org.onosproject.net.provider.ProviderId;
@@ -56,32 +54,24 @@
import java.util.Set;
import java.util.stream.Collectors;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.*;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.everyItem;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.lessThan;
+import static org.hamcrest.Matchers.*;
import static org.hamcrest.number.OrderingComparison.greaterThan;
import static org.junit.Assert.assertTrue;
import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
import static org.onosproject.net.Link.Type.DIRECT;
import static org.onosproject.net.Link.Type.INDIRECT;
-import static org.onosproject.net.NetTestTools.APP_ID;
-import static org.onosproject.net.NetTestTools.PID;
-import static org.onosproject.net.NetTestTools.connectPoint;
+import static org.onosproject.net.NetTestTools.*;
/**
* Unit tests for PathIntentCompiler.
*/
-public class PathIntentCompilerTest {
+public class PathIntentCompilerTest extends AbstractIntentTest {
private CoreService coreService;
private IntentExtensionService intentExtensionService;
private IntentConfigurableRegistrator registrator;
- private IdGenerator idGenerator = new MockIdGenerator();
private PathIntentCompiler sut;
private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
@@ -175,8 +165,7 @@
sut.coreService = coreService;
sut.resourceService = new MockResourceService();
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
intent = PathIntent.builder()
.appId(APP_ID)
@@ -338,15 +327,6 @@
}
/**
- * Tears down objects used in all the test cases.
- */
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
-
- /**
* Tests the compilation behavior of the path intent compiler in case of
* VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
* and edge communication. No ingress VLAN. No egress VLAN.
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompilerTest.java
index 595afd4..8b6c1fc 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompilerTest.java
@@ -68,7 +68,6 @@
private CoreService coreService;
private TestableIntentService intentService = new FakeIntentManager();
private IntentExtensionService intentExtensionService;
- private final IdGenerator idGenerator = new MockIdGenerator();
private VirtualNetworkIntentCompiler compiler;
private VirtualNetworkManager manager;
private DistributedVirtualNetworkStore virtualNetworkManagerStore;
@@ -97,8 +96,7 @@
coreService = new TestCoreService();
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ MockIdGenerator.cleanBind();
setField(virtualNetworkManagerStore, "coreService", coreService);
setField(virtualNetworkManagerStore, "storageService", new TestStorageService());
@@ -130,8 +128,8 @@
@After
public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
manager.deactivate();
+ MockIdGenerator.unbind();
}
/**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/AbstractIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/AbstractIntentInstallerTest.java
index caa07be..a7725bd 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/AbstractIntentInstallerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/AbstractIntentInstallerTest.java
@@ -18,7 +18,6 @@
import org.onosproject.TestApplicationId;
import org.onosproject.core.ApplicationId;
-import org.onosproject.core.IdGenerator;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.ResourceGroup;
@@ -26,12 +25,11 @@
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.IntentInstallCoordinator;
import org.onosproject.net.intent.IntentOperationContext;
import org.onosproject.net.intent.Key;
-import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.impl.ObjectiveTrackerService;
@@ -41,7 +39,7 @@
* Abstract class to hold the common variables and pieces of code for Intent
* installer test.
*/
-public class AbstractIntentInstallerTest {
+public class AbstractIntentInstallerTest extends AbstractIntentTest {
protected static final ApplicationId APP_ID = TestApplicationId.create("IntentInstallerTest");
protected static final ConnectPoint CP1 = ConnectPoint.deviceConnectPoint("s1/1");
protected static final ConnectPoint CP2 = ConnectPoint.deviceConnectPoint("s1/2");
@@ -49,24 +47,18 @@
protected static final Key KEY1 = Key.of("test intent 1", APP_ID);
protected static final ResourceGroup RG1 = ResourceGroup.of("test resource group 1");
protected static final int DEFAULT_PRIORITY = 30000;
- protected static final IdGenerator ID_GENERATOR = new MockIdGenerator();
protected IntentExtensionService intentExtensionService;
protected ObjectiveTrackerService trackerService;
protected TestIntentInstallCoordinator intentInstallCoordinator;
public void setup() {
- Intent.unbindIdGenerator(ID_GENERATOR);
- Intent.bindIdGenerator(ID_GENERATOR);
+ super.setUp();
intentExtensionService = createMock(IntentExtensionService.class);
trackerService = createMock(ObjectiveTrackerService.class);
intentInstallCoordinator = new TestIntentInstallCoordinator();
}
- public void tearDown() {
- Intent.unbindIdGenerator(ID_GENERATOR);
- }
-
/**
* Creates point to point Intent for test.
*
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java
index 9e508c6..393e56b 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/phase/CompilingTest.java
@@ -15,7 +15,6 @@
*/
package org.onosproject.net.intent.impl.phase;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.TestApplicationId;
@@ -30,10 +29,9 @@
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.IntentCompilationException;
import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.impl.IntentProcessor;
@@ -44,10 +42,7 @@
import java.util.List;
import java.util.Optional;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
+import static org.easymock.EasyMock.*;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@@ -59,7 +54,7 @@
/**
* Unit tests for Compiling phase.
*/
-public class CompilingTest {
+public class CompilingTest extends AbstractIntentTest {
private final ApplicationId appId = new TestApplicationId("test");
private final ProviderId pid = new ProviderId("of", "test");
@@ -83,14 +78,11 @@
@Before
public void setUp() {
+ super.setUp();
+
processor = createMock(IntentProcessor.class);
version = createMock(Timestamp.class);
- idGenerator = new MockIdGenerator();
-
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
-
// Intent creation should be placed after binding an ID generator
input = PointToPointIntent.builder()
.appId(appId)
@@ -107,12 +99,6 @@
.build();
}
-
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
/**
* Tests a next phase when no exception occurs.
*/
diff --git a/core/net/src/test/java/org/onosproject/net/resource/impl/LabelAllocatorTest.java b/core/net/src/test/java/org/onosproject/net/resource/impl/LabelAllocatorTest.java
index c05feca..48d7272 100644
--- a/core/net/src/test/java/org/onosproject/net/resource/impl/LabelAllocatorTest.java
+++ b/core/net/src/test/java/org/onosproject/net/resource/impl/LabelAllocatorTest.java
@@ -56,7 +56,7 @@
private LabelAllocator allocator;
private MockResourceService resourceService;
- private IdGenerator idGenerator = new MockIdGenerator();
+ private IdGenerator idGenerator = MockIdGenerator.INSTANCE;
private final ConnectPoint d1p0 = connectPoint("s1", 0);
private final ConnectPoint d1p1 = connectPoint("s1", 1);
diff --git a/core/store/dist/src/test/java/org/onosproject/store/intent/impl/GossipIntentStoreTest.java b/core/store/dist/src/test/java/org/onosproject/store/intent/impl/GossipIntentStoreTest.java
index 42ec399..95dd0cc 100644
--- a/core/store/dist/src/test/java/org/onosproject/store/intent/impl/GossipIntentStoreTest.java
+++ b/core/store/dist/src/test/java/org/onosproject/store/intent/impl/GossipIntentStoreTest.java
@@ -15,27 +15,26 @@
*/
package org.onosproject.store.intent.impl;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.IntStream;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.cfg.ConfigProperty;
import org.onosproject.cluster.ClusterServiceAdapter;
-import org.onosproject.core.IdGenerator;
+import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.HostToHostIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.IntentTestsMocks;
-import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.WorkPartitionServiceAdapter;
import org.onosproject.store.service.TestStorageService;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.IntStream;
+
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
@@ -45,10 +44,9 @@
/**
* Gossip Intent Store test using database adapter.
*/
-public class GossipIntentStoreTest {
+public class GossipIntentStoreTest extends AbstractIntentTest {
private GossipIntentStore intentStore;
- private IdGenerator idGenerator;
private HostToHostIntent.Builder builder1;
@Before
@@ -57,9 +55,7 @@
intentStore.storageService = new TestStorageService();
intentStore.partitionService = new WorkPartitionServiceAdapter();
intentStore.clusterService = new ClusterServiceAdapter();
- idGenerator = new MockIdGenerator();
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
builder1 = HostToHostIntent
.builder()
.one(hid("12:34:56:78:91:ab/1"))
@@ -70,9 +66,9 @@
}
@After
- public void cleanUp() {
+ public void tearDown() {
intentStore.deactivate();
- Intent.unbindIdGenerator(idGenerator);
+ super.tearDown();
}
/**