Merge "Add debugging of REST call"
[policy/drools-applications.git] / controlloop / common / model-impl / events / src / test / java / org / onap / policy / controlloop / ControlLoopNotificationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * controlloop
4  * ================================================================================
5  * Copyright (C) 2018 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.controlloop;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25
26 import java.time.ZoneOffset;
27 import java.time.ZonedDateTime;
28 import java.util.Collections;
29 import java.util.UUID;
30 import org.junit.Test;
31 import org.onap.policy.controlloop.util.Serialization;
32
33 public class ControlLoopNotificationTest {
34     
35     private class TestControlLoopNotification extends ControlLoopNotification {
36         private static final long serialVersionUID = 1L;
37     
38         public TestControlLoopNotification() {
39             super();
40         }
41
42         public TestControlLoopNotification(ControlLoopEvent event) {
43             super(event);
44         }
45     }
46
47     @Test
48     public void test() {
49         ControlLoopNotification notification = new TestControlLoopNotification();
50
51         assertEquals("1.0.2", notification.getVersion());
52         
53         notification.setClosedLoopControlName("name");
54         assertEquals("name", notification.getClosedLoopControlName());
55         
56         notification.setClosedLoopEventClient("client");
57         assertEquals("client", notification.getClosedLoopEventClient());
58         
59         notification.setFrom("from");
60         assertEquals("from", notification.getFrom());
61         
62         notification.setHistory(Collections.emptyList());
63         assertTrue(notification.getHistory().size() == 0);
64         
65         notification.setMessage("message");
66         assertEquals("message", notification.getMessage());
67         
68         notification.setNotification(ControlLoopNotificationType.ACTIVE);
69         assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
70         
71         ZonedDateTime time = ZonedDateTime.now(ZoneOffset.UTC);
72         notification.setNotificationTime(time);
73         assertEquals(time, notification.getNotificationTime());
74         
75         notification.setOpsClTimer(Integer.valueOf(1000));
76         assertEquals(Integer.valueOf(1000), notification.getOpsClTimer());
77         
78         notification.setPolicyName("name");
79         assertEquals("name", notification.getPolicyName());
80         
81         notification.setPolicyScope("scope");
82         assertEquals("scope", notification.getPolicyScope());
83         
84         notification.setPolicyVersion("1");
85         assertEquals("1", notification.getPolicyVersion());
86         
87         UUID id = UUID.randomUUID();
88         notification.setRequestId(id);
89         assertEquals(id, notification.getRequestId());
90         
91         notification.setTarget("target");
92         assertEquals("target", notification.getTarget());
93         
94         notification.setTargetType(ControlLoopTargetType.VFC);
95         assertEquals(ControlLoopTargetType.VFC, notification.getTargetType());
96
97         VirtualControlLoopEvent event = new VirtualControlLoopEvent();
98         event.setClosedLoopControlName("controlloop");
99         
100         TestControlLoopNotification notification2 = new TestControlLoopNotification(event);
101         assertEquals("controlloop", notification2.getClosedLoopControlName());
102         
103         notification2.setVersion("1");
104         assertEquals("1", notification2.getVersion());
105         
106         String json = Serialization.gsonPretty.toJson(notification);
107         
108         TestControlLoopNotification notification3 = Serialization.gson.fromJson(json, 
109                 TestControlLoopNotification.class);
110
111         //
112         // There is no equals for the class - chose not to create one
113         //
114         assertEquals(notification.getRequestId(), notification3.getRequestId());
115         
116     }
117 }