diff options
author | CNlucius <lukai1@huawei.com> | 2016-09-13 11:40:12 +0800 |
---|---|---|
committer | CNlucius <lukai1@huawei.com> | 2016-09-13 11:41:53 +0800 |
commit | b731e2f1dd0972409b136aebc7b463dd72c9cfad (patch) | |
tree | 5107d7d80c19ad8076c2c97c2b5ef8d1cf3ab903 /framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject | |
parent | ee93993458266114c29271a481ef9ce7ce621b2a (diff) |
ONOSFW-171
O/S-SFC-ONOS scenario documentation
Change-Id: I51ae1cf736ea24ab6680f8edca1b2bf5dd598365
Signed-off-by: CNlucius <lukai1@huawei.com>
Diffstat (limited to 'framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject')
10 files changed, 0 insertions, 1521 deletions
diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/FlowClassifierResourceTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/FlowClassifierResourceTest.java deleted file mode 100644 index db08d7c4..00000000 --- a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/FlowClassifierResourceTest.java +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright 2014-2015 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.vtnweb.resources; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -import javax.ws.rs.core.MediaType; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onlab.osgi.ServiceDirectory; -import org.onlab.osgi.TestServiceDirectory; -import org.onlab.packet.IpPrefix; -import org.onlab.rest.BaseResource; -import org.onosproject.codec.CodecService; -import org.onosproject.vtnrsc.FlowClassifier; -import org.onosproject.vtnrsc.FlowClassifierId; -import org.onosproject.vtnrsc.TenantId; -import org.onosproject.vtnrsc.VirtualPortId; -import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; -import org.onosproject.vtnweb.web.SfcCodecContext; - -import com.eclipsesource.json.JsonObject; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.UniformInterfaceException; -import com.sun.jersey.api.client.WebResource; -/** - * Unit tests for flow classifier REST APIs. - */ -public class FlowClassifierResourceTest extends VtnResourceTest { - - final FlowClassifierService flowClassifierService = createMock(FlowClassifierService.class); - - FlowClassifierId flowClassifierId1 = FlowClassifierId.of("4a334cd4-fe9c-4fae-af4b-321c5e2eb051"); - TenantId tenantId1 = TenantId.tenantId("1814726e2d22407b8ca76db5e567dcf1"); - VirtualPortId srcPortId1 = VirtualPortId.portId("dace4513-24fc-4fae-af4b-321c5e2eb3d1"); - VirtualPortId dstPortId1 = VirtualPortId.portId("aef3478a-4a56-2a6e-cd3a-9dee4e2ec345"); - - final MockFlowClassifier flowClassifier1 = new MockFlowClassifier(flowClassifierId1, tenantId1, "flowClassifier1", - "Mock flow classifier", "IPv4", "IP", 1001, 1500, - 5001, 6000, IpPrefix.valueOf("1.1.1.1/16"), - IpPrefix.valueOf("22.12.34.45/16"), - srcPortId1, dstPortId1); - - /** - * Mock class for a flow classifier. - */ - private static class MockFlowClassifier implements FlowClassifier { - - private final FlowClassifierId flowClassifierId; - private final TenantId tenantId; - private final String name; - private final String description; - private final String etherType; - private final String protocol; - private final int minSrcPortRange; - private final int maxSrcPortRange; - private final int minDstPortRange; - private final int maxDstPortRange; - private final IpPrefix srcIpPrefix; - private final IpPrefix dstIpPrefix; - private final VirtualPortId srcPort; - private final VirtualPortId dstPort; - - public MockFlowClassifier(FlowClassifierId flowClassifierId, TenantId tenantId, String name, - String description, String etherType, String protocol, int minSrcPortRange, - int maxSrcPortRange, int minDstPortRange, int maxDstPortRange, IpPrefix srcIpPrefix, - IpPrefix dstIpPrefix, VirtualPortId srcPort, VirtualPortId dstPort) { - this.flowClassifierId = flowClassifierId; - this.tenantId = tenantId; - this.name = name; - this.description = description; - this.etherType = etherType; - this.protocol = protocol; - this.minSrcPortRange = minSrcPortRange; - this.maxSrcPortRange = maxSrcPortRange; - this.minDstPortRange = minDstPortRange; - this.maxDstPortRange = maxDstPortRange; - this.srcIpPrefix = srcIpPrefix; - this.dstIpPrefix = dstIpPrefix; - this.srcPort = srcPort; - this.dstPort = dstPort; - } - - - @Override - public FlowClassifierId flowClassifierId() { - return flowClassifierId; - } - - @Override - public TenantId tenantId() { - return tenantId; - } - - @Override - public String name() { - return name; - } - - @Override - public String description() { - return description; - } - - @Override - public String etherType() { - return etherType; - } - - @Override - public String protocol() { - return protocol; - } - - @Override - public int minSrcPortRange() { - return minSrcPortRange; - } - - @Override - public int maxSrcPortRange() { - return maxSrcPortRange; - } - - @Override - public int minDstPortRange() { - return minDstPortRange; - } - - @Override - public int maxDstPortRange() { - return maxDstPortRange; - } - - @Override - public IpPrefix srcIpPrefix() { - return srcIpPrefix; - } - - @Override - public IpPrefix dstIpPrefix() { - return dstIpPrefix; - } - - @Override - public VirtualPortId srcPort() { - return srcPort; - } - - @Override - public VirtualPortId dstPort() { - return dstPort; - } - - @Override - public boolean exactMatch(FlowClassifier flowClassifier) { - return this.equals(flowClassifier) && - Objects.equals(this.flowClassifierId, flowClassifier.flowClassifierId()) && - Objects.equals(this.tenantId, flowClassifier.tenantId()); - } - } - - /** - * Sets up the global values for all the tests. - */ - @Before - public void setUpTest() { - SfcCodecContext context = new SfcCodecContext(); - - ServiceDirectory testDirectory = new TestServiceDirectory() - .add(FlowClassifierService.class, flowClassifierService) - .add(CodecService.class, context.codecManager()); - BaseResource.setServiceDirectory(testDirectory); - - } - - /** - * Cleans up. - */ - @After - public void tearDownTest() { - } - - /** - * Tests the result of the rest api GET when there are no flow classifiers. - */ - @Test - public void testFlowClassifiersEmpty() { - - expect(flowClassifierService.getFlowClassifiers()).andReturn(null).anyTimes(); - replay(flowClassifierService); - final WebResource rs = resource(); - final String response = rs.path("flow_classifiers").get(String.class); - assertThat(response, is("{\"flow_classifiers\":[]}")); - } - - /** - * Tests the result of a rest api GET for flow classifier id. - */ - @Test - public void testGetFlowClassifierId() { - - final Set<FlowClassifier> flowClassifiers = new HashSet<>(); - flowClassifiers.add(flowClassifier1); - - expect(flowClassifierService.exists(anyObject())).andReturn(true).anyTimes(); - expect(flowClassifierService.getFlowClassifier(anyObject())).andReturn(flowClassifier1).anyTimes(); - replay(flowClassifierService); - - final WebResource rs = resource(); - final String response = rs.path("flow_classifiers/4a334cd4-fe9c-4fae-af4b-321c5e2eb051").get(String.class); - final JsonObject result = JsonObject.readFrom(response); - assertThat(result, notNullValue()); - } - - /** - * Tests that a fetch of a non-existent flow classifier object throws an exception. - */ - @Test - public void testBadGet() { - expect(flowClassifierService.getFlowClassifier(anyObject())) - .andReturn(null).anyTimes(); - replay(flowClassifierService); - WebResource rs = resource(); - try { - rs.path("flow_classifiers/78dcd363-fc23-aeb6-f44b-56dc5aafb3ae").get(String.class); - fail("Fetch of non-existent flow classifier did not throw an exception"); - } catch (UniformInterfaceException ex) { - assertThat(ex.getMessage(), - containsString("returned a response status of")); - } - } - - /** - * Tests creating a flow classifier with POST. - */ - @Test - public void testPost() { - - expect(flowClassifierService.createFlowClassifier(anyObject())) - .andReturn(true).anyTimes(); - replay(flowClassifierService); - - WebResource rs = resource(); - InputStream jsonStream = FlowClassifierResourceTest.class.getResourceAsStream("post-FlowClassifier.json"); - - ClientResponse response = rs.path("flow_classifiers") - .type(MediaType.APPLICATION_JSON_TYPE) - .post(ClientResponse.class, jsonStream); - assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); - } - - /** - * Tests deleting a flow classifier. - */ - @Test - public void testDelete() { - expect(flowClassifierService.removeFlowClassifier(anyObject())) - .andReturn(true).anyTimes(); - replay(flowClassifierService); - - WebResource rs = resource(); - - String location = "flow_classifiers/4a334cd4-fe9c-4fae-af4b-321c5e2eb051"; - - ClientResponse deleteResponse = rs.path(location) - .type(MediaType.APPLICATION_JSON_TYPE) - .delete(ClientResponse.class); - assertThat(deleteResponse.getStatus(), - is(HttpURLConnection.HTTP_NO_CONTENT)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortChainResourceTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortChainResourceTest.java deleted file mode 100644 index 3cb2c83f..00000000 --- a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortChainResourceTest.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright 2014-2015 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.vtnweb.resources; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -import javax.ws.rs.core.MediaType; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onlab.osgi.ServiceDirectory; -import org.onlab.osgi.TestServiceDirectory; -import org.onlab.rest.BaseResource; -import org.onosproject.codec.CodecService; -import org.onosproject.vtnrsc.FlowClassifierId; -import org.onosproject.vtnrsc.PortChain; -import org.onosproject.vtnrsc.PortChainId; -import org.onosproject.vtnrsc.PortPairGroupId; -import org.onosproject.vtnrsc.TenantId; -import org.onosproject.vtnrsc.portchain.PortChainService; -import org.onosproject.vtnweb.web.SfcCodecContext; - -import com.eclipsesource.json.JsonObject; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.UniformInterfaceException; -import com.sun.jersey.api.client.WebResource; - -/** - * Unit tests for port chain REST APIs. - */ -public class PortChainResourceTest extends VtnResourceTest { - - final PortChainService portChainService = createMock(PortChainService.class); - - PortChainId portChainId1 = PortChainId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); - TenantId tenantId1 = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5"); - private final List<PortPairGroupId> portPairGroupList1 = Lists.newArrayList(); - private final List<FlowClassifierId> flowClassifierList1 = Lists.newArrayList(); - - - final MockPortChain portChain1 = new MockPortChain(portChainId1, tenantId1, "portChain1", - "Mock port chain", portPairGroupList1, - flowClassifierList1); - - /** - * Mock class for a port chain. - */ - private static class MockPortChain implements PortChain { - - private final PortChainId portChainId; - private final TenantId tenantId; - private final String name; - private final String description; - private final List<PortPairGroupId> portPairGroupList; - private final List<FlowClassifierId> flowClassifierList; - - public MockPortChain(PortChainId portChainId, TenantId tenantId, - String name, String description, - List<PortPairGroupId> portPairGroupList, - List<FlowClassifierId> flowClassifierList) { - - this.portChainId = portChainId; - this.tenantId = tenantId; - this.name = name; - this.description = description; - this.portPairGroupList = portPairGroupList; - this.flowClassifierList = flowClassifierList; - } - - @Override - public PortChainId portChainId() { - return portChainId; - } - - @Override - public TenantId tenantId() { - return tenantId; - } - - @Override - public String name() { - return name; - } - - @Override - public String description() { - return description; - } - - @Override - public List<PortPairGroupId> portPairGroups() { - return ImmutableList.copyOf(portPairGroupList); - } - - @Override - public List<FlowClassifierId> flowClassifiers() { - return ImmutableList.copyOf(flowClassifierList); - } - - @Override - public boolean exactMatch(PortChain portChain) { - return this.equals(portChain) && - Objects.equals(this.portChainId, portChain.portChainId()) && - Objects.equals(this.tenantId, portChain.tenantId()); - } - } - - /** - * Sets up the global values for all the tests. - */ - @Before - public void setUpTest() { - SfcCodecContext context = new SfcCodecContext(); - ServiceDirectory testDirectory = new TestServiceDirectory() - .add(PortChainService.class, portChainService) - .add(CodecService.class, context.codecManager()); - BaseResource.setServiceDirectory(testDirectory); - - } - - /** - * Cleans up. - */ - @After - public void tearDownTest() { - } - - /** - * Tests the result of the rest api GET when there are no port chains. - */ - @Test - public void testPortChainsEmpty() { - - expect(portChainService.getPortChains()).andReturn(null).anyTimes(); - replay(portChainService); - final WebResource rs = resource(); - final String response = rs.path("port_chains").get(String.class); - assertThat(response, is("{\"port_chains\":[]}")); - } - - /** - * Tests the result of a rest api GET for port chain id. - */ - @Test - public void testGetPortChainId() { - - final Set<PortChain> portChains = new HashSet<>(); - portChains.add(portChain1); - - expect(portChainService.exists(anyObject())).andReturn(true).anyTimes(); - expect(portChainService.getPortChain(anyObject())).andReturn(portChain1).anyTimes(); - replay(portChainService); - - final WebResource rs = resource(); - final String response = rs.path("port_chains/1278dcd4-459f-62ed-754b-87fc5e4a6751").get(String.class); - final JsonObject result = JsonObject.readFrom(response); - assertThat(result, notNullValue()); - } - - /** - * Tests that a fetch of a non-existent port chain object throws an exception. - */ - @Test - public void testBadGet() { - expect(portChainService.getPortChain(anyObject())) - .andReturn(null).anyTimes(); - replay(portChainService); - WebResource rs = resource(); - try { - rs.path("port_chains/78dcd363-fc23-aeb6-f44b-56dc5aafb3ae").get(String.class); - fail("Fetch of non-existent port chain did not throw an exception"); - } catch (UniformInterfaceException ex) { - assertThat(ex.getMessage(), - containsString("returned a response status of")); - } - } - - /** - * Tests creating a port chain with POST. - */ - @Test - public void testPost() { - - expect(portChainService.createPortChain(anyObject())) - .andReturn(true).anyTimes(); - replay(portChainService); - - WebResource rs = resource(); - InputStream jsonStream = PortChainResourceTest.class.getResourceAsStream("post-PortChain.json"); - - ClientResponse response = rs.path("port_chains") - .type(MediaType.APPLICATION_JSON_TYPE) - .post(ClientResponse.class, jsonStream); - assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); - } - - /** - * Tests deleting a port chain. - */ - @Test - public void testDelete() { - expect(portChainService.removePortChain(anyObject())) - .andReturn(true).anyTimes(); - replay(portChainService); - - WebResource rs = resource(); - - String location = "port_chains/1278dcd4-459f-62ed-754b-87fc5e4a6751"; - - ClientResponse deleteResponse = rs.path(location) - .type(MediaType.APPLICATION_JSON_TYPE) - .delete(ClientResponse.class); - assertThat(deleteResponse.getStatus(), - is(HttpURLConnection.HTTP_NO_CONTENT)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortPairGroupResourceTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortPairGroupResourceTest.java deleted file mode 100644 index c13f2141..00000000 --- a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortPairGroupResourceTest.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright 2014-2015 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.vtnweb.resources; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -import javax.ws.rs.core.MediaType; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onlab.osgi.ServiceDirectory; -import org.onlab.osgi.TestServiceDirectory; -import org.onlab.rest.BaseResource; -import org.onosproject.codec.CodecService; -import org.onosproject.vtnrsc.PortPairGroup; -import org.onosproject.vtnrsc.PortPairGroupId; -import org.onosproject.vtnrsc.PortPairId; -import org.onosproject.vtnrsc.TenantId; -import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; -import org.onosproject.vtnweb.web.SfcCodecContext; - -import com.eclipsesource.json.JsonObject; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.UniformInterfaceException; -import com.sun.jersey.api.client.WebResource; -/** - * Unit tests for port pair group REST APIs. - */ -public class PortPairGroupResourceTest extends VtnResourceTest { - - final PortPairGroupService portPairGroupService = createMock(PortPairGroupService.class); - - PortPairGroupId portPairGroupId1 = PortPairGroupId.of("4512d643-24fc-4fae-af4b-321c5e2eb3d1"); - TenantId tenantId1 = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5"); - private final List<PortPairId> portPairList1 = Lists.newArrayList(); - - final MockPortPairGroup portPairGroup1 = new MockPortPairGroup(portPairGroupId1, tenantId1, "portPairGroup1", - "Mock port pair group", portPairList1); - - /** - * Mock class for a port pair group. - */ - private static class MockPortPairGroup implements PortPairGroup { - - private final PortPairGroupId portPairGroupId; - private final TenantId tenantId; - private final String name; - private final String description; - private final List<PortPairId> portPairList; - - public MockPortPairGroup(PortPairGroupId portPairGroupId, TenantId tenantId, - String name, String description, - List<PortPairId> portPairList) { - - this.portPairGroupId = portPairGroupId; - this.tenantId = tenantId; - this.name = name; - this.description = description; - this.portPairList = portPairList; - } - - @Override - public PortPairGroupId portPairGroupId() { - return portPairGroupId; - } - - @Override - public TenantId tenantId() { - return tenantId; - } - - @Override - public String name() { - return name; - } - - @Override - public String description() { - return description; - } - - @Override - public List<PortPairId> portPairs() { - return ImmutableList.copyOf(portPairList); - } - - @Override - public boolean exactMatch(PortPairGroup portPairGroup) { - return this.equals(portPairGroup) && - Objects.equals(this.portPairGroupId, portPairGroup.portPairGroupId()) && - Objects.equals(this.tenantId, portPairGroup.tenantId()); - } - } - - /** - * Sets up the global values for all the tests. - */ - @Before - public void setUpTest() { - SfcCodecContext context = new SfcCodecContext(); - ServiceDirectory testDirectory = new TestServiceDirectory() - .add(PortPairGroupService.class, portPairGroupService) - .add(CodecService.class, context.codecManager()); - BaseResource.setServiceDirectory(testDirectory); - - } - - /** - * Cleans up. - */ - @After - public void tearDownTest() { - } - - /** - * Tests the result of the rest api GET when there are no port pair groups. - */ - @Test - public void testPortPairGroupsEmpty() { - - expect(portPairGroupService.getPortPairGroups()).andReturn(null).anyTimes(); - replay(portPairGroupService); - final WebResource rs = resource(); - final String response = rs.path("port_pair_groups").get(String.class); - assertThat(response, is("{\"port_pair_groups\":[]}")); - } - - /** - * Tests the result of a rest api GET for port pair group id. - */ - @Test - public void testGetPortPairGroupId() { - - final Set<PortPairGroup> portPairGroups = new HashSet<>(); - portPairGroups.add(portPairGroup1); - - expect(portPairGroupService.exists(anyObject())).andReturn(true).anyTimes(); - expect(portPairGroupService.getPortPairGroup(anyObject())).andReturn(portPairGroup1).anyTimes(); - replay(portPairGroupService); - - final WebResource rs = resource(); - final String response = rs.path("port_pair_groups/4512d643-24fc-4fae-af4b-321c5e2eb3d1").get(String.class); - final JsonObject result = JsonObject.readFrom(response); - assertThat(result, notNullValue()); - } - - /** - * Tests that a fetch of a non-existent port pair group object throws an exception. - */ - @Test - public void testBadGet() { - expect(portPairGroupService.getPortPairGroup(anyObject())) - .andReturn(null).anyTimes(); - replay(portPairGroupService); - WebResource rs = resource(); - try { - rs.path("port_pair_groups/78dcd363-fc23-aeb6-f44b-56dc5aafb3ae").get(String.class); - fail("Fetch of non-existent port pair group did not throw an exception"); - } catch (UniformInterfaceException ex) { - assertThat(ex.getMessage(), - containsString("returned a response status of")); - } - } - - /** - * Tests creating a port pair group with POST. - */ - @Test - public void testPost() { - - expect(portPairGroupService.createPortPairGroup(anyObject())) - .andReturn(true).anyTimes(); - replay(portPairGroupService); - - WebResource rs = resource(); - InputStream jsonStream = PortPairGroupResourceTest.class.getResourceAsStream("post-PortPairGroup.json"); - - ClientResponse response = rs.path("port_pair_groups") - .type(MediaType.APPLICATION_JSON_TYPE) - .post(ClientResponse.class, jsonStream); - assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); - } - - /** - * Tests deleting a port pair group. - */ - @Test - public void testDelete() { - expect(portPairGroupService.removePortPairGroup(anyObject())) - .andReturn(true).anyTimes(); - replay(portPairGroupService); - - WebResource rs = resource(); - - String location = "port_pair_groups/4512d643-24fc-4fae-af4b-321c5e2eb3d1"; - - ClientResponse deleteResponse = rs.path(location) - .type(MediaType.APPLICATION_JSON_TYPE) - .delete(ClientResponse.class); - assertThat(deleteResponse.getStatus(), - is(HttpURLConnection.HTTP_NO_CONTENT)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortPairResourceTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortPairResourceTest.java deleted file mode 100644 index 36014ec5..00000000 --- a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortPairResourceTest.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright 2014-2015 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.vtnweb.resources; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -import javax.ws.rs.core.MediaType; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onlab.osgi.ServiceDirectory; -import org.onlab.osgi.TestServiceDirectory; -import org.onlab.rest.BaseResource; -import org.onosproject.codec.CodecService; -import org.onosproject.vtnrsc.PortPair; -import org.onosproject.vtnrsc.PortPairId; -import org.onosproject.vtnrsc.TenantId; -import org.onosproject.vtnrsc.portpair.PortPairService; -import org.onosproject.vtnweb.web.SfcCodecContext; - -import com.eclipsesource.json.JsonObject; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.UniformInterfaceException; -import com.sun.jersey.api.client.WebResource; -/** - * Unit tests for port pair REST APIs. - */ -public class PortPairResourceTest extends VtnResourceTest { - - final PortPairService portPairService = createMock(PortPairService.class); - - PortPairId portPairId1 = PortPairId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); - TenantId tenantId1 = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5"); - - final MockPortPair portPair1 = new MockPortPair(portPairId1, tenantId1, "portPair1", - "Mock port pair", "dace4513-24fc-4fae-af4b-321c5e2eb3d1", - "aef3478a-4a56-2a6e-cd3a-9dee4e2ec345"); - - /** - * Mock class for a port pair. - */ - private static class MockPortPair implements PortPair { - - private final PortPairId portPairId; - private final TenantId tenantId; - private final String name; - private final String description; - private final String ingress; - private final String egress; - - public MockPortPair(PortPairId portPairId, TenantId tenantId, - String name, String description, - String ingress, String egress) { - - this.portPairId = portPairId; - this.tenantId = tenantId; - this.name = name; - this.description = description; - this.ingress = ingress; - this.egress = egress; - } - - @Override - public PortPairId portPairId() { - return portPairId; - } - - @Override - public TenantId tenantId() { - return tenantId; - } - - @Override - public String name() { - return name; - } - - @Override - public String description() { - return description; - } - - @Override - public String ingress() { - return ingress; - } - - @Override - public String egress() { - return egress; - } - - @Override - public boolean exactMatch(PortPair portPair) { - return this.equals(portPair) && - Objects.equals(this.portPairId, portPair.portPairId()) && - Objects.equals(this.tenantId, portPair.tenantId()); - } - } - - /** - * Sets up the global values for all the tests. - */ - @Before - public void setUpTest() { - - SfcCodecContext context = new SfcCodecContext(); - ServiceDirectory testDirectory = new TestServiceDirectory().add(PortPairService.class, portPairService) - .add(CodecService.class, context.codecManager()); - BaseResource.setServiceDirectory(testDirectory); - - } - - /** - * Cleans up. - */ - @After - public void tearDownTest() { - } - - /** - * Tests the result of the rest api GET when there are no port pairs. - */ - @Test - public void testPortPairsEmpty() { - - expect(portPairService.getPortPairs()).andReturn(null).anyTimes(); - replay(portPairService); - final WebResource rs = resource(); - final String response = rs.path("port_pairs").get(String.class); - assertThat(response, is("{\"port_pairs\":[]}")); - } - - /** - * Tests the result of a rest api GET for port pair id. - */ - @Test - public void testGetPortPairId() { - - final Set<PortPair> portPairs = new HashSet<>(); - portPairs.add(portPair1); - - expect(portPairService.exists(anyObject())).andReturn(true).anyTimes(); - expect(portPairService.getPortPair(anyObject())).andReturn(portPair1).anyTimes(); - replay(portPairService); - - final WebResource rs = resource(); - final String response = rs.path("port_pairs/78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae").get(String.class); - final JsonObject result = JsonObject.readFrom(response); - assertThat(result, notNullValue()); - } - - /** - * Tests that a fetch of a non-existent port pair object throws an exception. - */ - @Test - public void testBadGet() { - expect(portPairService.getPortPair(anyObject())) - .andReturn(null).anyTimes(); - replay(portPairService); - WebResource rs = resource(); - try { - rs.path("port_pairs/78dcd363-fc23-aeb6-f44b-56dc5aafb3ae").get(String.class); - fail("Fetch of non-existent port pair did not throw an exception"); - } catch (UniformInterfaceException ex) { - assertThat(ex.getMessage(), - containsString("returned a response status of")); - } - } - - /** - * Tests creating a port pair with POST. - */ - @Test - public void testPost() { - - expect(portPairService.createPortPair(anyObject())) - .andReturn(true).anyTimes(); - replay(portPairService); - - WebResource rs = resource(); - InputStream jsonStream = PortPairResourceTest.class.getResourceAsStream("post-PortPair.json"); - - ClientResponse response = rs.path("port_pairs") - .type(MediaType.APPLICATION_JSON_TYPE) - .post(ClientResponse.class, jsonStream); - assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); - } - - /** - * Tests deleting a port pair. - */ - @Test - public void testDelete() { - expect(portPairService.removePortPair(anyObject())) - .andReturn(true).anyTimes(); - replay(portPairService); - - WebResource rs = resource(); - - String location = "port_pairs/78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"; - - ClientResponse deleteResponse = rs.path(location) - .type(MediaType.APPLICATION_JSON_TYPE) - .delete(ClientResponse.class); - assertThat(deleteResponse.getStatus(), - is(HttpURLConnection.HTTP_NO_CONTENT)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/VtnResourceTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/VtnResourceTest.java deleted file mode 100644 index 4b95844d..00000000 --- a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/VtnResourceTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2015 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.vtnweb.resources; - -import java.io.IOException; -import java.net.ServerSocket; - -import com.sun.jersey.test.framework.AppDescriptor; -import com.sun.jersey.test.framework.JerseyTest; -import com.sun.jersey.test.framework.WebAppDescriptor; - -/** - * Base class for VTN REST API tests. Performs common configuration operations. - */ -public class VtnResourceTest extends JerseyTest { - - /** - * Assigns an available port for the test. - * - * @param defaultPort If a port cannot be determined, this one is used. - * @return free port - */ - @Override - public int getPort(int defaultPort) { - try { - ServerSocket socket = new ServerSocket(0); - socket.setReuseAddress(true); - int port = socket.getLocalPort(); - socket.close(); - return port; - } catch (IOException ioe) { - return defaultPort; - } - } - - @Override - public AppDescriptor configure() { - return new WebAppDescriptor.Builder("org.onosproject.vtnweb.resources").build(); - } - -} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/FlowClassifierCodecTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/FlowClassifierCodecTest.java deleted file mode 100644 index be36aa83..00000000 --- a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/FlowClassifierCodecTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2015 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.vtnweb.web; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; - -import java.io.IOException; -import java.io.InputStream; - -import org.junit.Before; -import org.junit.Test; -import org.onosproject.codec.JsonCodec; -import org.onosproject.vtnrsc.FlowClassifier; -import org.onosproject.vtnrsc.FlowClassifierId; -import org.onosproject.vtnrsc.TenantId; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -/** - * Flow classifier codec unit tests. - */ -public class FlowClassifierCodecTest { - - SfcCodecContext context; - JsonCodec<FlowClassifier> flowClassifierCodec; - /** - * Sets up for each test. Creates a context and fetches the flow classifier - * codec. - */ - @Before - public void setUp() { - context = new SfcCodecContext(); - flowClassifierCodec = context.codec(FlowClassifier.class); - assertThat(flowClassifierCodec, notNullValue()); - } - - /** - * Reads in a flow classifier from the given resource and decodes it. - * - * @param resourceName resource to use to read the JSON for the flow classifier - * @return decoded flow classifier - * @throws IOException if processing the resource fails - */ - private FlowClassifier getFlowClassifier(String resourceName) throws IOException { - InputStream jsonStream = FlowClassifierCodecTest.class - .getResourceAsStream(resourceName); - ObjectMapper mapper = new ObjectMapper(); - JsonNode json = mapper.readTree(jsonStream); - assertThat(json, notNullValue()); - FlowClassifier flowClassifier = flowClassifierCodec.decode((ObjectNode) json, context); - assertThat(flowClassifier, notNullValue()); - return flowClassifier; - } - - /** - * Checks that a simple flow classifier decodes properly. - * - * @throws IOException if the resource cannot be processed - */ - @Test - public void codecFlowClassifierTest() throws IOException { - - FlowClassifier flowClassifier = getFlowClassifier("flowClassifier.json"); - - assertThat(flowClassifier, notNullValue()); - - FlowClassifierId flowClassifierId = FlowClassifierId.of("4a334cd4-fe9c-4fae-af4b-321c5e2eb051"); - TenantId tenantId = TenantId.tenantId("1814726e2d22407b8ca76db5e567dcf1"); - - assertThat(flowClassifier.flowClassifierId().toString(), is(flowClassifierId.toString())); - assertThat(flowClassifier.name(), is("flow1")); - assertThat(flowClassifier.tenantId().toString(), is(tenantId.toString())); - assertThat(flowClassifier.description(), is("flow classifier")); - assertThat(flowClassifier.protocol(), is("tcp")); - assertThat(flowClassifier.minSrcPortRange(), is(22)); - assertThat(flowClassifier.maxSrcPortRange(), is(4000)); - assertThat(flowClassifier.minDstPortRange(), is(80)); - assertThat(flowClassifier.maxDstPortRange(), is(80)); - - } -} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortChainCodecTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortChainCodecTest.java deleted file mode 100644 index 02681db3..00000000 --- a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortChainCodecTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2015 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.vtnweb.web; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; - -import java.io.IOException; -import java.io.InputStream; - -import org.junit.Before; -import org.junit.Test; -import org.onosproject.codec.JsonCodec; -import org.onosproject.vtnrsc.PortChain; -import org.onosproject.vtnrsc.PortChainId; -import org.onosproject.vtnrsc.TenantId; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -/** - * Flow rule codec unit tests. - */ -public class PortChainCodecTest { - - SfcCodecContext context; - JsonCodec<PortChain> portChainCodec; - /** - * Sets up for each test. Creates a context and fetches the flow rule - * codec. - */ - @Before - public void setUp() { - context = new SfcCodecContext(); - portChainCodec = context.codec(PortChain.class); - assertThat(portChainCodec, notNullValue()); - } - - /** - * Reads in a rule from the given resource and decodes it. - * - * @param resourceName resource to use to read the JSON for the rule - * @return decoded flow rule - * @throws IOException if processing the resource fails - */ - private PortChain getPortChain(String resourceName) throws IOException { - InputStream jsonStream = PortChainCodecTest.class - .getResourceAsStream(resourceName); - ObjectMapper mapper = new ObjectMapper(); - JsonNode json = mapper.readTree(jsonStream); - assertThat(json, notNullValue()); - PortChain portChain = portChainCodec.decode((ObjectNode) json, context); - assertThat(portChain, notNullValue()); - return portChain; - } - - /** - * Checks that a simple rule decodes properly. - * - * @throws IOException if the resource cannot be processed - */ - @Test - public void codecPortChainTest() throws IOException { - - PortChain portChain = getPortChain("portChain.json"); - - assertThat(portChain, notNullValue()); - - PortChainId portChainId = PortChainId.of("1278dcd4-459f-62ed-754b-87fc5e4a6751"); - TenantId tenantId = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5"); - - assertThat(portChain.portChainId().toString(), is(portChainId.toString())); - assertThat(portChain.name(), is("PC2")); - assertThat(portChain.tenantId().toString(), is(tenantId.toString())); - assertThat(portChain.description(), is("Two flows and two port-pair-groups")); - - assertThat(portChain.flowClassifiers(), notNullValue()); - assertThat(portChain.portPairGroups(), notNullValue()); - } -} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairCodecTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairCodecTest.java deleted file mode 100644 index 7651e098..00000000 --- a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairCodecTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2015 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.vtnweb.web; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; - -import java.io.IOException; -import java.io.InputStream; - -import org.junit.Before; -import org.junit.Test; -import org.onosproject.codec.JsonCodec; -import org.onosproject.vtnrsc.PortPair; -import org.onosproject.vtnrsc.PortPairId; -import org.onosproject.vtnrsc.TenantId; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -/** - * Port pair codec unit tests. - */ -public class PortPairCodecTest { - - SfcCodecContext context; - JsonCodec<PortPair> portPairCodec; - /** - * Sets up for each test. Creates a context and fetches the port pair - * codec. - */ - @Before - public void setUp() { - context = new SfcCodecContext(); - portPairCodec = context.codec(PortPair.class); - assertThat(portPairCodec, notNullValue()); - } - - /** - * Reads in a port pair from the given resource and decodes it. - * - * @param resourceName resource to use to read the JSON for the port pair - * @return decoded port pair - * @throws IOException if processing the resource fails - */ - private PortPair getPortPair(String resourceName) throws IOException { - InputStream jsonStream = PortPairCodecTest.class - .getResourceAsStream(resourceName); - ObjectMapper mapper = new ObjectMapper(); - JsonNode json = mapper.readTree(jsonStream); - assertThat(json, notNullValue()); - PortPair portPair = portPairCodec.decode((ObjectNode) json, context); - assertThat(portPair, notNullValue()); - return portPair; - } - - /** - * Checks that a simple port pair decodes properly. - * - * @throws IOException if the resource cannot be processed - */ - @Test - public void codecPortPairTest() throws IOException { - - PortPair portPair = getPortPair("portPair.json"); - - assertThat(portPair, notNullValue()); - - PortPairId portPairId = PortPairId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); - TenantId tenantId = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5"); - - assertThat(portPair.portPairId().toString(), is(portPairId.toString())); - assertThat(portPair.name(), is("PP1")); - assertThat(portPair.tenantId().toString(), is(tenantId.toString())); - assertThat(portPair.description(), is("SF-A")); - assertThat(portPair.ingress().toString(), is("dace4513-24fc-4fae-af4b-321c5e2eb3d1")); - assertThat(portPair.egress().toString(), is("aef3478a-4a56-2a6e-cd3a-9dee4e2ec345")); - } -} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairGroupCodecTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairGroupCodecTest.java deleted file mode 100644 index de2ee001..00000000 --- a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairGroupCodecTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2015 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.vtnweb.web; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; - -import java.io.IOException; -import java.io.InputStream; - -import org.junit.Before; -import org.junit.Test; -import org.onosproject.codec.JsonCodec; -import org.onosproject.vtnrsc.PortPairGroup; -import org.onosproject.vtnrsc.PortPairGroupId; -import org.onosproject.vtnrsc.TenantId; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -/** - * Flow rule codec unit tests. - */ -public class PortPairGroupCodecTest { - - SfcCodecContext context; - JsonCodec<PortPairGroup> portPairGroupCodec; - /** - * Sets up for each test. Creates a context and fetches the flow rule - * codec. - */ - @Before - public void setUp() { - context = new SfcCodecContext(); - portPairGroupCodec = context.codec(PortPairGroup.class); - assertThat(portPairGroupCodec, notNullValue()); - } - - /** - * Reads in a rule from the given resource and decodes it. - * - * @param resourceName resource to use to read the JSON for the rule - * @return decoded flow rule - * @throws IOException if processing the resource fails - */ - private PortPairGroup getPortPairGroup(String resourceName) throws IOException { - InputStream jsonStream = PortPairGroupCodecTest.class - .getResourceAsStream(resourceName); - ObjectMapper mapper = new ObjectMapper(); - JsonNode json = mapper.readTree(jsonStream); - assertThat(json, notNullValue()); - PortPairGroup portPairGroup = portPairGroupCodec.decode((ObjectNode) json, context); - assertThat(portPairGroup, notNullValue()); - return portPairGroup; - } - - /** - * Checks that a simple rule decodes properly. - * - * @throws IOException if the resource cannot be processed - */ - @Test - public void codecPortPairGroupTest() throws IOException { - - PortPairGroup portPairGroup = getPortPairGroup("portPairGroup.json"); - - assertThat(portPairGroup, notNullValue()); - - PortPairGroupId portPairGroupId = PortPairGroupId.of("4512d643-24fc-4fae-af4b-321c5e2eb3d1"); - TenantId tenantId = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5"); - - assertThat(portPairGroup.portPairGroupId().toString(), is(portPairGroupId.toString())); - assertThat(portPairGroup.name(), is("PG1")); - assertThat(portPairGroup.tenantId().toString(), is(tenantId.toString())); - assertThat(portPairGroup.description(), is("Two port-pairs")); - assertThat(portPairGroup.portPairs(), notNullValue()); - } -} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/SfcCodecContext.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/SfcCodecContext.java deleted file mode 100644 index c56a4fcb..00000000 --- a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/SfcCodecContext.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2015 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.vtnweb.web; - -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.CodecService; -import org.onosproject.codec.JsonCodec; -import org.onosproject.codec.impl.CodecManager; - -import com.fasterxml.jackson.databind.ObjectMapper; - -/** - * Mock codec context for use in codec unit tests. - */ -public class SfcCodecContext implements CodecContext { - - private final ObjectMapper mapper = new ObjectMapper(); - private final CodecManager codecManager = new CodecManager(); - private final VtnCodecRegistrator manager = new VtnCodecRegistrator(); - - /** - * Constructs a new mock codec context. - */ - public SfcCodecContext() { - codecManager.activate(); - manager.codecService = codecManager; - manager.activate(); - } - - @Override - public ObjectMapper mapper() { - return mapper; - } - - @SuppressWarnings("unchecked") - @Override - public <T> T getService(Class<T> serviceClass) { - // TODO - return null; - } - - @Override - public <T> JsonCodec<T> codec(Class<T> entityClass) { - return codecManager.getCodec(entityClass); - } - - /** - * Get the codec manager. - * - * @return instance of codec manager - */ - public CodecService codecManager() { - return codecManager; - } -} |