Cleaning up intent tests setup/teardown to avoid cascading failures
with respect to binding ID generator.
Change-Id: Ia4778f16ff5a3ecb26062e7d7b2c36493081140d
diff --git a/apps/acl/src/test/java/org/onosproject/acl/AclWebResourceTest.java b/apps/acl/src/test/java/org/onosproject/acl/AclWebResourceTest.java
index 16b4330..e657db9 100644
--- a/apps/acl/src/test/java/org/onosproject/acl/AclWebResourceTest.java
+++ b/apps/acl/src/test/java/org/onosproject/acl/AclWebResourceTest.java
@@ -39,10 +39,7 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
-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.containsString;
import static org.junit.Assert.assertThat;
diff --git a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java
index 1ce3e6c..4d0fb65 100644
--- a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java
+++ b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java
@@ -15,8 +15,11 @@
*/
package org.onosproject.net.optical.intent.impl.compiler;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
import org.easymock.EasyMock;
-import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -25,13 +28,12 @@
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
-import org.onosproject.core.IdGenerator;
import org.onosproject.net.AbstractProjectableModel;
import org.onosproject.net.Annotations;
import org.onosproject.net.ChannelSpacing;
-import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.CltSignalType;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultDevice;
import org.onosproject.net.DefaultPort;
import org.onosproject.net.Device;
@@ -43,28 +45,6 @@
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.TributarySlot;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.flow.criteria.Criteria;
-import org.onosproject.net.flow.instructions.Instructions;
-import org.onosproject.net.intent.FlowRuleIntent;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.IntentId;
-import org.onosproject.net.intent.IntentServiceAdapter;
-import org.onosproject.net.intent.Key;
-import org.onosproject.net.intent.MockIdGenerator;
-import org.onosproject.net.intent.OpticalCircuitIntent;
-import org.onosproject.net.optical.OchPort;
-import org.onosproject.net.optical.OduCltPort;
-import org.onosproject.net.optical.impl.DefaultOchPort;
-import org.onosproject.net.optical.impl.DefaultOduCltPort;
-import org.onosproject.net.provider.ProviderId;
-import org.onosproject.net.resource.MockResourceService;
-import org.onosproject.net.intent.IntentSetMultimap;
import org.onosproject.net.behaviour.TributarySlotQuery;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.driver.Behaviour;
@@ -75,11 +55,28 @@
import org.onosproject.net.driver.DriverServiceAdapter;
import org.onosproject.net.driver.TestBehaviourImpl;
import org.onosproject.net.driver.TestBehaviourTwoImpl;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Sets;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.flow.criteria.Criteria;
+import org.onosproject.net.flow.instructions.Instructions;
+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.IntentId;
+import org.onosproject.net.intent.IntentServiceAdapter;
+import org.onosproject.net.intent.IntentSetMultimap;
+import org.onosproject.net.intent.Key;
+import org.onosproject.net.intent.OpticalCircuitIntent;
+import org.onosproject.net.optical.OchPort;
+import org.onosproject.net.optical.OduCltPort;
+import org.onosproject.net.optical.impl.DefaultOchPort;
+import org.onosproject.net.optical.impl.DefaultOduCltPort;
+import org.onosproject.net.provider.ProviderId;
+import org.onosproject.net.resource.MockResourceService;
import java.util.ArrayList;
import java.util.Collection;
@@ -89,23 +86,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.expectLastCall;
-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.*;
import static org.junit.Assert.assertEquals;
-import static org.onosproject.net.AnnotationKeys.STATIC_PORT;
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
+import static org.onosproject.net.AnnotationKeys.STATIC_PORT;
import static org.onosproject.net.Device.Type.ROADM;
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.net.NetTestTools.APP_ID;
-public class OpticalCircuitIntentCompilerTest {
+public class OpticalCircuitIntentCompilerTest extends AbstractIntentTest {
private static final String DEV1 = "of:1";
private static final String DEV2 = "of:2";
@@ -117,7 +108,6 @@
private CoreService coreService;
private IntentExtensionService intentExtensionService;
- private final IdGenerator idGenerator = new MockIdGenerator();
private OpticalCircuitIntentCompiler sut;
private final ApplicationId appId = new TestApplicationId("test");
@@ -377,8 +367,7 @@
sut.intentService = new TestIntentService();
sut.intentSetMultimap = new MockIntentSetMultimap();
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
intentExtensionService = createMock(IntentExtensionService.class);
intentExtensionService.registerCompiler(OpticalCircuitIntent.class, sut);
@@ -400,11 +389,6 @@
}
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
/**
* Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
* Compile two ODUCLT ports (with CLT_1GBE), over OCH ports (with ODU2):
diff --git a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompilerTest.java b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompilerTest.java
index fd3d0ae..4992b1a 100644
--- a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompilerTest.java
+++ b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompilerTest.java
@@ -15,19 +15,19 @@
*/
package org.onosproject.net.optical.intent.impl.compiler;
-import org.junit.After;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Sets;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.ChassisId;
import org.onosproject.TestApplicationId;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
-import org.onosproject.core.IdGenerator;
import org.onosproject.net.AbstractProjectableModel;
import org.onosproject.net.Annotations;
-import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.CltSignalType;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultDevice;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.DefaultPath;
@@ -43,6 +43,9 @@
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.TributarySlot;
+import org.onosproject.net.device.DeviceServiceAdapter;
+import org.onosproject.net.driver.DriverService;
+import org.onosproject.net.driver.DriverServiceAdapter;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.FlowRule;
@@ -50,11 +53,11 @@
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.instructions.Instructions;
+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.Key;
-import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.OpticalOduIntent;
import org.onosproject.net.optical.OduCltPort;
import org.onosproject.net.optical.OtuPort;
@@ -65,12 +68,6 @@
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyServiceAdapter;
-import org.onosproject.net.device.DeviceServiceAdapter;
-import org.onosproject.net.driver.DriverService;
-import org.onosproject.net.driver.DriverServiceAdapter;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Sets;
import java.util.Arrays;
import java.util.Collection;
@@ -80,23 +77,19 @@
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.*;
import static org.junit.Assert.assertEquals;
-import static org.onosproject.net.AnnotationKeys.STATIC_PORT;
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
+import static org.onosproject.net.AnnotationKeys.STATIC_PORT;
import static org.onosproject.net.Device.Type.OTN;
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.net.Link.Type.OPTICAL;
import static org.onosproject.net.NetTestTools.APP_ID;
import static org.onosproject.net.NetTestTools.PID;
-public class OpticalOduIntentCompilerTest {
+public class OpticalOduIntentCompilerTest extends AbstractIntentTest {
private static final String DEV1 = "of:1";
private static final String DEV2 = "of:2";
@@ -109,7 +102,6 @@
private CoreService coreService;
private IntentExtensionService intentExtensionService;
- private final IdGenerator idGenerator = new MockIdGenerator();
private OpticalOduIntentCompiler sut;
private final ApplicationId appId = new TestApplicationId("test");
@@ -274,8 +266,7 @@
sut.resourceService = new MockResourceService();
sut.topologyService = new MockTopologyService();
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
intentExtensionService = createMock(IntentExtensionService.class);
intentExtensionService.registerCompiler(OpticalOduIntent.class, sut);
@@ -285,11 +276,6 @@
replay(coreService, intentExtensionService);
}
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
/**
* Tests compile of OpticalOduIntent with allocation of TributarySlots.
* Compile two ODUCLT ports (with CLT_1GBE), over OTU ports (with OTU2):
diff --git a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompilerTest.java b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompilerTest.java
index 66e5c07..072592d 100644
--- a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompilerTest.java
+++ b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompilerTest.java
@@ -15,23 +15,21 @@
*/
package org.onosproject.net.optical.intent.impl.compiler;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
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;
import org.onosproject.net.Link;
import org.onosproject.net.OchSignalType;
import org.onosproject.net.flow.FlowRule;
+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.OpticalPathIntent;
import java.util.Arrays;
@@ -40,24 +38,17 @@
import java.util.List;
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.*;
import static org.junit.Assert.assertEquals;
import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.NetTestTools.PID;
-import static org.onosproject.net.NetTestTools.connectPoint;
-import static org.onosproject.net.NetTestTools.createLambda;
+import static org.onosproject.net.NetTestTools.*;
-public class OpticalPathIntentCompilerTest {
+public class OpticalPathIntentCompilerTest extends AbstractIntentTest {
private CoreService coreService;
private IntentExtensionService intentExtensionService;
- private final IdGenerator idGenerator = new MockIdGenerator();
private OpticalPathIntentCompiler sut;
private final ApplicationId appId = new TestApplicationId("test");
@@ -81,8 +72,7 @@
.andReturn(appId);
sut.coreService = coreService;
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ super.setUp();
intent = OpticalPathIntent.builder()
.appId(appId)
@@ -100,11 +90,6 @@
replay(coreService, intentExtensionService);
}
- @After
- public void tearDown() {
- Intent.unbindIdGenerator(idGenerator);
- }
-
@Test
public void testCompiler() {
sut.activate();
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java
index 9206d45..77ec36a 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java
+++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java
@@ -31,6 +31,7 @@
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceListener;
import org.onosproject.incubator.net.intf.InterfaceService;
+import org.onosproject.intentsync.IntentSynchronizationService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.EncapsulationType;
@@ -46,7 +47,6 @@
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.PointToPointIntent;
-import org.onosproject.intentsync.IntentSynchronizationService;
import org.onosproject.routing.config.BgpConfig;
import org.onosproject.sdnip.config.SdnIpConfig;
@@ -58,13 +58,7 @@
import java.util.Optional;
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.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reset;
-import static org.easymock.EasyMock.verify;
+import static org.easymock.EasyMock.*;
import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId;
/**
@@ -119,7 +113,7 @@
private static final VlanId VLAN30 = VlanId.vlanId(Short.valueOf("30"));
@Before
- public void setUp() throws Exception {
+ public void setUp() {
super.setUp();
interfaceService = createMock(InterfaceService.class);
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibTest.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibTest.java
index 4d04b82..f9e72ab 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibTest.java
+++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibTest.java
@@ -42,6 +42,7 @@
import org.onosproject.incubator.net.routing.RouteEvent;
import org.onosproject.incubator.net.routing.RouteListener;
import org.onosproject.incubator.net.routing.RouteServiceAdapter;
+import org.onosproject.intentsync.IntentSynchronizationService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.FilteredConnectPoint;
@@ -57,7 +58,6 @@
import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
-import org.onosproject.intentsync.IntentSynchronizationService;
import org.onosproject.sdnip.config.SdnIpConfig;
import java.util.Collections;
@@ -125,7 +125,7 @@
private InterfaceListener interfaceListener;
@Before
- public void setUp() throws Exception {
+ public void setUp() {
super.setUp();
interfaceService = createMock(InterfaceService.class);
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();
}
/**
diff --git a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockCoreService.java b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockCoreService.java
index d63c5e6..cf854b4 100644
--- a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockCoreService.java
+++ b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockCoreService.java
@@ -15,9 +15,6 @@
*/
package org.onosproject.drivers.netconf;
-import java.util.HashSet;
-import java.util.Set;
-
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.core.DefaultApplicationId;
@@ -25,6 +22,9 @@
import org.onosproject.core.Version;
import org.onosproject.net.intent.MockIdGenerator;
+import java.util.HashSet;
+import java.util.Set;
+
public class MockCoreService implements CoreService {
private HashSet<ApplicationId> appIds;
@@ -35,7 +35,6 @@
appIds = new HashSet<ApplicationId>();
appIds.add(new DefaultApplicationId(101, "org.onosproject.drivers.netconf"));
version = Version.version(1, 1, "1", "1");
- idGenerator = new MockIdGenerator();
}
@Override
@@ -83,7 +82,7 @@
@Override
public IdGenerator getIdGenerator(String topic) {
- return idGenerator;
+ return MockIdGenerator.INSTANCE;
}
}
diff --git a/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkIntentManagerTest.java b/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkIntentManagerTest.java
index 55232d1..4b7cf84 100644
--- a/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkIntentManagerTest.java
+++ b/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkIntentManagerTest.java
@@ -55,14 +55,14 @@
import org.onosproject.net.intent.IntentEvent;
import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.IntentListener;
-import org.onosproject.net.intent.WorkPartitionService;
-import org.onosproject.net.intent.WorkPartitionServiceAdapter;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.IntentTestsMocks;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.TestableIntentService;
+import org.onosproject.net.intent.WorkPartitionService;
+import org.onosproject.net.intent.WorkPartitionServiceAdapter;
import org.onosproject.net.intent.constraint.EncapsulationConstraint;
import org.onosproject.store.service.TestStorageService;
@@ -108,7 +108,6 @@
private WorkPartitionService workPartitionService;
private ServiceDirectory testDirectory;
private TestListener listener = new TestListener();
- private IdGenerator idGenerator = new MockIdGenerator();
private static final int MAX_WAIT_TIME = 5;
private static final int MAX_PERMITS = 1;
private static Semaphore created;
@@ -121,8 +120,7 @@
coreService = new VirtualNetworkIntentManagerTest.TestCoreService();
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ MockIdGenerator.cleanBind();
TestUtils.setField(virtualNetworkManagerStore, "coreService", coreService);
TestUtils.setField(virtualNetworkManagerStore, "storageService", new TestStorageService());
@@ -158,7 +156,7 @@
virtualNetworkManagerStore.deactivate();
manager.deactivate();
NetTestTools.injectEventDispatcher(manager, null);
- Intent.unbindIdGenerator(idGenerator);
+ MockIdGenerator.unbind();
intentService.removeListener(listener);
created = null;
withdrawn = null;
diff --git a/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManagerTest.java b/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManagerTest.java
index 202046e..765b4cb 100644
--- a/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManagerTest.java
+++ b/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManagerTest.java
@@ -70,7 +70,6 @@
import org.onosproject.net.group.GroupService;
import org.onosproject.net.host.HostService;
import org.onosproject.net.intent.FakeIntentManager;
-import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.Key;
@@ -83,11 +82,11 @@
import org.onosproject.net.topology.TopologyService;
import org.onosproject.store.service.TestStorageService;
-import java.util.Collection;
-import java.util.List;
import java.util.ArrayList;
-import java.util.Set;
+import java.util.Collection;
import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import static org.junit.Assert.*;
@@ -107,7 +106,6 @@
private TestListener listener = new TestListener();
private TestableIntentService intentService = new FakeIntentManager();
private TopologyService topologyService;
- private IdGenerator idGenerator = new MockIdGenerator();
private ConnectPoint cp6;
private ConnectPoint cp7;
@@ -117,8 +115,7 @@
@Before
public void setUp() throws Exception {
virtualNetworkManagerStore = new DistributedVirtualNetworkStore();
- Intent.unbindIdGenerator(idGenerator);
- Intent.bindIdGenerator(idGenerator);
+ MockIdGenerator.cleanBind();
coreService = new TestCoreService();
TestUtils.setField(virtualNetworkManagerStore, "coreService", coreService);
@@ -145,7 +142,7 @@
manager.removeListener(listener);
manager.deactivate();
NetTestTools.injectEventDispatcher(manager, null);
- Intent.unbindIdGenerator(idGenerator);
+ MockIdGenerator.cleanBind();
}
/**
diff --git a/utils/junit/src/main/java/org/onlab/junit/TestUtils.java b/utils/junit/src/main/java/org/onlab/junit/TestUtils.java
index 7b16d65..0707561 100644
--- a/utils/junit/src/main/java/org/onlab/junit/TestUtils.java
+++ b/utils/junit/src/main/java/org/onlab/junit/TestUtils.java
@@ -201,7 +201,7 @@
* through reflection. The original exception can be found by examining the
* cause.
*/
- public static class TestUtilsException extends Exception {
+ public static class TestUtilsException extends RuntimeException {
private static final long serialVersionUID = 1L;
diff --git a/web/api/src/test/java/org/onosproject/rest/resources/IntentsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/resources/IntentsResourceTest.java
index efabf66f..e041962 100644
--- a/web/api/src/test/java/org/onosproject/rest/resources/IntentsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/resources/IntentsResourceTest.java
@@ -35,7 +35,6 @@
import org.onosproject.core.CoreService;
import org.onosproject.core.DefaultApplicationId;
import org.onosproject.core.GroupId;
-import org.onosproject.core.IdGenerator;
import org.onosproject.net.DeviceId;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.flow.DefaultTrafficSelector;
@@ -56,6 +55,7 @@
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.Key;
+import org.onosproject.net.intent.MockIdGenerator;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.client.Entity;
@@ -76,7 +76,6 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.onosproject.net.intent.IntentTestsMocks.MockIntent;
-import static org.onosproject.net.intent.MockIdGenerator.bindNewGenerator;
/**
* Unit tests for Intents REST APIs.
@@ -101,7 +100,6 @@
final HashSet<Intent> intents = new HashSet<>();
final List<org.onosproject.net.intent.Intent> installableIntents = new ArrayList<>();
private static final ApplicationId APP_ID = new DefaultApplicationId(1, "test");
- private IdGenerator mockGenerator;
final DeviceId deviceId1 = DeviceId.deviceId("1");
@@ -698,7 +696,7 @@
BaseResource.setServiceDirectory(testDirectory);
- bindNewGenerator();
+ MockIdGenerator.cleanBind();
}
/**
@@ -706,6 +704,7 @@
*/
@After
public void tearDownTest() {
+ MockIdGenerator.unbind();
verify(mockIntentService);
}