aboutsummaryrefslogtreecommitdiffstats
path: root/model/basic-model/src/main
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2018-12-15 09:47:58 +0000
committerliamfallon <liam.fallon@est.tech>2018-12-15 09:48:04 +0000
commit8e8f3458646ec97d058d7322917f56021de2dc7f (patch)
treeb549a654cba7d87249751f85cf6b23d3b2b4cc48 /model/basic-model/src/main
parent4b01ae1ca8bc592fbbbc4d5408d6c645487811dd (diff)
Fix sonar test renaming issues
Renaming tests introduced Sonar issues: - Tests where coverage was <80% flagged as they are new code - Support test classes with names ending in "Test" flagged becasue they did not contain test cases Issue-ID: POLICY-1263 Change-Id: I17a4b27b2952a4978fab1c76579a013478b60ae1 Signed-off-by: liamfallon <liam.fallon@est.tech>
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);
+ }
+ }
}