summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-03-21 20:48:30 +0000
committerChristophe Closset <christophe.closset@intl.att.com>2021-03-24 06:59:24 +0000
commita6ae7294ecd336d7e88f915710b08e2658eaee00 (patch)
tree5353e6fd9ae41888f0f1cb5eb542ad90c261342e /catalog-be/src/test
parent1ccd74fb7723bc41424ca93902d68d351ce55462 (diff)
Enable selection of base type of service
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-3506 Change-Id: Iaba39955fac9056cb0d0f1eccd223c05dfb9c5b4 Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java7
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java20
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java37
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java3
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java11
5 files changed, 76 insertions, 2 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java b/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java
index f9605c1aed..5d05e65886 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/ElementOperationMock.java
@@ -26,6 +26,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.BaseType;
import org.openecomp.sdc.be.model.Category;
import org.openecomp.sdc.be.model.PropertyScope;
import org.openecomp.sdc.be.model.Tag;
@@ -280,4 +281,10 @@ public class ElementOperationMock implements IElementOperation {
return null;
}
+ @Override
+ public List<BaseType> getBaseTypes(String categoryName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java
index c87bb2481d..36eee96848 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java
@@ -39,6 +39,7 @@ import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.BaseType;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.Product;
import org.openecomp.sdc.be.model.Resource;
@@ -304,4 +305,23 @@ public class ElementBusinessLogicTest extends BaseBusinessLogicMock {
Assert.assertTrue(response.isRight());
Assert.assertEquals((Integer) 9, response.right().value().getStatus());
}
+
+ @Test
+ public void testGetBaseTypes_givenValidUserAndComponentType_thenReturnsSuccessful() {
+
+ List<BaseType> baseTypes = new ArrayList<>();
+ baseTypes.add(new BaseType("org.openecomp.type"));
+ String categoryName = "CAT01";
+
+ when(userValidations.validateUserExistsActionStatus(eq(user.getUserId()))).thenReturn(ActionStatus.OK);
+ when(elementDao.getBaseTypes(categoryName)).thenReturn(baseTypes);
+ Assert.assertTrue(elementBusinessLogic.getBaseTypes(categoryName, user.getUserId())
+ .isLeft());
+ }
+
+ @Test
+ public void testGetBaseTypes_givenUserValidationFails_thenReturnsException() {
+ when(userValidations.validateUserExistsActionStatus(eq(user.getUserId()))).thenReturn(ActionStatus.RESTRICTED_OPERATION);
+ Assert.assertTrue(elementBusinessLogic.getBaseTypes("CAT01", user.getUserId()).isRight());
+ }
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java
index cd8c0c57ab..4d2c3621d9 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ElementServletTest.java
@@ -68,6 +68,7 @@ import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.BaseType;
import org.openecomp.sdc.be.model.PropertyScope;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Tag;
@@ -1104,4 +1105,40 @@ class ElementServletTest extends JerseyTest {
})
.property("contextConfig", context);
}
+
+ @Test
+ void getBaseTypesTest() {
+ String path = "/v1/category/services/CAT1/baseTypes";
+ Either<List<BaseType>, ActionStatus> baseTypesEither = Either.left(new ArrayList<>());
+ when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId()))
+ .thenReturn(baseTypesEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_OK);
+ }
+
+ @Test
+ void getBaseTypesNoBaseTypesFoundTest() {
+ String path = "/v1/category/services/CAT1/baseTypes";
+ Either<List<BaseType>, ActionStatus> baseTypesEither = Either.right(ActionStatus.NO_CONTENT);
+
+ when(elementBusinessLogic.getBaseTypes("CAT1", designerUser.getUserId()))
+ .thenReturn(baseTypesEither);
+
+ Response response = target()
+ .path(path)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(Constants.USER_ID_HEADER, designerUser.getUserId())
+ .get();
+
+ assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_NO_CONTENT);
+ }
+
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
index 4aa967be47..ce7a10eb28 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/CsarUtilsTest.java
@@ -582,10 +582,9 @@ public class CsarUtilsTest extends BeConfDependentTest {
try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(out)) {
- Either<ZipOutputStream, ResponseFormat> output = Deencapsulation.invoke(testSubject, "writeComponentInterface", new Resource(), zip, fileName, false);
+ List<Triple<String, String, Component>> output = Deencapsulation.invoke(testSubject, "writeComponentInterface", new Resource(), zip, fileName, false);
assertNotNull(output);
- assertTrue(output.isLeft());
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
index bca8827736..1b38a245c4 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java
@@ -521,6 +521,17 @@ public class ToscaExportHandlerTest extends BeConfDependentTest {
when(toscaOperationFacade.getToscaFullElement(any(String.class)))
.thenReturn(Either.left(component));
+
+ Resource baseType = getNewResource();
+ Map<String, ArtifactDefinition> baseTypeToscaArtifacts = new HashMap<>();
+ ArtifactDefinition baseTypeArtifact = new ArtifactDefinition();
+ baseTypeArtifact.setArtifactName("typeA");
+ baseTypeToscaArtifacts.put("assettoscatemplate", baseTypeArtifact);
+ baseType.setToscaArtifacts(baseTypeToscaArtifacts);
+
+ component.setDerivedFromGenericType("org.typeA");
+ component.setDerivedFromGenericVersion("1.0");
+ when(toscaOperationFacade.getByToscaResourceNameAndVersion("org.typeA", "1.0")).thenReturn(Either.left(baseType));
// default test
result = Deencapsulation.invoke(testSubject, "fillImports", component, toscaTemplate);