aboutsummaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-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
-rw-r--r--model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java3
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java5
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java12
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitter.java7
9 files changed, 55 insertions, 45 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());
}
}
diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java
index 9df11ae25..cd452cae1 100644
--- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java
+++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java
@@ -135,6 +135,9 @@ public final class AxContextAlbums extends AxConcept implements AxConceptGetter<
* @param parent the parent object of this object in the unmarshaler
*/
public void afterUnmarshal(final Unmarshaller unmarsaller, final Object parent) {
+ Assertions.argumentNotNull(unmarsaller, "unmarsaller should not be null");
+ Assertions.argumentNotNull(parent, "parent should not be null");
+
// The map must be navigable to allow name and version searching, unmarshaling returns a
// hash map
final NavigableMap<AxArtifactKey, AxContextAlbum> navigableAlbums = new TreeMap<>();
diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java
index 822a803bf..aa57be552 100644
--- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java
@@ -143,8 +143,9 @@ public class PolicyLogicReader implements AxLogicReader {
// Check if the logic was found
if (logicString == null || logicString.length() == 0) {
- LOGGER.warn("logic not found for logic \"" + fullLogicFilePath + "\"");
- throw new PolicyRuntimeException("logic not found for logic \"" + fullLogicFilePath + "\"");
+ String errorMessage = "logic not found for logic \"" + fullLogicFilePath + "\"";
+ LOGGER.warn(errorMessage);
+ throw new PolicyRuntimeException(errorMessage);
}
// Return the right trimmed logic string
diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java
index 091f20462..28133cefa 100644
--- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java
@@ -80,8 +80,9 @@ public final class PolicyModelMerger {
final AxValidationResult leftValidationResult = new AxValidationResult();
leftPolicyModel.validate(leftValidationResult);
if (!leftValidationResult.isValid()) {
- LOGGER.warn("left model is invalid: " + leftValidationResult.toString());
- throw new ApexModelException("left model is invalid: " + leftValidationResult.toString());
+ String message = "left model is invalid: " + leftValidationResult.toString();
+ LOGGER.warn(message);
+ throw new ApexModelException(message);
}
}
@@ -90,13 +91,14 @@ public final class PolicyModelMerger {
final AxValidationResult rightValidationResult = new AxValidationResult();
rightPolicyModel.validate(rightValidationResult);
if (!rightValidationResult.isValid()) {
- LOGGER.warn("right model is invalid: " + rightValidationResult.toString());
- throw new ApexModelException("right model is invalid: " + rightValidationResult.toString());
+ String message = "right model is invalid: " + rightValidationResult.toString();
+ LOGGER.warn(message);
+ throw new ApexModelException(message);
}
}
// The new policy model uses the favoured copy side as its base
- final AxPolicyModel mergedPolicyModel = (AxPolicyModel) (useLeftOnMatches ? new AxPolicyModel(leftPolicyModel)
+ final AxPolicyModel mergedPolicyModel = (useLeftOnMatches ? new AxPolicyModel(leftPolicyModel)
: new AxPolicyModel(rightPolicyModel));
// The Compared to policy model is the unfavoured side
diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitter.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitter.java
index 586d0706e..7ecb8fb0f 100644
--- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitter.java
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitter.java
@@ -77,8 +77,9 @@ public final class PolicyModelSplitter {
final AxValidationResult sourceValidationResult = new AxValidationResult();
sourcePolicyModel.validate(sourceValidationResult);
if (!sourceValidationResult.isValid()) {
- LOGGER.warn("source model is invalid: " + sourceValidationResult.toString());
- throw new ApexModelException("source model is invalid: " + sourceValidationResult.toString());
+ String message = "source model is invalid: " + sourceValidationResult.toString();
+ LOGGER.warn(message);
+ throw new ApexModelException(message);
}
}
@@ -103,7 +104,7 @@ public final class PolicyModelSplitter {
for (final AxArtifactKey subPolicyKey : subPolicies) {
final AxPolicy subPolicy = sourcePolicyModel.getPolicies().getPolicyMap().get(subPolicyKey);
if (subPolicy == null) {
- LOGGER.warn("source sub policy not found: " + subPolicyKey);
+ LOGGER.warn("source sub policy not found: {}", subPolicyKey);
continue;
}