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.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;
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 = {SchemaLocationsBean.class, SchemaVersions.class, SchemaIncompleteTranslator.class, NodeIngestor.class})
54 @TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" })
56 public class NodeValidatorSchemaIncompleteTest {
60 //set thrown.expect to whatever a specific test needs
61 //this establishes a default of expecting no exceptions to be thrown
63 public ExpectedException thrown = ExpectedException.none();
65 //Throws a NullPointerException because a JavaType is referenced, but not defined
67 public void testIncompleteCombinedSchema() throws TransformerException, IOException, IllegalStateException {
68 thrown.expect(NullPointerException.class);
71 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
72 printDocument(ni.getSchema(new SchemaVersion("v12")),buffer);
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");
84 transformer.transform(new DOMSource(doc),
85 new StreamResult(new OutputStreamWriter(out, "UTF-8")));