aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
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/test
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/test')
-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
4 files changed, 181 insertions, 33 deletions
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 b64e6a0d0..40dffcd6b 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 34805d87a..c842068d9 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 55666e5c8..37f9bd7eb 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 3b7e2df9a..0ee712204 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