aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java3
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java24
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java40
3 files changed, 59 insertions, 8 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java
index 34f5a905fd..97d2a7f8ff 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaAnalyzerService.java
@@ -54,6 +54,9 @@ public interface ToscaAnalyzerService {
boolean isTypeOf(DefinitionOfDataType parameterDefinition, String dataType, ServiceTemplate serviceTemplate,
ToscaServiceModel toscaServiceModel);
+ boolean isTypeOf(CapabilityDefinition capabilityDefinition, String capabilityType, ServiceTemplate serviceTemplate,
+ ToscaServiceModel toscaServiceModel);
+
List<RequirementAssignment> getRequirements(NodeTemplate nodeTemplate, String requirementId);
Optional<NodeTemplate> getNodeTemplateById(ServiceTemplate serviceTemplate, String nodeTemplateId);
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
index 5e0f2f2e41..2d0d3fb59c 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImpl.java
@@ -38,13 +38,14 @@ import java.util.*;
public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
- private final String GET_NODE_TYPE_METHOD_NAME = "getNode_types";
- private final String GET_DERIVED_FROM_METHOD_NAME = "getDerived_from";
- private final String GET_TYPE_METHOD_NAME = "getType";
- private final String GET_DATA_TYPE_METHOD_NAME = "getData_types";
- private final String GET_INTERFACE_TYPE_METHOD_NAME = "getInterface_types";
- private final String TOSCA_DOT = "tosca.";
- private final String DOT_ROOT = ".Root";
+ private static final String GET_NODE_TYPE_METHOD_NAME = "getNode_types";
+ private static final String GET_DERIVED_FROM_METHOD_NAME = "getDerived_from";
+ private static final String GET_TYPE_METHOD_NAME = "getType";
+ private static final String GET_DATA_TYPE_METHOD_NAME = "getData_types";
+ private static final String GET_INTERFACE_TYPE_METHOD_NAME = "getInterface_types";
+ private static final String GET_CAPABILITY_TYPE_METHOD_NAME = "getCapability_types";
+ private static final String TOSCA_DOT = "tosca.";
+ private static final String DOT_ROOT = ".Root";
@Override
public List<Map<String, RequirementDefinition>> calculateExposedRequirements(List<Map<String, RequirementDefinition>> nodeTypeRequirementsDefinitionList,
@@ -925,6 +926,13 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
return isTypeOf(parameterDefinition, dataType, GET_DATA_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel);
}
+ @Override
+ public boolean isTypeOf(CapabilityDefinition capabilityDefinition, String capabilityType,
+ ServiceTemplate serviceTemplate, ToscaServiceModel toscaServiceModel) {
+ return isTypeOf(capabilityDefinition, capabilityType, GET_CAPABILITY_TYPE_METHOD_NAME, serviceTemplate, toscaServiceModel);
+ }
+
+
private <T> boolean isTypeOf(T object, String type, String getTypesMethodName, ServiceTemplate serviceTemplate,
ToscaServiceModel toscaServiceModel) {
if (object == null) {
@@ -944,7 +952,7 @@ public class ToscaAnalyzerServiceImpl implements ToscaAnalyzerService {
() -> new CoreException(new ToscaElementTypeNotFoundErrorBuilder(objectType).build()));
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
- throw new RuntimeException(e);
+ throw new SdcRuntimeException(e);
}
}
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
index d9e77e1f84..0f79ed05d6 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaAnalyzerServiceImplTest.java
@@ -44,6 +44,11 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class ToscaAnalyzerServiceImplTest {
+
+ public static final String CAPABILITY_TYPE_A = "capabilityTypeA";
+ public static final String CAPABILITY_TYPE_B = "capabilityTypeB";
+ public static final String TOSCA_CAPABILITIES_ROOT = "tosca.capabilities.Root";
+
/*
Dictionary:
SrvTmp: ServiceTemplate
@@ -874,4 +879,39 @@ public class ToscaAnalyzerServiceImplTest {
// not found at all should throw core exception
+
+ @Test
+ public void capabilityDefinitionIsTypeOfDirectTypeFound() {
+ CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
+ capabilityDefinition.setType(CAPABILITY_TYPE_A);
+ assertTrue(toscaAnalyzerService.isTypeOf(capabilityDefinition, CAPABILITY_TYPE_A, new ServiceTemplate(),
+ toscaServiceModelMock));
+ }
+
+ @Test
+ public void capabilityDefinitionIsTypeOfReturnNo() {
+ CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
+ capabilityDefinition.setType(CAPABILITY_TYPE_A);
+ ServiceTemplate serviceTemplate = new ServiceTemplate();
+ serviceTemplate.setCapability_types(new HashMap<>());
+ CapabilityType capabilityType = new CapabilityType();
+ capabilityType.setDerived_from(TOSCA_CAPABILITIES_ROOT);
+ serviceTemplate.getCapability_types().put(CAPABILITY_TYPE_A, capabilityType);
+ assertFalse(toscaAnalyzerService
+ .isTypeOf(capabilityDefinition, CAPABILITY_TYPE_B, serviceTemplate, toscaServiceModelMock));
+ }
+
+ @Test
+ public void capabilityDefinitionIsTypeOfInheritanceTypeFound() {
+ CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
+ capabilityDefinition.setType(CAPABILITY_TYPE_A);
+ ServiceTemplate serviceTemplate = new ServiceTemplate();
+ serviceTemplate.setCapability_types(new HashMap<>());
+ CapabilityType capabilityType = new CapabilityType();
+ capabilityType.setDerived_from(CAPABILITY_TYPE_B);
+ serviceTemplate.getCapability_types().put(CAPABILITY_TYPE_A, capabilityType);
+ assertTrue(toscaAnalyzerService
+ .isTypeOf(capabilityDefinition, CAPABILITY_TYPE_B, serviceTemplate, toscaServiceModelMock));
+ }
+
}