2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pap.main.rest;
23 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertSame;
26 import static org.junit.Assert.assertTrue;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.policy.models.pdp.concepts.PdpGroup;
32 public class TestGroupData {
33 private static final String NAME = "my-name";
35 private PdpGroup oldGroup;
36 private PdpGroup newGroup;
37 private GroupData data;
44 oldGroup = new PdpGroup();
45 oldGroup.setName(NAME);
47 newGroup = new PdpGroup(oldGroup);
49 data = new GroupData(oldGroup);
53 public void testNew() {
54 data = new GroupData(oldGroup, true);
55 assertSame(oldGroup, data.getGroup());
57 assertFalse(data.isUnchanged());
58 assertTrue(data.isNew());
59 assertFalse(data.isUpdated());
61 data.update(newGroup);
62 assertFalse(data.isUnchanged());
63 assertTrue(data.isNew());
64 assertFalse(data.isUpdated());
65 assertSame(newGroup, data.getGroup());
67 // repeat with a new group
68 newGroup = new PdpGroup(oldGroup);
69 data.update(newGroup);
70 assertFalse(data.isUnchanged());
71 assertTrue(data.isNew());
72 assertFalse(data.isUpdated());
73 assertSame(newGroup, data.getGroup());
77 public void testUpdateOnly() {
78 assertTrue(data.isUnchanged());
79 assertFalse(data.isUpdated());
80 assertSame(oldGroup, data.getGroup());
82 data.update(newGroup);
84 assertFalse(data.isUnchanged());
85 assertTrue(data.isUpdated());
86 assertFalse(data.isNew());
87 assertSame(newGroup, data.getGroup());
90 newGroup = new PdpGroup(oldGroup);
91 data.update(newGroup);
92 assertFalse(data.isUnchanged());
93 assertTrue(data.isUpdated());
94 assertFalse(data.isNew());
95 assertSame(newGroup, data.getGroup());
98 newGroup = new PdpGroup(oldGroup);
99 newGroup.setName("other");
100 assertThatIllegalArgumentException().isThrownBy(() -> data.update(newGroup))
101 .withMessage("expected group my-name, but received other");