diff options
Diffstat (limited to 'models-pdp')
15 files changed, 969 insertions, 1 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java new file mode 100644 index 000000000..4a26b16dd --- /dev/null +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 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.models.pdp.concepts; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.pdp.enums.PdpState; +import org.onap.policy.models.tosca.simple.concepts.ToscaEntityType; + +/** + * Class to represent a PDPGroup, which groups multiple PDPSubGroup entities together for + * a particular domain. + * + * @author Ram Krishna Verma (ram.krishna.verma@est.tech) + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +public class PdpGroup extends ToscaEntityType { + private static final long serialVersionUID = 1L; + + private PdpState pdpGroupState; + private Map<String, String> properties; + private List<PdpSubGroup> pdpSubgroups; + + /* + * Note: removed "@NotNull" annotation from the constructor argument, because it + * cannot be covered by a junit test, as the superclass does the check and throws an + * exception first. + */ + + /** + * Constructs the object, making a deep copy from the source. + * + * @param source source from which to copy fields + */ + public PdpGroup(PdpGroup source) { + super(source); + this.pdpGroupState = source.pdpGroupState; + this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties)); + this.pdpSubgroups = PfUtils.mapList(source.pdpSubgroups, PdpSubGroup::new); + } +} diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java new file mode 100644 index 000000000..ea1c8ff55 --- /dev/null +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pdp.concepts; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * Request deploy or update a set of groups via the PDP Group deployment + * REST API. + */ +@Getter +@Setter +@ToString +public class PdpGroups { + private List<PdpGroup> groups; +} diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpInstanceDetails.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpInstanceDetails.java new file mode 100644 index 000000000..6cf122e19 --- /dev/null +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpInstanceDetails.java @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 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.models.pdp.concepts; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.models.pdp.enums.PdpHealthStatus; +import org.onap.policy.models.pdp.enums.PdpState; + +/** + * Class to represent details of a running instance of PDP. + * + * @author Ram Krishna Verma (ram.krishna.verma@est.tech) + */ +@Getter +@Setter +@ToString +@NoArgsConstructor +public class PdpInstanceDetails { + + @NonNull + private String instanceId; + + @NonNull + private PdpState pdpState; + + private PdpHealthStatus healthy; + private String message; + + /** + * Constructs the object, creating a deep copy of the fields from the source. + * + * @param source source from which to copy the fields + */ + public PdpInstanceDetails(PdpInstanceDetails source) { + this.instanceId = source.instanceId; + this.pdpState = source.pdpState; + this.healthy = source.healthy; + this.message = source.message; + } +} diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java index f7b911fc4..814d35732 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatus.java @@ -25,7 +25,6 @@ import java.util.List; import lombok.Getter; import lombok.Setter; import lombok.ToString; -import org.onap.policy.models.base.keys.PolicyTypeIdent; import org.onap.policy.models.pdp.enums.PdpHealthStatus; import org.onap.policy.models.pdp.enums.PdpMessageType; import org.onap.policy.models.pdp.enums.PdpState; diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java new file mode 100644 index 000000000..0466c6300 --- /dev/null +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java @@ -0,0 +1,76 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 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.models.pdp.concepts; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; + +/** + * Class to represent a group of all PDP's of the same pdp type running for a particular + * domain. + * + * @author Ram Krishna Verma (ram.krishna.verma@est.tech) + */ +@Getter +@Setter +@ToString +public class PdpSubGroup { + + // TODO subclass from ToscaEntityType + + private String pdpType; + private List<PolicyTypeIdent> supportedPolicyTypes; + private List<ToscaPolicy> policies; + private int currentInstanceCount; + private int desiredInstanceCount; + private Map<String, String> properties; + private List<PdpInstanceDetails> pdpInstances; + + /** + * Constructs the object. + */ + public PdpSubGroup() { + super(); + } + + /** + * Constructs the object, making a deep copy from the source. + * + * @param source source from which to copy fields + */ + public PdpSubGroup(@NonNull PdpSubGroup source) { + this.pdpType = source.pdpType; + this.supportedPolicyTypes = PfUtils.mapList(source.supportedPolicyTypes, PolicyTypeIdent::new); + this.policies = PfUtils.mapList(source.policies, ToscaPolicy::new); + this.currentInstanceCount = source.currentInstanceCount; + this.desiredInstanceCount = source.desiredInstanceCount; + this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties)); + this.pdpInstances = PfUtils.mapList(source.pdpInstances, PdpInstanceDetails::new); + } +} diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdent.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdent.java new file mode 100644 index 000000000..6d6b6fedd --- /dev/null +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdent.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pdp.concepts; + +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.base.Validated; + +/** + * Identifies a policy. Both the name and version must be non-null. + */ +@NonNull +@NoArgsConstructor +public class PolicyIdent extends PfConceptKey { + private static final long serialVersionUID = 1L; + private static final Validated validator = new Validated(); + + public PolicyIdent(String name, String version) { + super(name, version); + } + + public PolicyIdent(PolicyIdent source) { + super(source); + } + + @Override + public PfValidationResult validate(PfValidationResult result) { + return super.validate(validator.validateNotNull(this, result)); + } +} diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdentOptVersion.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdentOptVersion.java new file mode 100644 index 000000000..a68a271f2 --- /dev/null +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyIdentOptVersion.java @@ -0,0 +1,61 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pdp.concepts; + +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.base.Validated; + +/** + * Policy identifier with an optional version; only the "name" is required. + */ +@NonNull +@NoArgsConstructor +public class PolicyIdentOptVersion extends PfConceptKey { + private static final long serialVersionUID = 1L; + private static final Validated validator = new Validated(); + + + public PolicyIdentOptVersion(PolicyIdentOptVersion source) { + super(source); + } + + /** + * Validates the object. + * + * @param resultIn where to place any errors + * @return a validation result + */ + public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { + PfValidationResult result = resultIn; + + String name = getName(); + if (PfConceptKey.NULL_KEY_NAME.equals(name)) { + validator.addError(this, "name", result, "null"); + } + result = validator.validateText(this, "name", name, PfKey.NAME_REGEXP, result); + + return validator.validateText(this, "version", getVersion(), PfKey.VERSION_REGEXP, result); + } +} diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyTypeIdent.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyTypeIdent.java new file mode 100644 index 000000000..ef67de86e --- /dev/null +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PolicyTypeIdent.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pdp.concepts; + +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.base.Validated; + +/** + * Identifies a policy type. Both the name and version must be non-null. + */ +@NonNull +@NoArgsConstructor +public class PolicyTypeIdent extends PfConceptKey { + private static final long serialVersionUID = 1L; + private static final Validated validator = new Validated(); + + public PolicyTypeIdent(String name, String version) { + super(name, version); + } + + public PolicyTypeIdent(PolicyTypeIdent source) { + super(source); + } + + @Override + public PfValidationResult validate(PfValidationResult result) { + return super.validate(validator.validateNotNull(this, result)); + } +} diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/IdentTestBase.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/IdentTestBase.java new file mode 100644 index 000000000..10bc9a997 --- /dev/null +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/IdentTestBase.java @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pdp.concepts; + +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; + +/** + * Super class to test identity keys. + * + * @param <T> type of key being tested + */ +public class IdentTestBase<T> { + + private static final Coder coder = new StandardCoder(); + + private final Class<T> clazz; + + + /** + * Constructs the object. + * @param clazz the type of class being tested + */ + public IdentTestBase(Class<T> clazz) { + this.clazz = clazz; + } + + /** + * Makes an identifier. Uses JSON which does no error checking. + * + * @param name name to put into the identifier + * @param version version to put into the identifier + * @return a new identifier + * @throws CoderException if the JSON cannot be decoded + */ + public T makeIdent(String name, String version) throws CoderException { + StringBuilder bldr = new StringBuilder(); + bldr.append("{"); + + if (name != null) { + bldr.append("'name':'"); + bldr.append(name); + bldr.append("'"); + } + + if (version != null) { + if (name != null) { + bldr.append(','); + } + + bldr.append("'version':'"); + bldr.append(version); + bldr.append("'"); + } + + bldr.append("}"); + + String json = bldr.toString().replace('\'', '"'); + + return coder.decode(json, clazz); + } +} diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java new file mode 100644 index 000000000..51bb66c97 --- /dev/null +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pdp.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.Map; +import java.util.TreeMap; +import org.junit.Test; +import org.onap.policy.models.pdp.enums.PdpState; + +/** + * Test the copy constructor, as {@link TestModels} tests the other methods. + */ +public class TestPdpGroup { + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new PdpGroup(null)).isInstanceOf(NullPointerException.class); + + PdpGroup orig = new PdpGroup(); + + // verify with null values + assertEquals("PdpGroup(pdpGroupState=null, properties=null, pdpSubgroups=[])", new PdpGroup(orig).toString()); + + // verify with all values + orig.setDescription("my-descript"); + orig.getKey().setName("my-name"); + orig.setPdpGroupState(PdpState.SAFE); + + PdpSubGroup sub1 = new PdpSubGroup(); + sub1.setCurrentInstanceCount(10); + PdpSubGroup sub2 = new PdpSubGroup(); + sub2.setCurrentInstanceCount(11); + orig.setPdpSubgroups(Arrays.asList(sub1, sub2)); + + Map<String, String> props = new TreeMap<>(); + props.put("key-A", "value-A"); + props.put("key-B", "value-B"); + orig.setProperties(props); + + assertEquals("PdpGroup(pdpGroupState=SAFE, properties={key-A=value-A, key-B=value-B}, " + + "pdpSubgroups=[PdpSubGroup(pdpType=null, supportedPolicyTypes=[], policies=[], " + + "currentInstanceCount=10, desiredInstanceCount=0, properties=null, pdpInstances=[]), " + + "PdpSubGroup(pdpType=null, supportedPolicyTypes=[], policies=[], currentInstanceCount=11, " + + "desiredInstanceCount=0, properties=null, pdpInstances=[])])", new PdpGroup(orig).toString()); + } + + @Test + public void testHashCode() { + PdpGroup group = new PdpGroup(); + group.setDescription("A"); + int hash = group.hashCode(); + + assertEquals(hash, group.hashCode()); + + group.setDescription("B"); + assertTrue(hash != group.hashCode()); + } +} diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpInstanceDetails.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpInstanceDetails.java new file mode 100644 index 000000000..2220ae126 --- /dev/null +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpInstanceDetails.java @@ -0,0 +1,52 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pdp.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.models.pdp.enums.PdpHealthStatus; +import org.onap.policy.models.pdp.enums.PdpState; + +/** + * Test the copy constructor, as {@link TestModels} tests the other methods. + */ +public class TestPdpInstanceDetails { + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new PdpInstanceDetails(null)).isInstanceOf(NullPointerException.class); + + PdpInstanceDetails orig = new PdpInstanceDetails(); + + // verify with null values + assertEquals(orig.toString(), new PdpInstanceDetails(orig).toString()); + + // verify with all values + orig.setHealthy(PdpHealthStatus.TEST_IN_PROGRESS); + orig.setInstanceId("my-instance"); + orig.setMessage("my-message"); + orig.setPdpState(PdpState.SAFE); + + assertEquals(orig.toString(), new PdpInstanceDetails(orig).toString()); + } +} diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java new file mode 100644 index 000000000..bc6363fae --- /dev/null +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pdp.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.Map; +import java.util.TreeMap; +import org.junit.Test; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; + +/** + * Test the copy constructor, as {@link TestModels} tests the other methods. + */ +public class TestPdpSubGroup { + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new PdpSubGroup(null)).isInstanceOf(NullPointerException.class); + + PdpSubGroup orig = new PdpSubGroup(); + + // verify with null values + assertEquals( + "PdpSubGroup(pdpType=null, supportedPolicyTypes=[], policies=[], " + + "currentInstanceCount=0, desiredInstanceCount=0, properties=null, pdpInstances=[])", + new PdpSubGroup(orig).toString()); + + // verify with all values + orig.setCurrentInstanceCount(10); + orig.setDesiredInstanceCount(11); + + PdpInstanceDetails inst1 = new PdpInstanceDetails(); + inst1.setInstanceId("my-id-A"); + PdpInstanceDetails inst2 = new PdpInstanceDetails(); + inst2.setInstanceId("my-id-B"); + orig.setPdpInstances(Arrays.asList(inst1, inst2)); + + orig.setPdpType("my-type"); + + ToscaPolicy pol1 = new ToscaPolicy(); + pol1.setDescription("policy-A"); + ToscaPolicy pol2 = new ToscaPolicy(); + pol2.setDescription("policy-B"); + orig.setPolicies(Arrays.asList(pol1, pol2)); + + Map<String, String> props = new TreeMap<>(); + props.put("key-A", "value-A"); + props.put("key-B", "value-B"); + orig.setProperties(props); + + PolicyTypeIdent supp1 = new PolicyTypeIdent("supp-A", "1.2"); + PolicyTypeIdent supp2 = new PolicyTypeIdent("supp-B", "3.4"); + orig.setSupportedPolicyTypes(Arrays.asList(supp1, supp2)); + + assertEquals(orig.toString(), new PdpSubGroup(orig).toString()); + } +} diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdent.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdent.java new file mode 100644 index 000000000..4cd5570e2 --- /dev/null +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdent.java @@ -0,0 +1,90 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pdp.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.assertTrue; + +import org.junit.Test; +import org.onap.policy.models.base.PfValidationResult; + +/** + * Test the other constructors, as {@link TestModels} tests the other methods. + */ +public class TestPolicyIdent extends IdentTestBase<PolicyIdent> { + private static final String NAME = "my-name"; + private static final String VERSION = "1.2.3"; + + public TestPolicyIdent() { + super(PolicyIdent.class); + } + + @Test + public void testAllArgsConstructor() { + assertThatThrownBy(() -> new PolicyIdent(null, VERSION)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> new PolicyIdent(NAME, null)).isInstanceOf(NullPointerException.class); + + PolicyIdent orig = new PolicyIdent(NAME, VERSION); + assertEquals(NAME, orig.getName()); + assertEquals(VERSION, orig.getVersion()); + } + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new PolicyIdent(null)).isInstanceOf(NullPointerException.class); + + PolicyIdent orig = new PolicyIdent(); + + // verify with null values + assertEquals(orig.toString(), new PolicyIdent(orig).toString()); + + // verify with all values + orig = new PolicyIdent(NAME, VERSION); + assertEquals(orig.toString(), new PolicyIdent(orig).toString()); + } + + @Test + public void testValidate() throws Exception { + assertTrue(makeIdent(NAME, VERSION).validate(new PfValidationResult()).isValid()); + + // everything is null + PfValidationResult result = makeIdent(null, null).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(2, result.getMessageList().size()); + + // name is null + result = makeIdent(null, VERSION).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(1, result.getMessageList().size()); + + // version is null + result = makeIdent(NAME, null).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(1, result.getMessageList().size()); + + // version is invalid + result = makeIdent(NAME, "!!!" + VERSION).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(1, result.getMessageList().size()); + } +} diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdentOptVersion.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdentOptVersion.java new file mode 100644 index 000000000..3428ac1be --- /dev/null +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyIdentOptVersion.java @@ -0,0 +1,87 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pdp.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.assertTrue; + +import org.junit.Test; +import org.onap.policy.models.base.PfValidationResult; + +/** + * Test the other constructors, as {@link TestModels} tests the other methods. + */ +public class TestPolicyIdentOptVersion extends IdentTestBase<PolicyIdentOptVersion> { + private static final String NAME = "my-name"; + private static final String VERSION = "1.2.3"; + + public TestPolicyIdentOptVersion() { + super(PolicyIdentOptVersion.class); + } + + @Test + public void testCopyConstructor() throws Exception { + assertThatThrownBy(() -> new PolicyIdentOptVersion(null)).isInstanceOf(NullPointerException.class); + + PolicyIdentOptVersion orig = new PolicyIdentOptVersion(); + + // verify with null values + assertEquals(orig.toString(), new PolicyIdentOptVersion(orig).toString()); + + // verify with all values + orig = makeIdent(NAME, VERSION); + assertEquals(orig.toString(), new PolicyIdentOptVersion(orig).toString()); + } + + @Test + public void testValidate() throws Exception { + assertThatThrownBy(() -> makeIdent(NAME, VERSION).validate(null)).isInstanceOf(NullPointerException.class); + assertTrue(makeIdent(NAME, VERSION).validate(new PfValidationResult()).isValid()); + assertTrue(makeIdent(NAME, null).validate(new PfValidationResult()).isValid()); + + // everything is null + PfValidationResult result = makeIdent(null, null).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(1, result.getMessageList().size()); + + // name is null + result = makeIdent(null, VERSION).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(1, result.getMessageList().size()); + + // name is null, version is invalid + result = makeIdent(null, "$$$" + VERSION).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(2, result.getMessageList().size()); + + // name is invalid + result = makeIdent("!!!invalid name$$$", VERSION).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(1, result.getMessageList().size()); + + // version is invalid + result = makeIdent(NAME, "!!!" + VERSION).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(1, result.getMessageList().size()); + } +} diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyTypeIdent.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyTypeIdent.java new file mode 100644 index 000000000..5b7494ebf --- /dev/null +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPolicyTypeIdent.java @@ -0,0 +1,91 @@ +/* + * ============LICENSE_START======================================================= + * ONAP Policy Models + * ================================================================================ + * Copyright (C) 2019 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.pdp.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.assertTrue; + +import org.junit.Test; +import org.onap.policy.models.base.PfValidationResult; + +/** + * Test the other constructors, as {@link TestModels} tests the other methods. + */ +public class TestPolicyTypeIdent extends IdentTestBase<PolicyTypeIdent> { + private static final String NAME = "my-name"; + private static final String VERSION = "1.2.3"; + + public TestPolicyTypeIdent() { + super(PolicyTypeIdent.class); + } + + @Test + public void testAllArgsConstructor() { + assertThatThrownBy(() -> new PolicyTypeIdent(null, VERSION)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> new PolicyTypeIdent(NAME, null)).isInstanceOf(NullPointerException.class); + + PolicyTypeIdent orig = new PolicyTypeIdent(NAME, VERSION); + assertEquals(NAME, orig.getName()); + assertEquals(VERSION, orig.getVersion()); + } + + @Test + public void testCopyConstructor() { + assertThatThrownBy(() -> new PolicyTypeIdent(null)).isInstanceOf(NullPointerException.class); + + PolicyTypeIdent orig = new PolicyTypeIdent(); + + // verify with null values + assertEquals(orig.toString(), new PolicyTypeIdent(orig).toString()); + + // verify with all values + orig = new PolicyTypeIdent(NAME, VERSION); + assertEquals(orig.toString(), new PolicyTypeIdent(orig).toString()); + } + + @Test + public void testValidate() throws Exception { + assertTrue(makeIdent(NAME, VERSION).validate(new PfValidationResult()).isValid()); + + // everything is null + PfValidationResult result = makeIdent(null, null).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(2, result.getMessageList().size()); + + // name is null + result = makeIdent(null, VERSION).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(1, result.getMessageList().size()); + + // version is null + result = makeIdent(NAME, null).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(1, result.getMessageList().size()); + + // version is invalid + result = makeIdent(NAME, "!!!" + VERSION).validate(new PfValidationResult()); + assertFalse(result.isValid()); + assertEquals(1, result.getMessageList().size()); + } + +} |