diff options
author | jh7358 <jh7358@att.com> | 2018-08-23 17:00:50 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2018-08-23 18:40:43 -0400 |
commit | 51e88a932274a3ff8a93996332bb4f1d55d4a773 (patch) | |
tree | 2328dbc3e54fbf29fffa6ebe10e5dad4837a83f4 /controlloop/common/model-impl/aai/src/test/java | |
parent | 5bb419efe574df172555263110f9492980f5d1e0 (diff) |
walk VF module names
Added code to walk the VF modules to count the number of modules and
to generate the new module instance name.
Added comment to test method.
Fix checkstyle errors.
Read json files instead of resources.
Removed checkstyle plugin from aai pom, as it continues to barf every
time I use some automated feature of Eclipse.
Use Files.readAllBytes() instead of IoUtils.toString(uri).
Try concatenating file path.
Turned out to be a problem with file name case sensitivity - renamed
the file.
Change-Id: I1ce98d846dfa1d29e109b161c869108425d29771
Issue-ID: POLICY-1037
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/model-impl/aai/src/test/java')
-rw-r--r-- | controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java | 110 |
1 files changed, 101 insertions, 9 deletions
diff --git a/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java b/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java index 0d6a49361..3c5502802 100644 --- a/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java +++ b/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AaiNqResponseWrapperTest.java @@ -20,13 +20,16 @@ package org.onap.policy.aai; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.LinkedList; +import java.util.List; import java.util.UUID; - -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.apache.commons.io.IOUtils; import org.junit.Test; import org.onap.policy.aai.util.Serialization; import org.slf4j.Logger; @@ -35,12 +38,6 @@ import org.slf4j.LoggerFactory; public class AaiNqResponseWrapperTest { private static final Logger logger = LoggerFactory.getLogger(AaiNqResponseWrapperTest.class); - @BeforeClass - public static void setUpBeforeClass() throws Exception {} - - @AfterClass - public static void tearDownAfterClass() throws Exception {} - @Test public void test() { AaiNqInventoryResponseItem serviceItem = new AaiNqInventoryResponseItem(); @@ -169,4 +166,99 @@ public class AaiNqResponseWrapperTest { assertNotNull(aaiNqResponseWarapper2.getAaiNqResponse()); logger.info(Serialization.gsonPretty.toJson(aaiNqResponseWarapper2)); } + + @Test + public void testCountVfModules() throws Exception { + AaiNqResponseWrapper resp; + + // null item + resp = new AaiNqResponseWrapper(); + assertEquals(0, resp.countVfModules()); + + // no names + resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoNames.json")); + assertEquals(0, resp.countVfModules()); + + // has VF modules + resp.setAaiNqResponse(load("AaiNqResponseWrapper-Vserver.json")); + assertEquals(3, resp.countVfModules()); + } + + @Test + public void testGenVfModuleName() throws Exception { + AaiNqResponseWrapper resp; + + // null item + resp = new AaiNqResponseWrapper(); + assertEquals(null, resp.genVfModuleName()); + + // no names + resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoNames.json")); + assertEquals(null, resp.genVfModuleName()); + + // has VF modules + resp.setAaiNqResponse(load("AaiNqResponseWrapper-Vserver.json")); + assertEquals("my-module-abc_124", resp.genVfModuleName()); + } + + @Test + public void testGetVfModules() throws Exception { + AaiNqResponseWrapper resp; + + // null item + resp = new AaiNqResponseWrapper(); + assertNull(resp.getVfModules(true)); + + // missing item + resp = new AaiNqResponseWrapper(); + resp.setAaiNqResponse(new AaiNqResponse()); + assertNull(resp.getVfModules(false)); + + // null item list + resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoItems.json")); + resp.getAaiNqResponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems().get(0) + .getItems().setInventoryResponseItems(null); + assertNull(resp.getVfModules(false)); + + // no modules + resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoModules.json")); + assertNull(resp.getVfModules(false)); + + // no names + resp.setAaiNqResponse(load("AaiNqResponseWrapper-NoNames.json")); + List<AaiNqVfModule> lst; + lst = resp.getVfModules(false); + assertNotNull(lst); + assertEquals(0, lst.size()); + + // base VF modules + resp.setAaiNqResponse(load("AaiNqResponseWrapper-Vserver.json")); + lst = resp.getVfModules(true); + assertNotNull(lst); + assertEquals(1, lst.size()); + assertEquals("Vfmodule_vLBMS-0809-1", lst.get(0).getVfModuleName()); + + // non base VF modules + resp.setAaiNqResponse(load("AaiNqResponseWrapper-Vserver.json")); + lst = resp.getVfModules(false); + assertNotNull(lst); + assertEquals(3, lst.size()); + int index; + index = 0; + assertEquals("my-module-abc_1", lst.get(index++).getVfModuleName()); + assertEquals("my-module-abc_123", lst.get(index++).getVfModuleName()); + assertEquals("my-module-abc_34", lst.get(index++).getVfModuleName()); + } + + /** + * Loads a response from a JSON file. + * + * @param fileName name of the file containing the JSON response + * @return the response + * @throws IOException if the file cannot be read + */ + private AaiNqResponse load(String fileName) throws IOException { + String json = IOUtils.toString(getClass().getResource(fileName), StandardCharsets.UTF_8); + return Serialization.gsonPretty.fromJson(json, AaiNqResponse.class); + } } |