summaryrefslogtreecommitdiffstats
path: root/model/basic-model/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'model/basic-model/src/main')
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java4
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java8
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java44
3 files changed, 29 insertions, 27 deletions
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java
index e76d00e12..f340f73d4 100644
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java
+++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java
@@ -260,7 +260,7 @@ public class ApexModelReader<C extends AxConcept> {
}
catch (final Exception e) {
LOGGER.warn("JAXB error setting marshaller for JSON Input", e);
- throw new ApexModelException("JAXB error setting marshaller for JSON Input", e);
+ throw new ApexModelException("JAXB error setting unmarshaller for JSON input", e);
}
}
else if (Pattern.compile(XML_INPUT_TYPE_REGEXP).matcher(apexConceptString).find()) {
@@ -270,7 +270,7 @@ public class ApexModelReader<C extends AxConcept> {
}
catch (final Exception e) {
LOGGER.warn("JAXB error setting marshaller for XML Input", e);
- throw new ApexModelException("JAXB error setting marshaller for XML Input", e);
+ throw new ApexModelException("JAXB error setting unmarshaller for XML input", e);
}
}
else {
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java
index 6cc542270..eded9fdec 100644
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java
+++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java
@@ -217,8 +217,8 @@ public class ApexModelWriter<C extends AxConcept> {
cdataFieldSet.toString().replaceAll("[\\[\\]\\,]", " "));
domTransformer.transform(new DOMSource(document), new StreamResult(apexConceptWriter));
} catch (JAXBException | TransformerException | ParserConfigurationException e) {
- LOGGER.warn("Unable to marshal Apex concept XML", e);
- throw new ApexModelException("Unable to marshal Apex concept XML", e);
+ LOGGER.warn("Unable to marshal Apex concept to XML", e);
+ throw new ApexModelException("Unable to marshal Apex concept to XML", e);
}
LOGGER.debug("wrote Apex concept XML");
}
@@ -254,8 +254,8 @@ public class ApexModelWriter<C extends AxConcept> {
try {
marshaller.marshal(concept, apexConceptWriter);
} catch (final JAXBException e) {
- LOGGER.warn("Unable to marshal Apex concept JSON", e);
- throw new ApexModelException("Unable to marshal Apex concept JSON", e);
+ LOGGER.warn("Unable to marshal Apex concept to JSON", e);
+ throw new ApexModelException("Unable to marshal Apex concept to JSON", e);
}
LOGGER.debug("wrote Apex concept JSON");
}
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java
index 24c682de4..6bab169a8 100644
--- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java
+++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java
@@ -108,10 +108,7 @@ public class TestApexModel<M extends AxModel> {
try {
final URL apexModelUrl = ResourceUtils.getLocalFile(xmlFile.getAbsolutePath());
final M fileModel = modelReader.read(apexModelUrl.openStream());
- if (!model.equals(fileModel)) {
- LOGGER.warn(TEST_MODEL_UNEQUAL_STR + xmlFile.getAbsolutePath());
- throw new ApexException(TEST_MODEL_UNEQUAL_STR + xmlFile.getAbsolutePath());
- }
+ checkModelEquality(model, fileModel, TEST_MODEL_UNEQUAL_STR + xmlFile.getAbsolutePath());
} catch (final Exception e) {
LOGGER.warn(ERROR_PROCESSING_FILE + xmlFile.getAbsolutePath(), e);
throw new ApexException(ERROR_PROCESSING_FILE + xmlFile.getAbsolutePath(), e);
@@ -126,10 +123,8 @@ public class TestApexModel<M extends AxModel> {
modelWriter.write(model, baOutputStream);
final ByteArrayInputStream baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray());
final M byteArrayModel = modelReader.read(baInputStream);
- if (!model.equals(byteArrayModel)) {
- LOGGER.warn("test model does not equal XML marshalled and unmarshalled model");
- throw new ApexException("test model does not equal XML marshalled and unmarshalled model");
- }
+
+ checkModelEquality(model, byteArrayModel, "test model does not equal XML marshalled and unmarshalled model");
LOGGER.debug("ran testApexModelWriteReadXML");
}
@@ -161,11 +156,7 @@ public class TestApexModel<M extends AxModel> {
try {
final URL apexModelUrl = ResourceUtils.getLocalFile(jsonFile.getAbsolutePath());
final M fileModel = modelReader.read(apexModelUrl.openStream());
- if (!model.equals(fileModel)) {
- LOGGER.warn(TEST_MODEL_UNEQUAL_STR + jsonFile.getAbsolutePath());
- throw new ApexException(
- TEST_MODEL_UNEQUAL_STR + jsonFile.getAbsolutePath());
- }
+ checkModelEquality(model, fileModel, TEST_MODEL_UNEQUAL_STR + jsonFile.getAbsolutePath());
} catch (final Exception e) {
LOGGER.warn(ERROR_PROCESSING_FILE + jsonFile.getAbsolutePath(), e);
throw new ApexException(ERROR_PROCESSING_FILE + jsonFile.getAbsolutePath(), e);
@@ -178,10 +169,8 @@ public class TestApexModel<M extends AxModel> {
modelWriter.write(model, baOutputStream);
final ByteArrayInputStream baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray());
final M byteArrayModel = modelReader.read(baInputStream);
- if (!model.equals(byteArrayModel)) {
- LOGGER.warn("test model does not equal JSON marshalled and unmarshalled model");
- throw new ApexException("test model does not equal JSON marshalled and unmarshalled model");
- }
+
+ checkModelEquality(model, byteArrayModel, "test model does not equal JSON marshalled and unmarshalled model");
LOGGER.debug("ran testApexModelWriteReadJSON");
}
@@ -204,10 +193,7 @@ public class TestApexModel<M extends AxModel> {
final M dbJpaModel = apexDao.get(rootModelClass, model.getKey());
apexDao.close();
- if (!model.equals(dbJpaModel)) {
- LOGGER.warn("test model does not equal model written and read using generic JPA");
- throw new ApexException("test model does not equal model written and read using generic JPA");
- }
+ checkModelEquality(model, dbJpaModel, "test model does not equal model written and read using generic JPA");
LOGGER.debug("ran testApexModelWriteReadJPA");
}
@@ -331,4 +317,20 @@ public class TestApexModel<M extends AxModel> {
LOGGER.debug("ran testApexModelVaidateInvalidModel");
return result;
}
+
+ /**
+ * Check if two models are equal.
+ *
+ * @param leftModel the left model
+ * @param rightModel the right model
+ * @param errorMessage the error message to output on inequality
+ * @throws ApexException the exception to throw on inequality
+ */
+ public void checkModelEquality(final M leftModel, final M rightModel, final String errorMessage)
+ throws ApexException {
+ if (!leftModel.equals(rightModel)) {
+ LOGGER.warn(errorMessage);
+ throw new ApexException(errorMessage);
+ }
+ }
}