re base code
[sdc.git] / catalog-model / src / test / java / org / openecomp / sdc / be / model / operations / JsonObjectTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.model.operations;
22
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;
31
32 import java.io.IOException;
33 import java.util.ArrayList;
34
35 import static org.junit.Assert.assertEquals;
36
37 public class JsonObjectTest {
38
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\" }";
45
46     @Before
47     public void setup() {
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);
53         }
54         ArrayList<String> tags = new ArrayList<>();
55         tags.add("tag1");
56         inputObjectRef = new UploadResourceInfo("My Test Object", "TestName", "my_description", null, tags, artifactList);
57
58     }
59
60     @Test
61     public void testStringToUploadResourceInfo() throws JsonParseException, JsonMappingException, IOException {
62         UploadResourceInfo resourceObjectTest = mapper.readValue(INPUT_RESOURCE_STRING, UploadResourceInfo.class);
63         assertEquals(inputObjectRef, resourceObjectTest);
64
65     }
66
67     // @Test
68     public void testUploadResourceInfoToString() throws JsonParseException, JsonMappingException, IOException {
69         String refAsString = mapper.writeValueAsString(inputObjectRef);
70         String unFormattedString = refAsString.replace("\n", "").replace("\t", "").replace(" ", "");
71
72         assertEquals(unFormattedString, INPUT_RESOURCE_STRING.replace("\n", "").replace("\t", "").replace(" ", ""));
73
74     }
75 }