diff options
author | Rob Daugherty <rd472p@att.com> | 2018-09-10 17:45:52 -0400 |
---|---|---|
committer | Rob Daugherty <rd472p@att.com> | 2018-09-10 17:53:28 -0400 |
commit | 9e0219abc61b28b94d88fefbf8cc4a13d1683a67 (patch) | |
tree | 2e1e76e80bcea8c398d2a22851dce66680e68352 /quantum-model/src/test | |
parent | 77ba0e5627d39af1459cf3058fb521e68b475220 (diff) |
Functional so/libs unit tests
Unit tests to prepare for migration from the codehaus to the fasterxml
implementation of jackson.
Iincreases the code coverage metric from 51% to 70%.
Change-Id: I6338214f3de9df95956b46d4e313d00052eb8692
Issue-ID: SO-1011
Signed-off-by: Rob Daugherty <rd472p@att.com>
Diffstat (limited to 'quantum-model/src/test')
19 files changed, 1664 insertions, 368 deletions
diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/BindingTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/BindingTest.java new file mode 100644 index 0000000..b99c167 --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/BindingTest.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.Port.Binding; +import java.util.Map; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class BindingTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"binding:host_id\" : \"hostid\"," + EOL + + " \"binding:vif_type\" : \"viftype\"," + EOL + + " \"binding:vnic_type\" : \"vnictype\"," + EOL + + " \"binding:vif_details\" : {" + EOL + + " \"vifdetails-k1\" : \"vifdetails-v1\"," + EOL + + " \"vifdetails-k2\" : \"vifdetails-v2\"" + EOL + + " }," + EOL + + " \"binding:profile\" : {" + EOL + + " \"profile-k1\" : \"profile-v1\"," + EOL + + " \"profile-k2\" : \"profile-v2\"" + EOL + + " }" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Binding.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Binding binding = objectMapper.readValue(JSON_FULL, Binding.class); + String json = objectMapper.writeValueAsString(binding); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Binding binding = objectMapper.readValue(JSON_FULL, Binding.class); + binding.toString(); + + String vnicType = binding.getVnicType(); + Assert.assertNotNull(vnicType); + binding.setVnicType(vnicType); + + Map<String,String> vifDetails = binding.getVifDetails(); + Assert.assertNotNull(vifDetails); + Assert.assertEquals(2, vifDetails.size()); + binding.setVifDetails(vifDetails); + + Map<String,String> profile = binding.getProfile(); + Assert.assertNotNull(profile); + Assert.assertEquals(2, profile.size()); + binding.setProfile(profile); + + String hostId = binding.getHostId(); + Assert.assertNotNull(hostId); + binding.setHostId(hostId); + + String vifType = binding.getVifType(); + Assert.assertNotNull(vifType); + binding.setVifType(vifType); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/GatewayInfoTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/GatewayInfoTest.java new file mode 100644 index 0000000..3e8c37f --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/GatewayInfoTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.GatewayInfo; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class GatewayInfoTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"network_id\" : \"networkid\"" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + GatewayInfo.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + GatewayInfo gatewayinfo = objectMapper.readValue(JSON_FULL, GatewayInfo.class); + String json = objectMapper.writeValueAsString(gatewayinfo); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + GatewayInfo gatewayinfo = objectMapper.readValue(JSON_FULL, GatewayInfo.class); + gatewayinfo.toString(); + + String networkId = gatewayinfo.getNetworkId(); + Assert.assertNotNull(networkId); + gatewayinfo.setNetworkId(networkId); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/HostRouteTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/HostRouteTest.java new file mode 100644 index 0000000..bfa7280 --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/HostRouteTest.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.HostRoute; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class HostRouteTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"destination\" : \"destination\"," + EOL + + " \"nexthop\" : \"nexthop\"" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + HostRoute.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + HostRoute hostroute = objectMapper.readValue(JSON_FULL, HostRoute.class); + String json = objectMapper.writeValueAsString(hostroute); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + HostRoute hostroute = objectMapper.readValue(JSON_FULL, HostRoute.class); + hostroute.toString(); + + String destination = hostroute.getDestination(); + Assert.assertNotNull(destination); + hostroute.setDestination(destination); + + String nexthop = hostroute.getNexthop(); + Assert.assertNotNull(nexthop); + hostroute.setNexthop(nexthop); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/IpTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/IpTest.java new file mode 100644 index 0000000..79fbff5 --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/IpTest.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.Port.Ip; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class IpTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"ip_address\" : \"address\"," + EOL + + " \"subnet_id\" : \"subnetid\"" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Ip.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Ip ip = objectMapper.readValue(JSON_FULL, Ip.class); + String json = objectMapper.writeValueAsString(ip); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Ip ip = objectMapper.readValue(JSON_FULL, Ip.class); + ip.toString(); + + String subnetId = ip.getSubnetId(); + Assert.assertNotNull(subnetId); + ip.setSubnetId(subnetId); + + String address = ip.getAddress(); + Assert.assertNotNull(address); + ip.setAddress(address); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/IpVersionTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/IpVersionTest.java new file mode 100644 index 0000000..b2a8604 --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/IpVersionTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.Subnet.IpVersion; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class IpVersionTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "4"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + IpVersion.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + IpVersion ipversion = objectMapper.readValue(JSON_FULL, IpVersion.class); + String json = objectMapper.writeValueAsString(ipversion); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + IpVersion ipversion = objectMapper.readValue(JSON_FULL, IpVersion.class); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/NetworkTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/NetworkTest.java index e736359..b9d5b37 100644 --- a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/NetworkTest.java +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/NetworkTest.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. - * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * 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 @@ -20,120 +20,101 @@ package com.woorea.openstack.quantum.model; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.hasItem; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; - +import com.woorea.openstack.quantum.model.Network; +import com.woorea.openstack.quantum.model.Segment; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Before; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class NetworkTest { - private static final String ID = "testId"; - - private static final boolean ADMIN_STATE_UP = true; - - private static final String NAME = "name"; - - private static final String TENANT_ID = "tenantId"; - - private static final String SHARED = "shared"; - - private static final String STATUS = "status"; - - private static final String SUBNET = "subnet"; - - private static final String PROVIDER_NETWORK_TYPE = "vlan"; - - private static final String PROVIDER_PHYSICAL_NETWORK = "physicalNetwork"; - - private static final int PROVIDER_SEGMENTATION_ID = 100; - - private static final String ROUTER_EXTERNAL = "routerExternal"; - - /** - * JSON with read only attributes. - */ - private static final String NETWORK_JSON = "{" - + " \"network\" : {" - + " \"id\" : \"" + ID + "\"," - + " \"status\" : \"" + STATUS + "\"," - + " \"subnets\" : [ \"" + SUBNET + "\" ]" - + " }" - + "}"; - - private ObjectMapper objectMapper; - - private String serializedNetwork; - - @Before - public void setUp() throws Exception { - objectMapper = PortTest.initializeObjectMapper(); - } + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"network\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"shared\" : \"shared\"," + EOL + + " \"segments\" : [ {" + EOL + + " \"provider:physical_network\" : \"providerphysicalnetwork\"," + EOL + + " \"provider:network_type\" : \"providernetworktype\"," + EOL + + " \"provider:segmentation_id\" : 92" + EOL + + " }, {" + EOL + + " \"provider:physical_network\" : \"providerphysicalnetwork\"," + EOL + + " \"provider:network_type\" : \"providernetworktype\"," + EOL + + " \"provider:segmentation_id\" : 92" + EOL + + " } ]," + EOL + + " \"admin_state_up\" : false," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"provider:physical_network\" : \"providerphysicalnetwork\"," + EOL + + " \"provider:network_type\" : \"providernetworktype\"," + EOL + + " \"provider:segmentation_id\" : 92," + EOL + + " \"router:external\" : \"routerexternal\"" + EOL + + " }" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test public void testSerialization() throws Exception { - Network network = new Network(); - network.setId(ID); - network.setProviderNetworkType(PROVIDER_NETWORK_TYPE); - network.setProviderPhysicalNetwork(PROVIDER_PHYSICAL_NETWORK); - network.setProviderSegmentationId(PROVIDER_SEGMENTATION_ID); - network.setAdminStateUp(ADMIN_STATE_UP); - network.setSubnets(Arrays.asList(SUBNET)); - network.setRouterExternal(ROUTER_EXTERNAL); - network.setName(NAME); - network.setShared(SHARED); - network.setTenantId(TENANT_ID); - - serializedNetwork = objectMapper.writeValueAsString(network); - assertThat(serializedNetwork, not(containsString(ID))); - assertThat(serializedNetwork, not(containsString(STATUS))); - assertThat(serializedNetwork, not(containsString(SUBNET))); - assertThat(serializedNetwork, containsString("\"admin_state_up\" : " + ADMIN_STATE_UP)); - assertThat(serializedNetwork, containsString(NAME)); - assertThat(serializedNetwork, containsString(SHARED)); - assertThat(serializedNetwork, containsString(TENANT_ID)); - assertThat(serializedNetwork, containsString(ROUTER_EXTERNAL)); - assertThat(serializedNetwork, containsString(PROVIDER_NETWORK_TYPE)); - assertThat(serializedNetwork, containsString(PROVIDER_PHYSICAL_NETWORK)); - assertThat(serializedNetwork, containsString(Integer.toString(PROVIDER_SEGMENTATION_ID))); - } - - @Test - public void testSerializationEmpty() throws Exception { - Network network = new Network(); - serializedNetwork = objectMapper.writeValueAsString(network); - - assertThat(serializedNetwork, containsString("\"network\" : { }")); + System.out.println("CLASS: " + Network.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Network network = objectMapper.readValue(JSON_FULL, Network.class); + String json = objectMapper.writeValueAsString(network); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void testDeserializationReadOnlyFields() throws Exception { - Network network = objectMapper.readValue(NETWORK_JSON, Network.class); - - assertThat(network.getId(), is(equalTo(ID))); - assertThat(network.getSubnets(), hasItem(equalTo(SUBNET))); - assertThat(network.getStatus(), is(equalTo(STATUS))); - } - - @Test - public void testDeserialization() throws Exception { - testSerialization(); - Network network = objectMapper.readValue(serializedNetwork, Network.class); - - assertThat(network.getName(), is(equalTo(NAME))); - assertThat(network.isAdminStateUp(), is(equalTo(ADMIN_STATE_UP))); - assertThat(network.getShared(), is(equalTo(SHARED))); - assertThat(network.getTenantId(), is(equalTo(TENANT_ID))); - assertThat(network.getRouterExternal(), is(equalTo(ROUTER_EXTERNAL))); - assertThat(network.getProviderNetworkType(), is(equalTo(PROVIDER_NETWORK_TYPE))); - assertThat(network.getProviderPhysicalNetwork(), is(equalTo(PROVIDER_PHYSICAL_NETWORK))); - assertThat(network.getProviderSegmentationId(), is(equalTo(PROVIDER_SEGMENTATION_ID))); + public void testMethods() throws Exception { + Network network = objectMapper.readValue(JSON_FULL, Network.class); + network.toString(); + + String shared = network.getShared(); + Assert.assertNotNull(shared); + network.setShared(shared); + + String providerNetworkType = network.getProviderNetworkType(); + Assert.assertNotNull(providerNetworkType); + network.setProviderNetworkType(providerNetworkType); + + String routerExternal = network.getRouterExternal(); + Assert.assertNotNull(routerExternal); + network.setRouterExternal(routerExternal); + + Integer providerSegmentationId = network.getProviderSegmentationId(); + Assert.assertNotNull(providerSegmentationId); + network.setProviderSegmentationId(providerSegmentationId); + + List<Segment> segments = network.getSegments(); + Assert.assertNotNull(segments); + Assert.assertEquals(2, segments.size()); + network.setSegments(segments); + + Boolean adminStateUp = network.getAdminStateUp(); + Assert.assertNotNull(adminStateUp); + network.setAdminStateUp(adminStateUp); + + String tenantId = network.getTenantId(); + Assert.assertNotNull(tenantId); + network.setTenantId(tenantId); + + String name = network.getName(); + Assert.assertNotNull(name); + network.setName(name); + + String providerPhysicalNetwork = network.getProviderPhysicalNetwork(); + Assert.assertNotNull(providerPhysicalNetwork); + network.setProviderPhysicalNetwork(providerPhysicalNetwork); } } diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/NetworksTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/NetworksTest.java new file mode 100644 index 0000000..dd39cf5 --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/NetworksTest.java @@ -0,0 +1,110 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.Network; +import com.woorea.openstack.quantum.model.Networks; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class NetworksTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"networks\" : [ {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"shared\" : \"shared\"," + EOL + + " \"segments\" : [ {" + EOL + + " \"provider:physical_network\" : \"providerphysicalnetwork\"," + EOL + + " \"provider:network_type\" : \"providernetworktype\"," + EOL + + " \"provider:segmentation_id\" : 92" + EOL + + " }, {" + EOL + + " \"provider:physical_network\" : \"providerphysicalnetwork\"," + EOL + + " \"provider:network_type\" : \"providernetworktype\"," + EOL + + " \"provider:segmentation_id\" : 92" + EOL + + " } ]," + EOL + + " \"admin_state_up\" : false," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"provider:physical_network\" : \"providerphysicalnetwork\"," + EOL + + " \"provider:network_type\" : \"providernetworktype\"," + EOL + + " \"provider:segmentation_id\" : 92," + EOL + + " \"router:external\" : \"routerexternal\"" + EOL + + " }, {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"shared\" : \"shared\"," + EOL + + " \"segments\" : [ {" + EOL + + " \"provider:physical_network\" : \"providerphysicalnetwork\"," + EOL + + " \"provider:network_type\" : \"providernetworktype\"," + EOL + + " \"provider:segmentation_id\" : 92" + EOL + + " }, {" + EOL + + " \"provider:physical_network\" : \"providerphysicalnetwork\"," + EOL + + " \"provider:network_type\" : \"providernetworktype\"," + EOL + + " \"provider:segmentation_id\" : 92" + EOL + + " } ]," + EOL + + " \"admin_state_up\" : false," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"provider:physical_network\" : \"providerphysicalnetwork\"," + EOL + + " \"provider:network_type\" : \"providernetworktype\"," + EOL + + " \"provider:segmentation_id\" : 92," + EOL + + " \"router:external\" : \"routerexternal\"" + EOL + + " } ]" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Networks.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Networks networks = objectMapper.readValue(JSON_FULL, Networks.class); + String json = objectMapper.writeValueAsString(networks); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Networks networks = objectMapper.readValue(JSON_FULL, Networks.class); + networks.toString(); + + List<Network> list = networks.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + networks.setList(list); + + int cnt = 0; + for (@SuppressWarnings("unused") Network x : networks) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/NeutronErrorTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/NeutronErrorTest.java new file mode 100644 index 0000000..a0031ee --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/NeutronErrorTest.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.NeutronError; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class NeutronErrorTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"NeutronError\" : {" + EOL + + " \"type\" : \"type\"," + EOL + + " \"message\" : \"message\"," + EOL + + " \"detail\" : \"detail\"" + EOL + + " }" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + NeutronError.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + NeutronError neutronerror = objectMapper.readValue(JSON_FULL, NeutronError.class); + String json = objectMapper.writeValueAsString(neutronerror); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + NeutronError neutronerror = objectMapper.readValue(JSON_FULL, NeutronError.class); + neutronerror.toString(); + + String detail = neutronerror.getDetail(); + Assert.assertNotNull(detail); + + String type = neutronerror.getType(); + Assert.assertNotNull(type); + + String message = neutronerror.getMessage(); + Assert.assertNotNull(message); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/PoolTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/PoolTest.java new file mode 100644 index 0000000..c2cf38e --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/PoolTest.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.Pool; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class PoolTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"start\" : \"start\"," + EOL + + " \"end\" : \"end\"" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Pool.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Pool pool = objectMapper.readValue(JSON_FULL, Pool.class); + String json = objectMapper.writeValueAsString(pool); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Pool pool = objectMapper.readValue(JSON_FULL, Pool.class); + pool.toString(); + + String start = pool.getStart(); + Assert.assertNotNull(start); + pool.setStart(start); + + String end = pool.getEnd(); + Assert.assertNotNull(end); + pool.setEnd(end); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/PortTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/PortTest.java index 7baa8d9..756753d 100644 --- a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/PortTest.java +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/PortTest.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. - * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * 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 @@ -20,156 +20,116 @@ package com.woorea.openstack.quantum.model; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.hasItem; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertThat; - -import java.util.ArrayList; -import java.util.Arrays; +import com.woorea.openstack.quantum.model.Port; +import com.woorea.openstack.quantum.model.Port.Binding; +import com.woorea.openstack.quantum.model.Port.Ip; import java.util.List; - import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.SerializationConfig; import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; -import org.hamcrest.CustomMatcher; -import org.junit.Before; +import org.junit.Assert; import org.junit.Test; - -import com.woorea.openstack.quantum.model.Port.Ip; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class PortTest { - private static final String TENANT_ID = "tenantId"; - - private static final String STATUS = "status"; - - private static final String NETWORK_ID = "networkId"; - - private static final String NAME = "name"; - - private static final String MAC_ADDRESS = "macAddress"; - - private static final String DEVICE_OWNER = "deviceOwner"; - - private static final String DEVICE_ID = "deviceId"; - - private static final String IP_SUBNET_ID = "ipSubnetId"; - - private static final String IP_ADDRESS = "10.0.0.1"; - - private static final boolean ADMIN_STATE_UP = true; - - private static final String SEC_GROUP = "secGroup"; - - private static final String ID = "testId"; - - /** - * JSON with read only attributes. - */ - private static final String PORT_JSON = "{" - + " \"port\" : {" - + " \"id\" : \"" + ID + "\"," - + " \"status\" : \"" + STATUS + "\"" - + " }" - + "}"; - - private ObjectMapper objectMapper; - - private String serializedPort; - - @Before - public void setUp() throws Exception { - objectMapper = initializeObjectMapper(); - } - - public static ObjectMapper initializeObjectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(Inclusion.NON_NULL) - .enable(SerializationConfig.Feature.INDENT_OUTPUT) - .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) - .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) - .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); - return objectMapper; - } + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"port\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"binding:host_id\" : \"hostid\"," + EOL + + " \"binding:vif_type\" : \"viftype\"," + EOL + + " \"binding:vnic_type\" : \"vnictype\"," + EOL + + " \"binding:vif_details\" : {" + EOL + + " \"vifdetails-k1\" : \"vifdetails-v1\"," + EOL + + " \"vifdetails-k2\" : \"vifdetails-v2\"" + EOL + + " }," + EOL + + " \"binding:profile\" : {" + EOL + + " \"profile-k1\" : \"profile-v1\"," + EOL + + " \"profile-k2\" : \"profile-v2\"" + EOL + + " }," + EOL + + " \"admin_state_up\" : false," + EOL + + " \"device_id\" : \"deviceid\"," + EOL + + " \"device_owner\" : \"deviceowner\"," + EOL + + " \"fixed_ips\" : [ {" + EOL + + " \"ip_address\" : \"address\"," + EOL + + " \"subnet_id\" : \"subnetid\"" + EOL + + " }, {" + EOL + + " \"ip_address\" : \"address\"," + EOL + + " \"subnet_id\" : \"subnetid\"" + EOL + + " } ]," + EOL + + " \"mac_address\" : \"macaddress\"," + EOL + + " \"network_id\" : \"networkid\"," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"security_groups\" : [ \"securitygroups-v1\", \"securitygroups-v2\" ]" + EOL + + " }" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test public void testSerialization() throws Exception { - Port port = new Port(); - port.setId(ID); - port.setAdminStateUp(ADMIN_STATE_UP); - port.setSecurityGroups(Arrays.asList(SEC_GROUP)); - port.setDeviceId(DEVICE_ID); - port.setDeviceOwner(DEVICE_OWNER); - port.setMacAddress(MAC_ADDRESS); - port.setName(NAME); - port.setNetworkId(NETWORK_ID); - port.setStatus(STATUS); - port.setTenantId(TENANT_ID); - - List<Ip> ips = new ArrayList<Port.Ip>(); - Ip ip = new Ip(); - ip.setAddress(IP_ADDRESS); - ip.setSubnetId(IP_SUBNET_ID); - ips.add(ip); - port.setList(ips); - - serializedPort = objectMapper.writeValueAsString(port); - assertThat(serializedPort, not(containsString(ID))); - assertThat(serializedPort, not(containsString(STATUS))); - assertThat(serializedPort, containsString("\"admin_state_up\" : " + ADMIN_STATE_UP)); - assertThat(serializedPort, containsString(SEC_GROUP)); - assertThat(serializedPort, containsString(IP_ADDRESS)); - assertThat(serializedPort, containsString(DEVICE_ID)); - assertThat(serializedPort, containsString(DEVICE_OWNER)); - assertThat(serializedPort, containsString(MAC_ADDRESS)); - assertThat(serializedPort, containsString(NAME)); - assertThat(serializedPort, containsString(NETWORK_ID)); - assertThat(serializedPort, containsString(TENANT_ID)); - } - - @Test - public void testSerializationEmpty() throws Exception { - Port port = new Port(); - serializedPort = objectMapper.writeValueAsString(port); - - assertThat(serializedPort, containsString("\"port\" : { }")); + System.out.println("CLASS: " + Port.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Port port = objectMapper.readValue(JSON_FULL, Port.class); + String json = objectMapper.writeValueAsString(port); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void testDeserializationReadOnlyFields() throws Exception { - Port port = objectMapper.readValue(PORT_JSON, Port.class); - - assertThat(port.getId(), is(equalTo(ID))); - assertThat(port.getStatus(), is(equalTo(STATUS))); - } - - @Test - public void testDeserializationAfterSerialization() throws Exception { - testSerialization(); - Port port = objectMapper.readValue(serializedPort, Port.class); - - assertThat(port.getAdminStateUp(), is(equalTo(ADMIN_STATE_UP))); - assertThat(port.getDeviceId(), is(equalTo(DEVICE_ID))); - assertThat(port.getDeviceOwner(), is(equalTo(DEVICE_OWNER))); - assertThat(port.getMacAddress(), is(equalTo(MAC_ADDRESS))); - assertThat(port.getName(), is(equalTo(NAME))); - assertThat(port.getNetworkId(), is(equalTo(NETWORK_ID))); - assertThat(port.getTenantId(), is(equalTo(TENANT_ID))); - - assertThat(port.getSecurityGroups(), hasItem(equalTo(SEC_GROUP))); - assertThat(port.getList(), hasItem(new CustomMatcher<Ip>( - "an Ip object with address " + IP_ADDRESS + " and subnet id " + IP_SUBNET_ID) { - - @Override - public boolean matches(Object ip) { - return ip instanceof Ip - && IP_ADDRESS.equals(((Ip) ip).getAddress()) - && IP_SUBNET_ID.equals(((Ip) ip).getSubnetId()); - } - })); + public void testMethods() throws Exception { + Port port = objectMapper.readValue(JSON_FULL, Port.class); + port.toString(); + + String deviceOwner = port.getDeviceOwner(); + Assert.assertNotNull(deviceOwner); + port.setDeviceOwner(deviceOwner); + + Boolean adminStateUp = port.getAdminStateUp(); + Assert.assertNotNull(adminStateUp); + port.setAdminStateUp(adminStateUp); + + String name = port.getName(); + Assert.assertNotNull(name); + port.setName(name); + + String tenantId = port.getTenantId(); + Assert.assertNotNull(tenantId); + port.setTenantId(tenantId); + + Binding binding = port.getBinding(); + Assert.assertNotNull(binding); + port.setBinding(binding); + + String macAddress = port.getMacAddress(); + Assert.assertNotNull(macAddress); + port.setMacAddress(macAddress); + + String networkId = port.getNetworkId(); + Assert.assertNotNull(networkId); + port.setNetworkId(networkId); + + List<Ip> list = port.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + port.setList(list); + + List<String> securityGroups = port.getSecurityGroups(); + Assert.assertNotNull(securityGroups); + Assert.assertEquals(2, securityGroups.size()); + port.setSecurityGroups(securityGroups); + + String deviceId = port.getDeviceId(); + Assert.assertNotNull(deviceId); + port.setDeviceId(deviceId); } } diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/PortsTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/PortsTest.java new file mode 100644 index 0000000..860ea7c --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/PortsTest.java @@ -0,0 +1,128 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.Port; +import com.woorea.openstack.quantum.model.Ports; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class PortsTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"ports\" : [ {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"binding:host_id\" : \"hostid\"," + EOL + + " \"binding:vif_type\" : \"viftype\"," + EOL + + " \"binding:vnic_type\" : \"vnictype\"," + EOL + + " \"binding:vif_details\" : {" + EOL + + " \"vifdetails-k1\" : \"vifdetails-v1\"," + EOL + + " \"vifdetails-k2\" : \"vifdetails-v2\"" + EOL + + " }," + EOL + + " \"binding:profile\" : {" + EOL + + " \"profile-k1\" : \"profile-v1\"," + EOL + + " \"profile-k2\" : \"profile-v2\"" + EOL + + " }," + EOL + + " \"admin_state_up\" : false," + EOL + + " \"device_id\" : \"deviceid\"," + EOL + + " \"device_owner\" : \"deviceowner\"," + EOL + + " \"fixed_ips\" : [ {" + EOL + + " \"ip_address\" : \"address\"," + EOL + + " \"subnet_id\" : \"subnetid\"" + EOL + + " }, {" + EOL + + " \"ip_address\" : \"address\"," + EOL + + " \"subnet_id\" : \"subnetid\"" + EOL + + " } ]," + EOL + + " \"mac_address\" : \"macaddress\"," + EOL + + " \"network_id\" : \"networkid\"," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"security_groups\" : [ \"securitygroups-v1\", \"securitygroups-v2\" ]" + EOL + + " }, {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"binding:host_id\" : \"hostid\"," + EOL + + " \"binding:vif_type\" : \"viftype\"," + EOL + + " \"binding:vnic_type\" : \"vnictype\"," + EOL + + " \"binding:vif_details\" : {" + EOL + + " \"vifdetails-k1\" : \"vifdetails-v1\"," + EOL + + " \"vifdetails-k2\" : \"vifdetails-v2\"" + EOL + + " }," + EOL + + " \"binding:profile\" : {" + EOL + + " \"profile-k1\" : \"profile-v1\"," + EOL + + " \"profile-k2\" : \"profile-v2\"" + EOL + + " }," + EOL + + " \"admin_state_up\" : false," + EOL + + " \"device_id\" : \"deviceid\"," + EOL + + " \"device_owner\" : \"deviceowner\"," + EOL + + " \"fixed_ips\" : [ {" + EOL + + " \"ip_address\" : \"address\"," + EOL + + " \"subnet_id\" : \"subnetid\"" + EOL + + " }, {" + EOL + + " \"ip_address\" : \"address\"," + EOL + + " \"subnet_id\" : \"subnetid\"" + EOL + + " } ]," + EOL + + " \"mac_address\" : \"macaddress\"," + EOL + + " \"network_id\" : \"networkid\"," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"security_groups\" : [ \"securitygroups-v1\", \"securitygroups-v2\" ]" + EOL + + " } ]" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Ports.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Ports ports = objectMapper.readValue(JSON_FULL, Ports.class); + String json = objectMapper.writeValueAsString(ports); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Ports ports = objectMapper.readValue(JSON_FULL, Ports.class); + ports.toString(); + + List<Port> list = ports.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + ports.setList(list); + + int cnt = 0; + for (@SuppressWarnings("unused") Port x : ports) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterForAddInterfaceTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterForAddInterfaceTest.java new file mode 100644 index 0000000..148637f --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterForAddInterfaceTest.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.RouterForAddInterface; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class RouterForAddInterfaceTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"routerId\" : \"routerid\"," + EOL + + " \"subnet_id\" : \"subnetid\"" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + RouterForAddInterface.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + RouterForAddInterface routerforaddinterface = objectMapper.readValue(JSON_FULL, RouterForAddInterface.class); + String json = objectMapper.writeValueAsString(routerforaddinterface); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + RouterForAddInterface routerforaddinterface = objectMapper.readValue(JSON_FULL, RouterForAddInterface.class); + routerforaddinterface.toString(); + + String subnetId = routerforaddinterface.getSubnetId(); + Assert.assertNotNull(subnetId); + routerforaddinterface.setSubnetId(subnetId); + + String routerId = routerforaddinterface.getRouterId(); + Assert.assertNotNull(routerId); + routerforaddinterface.setRouterId(routerId); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterForCreateTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterForCreateTest.java new file mode 100644 index 0000000..f7df840 --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterForCreateTest.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.GatewayInfo; +import com.woorea.openstack.quantum.model.HostRoute; +import com.woorea.openstack.quantum.model.RouterForCreate; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class RouterForCreateTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"router\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"routes\" : [ {" + EOL + + " \"destination\" : \"destination\"," + EOL + + " \"nexthop\" : \"nexthop\"" + EOL + + " }, {" + EOL + + " \"destination\" : \"destination\"," + EOL + + " \"nexthop\" : \"nexthop\"" + EOL + + " } ]," + EOL + + " \"admin_state_up\" : \"admin_state_up\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"id\" : \"id\"," + EOL + + " \"external_gateway_info\" : {" + EOL + + " \"network_id\" : \"networkid\"" + EOL + + " }," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + RouterForCreate.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + RouterForCreate routerforcreate = objectMapper.readValue(JSON_FULL, RouterForCreate.class); + String json = objectMapper.writeValueAsString(routerforcreate); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + RouterForCreate routerforcreate = objectMapper.readValue(JSON_FULL, RouterForCreate.class); + routerforcreate.toString(); + + List<HostRoute> routes = routerforcreate.getRoutes(); + Assert.assertNotNull(routes); + Assert.assertEquals(2, routes.size()); + routerforcreate.setRoutes(routes); + + String admin_state_up = routerforcreate.getAdmin_state_up(); + Assert.assertNotNull(admin_state_up); + routerforcreate.setAdmin_state_up(admin_state_up); + + String name = routerforcreate.getName(); + Assert.assertNotNull(name); + routerforcreate.setName(name); + + String tenantId = routerforcreate.getTenantId(); + Assert.assertNotNull(tenantId); + routerforcreate.setTenantId(tenantId); + + GatewayInfo externalGatewayInfo = routerforcreate.getExternalGatewayInfo(); + Assert.assertNotNull(externalGatewayInfo); + routerforcreate.setExternalGatewayInfo(externalGatewayInfo); + + String id = routerforcreate.getId(); + Assert.assertNotNull(id); + routerforcreate.setId(id); + + String status = routerforcreate.getStatus(); + Assert.assertNotNull(status); + routerforcreate.setStatus(status); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterInterfaceTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterInterfaceTest.java new file mode 100644 index 0000000..24713b7 --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterInterfaceTest.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.RouterInterface; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class RouterInterfaceTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"id\" : \"id\"," + EOL + + " \"subnet_id\" : \"subnetid\"," + EOL + + " \"port_id\" : \"portid\"," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + RouterInterface.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + RouterInterface routerinterface = objectMapper.readValue(JSON_FULL, RouterInterface.class); + String json = objectMapper.writeValueAsString(routerinterface); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + RouterInterface routerinterface = objectMapper.readValue(JSON_FULL, RouterInterface.class); + routerinterface.toString(); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterTest.java new file mode 100644 index 0000000..2ad549c --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RouterTest.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.GatewayInfo; +import com.woorea.openstack.quantum.model.HostRoute; +import com.woorea.openstack.quantum.model.Router; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class RouterTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"router\" : {" + EOL + + " \"status\" : \"status\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"admin_state_up\" : \"admin_state_up\"," + EOL + + " \"id\" : \"id\"," + EOL + + " \"routes\" : [ {" + EOL + + " \"destination\" : \"destination\"," + EOL + + " \"nexthop\" : \"nexthop\"" + EOL + + " }, {" + EOL + + " \"destination\" : \"destination\"," + EOL + + " \"nexthop\" : \"nexthop\"" + EOL + + " } ]," + EOL + + " \"external_gateway_info\" : {" + EOL + + " \"network_id\" : \"networkid\"" + EOL + + " }," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Router.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Router router = objectMapper.readValue(JSON_FULL, Router.class); + String json = objectMapper.writeValueAsString(router); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Router router = objectMapper.readValue(JSON_FULL, Router.class); + router.toString(); + + List<HostRoute> routes = router.getRoutes(); + Assert.assertNotNull(routes); + Assert.assertEquals(2, routes.size()); + router.setRoutes(routes); + + String admin_state_up = router.getAdmin_state_up(); + Assert.assertNotNull(admin_state_up); + router.setAdmin_state_up(admin_state_up); + + String name = router.getName(); + Assert.assertNotNull(name); + router.setName(name); + + String tenantId = router.getTenantId(); + Assert.assertNotNull(tenantId); + router.setTenantId(tenantId); + + GatewayInfo externalGatewayInfo = router.getExternalGatewayInfo(); + Assert.assertNotNull(externalGatewayInfo); + router.setExternalGatewayInfo(externalGatewayInfo); + + String id = router.getId(); + Assert.assertNotNull(id); + router.setId(id); + + String status = router.getStatus(); + Assert.assertNotNull(status); + router.setStatus(status); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RoutersTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RoutersTest.java new file mode 100644 index 0000000..ad955c8 --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/RoutersTest.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.Router; +import com.woorea.openstack.quantum.model.Routers; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class RoutersTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"routers\" : [ {" + EOL + + " \"status\" : \"status\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"admin_state_up\" : \"admin_state_up\"," + EOL + + " \"id\" : \"id\"," + EOL + + " \"routes\" : [ {" + EOL + + " \"destination\" : \"destination\"," + EOL + + " \"nexthop\" : \"nexthop\"" + EOL + + " }, {" + EOL + + " \"destination\" : \"destination\"," + EOL + + " \"nexthop\" : \"nexthop\"" + EOL + + " } ]," + EOL + + " \"external_gateway_info\" : {" + EOL + + " \"network_id\" : \"networkid\"" + EOL + + " }," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }, {" + EOL + + " \"status\" : \"status\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"admin_state_up\" : \"admin_state_up\"," + EOL + + " \"id\" : \"id\"," + EOL + + " \"routes\" : [ {" + EOL + + " \"destination\" : \"destination\"," + EOL + + " \"nexthop\" : \"nexthop\"" + EOL + + " }, {" + EOL + + " \"destination\" : \"destination\"," + EOL + + " \"nexthop\" : \"nexthop\"" + EOL + + " } ]," + EOL + + " \"external_gateway_info\" : {" + EOL + + " \"network_id\" : \"networkid\"" + EOL + + " }," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " } ]" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Routers.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Routers routers = objectMapper.readValue(JSON_FULL, Routers.class); + String json = objectMapper.writeValueAsString(routers); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Routers routers = objectMapper.readValue(JSON_FULL, Routers.class); + routers.toString(); + + List<Router> list = routers.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + routers.setList(list); + + int cnt = 0; + for (@SuppressWarnings("unused") Router x : routers) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/SegmentTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/SegmentTest.java new file mode 100644 index 0000000..9bc7fd7 --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/SegmentTest.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.Segment; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class SegmentTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"provider:physical_network\" : \"providerphysicalnetwork\"," + EOL + + " \"provider:network_type\" : \"providernetworktype\"," + EOL + + " \"provider:segmentation_id\" : 92" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Segment.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Segment segment = objectMapper.readValue(JSON_FULL, Segment.class); + String json = objectMapper.writeValueAsString(segment); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Segment segment = objectMapper.readValue(JSON_FULL, Segment.class); + segment.toString(); + + String providerNetworkType = segment.getProviderNetworkType(); + Assert.assertNotNull(providerNetworkType); + segment.setProviderNetworkType(providerNetworkType); + + Integer providerSegmentationId = segment.getProviderSegmentationId(); + Assert.assertNotNull(providerSegmentationId); + segment.setProviderSegmentationId(providerSegmentationId); + + String providerPhysicalNetwork = segment.getProviderPhysicalNetwork(); + Assert.assertNotNull(providerPhysicalNetwork); + segment.setProviderPhysicalNetwork(providerPhysicalNetwork); + } +} diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/SubnetTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/SubnetTest.java index db27bf2..5e1c7e1 100644 --- a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/SubnetTest.java +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/SubnetTest.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved. - * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * 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 @@ -20,138 +20,107 @@ package com.woorea.openstack.quantum.model; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.hasItem; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; - +import com.woorea.openstack.quantum.model.Pool; +import com.woorea.openstack.quantum.model.Subnet; +import com.woorea.openstack.quantum.model.Subnet.IpVersion; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; -import org.hamcrest.CustomMatcher; -import org.junit.Before; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; - -import com.woorea.openstack.quantum.model.Subnet.IpVersion; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class SubnetTest { - private static final String POOL_END = "poolEnd"; - - private static final String POOL_START = "poolStart"; - - private static final String TENANT_ID = "tenantId"; - - private static final String NETWORK_ID = "networkId"; - - private static final String NAME = "name"; - - private static final String HOST_ROUTE = "hostRoute"; - - private static final String GATEWAY = "gw"; - - private static final boolean ENABLE_DHCP = true; - - private static final String ID = "testId"; - - private static final String CIDR = "10.0.0.0/8"; - - private static final String DNS_SERVER = "dnsServer"; - - private static final IpVersion IP_VERSION = IpVersion.IPV4; - - /** - * JSON with read only attributes. - */ - private static final String SUBNET_JSON = "{" - + " \"subnet\" : {" - + " \"id\" : \"" + ID + "\"" - + " }" - + "}"; - - private ObjectMapper objectMapper; - - private String serializedSubnet; - - @Before - public void setUp() throws Exception { - objectMapper = PortTest.initializeObjectMapper(); - } + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"subnet\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"cidr\" : \"cidr\"," + EOL + + " \"enable_dhcp\" : true," + EOL + + " \"network_id\" : \"networkid\"," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"dns_nameservers\" : [ \"dnsnames-v1\", \"dnsnames-v2\" ]," + EOL + + " \"allocation_pools\" : [ {" + EOL + + " \"start\" : \"start\"," + EOL + + " \"end\" : \"end\"" + EOL + + " }, {" + EOL + + " \"start\" : \"start\"," + EOL + + " \"end\" : \"end\"" + EOL + + " } ]," + EOL + + " \"host_routes\" : [ \"hostroutes-v1\", \"hostroutes-v2\" ]," + EOL + + " \"ip_version\" : 4," + EOL + + " \"gateway_ip\" : \"gw\"" + EOL + + " }" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test public void testSerialization() throws Exception { - Subnet subnet = new Subnet(); - subnet.setId(ID); - subnet.setCidr(CIDR); - subnet.setDnsNames(Arrays.asList(DNS_SERVER)); - subnet.setEnableDHCP(ENABLE_DHCP); - subnet.setIpversion(IP_VERSION); - subnet.setGw(GATEWAY); - subnet.setHostRoutes(Arrays.asList(HOST_ROUTE)); - subnet.setName(NAME); - subnet.setNetworkId(NETWORK_ID); - subnet.setTenantId(TENANT_ID); - - Pool pool = new Pool(); - pool.setStart(POOL_START); - pool.setEnd(POOL_END); - subnet.setList(Arrays.asList(pool)); - - serializedSubnet = objectMapper.writeValueAsString(subnet); - assertThat(serializedSubnet, not(containsString(ID))); - assertThat(serializedSubnet, containsString(CIDR)); - assertThat(serializedSubnet, containsString(DNS_SERVER)); - assertThat(serializedSubnet, containsString("\"enable_dhcp\" : " + ENABLE_DHCP)); - assertThat(serializedSubnet, containsString(Integer.toString(IP_VERSION.code()))); - assertThat(serializedSubnet, containsString(GATEWAY)); - assertThat(serializedSubnet, containsString(HOST_ROUTE)); - assertThat(serializedSubnet, containsString(NAME)); - assertThat(serializedSubnet, containsString(NETWORK_ID)); - assertThat(serializedSubnet, containsString(TENANT_ID)); - assertThat(serializedSubnet, containsString(POOL_START)); - assertThat(serializedSubnet, containsString(POOL_END)); + System.out.println("CLASS: " + Subnet.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Subnet subnet = objectMapper.readValue(JSON_FULL, Subnet.class); + String json = objectMapper.writeValueAsString(subnet); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void testSerializationEmpty() throws Exception { - Subnet subnet = new Subnet(); - serializedSubnet = objectMapper.writeValueAsString(subnet); - - assertThat(serializedSubnet, containsString("\"subnet\" : { }")); - } - - @Test - public void testDeserializationReadOnlyFields() throws Exception { - Subnet subnet = objectMapper.readValue(SUBNET_JSON, Subnet.class); - - assertThat(subnet.getId(), is(equalTo(ID))); - } - - @Test - public void testDeserializationAfterSerialization() throws Exception { - testSerialization(); - Subnet subnet = objectMapper.readValue(serializedSubnet, Subnet.class); - - assertThat(subnet.getCidr(), is(equalTo(CIDR))); - assertThat(subnet.getDnsNames(), hasItem(equalTo(DNS_SERVER))); - assertThat(subnet.isEnableDHCP(), is(equalTo(ENABLE_DHCP))); - assertThat(subnet.getIpversion(), is(equalTo(IP_VERSION))); - assertThat(subnet.getGw(), is(equalTo(GATEWAY))); - assertThat(subnet.getHostRoutes(), hasItem(equalTo(HOST_ROUTE))); - assertThat(subnet.getName(), is(equalTo(NAME))); - assertThat(subnet.getNetworkId(), is(equalTo(NETWORK_ID))); - assertThat(subnet.getTenantId(), is(equalTo(TENANT_ID))); - assertThat(subnet.getList(), hasItem(new CustomMatcher<Pool>( - "a Pool object with start " + POOL_START + " and end " + POOL_END) { - - @Override - public boolean matches(Object pool) { - return pool instanceof Pool - && POOL_START.equals(((Pool) pool).getStart()) - && POOL_END.equals(((Pool) pool).getEnd()); - } - })); + public void testMethods() throws Exception { + Subnet subnet = objectMapper.readValue(JSON_FULL, Subnet.class); + subnet.toString(); + + String gw = subnet.getGw(); + Assert.assertNotNull(gw); + subnet.setGw(gw); + + List<String> dnsNames = subnet.getDnsNames(); + Assert.assertNotNull(dnsNames); + Assert.assertEquals(2, dnsNames.size()); + subnet.setDnsNames(dnsNames); + + List<String> hostRoutes = subnet.getHostRoutes(); + Assert.assertNotNull(hostRoutes); + Assert.assertEquals(2, hostRoutes.size()); + subnet.setHostRoutes(hostRoutes); + + String name = subnet.getName(); + Assert.assertNotNull(name); + subnet.setName(name); + + String tenantId = subnet.getTenantId(); + Assert.assertNotNull(tenantId); + subnet.setTenantId(tenantId); + + String cidr = subnet.getCidr(); + Assert.assertNotNull(cidr); + subnet.setCidr(cidr); + + String networkId = subnet.getNetworkId(); + Assert.assertNotNull(networkId); + subnet.setNetworkId(networkId); + + Boolean enableDHCP = subnet.getEnableDHCP(); + Assert.assertNotNull(enableDHCP); + subnet.setEnableDHCP(enableDHCP); + + IpVersion ipversion = subnet.getIpversion(); + Assert.assertNotNull(ipversion); + subnet.setIpversion(ipversion); + + List<Pool> list = subnet.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + subnet.setList(list); } } diff --git a/quantum-model/src/test/java/com/woorea/openstack/quantum/model/SubnetsTest.java b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/SubnetsTest.java new file mode 100644 index 0000000..d01d3f6 --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/SubnetsTest.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.quantum.model; + +import com.woorea.openstack.quantum.model.Subnet; +import com.woorea.openstack.quantum.model.Subnets; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class SubnetsTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"subnets\" : [ {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"cidr\" : \"cidr\"," + EOL + + " \"enable_dhcp\" : true," + EOL + + " \"network_id\" : \"networkid\"," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"dns_nameservers\" : [ \"dnsnames-v1\", \"dnsnames-v2\" ]," + EOL + + " \"allocation_pools\" : [ {" + EOL + + " \"start\" : \"start\"," + EOL + + " \"end\" : \"end\"" + EOL + + " }, {" + EOL + + " \"start\" : \"start\"," + EOL + + " \"end\" : \"end\"" + EOL + + " } ]," + EOL + + " \"host_routes\" : [ \"hostroutes-v1\", \"hostroutes-v2\" ]," + EOL + + " \"ip_version\" : 4," + EOL + + " \"gateway_ip\" : \"gw\"" + EOL + + " }, {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"cidr\" : \"cidr\"," + EOL + + " \"enable_dhcp\" : true," + EOL + + " \"network_id\" : \"networkid\"," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"dns_nameservers\" : [ \"dnsnames-v1\", \"dnsnames-v2\" ]," + EOL + + " \"allocation_pools\" : [ {" + EOL + + " \"start\" : \"start\"," + EOL + + " \"end\" : \"end\"" + EOL + + " }, {" + EOL + + " \"start\" : \"start\"," + EOL + + " \"end\" : \"end\"" + EOL + + " } ]," + EOL + + " \"host_routes\" : [ \"hostroutes-v1\", \"hostroutes-v2\" ]," + EOL + + " \"ip_version\" : 4," + EOL + + " \"gateway_ip\" : \"gw\"" + EOL + + " } ]" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Subnets.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Subnets subnets = objectMapper.readValue(JSON_FULL, Subnets.class); + String json = objectMapper.writeValueAsString(subnets); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Subnets subnets = objectMapper.readValue(JSON_FULL, Subnets.class); + subnets.toString(); + + List<Subnet> list = subnets.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + subnets.setList(list); + + int cnt = 0; + for (@SuppressWarnings("unused") Subnet x : subnets) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} |