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/src/test/java/com/woorea/openstack/nova/model/ImageFromVolumeTest.java | |
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/src/test/java/com/woorea/openstack/nova/model/ImageFromVolumeTest.java')
-rw-r--r-- | nova-model/src/test/java/com/woorea/openstack/nova/model/ImageFromVolumeTest.java | 196 |
1 files changed, 90 insertions, 106 deletions
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); + } +} |