diff options
author | 2017-01-31 13:57:24 +0100 | |
---|---|---|
committer | 2017-01-31 14:55:11 +0100 | |
commit | 2e984294ac28c6f2ede290c38164c5d536ccaf4a (patch) | |
tree | 5eba5a929b7a961c98749fa69e03cfea58e1a724 /quantum-model/src/test/java/com/woorea/openstack/quantum/model/NetworkTest.java | |
parent | 86c0f28c8ed469486b64d6422dc53e3a7bcc8adb (diff) |
Initial OpenECOMP MSO OpenStack SDK lib commit
Change-Id: Ieaacb2b2c0dcc469669880e73f0cda9fa59a6c5a
Signed-off-by: ChrisC <cc697w@intl.att.com>
Diffstat (limited to 'quantum-model/src/test/java/com/woorea/openstack/quantum/model/NetworkTest.java')
-rw-r--r-- | quantum-model/src/test/java/com/woorea/openstack/quantum/model/NetworkTest.java | 119 |
1 files changed, 119 insertions, 0 deletions
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 new file mode 100644 index 0000000..b6255b9 --- /dev/null +++ b/quantum-model/src/test/java/com/woorea/openstack/quantum/model/NetworkTest.java @@ -0,0 +1,119 @@ +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 org.codehaus.jackson.map.ObjectMapper; +import org.junit.Before; +import org.junit.Test; + +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(); + } + + @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\" : { }")); + } + + @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))); + } +} |