8c7b451fedccc910b69cad455eb983f5d9c4cbf1
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test;
23
24 import static org.junit.Assert.fail;
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import org.junit.Test;
27 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.ScopeRegistration;
28 import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper;
29
30 public class TestDeserialize {
31
32     private static final String SCOPE_REGISTRATION_JSON = "{\n" + "  \"data\":\"scopes\",\n" + "  \"scopes\":[\n"
33             + "    {\n" + "      \"node-id\":\"ROADM-A\",\n" + "      \"schema\":{\n"
34             + "          \"namespace\":\"onf:params:xml:ns:yang:microwave-model\",\n"
35             + "          \"revision\":\"2018-10-10\",\n" + "          \"notification\":[\"problem-notification\"]\n"
36             + "       }\n" + "    }\n" + "  ]\n" + "}";
37     private static final String SCOPE_REGISTRATION2_JSON = "{\n" + "  \"data\":\"scopes\",\n" + "  \"scopes\":[\n"
38             + "    {\n" + "      \"node-id\":\"ROADM-A\",\n" + "      \"schema\":{\n"
39             + "          \"namespace\":\"onf:params:xml:ns:yang:microwave-model\",\n"
40             + "          \"revision\":\"2018-10-10\",\n" + "          \"notification\":[\"problem-notification\"]\n"
41             + "       }\n" + "    }\n" + "  ],\n" + "  \"ratio\":\"120/min\"\n" + "}";
42     private static final String SCOPE_REGISTRATION3_INVALID_JSON = "{\n" + "  \"data\":\"scopes\",\n"
43             + "  \"scopes\":[\n" + "    {\n" + "      \"node-id\":\"ROADM-A\",\n" + "      \"schema\":{\n"
44             + "          \"namespace\":\"onf:params:xml:ns:yang:microwave-model\",\n"
45             + "          \"revision\":\"2018-10-10\",\n" + "          \"notification\":[\"problem-notification\"]\n"
46             + "       }\n" + "    }\n" + "  ],\n" + "  \"ratio\":\"120/sec\"\n" + "}";
47
48     @Test
49     public void testScopeRegistration() {
50         YangToolsMapper mapper = new YangToolsMapper();
51         ScopeRegistration obj = null;
52         try {
53             obj = mapper.readValue(SCOPE_REGISTRATION_JSON, ScopeRegistration.class);
54         } catch (JsonProcessingException e) {
55             e.printStackTrace();
56             fail(e.getMessage());
57         }
58         System.out.println(obj);
59     }
60
61     @Test
62     public void testScopeRegistration2() {
63         YangToolsMapper mapper = new YangToolsMapper();
64         ScopeRegistration obj = null;
65         try {
66             obj = mapper.readValue(SCOPE_REGISTRATION2_JSON, ScopeRegistration.class);
67         } catch (JsonProcessingException e) {
68             e.printStackTrace();
69             fail(e.getMessage());
70         }
71         System.out.println(obj);
72     }
73
74     @Test
75     public void testScopeRegistration3() {
76         YangToolsMapper mapper = new YangToolsMapper();
77         try {
78             mapper.readValue(SCOPE_REGISTRATION3_INVALID_JSON, ScopeRegistration.class);
79         } catch (JsonProcessingException | IllegalArgumentException e) {
80             // e.printStackTrace();
81             return;
82         }
83         fail("json should not contain a valid ratio");
84     }
85 }