diff options
author | Sonali Das <sd394g@att.com> | 2019-02-13 16:28:02 -0500 |
---|---|---|
committer | Takamune Cho <takamune.cho@att.com> | 2019-02-15 18:16:32 +0000 |
commit | fa84c610d97ea983203fa0e79635b7167578d745 (patch) | |
tree | 3a18988b69a418e27018e3b4d16f4e41a883f528 /appc-inbound/appc-artifact-handler/provider/src/test | |
parent | ffdeff1694e362befeebef4d462a45c1805a639d (diff) |
Support multiple Ansible servers
Issue-ID: APPC-1364
Change-Id: I63cf89f5964bcfaba7d1f0b0eac2477f827b69fa
Signed-off-by: Sonali Das <sd394g@att.com>
Review Comment update
Issue-ID: APPC-1364
Change-Id: I03fa97d60c6497218c14b53531c2dea69c7fba34
Signed-off-by: Sonali Das <sd394g@att.com>
Review Comment update
Issue-ID: APPC-1364
Change-Id: I03fa97d60c6497218c14b53531c2dea69c7fba34
Signed-off-by: Sonali Das <sd394g@att.com>
Support multiple Ansible servers
Issue-ID: APPC-1364
Change-Id: I63cf89f5964bcfaba7d1f0b0eac2477f827b69fa
Signed-off-by: Sonali Das <sd394g@att.com>
Support multiple Ansible servers
Issue-ID: APPC-1364
Change-Id: I63cf89f5964bcfaba7d1f0b0eac2477f827b69fa
Signed-off-by: Sonali Das <sd394g@att.com>
Diffstat (limited to 'appc-inbound/appc-artifact-handler/provider/src/test')
-rw-r--r-- | appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java index 0d25fbcb4..7adee0da9 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java @@ -58,6 +58,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + @RunWith(PowerMockRunner.class) @PrepareForTest({DBService.class, YANGGeneratorFactory.class}) @@ -298,4 +300,147 @@ public class ArtifactHandlerNodeTest { documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "12345"); return documentInfo; } + + + @Test + public void testValidateAnsibleAdminArtifact() throws Exception { + String contentStr = "{\"fqdn-list\":[{\"vnf-management-server-fqdn\":\"fqdn-value1 url:port\",\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\"," + + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]},{\"region-id\":\"san4b\"," + + "\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]}]},{\"cloud-owner\":\"nc1.0\",\"region-id-list\":[{\"region-id\":\"san4a\"," + + "\"tenant-id-list\":[\"tenantuuid3\",\"tenantuuid4\"]}]}],\"description\":\"fqdn for east zone Production\",\"username\":\"attuid\"," + + "\"create-date\":\"\",\"modify-username\":\"\",\"modify-date\":\"\"},{\"vnf-management-server-fqdn\":\"fqdn-value2 url:port\"," + + "\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\",\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid5\"," + + "\"tenantuuid6\"]},{\"region-id\":\"san4b\",\"tenant-id-list\":[\"tenantuuid5\",\"tenantuuid6\"]}]},{\"cloud-owner\":\"nc1.0\"," + + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid7\",\"tenantuuid8\"]}]}]," + + "\"description\":\"fqdn for east zone Test\",\"username\":\"attuid\",\"create-date\":\"\"," + + "\"modify-username\":\"\",\"modify-date\":\"\"}]}"; + + JSONObject documentInfo = new JSONObject(); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, contentStr); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.1V.json"); + artifactHandlerNode.validateAnsibleAdminArtifact(documentInfo); + } + + @Test + public void testValidateAnsibleAdminArtifactWithException() throws Exception { + String contentStrOne = "{\"fqdn-list\":[{\"vnf-management-server-fqdn\":\"fqdn-value1 url:port\",\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\"," + + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]},{\"region-id\":\"san4b\"," + + "\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]}]},{\"cloud-owner\":\"nc1.0\",\"region-id-list\":[{\"region-id\":\"san4a\"," + + "\"tenant-id-list\":[\"tenantuuid3\",\"tenantuuid4\"]}]}],\"description\":\"fqdn for east zone Production\",\"username\":\"attuid\"," + + "\"create-date\":\"\",\"modify-username\":\"\",\"modify-date\":\"\"},{\"vnf-management-server-fqdn\":\"fqdn-value2 url:port\"," + + "\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\",\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid1\"," + + "\"tenantuuid6\"]},{\"region-id\":\"san4b\",\"tenant-id-list\":[\"tenantuuid5\",\"tenantuuid6\"]}]},{\"cloud-owner\":\"nc1.0\"," + + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid7\",\"tenantuuid8\"]}]}]," + + "\"description\":\"fqdn for east zone Test\",\"username\":\"attuid\",\"create-date\":\"\"," + + "\"modify-username\":\"\",\"modify-date\":\"\"}]}"; + JSONObject documentInfoOne = new JSONObject(); + documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, contentStrOne); + documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.1V.json"); + + try { + artifactHandlerNode.validateAnsibleAdminArtifact(documentInfoOne); + fail("Missing exception"); + }catch(ArtifactHandlerInternalException e) { + assertTrue(e.getMessage().contains("Validation Failure")); + } + + } + + @Test + public void testValidateAnsibleAdminArtifactWithJSONException() throws Exception { + String contentStrOne = "{\"fqdn-list\":[{\"vnf-management-server-fqdn\":\"fqdn-value1 url:port\",\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\"}"; + + JSONObject documentInfoOne = new JSONObject(); + documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, contentStrOne); + documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.1V.json"); + + try { + artifactHandlerNode.validateAnsibleAdminArtifact(documentInfoOne); + fail("Missing exception"); + }catch(ArtifactHandlerInternalException je) { + assertTrue(je.getMessage().contains("JSON Exception")); + + } + + } + + @Test + public void testProcessArtifactWithException() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + Map<String, String> inParams = new HashMap<>(); + JSONObject postData = new JSONObject(); + JSONObject input = new JSONObject(); + inParams.put("response_prefix", "prefix"); + JSONObject requestInfo = new JSONObject(); + JSONObject documentInfo = new JSONObject(); + String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() + .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, ""); + requestInfo.put("RequestInfo", "testValue"); + requestInfo.put("request-id","testREQUEST_ID"); + input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo); + input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); + postData.put("input", input); + inParams.put("postData", postData.toString()); + try { + artifactHandlerNode.processArtifact(inParams, ctx); + fail("Missing exception"); + }catch(Exception e) { + assertTrue(e.getMessage().contains("Missing Artifact Name")); + } + + } + @Test + public void testProcessArtifactWithExceptionforAnsible() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + Map<String, String> inParams = new HashMap<>(); + JSONObject postData = new JSONObject(); + JSONObject input = new JSONObject(); + inParams.put("response_prefix", "prefix"); + JSONObject requestInfo = new JSONObject(); + JSONObject documentInfo = new JSONObject(); + String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() + .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.2V.json"); + requestInfo.put("RequestInfo", "testValue"); + requestInfo.put("request-id","testREQUEST_ID"); + input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo); + input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); + postData.put("input", input); + inParams.put("postData", postData.toString()); + + try { + artifactHandlerNode.processArtifact(inParams, ctx); + fail("Missing exception"); + }catch(Exception e) { + assertTrue(e.getMessage().contains("JSON Exception:ansible admin")); + } + } + + @Test + public void testProcessAndStoreCapablitiesArtifact() throws Exception { + ArtifactHandlerNode ah = new ArtifactHandlerNode(); + JSONObject capabilities = new JSONObject(); + JSONObject documentInfo = new JSONObject(); + MockDBService dbService = MockDBService.initialise(); + documentInfo.put(SdcArtifactHandlerConstants.SERVICE_UUID, "testuid"); + documentInfo.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "testDist"); + documentInfo.put(SdcArtifactHandlerConstants.SERVICE_NAME, "testName"); + documentInfo.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "testDesc"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "testRes"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "testResIns"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, "testVers"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "testResType"); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "testArtifactUuid"); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, "testArtifactVers"); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "testArtifactDesc"); + Whitebox.invokeMethod(ah, "processAndStoreCapabilitiesArtifact", dbService, documentInfo, capabilities, + "artifactName", "someVnf"); + } + + } |