Java 17 / Spring 6 / Spring Boot 3 Upgrade
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / rest / TestGroupData.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP PAP
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.pap.main.rest;
23
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;
28
29 import org.junit.jupiter.api.BeforeEach;
30 import org.junit.jupiter.api.Test;
31 import org.onap.policy.models.pdp.concepts.PdpGroup;
32
33 class TestGroupData {
34     private static final String NAME = "my-name";
35
36     private PdpGroup oldGroup;
37     private PdpGroup newGroup;
38     private GroupData data;
39
40     /**
41      * Sets up.
42      */
43     @BeforeEach
44     public void setUp() {
45         oldGroup = new PdpGroup();
46         oldGroup.setName(NAME);
47
48         newGroup = new PdpGroup(oldGroup);
49
50         data = new GroupData(oldGroup);
51     }
52
53     @Test
54     void testNew() {
55         data = new GroupData(oldGroup, true);
56         assertSame(oldGroup, data.getGroup());
57
58         assertFalse(data.isUnchanged());
59         assertTrue(data.isNew());
60         assertFalse(data.isUpdated());
61
62         data.update(newGroup);
63         assertFalse(data.isUnchanged());
64         assertTrue(data.isNew());
65         assertFalse(data.isUpdated());
66         assertSame(newGroup, data.getGroup());
67
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());
75     }
76
77     @Test
78     void testUpdateOnly() {
79         assertTrue(data.isUnchanged());
80         assertFalse(data.isUpdated());
81         assertSame(oldGroup, data.getGroup());
82
83         data.update(newGroup);
84
85         assertFalse(data.isUnchanged());
86         assertTrue(data.isUpdated());
87         assertFalse(data.isNew());
88         assertSame(newGroup, data.getGroup());
89
90         // repeat
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());
97
98         // incorrect name
99         newGroup = new PdpGroup(oldGroup);
100         newGroup.setName("other");
101         assertThatIllegalArgumentException().isThrownBy(() -> data.update(newGroup))
102                         .withMessage("expected group my-name, but received other");
103     }
104 }