83bf3748f168b3c19b2816c6ac6a87966cd79aba
[aai/aai-common.git] / aai-schema-ingest / src / test / java / org / onap / aai / validation / nodes / NodeValidatorSchemaIncompleteTest.java
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 org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
24 import org.junit.Ignore;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.rules.ExpectedException;
28 import org.junit.runner.RunWith;
29 import org.onap.aai.nodes.NodeIngestor;
30 import org.onap.aai.setup.SchemaLocationsBean;
31 import org.onap.aai.setup.SchemaVersion;
32 import org.onap.aai.setup.SchemaVersions;
33 import org.onap.aai.testutils.SchemaIncompleteTranslator;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.test.context.ContextConfiguration;
36 import org.springframework.test.context.TestPropertySource;
37 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
38 import org.w3c.dom.Document;
39
40 import java.io.ByteArrayOutputStream;
41 import java.io.IOException;
42 import java.io.OutputStream;
43 import java.io.OutputStreamWriter;
44
45 import javax.xml.transform.OutputKeys;
46 import javax.xml.transform.Transformer;
47 import javax.xml.transform.TransformerException;
48 import javax.xml.transform.TransformerFactory;
49 import javax.xml.transform.dom.DOMSource;
50 import javax.xml.transform.stream.StreamResult;
51 @Ignore
52 @RunWith(SpringJUnit4ClassRunner.class)
53 @ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, SchemaIncompleteTranslator.class, NodeIngestor.class})
54 @TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" })
55 //@SpringBootTest
56 public class NodeValidatorSchemaIncompleteTest {
57         @Autowired
58         NodeIngestor ni;
59         
60         //set thrown.expect to whatever a specific test needs
61         //this establishes a default of expecting no exceptions to be thrown
62         @Rule
63         public ExpectedException thrown = ExpectedException.none();
64
65         //Throws a NullPointerException because a JavaType is referenced, but not defined
66         @Test
67         public void testIncompleteCombinedSchema() throws TransformerException, IOException, IllegalStateException {
68                 thrown.expect(NullPointerException.class);
69
70                 
71                 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
72                 printDocument(ni.getSchema(new SchemaVersion("v12")),buffer);
73         }
74         
75         public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException {
76             TransformerFactory tf = TransformerFactory.newInstance();
77             Transformer transformer = tf.newTransformer();
78             transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
79             transformer.setOutputProperty(OutputKeys.METHOD, "xml");
80             transformer.setOutputProperty(OutputKeys.INDENT, "yes");
81             transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
82             transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
83
84             transformer.transform(new DOMSource(doc), 
85                  new StreamResult(new OutputStreamWriter(out, "UTF-8")));
86         }
87
88 }