2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.controlloop;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
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;
34 public class ControlLoopNotificationTest {
36 private class TestControlLoopNotification extends ControlLoopNotification {
37 private static final long serialVersionUID = 1L;
39 public TestControlLoopNotification() {
43 public TestControlLoopNotification(ControlLoopEvent event) {
50 ControlLoopNotification notification = new TestControlLoopNotification();
52 assertEquals("1.0.2", notification.getVersion());
54 notification.setClosedLoopControlName("name");
55 assertEquals("name", notification.getClosedLoopControlName());
57 notification.setClosedLoopEventClient("client");
58 assertEquals("client", notification.getClosedLoopEventClient());
60 notification.setFrom("from");
61 assertEquals("from", notification.getFrom());
63 notification.setHistory(Collections.emptyList());
64 assertTrue(notification.getHistory().size() == 0);
66 notification.setMessage("message");
67 assertEquals("message", notification.getMessage());
69 notification.setNotification(ControlLoopNotificationType.ACTIVE);
70 assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
72 ZonedDateTime time = ZonedDateTime.now(ZoneOffset.UTC);
73 notification.setNotificationTime(time);
74 assertEquals(time, notification.getNotificationTime());
76 notification.setOpsClTimer(Integer.valueOf(1000));
77 assertEquals(Integer.valueOf(1000), notification.getOpsClTimer());
79 notification.setPolicyName("name");
80 assertEquals("name", notification.getPolicyName());
82 notification.setPolicyScope("scope");
83 assertEquals("scope", notification.getPolicyScope());
85 notification.setPolicyVersion("1");
86 assertEquals("1", notification.getPolicyVersion());
88 UUID id = UUID.randomUUID();
89 notification.setRequestId(id);
90 assertEquals(id, notification.getRequestId());
92 notification.setTarget("target");
93 assertEquals("target", notification.getTarget());
95 notification.setTargetType(ControlLoopTargetType.VFC);
96 assertEquals(ControlLoopTargetType.VFC, notification.getTargetType());
98 VirtualControlLoopEvent event = new VirtualControlLoopEvent();
99 event.setClosedLoopControlName("controlloop");
101 TestControlLoopNotification notification2 = new TestControlLoopNotification(event);
102 assertEquals("controlloop", notification2.getClosedLoopControlName());
104 notification2.setVersion("1");
105 assertEquals("1", notification2.getVersion());
107 String json = Serialization.gsonPretty.toJson(notification);
109 TestControlLoopNotification notification3 = Serialization.gson.fromJson(json,
110 TestControlLoopNotification.class);
113 // There is no equals for the class - chose not to create one
115 assertEquals(notification.getRequestId(), notification3.getRequestId());