2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.model.operations;
23 import com.fasterxml.jackson.core.JsonParseException;
24 import com.fasterxml.jackson.databind.JsonMappingException;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.openecomp.sdc.be.model.UploadResourceInfo;
29 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
30 import org.openecomp.sdc.common.api.UploadArtifactInfo;
32 import java.io.IOException;
33 import java.util.ArrayList;
35 import static org.junit.Assert.assertEquals;
37 public class JsonObjectTest {
39 private ObjectMapper mapper;
40 UploadResourceInfo inputObjectRef;
41 private final String INPUT_RESOURCE_STRING = "{ \"payloadData\" : \"My Test Object\", \"payloadName\" : \"TestName\", " + " \"description\":\"my_description\",\"tags\":[\"tag1\"], "
42 + "\"artifactList\" : [ { \"artifactName\" : \"myArtifact0\", \"artifactPath\" : \"scripts/\", \"artifactType\" : \"PUPPET\", " + " \"artifactDescription\" : \"This is Description\", \"artifactData\" : null }, "
43 + "{ \"artifactName\" : \"myArtifact1\", \"artifactPath\" : \"scripts/\", \"artifactType\" : \"PUPPET\", \"artifactDescription\" : \"This is Description\", "
44 + " \"artifactData\" : null } ], \"contactId\" : null, \"name\" : null, \"resourceIconPath\" : null, \"vendorName\" : null, \"vendorRelease\" : null , \"resourceType\" : \"VFC\" }";
48 mapper = new ObjectMapper();
49 ArrayList<UploadArtifactInfo> artifactList = new ArrayList<>();
50 for (int i = 0; i < 2; i++) {
51 UploadArtifactInfo artifactInfo = new UploadArtifactInfo("myArtifact" + i, "scripts/", ArtifactTypeEnum.PUPPET, "This is Description");
52 artifactList.add(artifactInfo);
54 ArrayList<String> tags = new ArrayList<>();
56 inputObjectRef = new UploadResourceInfo("My Test Object", "TestName", "my_description", null, tags, artifactList);
61 public void testStringToUploadResourceInfo() throws JsonParseException, JsonMappingException, IOException {
62 UploadResourceInfo resourceObjectTest = mapper.readValue(INPUT_RESOURCE_STRING, UploadResourceInfo.class);
63 assertEquals(inputObjectRef, resourceObjectTest);
68 public void testUploadResourceInfoToString() throws JsonParseException, JsonMappingException, IOException {
69 String refAsString = mapper.writeValueAsString(inputObjectRef);
70 String unFormattedString = refAsString.replace("\n", "").replace("\t", "").replace(" ", "");
72 assertEquals(unFormattedString, INPUT_RESOURCE_STRING.replace("\n", "").replace("\t", "").replace(" ", ""));