aa8aabc3610c9afe7c0afe39246c1f6995f7eef3
[aai/aai-common.git] /
1 /** 
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-18 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.onap.aai.validation.nodes;
22
23 import static org.junit.jupiter.api.Assertions.assertThrows;
24
25 import java.io.ByteArrayOutputStream;
26 import java.io.IOException;
27 import java.io.OutputStream;
28 import java.io.OutputStreamWriter;
29
30 import javax.xml.transform.OutputKeys;
31 import javax.xml.transform.Transformer;
32 import javax.xml.transform.TransformerException;
33 import javax.xml.transform.TransformerFactory;
34 import javax.xml.transform.dom.DOMSource;
35 import javax.xml.transform.stream.StreamResult;
36
37 import org.junit.jupiter.api.Disabled;
38 import org.junit.jupiter.api.Test;
39 import org.onap.aai.config.NodesConfiguration;
40 import org.onap.aai.nodes.NodeIngestor;
41 import org.onap.aai.setup.SchemaVersion;
42 import org.onap.aai.testutils.SchemaIncompleteTranslator;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.boot.test.context.SpringBootTest;
45 import org.springframework.test.context.ContextConfiguration;
46 import org.springframework.test.context.TestPropertySource;
47 import org.w3c.dom.Document;
48
49 @ContextConfiguration(classes = {SchemaIncompleteTranslator.class, NodesConfiguration.class})
50
51 @TestPropertySource(
52         properties = {
53                 "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties"})
54 @SpringBootTest
55 @Disabled
56 public class NodeValidatorSchemaIncompleteTest {
57     @Autowired
58     NodeIngestor ni;
59
60     // Throws a NullPointerException because a JavaType is referenced, but not defined
61     @Test
62     public void testIncompleteCombinedSchema() {
63         assertThrows(NullPointerException.class, () -> {
64
65             // TODO Change for Exception
66             ByteArrayOutputStream buffer = new ByteArrayOutputStream();
67             printDocument(ni.getSchema(new SchemaVersion("v12")), buffer);
68         });
69     }
70
71     public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException {
72         TransformerFactory tf = TransformerFactory.newInstance();
73         Transformer transformer = tf.newTransformer();
74         transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
75         transformer.setOutputProperty(OutputKeys.METHOD, "xml");
76         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
77         transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
78         transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
79
80         transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, "UTF-8")));
81     }
82 }