Author: ggrzybek Date: Tue Feb 28 08:49:05 2017 New Revision: 1784703 URL: http://svn.apache.org/viewvc?rev=1784703&view=rev Log: [ARIES-1682] Provide integration test for relatively <xsd:include>d XSDs
Added: aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/ParserServiceImportAndIncludeXSDsTest.java aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/handler/Aries1682NamespaceHandler.java aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/ImportNamespacesWithXSDIncludeTest.xml aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682-common.xsd aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682.xml aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682.xsd Added: aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/ParserServiceImportAndIncludeXSDsTest.java URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/ParserServiceImportAndIncludeXSDsTest.java?rev=1784703&view=auto ============================================================================== --- aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/ParserServiceImportAndIncludeXSDsTest.java (added) +++ aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/ParserServiceImportAndIncludeXSDsTest.java Tue Feb 28 08:49:05 2017 @@ -0,0 +1,124 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.aries.blueprint.itests; + +import java.io.InputStream; +import java.net.URL; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.apache.aries.blueprint.ComponentDefinitionRegistry; +import org.apache.aries.blueprint.itests.cm.handler.Aries1682NamespaceHandler; +import org.apache.aries.blueprint.services.ParserService; +import org.junit.Test; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.osgi.framework.Constants; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.blueprint.container.BlueprintEvent; +import org.osgi.service.blueprint.container.BlueprintListener; + +import static org.apache.aries.blueprint.itests.Helper.blueprintBundles; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.ops4j.pax.exam.CoreOptions.*; + +public class ParserServiceImportAndIncludeXSDsTest extends AbstractBlueprintIntegrationTest { + + private static final String NS_HANDLER_BUNDLE = "org.apache.aries.blueprint.aries1682"; + private static final String TEST_BUNDLE = "org.apache.aries.blueprint.aries1682.test"; + + @org.ops4j.pax.exam.Configuration + public Option[] config() { + return new Option[] { + baseOptions(), + systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"), + blueprintBundles(), + keepCaches(), + streamBundle(createAries1682NamespaceHandlerBundle()), + streamBundle(createTestBundle()) + }; + } + + private InputStream createAries1682NamespaceHandlerBundle() { + return TinyBundles.bundle() + .add(Aries1682NamespaceHandler.class) + .add("OSGI-INF/blueprint/blueprint-aries-1682.xml", getResource("blueprint-aries-1682.xml")) + .add("blueprint-aries-1682.xsd", getResource("blueprint-aries-1682.xsd")) + .add("blueprint-aries-1682-common.xsd", getResource("blueprint-aries-1682-common.xsd")) + .set(Constants.BUNDLE_SYMBOLICNAME, NS_HANDLER_BUNDLE) + .set(Constants.EXPORT_PACKAGE, Aries1682NamespaceHandler.class.getPackage().getName()) + .set(Constants.IMPORT_PACKAGE, "org.apache.aries.blueprint," + + "org.apache.aries.blueprint.ext," + + "org.apache.aries.blueprint.mutable," + + FrameworkUtil.class.getPackage().getName() + "," + + "org.osgi.service.blueprint.reflect," + + "org.w3c.dom") + .build(TinyBundles.withClassicBuilder()); + } + + private InputStream createTestBundle() { + return TinyBundles.bundle() + .add("OSGI-INF/blueprint/ImportNamespacesWithXSDIncludeTest.xml", getResource("ImportNamespacesWithXSDIncludeTest.xml")) + .set(Constants.BUNDLE_SYMBOLICNAME, TEST_BUNDLE) + .set(Constants.IMPORT_PACKAGE, Aries1682NamespaceHandler.class.getPackage().getName() + + ",org.apache.aries.blueprint,org.apache.aries.blueprint.ext") + .build(TinyBundles.withBnd()); + } + + @Test + public void testXSDImports() throws Exception { + assertTrue(TEST_BUNDLE + " should correctly register blueprint container", waitForConfig()); + ParserService parserService = context().getService(ParserService.class); + URL blueprintXML = context().getBundleByName(TEST_BUNDLE).getEntry("OSGI-INF/blueprint/ImportNamespacesWithXSDIncludeTest.xml"); + ComponentDefinitionRegistry cdr = parserService.parse(blueprintXML, context().getBundleByName(TEST_BUNDLE)); + assertNotNull(cdr.getComponentDefinition("aries-1682")); + } + + private boolean waitForConfig() throws InterruptedException { + final AtomicBoolean ready = new AtomicBoolean(); + @SuppressWarnings("rawtypes") + ServiceRegistration reg = context().registerService( + BlueprintListener.class, + new BlueprintListener() { + @Override + public void blueprintEvent(BlueprintEvent event) { + if (TEST_BUNDLE.equals(event.getBundle().getSymbolicName()) + && BlueprintEvent.CREATED == event.getType()) { + synchronized (ready) { + ready.set(true); + ready.notify(); + } + } + } + }, + null); + try { + synchronized (ready) { + if (!ready.get()) { + ready.wait(3000); + } + } + return ready.get(); + } finally { + reg.unregister(); + } + } + +} Added: aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/handler/Aries1682NamespaceHandler.java URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/handler/Aries1682NamespaceHandler.java?rev=1784703&view=auto ============================================================================== --- aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/handler/Aries1682NamespaceHandler.java (added) +++ aries/trunk/blueprint/itests/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/cm/handler/Aries1682NamespaceHandler.java Tue Feb 28 08:49:05 2017 @@ -0,0 +1,94 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.aries.blueprint.itests.cm.handler; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.aries.blueprint.NamespaceHandler; +import org.apache.aries.blueprint.ParserContext; +import org.apache.aries.blueprint.PassThroughMetadata; +import org.apache.aries.blueprint.mutable.MutableBeanMetadata; +import org.osgi.framework.FrameworkUtil; +import org.osgi.service.blueprint.reflect.BeanMetadata; +import org.osgi.service.blueprint.reflect.ComponentMetadata; +import org.osgi.service.blueprint.reflect.Metadata; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +public class Aries1682NamespaceHandler implements NamespaceHandler { + + @Override + public URL getSchemaLocation(String namespace) { + if ("http://aries.apache.org/blueprint/xmlns/blueprint-aries-1682/v1.0.0".equals(namespace)) { + try { + return new URL("jar:" + FrameworkUtil.getBundle(this.getClass()).getLocation() + "!/blueprint-aries-1682.xsd"); + } catch (MalformedURLException e) { + throw new RuntimeException(e.getMessage(), e); + } + } + return null; + } + + @Override + public Set<Class> getManagedClasses() { + return new HashSet<Class>(Collections.<Class>singletonList(String.class)); + } + + @Override + public Metadata parse(Element element, ParserContext context) { + MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class); + metadata.setProcessor(true); + metadata.setId("aries-1682"); + metadata.setScope(BeanMetadata.SCOPE_SINGLETON); + metadata.addArgument(new PassThroughMetadata() { + @Override + public Object getObject() { + return "ARIES-1682"; + } + + @Override + public String getId() { + return "aries-1682-arg"; + } + + @Override + public int getActivation() { + return 0; + } + + @Override + public List<String> getDependsOn() { + return null; + } + }, null, 0); + metadata.setRuntimeClass(String.class); + return metadata; + } + + @Override + public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) { + return null; + } + +} Added: aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/ImportNamespacesWithXSDIncludeTest.xml URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/ImportNamespacesWithXSDIncludeTest.xml?rev=1784703&view=auto ============================================================================== --- aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/ImportNamespacesWithXSDIncludeTest.xml (added) +++ aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/ImportNamespacesWithXSDIncludeTest.xml Tue Feb 28 08:49:05 2017 @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version + 2.0 (the "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 Unless required by + applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. See the License for + the specific language governing permissions and limitations under the + License. + --> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0" + xmlns:a1682="http://aries.apache.org/blueprint/xmlns/blueprint-aries-1682/v1.0.0"> + + <a1682:property-placeholder2 id="aries1682"> + <ext:location>asd</ext:location> + </a1682:property-placeholder2> + +</blueprint> Added: aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682-common.xsd URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682-common.xsd?rev=1784703&view=auto ============================================================================== --- aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682-common.xsd (added) +++ aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682-common.xsd Tue Feb 28 08:49:05 2017 @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version + 2.0 (the "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 Unless required by + applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. See the License for + the specific language governing permissions and limitations under the + License. +--> +<xsd:schema xmlns="http://aries.apache.org/blueprint/xmlns/blueprint-aries-1682/v1.0.0" + xmlns:ext100="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0" + targetNamespace="http://aries.apache.org/blueprint/xmlns/blueprint-aries-1682/v1.0.0" + elementFormDefault="qualified" + attributeFormDefault="unqualified" + version="1.0.0"> + + <xsd:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0" /> + <xsd:import namespace="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0" /> + + <xsd:element name="property-placeholder" type="TpropertyPlaceholder"/> + + <xsd:complexType name="TpropertyPlaceholder"> + <xsd:complexContent> + <xsd:extension base="bp:Tcomponent"> + <xsd:sequence> + <xsd:element ref="ext100:location" /> + </xsd:sequence> + </xsd:extension> + </xsd:complexContent> + </xsd:complexType> + +</xsd:schema> Added: aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682.xml URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682.xml?rev=1784703&view=auto ============================================================================== --- aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682.xml (added) +++ aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682.xml Tue Feb 28 08:49:05 2017 @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version + 2.0 (the "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 Unless required by + applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. See the License for + the specific language governing permissions and limitations under the + License. + --> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy"> + + <bean id="Aries1682NamespaceHandler" class="org.apache.aries.blueprint.itests.cm.handler.Aries1682NamespaceHandler"/> + + <service ref="Aries1682NamespaceHandler" interface="org.apache.aries.blueprint.NamespaceHandler"> + <service-properties> + <entry key="osgi.service.blueprint.namespace" value="http://aries.apache.org/blueprint/xmlns/blueprint-aries-1682/v1.0.0"/> + </service-properties> + </service> + +</blueprint> Added: aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682.xsd URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682.xsd?rev=1784703&view=auto ============================================================================== --- aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682.xsd (added) +++ aries/trunk/blueprint/itests/blueprint-itests/src/test/resources/blueprint-aries-1682.xsd Tue Feb 28 08:49:05 2017 @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version + 2.0 (the "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 Unless required by + applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. See the License for + the specific language governing permissions and limitations under the + License. +--> +<xsd:schema xmlns="http://aries.apache.org/blueprint/xmlns/blueprint-aries-1682/v1.0.0" + xmlns:a1682="http://aries.apache.org/blueprint/xmlns/blueprint-aries-1682/v1.0.0" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://aries.apache.org/blueprint/xmlns/blueprint-aries-1682/v1.0.0" + elementFormDefault="qualified" + attributeFormDefault="unqualified" + version="1.0.0"> + + <xsd:include schemaLocation="./blueprint-aries-1682-common.xsd" /> + + <xsd:element name="property-placeholder2" type="TpropertyPlaceholder2"/> + + <xsd:complexType name="TpropertyPlaceholder2"> + <xsd:complexContent> + <xsd:extension base="a1682:TpropertyPlaceholder" /> + </xsd:complexContent> + </xsd:complexType> + +</xsd:schema>