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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test;
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;
28 public class TestMapping {
30 private final ObjectMapper mapper = new ObjectMapper();
33 private static Optional<SeverityType> getSeverity(String faultSeverity) {
34 return SeverityType.forName(faultSeverity); // <-- mapping provided by generated classes. Manual mapping beneficial.
37 private String updateFaultPayload(String faultNodeId, String faultCounter, String faultOccurrenceTime,
38 String faultObjectId, String faultReason, String faultSeverity) throws JsonProcessingException {
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());
50 // Do something to handle the problem
52 return mapper.writeValueAsString(faultNotificationBuilder);
57 public void test() throws JsonProcessingException {
58 DateAndTime dt = new DateAndTime("2017-03-01T09:15:00.0Z");
60 String result = updateFaultPayload("f1", "34", dt.getValue(), "fefef", "reason", "Critical");
62 System.out.println("Res: " + result);