[ONOS-2225] Add codecs with unit test for FlowObjective REST API

* Add codec for FilteringObjective
* Add codec for ForwardingObjective
* Add codec for NextObjective

Change-Id: I715aa7f1969697468692459052fd27cc65ca2363
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
new file mode 100644
index 0000000..c826d37
--- /dev/null
+++ b/core/common/src/test/java/org/onosproject/codec/impl/FilteringObjectiveCodecTest.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.codec.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.VlanId;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.flow.criteria.Criteria;
+import org.onosproject.net.flow.criteria.Criterion;
+import org.onosproject.net.flowobjective.DefaultFilteringObjective;
+import org.onosproject.net.flowobjective.FilteringObjective;
+
+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.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.onosproject.codec.impl.FilteringObjectiveJsonMatcher.matchesFilteringObjective;
+import static org.onosproject.net.NetTestTools.APP_ID;
+
+/**
+ * Unit tests for FilteringObjective Codec.
+ */
+public class FilteringObjectiveCodecTest {
+
+    MockCodecContext context;
+    JsonCodec<FilteringObjective> filteringObjectiveCodec;
+    final CoreService mockCoreService = createMock(CoreService.class);
+
+    /**
+     * Sets up for each test.
+     * Creates a context and fetches the FilteringObjective codec.
+     */
+    @Before
+    public void setUp() {
+        context = new MockCodecContext();
+        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);
+    }
+
+    /**
+     * Tests encoding of a FilteringObjective object.
+     */
+    @Test
+    public void testFilteringObjectiveEncode() {
+
+        Criterion condition1 = Criteria.matchVlanId(VlanId.ANY);
+        Criterion condition2 = Criteria.matchEthType((short) 0x8844);
+
+        FilteringObjective filteringObj = DefaultFilteringObjective.builder()
+                .makePermanent()
+                .permit()
+                .fromApp(APP_ID)
+                .withPriority(60)
+                .addCondition(condition1)
+                .addCondition(condition2)
+                .add();
+
+        // TODO: need to add test case for TrafficTreatment (META in filteringObj)
+
+        ObjectNode filteringObjJson = filteringObjectiveCodec.encode(filteringObj, context);
+        assertThat(filteringObjJson, matchesFilteringObjective(filteringObj));
+    }
+
+    /**
+     * Test decoding of a FilteringObjective object.
+     */
+    @Test
+    public void testFilteringObjectiveDecode() throws IOException {
+        FilteringObjective filteringObjective = getFilteringObjective("FilteringObjective.json");
+
+        assertThat(filteringObjective.type(), is(FilteringObjective.Type.PERMIT));
+        assertThat(filteringObjective.priority(), is(60));
+        assertThat(filteringObjective.timeout(), is(1));
+        assertThat(filteringObjective.op(), is(FilteringObjective.Operation.ADD));
+        assertThat(filteringObjective.permanent(), is(false));
+    }
+
+    /**
+     * Reads in a filteringObjective from the given resource and decodes it.
+     *
+     * @param resourceName resource to use to read the JSON for the rule
+     * @return decoded filteringObjective
+     * @throws IOException if processing the resource fails
+     */
+    private FilteringObjective getFilteringObjective(String resourceName) throws IOException {
+        InputStream jsonStream = FilteringObjectiveCodecTest.class.getResourceAsStream(resourceName);
+        JsonNode json = context.mapper().readTree(jsonStream);
+        assertThat(json, notNullValue());
+        FilteringObjective filteringObjective = filteringObjectiveCodec.decode((ObjectNode) json, context);
+        assertThat(filteringObjective, notNullValue());
+        return filteringObjective;
+    }
+}
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/FilteringObjectiveJsonMatcher.java b/core/common/src/test/java/org/onosproject/codec/impl/FilteringObjectiveJsonMatcher.java
new file mode 100644
index 0000000..99d3bd9
--- /dev/null
+++ b/core/common/src/test/java/org/onosproject/codec/impl/FilteringObjectiveJsonMatcher.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.codec.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.onosproject.net.flow.criteria.Criterion;
+import org.onosproject.net.flowobjective.FilteringObjective;
+
+/**
+ * Hamcrest matcher for filteringObjective.
+ */
+public final class FilteringObjectiveJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
+
+    final FilteringObjective filteringObj;
+
+    private FilteringObjectiveJsonMatcher(FilteringObjective filteringObjective) {
+        this.filteringObj = filteringObjective;
+    }
+
+    @Override
+    protected boolean matchesSafely(JsonNode jsonFilteringObj, Description description) {
+
+        ObjectiveJsonMatcher.matchesObjective(filteringObj).matchesSafely(jsonFilteringObj);
+
+        // check id
+        int jsonId = jsonFilteringObj.get("id").asInt();
+        int id = filteringObj.id();
+        if (jsonId != id) {
+            description.appendText("id was " + jsonId);
+            return false;
+        }
+
+        // check type
+        String jsonType = jsonFilteringObj.get("type").asText();
+        String type = filteringObj.type().toString();
+        if (!jsonType.equals(type)) {
+            description.appendText("type was " + jsonType);
+            return false;
+        }
+
+        // check size of condition array
+        JsonNode jsonConditions = jsonFilteringObj.get("conditions");
+        if (jsonConditions.size() != filteringObj.conditions().size()) {
+            description.appendText("conditions size was " + jsonConditions.size());
+            return false;
+        }
+
+        // check conditions
+        for (Criterion c : filteringObj.conditions()) {
+            boolean conditionFound = false;
+            for (int cIndex = 0; cIndex < jsonConditions.size(); cIndex++) {
+                CriterionJsonMatcher criterionMatcher = CriterionJsonMatcher.matchesCriterion(c);
+                if (criterionMatcher.matches(jsonConditions.get(cIndex))) {
+                    conditionFound = true;
+                    break;
+                }
+            }
+            if (!conditionFound) {
+                description.appendText("condition not found " + c.toString());
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public void describeTo(Description description) {
+        description.appendText(filteringObj.toString());
+    }
+
+    /**
+     * Factory to allocate a filteringObjective matcher.
+     *
+     * @param filteringObj filteringObjective object we are looking for
+     * @return matcher
+     */
+    public static FilteringObjectiveJsonMatcher matchesFilteringObjective(FilteringObjective filteringObj) {
+        return new FilteringObjectiveJsonMatcher(filteringObj);
+    }
+}
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
new file mode 100644
index 0000000..7b1354e
--- /dev/null
+++ b/core/common/src/test/java/org/onosproject/codec/impl/ForwardingObjectiveCodecTest.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.codec.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.VlanId;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.criteria.Criteria;
+import org.onosproject.net.flow.criteria.Criterion;
+import org.onosproject.net.flowobjective.DefaultForwardingObjective;
+import org.onosproject.net.flowobjective.ForwardingObjective;
+
+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.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.onosproject.codec.impl.ForwardingObjectiveJsonMatcher.matchesForwardingObjective;
+import static org.onosproject.net.NetTestTools.APP_ID;
+
+/**
+ * Unit tests for ForwardingObjective Codec.
+ */
+public class ForwardingObjectiveCodecTest {
+
+    MockCodecContext context;
+    JsonCodec<ForwardingObjective> forwardingObjectiveCodec;
+    final CoreService mockCoreService = createMock(CoreService.class);
+
+    /**
+     * Sets up for each test.
+     * Creates a context and fetches the ForwardingObjective codec.
+     */
+    @Before
+    public void setUp() {
+        context = new MockCodecContext();
+        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);
+    }
+
+    /**
+     * Tests encoding of a ForwardingObjective object.
+     */
+    @Test
+    public void testForwardingObjectiveEncode() {
+
+        Criterion criterion1 = Criteria.matchVlanId(VlanId.ANY);
+        Criterion criterion2 = Criteria.matchEthType((short) 0x8844);
+        TrafficSelector selector = DefaultTrafficSelector.builder()
+                .add(criterion1)
+                .add(criterion2)
+                .build();
+
+        ForwardingObjective forwardingObj = DefaultForwardingObjective.builder()
+                .makePermanent()
+                .fromApp(APP_ID)
+                .withPriority(60)
+                .withFlag(ForwardingObjective.Flag.SPECIFIC)
+                .nextStep(1)
+                .withSelector(selector)
+                .add();
+
+        ObjectNode forwardingObjJson = forwardingObjectiveCodec.encode(forwardingObj, context);
+        assertThat(forwardingObjJson, matchesForwardingObjective(forwardingObj));
+    }
+
+    /**
+     * Test decoding of a ForwardingObjective object.
+     */
+    @Test
+    public void testForwardingObjectiveDecode() throws IOException {
+        ForwardingObjective forwardingObjective = getForwardingObjective("ForwardingObjective.json");
+
+        assertThat(forwardingObjective.flag(), is(ForwardingObjective.Flag.SPECIFIC));
+        assertThat(forwardingObjective.priority(), is(60));
+        assertThat(forwardingObjective.timeout(), is(1));
+        assertThat(forwardingObjective.op(), is(ForwardingObjective.Operation.ADD));
+        assertThat(forwardingObjective.permanent(), is(false));
+    }
+
+    /**
+     * Reads in a forwardingObjectiveJsonCodec from the given resource and decodes it.
+     *
+     * @param resourceName resource to use to read the JSON for the rule
+     * @return decoded forwardingObjectiveJsonCodec
+     * @throws IOException if processing the resource fails
+     */
+    private ForwardingObjective getForwardingObjective(String resourceName) throws IOException {
+        InputStream jsonStream = ForwardingObjectiveCodecTest.class.getResourceAsStream(resourceName);
+        JsonNode json = context.mapper().readTree(jsonStream);
+        assertThat(json, notNullValue());
+        ForwardingObjective forwardingObjective = forwardingObjectiveCodec.decode((ObjectNode) json, context);
+        assertThat(forwardingObjective, notNullValue());
+        return forwardingObjective;
+    }
+}
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/ForwardingObjectiveJsonMatcher.java b/core/common/src/test/java/org/onosproject/codec/impl/ForwardingObjectiveJsonMatcher.java
new file mode 100644
index 0000000..9c9054b
--- /dev/null
+++ b/core/common/src/test/java/org/onosproject/codec/impl/ForwardingObjectiveJsonMatcher.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.codec.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.onosproject.net.flowobjective.ForwardingObjective;
+
+/**
+ * Hamcrest matcher for forwardingObjective.
+ */
+public final class ForwardingObjectiveJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
+
+    final ForwardingObjective forwardingObjective;
+
+    private ForwardingObjectiveJsonMatcher(ForwardingObjective forwardingObjective) {
+        this.forwardingObjective = forwardingObjective;
+    }
+
+    @Override
+    protected boolean matchesSafely(JsonNode jsonForwardingObj, Description description) {
+
+        ObjectiveJsonMatcher.matchesObjective(forwardingObjective).matchesSafely(jsonForwardingObj);
+
+        // check id
+        int jsonId = jsonForwardingObj.get("id").asInt();
+        int id = forwardingObjective.id();
+        if (jsonId != id) {
+            description.appendText("id was " + jsonId);
+            return false;
+        }
+
+        // check nextId
+        int jsonNextId = jsonForwardingObj.get("nextId").asInt();
+        int nextId = forwardingObjective.nextId();
+        if (jsonNextId != nextId) {
+            description.appendText("nextId was " + jsonNextId);
+            return false;
+        }
+
+        // check flag
+        String jsonFlag = jsonForwardingObj.get("flag").asText();
+        String flag = forwardingObjective.flag().toString();
+        if (!jsonFlag.equals(flag)) {
+            description.appendText("flag was " + jsonFlag);
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public void describeTo(Description description) {
+        description.appendText(forwardingObjective.toString());
+    }
+
+    /**
+     * Factory to allocate a forwardingObjective matcher.
+     *
+     * @param forwardingObjective forwardingObjective object we are looking for
+     * @return matcher
+     */
+    public static ForwardingObjectiveJsonMatcher matchesForwardingObjective(ForwardingObjective forwardingObjective) {
+        return new ForwardingObjectiveJsonMatcher(forwardingObjective);
+    }
+}
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
new file mode 100644
index 0000000..06c6c9c
--- /dev/null
+++ b/core/common/src/test/java/org/onosproject/codec/impl/NextObjectiveCodecTest.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.codec.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.flowobjective.DefaultNextObjective;
+import org.onosproject.net.flowobjective.NextObjective;
+
+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.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.onosproject.codec.impl.NextObjectiveJsonMatcher.matchesNextObjective;
+import static org.onosproject.net.NetTestTools.APP_ID;
+
+/**
+ * Unit tests for NextObjective Codec.
+ */
+public class NextObjectiveCodecTest {
+
+    MockCodecContext context;
+    JsonCodec<NextObjective> nextObjectiveCodec;
+    final CoreService mockCoreService = createMock(CoreService.class);
+
+    /**
+     * Sets up for each test.
+     * Creates a context and fetches the NextObjective codec.
+     */
+    @Before
+    public void setUp() {
+        context = new MockCodecContext();
+        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);
+    }
+
+    /**
+     * Tests encoding of a NextObjective object.
+     */
+    @Test
+    public void testNextObjectiveEncode() {
+
+        TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
+
+        NextObjective nextObj = DefaultNextObjective.builder()
+                .makePermanent()
+                .withType(NextObjective.Type.HASHED)
+                .fromApp(APP_ID)
+                .withPriority(60)
+                .withId(5)
+                .addTreatment(treatment)
+                .add();
+
+        ObjectNode nextObjJson = nextObjectiveCodec.encode(nextObj, context);
+        assertThat(nextObjJson, matchesNextObjective(nextObj));
+    }
+
+    /**
+     * Test decoding of a NextObjective object.
+     */
+    @Test
+    public void testNextObjectiveDecode() throws IOException {
+        NextObjective nextObjective = getNextObjective("NextObjective.json");
+
+        assertThat(nextObjective.type(), is(NextObjective.Type.FAILOVER));
+        assertThat(nextObjective.op(), is(NextObjective.Operation.ADD));
+    }
+
+    /**
+     * Reads in a nextObjective from the given resource and decodes it.
+     *
+     * @param resourceName resource to use to read the JSON for the rule
+     * @return decoded nextObjective
+     * @throws IOException if processing the resource fails
+     */
+    private NextObjective getNextObjective(String resourceName) throws IOException {
+        InputStream jsonStream = NextObjectiveCodecTest.class.getResourceAsStream(resourceName);
+        JsonNode json = context.mapper().readTree(jsonStream);
+        assertThat(json, notNullValue());
+        NextObjective nextObjective = nextObjectiveCodec.decode((ObjectNode) json, context);
+        assertThat(nextObjective, notNullValue());
+        return nextObjective;
+    }
+}
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/NextObjectiveJsonMatcher.java b/core/common/src/test/java/org/onosproject/codec/impl/NextObjectiveJsonMatcher.java
new file mode 100644
index 0000000..fe63f20
--- /dev/null
+++ b/core/common/src/test/java/org/onosproject/codec/impl/NextObjectiveJsonMatcher.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.codec.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.onosproject.net.flowobjective.NextObjective;
+
+/**
+ * Hamcrest matcher for nextObjective.
+ */
+public final class NextObjectiveJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
+
+    final NextObjective nextObjective;
+
+    private NextObjectiveJsonMatcher(NextObjective nextObjective) {
+        this.nextObjective = nextObjective;
+    }
+
+    @Override
+    protected boolean matchesSafely(JsonNode jsonNextObj, Description description) {
+        ObjectiveJsonMatcher.matchesObjective(nextObjective).matchesSafely(jsonNextObj);
+
+        // check id
+        int jsonId = jsonNextObj.get("id").asInt();
+        int id = nextObjective.id();
+        if (jsonId != id) {
+            description.appendText("id was " + jsonId);
+            return false;
+        }
+
+        // check type
+        String jsonType = jsonNextObj.get("type").asText();
+        String type = nextObjective.type().toString();
+        if (!jsonType.equals(type)) {
+            description.appendText("type was " + jsonType);
+            return false;
+        }
+
+        // check size of treatment array
+        JsonNode jsonTreatments = jsonNextObj.get("treatments");
+        if (jsonTreatments.size() != nextObjective.next().size()) {
+            description.appendText("treatments size was " + jsonTreatments.size());
+            return false;
+        }
+
+        // TODO: need to check the content of treatment collection
+
+        // TODO: need to check the content of selector instance
+
+        return true;
+    }
+
+    @Override
+    public void describeTo(Description description) {
+        description.appendText(nextObjective.toString());
+    }
+
+    /**
+     * Factory to allocate a nextObjective matcher.
+     *
+     * @param nextObjective nextObjective object we are looking for
+     * @return matcher
+     */
+    public static NextObjectiveJsonMatcher matchesNextObjective(NextObjective nextObjective) {
+        return new NextObjectiveJsonMatcher(nextObjective);
+    }
+}
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/ObjectiveJsonMatcher.java b/core/common/src/test/java/org/onosproject/codec/impl/ObjectiveJsonMatcher.java
new file mode 100644
index 0000000..a99d3fb
--- /dev/null
+++ b/core/common/src/test/java/org/onosproject/codec/impl/ObjectiveJsonMatcher.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.codec.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.onosproject.net.flowobjective.Objective;
+
+/**
+ * Hamcrest matcher for instructions.
+ */
+public final class ObjectiveJsonMatcher {
+
+    final Objective objective;
+
+    private ObjectiveJsonMatcher(Objective objective) {
+        this.objective = objective;
+    }
+
+    protected boolean matchesSafely(JsonNode jsonObjective) {
+
+        // check operation
+        String jsonOp = jsonObjective.get("operation").asText();
+        String op = objective.op().toString();
+        if (!jsonOp.equals(op)) {
+            return false;
+        }
+
+        // check permanent
+        boolean jsonPermanent = jsonObjective.get("isPermanent").asBoolean();
+        boolean permanent = objective.permanent();
+        if (jsonPermanent != permanent) {
+            return false;
+        }
+
+        // check priority
+        int jsonPriority = jsonObjective.get("priority").asInt();
+        int priority = objective.priority();
+        if (jsonPriority != priority) {
+            return false;
+        }
+
+        // check timeout
+        int jsonTimeout = jsonObjective.get("timeout").asInt();
+        int timeout = objective.timeout();
+        if (jsonTimeout != timeout) {
+            return false;
+        }
+
+        return true;
+    }
+
+    /**
+     * Factory to allocate a ObjectiveJsonMatcher.
+     *
+     * @param objective objective object we are looking for
+     * @return matcher
+     */
+    public static ObjectiveJsonMatcher matchesObjective(Objective objective) {
+        return new ObjectiveJsonMatcher(objective);
+    }
+}
diff --git a/core/common/src/test/resources/org/onosproject/codec/impl/FilteringObjective.json b/core/common/src/test/resources/org/onosproject/codec/impl/FilteringObjective.json
new file mode 100644
index 0000000..228e7b0
--- /dev/null
+++ b/core/common/src/test/resources/org/onosproject/codec/impl/FilteringObjective.json
@@ -0,0 +1,25 @@
+{
+  "priority": 60,
+  "isPermanent": "false",
+  "timeout": 1,
+  "type": "PERMIT",
+  "operation": "ADD",
+  "conditions": [
+    {
+      "type": "IN_PORT",
+      "port": 23
+    }
+  ],
+  "meta": {
+    "instructions": [
+      {
+        "type": "OUTPUT",
+        "port": -3
+      },
+      {
+        "type": "DROP"
+      }
+    ],
+    "deferred": []
+  }
+}
\ No newline at end of file
diff --git a/core/common/src/test/resources/org/onosproject/codec/impl/ForwardingObjective.json b/core/common/src/test/resources/org/onosproject/codec/impl/ForwardingObjective.json
new file mode 100644
index 0000000..f3f53d4
--- /dev/null
+++ b/core/common/src/test/resources/org/onosproject/codec/impl/ForwardingObjective.json
@@ -0,0 +1,24 @@
+{
+  "priority": 60,
+  "isPermanent": "false",
+  "timeout": 1,
+  "flag": "SPECIFIC",
+  "operation": "ADD",
+  "selector": {
+    "criteria": [
+      {
+        "type": "ETH_TYPE",
+        "ethType": "0x806"
+      }
+    ]
+  },
+  "treatment":
+  {
+    "instructions":
+    [
+      {"type":"OUTPUT","port":-3},
+      {"type":"DROP"}
+    ],
+    "deferred":[]
+  }
+}
\ No newline at end of file
diff --git a/core/common/src/test/resources/org/onosproject/codec/impl/NextObjective.json b/core/common/src/test/resources/org/onosproject/codec/impl/NextObjective.json
new file mode 100644
index 0000000..dad9b03
--- /dev/null
+++ b/core/common/src/test/resources/org/onosproject/codec/impl/NextObjective.json
@@ -0,0 +1,27 @@
+{
+  "id": 1,
+  "type": "FAILOVER",
+  "operation": "ADD",
+  "treatments": [
+    {
+      "instructions": [
+        {
+          "type": "OUTPUT",
+          "port": -3
+        },
+        {
+          "type": "DROP"
+        }
+      ],
+      "deferred": []
+    }
+  ],
+  "meta": {
+    "criteria": [
+      {
+        "type": "IN_PORT",
+        "port": 23
+      }
+    ]
+  }
+}
\ No newline at end of file