summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2018-03-23 14:46:56 +0100
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2018-03-23 14:46:56 +0100
commit378d05bded462b721cd04e7eb5ab06a944da452e (patch)
tree1469e4d7645cb33c5c86a8c4ecccb63593e50626 /src
parentdc90370d229c69ed6c7ce39993f72a0ea3a314e9 (diff)
Rework the SDC test
Rework the uni tests so that SDC controller is more tested, also dcae code has been reworked for improving sonar report Issue-ID: CLAMP-81 Change-Id: Ia6ec272e1bf86e72d9d7294aeec0695b861f78af Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java59
-rw-r--r--src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryResponse.java53
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java5
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java10
-rw-r--r--src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java44
-rw-r--r--src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java61
-rw-r--r--src/test/resources/application.properties4
-rw-r--r--src/test/resources/example/dao/template-doc-content.json105
8 files changed, 266 insertions, 75 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
index c4abebdc..d5015040 100644
--- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
@@ -30,13 +30,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
-import java.security.GeneralSecurityException;
import java.util.Date;
import java.util.List;
import javax.ws.rs.BadRequestException;
-import org.apache.commons.codec.DecoderException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@ -46,6 +44,7 @@ import org.onap.clamp.clds.dao.CldsDao;
import org.onap.clamp.clds.model.CldsEvent;
import org.onap.clamp.clds.model.CldsModel;
import org.onap.clamp.clds.model.DcaeEvent;
+import org.onap.clamp.clds.model.dcae.DcaeInventoryResponse;
import org.onap.clamp.clds.model.properties.Global;
import org.onap.clamp.clds.model.properties.ModelProperties;
import org.onap.clamp.clds.util.LoggingUtils;
@@ -61,7 +60,9 @@ public class DcaeInventoryServices {
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(DcaeInventoryServices.class);
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
- private static final String DCAE_INVENTORY_URL = "dcae.inventory.url";
+ public static final String DCAE_INVENTORY_URL = "dcae.inventory.url";
+ public static final String DCAE_TYPE_NAME = "typeName";
+ public static final String DCAE_TYPE_ID = "typeId";
@Autowired
private ClampProperties refProp;
@Autowired
@@ -74,18 +75,13 @@ public class DcaeInventoryServices {
* The CldsModel
* @param userId
* The user ID
- * @throws GeneralSecurityException
- * In case of issue when decryting the DCAE password
* @throws ParseException
* In case of DCAE Json parse exception
- * @throws DecoderException
- * In case of issues with HexString decoding
*/
- public void setEventInventory(CldsModel cldsModel, String userId)
- throws GeneralSecurityException, ParseException, DecoderException {
+ public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException {
String artifactName = cldsModel.getControlName();
DcaeEvent dcaeEvent = new DcaeEvent();
- String isDcaeInfoAvailable = null;
+ DcaeInventoryResponse dcaeResponse = null;
Date startTime = new Date();
LoggingUtils.setTargetContext("DCAE", "setEventInventory");
if (artifactName != null) {
@@ -103,7 +99,7 @@ public class DcaeInventoryServices {
resourceUuid = resourceUuidList.get(0);
}
/* Inventory service url is called in this method */
- isDcaeInfoAvailable = getDcaeInformation(artifactName, invariantServiceUuid, resourceUuid);
+ dcaeResponse = getDcaeInformation(artifactName, invariantServiceUuid, resourceUuid);
/* set dcae events */
dcaeEvent.setArtifactName(artifactName);
dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION);
@@ -120,22 +116,21 @@ public class DcaeInventoryServices {
LoggingUtils.setTimeContext(startTime, new Date());
metricsLogger.info("setEventInventory complete");
}
- /* Null whether the DCAE has items lenght or not */
- if (isDcaeInfoAvailable != null) {
- /* Inserting Event in to DB */
- logger.info(isDcaeInfoAvailable);
- JSONParser parser = new JSONParser();
- Object obj0 = parser.parse(isDcaeInfoAvailable);
- JSONObject jsonObj = (JSONObject) obj0;
+ this.analyzeAndSaveDcaeResponse(dcaeResponse, cldsModel, dcaeEvent, userId);
+ }
+
+ private void analyzeAndSaveDcaeResponse(DcaeInventoryResponse dcaeResponse, CldsModel cldsModel,
+ DcaeEvent dcaeEvent, String userId) throws ParseException {
+ if (dcaeResponse != null) {
+ logger.info("Dcae Response for query on inventory: " + dcaeResponse);
String oldTypeId = cldsModel.getTypeId();
String newTypeId = "";
- if (jsonObj.get("typeId") != null) {
- newTypeId = jsonObj.get("typeId").toString();
- cldsModel.setTypeId(jsonObj.get("typeId").toString());
+ if (dcaeResponse.getTypeId() != null) {
+ newTypeId = dcaeResponse.getTypeId();
+ cldsModel.setTypeId(dcaeResponse.getTypeId());
}
- // cldsModel.setTypeName(cldsModel.getControlName().toString()+".yml");
- if (jsonObj.get("typeName") != null) {
- cldsModel.setTypeName(jsonObj.get("typeName").toString());
+ if (dcaeResponse.getTypeName() != null) {
+ cldsModel.setTypeName(dcaeResponse.getTypeName());
}
if (oldTypeId == null || !oldTypeId.equalsIgnoreCase(newTypeId)
|| cldsModel.getEvent().getActionCd().equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE)) {
@@ -157,13 +152,13 @@ public class DcaeInventoryServices {
* The service UUID
* @param resourceUuid
* The resource UUID
- * @return The DCAE inventory for the artifact
+ * @return The DCAE inventory for the artifact in DcaeInventoryResponse
* @throws IOException
* In case of issues with the stream
* @throws ParseException
* In case of issues with the Json parsing
*/
- public String getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)
+ public DcaeInventoryResponse getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)
throws IOException, ParseException {
Date startTime = new Date();
LoggingUtils.setTargetContext("DCAE", "getDcaeInformation");
@@ -171,25 +166,23 @@ public class DcaeInventoryServices {
+ artifactName;
String fullUrl = refProp.getStringValue(DCAE_INVENTORY_URL) + "/dcae-service-types" + queryString;
logger.info("Dcae Inventory Service full url - " + fullUrl);
- String daceInventoryResponse = null;
+ String dcaeInventoryResponse = null;
String responseStr = DcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "GET", null, null);
JSONParser parser = new JSONParser();
Object obj0 = parser.parse(responseStr);
JSONObject jsonObj = (JSONObject) obj0;
Long totalCount = (Long) jsonObj.get("totalCount");
int numServices = totalCount.intValue();
- if (numServices == 0) {
- daceInventoryResponse = null;
- } else if (numServices > 0) {
+ if (numServices > 0) {
JSONArray itemsArray = (JSONArray) jsonObj.get("items");
JSONObject dcaeServiceType0 = (JSONObject) itemsArray.get(0);
- daceInventoryResponse = dcaeServiceType0.toString();
- logger.info(daceInventoryResponse);
+ dcaeInventoryResponse = dcaeServiceType0.toString();
+ logger.info("getDcaeInformation, answer from DCAE inventory:" + dcaeInventoryResponse);
}
LoggingUtils.setResponseContext("0", "Get Dcae Information success", this.getClass().getName());
LoggingUtils.setTimeContext(startTime, new Date());
metricsLogger.info("getDcaeInformation complete: number services returned=" + numServices);
- return daceInventoryResponse;
+ return new ObjectMapper().readValue(dcaeInventoryResponse, DcaeInventoryResponse.class);
}
/**
diff --git a/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryResponse.java b/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryResponse.java
new file mode 100644
index 00000000..b0a784c8
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryResponse.java
@@ -0,0 +1,53 @@
+
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * 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============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.model.dcae;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+/**
+ * This class maps the DCAE inventory answer to a nice pojo.
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class DcaeInventoryResponse {
+
+ private String typeName;
+ private String typeId;
+
+ public String getTypeName() {
+ return typeName;
+ }
+
+ public void setTypeName(String typeName) {
+ this.typeName = typeName;
+ }
+
+ public String getTypeId() {
+ return typeId;
+ }
+
+ public void setTypeId(String typeId) {
+ this.typeId = typeId;
+ }
+}
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
index b1138523..97ab0586 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
@@ -66,6 +66,7 @@ public class CsarHandler {
private String blueprintInvariantResourceUuid;
private String blueprintInvariantServiceUuid;
public static final String CSAR_TYPE = "TOSCA_CSAR";
+ public static final String BLUEPRINT_TYPE = "DCAE_INVENTORY_BLUEPRINT";
private INotificationData sdcNotification;
public CsarHandler(INotificationData iNotif, String controller, String clampCsarPath) throws CsarHandlerException {
@@ -114,7 +115,7 @@ public class CsarHandler {
for (IResourceInstance resource : this.getSdcNotification().getResources()) {
if ("VF".equals(resource.getResourceType())) {
for (IArtifactInfo artifact : resource.getArtifacts()) {
- if ("DCAE_INVENTORY_BLUEPRINT".equals(artifact.getArtifactType())) {
+ if (BLUEPRINT_TYPE.equals(artifact.getArtifactType())) {
blueprintArtifactName = artifact.getArtifactName();
blueprintInvariantResourceUuid = resource.getResourceInvariantUUID();
}
@@ -129,7 +130,7 @@ public class CsarHandler {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
- if (entry.getName().contains("DCAE_INVENTORY_BLUEPRINT")) {
+ if (entry.getName().contains(BLUEPRINT_TYPE)) {
listEntries.add(entry);
}
}
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
index cb100725..4c6ed7fc 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
@@ -24,8 +24,6 @@
package org.onap.clamp.clds.sdc.controller.installer;
import com.att.aft.dme2.internal.apache.commons.io.IOUtils;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
import java.util.ArrayList;
@@ -57,7 +55,6 @@ import org.yaml.snakeyaml.Yaml;
*/
public class CsarInstallerImpl implements CsarInstaller {
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarInstallerImpl.class);
private Map<String, BlueprintParserFilesConfiguration> bpmnMapping = new HashMap<>();
public static final String TEMPLATE_NAME_PREFIX = "DCAE-Designer-ClosedLoopTemplate-";
public static final String MODEL_NAME_PREFIX = "ClosedLoop-";
@@ -153,11 +150,11 @@ public class CsarInstallerImpl implements CsarInstaller {
private String queryDcaeToGetServiceTypeId(CsarHandler csar) throws IOException, ParseException {
return dcaeInventoryService.getDcaeInformation(csar.getBlueprintArtifactName(),
- csar.getBlueprintInvariantServiceUuid(), csar.getBlueprintInvariantResourceUuid());
+ csar.getBlueprintInvariantServiceUuid(), csar.getBlueprintInvariantResourceUuid()).getTypeId();
}
private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintParserFilesConfiguration configFiles)
- throws IOException, SdcArtifactInstallerException {
+ throws IOException {
CldsTemplate template = new CldsTemplate();
template.setBpmnId("Sdc-Generated");
template.setBpmnText(
@@ -184,9 +181,8 @@ public class CsarInstallerImpl implements CsarInstaller {
cldsModel.setBlueprintText(csar.getDcaeBlueprint());
cldsModel.setTemplateName(cldsTemplate.getName());
cldsModel.setTemplateId(cldsTemplate.getId());
- // cldsModel.setDocText(cldsTemplate.getPropText());
cldsModel.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\""
- + csar.getSdcNotification().getServiceInvariantUUID() + "\"]},{\"name\":\"vf\",\"value\":[\""
+ + csar.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\""
+ csar.getBlueprintInvariantResourceUuid()
+ "\"]},{\"name\":\"actionSet\",\"value\":[\"vnfRecipe\"]},{\"name\":\"location\",\"value\":[\"DC1\"]}]}");
cldsModel.setBpmnText(cldsTemplate.getBpmnText());
diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java
index b64e6a0d..40dffcd6 100644
--- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java
@@ -25,6 +25,7 @@ package org.onap.clamp.clds.it.sdc.controller.installer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.att.aft.dme2.internal.apache.commons.io.IOUtils;
@@ -47,28 +48,22 @@ import org.onap.clamp.clds.util.ResourceFileUtil;
import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.openecomp.sdc.toscaparser.api.elements.Metadata;
-import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.test.util.ReflectionTestUtils;
@RunWith(SpringRunner.class)
@SpringBootTest
public class CsarInstallerItCase {
- private static final String sdcFolder = "/tmp/csar-handler-tests";
- private static final String csarArtifactName = "testArtifact.csar";
+ private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar";
+ private static final String SERVICE_UUID = "serviceUUID";
+ private static final String RESOURCE1_UUID = "resource1UUID";
@Autowired
private CsarInstaller csarInstaller;
@Autowired
private CldsDao cldsDao;
- private void loadFile(String fileName) throws IOException {
- ReflectionTestUtils.setField(csarInstaller, "blueprintMappingFile", fileName);
- ((CsarInstallerImpl) csarInstaller).loadConfiguration();
- }
-
@Test(expected = SdcArtifactInstallerException.class)
public void testInstallTheCsarFail()
throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException {
@@ -79,10 +74,7 @@ public class CsarInstallerItCase {
fail("Should have raised an SdcArtifactInstallerException");
}
- @Test(expected = SdcArtifactInstallerException.class)
- public void testInstallTheCsarTca()
- throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException {
- String generatedName = RandomStringUtils.randomAlphanumeric(5);
+ private CsarHandler buildFakeCsarHandler(String generatedName) throws IOException {
CsarHandler csarHandler = Mockito.mock(CsarHandler.class);
Mockito.when(csarHandler.getDcaeBlueprint())
.thenReturn(ResourceFileUtil.getResourceAsString("example/sdc/blueprint-dcae/tca.yaml"));
@@ -91,7 +83,26 @@ public class CsarInstallerItCase {
Mockito.when(data.getValue("name")).thenReturn(generatedName);
Mockito.when(csarHelper.getServiceMetadata()).thenReturn(data);
Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(csarHelper);
+ Mockito.when(csarHandler.getBlueprintArtifactName()).thenReturn(CSAR_ARTIFACT_NAME);
+ Mockito.when(csarHandler.getBlueprintInvariantServiceUuid()).thenReturn(SERVICE_UUID);
+ Mockito.when(csarHandler.getBlueprintInvariantResourceUuid()).thenReturn(RESOURCE1_UUID);
+ return csarHandler;
+ }
+
+ @Test
+ public void testIsCsarAlreadyDeployedTca()
+ throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException {
+ String generatedName = RandomStringUtils.randomAlphanumeric(5);
+ CsarHandler csarHandler = buildFakeCsarHandler(generatedName);
csarInstaller.installTheCsar(csarHandler);
+ assertTrue(csarInstaller.isCsarAlreadyDeployed(csarHandler));
+ }
+
+ @Test
+ public void testInstallTheCsarTca()
+ throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException {
+ String generatedName = RandomStringUtils.randomAlphanumeric(5);
+ csarInstaller.installTheCsar(buildFakeCsarHandler(generatedName));
// Get the template back from DB
CldsTemplate templateFromDB = CldsTemplate.retrieve(cldsDao,
CsarInstallerImpl.TEMPLATE_NAME_PREFIX + generatedName, false);
@@ -99,15 +110,16 @@ public class CsarInstallerItCase {
assertNotNull(templateFromDB.getBpmnText());
assertNotNull(templateFromDB.getImageText());
assertNotNull(templateFromDB.getPropText());
+ assertTrue(templateFromDB.getPropText().contains("global")
+ && templateFromDB.getPropText().contains("node_templates:"));
assertEquals(templateFromDB.getName(), CsarInstallerImpl.TEMPLATE_NAME_PREFIX + generatedName);
- JSONAssert.assertEquals(templateFromDB.getPropText(),
- ResourceFileUtil.getResourceAsString("example/dao/template-doc-content.json"), true);
// Get the Model back from DB
- CldsModel modelFromDB = CldsModel.retrieve(cldsDao, generatedName, false);
+ CldsModel modelFromDB = CldsModel.retrieve(cldsDao, generatedName, true);
assertNotNull(modelFromDB);
assertNotNull(modelFromDB.getBpmnText());
assertNotNull(modelFromDB.getImageText());
assertNotNull(modelFromDB.getPropText());
assertEquals(modelFromDB.getName(), generatedName);
+ assertEquals(CsarInstallerImpl.MODEL_NAME_PREFIX, modelFromDB.getControlNamePrefix());
}
}
diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java
index 34805d87..c842068d 100644
--- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java
+++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandlerTest.java
@@ -45,25 +45,29 @@ import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerExceptio
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.openecomp.sdc.api.notification.IArtifactInfo;
import org.openecomp.sdc.api.notification.INotificationData;
+import org.openecomp.sdc.api.notification.IResourceInstance;
import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
public class CsarHandlerTest {
- private static final String sdcFolder = "/tmp/csar-handler-tests";
- private static final String csarArtifactName = "testArtifact.csar";
+ private static final String SDC_FOLDER = "/tmp/csar-handler-tests";
+ private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar";
+ private static final String SERVICE_UUID = "serviceUUID";
+ private static final String RESOURCE1_UUID = "resource1UUID";
+ private static final String BLUEPRINT1_NAME = "blueprint1-name";
@Test
public void testConstructor() throws CsarHandlerException {
IArtifactInfo serviceArtifact = Mockito.mock(IArtifactInfo.class);
Mockito.when(serviceArtifact.getArtifactType()).thenReturn(CsarHandler.CSAR_TYPE);
- Mockito.when(serviceArtifact.getArtifactName()).thenReturn(csarArtifactName);
+ Mockito.when(serviceArtifact.getArtifactName()).thenReturn(CSAR_ARTIFACT_NAME);
List<IArtifactInfo> servicesList = new ArrayList<>();
servicesList.add(serviceArtifact);
INotificationData notifData = Mockito.mock(INotificationData.class);
Mockito.when(notifData.getServiceArtifacts()).thenReturn(servicesList);
- CsarHandler csar = new CsarHandler(notifData, "test-controller", sdcFolder);
- assertEquals(sdcFolder + "/test-controller" + "/" + csarArtifactName, csar.getFilePath());
+ CsarHandler csar = new CsarHandler(notifData, "test-controller", SDC_FOLDER);
+ assertEquals(SDC_FOLDER + "/test-controller" + "/" + CSAR_ARTIFACT_NAME, csar.getFilePath());
}
@Test(expected = CsarHandlerException.class)
@@ -74,32 +78,61 @@ public class CsarHandlerTest {
fail("Exception should have been raised");
}
- @Test
- public void testSave()
- throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException {
+ private INotificationData buildFakeSdcNotification() {
+ // BUild what is needed for CSAR
IArtifactInfo serviceArtifact = Mockito.mock(IArtifactInfo.class);
Mockito.when(serviceArtifact.getArtifactType()).thenReturn(CsarHandler.CSAR_TYPE);
- Mockito.when(serviceArtifact.getArtifactName()).thenReturn(csarArtifactName);
+ Mockito.when(serviceArtifact.getArtifactName()).thenReturn(CSAR_ARTIFACT_NAME);
List<IArtifactInfo> servicesList = new ArrayList<>();
servicesList.add(serviceArtifact);
INotificationData notifData = Mockito.mock(INotificationData.class);
Mockito.when(notifData.getServiceArtifacts()).thenReturn(servicesList);
- CsarHandler csar = new CsarHandler(notifData, "test-controller", "/tmp/csar-handler-tests");
+ // Build what is needed for UUID
+ Mockito.when(notifData.getServiceInvariantUUID()).thenReturn(SERVICE_UUID);
+ // Build fake resource with one artifact BLUEPRINT
+ List<IResourceInstance> resourcesList = new ArrayList<>();
+ List<IArtifactInfo> artifactsListForResource = new ArrayList<>();
+ IResourceInstance resource1 = Mockito.mock(IResourceInstance.class);
+ Mockito.when(resource1.getResourceType()).thenReturn("VF");
+ Mockito.when(resource1.getResourceInvariantUUID()).thenReturn(RESOURCE1_UUID);
+ // Create a fake artifact for resource
+ IArtifactInfo blueprintArtifact = Mockito.mock(IArtifactInfo.class);
+ Mockito.when(blueprintArtifact.getArtifactType()).thenReturn(CsarHandler.BLUEPRINT_TYPE);
+ Mockito.when(blueprintArtifact.getArtifactName()).thenReturn(BLUEPRINT1_NAME);
+ artifactsListForResource.add(blueprintArtifact);
+ Mockito.when(resource1.getArtifacts()).thenReturn(artifactsListForResource);
+ resourcesList.add(resource1);
+ Mockito.when(notifData.getResources()).thenReturn(resourcesList);
+ return notifData;
+ }
+
+ private IDistributionClientDownloadResult buildFakeSdcResut() throws IOException {
IDistributionClientDownloadResult resultArtifact = Mockito.mock(IDistributionClientDownloadResult.class);
Mockito.when(resultArtifact.getArtifactPayload()).thenReturn(
IOUtils.toByteArray(ResourceFileUtil.getResourceAsStream("example/sdc/service-Simsfoimap0112.csar")));
+ return resultArtifact;
+ }
+
+ @Test
+ public void testSave()
+ throws SdcArtifactInstallerException, SdcToscaParserException, CsarHandlerException, IOException {
+ CsarHandler csar = new CsarHandler(buildFakeSdcNotification(), "test-controller", "/tmp/csar-handler-tests");
// Test the save
- csar.save(resultArtifact);
- assertTrue((new File(sdcFolder + "/test-controller/" + csarArtifactName)).exists());
- assertEquals(csarArtifactName, csar.getArtifactElement().getArtifactName());
+ csar.save(buildFakeSdcResut());
+ assertTrue((new File(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME)).exists());
+ assertEquals(CSAR_ARTIFACT_NAME, csar.getArtifactElement().getArtifactName());
assertNotNull(csar.getSdcCsarHelper());
// Test dcaeBlueprint
String blueprint = csar.getDcaeBlueprint();
assertNotNull(blueprint);
assertTrue(!blueprint.isEmpty());
assertTrue(blueprint.contains("DCAE-VES-PM-EVENT-v1"));
+ // Test additional properties from Sdc notif
+ assertEquals(BLUEPRINT1_NAME, csar.getBlueprintArtifactName());
+ assertEquals(RESOURCE1_UUID, csar.getBlueprintInvariantResourceUuid());
+ assertEquals(SERVICE_UUID, csar.getBlueprintInvariantServiceUuid());
// Do some cleanup
- Path path = Paths.get(sdcFolder + "/test-controller/" + csarArtifactName);
+ Path path = Paths.get(SDC_FOLDER + "/test-controller/" + CSAR_ARTIFACT_NAME);
Files.deleteIfExists(path);
}
}
diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties
index 55666e5c..37f9bd7e 100644
--- a/src/test/resources/application.properties
+++ b/src/test/resources/application.properties
@@ -190,10 +190,10 @@ clamp.config.action.insert.test.event=false
clamp.config.clds.service.cache.invalidate.after.seconds=120
#DCAE Inventory Url Properties
-clamp.config.dcae.inventory.url=http://dcae.api.simpledemo.onap.org:8080
+clamp.config.dcae.inventory.url=http://localhost:${docker.http-cache.port.host}
#DCAE Dispatcher Url Properties
-clamp.config.dcae.dispatcher.url=http://dcae.api.simpledemo.onap.org:8080
+clamp.config.dcae.dispatcher.url=http://localhost:${docker.http-cache.port.host}
clamp.config.dcae.header.requestId = X-ECOMP-RequestID
#Define user permission related parameters, the permission type can be changed but MUST be redefined in clds-users.properties in that case !
diff --git a/src/test/resources/example/dao/template-doc-content.json b/src/test/resources/example/dao/template-doc-content.json
index 3b7e2df9..0ee71220 100644
--- a/src/test/resources/example/dao/template-doc-content.json
+++ b/src/test/resources/example/dao/template-doc-content.json
@@ -1 +1,104 @@
-{"global":[{"name":"service","value":["tosca_definitions_version: cloudify_dsl_1_3\r\nimports:\r\n- http://www.getcloudify.org/spec/cloudify/3.4/types.yaml\r\n- https://onap.org:8443/repository/solutioning01-mte2-raw/type_files/docker/2.2.0/node-type.yaml\r\n- https://onap.org:8443/repository/solutioning01-mte2-raw/type_files/relationship/1.0.0/node-type.yaml\r\n- http://onap.org:8081/repository/solutioning01-mte2-raw/type_files/dmaap/dmaap_mr.yaml\r\ninputs:\r\n location_id:\r\n type: string\r\n service_id:\r\n type: string\r\n policy_id:\r\n type: string\r\nnode_templates:\r\n policy_0:\r\n type: dcae.nodes.policy\r\n properties:\r\n policy_id: \r\n get_input: policy_id\r\n cdap_host_host:\r\n type: dcae.nodes.StreamingAnalytics.SelectedCDAPInfrastructure\r\n properties:\r\n location_id:\r\n get_input: location_id\r\n scn_override: cdap_broker.solutioning-central.dcae.onap.org\r\n interfaces:\r\n cloudify.interfaces.lifecycle: {\r\n }\r\n tca_tca:\r\n type: dcae.nodes.MicroService.cdap\r\n properties:\r\n app_config:\r\n appDescription: DCAE Analytics Threshold Crossing Alert Application\r\n appName: dcae-tca\r\n tcaSubscriberOutputStreamName: TCASubscriberOutputStream\r\n tcaVESAlertsTableName: TCAVESAlertsTable\r\n tcaVESAlertsTableTTLSeconds: '1728000'\r\n tcaVESMessageStatusTableName: TCAVESMessageStatusTable\r\n tcaVESMessageStatusTableTTLSeconds: '86400'\r\n thresholdCalculatorFlowletInstances: '2'\r\n app_preferences:\r\n publisherContentType: application/json\r\n publisherHostName: mrlocal-mtnjftle01.onap.org\r\n publisherHostPort: '3905'\r\n publisherMaxBatchSize: '10'\r\n publisherMaxRecoveryQueueSize: '100000'\r\n publisherPollingInterval: '20000'\r\n publisherProtocol: https\r\n publisherTopicName: org.onap.dcae.dmaap.mtnje2.DcaeTestVESPub\r\n publisherUserName: m00502@tca.af.dcae.onap.org\r\n publisherUserPassword: Te5021abc\r\n subscriberConsumerGroup: OpenDCAE-c12\r\n subscriberConsumerId: c12\r\n subscriberContentType: application/json\r\n subscriberHostName: mrlocal-mtnjftle01.onap.org\r\n subscriberHostPort: '3905'\r\n subscriberMessageLimit: '-1'\r\n subscriberPollingInterval: '20000'\r\n subscriberProtocol: https\r\n subscriberTimeoutMS: '-1'\r\n subscriberTopicName: org.onap.dcae.dmaap.mtnje2.DcaeTestVESSub\r\n subscriberUserName: m00502@tca.af.dcae.onap.org\r\n subscriberUserPassword: Te5021abc\r\n tca_policy: null\r\n artifact_name: dcae-analytics-tca\r\n artifact_version: 1.0.0\r\n connections:\r\n streams_publishes: [\r\n ]\r\n streams_subscribes: [\r\n ]\r\n jar_url: http://somejar\r\n location_id:\r\n get_input: location_id\r\n namespace: cdap_tca_hi_lo\r\n programs:\r\n - program_id: TCAVESCollectorFlow\r\n program_type: flows\r\n - program_id: TCADMaaPMRSubscriberWorker\r\n program_type: workers\r\n - program_id: TCADMaaPMRPublisherWorker\r\n program_type: workers\r\n service_component_type: cdap_app_tca\r\n service_id:\r\n get_input: service_id\r\n streamname: TCASubscriberOutputStream\r\n relationships:\r\n - target: topic0\r\n type: dcae.relationships.subscribe_to_events\r\n - target: topic1\r\n type: dcae.relationships.publish_events\r\n - target: cdap_host_host\r\n type: dcae.relationships.component_contained_in\r\n - target: policy_0\r\n type: dcae.relationships.depends_on\r\n topic0:\r\n type: dcae.nodes.Topic\r\n properties:\r\n topic_name: ''\r\n topic1:\r\n type: dcae.nodes.Topic\r\n properties:\r\n topic_name: ''\r\n"]}]} \ No newline at end of file
+{"global":[{"name":"service","value":["tosca_definitions_version: cloudify_dsl_1_3
+imports:
+- http://www.getcloudify.org/spec/cloudify/3.4/types.yaml
+- https://onap.org:8443/repository/solutioning01-mte2-raw/type_files/docker/2.2.0/node-type.yaml
+- https://onap.org:8443/repository/solutioning01-mte2-raw/type_files/relationship/1.0.0/node-type.yaml
+- http://onap.org:8081/repository/solutioning01-mte2-raw/type_files/dmaap/dmaap_mr.yaml
+inputs:
+ location_id:
+ type: string
+ service_id:
+ type: string
+ policy_id:
+ type: string
+node_templates:
+ policy_0:
+ type: dcae.nodes.policy
+ properties:
+ policy_id:
+ get_input: policy_id
+ cdap_host_host:
+ type: dcae.nodes.StreamingAnalytics.SelectedCDAPInfrastructure
+ properties:
+ location_id:
+ get_input: location_id
+ scn_override: cdap_broker.solutioning-central.dcae.onap.org
+ interfaces:
+ cloudify.interfaces.lifecycle: {
+ }
+ tca_tca:
+ type: dcae.nodes.MicroService.cdap
+ properties:
+ app_config:
+ appDescription: DCAE Analytics Threshold Crossing Alert Application
+ appName: dcae-tca
+ tcaSubscriberOutputStreamName: TCASubscriberOutputStream
+ tcaVESAlertsTableName: TCAVESAlertsTable
+ tcaVESAlertsTableTTLSeconds: '1728000'
+ tcaVESMessageStatusTableName: TCAVESMessageStatusTable
+ tcaVESMessageStatusTableTTLSeconds: '86400'
+ thresholdCalculatorFlowletInstances: '2'
+ app_preferences:
+ publisherContentType: application/json
+ publisherHostName: mrlocal-mtnjftle01.onap.org
+ publisherHostPort: '3905'
+ publisherMaxBatchSize: '10'
+ publisherMaxRecoveryQueueSize: '100000'
+ publisherPollingInterval: '20000'
+ publisherProtocol: https
+ publisherTopicName: org.onap.dcae.dmaap.mtnje2.DcaeTestVESPub
+ publisherUserName: m00502@tca.af.dcae.onap.org
+ publisherUserPassword: Te5021abc
+ subscriberConsumerGroup: OpenDCAE-c12
+ subscriberConsumerId: c12
+ subscriberContentType: application/json
+ subscriberHostName: mrlocal-mtnjftle01.onap.org
+ subscriberHostPort: '3905'
+ subscriberMessageLimit: '-1'
+ subscriberPollingInterval: '20000'
+ subscriberProtocol: https
+ subscriberTimeoutMS: '-1'
+ subscriberTopicName: org.onap.dcae.dmaap.mtnje2.DcaeTestVESSub
+ subscriberUserName: m00502@tca.af.dcae.onap.org
+ subscriberUserPassword: Te5021abc
+ tca_policy: null
+ artifact_name: dcae-analytics-tca
+ artifact_version: 1.0.0
+ connections:
+ streams_publishes: [
+ ]
+ streams_subscribes: [
+ ]
+ jar_url: http://somejar
+ location_id:
+ get_input: location_id
+ namespace: cdap_tca_hi_lo
+ programs:
+ - program_id: TCAVESCollectorFlow
+ program_type: flows
+ - program_id: TCADMaaPMRSubscriberWorker
+ program_type: workers
+ - program_id: TCADMaaPMRPublisherWorker
+ program_type: workers
+ service_component_type: cdap_app_tca
+ service_id:
+ get_input: service_id
+ streamname: TCASubscriberOutputStream
+ relationships:
+ - target: topic0
+ type: dcae.relationships.subscribe_to_events
+ - target: topic1
+ type: dcae.relationships.publish_events
+ - target: cdap_host_host
+ type: dcae.relationships.component_contained_in
+ - target: policy_0
+ type: dcae.relationships.depends_on
+ topic0:
+ type: dcae.nodes.Topic
+ properties:
+ topic_name: ''
+ topic1:
+ type: dcae.nodes.Topic
+ properties:
+ topic_name: ''
+ "]}]} \ No newline at end of file