From 1418e7fcc3bba8980e1877c6576983583877ec1e Mon Sep 17 00:00:00 2001 From: lapentafd Date: Wed, 2 Jun 2021 12:02:46 +0100 Subject: Fix Sonar Issues in apex-pdp-model Changes made into model/basic-model Renamed test classes to match the others Issue-ID: POLICY-3093 Change-Id: I7a0d6046ead42a9165aaf96b89511dd8d064d109 Signed-off-by: lapentafd --- .../model/basicmodel/concepts/ApexException.java | 5 +- .../model/basicmodel/concepts/AxArtifactKey.java | 14 +- .../basicmodel/concepts/AxConceptGetterImpl.java | 6 +- .../apex/model/basicmodel/concepts/AxKeyInfo.java | 12 +- .../basicmodel/concepts/AxKeyInformation.java | 10 +- .../basicmodel/handling/ApexModelFileWriter.java | 13 +- .../model/basicmodel/handling/ApexModelReader.java | 15 +- .../model/basicmodel/handling/ApexModelSaver.java | 6 +- .../basicmodel/handling/ApexModelStringWriter.java | 16 +- .../model/basicmodel/handling/ApexModelWriter.java | 16 +- .../basicmodel/handling/ApexSchemaGenerator.java | 12 +- .../apex/model/basicmodel/test/TestApexModel.java | 53 ++-- .../model/basicmodel/concepts/AxKeyInfoTest.java | 17 +- .../SupportApexBasicModelConceptsTest.java | 294 +++++++++++++++++++++ .../SupportApexBasicModelConceptsTester.java | 279 ------------------- .../handling/SupportApexBasicModelTest.java | 131 +++++++++ .../handling/SupportApexBasicModelTester.java | 131 --------- .../basicmodel/handling/SupportBasicModelTest.java | 115 ++++++++ .../handling/SupportBasicModelTester.java | 115 -------- .../handling/SupportConceptGetterTest.java | 217 +++++++++++++++ .../handling/SupportConceptGetterTester.java | 200 -------------- 21 files changed, 856 insertions(+), 821 deletions(-) create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTester.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTester.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTester.java diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java index 97920c3b5..2eca2f783 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -88,10 +89,10 @@ public class ApexException extends Exception { * @return cascaded message string */ public static String buildCascadedMessage(Throwable throwable) { - final StringBuilder builder = new StringBuilder(); + final var builder = new StringBuilder(); builder.append(throwable.getMessage()); - for (Throwable t = throwable; t != null; t = t.getCause()) { + for (var t = throwable; t != null; t = t.getCause()) { builder.append("\ncaused by: "); builder.append(t.getMessage()); } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java index 86c89c35e..6e0a3cf4d 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -235,7 +235,7 @@ public class AxArtifactKey extends AxKey { } final AxArtifactKey otherArtifactKey = (AxArtifactKey) otherKey; - final Compatibility compatibility = this.getCompatibility(otherArtifactKey); + final var compatibility = this.getCompatibility(otherArtifactKey); return !(compatibility == Compatibility.DIFFERENT || compatibility == Compatibility.MAJOR); } @@ -245,14 +245,14 @@ public class AxArtifactKey extends AxKey { */ @Override public AxValidationResult validate(final AxValidationResult result) { - final String nameValidationErrorMessage = Assertions.getStringParameterValidationMessage(NAME_TOKEN, name, + final var nameValidationErrorMessage = Assertions.getStringParameterValidationMessage(NAME_TOKEN, name, NAME_REGEXP); if (nameValidationErrorMessage != null) { result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID, "name invalid-" + nameValidationErrorMessage)); } - final String versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN, + final var versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN, version, VERSION_REGEXP); if (versionValidationErrorMessage != null) { result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID, @@ -276,7 +276,7 @@ public class AxArtifactKey extends AxKey { */ @Override public String toString() { - final StringBuilder builder = new StringBuilder(); + final var builder = new StringBuilder(); builder.append(this.getClass().getSimpleName()); builder.append(":("); builder.append("name="); @@ -309,8 +309,8 @@ public class AxArtifactKey extends AxKey { */ @Override public int hashCode() { - final int prime = 31; - int result = 1; + final var prime = 31; + var result = 1; result = prime * result + name.hashCode(); result = prime * result + version.hashCode(); return result; diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java index 175cded08..9c907da9c 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,7 +62,7 @@ public class AxConceptGetterImpl implements AxConceptGetter { Assertions.argumentNotNull(conceptKeyName, "conceptKeyName may not be null"); // The very fist key that could have this name - final AxArtifactKey lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1"); + final var lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1"); // Check if we found a key for our name AxArtifactKey foundKey = conceptMap.ceilingKey(lowestArtifactKey); @@ -117,7 +117,7 @@ public class AxConceptGetterImpl implements AxConceptGetter { } // The very fist key that could have this name - final AxArtifactKey lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1"); + final var lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1"); if (conceptKeyVersion != null) { lowestArtifactKey.setVersion(conceptKeyVersion); } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java index 4b84a403a..7e92faddf 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -233,7 +233,7 @@ public class AxKeyInfo extends AxConcept { */ @Override public String toString() { - final StringBuilder builder = new StringBuilder(); + final var builder = new StringBuilder(); builder.append(this.getClass().getSimpleName()); builder.append(":("); builder.append("artifactId="); @@ -269,8 +269,8 @@ public class AxKeyInfo extends AxConcept { */ @Override public int hashCode() { - final int prime = 31; - int result = 1; + final var prime = 31; + var result = 1; result = prime * result + key.hashCode(); result = prime * result + uuid.hashCode(); result = prime * result + description.hashCode(); @@ -336,14 +336,14 @@ public class AxKeyInfo extends AxConcept { * @return the uuid */ public static UUID generateReproducibleUuid(final String seed) { - Random random = sharedRandom; + var random = sharedRandom; if (!StringUtils.isEmpty(seed)) { /* * This is not used for encryption/security, thus disabling sonar. */ random = new Random(seed.hashCode()); // NOSONAR } - final byte[] array = new byte[UUID_BYTE_LENGTH_16]; + final var array = new byte[UUID_BYTE_LENGTH_16]; random.nextBytes(array); return UUID.nameUUIDFromBytes(array); } diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java index 2619d2eea..fe597bb08 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -151,7 +151,7 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter { - final AxKeyInfo keyInfo = new AxKeyInfo(artifactKey); + final var keyInfo = new AxKeyInfo(artifactKey); // generate a reproducible UUID keyInfo.setUuid(AxKeyInfo.generateReproducibleUuid(keyInfo.getId() + keyInfo.getDescription())); return keyInfo; @@ -290,7 +290,7 @@ public class AxKeyInformation extends AxConcept implements AxConceptGetter { */ private void writeModelFile(final M model, final ApexModelWriter modelWriter, final String modelFileName) throws ApexException { - final File modelFile = new File(modelFileName); + final var modelFile = new File(modelFileName); if (!modelFile.getParentFile().exists() && !modelFile.getParentFile().mkdirs()) { LOGGER.warn("could not create directory " + modelFile.getParentFile()); throw new ApexException("could not create directory " + modelFile.getParentFile()); } - try { - final FileOutputStream fileOutputStream = new FileOutputStream(modelFile); + try (final var fileOutputStream = new FileOutputStream(modelFile)) { modelWriter.write(model, fileOutputStream); - fileOutputStream.close(); } catch (final Exception e) { LOGGER.warn("error processing file " + modelFile.getAbsolutePath(), e); throw new ApexException("error processing file " + modelFile.getAbsolutePath(), e); 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 db7360e75..7e136f6b3 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 @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,15 +27,12 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringReader; -import java.net.URL; import java.util.regex.Pattern; import javax.xml.XMLConstants; -import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import org.eclipse.persistence.jaxb.JAXBContextFactory; import org.eclipse.persistence.jaxb.MarshallerProperties; @@ -86,7 +83,7 @@ public class ApexModelReader { this.rootConceptClass = rootConceptClass; try { - final JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[] {rootConceptClass}, null); + final var jaxbContext = JAXBContextFactory.createContext(new Class[] {rootConceptClass}, null); // Set up the unmarshaller to carry out validation unmarshaller = jaxbContext.createUnmarshaller(); @@ -120,8 +117,8 @@ public class ApexModelReader { if (schemaFileName != null) { try { // Set the concept schema - final URL schemaUrl = ResourceUtils.getUrlResource(schemaFileName); - final Schema apexConceptSchema = + final var schemaUrl = ResourceUtils.getUrlResource(schemaFileName); + final var apexConceptSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaUrl); unmarshaller.setSchema(apexConceptSchema); } catch (final Exception e) { @@ -182,7 +179,7 @@ public class ApexModelReader { LOGGER.entry("reading Apex concept from string . . ."); - final String apexString = apexConceptString.trim(); + final var apexString = apexConceptString.trim(); // Set the type of input for this stream setInputType(apexString); @@ -193,7 +190,7 @@ public class ApexModelReader { // Use JAXB to read and verify the Apex concept XML file try { // Load the configuration file - final StreamSource source = new StreamSource(new StringReader(apexString)); + final var source = new StreamSource(new StringReader(apexString)); final JAXBElement rootElement = unmarshaller.unmarshal(source, rootConceptClass); apexConcept = rootElement.getValue(); } catch (final JAXBException e) { diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java index 8217badbc..dea32df49 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,7 +72,7 @@ public class ApexModelSaver { LOGGER.debug("running apexModelWriteXML . . ."); // Write the file to disk - final File xmlFile = new File(writePath + File.separatorChar + model.getKey().getName() + ".xml"); + final var xmlFile = new File(writePath + File.separatorChar + model.getKey().getName() + ".xml"); new ApexModelFileWriter(true).apexModelWriteXmlFile(model, rootModelClass, xmlFile.getPath()); LOGGER.debug("ran apexModelWriteXML"); @@ -87,7 +87,7 @@ public class ApexModelSaver { LOGGER.debug("running apexModelWriteJSON . . ."); // Write the file to disk - final File jsonFile = new File(writePath + File.separatorChar + model.getKey().getName() + ".json"); + final var jsonFile = new File(writePath + File.separatorChar + model.getKey().getName() + ".json"); new ApexModelFileWriter(true).apexModelWriteJsonFile(model, rootModelClass, jsonFile.getPath()); LOGGER.debug("ran apexModelWriteJSON"); diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java index f1725d8e3..de6a72ffd 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,17 +86,14 @@ public class ApexModelStringWriter { conceptWriter.getCDataFieldSet().add("logic"); conceptWriter.getCDataFieldSet().add("uiLogic"); - final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream(); - try { + try (var baOutputStream = new ByteArrayOutputStream()) { conceptWriter.write(concept, baOutputStream); - baOutputStream.close(); + return baOutputStream.toString(); } catch (final Exception e) { LOGGER.warn("error writing XML string", e); throw new ApexException("error writing XML string", e); } - LOGGER.debug("ran writeXMLString"); - return baOutputStream.toString(); } /** @@ -114,17 +111,14 @@ public class ApexModelStringWriter { conceptWriter.setJsonOutput(true); conceptWriter.setValidateFlag(validateFlag); - final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream(); - try { + try (var baOutputStream = new ByteArrayOutputStream()) { conceptWriter.write(concept, baOutputStream); - baOutputStream.close(); + return baOutputStream.toString(); } catch (final Exception e) { LOGGER.warn("error writing JSON string", e); throw new ApexException("error writing JSON string", e); } - LOGGER.debug("ran writeJSONString"); - return baOutputStream.toString(); } /** 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 0763492fc..9e43f76bd 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 @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import java.io.Writer; import java.util.Set; import java.util.TreeSet; import javax.xml.XMLConstants; -import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.parsers.DocumentBuilderFactory; @@ -47,7 +46,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; import org.onap.policy.common.utils.validation.Assertions; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; -import org.w3c.dom.Document; /** * This class writes an Apex concept to an XML file or JSON file from a Java Apex Concept. @@ -87,7 +85,7 @@ public class ApexModelWriter { System.setProperty("javax.xml.bind.context.factory", "org.eclipse.persistence.jaxb.JAXBContextFactory"); try { - final JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[]{rootConceptClass}, null); + final var jaxbContext = JAXBContextFactory.createContext(new Class[]{rootConceptClass}, null); // Set up the unmarshaller to carry out validation marshaller = jaxbContext.createMarshaller(); @@ -201,17 +199,17 @@ public class ApexModelWriter { try { // Write the concept into a DOM document, then transform to add CDATA fields and pretty // print, then write out the result - final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); + final var docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); docBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); docBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - final Document document = docBuilderFactory.newDocumentBuilder().newDocument(); + final var document = docBuilderFactory.newDocumentBuilder().newDocument(); // Marshal the concept into the empty document. marshaller.marshal(concept, document); - final Transformer domTransformer = getTransformer(); + final var domTransformer = getTransformer(); // Convert the cDataFieldSet into a space delimited string domTransformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, @@ -225,11 +223,11 @@ public class ApexModelWriter { private Transformer getTransformer() throws TransformerConfigurationException { // Transform the DOM to the output stream - final TransformerFactory transformerFactory = TransformerFactory.newInstance(); + final var transformerFactory = TransformerFactory.newInstance(); transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); - final Transformer domTransformer = transformerFactory.newTransformer(); + final var domTransformer = transformerFactory.newTransformer(); // Pretty print try { diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java index 8617f2c81..d5f34785b 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGenerator.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ public class ApexSchemaGenerator { if (args.length == 1) { printStream = System.out; } else if (args.length == 2) { - final File schemaFile = new File(args[1]); + final var schemaFile = new File(args[1]); try { schemaFile.getParentFile().mkdirs(); @@ -94,7 +94,7 @@ public class ApexSchemaGenerator { return null; } - final ApexSchemaOutputResolver sor = new ApexSchemaOutputResolver(); + final var sor = new ApexSchemaOutputResolver(); try { jaxbContext.generateSchema(sor); } catch (final IOException e) { @@ -102,7 +102,7 @@ public class ApexSchemaGenerator { return null; } - String schemaString = sor.getSchema(); + var schemaString = sor.getSchema(); schemaString = fixForUnqualifiedBug(schemaString); return schemaString; @@ -118,7 +118,7 @@ public class ApexSchemaGenerator { */ private String fixForUnqualifiedBug(final String schemaString) { // Fix the "entry" element - String newSchemaString = schemaString.replace( + var newSchemaString = schemaString.replace( "", ""); @@ -144,7 +144,7 @@ public class ApexSchemaGenerator { */ @Override public Result createOutput(final String namespaceUri, final String suggestedFileName) throws IOException { - final StreamResult result = new StreamResult(stringWriter); + final var result = new StreamResult(stringWriter); result.setSystemId(suggestedFileName); return result; } 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 bf63e6db7..36ce4e438 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 @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -23,11 +24,9 @@ package org.onap.policy.apex.model.basicmodel.test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; -import java.net.URL; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxModel; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.dao.ApexDao; import org.onap.policy.apex.model.basicmodel.dao.ApexDaoFactory; import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; import org.onap.policy.apex.model.basicmodel.handling.ApexModelFileWriter; @@ -87,7 +86,7 @@ public class TestApexModel { public final void testApexModelWriteReadXml() throws ApexException { LOGGER.debug("running testApexModelWriteReadXML . . ."); - final M model = modelCreator.getModel(); + final var model = modelCreator.getModel(); // Write the file to disk File xmlFile; @@ -105,8 +104,8 @@ public class TestApexModel { final ApexModelReader modelReader = new ApexModelReader<>(rootModelClass); try { - final URL apexModelUrl = ResourceUtils.getLocalFile(xmlFile.getAbsolutePath()); - final M fileModel = modelReader.read(apexModelUrl.openStream()); + final var apexModelUrl = ResourceUtils.getLocalFile(xmlFile.getAbsolutePath()); + final var fileModel = modelReader.read(apexModelUrl.openStream()); checkModelEquality(model, fileModel, TEST_MODEL_UNEQUAL_STR + xmlFile.getAbsolutePath()); } catch (final Exception e) { LOGGER.warn(ERROR_PROCESSING_FILE + xmlFile.getAbsolutePath(), e); @@ -118,10 +117,10 @@ public class TestApexModel { modelWriter.getCDataFieldSet().add("logic"); modelWriter.getCDataFieldSet().add("uiLogic"); - final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream(); + final var baOutputStream = new ByteArrayOutputStream(); modelWriter.write(model, baOutputStream); - final ByteArrayInputStream baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray()); - final M byteArrayModel = modelReader.read(baInputStream); + final var baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray()); + final var byteArrayModel = modelReader.read(baInputStream); checkModelEquality(model, byteArrayModel, "test model does not equal XML marshalled and unmarshalled model"); @@ -136,7 +135,7 @@ public class TestApexModel { public final void testApexModelWriteReadJson() throws ApexException { LOGGER.debug("running testApexModelWriteReadJSON . . ."); - final M model = modelCreator.getModel(); + final var model = modelCreator.getModel(); // Write the file to disk File jsonFile; @@ -153,8 +152,8 @@ public class TestApexModel { final ApexModelReader modelReader = new ApexModelReader<>(rootModelClass); try { - final URL apexModelUrl = ResourceUtils.getLocalFile(jsonFile.getAbsolutePath()); - final M fileModel = modelReader.read(apexModelUrl.openStream()); + final var apexModelUrl = ResourceUtils.getLocalFile(jsonFile.getAbsolutePath()); + final var fileModel = modelReader.read(apexModelUrl.openStream()); checkModelEquality(model, fileModel, TEST_MODEL_UNEQUAL_STR + jsonFile.getAbsolutePath()); } catch (final Exception e) { LOGGER.warn(ERROR_PROCESSING_FILE + jsonFile.getAbsolutePath(), e); @@ -164,11 +163,11 @@ public class TestApexModel { final ApexModelWriter modelWriter = new ApexModelWriter<>(rootModelClass); modelWriter.setJsonOutput(true); - final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream(); + final var baOutputStream = new ByteArrayOutputStream(); modelWriter.write(model, baOutputStream); - final ByteArrayInputStream baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray()); - final M byteArrayModel = modelReader.read(baInputStream); - + final var baInputStream = new ByteArrayInputStream(baOutputStream.toByteArray()); + final var byteArrayModel = modelReader.read(baInputStream); + checkModelEquality(model, byteArrayModel, "test model does not equal JSON marshalled and unmarshalled model"); LOGGER.debug("ran testApexModelWriteReadJSON"); @@ -183,13 +182,13 @@ public class TestApexModel { public final void testApexModelWriteReadJpa(final DaoParameters daoParameters) throws ApexException { LOGGER.debug("running testApexModelWriteReadJPA . . ."); - final M model = modelCreator.getModel(); + final var model = modelCreator.getModel(); - final ApexDao apexDao = new ApexDaoFactory().createApexDao(daoParameters); + final var apexDao = new ApexDaoFactory().createApexDao(daoParameters); apexDao.init(daoParameters); apexDao.create(model); - final M dbJpaModel = apexDao.get(rootModelClass, model.getKey()); + final var dbJpaModel = apexDao.get(rootModelClass, model.getKey()); apexDao.close(); checkModelEquality(model, dbJpaModel, "test model does not equal model written and read using generic JPA"); @@ -206,7 +205,7 @@ public class TestApexModel { public final AxValidationResult testApexModelValid() throws ApexException { LOGGER.debug("running testApexModelVaid . . ."); - final M model = modelCreator.getModel(); + final var model = modelCreator.getModel(); final AxValidationResult result = model.validate(new AxValidationResult()); if (!result.isValid()) { @@ -228,7 +227,7 @@ public class TestApexModel { public final AxValidationResult testApexModelVaidateMalstructured() throws ApexException { LOGGER.debug("running testApexModelVaidateMalstructured . . ."); - final M model = modelCreator.getMalstructuredModel(); + final var model = modelCreator.getMalstructuredModel(); final AxValidationResult result = model.validate(new AxValidationResult()); if (result.isValid()) { @@ -250,7 +249,7 @@ public class TestApexModel { public final AxValidationResult testApexModelVaidateObservation() throws ApexException { LOGGER.debug("running testApexModelVaidateObservation . . ."); - final M model = modelCreator.getObservationModel(); + final var model = modelCreator.getObservationModel(); final AxValidationResult result = model.validate(new AxValidationResult()); if (!result.isValid()) { @@ -277,7 +276,7 @@ public class TestApexModel { public final AxValidationResult testApexModelVaidateWarning() throws ApexException { LOGGER.debug("running testApexModelVaidateWarning . . ."); - final M model = modelCreator.getWarningModel(); + final var model = modelCreator.getWarningModel(); final AxValidationResult result = model.validate(new AxValidationResult()); if (!result.isValid()) { @@ -304,7 +303,7 @@ public class TestApexModel { public final AxValidationResult testApexModelVaidateInvalidModel() throws ApexException { LOGGER.debug("running testApexModelVaidateInvalidModel . . ."); - final M model = modelCreator.getInvalidModel(); + final var model = modelCreator.getInvalidModel(); final AxValidationResult result = model.validate(new AxValidationResult()); if (result.isValid()) { @@ -319,7 +318,7 @@ public class TestApexModel { /** * 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 diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java index 5a57ba3a6..ff7adcd26 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix-2020 Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,6 +70,21 @@ public class AxKeyInfoTest { assertEquals(0, testKeyInfo.compareTo(testKeyInfo)); assertEquals(0, testKeyInfo.compareTo(clonedReferenceKey)); + + + } + + @Test + public void testAxKeyValidation() { + AxKeyInfo testKeyInfo = new AxKeyInfo(); + + AxArtifactKey key = new AxArtifactKey("key", "0.0.1"); + testKeyInfo.setKey(key); + + UUID uuid = UUID.randomUUID(); + testKeyInfo.setUuid(uuid); + testKeyInfo.setDescription("Key Description"); + assertNotEquals(0, testKeyInfo.compareTo(null)); assertNotEquals(0, testKeyInfo.compareTo(new AxArtifactKey())); assertNotEquals(0, testKeyInfo.compareTo(new AxKeyInfo(new AxArtifactKey()))); diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java new file mode 100644 index 000000000..905a27f38 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java @@ -0,0 +1,294 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.Set; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyUse; +import org.onap.policy.apex.model.basicmodel.concepts.AxModel; +import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; + +public class SupportApexBasicModelConceptsTest { + TestApexModel testApexModel; + + @Before + public void setup() throws Exception { + testApexModel = new TestApexModel(AxModel.class, new DummyApexBasicModelCreator()); + } + + @Test + public void testModelConcepts() { + final AxModel model = testApexModel.getModel(); + assertNotNull(model); + model.clean(); + assertNotNull(model); + + AxValidationResult result = new AxValidationResult(); + result = model.validate(result); + assertEquals(ValidationResult.WARNING, result.getValidationResult()); + + model.register(); + assertEquals(model.getKeyInformation(), ModelService.getModel(AxKeyInformation.class)); + + final AxModel clonedModel = new AxModel(model); + assertTrue(clonedModel.toString().startsWith("AxModel:(key=AxArtifactKey:(name=BasicModel")); + + assertNotEquals(0, model.hashCode()); + + // disabling sonar because this code tests the equals() method + assertEquals(model, model); // NOSONAR + assertEquals(model, clonedModel); + assertNotNull(model); + assertNotEquals(model, (Object) "Hello"); + clonedModel.getKey().setVersion("0.0.2"); + assertNotEquals(model, clonedModel); + clonedModel.getKey().setVersion("0.0.1"); + + assertEquals(0, model.compareTo(model)); + assertNotEquals(0, model.compareTo(null)); + assertNotEquals(0, model.compareTo(new AxReferenceKey())); + assertEquals(0, model.compareTo(clonedModel)); + clonedModel.getKey().setVersion("0.0.2"); + assertNotEquals(0, model.compareTo(clonedModel)); + clonedModel.getKey().setVersion("0.0.1"); + + assertNotNull(model.getKeys()); + + model.getKeyInformation().generateKeyInfo(model); + assertNotNull(model.getKeyInformation()); + + } + + @Test + public void testKeyInformation() { + + final AxModel model = testApexModel.getModel(); + final AxKeyInformation keyI = model.getKeyInformation(); + final AxKeyInformation clonedKeyI = new AxKeyInformation(keyI); + + assertNotNull(keyI); + assertNotEquals(keyI, (Object) new AxArtifactKey()); + assertEquals(keyI, clonedKeyI); + + clonedKeyI.setKey(new AxArtifactKey()); + assertNotEquals(keyI, clonedKeyI); + clonedKeyI.setKey(keyI.getKey()); + + assertEquals(0, keyI.compareTo(keyI)); + assertEquals(0, keyI.compareTo(clonedKeyI)); + assertNotEquals(0, keyI.compareTo(null)); + assertNotEquals(0, keyI.compareTo(new AxArtifactKey())); + + clonedKeyI.setKey(new AxArtifactKey()); + assertNotEquals(0, keyI.compareTo(clonedKeyI)); + clonedKeyI.setKey(keyI.getKey()); + assertEquals(0, keyI.compareTo(clonedKeyI)); + + clonedKeyI.getKeyInfoMap().clear(); + assertNotEquals(0, keyI.compareTo(clonedKeyI)); + + AxKeyInfo keyInfo = keyI.get("BasicModel"); + assertNotNull(keyInfo); + + keyInfo = keyI.get(new AxArtifactKey("BasicModel", "0.0.1")); + assertNotNull(keyInfo); + + Set keyInfoSet = keyI.getAll("BasicModel"); + assertNotNull(keyInfoSet); + + keyInfoSet = keyI.getAll("BasicModel", "0..0.1"); + assertNotNull(keyInfoSet); + + List keys = model.getKeys(); + assertNotEquals(0, keys.size()); + + keys = keyI.getKeys(); + assertNotEquals(0, keys.size()); + + model.getKeyInformation().generateKeyInfo(model); + assertNotNull(model.getKeyInformation()); + model.getKeyInformation().getKeyInfoMap().clear(); + model.getKeyInformation().generateKeyInfo(model); + assertNotNull(model.getKeyInformation()); + } + + @Test + public void testClonedKey() { + final AxModel model = testApexModel.getModel(); + final AxKeyInformation keyI = model.getKeyInformation(); + final AxKeyInformation clonedKeyI = new AxKeyInformation(keyI); + AxValidationResult result = new AxValidationResult(); + + clonedKeyI.setKey(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + clonedKeyI.setKey(keyI.getKey()); + + clonedKeyI.getKeyInfoMap().clear(); + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + clonedKeyI.generateKeyInfo(model); + + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + clonedKeyI.getKeyInfoMap().put(AxArtifactKey.getNullKey(), null); + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + clonedKeyI.getKeyInfoMap().clear(); + clonedKeyI.generateKeyInfo(model); + + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + clonedKeyI.getKeyInfoMap().put(new AxArtifactKey("SomeKey", "0.0.1"), null); + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + clonedKeyI.getKeyInfoMap().clear(); + clonedKeyI.generateKeyInfo(model); + + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + final AxKeyInfo mk = clonedKeyI.get(new AxArtifactKey("BasicModel", "0.0.1")); + assertNotNull(mk); + mk.setKey(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + clonedKeyI.getKeyInfoMap().clear(); + clonedKeyI.generateKeyInfo(model); + + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + final AxModel clonedModel = new AxModel(model); + clonedModel.setKey(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = clonedModel.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + clonedModel.setKey(model.getKey()); + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + } + + @Test + public void testModelConceptsWithReferences() { + final DummyAxModelWithReferences mwr = new DummyApexBasicModelCreator().getModelWithReferences(); + assertNotNull(mwr); + mwr.getKeyInformation().getKeyInfoMap().clear(); + mwr.getKeyInformation().generateKeyInfo(mwr); + + AxValidationResult result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + // Duplicate key error + mwr.addKey(mwr.getKey()); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(mwr.getKey()); + + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + // Null Reference Key + mwr.addKey(AxReferenceKey.getNullKey()); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(AxReferenceKey.getNullKey()); + + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + // Duplicate Reference Key + final AxReferenceKey rKey = new AxReferenceKey(mwr.getKey(), "LocalName"); + mwr.addKey(rKey); + mwr.addKey(rKey); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(rKey); + mwr.removeKey(rKey); + + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + // Key Use is legal + final AxKeyUse keyU = new AxKeyUse(mwr.getKey()); + mwr.addKey(keyU); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + mwr.removeKey(keyU); + + // Key Use on bad artifact key + final AxKeyUse keyBadUsage = new AxKeyUse(new AxArtifactKey("SomeKey", "0.0.1")); + mwr.addKey(keyBadUsage); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(keyBadUsage); + + // Key Use on bad reference key + final AxKeyUse keyBadReferenceUsage = new AxKeyUse(new AxReferenceKey("SomeKey", "0.0.1", "Local")); + mwr.addKey(keyBadReferenceUsage); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(keyBadReferenceUsage); + + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTester.java deleted file mode 100644 index 8ce072c68..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTester.java +++ /dev/null @@ -1,279 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyUse; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; - -public class SupportApexBasicModelConceptsTester { - TestApexModel testApexModel; - - @Before - public void setup() throws Exception { - testApexModel = new TestApexModel(AxModel.class, new DummyApexBasicModelCreator()); - } - - @Test - public void testModelConcepts() { - final AxModel model = testApexModel.getModel(); - assertNotNull(model); - model.clean(); - assertNotNull(model); - - AxValidationResult result = new AxValidationResult(); - result = model.validate(result); - assertEquals(ValidationResult.WARNING, result.getValidationResult()); - - model.register(); - assertEquals(model.getKeyInformation(), ModelService.getModel(AxKeyInformation.class)); - - final AxModel clonedModel = new AxModel(model); - assertTrue(clonedModel.toString().startsWith("AxModel:(key=AxArtifactKey:(name=BasicModel")); - - assertNotEquals(0, model.hashCode()); - - // disabling sonar because this code tests the equals() method - assertEquals(model, model); // NOSONAR - assertEquals(model, clonedModel); - assertNotNull(model); - assertNotEquals(model, (Object) "Hello"); - clonedModel.getKey().setVersion("0.0.2"); - assertNotEquals(model, clonedModel); - clonedModel.getKey().setVersion("0.0.1"); - - assertEquals(0, model.compareTo(model)); - assertNotEquals(0, model.compareTo(null)); - assertNotEquals(0, model.compareTo(new AxReferenceKey())); - assertEquals(0, model.compareTo(clonedModel)); - clonedModel.getKey().setVersion("0.0.2"); - assertNotEquals(0, model.compareTo(clonedModel)); - clonedModel.getKey().setVersion("0.0.1"); - - assertNotNull(model.getKeys()); - - model.getKeyInformation().generateKeyInfo(model); - assertNotNull(model.getKeyInformation()); - - final AxKeyInformation keyI = model.getKeyInformation(); - final AxKeyInformation clonedKeyI = new AxKeyInformation(keyI); - - assertNotNull(keyI); - assertNotEquals(keyI, (Object) new AxArtifactKey()); - assertEquals(keyI, clonedKeyI); - - clonedKeyI.setKey(new AxArtifactKey()); - assertNotEquals(keyI, clonedKeyI); - clonedKeyI.setKey(keyI.getKey()); - - assertEquals(0, keyI.compareTo(keyI)); - assertEquals(0, keyI.compareTo(clonedKeyI)); - assertNotEquals(0, keyI.compareTo(null)); - assertNotEquals(0, keyI.compareTo(new AxArtifactKey())); - - clonedKeyI.setKey(new AxArtifactKey()); - assertNotEquals(0, keyI.compareTo(clonedKeyI)); - clonedKeyI.setKey(keyI.getKey()); - assertEquals(0, keyI.compareTo(clonedKeyI)); - - clonedKeyI.getKeyInfoMap().clear(); - assertNotEquals(0, keyI.compareTo(clonedKeyI)); - - AxKeyInfo keyInfo = keyI.get("BasicModel"); - assertNotNull(keyInfo); - - keyInfo = keyI.get(new AxArtifactKey("BasicModel", "0.0.1")); - assertNotNull(keyInfo); - - Set keyInfoSet = keyI.getAll("BasicModel"); - assertNotNull(keyInfoSet); - - keyInfoSet = keyI.getAll("BasicModel", "0..0.1"); - assertNotNull(keyInfoSet); - - List keys = model.getKeys(); - assertNotEquals(0, keys.size()); - - keys = keyI.getKeys(); - assertNotEquals(0, keys.size()); - - model.getKeyInformation().generateKeyInfo(model); - assertNotNull(model.getKeyInformation()); - model.getKeyInformation().getKeyInfoMap().clear(); - model.getKeyInformation().generateKeyInfo(model); - assertNotNull(model.getKeyInformation()); - - clonedKeyI.setKey(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - clonedKeyI.setKey(keyI.getKey()); - - clonedKeyI.getKeyInfoMap().clear(); - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - clonedKeyI.generateKeyInfo(model); - - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - clonedKeyI.getKeyInfoMap().put(AxArtifactKey.getNullKey(), null); - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - clonedKeyI.getKeyInfoMap().clear(); - clonedKeyI.generateKeyInfo(model); - - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - clonedKeyI.getKeyInfoMap().put(new AxArtifactKey("SomeKey", "0.0.1"), null); - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - clonedKeyI.getKeyInfoMap().clear(); - clonedKeyI.generateKeyInfo(model); - - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - final AxKeyInfo mk = clonedKeyI.get(new AxArtifactKey("BasicModel", "0.0.1")); - assertNotNull(mk); - mk.setKey(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - clonedKeyI.getKeyInfoMap().clear(); - clonedKeyI.generateKeyInfo(model); - - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - clonedModel.setKey(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = clonedModel.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - clonedModel.setKey(model.getKey()); - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - } - - @Test - public void testModelConceptsWithReferences() { - final DummyAxModelWithReferences mwr = new DummyApexBasicModelCreator().getModelWithReferences(); - assertNotNull(mwr); - mwr.getKeyInformation().getKeyInfoMap().clear(); - mwr.getKeyInformation().generateKeyInfo(mwr); - - AxValidationResult result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - // Duplicate key error - mwr.addKey(mwr.getKey()); - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - mwr.removeKey(mwr.getKey()); - - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - // Null Reference Key - mwr.addKey(AxReferenceKey.getNullKey()); - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - mwr.removeKey(AxReferenceKey.getNullKey()); - - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - // Duplicate Reference Key - final AxReferenceKey rKey = new AxReferenceKey(mwr.getKey(), "LocalName"); - mwr.addKey(rKey); - mwr.addKey(rKey); - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - mwr.removeKey(rKey); - mwr.removeKey(rKey); - - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - // Key Use is legal - final AxKeyUse keyU = new AxKeyUse(mwr.getKey()); - mwr.addKey(keyU); - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - mwr.removeKey(keyU); - - // Key Use on bad artifact key - final AxKeyUse keyBadUsage = new AxKeyUse(new AxArtifactKey("SomeKey", "0.0.1")); - mwr.addKey(keyBadUsage); - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - mwr.removeKey(keyBadUsage); - - // Key Use on bad reference key - final AxKeyUse keyBadReferenceUsage = new AxKeyUse(new AxReferenceKey("SomeKey", "0.0.1", "Local")); - mwr.addKey(keyBadReferenceUsage); - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - mwr.removeKey(keyBadReferenceUsage); - - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java new file mode 100644 index 000000000..1c21b6c33 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java @@ -0,0 +1,131 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxModel; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; + +public class SupportApexBasicModelTest { + TestApexModel testApexModel; + + /** + * Set up the test. + * + * @throws Exception any exception thrown by the test + */ + @Before + public void setup() throws Exception { + testApexModel = new TestApexModel(AxModel.class, new DummyApexBasicModelCreator()); + } + + @Test + public void testModelValid() throws Exception { + final AxValidationResult result = testApexModel.testApexModelValid(); + assertEquals(VALID_MODEL_STRING, result.toString()); + } + + @Test + public void testApexModelVaidateObservation() throws Exception { + assertThatThrownBy(testApexModel::testApexModelVaidateObservation) + .hasMessage("model should have observations"); + } + + @Test + public void testApexModelVaidateWarning() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateWarning(); + assertEquals(WARNING_MODEL_STRING, result.toString()); + } + + @Test + public void testModelVaidateInvalidModel() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel(); + assertEquals(INVALID_MODEL_STRING, result.toString()); + } + + @Test + public void testModelVaidateMalstructured() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured(); + assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString()); + } + + @Test + public void testModelWriteReadXml() throws Exception { + testApexModel.testApexModelWriteReadXml(); + } + + @Test + public void testModelWriteReadJson() throws Exception { + testApexModel.testApexModelWriteReadJson(); + } + + @Test + public void testModelWriteReadJpa() throws Exception { + final DaoParameters daoParameters = new DaoParameters(); + daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao"); + daoParameters.setPersistenceUnit("DaoTest"); + + testApexModel.testApexModelWriteReadJpa(daoParameters); + } + + // As there are no real concepts in a basic model, this is as near to a valid model as we can get + private static final String VALID_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" + + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" + + ".AxModel:WARNING:key not found for key information entry\n" + + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" + + ".AxModel:WARNING:key not found for key information entry\n" + "********************************"; + + private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" + + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" + + ".AxModel:WARNING:key not found for key information entry\n" + + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" + + ".AxModel:WARNING:key not found for key information entry\n" + + "AxArtifactKey:(name=Unref0,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" + + ".AxModel:WARNING:key not found for key information entry\n" + + "AxArtifactKey:(name=Unref1,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" + + ".AxModel:WARNING:key not found for key information entry\n" + "********************************"; + + private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" + + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." + + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" + + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." + + "AxKeyInfo:OBSERVATION:description is blank\n" + + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." + + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" + + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." + + "AxKeyInformation:INVALID:duplicate UUID found on keyInfoMap entry AxArtifactKey:" + + "(name=KeyInfoMapKey,version=0.0.1):00000000-0000-0000-0000-000000000000\n" + + "********************************"; + + private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" + + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." + + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" + + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." + + "AxModel:INVALID:key information not found for key " + + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + "********************************"; +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java deleted file mode 100644 index 064a107e7..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java +++ /dev/null @@ -1,131 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; - -public class SupportApexBasicModelTester { - TestApexModel testApexModel; - - /** - * Set up the test. - * - * @throws Exception any exception thrown by the test - */ - @Before - public void setup() throws Exception { - testApexModel = new TestApexModel(AxModel.class, new DummyApexBasicModelCreator()); - } - - @Test - public void testModelValid() throws Exception { - final AxValidationResult result = testApexModel.testApexModelValid(); - assertEquals(VALID_MODEL_STRING, result.toString()); - } - - @Test - public void testApexModelVaidateObservation() throws Exception { - assertThatThrownBy(testApexModel::testApexModelVaidateObservation) - .hasMessage("model should have observations"); - } - - @Test - public void testApexModelVaidateWarning() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateWarning(); - assertEquals(WARNING_MODEL_STRING, result.toString()); - } - - @Test - public void testModelVaidateInvalidModel() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel(); - assertEquals(INVALID_MODEL_STRING, result.toString()); - } - - @Test - public void testModelVaidateMalstructured() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured(); - assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString()); - } - - @Test - public void testModelWriteReadXml() throws Exception { - testApexModel.testApexModelWriteReadXml(); - } - - @Test - public void testModelWriteReadJson() throws Exception { - testApexModel.testApexModelWriteReadJson(); - } - - @Test - public void testModelWriteReadJpa() throws Exception { - final DaoParameters daoParameters = new DaoParameters(); - daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao"); - daoParameters.setPersistenceUnit("DaoTest"); - - testApexModel.testApexModelWriteReadJpa(daoParameters); - } - - // As there are no real concepts in a basic model, this is as near to a valid model as we can get - private static final String VALID_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" - + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" - + ".AxModel:WARNING:key not found for key information entry\n" - + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" - + ".AxModel:WARNING:key not found for key information entry\n" + "********************************"; - - private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" - + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" - + ".AxModel:WARNING:key not found for key information entry\n" - + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" - + ".AxModel:WARNING:key not found for key information entry\n" - + "AxArtifactKey:(name=Unref0,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" - + ".AxModel:WARNING:key not found for key information entry\n" - + "AxArtifactKey:(name=Unref1,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" - + ".AxModel:WARNING:key not found for key information entry\n" + "********************************"; - - private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." - + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" - + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." - + "AxKeyInfo:OBSERVATION:description is blank\n" - + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." - + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" - + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." - + "AxKeyInformation:INVALID:duplicate UUID found on keyInfoMap entry AxArtifactKey:" - + "(name=KeyInfoMapKey,version=0.0.1):00000000-0000-0000-0000-000000000000\n" - + "********************************"; - - private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." - + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" - + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." - + "AxModel:INVALID:key information not found for key " - + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + "********************************"; -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java new file mode 100644 index 000000000..5fc678ac0 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020-2021 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.concepts.AxModel; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; + +public class SupportBasicModelTest { + + @Test + public void testNormalModelCreator() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new DummyApexBasicModelCreator()); + + testApexModel.testApexModelValid(); + assertThatThrownBy(testApexModel::testApexModelVaidateObservation) + .hasMessage("model should have observations"); + testApexModel.testApexModelVaidateWarning(); + testApexModel.testApexModelVaidateInvalidModel(); + testApexModel.testApexModelVaidateMalstructured(); + + testApexModel.testApexModelWriteReadJson(); + testApexModel.testApexModelWriteReadXml(); + } + + @Test + public void testModelsUnequal() throws ApexException { + final TestApexModel testApexModel0 = new TestApexModel(AxModel.class, + new DummyApexBasicModelCreator()); + final TestApexModel testApexModel1 = new TestApexModel(AxModel.class, + new DummyApexBasicModelCreator()); + + testApexModel1.getModel().getKey().setVersion("0.0.2"); + + assertThatThrownBy(() -> testApexModel0.checkModelEquality(testApexModel0.getModel(), testApexModel1.getModel(), + "Models are not equal")).hasMessage("Models are not equal"); + } + + @Test + public void testModelCreator0() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new SupportApexModelCreator0()); + + testApexModel.testApexModelValid(); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation()) + .hasMessage("model should have observations"); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) + .hasMessage("model should have warnings"); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateInvalidModel()) + .hasMessage("model should not be valid ***validation of model successful***"); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateMalstructured()) + .hasMessage("model should not be valid ***validation of model successful***"); + } + + @Test + public void testModelCreator1() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new SupportApexModelCreator1()); + + assertThatThrownBy(() -> testApexModel.testApexModelValid()) + .hasMessageStartingWith("model is invalid"); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation()) + .hasMessageStartingWith("model is invalid"); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) + .hasMessageStartingWith("model is invalid"); + testApexModel.testApexModelVaidateInvalidModel(); + testApexModel.testApexModelVaidateMalstructured(); + } + + @Test + public void testModelCreator2() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new SupportApexModelCreator2()); + + testApexModel.testApexModelValid(); + testApexModel.testApexModelVaidateObservation(); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) + .hasMessage("model should have warnings"); + } + + @Test + public void testModelCreator1XmlJson() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new SupportApexModelCreator1()); + + assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson()) + .hasMessageStartingWith("error processing file"); + + assertThatThrownBy(() -> testApexModel.testApexModelWriteReadXml()) + .hasMessageStartingWith("error processing file"); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTester.java deleted file mode 100644 index 2761d86da..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTester.java +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; - -public class SupportBasicModelTester { - - @Test - public void testNormalModelCreator() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new DummyApexBasicModelCreator()); - - testApexModel.testApexModelValid(); - assertThatThrownBy(testApexModel::testApexModelVaidateObservation) - .hasMessage("model should have observations"); - testApexModel.testApexModelVaidateWarning(); - testApexModel.testApexModelVaidateInvalidModel(); - testApexModel.testApexModelVaidateMalstructured(); - - testApexModel.testApexModelWriteReadJson(); - testApexModel.testApexModelWriteReadXml(); - } - - @Test - public void testModelsUnequal() throws ApexException { - final TestApexModel testApexModel0 = new TestApexModel(AxModel.class, - new DummyApexBasicModelCreator()); - final TestApexModel testApexModel1 = new TestApexModel(AxModel.class, - new DummyApexBasicModelCreator()); - - testApexModel1.getModel().getKey().setVersion("0.0.2"); - - assertThatThrownBy(() -> testApexModel0.checkModelEquality(testApexModel0.getModel(), testApexModel1.getModel(), - "Models are not equal")).hasMessage("Models are not equal"); - } - - @Test - public void testModelCreator0() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new SupportApexModelCreator0()); - - testApexModel.testApexModelValid(); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation()) - .hasMessage("model should have observations"); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) - .hasMessage("model should have warnings"); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateInvalidModel()) - .hasMessage("model should not be valid ***validation of model successful***"); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateMalstructured()) - .hasMessage("model should not be valid ***validation of model successful***"); - } - - @Test - public void testModelCreator1() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new SupportApexModelCreator1()); - - assertThatThrownBy(() -> testApexModel.testApexModelValid()) - .hasMessageStartingWith("model is invalid"); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation()) - .hasMessageStartingWith("model is invalid"); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) - .hasMessageStartingWith("model is invalid"); - testApexModel.testApexModelVaidateInvalidModel(); - testApexModel.testApexModelVaidateMalstructured(); - } - - @Test - public void testModelCreator2() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new SupportApexModelCreator2()); - - testApexModel.testApexModelValid(); - testApexModel.testApexModelVaidateObservation(); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) - .hasMessage("model should have warnings"); - } - - @Test - public void testModelCreator1XmlJson() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new SupportApexModelCreator1()); - - assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson()) - .hasMessageStartingWith("error processing file"); - - assertThatThrownBy(() -> testApexModel.testApexModelWriteReadXml()) - .hasMessageStartingWith("error processing file"); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java new file mode 100644 index 000000000..006c583ec --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java @@ -0,0 +1,217 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; +import org.onap.policy.apex.model.basicmodel.concepts.AxModel; + +public class SupportConceptGetterTest { + + private static final AxKeyInfo intKI01 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey01", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey01 description"); + private static final AxKeyInfo intKI11 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey11", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey11 description"); + private static final AxKeyInfo intKI21 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey21", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey21 description"); + private static final AxKeyInfo intKI22 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey22", "0.0.2"), + UUID.randomUUID(), "IntegerKIKey22 description"); + private static final AxKeyInfo intKI23 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey23", "0.0.3"), + UUID.randomUUID(), "IntegerKIKey23 description"); + private static final AxKeyInfo intKI24 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey24", "0.0.4"), + UUID.randomUUID(), "IntegerKIKey24 description"); + private static final AxKeyInfo intKI25 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey25", "0.0.5"), + UUID.randomUUID(), "IntegerKIKey25 description"); + private static final AxKeyInfo intKI26 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey26", "0.0.6"), + UUID.randomUUID(), "IntegerKIKey26 description"); + private static final AxKeyInfo intKI31 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey31", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey31 description"); + private static final AxKeyInfo intKI41 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey41", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey41 description"); + private static final AxKeyInfo intKI51 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey51", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey51 description"); + private static final AxKeyInfo intKI52 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey52", "0.0.2"), + UUID.randomUUID(), "IntegerKIKey52 description"); + private static final AxKeyInfo intKI53 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey53", "0.0.3"), + UUID.randomUUID(), "IntegerKIKey53 description"); + private static final AxKeyInfo intKI54 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey54", "0.0.4"), + UUID.randomUUID(), "IntegerKIKey54 description"); + private static final AxKeyInfo intKI61 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey61", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey61 description"); + private static final AxKeyInfo intKI62 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey62", "0.0.2"), + UUID.randomUUID(), "IntegerKIKey62 description"); + private static final AxKeyInfo intKI63 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey63", "0.0.3"), + UUID.randomUUID(), "IntegerKIKey63 description"); + private static final AxKeyInfo intKI64 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey64", "0.0.4"), + UUID.randomUUID(), "IntegerKIKey64 description"); + private static final AxKeyInfo intKI71 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey71", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey71 description"); + private static final AxKeyInfo intKI81 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey81", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey81 description"); + private static final AxKeyInfo intKI91 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey91", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey91 description"); + private static final AxKeyInfo floatKI01 = new AxKeyInfo(new AxArtifactKey("FloatKIKey01", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey01 description"); + private static final AxKeyInfo floatKI11 = new AxKeyInfo(new AxArtifactKey("FloatKIKey11", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey11 description"); + private static final AxKeyInfo floatKI21 = new AxKeyInfo(new AxArtifactKey("FloatKIKey21", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey21 description"); + private static final AxKeyInfo floatKI31 = new AxKeyInfo(new AxArtifactKey("FloatKIKey31", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey31 description"); + private static final AxKeyInfo floatKI41 = new AxKeyInfo(new AxArtifactKey("FloatKIKey41", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey41 description"); + private static final AxKeyInfo floatKI51 = new AxKeyInfo(new AxArtifactKey("FloatKIKey51", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey51 description"); + private static final AxKeyInfo floatKI61 = new AxKeyInfo(new AxArtifactKey("FloatKIKey61", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey61 description"); + private static final AxKeyInfo floatKI71 = new AxKeyInfo(new AxArtifactKey("FloatKIKey71", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey71 description"); + private static final AxKeyInfo floatKI81 = new AxKeyInfo(new AxArtifactKey("FloatKIKey81", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey81 description"); + private static final AxKeyInfo floatKI82 = new AxKeyInfo(new AxArtifactKey("FloatKIKey82", "0.0.2"), + UUID.randomUUID(), "IntegerKIKey82 description"); + private static final AxKeyInfo floatKI83 = new AxKeyInfo(new AxArtifactKey("FloatKIKey83", "0.0.3"), + UUID.randomUUID(), "IntegerKIKey83 description"); + private static final AxKeyInfo floatKI91 = new AxKeyInfo(new AxArtifactKey("FloatKIKey91", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey91 description"); + private static final AxKeyInfo floatKI92 = new AxKeyInfo(new AxArtifactKey("FloatKIKey92", "0.0.2"), + UUID.randomUUID(), "IntegerKIKey92 description"); + private static final AxKeyInfo floatKI93 = new AxKeyInfo(new AxArtifactKey("FloatKIKey93", "0.0.3"), + UUID.randomUUID(), "IntegerKIKey93 description"); + + @Test + public void testConceptGetterInteger() { + AxModel basicModel = setTestBasicModel(); + + assertNull(basicModel.getKeyInformation().get("NonExistantKey", "0.0.6")); + assertEquals(intKI26, basicModel.getKeyInformation().get("IntegerKIKey26", "0.0.6")); + assertEquals(intKI62, basicModel.getKeyInformation().get("IntegerKIKey62", "0.0.2")); + assertEquals(intKI21, basicModel.getKeyInformation().get("IntegerKIKey21", "0.0.1")); + assertEquals(intKI61, basicModel.getKeyInformation().get("IntegerKIKey61", "0.0.1")); + + assertNull(basicModel.getKeyInformation().get("NonExistantKey")); + + assertEquals(intKI01, basicModel.getKeyInformation().get("IntegerKIKey01")); + assertEquals(intKI11, basicModel.getKeyInformation().get("IntegerKIKey11")); + assertEquals(intKI26, basicModel.getKeyInformation().get("IntegerKIKey26")); + assertEquals(intKI31, basicModel.getKeyInformation().get("IntegerKIKey31")); + assertEquals(intKI41, basicModel.getKeyInformation().get("IntegerKIKey41")); + assertEquals(intKI54, basicModel.getKeyInformation().get("IntegerKIKey54")); + assertEquals(intKI64, basicModel.getKeyInformation().get("IntegerKIKey64")); + assertEquals(intKI71, basicModel.getKeyInformation().get("IntegerKIKey71")); + assertEquals(intKI81, basicModel.getKeyInformation().get("IntegerKIKey81")); + assertEquals(intKI91, basicModel.getKeyInformation().get("IntegerKIKey91")); + } + + @Test + public void testConceptGetterFloat() { + AxModel basicModel = setTestBasicModel(); + + assertEquals(floatKI01, basicModel.getKeyInformation().get("FloatKIKey01")); + assertEquals(floatKI11, basicModel.getKeyInformation().get("FloatKIKey11")); + assertEquals(floatKI21, basicModel.getKeyInformation().get("FloatKIKey21")); + assertEquals(floatKI31, basicModel.getKeyInformation().get("FloatKIKey31")); + assertEquals(floatKI41, basicModel.getKeyInformation().get("FloatKIKey41")); + assertEquals(floatKI51, basicModel.getKeyInformation().get("FloatKIKey51")); + assertEquals(floatKI61, basicModel.getKeyInformation().get("FloatKIKey61")); + assertEquals(floatKI71, basicModel.getKeyInformation().get("FloatKIKey71")); + assertEquals(floatKI83, basicModel.getKeyInformation().get("FloatKIKey83")); + assertEquals(floatKI93, basicModel.getKeyInformation().get("FloatKIKey93")); + } + + @Test + public void testMarshalling() throws IOException, ApexException { + AxModel basicModel = setTestBasicModel(); + + // Ensure marshalling and unmarshalling is OK + ApexModelReader modelReader = new ApexModelReader(AxModel.class); + ApexModelFileWriter modelWriter = new ApexModelFileWriter(true); + + modelReader.setValidateFlag(false); + modelWriter.setValidateFlag(false); + + File tempXmlFile = File.createTempFile("ApexModel", "xml"); + modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempXmlFile.getCanonicalPath()); + + FileInputStream xmlFileInputStream = new FileInputStream(tempXmlFile); + AxModel readXmlModel = modelReader.read(xmlFileInputStream); + xmlFileInputStream.close(); + assertEquals(basicModel, readXmlModel); + assertEquals(intKI91, readXmlModel.getKeyInformation().get("IntegerKIKey91")); + assertNotNull(readXmlModel.getKeyInformation().get("FloatKIKey")); + tempXmlFile.delete(); + } + + private AxModel setTestBasicModel() { + AxModel basicModel = new DummyApexBasicModelCreator().getModel(); + assertNotNull(basicModel); + + basicModel.getKeyInformation().getKeyInfoMap().put(intKI31.getKey(), intKI31); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI24.getKey(), intKI24); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI11.getKey(), intKI11); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI64.getKey(), intKI64); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI41.getKey(), intKI41); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI51.getKey(), intKI51); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI23.getKey(), intKI23); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI81.getKey(), intKI81); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI71.getKey(), intKI71); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI01.getKey(), intKI01); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI91.getKey(), intKI91); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI52.getKey(), intKI52); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI53.getKey(), intKI53); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI62.getKey(), intKI62); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI54.getKey(), intKI54); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI26.getKey(), intKI26); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI22.getKey(), intKI22); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI25.getKey(), intKI25); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI21.getKey(), intKI21); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI61.getKey(), intKI61); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI63.getKey(), intKI63); + + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI11.getKey(), floatKI11); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI83.getKey(), floatKI83); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI51.getKey(), floatKI51); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI71.getKey(), floatKI71); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI21.getKey(), floatKI21); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI81.getKey(), floatKI81); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI92.getKey(), floatKI92); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI91.getKey(), floatKI91); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI01.getKey(), floatKI01); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI82.getKey(), floatKI82); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI61.getKey(), floatKI61); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI41.getKey(), floatKI41); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI31.getKey(), floatKI31); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI93.getKey(), floatKI93); + + return basicModel; + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTester.java deleted file mode 100644 index 786df5258..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTester.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.UUID; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; - -public class SupportConceptGetterTester { - - @Test - public void testConceptGetter() throws IOException, ApexException { - AxModel basicModel = new DummyApexBasicModelCreator().getModel(); - assertNotNull(basicModel); - - AxKeyInfo intKI01 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey01", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey01 description"); - AxKeyInfo intKI11 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey11", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey11 description"); - AxKeyInfo intKI21 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey21", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey21 description"); - AxKeyInfo intKI22 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey22", "0.0.2"), UUID.randomUUID(), - "IntegerKIKey22 description"); - AxKeyInfo intKI23 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey23", "0.0.3"), UUID.randomUUID(), - "IntegerKIKey23 description"); - AxKeyInfo intKI24 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey24", "0.0.4"), UUID.randomUUID(), - "IntegerKIKey24 description"); - AxKeyInfo intKI25 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey25", "0.0.5"), UUID.randomUUID(), - "IntegerKIKey25 description"); - AxKeyInfo intKI26 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey26", "0.0.6"), UUID.randomUUID(), - "IntegerKIKey26 description"); - AxKeyInfo intKI31 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey31", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey31 description"); - AxKeyInfo intKI41 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey41", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey41 description"); - AxKeyInfo intKI51 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey51", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey51 description"); - AxKeyInfo intKI52 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey52", "0.0.2"), UUID.randomUUID(), - "IntegerKIKey52 description"); - AxKeyInfo intKI53 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey53", "0.0.3"), UUID.randomUUID(), - "IntegerKIKey53 description"); - AxKeyInfo intKI54 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey54", "0.0.4"), UUID.randomUUID(), - "IntegerKIKey54 description"); - AxKeyInfo intKI61 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey61", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey61 description"); - AxKeyInfo intKI62 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey62", "0.0.2"), UUID.randomUUID(), - "IntegerKIKey62 description"); - AxKeyInfo intKI63 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey63", "0.0.3"), UUID.randomUUID(), - "IntegerKIKey63 description"); - AxKeyInfo intKI64 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey64", "0.0.4"), UUID.randomUUID(), - "IntegerKIKey64 description"); - AxKeyInfo intKI71 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey71", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey71 description"); - AxKeyInfo intKI81 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey81", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey81 description"); - AxKeyInfo intKI91 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey91", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey91 description"); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI31.getKey(), intKI31); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI24.getKey(), intKI24); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI11.getKey(), intKI11); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI64.getKey(), intKI64); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI41.getKey(), intKI41); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI51.getKey(), intKI51); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI23.getKey(), intKI23); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI81.getKey(), intKI81); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI71.getKey(), intKI71); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI01.getKey(), intKI01); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI91.getKey(), intKI91); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI52.getKey(), intKI52); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI53.getKey(), intKI53); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI62.getKey(), intKI62); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI54.getKey(), intKI54); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI26.getKey(), intKI26); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI22.getKey(), intKI22); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI25.getKey(), intKI25); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI21.getKey(), intKI21); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI61.getKey(), intKI61); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI63.getKey(), intKI63); - - AxKeyInfo floatKI01 = new AxKeyInfo(new AxArtifactKey("FloatKIKey01", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey01 description"); - AxKeyInfo floatKI11 = new AxKeyInfo(new AxArtifactKey("FloatKIKey11", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey11 description"); - AxKeyInfo floatKI21 = new AxKeyInfo(new AxArtifactKey("FloatKIKey21", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey21 description"); - AxKeyInfo floatKI31 = new AxKeyInfo(new AxArtifactKey("FloatKIKey31", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey31 description"); - AxKeyInfo floatKI41 = new AxKeyInfo(new AxArtifactKey("FloatKIKey41", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey41 description"); - AxKeyInfo floatKI51 = new AxKeyInfo(new AxArtifactKey("FloatKIKey51", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey51 description"); - AxKeyInfo floatKI61 = new AxKeyInfo(new AxArtifactKey("FloatKIKey61", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey61 description"); - AxKeyInfo floatKI71 = new AxKeyInfo(new AxArtifactKey("FloatKIKey71", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey71 description"); - AxKeyInfo floatKI81 = new AxKeyInfo(new AxArtifactKey("FloatKIKey81", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey81 description"); - AxKeyInfo floatKI82 = new AxKeyInfo(new AxArtifactKey("FloatKIKey82", "0.0.2"), UUID.randomUUID(), - "IntegerKIKey82 description"); - AxKeyInfo floatKI83 = new AxKeyInfo(new AxArtifactKey("FloatKIKey83", "0.0.3"), UUID.randomUUID(), - "IntegerKIKey83 description"); - AxKeyInfo floatKI91 = new AxKeyInfo(new AxArtifactKey("FloatKIKey91", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey91 description"); - AxKeyInfo floatKI92 = new AxKeyInfo(new AxArtifactKey("FloatKIKey92", "0.0.2"), UUID.randomUUID(), - "IntegerKIKey92 description"); - AxKeyInfo floatKI93 = new AxKeyInfo(new AxArtifactKey("FloatKIKey93", "0.0.3"), UUID.randomUUID(), - "IntegerKIKey93 description"); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI11.getKey(), floatKI11); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI83.getKey(), floatKI83); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI51.getKey(), floatKI51); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI71.getKey(), floatKI71); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI21.getKey(), floatKI21); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI81.getKey(), floatKI81); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI92.getKey(), floatKI92); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI91.getKey(), floatKI91); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI01.getKey(), floatKI01); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI82.getKey(), floatKI82); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI61.getKey(), floatKI61); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI41.getKey(), floatKI41); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI31.getKey(), floatKI31); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI93.getKey(), floatKI93); - - assertNull(basicModel.getKeyInformation().get("NonExistantKey", "0.0.6")); - assertEquals(intKI26, basicModel.getKeyInformation().get("IntegerKIKey26", "0.0.6")); - assertEquals(intKI62, basicModel.getKeyInformation().get("IntegerKIKey62", "0.0.2")); - assertEquals(intKI21, basicModel.getKeyInformation().get("IntegerKIKey21", "0.0.1")); - assertEquals(intKI61, basicModel.getKeyInformation().get("IntegerKIKey61", "0.0.1")); - - assertNull(basicModel.getKeyInformation().get("NonExistantKey")); - - assertEquals(intKI01, basicModel.getKeyInformation().get("IntegerKIKey01")); - assertEquals(intKI11, basicModel.getKeyInformation().get("IntegerKIKey11")); - assertEquals(intKI26, basicModel.getKeyInformation().get("IntegerKIKey26")); - assertEquals(intKI31, basicModel.getKeyInformation().get("IntegerKIKey31")); - assertEquals(intKI41, basicModel.getKeyInformation().get("IntegerKIKey41")); - assertEquals(intKI54, basicModel.getKeyInformation().get("IntegerKIKey54")); - assertEquals(intKI64, basicModel.getKeyInformation().get("IntegerKIKey64")); - assertEquals(intKI71, basicModel.getKeyInformation().get("IntegerKIKey71")); - assertEquals(intKI81, basicModel.getKeyInformation().get("IntegerKIKey81")); - assertEquals(intKI91, basicModel.getKeyInformation().get("IntegerKIKey91")); - - assertEquals(floatKI01, basicModel.getKeyInformation().get("FloatKIKey01")); - assertEquals(floatKI11, basicModel.getKeyInformation().get("FloatKIKey11")); - assertEquals(floatKI21, basicModel.getKeyInformation().get("FloatKIKey21")); - assertEquals(floatKI31, basicModel.getKeyInformation().get("FloatKIKey31")); - assertEquals(floatKI41, basicModel.getKeyInformation().get("FloatKIKey41")); - assertEquals(floatKI51, basicModel.getKeyInformation().get("FloatKIKey51")); - assertEquals(floatKI61, basicModel.getKeyInformation().get("FloatKIKey61")); - assertEquals(floatKI71, basicModel.getKeyInformation().get("FloatKIKey71")); - assertEquals(floatKI83, basicModel.getKeyInformation().get("FloatKIKey83")); - assertEquals(floatKI93, basicModel.getKeyInformation().get("FloatKIKey93")); - - // Ensure marshalling and unmarshalling is OK - ApexModelReader modelReader = new ApexModelReader(AxModel.class); - ApexModelFileWriter modelWriter = new ApexModelFileWriter(true); - - modelReader.setValidateFlag(false); - modelWriter.setValidateFlag(false); - - File tempXmlFile = File.createTempFile("ApexModel", "xml"); - modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempXmlFile.getCanonicalPath()); - - FileInputStream xmlFileInputStream = new FileInputStream(tempXmlFile); - AxModel readXmlModel = modelReader.read(xmlFileInputStream); - xmlFileInputStream.close(); - assertEquals(basicModel, readXmlModel); - assertEquals(intKI91, readXmlModel.getKeyInformation().get("IntegerKIKey91")); - assertNotNull(readXmlModel.getKeyInformation().get("FloatKIKey")); - tempXmlFile.delete(); - } -} -- cgit 1.2.3-korg