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