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/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java
index 6db1a35..2149b26 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java
@@ -15,6 +15,8 @@
*/
package org.onosproject.net.intent;
+import java.util.Arrays;
+
import org.junit.Test;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultLink;
@@ -25,8 +27,6 @@
import org.onosproject.net.PortNumber;
import org.onosproject.net.provider.ProviderId;
-import java.util.Arrays;
-
import static org.junit.Assert.assertEquals;
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.net.Link.Type.DIRECT;
@@ -65,12 +65,22 @@
@Override
protected PathIntent createOne() {
- return new PathIntent(APPID, MATCH, NOP, PATH1);
+ return PathIntent.builder()
+ .appId(APPID)
+ .selector(MATCH)
+ .treatment(NOP)
+ .path(PATH1)
+ .build();
}
@Override
protected PathIntent createAnother() {
- return new PathIntent(APPID, MATCH, NOP, PATH2);
+ return PathIntent.builder()
+ .appId(APPID)
+ .selector(MATCH)
+ .treatment(NOP)
+ .path(PATH2)
+ .build();
}
/**
@@ -79,7 +89,12 @@
*/
@Test(expected = IllegalArgumentException.class)
public void testRaiseExceptionWhenSameDevices() {
- new PathIntent(APPID, MATCH, NOP, new DefaultPath(provider1, Arrays.asList(link1), cost));
+ PathIntent.builder()
+ .appId(APPID)
+ .selector(MATCH)
+ .treatment(NOP)
+ .path(new DefaultPath(provider1, Arrays.asList(link1), cost))
+ .build();
}
/**
@@ -88,7 +103,12 @@
*/
@Test(expected = IllegalArgumentException.class)
public void testRaiseExceptionWhenDifferentDevice() {
- new PathIntent(APPID, MATCH, NOP, new DefaultPath(provider1, Arrays.asList(link1, link2), cost));
+ PathIntent.builder()
+ .appId(APPID)
+ .selector(MATCH)
+ .treatment(NOP)
+ .path(new DefaultPath(provider1, Arrays.asList(link1, link2), cost))
+ .build();
}
}