* @param serviceTemplate the service template containing data types to be checked
*/
public static void assertDataTypesExist(final JpaToscaServiceTemplate serviceTemplate) {
- String message = checkDataTypesExist(serviceTemplate);
- if (message != null) {
- LOGGER.warn(message);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, message);
- }
+ assertExist(serviceTemplate, checkDataTypesExist());
}
/**
* @param serviceTemplate the service template containing policy types to be checked
*/
public static void assertPolicyTypesExist(final JpaToscaServiceTemplate serviceTemplate) {
- String message = checkPolicyTypesExist(serviceTemplate);
- if (message != null) {
- LOGGER.warn(message);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, message);
- }
+ assertExist(serviceTemplate, checkPolicyTypesExist());
}
/**
* @param serviceTemplate the service template containing policy types to be checked
*/
public static void assertPoliciesExist(final JpaToscaServiceTemplate serviceTemplate) {
- String message = checkPoliciesExist(serviceTemplate);
- if (message != null) {
- LOGGER.warn(message);
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, message);
- }
+ assertExist(serviceTemplate, checkPoliciesExist());
}
/**
* @param serviceTemplate the service template containing data types to be checked
*/
public static boolean doDataTypesExist(final JpaToscaServiceTemplate serviceTemplate) {
- return checkDataTypesExist(serviceTemplate) == null;
+ return doExist(serviceTemplate, checkDataTypesExist());
}
/**
* @param serviceTemplate the service template containing policy types to be checked
*/
public static boolean doPolicyTypesExist(final JpaToscaServiceTemplate serviceTemplate) {
- return checkPolicyTypesExist(serviceTemplate) == null;
+ return doExist(serviceTemplate, checkPolicyTypesExist());
}
/**
* @param serviceTemplate the service template containing policy types to be checked
*/
public static boolean doPoliciesExist(final JpaToscaServiceTemplate serviceTemplate) {
- return checkPoliciesExist(serviceTemplate) == null;
+ return doExist(serviceTemplate, checkPoliciesExist());
}
/**
- * Check if data types have been specified correctly.
+ * Assert that something have been specified correctly.
*
- * @param serviceTemplate the service template containing data types to be checked
+ * @param serviceTemplate the service template containing policy types to be checked
*/
- public static String checkDataTypesExist(final JpaToscaServiceTemplate serviceTemplate) {
- if (serviceTemplate.getDataTypes() == null) {
- return "no data types specified on service template";
- }
-
- if (serviceTemplate.getDataTypes().getConceptMap().isEmpty()) {
- return "list of data types specified on service template is empty";
+ public static void assertExist(final JpaToscaServiceTemplate serviceTemplate,
+ final ToscaChecker<JpaToscaServiceTemplate> checkerFunction) {
+ String message = checkerFunction.check(serviceTemplate);
+ if (message != null) {
+ LOGGER.warn(message);
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, message);
}
-
- return null;
}
/**
- * Check if policy types have been specified correctly.
+ * Check that something have been specified correctly.
*
* @param serviceTemplate the service template containing policy types to be checked
*/
- public static String checkPolicyTypesExist(final JpaToscaServiceTemplate serviceTemplate) {
- if (serviceTemplate.getPolicyTypes() == null) {
- return "no policy types specified on service template";
- }
+ public static boolean doExist(final JpaToscaServiceTemplate serviceTemplate,
+ final ToscaChecker<JpaToscaServiceTemplate> checkerFunction) {
+ return checkerFunction.check(serviceTemplate) == null;
+ }
- if (serviceTemplate.getPolicyTypes().getConceptMap().isEmpty()) {
- return "list of policy types specified on service template is empty";
- }
+ /**
+ * Check if data types have been specified correctly.
+ */
+ public static ToscaChecker<JpaToscaServiceTemplate> checkDataTypesExist() {
+ return serviceTemplate -> {
+ if (serviceTemplate.getDataTypes() == null) {
+ return "no data types specified on service template";
+ }
+
+ if (serviceTemplate.getDataTypes().getConceptMap().isEmpty()) {
+ return "list of data types specified on service template is empty";
+ }
+
+ return null;
+ };
+ }
- return null;
+ /**
+ * Check if policy types have been specified correctly.
+ */
+ public static ToscaChecker<JpaToscaServiceTemplate> checkPolicyTypesExist() {
+ return serviceTemplate -> {
+ if (serviceTemplate.getPolicyTypes() == null) {
+ return "no policy types specified on service template";
+ }
+
+ if (serviceTemplate.getPolicyTypes().getConceptMap().isEmpty()) {
+ return "list of policy types specified on service template is empty";
+ }
+
+ return null;
+ };
}
/**
* Check if policies have been specified correctly.
- *
- * @param serviceTemplate the service template containing policy types to be checked
*/
- public static String checkPoliciesExist(final JpaToscaServiceTemplate serviceTemplate) {
- if (serviceTemplate.getTopologyTemplate() == null) {
- return "topology template not specified on service template";
- }
-
- if (serviceTemplate.getTopologyTemplate().getPolicies() == null) {
- return "no policies specified on topology template of service template";
- }
-
- if (serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().isEmpty()) {
- return "list of policies specified on topology template of service template is empty";
- }
+ public static ToscaChecker<JpaToscaServiceTemplate> checkPoliciesExist() {
+ return serviceTemplate -> {
+ if (serviceTemplate.getTopologyTemplate() == null) {
+ return "topology template not specified on service template";
+ }
+
+ if (serviceTemplate.getTopologyTemplate().getPolicies() == null) {
+ return "no policies specified on topology template of service template";
+ }
+
+ if (serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().isEmpty()) {
+ return "list of policies specified on topology template of service template is empty";
+ }
+
+ return null;
+ };
+ }
- return null;
+ @FunctionalInterface
+ interface ToscaChecker<T> {
+ String check(final T serviceTemplate);
}
}
assertFalse(ToscaUtils.doDataTypesExist(jpaToscaServiceTemplate));
assertEquals("no data types specified on service template",
- ToscaUtils.checkDataTypesExist(jpaToscaServiceTemplate));
+ ToscaUtils.checkDataTypesExist().check(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
}).hasMessage("no data types specified on service template");
assertFalse(ToscaUtils.doDataTypesExist(jpaToscaServiceTemplate));
assertEquals("list of data types specified on service template is empty",
- ToscaUtils.checkDataTypesExist(jpaToscaServiceTemplate));
+ ToscaUtils.checkDataTypesExist().check(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
}).hasMessage("list of data types specified on service template is empty");
jpaToscaServiceTemplate.getDataTypes().getConceptMap().put(new PfConceptKey(), null);
assertTrue(ToscaUtils.doDataTypesExist(jpaToscaServiceTemplate));
- assertEquals(null, ToscaUtils.checkDataTypesExist(jpaToscaServiceTemplate));
+ assertEquals(null, ToscaUtils.checkDataTypesExist().check(jpaToscaServiceTemplate));
assertThatCode(() -> {
ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
}).doesNotThrowAnyException();
assertFalse(ToscaUtils.doPolicyTypesExist(jpaToscaServiceTemplate));
assertEquals("no policy types specified on service template",
- ToscaUtils.checkPolicyTypesExist(jpaToscaServiceTemplate));
+ ToscaUtils.checkPolicyTypesExist().check(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
}).hasMessage("no policy types specified on service template");
assertFalse(ToscaUtils.doPolicyTypesExist(jpaToscaServiceTemplate));
assertEquals("list of policy types specified on service template is empty",
- ToscaUtils.checkPolicyTypesExist(jpaToscaServiceTemplate));
+ ToscaUtils.checkPolicyTypesExist().check(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
}).hasMessage("list of policy types specified on service template is empty");
jpaToscaServiceTemplate.getPolicyTypes().getConceptMap().put(new PfConceptKey(), null);
assertTrue(ToscaUtils.doPolicyTypesExist(jpaToscaServiceTemplate));
- assertEquals(null, ToscaUtils.checkPolicyTypesExist(jpaToscaServiceTemplate));
+ assertEquals(null, ToscaUtils.checkPolicyTypesExist().check(jpaToscaServiceTemplate));
assertThatCode(() -> {
ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
}).doesNotThrowAnyException();
assertFalse(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate));
assertEquals("topology template not specified on service template",
- ToscaUtils.checkPoliciesExist(jpaToscaServiceTemplate));
+ ToscaUtils.checkPoliciesExist().check(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
}).hasMessage("topology template not specified on service template");
assertFalse(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate));
assertEquals("no policies specified on topology template of service template",
- ToscaUtils.checkPoliciesExist(jpaToscaServiceTemplate));
+ ToscaUtils.checkPoliciesExist().check(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
}).hasMessage("no policies specified on topology template of service template");
assertFalse(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate));
assertEquals("list of policies specified on topology template of service template is empty",
- ToscaUtils.checkPoliciesExist(jpaToscaServiceTemplate));
+ ToscaUtils.checkPoliciesExist().check(jpaToscaServiceTemplate));
assertThatThrownBy(() -> {
ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
}).hasMessage("list of policies specified on topology template of service template is empty");
jpaToscaServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(new PfConceptKey(), null);
assertTrue(ToscaUtils.doPoliciesExist(jpaToscaServiceTemplate));
- assertEquals(null, ToscaUtils.checkPoliciesExist(jpaToscaServiceTemplate));
+ assertEquals(null, ToscaUtils.checkPoliciesExist().check(jpaToscaServiceTemplate));
assertThatCode(() -> {
ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
}).doesNotThrowAnyException();