/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 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.
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
-
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfSearchableKey;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.testconcepts.DummyJpaPdpSubgroupChild;
*/
public class JpaPdpSubGroupTest {
+ private static final String NULL_KEY_ERROR = "key is marked .*ull but is null";
+ private static final String PDP_A = "PDP-A";
+
@Test
public void testJpaPdpSubGroup() {
assertThatThrownBy(() -> {
new JpaPdpSubGroup((JpaPdpSubGroup) null);
- }).hasMessage("copyConcept is marked @NonNull but is null");
+ }).hasMessageMatching("copyConcept is marked .*ull but is null");
assertThatThrownBy(() -> {
new JpaPdpSubGroup((PfReferenceKey) null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaPdpSubGroup((PdpSubGroup) null);
- }).hasMessage("authorativeConcept is marked @NonNull but is null");
+ }).hasMessageMatching("authorativeConcept is marked .*ull but is null");
assertThatThrownBy(() -> {
new JpaPdpSubGroup(null, null, null, null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaPdpSubGroup(new PfReferenceKey(), null, null, null);
- }).hasMessage("supportedPolicyTypes is marked @NonNull but is null");
+ }).hasMessageMatching("supportedPolicyTypes is marked .*ull but is null");
assertThatThrownBy(() -> {
new JpaPdpSubGroup(new PfReferenceKey(), new ArrayList<>(), null, null);
- }).hasMessage("policies is marked @NonNull but is null");
+ }).hasMessageMatching("policies is marked .*ull but is null");
assertThatThrownBy(() -> {
new JpaPdpSubGroup(null, new ArrayList<>(), null, null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaPdpSubGroup(null, new ArrayList<>(), new ArrayList<>(), null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaPdpSubGroup(null, null, new ArrayList<>(), null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaPdpSubGroup(null, null, null, new ArrayList<>());
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaPdpSubGroup(new PfReferenceKey(), null, null, new ArrayList<>());
- }).hasMessage("supportedPolicyTypes is marked @NonNull but is null");
+ }).hasMessageMatching("supportedPolicyTypes is marked .*ull but is null");
assertThatThrownBy(() -> {
new JpaPdpSubGroup(new PfReferenceKey(), new ArrayList<>(), null, new ArrayList<>());
- }).hasMessage("policies is marked @NonNull but is null");
+ }).hasMessageMatching("policies is marked .*ull but is null");
assertThatThrownBy(() -> {
new JpaPdpSubGroup(null, new ArrayList<>(), null, new ArrayList<>());
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaPdpSubGroup(null, new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaPdpSubGroup(null, null, new ArrayList<>(), null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertNotNull(new JpaPdpSubGroup((new PfReferenceKey())));
PdpSubGroup testPdpSubgroup = new PdpSubGroup();
- testPdpSubgroup.setPdpType("PDP-A");
+ testPdpSubgroup.setPdpType(PDP_A);
JpaPdpSubGroup testJpaPdpSubGroup = new JpaPdpSubGroup();
testJpaPdpSubGroup.setKey(null);
testJpaPdpSubGroup.fromAuthorative(testPdpSubgroup);
- assertEquals("PDP-A", testJpaPdpSubGroup.getKey().getLocalName());
+ assertEquals(PDP_A, testJpaPdpSubGroup.getKey().getLocalName());
testJpaPdpSubGroup.setKey(PfReferenceKey.getNullKey());
testJpaPdpSubGroup.fromAuthorative(testPdpSubgroup);
assertThatThrownBy(() -> {
testJpaPdpSubGroup.fromAuthorative(null);
- }).hasMessage("pdpSubgroup is marked @NonNull but is null");
+ }).hasMessageMatching("pdpSubgroup is marked .*ull but is null");
- assertThatThrownBy(() -> {
- testJpaPdpSubGroup.copyTo(null);
- }).hasMessage("target is marked @NonNull but is null");
+ assertThatThrownBy(() -> new JpaPdpSubGroup((JpaPdpSubGroup) null)).isInstanceOf(NullPointerException.class);
- assertEquals("PDP-A", testJpaPdpSubGroup.getKey().getLocalName());
- assertEquals("PDP-A", new JpaPdpSubGroup(testPdpSubgroup).getKey().getLocalName());
- assertEquals("PDP-A", ((PfReferenceKey) new JpaPdpSubGroup(testPdpSubgroup).getKeys().get(0)).getLocalName());
+ assertEquals(PDP_A, testJpaPdpSubGroup.getKey().getLocalName());
+ assertEquals(PDP_A, new JpaPdpSubGroup(testPdpSubgroup).getKey().getLocalName());
+ assertEquals(PDP_A, ((PfReferenceKey) new JpaPdpSubGroup(testPdpSubgroup).getKeys().get(0)).getLocalName());
testJpaPdpSubGroup.clean();
- assertEquals("PDP-A", testJpaPdpSubGroup.getKey().getLocalName());
+ assertEquals(PDP_A, testJpaPdpSubGroup.getKey().getLocalName());
assertThatThrownBy(() -> {
testJpaPdpSubGroup.validate(null);
- }).hasMessage("resultIn is marked @NonNull but is null");
+ }).hasMessageMatching("resultIn is marked .*ull but is null");
assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).toString()
.contains("INVALID:a PDP subgroup must support at least one policy type"));
testJpaPdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
- testJpaPdpSubGroup.getSupportedPolicyTypes().add(new PfConceptKey("APolicyType:1.0.0"));
+ testJpaPdpSubGroup.getSupportedPolicyTypes().add(new PfSearchableKey("APolicyType:1.0.0"));
assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).toString()
.contains("INVALID:a PDP subgroup must support at least one policy type"));
testJpaPdpSubGroup.setProperties(null);
assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
- List<PfConceptKey> supportedPolicyTypes = testJpaPdpSubGroup.getSupportedPolicyTypes();
+ List<PfSearchableKey> supportedPolicyTypes = testJpaPdpSubGroup.getSupportedPolicyTypes();
assertNotNull(supportedPolicyTypes);
testJpaPdpSubGroup.setSupportedPolicyTypes(null);
assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
assertEquals(0, testJpaPdpSubGroup.compareTo(otherJpaPdpSubGroup));
assertEquals(-1, testJpaPdpSubGroup.compareTo(null));
assertEquals(0, testJpaPdpSubGroup.compareTo(testJpaPdpSubGroup));
- assertFalse(testJpaPdpSubGroup.compareTo(new DummyJpaPdpSubgroupChild()) == 0);
+ assertNotEquals(0, testJpaPdpSubGroup.compareTo(new DummyJpaPdpSubgroupChild()));
testJpaPdpSubGroup.getKey().setParentKeyName("Parent1");
assertEquals(1, testJpaPdpSubGroup.compareTo(otherJpaPdpSubGroup));
testJpaPdpSubGroup.setDesiredInstanceCount(0);
assertEquals(0, testJpaPdpSubGroup.compareTo(otherJpaPdpSubGroup));
- PfConceptKey anotherPolicyType = new PfConceptKey("AnotherPolicyType", "1.0.0");
+ PfSearchableKey anotherPolicyType = new PfSearchableKey("AnotherPolicyType.*", "1.0.0");
testJpaPdpSubGroup.getSupportedPolicyTypes().add(anotherPolicyType);
assertNotEquals(0, testJpaPdpSubGroup.compareTo(otherJpaPdpSubGroup));
testJpaPdpSubGroup.getSupportedPolicyTypes().remove(anotherPolicyType);
assertEquals("Prop Value", testJpaPdpSubGroup.getProperties().get("PropKey"));
assertEquals(4, testJpaPdpSubGroup.getKeys().size());
+
+ assertEquals(testJpaPdpSubGroup, new JpaPdpSubGroup(testJpaPdpSubGroup));
}
}