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