summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2020-02-02 19:47:39 +0000
committerYuli Shlosberg <ys9693@att.com>2020-02-25 08:27:11 +0000
commit0c274e9356fc77c53340828b0ec18869dad71631 (patch)
tree667e9f83ab3bb4bb56f261244b88ebb90bd0b497 /catalog-be/src/test/java/org
parentc5ef980bb5c9af65e1f190c0352329134d6a7459 (diff)
Support import of custom node type name
Issue-ID: SDC-2760 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Change-Id: I3645c737ba367a3576d58afb581c8118eb0f6011
Diffstat (limited to 'catalog-be/src/test/java/org')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java60
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java16
2 files changed, 48 insertions, 28 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index da3955e560..69b3f1d660 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -20,7 +20,31 @@
package org.openecomp.sdc.be.components.impl;
+import static org.assertj.core.api.Java6Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.servlet.ServletContext;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Assert;
import org.junit.Before;
@@ -113,30 +137,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
-import javax.servlet.ServletContext;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static org.assertj.core.api.Java6Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
-
public class ResourceBusinessLogicTest {
ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be");
@@ -1585,6 +1585,18 @@ public class ResourceBusinessLogicTest {
}
@Test
+ public void testIfNodeTypeNameHasValidPrefix() {
+ final List<String> definedNodeTypeNamespaceList = ConfigurationManager.getConfigurationManager()
+ .getConfiguration().getDefinedResourceNamespace();
+
+ definedNodeTypeNamespaceList.parallelStream().forEach(validNodeTypePrefix -> {
+ final String nodeName = validNodeTypePrefix + "." + "abc";
+ final Optional<String> result = bl.validateNodeTypeNamePrefix(nodeName, definedNodeTypeNamespaceList);
+ assertTrue(result.isPresent());
+ });
+ }
+
+ @Test
public void updateNestedResource_typeIsNew() throws IOException {
Resource resourceToUpdate = createResourceObject(false);
String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "." + "abc";
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java
index 284cc3fb47..af28aca26b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java
@@ -42,6 +42,7 @@ import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.SpringConfig;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
@@ -56,8 +57,10 @@ import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.ConfigurationSource;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.common.util.GeneralUtility;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.context.ApplicationContext;
@@ -107,6 +110,9 @@ public class ResourceServletTest extends JerseyTest {
private static final ResponseFormat noContentResponseFormat = new ResponseFormat(HttpStatus.SC_NO_CONTENT);
private static final ResponseFormat notFoundResponseFormat = new ResponseFormat(HttpStatus.SC_NOT_FOUND);
private static final ResponseFormat badRequestResponseFormat = new ResponseFormat(HttpStatus.SC_BAD_REQUEST);
+ private static final ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration
+ .getChangeListener(), "src/test/resources/config/catalog-be");
+ private static final ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
private static final String RESOURCE_NAME = "resourceName";
private static final String VERSION = "version";
private static final String RESOURCE_ID = "resourceId";
@@ -162,11 +168,12 @@ public class ResourceServletTest extends JerseyTest {
@Test
public void testHappyScenarioTest() {
- when(componentUtils.getResponseFormat(ActionStatus.OK)) .thenReturn(createdResponseFormat);
+ when(componentUtils.getResponseFormat(ActionStatus.OK)).thenReturn(createdResponseFormat);
UploadResourceInfo validJson = buildValidJson();
setMD5OnRequest(true, validJson);
- Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON).post(Entity.json(gson.toJson(validJson)), Response.class);
+ Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON)
+ .post(Entity.json(gson.toJson(validJson)), Response.class);
Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(Mockito.any(ActionStatus.class));
Mockito.verify(componentUtils, Mockito.times(1)).getResponseFormat(ActionStatus.OK);
assertEquals(HttpStatus.SC_CREATED, response.getStatus());
@@ -250,11 +257,12 @@ public class ResourceServletTest extends JerseyTest {
public void testNonValidNameSpaceInPayloadFail() {
UploadResourceInfo mdJson = buildValidJson();
- String payload = "tosca_definitions_version: tosca_simple_yaml_1_0_0\r\n" + "node_types: \r\n" + " org.openecomp.resourceX.importResource4test:\r\n" + " derived_from: tosca.nodes.Root\r\n" + " description: update update";
+ String payload = "tosca_definitions_version: tosca_simple_yaml_1_0_0\r\n" + "node_types: \r\n"
+ + " org.openecomp.resourceX.importResource4test:\r\n" + " derived_from: tosca.nodes.Root\r\n"
+ + " description: update update";
encodeAndSetPayload(mdJson, payload);
runAndVerifyActionStatusError(mdJson, ActionStatus.INVALID_RESOURCE_NAMESPACE);
-
}
@Test