2 * ============LICENSE_START===================================================
\r
3 * Copyright (c) 2018 Amdocs
\r
4 * ============================================================================
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
16 * ============LICENSE_END=====================================================
\r
19 package org.onap.sdnc.apps.pomba.networkdiscovery.unittest.service.util;
\r
21 import com.bazaarvoice.jolt.JsonUtils;
\r
22 import com.bazaarvoice.jolt.exception.JsonUnmarshalException;
\r
23 import com.google.gson.Gson;
\r
25 import org.junit.Assert;
\r
26 import org.junit.Rule;
\r
27 import org.junit.Test;
\r
28 import org.junit.rules.ExpectedException;
\r
29 import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Resource;
\r
30 import org.onap.sdnc.apps.pomba.networkdiscovery.service.util.TransformationUtil;
\r
32 public class TransformationUtilTest {
\r
34 private static final String TEST_RESOURCES = "src/test/resources/jolt/";
\r
37 public ExpectedException expectedEx = ExpectedException.none();
\r
40 public void testTransformVServer() {
\r
42 Object sourceObject = JsonUtils.filepathToObject(TEST_RESOURCES + "vserver-input.json");
\r
44 String resultJson = TransformationUtil.transform(JsonUtils.toJsonString(sourceObject), "vserver");
\r
46 Gson gson = new Gson();
\r
47 Resource resourceInst = gson.fromJson(resultJson, Resource.class);
\r
48 String resourceInstJson = gson.toJson(resourceInst);
\r
50 Object expectedObject = JsonUtils.filepathToObject(TEST_RESOURCES + "vserver-expected.json");
\r
52 Assert.assertEquals("Json transformation result does not match expected content",
\r
53 JsonUtils.toPrettyJsonString(expectedObject),
\r
54 JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(resourceInstJson)));
\r
59 public void testTransformL3Network() {
\r
61 Object sourceObject = JsonUtils.filepathToObject(TEST_RESOURCES + "l3network-input.json");
\r
62 String resultJson = TransformationUtil.transform(JsonUtils.toJsonString(sourceObject), "l3-network");
\r
64 Gson gson = new Gson();
\r
65 Resource resourceInst = gson.fromJson(resultJson, Resource.class);
\r
66 String resourceInstJson = gson.toJson(resourceInst);
\r
68 Object expectedObject = JsonUtils.filepathToObject(TEST_RESOURCES + "l3network-expected.json");
\r
70 Assert.assertEquals("Json transformation result does not match expected content",
\r
71 JsonUtils.toPrettyJsonString(expectedObject),
\r
72 JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(resourceInstJson)));
\r
77 public void testTransformFailureFileNotFound() {
\r
79 expectedEx.expect(RuntimeException.class);
\r
80 expectedEx.expectMessage("Unable to load JSON file");
\r
82 TransformationUtil.transform("{}", "foobar");
\r
86 public void testTransformFailureInvalidInputJson() {
\r
88 expectedEx.expect(JsonUnmarshalException.class);
\r
89 expectedEx.expectMessage("Unable to unmarshal JSON");
\r
91 TransformationUtil.transform("xxx", "foobar");
\r