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 java.util.Optional;
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;
27 import com.fasterxml.jackson.core.JsonProcessingException;
28 import com.fasterxml.jackson.databind.ObjectMapper;
30 public class TestMapping {
32 private final ObjectMapper mapper = new ObjectMapper();
35 private static Optional<SeverityType> getSeverity(String faultSeverity) {
36 return SeverityType.forName(faultSeverity); // <-- mapping provided by generated classes. Manual mapping beneficial.
39 private String updateFaultPayload(String faultNodeId, String faultCounter, String faultOccurrenceTime,
40 String faultObjectId, String faultReason, String faultSeverity) throws JsonProcessingException {
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());
52 // Do something to handle the problem
54 return mapper.writeValueAsString(faultNotificationBuilder);
59 public void test() throws JsonProcessingException {
60 DateAndTime dt = new DateAndTime("2017-03-01T09:15:00.0Z");
62 String result = updateFaultPayload("f1", "34", dt.getValue(), "fefef", "reason", "Critical");
64 System.out.println("Res: " + result);