3259f2e4c3147e780900d7d6f11421fb316c4049
[ccsdk/features.git] /
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 java.util.Optional;
21
22 import org.junit.Test;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushFaultNotificationInputBuilder;
26
27 import com.fasterxml.jackson.core.JsonProcessingException;
28 import com.fasterxml.jackson.databind.ObjectMapper;
29
30 public class TestMapping {
31
32     private final ObjectMapper mapper = new ObjectMapper();
33
34
35     private static Optional<SeverityType> getSeverity(String faultSeverity) {
36         return SeverityType.forName(faultSeverity); // <-- mapping provided by generated classes. Manual mapping beneficial.
37     }
38
39     private String updateFaultPayload(String faultNodeId, String faultCounter, String faultOccurrenceTime, String faultObjectId,
40             String faultReason, String faultSeverity) throws JsonProcessingException {
41
42         PushFaultNotificationInputBuilder faultNotificationBuilder = new PushFaultNotificationInputBuilder();
43         faultNotificationBuilder.setNodeId(faultNodeId);
44         faultNotificationBuilder.setCounter(Integer.valueOf(faultCounter));
45         faultNotificationBuilder.setTimestamp(new DateAndTime(faultOccurrenceTime));
46         faultNotificationBuilder.setObjectId(faultObjectId);
47         faultNotificationBuilder.setProblem(faultReason);
48         Optional<SeverityType> oSeverity = getSeverity(faultSeverity); //TODO getSeverity
49         if (oSeverity.isPresent()) {
50             faultNotificationBuilder.setSeverity(oSeverity.get());
51         } else {
52             // Do something to handle the problem
53         }
54         return mapper.writeValueAsString(faultNotificationBuilder);
55     }
56
57
58     @Test
59     public void test() throws JsonProcessingException {
60         DateAndTime dt = new DateAndTime("2017-03-01T09:15:00.0Z");
61
62         String result = updateFaultPayload("f1","34",dt.getValue(),"fefef","reason","Critical");
63
64         System.out.println("Res: "+result);
65    }
66
67 }