aboutsummaryrefslogtreecommitdiffstats
path: root/blueprints-processor/plugin/assignment-provider/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'blueprints-processor/plugin/assignment-provider/src/test/java')
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java51
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java49
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java33
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java37
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java23
5 files changed, 104 insertions, 89 deletions
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java
index 4696fd281..75b7f2e28 100644
--- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java
+++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java
@@ -1,15 +1,18 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
- * 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
+ * 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.
+ * 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.
*/
package org.onap.ccsdk.config.assignment.service;
@@ -39,37 +42,37 @@ import com.att.eelf.configuration.EELFManager;
@RunWith(MockitoJUnitRunner.class)
public class ConfigPreviewServiceTest {
-
+
private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigPreviewServiceTest.class);
-
+
@Rule
public ExpectedException thrown = ExpectedException.none();
-
+
@Mock
private ConfigResourceService configResourceService;
-
+
@Mock
private ConfigRestAdaptorService configRestAdaptorService;
-
+
private ConfigModelService configModelService;
private ConfigGeneratorService configGeneratorService;
-
+
@SuppressWarnings("unchecked")
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
}
-
+
@Test
public void testGenerateTemplateResourceMash() throws Exception {
-
+
ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService);
-
+
ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment");
-
+
ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService,
"assignments/empty-dictionary.json");
-
+
ConfigResource configResourceQuery = new ConfigResource();
configResourceQuery.setServiceTemplateVersion("sample-serviceTemplateName");
configResourceQuery.setServiceTemplateVersion("1.0.0");
@@ -80,28 +83,28 @@ public class ConfigPreviewServiceTest {
String inputContent = FileUtils.readFileToString(
new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset());
configResourceQuery.setResourceData(inputContent);
-
+
ConfigResourceAssignmentTestUtils.injectGetConfigResourceMock(configResourceService, configResourceQuery);
-
+
configModelService = new ConfigModelServiceImpl(configRestAdaptorService);
configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService);
-
+
ConfigPreviewService configPreviewService =
new ConfigPreviewService(configResourceService, configModelService, configGeneratorService);
-
+
ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData();
resourceAssignmentData.setResourceId("123-resourceId");
resourceAssignmentData.setResourceType("sample-resourceType");
resourceAssignmentData.setServiceTemplateName("sample-serviceTemplateName");
resourceAssignmentData.setServiceTemplateVersion("1.0.0");
resourceAssignmentData.setActionName("sample-action");
-
+
resourceAssignmentData = configPreviewService.generateTemplateResourceMash(resourceAssignmentData);
-
+
Assert.assertNotNull("Failed to get GenerateTemplateResourceMash response.", resourceAssignmentData);
Assert.assertNotNull("Failed to get template mashed contents.",
resourceAssignmentData.getTemplatesMashedContents());
-
+
Assert.assertNotNull("Failed to get base-config template mashed contents.",
resourceAssignmentData.getTemplatesMashedContents().get("base-config-template"));
}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java
index f4ee969fb..ee1c076ae 100644
--- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java
+++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java
@@ -1,15 +1,18 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
- * 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
+ * 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.
+ * 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.
*/
package org.onap.ccsdk.config.assignment.service;
@@ -44,9 +47,9 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
public class ConfigResourceAssignmentTestUtils {
-
+
private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigResourceAssignmentTestUtils.class);
-
+
public static void injectTransactionLogSaveMock(ConfigResourceService configResourceService) throws Exception {
Mockito.doAnswer(new Answer<Void>() {
@Override
@@ -59,10 +62,10 @@ public class ConfigResourceAssignmentTestUtils {
}
}).when(configResourceService).save(any(TransactionLog.class));
}
-
+
public static void injectConfigModelMock(ConfigRestAdaptorService configRestAdaptorService,
String serviceTemplateName) throws Exception {
-
+
Mockito.doAnswer(new Answer<ConfigModel>() {
@Override
public org.onap.ccsdk.config.model.domain.ConfigModel answer(InvocationOnMock invocationOnMock)
@@ -70,23 +73,23 @@ public class ConfigResourceAssignmentTestUtils {
Object[] args = invocationOnMock.getArguments();
org.onap.ccsdk.config.model.domain.ConfigModel serviceArtifact = null;
if (args != null && args.length == 3) {
-
+
logger.info("Artifact info " + Arrays.asList(args));
String modelContent = IOUtils.toString(
ConfigResourceAssignmentTestUtils.class.getClassLoader().getResourceAsStream(
"service_templates/" + serviceTemplateName + "/" + serviceTemplateName + ".json"),
Charset.defaultCharset());
-
+
ConfigModelContent configModelContent = new ConfigModelContent();
configModelContent.setContent(modelContent);
configModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON);
-
+
List<ConfigModelContent> configModelContents = new ArrayList<>();
configModelContents.add(configModelContent);
-
+
String velocityDir = ConfigResourceAssignmentTestUtils.class.getClassLoader()
.getResource("service_templates/" + serviceTemplateName + "/velocity").getPath();
-
+
Collection<File> templateFiles =
FileUtils.listFiles(new File(velocityDir), new String[] {"vtl"}, true);
logger.info("Template Files info " + templateFiles);
@@ -98,22 +101,22 @@ public class ConfigResourceAssignmentTestUtils {
configModelTemplateContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE);
configModelContents.add(configModelTemplateContent);
}
-
+
serviceArtifact = new org.onap.ccsdk.config.model.domain.ConfigModel();
serviceArtifact.setArtifactName(String.valueOf(args[0]));
serviceArtifact.setArtifactVersion(String.valueOf(args[1]));
serviceArtifact.setPublished("Y");
serviceArtifact.setConfigModelContents(configModelContents);
}
-
+
return serviceArtifact;
}
}).when(configRestAdaptorService).getResource(anyString(), anyString(), Matchers.any(Class.class));
}
-
+
public static void injectResourceDictionaryMock(ConfigRestAdaptorService configRestAdaptorService,
String dictionaryFileName) throws Exception {
-
+
Mockito.doAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocationOnMock) throws Throwable {
@@ -130,7 +133,7 @@ public class ConfigResourceAssignmentTestUtils {
}).when(configRestAdaptorService).postResource(Matchers.any(), Matchers.any(), Matchers.any(),
Matchers.any(Class.class));
}
-
+
public static void injectConfigResourceSaveMock(ConfigResourceService configResourceService) throws Exception {
Mockito.doAnswer(new Answer<ConfigResource>() {
@Override
@@ -146,7 +149,7 @@ public class ConfigResourceAssignmentTestUtils {
}
}).when(configResourceService).saveConfigResource(any(ConfigResource.class));
}
-
+
public static void injectGetConfigResourceMock(ConfigResourceService configResourceService,
ConfigResource configResource) throws Exception {
Mockito.doAnswer(new Answer<List<ConfigResource>>() {
@@ -161,12 +164,12 @@ public class ConfigResourceAssignmentTestUtils {
}
}).when(configResourceService).getConfigResource(any(ConfigResource.class));
}
-
+
public static String getFileContent(String filePath) throws Exception {
return IOUtils.toString(ConfigResourceAssignmentTestUtils.class.getClassLoader().getResourceAsStream(filePath),
Charset.defaultCharset());
}
-
+
public static Map<String, ResourceDefinition> getMapfromJson(String content) {
try {
ObjectMapper mapper = new ObjectMapper();
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java
index e979ea3d1..3dc7da7eb 100644
--- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java
+++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java
@@ -1,15 +1,18 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
- * 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
+ * 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.
+ * 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.
*/
package org.onap.ccsdk.config.assignment.service;
@@ -31,16 +34,16 @@ import com.att.eelf.configuration.EELFManager;
import com.fasterxml.jackson.databind.JsonNode;
public class ResourceAssignmentGenerationTest {
-
+
private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentGenerationTest.class);
-
+
@Test
public void testResourceDataSetting() {
try {
logger.info(" **************** testResourceDataSetting *****************");
String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader()
.getResourceAsStream("assignments/alltype-empty-value-mapping.json"), Charset.defaultCharset());
-
+
List<ResourceAssignment> assignments =
TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class);
if (assignments != null) {
@@ -75,33 +78,33 @@ public class ResourceAssignmentGenerationTest {
}
String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments);
logger.trace("Generated Data " + generatedData);
-
+
Assert.assertNotNull("Failed to generate resource data", generatedData);
}
} catch (Exception e) {
e.printStackTrace();
}
}
-
+
@Test
public void testGenerateResourceData() {
try {
logger.info(" **************** testGenerateResourceData *****************");
String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader()
.getResourceAsStream("assignments/alltype-mapping.json"), Charset.defaultCharset());
-
+
List<ResourceAssignment> assignments =
TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class);
if (assignments != null) {
-
+
String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments);
logger.trace("Generated Data " + generatedData);
-
+
Assert.assertNotNull("Failed to generate resource data", generatedData);
}
} catch (Exception e) {
e.printStackTrace();
}
}
-
+
}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java
index 0bf74b4c0..d708404f5 100644
--- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java
+++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java
@@ -1,15 +1,18 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
- * 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
+ * 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.
+ * 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.
*/
package org.onap.ccsdk.config.assignment.service;
@@ -31,10 +34,10 @@ import com.att.eelf.configuration.EELFManager;
public class ResourceAssignmentValidation {
private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentValidation.class);
-
+
@Rule
public final ExpectedException exception = ExpectedException.none();
-
+
@Test
public void testValidateSuccess() {
try {
@@ -42,12 +45,12 @@ public class ResourceAssignmentValidation {
String resourceMapping = IOUtils.toString(
TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/success.json"),
Charset.defaultCharset());
-
+
List<ResourceAssignment> assignments =
TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class);
if (assignments != null) {
ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments);
-
+
boolean result = resourceAssignmentValidator.validateResourceAssignment();
Assert.assertTrue("Failed to Validate", result);
}
@@ -55,37 +58,37 @@ public class ResourceAssignmentValidation {
e.printStackTrace();
}
}
-
+
@Test(expected = ConfigModelException.class)
public void testValidateDuplicate() throws IOException, ConfigModelException {
logger.info(" **************** testValidateDuplicate *****************");
String resourceMapping = IOUtils.toString(
TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/duplicate.json"),
Charset.defaultCharset());
-
+
List<ResourceAssignment> assignments =
TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class);
if (assignments != null) {
ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments);
resourceAssignmentValidator.validateResourceAssignment();
}
-
+
}
-
+
@Test(expected = ConfigModelException.class)
public void testValidateCyclic() throws IOException, ConfigModelException {
logger.info(" **************** testValidateCyclic *****************");
String resourceMapping = IOUtils.toString(
TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/cyclic.json"),
Charset.defaultCharset());
-
+
List<ResourceAssignment> assignments =
TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class);
if (assignments != null) {
ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments);
-
+
resourceAssignmentValidator.validateResourceAssignment();
}
-
+
}
}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java
index 1b05e4b0e..e4b7f5dee 100644
--- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java
+++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java
@@ -1,15 +1,18 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
- * 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
+ * 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.
+ * 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.
*/
package org.onap.ccsdk.config.assignment.service;
@@ -28,7 +31,7 @@ import com.att.eelf.configuration.EELFManager;
public class TopologicalSortingTest {
private static EELFLogger logger = EELFManager.getInstance().getLogger(TopologicalSortingTest.class);
-
+
@Test
public void testBulkSequencingMapping() {
try {
@@ -36,7 +39,7 @@ public class TopologicalSortingTest {
String resourceMapping = IOUtils.toString(
TopologicalSortingTest.class.getClassLoader().getResourceAsStream("mapping/dependency.json"),
Charset.defaultCharset());
-
+
List<ResourceAssignment> assignments =
TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class);
if (assignments != null) {
@@ -44,7 +47,7 @@ public class TopologicalSortingTest {
ResourceAssignmentProcessor resourceAssignmentProcessor =
new ResourceAssignmentProcessor(assignments, ctx);
List<List<ResourceAssignment>> sequenceBatchResourceAssignment = resourceAssignmentProcessor.process();
-
+
Assert.assertNotNull("Failed to populate Sequence Bulk Mappings", sequenceBatchResourceAssignment);
Assert.assertNotEquals("Failed to populate Sequence Bulk Mappings size ",
(sequenceBatchResourceAssignment.size() > 0));
@@ -53,5 +56,5 @@ public class TopologicalSortingTest {
e.printStackTrace();
}
}
-
+
}