aboutsummaryrefslogtreecommitdiffstats
path: root/model/basic-model/src
diff options
context:
space:
mode:
Diffstat (limited to 'model/basic-model/src')
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java6
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java13
-rw-r--r--model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java25
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestBasicModelTest.java4
-rw-r--r--model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelWriter.java25
5 files changed, 38 insertions, 35 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 ce2c9fc56..e76d00e12 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
@@ -211,13 +211,13 @@ public class ApexModelReader<C extends AxConcept> {
if (validateFlag) {
// Validate the configuration file
final AxValidationResult validationResult = apexConcept.validate(new AxValidationResult());
- LOGGER.debug(validationResult.toString());
if (validationResult.isValid()) {
return apexConcept;
}
else {
- LOGGER.error("Apex concept validation failed" + validationResult.toString());
- throw new ApexModelException("Apex concept validation failed" + validationResult.toString());
+ String message = "Apex concept validation failed" + validationResult.toString();
+ LOGGER.error(message);
+ throw new ApexModelException(message);
}
}
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 977a8e7c6..6cc542270 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
@@ -86,7 +86,8 @@ public class ApexModelWriter<C extends AxConcept> {
System.setProperty("javax.xml.bind.context.factory", "org.eclipse.persistence.jaxb.JAXBContextFactory");
try {
- final JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[] {rootConceptClass}, null);
+ final JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[]
+ { rootConceptClass }, null);
// Set up the unmarshaller to carry out validation
marshaller = jaxbContext.createMarshaller();
@@ -173,10 +174,11 @@ public class ApexModelWriter<C extends AxConcept> {
if (validateFlag) {
// Validate the concept first
final AxValidationResult validationResult = concept.validate(new AxValidationResult());
- LOGGER.debug(validationResult.toString());
if (!validationResult.isValid()) {
- LOGGER.warn(validationResult.toString());
- throw new ApexModelException("Apex concept xml (" + concept.getKey().getId() + ") validation failed");
+ String message = "Apex concept xml (" + concept.getKey().getId() + ") validation failed: "
+ + validationResult.toString();
+ LOGGER.warn(message);
+ throw new ApexModelException(message);
}
}
@@ -212,7 +214,7 @@ public class ApexModelWriter<C extends AxConcept> {
// Convert the cDataFieldSet into a space delimited string
domTransformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS,
- cdataFieldSet.toString().replaceAll("[\\[\\]\\,]", " "));
+ 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);
@@ -221,7 +223,6 @@ public class ApexModelWriter<C extends AxConcept> {
LOGGER.debug("wrote Apex concept XML");
}
-
private Transformer getTransformer() throws TransformerConfigurationException {
// Transform the DOM to the output stream
final TransformerFactory transformerFactory = TransformerFactory.newInstance();
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 81b3373e1..24c682de4 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
@@ -225,8 +225,9 @@ public class TestApexModel<M extends AxModel> {
final AxValidationResult result = model.validate(new AxValidationResult());
if (!result.isValid()) {
- LOGGER.warn(MODEL_IS_INVALID + result.toString());
- throw new ApexException(MODEL_IS_INVALID + result.toString());
+ String message = MODEL_IS_INVALID + result.toString();
+ LOGGER.warn(message);
+ throw new ApexException(message);
}
LOGGER.debug("ran testApexModelVaid");
@@ -246,8 +247,9 @@ public class TestApexModel<M extends AxModel> {
final AxValidationResult result = model.validate(new AxValidationResult());
if (result.isValid()) {
- LOGGER.warn("model should not be valid " + result.toString());
- throw new ApexException("should not be valid " + result.toString());
+ String message = "model should not be valid " + result.toString();
+ LOGGER.warn(message);
+ throw new ApexException(message);
}
LOGGER.debug("ran testApexModelVaidateMalstructured");
@@ -267,8 +269,9 @@ public class TestApexModel<M extends AxModel> {
final AxValidationResult result = model.validate(new AxValidationResult());
if (!result.isValid()) {
- LOGGER.warn(MODEL_IS_INVALID + result.toString());
- throw new ApexException(MODEL_IS_INVALID + result.toString());
+ String message = MODEL_IS_INVALID + result.toString();
+ LOGGER.warn(message);
+ throw new ApexException(message);
}
if (!result.getValidationResult().equals(AxValidationResult.ValidationResult.OBSERVATION)) {
@@ -293,8 +296,9 @@ public class TestApexModel<M extends AxModel> {
final AxValidationResult result = model.validate(new AxValidationResult());
if (!result.isValid()) {
- LOGGER.warn(MODEL_IS_INVALID + result.toString());
- throw new ApexException(MODEL_IS_INVALID + result.toString());
+ String message = MODEL_IS_INVALID + result.toString();
+ LOGGER.warn(message);
+ throw new ApexException(message);
}
if (!result.getValidationResult().equals(AxValidationResult.ValidationResult.WARNING)) {
@@ -319,8 +323,9 @@ public class TestApexModel<M extends AxModel> {
final AxValidationResult result = model.validate(new AxValidationResult());
if (result.isValid()) {
- LOGGER.warn("model should not be valid " + result.toString());
- throw new ApexException("should not be valid " + result.toString());
+ String message = "model should not be valid " + result.toString();
+ LOGGER.warn(message);
+ throw new ApexException(message);
}
LOGGER.debug("ran testApexModelVaidateInvalidModel");
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestBasicModelTest.java
index 9ced9d84b..905f9e16b 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestBasicModelTest.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestBasicModelTest.java
@@ -73,13 +73,13 @@ public class TestBasicModelTest {
testApexModel.testApexModelVaidateInvalidModel();
fail("Test should throw an exception");
} catch (final Exception e) {
- assertEquals("should not be valid ***validation of model successful***", e.getMessage());
+ assertEquals("model should not be valid ***validation of model successful***", e.getMessage());
}
try {
testApexModel.testApexModelVaidateMalstructured();
fail("Test should throw an exception");
} catch (final Exception e) {
- assertEquals("should not be valid ***validation of model successful***", e.getMessage());
+ assertEquals("model should not be valid ***validation of model successful***", e.getMessage());
}
}
diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelWriter.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelWriter.java
index 648194a52..57c30db11 100644
--- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelWriter.java
+++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelWriter.java
@@ -38,57 +38,54 @@ public class TestModelWriter {
@Test
public void testModelWriter() throws IOException, ApexException {
ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
-
+
modelWriter.setValidateFlag(true);
assertTrue(modelWriter.getValidateFlag());
assertEquals(0, modelWriter.getCDataFieldSet().size());
-
+
assertFalse(modelWriter.isJsonOutput());
modelWriter.setJsonOutput(true);
assertTrue(modelWriter.isJsonOutput());
modelWriter.setJsonOutput(false);
assertFalse(modelWriter.isJsonOutput());
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
AxModel model = new TestApexBasicModelCreator().getModel();
-
+
modelWriter.write(model, baos);
modelWriter.setJsonOutput(true);
modelWriter.write(model, baos);
modelWriter.setJsonOutput(false);
-
+
modelWriter.setValidateFlag(false);
modelWriter.write(model, baos);
modelWriter.setJsonOutput(true);
modelWriter.write(model, baos);
modelWriter.setJsonOutput(false);
-
+
modelWriter.setValidateFlag(true);
model.getKeyInformation().getKeyInfoMap().clear();
try {
modelWriter.write(model, baos);
fail("Test should throw an exception here");
- }
- catch (Exception e) {
- assertEquals("Apex concept xml (BasicModel:0.0.1) validation failed", e.getMessage());
+ } catch (Exception e) {
+ assertEquals("Apex concept xml (BasicModel:0.0.1) validation failed", e.getMessage().substring(0, 53));
}
model.getKeyInformation().generateKeyInfo(model);
try {
modelWriter.write(null, baos);
fail("Test should throw an exception here");
- }
- catch (Exception e) {
+ } catch (Exception e) {
assertEquals("concept may not be null", e.getMessage());
}
-
+
try {
ByteArrayOutputStream nullBaos = null;
modelWriter.write(model, nullBaos);
fail("Test should throw an exception here");
- }
- catch (Exception e) {
+ } catch (Exception e) {
assertEquals("concept stream may not be null", e.getMessage());
}
}