diff options
Diffstat (limited to 'heat-model')
11 files changed, 1020 insertions, 3 deletions
diff --git a/heat-model/pom.xml b/heat-model/pom.xml index e33b807..47a5a55 100644 --- a/heat-model/pom.xml +++ b/heat-model/pom.xml @@ -1,14 +1,18 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <dependencies> + <dependencies> <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> - <parent> + <parent> <groupId>org.onap.so.libs</groupId> <artifactId>openstack-java-sdk</artifactId> <version>1.2.1-SNAPSHOT</version> diff --git a/heat-model/src/test/java/com/woorea/openstack/heat/model/CreateStackParamTest.java b/heat-model/src/test/java/com/woorea/openstack/heat/model/CreateStackParamTest.java new file mode 100644 index 0000000..f181175 --- /dev/null +++ b/heat-model/src/test/java/com/woorea/openstack/heat/model/CreateStackParamTest.java @@ -0,0 +1,109 @@ +/*- + * ============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.heat.model; + +import com.woorea.openstack.heat.model.CreateStackParam; +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 CreateStackParamTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"template\" : \"template\"," + EOL + + " \"parameters\" : {" + EOL + + " \"parameters-k1\" : \"parameters-v1\"," + EOL + + " \"parameters-k2\" : \"parameters-v2\"" + EOL + + " }," + EOL + + " \"environment\" : \"environment\"," + EOL + + " \"files\" : {" + EOL + + " \"files-k1\" : \"files-v1\"," + EOL + + " \"files-k2\" : \"files-v2\"" + EOL + + " }," + EOL + + " \"stack_name\" : \"stackname\"," + EOL + + " \"template_url\" : \"templateurl\"," + EOL + + " \"timeout_mins\" : 79," + EOL + + " \"disable_rollback\" : true" + 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: " + CreateStackParam.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + CreateStackParam createstackparam = objectMapper.readValue(JSON_FULL, CreateStackParam.class); + String json = objectMapper.writeValueAsString(createstackparam); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + CreateStackParam createstackparam = objectMapper.readValue(JSON_FULL, CreateStackParam.class); + createstackparam.toString(); + + String template = createstackparam.getTemplate(); + Assert.assertNotNull(template); + createstackparam.setTemplate(template); + + String environment = createstackparam.getEnvironment(); + Assert.assertNotNull(environment); + createstackparam.setEnvironment(environment); + + int timeoutMinutes = createstackparam.getTimeoutMinutes(); + Assert.assertNotNull(timeoutMinutes); + createstackparam.setTimeoutMinutes(timeoutMinutes); + + boolean disableRollback = createstackparam.getDisableRollback(); + Assert.assertNotNull(disableRollback); + createstackparam.setDisableRollback(disableRollback); + + Map<String,Object> files = createstackparam.getFiles(); + Assert.assertNotNull(files); + Assert.assertEquals(2, files.size()); + createstackparam.setFiles(files); + + String stackName = createstackparam.getStackName(); + Assert.assertNotNull(stackName); + createstackparam.setStackName(stackName); + + Map<String,Object> parameters = createstackparam.getParameters(); + Assert.assertNotNull(parameters); + Assert.assertEquals(2, parameters.size()); + createstackparam.setParameters(parameters); + + String templateUrl = createstackparam.getTemplateUrl(); + Assert.assertNotNull(templateUrl); + createstackparam.setTemplateUrl(templateUrl); + } +} diff --git a/heat-model/src/test/java/com/woorea/openstack/heat/model/ErrorTest.java b/heat-model/src/test/java/com/woorea/openstack/heat/model/ErrorTest.java new file mode 100644 index 0000000..76582e7 --- /dev/null +++ b/heat-model/src/test/java/com/woorea/openstack/heat/model/ErrorTest.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.heat.model; + +import com.woorea.openstack.heat.model.Explanation.Error; +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 ErrorTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"error\" : {" + EOL + + " \"message\" : \"message\"," + EOL + + " \"traceback\" : \"traceback\"," + 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: " + Error.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Error error = objectMapper.readValue(JSON_FULL, Error.class); + String json = objectMapper.writeValueAsString(error); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Error error = objectMapper.readValue(JSON_FULL, Error.class); + error.toString(); + + String type = error.getType(); + Assert.assertNotNull(type); + + String message = error.getMessage(); + Assert.assertNotNull(message); + + String traceback = error.getTraceback(); + Assert.assertNotNull(traceback); + } +} diff --git a/heat-model/src/test/java/com/woorea/openstack/heat/model/ExplanationTest.java b/heat-model/src/test/java/com/woorea/openstack/heat/model/ExplanationTest.java new file mode 100644 index 0000000..4132cb0 --- /dev/null +++ b/heat-model/src/test/java/com/woorea/openstack/heat/model/ExplanationTest.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.heat.model; + +import com.woorea.openstack.heat.model.Explanation; +import com.woorea.openstack.heat.model.Explanation.Error; +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 ExplanationTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"explanation\" : \"explanation\"," + EOL + + " \"code\" : 42," + EOL + + " \"title\" : \"title\"," + EOL + + " \"error\" : {" + EOL + + " \"message\" : \"message\"," + EOL + + " \"traceback\" : \"traceback\"," + EOL + + " \"type\" : \"type\"" + 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: " + Explanation.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Explanation explanation = objectMapper.readValue(JSON_FULL, Explanation.class); + String json = objectMapper.writeValueAsString(explanation); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Explanation explanation = objectMapper.readValue(JSON_FULL, Explanation.class); + explanation.toString(); + + int code = explanation.getCode(); + Assert.assertNotNull(code); + + String explanationProperty = explanation.getExplanation(); + Assert.assertNotNull(explanationProperty); + + String title = explanation.getTitle(); + Assert.assertNotNull(title); + + Error error = explanation.getError(); + Assert.assertNotNull(error); + } +} diff --git a/heat-model/src/test/java/com/woorea/openstack/heat/model/LinkTest.java b/heat-model/src/test/java/com/woorea/openstack/heat/model/LinkTest.java new file mode 100644 index 0000000..503e0e5 --- /dev/null +++ b/heat-model/src/test/java/com/woorea/openstack/heat/model/LinkTest.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.heat.model; + +import com.woorea.openstack.heat.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 org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class LinkTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + 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: " + 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 testMethods() throws Exception { + Link link = objectMapper.readValue(JSON_FULL, Link.class); + link.toString(); + + String rel = link.getRel(); + Assert.assertNotNull(rel); + link.setRel(rel); + + String href = link.getHref(); + Assert.assertNotNull(href); + link.setHref(href); + } +} diff --git a/heat-model/src/test/java/com/woorea/openstack/heat/model/OutputTest.java b/heat-model/src/test/java/com/woorea/openstack/heat/model/OutputTest.java new file mode 100644 index 0000000..cc07012 --- /dev/null +++ b/heat-model/src/test/java/com/woorea/openstack/heat/model/OutputTest.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.heat.model; + +import com.woorea.openstack.heat.model.Stack.Output; +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 OutputTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"description\" : \"description\"," + EOL + + " \"output_value\" : \"outputvalue\"," + EOL + + " \"output_key\" : \"outputkey\"" + 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: " + Output.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Output output = objectMapper.readValue(JSON_FULL, Output.class); + String json = objectMapper.writeValueAsString(output); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Output output = objectMapper.readValue(JSON_FULL, Output.class); + output.toString(); + + String outputKey = output.getOutputKey(); + Assert.assertNotNull(outputKey); + + Object outputValue = output.getOutputValue(); + Assert.assertNotNull(outputValue); + + String description = output.getDescription(); + Assert.assertNotNull(description); + } +} diff --git a/heat-model/src/test/java/com/woorea/openstack/heat/model/ResourceTest.java b/heat-model/src/test/java/com/woorea/openstack/heat/model/ResourceTest.java new file mode 100644 index 0000000..ff7497e --- /dev/null +++ b/heat-model/src/test/java/com/woorea/openstack/heat/model/ResourceTest.java @@ -0,0 +1,116 @@ +/*- + * ============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.heat.model; + +import com.woorea.openstack.heat.model.Link; +import com.woorea.openstack.heat.model.Resource; +import java.util.Date; +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 ResourceTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"links\" : [ {" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + EOL + + " }, {" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + EOL + + " } ]," + EOL + + " \"resource_name\" : \"name\"," + EOL + + " \"resource_status\" : \"status\"," + EOL + + " \"physical_resource_id\" : \"physicalresourceid\"," + EOL + + " \"logical_resource_id\" : \"logicalresourceid\"," + EOL + + " \"required_by\" : [ \"requiredby-v1\", \"requiredby-v2\" ]," + EOL + + " \"updated_time\" : 1488110400000," + EOL + + " \"resource_type\" : \"type\"," + EOL + + " \"resource_status_reason\" : \"statusreason\"" + 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(); + + Date updatedTime = resource.getUpdatedTime(); + Assert.assertNotNull(updatedTime); + resource.setUpdatedTime(updatedTime); + + String physicalResourceId = resource.getPhysicalResourceId(); + Assert.assertNotNull(physicalResourceId); + resource.setPhysicalResourceId(physicalResourceId); + + List<String> requiredBy = resource.getRequiredBy(); + Assert.assertNotNull(requiredBy); + Assert.assertEquals(2, requiredBy.size()); + resource.setRequiredBy(requiredBy); + + String statusReason = resource.getStatusReason(); + Assert.assertNotNull(statusReason); + resource.setStatusReason(statusReason); + + String name = resource.getName(); + Assert.assertNotNull(name); + resource.setName(name); + + List<Link> links = resource.getLinks(); + Assert.assertNotNull(links); + Assert.assertEquals(2, links.size()); + resource.setLinks(links); + + String logicalResourceId = resource.getLogicalResourceId(); + Assert.assertNotNull(logicalResourceId); + resource.setLogicalResourceId(logicalResourceId); + + String type = resource.getType(); + Assert.assertNotNull(type); + resource.setType(type); + + String status = resource.getStatus(); + Assert.assertNotNull(status); + resource.setStatus(status); + } +} diff --git a/heat-model/src/test/java/com/woorea/openstack/heat/model/ResourcesTest.java b/heat-model/src/test/java/com/woorea/openstack/heat/model/ResourcesTest.java new file mode 100644 index 0000000..0093ab3 --- /dev/null +++ b/heat-model/src/test/java/com/woorea/openstack/heat/model/ResourcesTest.java @@ -0,0 +1,105 @@ +/*- + * ============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.heat.model; + +import com.woorea.openstack.heat.model.Resource; +import com.woorea.openstack.heat.model.Resources; +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 ResourcesTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"resources\" : [ {" + EOL + + " \"links\" : [ {" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + EOL + + " }, {" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + EOL + + " } ]," + EOL + + " \"resource_name\" : \"name\"," + EOL + + " \"resource_status\" : \"status\"," + EOL + + " \"physical_resource_id\" : \"physicalresourceid\"," + EOL + + " \"logical_resource_id\" : \"logicalresourceid\"," + EOL + + " \"required_by\" : [ \"requiredby-v1\", \"requiredby-v2\" ]," + EOL + + " \"updated_time\" : 1488110400000," + EOL + + " \"resource_type\" : \"type\"," + EOL + + " \"resource_status_reason\" : \"statusreason\"" + EOL + + " }, {" + EOL + + " \"links\" : [ {" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + EOL + + " }, {" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + EOL + + " } ]," + EOL + + " \"resource_name\" : \"name\"," + EOL + + " \"resource_status\" : \"status\"," + EOL + + " \"physical_resource_id\" : \"physicalresourceid\"," + EOL + + " \"logical_resource_id\" : \"logicalresourceid\"," + EOL + + " \"required_by\" : [ \"requiredby-v1\", \"requiredby-v2\" ]," + EOL + + " \"updated_time\" : 1488110400000," + EOL + + " \"resource_type\" : \"type\"," + EOL + + " \"resource_status_reason\" : \"statusreason\"" + 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: " + Resources.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Resources resources = objectMapper.readValue(JSON_FULL, Resources.class); + String json = objectMapper.writeValueAsString(resources); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Resources resources = objectMapper.readValue(JSON_FULL, Resources.class); + resources.toString(); + + List<Resource> list = resources.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Resource x : resources) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/heat-model/src/test/java/com/woorea/openstack/heat/model/StackTest.java b/heat-model/src/test/java/com/woorea/openstack/heat/model/StackTest.java new file mode 100644 index 0000000..8659895 --- /dev/null +++ b/heat-model/src/test/java/com/woorea/openstack/heat/model/StackTest.java @@ -0,0 +1,147 @@ +/*- + * ============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.heat.model; + +import com.woorea.openstack.heat.model.Link; +import com.woorea.openstack.heat.model.Stack; +import com.woorea.openstack.heat.model.Stack.Output; +import java.util.Date; +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 StackTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"stack\" : {" + EOL + + " \"description\" : \"description\"," + EOL + + " \"links\" : [ {" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + EOL + + " }, {" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + EOL + + " } ]," + EOL + + " \"id\" : \"id\"," + EOL + + " \"files\" : {" + EOL + + " \"files-k1\" : \"files-v1\"," + EOL + + " \"files-k2\" : \"files-v2\"" + EOL + + " }," + EOL + + " \"outputs\" : [ {" + EOL + + " \"description\" : \"description\"," + EOL + + " \"output_value\" : \"outputvalue\"," + EOL + + " \"output_key\" : \"outputkey\"" + EOL + + " }, {" + EOL + + " \"description\" : \"description\"," + EOL + + " \"output_value\" : \"outputvalue\"," + EOL + + " \"output_key\" : \"outputkey\"" + EOL + + " } ]," + EOL + + " \"parameters\" : {" + EOL + + " \"parameters-k1\" : \"parameters-v1\"," + EOL + + " \"parameters-k2\" : \"parameters-v2\"" + EOL + + " }," + EOL + + " \"stack_status_reason\" : \"stackstatusreason\"," + EOL + + " \"stack_name\" : \"stackname\"," + EOL + + " \"updated_time\" : 1488110400000," + EOL + + " \"creation_time\" : 1488974400000," + EOL + + " \"stack_status\" : \"stackstatus\"" + 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: " + Stack.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Stack stack = objectMapper.readValue(JSON_FULL, Stack.class); + String json = objectMapper.writeValueAsString(stack); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Stack stack = objectMapper.readValue(JSON_FULL, Stack.class); + stack.toString(); + + Date updatedTime = stack.getUpdatedTime(); + Assert.assertNotNull(updatedTime); + stack.setUpdatedTime(updatedTime); + + List<Output> outputs = stack.getOutputs(); + Assert.assertNotNull(outputs); + Assert.assertEquals(2, outputs.size()); + + String stackStatus = stack.getStackStatus(); + Assert.assertNotNull(stackStatus); + stack.setStackStatus(stackStatus); + + String description = stack.getDescription(); + Assert.assertNotNull(description); + stack.setDescription(description); + + Map<String,Object> files = stack.getFiles(); + Assert.assertNotNull(files); + Assert.assertEquals(2, files.size()); + stack.setFiles(files); + + List<Link> links = stack.getLinks(); + Assert.assertNotNull(links); + Assert.assertEquals(2, links.size()); + stack.setLinks(links); + + String stackName = stack.getStackName(); + Assert.assertNotNull(stackName); + stack.setStackName(stackName); + + String id = stack.getId(); + Assert.assertNotNull(id); + stack.setId(id); + + Date creationTime = stack.getCreationTime(); + Assert.assertNotNull(creationTime); + stack.setCreationTime(creationTime); + + Map<String,Object> parameters = stack.getParameters(); + Assert.assertNotNull(parameters); + Assert.assertEquals(2, parameters.size()); + stack.setParameters(parameters); + + String stackStatusReason = stack.getStackStatusReason(); + Assert.assertNotNull(stackStatusReason); + stack.setStackStatusReason(stackStatusReason); + } +} diff --git a/heat-model/src/test/java/com/woorea/openstack/heat/model/StacksTest.java b/heat-model/src/test/java/com/woorea/openstack/heat/model/StacksTest.java new file mode 100644 index 0000000..884d5a9 --- /dev/null +++ b/heat-model/src/test/java/com/woorea/openstack/heat/model/StacksTest.java @@ -0,0 +1,133 @@ +/*- + * ============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.heat.model; + +import com.woorea.openstack.heat.model.Stack; +import com.woorea.openstack.heat.model.Stacks; +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 StacksTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"stacks\" : [ {" + EOL + + " \"description\" : \"description\"," + EOL + + " \"links\" : [ {" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + EOL + + " }, {" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + EOL + + " } ]," + EOL + + " \"id\" : \"id\"," + EOL + + " \"files\" : {" + EOL + + " \"files-k1\" : \"files-v1\"," + EOL + + " \"files-k2\" : \"files-v2\"" + EOL + + " }," + EOL + + " \"outputs\" : [ {" + EOL + + " \"description\" : \"description\"," + EOL + + " \"output_value\" : \"outputvalue\"," + EOL + + " \"output_key\" : \"outputkey\"" + EOL + + " }, {" + EOL + + " \"description\" : \"description\"," + EOL + + " \"output_value\" : \"outputvalue\"," + EOL + + " \"output_key\" : \"outputkey\"" + EOL + + " } ]," + EOL + + " \"parameters\" : {" + EOL + + " \"parameters-k1\" : \"parameters-v1\"," + EOL + + " \"parameters-k2\" : \"parameters-v2\"" + EOL + + " }," + EOL + + " \"stack_status_reason\" : \"stackstatusreason\"," + EOL + + " \"stack_name\" : \"stackname\"," + EOL + + " \"updated_time\" : 1488110400000," + EOL + + " \"creation_time\" : 1488974400000," + EOL + + " \"stack_status\" : \"stackstatus\"" + EOL + + " }, {" + EOL + + " \"description\" : \"description\"," + EOL + + " \"links\" : [ {" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + EOL + + " }, {" + EOL + + " \"href\" : \"href\"," + EOL + + " \"rel\" : \"rel\"" + EOL + + " } ]," + EOL + + " \"id\" : \"id\"," + EOL + + " \"files\" : {" + EOL + + " \"files-k1\" : \"files-v1\"," + EOL + + " \"files-k2\" : \"files-v2\"" + EOL + + " }," + EOL + + " \"outputs\" : [ {" + EOL + + " \"description\" : \"description\"," + EOL + + " \"output_value\" : \"outputvalue\"," + EOL + + " \"output_key\" : \"outputkey\"" + EOL + + " }, {" + EOL + + " \"description\" : \"description\"," + EOL + + " \"output_value\" : \"outputvalue\"," + EOL + + " \"output_key\" : \"outputkey\"" + EOL + + " } ]," + EOL + + " \"parameters\" : {" + EOL + + " \"parameters-k1\" : \"parameters-v1\"," + EOL + + " \"parameters-k2\" : \"parameters-v2\"" + EOL + + " }," + EOL + + " \"stack_status_reason\" : \"stackstatusreason\"," + EOL + + " \"stack_name\" : \"stackname\"," + EOL + + " \"updated_time\" : 1488110400000," + EOL + + " \"creation_time\" : 1488974400000," + EOL + + " \"stack_status\" : \"stackstatus\"" + 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: " + Stacks.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Stacks stacks = objectMapper.readValue(JSON_FULL, Stacks.class); + String json = objectMapper.writeValueAsString(stacks); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Stacks stacks = objectMapper.readValue(JSON_FULL, Stacks.class); + stacks.toString(); + + int cnt = 0; + for (@SuppressWarnings("unused") Stack x : stacks) { + ++cnt; + } + Assert.assertEquals(2, cnt); + } +} diff --git a/heat-model/src/test/java/com/woorea/openstack/heat/model/UpdateStackParamTest.java b/heat-model/src/test/java/com/woorea/openstack/heat/model/UpdateStackParamTest.java new file mode 100644 index 0000000..5bff417 --- /dev/null +++ b/heat-model/src/test/java/com/woorea/openstack/heat/model/UpdateStackParamTest.java @@ -0,0 +1,104 @@ +/*- + * ============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.heat.model; + +import com.woorea.openstack.heat.model.UpdateStackParam; +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 UpdateStackParamTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"template\" : \"template\"," + EOL + + " \"parameters\" : {" + EOL + + " \"parameters-k1\" : \"parameters-v1\"," + EOL + + " \"parameters-k2\" : \"parameters-v2\"" + EOL + + " }," + EOL + + " \"environment\" : \"environment\"," + EOL + + " \"files\" : {" + EOL + + " \"files-k1\" : \"files-v1\"," + EOL + + " \"files-k2\" : \"files-v2\"" + EOL + + " }," + EOL + + " \"template_url\" : \"templateurl\"," + EOL + + " \"timeout_mins\" : 79," + EOL + + " \"disable_rollback\" : true" + 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: " + UpdateStackParam.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + UpdateStackParam updatestackparam = objectMapper.readValue(JSON_FULL, UpdateStackParam.class); + String json = objectMapper.writeValueAsString(updatestackparam); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + UpdateStackParam updatestackparam = objectMapper.readValue(JSON_FULL, UpdateStackParam.class); + updatestackparam.toString(); + + String template = updatestackparam.getTemplate(); + Assert.assertNotNull(template); + updatestackparam.setTemplate(template); + + String environment = updatestackparam.getEnvironment(); + Assert.assertNotNull(environment); + updatestackparam.setEnvironment(environment); + + int timeoutMinutes = updatestackparam.getTimeoutMinutes(); + Assert.assertNotNull(timeoutMinutes); + updatestackparam.setTimeoutMinutes(timeoutMinutes); + + boolean disableRollback = updatestackparam.getDisableRollback(); + Assert.assertNotNull(disableRollback); + updatestackparam.setDisableRollback(disableRollback); + + Map<String,Object> files = updatestackparam.getFiles(); + Assert.assertNotNull(files); + Assert.assertEquals(2, files.size()); + updatestackparam.setFiles(files); + + Map<String,Object> parameters = updatestackparam.getParameters(); + Assert.assertNotNull(parameters); + Assert.assertEquals(2, parameters.size()); + updatestackparam.setParameters(parameters); + + String templateUrl = updatestackparam.getTemplateUrl(); + Assert.assertNotNull(templateUrl); + updatestackparam.setTemplateUrl(templateUrl); + } +} |