Allow to specify appId through FlowObjective REST API
Change-Id: Iadff74d379e1d5ec4f6e8ff2cda2ad96892d2cc1
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/FilteringObjectiveCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/FilteringObjectiveCodecTest.java
index 87918e4..7718c81 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/FilteringObjectiveCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/FilteringObjectiveCodecTest.java
@@ -21,7 +21,9 @@
import org.junit.Test;
import org.onlab.packet.VlanId;
import org.onosproject.codec.JsonCodec;
+import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
+import org.onosproject.core.DefaultApplicationId;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flowobjective.DefaultFilteringObjective;
@@ -47,6 +49,7 @@
MockCodecContext context;
JsonCodec<FilteringObjective> filteringObjectiveCodec;
final CoreService mockCoreService = createMock(CoreService.class);
+ static final String SAMPLE_APP_ID = "org.onosproject.sample";
/**
* Sets up for each test.
@@ -58,9 +61,6 @@
filteringObjectiveCodec = context.codec(FilteringObjective.class);
assertThat(filteringObjectiveCodec, notNullValue());
- expect(mockCoreService.registerApplication(FilteringObjectiveCodec.REST_APP_ID))
- .andReturn(APP_ID).anyTimes();
- replay(mockCoreService);
context.registerService(CoreService.class, mockCoreService);
}
@@ -93,6 +93,12 @@
*/
@Test
public void testFilteringObjectiveDecode() throws IOException {
+
+ ApplicationId appId = new DefaultApplicationId(0, SAMPLE_APP_ID);
+
+ expect(mockCoreService.registerApplication(SAMPLE_APP_ID)).andReturn(appId).anyTimes();
+ replay(mockCoreService);
+
FilteringObjective filteringObjective = getFilteringObjective("FilteringObjective.json");
assertThat(filteringObjective.type(), is(FilteringObjective.Type.PERMIT));
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/ForwardingObjectiveCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/ForwardingObjectiveCodecTest.java
index 9b4e2b1..b6cc7a6 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/ForwardingObjectiveCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/ForwardingObjectiveCodecTest.java
@@ -21,7 +21,9 @@
import org.junit.Test;
import org.onlab.packet.VlanId;
import org.onosproject.codec.JsonCodec;
+import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
+import org.onosproject.core.DefaultApplicationId;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.criteria.Criteria;
@@ -32,9 +34,7 @@
import java.io.IOException;
import java.io.InputStream;
-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.is;
import static org.hamcrest.Matchers.notNullValue;
@@ -49,6 +49,7 @@
MockCodecContext context;
JsonCodec<ForwardingObjective> forwardingObjectiveCodec;
final CoreService mockCoreService = createMock(CoreService.class);
+ static final String SAMPLE_APP_ID = "org.onosproject.sample";
/**
* Sets up for each test.
@@ -60,9 +61,6 @@
forwardingObjectiveCodec = context.codec(ForwardingObjective.class);
assertThat(forwardingObjectiveCodec, notNullValue());
- expect(mockCoreService.registerApplication(ForwardingObjectiveCodec.REST_APP_ID))
- .andReturn(APP_ID).anyTimes();
- replay(mockCoreService);
context.registerService(CoreService.class, mockCoreService);
}
@@ -97,6 +95,12 @@
*/
@Test
public void testForwardingObjectiveDecode() throws IOException {
+
+ ApplicationId appId = new DefaultApplicationId(0, SAMPLE_APP_ID);
+
+ expect(mockCoreService.registerApplication(SAMPLE_APP_ID)).andReturn(appId).anyTimes();
+ replay(mockCoreService);
+
ForwardingObjective forwardingObjective = getForwardingObjective("ForwardingObjective.json");
assertThat(forwardingObjective.flag(), is(ForwardingObjective.Flag.SPECIFIC));
@@ -104,6 +108,7 @@
assertThat(forwardingObjective.timeout(), is(1));
assertThat(forwardingObjective.op(), is(ForwardingObjective.Operation.ADD));
assertThat(forwardingObjective.permanent(), is(false));
+ assertThat(forwardingObjective.appId().name(), is(SAMPLE_APP_ID));
}
/**
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/NextObjectiveCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/NextObjectiveCodecTest.java
index c0fc138..04746db 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/NextObjectiveCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/NextObjectiveCodecTest.java
@@ -20,7 +20,9 @@
import org.junit.Before;
import org.junit.Test;
import org.onosproject.codec.JsonCodec;
+import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
+import org.onosproject.core.DefaultApplicationId;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flowobjective.DefaultNextObjective;
@@ -46,6 +48,7 @@
MockCodecContext context;
JsonCodec<NextObjective> nextObjectiveCodec;
final CoreService mockCoreService = createMock(CoreService.class);
+ static final String SAMPLE_APP_ID = "org.onosproject.sample";
/**
* Sets up for each test.
@@ -57,9 +60,6 @@
nextObjectiveCodec = context.codec(NextObjective.class);
assertThat(nextObjectiveCodec, notNullValue());
- expect(mockCoreService.registerApplication(NextObjectiveCodec.REST_APP_ID))
- .andReturn(APP_ID).anyTimes();
- replay(mockCoreService);
context.registerService(CoreService.class, mockCoreService);
}
@@ -89,6 +89,12 @@
*/
@Test
public void testNextObjectiveDecode() throws IOException {
+
+ ApplicationId appId = new DefaultApplicationId(0, SAMPLE_APP_ID);
+
+ expect(mockCoreService.registerApplication(SAMPLE_APP_ID)).andReturn(appId).anyTimes();
+ replay(mockCoreService);
+
NextObjective nextObjective = getNextObjective("NextObjective.json");
assertThat(nextObjective.type(), is(NextObjective.Type.FAILOVER));