Add .tox/ to .gitignore
[odlparent.git] / karaf / karaf-maven-plugin / src / test / java / org / apache / karaf / tooling / features / GenerateDescriptorMojoTest.java
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
20 package org.apache.karaf.tooling.features;
21
22 import static org.junit.Assert.*;
23
24 import java.io.ByteArrayOutputStream;
25 import java.io.InputStream;
26 import java.net.URL;
27 import java.util.List;
28
29 import javax.xml.bind.JAXBException;
30 import javax.xml.parsers.ParserConfigurationException;
31 import javax.xml.stream.XMLStreamException;
32
33 import org.apache.karaf.features.FeaturesNamespaces;
34 import org.apache.karaf.features.internal.model.Features;
35 import org.apache.karaf.features.internal.model.Feature;
36 import org.apache.karaf.features.internal.model.JaxbUtil;
37 import org.junit.Test;
38 import org.xml.sax.SAXException;
39
40 public class GenerateDescriptorMojoTest {
41
42     @Test
43     public void testReadXml100() throws JAXBException, SAXException, ParserConfigurationException, XMLStreamException {
44
45         URL url = getClass().getClassLoader().getResource("input-features-1.0.0.xml");
46
47         Features featuresRoot = JaxbUtil.unmarshal(url.toExternalForm(), false);
48
49         assertEquals(featuresRoot.getRepository().size(), 1);
50
51         ByteArrayOutputStream baos = new ByteArrayOutputStream();
52
53         JaxbUtil.marshal(featuresRoot, baos);
54
55         String text = new String(baos.toByteArray());
56
57         assertTrue(text.contains("repository"));
58
59         assertTrue(text.contains(FeaturesNamespaces.URI_CURRENT));
60     }
61
62     @Test
63     public void testReadXml1() throws Exception {
64
65         URL url = getClass().getClassLoader().getResource("input-features-1.1.0.xml");
66
67         Features featuresRoot = JaxbUtil.unmarshal(url.toExternalForm(), false);
68
69         List<Feature> featuresList = featuresRoot.getFeature();
70
71         assertEquals(featuresList.size(), 1);
72
73         Feature feature = featuresList.get(0);
74
75         assertEquals(feature.getInstall(), "auto");
76     }
77
78 }