Add missing distributionManagement section to poms
[aai/search-data-service.git] / search-data-service-app / src / test / java / org / onap / aai / sa / rest / DocumentSchemaTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
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 package org.onap.aai.sa.rest;
22
23 import static org.junit.Assert.assertTrue;
24
25 import com.fasterxml.jackson.core.JsonParseException;
26 import com.fasterxml.jackson.databind.JsonMappingException;
27 import com.fasterxml.jackson.databind.ObjectMapper;
28 import java.io.File;
29 import java.io.IOException;
30 import org.junit.Test;
31
32 public class DocumentSchemaTest {
33
34     private final String SIMPLE_DOC_SCHEMA_JSON = "src/test/resources/json/simpleDocument.json";
35     private final String NESTED_DOC_SCHEMA_JSON = "src/test/resources/json/nested-document.json";
36
37
38     /**
39      * This test validates that we convert document definitions back and forth between json strings and POJOs without
40      * any loss of data.
41      *
42      * @throws com.fasterxml.jackson.core.JsonParseException
43      * @throws com.fasterxml.jackson.databind.JsonMappingException
44      * @throws IOException
45      */
46     @Test
47     public void simpleDocSchemaFromJsonFileTest() throws com.fasterxml.jackson.core.JsonParseException,
48             com.fasterxml.jackson.databind.JsonMappingException, IOException {
49
50         // Import our json format document schema from a file.
51         File schemaFile = new File(SIMPLE_DOC_SCHEMA_JSON);
52         String fileString = TestUtils.readFileToString(schemaFile);
53
54         // Unmarshall that to a Java POJO
55         ObjectMapper mapper = new ObjectMapper();
56         DocumentSchema docSchema = mapper.readValue(schemaFile, DocumentSchema.class);
57
58         // Now, for the purposes of comparison, produce a JSON string from
59         // our Java object.
60         String jsonString = mapper.writeValueAsString(docSchema);
61
62         // Assert that the raw JSON that we read from the file matches the marshalled
63         // JSON we generated from our Java object (ie: validate that we didn't lose
64         // anything going in either direction).
65         assertTrue("Marshalled object does not match the original json source that produced it",
66                 fileString.equals(jsonString));
67     }
68
69     //
70     // /**
71     // * This test validates that we convert document definitions back and
72     // * forth between json strings and POJOs without any loss of data in
73     // * the case of document schemas which contain nested fields.
74     // *
75     // * @throws com.fasterxml.jackson.core.JsonParseException
76     // * @throws com.fasterxml.jackson.databind.JsonMappingException
77     // * @throws IOException
78     // */
79
80     @Test
81     public void nestedDocSchemaFromJsonFileTest() throws JsonParseException, JsonMappingException, IOException {
82
83         // Import our json format document schema from a file.
84         File schemaFile = new File(NESTED_DOC_SCHEMA_JSON);
85         String fileString = TestUtils.readFileToString(schemaFile);
86
87         // Unmarshall that to a Java POJO
88         ObjectMapper mapper = new ObjectMapper();
89         DocumentSchema docSchema = mapper.readValue(schemaFile, DocumentSchema.class);
90
91         String jsonString = mapper.writeValueAsString(docSchema);
92
93         // Assert that the raw JSON that we read from the file matches the marshalled
94         // JSON we generated from our Java object (ie: validate that we didn't lose
95         // anything going in either direction).
96         assertTrue("Marshalled object does not match the original json source that produced it",
97                 fileString.equals(jsonString));
98     }
99 }