diff options
Diffstat (limited to 'model/basic-model')
60 files changed, 0 insertions, 7403 deletions
diff --git a/model/basic-model/pom.xml b/model/basic-model/pom.xml deleted file mode 100644 index 45d9978cf..000000000 --- a/model/basic-model/pom.xml +++ /dev/null @@ -1,83 +0,0 @@ -<!-- - ============LICENSE_START======================================================= - Copyright (c) 2020,2022 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========================================================= ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onap.policy.apex-pdp.model</groupId> - <artifactId>model</artifactId> - <version>2.7.1-SNAPSHOT</version> - </parent> - - <artifactId>basic-model</artifactId> - <name>${project.artifactId}</name> - <description>Basic Models used and model handling in Apex</description> - <properties> - <sonar.exclusions> - **/package-info.java, - **/TestApexModel.java, - **/TestApexModelCreator.java - </sonar.exclusions> - </properties> - - <dependencies> - <dependency> - <groupId>org.onap.policy.common</groupId> - <artifactId>utils</artifactId> - <exclusions> - <exclusion> - <groupId>javax.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.onap.policy.apex-pdp.model</groupId> - <artifactId>utilities</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>javax.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - <version>${version.javax.bind}</version> - </dependency> - <dependency> - <groupId>org.glassfish.jaxb</groupId> - <artifactId>jaxb-runtime</artifactId> - <version>${version.javax.bind}</version> - </dependency> - <dependency> - <groupId>org.glassfish</groupId> - <artifactId>javax.json</artifactId> - <version>${version.javax.json}</version> - </dependency> - <dependency> - <groupId>javax.json</groupId> - <artifactId>javax.json-api</artifactId> - <version>${version.javax.json}</version> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <scope>test</scope> - </dependency> - </dependencies> -</project>
\ No newline at end of file diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexConceptException.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexConceptException.java deleted file mode 100644 index d62818dc8..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexConceptException.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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.concepts; - -/** - * This class is an exception thrown on Apex Concept errors. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexConceptException extends ApexException { - private static final long serialVersionUID = -8507246953751956974L; - - /** - * Instantiates a new apex concept exception. - * - * @param message the message on the exception - */ - public ApexConceptException(final String message) { - super(message); - } - - /** - * Instantiates a new apex concept exception. - * - * @param message the message on the exception - * @param exception the exception that caused this Apex exception - */ - public ApexConceptException(final String message, final Exception exception) { - super(message, exception); - } -} 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 deleted file mode 100644 index 2eca2f783..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexException.java +++ /dev/null @@ -1,111 +0,0 @@ -/*- - * ============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========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.concepts; - -/** - * This class is a base exception from which all Apex exceptions are sub classes. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexException extends Exception { - private static final long serialVersionUID = -8507246953751956974L; - - // The object on which the exception was thrown - private final transient Object object; - - /** - * Instantiates a new apex exception. - * - * @param message the message on the exception - */ - public ApexException(final String message) { - this(message, null); - } - - /** - * Instantiates a new apex exception. - * - * @param message the message on the exception - * @param object the object that the exception was thrown on - */ - public ApexException(final String message, final Object object) { - super(message); - this.object = object; - } - - /** - * Instantiates a new apex exception. - * - * @param message the message on the exception - * @param exception the exception that caused this Apex exception - */ - public ApexException(final String message, final Exception exception) { - this(message, exception, null); - } - - /** - * Instantiates a new apex exception. - * - * @param message the message on the exception - * @param exception the exception that caused this Apex exception - * @param object the object that the exception was thrown on - */ - public ApexException(final String message, final Exception exception, final Object object) { - super(message, exception); - this.object = object; - } - - /** - * Get the message from this exception and its causes. - * - * @return the cascaded messages from this exception and the exceptions that caused it - */ - public String getCascadedMessage() { - return buildCascadedMessage(this); - } - - /** - * Build a cascaded message from an exception and all its nested exceptions. - * @param throwable the top level exception - * @return cascaded message string - */ - public static String buildCascadedMessage(Throwable throwable) { - final var builder = new StringBuilder(); - builder.append(throwable.getMessage()); - - for (var t = throwable; t != null; t = t.getCause()) { - builder.append("\ncaused by: "); - builder.append(t.getMessage()); - } - - return builder.toString(); - } - - /** - * Get the object on which the exception was thrown. - * - * @return The object on which the exception was thrown - */ - public Object getObject() { - return object; - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexRuntimeException.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexRuntimeException.java deleted file mode 100644 index b4240ad0f..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/ApexRuntimeException.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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.concepts; - -/** - * This class is a base run time exception from which all Apex run time exceptions are sub classes. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexRuntimeException extends RuntimeException { - private static final long serialVersionUID = -8507246953751956974L; - - // The object on which the exception was thrown - private final transient Object object; - - /** - * Instantiates a new apex runtime exception. - * - * @param message the message on the exception - */ - public ApexRuntimeException(final String message) { - this(message, null); - } - - /** - * Instantiates a new apex runtime exception. - * - * @param message the message on the exception - * @param object the object that the exception was thrown on - */ - public ApexRuntimeException(final String message, final Object object) { - super(message); - this.object = object; - } - - /** - * Instantiates a new apex runtime exception. - * - * @param message the message on the exception - * @param exception the exception that caused this Apex exception - */ - public ApexRuntimeException(final String message, final Exception exception) { - this(message, exception, null); - } - - /** - * Instantiates a new apex runtime exception. - * - * @param message the message on the exception - * @param exception the exception that caused this Apex exception - * @param object the object that the exception was thrown on - */ - public ApexRuntimeException(final String message, final Exception exception, final Object object) { - super(message, exception); - this.object = object; - } - - /** - * Get the message from this exception and its causes. - * - * @return the message of this exception and all the exceptions that caused this exception - */ - public String getCascadedMessage() { - return ApexException.buildCascadedMessage(this); - } - - /** - * Get the object on which the exception was thrown. - * - * @return The object - */ - public Object getObject() { - return object; - } -} 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 deleted file mode 100644 index 1efe83db8..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxArtifactKey.java +++ /dev/null @@ -1,344 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2022 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.concepts; - -import java.util.ArrayList; -import java.util.List; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.common.utils.validation.Assertions; - -/** - * An artifact key uniquely identifies every first order entity in the system. Every first order concept in the system - * must have an {@link AxArtifactKey} to identify it. Concepts that are wholly contained in another concept are - * identified using a {@link AxReferenceKey} key. - * - * <p>Key validation checks that the name and version fields match the NAME_REGEXP and VERSION_REGEXP - * regular expressions respectively. - */ -public class AxArtifactKey extends AxKey { - private static final long serialVersionUID = 8932717618579392561L; - - private static final String NAME_TOKEN = "name"; - private static final String VERSION_TOKEN = "version"; - - private String name; - private String version; - - /** - * The default constructor creates a null artifact key. - */ - public AxArtifactKey() { - this(NULL_KEY_NAME, NULL_KEY_VERSION); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxArtifactKey(final AxArtifactKey copyConcept) { - super(copyConcept); - } - - /** - * Constructor to create a key with the specified name and version. - * - * @param name the key name - * @param version the key version - */ - public AxArtifactKey(final String name, final String version) { - super(); - this.name = Assertions.validateStringParameter(NAME_TOKEN, name, NAME_REGEXP); - this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, VERSION_REGEXP); - } - - /** - * Constructor to create a key using the key and version from the specified key ID. - * - * @param id the key ID in a format that respects the KEY_ID_REGEXP - */ - public AxArtifactKey(final String id) { - Assertions.argumentNotNull(id, "id may not be null"); - - // Check the incoming ID is valid - Assertions.validateStringParameter("id", id, KEY_ID_REGEXP); - - // Split on colon, if the id passes the regular expression test above - // it'll have just one colon separating the name and version - // No need for range checks or size checks on the array - final String[] nameVersionArray = id.split(":"); - - // Return the new key - name = Assertions.validateStringParameter(NAME_TOKEN, nameVersionArray[0], NAME_REGEXP); - version = Assertions.validateStringParameter(VERSION_TOKEN, nameVersionArray[1], VERSION_REGEXP); - } - - /** - * Get a null artifact key. - * - * @return a null artifact key - */ - public static final AxArtifactKey getNullKey() { - return new AxArtifactKey(AxKey.NULL_KEY_NAME, AxKey.NULL_KEY_VERSION); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxArtifactKey getKey() { - return this; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - final List<AxKey> keyList = new ArrayList<>(); - keyList.add(getKey()); - return keyList; - } - - /** - * {@inheritDoc}. - */ - @Override - public String getId() { - return name + ':' + version; - } - - /** - * Gets the key name. - * - * @return the key name - */ - public String getName() { - return name; - } - - /** - * Sets the key name. - * - * @param name the key name - */ - public void setName(final String name) { - this.name = Assertions.validateStringParameter(NAME_TOKEN, name, NAME_REGEXP); - } - - /** - * Gets the key version. - * - * @return the key version - */ - public String getVersion() { - return version; - } - - /** - * Sets the key version. - * - * @param version the key version - */ - public void setVersion(final String version) { - this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, VERSION_REGEXP); - } - - /** - * Check if the key is IDENTICAL to a null key. - * - * @return true, if the key is IDENTICAL to a null key - */ - public boolean isNullKey() { - return this.getCompatibility(AxArtifactKey.getNullKey()).equals(AxKey.Compatibility.IDENTICAL); - } - - - /** - * {@inheritDoc}. - */ - @Override - public AxKey.Compatibility getCompatibility(final AxKey otherKey) { - if (!(otherKey instanceof AxArtifactKey)) { - return Compatibility.DIFFERENT; - } - final AxArtifactKey otherArtifactKey = (AxArtifactKey) otherKey; - - if (this.equals(otherArtifactKey)) { - return Compatibility.IDENTICAL; - } - if (!this.getName().equals(otherArtifactKey.getName())) { - return Compatibility.DIFFERENT; - } - - final String[] thisVersionArray = getVersion().split("\\."); - final String[] otherVersionArray = otherArtifactKey.getVersion().split("\\."); - - // There must always be at least one element in each version - if (!thisVersionArray[0].equals(otherVersionArray[0])) { - return Compatibility.MAJOR; - } - - if (thisVersionArray.length >= 2 && otherVersionArray.length >= 2 - && !thisVersionArray[1].equals(otherVersionArray[1])) { - return Compatibility.MINOR; - } - - return Compatibility.PATCH; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean isCompatible(final AxKey otherKey) { - if (!(otherKey instanceof AxArtifactKey)) { - return false; - } - final AxArtifactKey otherArtifactKey = (AxArtifactKey) otherKey; - - final var compatibility = this.getCompatibility(otherArtifactKey); - - return !(compatibility == Compatibility.DIFFERENT || compatibility == Compatibility.MAJOR); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult result) { - 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 var versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN, - version, VERSION_REGEXP); - if (versionValidationErrorMessage != null) { - result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID, - "version invalid-" + versionValidationErrorMessage)); - } - - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - name = Assertions.validateStringParameter(NAME_TOKEN, name, NAME_REGEXP); - version = Assertions.validateStringParameter(VERSION_TOKEN, version, VERSION_REGEXP); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final var builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("name="); - builder.append(name); - builder.append(",version="); - builder.append(version); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept target) { - Assertions.argumentNotNull(target, "target may not be null"); - - final AxConcept copyObject = target; - Assertions.instanceOf(copyObject, AxArtifactKey.class); - - final AxArtifactKey copy = ((AxArtifactKey) copyObject); - copy.setName(name); - copy.setVersion(version); - - return copyObject; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final var prime = 31; - var result = 1; - result = prime * result + name.hashCode(); - result = prime * result + version.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - - final AxArtifactKey other = (AxArtifactKey) obj; - - if (!name.equals(other.name)) { - return false; - } - return version.equals(other.version); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - Assertions.argumentNotNull(otherObj, "comparison object may not be null"); - - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxArtifactKey other = (AxArtifactKey) otherObj; - - if (!name.equals(other.name)) { - return name.compareTo(other.name); - } - return version.compareTo(other.version); - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java deleted file mode 100644 index 37fe30b33..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConcept.java +++ /dev/null @@ -1,137 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019,2022 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.concepts; - -import java.io.Serializable; -import java.util.List; -import org.onap.policy.common.utils.validation.Assertions; - -/** - * This class is the base class for all Apex concept classes. It enforces implementation of abstract methods and - * interfaces on all concepts that are sub-classes of this class. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public abstract class AxConcept implements Serializable, Comparable<AxConcept> { - private static final long serialVersionUID = -7434939557282697490L; - - /** - * Default constructor. - */ - protected AxConcept() { - // Default constructor - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - protected AxConcept(final AxConcept copyConcept) { - Assertions.argumentNotNull(copyConcept, "copy concept may not be null"); - copyConcept.copyTo(this); - } - - /** - * Gets the key of this concept. - * - * @return the concept key - */ - public abstract AxKey getKey(); - - /** - * Gets a list of all keys for this concept and all concepts that are defined or referenced by this concept and its - * sub-concepts. - * - * @return the keys used by this concept and it's contained concepts - */ - public abstract List<AxKey> getKeys(); - - /** - * Validate that this concept is structurally correct. - * - * @param result the parameter in which the result of the validation will be returned - * @return the validation result that was passed in in the @{link result} field with the result of this validation - * added - */ - public abstract AxValidationResult validate(AxValidationResult result); - - /** - * Clean this concept, tidy up any superfluous information such as leading and trailing white space. - */ - public abstract void clean(); - - /** - * Builds references used by a concept. - */ - public void buildReferences() { - } - - /** - * {@inheritDoc}. - */ - @Override - public abstract boolean equals(Object otherObject); - - /** - * {@inheritDoc}. - */ - @Override - public abstract String toString(); - - /** - * {@inheritDoc}. - */ - @Override - public abstract int hashCode(); - - /** - * Copy this concept to another object. The target object must have the same class as the source object. - * - * @param target the target object to which this object is copied - * @return the copied object - */ - public abstract AxConcept copyTo(AxConcept target); - - /** - * Gets the ID string of this concept. - * - * @return the ID string of this concept - */ - public String getId() { - return getKey().getId(); - } - - /** - * Checks if this key matches the given key ID. - * - * @param id the key ID to match against - * @return true, if this key matches the ID - */ - public final boolean matchesId(final String id) { - Assertions.argumentNotNull(id, "id may not be null"); - - // Check the ID - return getId().equals(id); - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetter.java deleted file mode 100644 index 0284de48a..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetter.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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.concepts; - -import java.util.Set; - -/** - * This interface is used to allow get methods to be placed on concepts that have embedded maps. - * - * <p>It forces those concepts with maps to implement the get methods specified on this interface as convenience methods - * to avoid concept users having to use a second level of referencing to access concepts in the the maps. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - * @param <C> the type of concept on which the interface is applied. - */ -public interface AxConceptGetter<C> { - - /** - * Get the latest version for a concept with the given key. - * - * @param conceptKey The key of the concept - * @return The concept - */ - C get(AxArtifactKey conceptKey); - - /** - * Get the latest version for a concept with the given key name. - * - * @param conceptKeyName The name of the concept - * @return The concept - */ - C get(String conceptKeyName); - - /** - * Get the latest version for a concept with the given key name and version. - * - * @param conceptKeyName The name of the concept - * @param conceptKeyVersion The version of the concept - * @return The concept - */ - C get(String conceptKeyName, String conceptKeyVersion); - - /** - * Get the all versions for a concept with the given key name. - * - * @param conceptKeyName The name of the concept - * @return The concepts - */ - Set<C> getAll(String conceptKeyName); - - /** - * Get the all versions for a concept with the given key name and starting version. - * - * @param conceptKeyName The name of the concept - * @param conceptKeyVersion The first version version of the concept to get - * @return The concepts - */ - Set<C> getAll(String conceptKeyName, String conceptKeyVersion); -} 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 deleted file mode 100644 index 9c907da9c..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImpl.java +++ /dev/null @@ -1,143 +0,0 @@ -/*- - * ============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.concepts; - -import java.util.NavigableMap; -import java.util.Set; -import java.util.TreeSet; -import org.onap.policy.common.utils.validation.Assertions; - -/** - * Implements concept getting from navigable maps. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - * @param <C> the type of concept on which the interface implementation is applied. - */ -public class AxConceptGetterImpl<C> implements AxConceptGetter<C> { - - // The map from which to get concepts - private final NavigableMap<AxArtifactKey, C> conceptMap; - - /** - * Constructor that sets the concept map on which the getter methods in the interface will operate.. - * - * @param conceptMap the concept map on which the method will operate - */ - public AxConceptGetterImpl(final NavigableMap<AxArtifactKey, C> conceptMap) { - this.conceptMap = conceptMap; - } - - /** - * {@inheritDoc}. - */ - @Override - public C get(final AxArtifactKey conceptKey) { - return conceptMap.get(conceptKey); - } - - /** - * {@inheritDoc}. - */ - @Override - public C get(final String conceptKeyName) { - Assertions.argumentNotNull(conceptKeyName, "conceptKeyName may not be null"); - - // The very fist key that could have this name - final var lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1"); - - // Check if we found a key for our name - AxArtifactKey foundKey = conceptMap.ceilingKey(lowestArtifactKey); - if (foundKey == null || !foundKey.getName().equals(conceptKeyName)) { - return null; - } - - // Look for higher versions of the key - do { - final AxArtifactKey nextkey = conceptMap.higherKey(foundKey); - if (nextkey == null || !nextkey.getName().equals(conceptKeyName)) { - break; - } - foundKey = nextkey; - } while (true); - - return conceptMap.get(foundKey); - } - - /** - * {@inheritDoc}. - */ - @Override - public C get(final String conceptKeyName, final String conceptKeyVersion) { - Assertions.argumentNotNull(conceptKeyName, "conceptKeyName may not be null"); - - if (conceptKeyVersion != null) { - return conceptMap.get(new AxArtifactKey(conceptKeyName, conceptKeyVersion)); - } else { - return this.get(conceptKeyName); - } - } - - /** - * {@inheritDoc}. - */ - @Override - public Set<C> getAll(final String conceptKeyName) { - return getAll(conceptKeyName, null); - } - - /** - * {@inheritDoc}. - */ - @Override - public Set<C> getAll(final String conceptKeyName, final String conceptKeyVersion) { - final Set<C> returnSet = new TreeSet<>(); - - if (conceptKeyName == null) { - returnSet.addAll(conceptMap.values()); - return returnSet; - } - - // The very fist key that could have this name - final var lowestArtifactKey = new AxArtifactKey(conceptKeyName, "0.0.1"); - if (conceptKeyVersion != null) { - lowestArtifactKey.setVersion(conceptKeyVersion); - } - - // Check if we found a key for our name - AxArtifactKey foundKey = conceptMap.ceilingKey(lowestArtifactKey); - if (foundKey == null || !foundKey.getName().equals(conceptKeyName)) { - return returnSet; - } - returnSet.add(conceptMap.get(foundKey)); - - // Look for higher versions of the key - do { - foundKey = conceptMap.higherKey(foundKey); - if (foundKey == null || !foundKey.getName().equals(conceptKeyName)) { - break; - } - returnSet.add(conceptMap.get(foundKey)); - } while (true); - - return returnSet; - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKey.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKey.java deleted file mode 100644 index 1b6f0148f..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKey.java +++ /dev/null @@ -1,105 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.concepts; - -/** - * The key uniquely identifies every entity in the system. This class is an abstract class to give a common parent for - * all key types in the system. - */ -public abstract class AxKey extends AxConcept { - private static final long serialVersionUID = 6281159885962014041L; - - /** Regular expression to specify the structure of key names. */ - public static final String NAME_REGEXP = "[A-Za-z0-9\\-_\\.]+"; - - /** Regular expression to specify the structure of key versions. */ - public static final String VERSION_REGEXP = "[A-Za-z0-9.]+"; - - /** Regular expression to specify the structure of key IDs. */ - public static final String KEY_ID_REGEXP = "[A-Za-z0-9\\-_\\.]+:[0-9].[0-9].[0-9]"; - - /** Specifies the value for names in NULL keys. */ - public static final String NULL_KEY_NAME = "NULL"; - - /** Specifies the value for versions in NULL keys. */ - public static final String NULL_KEY_VERSION = "0.0.0"; - - /** - * This enumeration is returned on key compatibility checks. - */ - public enum Compatibility { - /** The keys have different names. */ - DIFFERENT, - /** - * The name of the key matches but the Major version number of the keys is different (x in x.y.z do not match). - */ - MAJOR, - /** - * The name of the key matches but the Minor version number of the keys is different (y in x.y.z do not match). - */ - MINOR, - /** - * The name of the key matches but the Patch version number of the keys is different (z in x.y.z do not match). - */ - PATCH, - /** The keys match completely. */ - IDENTICAL - } - - /** - * Default constructor. - */ - protected AxKey() { - super(); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - protected AxKey(final AxKey copyConcept) { - super(copyConcept); - } - - /** - * {@inheritDoc}. - */ - @Override - public abstract String getId(); - - /** - * Return the result of a compatibility check of two keys. - * - * @param otherKey the key to check compatibility against - * @return the compatibility result of the check - */ - public abstract Compatibility getCompatibility(AxKey otherKey); - - /** - * Check if two keys are compatible, that is the keys are IDENTICAL or have only MINOR, PATCH differences. - * - * @param otherKey the key to check compatibility against - * @return true, if the keys are compatible - */ - public abstract boolean isCompatible(AxKey otherKey); -} 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 deleted file mode 100644 index bd3b18ec9..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfo.java +++ /dev/null @@ -1,317 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2022 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.concepts; - -import com.google.gson.annotations.SerializedName; -import java.util.List; -import java.util.Random; -import java.util.UUID; -import org.apache.commons.lang3.StringUtils; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.common.utils.validation.Assertions; - -/** - * The key information on an {@link AxArtifactKey} key in an Apex policy model. Each {@link AxArtifactKey} must have an - * {@link AxKeyInfo} object. THe information held is the key's UUID and it's description. - * - * <p>Validation checks that all fields are defined and that the key is valid. It also observes that descriptions are - * blank and warns if the UUID is a zero UUID. - */ -public class AxKeyInfo extends AxConcept { - private static final long serialVersionUID = -4023935924068914308L; - - private static final int UUID_BYTE_LENGTH_16 = 16; - - /* - * This is not used for encryption/security, thus disabling sonar. - */ - private static final Random sharedRandom = new Random(); // NOSONAR - - private AxArtifactKey key; - - @SerializedName("UUID") - private UUID uuid; - - private String description; - - /** - * The Default Constructor creates this concept with a NULL artifact key. - */ - public AxKeyInfo() { - this(new AxArtifactKey()); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxKeyInfo(final AxKeyInfo copyConcept) { - super(copyConcept); - } - - /** - * Constructor to create this concept with the specified key. - * - * @param key the key of the concept - */ - public AxKeyInfo(final AxArtifactKey key) { - this(key, UUID.randomUUID(), "Generated description for concept referred to by key \"" + key.getId() + "\""); - } - - /** - * Constructor to create this concept and set all its fields. - * - * @param key the key of the concept - * @param uuid the UUID of the concept - * @param description the description of the concept - */ - public AxKeyInfo(final AxArtifactKey key, final UUID uuid, final String description) { - super(); - Assertions.argumentNotNull(key, "key may not be null"); - Assertions.argumentNotNull(uuid, "uuid may not be null"); - Assertions.argumentNotNull(description, "description may not be null"); - - this.key = key; - this.uuid = uuid; - this.description = description.trim(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxArtifactKey getKey() { - return key; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - return key.getKeys(); - } - - /** - * Sets the key of the concept. - * - * @param key the concept key - */ - public void setKey(final AxArtifactKey key) { - Assertions.argumentNotNull(key, "key may not be null"); - this.key = key; - } - - /** - * Gets the UUID of the concept. - * - * @return the uuid of the concept - */ - public UUID getUuid() { - return uuid; - } - - /** - * Sets the UUID of the concept. - * - * @param uuid the uuid of the concept - */ - public void setUuid(final UUID uuid) { - Assertions.argumentNotNull(uuid, "uuid may not be null"); - this.uuid = uuid; - } - - /** - * Gets the description of the concept. - * - * @return the description of the concept - */ - public String getDescription() { - return description; - } - - /** - * Sets the description of the concept. - * - * @param description the description of the concept - */ - public void setDescription(final String description) { - Assertions.argumentNotNull(description, "description may not be null"); - this.description = description.trim(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - if (key.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage( - new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); - - if (description.trim().length() == 0) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.OBSERVATION, - "description is blank")); - } - - if (uuid.equals(new UUID(0, 0))) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.WARNING, - "UUID is a zero UUID: " + new UUID(0, 0))); - } - - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - key.clean(); - description = description.trim(); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final var builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("artifactId="); - builder.append(key); - builder.append(",uuid="); - builder.append(uuid); - builder.append(",description="); - builder.append(description); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept target) { - Assertions.argumentNotNull(target, "target may not be null"); - - final Object copyObject = target; - Assertions.instanceOf(copyObject, AxKeyInfo.class); - - final AxKeyInfo copy = ((AxKeyInfo) copyObject); - copy.setKey(new AxArtifactKey(key)); - copy.setUuid(UUID.fromString(uuid.toString())); - copy.setDescription(description); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final var prime = 31; - var result = 1; - result = prime * result + key.hashCode(); - result = prime * result + uuid.hashCode(); - result = prime * result + description.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - - final AxKeyInfo other = (AxKeyInfo) obj; - if (!key.equals(other.key)) { - return false; - } - if (!uuid.equals(other.uuid)) { - return false; - } - return description.equals(description); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxKeyInfo other = (AxKeyInfo) otherObj; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - if (!uuid.equals(other.uuid)) { - return uuid.compareTo(other.uuid); - } - return description.compareTo(other.description); - } - - /** - * Generate a reproducible UUID for a given string seed. - * - * @param seed the seed - * @return the uuid - */ - public static UUID generateReproducibleUuid(final String seed) { - var random = sharedRandom; - if (!StringUtils.isEmpty(seed)) { - /* - * This is not used for encryption/security, thus disabling sonar. - */ - random = new Random(seed.hashCode()); // NOSONAR - } - 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 deleted file mode 100644 index 439b2960f..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInformation.java +++ /dev/null @@ -1,389 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2022 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.concepts; - -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.NavigableMap; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.UUID; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.common.utils.validation.Assertions; - -/** - * The Class AxKeyInformation holds a map of the key information for the entire Apex model. All Apex models - * {@link AxModel} must have an {@link AxKeyInformation} field. The {@link AxKeyInformation} class implements the helper - * methods of the {@link AxConceptGetter} interface to allow {@link AxKeyInfo} instances to be retrieved by calling - * methods directly on this class without referencing the contained map. - * - * <p>Validation checks that the key is not null, that the key information map is not empty, that each key and value in - * the map is defined, that the key in each map entry matches the key if each entry value, and that no duplicate UUIDs - * exist. Each key information entry is then validated individually. - */ -public class AxKeyInformation extends AxConcept implements AxConceptGetter<AxKeyInfo> { - private static final long serialVersionUID = -2746380769017043888L; - - private AxArtifactKey key; - private Map<AxArtifactKey, AxKeyInfo> keyInfoMap; - - /** - * The Default Constructor creates this concept with a null key. - */ - public AxKeyInformation() { - this(new AxArtifactKey()); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxKeyInformation(final AxKeyInformation copyConcept) { - super(copyConcept); - } - - /** - * Constructor to create this concept with the specified key. - * - * @param key the key of the concept - */ - public AxKeyInformation(final AxArtifactKey key) { - this(key, new TreeMap<>()); - } - - /** - * Constructor to create this concept and set all its fields. - * - * @param key the key of the concept - * @param keyInfoMap the key info map of the concept - */ - public AxKeyInformation(final AxArtifactKey key, final Map<AxArtifactKey, AxKeyInfo> keyInfoMap) { - super(); - Assertions.argumentNotNull(key, "key may not be null"); - Assertions.argumentNotNull(keyInfoMap, "keyInfoMap may not be null"); - - this.key = key; - this.keyInfoMap = new TreeMap<>(); - this.keyInfoMap.putAll(keyInfoMap); - } - - /** - * This method generates default key information for all keys found in the concept passed in as a parameter that do - * not already have key information. - * - * @param concept the concept for which to generate key information - */ - public void generateKeyInfo(final AxConcept concept) { - for (final AxKey axKey : concept.getKeys()) { - if (!(axKey instanceof AxArtifactKey)) { - continue; - } - - final AxArtifactKey artifactKey = (AxArtifactKey) axKey; - - keyInfoMap.computeIfAbsent(artifactKey, unusedKey -> { - final var keyInfo = new AxKeyInfo(artifactKey); - // generate a reproducible UUID - keyInfo.setUuid(AxKeyInfo.generateReproducibleUuid(keyInfo.getId() + keyInfo.getDescription())); - return keyInfo; - }); - } - } - - /** - * {@inheritDoc}. - */ - @Override - public AxArtifactKey getKey() { - return key; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - final List<AxKey> keyList = key.getKeys(); - keyList.addAll(keyInfoMap.keySet()); - - return keyList; - } - - /** - * {@inheritDoc}. - */ - @Override - public void buildReferences() { - keyInfoMap.values().stream().forEach(keyInfo -> keyInfo.buildReferences()); - } - - /** - * Sets the key of this concept. - * - * @param key the key of this concept - */ - public void setKey(final AxArtifactKey key) { - Assertions.argumentNotNull(key, "key may not be null"); - this.key = key; - } - - /** - * Gets the key info map of this concept. - * - * @return the key info map of this concept - */ - public Map<AxArtifactKey, AxKeyInfo> getKeyInfoMap() { - return keyInfoMap; - } - - /** - * Sets the key info map of this concept. - * - * @param keyInfoMap the key info map of this concept - */ - public void setKeyInfoMap(final Map<AxArtifactKey, AxKeyInfo> keyInfoMap) { - Assertions.argumentNotNull(keyInfoMap, "keyInfoMap may not be null"); - this.keyInfoMap = new TreeMap<>(); - this.keyInfoMap.putAll(keyInfoMap); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - if (key.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage( - new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); - - if (keyInfoMap.size() == 0) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "keyInfoMap may not be empty")); - } else { - final Set<UUID> uuidSet = new TreeSet<>(); - - for (final Entry<AxArtifactKey, AxKeyInfo> keyInfoEntry : keyInfoMap.entrySet()) { - result = validateKeyInfoEntry(keyInfoEntry, uuidSet, result); - } - } - - return result; - } - - /** - * Validate a key information entry. - * - * @param keyInfoEntry the key information entry - * @param uuidSet the set of UUIDs encountered in validation so far, the UUID of this entry is added to the set - * @param result the validation result to append to - * @return The validation result - */ - private AxValidationResult validateKeyInfoEntry(final Entry<AxArtifactKey, AxKeyInfo> keyInfoEntry, - final Set<UUID> uuidSet, AxValidationResult result) { - if (keyInfoEntry.getKey().equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on keyInfoMap entry " + keyInfoEntry.getKey() + " may not be the null key")); - } else if (keyInfoEntry.getValue() == null) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "value on keyInfoMap entry " + keyInfoEntry.getKey() + " may not be null")); - } else { - if (!keyInfoEntry.getKey().equals(keyInfoEntry.getValue().getKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on keyInfoMap entry " + keyInfoEntry.getKey() + " does not equal entry key " - + keyInfoEntry.getValue().getKey())); - } - - result = keyInfoEntry.getValue().validate(result); - - if (uuidSet.contains(keyInfoEntry.getValue().getUuid())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "duplicate UUID found on keyInfoMap entry " + keyInfoEntry.getKey() + ":" - + keyInfoEntry.getValue().getUuid())); - } else { - uuidSet.add(keyInfoEntry.getValue().getUuid()); - } - } - - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - key.clean(); - for (final Entry<AxArtifactKey, AxKeyInfo> keyInfoEntry : keyInfoMap.entrySet()) { - keyInfoEntry.getKey().clean(); - keyInfoEntry.getValue().clean(); - } - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final var builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("key="); - builder.append(key); - builder.append(",keyInfoMap="); - builder.append(keyInfoMap); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept target) { - Assertions.argumentNotNull(target, "target may not be null"); - - final Object copyObject = target; - Assertions.instanceOf(copyObject, AxKeyInformation.class); - - final AxKeyInformation copy = ((AxKeyInformation) copyObject); - copy.setKey(new AxArtifactKey(key)); - final Map<AxArtifactKey, AxKeyInfo> newKeyInfoMap = new TreeMap<>(); - for (final Entry<AxArtifactKey, AxKeyInfo> keyInfoMapEntry : keyInfoMap.entrySet()) { - newKeyInfoMap.put(new AxArtifactKey(keyInfoMapEntry.getKey()), new AxKeyInfo(keyInfoMapEntry.getValue())); - } - copy.setKeyInfoMap(newKeyInfoMap); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final var prime = 31; - var result = 1; - result = prime * result + key.hashCode(); - result = prime * result + keyInfoMap.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - - if (getClass() != obj.getClass()) { - return false; - } - - final AxKeyInformation other = (AxKeyInformation) obj; - if (!key.equals(other.key)) { - return false; - } - return keyInfoMap.equals(other.keyInfoMap); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxKeyInformation other = (AxKeyInformation) otherObj; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - if (!keyInfoMap.equals(other.keyInfoMap)) { - return (keyInfoMap.hashCode() - other.keyInfoMap.hashCode()); - } - - return 0; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxKeyInfo get(final AxArtifactKey conceptKey) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxKeyInfo>) keyInfoMap).get(conceptKey); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxKeyInfo get(final String conceptKeyName) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxKeyInfo>) keyInfoMap).get(conceptKeyName); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxKeyInfo get(final String conceptKeyName, final String conceptKeyVersion) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxKeyInfo>) keyInfoMap).get(conceptKeyName, - conceptKeyVersion); - } - - /** - * {@inheritDoc}. - */ - @Override - public Set<AxKeyInfo> getAll(final String conceptKeyName) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxKeyInfo>) keyInfoMap).getAll(conceptKeyName); - } - - /** - * {@inheritDoc}. - */ - @Override - public Set<AxKeyInfo> getAll(final String conceptKeyName, final String conceptKeyVersion) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxKeyInfo>) keyInfoMap).getAll(conceptKeyName, - conceptKeyVersion); - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUse.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUse.java deleted file mode 100644 index eb701e5b3..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUse.java +++ /dev/null @@ -1,221 +0,0 @@ -/*- - * ============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.concepts; - -import java.util.List; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.common.utils.validation.Assertions; - -/** - * This class records a usage of a key in the system. When the list of keys being used by a concept is built using the - * getKeys() method of the {@link AxConcept} class, an instance of this class is created for every key occurrence. The - * list of keys returned by the getKeys() method is a list of {@link AxKeyUse} objects. - * - * <p>Validation checks that each key is valid. - */ - -public class AxKeyUse extends AxKey { - private static final long serialVersionUID = 2007147220109881705L; - - private AxKey usedKey; - - /** - * The Default Constructor creates this concept with a null key. - */ - public AxKeyUse() { - this(new AxArtifactKey()); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxKeyUse(final AxKeyUse copyConcept) { - super(copyConcept); - } - - /** - * This constructor creates an instance of this class, and holds a reference to a used key. - * - * @param usedKey a used key - */ - public AxKeyUse(final AxKey usedKey) { - Assertions.argumentNotNull(usedKey, "usedKey may not be null"); - this.usedKey = usedKey; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxKey getKey() { - return usedKey; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - return usedKey.getKeys(); - } - - /** - * {@inheritDoc}. - */ - @Override - public String getId() { - return usedKey.getId(); - } - - /** - * Sets the key. - * - * @param key the key - */ - public void setKey(final AxKey key) { - Assertions.argumentNotNull(key, "usedKey may not be null"); - this.usedKey = key; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxKey.Compatibility getCompatibility(final AxKey otherKey) { - return usedKey.getCompatibility(otherKey); - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean isCompatible(final AxKey otherKey) { - return usedKey.isCompatible(otherKey); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult result) { - if (usedKey.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(usedKey, this.getClass(), ValidationResult.INVALID, - "usedKey is a null key")); - } - return usedKey.validate(result); - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - usedKey.clean(); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final var builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("usedKey="); - builder.append(usedKey); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept target) { - Assertions.argumentNotNull(target, "target may not be null"); - - final Object copyObject = target; - Assertions.instanceOf(copyObject, AxKeyUse.class); - - final AxKeyUse copy = ((AxKeyUse) copyObject); - try { - copy.usedKey = usedKey.getClass().getDeclaredConstructor().newInstance(); - } catch (final Exception e) { - throw new ApexRuntimeException("error copying concept key: " + e.getMessage(), e); - } - usedKey.copyTo(copy.usedKey); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final var prime = 31; - var result = 1; - result = prime * result + usedKey.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - throw new IllegalArgumentException("comparison object may not be null"); - } - - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - - final AxKeyUse other = (AxKeyUse) obj; - return usedKey.equals(other.usedKey); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - Assertions.argumentNotNull(otherObj, "comparison object may not be null"); - - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxKeyUse other = (AxKeyUse) otherObj; - - return usedKey.compareTo(other.usedKey); - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxModel.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxModel.java deleted file mode 100644 index ce52b147f..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxModel.java +++ /dev/null @@ -1,423 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2022 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.concepts; - -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.common.utils.validation.Assertions; - -/** - * This class is the base class for all models in Apex. All model classes inherit from this model so all models must - * have a key and have key information. - * - * <p>Validation checks that the model key is valid. It goes on to check for null keys and checks each key for - * uniqueness in the model. A check is carried out to ensure that an {@link AxKeyInfo} instance exists for every - * {@link AxArtifactKey} key. For each {@link AxReferenceKey} instance, a check is made that its parent and local name - * are nut null and that a {@link AxKeyInfo} entry exists for its parent. Then a check is made that each used - * {@link AxArtifactKey} and {@link AxReferenceKey} usage references a key that exists. Finally, a check is made to - * ensure that an {@link AxArtifactKey} instance exists for every {@link AxKeyInfo} instance. - */ -public class AxModel extends AxConcept { - private static final String IS_A_NULL_KEY = " is a null key"; - - private static final long serialVersionUID = -771659065637205430L; - - private AxArtifactKey key; - private AxKeyInformation keyInformation; - - /** - * The Default Constructor creates this concept with a NULL artifact key. - */ - public AxModel() { - this(new AxArtifactKey()); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxModel(final AxModel copyConcept) { - super(copyConcept); - } - - /** - * Constructor to create this concept with the specified key. - * - * @param key the key of this concept - */ - public AxModel(final AxArtifactKey key) { - this(key, new AxKeyInformation(new AxArtifactKey(key.getName() + "_KeyInfo", key.getVersion()))); - } - - /** - * Constructor to create this concept and set all its fields. - * - * @param key the key of this concept - * @param keyInformation the key information of this concept - */ - public AxModel(final AxArtifactKey key, final AxKeyInformation keyInformation) { - super(); - Assertions.argumentNotNull(key, "key may not be null"); - Assertions.argumentNotNull(keyInformation, "keyInformation may not be null"); - - this.key = key; - this.keyInformation = keyInformation; - } - - /** - * Registers this model with the {@link ModelService}. All models are registered with the model service so that - * models can be references from anywhere in the Apex system without being passed as references through deep call - * chains. - */ - public void register() { - ModelService.registerModel(AxKeyInformation.class, getKeyInformation()); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxArtifactKey getKey() { - return key; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - final List<AxKey> keyList = key.getKeys(); - - // We just add the key for the KeyInformation itself. We don't add the - // keys from key information because - // that is a list of key information for existing keys - keyList.add(keyInformation.getKey()); - - return keyList; - } - - /** - * Sets the key of this concept. - * - * @param key the key of this concept - */ - public void setKey(final AxArtifactKey key) { - Assertions.argumentNotNull(key, "key may not be null"); - this.key = key; - } - - /** - * Gets the key information of this concept. - * - * @return the key information of this concept - */ - public AxKeyInformation getKeyInformation() { - return keyInformation; - } - - /** - * Sets the key information of this concept. - * - * @param keyInformation the key information of this concept - */ - public void setKeyInformation(final AxKeyInformation keyInformation) { - Assertions.argumentNotNull(keyInformation, "keyInformation may not be null"); - this.keyInformation = keyInformation; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - if (key.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key is a null key")); - } - - result = key.validate(result); - result = keyInformation.validate(result); - - // Key consistency check - final Set<AxArtifactKey> artifactKeySet = new TreeSet<>(); - final Set<AxReferenceKey> referenceKeySet = new TreeSet<>(); - final Set<AxKeyUse> usedKeySet = new TreeSet<>(); - - for (final AxKey axKey : this.getKeys()) { - // Check for the two type of keys we have - if (axKey instanceof AxArtifactKey) { - result = validateArtifactKeyInModel((AxArtifactKey) axKey, artifactKeySet, result); - } else if (axKey instanceof AxReferenceKey) { - result = validateReferenceKeyInModel((AxReferenceKey) axKey, referenceKeySet, result); - } else { - // It must be an AxKeyUse, nothing else is legal - usedKeySet.add((AxKeyUse) axKey); - } - } - - // Check all reference keys have correct parent keys - for (final AxReferenceKey referenceKey : referenceKeySet) { - if (!artifactKeySet.contains(referenceKey.getParentArtifactKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "parent artifact key not found for reference key " + referenceKey)); - } - } - - result = validateKeyUses(usedKeySet, artifactKeySet, referenceKeySet, result); - - // Check key information for unused key information - for (final AxArtifactKey keyInfoKey : keyInformation.getKeyInfoMap().keySet()) { - if (!artifactKeySet.contains(keyInfoKey)) { - result.addValidationMessage(new AxValidationMessage(keyInfoKey, this.getClass(), - ValidationResult.WARNING, "key not found for key information entry")); - } - } - - return result; - } - - /** - * Check for consistent usage of an artifact key in the model. - * - * @param artifactKey The artifact key to check - * @param artifactKeySet The set of artifact keys encountered so far, this key is appended to the set - * @param result The validation result to append to - * @return the result of the validation - */ - private AxValidationResult validateArtifactKeyInModel(final AxArtifactKey artifactKey, - final Set<AxArtifactKey> artifactKeySet, final AxValidationResult result) { - // Null key check - if (artifactKey.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key " + artifactKey + IS_A_NULL_KEY)); - } - - // Null key name start check - if (artifactKey.getName().toUpperCase().startsWith(AxKey.NULL_KEY_NAME)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key " + artifactKey + " name starts with keyword " + AxKey.NULL_KEY_NAME)); - } - - // Unique key check - if (artifactKeySet.contains(artifactKey)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "duplicate key " + artifactKey + " found")); - } else { - artifactKeySet.add(artifactKey); - } - - // Key information check - if (!keyInformation.getKeyInfoMap().containsKey(artifactKey)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key information not found for key " + artifactKey)); - } - - return result; - } - - /** - * Check for consistent usage of a reference key in the model. - * - * @param referenceKey The reference key to check - * @param referenceKeySet The set of reference keys encountered so far, this key is appended to the set - * @param result The validation result to append to - * @return the result of the validation - */ - private AxValidationResult validateReferenceKeyInModel(final AxReferenceKey referenceKey, - final Set<AxReferenceKey> referenceKeySet, final AxValidationResult result) { - // Null key check - if (referenceKey.equals(AxReferenceKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key " + referenceKey + IS_A_NULL_KEY)); - } - - // Null parent key check - if (referenceKey.getParentArtifactKey().equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "parent artifact key of key " + referenceKey + IS_A_NULL_KEY)); - } - - // Null local name check - if (referenceKey.getLocalName().equals(AxKey.NULL_KEY_NAME)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key " + referenceKey + " has a null local name")); - } - - // Null key name start check - if (referenceKey.getParentArtifactKey().getName().toUpperCase().startsWith(AxKey.NULL_KEY_NAME)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key " + referenceKey + " parent name starts with keyword " + AxKey.NULL_KEY_NAME)); - } - - // Unique key check - if (referenceKeySet.contains(referenceKey)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "duplicate key " + referenceKey + " found")); - } else { - referenceKeySet.add(referenceKey); - } - - // Key information check - if (!keyInformation.getKeyInfoMap().containsKey(referenceKey.getParentArtifactKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key information not found for parent key of key " + referenceKey)); - } - - return result; - } - - /** - * Check for consistent usage of cross-key references in the model. - * - * @param usedKeySet The set of all keys used in the model - * @param artifactKeySet The set of artifact keys encountered so far, this key is appended to the set - * @param referenceKeySet The set of reference keys encountered so far, this key is appended to the set - * @param result The validation result to append to - * @return the result of the validation - */ - private AxValidationResult validateKeyUses(final Set<AxKeyUse> usedKeySet, final Set<AxArtifactKey> artifactKeySet, - final Set<AxReferenceKey> referenceKeySet, final AxValidationResult result) { - // Check all key uses - for (final AxKeyUse usedKey : usedKeySet) { - if (usedKey.getKey() instanceof AxArtifactKey) { - // AxArtifact key usage, check the key exists - if (!artifactKeySet.contains(usedKey.getKey())) { - result.addValidationMessage(new AxValidationMessage(usedKey.getKey(), this.getClass(), - ValidationResult.INVALID, "an artifact key used in the model is not defined")); - } - } else { - // AxReference key usage, check the key exists - if (!referenceKeySet.contains(usedKey.getKey())) { - result.addValidationMessage(new AxValidationMessage(usedKey.getKey(), this.getClass(), - ValidationResult.INVALID, "a reference key used in the model is not defined")); - } - } - } - - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - key.clean(); - keyInformation.clean(); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final var builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("key="); - builder.append(key); - builder.append(",keyInformation="); - builder.append(keyInformation); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept target) { - Assertions.argumentNotNull(target, "target may not be null"); - - final Object copyObject = target; - Assertions.instanceOf(copyObject, AxModel.class); - - final AxModel copy = ((AxModel) copyObject); - copy.setKey(new AxArtifactKey(key)); - copy.setKeyInformation(new AxKeyInformation(keyInformation)); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final var prime = 31; - var result = 1; - result = prime * result + key.hashCode(); - result = prime * result + keyInformation.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - - final AxModel other = (AxModel) obj; - if (!key.equals(other.key)) { - return false; - } - return keyInformation.equals(other.keyInformation); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxModel other = (AxModel) otherObj; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - return keyInformation.compareTo(other.keyInformation); - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKey.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKey.java deleted file mode 100644 index b37bc47e4..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKey.java +++ /dev/null @@ -1,527 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2022 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.concepts; - -import java.util.ArrayList; -import java.util.List; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.common.utils.validation.Assertions; - -/** - * A reference key identifies entities in the system that are contained in other entities. Every contained concept in - * the system must have an {@link AxReferenceKey} to identify it. Non-contained first order concepts are identified - * using an {@link AxArtifactKey} key. - * - * <p>An {@link AxReferenceKey} contains an {@link AxArtifactKey} key reference to the first order entity that contains - * it. The local name of the reference key must uniquely identify the referenced concept among those concepts contained - * in the reference key's parent. In other words, if a parent concept has more than one child, the local name in the key - * of all its children must be unique. - * - * <p>If a reference key's parent is itself a reference key, then the parent's local name must be set in the reference - * key. If the parent is a first order concept, then the parent's local name in the key will be set to NULL. - * - * <p>Key validation checks that the parent name and parent version fields match the NAME_REGEXP and - * VERSION_REGEXP regular expressions respectively and that the local name fields match the - * LOCAL_NAME_REGEXP regular expression. - */ -public class AxReferenceKey extends AxKey { - private static final String PARENT_KEY_NAME = "parentKeyName"; - private static final String PARENT_KEY_VERSION = "parentKeyVersion"; - private static final String PARENT_LOCAL_NAME = "parentLocalName"; - private static final String LOCAL_NAME = "localName"; - - private static final long serialVersionUID = 8932717618579392561L; - - /** - * Regular expression to specify the structure of local names in reference keys. - */ - public static final String LOCAL_NAME_REGEXP = "[A-Za-z0-9\\-_\\.]+|^$"; - - /** - * Regular expression to specify the structure of IDs in reference keys. - */ - public static final String REFERENCE_KEY_ID_REGEXP = - "[A-Za-z0-9\\-_]+:[0-9].[0-9].[0-9]:[A-Za-z0-9\\-_]+:[A-Za-z0-9\\-_]+"; - - private static final int PARENT_NAME_FIELD = 0; - private static final int PARENT_VERSION_FIELD = 1; - private static final int PARENT_LOCAL_NAME_FIELD = 2; - private static final int LOCAL_NAME_FIELD = 3; - - private String parentKeyName; - private String parentKeyVersion; - private String parentLocalName; - private String localName; - - /** - * The default constructor creates a null reference key. - */ - public AxReferenceKey() { - this(NULL_KEY_NAME, NULL_KEY_VERSION, NULL_KEY_NAME, NULL_KEY_NAME); - } - - /** - * The Copy Constructor creates a key by copying another key. - * - * @param referenceKey the reference key to copy from - */ - public AxReferenceKey(final AxReferenceKey referenceKey) { - this(referenceKey.getParentKeyName(), referenceKey.getParentKeyVersion(), referenceKey.getParentLocalName(), - referenceKey.getLocalName()); - } - - /** - * Constructor to create a null reference key for the specified parent artifact key. - * - * @param axArtifactKey the parent artifact key of this reference key - */ - public AxReferenceKey(final AxArtifactKey axArtifactKey) { - this(axArtifactKey.getName(), axArtifactKey.getVersion(), NULL_KEY_NAME, NULL_KEY_NAME); - } - - /** - * Constructor to create a reference key for the given parent artifact key with the given local name. - * - * @param axArtifactKey the parent artifact key of this reference key - * @param localName the local name of this reference key - */ - public AxReferenceKey(final AxArtifactKey axArtifactKey, final String localName) { - this(axArtifactKey, NULL_KEY_NAME, localName); - } - - /** - * Constructor to create a reference key for the given parent reference key with the given local name. - * - * @param parentReferenceKey the parent reference key of this reference key - * @param localName the local name of this reference key - */ - public AxReferenceKey(final AxReferenceKey parentReferenceKey, final String localName) { - this(parentReferenceKey.getParentArtifactKey(), parentReferenceKey.getLocalName(), localName); - } - - /** - * Constructor to create a reference key for the given parent reference key (specified by the parent reference key's - * artifact key and local name) with the given local name. - * - * @param axArtifactKey the artifact key of the parent reference key of this reference key - * @param parentLocalName the local name of the parent reference key of this reference key - * @param localName the local name of this reference key - */ - public AxReferenceKey(final AxArtifactKey axArtifactKey, final String parentLocalName, final String localName) { - this(axArtifactKey.getName(), axArtifactKey.getVersion(), parentLocalName, localName); - } - - /** - * Constructor to create a reference key for the given parent artifact key (specified by the parent artifact key's - * name and version) with the given local name. - * - * @param parentKeyName the name of the parent artifact key of this reference key - * @param parentKeyVersion the version of the parent artifact key of this reference key - * @param localName the local name of this reference key - */ - public AxReferenceKey(final String parentKeyName, final String parentKeyVersion, final String localName) { - this(parentKeyName, parentKeyVersion, NULL_KEY_NAME, localName); - } - - /** - * Constructor to create a reference key for the given parent key (specified by the parent key's name, version nad - * local name) with the given local name. - * - * @param parentKeyName the parent key name of this reference key - * @param parentKeyVersion the parent key version of this reference key - * @param parentLocalName the parent local name of this reference key - * @param localName the local name of this reference key - */ - public AxReferenceKey(final String parentKeyName, final String parentKeyVersion, final String parentLocalName, - final String localName) { - super(); - this.parentKeyName = Assertions.validateStringParameter(PARENT_KEY_NAME, parentKeyName, NAME_REGEXP); - this.parentKeyVersion = Assertions.validateStringParameter(PARENT_KEY_VERSION, parentKeyVersion, - VERSION_REGEXP); - this.parentLocalName = Assertions.validateStringParameter(PARENT_LOCAL_NAME, parentLocalName, - LOCAL_NAME_REGEXP); - this.localName = Assertions.validateStringParameter(LOCAL_NAME, localName, LOCAL_NAME_REGEXP); - } - - /** - * Constructor to create a key from the specified key ID. - * - * @param id the key ID in a format that respects the KEY_ID_REGEXP - */ - public AxReferenceKey(final String id) { - final var conditionedId = Assertions.validateStringParameter("id", id, REFERENCE_KEY_ID_REGEXP); - - // Split on colon, if the id passes the regular expression test above - // it'll have just three colons separating the parent name, - // parent version, parent local name, and and local name - // No need for range checks or size checks on the array - final String[] nameVersionNameArray = conditionedId.split(":"); - - // Initiate the new key - parentKeyName = Assertions.validateStringParameter(PARENT_KEY_NAME, nameVersionNameArray[PARENT_NAME_FIELD], - NAME_REGEXP); - parentKeyVersion = Assertions.validateStringParameter(PARENT_KEY_VERSION, - nameVersionNameArray[PARENT_VERSION_FIELD], VERSION_REGEXP); - parentLocalName = Assertions.validateStringParameter(PARENT_LOCAL_NAME, - nameVersionNameArray[PARENT_LOCAL_NAME_FIELD], LOCAL_NAME_REGEXP); - localName = Assertions.validateStringParameter(LOCAL_NAME, nameVersionNameArray[LOCAL_NAME_FIELD], - LOCAL_NAME_REGEXP); - } - - /** - * Get a null reference key. - * - * @return a null reference key - */ - public static AxReferenceKey getNullKey() { - return new AxReferenceKey(AxKey.NULL_KEY_NAME, AxKey.NULL_KEY_VERSION, AxKey.NULL_KEY_NAME, - AxKey.NULL_KEY_NAME); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxReferenceKey getKey() { - return this; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - final List<AxKey> keyList = new ArrayList<>(); - keyList.add(getKey()); - return keyList; - } - - /** - * {@inheritDoc}. - */ - @Override - public String getId() { - return parentKeyName + ':' + parentKeyVersion + ':' + parentLocalName + ':' + localName; - } - - /** - * Gets the parent artifact key of this reference key. - * - * @return the parent artifact key of this reference key - */ - public AxArtifactKey getParentArtifactKey() { - return new AxArtifactKey(parentKeyName, parentKeyVersion); - } - - /** - * Gets the parent reference key of this reference key. - * - * @return the parent reference key of this reference key - */ - public AxReferenceKey getParentReferenceKey() { - return new AxReferenceKey(parentKeyName, parentKeyVersion, parentLocalName); - } - - /** - * Sets the parent artifact key of this reference key. - * - * @param parentKey the parent artifact key of this reference key - */ - public void setParentArtifactKey(final AxArtifactKey parentKey) { - Assertions.argumentNotNull(parentKey, "parentKey may not be null"); - - parentKeyName = parentKey.getName(); - parentKeyVersion = parentKey.getVersion(); - parentLocalName = NULL_KEY_NAME; - } - - /** - * Sets the parent reference key of this reference key. - * - * @param parentKey the parent reference key of this reference key - */ - public void setParentReferenceKey(final AxReferenceKey parentKey) { - Assertions.argumentNotNull(parentKey, "parentKey may not be null"); - - parentKeyName = parentKey.getParentKeyName(); - parentKeyVersion = parentKey.getParentKeyVersion(); - parentLocalName = parentKey.getLocalName(); - } - - /** - * Gets the parent key name of this reference key. - * - * @return the parent key name of this reference key - */ - public String getParentKeyName() { - return parentKeyName; - } - - /** - * Sets the parent key name of this reference key. - * - * @param parentKeyName the parent key name of this reference key - */ - public void setParentKeyName(final String parentKeyName) { - this.parentKeyName = Assertions.validateStringParameter(PARENT_KEY_NAME, parentKeyName, NAME_REGEXP); - } - - /** - * Gets the parent key version of this reference key. - * - * @return the parent key version of this reference key - */ - public String getParentKeyVersion() { - return parentKeyVersion; - } - - /** - * Sets the parent key version of this reference key. - * - * @param parentKeyVersion the parent key version of this reference key - */ - public void setParentKeyVersion(final String parentKeyVersion) { - this.parentKeyVersion = Assertions.validateStringParameter(PARENT_KEY_VERSION, parentKeyVersion, - VERSION_REGEXP); - } - - /** - * Gets the parent local name of this reference key. - * - * @return the parent local name of this reference key - */ - public String getParentLocalName() { - return parentLocalName; - } - - /** - * Sets the parent local name of this reference key. - * - * @param parentLocalName the parent local name of this reference key - */ - public void setParentLocalName(final String parentLocalName) { - this.parentLocalName = Assertions.validateStringParameter(PARENT_LOCAL_NAME, parentLocalName, - LOCAL_NAME_REGEXP); - } - - /** - * Gets the local name of this reference key. - * - * @return the local name of this reference key - */ - public String getLocalName() { - return localName; - } - - /** - * Sets the local name of this reference key. - * - * @param localName the local name of this reference key - */ - public void setLocalName(final String localName) { - this.localName = Assertions.validateStringParameter(LOCAL_NAME, localName, LOCAL_NAME_REGEXP); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxKey.Compatibility getCompatibility(final AxKey otherKey) { - if (!(otherKey instanceof AxReferenceKey)) { - return Compatibility.DIFFERENT; - } - final AxReferenceKey otherReferenceKey = (AxReferenceKey) otherKey; - - return this.getParentArtifactKey().getCompatibility(otherReferenceKey.getParentArtifactKey()); - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean isCompatible(final AxKey otherKey) { - if (!(otherKey instanceof AxReferenceKey)) { - return false; - } - final AxReferenceKey otherReferenceKey = (AxReferenceKey) otherKey; - - return this.getParentArtifactKey().isCompatible(otherReferenceKey.getParentArtifactKey()); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult result) { - final var parentNameValidationErrorMessage = Assertions.getStringParameterValidationMessage(PARENT_KEY_NAME, - parentKeyName, NAME_REGEXP); - if (parentNameValidationErrorMessage != null) { - result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID, - "parentKeyName invalid-" + parentNameValidationErrorMessage)); - } - - final var parentKeyVersionValidationErrorMessage = Assertions - .getStringParameterValidationMessage(PARENT_KEY_VERSION, parentKeyVersion, VERSION_REGEXP); - if (parentKeyVersionValidationErrorMessage != null) { - result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID, - "parentKeyVersion invalid-" + parentKeyVersionValidationErrorMessage)); - } - - final var parentLocalNameValidationErrorMessage = Assertions - .getStringParameterValidationMessage(PARENT_LOCAL_NAME, parentLocalName, LOCAL_NAME_REGEXP); - if (parentLocalNameValidationErrorMessage != null) { - result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID, - "parentLocalName invalid-" + parentLocalNameValidationErrorMessage)); - } - - final var localNameValidationErrorMessage = Assertions.getStringParameterValidationMessage(LOCAL_NAME, - localName, LOCAL_NAME_REGEXP); - if (localNameValidationErrorMessage != null) { - result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID, - "localName invalid-" + localNameValidationErrorMessage)); - } - - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - parentKeyName = Assertions.validateStringParameter(PARENT_KEY_NAME, parentKeyName, NAME_REGEXP); - parentKeyVersion = Assertions.validateStringParameter(PARENT_KEY_VERSION, parentKeyVersion, VERSION_REGEXP); - parentLocalName = Assertions.validateStringParameter(PARENT_LOCAL_NAME, parentLocalName, LOCAL_NAME_REGEXP); - localName = Assertions.validateStringParameter(LOCAL_NAME, localName, LOCAL_NAME_REGEXP); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final var builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("parentKeyName="); - builder.append(parentKeyName); - builder.append(",parentKeyVersion="); - builder.append(parentKeyVersion); - builder.append(",parentLocalName="); - builder.append(parentLocalName); - builder.append(",localName="); - builder.append(localName); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept target) { - Assertions.argumentNotNull(target, "target may not be null"); - - final Object copyObject = target; - Assertions.instanceOf(copyObject, AxReferenceKey.class); - - final AxReferenceKey copy = ((AxReferenceKey) copyObject); - copy.setParentKeyName(parentKeyName); - copy.setParentKeyVersion(parentKeyVersion); - copy.setLocalName(localName); - copy.setParentLocalName(parentLocalName); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final var prime = 31; - var result = 1; - result = prime * result + parentKeyName.hashCode(); - result = prime * result + parentKeyVersion.hashCode(); - result = prime * result + parentLocalName.hashCode(); - result = prime * result + localName.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - throw new IllegalArgumentException("comparison object may not be null"); - } - - if (this == obj) { - return true; - } - - if (getClass() != obj.getClass()) { - return false; - } - - final AxReferenceKey other = (AxReferenceKey) obj; - - if (!parentKeyName.equals(other.parentKeyName)) { - return false; - } - if (!parentKeyVersion.equals(other.parentKeyVersion)) { - return false; - } - if (!parentLocalName.equals(other.parentLocalName)) { - return false; - } - return localName.equals(other.localName); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - Assertions.argumentNotNull(otherObj, "comparison object may not be null"); - - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxReferenceKey other = (AxReferenceKey) otherObj; - if (!parentKeyName.equals(other.parentKeyName)) { - return parentKeyName.compareTo(other.parentKeyName); - } - if (!parentKeyVersion.equals(other.parentKeyVersion)) { - return parentKeyVersion.compareTo(other.parentKeyVersion); - } - if (!parentLocalName.equals(other.parentLocalName)) { - return parentLocalName.compareTo(other.parentLocalName); - } - return localName.compareTo(other.localName); - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxToscaPolicyProcessingStatus.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxToscaPolicyProcessingStatus.java deleted file mode 100644 index 43c7e7866..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxToscaPolicyProcessingStatus.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada. All rights reserved. - * ================================================================================ - * 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.concepts; - -/** - * This enumeration indicates the status of TOSCA policy processing on an APEX event. - */ -public enum AxToscaPolicyProcessingStatus { - - /** Indicates the entrypoint for the processing of a TOSCA Policy. */ - ENTRY(0), - - /** Indicates a successful exit point for a TOSCA Policy. */ - EXIT_SUCCESS(1), - - /** Indicates a failure exit point for a TOSCA Policy. */ - EXIT_FAILURE(2); - - private final int statusCode; - - AxToscaPolicyProcessingStatus(int statusCode) { - this.statusCode = statusCode; - } - - public int getStatusCode() { - return statusCode; - } -}
\ No newline at end of file diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxValidationMessage.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxValidationMessage.java deleted file mode 100644 index 9e245c07b..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxValidationMessage.java +++ /dev/null @@ -1,104 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 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.concepts; - -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.common.utils.validation.Assertions; - -/** - * A validation message is created for each validation observation observed during validation of a concept. The message - * holds the key and the class of the concept on which the observation was made as well as the type of observation and a - * message describing the observation. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class AxValidationMessage { - private final AxKey observedKey; - private ValidationResult validationResult = ValidationResult.VALID; - private final String observedClass; - private final String message; - - /** - * Create an validation observation with the given fields. - * - * @param observedKey the key of the class on which the validation observation was made - * @param observedClass the class on which the validation observation was made - * @param validationResult the type of observation made - * @param message a message describing the observation - */ - public AxValidationMessage(final AxKey observedKey, final Class<?> observedClass, - final ValidationResult validationResult, final String message) { - Assertions.argumentNotNull(observedKey, "observedKey may not be null"); - Assertions.argumentNotNull(observedClass, "observedClass may not be null"); - Assertions.argumentNotNull(validationResult, "validationResult may not be null"); - Assertions.argumentNotNull(message, "message may not be null"); - - this.observedKey = observedKey; - this.observedClass = observedClass.getName(); - this.validationResult = validationResult; - this.message = message; - } - - /** - * Gets the key of the observation. - * - * @return the key of the observation - */ - public AxKey getObservedKey() { - return observedKey; - } - - /** - * Gets the observed class. - * - * @return the observed class - */ - public String getObservedClass() { - return observedClass; - } - - /** - * Gets the type of observation made. - * - * @return the type of observation made - */ - public ValidationResult getValidationResult() { - return validationResult; - } - - /** - * Get a description of the observation. - * - * @return the observation description - */ - public String getMessage() { - return message; - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - return observedKey.toString() + ':' + observedClass + ':' + validationResult.name() + ':' + message; - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxValidationResult.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxValidationResult.java deleted file mode 100644 index 10ccb30aa..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/AxValidationResult.java +++ /dev/null @@ -1,150 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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.concepts; - -import java.util.LinkedList; -import java.util.List; - -/** - * This class records the result of a validation and holds all validatino observation messages. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class AxValidationResult { - /** - * The ValidationResult enumeration describes the severity of a validation result. - */ - public enum ValidationResult { - /** No problems or observations were detected during validation. */ - VALID, - /** - * Observations were made on a concept (such as blank descriptions) of a nature that will not affect the use of - * the concept. - */ - OBSERVATION, - /** - * Warnings were made on a concept (such as defined but unused concepts) of a nature that may affect the use of - * the concept. - */ - WARNING, - /** - * Errors were detected on a concept (such as referenced but undefined concepts) of a nature that will affect - * the use of the concept. - */ - INVALID - } - - // The actual verification result - private ValidationResult validationResult = ValidationResult.VALID; - - // Messages collected during the verification process - private final List<AxValidationMessage> messageList = new LinkedList<>(); - - /** - * Check if a validation reported a valid concept, returns true if the model is usable (that is, even if the model - * has warnings or observations). - * - * @return true, if the concept is reported as valid and can be used - */ - public boolean isValid() { - return validationResult != ValidationResult.INVALID; - } - - /** - * Check if a validation reported a concept with no errors or warnings, returns true if the model is OK to use. - * - * @return true, if the concept has no warnings or errors - */ - public boolean isOk() { - return validationResult == ValidationResult.VALID || validationResult == ValidationResult.OBSERVATION; - } - - /** - * Gets the validation result. - * - * @return the validation result on a concept - */ - public ValidationResult getValidationResult() { - return validationResult; - } - - /** - * Gets the list of validation results on the concept. - * - * @return the list of validaiton results - */ - public List<AxValidationMessage> getMessageList() { - return messageList; - } - - /** - * Adds a validation message to the validation result, used by validate() implementations on {@link AxConcept} - * subclasses to report validaiton observations. - * - * @param validationMessage the validation message - */ - public void addValidationMessage(final AxValidationMessage validationMessage) { - messageList.add(validationMessage); - - // Check if the incoming message has a more sever status than the - // current one on the overall validation result, - // if so, the overall result goes to that level - if (validationMessage.getValidationResult().ordinal() > validationResult.ordinal()) { - validationResult = validationMessage.getValidationResult(); - } - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - - switch (validationResult) { - case VALID: - - builder.append("***validation of model successful***"); - return builder.toString(); - case OBSERVATION: - - builder.append("\n***observations noted during validation of model***\n"); - break; - case WARNING: - - builder.append("\n***warnings issued during validation of model***\n"); - break; - case INVALID: - builder.append("\n***validation of model failed***\n"); - break; - default: - break; - } - - for (final AxValidationMessage message : messageList) { - builder.append(message); - builder.append("\n"); - } - - builder.append("********************************"); - return builder.toString(); - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/package-info.java deleted file mode 100644 index 347e46a0f..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/concepts/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2022 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========================================================= - */ - -/** - * This package contains the fundamental concepts for all APEX models. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -package org.onap.policy.apex.model.basicmodel.concepts; diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCreator.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCreator.java deleted file mode 100644 index a33e1bf1a..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCreator.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 org.onap.policy.apex.model.basicmodel.concepts.AxModel; - -/** - * This interface is implemented by factories that create Apex models. It is mainly used by unit test classes that - * generate Apex models for test purposes. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - * @param <M> the type of Apex model to create, must be a sub class of {@link AxModel} - */ -@FunctionalInterface -public interface ApexModelCreator<M extends AxModel> { - - /** - * Gets the model created by the model creator. - * - * @return the model created by the model creator - */ - M getModel(); -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonMapAdapter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonMapAdapter.java deleted file mode 100644 index cb67590f7..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonMapAdapter.java +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2022 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 com.google.gson.JsonArray; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.AbstractMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TreeMap; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -@SuppressWarnings("rawtypes") -public class ApexModelCustomGsonMapAdapter implements JsonSerializer<Map>, JsonDeserializer<Map> { - private static final String MAP_ENTRY_KEY = "entry"; - - @SuppressWarnings("unchecked") - @Override - public Map deserialize(JsonElement jsonElement, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { - - if (!(jsonElement instanceof JsonObject)) { - throw new JsonParseException("could not parse JSON map, map is not a JsonObject"); - } - - JsonObject jsonObject = (JsonObject) jsonElement; - - if (jsonObject.size() != 1) { - throw new JsonParseException("could not parse JSON map, map must be in a JsonObject with a single member"); - } - - JsonArray mapEntryArray = (JsonArray) jsonObject.get(MAP_ENTRY_KEY); - if (mapEntryArray == null) { - throw new JsonParseException("could not parse JSON map, map \"entry\" in JsonObject not found"); - } - - return new TreeMap( - StreamSupport - .stream(mapEntryArray.spliterator(), true) - .map(element -> deserializeMapEntry(element, typeOfT, context)) - .collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue())) - ); - } - - @Override - public JsonElement serialize(Map sourceMap, Type typeOfSrc, JsonSerializationContext context) { - - // A map is stored in a JsonArray - JsonArray mapEntryArray = new JsonArray(); - - for (Object mapEntryObject : sourceMap.entrySet()) { - Entry mapEntry = (Entry) mapEntryObject; - mapEntryArray.add(serializeMapEntry(mapEntry, typeOfSrc, context)); - } - - JsonObject returnObject = new JsonObject(); - returnObject.add(MAP_ENTRY_KEY, mapEntryArray); - - return returnObject; - } - - @SuppressWarnings("unchecked") - private static Entry deserializeMapEntry(JsonElement element, Type typeOfT, JsonDeserializationContext context) { - // Get the types of the map - ParameterizedType pt = (ParameterizedType) typeOfT; - - // Type of the key and value of the map - Type keyType = pt.getActualTypeArguments()[0]; - Type valueType = pt.getActualTypeArguments()[1]; - - // Deserialize the key and value - return new AbstractMap.SimpleEntry( - context.deserialize(element.getAsJsonObject().get("key"), keyType), - context.deserialize(element.getAsJsonObject().get("value"), valueType)); - } - - private static JsonElement serializeMapEntry(Entry sourceEntry, Type typeOfSrc, JsonSerializationContext context) { - // Get the types of the map - ParameterizedType pt = (ParameterizedType) typeOfSrc; - - // Type of the key and value of the map - Type keyType = pt.getActualTypeArguments()[0]; - Type valueType = pt.getActualTypeArguments()[1]; - - JsonObject entryObject = new JsonObject(); - entryObject.add("key", context.serialize(sourceEntry.getKey(), keyType)); - entryObject.add("value", context.serialize(sourceEntry.getValue(), valueType)); - - return entryObject; - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonRefereceKeyAdapter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonRefereceKeyAdapter.java deleted file mode 100644 index d731c8689..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelCustomGsonRefereceKeyAdapter.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2022 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 com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import java.lang.reflect.Type; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; - -public class ApexModelCustomGsonRefereceKeyAdapter implements JsonDeserializer<AxReferenceKey> { - - @Override - public AxReferenceKey deserialize(JsonElement jsonElement, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { - - if (jsonElement instanceof JsonObject) { - return new AxReferenceKey( - jsonElement.getAsJsonObject().get("parentKeyName").getAsString(), - jsonElement.getAsJsonObject().get("parentKeyVersion").getAsString(), - jsonElement.getAsJsonObject().get("parentLocalName").getAsString(), - jsonElement.getAsJsonObject().get("localName").getAsString() - ); - } else { - AxReferenceKey returnKey = new AxReferenceKey(); - returnKey.setLocalName(jsonElement.getAsString()); - return returnKey; - } - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelException.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelException.java deleted file mode 100644 index 17eb2639d..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelException.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 org.onap.policy.apex.model.basicmodel.concepts.ApexException; - -/** - * This exception is invoked if an exception occurs in model handling. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexModelException extends ApexException { - private static final long serialVersionUID = -4245694568321686450L; - - /** - * Instantiates a new apex model handling exception. - * - * @param message the message - */ - public ApexModelException(final String message) { - super(message); - } - - /** - * Instantiates a new apex model handling exception. - * - * @param message the message - * @param exception the exception - */ - public ApexModelException(final String message, final Exception exception) { - super(message, exception); - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java deleted file mode 100644 index 54b5651cc..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriter.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2021-2022 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 java.io.File; -import java.io.FileOutputStream; -import lombok.Getter; -import lombok.Setter; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class writes an Apex model to a file. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - * @param <M> the type of Apex model to write to file, must be a sub class of {@link AxModel} - */ -@Getter -@Setter -public class ApexModelFileWriter<M extends AxModel> { - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelFileWriter.class); - - // Should models being written to files be valid - private boolean validate; - - /** - * Constructor, set the validation flag. - * - * @param validate indicates if validation be performed prior to output - */ - public ApexModelFileWriter(final boolean validate) { - this.validate = validate; - } - - /** - * Write a model to an JSON file. - * - * @param model The model to write - * @param rootModelClass The concept class - * @param modelFileName The name of the file to write to - * @throws ApexException thrown on errors - */ - public void apexModelWriteJsonFile(final M model, final Class<M> rootModelClass, final String modelFileName) - throws ApexException { - LOGGER.debug("running apexModelWriteJSONFile . . ."); - - final ApexModelWriter<M> modelWriter = new ApexModelWriter<>(rootModelClass); - modelWriter.setValidate(validate); - - writeModelFile(model, modelWriter, modelFileName); - - LOGGER.debug("ran apexModelWriteJSONFile"); - } - - /** - * Write a model to a file using a model writer. - * - * @param model The model to write - * @param modelWriter the model writer to use to write the model to the file - * @param modelFileName the file name of the file to write to - * @throws ApexException on exceptions writing the model - */ - private void writeModelFile(final M model, final ApexModelWriter<M> modelWriter, final String modelFileName) - throws ApexException { - 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 var fileOutputStream = new FileOutputStream(modelFile)) { - modelWriter.write(model, fileOutputStream); - } 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 deleted file mode 100644 index a9bd2fe60..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReader.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2022 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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 com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.Map; -import lombok.Getter; -import lombok.Setter; -import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.common.utils.resources.TextFileUtils; -import org.onap.policy.common.utils.validation.Assertions; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class reads an Apex concept from a file into a Java Apex Concept {@link AxConcept}. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - * @param <C> the type of Apex concept to read, must be a sub class of {@link AxConcept} - */ -@Getter -@Setter -public class ApexModelReader<C extends AxConcept> { - // Get a reference to the logger - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelReader.class); - - // Use GSON to deserialize JSON - private static Gson gson = new GsonBuilder() - .registerTypeAdapter(AxReferenceKey.class, new ApexModelCustomGsonRefereceKeyAdapter()) - .registerTypeAdapter(Map.class, new ApexModelCustomGsonMapAdapter()) - .setPrettyPrinting() - .create(); - - // Â The root class of the concept we are reading - private final Class<C> rootConceptClass; - - // All read concepts are validated after reading if this flag is set - private boolean validate = true; - - /** - * Constructor, initiates the reader with validation on. - * - * @param rootConceptClass the root concept class for concept reading - * @throws ApexModelException the apex concept reader exception - */ - public ApexModelReader(final Class<C> rootConceptClass) throws ApexModelException { - // Save the root concept class - this.rootConceptClass = rootConceptClass; - } - - /** - * Constructor, initiates the reader. - * - * @param rootConceptClass the root concept class for concept reading - * @param validate whether to perform validation by default - * @throws ApexModelException the apex concept reader exception - */ - public ApexModelReader(final Class<C> rootConceptClass, final boolean validate) throws ApexModelException { - this(rootConceptClass); - this.validate = validate; - } - - /** - * This method checks the specified Apex concept file and reads it into an Apex concept. - * - * @param apexConceptStream the apex concept stream - * @return the Apex concept - * @throws ApexModelException on reading exceptions - */ - public C read(final InputStream apexConceptStream) throws ApexModelException { - Assertions.argumentNotNull(apexConceptStream, "concept stream may not be null"); - - return read(new BufferedReader(new InputStreamReader(apexConceptStream))); - } - - /** - * This method reads the specified Apex reader into an Apex concept. - * - * @param apexConceptReader the apex concept reader - * @return the Apex concept - * @throws ApexModelException on reading exceptions - */ - public C read(final BufferedReader apexConceptReader) throws ApexModelException { - Assertions.argumentNotNull(apexConceptReader, "concept reader may not be null"); - - LOGGER.entry("reading Apex concept into a String . . ."); - - // Get the Apex concept as a string - String apexConceptString = null; - try { - apexConceptString = TextFileUtils.getReaderAsString(apexConceptReader).trim(); - } catch (final IOException e) { - throw new ApexModelException("Unable to read Apex concept ", e); - } - - return read(apexConceptString); - } - - /** - * This method reads the specified Apex string into an Apex concept. - * - * @param apexConceptString the apex concept as a string - * @return the Apex concept - * @throws ApexModelException on reading exceptions - */ - public C read(final String apexConceptString) throws ApexModelException { - Assertions.argumentNotNull(apexConceptString, "concept string may not be null"); - - LOGGER.entry("reading Apex concept from string . . ."); - - C apexConcept = null; - try { - apexConcept = gson.fromJson(apexConceptString, rootConceptClass); - } catch (final Exception je) { - throw new ApexModelException("Unable to unmarshal Apex concept ", je); - } - - if (apexConcept == null) { - throw new ApexModelException("Unable to unmarshal Apex concept, unmarshaled model is null "); - } - - LOGGER.debug("reading of Apex concept {} completed"); - - apexConcept.buildReferences(); - - // Check if the concept should be validated - if (validate) { - // Validate the configuration file - final AxValidationResult validationResult = apexConcept.validate(new AxValidationResult()); - if (validationResult.isValid()) { - return apexConcept; - } else { - String message = "Apex concept validation failed" + validationResult.toString(); - LOGGER.error(message); - throw new ApexModelException(message); - } - } else { - // No validation check - return apexConcept; - } - } -} 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 deleted file mode 100644 index 79d69bdd5..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaver.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2022 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 java.io.File; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.common.utils.validation.Assertions; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class is used to save Apex models to file in JSON format. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - * @param <M> the type of Apex model to save to file, must be a sub class of {@link AxModel} - */ -public class ApexModelSaver<M extends AxModel> { - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelSaver.class); - - // The class of the model and the model to write to disk - private final Class<M> rootModelClass; - private final M model; - - // The path into which to write the models - private final String writePath; - - /** - * Constructor, specifies the type of the Apex model (a sub class of {@link AxModel}), the model to write, and the - * path of a directory to which to write the model. - * - * @param rootModelClass the class of the model, a sub class of {@link AxModel} - * @param model the model to write, an instance of a sub class of {@link AxModel} - * @param writePath the directory to which models will be written. The name of the written model will be the Model - * Name for its key with the suffix {@code .json}. - */ - public ApexModelSaver(final Class<M> rootModelClass, final M model, final String writePath) { - Assertions.argumentNotNull(rootModelClass, "argument rootModelClass may not be null"); - Assertions.argumentNotNull(model, "argument model may not be null"); - Assertions.argumentNotNull(writePath, "writePath rootModelClass may not be null"); - - this.rootModelClass = rootModelClass; - this.model = model; - this.writePath = writePath; - } - - /** - * Write an Apex model to a file in JSON format. The model will be written to {@code <writePath/modelKeyName.json>} - * - * @throws ApexException on errors writing the Apex model - */ - public void apexModelWriteJson() throws ApexException { - LOGGER.debug("running apexModelWriteJSON . . ."); - - // Write the file to disk - final var jsonFile = new File(writePath + File.separatorChar + model.getKey().getName() + ".json"); - new ApexModelFileWriter<M>(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 deleted file mode 100644 index a9df23afc..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriter.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2022 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 java.io.ByteArrayOutputStream; -import lombok.Getter; -import lombok.Setter; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; -import org.onap.policy.common.utils.validation.Assertions; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class writes an Apex concept to a string. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - * @param <C> the type of Apex concept to write to a string, must be a sub class of {@link AxConcept} - */ -@Getter -@Setter -public class ApexModelStringWriter<C extends AxConcept> { - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelStringWriter.class); - - // Should concepts being written to files be valid - private boolean validate; - - /** - * Constructor, set the validation flag. - * - * @param validate Should validation be performed prior to output - */ - public ApexModelStringWriter(final boolean validate) { - this.validate = validate; - } - - /** - * Write a concept to a string. - * - * @param concept The concept to write - * @param rootConceptClass The concept class - * @return The string with the concept - * @throws ApexException thrown on errors - */ - public String writeString(final C concept, final Class<C> rootConceptClass) - throws ApexException { - Assertions.argumentNotNull(concept, "concept may not be null"); - - return writeJsonString(concept, rootConceptClass); - } - - /** - * Write a concept to a JSON string. - * - * @param concept The concept to write - * @param rootConceptClass The concept class - * @return The string with the concept - * @throws ApexException thrown on errors - */ - public String writeJsonString(final C concept, final Class<C> rootConceptClass) throws ApexException { - LOGGER.debug("running writeJSONString . . ."); - - final ApexModelWriter<C> conceptWriter = new ApexModelWriter<>(rootConceptClass); - conceptWriter.setValidate(validate); - - try (var baOutputStream = new ByteArrayOutputStream()) { - conceptWriter.write(concept, baOutputStream); - return baOutputStream.toString(); - } catch (final Exception e) { - LOGGER.warn("error writing JSON string", e); - throw new ApexException("error writing JSON string", e); - } - - } -} 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 deleted file mode 100644 index 349622697..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java +++ /dev/null @@ -1,148 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2022 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 com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.Map; -import lombok.Getter; -import lombok.Setter; -import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; -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; - -/** - * This class writes an Apex concept to a file from a Java Apex Concept. - * - * @param <C> the type of Apex concept to write, must be a sub class of {@link AxConcept} - * @author John Keeney (john.keeney@ericsson.com) - */ -@Getter -@Setter -public class ApexModelWriter<C extends AxConcept> { - - private static final String CONCEPT_MAY_NOT_BE_NULL = "concept may not be null"; - private static final String CONCEPT_WRITER_MAY_NOT_BE_NULL = "concept writer may not be null"; - private static final String CONCEPT_STREAM_MAY_NOT_BE_NULL = "concept stream may not be null"; - - // Use GSON to serialize JSON - private static Gson gson = new GsonBuilder() - .registerTypeAdapter(AxReferenceKey.class, new ApexModelCustomGsonRefereceKeyAdapter()) - .registerTypeAdapter(Map.class, new ApexModelCustomGsonMapAdapter()) - .setPrettyPrinting() - .create(); - - // Get a reference to the logger - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexModelWriter.class); - - // Â The root class of the concept we are reading - private final Class<C> rootConceptClass; - - // All written concepts are validated before writing if this flag is set - private boolean validate = true; - - /** - * Constructor, initiates the writer with validation on. - * - * @param rootConceptClass the root concept class for concept reading - * @throws ApexModelException the apex concept reader exception - */ - public ApexModelWriter(final Class<C> rootConceptClass) throws ApexModelException { - // Save the root concept class - this.rootConceptClass = rootConceptClass; - } - - /** - * This method validates the Apex concept then writes it into a stream. - * - * @param concept the concept to write - * @param apexConceptStream the stream to write to - * @throws ApexModelException on validation or writing exceptions - */ - public void write(final C concept, final OutputStream apexConceptStream) throws ApexModelException { - Assertions.argumentNotNull(concept, CONCEPT_MAY_NOT_BE_NULL); - Assertions.argumentNotNull(apexConceptStream, CONCEPT_STREAM_MAY_NOT_BE_NULL); - - this.write(concept, new OutputStreamWriter(apexConceptStream)); - } - - /** - * This method validates the Apex concept then writes it into a writer. - * - * @param concept the concept to write - * @param apexConceptWriter the writer to write to - * @throws ApexModelException on validation or writing exceptions - */ - public void write(final C concept, final Writer apexConceptWriter) throws ApexModelException { - Assertions.argumentNotNull(concept, CONCEPT_MAY_NOT_BE_NULL); - Assertions.argumentNotNull(apexConceptWriter, CONCEPT_WRITER_MAY_NOT_BE_NULL); - - // Check if we should validate the concept - if (validate) { - // Validate the concept first - final AxValidationResult validationResult = concept.validate(new AxValidationResult()); - if (!validationResult.isValid()) { - String message = - "Apex concept (" + concept.getKey().getId() + ") validation failed: " + validationResult.toString(); - throw new ApexModelException(message); - } - } - - writeJson(concept, apexConceptWriter); - } - - /** - * This method writes the Apex concept into a writer in JSON format. - * - * @param concept the concept to write - * @param apexConceptWriter the writer to write to - * @throws ApexModelException on validation or writing exceptions - */ - private void writeJson(final C concept, final Writer apexConceptWriter) throws ApexModelException { - Assertions.argumentNotNull(concept, CONCEPT_MAY_NOT_BE_NULL); - - LOGGER.debug("writing Apex concept JSON . . ."); - - String modelJsonString = null; - try { - modelJsonString = gson.toJson(concept, rootConceptClass); - } catch (Exception je) { - throw new ApexModelException("Unable to marshal Apex concept to JSON", je); - } - - try { - apexConceptWriter.write(modelJsonString); - apexConceptWriter.close(); - } catch (IOException ioe) { - throw new ApexModelException("Unable to write Apex concept as JSON", ioe); - } - - LOGGER.debug("wrote Apex concept JSON"); - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/package-info.java deleted file mode 100644 index 3d6dab3b2..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2022 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; diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/package-info.java deleted file mode 100644 index 8ad405e25..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/package-info.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019,2022 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========================================================= - */ - -/** - * Provides the base definition of an APEX model. It also defines the Model Service, the mechanism that allows access to - * the model for APEX concepts anywhere in the system. - * - * <p>It also provides handling support to models, allowing them to be read and written to file and databases in JSON - * format. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -package org.onap.policy.apex.model.basicmodel; diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/service/ModelService.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/service/ModelService.java deleted file mode 100644 index c6eb0e011..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/service/ModelService.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 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.service; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException; -import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; - -/** - * The model service makes Apex models available to all classes in a JVM. - * - * <p>The reason for having a model service is to avoid having to pass concept and model definitions down long call - * chains in modules such as the Apex engine and editor. The model service makes the model and concept definitions - * available statically. - * - * <p>Note that the use of the model service means that only a single Apex model of a particular type may exist in Apex - * (particularly the engine) at any time. Of course the model in a JVM can be changed at any time provided all users of - * the model are stopped and restarted in an orderly manner. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public abstract class ModelService { - // The map holding the models - private static Map<Class<?>, AxConcept> modelMap = new ConcurrentHashMap<>(); - - /** - * This class is an abstract static class that cannot be extended. - */ - private ModelService() { - } - - /** - * Register a model with the model service. - * - * @param <M> the generic type - * @param modelClass the class of the model, used to index the model - * @param model The model - */ - public static <M extends AxConcept> void registerModel(final Class<M> modelClass, final M model) { - modelMap.put(modelClass, model); - } - - /** - * Remove a model from the model service. - * - * @param <M> the generic type - * @param modelClass the class of the model, used to index the model - */ - public static <M extends AxConcept> void deregisterModel(final Class<M> modelClass) { - modelMap.remove(modelClass); - } - - /** - * Get a model from the model service. - * - * @param <M> the generic type - * @param modelClass the class of the model, used to index the model - * @return The model - */ - @SuppressWarnings("unchecked") - public static <M extends AxConcept> M getModel(final Class<M> modelClass) { - final M model = (M) modelMap.get(modelClass); - - if (model == null) { - throw new ApexRuntimeException("Model for " + modelClass.getName() + " not found in model service"); - } - - return model; - } - - /** - * Check if a model is defined on the model service. - * - * @param <M> the generic type - * @param modelClass the class of the model, used to index the model - * @return true if the model is defined - */ - public static <M extends AxConcept> boolean existsModel(final Class<M> modelClass) { - return modelMap.get(modelClass) != null; - } - - /** - * Clear all models in the model service. - */ - public static void clear() { - modelMap.clear(); - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/service/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/service/package-info.java deleted file mode 100644 index a27e45d1a..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/service/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - -/** - * Contains the static services in Apex that make models and parameters available to all objects in the JVM. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -package org.onap.policy.apex.model.basicmodel.service; 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 deleted file mode 100644 index 9dde47d05..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModel.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2021-2022 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.test; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -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.handling.ApexModelFileWriter; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelWriter; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class tests reading and writing of Apex models to file and to a database using JPA. It also tests validation of - * Apex models. This class is designed for use in unit tests in modules that define Apex models. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - * @param <M> the generic type - */ -public class TestApexModel<M extends AxModel> { - private static final String MODEL_IS_INVALID = "model is invalid "; - private static final String ERROR_PROCESSING_FILE = "error processing file "; - private static final String TEST_MODEL_UNEQUAL_STR = "test model does not equal model read from file "; - private static final String TEMP_FILE_CREATE_ERR_STR = "error creating temporary file for Apex model"; - - private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestApexModel.class); - - // The root model class that specifies the root to import and export from - private final Class<M> rootModelClass; - - // The class that provides the model - private TestApexModelCreator<M> modelCreator = null; - - /** - * Constructor, defines the subclass of {@link AxModel} that is being tested and the {@link TestApexModelCreator} - * object that is used to generate Apex models. - * - * @param rootModelClass the Apex model class, a sub class of {@link AxModel} - * @param modelCreator the @link TestApexModelCreator} that will generate Apex models of various types for testing - */ - public TestApexModel(final Class<M> rootModelClass, final TestApexModelCreator<M> modelCreator) { - this.rootModelClass = rootModelClass; - this.modelCreator = modelCreator; - } - - /** - * Get a test Apex model using the model creator. - * - * @return the test Apex model - */ - public final M getModel() { - return modelCreator.getModel(); - } - - /** - * Test write and read in JSON format. - * - * @throws ApexException on write/read errors - */ - public final void testApexModelWriteReadJson() throws ApexException { - LOGGER.debug("running testApexModelWriteReadJSON . . ."); - - final var model = modelCreator.getModel(); - - // Write the file to disk - File jsonFile; - try { - jsonFile = File.createTempFile("ApexModel", ".json"); - jsonFile.deleteOnExit(); - } catch (final Exception e) { - LOGGER.warn(TEMP_FILE_CREATE_ERR_STR, e); - throw new ApexException(TEMP_FILE_CREATE_ERR_STR, e); - } - new ApexModelFileWriter<M>(true).apexModelWriteJsonFile(model, rootModelClass, jsonFile.getPath()); - - // Read the file from disk - final ApexModelReader<M> modelReader = new ApexModelReader<>(rootModelClass); - - try { - 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); - throw new ApexException(ERROR_PROCESSING_FILE + jsonFile.getAbsolutePath(), e); - } - - final ApexModelWriter<M> modelWriter = new ApexModelWriter<>(rootModelClass); - - final var baOutputStream = new ByteArrayOutputStream(); - modelWriter.write(model, baOutputStream); - 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"); - } - - /** - * Test that an Apex model is valid. - * - * @return the result of the validation - * @throws ApexException thrown on errors validating the Apex model - */ - public final AxValidationResult testApexModelValid() throws ApexException { - LOGGER.debug("running testApexModelVaid . . ."); - - final var model = modelCreator.getModel(); - final AxValidationResult result = model.validate(new AxValidationResult()); - - if (!result.isValid()) { - String message = MODEL_IS_INVALID + result.toString(); - LOGGER.warn(message); - throw new ApexException(message); - } - - LOGGER.debug("ran testApexModelVaid"); - return result; - } - - /** - * Test that an Apex model is structured incorrectly. - * - * @return the result of the validation - * @throws ApexException thrown on errors validating the Apex model - */ - public final AxValidationResult testApexModelVaidateMalstructured() throws ApexException { - LOGGER.debug("running testApexModelVaidateMalstructured . . ."); - - final var model = modelCreator.getMalstructuredModel(); - final AxValidationResult result = model.validate(new AxValidationResult()); - - if (result.isValid()) { - String message = "model should not be valid " + result.toString(); - LOGGER.warn(message); - throw new ApexException(message); - } - - LOGGER.debug("ran testApexModelVaidateMalstructured"); - return result; - } - - /** - * Test that an Apex model has observations. - * - * @return the result of the validation - * @throws ApexException thrown on errors validating the Apex model - */ - public final AxValidationResult testApexModelVaidateObservation() throws ApexException { - LOGGER.debug("running testApexModelVaidateObservation . . ."); - - final var model = modelCreator.getObservationModel(); - final AxValidationResult result = model.validate(new AxValidationResult()); - - if (!result.isValid()) { - String message = MODEL_IS_INVALID + result.toString(); - LOGGER.warn(message); - throw new ApexException(message); - } - - if (!result.getValidationResult().equals(AxValidationResult.ValidationResult.OBSERVATION)) { - LOGGER.warn("model should have observations"); - throw new ApexException("model should have observations"); - } - - LOGGER.debug("ran testApexModelVaidateObservation"); - return result; - } - - /** - * Test that an Apex model has warnings. - * - * @return the result of the validation - * @throws ApexException thrown on errors validating the Apex model - */ - public final AxValidationResult testApexModelVaidateWarning() throws ApexException { - LOGGER.debug("running testApexModelVaidateWarning . . ."); - - final var model = modelCreator.getWarningModel(); - final AxValidationResult result = model.validate(new AxValidationResult()); - - if (!result.isValid()) { - String message = MODEL_IS_INVALID + result.toString(); - LOGGER.warn(message); - throw new ApexException(message); - } - - if (!result.getValidationResult().equals(AxValidationResult.ValidationResult.WARNING)) { - LOGGER.warn("model should have warnings"); - throw new ApexException("model should have warnings"); - } - - LOGGER.debug("ran testApexModelVaidateWarning"); - return result; - } - - /** - * Test that an Apex model is invalid. - * - * @return the result of the validation - * @throws ApexException thrown on errors validating the Apex model - */ - public final AxValidationResult testApexModelVaidateInvalidModel() throws ApexException { - LOGGER.debug("running testApexModelVaidateInvalidModel . . ."); - - final var model = modelCreator.getInvalidModel(); - final AxValidationResult result = model.validate(new AxValidationResult()); - - if (result.isValid()) { - String message = "model should not be valid " + result.toString(); - LOGGER.warn(message); - throw new ApexException(message); - } - - LOGGER.debug("ran testApexModelVaidateInvalidModel"); - return result; - } - - /** - * Check if two models are equal. - * - * @param leftModel the left model - * @param rightModel the right model - * @param errorMessage the error message to output on inequality - * @throws ApexException the exception to throw on inequality - */ - public void checkModelEquality(final M leftModel, final M rightModel, final String errorMessage) - throws ApexException { - if (!leftModel.equals(rightModel)) { - LOGGER.warn(errorMessage); - throw new ApexException(errorMessage); - } - } -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModelCreator.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModelCreator.java deleted file mode 100644 index 65441a33c..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/TestApexModelCreator.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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.test; - -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelCreator; - -/** - * The Interface TestApexModelCreator is used to create models for Apex model tests. It is mainly used by unit tests for - * Apex domain models so that developers can write test Java programs to create models. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - * @param <M> the generic type - */ -public interface TestApexModelCreator<M extends AxModel> extends ApexModelCreator<M> { - - /** - * Gets the malstructured model. - * - * @return the malstructured model - */ - M getMalstructuredModel(); - - /** - * Gets the observation model. - * - * @return the observation model - */ - M getObservationModel(); - - /** - * Gets the warning model. - * - * @return the warning model - */ - M getWarningModel(); - - /** - * Gets the invalid model. - * - * @return the invalid model - */ - M getInvalidModel(); -} diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/package-info.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/package-info.java deleted file mode 100644 index 9bbdd1cce..000000000 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/test/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - -/** - * Contains utility classes that allow testing of validation and reads and writes on APEX models to files and databases. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -package org.onap.policy.apex.model.basicmodel.test; diff --git a/model/basic-model/src/main/resources/doc/JDBCPropertiesExamples.txt b/model/basic-model/src/main/resources/doc/JDBCPropertiesExamples.txt deleted file mode 100644 index 6e105a68d..000000000 --- a/model/basic-model/src/main/resources/doc/JDBCPropertiesExamples.txt +++ /dev/null @@ -1,35 +0,0 @@ -#------------------------------------------------------------------------------- -# ============LICENSE_START======================================================= -# Copyright (C) 2016-2018 Ericsson. All rights reserved. -# ================================================================================ -# 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========================================================= -#------------------------------------------------------------------------------- - -Properties jdbcProperties = new Properties(); -jdbcProperties.put("javax.persistence.jdbc.url", "jdbc:postgresql://localhost:5432/apex_test"); -jdbcProperties.put("eclipselink.ddl-generation", "drop-and-create-tables"); - -Properties jdbcProperties = new Properties(); -jdbcProperties.put("javax.persistence.jdbc.url", "jdbc:postgresql://localhost:5432/apex_test"); -jdbcProperties.put("hibernate.hbm2ddl.auto", "create-drop"); - -Properties jdbcProperties = new Properties(); -jdbcProperties.put("javax.persistence.jdbc.url", "jdbc:postgresql://localhost:5432/apex"); -jdbcProperties.put("eclipselink.ddl-generation", "create-or-extend-tables"); - -Properties jdbcProperties = new Properties(); -jdbcProperties.put("javax.persistence.jdbc.url", "jdbc:postgresql://localhost:5432/apex"); -jdbcProperties.put("hibernate.hbm2ddl.auto", "update"); diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImplTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImplTest.java deleted file mode 100644 index 44a9de49e..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImplTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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.concepts; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.NavigableMap; -import java.util.TreeMap; -import java.util.TreeSet; -import org.junit.Test; - -/** - * Test the AxConceptGetterImpl class. - */ -public class AxConceptGetterImplTest { - - @Test - public void testAxConceptGetterImpl() { - NavigableMap<AxArtifactKey, AxArtifactKey> keyMap = new TreeMap<>(); - - AxConceptGetterImpl<AxArtifactKey> getter = new AxConceptGetterImpl<>(keyMap); - assertNotNull(getter); - - AxArtifactKey keyA = new AxArtifactKey("A", "0.0.1"); - assertNull(getter.get(keyA)); - - assertThatThrownBy(() -> getter.get((String) null)) - .hasMessage("conceptKeyName may not be null"); - assertNull(getter.get("W")); - - AxArtifactKey keyZ = new AxArtifactKey("Z", "0.0.1"); - keyMap.put(keyZ, keyZ); - assertNull(getter.get("W")); - - AxArtifactKey keyW001 = new AxArtifactKey("W", "0.0.1"); - keyMap.put(keyW001, keyW001); - assertEquals(keyW001, getter.get("W")); - - AxArtifactKey keyW002 = new AxArtifactKey("W", "0.0.2"); - keyMap.put(keyW002, keyW002); - assertEquals(keyW002, getter.get("W")); - - keyMap.remove(keyZ); - assertEquals(keyW002, getter.get("W")); - - assertThatThrownBy(() -> getter.get((String) null, "0.0.1")) - .hasMessage("conceptKeyName may not be null"); - assertEquals(keyW002, getter.get("W", "0.0.2")); - assertEquals(keyW002, getter.get("W", (String) null)); - - assertEquals(new TreeSet<AxArtifactKey>(keyMap.values()), getter.getAll(null)); - assertEquals(new TreeSet<AxArtifactKey>(keyMap.values()), getter.getAll(null, null)); - - assertEquals(keyW001, getter.getAll("W", null).iterator().next()); - assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next()); - assertEquals(0, getter.getAll("A", null).size()); - assertEquals(0, getter.getAll("Z", null).size()); - - keyMap.put(keyZ, keyZ); - assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next()); - } -} 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 deleted file mode 100644 index 0c7edee28..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2022 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.concepts; - -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.UUID; -import org.junit.Test; - - -public class AxKeyInfoTest { - - @Test - public void testNullAxKeyInfo() { - assertNotNull(new AxKeyInfo()); - assertNotNull(new AxKeyInfo(new AxArtifactKey())); - assertNotNull(new AxKeyInfo(new AxArtifactKey(), UUID.randomUUID(), "Key description")); - } - - @Test - public void testAxKeyInfo() { - AxKeyInfo testKeyInfo = new AxKeyInfo(); - testKeyInfo.setKey((new AxArtifactKey("PN", "0.0.1"))); - assertEquals("PN:0.0.1", testKeyInfo.getKey().getId()); - assertTrue(testKeyInfo.matchesId("PN:0.0.1")); - - AxArtifactKey key = new AxArtifactKey("key", "0.0.1"); - testKeyInfo.setKey(key); - assertEquals(key, testKeyInfo.getKey()); - - UUID uuid = UUID.randomUUID(); - testKeyInfo.setUuid(uuid); - assertEquals(uuid, testKeyInfo.getUuid()); - testKeyInfo.setDescription("Key Description"); - assertEquals("Key Description", testKeyInfo.getDescription()); - - AxKeyInfo clonedReferenceKey = new AxKeyInfo(testKeyInfo); - assertTrue(clonedReferenceKey.toString() - .startsWith("AxKeyInfo:(artifactId=AxArtifactKey:(name=key,version=0.0.1),uuid=")); - - assertNotEquals(0, testKeyInfo.hashCode()); - // disabling sonar because this code tests the equals() method - assertEquals(testKeyInfo, testKeyInfo); // NOSONAR - assertEquals(testKeyInfo, clonedReferenceKey); - assertNotNull(testKeyInfo); - Object differentKeyType = new AxArtifactKey(); - assertNotEquals(testKeyInfo, differentKeyType); - assertNotEquals(testKeyInfo, new AxKeyInfo(new AxArtifactKey())); - assertNotEquals(testKeyInfo, new AxKeyInfo(key, UUID.randomUUID(), "Some Description")); - assertEquals(testKeyInfo, new AxKeyInfo(key, uuid, "Some Other Description")); - assertEquals(testKeyInfo, new AxKeyInfo(key, uuid, "Key Description")); - - assertEquals(0, testKeyInfo.compareTo(testKeyInfo)); - assertEquals(0, testKeyInfo.compareTo(clonedReferenceKey)); - - - } - - @Test - public void testAxKeyValidation() { - AxKeyInfo testKeyInfo = new AxKeyInfo(); - testKeyInfo.setKey((new AxArtifactKey("PN", "0.0.1"))); - - AxValidationResult result = new AxValidationResult(); - result = testKeyInfo.validate(result); - assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); - - testKeyInfo.setDescription(""); - result = testKeyInfo.validate(result); - assertEquals(AxValidationResult.ValidationResult.OBSERVATION, result.getValidationResult()); - - testKeyInfo.setUuid(new UUID(0, 0)); - result = testKeyInfo.validate(result); - assertEquals(AxValidationResult.ValidationResult.WARNING, result.getValidationResult()); - - testKeyInfo.setKey(AxArtifactKey.getNullKey()); - result = testKeyInfo.validate(result); - assertEquals(AxValidationResult.ValidationResult.INVALID, result.getValidationResult()); - - assertNotNull(AxKeyInfo.generateReproducibleUuid(null)); - assertNotNull(AxKeyInfo.generateReproducibleUuid("SeedString")); - - testKeyInfo.clean(); - assertNotNull(testKeyInfo); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyTest.java deleted file mode 100644 index 010f4b8a3..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * ============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.concepts; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.lang.reflect.Field; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey.Compatibility; - -public class AxKeyTest { - - private static AxArtifactKey someKey0; - private static AxArtifactKey someKey1; - private static AxArtifactKey someKey2; - private static AxArtifactKey someKey3; - private static AxArtifactKey someKey4; - private static AxArtifactKey someKey5; - private static AxArtifactKey someKey6; - - /** - * Sets data in Keys for the tests. - */ - @Before - public void setKeys() { - someKey0 = new AxArtifactKey(); - someKey1 = new AxArtifactKey("name", "0.0.1"); - someKey2 = new AxArtifactKey(someKey1); - someKey3 = new AxArtifactKey(someKey1.getId()); - someKey4 = new AxArtifactKey(someKey1); - someKey5 = new AxArtifactKey(someKey1); - someKey6 = new AxArtifactKey(someKey1); - } - - private void setKeyValues() { - someKey0.setName("zero"); - someKey0.setVersion("0.0.2"); - someKey3.setVersion("0.0.2"); - someKey4.setVersion("0.1.2"); - someKey5.setVersion("1.2.2"); - someKey6.setVersion("3"); - } - - @Test - public void testArtifactKey() { - assertThatThrownBy(() -> new AxArtifactKey("some bad key id")) - .hasMessage("parameter \"id\": value \"some bad key id\", " - + "does not match regular expression \"[A-Za-z0-9\\-_\\.]+:[0-9].[0-9].[0-9]\""); - - assertEquals(AxArtifactKey.getNullKey(), someKey0); - - assertEquals(someKey1, someKey2); - assertEquals(someKey1, someKey3); - - assertEquals(someKey2, someKey1.getKey()); - assertEquals(1, someKey1.getKeys().size()); - - setKeyValues(); - - someKey0.clean(); - assertNotNull(someKey0.toString()); - - AxArtifactKey someKey7 = new AxArtifactKey(someKey1); - assertEquals(150332875, someKey7.hashCode()); - assertEquals(0, someKey7.compareTo(someKey1)); - assertEquals(-12, someKey7.compareTo(someKey0)); - - assertThatThrownBy(() -> someKey0.compareTo(null)) - .hasMessage("comparison object may not be null"); - assertEquals(0, someKey0.compareTo(someKey0)); - assertEquals(353602977, someKey0.compareTo(new AxReferenceKey())); - - assertNotNull(someKey0); - // disabling sonar because this code tests the equals() method - assertEquals(someKey0, someKey0); // NOSONAR - assertNotEquals(someKey0, (Object) new AxReferenceKey()); - } - - @Test - public void testAxCompatibility() { - setKeyValues(); - - assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(new AxReferenceKey())); - assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(someKey1)); - assertEquals(Compatibility.IDENTICAL, someKey2.getCompatibility(someKey1)); - assertEquals(Compatibility.PATCH, someKey3.getCompatibility(someKey1)); - assertEquals(Compatibility.MINOR, someKey4.getCompatibility(someKey1)); - assertEquals(Compatibility.MAJOR, someKey5.getCompatibility(someKey1)); - assertEquals(Compatibility.MAJOR, someKey6.getCompatibility(someKey1)); - - assertTrue(someKey1.isCompatible(someKey2)); - assertTrue(someKey1.isCompatible(someKey3)); - assertTrue(someKey1.isCompatible(someKey4)); - assertFalse(someKey1.isCompatible(someKey0)); - assertFalse(someKey1.isCompatible(someKey5)); - assertFalse(someKey1.isCompatible(new AxReferenceKey())); - } - - @Test - public void testAxValidation() { - setKeyValues(); - - assertEquals(AxValidationResult.ValidationResult.VALID, - someKey0.validate(new AxValidationResult()).getValidationResult()); - assertEquals(AxValidationResult.ValidationResult.VALID, - someKey1.validate(new AxValidationResult()).getValidationResult()); - assertEquals(AxValidationResult.ValidationResult.VALID, - someKey2.validate(new AxValidationResult()).getValidationResult()); - assertEquals(AxValidationResult.ValidationResult.VALID, - someKey3.validate(new AxValidationResult()).getValidationResult()); - assertEquals(AxValidationResult.ValidationResult.VALID, - someKey4.validate(new AxValidationResult()).getValidationResult()); - assertEquals(AxValidationResult.ValidationResult.VALID, - someKey5.validate(new AxValidationResult()).getValidationResult()); - assertEquals(AxValidationResult.ValidationResult.VALID, - someKey6.validate(new AxValidationResult()).getValidationResult()); - } - - @Test - public void testNullKey() { - setKeyValues(); - - AxArtifactKey nullKey0 = AxArtifactKey.getNullKey(); - assertTrue(nullKey0.isNullKey()); - AxArtifactKey nullKey1 = new AxArtifactKey(); - assertTrue(nullKey1.isNullKey()); - AxArtifactKey nullKey2 = new AxArtifactKey(AxKey.NULL_KEY_NAME, AxKey.NULL_KEY_VERSION); - assertTrue(nullKey2.isNullKey()); - AxArtifactKey notnullKey = new AxArtifactKey("Blah", AxKey.NULL_KEY_VERSION); - assertFalse(notnullKey.isNullKey()); - } - - - @Test - public void testValidation() throws IllegalArgumentException, IllegalAccessException, - NoSuchFieldException, SecurityException { - AxArtifactKey testKey = new AxArtifactKey("TheKey", "0.0.1"); - assertEquals("TheKey:0.0.1", testKey.getId()); - - Field nameField = testKey.getClass().getDeclaredField("name"); - nameField.setAccessible(true); - nameField.set(testKey, "Key Name"); - AxValidationResult validationResult = new AxValidationResult(); - testKey.validate(validationResult); - nameField.set(testKey, "TheKey"); - nameField.setAccessible(false); - assertEquals( - "name invalid-parameter name with value Key Name " - + "does not match regular expression [A-Za-z0-9\\-_\\.]+", - validationResult.getMessageList().get(0).getMessage()); - - Field versionField = testKey.getClass().getDeclaredField("version"); - versionField.setAccessible(true); - versionField.set(testKey, "Key Version"); - AxValidationResult validationResultV = new AxValidationResult(); - testKey.validate(validationResultV); - versionField.set(testKey, "0.0.1"); - versionField.setAccessible(false); - assertEquals( - "version invalid-parameter version with value Key Version " - + "does not match regular expression [A-Za-z0-9.]+", - validationResultV.getMessageList().get(0).getMessage()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUseTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUseTest.java deleted file mode 100644 index 5346b6b21..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUseTest.java +++ /dev/null @@ -1,78 +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.concepts; - -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 org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey.Compatibility; - -public class AxKeyUseTest { - - @Test - public void test() { - assertNotNull(new AxKeyUse()); - assertNotNull(new AxKeyUse(new AxArtifactKey())); - assertNotNull(new AxKeyUse(new AxReferenceKey())); - - AxArtifactKey key = new AxArtifactKey("Key", "0.0.1"); - AxKeyUse keyUse = new AxKeyUse(); - keyUse.setKey(key); - assertEquals(key, keyUse.getKey()); - assertEquals("Key:0.0.1", keyUse.getId()); - assertEquals(key, keyUse.getKeys().get(0)); - - assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key)); - assertTrue(keyUse.isCompatible(key)); - - keyUse.clean(); - assertNotNull(keyUse); - - AxValidationResult result = new AxValidationResult(); - result = keyUse.validate(result); - assertNotNull(result); - - assertNotEquals(0, keyUse.hashCode()); - - AxKeyUse clonedKeyUse = new AxKeyUse(keyUse); - assertEquals("AxKeyUse:(usedKey=AxArtifactKey:(name=Key,version=0.0.1))", clonedKeyUse.toString()); - - assertNotEquals(0, keyUse.hashCode()); - // disabling sonar because this code tests the equals() method - assertEquals(keyUse, keyUse); // NOSONAR - assertEquals(keyUse, clonedKeyUse); - assertNotEquals(keyUse, (Object) "Hello"); - assertEquals(keyUse, new AxKeyUse(key)); - - assertEquals(0, keyUse.compareTo(keyUse)); - assertEquals(0, keyUse.compareTo(clonedKeyUse)); - assertNotEquals(0, keyUse.compareTo(new AxArtifactKey())); - assertEquals(0, keyUse.compareTo(new AxKeyUse(key))); - - AxKeyUse keyUseNull = new AxKeyUse(AxArtifactKey.getNullKey()); - AxValidationResult resultNull = new AxValidationResult(); - assertEquals(false, keyUseNull.validate(resultNull).isValid()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKeyTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKeyTest.java deleted file mode 100644 index 515587558..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKeyTest.java +++ /dev/null @@ -1,177 +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.concepts; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.lang.reflect.Field; -import org.junit.Test; - - -public class AxReferenceKeyTest { - - @Test - public void testAxReferenceKey() { - assertNotNull(new AxReferenceKey()); - assertNotNull(new AxReferenceKey(new AxArtifactKey())); - assertNotNull(new AxReferenceKey(new AxArtifactKey(), "LocalName")); - assertNotNull(new AxReferenceKey(new AxReferenceKey())); - assertNotNull(new AxReferenceKey(new AxReferenceKey(), "LocalName")); - assertNotNull(new AxReferenceKey(new AxArtifactKey(), "ParentLocalName", "LocalName")); - assertNotNull(new AxReferenceKey("ParentKeyName", "0.0.1", "LocalName")); - assertNotNull(new AxReferenceKey("ParentKeyName", "0.0.1", "ParentLocalName", "LocalName")); - assertNotNull(new AxReferenceKey("ParentKeyName:0.0.1:ParentLocalName:LocalName")); - assertEquals(AxReferenceKey.getNullKey().getKey(), AxReferenceKey.getNullKey()); - assertEquals("NULL:0.0.0:NULL:NULL", AxReferenceKey.getNullKey().getId()); - - AxReferenceKey testReferenceKey = new AxReferenceKey(); - testReferenceKey.setParentArtifactKey(new AxArtifactKey("PN", "0.0.1")); - assertEquals("PN:0.0.1", testReferenceKey.getParentArtifactKey().getId()); - - testReferenceKey.setParentReferenceKey(new AxReferenceKey("PN", "0.0.1", "LN")); - assertEquals("PN:0.0.1:NULL:LN", testReferenceKey.getParentReferenceKey().getId()); - - testReferenceKey.setParentKeyName("NPKN"); - assertEquals("NPKN", testReferenceKey.getParentKeyName()); - - testReferenceKey.setParentKeyVersion("0.0.1"); - assertEquals("0.0.1", testReferenceKey.getParentKeyVersion()); - - testReferenceKey.setParentLocalName("NPKLN"); - assertEquals("NPKLN", testReferenceKey.getParentLocalName()); - - testReferenceKey.setLocalName("NLN"); - assertEquals("NLN", testReferenceKey.getLocalName()); - - assertFalse(testReferenceKey.isCompatible(AxArtifactKey.getNullKey())); - assertFalse(testReferenceKey.isCompatible(AxReferenceKey.getNullKey())); - assertTrue(testReferenceKey.isCompatible(testReferenceKey)); - - assertEquals(AxKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(AxArtifactKey.getNullKey())); - assertEquals(AxKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(AxReferenceKey.getNullKey())); - assertEquals(AxKey.Compatibility.IDENTICAL, testReferenceKey.getCompatibility(testReferenceKey)); - - AxValidationResult result = new AxValidationResult(); - result = testReferenceKey.validate(result); - assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); - - testReferenceKey.clean(); - - AxReferenceKey clonedReferenceKey = new AxReferenceKey(testReferenceKey); - assertEquals("AxReferenceKey:(parentKeyName=NPKN,parentKeyVersion=0.0.1,parentLocalName=NPKLN,localName=NLN)", - clonedReferenceKey.toString()); - - assertNotEquals(0, testReferenceKey.hashCode()); - // disabling sonar because this code tests the equals() method - assertEquals(testReferenceKey, testReferenceKey); // NOSONAR - assertEquals(testReferenceKey, clonedReferenceKey); - assertNotEquals(testReferenceKey, (Object) "Hello"); - assertNotEquals(testReferenceKey, new AxReferenceKey("PKN", "0.0.2", "PLN", "LN")); - assertNotEquals(testReferenceKey, new AxReferenceKey("NPKN", "0.0.2", "PLN", "LN")); - assertNotEquals(testReferenceKey, new AxReferenceKey("NPKN", "0.0.1", "PLN", "LN")); - assertNotEquals(testReferenceKey, new AxReferenceKey("NPKN", "0.0.1", "NPLN", "LN")); - assertEquals(testReferenceKey, new AxReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN")); - - assertEquals(0, testReferenceKey.compareTo(testReferenceKey)); - assertEquals(0, testReferenceKey.compareTo(clonedReferenceKey)); - assertNotEquals(0, testReferenceKey.compareTo(new AxArtifactKey())); - assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("PKN", "0.0.2", "PLN", "LN"))); - assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.2", "PLN", "LN"))); - assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "PLN", "LN"))); - assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "NPLN", "LN"))); - assertEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN"))); - - assertNotNull(testReferenceKey.getKeys()); - - assertThatThrownBy(() -> testReferenceKey.equals(null)) - .hasMessage("comparison object may not be null"); - assertThatThrownBy(() -> testReferenceKey.copyTo(null)) - .hasMessage("target may not be null"); - assertThatThrownBy(() -> testReferenceKey.copyTo(new AxArtifactKey("Key", "0.0.1"))) - .hasMessage("org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey is not an instance of " - + "org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey"); - AxReferenceKey targetRefKey = new AxReferenceKey(); - assertEquals(testReferenceKey, testReferenceKey.copyTo(targetRefKey)); - } - - @Test - public void testValidation() throws IllegalArgumentException, IllegalAccessException, - NoSuchFieldException, SecurityException { - AxReferenceKey testReferenceKey = new AxReferenceKey(); - testReferenceKey.setParentArtifactKey(new AxArtifactKey("PN", "0.0.1")); - assertEquals("PN:0.0.1", testReferenceKey.getParentArtifactKey().getId()); - - Field parentNameField = testReferenceKey.getClass().getDeclaredField("parentKeyName"); - parentNameField.setAccessible(true); - parentNameField.set(testReferenceKey, "Parent Name"); - AxValidationResult validationResult = new AxValidationResult(); - testReferenceKey.validate(validationResult); - parentNameField.set(testReferenceKey, "ParentName"); - parentNameField.setAccessible(false); - assertEquals( - "parentKeyName invalid-parameter parentKeyName with value Parent Name " - + "does not match regular expression [A-Za-z0-9\\-_\\.]+", - validationResult.getMessageList().get(0).getMessage()); - - Field parentVersionField = testReferenceKey.getClass().getDeclaredField("parentKeyVersion"); - parentVersionField.setAccessible(true); - parentVersionField.set(testReferenceKey, "Parent Version"); - AxValidationResult validationResultPV = new AxValidationResult(); - testReferenceKey.validate(validationResultPV); - parentVersionField.set(testReferenceKey, "0.0.1"); - parentVersionField.setAccessible(false); - assertEquals( - "parentKeyVersion invalid-parameter parentKeyVersion with value Parent Version " - + "does not match regular expression [A-Za-z0-9.]+", - validationResultPV.getMessageList().get(0).getMessage()); - - Field parentLocalNameField = testReferenceKey.getClass().getDeclaredField("parentLocalName"); - parentLocalNameField.setAccessible(true); - parentLocalNameField.set(testReferenceKey, "Parent Local Name"); - AxValidationResult validationResultPL = new AxValidationResult(); - testReferenceKey.validate(validationResultPL); - parentLocalNameField.set(testReferenceKey, "ParentLocalName"); - parentLocalNameField.setAccessible(false); - assertEquals( - "parentLocalName invalid-parameter parentLocalName with value " - + "Parent Local Name does not match regular expression [A-Za-z0-9\\-_\\.]+|^$", - validationResultPL.getMessageList().get(0).getMessage()); - - Field localNameField = testReferenceKey.getClass().getDeclaredField("localName"); - localNameField.setAccessible(true); - localNameField.set(testReferenceKey, "Local Name"); - AxValidationResult validationResultLN = new AxValidationResult(); - testReferenceKey.validate(validationResultLN); - localNameField.set(testReferenceKey, "LocalName"); - localNameField.setAccessible(false); - assertEquals( - "localName invalid-parameter localName with value Local Name " - + "does not match regular expression [A-Za-z0-9\\-_\\.]+|^$", - validationResultLN.getMessageList().get(0).getMessage()); - - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java deleted file mode 100644 index 2b16e89ed..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 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.concepts; - -import java.util.Arrays; -import java.util.List; - -public class DummyEntity extends AxConcept { - private static final long serialVersionUID = -2962570563281067894L; - - protected AxReferenceKey key; - private double doubleValue; - - public DummyEntity() { - this.key = new AxReferenceKey(); - this.doubleValue = 0; - } - - public DummyEntity(Double doubleValue) { - this.key = new AxReferenceKey(); - this.doubleValue = doubleValue; - } - - public DummyEntity(AxReferenceKey key, Double doubleValue) { - this.key = key; - this.doubleValue = doubleValue; - } - - @Override - public AxReferenceKey getKey() { - return key; - } - - @Override - public List<AxKey> getKeys() { - return Arrays.asList((AxKey) getKey()); - } - - public void setKey(AxReferenceKey key) { - this.key = key; - } - - public boolean checkSetKey() { - return (this.key != null); - } - - public double getDoubleValue() { - return doubleValue; - } - - public void setDoubleValue(double doubleValue) { - this.doubleValue = doubleValue; - } - - @Override - public AxValidationResult validate(AxValidationResult result) { - return key.validate(result); - } - - @Override - public void clean() { - key.clean(); - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("doubleValue="); - builder.append(doubleValue); - return builder.toString(); - } - - @Override - public AxConcept copyTo(AxConcept target) { - final Object copyObject = ((target == null) ? new DummyEntity() : target); - if (copyObject instanceof DummyEntity) { - final DummyEntity copy = ((DummyEntity) copyObject); - if (this.checkSetKey()) { - copy.setKey(new AxReferenceKey(key)); - } else { - copy.key = null; - } - copy.doubleValue = doubleValue; - return copy; - } else { - return null; - } - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - DummyEntity other = (DummyEntity) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { - return false; - } - if (doubleValue != other.doubleValue) { - return false; - } - return true; - } - - @Override - public int compareTo(AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - DummyEntity other = (DummyEntity) otherObj; - if (key == null) { - if (other.key != null) { - return 1; - } - } else if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - if (doubleValue != other.doubleValue) { - return Double.valueOf(doubleValue).compareTo(other.doubleValue); - } - - return 0; - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ExceptionsTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ExceptionsTest.java deleted file mode 100644 index ff87bc2d0..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ExceptionsTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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.concepts; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; -import org.junit.Test; - - -public class ExceptionsTest { - - @Test - public void test() { - assertNotNull(new ApexException("Message")); - assertNotNull(new ApexException("Message", new AxArtifactKey())); - assertNotNull(new ApexException("Message", new IOException())); - assertNotNull(new ApexException("Message", new IOException(), new AxArtifactKey())); - - AxArtifactKey key = new AxArtifactKey(); - ApexException ae = new ApexException("Message", new IOException("IO exception message"), key); - assertEquals("Message\ncaused by: Message\ncaused by: IO exception message", ae.getCascadedMessage()); - assertEquals(key, ae.getObject()); - - assertNotNull(new ApexRuntimeException("Message")); - assertNotNull(new ApexRuntimeException("Message", new AxArtifactKey())); - assertNotNull(new ApexRuntimeException("Message", new IOException())); - assertNotNull(new ApexRuntimeException("Message", new IOException(), new AxArtifactKey())); - - AxArtifactKey rkey = new AxArtifactKey(); - ApexRuntimeException re = new ApexRuntimeException("Runtime Message", - new IOException("IO runtime exception message"), rkey); - assertEquals("Runtime Message\ncaused by: Runtime Message\ncaused by: IO runtime exception message", - re.getCascadedMessage()); - assertEquals(key, re.getObject()); - - assertNotNull(new ApexConceptException("Message")); - assertNotNull(new ApexConceptException("Message", new IOException())); - - AxArtifactKey ckey = new AxArtifactKey(); - ApexException ace = new ApexException("Concept Message", new IOException("IO concept exception message"), ckey); - assertEquals("Concept Message\ncaused by: Concept Message\ncaused by: IO concept exception message", - ace.getCascadedMessage()); - assertEquals(ckey, ace.getObject()); - } - -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ValidationTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ValidationTest.java deleted file mode 100644 index 21ae9b65c..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ValidationTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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.concepts; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; - -public class ValidationTest { - - @Test - public void test() { - AxValidationResult result = new AxValidationResult(); - AxReferenceKey refKey = new AxReferenceKey("PK", "0.0.1", "PLN", "LN"); - result = refKey.validate(result); - - assertNotNull(result); - assertTrue(result.isOk()); - assertTrue(result.isValid()); - assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); - assertNotNull(result.getMessageList()); - - AxValidationMessage vmess0 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class, - ValidationResult.VALID, "Some message"); - result.addValidationMessage(vmess0); - - assertTrue(result.isOk()); - assertTrue(result.isValid()); - assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); - assertNotNull(result.getMessageList()); - assertNotNull("hello", result.toString()); - - AxValidationMessage vmess1 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class, - ValidationResult.OBSERVATION, "Some message"); - result.addValidationMessage(vmess1); - - assertTrue(result.isOk()); - assertTrue(result.isValid()); - assertEquals(AxValidationResult.ValidationResult.OBSERVATION, result.getValidationResult()); - assertNotNull(result.getMessageList()); - assertNotNull("hello", result.toString()); - - AxValidationMessage vmess2 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class, - ValidationResult.WARNING, "Some message"); - result.addValidationMessage(vmess2); - - assertFalse(result.isOk()); - assertTrue(result.isValid()); - assertEquals(AxValidationResult.ValidationResult.WARNING, result.getValidationResult()); - assertNotNull(result.getMessageList()); - assertNotNull("hello", result.toString()); - - AxValidationMessage vmess3 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class, - ValidationResult.INVALID, "Some message"); - result.addValidationMessage(vmess3); - - assertFalse(result.isOk()); - assertFalse(result.isValid()); - assertEquals(AxValidationResult.ValidationResult.INVALID, result.getValidationResult()); - assertNotNull(result.getMessageList()); - assertNotNull("hello", result.toString()); - - assertEquals(AxValidationResult.ValidationResult.INVALID, result.getMessageList().get(3).getValidationResult()); - assertEquals("Some message", result.getMessageList().get(3).getMessage()); - assertEquals(AxArtifactKey.class.getName(), result.getMessageList().get(3).getObservedClass()); - assertEquals(AxArtifactKey.getNullKey(), result.getMessageList().get(3).getObservedKey()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelExceptionTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelExceptionTest.java deleted file mode 100644 index 2571ea65b..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelExceptionTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 java.io.IOException; -import org.junit.Test; - -public class ApexModelExceptionTest { - - @Test - public void test() { - assertNotNull(new ApexModelException("Message")); - assertNotNull(new ApexModelException("Message", new IOException())); - - ApexModelException ame = new ApexModelException("Message", new IOException("IO exception message")); - assertEquals("Message\ncaused by: Message\ncaused by: IO exception message", ame.getCascadedMessage()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java deleted file mode 100644 index 0f8f956ab..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 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.assertTrue; - -import java.io.File; -import java.io.IOException; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; - -public class ApexModelFileWriterTest { - - @Test - public void testModelFileWriter() throws IOException, ApexException { - ApexModelFileWriter<AxModel> modelFileWriter = new ApexModelFileWriter<>(true); - - modelFileWriter.setValidate(true); - assertTrue(modelFileWriter.isValidate()); - - File tempFile = File.createTempFile("ApexFileWriterTest", "test"); - File tempDir = tempFile.getParentFile(); - - File jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/ApexFileWriterTest.json"); - - AxModel model = new DummyApexBasicModelCreator().getModel(); - - modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); - - jsonTempFile.delete(); - new File(tempDir.getAbsolutePath() + "/aaa").delete(); - new File(tempDir.getAbsolutePath() + "/ccc").delete(); - - jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json"); - - modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); - - jsonTempFile.delete(); - - new File(tempDir.getAbsolutePath() + "/aaa/bbb").delete(); - new File(tempDir.getAbsolutePath() + "/aaa").delete(); - new File(tempDir.getAbsolutePath() + "/ccc/ddd").delete(); - new File(tempDir.getAbsolutePath() + "/ccc").delete(); - - File dirA = new File(tempDir.getAbsolutePath() + "/aaa"); - // File dirB = new File(tempDir.getAbsolutePath() + "/aaa/bbb"); - dirA.createNewFile(); - // dirB.createNewFile(); - - jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json"); - final File jsonTempFile01 = jsonTempFile; - assertThatThrownBy( - () -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile01.getAbsolutePath())) - .hasMessageContaining("could not create directory"); - - dirA.delete(); - - dirA = new File(tempDir.getAbsolutePath() + "/aaa"); - File fileB = new File(tempDir.getAbsolutePath() + "/aaa/bbb"); - dirA.mkdir(); - fileB.createNewFile(); - - jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json"); - - File jsonTempFile02 = jsonTempFile; - assertThatThrownBy( - () -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile02.getAbsolutePath())) - .hasMessageContaining("error processing file"); - - fileB.delete(); - dirA.delete(); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java deleted file mode 100644 index 1152771ea..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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 static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; - -@RunWith(MockitoJUnitRunner.class) -public class ApexModelReaderTest { - @Test - public void testModelReader() throws IOException, ApexException { - AxModel model = new DummyApexBasicModelCreator().getModel(); - AxModel invalidModel = new DummyApexBasicModelCreator().getInvalidModel(); - - ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class); - modelWriter.setValidate(true); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - modelWriter.write(model, baos); - - ByteArrayOutputStream baosInvalid = new ByteArrayOutputStream(); - modelWriter.setValidate(false); - modelWriter.write(invalidModel, baosInvalid); - - ApexModelReader<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class, true); - - modelReader.setValidate(true); - assertTrue(modelReader.isValidate()); - - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - AxModel readModel = modelReader.read(bais); - assertEquals(model, readModel); - - ByteArrayInputStream baisInvalid = new ByteArrayInputStream(baosInvalid.toByteArray()); - assertThatThrownBy(() -> modelReader.read(baisInvalid)) - .hasMessageStartingWith("Apex concept validation failed"); - modelReader.setValidate(false); - assertFalse(modelReader.isValidate()); - - ByteArrayInputStream bais2 = new ByteArrayInputStream(baos.toByteArray()); - AxModel readModel2 = modelReader.read(bais2); - assertEquals(model, readModel2); - - ByteArrayOutputStream baosJson = new ByteArrayOutputStream(); - modelWriter.write(model, baosJson); - - ByteArrayInputStream baisJson = new ByteArrayInputStream(baosJson.toByteArray()); - AxModel readModelJson = modelReader.read(baisJson); - assertEquals(model, readModelJson); - - String dummyString = "SomeDummyText"; - ByteArrayInputStream baisDummy = new ByteArrayInputStream(dummyString.getBytes()); - assertThatThrownBy(() -> modelReader.read(baisDummy)) - .hasMessageContaining("Unable to unmarshal Apex concept"); - ByteArrayInputStream nullBais = null; - assertThatThrownBy(() -> modelReader.read(nullBais)) - .hasMessage("concept stream may not be null"); - - assertThatThrownBy(() -> { - FileInputStream fis = new FileInputStream(new File("somewhere/over/the/rainbow")); - modelReader.read(fis); - }).hasMessageContaining("rainbow"); - final File tempFile = File.createTempFile("Apex", "Dummy"); - BufferedReader br = new BufferedReader(new FileReader(tempFile)); - br.close(); - assertThatThrownBy(() -> modelReader.read(br)) - .hasMessage("Unable to read Apex concept "); - tempFile.delete(); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java deleted file mode 100644 index c95106aa8..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 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.assertNotNull; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; - -public class ApexModelSaverTest { - - @Test - public void testModelSaver() throws IOException, ApexException { - AxModel model = new DummyApexBasicModelCreator().getModel(); - assertNotNull(model); - - Path tempPath = Files.createTempDirectory("ApexTest"); - assertNotNull(tempPath); - - ApexModelSaver<AxModel> modelSaver = - new ApexModelSaver<AxModel>(AxModel.class, model, tempPath.toAbsolutePath().toString()); - assertNotNull(modelSaver); - modelSaver.apexModelWriteJson(); - - Files.deleteIfExists(new File(tempPath.toAbsolutePath() + "/BasicModel.json").toPath()); - Files.deleteIfExists(tempPath); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java deleted file mode 100644 index 13e72d3e2..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 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.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; - -public class ApexModelStringWriterTest { - - @Test - public void testModelStringWriter() throws IOException, ApexException { - AxModel basicModel = new DummyApexBasicModelCreator().getModel(); - assertNotNull(basicModel); - - AxKeyInfo intKeyInfo = basicModel.getKeyInformation().get("IntegerKIKey"); - AxKeyInfo floatKeyInfo = basicModel.getKeyInformation().get("FloatKIKey"); - - // Ensure marshalling is OK - ApexModelStringWriter<AxKeyInfo> stringWriter = new ApexModelStringWriter<AxKeyInfo>(true); - - assertNotNull(stringWriter.writeJsonString(intKeyInfo, AxKeyInfo.class)); - assertNotNull(stringWriter.writeJsonString(floatKeyInfo, AxKeyInfo.class)); - - assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class)); - assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class)); - - assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class)); - assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class)); - - assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class)).hasMessage("concept may not be null"); - assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class)).hasMessage("concept may not be null"); - assertThatThrownBy(() -> stringWriter.writeJsonString(null, AxKeyInfo.class)) - .hasMessage("error writing JSON string"); - stringWriter.setValidate(true); - assertTrue(stringWriter.isValidate()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java deleted file mode 100644 index 063855976..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.assertTrue; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; - -@RunWith(MockitoJUnitRunner.class) -public class ApexModelWriterTest { - @Test - public void testModelWriter() throws IOException, ApexException { - ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class); - - modelWriter.setValidate(true); - assertTrue(modelWriter.isValidate()); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - AxModel model = new DummyApexBasicModelCreator().getModel(); - - modelWriter.write(model, baos); - - modelWriter.setValidate(false); - modelWriter.write(model, baos); - - modelWriter.setValidate(true); - model.getKeyInformation().getKeyInfoMap().clear(); - assertThatThrownBy(() -> modelWriter.write(model, baos)) - .hasMessageContaining("Apex concept (BasicModel:0.0.1) validation failed"); - model.getKeyInformation().generateKeyInfo(model); - - assertThatThrownBy(() -> modelWriter.write(null, baos)) - .hasMessage("concept may not be null"); - - ByteArrayOutputStream nullBaos = null; - assertThatThrownBy(() -> modelWriter.write(model, nullBaos)) - .hasMessage("concept stream may not be null"); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyApexBasicModelCreator.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyApexBasicModelCreator.java deleted file mode 100644 index 353722b2d..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyApexBasicModelCreator.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 java.util.UUID; -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.AxKeyInformation; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; - -public class DummyApexBasicModelCreator implements TestApexModelCreator<AxModel> { - - @Override - public AxModel getModel() { - AxModel basicModel = new AxModel(); - - basicModel.setKey(new AxArtifactKey("BasicModel", "0.0.1")); - basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); - - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey())); - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), - new AxKeyInfo(basicModel.getKeyInformation().getKey())); - - AxKeyInfo intKeyInfo = new AxKeyInfo(new AxArtifactKey("IntegerKIKey", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey description"); - basicModel.getKeyInformation().getKeyInfoMap().put(intKeyInfo.getKey(), new AxKeyInfo(intKeyInfo.getKey())); - - AxKeyInfo floatKeyInfo = new AxKeyInfo(new AxArtifactKey("FloatKIKey", "0.0.1"), UUID.randomUUID(), - "FloatKIKey description"); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKeyInfo.getKey(), new AxKeyInfo(floatKeyInfo.getKey())); - - return basicModel; - } - - @Override - public final AxModel getMalstructuredModel() { - AxModel basicModel = new AxModel(); - - // Note: No Data types - basicModel.setKey(new AxArtifactKey("BasicModelKey", "0.0.1")); - basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); - - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey(), - UUID.fromString("00000000-0000-0000-0000-000000000000"), - "\nbasic model description\nThis is a multi line description\nwith another line of text.")); - - return basicModel; - } - - @Override - public final AxModel getObservationModel() { - AxModel basicModel = getModel(); - - // Set key information as blank - basicModel.getKeyInformation().getKeyInfoMap().get(basicModel.getKey()).setDescription(""); - - return basicModel; - } - - @Override - public final AxModel getWarningModel() { - AxModel basicModel = getModel(); - - // Add unreferenced key information - AxKeyInfo unreferencedKeyInfo0 = new AxKeyInfo(new AxArtifactKey("Unref0", "0.0.1")); - AxKeyInfo unreferencedKeyInfo1 = new AxKeyInfo(new AxArtifactKey("Unref1", "0.0.1")); - - basicModel.getKeyInformation().getKeyInfoMap().put(unreferencedKeyInfo0.getKey(), unreferencedKeyInfo0); - basicModel.getKeyInformation().getKeyInfoMap().put(unreferencedKeyInfo1.getKey(), unreferencedKeyInfo1); - - return basicModel; - } - - @Override - public final AxModel getInvalidModel() { - AxModel basicModel = new AxModel(); - - basicModel.setKey(new AxArtifactKey("BasicModelKey", "0.0.1")); - basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); - - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey(), - UUID.fromString("00000000-0000-0000-0000-000000000000"), - "nbasic model description\nThis is a multi line description\nwith another line of text.")); - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), - new AxKeyInfo(basicModel.getKeyInformation().getKey(), - UUID.fromString("00000000-0000-0000-0000-000000000000"), "")); - - return basicModel; - } - - /** - * Get the model with its references. - * @return the model with its references - */ - public final DummyAxModelWithReferences getModelWithReferences() { - AxModel model = getModel(); - - DummyAxModelWithReferences modelWithReferences = new DummyAxModelWithReferences(model.getKey()); - modelWithReferences.setKeyInformation(model.getKeyInformation()); - modelWithReferences.setReferenceKeyList(); - - return modelWithReferences; - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyAxModelWithReferences.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyAxModelWithReferences.java deleted file mode 100644 index 887755d03..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyAxModelWithReferences.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 java.util.ArrayList; -import java.util.List; -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.AxModel; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; - -public class DummyAxModelWithReferences extends AxModel { - private static final long serialVersionUID = -8194956638511120008L; - - private List<AxKey> extrakeyList = new ArrayList<>(); - - public DummyAxModelWithReferences(final AxArtifactKey key) { - super(key); - } - - @Override - public List<AxKey> getKeys() { - List<AxKey> keys = super.getKeys(); - keys.addAll(extrakeyList); - - return keys; - } - - public List<AxKey> getExtrakeyList() { - return extrakeyList; - } - - /** - * Set the reference key list. - */ - public void setReferenceKeyList() { - List<AxKey> keys = super.getKeys(); - - for (AxKey key: keys) { - AxArtifactKey akey = (AxArtifactKey) key; - AxReferenceKey keyRef = new AxReferenceKey(akey, akey.getName()); - extrakeyList.add(keyRef); - } - } - - public void addKey(final AxKey akey) { - extrakeyList.add(akey); - } - - public void removeKey(final AxKey akey) { - extrakeyList.remove(akey); - } -} 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 deleted file mode 100644 index 905a27f38..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java +++ /dev/null @@ -1,294 +0,0 @@ -/*- - * ============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<AxModel> testApexModel; - - @Before - public void setup() throws Exception { - testApexModel = new TestApexModel<AxModel>(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<AxKeyInfo> keyInfoSet = keyI.getAll("BasicModel"); - assertNotNull(keyInfoSet); - - keyInfoSet = keyI.getAll("BasicModel", "0..0.1"); - assertNotNull(keyInfoSet); - - List<AxKey> 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/SupportApexBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java deleted file mode 100644 index 68f755886..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020-2022 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.test.TestApexModel; - -public class SupportApexBasicModelTest { - // 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" + "********************************"; - - TestApexModel<AxModel> testApexModel; - - /** - * Set up the test. - * - * @throws Exception any exception thrown by the test - */ - @Before - public void setup() throws Exception { - testApexModel = new TestApexModel<AxModel>(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 testModelWriteReadJson() throws Exception { - testApexModel.testApexModelWriteReadJson(); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator0.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator0.java deleted file mode 100644 index e835bc0fc..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator0.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 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.AxKeyInformation; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; - -public class SupportApexModelCreator0 implements TestApexModelCreator<AxModel> { - - @Override - public AxModel getModel() { - AxModel basicModel = new AxModel(); - - basicModel.setKey(new AxArtifactKey("BasicModel", "0.0.1")); - basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); - - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey())); - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), - new AxKeyInfo(basicModel.getKeyInformation().getKey())); - - return basicModel; - } - - @Override - public final AxModel getMalstructuredModel() { - return getModel(); - } - - @Override - public final AxModel getObservationModel() { - return getModel(); - } - - @Override - public final AxModel getWarningModel() { - return getModel(); - } - - @Override - public final AxModel getInvalidModel() { - return getModel(); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator1.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator1.java deleted file mode 100644 index 9ad34a38c..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator1.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 java.util.UUID; -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.AxKeyInformation; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; - -public class SupportApexModelCreator1 implements TestApexModelCreator<AxModel> { - - @Override - public AxModel getModel() { - return getInvalidModel(); - } - - @Override - public final AxModel getMalstructuredModel() { - return getInvalidModel(); - } - - @Override - public final AxModel getObservationModel() { - return getInvalidModel(); - } - - @Override - public final AxModel getWarningModel() { - return getInvalidModel(); - } - - @Override - public final AxModel getInvalidModel() { - AxModel basicModel = new AxModel(); - - basicModel.setKey(new AxArtifactKey("BasicModelKey", "0.0.1")); - basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); - - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey(), - UUID.fromString("00000000-0000-0000-0000-000000000000"), - "nbasic model description\nThis is a multi line description\nwith another line of text.")); - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), - new AxKeyInfo(basicModel.getKeyInformation().getKey(), - UUID.fromString("00000000-0000-0000-0000-000000000000"), "")); - - return basicModel; - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator2.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator2.java deleted file mode 100644 index 0ab7aab7f..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator2.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 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.AxKeyInformation; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; - -public class SupportApexModelCreator2 implements TestApexModelCreator<AxModel> { - - @Override - public AxModel getModel() { - AxModel basicModel = new AxModel(); - - basicModel.setKey(new AxArtifactKey("BasicModel", "0.0.1")); - basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); - - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey())); - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), - new AxKeyInfo(basicModel.getKeyInformation().getKey())); - basicModel.getKeyInformation().get("BasicModel").setDescription(""); - return basicModel; - } - - @Override - public final AxModel getMalstructuredModel() { - return getModel(); - } - - @Override - public final AxModel getObservationModel() { - return getModel(); - } - - @Override - public final AxModel getWarningModel() { - return getModel(); - } - - @Override - public final AxModel getInvalidModel() { - return getModel(); - } -} 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 deleted file mode 100644 index d55a9da29..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020-2022 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<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class, - new DummyApexBasicModelCreator()); - - testApexModel.testApexModelValid(); - assertThatThrownBy(testApexModel::testApexModelVaidateObservation) - .hasMessage("model should have observations"); - testApexModel.testApexModelVaidateWarning(); - testApexModel.testApexModelVaidateInvalidModel(); - testApexModel.testApexModelVaidateMalstructured(); - - testApexModel.testApexModelWriteReadJson(); - } - - @Test - public void testModelsUnequal() throws ApexException { - final TestApexModel<AxModel> testApexModel0 = new TestApexModel<AxModel>(AxModel.class, - new DummyApexBasicModelCreator()); - final TestApexModel<AxModel> testApexModel1 = new TestApexModel<AxModel>(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<AxModel> testApexModel = new TestApexModel<AxModel>(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<AxModel> testApexModel = new TestApexModel<AxModel>(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<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class, - new SupportApexModelCreator2()); - - testApexModel.testApexModelValid(); - testApexModel.testApexModelVaidateObservation(); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) - .hasMessage("model should have warnings"); - } - - @Test - public void testModelCreator1Json() throws ApexException { - final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class, - new SupportApexModelCreator1()); - - assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson()) - .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 deleted file mode 100644 index 1783fc00f..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020-2022 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<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class); - ApexModelFileWriter<AxModel> modelWriter = new ApexModelFileWriter<AxModel>(true); - - modelReader.setValidate(false); - modelWriter.setValidate(false); - - File tempJsonFile = File.createTempFile("ApexModel", "json"); - modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempJsonFile.getCanonicalPath()); - - FileInputStream jsonFileInputStream = new FileInputStream(tempJsonFile); - AxModel readJsonModel = modelReader.read(jsonFileInputStream); - jsonFileInputStream.close(); - assertEquals(basicModel, readJsonModel); - assertEquals(intKI91, readJsonModel.getKeyInformation().get("IntegerKIKey91")); - assertNotNull(readJsonModel.getKeyInformation().get("FloatKIKey")); - tempJsonFile.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/service/ModelServiceTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/service/ModelServiceTest.java deleted file mode 100644 index 746e10607..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/service/ModelServiceTest.java +++ /dev/null @@ -1,65 +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.service; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation; -import org.onap.policy.apex.model.basicmodel.handling.DummyApexBasicModelCreator; - -public class ModelServiceTest { - - @Test - public void testModelService() { - ModelService.clear(); - - assertFalse(ModelService.existsModel(AxKeyInformation.class)); - assertThatThrownBy(() -> ModelService.getModel(AxKeyInformation.class)) - .hasMessage("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation " - + "not found in model service"); - ModelService.registerModel(AxKeyInformation.class, - new DummyApexBasicModelCreator().getModel().getKeyInformation()); - assertTrue(ModelService.existsModel(AxKeyInformation.class)); - assertNotNull(ModelService.getModel(AxKeyInformation.class)); - - ModelService.deregisterModel(AxKeyInformation.class); - - assertFalse(ModelService.existsModel(AxKeyInformation.class)); - assertThatThrownBy(() -> ModelService.getModel(AxKeyInformation.class)) - .hasMessage("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation " - + "not found in model service"); - ModelService.registerModel(AxKeyInformation.class, - new DummyApexBasicModelCreator().getModel().getKeyInformation()); - assertTrue(ModelService.existsModel(AxKeyInformation.class)); - assertNotNull(ModelService.getModel(AxKeyInformation.class)); - - ModelService.clear(); - assertFalse(ModelService.existsModel(AxKeyInformation.class)); - assertThatThrownBy(() -> ModelService.getModel(AxKeyInformation.class)) - .hasMessage("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation " - + "not found in model service"); - } -} diff --git a/model/basic-model/src/test/resources/logback-test.xml b/model/basic-model/src/test/resources/logback-test.xml deleted file mode 100644 index c52f2ded6..000000000 --- a/model/basic-model/src/test/resources/logback-test.xml +++ /dev/null @@ -1,70 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ============LICENSE_START======================================================= - Copyright (C) 2016-2018 Ericsson. All rights reserved. - ================================================================================ - 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========================================================= ---> - -<configuration> - - <contextName>Apex</contextName> - <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> - <property name="LOG_DIR" value="${java.io.tmpdir}/apex_logging/" /> - - <!-- USE FOR STD OUT ONLY --> - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> - <encoder> - <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern> - </encoder> - </appender> - - <root level="INFO"> - <appender-ref ref="STDOUT" /> - </root> - - <logger name="org.infinispan" level="INFO" additivity="false"> - <appender-ref ref="STDOUT" /> - </logger> - - <logger name="org.apache.zookeeper.ClientCnxn" level="OFF" additivity="false"> - <appender-ref ref="STDOUT" /> - </logger> - - <appender name="FILE" class="ch.qos.logback.core.FileAppender"> - <file>${LOG_DIR}/apex.log</file> - <encoder> - <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level - %logger{26} - %msg %n %ex{full}</pattern> - </encoder> - </appender> - - <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender"> - <file>${LOG_DIR}/apex_ctxt.log</file> - <encoder> - <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level - %logger{26} - %msg %n %ex{full}</pattern> - </encoder> - </appender> - - <logger name="org.onap.policy.apex.core.context.impl.monitoring" level="INFO" additivity="false"> - <appender-ref ref="CTXT_FILE" /> - </logger> - - <logger name="org.onap.policy.apex.core.context" level="INFO" additivity="false"> - <appender-ref ref="STDOUT" /> - </logger> -</configuration> |