2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.validation.nodes;
23 import org.junit.Rule;
24 import org.junit.Test;
25 import org.junit.rules.ExpectedException;
26 import org.junit.runner.RunWith;
27 import org.onap.aai.config.NodesConfiguration;
28 import org.onap.aai.nodes.NodeIngestor;
30 import org.onap.aai.setup.SchemaVersion;
32 import org.onap.aai.testutils.SchemaIncompleteTranslator;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.boot.test.context.SpringBootTest;
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;
40 import java.io.ByteArrayOutputStream;
41 import java.io.IOException;
42 import java.io.OutputStream;
43 import java.io.OutputStreamWriter;
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;
52 @RunWith(SpringJUnit4ClassRunner.class)
53 @ContextConfiguration(classes = { SchemaIncompleteTranslator.class, NodesConfiguration.class})
55 @TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties" })
57 public class NodeValidatorSchemaIncompleteTest {
61 //set thrown.expect to whatever a specific test needs
62 //this establishes a default of expecting no exceptions to be thrown
64 public ExpectedException thrown = ExpectedException.none();
66 //Throws a NullPointerException because a JavaType is referenced, but not defined
68 public void testIncompleteCombinedSchema() throws TransformerException, IOException, IllegalStateException {
69 //thrown.expect(NullPointerException.class);
71 //TODO Change for Exception
72 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
73 printDocument(ni.getSchema(new SchemaVersion("v12")),buffer);
76 public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException {
77 TransformerFactory tf = TransformerFactory.newInstance();
78 Transformer transformer = tf.newTransformer();
79 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
80 transformer.setOutputProperty(OutputKeys.METHOD, "xml");
81 transformer.setOutputProperty(OutputKeys.INDENT, "yes");
82 transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
83 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
85 transformer.transform(new DOMSource(doc),
86 new StreamResult(new OutputStreamWriter(out, "UTF-8")));