Committed by
Gerrit Code Review
[ONOS-3163]Flow classifier UT updated for review comments
Change-Id: Ibf19c1781a76d8647f3b6c293302513796b8b5a5
Showing
2 changed files
with
19 additions
and
17 deletions
... | @@ -36,12 +36,10 @@ import org.onosproject.rest.AbstractWebResource; | ... | @@ -36,12 +36,10 @@ import org.onosproject.rest.AbstractWebResource; |
36 | import org.onosproject.vtnrsc.FlowClassifier; | 36 | import org.onosproject.vtnrsc.FlowClassifier; |
37 | import org.onosproject.vtnrsc.FlowClassifierId; | 37 | import org.onosproject.vtnrsc.FlowClassifierId; |
38 | import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; | 38 | import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; |
39 | -import org.onosproject.vtnweb.web.FlowClassifierCodec; | ||
40 | import org.slf4j.Logger; | 39 | import org.slf4j.Logger; |
41 | import org.slf4j.LoggerFactory; | 40 | import org.slf4j.LoggerFactory; |
42 | 41 | ||
43 | import com.fasterxml.jackson.databind.JsonNode; | 42 | import com.fasterxml.jackson.databind.JsonNode; |
44 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
45 | import com.fasterxml.jackson.databind.node.ArrayNode; | 43 | import com.fasterxml.jackson.databind.node.ArrayNode; |
46 | import com.fasterxml.jackson.databind.node.ObjectNode; | 44 | import com.fasterxml.jackson.databind.node.ObjectNode; |
47 | 45 | ||
... | @@ -64,11 +62,11 @@ public class FlowClassifierWebResource extends AbstractWebResource { | ... | @@ -64,11 +62,11 @@ public class FlowClassifierWebResource extends AbstractWebResource { |
64 | @Produces(MediaType.APPLICATION_JSON) | 62 | @Produces(MediaType.APPLICATION_JSON) |
65 | public Response getFlowClassifiers() { | 63 | public Response getFlowClassifiers() { |
66 | Iterable<FlowClassifier> flowClassifiers = get(FlowClassifierService.class).getFlowClassifiers(); | 64 | Iterable<FlowClassifier> flowClassifiers = get(FlowClassifierService.class).getFlowClassifiers(); |
67 | - ObjectNode result = new ObjectMapper().createObjectNode(); | 65 | + ObjectNode result = mapper().createObjectNode(); |
68 | ArrayNode flowClassifierEntry = result.putArray("flow_classifiers"); | 66 | ArrayNode flowClassifierEntry = result.putArray("flow_classifiers"); |
69 | if (flowClassifiers != null) { | 67 | if (flowClassifiers != null) { |
70 | for (final FlowClassifier flowClassifier : flowClassifiers) { | 68 | for (final FlowClassifier flowClassifier : flowClassifiers) { |
71 | - flowClassifierEntry.add(new FlowClassifierCodec().encode(flowClassifier, this)); | 69 | + flowClassifierEntry.add(codec(FlowClassifier.class).encode(flowClassifier, this)); |
72 | } | 70 | } |
73 | } | 71 | } |
74 | return ok(result.toString()).build(); | 72 | return ok(result.toString()).build(); |
... | @@ -85,11 +83,11 @@ public class FlowClassifierWebResource extends AbstractWebResource { | ... | @@ -85,11 +83,11 @@ public class FlowClassifierWebResource extends AbstractWebResource { |
85 | @Path("{flow_id}") | 83 | @Path("{flow_id}") |
86 | @Produces(MediaType.APPLICATION_JSON) | 84 | @Produces(MediaType.APPLICATION_JSON) |
87 | public Response getFlowClassifier(@PathParam("flow_id") String id) { | 85 | public Response getFlowClassifier(@PathParam("flow_id") String id) { |
88 | - FlowClassifier flowClassifier = nullIsNotFound( | 86 | + FlowClassifier flowClassifier = nullIsNotFound(get(FlowClassifierService.class) |
89 | - get(FlowClassifierService.class).getFlowClassifier(FlowClassifierId.of(id)), FLOW_CLASSIFIER_NOT_FOUND); | 87 | + .getFlowClassifier(FlowClassifierId.of(id)), FLOW_CLASSIFIER_NOT_FOUND); |
90 | 88 | ||
91 | - ObjectNode result = new ObjectMapper().createObjectNode(); | 89 | + ObjectNode result = mapper().createObjectNode(); |
92 | - result.set("flow_classifier", new FlowClassifierCodec().encode(flowClassifier, this)); | 90 | + result.set("flow_classifier", codec(FlowClassifier.class).encode(flowClassifier, this)); |
93 | 91 | ||
94 | return ok(result.toString()).build(); | 92 | return ok(result.toString()).build(); |
95 | } | 93 | } |
... | @@ -107,13 +105,12 @@ public class FlowClassifierWebResource extends AbstractWebResource { | ... | @@ -107,13 +105,12 @@ public class FlowClassifierWebResource extends AbstractWebResource { |
107 | @Produces(MediaType.APPLICATION_JSON) | 105 | @Produces(MediaType.APPLICATION_JSON) |
108 | public Response createFlowClassifier(InputStream stream) { | 106 | public Response createFlowClassifier(InputStream stream) { |
109 | try { | 107 | try { |
110 | - ObjectMapper mapper = new ObjectMapper(); | 108 | + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
111 | - ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream); | ||
112 | JsonNode flow = jsonTree.get("flow_classifier"); | 109 | JsonNode flow = jsonTree.get("flow_classifier"); |
113 | 110 | ||
114 | - FlowClassifier flowClassifier = new FlowClassifierCodec().decode((ObjectNode) flow, this); | 111 | + FlowClassifier flowClassifier = codec(FlowClassifier.class).decode((ObjectNode) flow, this); |
115 | Boolean issuccess = nullIsNotFound(get(FlowClassifierService.class).createFlowClassifier(flowClassifier), | 112 | Boolean issuccess = nullIsNotFound(get(FlowClassifierService.class).createFlowClassifier(flowClassifier), |
116 | - FLOW_CLASSIFIER_NOT_FOUND); | 113 | + FLOW_CLASSIFIER_NOT_FOUND); |
117 | return Response.status(OK).entity(issuccess.toString()).build(); | 114 | return Response.status(OK).entity(issuccess.toString()).build(); |
118 | } catch (IOException ex) { | 115 | } catch (IOException ex) { |
119 | log.error("Exception while creating flow classifier {}.", ex.toString()); | 116 | log.error("Exception while creating flow classifier {}.", ex.toString()); |
... | @@ -139,9 +136,9 @@ public class FlowClassifierWebResource extends AbstractWebResource { | ... | @@ -139,9 +136,9 @@ public class FlowClassifierWebResource extends AbstractWebResource { |
139 | 136 | ||
140 | JsonNode jsonTree = mapper().readTree(stream); | 137 | JsonNode jsonTree = mapper().readTree(stream); |
141 | JsonNode flow = jsonTree.get("flow_classifier"); | 138 | JsonNode flow = jsonTree.get("flow_classifier"); |
142 | - FlowClassifier flowClassifier = new FlowClassifierCodec().decode((ObjectNode) flow, this); | 139 | + FlowClassifier flowClassifier = codec(FlowClassifier.class).decode((ObjectNode) flow, this); |
143 | Boolean result = nullIsNotFound(get(FlowClassifierService.class).updateFlowClassifier(flowClassifier), | 140 | Boolean result = nullIsNotFound(get(FlowClassifierService.class).updateFlowClassifier(flowClassifier), |
144 | - FLOW_CLASSIFIER_NOT_FOUND); | 141 | + FLOW_CLASSIFIER_NOT_FOUND); |
145 | return Response.status(OK).entity(result.toString()).build(); | 142 | return Response.status(OK).entity(result.toString()).build(); |
146 | } catch (IOException e) { | 143 | } catch (IOException e) { |
147 | log.error("Update flow classifier failed because of exception {}.", e.toString()); | 144 | log.error("Update flow classifier failed because of exception {}.", e.toString()); |
... | @@ -161,7 +158,7 @@ public class FlowClassifierWebResource extends AbstractWebResource { | ... | @@ -161,7 +158,7 @@ public class FlowClassifierWebResource extends AbstractWebResource { |
161 | log.debug("Deletes flow classifier by identifier {}.", id); | 158 | log.debug("Deletes flow classifier by identifier {}.", id); |
162 | FlowClassifierId flowClassifierId = FlowClassifierId.of(id); | 159 | FlowClassifierId flowClassifierId = FlowClassifierId.of(id); |
163 | Boolean issuccess = nullIsNotFound(get(FlowClassifierService.class).removeFlowClassifier(flowClassifierId), | 160 | Boolean issuccess = nullIsNotFound(get(FlowClassifierService.class).removeFlowClassifier(flowClassifierId), |
164 | - FLOW_CLASSIFIER_NOT_FOUND); | 161 | + FLOW_CLASSIFIER_NOT_FOUND); |
165 | 162 | ||
166 | } | 163 | } |
167 | } | 164 | } | ... | ... |
... | @@ -40,11 +40,13 @@ import org.onlab.osgi.ServiceDirectory; | ... | @@ -40,11 +40,13 @@ import org.onlab.osgi.ServiceDirectory; |
40 | import org.onlab.osgi.TestServiceDirectory; | 40 | import org.onlab.osgi.TestServiceDirectory; |
41 | import org.onlab.packet.IpPrefix; | 41 | import org.onlab.packet.IpPrefix; |
42 | import org.onlab.rest.BaseResource; | 42 | import org.onlab.rest.BaseResource; |
43 | +import org.onosproject.codec.CodecService; | ||
43 | import org.onosproject.vtnrsc.FlowClassifier; | 44 | import org.onosproject.vtnrsc.FlowClassifier; |
44 | import org.onosproject.vtnrsc.FlowClassifierId; | 45 | import org.onosproject.vtnrsc.FlowClassifierId; |
45 | import org.onosproject.vtnrsc.TenantId; | 46 | import org.onosproject.vtnrsc.TenantId; |
46 | import org.onosproject.vtnrsc.VirtualPortId; | 47 | import org.onosproject.vtnrsc.VirtualPortId; |
47 | import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; | 48 | import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; |
49 | +import org.onosproject.vtnweb.web.SfcCodecContext; | ||
48 | 50 | ||
49 | import com.eclipsesource.json.JsonObject; | 51 | import com.eclipsesource.json.JsonObject; |
50 | import com.sun.jersey.api.client.ClientResponse; | 52 | import com.sun.jersey.api.client.ClientResponse; |
... | @@ -192,8 +194,11 @@ public class FlowClassifierResourceTest extends VtnResourceTest { | ... | @@ -192,8 +194,11 @@ public class FlowClassifierResourceTest extends VtnResourceTest { |
192 | */ | 194 | */ |
193 | @Before | 195 | @Before |
194 | public void setUpTest() { | 196 | public void setUpTest() { |
195 | - ServiceDirectory testDirectory = new TestServiceDirectory().add(FlowClassifierService.class, | 197 | + SfcCodecContext context = new SfcCodecContext(); |
196 | - flowClassifierService); | 198 | + |
199 | + ServiceDirectory testDirectory = new TestServiceDirectory() | ||
200 | + .add(FlowClassifierService.class, flowClassifierService) | ||
201 | + .add(CodecService.class, context.codecManager()); | ||
197 | BaseResource.setServiceDirectory(testDirectory); | 202 | BaseResource.setServiceDirectory(testDirectory); |
198 | 203 | ||
199 | } | 204 | } | ... | ... |
-
Please register or login to post a comment