From 8e8f3458646ec97d058d7322917f56021de2dc7f Mon Sep 17 00:00:00 2001 From: liamfallon Date: Sat, 15 Dec 2018 09:47:58 +0000 Subject: 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 --- .../model/basicmodel/handling/ApexModelReader.java | 4 +- .../model/basicmodel/handling/ApexModelWriter.java | 8 ++-- .../apex/model/basicmodel/test/TestApexModel.java | 44 +++++++++++----------- 3 files changed, 29 insertions(+), 27 deletions(-) (limited to 'model/basic-model/src/main/java/org/onap') 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 { } 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 { } 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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); + } + } } -- cgit 1.2.3-korg