Refactor to remove duplicated code snippet on mapping cxt class
Change-Id: Ic4e2aba07b7b69c63a838abc85addcec10d6eb30
diff --git a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingActionCodecTest.java b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingActionCodecTest.java
index 86d259d..c80837f 100644
--- a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingActionCodecTest.java
+++ b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingActionCodecTest.java
@@ -15,13 +15,11 @@
*/
package org.onosproject.mapping.web.codec;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.codec.CodecContext;
-import org.onosproject.codec.CodecService;
import org.onosproject.codec.JsonCodec;
import org.onosproject.codec.impl.CodecManager;
import org.onosproject.mapping.actions.MappingAction;
@@ -56,7 +54,7 @@
registrator.codecService = manager;
registrator.activate();
- context = new MappingActionCodecTest.MappingTestContext(registrator.codecService);
+ context = new MappingCodecContextAdapter(registrator.codecService);
actionCodec = context.codec(MappingAction.class);
assertThat(actionCodec, notNullValue());
}
@@ -108,34 +106,4 @@
final ObjectNode actionJson = actionCodec.encode(action, context);
assertThat(actionJson, matchesAction(action));
}
-
- /**
- * Test mapping codec context.
- */
- private class MappingTestContext implements CodecContext {
- private final ObjectMapper mapper = new ObjectMapper();
- private final CodecService manager;
-
- /**
- * Constructs a new mock codec context.
- */
- public MappingTestContext(CodecService manager) {
- this.manager = manager;
- }
-
- @Override
- public ObjectMapper mapper() {
- return mapper;
- }
-
- @Override
- public <T> JsonCodec<T> codec(Class<T> entityClass) {
- return manager.getCodec(entityClass);
- }
-
- @Override
- public <T> T getService(Class<T> serviceClass) {
- return null;
- }
- }
}
diff --git a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingAddressCodecTest.java b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingAddressCodecTest.java
index 41913c3..f5eb825 100644
--- a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingAddressCodecTest.java
+++ b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingAddressCodecTest.java
@@ -15,7 +15,6 @@
*/
package org.onosproject.mapping.web.codec;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.After;
import org.junit.Before;
@@ -23,7 +22,6 @@
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onosproject.codec.CodecContext;
-import org.onosproject.codec.CodecService;
import org.onosproject.codec.JsonCodec;
import org.onosproject.codec.impl.CodecManager;
import org.onosproject.mapping.addresses.MappingAddress;
@@ -59,7 +57,7 @@
registrator.codecService = manager;
registrator.activate();
- context = new MappingTestContext(registrator.codecService);
+ context = new MappingCodecContextAdapter(registrator.codecService);
addressCodec = context.codec(MappingAddress.class);
assertThat(addressCodec, notNullValue());
@@ -119,34 +117,4 @@
ObjectNode result = addressCodec.encode(address, context);
assertThat(result, matchesMappingAddress(address));
}
-
- /**
- * Test mapping codec context.
- */
- private class MappingTestContext implements CodecContext {
- private final ObjectMapper mapper = new ObjectMapper();
- private final CodecService manager;
-
- /**
- * Constructs a new mock codec context.
- */
- public MappingTestContext(CodecService manager) {
- this.manager = manager;
- }
-
- @Override
- public ObjectMapper mapper() {
- return mapper;
- }
-
- @Override
- public <T> JsonCodec<T> codec(Class<T> entityClass) {
- return manager.getCodec(entityClass);
- }
-
- @Override
- public <T> T getService(Class<T> serviceClass) {
- return null;
- }
- }
}
diff --git a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingCodecContextAdapter.java b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingCodecContextAdapter.java
new file mode 100644
index 0000000..69f88f5
--- /dev/null
+++ b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingCodecContextAdapter.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2017-present 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.mapping.web.codec;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.CodecService;
+import org.onosproject.codec.JsonCodec;
+
+/**
+ * An adapter that provides mapping codec context.
+ */
+public class MappingCodecContextAdapter implements CodecContext {
+
+ private final ObjectMapper mapper = new ObjectMapper();
+ private final CodecService manager;
+
+ /**
+ * Constructs a new mock codec context.
+ *
+ * @param manager codec manager
+ */
+ public MappingCodecContextAdapter(CodecService manager) {
+ this.manager = manager;
+ }
+
+ @Override
+ public ObjectMapper mapper() {
+ return mapper;
+ }
+
+ @Override
+ public <T> JsonCodec<T> codec(Class<T> entityClass) {
+ return manager.getCodec(entityClass);
+ }
+
+ @Override
+ public <T> T getService(Class<T> serviceClass) {
+ return null;
+ }
+}
diff --git a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingInstructionCodecTest.java b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingInstructionCodecTest.java
index 715af50..b2fb3d4 100644
--- a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingInstructionCodecTest.java
+++ b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingInstructionCodecTest.java
@@ -15,13 +15,11 @@
*/
package org.onosproject.mapping.web.codec;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.codec.CodecContext;
-import org.onosproject.codec.CodecService;
import org.onosproject.codec.JsonCodec;
import org.onosproject.codec.impl.CodecManager;
import org.onosproject.mapping.instructions.MappingInstruction;
@@ -59,7 +57,7 @@
registrator.codecService = manager;
registrator.activate();
- context = new MappingInstructionCodecTest.MappingTestContext(registrator.codecService);
+ context = new MappingCodecContextAdapter(registrator.codecService);
instructionCodec = context.codec(MappingInstruction.class);
assertThat(instructionCodec, notNullValue());
@@ -119,35 +117,6 @@
MappingInstructions.multicastPriority(MULTICAST_PRIORITY);
final ObjectNode instructionJson =
instructionCodec.encode(instruction, context);
- assertThat(instructionJson, matchesInstruction(instruction)); }
-
- /**
- * Test mapping codec context.
- */
- private class MappingTestContext implements CodecContext {
- private final ObjectMapper mapper = new ObjectMapper();
- private final CodecService manager;
-
- /**
- * Constructs a new mock codec context.
- */
- public MappingTestContext(CodecService manager) {
- this.manager = manager;
- }
-
- @Override
- public ObjectMapper mapper() {
- return mapper;
- }
-
- @Override
- public <T> JsonCodec<T> codec(Class<T> entityClass) {
- return manager.getCodec(entityClass);
- }
-
- @Override
- public <T> T getService(Class<T> serviceClass) {
- return null;
- }
+ assertThat(instructionJson, matchesInstruction(instruction));
}
}
diff --git a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingKeyCodecTest.java b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingKeyCodecTest.java
index 39f43d4..f71e0b1 100644
--- a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingKeyCodecTest.java
+++ b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingKeyCodecTest.java
@@ -16,7 +16,6 @@
package org.onosproject.mapping.web.codec;
import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;
@@ -25,7 +24,6 @@
import org.junit.Test;
import org.onlab.packet.IpPrefix;
import org.onosproject.codec.CodecContext;
-import org.onosproject.codec.CodecService;
import org.onosproject.codec.JsonCodec;
import org.onosproject.codec.impl.CodecManager;
import org.onosproject.mapping.DefaultMappingKey;
@@ -66,7 +64,7 @@
registrator.codecService = manager;
registrator.activate();
- context = new MappingKeyCodecTest.MappingTestContext(registrator.codecService);
+ context = new MappingCodecContextAdapter(registrator.codecService);
keyCodec = context.codec(MappingKey.class);
assertThat(keyCodec, notNullValue());
}
@@ -151,36 +149,6 @@
}
/**
- * Test mapping codec context.
- */
- private class MappingTestContext implements CodecContext {
- private final ObjectMapper mapper = new ObjectMapper();
- private final CodecService manager;
-
- /**
- * Constructs a new mock codec context.
- */
- public MappingTestContext(CodecService manager) {
- this.manager = manager;
- }
-
- @Override
- public ObjectMapper mapper() {
- return mapper;
- }
-
- @Override
- public <T> JsonCodec<T> codec(Class<T> entityClass) {
- return manager.getCodec(entityClass);
- }
-
- @Override
- public <T> T getService(Class<T> serviceClass) {
- return null;
- }
- }
-
- /**
* Reads in a mapping key from the given resource and decodes it.
*
* @param resourceName resource to use to read the JSON for the rule
diff --git a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingTreatmentCodecTest.java b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingTreatmentCodecTest.java
index 6a17502..23817e1 100644
--- a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingTreatmentCodecTest.java
+++ b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingTreatmentCodecTest.java
@@ -16,7 +16,6 @@
package org.onosproject.mapping.web.codec;
import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableSet;
import org.hamcrest.Description;
@@ -25,7 +24,6 @@
import org.junit.Before;
import org.junit.Test;
import org.onosproject.codec.CodecContext;
-import org.onosproject.codec.CodecService;
import org.onosproject.codec.JsonCodec;
import org.onosproject.codec.impl.CodecManager;
import org.onosproject.mapping.DefaultMappingTreatment;
@@ -73,7 +71,7 @@
registrator.codecService = manager;
registrator.activate();
- context = new MappingTreatmentCodecTest.MappingTestContext(registrator.codecService);
+ context = new MappingCodecContextAdapter(registrator.codecService);
treatmentCodec = context.codec(MappingTreatment.class);
assertThat(treatmentCodec, notNullValue());
}
@@ -196,36 +194,6 @@
}
/**
- * Test mapping codec context.
- */
- private class MappingTestContext implements CodecContext {
- private final ObjectMapper mapper = new ObjectMapper();
- private final CodecService manager;
-
- /**
- * Constructs a new mock codec context.
- */
- public MappingTestContext(CodecService manager) {
- this.manager = manager;
- }
-
- @Override
- public ObjectMapper mapper() {
- return mapper;
- }
-
- @Override
- public <T> JsonCodec<T> codec(Class<T> entityClass) {
- return manager.getCodec(entityClass);
- }
-
- @Override
- public <T> T getService(Class<T> serviceClass) {
- return null;
- }
- }
-
- /**
* Reads in a mapping treatment from the given resource and decodes it.
*
* @param resourceName resource to use to read the JSON for the rule
diff --git a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingValueCodecTest.java b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingValueCodecTest.java
index 48e862f..6f6a824 100644
--- a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingValueCodecTest.java
+++ b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/codec/MappingValueCodecTest.java
@@ -16,7 +16,6 @@
package org.onosproject.mapping.web.codec;
import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;
@@ -25,7 +24,6 @@
import org.junit.Test;
import org.onlab.packet.IpPrefix;
import org.onosproject.codec.CodecContext;
-import org.onosproject.codec.CodecService;
import org.onosproject.codec.JsonCodec;
import org.onosproject.codec.impl.CodecManager;
import org.onosproject.mapping.DefaultMappingTreatment;
@@ -79,7 +77,7 @@
registrator.codecService = manager;
registrator.activate();
- context = new MappingValueCodecTest.MappingTestContext(registrator.codecService);
+ context = new MappingCodecContextAdapter(registrator.codecService);
valueCodec = context.codec(MappingValue.class);
assertThat(valueCodec, notNullValue());
}
@@ -206,36 +204,6 @@
}
/**
- * Test mapping codec context.
- */
- private class MappingTestContext implements CodecContext {
- private final ObjectMapper mapper = new ObjectMapper();
- private final CodecService manager;
-
- /**
- * Constructs a new mock codec context.
- */
- public MappingTestContext(CodecService manager) {
- this.manager = manager;
- }
-
- @Override
- public ObjectMapper mapper() {
- return mapper;
- }
-
- @Override
- public <T> JsonCodec<T> codec(Class<T> entityClass) {
- return manager.getCodec(entityClass);
- }
-
- @Override
- public <T> T getService(Class<T> serviceClass) {
- return null;
- }
- }
-
- /**
* Reads in a mapping value from the given resource and decodes it.
*
* @param resourceName resource to use to read the JSON for the rule