Merge "SDN-R Sodium compliant mountpoint-registrar"
[ccsdk/features.git] / sdnr / wt / mountpoint-registrar / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / mountpointregistrar / test / TestMapping.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test;
19
20 import com.fasterxml.jackson.core.JsonProcessingException;
21 import com.fasterxml.jackson.databind.ObjectMapper;
22 import java.util.Optional;
23 import org.junit.Test;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushFaultNotificationInputBuilder;
27
28 public class TestMapping {
29
30     private final ObjectMapper mapper = new ObjectMapper();
31
32
33     private static Optional<SeverityType> getSeverity(String faultSeverity) {
34         return SeverityType.forName(faultSeverity); // <-- mapping provided by generated classes. Manual mapping beneficial.
35     }
36
37     private String updateFaultPayload(String faultNodeId, String faultCounter, String faultOccurrenceTime,
38             String faultObjectId, String faultReason, String faultSeverity) throws JsonProcessingException {
39
40         PushFaultNotificationInputBuilder faultNotificationBuilder = new PushFaultNotificationInputBuilder();
41         faultNotificationBuilder.setNodeId(faultNodeId);
42         faultNotificationBuilder.setCounter(Integer.valueOf(faultCounter));
43         faultNotificationBuilder.setTimestamp(new DateAndTime(faultOccurrenceTime));
44         faultNotificationBuilder.setObjectId(faultObjectId);
45         faultNotificationBuilder.setProblem(faultReason);
46         Optional<SeverityType> oSeverity = getSeverity(faultSeverity);
47         if (oSeverity.isPresent()) {
48             faultNotificationBuilder.setSeverity(oSeverity.get());
49         } else {
50             // Do something to handle the problem
51         }
52         return mapper.writeValueAsString(faultNotificationBuilder);
53     }
54
55
56     @Test
57     public void test() throws JsonProcessingException {
58         DateAndTime dt = new DateAndTime("2017-03-01T09:15:00.0Z");
59
60         String result = updateFaultPayload("f1", "34", dt.getValue(), "fefef", "reason", "Critical");
61
62         System.out.println("Res: " + result);
63     }
64
65 }