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);
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,
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) {
() -> new CoreException(new ToscaElementTypeNotFoundErrorBuilder(objectType).build()));
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
- throw new RuntimeException(e);
+ throw new SdcRuntimeException(e);
}
}
}
@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
// 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));
+ }
+
}