2 * ============LICENSE_START=======================================================
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
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.controlloop;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
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;
33 public class ControlLoopNotificationTest {
35 private class TestControlLoopNotification extends ControlLoopNotification {
36 private static final long serialVersionUID = 1L;
38 public TestControlLoopNotification() {
42 public TestControlLoopNotification(ControlLoopEvent event) {
49 ControlLoopNotification notification = new TestControlLoopNotification();
51 assertEquals("1.0.2", notification.getVersion());
53 notification.setClosedLoopControlName("name");
54 assertEquals("name", notification.getClosedLoopControlName());
56 notification.setClosedLoopEventClient("client");
57 assertEquals("client", notification.getClosedLoopEventClient());
59 notification.setFrom("from");
60 assertEquals("from", notification.getFrom());
62 notification.setHistory(Collections.emptyList());
63 assertTrue(notification.getHistory().size() == 0);
65 notification.setMessage("message");
66 assertEquals("message", notification.getMessage());
68 notification.setNotification(ControlLoopNotificationType.ACTIVE);
69 assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
71 ZonedDateTime time = ZonedDateTime.now(ZoneOffset.UTC);
72 notification.setNotificationTime(time);
73 assertEquals(time, notification.getNotificationTime());
75 notification.setOpsClTimer(Integer.valueOf(1000));
76 assertEquals(Integer.valueOf(1000), notification.getOpsClTimer());
78 notification.setPolicyName("name");
79 assertEquals("name", notification.getPolicyName());
81 notification.setPolicyScope("scope");
82 assertEquals("scope", notification.getPolicyScope());
84 notification.setPolicyVersion("1");
85 assertEquals("1", notification.getPolicyVersion());
87 UUID id = UUID.randomUUID();
88 notification.setRequestId(id);
89 assertEquals(id, notification.getRequestId());
91 notification.setTarget("target");
92 assertEquals("target", notification.getTarget());
94 notification.setTargetType(ControlLoopTargetType.VFC);
95 assertEquals(ControlLoopTargetType.VFC, notification.getTargetType());
97 VirtualControlLoopEvent event = new VirtualControlLoopEvent();
98 event.setClosedLoopControlName("controlloop");
100 TestControlLoopNotification notification2 = new TestControlLoopNotification(event);
101 assertEquals("controlloop", notification2.getClosedLoopControlName());
103 notification2.setVersion("1");
104 assertEquals("1", notification2.getVersion());
106 String json = Serialization.gsonPretty.toJson(notification);
108 TestControlLoopNotification notification3 = Serialization.gson.fromJson(json,
109 TestControlLoopNotification.class);
112 // There is no equals for the class - chose not to create one
114 assertEquals(notification.getRequestId(), notification3.getRequestId());