View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.buildcache.xml;
20  
21  import javax.xml.XMLConstants;
22  import javax.xml.parsers.DocumentBuilder;
23  import javax.xml.parsers.DocumentBuilderFactory;
24  import javax.xml.validation.Schema;
25  import javax.xml.validation.SchemaFactory;
26  
27  import java.io.InputStream;
28  
29  import org.apache.maven.buildcache.xml.build.Build;
30  import org.apache.maven.buildcache.xml.config.CacheConfig;
31  import org.apache.maven.buildcache.xml.diff.Diff;
32  import org.apache.maven.buildcache.xml.report.CacheReport;
33  import org.junit.jupiter.api.Disabled;
34  import org.junit.jupiter.api.Test;
35  import org.w3c.dom.Document;
36  
37  public class XmlServiceTest {
38  
39      @Test
40      @Disabled("cache-build-1.0.0.xsd not found")
41      public void testConfig() throws Exception {
42          SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
43          Schema schema = sf.newSchema(getClass().getResource("/build-cache-config-1.0.0.xsd"));
44          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
45          dbf.setNamespaceAware(true);
46          dbf.setSchema(schema);
47          DocumentBuilder db = dbf.newDocumentBuilder();
48          Document doc = db.parse(
49                  getClass().getResource("build-cache-config-instance.xml").toString());
50  
51          InputStream is = getClass().getResourceAsStream("build-cache-config-instance.xml");
52          final CacheConfig cache = new XmlService().loadCacheConfig(is);
53      }
54  
55      @Test
56      @Disabled("cache-build-1.0.0.xsd not found")
57      public void testReport() throws Exception {
58          SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
59          Schema schema = sf.newSchema(getClass().getResource("/build-cache-report-1.0.0.xsd"));
60          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
61          dbf.setNamespaceAware(true);
62          dbf.setSchema(schema);
63          DocumentBuilder db = dbf.newDocumentBuilder();
64          Document doc = db.parse(
65                  getClass().getResource("build-cache-report-instance.xml").toString());
66  
67          InputStream is = getClass().getResourceAsStream("build-cache-report-instance.xml");
68          final CacheReport cacheReport = new XmlService().loadCacheReport(is);
69      }
70  
71      @Test
72      @Disabled("cache-build-1.0.0.xsd not found")
73      public void testBuild() throws Exception {
74          SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
75          Schema schema = sf.newSchema(getClass().getResource("/build-cache-build-1.0.0.xsd"));
76          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
77          dbf.setNamespaceAware(true);
78          dbf.setSchema(schema);
79          DocumentBuilder db = dbf.newDocumentBuilder();
80          Document doc = db.parse(
81                  getClass().getResource("build-cache-build-instance.xml").toString());
82  
83          InputStream is = getClass().getResourceAsStream("build-cache-build-instance.xml");
84          final Build build = new XmlService().loadBuild(is);
85      }
86  
87      @Test
88      @Disabled("cache-build-1.0.0.xsd not found")
89      public void testDiff() throws Exception {
90          SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
91          Schema schema = sf.newSchema(getClass().getResource("/build-cache-diff-1.0.0.xsd"));
92          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
93          dbf.setNamespaceAware(true);
94          dbf.setSchema(schema);
95          DocumentBuilder db = dbf.newDocumentBuilder();
96          Document doc =
97                  db.parse(getClass().getResource("build-cache-diff-instance.xml").toString());
98  
99          InputStream is = getClass().getResourceAsStream("build-cache-diff-instance.xml");
100         final Diff buildDiff = new XmlService().loadDiff(is);
101     }
102 }