/*-
* ============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;
*/
public class JpaPdpGroupTest {
+ private static final String NULL_ERROR = " is marked .*ull but is null";
+ private static final String NULL_KEY_ERROR = "key" + NULL_ERROR;
+ private static final String PDP_GROUP0 = "PDPGroup0";
+ private static final String VERSION = "1.0.0";
+
@Test
public void testJpaPdpGroup() {
assertThatThrownBy(() -> {
new JpaPdpGroup((JpaPdpGroup) null);
- }).hasMessage("copyConcept is marked @NonNull but is null");
+ }).hasMessageMatching("copyConcept" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaPdpGroup((PfConceptKey) null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaPdpGroup((PdpGroup) null);
- }).hasMessage("authorativeConcept is marked @NonNull but is null");
+ }).hasMessageMatching("authorativeConcept" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaPdpGroup((JpaPdpGroup) null);
- }).hasMessage("copyConcept is marked @NonNull but is null");
+ }).hasMessageMatching("copyConcept" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaPdpGroup(null, null, null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaPdpGroup(new PfConceptKey(), null, null);
- }).hasMessage("pdpGroupState is marked @NonNull but is null");
+ }).hasMessageMatching("pdpGroupState" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaPdpGroup(new PfConceptKey(), PdpState.PASSIVE, null);
- }).hasMessage("pdpSubGroups is marked @NonNull but is null");
+ }).hasMessageMatching("pdpSubGroups" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaPdpGroup(null, PdpState.PASSIVE, null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaPdpGroup(null, PdpState.PASSIVE, new ArrayList<>());
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertThatThrownBy(() -> {
new JpaPdpGroup(null, null, new ArrayList<>());
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching(NULL_KEY_ERROR);
assertNotNull(new JpaPdpGroup((new PfConceptKey())));
assertNotNull(new JpaPdpGroup((new JpaPdpGroup())));
PdpGroup testPdpGroup = new PdpGroup();
- testPdpGroup.setName("PDPGroup0");
+ testPdpGroup.setName(PDP_GROUP0);
testPdpGroup.setPdpSubgroups(new ArrayList<>());
JpaPdpGroup testJpaPdpGroup = new JpaPdpGroup();
testJpaPdpGroup.setKey(null);
testJpaPdpGroup.setKey(new PfConceptKey());
- testPdpGroup.setVersion("1.0.0");
+ testPdpGroup.setVersion(VERSION);
testJpaPdpGroup.fromAuthorative(testPdpGroup);
- assertEquals("PDPGroup0", testJpaPdpGroup.getKey().getName());
+ assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName());
testJpaPdpGroup.setKey(PfConceptKey.getNullKey());
testJpaPdpGroup.fromAuthorative(testPdpGroup);
assertThatThrownBy(() -> {
testJpaPdpGroup.fromAuthorative(null);
- }).hasMessage("pdpGroup is marked @NonNull but is null");
+ }).hasMessageMatching("pdpGroup" + NULL_ERROR);
- testJpaPdpGroup.setKey(new PfConceptKey("PDPGroup0", "1.0.0"));
+ testJpaPdpGroup.setKey(new PfConceptKey(PDP_GROUP0, VERSION));
testJpaPdpGroup.fromAuthorative(testPdpGroup);
- assertThatThrownBy(() -> {
- testJpaPdpGroup.copyTo(null);
- }).hasMessage("target is marked @NonNull but is null");
+ assertThatThrownBy(() -> new JpaPdpGroup((JpaPdpGroup) null)).isInstanceOf(NullPointerException.class);
- assertEquals("PDPGroup0", testJpaPdpGroup.getKey().getName());
- assertEquals("PDPGroup0", new JpaPdpGroup(testPdpGroup).getKey().getName());
- assertEquals("PDPGroup0", ((PfConceptKey) new JpaPdpGroup(testPdpGroup).getKeys().get(0)).getName());
+ assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName());
+ assertEquals(PDP_GROUP0, new JpaPdpGroup(testPdpGroup).getKey().getName());
+ assertEquals(PDP_GROUP0, ((PfConceptKey) new JpaPdpGroup(testPdpGroup).getKeys().get(0)).getName());
testJpaPdpGroup.clean();
- assertEquals("PDPGroup0", testJpaPdpGroup.getKey().getName());
+ assertEquals(PDP_GROUP0, testJpaPdpGroup.getKey().getName());
assertThatThrownBy(() -> {
testJpaPdpGroup.validate(null);
- }).hasMessage("resultIn is marked @NonNull but is null");
+ }).hasMessageMatching("resultIn" + NULL_ERROR);
assertFalse(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
testJpaPdpGroup.setPdpGroupState(PdpState.PASSIVE);
testJpaPdpGroup.setKey(PfConceptKey.getNullKey());
assertFalse(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
- testJpaPdpGroup.setKey(new PfConceptKey("PdpGroup0", "1.0.0"));
+ testJpaPdpGroup.setKey(new PfConceptKey("PdpGroup0", VERSION));
assertTrue(testJpaPdpGroup.validate(new PfValidationResult()).isOk());
testJpaPdpGroup.setDescription(" ");
assertEquals(0, testJpaPdpGroup.compareTo(otherJpaPdpGroup));
assertEquals(-1, testJpaPdpGroup.compareTo(null));
assertEquals(0, testJpaPdpGroup.compareTo(testJpaPdpGroup));
- assertFalse(testJpaPdpGroup.compareTo(new DummyJpaPdpSubgroupChild()) == 0);
+ assertNotEquals(0, testJpaPdpGroup.compareTo(new DummyJpaPdpSubgroupChild()));
testJpaPdpGroup.getKey().setName("OtherName");
assertEquals(-1, testJpaPdpGroup.compareTo(otherJpaPdpGroup));
assertEquals(2, testJpaPdpGroup.getKeys().size());
testJpaPdpGroup.clean();
assertEquals(2, testJpaPdpGroup.getKeys().size());
+
+ assertEquals(testJpaPdpGroup, new JpaPdpGroup(testJpaPdpGroup));
}
}