2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.openstack.mappers;
25 import static org.junit.Assert.assertEquals;
26 import java.io.IOException;
27 import java.nio.file.Files;
28 import java.nio.file.Paths;
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.Collections;
32 import javax.xml.bind.JAXBContext;
33 import javax.xml.bind.JAXBException;
34 import org.junit.Test;
35 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
38 public class JAXBMarshallingTest {
42 public void xmlUnMarshalTest() throws IOException, JAXBException {
43 JAXBContext context = JAXBContext.newInstance(CreateVfModuleRequest.class);
45 CreateVfModuleRequest request = (CreateVfModuleRequest) context.createUnmarshaller().unmarshal(
46 Files.newBufferedReader(Paths.get("src/test/resources/createVfModuleRequest-with-params.xml")));
48 assertEquals("ubuntu-16-04-cloud-amd64", request.getVfModuleParams().get("vcpe_image_name"));
49 assertEquals("10.2.0.0/24", request.getVfModuleParams().get("cpe_public_net_cidr"));
50 assertEquals("", request.getVfModuleParams().get("workload_context"));
51 assertEquals("[\"a\",\"b\",\"c\"]", request.getVfModuleParams().get("raw-json-param"));
55 public void xmlMarshalTest() throws IOException, JAXBException {
57 CreateVfModuleRequest request = new CreateVfModuleRequest();
58 request.getVfModuleParams().put("test-null", null);
59 request.getVfModuleParams().put("vcpe_image_name", "ubuntu-16-04-cloud-amd64");
60 request.getVfModuleParams().put("test-empty", "");
61 request.getVfModuleParams().put("test array", Arrays.asList("a", "b", "c"));
62 request.getVfModuleParams().put("test map", Collections.singletonMap("d", "e"));
63 request.getVfModuleParams().put("marshalling error", new ArrayList());
65 assertEquals("documents should be equal",
67 .readAllBytes(Paths.get("src/test/resources/VfRequest-marshalled-with-complex-object.xml")))
68 .replaceAll("\\R", "\n"),
69 request.toXmlString());