Refactor connectivity intent creation to use builders
- Each connectivity intent now has only one constructor
- Intent constructors are now private for leaf classes and
protected for classes that can be derived from
- Each intent class has a Builder class that accumulates
parameters for intent creation
- Each intent class has a public static builder() method
to create a builder
- Each Builder class has a build() method to create the
intent from the accumulated parameters
- Added keys to a few intent types that were missing them
- Tightened up usage of checkNotNull(), taking advantage of
the return value to save some lines of code
- Modified callers to use the builders instead of directly
calling the constructors
Change-Id: I713185d5ecbadbf51f87ef7f68fec41102106c78
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 b154d22..be9ab66 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
@@ -90,8 +90,13 @@
* @return HostToHostIntent for the two hosts
*/
private HostToHostIntent makeIntent(String oneIdString, String twoIdString) {
- return new HostToHostIntent(APPID, hid(oneIdString), hid(twoIdString),
- selector, treatment);
+ return HostToHostIntent.builder()
+ .appId(APPID)
+ .one(hid(oneIdString))
+ .two(hid(twoIdString))
+ .selector(selector)
+ .treatment(treatment)
+ .build();
}
/**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java
index 4890e03..76b26f4 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompilerTest.java
@@ -55,11 +55,14 @@
private MplsIntent makeIntent(String ingressIdString, Optional<MplsLabel> ingressLabel,
String egressIdString, Optional<MplsLabel> egressLabel) {
- return new MplsIntent(APPID, selector, treatment,
- connectPoint(ingressIdString, 1),
- ingressLabel,
- connectPoint(egressIdString, 1),
- egressLabel);
+ return MplsIntent.builder()
+ .appId(APPID)
+ .selector(selector)
+ .treatment(treatment)
+ .ingressPoint(connectPoint(ingressIdString, 1))
+ .ingressLabel(ingressLabel)
+ .egressPoint(connectPoint(egressIdString, 1))
+ .egressLabel(egressLabel).build();
}
/**
* Creates a compiler for HostToHost intents.
@@ -157,7 +160,15 @@
public void testSameSwitchDifferentPortsIntentCompilation() {
ConnectPoint src = new ConnectPoint(deviceId("1"), portNumber(1));
ConnectPoint dst = new ConnectPoint(deviceId("1"), portNumber(2));
- MplsIntent intent = new MplsIntent(APP_ID, selector, treatment, src, Optional.empty(), dst, Optional.empty());
+ MplsIntent intent = MplsIntent.builder()
+ .appId(APP_ID)
+ .selector(selector)
+ .treatment(treatment)
+ .ingressPoint(src)
+ .ingressLabel(Optional.empty())
+ .egressPoint(dst)
+ .egressLabel(Optional.empty())
+ .build();
String[] hops = {"1"};
MplsIntentCompiler sut = makeCompiler(hops);
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
index bbc7ad1..eb6be57 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
@@ -104,8 +104,13 @@
ingressPoints.add(connectPoint(ingressId, 1));
}
- return new MultiPointToSinglePointIntent(APPID, selector, treatment,
- ingressPoints, egressPoint);
+ return MultiPointToSinglePointIntent.builder()
+ .appId(APPID)
+ .selector(selector)
+ .treatment(treatment)
+ .ingressPoints(ingressPoints)
+ .egressPoint(egressPoint)
+ .build();
}
/**