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 /nova-model | |
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 'nova-model')
92 files changed, 7690 insertions, 2162 deletions
diff --git a/nova-model/pom.xml b/nova-model/pom.xml index 19ce8bd..4d20af9 100644 --- a/nova-model/pom.xml +++ b/nova-model/pom.xml @@ -13,7 +13,11 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>4.12</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.skyscreamer</groupId> + <artifactId>jsonassert</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/nova-model/src/main/java/com/woorea/openstack/nova/model/SecurityGroupRuleForCreate.java b/nova-model/src/main/java/com/woorea/openstack/nova/model/SecurityGroupRuleForCreate.java index fbb3f46..8911156 100644 --- a/nova-model/src/main/java/com/woorea/openstack/nova/model/SecurityGroupRuleForCreate.java +++ b/nova-model/src/main/java/com/woorea/openstack/nova/model/SecurityGroupRuleForCreate.java @@ -20,6 +20,7 @@ import java.io.Serializable; import javax.xml.bind.annotation.XmlElement; +import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonProperty; import org.codehaus.jackson.map.annotate.JsonRootName; @@ -112,6 +113,7 @@ public class SecurityGroupRuleForCreate implements Serializable { * @deprecated Use {@link #setParentGroupId(String)} */ @Deprecated + @JsonIgnore public void setParentGroupId(Integer parentGroupId) { this.parentGroupId = String.valueOf(parentGroupId); } @@ -191,6 +193,7 @@ public class SecurityGroupRuleForCreate implements Serializable { * @deprecated Use {@link #setGroupId(String)} */ @Deprecated + @JsonIgnore public void setGroupId(Integer groupId) { this.groupId = String.valueOf(groupId); } diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/AbsoluteLimitTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/AbsoluteLimitTest.java new file mode 100644 index 0000000..2fabb2b --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/AbsoluteLimitTest.java @@ -0,0 +1,164 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Limits.AbsoluteLimit; +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 AbsoluteLimitTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"maxServerMeta\" : 30," + EOL + + " \"serverMetaUsed\" : 37," + EOL + + " \"maxPersonality\" : 54," + EOL + + " \"personalityUsed\" : 61," + EOL + + " \"maxImageMeta\" : 82," + EOL + + " \"imageMetaUsed\" : 89," + EOL + + " \"maxPersonalitySize\" : 97," + EOL + + " \"personalitySizeUsed\" : 4," + EOL + + " \"maxTotalCores\" : 32," + EOL + + " \"totalCoresUsed\" : 39," + EOL + + " \"maxTotalInstances\" : 60," + EOL + + " \"totalInstancesUsed\" : 67," + EOL + + " \"maxTotalRAMSize\" : 55," + EOL + + " \"totalRAMUsed\" : 19," + EOL + + " \"maxSecurityGroupRules\" : 44," + EOL + + " \"securityGroupRulesUsed\" : 51," + EOL + + " \"maxTotalKeypairs\" : 64," + EOL + + " \"totalKeyPairsUsed\" : 71," + EOL + + " \"maxTotalVolumes\" : 71," + EOL + + " \"totalVolumesUsed\" : 78," + EOL + + " \"maxSecurityGroups\" : 4," + EOL + + " \"totalSecurityGroupsUsed\" : 59," + EOL + + " \"maxTotalFloatingIps\" : 76," + EOL + + " \"totalFloatingIpsUsed\" : 83," + EOL + + " \"maxTotalVolumeGigabytes\" : 15," + EOL + + " \"totalVolumeGigabytesUsed\" : 22" + 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: " + AbsoluteLimit.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + AbsoluteLimit absolutelimit = objectMapper.readValue(JSON_FULL, AbsoluteLimit.class); + String json = objectMapper.writeValueAsString(absolutelimit); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + AbsoluteLimit absolutelimit = objectMapper.readValue(JSON_FULL, AbsoluteLimit.class); + absolutelimit.toString(); + + Integer maxTotalRAMSize = absolutelimit.getMaxTotalRAMSize(); + Assert.assertNotNull(maxTotalRAMSize); + + Integer maxTotalInstances = absolutelimit.getMaxTotalInstances(); + Assert.assertNotNull(maxTotalInstances); + + Integer serverMetaUsed = absolutelimit.getServerMetaUsed(); + Assert.assertNotNull(serverMetaUsed); + + Integer maxTotalKeypairs = absolutelimit.getMaxTotalKeypairs(); + Assert.assertNotNull(maxTotalKeypairs); + + Integer maxTotalVolumeGigabytes = absolutelimit.getMaxTotalVolumeGigabytes(); + Assert.assertNotNull(maxTotalVolumeGigabytes); + + Integer totalSecurityGroupsUsed = absolutelimit.getTotalSecurityGroupsUsed(); + Assert.assertNotNull(totalSecurityGroupsUsed); + + Integer maxTotalVolumes = absolutelimit.getMaxTotalVolumes(); + Assert.assertNotNull(maxTotalVolumes); + + Integer maxImageMeta = absolutelimit.getMaxImageMeta(); + Assert.assertNotNull(maxImageMeta); + + Integer imageMetaUsed = absolutelimit.getImageMetaUsed(); + Assert.assertNotNull(imageMetaUsed); + + Integer totalVolumeGigabytesUsed = absolutelimit.getTotalVolumeGigabytesUsed(); + Assert.assertNotNull(totalVolumeGigabytesUsed); + + Integer maxSecurityGroupRules = absolutelimit.getMaxSecurityGroupRules(); + Assert.assertNotNull(maxSecurityGroupRules); + + Integer totalCoresUsed = absolutelimit.getTotalCoresUsed(); + Assert.assertNotNull(totalCoresUsed); + + Integer totalVolumesUsed = absolutelimit.getTotalVolumesUsed(); + Assert.assertNotNull(totalVolumesUsed); + + Integer maxTotalFloatingIps = absolutelimit.getMaxTotalFloatingIps(); + Assert.assertNotNull(maxTotalFloatingIps); + + Integer maxPersonality = absolutelimit.getMaxPersonality(); + Assert.assertNotNull(maxPersonality); + + Integer personalityUsed = absolutelimit.getPersonalityUsed(); + Assert.assertNotNull(personalityUsed); + + Integer maxSecurityGroups = absolutelimit.getMaxSecurityGroups(); + Assert.assertNotNull(maxSecurityGroups); + + Integer securityGroupRulesUsed = absolutelimit.getSecurityGroupRulesUsed(); + Assert.assertNotNull(securityGroupRulesUsed); + + Integer maxTotalCores = absolutelimit.getMaxTotalCores(); + Assert.assertNotNull(maxTotalCores); + + Integer maxServerMeta = absolutelimit.getMaxServerMeta(); + Assert.assertNotNull(maxServerMeta); + + Integer maxPersonalitySize = absolutelimit.getMaxPersonalitySize(); + Assert.assertNotNull(maxPersonalitySize); + + Integer personalitySizeUsed = absolutelimit.getPersonalitySizeUsed(); + Assert.assertNotNull(personalitySizeUsed); + + Integer totalKeyPairsUsed = absolutelimit.getTotalKeyPairsUsed(); + Assert.assertNotNull(totalKeyPairsUsed); + + Integer totalFloatingIpsUsed = absolutelimit.getTotalFloatingIpsUsed(); + Assert.assertNotNull(totalFloatingIpsUsed); + + Integer totalInstancesUsed = absolutelimit.getTotalInstancesUsed(); + Assert.assertNotNull(totalInstancesUsed); + + Integer totalRAMUsed = absolutelimit.getTotalRAMUsed(); + Assert.assertNotNull(totalRAMUsed); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/AddressTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/AddressTest.java new file mode 100644 index 0000000..45e1f1d --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/AddressTest.java @@ -0,0 +1,80 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Server.Addresses.Address; +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 AddressTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"version\" : \"version\"," + EOL + + " \"addr\" : \"addr\"," + EOL + + " \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL + + " \"OS-EXT-IPS:type\" : \"type\"" + 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: " + Address.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Address address = objectMapper.readValue(JSON_FULL, Address.class); + String json = objectMapper.writeValueAsString(address); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Address address = objectMapper.readValue(JSON_FULL, Address.class); + address.toString(); + + String type = address.getType(); + Assert.assertNotNull(type); + address.setType(type); + + String addr = address.getAddr(); + Assert.assertNotNull(addr); + address.setAddr(addr); + + String version = address.getVersion(); + Assert.assertNotNull(version); + address.setVersion(version); + + String macAddr = address.getMacAddr(); + Assert.assertNotNull(macAddr); + address.setMacAddr(macAddr); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/AddressesTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/AddressesTest.java new file mode 100644 index 0000000..8449f83 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/AddressesTest.java @@ -0,0 +1,91 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Server.Addresses; +import com.woorea.openstack.nova.model.Server.Addresses.Address; +import java.util.List; +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 AddressesTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"addresses\" : {" + EOL + + " \"addresses-k1\" : [ {" + EOL + + " \"version\" : \"version\"," + EOL + + " \"addr\" : \"addr\"," + EOL + + " \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL + + " \"OS-EXT-IPS:type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"version\" : \"version\"," + EOL + + " \"addr\" : \"addr\"," + EOL + + " \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL + + " \"OS-EXT-IPS:type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"addresses-k2\" : [ {" + EOL + + " \"version\" : \"version\"," + EOL + + " \"addr\" : \"addr\"," + EOL + + " \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL + + " \"OS-EXT-IPS:type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"version\" : \"version\"," + EOL + + " \"addr\" : \"addr\"," + EOL + + " \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL + + " \"OS-EXT-IPS:type\" : \"type\"" + EOL + + " } ]" + 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: " + Addresses.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Addresses addresses = objectMapper.readValue(JSON_FULL, Addresses.class); + String json = objectMapper.writeValueAsString(addresses); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Addresses addresses = objectMapper.readValue(JSON_FULL, Addresses.class); + addresses.toString(); + + Map<String,List<Address>> addressesProperty = addresses.getAddresses(); + Assert.assertNotNull(addressesProperty); + Assert.assertEquals(2, addressesProperty.size()); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/AssociateFloatingIpTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/AssociateFloatingIpTest.java new file mode 100644 index 0000000..a242728 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/AssociateFloatingIpTest.java @@ -0,0 +1,69 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.AssociateFloatingIp; +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 AssociateFloatingIpTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"addFloatingIp\" : {" + EOL + + " \"address\" : \"address\"" + 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: " + AssociateFloatingIp.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + AssociateFloatingIp associatefloatingip = objectMapper.readValue(JSON_FULL, AssociateFloatingIp.class); + String json = objectMapper.writeValueAsString(associatefloatingip); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + AssociateFloatingIp associatefloatingip = objectMapper.readValue(JSON_FULL, AssociateFloatingIp.class); + associatefloatingip.toString(); + + String address = associatefloatingip.getAddress(); + Assert.assertNotNull(address); + associatefloatingip.setAddress(address); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/CertificateTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/CertificateTest.java index 46d8c2b..24ca40c 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/CertificateTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/CertificateTest.java @@ -2,7 +2,7 @@ * ============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. @@ -17,24 +17,56 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Certificate; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class CertificateTest { - private Certificate certificate = new Certificate(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"certificate\" : {" + EOL + + " \"data\" : \"data\"," + EOL + + " \"private_key\" : \"privatekey\"" + 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 getData() { - certificate.getData(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Certificate.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Certificate certificate = objectMapper.readValue(JSON_FULL, Certificate.class); + String json = objectMapper.writeValueAsString(certificate); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getPrivateKey() { - certificate.getPrivateKey(); + public void testMethods() throws Exception { + Certificate certificate = objectMapper.readValue(JSON_FULL, Certificate.class); + certificate.toString(); + + String privateKey = certificate.getPrivateKey(); + Assert.assertNotNull(privateKey); + + String data = certificate.getData(); + Assert.assertNotNull(data); } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ChangePasswordTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ChangePasswordTest.java new file mode 100644 index 0000000..35a3c8d --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ChangePasswordTest.java @@ -0,0 +1,69 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.ChangePassword; +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 ChangePasswordTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"changePassword\" : {" + EOL + + " \"adminPass\" : \"adminpass\"" + 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: " + ChangePassword.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + ChangePassword changepassword = objectMapper.readValue(JSON_FULL, ChangePassword.class); + String json = objectMapper.writeValueAsString(changepassword); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + ChangePassword changepassword = objectMapper.readValue(JSON_FULL, ChangePassword.class); + changepassword.toString(); + + String adminPass = changepassword.getAdminPass(); + Assert.assertNotNull(adminPass); + changepassword.setAdminPass(adminPass); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/CloudpipeTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/CloudpipeTest.java index a35676f..b59703c 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/CloudpipeTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/CloudpipeTest.java @@ -1,5 +1,9 @@ /*- * ============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 @@ -16,83 +20,81 @@ package com.woorea.openstack.nova.model; -import org.junit.Test; - +import com.woorea.openstack.nova.model.Cloudpipe; import java.util.Calendar; - -import static org.junit.Assert.*; +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 CloudpipeTest { - private Cloudpipe pipe = new Cloudpipe(); - - @Test - public void getProjectId() { - pipe.getProjectId(); - } - - @Test - public void setProjectId() { - pipe.setProjectId("1234"); - } - - @Test - public void getInternalIp() { - pipe.getInternalIp(); - } - - @Test - public void setInternalIp() { - pipe.setInternalIp("123"); - } - - @Test - public void getPublicIp() { - pipe.getPublicIp(); - } - - @Test - public void setPublicIp() { - pipe.setPublicIp("1234"); - } - - @Test - public void getPublicPort() { - pipe.getPublicPort(); - } - - @Test - public void setPublicPort() { - pipe.setPublicPort("1234"); - } - - @Test - public void getState() { - pipe.getState(); - } - - @Test - public void setState() { - pipe.setState("1234"); - } - - @Test - public void getInstanceId() { - pipe.getInstanceId(); - } - - @Test - public void setInstanceId() { - pipe.setInstanceId("1234"); - } + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"cloudpipe\" : {" + EOL + + " \"projectId\" : \"projectid\"," + EOL + + " \"internalIp\" : \"internalip\"," + EOL + + " \"publicIp\" : \"publicip\"," + EOL + + " \"publicPort\" : \"publicport\"," + EOL + + " \"state\" : \"state\"," + EOL + + " \"instanceId\" : \"instanceid\"," + EOL + + " \"createdAt\" : 1486296000000" + 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 getCreatedAt() { - pipe.getCreatedAt(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Cloudpipe.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Cloudpipe cloudpipe = objectMapper.readValue(JSON_FULL, Cloudpipe.class); + String json = objectMapper.writeValueAsString(cloudpipe); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setCreatedAt() { - pipe.setCreatedAt(Calendar.getInstance()); + public void testMethods() throws Exception { + Cloudpipe cloudpipe = objectMapper.readValue(JSON_FULL, Cloudpipe.class); + cloudpipe.toString(); + + Calendar createdAt = cloudpipe.getCreatedAt(); + Assert.assertNotNull(createdAt); + cloudpipe.setCreatedAt(createdAt); + + String instanceId = cloudpipe.getInstanceId(); + Assert.assertNotNull(instanceId); + cloudpipe.setInstanceId(instanceId); + + String publicIp = cloudpipe.getPublicIp(); + Assert.assertNotNull(publicIp); + cloudpipe.setPublicIp(publicIp); + + String publicPort = cloudpipe.getPublicPort(); + Assert.assertNotNull(publicPort); + cloudpipe.setPublicPort(publicPort); + + String state = cloudpipe.getState(); + Assert.assertNotNull(state); + cloudpipe.setState(state); + + String projectId = cloudpipe.getProjectId(); + Assert.assertNotNull(projectId); + cloudpipe.setProjectId(projectId); + + String internalIp = cloudpipe.getInternalIp(); + Assert.assertNotNull(internalIp); + cloudpipe.setInternalIp(internalIp); } -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/CloudpipesTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/CloudpipesTest.java index 71cacd1..b7e0b01 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/CloudpipesTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/CloudpipesTest.java @@ -2,7 +2,7 @@ * ============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. @@ -20,14 +20,64 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Cloudpipe; +import com.woorea.openstack.nova.model.Cloudpipes; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class CloudpipesTest { + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"cloudpipes\" : [ {" + EOL + + " \"projectId\" : \"projectid\"," + EOL + + " \"internalIp\" : \"internalip\"," + EOL + + " \"publicIp\" : \"publicip\"," + EOL + + " \"publicPort\" : \"publicport\"," + EOL + + " \"state\" : \"state\"," + EOL + + " \"instanceId\" : \"instanceid\"," + EOL + + " \"createdAt\" : 1486296000000" + EOL + + " }, {" + EOL + + " \"projectId\" : \"projectid\"," + EOL + + " \"internalIp\" : \"internalip\"," + EOL + + " \"publicIp\" : \"publicip\"," + EOL + + " \"publicPort\" : \"publicport\"," + EOL + + " \"state\" : \"state\"," + EOL + + " \"instanceId\" : \"instanceid\"," + EOL + + " \"createdAt\" : 1486296000000" + 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: " + Cloudpipes.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Cloudpipes cloudpipes = objectMapper.readValue(JSON_FULL, Cloudpipes.class); + String json = objectMapper.writeValueAsString(cloudpipes); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + @Test - public void getList() { - new Cloudpipes().getList(); + public void testMethods() throws Exception { + Cloudpipes cloudpipes = objectMapper.readValue(JSON_FULL, Cloudpipes.class); + cloudpipes.toString(); + + List<Cloudpipe> list = cloudpipes.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); } -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ConfirmResizeTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ConfirmResizeTest.java new file mode 100644 index 0000000..c5710a9 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ConfirmResizeTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.ConfirmResize; +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 ConfirmResizeTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"confirmResize\" : { }" + 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: " + ConfirmResize.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + ConfirmResize confirmresize = objectMapper.readValue(JSON_FULL, ConfirmResize.class); + String json = objectMapper.writeValueAsString(confirmresize); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + ConfirmResize confirmresize = objectMapper.readValue(JSON_FULL, ConfirmResize.class); + confirmresize.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ConsoleOutputTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ConsoleOutputTest.java new file mode 100644 index 0000000..85385d8 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ConsoleOutputTest.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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.ConsoleOutput; +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 ConsoleOutputTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"output\" : \"output\"" + 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: " + ConsoleOutput.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + ConsoleOutput consoleoutput = objectMapper.readValue(JSON_FULL, ConsoleOutput.class); + String json = objectMapper.writeValueAsString(consoleoutput); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + ConsoleOutput consoleoutput = objectMapper.readValue(JSON_FULL, ConsoleOutput.class); + consoleoutput.toString(); + + String output = consoleoutput.getOutput(); + Assert.assertNotNull(output); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/CreateBackupTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/CreateBackupTest.java new file mode 100644 index 0000000..84b0622 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/CreateBackupTest.java @@ -0,0 +1,89 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.CreateBackup; +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 CreateBackupTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"createBackup\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"rotation\" : \"rotation\"," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"backup_type\" : \"type\"" + 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: " + CreateBackup.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + CreateBackup createbackup = objectMapper.readValue(JSON_FULL, CreateBackup.class); + String json = objectMapper.writeValueAsString(createbackup); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + CreateBackup createbackup = objectMapper.readValue(JSON_FULL, CreateBackup.class); + createbackup.toString(); + + Map<String,String> metadata = createbackup.getMetadata(); + Assert.assertNotNull(metadata); + Assert.assertEquals(2, metadata.size()); + createbackup.setMetadata(metadata); + + String rotation = createbackup.getRotation(); + Assert.assertNotNull(rotation); + createbackup.setRotation(rotation); + + String name = createbackup.getName(); + Assert.assertNotNull(name); + createbackup.setName(name); + + String type = createbackup.getType(); + Assert.assertNotNull(type); + createbackup.setType(type); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/CreateImageTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/CreateImageTest.java new file mode 100644 index 0000000..cd0603d --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/CreateImageTest.java @@ -0,0 +1,79 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.CreateImage; +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 CreateImageTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"createImage\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }" + 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: " + CreateImage.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + CreateImage createimage = objectMapper.readValue(JSON_FULL, CreateImage.class); + String json = objectMapper.writeValueAsString(createimage); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + CreateImage createimage = objectMapper.readValue(JSON_FULL, CreateImage.class); + createimage.toString(); + + Map<String,String> metadata = createimage.getMetadata(); + Assert.assertNotNull(metadata); + Assert.assertEquals(2, metadata.size()); + createimage.setMetadata(metadata); + + String name = createimage.getName(); + Assert.assertNotNull(name); + createimage.setName(name); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/DisassociateFloatingIpTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/DisassociateFloatingIpTest.java new file mode 100644 index 0000000..c58daa1 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/DisassociateFloatingIpTest.java @@ -0,0 +1,69 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.DisassociateFloatingIp; +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 DisassociateFloatingIpTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"removeFloatingIp\" : {" + EOL + + " \"address\" : \"address\"" + 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: " + DisassociateFloatingIp.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + DisassociateFloatingIp disassociatefloatingip = objectMapper.readValue(JSON_FULL, DisassociateFloatingIp.class); + String json = objectMapper.writeValueAsString(disassociatefloatingip); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + DisassociateFloatingIp disassociatefloatingip = objectMapper.readValue(JSON_FULL, DisassociateFloatingIp.class); + disassociatefloatingip.toString(); + + String address = disassociatefloatingip.getAddress(); + Assert.assertNotNull(address); + disassociatefloatingip.setAddress(address); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ExtensionTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ExtensionTest.java index ab27d8c..2047d22 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/ExtensionTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ExtensionTest.java @@ -2,7 +2,7 @@ * ============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. @@ -20,41 +20,81 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Extension; +import com.woorea.openstack.nova.model.Link; +import java.util.Calendar; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class ExtensionTest { - private Extension extension = new Extension(); - - @Test - public void getAlias() { - extension.getAlias(); - } + private static final String EOL = System.lineSeparator(); - @Test - public void getDescription() { - extension.getDescription(); - } + private static final String JSON_FULL = "{" + EOL + + " \"extension\" : {" + EOL + + " \"alias\" : \"alias\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"namespace\" : \"namespace\"," + EOL + + " \"updated\" : 1486468800000," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]" + EOL + + " }" + EOL + + "}"; - @Test - public void getName() { - extension.getName(); - } - - @Test - public void getNamespace() { - extension.getNamespace(); - } + 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 getUpdated() { - extension.getUpdated(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Extension.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Extension extension = objectMapper.readValue(JSON_FULL, Extension.class); + String json = objectMapper.writeValueAsString(extension); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getLinks() { - extension.getLinks(); + public void testMethods() throws Exception { + Extension extension = objectMapper.readValue(JSON_FULL, Extension.class); + extension.toString(); + + String name = extension.getName(); + Assert.assertNotNull(name); + + String namespace = extension.getNamespace(); + Assert.assertNotNull(namespace); + + String alias = extension.getAlias(); + Assert.assertNotNull(alias); + + String description = extension.getDescription(); + Assert.assertNotNull(description); + + List<Link> links = extension.getLinks(); + Assert.assertNotNull(links); + Assert.assertEquals(2, links.size()); + + Calendar updated = extension.getUpdated(); + Assert.assertNotNull(updated); } -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ExtensionsTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ExtensionsTest.java new file mode 100644 index 0000000..56bdf9c --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ExtensionsTest.java @@ -0,0 +1,103 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Extension; +import com.woorea.openstack.nova.model.Extensions; +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 ExtensionsTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"extensions\" : [ {" + EOL + + " \"alias\" : \"alias\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"namespace\" : \"namespace\"," + EOL + + " \"updated\" : 1486468800000," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]" + EOL + + " }, {" + EOL + + " \"alias\" : \"alias\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"namespace\" : \"namespace\"," + EOL + + " \"updated\" : 1486468800000," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]" + 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: " + Extensions.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Extensions extensions = objectMapper.readValue(JSON_FULL, Extensions.class); + String json = objectMapper.writeValueAsString(extensions); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Extensions extensions = objectMapper.readValue(JSON_FULL, Extensions.class); + extensions.toString(); + + List<Extension> list = extensions.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Extension x : extensions) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/FaultTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/FaultTest.java new file mode 100644 index 0000000..d4d58fb --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/FaultTest.java @@ -0,0 +1,77 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Server.Fault; +import java.util.Calendar; +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 FaultTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"code\" : 29," + EOL + + " \"message\" : \"message\"," + EOL + + " \"details\" : \"details\"," + EOL + + " \"created\" : 1485172800000" + 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: " + Fault.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Fault fault = objectMapper.readValue(JSON_FULL, Fault.class); + String json = objectMapper.writeValueAsString(fault); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Fault fault = objectMapper.readValue(JSON_FULL, Fault.class); + fault.toString(); + + Integer code = fault.getCode(); + Assert.assertNotNull(code); + + Calendar created = fault.getCreated(); + Assert.assertNotNull(created); + + String details = fault.getDetails(); + Assert.assertNotNull(details); + + String message = fault.getMessage(); + Assert.assertNotNull(message); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/FlavorForCreateTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/FlavorForCreateTest.java index ebd88b4..578f55a 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/FlavorForCreateTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/FlavorForCreateTest.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,91 +20,85 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.FlavorForCreate; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class FlavorForCreateTest { - private FlavorForCreate flavor = new FlavorForCreate(); - - @Test - public void getId() { - flavor.getId(); - } - - @Test - public void setId() { - flavor.setId("123"); - } - - @Test - public void getName() { - flavor.getName(); - } - - @Test - public void setName() { - flavor.setName("123"); - } - - @Test - public void getVcpus() { - flavor.getVcpus(); - } - - @Test - public void setVcpus() { - flavor.setVcpus("123"); - } - - @Test - public void getRam() { - flavor.getRam(); - } - - @Test - public void setRam() { - flavor.setRam(123); - } - - @Test - public void getDisk() { - flavor.getDisk(); - } - - @Test - public void setDisk() { - flavor.setDisk("123"); - } - - @Test - public void getEphemeral() { - flavor.getEphemeral(); - } - - @Test - public void setEphemeral() { - flavor.setEphemeral(123); - } - - @Test - public void getSwap() { - flavor.getSwap(); - } - - @Test - public void setSwap() { - flavor.setSwap("123"); - } - - @Test - public void getRxtxFactor() { - flavor.getRxtxFactor(); - } - - @Test - public void setRxtxFactor() { - flavor.setRxtxFactor(123.0f); - } -}
\ No newline at end of file + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"flavor\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"vcpus\" : \"vcpus\"," + EOL + + " \"ram\" : 38," + EOL + + " \"disk\" : \"disk\"," + EOL + + " \"swap\" : \"swap\"," + EOL + + " \"OS-FLV-EXT-DATA:ephemeral\" : 65," + EOL + + " \"rxtx_factor\" : 11.0" + 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: " + FlavorForCreate.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + FlavorForCreate flavorforcreate = objectMapper.readValue(JSON_FULL, FlavorForCreate.class); + String json = objectMapper.writeValueAsString(flavorforcreate); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + FlavorForCreate flavorforcreate = objectMapper.readValue(JSON_FULL, FlavorForCreate.class); + flavorforcreate.toString(); + + String disk = flavorforcreate.getDisk(); + Assert.assertNotNull(disk); + flavorforcreate.setDisk(disk); + + String swap = flavorforcreate.getSwap(); + Assert.assertNotNull(swap); + flavorforcreate.setSwap(swap); + + String name = flavorforcreate.getName(); + Assert.assertNotNull(name); + flavorforcreate.setName(name); + + Float rxtxFactor = flavorforcreate.getRxtxFactor(); + Assert.assertNotNull(rxtxFactor); + flavorforcreate.setRxtxFactor(rxtxFactor); + + Integer ephemeral = flavorforcreate.getEphemeral(); + Assert.assertNotNull(ephemeral); + flavorforcreate.setEphemeral(ephemeral); + + String id = flavorforcreate.getId(); + Assert.assertNotNull(id); + flavorforcreate.setId(id); + + String vcpus = flavorforcreate.getVcpus(); + Assert.assertNotNull(vcpus); + flavorforcreate.setVcpus(vcpus); + + Integer ram = flavorforcreate.getRam(); + Assert.assertNotNull(ram); + flavorforcreate.setRam(ram); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/FlavorTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/FlavorTest.java index cef42fc..d3a369f 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/FlavorTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/FlavorTest.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,143 +20,118 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Flavor; +import com.woorea.openstack.nova.model.Link; +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 java.util.Collections; - -import static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class FlavorTest { - private Flavor flavor = new Flavor(); - - @Test - public void getId() { - flavor.getId(); - } - - @Test - public void setId() { - flavor.setId("123"); - } - - @Test - public void getName() { - flavor.getName(); - } - - @Test - public void setName() { - flavor.setName("123"); - } - - @Test - public void getVcpus() { - flavor.getVcpus(); - } - - @Test - public void setVcpus() { - flavor.setVcpus(123); - } - - @Test - public void getRam() { - flavor.getRam(); - } - - @Test - public void setRam() { - flavor.setRam(123); - } - - @Test - public void getDisk() { - flavor.getDisk(); - } - - @Test - public void setDisk() { - flavor.setDisk(123); - } - - @Test - public void getEphemeral() { - flavor.getEphemeral(); - } - - @Test - public void setEphemeral() { - flavor.setEphemeral(123); - } - - @Test - public void getSwap() { - flavor.getSwap(); - } - - @Test - public void setSwap() { - flavor.setSwap("123"); - } - - @Test - public void getRxtxFactor() { - flavor.getRxtxFactor(); - } - - @Test - public void setRxtxFactor() { - flavor.setRxtxFactor(123.0f); - } - - @Test - public void getRxtxQuota() { - flavor.getRxtxQuota(); - } - - @Test - public void setRxtxQuota() { - flavor.setRxtxQuota(123); - } - - @Test - public void getRxtxCap() { - flavor.getRxtxCap(); - } - - @Test - public void setRxtxCap() { - flavor.setRxtxCap(123); - } - - @Test - public void getDisabled() { - flavor.getDisabled(); - } - - @Test - public void setDisabled() { - flavor.setDisabled(true); - } - - @Test - public void isPublic() { - flavor.isPublic(); - } - - @Test - public void setPublic() { - flavor.setPublic(true); - } - - @Test - public void getLinks() { - flavor.getLinks(); - } - - @Test - public void setLinks() { - flavor.setLinks(Collections.<Link>emptyList()); - } -}
\ No newline at end of file + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"flavor\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"vcpus\" : 79," + EOL + + " \"ram\" : 38," + EOL + + " \"disk\" : 45," + EOL + + " \"swap\" : \"swap\"," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"public\" : false," + EOL + + " \"OS-FLV-EXT-DATA:ephemeral\" : 65," + EOL + + " \"rxtx_factor\" : 11.0," + EOL + + " \"OS-FLV-DISABLED:disabled\" : true," + EOL + + " \"rxtx_quota\" : 42," + EOL + + " \"rxtx_cap\" : 96," + EOL + + " \"os-flavor-access:is_public\" : false" + 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: " + Flavor.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Flavor flavor = objectMapper.readValue(JSON_FULL, Flavor.class); + String json = objectMapper.writeValueAsString(flavor); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Flavor flavor = objectMapper.readValue(JSON_FULL, Flavor.class); + flavor.toString(); + + Integer rxtxQuota = flavor.getRxtxQuota(); + Assert.assertNotNull(rxtxQuota); + flavor.setRxtxQuota(rxtxQuota); + + String swap = flavor.getSwap(); + Assert.assertNotNull(swap); + flavor.setSwap(swap); + + Float rxtxFactor = flavor.getRxtxFactor(); + Assert.assertNotNull(rxtxFactor); + flavor.setRxtxFactor(rxtxFactor); + + Integer ephemeral = flavor.getEphemeral(); + Assert.assertNotNull(ephemeral); + flavor.setEphemeral(ephemeral); + + Integer vcpus = flavor.getVcpus(); + Assert.assertNotNull(vcpus); + flavor.setVcpus(vcpus); + + Integer rxtxCap = flavor.getRxtxCap(); + Assert.assertNotNull(rxtxCap); + flavor.setRxtxCap(rxtxCap); + + Integer disk = flavor.getDisk(); + Assert.assertNotNull(disk); + flavor.setDisk(disk); + + String name = flavor.getName(); + Assert.assertNotNull(name); + flavor.setName(name); + + List<Link> links = flavor.getLinks(); + Assert.assertNotNull(links); + Assert.assertEquals(2, links.size()); + flavor.setLinks(links); + + Boolean disabled = flavor.getDisabled(); + Assert.assertNotNull(disabled); + flavor.setDisabled(disabled); + + String id = flavor.getId(); + Assert.assertNotNull(id); + flavor.setId(id); + + Integer ram = flavor.getRam(); + Assert.assertNotNull(ram); + flavor.setRam(ram); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/FlavorsTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/FlavorsTest.java new file mode 100644 index 0000000..326b11e --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/FlavorsTest.java @@ -0,0 +1,119 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Flavor; +import com.woorea.openstack.nova.model.Flavors; +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 FlavorsTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"flavors\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"vcpus\" : 79," + EOL + + " \"ram\" : 38," + EOL + + " \"disk\" : 45," + EOL + + " \"swap\" : \"swap\"," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"public\" : false," + EOL + + " \"OS-FLV-EXT-DATA:ephemeral\" : 65," + EOL + + " \"rxtx_factor\" : 11.0," + EOL + + " \"OS-FLV-DISABLED:disabled\" : true," + EOL + + " \"rxtx_quota\" : 42," + EOL + + " \"rxtx_cap\" : 96," + EOL + + " \"os-flavor-access:is_public\" : false" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"vcpus\" : 79," + EOL + + " \"ram\" : 38," + EOL + + " \"disk\" : 45," + EOL + + " \"swap\" : \"swap\"," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"public\" : false," + EOL + + " \"OS-FLV-EXT-DATA:ephemeral\" : 65," + EOL + + " \"rxtx_factor\" : 11.0," + EOL + + " \"OS-FLV-DISABLED:disabled\" : true," + EOL + + " \"rxtx_quota\" : 42," + EOL + + " \"rxtx_cap\" : 96," + EOL + + " \"os-flavor-access:is_public\" : false" + 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: " + Flavors.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Flavors flavors = objectMapper.readValue(JSON_FULL, Flavors.class); + String json = objectMapper.writeValueAsString(flavors); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Flavors flavors = objectMapper.readValue(JSON_FULL, Flavors.class); + flavors.toString(); + + List<Flavor> list = flavors.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Flavor x : flavors) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpDomainTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpDomainTest.java index 0107cef..02fd66c 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpDomainTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpDomainTest.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,31 +20,61 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.FloatingIpDomain; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class FloatingIpDomainTest { - private FloatingIpDomain domain = new FloatingIpDomain();; + private static final String EOL = System.lineSeparator(); - @Test - public void getDomain() { - domain.getDomain(); - } + private static final String JSON_FULL = "{" + EOL + + " \"floating-ip-pool\" : {" + EOL + + " \"domain\" : \"domain\"," + EOL + + " \"scope\" : \"scope\"," + EOL + + " \"project\" : \"project\"," + EOL + + " \"availabilityZone\" : \"availabilityzone\"" + EOL + + " }" + EOL + + "}"; - @Test - public void getScope() { - domain.getScope(); - } + 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 getProject() { - domain.getProject(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + FloatingIpDomain.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + FloatingIpDomain floatingipdomain = objectMapper.readValue(JSON_FULL, FloatingIpDomain.class); + String json = objectMapper.writeValueAsString(floatingipdomain); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getAvailabilityZone() { - domain.getAvailabilityZone(); + public void testMethods() throws Exception { + FloatingIpDomain floatingipdomain = objectMapper.readValue(JSON_FULL, FloatingIpDomain.class); + floatingipdomain.toString(); + + String domain = floatingipdomain.getDomain(); + Assert.assertNotNull(domain); + + String scope = floatingipdomain.getScope(); + Assert.assertNotNull(scope); + + String project = floatingipdomain.getProject(); + Assert.assertNotNull(project); + + String availabilityZone = floatingipdomain.getAvailabilityZone(); + Assert.assertNotNull(availabilityZone); } -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpDomainsTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpDomainsTest.java new file mode 100644 index 0000000..6cc5108 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpDomainsTest.java @@ -0,0 +1,83 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.FloatingIpDomain; +import com.woorea.openstack.nova.model.FloatingIpDomains; +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 FloatingIpDomainsTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"domain_entries\" : [ {" + EOL + + " \"domain\" : \"domain\"," + EOL + + " \"scope\" : \"scope\"," + EOL + + " \"project\" : \"project\"," + EOL + + " \"availabilityZone\" : \"availabilityzone\"" + EOL + + " }, {" + EOL + + " \"domain\" : \"domain\"," + EOL + + " \"scope\" : \"scope\"," + EOL + + " \"project\" : \"project\"," + EOL + + " \"availabilityZone\" : \"availabilityzone\"" + 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: " + FloatingIpDomains.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + FloatingIpDomains floatingipdomains = objectMapper.readValue(JSON_FULL, FloatingIpDomains.class); + String json = objectMapper.writeValueAsString(floatingipdomains); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + FloatingIpDomains floatingipdomains = objectMapper.readValue(JSON_FULL, FloatingIpDomains.class); + floatingipdomains.toString(); + + List<FloatingIpDomain> list = floatingipdomains.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") FloatingIpDomain x : floatingipdomains) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpPoolTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpPoolTest.java new file mode 100644 index 0000000..d8dd6c2 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpPoolTest.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.nova.model; + +import com.woorea.openstack.nova.model.FloatingIpPools.FloatingIpPool; +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 FloatingIpPoolTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"name\" : \"name\"" + 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: " + FloatingIpPool.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + FloatingIpPool floatingippool = objectMapper.readValue(JSON_FULL, FloatingIpPool.class); + String json = objectMapper.writeValueAsString(floatingippool); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + FloatingIpPool floatingippool = objectMapper.readValue(JSON_FULL, FloatingIpPool.class); + floatingippool.toString(); + + String name = floatingippool.getName(); + Assert.assertNotNull(name); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpPoolsTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpPoolsTest.java index 334942e..d4dcfd6 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpPoolsTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpPoolsTest.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,21 +20,58 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.FloatingIpPools; +import com.woorea.openstack.nova.model.FloatingIpPools.FloatingIpPool; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class FloatingIpPoolsTest { - private FloatingIpPools pools = new FloatingIpPools(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"floating_ip_pools\" : [ {" + EOL + + " \"name\" : \"name\"" + EOL + + " }, {" + EOL + + " \"name\" : \"name\"" + 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 getList() { - pools.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + FloatingIpPools.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + FloatingIpPools floatingippools = objectMapper.readValue(JSON_FULL, FloatingIpPools.class); + String json = objectMapper.writeValueAsString(floatingippools); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void iterator() { - pools.getList(); + public void testMethods() throws Exception { + FloatingIpPools floatingippools = objectMapper.readValue(JSON_FULL, FloatingIpPools.class); + floatingippools.toString(); + + List<FloatingIpPool> list = floatingippools.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") FloatingIpPool x : floatingippools) { + ++cnt; + } + Assert.assertEquals(2, cnt); } -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpTest.java index 968b8bd..f184e83 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpTest.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,36 +20,65 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.FloatingIp; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class FloatingIpTest { - private FloatingIp ip = new FloatingIp(); + private static final String EOL = System.lineSeparator(); - @Test - public void getId() { - ip.getId(); - } + private static final String JSON_FULL = "{" + EOL + + " \"floating_ip\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"pool\" : \"pool\"," + EOL + + " \"ip\" : \"ip\"," + EOL + + " \"fixed_ip\" : \"fixedip\"," + EOL + + " \"instance_id\" : \"instanceid\"" + EOL + + " }" + EOL + + "}"; - @Test - public void getPool() { - ip.getPool(); - } - - @Test - public void getIp() { - ip.getIp(); - } + 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 getFixedIp() { - ip.getFixedIp(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + FloatingIp.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + FloatingIp floatingip = objectMapper.readValue(JSON_FULL, FloatingIp.class); + String json = objectMapper.writeValueAsString(floatingip); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getInstanceId() { - ip.getInstanceId(); + public void testMethods() throws Exception { + FloatingIp floatingip = objectMapper.readValue(JSON_FULL, FloatingIp.class); + floatingip.toString(); + + String instanceId = floatingip.getInstanceId(); + Assert.assertNotNull(instanceId); + + String ip = floatingip.getIp(); + Assert.assertNotNull(ip); + + String pool = floatingip.getPool(); + Assert.assertNotNull(pool); + + String fixedIp = floatingip.getFixedIp(); + Assert.assertNotNull(fixedIp); + + String id = floatingip.getId(); + Assert.assertNotNull(id); } -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpsTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpsTest.java new file mode 100644 index 0000000..9cfd3ec --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/FloatingIpsTest.java @@ -0,0 +1,85 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.FloatingIp; +import com.woorea.openstack.nova.model.FloatingIps; +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 FloatingIpsTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"floating_ips\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"pool\" : \"pool\"," + EOL + + " \"ip\" : \"ip\"," + EOL + + " \"fixed_ip\" : \"fixedip\"," + EOL + + " \"instance_id\" : \"instanceid\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"pool\" : \"pool\"," + EOL + + " \"ip\" : \"ip\"," + EOL + + " \"fixed_ip\" : \"fixedip\"," + EOL + + " \"instance_id\" : \"instanceid\"" + 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: " + FloatingIps.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + FloatingIps floatingips = objectMapper.readValue(JSON_FULL, FloatingIps.class); + String json = objectMapper.writeValueAsString(floatingips); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + FloatingIps floatingips = objectMapper.readValue(JSON_FULL, FloatingIps.class); + floatingips.toString(); + + List<FloatingIp> list = floatingips.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") FloatingIp x : floatingips) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ForceDeleteTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ForceDeleteTest.java new file mode 100644 index 0000000..87a904c --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ForceDeleteTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.ForceDelete; +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 ForceDeleteTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"forceDelete\" : { }" + 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: " + ForceDelete.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + ForceDelete forcedelete = objectMapper.readValue(JSON_FULL, ForceDelete.class); + String json = objectMapper.writeValueAsString(forcedelete); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + ForceDelete forcedelete = objectMapper.readValue(JSON_FULL, ForceDelete.class); + forcedelete.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/GetConsoleOutputTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/GetConsoleOutputTest.java new file mode 100644 index 0000000..6293712 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/GetConsoleOutputTest.java @@ -0,0 +1,69 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.GetConsoleOutput; +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 GetConsoleOutputTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"os-getConsoleOutput\" : {" + EOL + + " \"length\" : 60" + 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: " + GetConsoleOutput.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + GetConsoleOutput getconsoleoutput = objectMapper.readValue(JSON_FULL, GetConsoleOutput.class); + String json = objectMapper.writeValueAsString(getconsoleoutput); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + GetConsoleOutput getconsoleoutput = objectMapper.readValue(JSON_FULL, GetConsoleOutput.class); + getconsoleoutput.toString(); + + Integer length = getconsoleoutput.getLength(); + Assert.assertNotNull(length); + getconsoleoutput.setLength(length); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/GetVncConsoleTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/GetVncConsoleTest.java new file mode 100644 index 0000000..0de38d7 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/GetVncConsoleTest.java @@ -0,0 +1,69 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.GetVncConsole; +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 GetVncConsoleTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"os-getVNCConsole\" : {" + EOL + + " \"type\" : \"type\"" + 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: " + GetVncConsole.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + GetVncConsole getvncconsole = objectMapper.readValue(JSON_FULL, GetVncConsole.class); + String json = objectMapper.writeValueAsString(getvncconsole); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + GetVncConsole getvncconsole = objectMapper.readValue(JSON_FULL, GetVncConsole.class); + getvncconsole.toString(); + + String type = getvncconsole.getType(); + Assert.assertNotNull(type); + getvncconsole.setType(type); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/GroupTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/GroupTest.java new file mode 100644 index 0000000..3cb1144 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/GroupTest.java @@ -0,0 +1,68 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.SecurityGroup.Rule.Group; +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 GroupTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"name\" : \"name\"," + 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: " + Group.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Group group = objectMapper.readValue(JSON_FULL, Group.class); + String json = objectMapper.writeValueAsString(group); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Group group = objectMapper.readValue(JSON_FULL, Group.class); + group.toString(); + + String name = group.getName(); + Assert.assertNotNull(name); + + String tenantId = group.getTenantId(); + Assert.assertNotNull(tenantId); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/HostAggregateTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/HostAggregateTest.java index 414ada0..f694e44 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/HostAggregateTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/HostAggregateTest.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,56 +20,88 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.HostAggregate; +import java.util.List; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class HostAggregateTest { - private HostAggregate host = new HostAggregate(); + private static final String EOL = System.lineSeparator(); - @Test - public void getId() { - host.getId(); - } + private static final String JSON_FULL = "{" + EOL + + " \"aggregate\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"deleted\" : false," + EOL + + " \"hosts\" : [ \"hosts-v1\", \"hosts-v2\" ]," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"availability_zone\" : \"availabilityzone\"," + EOL + + " \"created_at\" : \"createdat\"," + EOL + + " \"updated_at\" : \"updatedat\"," + EOL + + " \"deleted_at\" : \"deletedat\"" + EOL + + " }" + EOL + + "}"; - @Test - public void getName() { - host.getName(); - } - - @Test - public void getAvailabilityZone() { - host.getAvailabilityZone(); - } - - @Test - public void getCreatedAt() { - host.getCreatedAt(); - } - - @Test - public void getUpdatedAt() { - host.getUpdatedAt(); - } - - @Test - public void getDeletedAt() { - host.getDeletedAt(); - } - - @Test - public void getDeleted() { - host.getDeleted(); - } + 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 getHosts() { - host.getHosts(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + HostAggregate.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + HostAggregate hostaggregate = objectMapper.readValue(JSON_FULL, HostAggregate.class); + String json = objectMapper.writeValueAsString(hostaggregate); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getMetadata() { - host.getMetadata(); + public void testMethods() throws Exception { + HostAggregate hostaggregate = objectMapper.readValue(JSON_FULL, HostAggregate.class); + hostaggregate.toString(); + + String createdAt = hostaggregate.getCreatedAt(); + Assert.assertNotNull(createdAt); + + Map<String,String> metadata = hostaggregate.getMetadata(); + Assert.assertNotNull(metadata); + Assert.assertEquals(2, metadata.size()); + + String deletedAt = hostaggregate.getDeletedAt(); + Assert.assertNotNull(deletedAt); + + Boolean deleted = hostaggregate.getDeleted(); + Assert.assertNotNull(deleted); + + List<String> hosts = hostaggregate.getHosts(); + Assert.assertNotNull(hosts); + Assert.assertEquals(2, hosts.size()); + + String name = hostaggregate.getName(); + Assert.assertNotNull(name); + + String id = hostaggregate.getId(); + Assert.assertNotNull(id); + + String availabilityZone = hostaggregate.getAvailabilityZone(); + Assert.assertNotNull(availabilityZone); + + String updatedAt = hostaggregate.getUpdatedAt(); + Assert.assertNotNull(updatedAt); } -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/HostAggregatesTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/HostAggregatesTest.java new file mode 100644 index 0000000..8e97938 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/HostAggregatesTest.java @@ -0,0 +1,99 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.HostAggregate; +import com.woorea.openstack.nova.model.HostAggregates; +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 HostAggregatesTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"aggregates\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"deleted\" : false," + EOL + + " \"hosts\" : [ \"hosts-v1\", \"hosts-v2\" ]," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"availability_zone\" : \"availabilityzone\"," + EOL + + " \"created_at\" : \"createdat\"," + EOL + + " \"updated_at\" : \"updatedat\"," + EOL + + " \"deleted_at\" : \"deletedat\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"deleted\" : false," + EOL + + " \"hosts\" : [ \"hosts-v1\", \"hosts-v2\" ]," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"availability_zone\" : \"availabilityzone\"," + EOL + + " \"created_at\" : \"createdat\"," + EOL + + " \"updated_at\" : \"updatedat\"," + EOL + + " \"deleted_at\" : \"deletedat\"" + 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: " + HostAggregates.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + HostAggregates hostaggregates = objectMapper.readValue(JSON_FULL, HostAggregates.class); + String json = objectMapper.writeValueAsString(hostaggregates); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + HostAggregates hostaggregates = objectMapper.readValue(JSON_FULL, HostAggregates.class); + hostaggregates.toString(); + + List<HostAggregate> list = hostaggregates.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") HostAggregate x : hostaggregates) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/HostTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/HostTest.java index abf1fc5..424a265 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/HostTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/HostTest.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,48 +20,54 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Hosts.Host; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class HostTest { - private Host host = new Host(); - private Host.ResourceWrapper wrapper = new Host.ResourceWrapper(); - private Host.ResourceWrapper.Resource resource = new Host.ResourceWrapper.Resource(); - - @Test - public void getHost() { - host.getHost(); - } + private static final String EOL = System.lineSeparator(); - @Test - public void getResource() { - wrapper.getResource(); - } + private static final String JSON_FULL = "{" + EOL + + " \"zone\" : \"zone\"," + EOL + + " \"service\" : \"service\"," + EOL + + " \"host_name\" : \"hostname\"" + EOL + + "}"; - @Test - public void getProject() { - resource.getProject(); - } - - @Test - public void getMemoryMb() { - resource.getMemoryMb(); - } - - @Test - public void getHostResource() { - resource.getHost(); - } + 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 getCpu() { - resource.getCpu(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Host.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Host host = objectMapper.readValue(JSON_FULL, Host.class); + String json = objectMapper.writeValueAsString(host); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getDiskGb() { - resource.getDiskGb(); + public void testMethods() throws Exception { + Host host = objectMapper.readValue(JSON_FULL, Host.class); + host.toString(); + + String hostName = host.getHostName(); + Assert.assertNotNull(hostName); + + String zone = host.getZone(); + Assert.assertNotNull(zone); + host.setZone(zone); + + String service = host.getService(); + Assert.assertNotNull(service); } -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/HostsTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/HostsTest.java new file mode 100644 index 0000000..ae0c6d8 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/HostsTest.java @@ -0,0 +1,81 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Hosts; +import com.woorea.openstack.nova.model.Hosts.Host; +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 HostsTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"hosts\" : [ {" + EOL + + " \"zone\" : \"zone\"," + EOL + + " \"service\" : \"service\"," + EOL + + " \"host_name\" : \"hostname\"" + EOL + + " }, {" + EOL + + " \"zone\" : \"zone\"," + EOL + + " \"service\" : \"service\"," + EOL + + " \"host_name\" : \"hostname\"" + 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: " + Hosts.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Hosts hosts = objectMapper.readValue(JSON_FULL, Hosts.class); + String json = objectMapper.writeValueAsString(hosts); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Hosts hosts = objectMapper.readValue(JSON_FULL, Hosts.class); + hosts.toString(); + + List<Host> list = hosts.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Host x : hosts) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ImageFromVolumeTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ImageFromVolumeTest.java index 4084d10..2c4b6c4 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/ImageFromVolumeTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ImageFromVolumeTest.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,111 +20,95 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.ImageFromVolume; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class ImageFromVolumeTest { - private ImageFromVolume image = new ImageFromVolume(); - - @Test - public void getId() { - image.getId(); - } - - @Test - public void setId() { - image.setId("123"); - } - - @Test - public void getUpdates_at() { - image.getUpdates_at(); - } - - @Test - public void setUpdates_at() { - image.setUpdates_at("123"); - } - - @Test - public void getStatus() { - image.getStatus(); - } - - @Test - public void setStatus() { - image.setStatus("123"); - } - - @Test - public void getDisplay_description() { - image.getDisplay_description(); - } - - @Test - public void setDisplay_description() { - image.setDisplay_description("123"); - } - - @Test - public void getSize() { - image.getSize(); - } - - @Test - public void setSize() { - image.setSize("123"); - } - - @Test - public void getVolume_type() { - image.getVolume_type(); - } - - @Test - public void setVolume_type() { - image.setVolume_type("123"); - } - - @Test - public void getImage_id() { - image.getImage_id(); - } - - @Test - public void setImage_id() { - image.setImage_id("123"); - } - - @Test - public void getContainer_format() { - image.getContainer_format(); - } - - @Test - public void setContainer_format() { - image.setContainer_format("123"); - } - - @Test - public void getDisk_format() { - image.getDisk_format(); - } - - @Test - public void setDisk_format() { - image.setDisk_format("123"); - } - - @Test - public void getImage_name() { - image.getImage_name(); - } - - @Test - public void setImage_name() { - image.setImage_name("123"); - } -}
\ No newline at end of file + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"os-volume_upload_image\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"updates_at\" : \"updates_at\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"display_description\" : \"display_description\"," + EOL + + " \"size\" : \"size\"," + EOL + + " \"volume_type\" : \"volume_type\"," + EOL + + " \"image_id\" : \"image_id\"," + EOL + + " \"container_format\" : \"container_format\"," + EOL + + " \"disk_format\" : \"disk_format\"," + EOL + + " \"image_name\" : \"image_name\"" + 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: " + ImageFromVolume.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + ImageFromVolume imagefromvolume = objectMapper.readValue(JSON_FULL, ImageFromVolume.class); + String json = objectMapper.writeValueAsString(imagefromvolume); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + ImageFromVolume imagefromvolume = objectMapper.readValue(JSON_FULL, ImageFromVolume.class); + imagefromvolume.toString(); + + String image_name = imagefromvolume.getImage_name(); + Assert.assertNotNull(image_name); + imagefromvolume.setImage_name(image_name); + + String display_description = imagefromvolume.getDisplay_description(); + Assert.assertNotNull(display_description); + imagefromvolume.setDisplay_description(display_description); + + String updates_at = imagefromvolume.getUpdates_at(); + Assert.assertNotNull(updates_at); + imagefromvolume.setUpdates_at(updates_at); + + String volume_type = imagefromvolume.getVolume_type(); + Assert.assertNotNull(volume_type); + imagefromvolume.setVolume_type(volume_type); + + String size = imagefromvolume.getSize(); + Assert.assertNotNull(size); + imagefromvolume.setSize(size); + + String disk_format = imagefromvolume.getDisk_format(); + Assert.assertNotNull(disk_format); + imagefromvolume.setDisk_format(disk_format); + + String id = imagefromvolume.getId(); + Assert.assertNotNull(id); + imagefromvolume.setId(id); + + String image_id = imagefromvolume.getImage_id(); + Assert.assertNotNull(image_id); + imagefromvolume.setImage_id(image_id); + + String container_format = imagefromvolume.getContainer_format(); + Assert.assertNotNull(container_format); + imagefromvolume.setContainer_format(container_format); + + String status = imagefromvolume.getStatus(); + Assert.assertNotNull(status); + imagefromvolume.setStatus(status); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ImageTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ImageTest.java index 4db1cc1..4fa6869 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/ImageTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ImageTest.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,125 +20,132 @@ package com.woorea.openstack.nova.model; -import org.junit.Test; - -import java.io.PrintStream; +import com.woorea.openstack.nova.model.Image; +import com.woorea.openstack.nova.model.Image.Server; +import com.woorea.openstack.nova.model.Link; import java.util.Calendar; -import java.util.Collections; - -import static org.junit.Assert.*; +import java.util.List; +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 ImageTest { - private Image image = new Image(); - - @Test - public void getId() { - image.getId(); - } - - @Test - public void setId() { - image.setId("123"); - } - - @Test - public void getStatus() { - image.getStatus(); - } - - @Test - public void setStatus() { - image.setStatus("123"); - } - - @Test - public void getName() { - image.setName("123"); - } - - @Test - public void setName() { - image.setName("123"); - } - - @Test - public void getProgress() { - image.getProgress(); - } - - @Test - public void setProgress() { - image.setProgress(123); - } - - @Test - public void getMinRam() { - image.getMinRam(); - } - - @Test - public void setMinRam() { - image.setMinRam(123); - } - - @Test - public void getMinDisk() { - image.getMinDisk(); - } - - @Test - public void setMinDisk() { - image.setMinDisk(123); - } - - @Test - public void getCreated() { - image.getCreated(); - } - - @Test - public void setCreated() { - image.setCreated(Calendar.getInstance()); - } - - @Test - public void getUpdated() { - image.getUpdated(); - } - - @Test - public void setUpdated() { - image.setUpdated(Calendar.getInstance()); - } - - @Test - public void getMetadata() { - image.getMetadata(); - } - - @Test - public void getSize() { - image.getSize(); - } - - @Test - public void setMetadata() { - image.setMetadata(Collections.<String, String>emptyMap()); - } - - @Test - public void getServer() { - image.getServer(); - } - - @Test - public void getLinks() { - image.getLinks(); - } - - @Test - public void setLinks() { - image.setLinks(Collections.<Link>emptyList()); - } -}
\ No newline at end of file + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"image\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"progress\" : 3," + EOL + + " \"minRam\" : 62," + EOL + + " \"minDisk\" : 69," + EOL + + " \"created\" : 1485172800000," + EOL + + " \"updated\" : 1486468800000," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"server\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]" + EOL + + " }," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"OS-EXT-IMG-SIZE:size\" : 43" + 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: " + Image.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Image image = objectMapper.readValue(JSON_FULL, Image.class); + String json = objectMapper.writeValueAsString(image); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Image image = objectMapper.readValue(JSON_FULL, Image.class); + image.toString(); + + Server server = image.getServer(); + Assert.assertNotNull(server); + + Map<String,String> metadata = image.getMetadata(); + Assert.assertNotNull(metadata); + Assert.assertEquals(2, metadata.size()); + image.setMetadata(metadata); + + Long size = image.getSize(); + Assert.assertNotNull(size); + + Calendar created = image.getCreated(); + Assert.assertNotNull(created); + image.setCreated(created); + + Integer minRam = image.getMinRam(); + Assert.assertNotNull(minRam); + image.setMinRam(minRam); + + String name = image.getName(); + Assert.assertNotNull(name); + image.setName(name); + + Integer progress = image.getProgress(); + Assert.assertNotNull(progress); + image.setProgress(progress); + + List<Link> links = image.getLinks(); + Assert.assertNotNull(links); + Assert.assertEquals(2, links.size()); + image.setLinks(links); + + String id = image.getId(); + Assert.assertNotNull(id); + image.setId(id); + + Calendar updated = image.getUpdated(); + Assert.assertNotNull(updated); + image.setUpdated(updated); + + Integer minDisk = image.getMinDisk(); + Assert.assertNotNull(minDisk); + image.setMinDisk(minDisk); + + String status = image.getStatus(); + Assert.assertNotNull(status); + image.setStatus(status); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ImagesTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ImagesTest.java new file mode 100644 index 0000000..bd92fb2 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ImagesTest.java @@ -0,0 +1,143 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Image; +import com.woorea.openstack.nova.model.Images; +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 ImagesTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"images\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"progress\" : 3," + EOL + + " \"minRam\" : 62," + EOL + + " \"minDisk\" : 69," + EOL + + " \"created\" : 1485172800000," + EOL + + " \"updated\" : 1486468800000," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"server\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]" + EOL + + " }," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"OS-EXT-IMG-SIZE:size\" : 43" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"progress\" : 3," + EOL + + " \"minRam\" : 62," + EOL + + " \"minDisk\" : 69," + EOL + + " \"created\" : 1485172800000," + EOL + + " \"updated\" : 1486468800000," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"server\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]" + EOL + + " }," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"OS-EXT-IMG-SIZE:size\" : 43" + 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: " + Images.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Images images = objectMapper.readValue(JSON_FULL, Images.class); + String json = objectMapper.writeValueAsString(images); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Images images = objectMapper.readValue(JSON_FULL, Images.class); + images.toString(); + + List<Image> list = images.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Image x : images) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/IpRangeTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/IpRangeTest.java new file mode 100644 index 0000000..2db77e5 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/IpRangeTest.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.nova.model; + +import com.woorea.openstack.nova.model.SecurityGroup.Rule.IpRange; +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 IpRangeTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"cidr\" : \"cidr\"" + 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: " + IpRange.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + IpRange iprange = objectMapper.readValue(JSON_FULL, IpRange.class); + String json = objectMapper.writeValueAsString(iprange); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + IpRange iprange = objectMapper.readValue(JSON_FULL, IpRange.class); + iprange.toString(); + + String cidr = iprange.getCidr(); + Assert.assertNotNull(cidr); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/KeyPairTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/KeyPairTest.java index 31cf096..39a159e 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/KeyPairTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/KeyPairTest.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,46 +20,67 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.KeyPair; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class KeyPairTest { - private KeyPair pair = new KeyPair(); - - @Test - public void getName() { - pair.getName(); - } + private static final String EOL = System.lineSeparator(); - @Test - public void setName() { - pair.setName("123"); - } + private static final String JSON_FULL = "{" + EOL + + " \"keypair\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"fingerprint\" : \"fingerprint\"," + EOL + + " \"user_id\" : \"userid\"," + EOL + + " \"public_key\" : \"publickey\"," + EOL + + " \"private_key\" : \"privatekey\"" + EOL + + " }" + EOL + + "}"; - @Test - public void getUserId() { - pair.getUserId(); - } - - @Test - public void getPublicKey() { - pair.getPublicKey(); - } - - @Test - public void setPublicKey() { - pair.setPublicKey("123"); - } + 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 getPrivateKey() { - pair.getPrivateKey(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + KeyPair.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + KeyPair keypair = objectMapper.readValue(JSON_FULL, KeyPair.class); + String json = objectMapper.writeValueAsString(keypair); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getFingerprint() { - pair.getFingerprint(); + public void testMethods() throws Exception { + KeyPair keypair = objectMapper.readValue(JSON_FULL, KeyPair.class); + keypair.toString(); + + String privateKey = keypair.getPrivateKey(); + Assert.assertNotNull(privateKey); + + String name = keypair.getName(); + Assert.assertNotNull(name); + keypair.setName(name); + + String fingerprint = keypair.getFingerprint(); + Assert.assertNotNull(fingerprint); + + String publicKey = keypair.getPublicKey(); + Assert.assertNotNull(publicKey); + keypair.setPublicKey(publicKey); + + String userId = keypair.getUserId(); + Assert.assertNotNull(userId); } -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/KeyPairWrapperTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/KeyPairWrapperTest.java new file mode 100644 index 0000000..b71cc09 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/KeyPairWrapperTest.java @@ -0,0 +1,68 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.KeyPair; +import com.woorea.openstack.nova.model.KeyPairs.KeyPairWrapper; +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 KeyPairWrapperTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"keypair\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"fingerprint\" : \"fingerprint\"," + EOL + + " \"user_id\" : \"userid\"," + EOL + + " \"public_key\" : \"publickey\"," + EOL + + " \"private_key\" : \"privatekey\"" + 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: " + KeyPairWrapper.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + KeyPairWrapper keypairwrapper = objectMapper.readValue(JSON_FULL, KeyPairWrapper.class); + String json = objectMapper.writeValueAsString(keypairwrapper); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + KeyPairWrapper keypairwrapper = objectMapper.readValue(JSON_FULL, KeyPairWrapper.class); + keypairwrapper.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/KeyPairsTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/KeyPairsTest.java new file mode 100644 index 0000000..4eb25a8 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/KeyPairsTest.java @@ -0,0 +1,93 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.KeyPairs; +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.Ignore; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class KeyPairsTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"keypairs\" : [ {" + EOL + + " \"keypair\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"fingerprint\" : \"fingerprint\"," + EOL + + " \"user_id\" : \"userid\"," + EOL + + " \"public_key\" : \"publickey\"," + EOL + + " \"private_key\" : \"privatekey\"" + EOL + + " }" + EOL + + " }, {" + EOL + + " \"keypair\" : { " + EOL + + " \"name\" : \"name\"," + EOL + + " \"fingerprint\" : \"fingerprint\"," + EOL + + " \"user_id\" : \"userid\"," + EOL + + " \"public_key\" : \"publickey\"," + EOL + + " \"private_key\" : \"privatekey\"" + EOL + + " }" + EOL + + " } ]" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + // This is test is ignored because The KeyPairs class does not + // serialize into JSON correctly. It is probably not an operational + // issue because KeyPairs is only used to represent the response to + // the GET os-keypairs request. + @Ignore + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + KeyPairs.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + KeyPairs keypairs = objectMapper.readValue(JSON_FULL, KeyPairs.class); + String json = objectMapper.writeValueAsString(keypairs); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testGettersAndSetters() throws Exception { + KeyPairs keypairs = objectMapper.readValue(JSON_FULL, KeyPairs.class); + keypairs.toString(); + + List<KeyPair> list = keypairs.getList(); + Assert.assertNotNull(list); + + int cnt = 0; + for (@SuppressWarnings("unused") KeyPair x : keypairs) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/LimitEntryTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/LimitEntryTest.java new file mode 100644 index 0000000..2396827 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/LimitEntryTest.java @@ -0,0 +1,85 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Limits.RateLimit.LimitEntry; +import java.util.Calendar; +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 LimitEntryTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"unit\" : \"unit\"," + EOL + + " \"verb\" : \"verb\"," + EOL + + " \"remaining\" : 72," + EOL + + " \"available\" : 47," + EOL + + " \"value\" : 59," + EOL + + " \"next-available\" : 1489320000000" + 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: " + LimitEntry.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + LimitEntry limitentry = objectMapper.readValue(JSON_FULL, LimitEntry.class); + String json = objectMapper.writeValueAsString(limitentry); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + LimitEntry limitentry = objectMapper.readValue(JSON_FULL, LimitEntry.class); + limitentry.toString(); + + String unit = limitentry.getUnit(); + Assert.assertNotNull(unit); + + String verb = limitentry.getVerb(); + Assert.assertNotNull(verb); + + Integer available = limitentry.getAvailable(); + Assert.assertNotNull(available); + + Calendar nextAvailable = limitentry.getNextAvailable(); + Assert.assertNotNull(nextAvailable); + + Integer value = limitentry.getValue(); + Assert.assertNotNull(value); + + Integer remaining = limitentry.getRemaining(); + Assert.assertNotNull(remaining); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/LimitsTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/LimitsTest.java index 2d65192..2977a3a 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/LimitsTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/LimitsTest.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,203 +20,120 @@ package com.woorea.openstack.nova.model; -import org.junit.Test; - -import java.util.Calendar; +import com.woorea.openstack.nova.model.Limits; +import com.woorea.openstack.nova.model.Limits.AbsoluteLimit; +import com.woorea.openstack.nova.model.Limits.RateLimit; import java.util.List; - -import static org.junit.Assert.*; +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 LimitsTest { - private Limits limits = new Limits(); - private Limits.AbsoluteLimit aLimit = new Limits.AbsoluteLimit(); - private Limits.RateLimit rLimit = new Limits.RateLimit(); - private Limits.RateLimit.LimitEntry entry = new Limits.RateLimit.LimitEntry(); - - @Test - public void getNextAvailable() { - entry.getNextAvailable(); - } - - @Test - public void getUnit() { - entry.getUnit(); - } - - @Test - public void getVerb() { - entry.getVerb(); - } - - @Test - public void getRemaining() { - entry.getRemaining(); - } - - @Test - public void getAvailable() { - entry.getAvailable(); - } - - @Test - public void getValue() { - entry.getValue(); - } - - @Test - public void getRate() { - limits.getRate(); - } - - @Test - public void getAbsolute() { - limits.getAbsolute(); - } - - @Test - public void getRegex() { - rLimit.getRegex(); - } - - @Test - public void getUri() { - rLimit.getUri(); - } - - @Test - public void getLimit() { - rLimit.getLimit(); - } - - @Test - public void getMaxServerMeta() { - aLimit.getMaxServerMeta(); - } - - @Test - public void getMaxPersonality() { - aLimit.getMaxPersonality(); - } - - @Test - public void getMaxImageMeta() { - aLimit.getMaxImageMeta(); - } - - @Test - public void getMaxPersonalitySize() { - aLimit.getMaxPersonalitySize(); - } - - @Test - public void getMaxTotalCores() { - aLimit.getMaxTotalCores(); - } - - @Test - public void getMaxTotalInstances() { - aLimit.getMaxTotalInstances(); - } - - @Test - public void getMaxTotalRAMSize() { - aLimit.getMaxTotalRAMSize(); - } - - @Test - public void getTotalVolumesUsed() { - aLimit.getTotalVolumesUsed(); - } - - @Test - public void getMaxSecurityGroupRules() { - aLimit.getMaxSecurityGroupRules(); - } - - @Test - public void getMaxTotalKeypairs() { - aLimit.getMaxTotalKeypairs(); - } - - @Test - public void getTotalCoresUsed() { - aLimit.getTotalCoresUsed(); - } - - @Test - public void getMaxTotalVolumes() { - aLimit.getMaxTotalVolumes(); - } - - @Test - public void getTotalRAMUsed() { - aLimit.getTotalRAMUsed(); - } - - @Test - public void getTotalInstancesUsed() { - aLimit.getTotalInstancesUsed(); - } - - @Test - public void getMaxSecurityGroups() { - aLimit.getMaxSecurityGroups(); - } - - @Test - public void getTotalVolumeGigabytesUsed() { - aLimit.getTotalVolumeGigabytesUsed(); - } - - @Test - public void getTotalSecurityGroupsUsed() { - aLimit.getTotalSecurityGroupsUsed(); - } - - @Test - public void getMaxTotalFloatingIps() { - aLimit.getMaxTotalFloatingIps(); - } - - @Test - public void getTotalKeyPairsUsed() { - aLimit.getTotalKeyPairsUsed(); - } - - @Test - public void getMaxTotalVolumeGigabytes() { - aLimit.getMaxTotalVolumeGigabytes(); - } - - @Test - public void getServerMetaUsed() { - aLimit.getServerMetaUsed(); - } - - @Test - public void getPersonalityUsed() { - aLimit.getPersonalityUsed(); - } - - @Test - public void getImageMetaUsed() { - aLimit.getImageMetaUsed(); - } - - @Test - public void getPersonalitySizeUsed() { - aLimit.getPersonalitySizeUsed(); - } - - @Test - public void getSecurityGroupRulesUsed() { - aLimit.getSecurityGroupRulesUsed(); - } - - @Test - public void getTotalFloatingIpsUsed() { - aLimit.getTotalFloatingIpsUsed(); - } - -}
\ No newline at end of file + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"limits\" : {" + EOL + + " \"rate\" : [ {" + EOL + + " \"regex\" : \"regex\"," + EOL + + " \"uri\" : \"uri\"," + EOL + + " \"limit\" : [ {" + EOL + + " \"unit\" : \"unit\"," + EOL + + " \"verb\" : \"verb\"," + EOL + + " \"remaining\" : 72," + EOL + + " \"available\" : 47," + EOL + + " \"value\" : 59," + EOL + + " \"next-available\" : 1489320000000" + EOL + + " }, {" + EOL + + " \"unit\" : \"unit\"," + EOL + + " \"verb\" : \"verb\"," + EOL + + " \"remaining\" : 72," + EOL + + " \"available\" : 47," + EOL + + " \"value\" : 59," + EOL + + " \"next-available\" : 1489320000000" + EOL + + " } ]" + EOL + + " }, {" + EOL + + " \"regex\" : \"regex\"," + EOL + + " \"uri\" : \"uri\"," + EOL + + " \"limit\" : [ {" + EOL + + " \"unit\" : \"unit\"," + EOL + + " \"verb\" : \"verb\"," + EOL + + " \"remaining\" : 72," + EOL + + " \"available\" : 47," + EOL + + " \"value\" : 59," + EOL + + " \"next-available\" : 1489320000000" + EOL + + " }, {" + EOL + + " \"unit\" : \"unit\"," + EOL + + " \"verb\" : \"verb\"," + EOL + + " \"remaining\" : 72," + EOL + + " \"available\" : 47," + EOL + + " \"value\" : 59," + EOL + + " \"next-available\" : 1489320000000" + EOL + + " } ]" + EOL + + " } ]," + EOL + + " \"absolute\" : {" + EOL + + " \"maxServerMeta\" : 30," + EOL + + " \"serverMetaUsed\" : 37," + EOL + + " \"maxPersonality\" : 54," + EOL + + " \"personalityUsed\" : 61," + EOL + + " \"maxImageMeta\" : 82," + EOL + + " \"imageMetaUsed\" : 89," + EOL + + " \"maxPersonalitySize\" : 97," + EOL + + " \"personalitySizeUsed\" : 4," + EOL + + " \"maxTotalCores\" : 32," + EOL + + " \"totalCoresUsed\" : 39," + EOL + + " \"maxTotalInstances\" : 60," + EOL + + " \"totalInstancesUsed\" : 67," + EOL + + " \"maxTotalRAMSize\" : 55," + EOL + + " \"totalRAMUsed\" : 19," + EOL + + " \"maxSecurityGroupRules\" : 44," + EOL + + " \"securityGroupRulesUsed\" : 51," + EOL + + " \"maxTotalKeypairs\" : 64," + EOL + + " \"totalKeyPairsUsed\" : 71," + EOL + + " \"maxTotalVolumes\" : 71," + EOL + + " \"totalVolumesUsed\" : 78," + EOL + + " \"maxSecurityGroups\" : 4," + EOL + + " \"totalSecurityGroupsUsed\" : 59," + EOL + + " \"maxTotalFloatingIps\" : 76," + EOL + + " \"totalFloatingIpsUsed\" : 83," + EOL + + " \"maxTotalVolumeGigabytes\" : 15," + EOL + + " \"totalVolumeGigabytesUsed\" : 22" + EOL + + " }" + 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: " + Limits.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Limits limits = objectMapper.readValue(JSON_FULL, Limits.class); + String json = objectMapper.writeValueAsString(limits); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Limits limits = objectMapper.readValue(JSON_FULL, Limits.class); + limits.toString(); + + List<RateLimit> rate = limits.getRate(); + Assert.assertNotNull(rate); + Assert.assertEquals(2, rate.size()); + + AbsoluteLimit absolute = limits.getAbsolute(); + Assert.assertNotNull(absolute); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/LinkTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/LinkTest.java index c1c12cf..81b91a8 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/LinkTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/LinkTest.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,25 +20,53 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Link; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class LinkTest { - private Link link = new Link(); - @Test - public void getRel() { - link.getRel(); - } + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + 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 getHref() { - link.getHref(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Link.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Link link = objectMapper.readValue(JSON_FULL, Link.class); + String json = objectMapper.writeValueAsString(link); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getType() { - link.getType(); + public void testMethods() throws Exception { + Link link = objectMapper.readValue(JSON_FULL, Link.class); + link.toString(); + + String rel = link.getRel(); + Assert.assertNotNull(rel); + + String href = link.getHref(); + Assert.assertNotNull(href); + + String type = link.getType(); + Assert.assertNotNull(type); } -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/LockTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/LockTest.java new file mode 100644 index 0000000..aca120e --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/LockTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Lock; +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 LockTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"lock\" : { }" + 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: " + Lock.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Lock lock = objectMapper.readValue(JSON_FULL, Lock.class); + String json = objectMapper.writeValueAsString(lock); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Lock lock = objectMapper.readValue(JSON_FULL, Lock.class); + lock.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/NetworkForCreateTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/NetworkForCreateTest.java index 83c64e9..e5b379b 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/NetworkForCreateTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/NetworkForCreateTest.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,29 +20,51 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.NetworkForCreate; +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 NetworkForCreateTest { - private NetworkForCreate network = new NetworkForCreate(); + private static final String EOL = System.lineSeparator(); - @Test - public void getId() { - network.getId(); - } + private static final String JSON_FULL = "{" + EOL + + " \"uuid\" : \"id\"," + EOL + + " \"fixed_ip\" : \"fixedip\"" + EOL + + "}"; - @Test - public void getFixedIp() { - network.getFixedIp(); - } + 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 setId() { - network.setId("123"); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + NetworkForCreate.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + NetworkForCreate networkforcreate = objectMapper.readValue(JSON_FULL, NetworkForCreate.class); + String json = objectMapper.writeValueAsString(networkforcreate); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setFixedIp() { - network.setFixedIp("123"); + public void testMethods() throws Exception { + NetworkForCreate networkforcreate = objectMapper.readValue(JSON_FULL, NetworkForCreate.class); + networkforcreate.toString(); + + String fixedIp = networkforcreate.getFixedIp(); + Assert.assertNotNull(fixedIp); + networkforcreate.setFixedIp(fixedIp); + + String id = networkforcreate.getId(); + Assert.assertNotNull(id); + networkforcreate.setId(id); } -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/NetworkTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/NetworkTest.java index 2c7a32e..ef4a683 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/NetworkTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/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,146 +20,154 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Network; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class NetworkTest { - private Network network = new Network(); - - @Test - public void getId() { - network.getId(); - } - - @Test - public void getVpnPublicAddress() { - network.getVpnPublicAddress(); - } - - @Test - public void getVpnPublicPort() { - network.getVpnPublicPort(); - } - - @Test - public void getDhcpStart() { - network.getDhcpStart(); - } - - @Test - public void getBridge() { - network.getBridge(); - } - - @Test - public void getBridgeInterface() { - network.getBridgeInterface(); - } - - @Test - public void getUpdatedAt() { - network.getUpdatedAt(); - } - - @Test - public void getDeleted() { - network.getDeleted(); - } - - @Test - public void getVlan() { - network.getVlan(); - } - - @Test - public void getBroadcast() { - network.getBroadcast(); - } - - @Test - public void getNetmask() { - network.getNetmask(); - } - - @Test - public void getInjected() { - network.getInjected(); - } - - @Test - public void getHost() { - network.getHost(); - } - - @Test - public void getMultiHost() { - network.getMultiHost(); - } - - @Test - public void getCreatedAt() { - network.getCreatedAt(); - } - - @Test - public void getDeletedAt() { - network.getDeletedAt(); - } - - @Test - public void getCidr() { - network.getCidr(); - } - - @Test - public void getCidrV6() { - network.getCidrV6(); - } - - @Test - public void getGateway() { - network.getGateway(); - } - - @Test - public void getGatewayV6() { - network.getGatewayV6(); - } - - @Test - public void getNetmaskV6() { - network.getNetmaskV6(); - } - - @Test - public void getProjectId() { - network.getProjectId(); - } - - @Test - public void getRxtxBase() { - network.getRxtxBase(); - } - - @Test - public void getDns1() { - network.getDns1(); - } - - @Test - public void getDns2() { - network.getDns2(); - } - - @Test - public void getLabel() { - network.getLabel(); - } - - @Test - public void getPriority() { - network.getPriority(); - } -}
\ No newline at end of file + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"network\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"bridge\" : \"bridge\"," + EOL + + " \"deleted\" : false," + EOL + + " \"vlan\" : \"vlan\"," + EOL + + " \"broadcast\" : \"broadcast\"," + EOL + + " \"netmask\" : \"netmask\"," + EOL + + " \"injected\" : true," + EOL + + " \"host\" : \"host\"," + EOL + + " \"cidr\" : \"cidr\"," + EOL + + " \"gateway\" : \"gateway\"," + EOL + + " \"dns1\" : \"dns1\"," + EOL + + " \"dns2\" : \"dns2\"," + EOL + + " \"label\" : \"label\"," + EOL + + " \"priority\" : \"priority\"," + EOL + + " \"vpn_public_address\" : \"vpnpublicaddress\"," + EOL + + " \"vpn_private_address\" : \"vpnprivateaddress\"," + EOL + + " \"vpn_public_port\" : \"vpnpublicport\"," + EOL + + " \"dhcp_start\" : \"dhcpstart\"," + EOL + + " \"bridge_interface\" : \"bridgeinterface\"," + EOL + + " \"updated_at\" : \"updatedat\"," + EOL + + " \"multi_host\" : false," + EOL + + " \"created_at\" : \"createdat\"," + EOL + + " \"deleted_at\" : \"deletedat\"," + EOL + + " \"cidr_v6\" : \"cidrv6\"," + EOL + + " \"gateway_v6\" : \"gatewayv6\"," + EOL + + " \"netmask_v6\" : \"netmaskv6\"," + EOL + + " \"project_id\" : \"projectid\"," + EOL + + " \"rxtx_base\" : \"rxtxbase\"" + 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: " + 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 testMethods() throws Exception { + Network network = objectMapper.readValue(JSON_FULL, Network.class); + network.toString(); + + String broadcast = network.getBroadcast(); + Assert.assertNotNull(broadcast); + + String gatewayV6 = network.getGatewayV6(); + Assert.assertNotNull(gatewayV6); + + String dns2 = network.getDns2(); + Assert.assertNotNull(dns2); + + String bridgeInterface = network.getBridgeInterface(); + Assert.assertNotNull(bridgeInterface); + + String dns1 = network.getDns1(); + Assert.assertNotNull(dns1); + + String cidrV6 = network.getCidrV6(); + Assert.assertNotNull(cidrV6); + + String deletedAt = network.getDeletedAt(); + Assert.assertNotNull(deletedAt); + + String vlan = network.getVlan(); + Assert.assertNotNull(vlan); + + String netmask = network.getNetmask(); + Assert.assertNotNull(netmask); + + String netmaskV6 = network.getNetmaskV6(); + Assert.assertNotNull(netmaskV6); + + Boolean injected = network.getInjected(); + Assert.assertNotNull(injected); + + String host = network.getHost(); + Assert.assertNotNull(host); + + String cidr = network.getCidr(); + Assert.assertNotNull(cidr); + + String id = network.getId(); + Assert.assertNotNull(id); + + String projectId = network.getProjectId(); + Assert.assertNotNull(projectId); + + String vpnPublicAddress = network.getVpnPublicAddress(); + Assert.assertNotNull(vpnPublicAddress); + + String label = network.getLabel(); + Assert.assertNotNull(label); + + String priority = network.getPriority(); + Assert.assertNotNull(priority); + + String vpnPublicPort = network.getVpnPublicPort(); + Assert.assertNotNull(vpnPublicPort); + + String createdAt = network.getCreatedAt(); + Assert.assertNotNull(createdAt); + + Boolean deleted = network.getDeleted(); + Assert.assertNotNull(deleted); + + String rxtxBase = network.getRxtxBase(); + Assert.assertNotNull(rxtxBase); + + String dhcpStart = network.getDhcpStart(); + Assert.assertNotNull(dhcpStart); + + Boolean multiHost = network.getMultiHost(); + Assert.assertNotNull(multiHost); + + String bridge = network.getBridge(); + Assert.assertNotNull(bridge); + + String gateway = network.getGateway(); + Assert.assertNotNull(gateway); + + String updatedAt = network.getUpdatedAt(); + Assert.assertNotNull(updatedAt); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/NetworksTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/NetworksTest.java new file mode 100644 index 0000000..9268445 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/NetworksTest.java @@ -0,0 +1,131 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Network; +import com.woorea.openstack.nova.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 + + " \"id\" : \"id\"," + EOL + + " \"bridge\" : \"bridge\"," + EOL + + " \"deleted\" : false," + EOL + + " \"vlan\" : \"vlan\"," + EOL + + " \"broadcast\" : \"broadcast\"," + EOL + + " \"netmask\" : \"netmask\"," + EOL + + " \"injected\" : true," + EOL + + " \"host\" : \"host\"," + EOL + + " \"cidr\" : \"cidr\"," + EOL + + " \"gateway\" : \"gateway\"," + EOL + + " \"dns1\" : \"dns1\"," + EOL + + " \"dns2\" : \"dns2\"," + EOL + + " \"label\" : \"label\"," + EOL + + " \"priority\" : \"priority\"," + EOL + + " \"vpn_public_address\" : \"vpnpublicaddress\"," + EOL + + " \"vpn_private_address\" : \"vpnprivateaddress\"," + EOL + + " \"vpn_public_port\" : \"vpnpublicport\"," + EOL + + " \"dhcp_start\" : \"dhcpstart\"," + EOL + + " \"bridge_interface\" : \"bridgeinterface\"," + EOL + + " \"updated_at\" : \"updatedat\"," + EOL + + " \"multi_host\" : false," + EOL + + " \"created_at\" : \"createdat\"," + EOL + + " \"deleted_at\" : \"deletedat\"," + EOL + + " \"cidr_v6\" : \"cidrv6\"," + EOL + + " \"gateway_v6\" : \"gatewayv6\"," + EOL + + " \"netmask_v6\" : \"netmaskv6\"," + EOL + + " \"project_id\" : \"projectid\"," + EOL + + " \"rxtx_base\" : \"rxtxbase\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"bridge\" : \"bridge\"," + EOL + + " \"deleted\" : false," + EOL + + " \"vlan\" : \"vlan\"," + EOL + + " \"broadcast\" : \"broadcast\"," + EOL + + " \"netmask\" : \"netmask\"," + EOL + + " \"injected\" : true," + EOL + + " \"host\" : \"host\"," + EOL + + " \"cidr\" : \"cidr\"," + EOL + + " \"gateway\" : \"gateway\"," + EOL + + " \"dns1\" : \"dns1\"," + EOL + + " \"dns2\" : \"dns2\"," + EOL + + " \"label\" : \"label\"," + EOL + + " \"priority\" : \"priority\"," + EOL + + " \"vpn_public_address\" : \"vpnpublicaddress\"," + EOL + + " \"vpn_private_address\" : \"vpnprivateaddress\"," + EOL + + " \"vpn_public_port\" : \"vpnpublicport\"," + EOL + + " \"dhcp_start\" : \"dhcpstart\"," + EOL + + " \"bridge_interface\" : \"bridgeinterface\"," + EOL + + " \"updated_at\" : \"updatedat\"," + EOL + + " \"multi_host\" : false," + EOL + + " \"created_at\" : \"createdat\"," + EOL + + " \"deleted_at\" : \"deletedat\"," + EOL + + " \"cidr_v6\" : \"cidrv6\"," + EOL + + " \"gateway_v6\" : \"gatewayv6\"," + EOL + + " \"netmask_v6\" : \"netmaskv6\"," + EOL + + " \"project_id\" : \"projectid\"," + EOL + + " \"rxtx_base\" : \"rxtxbase\"" + 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()); + + int cnt = 0; + for (@SuppressWarnings("unused") Network x : networks) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/PauseTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/PauseTest.java new file mode 100644 index 0000000..a5ec89d --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/PauseTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Pause; +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 PauseTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"pause\" : { }" + 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: " + Pause.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Pause pause = objectMapper.readValue(JSON_FULL, Pause.class); + String json = objectMapper.writeValueAsString(pause); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Pause pause = objectMapper.readValue(JSON_FULL, Pause.class); + pause.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/PersonalityFileTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/PersonalityFileTest.java index c735995..81cc6ac 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/PersonalityFileTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/PersonalityFileTest.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,31 +20,51 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.PersonalityFile; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class PersonalityFileTest { - private PersonalityFile file = new PersonalityFile(); + private static final String EOL = System.lineSeparator(); - @Test - public void getPath() { - file.getPath(); - } + private static final String JSON_FULL = "{" + EOL + + " \"path\" : \"path\"," + EOL + + " \"contents\" : \"contents\"" + EOL + + "}"; - @Test - public void setPath() { - file.setPath("123"); - } + 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 getContents() { - file.getContents(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + PersonalityFile.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + PersonalityFile personalityfile = objectMapper.readValue(JSON_FULL, PersonalityFile.class); + String json = objectMapper.writeValueAsString(personalityfile); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setContents() { - file.setContents("123"); + public void testMethods() throws Exception { + PersonalityFile personalityfile = objectMapper.readValue(JSON_FULL, PersonalityFile.class); + personalityfile.toString(); + + String path = personalityfile.getPath(); + Assert.assertNotNull(path); + personalityfile.setPath(path); + + String contents = personalityfile.getContents(); + Assert.assertNotNull(contents); + personalityfile.setContents(contents); } -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/QuotaSetTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/QuotaSetTest.java index 03b0a1f..0a424ed 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/QuotaSetTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/QuotaSetTest.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,151 +20,115 @@ package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.QuotaSet; +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 static org.junit.Assert.*; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class QuotaSetTest { - private QuotaSet set = new QuotaSet(); - - @Test - public void getId() { - set.getId(); - } - - @Test - public void setId() { - set.setId("123"); - } - - @Test - public void getMetadataItems() { - set.getMetadataItems(); - } - - @Test - public void setMetadataItems() { - set.setMetadataItems(123); - } - - @Test - public void getInjectedFileContentBytes() { - set.getInjectedFileContentBytes(); - } - - @Test - public void setInjectedFileContentBytes() { - set.setInjectedFileContentBytes(123); - } - - @Test - public void getInjectedFiles() { - set.getInjectedFiles(); - } - - @Test - public void setInjectedFiles() { - set.setInjectedFiles(123); - } - - @Test - public void getGigabytes() { - set.getGigabytes(); - } - - @Test - public void setGigabytes() { - set.setGigabytes(123); - } - - @Test - public void getRam() { - set.getRam(); - } - - @Test - public void setRam() { - set.setRam(123); - } - - @Test - public void getFloatingIps() { - set.getFloatingIps(); - } - - @Test - public void setFloatingIps() { - set.setFloatingIps(123); - } - - @Test - public void getInstances() { - set.getInstances(); - } - - @Test - public void setInstances() { - set.setInstances(123); - } - - @Test - public void getVolumes() { - set.getVolumes(); - } - - @Test - public void setVolumes() { - set.setVolumes(123); - } - - @Test - public void getCores() { - set.getCores(); - } - - @Test - public void setCores() { - set.setCores(123); - } - - @Test - public void getSecurityGroups() { - set.getSecurityGroups(); - } - - @Test - public void setSecurityGroups() { - set.setSecurityGroups(123); - } - - @Test - public void getSecurityGroupRules() { - set.getSecurityGroupRules(); - } - - @Test - public void setSecurityGroupRules() { - set.setSecurityGroupRules(123); - } - - @Test - public void getKeyPairs() { - set.getKeyPairs(); - } - - @Test - public void setKeyPairs() { - set.setKeyPairs(123); - } - - @Test - public void getInjectedFilePathBytes() { - set.getInjectedFilePathBytes(); - } - - @Test - public void setInjectedFilePathBytes() { - set.setInjectedFilePathBytes(123); - } -}
\ No newline at end of file + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"quota_set\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"gigabytes\" : 77," + EOL + + " \"ram\" : 38," + EOL + + " \"instances\" : 86," + EOL + + " \"volumes\" : 97," + EOL + + " \"cores\" : 58," + EOL + + " \"metadata_items\" : 97," + EOL + + " \"injected_file_content_bytes\" : 86," + EOL + + " \"injected_files\" : 87," + EOL + + " \"floating_ips\" : 2," + EOL + + " \"security_groups\" : 78," + EOL + + " \"security_group_rules\" : 18," + EOL + + " \"injected_file_path_bytes\" : 52," + EOL + + " \"key_pairs\" : 90" + 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: " + QuotaSet.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + QuotaSet quotaset = objectMapper.readValue(JSON_FULL, QuotaSet.class); + String json = objectMapper.writeValueAsString(quotaset); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + QuotaSet quotaset = objectMapper.readValue(JSON_FULL, QuotaSet.class); + quotaset.toString(); + + Integer injectedFileContentBytes = quotaset.getInjectedFileContentBytes(); + Assert.assertNotNull(injectedFileContentBytes); + quotaset.setInjectedFileContentBytes(injectedFileContentBytes); + + Integer injectedFiles = quotaset.getInjectedFiles(); + Assert.assertNotNull(injectedFiles); + quotaset.setInjectedFiles(injectedFiles); + + Integer instances = quotaset.getInstances(); + Assert.assertNotNull(instances); + quotaset.setInstances(instances); + + Integer gigabytes = quotaset.getGigabytes(); + Assert.assertNotNull(gigabytes); + quotaset.setGigabytes(gigabytes); + + Integer metadataItems = quotaset.getMetadataItems(); + Assert.assertNotNull(metadataItems); + quotaset.setMetadataItems(metadataItems); + + Integer volumes = quotaset.getVolumes(); + Assert.assertNotNull(volumes); + quotaset.setVolumes(volumes); + + Integer injectedFilePathBytes = quotaset.getInjectedFilePathBytes(); + Assert.assertNotNull(injectedFilePathBytes); + quotaset.setInjectedFilePathBytes(injectedFilePathBytes); + + Integer securityGroupRules = quotaset.getSecurityGroupRules(); + Assert.assertNotNull(securityGroupRules); + quotaset.setSecurityGroupRules(securityGroupRules); + + Integer floatingIps = quotaset.getFloatingIps(); + Assert.assertNotNull(floatingIps); + quotaset.setFloatingIps(floatingIps); + + Integer cores = quotaset.getCores(); + Assert.assertNotNull(cores); + quotaset.setCores(cores); + + String id = quotaset.getId(); + Assert.assertNotNull(id); + quotaset.setId(id); + + Integer securityGroups = quotaset.getSecurityGroups(); + Assert.assertNotNull(securityGroups); + quotaset.setSecurityGroups(securityGroups); + + Integer ram = quotaset.getRam(); + Assert.assertNotNull(ram); + quotaset.setRam(ram); + + Integer keyPairs = quotaset.getKeyPairs(); + Assert.assertNotNull(keyPairs); + quotaset.setKeyPairs(keyPairs); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/RateLimitTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/RateLimitTest.java new file mode 100644 index 0000000..24553a5 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/RateLimitTest.java @@ -0,0 +1,89 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Limits.RateLimit; +import com.woorea.openstack.nova.model.Limits.RateLimit.LimitEntry; +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 RateLimitTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"regex\" : \"regex\"," + EOL + + " \"uri\" : \"uri\"," + EOL + + " \"limit\" : [ {" + EOL + + " \"unit\" : \"unit\"," + EOL + + " \"verb\" : \"verb\"," + EOL + + " \"remaining\" : 72," + EOL + + " \"available\" : 47," + EOL + + " \"value\" : 59," + EOL + + " \"next-available\" : 1489320000000" + EOL + + " }, {" + EOL + + " \"unit\" : \"unit\"," + EOL + + " \"verb\" : \"verb\"," + EOL + + " \"remaining\" : 72," + EOL + + " \"available\" : 47," + EOL + + " \"value\" : 59," + EOL + + " \"next-available\" : 1489320000000" + 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: " + RateLimit.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + RateLimit ratelimit = objectMapper.readValue(JSON_FULL, RateLimit.class); + String json = objectMapper.writeValueAsString(ratelimit); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + RateLimit ratelimit = objectMapper.readValue(JSON_FULL, RateLimit.class); + ratelimit.toString(); + + String regex = ratelimit.getRegex(); + Assert.assertNotNull(regex); + + List<LimitEntry> limit = ratelimit.getLimit(); + Assert.assertNotNull(limit); + Assert.assertEquals(2, limit.size()); + + String uri = ratelimit.getUri(); + Assert.assertNotNull(uri); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/RebootTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/RebootTest.java new file mode 100644 index 0000000..1a9ea77 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/RebootTest.java @@ -0,0 +1,69 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Reboot; +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 RebootTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"reboot\" : {" + EOL + + " \"type\" : \"type\"" + 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: " + Reboot.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Reboot reboot = objectMapper.readValue(JSON_FULL, Reboot.class); + String json = objectMapper.writeValueAsString(reboot); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Reboot reboot = objectMapper.readValue(JSON_FULL, Reboot.class); + reboot.toString(); + + String type = reboot.getType(); + Assert.assertNotNull(type); + reboot.setType(type); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/RebuildTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/RebuildTest.java new file mode 100644 index 0000000..1fb9e86 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/RebuildTest.java @@ -0,0 +1,118 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.PersonalityFile; +import com.woorea.openstack.nova.model.ServerAction.Rebuild; +import java.util.List; +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 RebuildTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"rebuild\" : {" + EOL + + " \"imageRef\" : \"imageref\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"adminPass\" : \"adminpass\"," + EOL + + " \"accessIPv4\" : \"accessipv4\"," + EOL + + " \"accessIPv6\" : \"accessipv6\"," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"personality\" : [ {" + EOL + + " \"path\" : \"path\"," + EOL + + " \"contents\" : \"contents\"" + EOL + + " }, {" + EOL + + " \"path\" : \"path\"," + EOL + + " \"contents\" : \"contents\"" + EOL + + " } ]," + EOL + + " \"OS-DCF:diskConfig\" : \"diskconfig\"" + 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: " + Rebuild.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Rebuild rebuild = objectMapper.readValue(JSON_FULL, Rebuild.class); + String json = objectMapper.writeValueAsString(rebuild); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Rebuild rebuild = objectMapper.readValue(JSON_FULL, Rebuild.class); + rebuild.toString(); + + Map<String,String> metadata = rebuild.getMetadata(); + Assert.assertNotNull(metadata); + Assert.assertEquals(2, metadata.size()); + rebuild.setMetadata(metadata); + + List<PersonalityFile> personality = rebuild.getPersonality(); + Assert.assertNotNull(personality); + Assert.assertEquals(2, personality.size()); + rebuild.setPersonality(personality); + + String name = rebuild.getName(); + Assert.assertNotNull(name); + rebuild.setName(name); + + String adminPass = rebuild.getAdminPass(); + Assert.assertNotNull(adminPass); + rebuild.setAdminPass(adminPass); + + String imageRef = rebuild.getImageRef(); + Assert.assertNotNull(imageRef); + rebuild.setImageRef(imageRef); + + String accessIPv6 = rebuild.getAccessIPv6(); + Assert.assertNotNull(accessIPv6); + rebuild.setAccessIPv6(accessIPv6); + + String diskConfig = rebuild.getDiskConfig(); + Assert.assertNotNull(diskConfig); + rebuild.setDiskConfig(diskConfig); + + String accessIPv4 = rebuild.getAccessIPv4(); + Assert.assertNotNull(accessIPv4); + rebuild.setAccessIPv4(accessIPv4); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/RescueResponseTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/RescueResponseTest.java new file mode 100644 index 0000000..519e2a3 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/RescueResponseTest.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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.RescueResponse; +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 RescueResponseTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"adminPass\" : \"adminpass\"" + 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: " + RescueResponse.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + RescueResponse rescueresponse = objectMapper.readValue(JSON_FULL, RescueResponse.class); + String json = objectMapper.writeValueAsString(rescueresponse); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + RescueResponse rescueresponse = objectMapper.readValue(JSON_FULL, RescueResponse.class); + rescueresponse.toString(); + + String adminPass = rescueresponse.getAdminPass(); + Assert.assertNotNull(adminPass); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/RescueTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/RescueTest.java new file mode 100644 index 0000000..ea14bd2 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/RescueTest.java @@ -0,0 +1,69 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Rescue; +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 RescueTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"rescue\" : {" + EOL + + " \"adminPass\" : \"adminpass\"" + 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: " + Rescue.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Rescue rescue = objectMapper.readValue(JSON_FULL, Rescue.class); + String json = objectMapper.writeValueAsString(rescue); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Rescue rescue = objectMapper.readValue(JSON_FULL, Rescue.class); + rescue.toString(); + + String adminPass = rescue.getAdminPass(); + Assert.assertNotNull(adminPass); + rescue.setAdminPass(adminPass); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ResizeTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ResizeTest.java new file mode 100644 index 0000000..05aafd1 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ResizeTest.java @@ -0,0 +1,74 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Resize; +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 ResizeTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"resize\" : {" + EOL + + " \"flavorRef\" : \"flavorref\"," + EOL + + " \"OS-DCF:diskConfig\" : \"diskconfig\"" + 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: " + Resize.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Resize resize = objectMapper.readValue(JSON_FULL, Resize.class); + String json = objectMapper.writeValueAsString(resize); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Resize resize = objectMapper.readValue(JSON_FULL, Resize.class); + resize.toString(); + + String flavorRef = resize.getFlavorRef(); + Assert.assertNotNull(flavorRef); + resize.setFlavorRef(flavorRef); + + String diskConfig = resize.getDiskConfig(); + Assert.assertNotNull(diskConfig); + resize.setDiskConfig(diskConfig); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ResourceTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ResourceTest.java new file mode 100644 index 0000000..b075071 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ResourceTest.java @@ -0,0 +1,80 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Host.ResourceWrapper.Resource; +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 ResourceTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"project\" : \"project\"," + EOL + + " \"host\" : \"host\"," + EOL + + " \"cpu\" : 46," + EOL + + " \"memory_mb\" : 90," + EOL + + " \"disk_gb\" : 46" + 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: " + Resource.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Resource resource = objectMapper.readValue(JSON_FULL, Resource.class); + String json = objectMapper.writeValueAsString(resource); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Resource resource = objectMapper.readValue(JSON_FULL, Resource.class); + resource.toString(); + + Integer memoryMb = resource.getMemoryMb(); + Assert.assertNotNull(memoryMb); + + String host = resource.getHost(); + Assert.assertNotNull(host); + + String project = resource.getProject(); + Assert.assertNotNull(project); + + Integer cpu = resource.getCpu(); + Assert.assertNotNull(cpu); + + Integer diskGb = resource.getDiskGb(); + Assert.assertNotNull(diskGb); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ResourceWrapperTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ResourceWrapperTest.java new file mode 100644 index 0000000..b9ab596 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ResourceWrapperTest.java @@ -0,0 +1,71 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.Host.ResourceWrapper; +import com.woorea.openstack.nova.model.Host.ResourceWrapper.Resource; +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 ResourceWrapperTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"resource\" : {" + EOL + + " \"project\" : \"project\"," + EOL + + " \"host\" : \"host\"," + EOL + + " \"cpu\" : 46," + EOL + + " \"memory_mb\" : 90," + EOL + + " \"disk_gb\" : 46" + 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: " + ResourceWrapper.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + ResourceWrapper resourcewrapper = objectMapper.readValue(JSON_FULL, ResourceWrapper.class); + String json = objectMapper.writeValueAsString(resourcewrapper); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + ResourceWrapper resourcewrapper = objectMapper.readValue(JSON_FULL, ResourceWrapper.class); + resourcewrapper.toString(); + + Resource resource = resourcewrapper.getResource(); + Assert.assertNotNull(resource); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/RestoreTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/RestoreTest.java new file mode 100644 index 0000000..1b78aac --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/RestoreTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Restore; +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 RestoreTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"restore\" : { }" + 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: " + Restore.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Restore restore = objectMapper.readValue(JSON_FULL, Restore.class); + String json = objectMapper.writeValueAsString(restore); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Restore restore = objectMapper.readValue(JSON_FULL, Restore.class); + restore.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ResumeTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ResumeTest.java new file mode 100644 index 0000000..e8b1ff3 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ResumeTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Resume; +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 ResumeTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"resume\" : { }" + 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: " + Resume.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Resume resume = objectMapper.readValue(JSON_FULL, Resume.class); + String json = objectMapper.writeValueAsString(resume); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Resume resume = objectMapper.readValue(JSON_FULL, Resume.class); + resume.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/RevertResizeTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/RevertResizeTest.java new file mode 100644 index 0000000..b3d6d36 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/RevertResizeTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.RevertResize; +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 RevertResizeTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"revertResize\" : { }" + 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: " + RevertResize.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + RevertResize revertresize = objectMapper.readValue(JSON_FULL, RevertResize.class); + String json = objectMapper.writeValueAsString(revertresize); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + RevertResize revertresize = objectMapper.readValue(JSON_FULL, RevertResize.class); + revertresize.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/RuleTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/RuleTest.java new file mode 100644 index 0000000..0ec78dc --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/RuleTest.java @@ -0,0 +1,103 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.SecurityGroup.Rule; +import com.woorea.openstack.nova.model.SecurityGroup.Rule.Group; +import com.woorea.openstack.nova.model.SecurityGroup.Rule.IpRange; +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 RuleTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"security_group_rule\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"group\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }," + EOL + + " \"parent_group_id\" : \"parentgroupid\"," + EOL + + " \"from_port\" : 7," + EOL + + " \"to_port\" : 98," + EOL + + " \"ip_protocol\" : \"ipprotocol\"," + EOL + + " \"ip_range\" : {" + EOL + + " \"cidr\" : \"cidr\"" + EOL + + " }" + 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: " + Rule.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Rule rule = objectMapper.readValue(JSON_FULL, Rule.class); + String json = objectMapper.writeValueAsString(rule); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Rule rule = objectMapper.readValue(JSON_FULL, Rule.class); + rule.toString(); + + String parentGroupId = rule.getParentGroupId(); + Assert.assertNotNull(parentGroupId); + + String ipProtocol = rule.getIpProtocol(); + Assert.assertNotNull(ipProtocol); + + IpRange ipRange = rule.getIpRange(); + Assert.assertNotNull(ipRange); + + Integer fromPort = rule.getFromPort(); + Assert.assertNotNull(fromPort); + + String name = rule.getName(); + Assert.assertNotNull(name); + + String id = rule.getId(); + Assert.assertNotNull(id); + + Integer toPort = rule.getToPort(); + Assert.assertNotNull(toPort); + + Group group = rule.getGroup(); + Assert.assertNotNull(group); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupForCreateTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupForCreateTest.java index 9b3001f..71460b4 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupForCreateTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupForCreateTest.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 @@ -17,32 +17,58 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.SecurityGroupForCreate; +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 SecurityGroupForCreateTest { - SecurityGroupForCreate securityGroupForCreate = new SecurityGroupForCreate(); + private static final String EOL = System.lineSeparator(); - @Test - public void getName() throws Exception { - securityGroupForCreate.getName(); - } + private static final String JSON_FULL = "{" + EOL + + " \"security_group\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"" + EOL + + " }" + EOL + + "}"; - @Test - public void setName() throws Exception { - securityGroupForCreate.setName("test"); - } + 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 getDescription() throws Exception { - securityGroupForCreate.getDescription(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + SecurityGroupForCreate.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + SecurityGroupForCreate securitygroupforcreate = objectMapper.readValue(JSON_FULL, SecurityGroupForCreate.class); + String json = objectMapper.writeValueAsString(securitygroupforcreate); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setDescription() throws Exception { - securityGroupForCreate.setDescription("desc"); + public void testMethods() throws Exception { + SecurityGroupForCreate securitygroupforcreate = objectMapper.readValue(JSON_FULL, SecurityGroupForCreate.class); + securitygroupforcreate.toString(); + + String name = securitygroupforcreate.getName(); + Assert.assertNotNull(name); + securitygroupforcreate.setName(name); + + String description = securitygroupforcreate.getDescription(); + Assert.assertNotNull(description); + securitygroupforcreate.setDescription(description); } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupRuleForCreateTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupRuleForCreateTest.java index d72094b..ae1dbac 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupRuleForCreateTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupRuleForCreateTest.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 @@ -17,82 +17,78 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.SecurityGroupRuleForCreate; +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 SecurityGroupRuleForCreateTest { - SecurityGroupRuleForCreate securityGroupRuleForCreate = new SecurityGroupRuleForCreate(); - - @Test - public void getParentGroupId() throws Exception { - securityGroupRuleForCreate.getParentGroupId(); - } - - @Test - public void setParentGroupId() throws Exception { - securityGroupRuleForCreate.setParentGroupId("parent"); - } - - @Test - public void setParentGroupId1() throws Exception { - securityGroupRuleForCreate.setParentGroupId(1); - } - - @Test - public void getFromPort() throws Exception { - securityGroupRuleForCreate.getFromPort(); - } - - @Test - public void setFromPort() throws Exception { - securityGroupRuleForCreate.setFromPort(80); - } - - @Test - public void getToPort() throws Exception { - securityGroupRuleForCreate.getToPort(); - } + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"security_group_rule\" : {" + EOL + + " \"cidr\" : \"cidr\"," + EOL + + " \"parent_group_id\" : \"parentgroupid\"," + EOL + + " \"ip_protocol\" : \"ipprotocol\"," + EOL + + " \"from_port\" : 7," + EOL + + " \"to_port\" : 98," + EOL + + " \"group_id\" : \"groupid\"" + 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 setToPort() throws Exception { - securityGroupRuleForCreate.setToPort(80); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + SecurityGroupRuleForCreate.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + SecurityGroupRuleForCreate securitygroupruleforcreate = objectMapper.readValue(JSON_FULL, SecurityGroupRuleForCreate.class); + String json = objectMapper.writeValueAsString(securitygroupruleforcreate); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getIpProtocol() throws Exception { - securityGroupRuleForCreate.getIpProtocol(); + public void testMethods() throws Exception { + SecurityGroupRuleForCreate securitygroupruleforcreate = objectMapper.readValue(JSON_FULL, SecurityGroupRuleForCreate.class); + securitygroupruleforcreate.toString(); + + String parentGroupId = securitygroupruleforcreate.getParentGroupId(); + Assert.assertNotNull(parentGroupId); + securitygroupruleforcreate.setParentGroupId(parentGroupId); + + String ipProtocol = securitygroupruleforcreate.getIpProtocol(); + Assert.assertNotNull(ipProtocol); + securitygroupruleforcreate.setIpProtocol(ipProtocol); + + String groupId = securitygroupruleforcreate.getGroupId(); + Assert.assertNotNull(groupId); + securitygroupruleforcreate.setGroupId(groupId); + + Integer fromPort = securitygroupruleforcreate.getFromPort(); + Assert.assertNotNull(fromPort); + securitygroupruleforcreate.setFromPort(fromPort); + + String cidr = securitygroupruleforcreate.getCidr(); + Assert.assertNotNull(cidr); + securitygroupruleforcreate.setCidr(cidr); + + Integer toPort = securitygroupruleforcreate.getToPort(); + Assert.assertNotNull(toPort); + securitygroupruleforcreate.setToPort(toPort); } - - @Test - public void setIpProtocol() throws Exception { - securityGroupRuleForCreate.setIpProtocol("test"); - } - - @Test - public void getCidr() throws Exception { - securityGroupRuleForCreate.getCidr(); - } - - @Test - public void setCidr() throws Exception { - securityGroupRuleForCreate.setCidr("test"); - } - - @Test - public void getGroupId() throws Exception { - securityGroupRuleForCreate.getGroupId(); - } - - @Test - public void setGroupId() throws Exception { - securityGroupRuleForCreate.setGroupId("test"); - } - - @Test - public void setGroupId1() throws Exception { - securityGroupRuleForCreate.setGroupId(1); - } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupTest.java index e238c4e..5bcc32a 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupTest.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 @@ -17,42 +17,49 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.ServerForCreate.SecurityGroup; +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 SecurityGroupTest { - SecurityGroup securityGroup = new SecurityGroup(); + private static final String EOL = System.lineSeparator(); - @Test - public void getId() throws Exception { - securityGroup.getId(); - } + private static final String JSON_FULL = "{" + EOL + + " \"name\" : \"name\"" + EOL + + "}"; - @Test - public void getName() throws Exception { - securityGroup.getName(); - } + 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 getDescription() throws Exception { - securityGroup.getDescription(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + SecurityGroup.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + SecurityGroup securitygroup = objectMapper.readValue(JSON_FULL, SecurityGroup.class); + String json = objectMapper.writeValueAsString(securitygroup); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getTenantId() throws Exception { - securityGroup.getTenantId(); + public void testMethods() throws Exception { + SecurityGroup securitygroup = objectMapper.readValue(JSON_FULL, SecurityGroup.class); + securitygroup.toString(); + + String name = securitygroup.getName(); + Assert.assertNotNull(name); + securitygroup.setName(name); } - - @Test - public void getRules() throws Exception { - securityGroup.getRules(); - } - - @Test - public void getLinks() throws Exception { - securityGroup.getLinks(); - } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupsTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupsTest.java index c5ecf89..f3446f2 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupsTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/SecurityGroupsTest.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 @@ -17,22 +17,143 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.SecurityGroup; +import com.woorea.openstack.nova.model.SecurityGroups; +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 SecurityGroupsTest { - SecurityGroups securityGroups = new SecurityGroups(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"security_groups\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"rules\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"group\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }," + EOL + + " \"parent_group_id\" : \"parentgroupid\"," + EOL + + " \"from_port\" : 7," + EOL + + " \"to_port\" : 98," + EOL + + " \"ip_protocol\" : \"ipprotocol\"," + EOL + + " \"ip_range\" : {" + EOL + + " \"cidr\" : \"cidr\"" + EOL + + " }" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"group\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }," + EOL + + " \"parent_group_id\" : \"parentgroupid\"," + EOL + + " \"from_port\" : 7," + EOL + + " \"to_port\" : 98," + EOL + + " \"ip_protocol\" : \"ipprotocol\"," + EOL + + " \"ip_range\" : {" + EOL + + " \"cidr\" : \"cidr\"" + EOL + + " }" + EOL + + " } ]," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"rules\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"group\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }," + EOL + + " \"parent_group_id\" : \"parentgroupid\"," + EOL + + " \"from_port\" : 7," + EOL + + " \"to_port\" : 98," + EOL + + " \"ip_protocol\" : \"ipprotocol\"," + EOL + + " \"ip_range\" : {" + EOL + + " \"cidr\" : \"cidr\"" + EOL + + " }" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"group\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }," + EOL + + " \"parent_group_id\" : \"parentgroupid\"," + EOL + + " \"from_port\" : 7," + EOL + + " \"to_port\" : 98," + EOL + + " \"ip_protocol\" : \"ipprotocol\"," + EOL + + " \"ip_range\" : {" + EOL + + " \"cidr\" : \"cidr\"" + EOL + + " }" + EOL + + " } ]," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + 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 getList() throws Exception { - securityGroups.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + SecurityGroups.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + SecurityGroups securitygroups = objectMapper.readValue(JSON_FULL, SecurityGroups.class); + String json = objectMapper.writeValueAsString(securitygroups); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - securityGroups.iterator(); + @Test + public void testMethods() throws Exception { + SecurityGroups securitygroups = objectMapper.readValue(JSON_FULL, SecurityGroups.class); + securitygroups.toString(); + + List<SecurityGroup> list = securitygroups.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") SecurityGroup x : securitygroups) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ServerForCreateTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ServerForCreateTest.java index ce7b4a2..2653f02 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/ServerForCreateTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ServerForCreateTest.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 @@ -17,185 +17,156 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.NetworkForCreate; +import com.woorea.openstack.nova.model.PersonalityFile; +import com.woorea.openstack.nova.model.ServerForCreate; +import com.woorea.openstack.nova.model.ServerForCreate.SecurityGroup; +import java.util.List; +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 java.util.Collections; -import java.util.HashMap; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class ServerForCreateTest { - ServerForCreate serverForCreate = new ServerForCreate(); - - @Test - public void getName() throws Exception { - serverForCreate.getName(); - } - - @Test - public void setName() throws Exception { - serverForCreate.setName("test"); - } - - @Test - public void getAdminPass() throws Exception { - serverForCreate.getAdminPass(); - } - - @Test - public void setAdminPass() throws Exception { - serverForCreate.setAdminPass("adminpass"); - } - - @Test - public void getImageRef() throws Exception { - serverForCreate.getImageRef(); - } - - @Test - public void setImageRef() throws Exception { - serverForCreate.setImageRef("image"); - } - - @Test - public void getFlavorRef() throws Exception { - serverForCreate.getFlavorRef(); - } - - @Test - public void setFlavorRef() throws Exception { - serverForCreate.setFlavorRef("test"); - } - - @Test - public void getAccessIPv4() throws Exception { - serverForCreate.getAccessIPv4(); - } - - @Test - public void setAccessIPv4() throws Exception { - serverForCreate.setAccessIPv4("test"); - } - - @Test - public void getAccessIPv6() throws Exception { - serverForCreate.getAccessIPv6(); - } - - @Test - public void setAccessIPv6() throws Exception { - serverForCreate.setAccessIPv6("ipv6"); - } - - @Test - public void getMin() throws Exception { - serverForCreate.getMin(); - } - - @Test - public void setMin() throws Exception { - serverForCreate.setMin(1); - } - - @Test - public void getMax() throws Exception { - serverForCreate.setMax(2); - } - - @Test - public void setMax() throws Exception { - serverForCreate.setMax(2); - } - - @Test - public void getDiskConfig() throws Exception { - serverForCreate.getDiskConfig(); - } - - @Test - public void setDiskConfig() throws Exception { - serverForCreate.setDiskConfig("config"); - } - - @Test - public void getKeyName() throws Exception { - serverForCreate.getKeyName(); - } - - @Test - public void setKeyName() throws Exception { - serverForCreate.setKeyName("test"); - } - - @Test - public void getPersonality() throws Exception { - serverForCreate.getPersonality(); - } - - @Test - public void setPersonality() throws Exception { - serverForCreate.setPersonality(Collections.<PersonalityFile>emptyList()); - } - - @Test - public void getMetadata() throws Exception { - serverForCreate.getMetadata(); - } - - @Test - public void setMetadata() throws Exception { - serverForCreate.setMetadata(new HashMap<String, String>()); - } - - @Test - public void getSecurityGroups() throws Exception { - serverForCreate.getSecurityGroups(); - } - - @Test - public void getUserData() throws Exception { - serverForCreate.getUserData(); - } - - @Test - public void setUserData() throws Exception { - serverForCreate.setUserData("test"); - } - - @Test - public void getAvailabilityZone() throws Exception { - serverForCreate.getAvailabilityZone(); - } - - @Test - public void setAvailabilityZone() throws Exception { - serverForCreate.setAvailabilityZone("test"); - } - - @Test - public void isConfigDrive() throws Exception { - serverForCreate.isConfigDrive(); - } - - @Test - public void setConfigDrive() throws Exception { - serverForCreate.setConfigDrive(true); - } - - @Test - public void getNetworks() throws Exception { - serverForCreate.getNetworks(); - } - - @Test - public void setNetworks() throws Exception { - serverForCreate.setNetworks(Collections.<NetworkForCreate>emptyList()); - } - - @Test - public void addNetworks() throws Exception { - serverForCreate.addNetworks("test", "localhost"); - } - -}
\ No newline at end of file + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"server\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"adminPass\" : \"adminpass\"," + EOL + + " \"imageRef\" : \"imageref\"," + EOL + + " \"flavorRef\" : \"flavorref\"," + EOL + + " \"accessIPv4\" : \"accessipv4\"," + EOL + + " \"accessIPv6\" : \"accessipv6\"," + EOL + + " \"min\" : 42," + EOL + + " \"max\" : 44," + EOL + + " \"diskConfig\" : \"diskconfig\"," + EOL + + " \"personality\" : [ {" + EOL + + " \"path\" : \"path\"," + EOL + + " \"contents\" : \"contents\"" + EOL + + " }, {" + EOL + + " \"path\" : \"path\"," + EOL + + " \"contents\" : \"contents\"" + EOL + + " } ]," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"networks\" : [ {" + EOL + + " \"uuid\" : \"id\"," + EOL + + " \"fixed_ip\" : \"fixedip\"" + EOL + + " }, {" + EOL + + " \"uuid\" : \"id\"," + EOL + + " \"fixed_ip\" : \"fixedip\"" + EOL + + " } ]," + EOL + + " \"key_name\" : \"keyname\"," + EOL + + " \"security_groups\" : [ {" + EOL + + " \"name\" : \"name\"" + EOL + + " }, {" + EOL + + " \"name\" : \"name\"" + EOL + + " } ]," + EOL + + " \"user_data\" : \"userdata\"," + EOL + + " \"availability_zone\" : \"availabilityzone\"," + EOL + + " \"config_drive\" : true" + 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: " + ServerForCreate.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + ServerForCreate serverforcreate = objectMapper.readValue(JSON_FULL, ServerForCreate.class); + String json = objectMapper.writeValueAsString(serverforcreate); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + ServerForCreate serverforcreate = objectMapper.readValue(JSON_FULL, ServerForCreate.class); + serverforcreate.toString(); + + Map<String,String> metadata = serverforcreate.getMetadata(); + Assert.assertNotNull(metadata); + Assert.assertEquals(2, metadata.size()); + serverforcreate.setMetadata(metadata); + + Integer max = serverforcreate.getMax(); + Assert.assertNotNull(max); + serverforcreate.setMax(max); + + List<NetworkForCreate> networks = serverforcreate.getNetworks(); + Assert.assertNotNull(networks); + Assert.assertEquals(2, networks.size()); + serverforcreate.setNetworks(networks); + + String userData = serverforcreate.getUserData(); + Assert.assertNotNull(userData); + serverforcreate.setUserData(userData); + + Integer min = serverforcreate.getMin(); + Assert.assertNotNull(min); + serverforcreate.setMin(min); + + List<PersonalityFile> personality = serverforcreate.getPersonality(); + Assert.assertNotNull(personality); + Assert.assertEquals(2, personality.size()); + serverforcreate.setPersonality(personality); + + String name = serverforcreate.getName(); + Assert.assertNotNull(name); + serverforcreate.setName(name); + + String flavorRef = serverforcreate.getFlavorRef(); + Assert.assertNotNull(flavorRef); + serverforcreate.setFlavorRef(flavorRef); + + String keyName = serverforcreate.getKeyName(); + Assert.assertNotNull(keyName); + serverforcreate.setKeyName(keyName); + + String adminPass = serverforcreate.getAdminPass(); + Assert.assertNotNull(adminPass); + serverforcreate.setAdminPass(adminPass); + + String imageRef = serverforcreate.getImageRef(); + Assert.assertNotNull(imageRef); + serverforcreate.setImageRef(imageRef); + + String accessIPv6 = serverforcreate.getAccessIPv6(); + Assert.assertNotNull(accessIPv6); + serverforcreate.setAccessIPv6(accessIPv6); + + String diskConfig = serverforcreate.getDiskConfig(); + Assert.assertNotNull(diskConfig); + serverforcreate.setDiskConfig(diskConfig); + + List<SecurityGroup> securityGroups = serverforcreate.getSecurityGroups(); + Assert.assertNotNull(securityGroups); + Assert.assertEquals(2, securityGroups.size()); + + String availabilityZone = serverforcreate.getAvailabilityZone(); + Assert.assertNotNull(availabilityZone); + serverforcreate.setAvailabilityZone(availabilityZone); + + String accessIPv4 = serverforcreate.getAccessIPv4(); + Assert.assertNotNull(accessIPv4); + serverforcreate.setAccessIPv4(accessIPv4); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ServerTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ServerTest.java index e7658c1..3aa4833 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/ServerTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ServerTest.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 @@ -17,187 +17,379 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Flavor; +import com.woorea.openstack.nova.model.Image; +import com.woorea.openstack.nova.model.Link; +import com.woorea.openstack.nova.model.SecurityGroup; +import com.woorea.openstack.nova.model.Server; +import com.woorea.openstack.nova.model.Server.Addresses; +import com.woorea.openstack.nova.model.Server.Fault; +import java.util.List; +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 ServerTest { - Server server = new Server(); - - @Test - public void getId() throws Exception { - server.getId(); - } - - @Test - public void getName() throws Exception { - server.getName(); - } - - @Test - public void getAddresses() throws Exception { - server.getAddresses(); - } - - @Test - public void getLinks() throws Exception { - server.getLinks(); - } - - @Test - public void getImage() throws Exception { - server.getImage(); - } - - @Test - public void setImage() throws Exception { - server.setImage(new Image()); - } - - @Test - public void getFlavor() throws Exception { - server.getFlavor(); - } - - @Test - public void setFlavor() throws Exception { - server.setFlavor(new Flavor()); - } - - @Test - public void getAccessIPv4() throws Exception { - server.getAccessIPv4(); - } - - @Test - public void getAccessIPv6() throws Exception { - server.getAccessIPv6(); - } - - @Test - public void getConfigDrive() throws Exception { - server.getConfigDrive(); - } - - @Test - public void getStatus() throws Exception { - server.getStatus(); - } - - @Test - public void getProgress() throws Exception { - server.getProgress(); - } - - @Test - public void getFault() throws Exception { - server.getFault(); - } - - @Test - public void getTenantId() throws Exception { - server.getTenantId(); - } - - @Test - public void getUserId() throws Exception { - server.getUserId(); - } - - @Test - public void getKeyName() throws Exception { - server.getKeyName(); - } - - @Test - public void getHostId() throws Exception { - server.getHostId(); - } - - @Test - public void getUpdated() throws Exception { - server.getUpdated(); - } - - @Test - public void getCreated() throws Exception { - server.getCreated(); - } - - @Test - public void getMetadata() throws Exception { - server.getMetadata(); - } - - @Test - public void getSecurityGroups() throws Exception { - server.getSecurityGroups(); - } - - @Test - public void getTaskState() throws Exception { - server.getTaskState(); - } - - @Test - public void getPowerState() throws Exception { - server.getPowerState(); - } - - @Test - public void getVmState() throws Exception { - server.getVmState(); - } - - @Test - public void getHost() throws Exception { - server.getHost(); - } - - @Test - public void getInstanceName() throws Exception { - server.getInstanceName(); - } - - @Test - public void getHypervisorHostname() throws Exception { - server.getHypervisorHostname(); - } - - @Test - public void getDiskConfig() throws Exception { - server.getDiskConfig(); - } - - @Test - public void getAvailabilityZone() throws Exception { - server.getAvailabilityZone(); - } - - @Test - public void getLaunchedAt() throws Exception { - server.getLaunchedAt(); - } - - @Test - public void getTerminatedAt() throws Exception { - server.getTerminatedAt(); - } - - @Test - public void getOsExtendedVolumesAttached() throws Exception { - server.getOsExtendedVolumesAttached(); - } - - @Test - public void getUuid() throws Exception { - server.getUuid(); - } - - @Test - public void getAdminPass() throws Exception { - server.getAdminPass(); - } - -}
\ No newline at end of file + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"server\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"addresses\" : {" + EOL + + " \"addresses\" : {" + EOL + + " \"addresses-k1\" : [ {" + EOL + + " \"version\" : \"version\"," + EOL + + " \"addr\" : \"addr\"," + EOL + + " \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL + + " \"OS-EXT-IPS:type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"version\" : \"version\"," + EOL + + " \"addr\" : \"addr\"," + EOL + + " \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL + + " \"OS-EXT-IPS:type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"addresses-k2\" : [ {" + EOL + + " \"version\" : \"version\"," + EOL + + " \"addr\" : \"addr\"," + EOL + + " \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL + + " \"OS-EXT-IPS:type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"version\" : \"version\"," + EOL + + " \"addr\" : \"addr\"," + EOL + + " \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL + + " \"OS-EXT-IPS:type\" : \"type\"" + EOL + + " } ]" + EOL + + " }" + EOL + + " }," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"image\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"progress\" : 3," + EOL + + " \"minRam\" : 62," + EOL + + " \"minDisk\" : 69," + EOL + + " \"created\" : 1485172800000," + EOL + + " \"updated\" : 1486468800000," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"server\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]" + EOL + + " }," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"OS-EXT-IMG-SIZE:size\" : 43" + EOL + + " }," + EOL + + " \"flavor\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"vcpus\" : 79," + EOL + + " \"ram\" : 38," + EOL + + " \"disk\" : 45," + EOL + + " \"swap\" : \"swap\"," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"public\" : false," + EOL + + " \"OS-FLV-EXT-DATA:ephemeral\" : 65," + EOL + + " \"rxtx_factor\" : 11.0," + EOL + + " \"OS-FLV-DISABLED:disabled\" : true," + EOL + + " \"rxtx_quota\" : 42," + EOL + + " \"rxtx_cap\" : 96," + EOL + + " \"os-flavor-access:is_public\" : false" + EOL + + " }," + EOL + + " \"accessIPv4\" : \"accessipv4\"," + EOL + + " \"accessIPv6\" : \"accessipv6\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"progress\" : 3," + EOL + + " \"fault\" : {" + EOL + + " \"code\" : 29," + EOL + + " \"message\" : \"message\"," + EOL + + " \"details\" : \"details\"," + EOL + + " \"created\" : 1485172800000" + EOL + + " }," + EOL + + " \"hostId\" : \"hostid\"," + EOL + + " \"updated\" : \"updated\"," + EOL + + " \"created\" : \"created\"," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"uuid\" : \"uuid\"," + EOL + + " \"adminPass\" : \"adminpass\"," + EOL + + " \"config_drive\" : \"configdrive\"," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"user_id\" : \"userid\"," + EOL + + " \"key_name\" : \"keyname\"," + EOL + + " \"security_groups\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"rules\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"group\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }," + EOL + + " \"parent_group_id\" : \"parentgroupid\"," + EOL + + " \"from_port\" : 7," + EOL + + " \"to_port\" : 98," + EOL + + " \"ip_protocol\" : \"ipprotocol\"," + EOL + + " \"ip_range\" : {" + EOL + + " \"cidr\" : \"cidr\"" + EOL + + " }" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"group\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }," + EOL + + " \"parent_group_id\" : \"parentgroupid\"," + EOL + + " \"from_port\" : 7," + EOL + + " \"to_port\" : 98," + EOL + + " \"ip_protocol\" : \"ipprotocol\"," + EOL + + " \"ip_range\" : {" + EOL + + " \"cidr\" : \"cidr\"" + EOL + + " }" + EOL + + " } ]," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"rules\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"group\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }," + EOL + + " \"parent_group_id\" : \"parentgroupid\"," + EOL + + " \"from_port\" : 7," + EOL + + " \"to_port\" : 98," + EOL + + " \"ip_protocol\" : \"ipprotocol\"," + EOL + + " \"ip_range\" : {" + EOL + + " \"cidr\" : \"cidr\"" + EOL + + " }" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"group\" : {" + EOL + + " \"name\" : \"name\"," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " }," + EOL + + " \"parent_group_id\" : \"parentgroupid\"," + EOL + + " \"from_port\" : 7," + EOL + + " \"to_port\" : 98," + EOL + + " \"ip_protocol\" : \"ipprotocol\"," + EOL + + " \"ip_range\" : {" + EOL + + " \"cidr\" : \"cidr\"" + EOL + + " }" + EOL + + " } ]," + EOL + + " \"links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]," + EOL + + " \"tenant_id\" : \"tenantid\"" + EOL + + " } ]," + EOL + + " \"OS-EXT-STS:task_state\" : \"taskstate\"," + EOL + + " \"OS-EXT-STS:power_state\" : \"powerstate\"," + EOL + + " \"OS-EXT-STS:vm_state\" : \"vmstate\"," + EOL + + " \"OS-EXT-SRV-ATTR:host\" : \"host\"," + EOL + + " \"OS-EXT-SRV-ATTR:instance_name\" : \"instancename\"," + EOL + + " \"OS-EXT-SRV-ATTR:hypervisor_hostname\" : \"hypervisorhostname\"," + EOL + + " \"OS-DCF:diskConfig\" : \"diskconfig\"," + EOL + + " \"OS-EXT-AZ:availability_zone\" : \"availabilityzone\"," + EOL + + " \"OS-SRV-USG:launched_at\" : \"launchedat\"," + EOL + + " \"OS-SRV-USG:terminated_at\" : \"terminatedat\"," + EOL + + " \"os-extended-volumes:volumes_attached\" : [ \"osextendedvolumesattached-v1\", \"osextendedvolumesattached-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 { + System.out.println("CLASS: " + Server.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Server server = objectMapper.readValue(JSON_FULL, Server.class); + String json = objectMapper.writeValueAsString(server); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Server server = objectMapper.readValue(JSON_FULL, Server.class); + server.toString(); + + Addresses addresses = server.getAddresses(); + Assert.assertNotNull(addresses); + + Map<String,String> metadata = server.getMetadata(); + Assert.assertNotNull(metadata); + Assert.assertEquals(2, metadata.size()); + + String hostId = server.getHostId(); + Assert.assertNotNull(hostId); + + String uuid = server.getUuid(); + Assert.assertNotNull(uuid); + + String userId = server.getUserId(); + Assert.assertNotNull(userId); + + String taskState = server.getTaskState(); + Assert.assertNotNull(taskState); + + String powerState = server.getPowerState(); + Assert.assertNotNull(powerState); + + String vmState = server.getVmState(); + Assert.assertNotNull(vmState); + + String tenantId = server.getTenantId(); + Assert.assertNotNull(tenantId); + + String configDrive = server.getConfigDrive(); + Assert.assertNotNull(configDrive); + + String host = server.getHost(); + Assert.assertNotNull(host); + + String keyName = server.getKeyName(); + Assert.assertNotNull(keyName); + + List<Link> links = server.getLinks(); + Assert.assertNotNull(links); + Assert.assertEquals(2, links.size()); + + String id = server.getId(); + Assert.assertNotNull(id); + + String launchedAt = server.getLaunchedAt(); + Assert.assertNotNull(launchedAt); + + Image image = server.getImage(); + Assert.assertNotNull(image); + server.setImage(image); + + String terminatedAt = server.getTerminatedAt(); + Assert.assertNotNull(terminatedAt); + + String created = server.getCreated(); + Assert.assertNotNull(created); + + Fault fault = server.getFault(); + Assert.assertNotNull(fault); + + String hypervisorHostname = server.getHypervisorHostname(); + Assert.assertNotNull(hypervisorHostname); + + Flavor flavor = server.getFlavor(); + Assert.assertNotNull(flavor); + server.setFlavor(flavor); + + String instanceName = server.getInstanceName(); + Assert.assertNotNull(instanceName); + + List<String> osExtendedVolumesAttached = server.getOsExtendedVolumesAttached(); + Assert.assertNotNull(osExtendedVolumesAttached); + Assert.assertEquals(2, osExtendedVolumesAttached.size()); + + String name = server.getName(); + Assert.assertNotNull(name); + + Integer progress = server.getProgress(); + Assert.assertNotNull(progress); + + String adminPass = server.getAdminPass(); + Assert.assertNotNull(adminPass); + + String accessIPv6 = server.getAccessIPv6(); + Assert.assertNotNull(accessIPv6); + + String diskConfig = server.getDiskConfig(); + Assert.assertNotNull(diskConfig); + + List<SecurityGroup> securityGroups = server.getSecurityGroups(); + Assert.assertNotNull(securityGroups); + Assert.assertEquals(2, securityGroups.size()); + + String updated = server.getUpdated(); + Assert.assertNotNull(updated); + + String availabilityZone = server.getAvailabilityZone(); + Assert.assertNotNull(availabilityZone); + + String accessIPv4 = server.getAccessIPv4(); + Assert.assertNotNull(accessIPv4); + + String status = server.getStatus(); + Assert.assertNotNull(status); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ServerUsageTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ServerUsageTest.java new file mode 100644 index 0000000..4b7f683 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ServerUsageTest.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.nova.model; + +import com.woorea.openstack.nova.model.SimpleTenantUsage.ServerUsage; +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 ServerUsageTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"uptime\" : 78," + EOL + + " \"state\" : \"state\"," + EOL + + " \"hours\" : 64.0," + EOL + + " \"vcpus\" : 79," + EOL + + " \"flavor\" : \"flavor\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"instance_id\" : \"instanceid\"," + EOL + + " \"started_at\" : \"startedat\"," + EOL + + " \"ended_at\" : \"endedat\"," + EOL + + " \"memory_mb\" : 90," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"local_gb\" : 11" + 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: " + ServerUsage.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + ServerUsage serverusage = objectMapper.readValue(JSON_FULL, ServerUsage.class); + String json = objectMapper.writeValueAsString(serverusage); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + ServerUsage serverusage = objectMapper.readValue(JSON_FULL, ServerUsage.class); + serverusage.toString(); + + String flavor = serverusage.getFlavor(); + Assert.assertNotNull(flavor); + + Integer memoryMb = serverusage.getMemoryMb(); + Assert.assertNotNull(memoryMb); + + Double hours = serverusage.getHours(); + Assert.assertNotNull(hours); + + String instanceId = serverusage.getInstanceId(); + Assert.assertNotNull(instanceId); + + Integer localDiskSize = serverusage.getLocalDiskSize(); + Assert.assertNotNull(localDiskSize); + + String endedAt = serverusage.getEndedAt(); + Assert.assertNotNull(endedAt); + + String name = serverusage.getName(); + Assert.assertNotNull(name); + + String tenantId = serverusage.getTenantId(); + Assert.assertNotNull(tenantId); + + String startedAt = serverusage.getStartedAt(); + Assert.assertNotNull(startedAt); + + String state = serverusage.getState(); + Assert.assertNotNull(state); + + Integer vcpus = serverusage.getVcpus(); + Assert.assertNotNull(vcpus); + + Integer uptime = serverusage.getUptime(); + Assert.assertNotNull(uptime); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/ServersTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/ServersTest.java index 313f6f7..7f45acc 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/ServersTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/ServersTest.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 @@ -17,22 +17,503 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Server; +import com.woorea.openstack.nova.model.Servers; +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 ServersTest { - Servers servers = new Servers(); + private static final String EOL = System.lineSeparator(); - @Test - public void getList() throws Exception { - servers.getList(); + private static final String JSON_FULL; + + static { + // StringBuilder is used because extremely long concatenations + // can cause compiler stack overflow + StringBuilder sb = new StringBuilder(); + sb.append("{" + EOL); + sb.append(" \"servers\" : [ {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"addresses\" : {" + EOL); + sb.append(" \"addresses\" : {" + EOL); + sb.append(" \"addresses-k1\" : [ {" + EOL); + sb.append(" \"version\" : \"version\"," + EOL); + sb.append(" \"addr\" : \"addr\"," + EOL); + sb.append(" \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL); + sb.append(" \"OS-EXT-IPS:type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"version\" : \"version\"," + EOL); + sb.append(" \"addr\" : \"addr\"," + EOL); + sb.append(" \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL); + sb.append(" \"OS-EXT-IPS:type\" : \"type\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"addresses-k2\" : [ {" + EOL); + sb.append(" \"version\" : \"version\"," + EOL); + sb.append(" \"addr\" : \"addr\"," + EOL); + sb.append(" \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL); + sb.append(" \"OS-EXT-IPS:type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"version\" : \"version\"," + EOL); + sb.append(" \"addr\" : \"addr\"," + EOL); + sb.append(" \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL); + sb.append(" \"OS-EXT-IPS:type\" : \"type\"" + EOL); + sb.append(" } ]" + EOL); + sb.append(" }" + EOL); + sb.append(" }," + EOL); + sb.append(" \"links\" : [ {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"image\" : {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"status\" : \"status\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"progress\" : 3," + EOL); + sb.append(" \"minRam\" : 62," + EOL); + sb.append(" \"minDisk\" : 69," + EOL); + sb.append(" \"created\" : 1485172800000," + EOL); + sb.append(" \"updated\" : 1486468800000," + EOL); + sb.append(" \"metadata\" : {" + EOL); + sb.append(" \"metadata-k1\" : \"metadata-v1\"," + EOL); + sb.append(" \"metadata-k2\" : \"metadata-v2\"" + EOL); + sb.append(" }," + EOL); + sb.append(" \"server\" : {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"links\" : [ {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" } ]" + EOL); + sb.append(" }," + EOL); + sb.append(" \"links\" : [ {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"OS-EXT-IMG-SIZE:size\" : 43" + EOL); + sb.append(" }," + EOL); + sb.append(" \"flavor\" : {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"vcpus\" : 79," + EOL); + sb.append(" \"ram\" : 38," + EOL); + sb.append(" \"disk\" : 45," + EOL); + sb.append(" \"swap\" : \"swap\"," + EOL); + sb.append(" \"links\" : [ {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"public\" : false," + EOL); + sb.append(" \"OS-FLV-EXT-DATA:ephemeral\" : 65," + EOL); + sb.append(" \"rxtx_factor\" : 11.0," + EOL); + sb.append(" \"OS-FLV-DISABLED:disabled\" : true," + EOL); + sb.append(" \"rxtx_quota\" : 42," + EOL); + sb.append(" \"rxtx_cap\" : 96," + EOL); + sb.append(" \"os-flavor-access:is_public\" : false" + EOL); + sb.append(" }," + EOL); + sb.append(" \"accessIPv4\" : \"accessipv4\"," + EOL); + sb.append(" \"accessIPv6\" : \"accessipv6\"," + EOL); + sb.append(" \"status\" : \"status\"," + EOL); + sb.append(" \"progress\" : 3," + EOL); + sb.append(" \"fault\" : {" + EOL); + sb.append(" \"code\" : 29," + EOL); + sb.append(" \"message\" : \"message\"," + EOL); + sb.append(" \"details\" : \"details\"," + EOL); + sb.append(" \"created\" : 1485172800000" + EOL); + sb.append(" }," + EOL); + sb.append(" \"hostId\" : \"hostid\"," + EOL); + sb.append(" \"updated\" : \"updated\"," + EOL); + sb.append(" \"created\" : \"created\"," + EOL); + sb.append(" \"metadata\" : {" + EOL); + sb.append(" \"metadata-k1\" : \"metadata-v1\"," + EOL); + sb.append(" \"metadata-k2\" : \"metadata-v2\"" + EOL); + sb.append(" }," + EOL); + sb.append(" \"uuid\" : \"uuid\"," + EOL); + sb.append(" \"adminPass\" : \"adminpass\"," + EOL); + sb.append(" \"config_drive\" : \"configdrive\"," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"," + EOL); + sb.append(" \"user_id\" : \"userid\"," + EOL); + sb.append(" \"key_name\" : \"keyname\"," + EOL); + sb.append(" \"security_groups\" : [ {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"description\" : \"description\"," + EOL); + sb.append(" \"rules\" : [ {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"group\" : {" + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"" + EOL); + sb.append(" }," + EOL); + sb.append(" \"parent_group_id\" : \"parentgroupid\"," + EOL); + sb.append(" \"from_port\" : 7," + EOL); + sb.append(" \"to_port\" : 98," + EOL); + sb.append(" \"ip_protocol\" : \"ipprotocol\"," + EOL); + sb.append(" \"ip_range\" : {" + EOL); + sb.append(" \"cidr\" : \"cidr\"" + EOL); + sb.append(" }" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"group\" : {" + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"" + EOL); + sb.append(" }," + EOL); + sb.append(" \"parent_group_id\" : \"parentgroupid\"," + EOL); + sb.append(" \"from_port\" : 7," + EOL); + sb.append(" \"to_port\" : 98," + EOL); + sb.append(" \"ip_protocol\" : \"ipprotocol\"," + EOL); + sb.append(" \"ip_range\" : {" + EOL); + sb.append(" \"cidr\" : \"cidr\"" + EOL); + sb.append(" }" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"links\" : [ {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"description\" : \"description\"," + EOL); + sb.append(" \"rules\" : [ {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"group\" : {" + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"" + EOL); + sb.append(" }," + EOL); + sb.append(" \"parent_group_id\" : \"parentgroupid\"," + EOL); + sb.append(" \"from_port\" : 7," + EOL); + sb.append(" \"to_port\" : 98," + EOL); + sb.append(" \"ip_protocol\" : \"ipprotocol\"," + EOL); + sb.append(" \"ip_range\" : {" + EOL); + sb.append(" \"cidr\" : \"cidr\"" + EOL); + sb.append(" }" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"group\" : {" + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"" + EOL); + sb.append(" }," + EOL); + sb.append(" \"parent_group_id\" : \"parentgroupid\"," + EOL); + sb.append(" \"from_port\" : 7," + EOL); + sb.append(" \"to_port\" : 98," + EOL); + sb.append(" \"ip_protocol\" : \"ipprotocol\"," + EOL); + sb.append(" \"ip_range\" : {" + EOL); + sb.append(" \"cidr\" : \"cidr\"" + EOL); + sb.append(" }" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"links\" : [ {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"OS-EXT-STS:task_state\" : \"taskstate\"," + EOL); + sb.append(" \"OS-EXT-STS:power_state\" : \"powerstate\"," + EOL); + sb.append(" \"OS-EXT-STS:vm_state\" : \"vmstate\"," + EOL); + sb.append(" \"OS-EXT-SRV-ATTR:host\" : \"host\"," + EOL); + sb.append(" \"OS-EXT-SRV-ATTR:instance_name\" : \"instancename\"," + EOL); + sb.append(" \"OS-EXT-SRV-ATTR:hypervisor_hostname\" : \"hypervisorhostname\"," + EOL); + sb.append(" \"OS-DCF:diskConfig\" : \"diskconfig\"," + EOL); + sb.append(" \"OS-EXT-AZ:availability_zone\" : \"availabilityzone\"," + EOL); + sb.append(" \"OS-SRV-USG:launched_at\" : \"launchedat\"," + EOL); + sb.append(" \"OS-SRV-USG:terminated_at\" : \"terminatedat\"," + EOL); + sb.append(" \"os-extended-volumes:volumes_attached\" : [ \"osextendedvolumesattached-v1\", \"osextendedvolumesattached-v2\" ]" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"addresses\" : {" + EOL); + sb.append(" \"addresses\" : {" + EOL); + sb.append(" \"addresses-k1\" : [ {" + EOL); + sb.append(" \"version\" : \"version\"," + EOL); + sb.append(" \"addr\" : \"addr\"," + EOL); + sb.append(" \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL); + sb.append(" \"OS-EXT-IPS:type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"version\" : \"version\"," + EOL); + sb.append(" \"addr\" : \"addr\"," + EOL); + sb.append(" \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL); + sb.append(" \"OS-EXT-IPS:type\" : \"type\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"addresses-k2\" : [ {" + EOL); + sb.append(" \"version\" : \"version\"," + EOL); + sb.append(" \"addr\" : \"addr\"," + EOL); + sb.append(" \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL); + sb.append(" \"OS-EXT-IPS:type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"version\" : \"version\"," + EOL); + sb.append(" \"addr\" : \"addr\"," + EOL); + sb.append(" \"OS-EXT-IPS-MAC:mac_addr\" : \"macaddr\"," + EOL); + sb.append(" \"OS-EXT-IPS:type\" : \"type\"" + EOL); + sb.append(" } ]" + EOL); + sb.append(" }" + EOL); + sb.append(" }," + EOL); + sb.append(" \"links\" : [ {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"image\" : {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"status\" : \"status\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"progress\" : 3," + EOL); + sb.append(" \"minRam\" : 62," + EOL); + sb.append(" \"minDisk\" : 69," + EOL); + sb.append(" \"created\" : 1485172800000," + EOL); + sb.append(" \"updated\" : 1486468800000," + EOL); + sb.append(" \"metadata\" : {" + EOL); + sb.append(" \"metadata-k1\" : \"metadata-v1\"," + EOL); + sb.append(" \"metadata-k2\" : \"metadata-v2\"" + EOL); + sb.append(" }," + EOL); + sb.append(" \"server\" : {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"links\" : [ {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" } ]" + EOL); + sb.append(" }," + EOL); + sb.append(" \"links\" : [ {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"OS-EXT-IMG-SIZE:size\" : 43" + EOL); + sb.append(" }," + EOL); + sb.append(" \"flavor\" : {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"vcpus\" : 79," + EOL); + sb.append(" \"ram\" : 38," + EOL); + sb.append(" \"disk\" : 45," + EOL); + sb.append(" \"swap\" : \"swap\"," + EOL); + sb.append(" \"links\" : [ {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"public\" : false," + EOL); + sb.append(" \"OS-FLV-EXT-DATA:ephemeral\" : 65," + EOL); + sb.append(" \"rxtx_factor\" : 11.0," + EOL); + sb.append(" \"OS-FLV-DISABLED:disabled\" : true," + EOL); + sb.append(" \"rxtx_quota\" : 42," + EOL); + sb.append(" \"rxtx_cap\" : 96," + EOL); + sb.append(" \"os-flavor-access:is_public\" : false" + EOL); + sb.append(" }," + EOL); + sb.append(" \"accessIPv4\" : \"accessipv4\"," + EOL); + sb.append(" \"accessIPv6\" : \"accessipv6\"," + EOL); + sb.append(" \"status\" : \"status\"," + EOL); + sb.append(" \"progress\" : 3," + EOL); + sb.append(" \"fault\" : {" + EOL); + sb.append(" \"code\" : 29," + EOL); + sb.append(" \"message\" : \"message\"," + EOL); + sb.append(" \"details\" : \"details\"," + EOL); + sb.append(" \"created\" : 1485172800000" + EOL); + sb.append(" }," + EOL); + sb.append(" \"hostId\" : \"hostid\"," + EOL); + sb.append(" \"updated\" : \"updated\"," + EOL); + sb.append(" \"created\" : \"created\"," + EOL); + sb.append(" \"metadata\" : {" + EOL); + sb.append(" \"metadata-k1\" : \"metadata-v1\"," + EOL); + sb.append(" \"metadata-k2\" : \"metadata-v2\"" + EOL); + sb.append(" }," + EOL); + sb.append(" \"uuid\" : \"uuid\"," + EOL); + sb.append(" \"adminPass\" : \"adminpass\"," + EOL); + sb.append(" \"config_drive\" : \"configdrive\"," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"," + EOL); + sb.append(" \"user_id\" : \"userid\"," + EOL); + sb.append(" \"key_name\" : \"keyname\"," + EOL); + sb.append(" \"security_groups\" : [ {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"description\" : \"description\"," + EOL); + sb.append(" \"rules\" : [ {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"group\" : {" + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"" + EOL); + sb.append(" }," + EOL); + sb.append(" \"parent_group_id\" : \"parentgroupid\"," + EOL); + sb.append(" \"from_port\" : 7," + EOL); + sb.append(" \"to_port\" : 98," + EOL); + sb.append(" \"ip_protocol\" : \"ipprotocol\"," + EOL); + sb.append(" \"ip_range\" : {" + EOL); + sb.append(" \"cidr\" : \"cidr\"" + EOL); + sb.append(" }" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"group\" : {" + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"" + EOL); + sb.append(" }," + EOL); + sb.append(" \"parent_group_id\" : \"parentgroupid\"," + EOL); + sb.append(" \"from_port\" : 7," + EOL); + sb.append(" \"to_port\" : 98," + EOL); + sb.append(" \"ip_protocol\" : \"ipprotocol\"," + EOL); + sb.append(" \"ip_range\" : {" + EOL); + sb.append(" \"cidr\" : \"cidr\"" + EOL); + sb.append(" }" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"links\" : [ {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"description\" : \"description\"," + EOL); + sb.append(" \"rules\" : [ {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"group\" : {" + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"" + EOL); + sb.append(" }," + EOL); + sb.append(" \"parent_group_id\" : \"parentgroupid\"," + EOL); + sb.append(" \"from_port\" : 7," + EOL); + sb.append(" \"to_port\" : 98," + EOL); + sb.append(" \"ip_protocol\" : \"ipprotocol\"," + EOL); + sb.append(" \"ip_range\" : {" + EOL); + sb.append(" \"cidr\" : \"cidr\"" + EOL); + sb.append(" }" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"id\" : \"id\"," + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"group\" : {" + EOL); + sb.append(" \"name\" : \"name\"," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"" + EOL); + sb.append(" }," + EOL); + sb.append(" \"parent_group_id\" : \"parentgroupid\"," + EOL); + sb.append(" \"from_port\" : 7," + EOL); + sb.append(" \"to_port\" : 98," + EOL); + sb.append(" \"ip_protocol\" : \"ipprotocol\"," + EOL); + sb.append(" \"ip_range\" : {" + EOL); + sb.append(" \"cidr\" : \"cidr\"" + EOL); + sb.append(" }" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"links\" : [ {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" }, {" + EOL); + sb.append(" \"rel\" : \"rel\"," + EOL); + sb.append(" \"href\" : \"href\"," + EOL); + sb.append(" \"type\" : \"type\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"tenant_id\" : \"tenantid\"" + EOL); + sb.append(" } ]," + EOL); + sb.append(" \"OS-EXT-STS:task_state\" : \"taskstate\"," + EOL); + sb.append(" \"OS-EXT-STS:power_state\" : \"powerstate\"," + EOL); + sb.append(" \"OS-EXT-STS:vm_state\" : \"vmstate\"," + EOL); + sb.append(" \"OS-EXT-SRV-ATTR:host\" : \"host\"," + EOL); + sb.append(" \"OS-EXT-SRV-ATTR:instance_name\" : \"instancename\"," + EOL); + sb.append(" \"OS-EXT-SRV-ATTR:hypervisor_hostname\" : \"hypervisorhostname\"," + EOL); + sb.append(" \"OS-DCF:diskConfig\" : \"diskconfig\"," + EOL); + sb.append(" \"OS-EXT-AZ:availability_zone\" : \"availabilityzone\"," + EOL); + sb.append(" \"OS-SRV-USG:launched_at\" : \"launchedat\"," + EOL); + sb.append(" \"OS-SRV-USG:terminated_at\" : \"terminatedat\"," + EOL); + sb.append(" \"os-extended-volumes:volumes_attached\" : [ \"osextendedvolumesattached-v1\", \"osextendedvolumesattached-v2\" ]" + EOL); + sb.append(" } ]" + EOL); + sb.append("}"); + JSON_FULL = sb.toString(); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - servers.iterator(); + 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: " + Servers.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Servers servers = objectMapper.readValue(JSON_FULL, Servers.class); + String json = objectMapper.writeValueAsString(servers); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } -}
\ No newline at end of file + @Test + public void testMethods() throws Exception { + Servers servers = objectMapper.readValue(JSON_FULL, Servers.class); + servers.toString(); + + List<Server> list = servers.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Server x : servers) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/SimpleTenantUsageTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/SimpleTenantUsageTest.java index 91ac200..8303e33 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/SimpleTenantUsageTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/SimpleTenantUsageTest.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 @@ -17,95 +17,118 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package com.woorea.openstack.nova.model; -import org.junit.Test; +package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.SimpleTenantUsage; +import com.woorea.openstack.nova.model.SimpleTenantUsage.ServerUsage; import java.math.BigDecimal; -import java.util.Collections; +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 SimpleTenantUsageTest { - SimpleTenantUsage simpleTenantUsage = new SimpleTenantUsage(); - - @Test - public void getTotalMemoryMbUsage() throws Exception { - simpleTenantUsage.getTotalMemoryMbUsage(); - } - - @Test - public void setTotalMemoryMbUsage() throws Exception { - simpleTenantUsage.setTotalMemoryMbUsage(new BigDecimal(1)); - } - - @Test - public void getTotalVcpusUsage() throws Exception { - simpleTenantUsage.getTotalVcpusUsage(); - } - - @Test - public void setTotalVcpusUsage() throws Exception { - simpleTenantUsage.setTotalVcpusUsage(new BigDecimal(1)); - } - - @Test - public void getTotalLocalGbUsage() throws Exception { - simpleTenantUsage.getTotalLocalGbUsage(); - } - - @Test - public void setTotalLocalGbUsage() throws Exception { - simpleTenantUsage.setTotalLocalGbUsage(BigDecimal.ONE); - } - - @Test - public void getStart() throws Exception { - simpleTenantUsage.getStart(); - } - - @Test - public void setStart() throws Exception { - simpleTenantUsage.setStart("test"); - } - - @Test - public void getStop() throws Exception { - simpleTenantUsage.getStop(); - } - - @Test - public void setStop() throws Exception { - simpleTenantUsage.setStop("test"); - } - - @Test - public void getTenantId() throws Exception { - simpleTenantUsage.getTenantId(); - } - - @Test - public void setTenantId() throws Exception { - simpleTenantUsage.setTenantId("test"); - } - - @Test - public void getTotalHours() throws Exception { - simpleTenantUsage.getTotalHours(); - } - - @Test - public void setTotalHours() throws Exception { - simpleTenantUsage.setTotalHours("test"); - } - - @Test - public void getServerUsages() throws Exception { - simpleTenantUsage.getServerUsages(); - } - - @Test - public void setServerUsages() throws Exception { - simpleTenantUsage.setServerUsages(Collections.<SimpleTenantUsage.ServerUsage>emptyList()); - } - -}
\ No newline at end of file + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"tenant_usage\" : {" + EOL + + " \"start\" : \"start\"," + EOL + + " \"stop\" : \"stop\"," + EOL + + " \"total_memory_mb_usage\" : 14," + EOL + + " \"total_vcpus_usage\" : 3," + EOL + + " \"total_local_gb_usage\" : 66," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"total_hours\" : \"totalhours\"," + EOL + + " \"server_usages\" : [ {" + EOL + + " \"uptime\" : 78," + EOL + + " \"state\" : \"state\"," + EOL + + " \"hours\" : 64.0," + EOL + + " \"vcpus\" : 79," + EOL + + " \"flavor\" : \"flavor\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"instance_id\" : \"instanceid\"," + EOL + + " \"started_at\" : \"startedat\"," + EOL + + " \"ended_at\" : \"endedat\"," + EOL + + " \"memory_mb\" : 90," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"local_gb\" : 11" + EOL + + " }, {" + EOL + + " \"uptime\" : 78," + EOL + + " \"state\" : \"state\"," + EOL + + " \"hours\" : 64.0," + EOL + + " \"vcpus\" : 79," + EOL + + " \"flavor\" : \"flavor\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"instance_id\" : \"instanceid\"," + EOL + + " \"started_at\" : \"startedat\"," + EOL + + " \"ended_at\" : \"endedat\"," + EOL + + " \"memory_mb\" : 90," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"local_gb\" : 11" + EOL + + " } ]" + 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: " + SimpleTenantUsage.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + SimpleTenantUsage simpletenantusage = objectMapper.readValue(JSON_FULL, SimpleTenantUsage.class); + String json = objectMapper.writeValueAsString(simpletenantusage); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + SimpleTenantUsage simpletenantusage = objectMapper.readValue(JSON_FULL, SimpleTenantUsage.class); + simpletenantusage.toString(); + + BigDecimal totalMemoryMbUsage = simpletenantusage.getTotalMemoryMbUsage(); + Assert.assertNotNull(totalMemoryMbUsage); + simpletenantusage.setTotalMemoryMbUsage(totalMemoryMbUsage); + + String stop = simpletenantusage.getStop(); + Assert.assertNotNull(stop); + simpletenantusage.setStop(stop); + + BigDecimal totalVcpusUsage = simpletenantusage.getTotalVcpusUsage(); + Assert.assertNotNull(totalVcpusUsage); + simpletenantusage.setTotalVcpusUsage(totalVcpusUsage); + + String tenantId = simpletenantusage.getTenantId(); + Assert.assertNotNull(tenantId); + simpletenantusage.setTenantId(tenantId); + + String start = simpletenantusage.getStart(); + Assert.assertNotNull(start); + simpletenantusage.setStart(start); + + List<ServerUsage> serverUsages = simpletenantusage.getServerUsages(); + Assert.assertNotNull(serverUsages); + Assert.assertEquals(2, serverUsages.size()); + simpletenantusage.setServerUsages(serverUsages); + + BigDecimal totalLocalGbUsage = simpletenantusage.getTotalLocalGbUsage(); + Assert.assertNotNull(totalLocalGbUsage); + simpletenantusage.setTotalLocalGbUsage(totalLocalGbUsage); + + String totalHours = simpletenantusage.getTotalHours(); + Assert.assertNotNull(totalHours); + simpletenantusage.setTotalHours(totalHours); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/SimpleTenantUsagesTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/SimpleTenantUsagesTest.java index d1e9bfa..523a9ab 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/SimpleTenantUsagesTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/SimpleTenantUsagesTest.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 @@ -17,22 +17,127 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.SimpleTenantUsage; +import com.woorea.openstack.nova.model.SimpleTenantUsages; +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 SimpleTenantUsagesTest { - SimpleTenantUsages simpleTenantUsages = new SimpleTenantUsages(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"tenant_usages\" : [ {" + EOL + + " \"start\" : \"start\"," + EOL + + " \"stop\" : \"stop\"," + EOL + + " \"total_memory_mb_usage\" : 14," + EOL + + " \"total_vcpus_usage\" : 3," + EOL + + " \"total_local_gb_usage\" : 66," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"total_hours\" : \"totalhours\"," + EOL + + " \"server_usages\" : [ {" + EOL + + " \"uptime\" : 78," + EOL + + " \"state\" : \"state\"," + EOL + + " \"hours\" : 64.0," + EOL + + " \"vcpus\" : 79," + EOL + + " \"flavor\" : \"flavor\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"instance_id\" : \"instanceid\"," + EOL + + " \"started_at\" : \"startedat\"," + EOL + + " \"ended_at\" : \"endedat\"," + EOL + + " \"memory_mb\" : 90," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"local_gb\" : 11" + EOL + + " }, {" + EOL + + " \"uptime\" : 78," + EOL + + " \"state\" : \"state\"," + EOL + + " \"hours\" : 64.0," + EOL + + " \"vcpus\" : 79," + EOL + + " \"flavor\" : \"flavor\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"instance_id\" : \"instanceid\"," + EOL + + " \"started_at\" : \"startedat\"," + EOL + + " \"ended_at\" : \"endedat\"," + EOL + + " \"memory_mb\" : 90," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"local_gb\" : 11" + EOL + + " } ]" + EOL + + " }, {" + EOL + + " \"start\" : \"start\"," + EOL + + " \"stop\" : \"stop\"," + EOL + + " \"total_memory_mb_usage\" : 14," + EOL + + " \"total_vcpus_usage\" : 3," + EOL + + " \"total_local_gb_usage\" : 66," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"total_hours\" : \"totalhours\"," + EOL + + " \"server_usages\" : [ {" + EOL + + " \"uptime\" : 78," + EOL + + " \"state\" : \"state\"," + EOL + + " \"hours\" : 64.0," + EOL + + " \"vcpus\" : 79," + EOL + + " \"flavor\" : \"flavor\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"instance_id\" : \"instanceid\"," + EOL + + " \"started_at\" : \"startedat\"," + EOL + + " \"ended_at\" : \"endedat\"," + EOL + + " \"memory_mb\" : 90," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"local_gb\" : 11" + EOL + + " }, {" + EOL + + " \"uptime\" : 78," + EOL + + " \"state\" : \"state\"," + EOL + + " \"hours\" : 64.0," + EOL + + " \"vcpus\" : 79," + EOL + + " \"flavor\" : \"flavor\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"instance_id\" : \"instanceid\"," + EOL + + " \"started_at\" : \"startedat\"," + EOL + + " \"ended_at\" : \"endedat\"," + EOL + + " \"memory_mb\" : 90," + EOL + + " \"tenant_id\" : \"tenantid\"," + EOL + + " \"local_gb\" : 11" + EOL + + " } ]" + 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 getList() throws Exception { - simpleTenantUsages.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + SimpleTenantUsages.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + SimpleTenantUsages simpletenantusages = objectMapper.readValue(JSON_FULL, SimpleTenantUsages.class); + String json = objectMapper.writeValueAsString(simpletenantusages); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - simpleTenantUsages.iterator(); + @Test + public void testMethods() throws Exception { + SimpleTenantUsages simpletenantusages = objectMapper.readValue(JSON_FULL, SimpleTenantUsages.class); + simpletenantusages.toString(); + + List<SimpleTenantUsage> list = simpletenantusages.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") SimpleTenantUsage x : simpletenantusages) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/SnapshotForCreateTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/SnapshotForCreateTest.java index 39abc2c..edcca0f 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/SnapshotForCreateTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/SnapshotForCreateTest.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 @@ -17,52 +17,68 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.SnapshotForCreate; +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 SnapshotForCreateTest { - SnapshotForCreate snapshotForCreate = new SnapshotForCreate(); - - @Test - public void getVolumeId() throws Exception { - snapshotForCreate.getVolumeId(); - } + private static final String EOL = System.lineSeparator(); - @Test - public void setVolumeId() throws Exception { - snapshotForCreate.setVolumeId("Test"); - } + private static final String JSON_FULL = "{" + EOL + + " \"snapshot\" : {" + EOL + + " \"force\" : false," + EOL + + " \"volume_id\" : \"volumeid\"," + EOL + + " \"display_name\" : \"name\"," + EOL + + " \"display_description\" : \"description\"" + EOL + + " }" + EOL + + "}"; - @Test - public void getForce() throws Exception { - snapshotForCreate.getForce(); - } + 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 setForce() throws Exception { - snapshotForCreate.setForce(true); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + SnapshotForCreate.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + SnapshotForCreate snapshotforcreate = objectMapper.readValue(JSON_FULL, SnapshotForCreate.class); + String json = objectMapper.writeValueAsString(snapshotforcreate); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getName() throws Exception { - snapshotForCreate.getName(); + public void testMethods() throws Exception { + SnapshotForCreate snapshotforcreate = objectMapper.readValue(JSON_FULL, SnapshotForCreate.class); + snapshotforcreate.toString(); + + String name = snapshotforcreate.getName(); + Assert.assertNotNull(name); + snapshotforcreate.setName(name); + + String volumeId = snapshotforcreate.getVolumeId(); + Assert.assertNotNull(volumeId); + snapshotforcreate.setVolumeId(volumeId); + + String description = snapshotforcreate.getDescription(); + Assert.assertNotNull(description); + snapshotforcreate.setDescription(description); + + Boolean force = snapshotforcreate.getForce(); + Assert.assertNotNull(force); + snapshotforcreate.setForce(force); } - - @Test - public void setName() throws Exception { - snapshotForCreate.setName("Test"); - } - - @Test - public void getDescription() throws Exception { - snapshotForCreate.getDescription(); - } - - @Test - public void setDescription() throws Exception { - snapshotForCreate.setDescription("test"); - } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/SnapshotTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/SnapshotTest.java index 816f9c9..d62f730 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/SnapshotTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/SnapshotTest.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 @@ -17,47 +17,76 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Snapshot; +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 SnapshotTest { - Snapshot snapshot = new Snapshot(); - - @Test - public void getId() throws Exception { - snapshot.getId(); - } - - @Test - public void getStatus() throws Exception { - snapshot.getStatus(); - } - - @Test - public void getName() throws Exception { - snapshot.getName(); - } + private static final String EOL = System.lineSeparator(); - @Test - public void getDescription() throws Exception { - snapshot.getDescription(); - } + private static final String JSON_FULL = "{" + EOL + + " \"snapshot\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"volumeId\" : \"volumeid\"," + EOL + + " \"size\" : 61," + EOL + + " \"createdAt\" : \"createdat\"," + EOL + + " \"displayName\" : \"name\"," + EOL + + " \"displayDescription\" : \"description\"" + EOL + + " }" + EOL + + "}"; - @Test - public void getVolumeId() throws Exception { - snapshot.getVolumeId(); - } + 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 getSize() throws Exception { - snapshot.getSize(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Snapshot.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Snapshot snapshot = objectMapper.readValue(JSON_FULL, Snapshot.class); + String json = objectMapper.writeValueAsString(snapshot); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getCreatedAt() throws Exception { - snapshot.getCreatedAt(); + public void testMethods() throws Exception { + Snapshot snapshot = objectMapper.readValue(JSON_FULL, Snapshot.class); + snapshot.toString(); + + String createdAt = snapshot.getCreatedAt(); + Assert.assertNotNull(createdAt); + + Integer size = snapshot.getSize(); + Assert.assertNotNull(size); + + String name = snapshot.getName(); + Assert.assertNotNull(name); + + String volumeId = snapshot.getVolumeId(); + Assert.assertNotNull(volumeId); + + String description = snapshot.getDescription(); + Assert.assertNotNull(description); + + String id = snapshot.getId(); + Assert.assertNotNull(id); + + String status = snapshot.getStatus(); + Assert.assertNotNull(status); } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/SnapshotsTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/SnapshotsTest.java index 3c7ec60..9bf525b 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/SnapshotsTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/SnapshotsTest.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 @@ -17,22 +17,73 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Snapshot; +import com.woorea.openstack.nova.model.Snapshots; +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 SnapshotsTest { - Snapshots snapshots = new Snapshots(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"snapshots\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"volumeId\" : \"volumeid\"," + EOL + + " \"size\" : 61," + EOL + + " \"createdAt\" : \"createdat\"," + EOL + + " \"displayName\" : \"name\"," + EOL + + " \"displayDescription\" : \"description\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"volumeId\" : \"volumeid\"," + EOL + + " \"size\" : 61," + EOL + + " \"createdAt\" : \"createdat\"," + EOL + + " \"displayName\" : \"name\"," + EOL + + " \"displayDescription\" : \"description\"" + 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 getList() throws Exception { - snapshots.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Snapshots.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Snapshots snapshots = objectMapper.readValue(JSON_FULL, Snapshots.class); + String json = objectMapper.writeValueAsString(snapshots); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - snapshots.iterator(); + @Test + public void testMethods() throws Exception { + Snapshots snapshots = objectMapper.readValue(JSON_FULL, Snapshots.class); + snapshots.toString(); + + List<Snapshot> list = snapshots.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Snapshot x : snapshots) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/StartTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/StartTest.java new file mode 100644 index 0000000..c96b74a --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/StartTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Start; +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 StartTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"os-start\" : { }" + 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: " + Start.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Start start = objectMapper.readValue(JSON_FULL, Start.class); + String json = objectMapper.writeValueAsString(start); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Start start = objectMapper.readValue(JSON_FULL, Start.class); + start.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/StopTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/StopTest.java new file mode 100644 index 0000000..2abb35e --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/StopTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Stop; +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 StopTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"os-stop\" : { }" + 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: " + Stop.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Stop stop = objectMapper.readValue(JSON_FULL, Stop.class); + String json = objectMapper.writeValueAsString(stop); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Stop stop = objectMapper.readValue(JSON_FULL, Stop.class); + stop.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/SuspendTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/SuspendTest.java new file mode 100644 index 0000000..bcbb0da --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/SuspendTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Suspend; +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 SuspendTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"suspend\" : { }" + 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: " + Suspend.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Suspend suspend = objectMapper.readValue(JSON_FULL, Suspend.class); + String json = objectMapper.writeValueAsString(suspend); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Suspend suspend = objectMapper.readValue(JSON_FULL, Suspend.class); + suspend.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/UnlockTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/UnlockTest.java new file mode 100644 index 0000000..43ad515 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/UnlockTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Unlock; +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 UnlockTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"unlock\" : { }" + 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: " + Unlock.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Unlock unlock = objectMapper.readValue(JSON_FULL, Unlock.class); + String json = objectMapper.writeValueAsString(unlock); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Unlock unlock = objectMapper.readValue(JSON_FULL, Unlock.class); + unlock.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/UnpauseTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/UnpauseTest.java new file mode 100644 index 0000000..f180b96 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/UnpauseTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Unpause; +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 UnpauseTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"unpause\" : { }" + 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: " + Unpause.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Unpause unpause = objectMapper.readValue(JSON_FULL, Unpause.class); + String json = objectMapper.writeValueAsString(unpause); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Unpause unpause = objectMapper.readValue(JSON_FULL, Unpause.class); + unpause.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/UnrescueTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/UnrescueTest.java new file mode 100644 index 0000000..6e92807 --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/UnrescueTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.Unrescue; +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 UnrescueTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"unrescue\" : { }" + 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: " + Unrescue.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Unrescue unrescue = objectMapper.readValue(JSON_FULL, Unrescue.class); + String json = objectMapper.writeValueAsString(unrescue); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Unrescue unrescue = objectMapper.readValue(JSON_FULL, Unrescue.class); + unrescue.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/VncConsoleTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/VncConsoleTest.java new file mode 100644 index 0000000..8582bca --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/VncConsoleTest.java @@ -0,0 +1,72 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.ServerAction.VncConsole; +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 VncConsoleTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"console\" : {" + EOL + + " \"type\" : \"type\"," + EOL + + " \"url\" : \"url\"" + 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: " + VncConsole.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + VncConsole vncconsole = objectMapper.readValue(JSON_FULL, VncConsole.class); + String json = objectMapper.writeValueAsString(vncconsole); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + VncConsole vncconsole = objectMapper.readValue(JSON_FULL, VncConsole.class); + vncconsole.toString(); + + String type = vncconsole.getType(); + Assert.assertNotNull(type); + + String url = vncconsole.getUrl(); + Assert.assertNotNull(url); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeAttachmentTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeAttachmentTest.java index 008e047..c51efe7 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeAttachmentTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeAttachmentTest.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 @@ -17,52 +17,68 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.VolumeAttachment; +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 VolumeAttachmentTest { - VolumeAttachment volumeAttachment = new VolumeAttachment(); - - @Test - public void getId() throws Exception { - volumeAttachment.getId(); - } + private static final String EOL = System.lineSeparator(); - @Test - public void setId() throws Exception { - volumeAttachment.setId("Test"); - } + private static final String JSON_FULL = "{" + EOL + + " \"volumeAttachment\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"volumeId\" : \"volumeid\"," + EOL + + " \"serverId\" : \"serverid\"," + EOL + + " \"device\" : \"device\"" + EOL + + " }" + EOL + + "}"; - @Test - public void getVolumeId() throws Exception { - volumeAttachment.getVolumeId(); - } + 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 setVolumeId() throws Exception { - volumeAttachment.setVolumeId("test"); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + VolumeAttachment.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + VolumeAttachment volumeattachment = objectMapper.readValue(JSON_FULL, VolumeAttachment.class); + String json = objectMapper.writeValueAsString(volumeattachment); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getServerId() throws Exception { - volumeAttachment.getServerId(); + public void testMethods() throws Exception { + VolumeAttachment volumeattachment = objectMapper.readValue(JSON_FULL, VolumeAttachment.class); + volumeattachment.toString(); + + String volumeId = volumeattachment.getVolumeId(); + Assert.assertNotNull(volumeId); + volumeattachment.setVolumeId(volumeId); + + String id = volumeattachment.getId(); + Assert.assertNotNull(id); + volumeattachment.setId(id); + + String device = volumeattachment.getDevice(); + Assert.assertNotNull(device); + volumeattachment.setDevice(device); + + String serverId = volumeattachment.getServerId(); + Assert.assertNotNull(serverId); + volumeattachment.setServerId(serverId); } - - @Test - public void setServerId() throws Exception { - volumeAttachment.setServerId("test"); - } - - @Test - public void getDevice() throws Exception { - volumeAttachment.getDevice(); - } - - @Test - public void setDevice() throws Exception { - volumeAttachment.setDevice("test"); - } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeAttachmentsTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeAttachmentsTest.java index 34b8e51..b84389b 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeAttachmentsTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeAttachmentsTest.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 @@ -17,22 +17,67 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.VolumeAttachment; +import com.woorea.openstack.nova.model.VolumeAttachments; +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 VolumeAttachmentsTest { - VolumeAttachments volumeAttachments = new VolumeAttachments(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"volumeAttachments\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"volumeId\" : \"volumeid\"," + EOL + + " \"serverId\" : \"serverid\"," + EOL + + " \"device\" : \"device\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"volumeId\" : \"volumeid\"," + EOL + + " \"serverId\" : \"serverid\"," + EOL + + " \"device\" : \"device\"" + 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 getList() throws Exception { - volumeAttachments.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + VolumeAttachments.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + VolumeAttachments volumeattachments = objectMapper.readValue(JSON_FULL, VolumeAttachments.class); + String json = objectMapper.writeValueAsString(volumeattachments); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - volumeAttachments.iterator(); + @Test + public void testMethods() throws Exception { + VolumeAttachments volumeattachments = objectMapper.readValue(JSON_FULL, VolumeAttachments.class); + volumeattachments.toString(); + + List<VolumeAttachment> list = volumeattachments.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") VolumeAttachment x : volumeattachments) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeForCreateTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeForCreateTest.java index 1c44c34..5caf86d 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeForCreateTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeForCreateTest.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 @@ -17,74 +17,83 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.VolumeForCreate; +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 java.util.HashMap; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class VolumeForCreateTest { - VolumeForCreate volumeForCreate = new VolumeForCreate(); - - @Test - public void getSize() throws Exception { - volumeForCreate.getSize(); - } - - @Test - public void setSize() throws Exception { - volumeForCreate.setSize(1); - } - - @Test - public void getAvailabilityZone() throws Exception { - volumeForCreate.getAvailabilityZone(); - } - - @Test - public void setAvailabilityZone() throws Exception { - volumeForCreate.setAvailabilityZone("test"); - } - - @Test - public void getName() throws Exception { - volumeForCreate.getName(); - } - - @Test - public void setName() throws Exception { - volumeForCreate.setName("test"); - } + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"volume\" : {" + EOL + + " \"size\" : 61," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"availability_zone\" : \"availabilityzone\"," + EOL + + " \"display_name\" : \"name\"," + EOL + + " \"display_description\" : \"description\"," + EOL + + " \"snapshot_id\" : 3" + 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 getDescription() throws Exception { - volumeForCreate.getDescription(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + VolumeForCreate.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + VolumeForCreate volumeforcreate = objectMapper.readValue(JSON_FULL, VolumeForCreate.class); + String json = objectMapper.writeValueAsString(volumeforcreate); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setDescription() throws Exception { - volumeForCreate.setDescription("test"); + public void testMethods() throws Exception { + VolumeForCreate volumeforcreate = objectMapper.readValue(JSON_FULL, VolumeForCreate.class); + volumeforcreate.toString(); + + Map<String,String> metadata = volumeforcreate.getMetadata(); + Assert.assertNotNull(metadata); + Assert.assertEquals(2, metadata.size()); + volumeforcreate.setMetadata(metadata); + + Integer snapshotId = volumeforcreate.getSnapshotId(); + Assert.assertNotNull(snapshotId); + volumeforcreate.setSnapshotId(snapshotId); + + Integer size = volumeforcreate.getSize(); + Assert.assertNotNull(size); + volumeforcreate.setSize(size); + + String name = volumeforcreate.getName(); + Assert.assertNotNull(name); + volumeforcreate.setName(name); + + String description = volumeforcreate.getDescription(); + Assert.assertNotNull(description); + volumeforcreate.setDescription(description); + + String availabilityZone = volumeforcreate.getAvailabilityZone(); + Assert.assertNotNull(availabilityZone); + volumeforcreate.setAvailabilityZone(availabilityZone); } - - @Test - public void getSnapshotId() throws Exception { - volumeForCreate.getSnapshotId(); - } - - @Test - public void setSnapshotId() throws Exception { - volumeForCreate.setSnapshotId(1); - } - - @Test - public void getMetadata() throws Exception { - volumeForCreate.getMetadata(); - } - - @Test - public void setMetadata() throws Exception { - volumeForCreate.setMetadata(new HashMap<String, String>()); - } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeForImageCreateTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeForImageCreateTest.java index a86c021..eae93e5 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeForImageCreateTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeForImageCreateTest.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 @@ -17,72 +17,78 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.VolumeForImageCreate; +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 VolumeForImageCreateTest { - VolumeForImageCreate volumeForImageCreate = new VolumeForImageCreate(); - - @Test - public void getTenantId() throws Exception { - volumeForImageCreate.getTenantId(); - } - - @Test - public void setTenantId() throws Exception { - volumeForImageCreate.setTenantId("Test"); - } - - @Test - public void getForce() throws Exception { - volumeForImageCreate.getForce(); - } - - @Test - public void setForce() throws Exception { - volumeForImageCreate.setForce(true); - } - - @Test - public void getVolumeId() throws Exception { - volumeForImageCreate.getVolumeId(); - } + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"os-volume_upload_image\" : {" + EOL + + " \"volumeId\" : \"volumeid\"," + EOL + + " \"tenantId\" : \"tenantid\"," + EOL + + " \"force\" : false," + EOL + + " \"container_format\" : \"container_format\"," + EOL + + " \"disk_format\" : \"disk_format\"," + EOL + + " \"image_name\" : \"image_name\"" + 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 setVolumeId() throws Exception { - volumeForImageCreate.setVolumeId("testid"); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + VolumeForImageCreate.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + VolumeForImageCreate volumeforimagecreate = objectMapper.readValue(JSON_FULL, VolumeForImageCreate.class); + String json = objectMapper.writeValueAsString(volumeforimagecreate); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getContainer_format() throws Exception { - volumeForImageCreate.getContainer_format(); + public void testMethods() throws Exception { + VolumeForImageCreate volumeforimagecreate = objectMapper.readValue(JSON_FULL, VolumeForImageCreate.class); + volumeforimagecreate.toString(); + + String image_name = volumeforimagecreate.getImage_name(); + Assert.assertNotNull(image_name); + volumeforimagecreate.setImage_name(image_name); + + String tenantId = volumeforimagecreate.getTenantId(); + Assert.assertNotNull(tenantId); + volumeforimagecreate.setTenantId(tenantId); + + String volumeId = volumeforimagecreate.getVolumeId(); + Assert.assertNotNull(volumeId); + volumeforimagecreate.setVolumeId(volumeId); + + String disk_format = volumeforimagecreate.getDisk_format(); + Assert.assertNotNull(disk_format); + volumeforimagecreate.setDisk_format(disk_format); + + Boolean force = volumeforimagecreate.getForce(); + Assert.assertNotNull(force); + volumeforimagecreate.setForce(force); + + String container_format = volumeforimagecreate.getContainer_format(); + Assert.assertNotNull(container_format); + volumeforimagecreate.setContainer_format(container_format); } - - @Test - public void setContainer_format() throws Exception { - volumeForImageCreate.setContainer_format("test"); - } - - @Test - public void getDisk_format() throws Exception { - volumeForImageCreate.getDisk_format(); - } - - @Test - public void setDisk_format() throws Exception { - volumeForImageCreate.setDisk_format("test"); - } - - @Test - public void getImage_name() throws Exception { - volumeForImageCreate.getImage_name(); - } - - @Test - public void setImage_name() throws Exception { - volumeForImageCreate.setImage_name("test"); - } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeTest.java index ede7d29..7a8d058 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeTest.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 @@ -17,67 +17,105 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Volume; +import java.util.List; +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 VolumeTest { - Volume volume = new Volume(); - - @Test - public void getId() throws Exception { - volume.getId(); - } - - @Test - public void getStatus() throws Exception { - volume.getStatus(); - } - - @Test - public void getName() throws Exception { - volume.getName(); - } - - @Test - public void getDescription() throws Exception { - volume.getDescription(); - } - - @Test - public void getAvailabilityZone() throws Exception { - volume.getAvailabilityZone(); - } - - @Test - public void getVolumeType() throws Exception { - volume.getVolumeType(); - } - - @Test - public void getSnapshotId() throws Exception { - volume.getSnapshotId(); - } + private static final String EOL = System.lineSeparator(); - @Test - public void getAttachments() throws Exception { - volume.getAttachments(); - } + private static final String JSON_FULL = "{" + EOL + + " \"volume\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"availabilityZone\" : \"availabilityzone\"," + EOL + + " \"volumeType\" : \"volumetype\"," + EOL + + " \"snapshotId\" : \"snapshotid\"," + EOL + + " \"attachments\" : [ {" + EOL + + " \"attachments-v1-k1\" : \"attachments-v1-v1\"," + EOL + + " \"attachments-v1-k2\" : \"attachments-v1-v2\"" + EOL + + " }, {" + EOL + + " \"attachments-v2-k1\" : \"attachments-v2-v1\"," + EOL + + " \"attachments-v2-k2\" : \"attachments-v2-v2\"" + EOL + + " } ]," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"createdAt\" : \"createdat\"," + EOL + + " \"size\" : 61," + EOL + + " \"displayName\" : \"name\"," + EOL + + " \"displayDescription\" : \"description\"" + EOL + + " }" + EOL + + "}"; - @Test - public void getMetadata() throws Exception { - volume.getMetadata(); - } + 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 getCreatedAt() throws Exception { - volume.getCreatedAt(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Volume.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Volume volume = objectMapper.readValue(JSON_FULL, Volume.class); + String json = objectMapper.writeValueAsString(volume); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getSize() throws Exception { - volume.getSize(); + public void testMethods() throws Exception { + Volume volume = objectMapper.readValue(JSON_FULL, Volume.class); + volume.toString(); + + String volumeType = volume.getVolumeType(); + Assert.assertNotNull(volumeType); + + String createdAt = volume.getCreatedAt(); + Assert.assertNotNull(createdAt); + + Map<String,String> metadata = volume.getMetadata(); + Assert.assertNotNull(metadata); + Assert.assertEquals(2, metadata.size()); + + List<Map<String,Object>> attachments = volume.getAttachments(); + Assert.assertNotNull(attachments); + Assert.assertEquals(2, attachments.size()); + + String snapshotId = volume.getSnapshotId(); + Assert.assertNotNull(snapshotId); + + Integer size = volume.getSize(); + Assert.assertNotNull(size); + + String name = volume.getName(); + Assert.assertNotNull(name); + + String description = volume.getDescription(); + Assert.assertNotNull(description); + + String id = volume.getId(); + Assert.assertNotNull(id); + + String availabilityZone = volume.getAvailabilityZone(); + Assert.assertNotNull(availabilityZone); + + String status = volume.getStatus(); + Assert.assertNotNull(status); } - -}
\ No newline at end of file +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeTypeTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeTypeTest.java new file mode 100644 index 0000000..b485dbb --- /dev/null +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeTypeTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.nova.model; + +import com.woorea.openstack.nova.model.VolumeType; +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 VolumeTypeTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"volume-type\" : { }" + 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: " + VolumeType.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + VolumeType volumetype = objectMapper.readValue(JSON_FULL, VolumeType.class); + String json = objectMapper.writeValueAsString(volumetype); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + VolumeType volumetype = objectMapper.readValue(JSON_FULL, VolumeType.class); + volumetype.toString(); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeTypesTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeTypesTest.java index 75fe600..903b67d 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeTypesTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumeTypesTest.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 @@ -17,17 +17,57 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.VolumeType; +import com.woorea.openstack.nova.model.VolumeTypes; +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 VolumeTypesTest { - VolumeTypes volumeTypes = new VolumeTypes(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"volume-types\" : [ { }, { } ]" + 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 getList() throws Exception { - volumeTypes.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + VolumeTypes.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + VolumeTypes volumetypes = objectMapper.readValue(JSON_FULL, VolumeTypes.class); + String json = objectMapper.writeValueAsString(volumetypes); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } -}
\ No newline at end of file + @Test + public void testMethods() throws Exception { + VolumeTypes volumetypes = objectMapper.readValue(JSON_FULL, VolumeTypes.class); + volumetypes.toString(); + + List<VolumeType> list = volumetypes.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") VolumeType x : volumetypes) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumesTest.java b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumesTest.java index fae5f1b..4c2d5b1 100644 --- a/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumesTest.java +++ b/nova-model/src/test/java/com/woorea/openstack/nova/model/VolumesTest.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 @@ -17,22 +17,99 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.nova.model; +import com.woorea.openstack.nova.model.Volume; +import com.woorea.openstack.nova.model.Volumes; +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 VolumesTest { - Volumes volumes = new Volumes(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"volumes\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"availabilityZone\" : \"availabilityzone\"," + EOL + + " \"volumeType\" : \"volumetype\"," + EOL + + " \"snapshotId\" : \"snapshotid\"," + EOL + + " \"attachments\" : [ {" + EOL + + " \"attachments-v1-k1\" : \"attachments-v1-v1\"," + EOL + + " \"attachments-v1-k2\" : \"attachments-v1-v2\"" + EOL + + " }, {" + EOL + + " \"attachments-v2-k1\" : \"attachments-v2-v1\"," + EOL + + " \"attachments-v2-k2\" : \"attachments-v2-v2\"" + EOL + + " } ]," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"createdAt\" : \"createdat\"," + EOL + + " \"size\" : 61," + EOL + + " \"displayName\" : \"name\"," + EOL + + " \"displayDescription\" : \"description\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"status\" : \"status\"," + EOL + + " \"availabilityZone\" : \"availabilityzone\"," + EOL + + " \"volumeType\" : \"volumetype\"," + EOL + + " \"snapshotId\" : \"snapshotid\"," + EOL + + " \"attachments\" : [ {" + EOL + + " \"attachments-v1-k1\" : \"attachments-v1-v1\"," + EOL + + " \"attachments-v1-k2\" : \"attachments-v1-v2\"" + EOL + + " }, {" + EOL + + " \"attachments-v2-k1\" : \"attachments-v2-v1\"," + EOL + + " \"attachments-v2-k2\" : \"attachments-v2-v2\"" + EOL + + " } ]," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }," + EOL + + " \"createdAt\" : \"createdat\"," + EOL + + " \"size\" : 61," + EOL + + " \"displayName\" : \"name\"," + EOL + + " \"displayDescription\" : \"description\"" + 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 getList() throws Exception { - volumes.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Volumes.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Volumes volumes = objectMapper.readValue(JSON_FULL, Volumes.class); + String json = objectMapper.writeValueAsString(volumes); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - volumes.iterator(); + @Test + public void testMethods() throws Exception { + Volumes volumes = objectMapper.readValue(JSON_FULL, Volumes.class); + volumes.toString(); + + List<Volume> list = volumes.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Volume x : volumes) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -}
\ No newline at end of file +} |