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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 package org.apache.karaf.tooling.features;
22 import static org.junit.Assert.*;
24 import java.io.ByteArrayOutputStream;
25 import java.io.InputStream;
27 import java.util.List;
29 import javax.xml.bind.JAXBException;
30 import javax.xml.parsers.ParserConfigurationException;
31 import javax.xml.stream.XMLStreamException;
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;
40 public class GenerateDescriptorMojoTest {
43 public void testReadXml100() throws JAXBException, SAXException, ParserConfigurationException, XMLStreamException {
45 URL url = getClass().getClassLoader().getResource("input-features-1.0.0.xml");
47 Features featuresRoot = JaxbUtil.unmarshal(url.toExternalForm(), false);
49 assertEquals(featuresRoot.getRepository().size(), 1);
51 ByteArrayOutputStream baos = new ByteArrayOutputStream();
53 JaxbUtil.marshal(featuresRoot, baos);
55 String text = new String(baos.toByteArray());
57 assertTrue(text.contains("repository"));
59 assertTrue(text.contains(FeaturesNamespaces.URI_CURRENT));
63 public void testReadXml1() throws Exception {
65 URL url = getClass().getClassLoader().getResource("input-features-1.1.0.xml");
67 Features featuresRoot = JaxbUtil.unmarshal(url.toExternalForm(), false);
69 List<Feature> featuresList = featuresRoot.getFeature();
71 assertEquals(featuresList.size(), 1);
73 Feature feature = featuresList.get(0);
75 assertEquals(feature.getInstall(), "auto");