2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2023 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.pap.main.rest;
24 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
25 import static org.junit.jupiter.api.Assertions.assertFalse;
26 import static org.junit.jupiter.api.Assertions.assertSame;
27 import static org.junit.jupiter.api.Assertions.assertTrue;
29 import org.junit.jupiter.api.BeforeEach;
30 import org.junit.jupiter.api.Test;
31 import org.onap.policy.models.pdp.concepts.PdpGroup;
34 private static final String NAME = "my-name";
36 private PdpGroup oldGroup;
37 private PdpGroup newGroup;
38 private GroupData data;
45 oldGroup = new PdpGroup();
46 oldGroup.setName(NAME);
48 newGroup = new PdpGroup(oldGroup);
50 data = new GroupData(oldGroup);
55 data = new GroupData(oldGroup, true);
56 assertSame(oldGroup, data.getGroup());
58 assertFalse(data.isUnchanged());
59 assertTrue(data.isNew());
60 assertFalse(data.isUpdated());
62 data.update(newGroup);
63 assertFalse(data.isUnchanged());
64 assertTrue(data.isNew());
65 assertFalse(data.isUpdated());
66 assertSame(newGroup, data.getGroup());
68 // repeat with a new group
69 newGroup = new PdpGroup(oldGroup);
70 data.update(newGroup);
71 assertFalse(data.isUnchanged());
72 assertTrue(data.isNew());
73 assertFalse(data.isUpdated());
74 assertSame(newGroup, data.getGroup());
78 void testUpdateOnly() {
79 assertTrue(data.isUnchanged());
80 assertFalse(data.isUpdated());
81 assertSame(oldGroup, data.getGroup());
83 data.update(newGroup);
85 assertFalse(data.isUnchanged());
86 assertTrue(data.isUpdated());
87 assertFalse(data.isNew());
88 assertSame(newGroup, data.getGroup());
91 newGroup = new PdpGroup(oldGroup);
92 data.update(newGroup);
93 assertFalse(data.isUnchanged());
94 assertTrue(data.isUpdated());
95 assertFalse(data.isNew());
96 assertSame(newGroup, data.getGroup());
99 newGroup = new PdpGroup(oldGroup);
100 newGroup.setName("other");
101 assertThatIllegalArgumentException().isThrownBy(() -> data.update(newGroup))
102 .withMessage("expected group my-name, but received other");