Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #498 Improve the XSLT test coverage #777

Merged
merged 3 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ jobs:
-pl :camel-quarkus-integration-test-base64 \
-pl :camel-quarkus-integration-test-bindy \
-pl :camel-quarkus-integration-test-snakeyaml \
-pl :camel-quarkus-integration-test-tagsoup \
-pl :camel-quarkus-integration-test-csv \
-pl :camel-quarkus-integration-test-dataformat
networking:
Expand Down Expand Up @@ -417,7 +416,7 @@ jobs:
needs: build
strategy:
matrix:
extension: [ 'dataformats-json', 'infinispan', 'olingo4', 'xslt' ]
extension: [ 'dataformats-json', 'infinispan', 'olingo4', 'xml' ]
steps:
- name: Set BRANCH_OPTIONS
if: github.base_ref == 'camel-master' || github.base_ref == 'quarkus-master'
Expand Down
2 changes: 1 addition & 1 deletion examples/timer-log/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. -->
<!-- Please update rule whenever you change the dependencies of this module by running -->
<!-- mvn process-resources -Pformat from the root directory -->
<mvnd.builder.rule>camel-quarkus-log-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-timer-deployment</mvnd.builder.rule>
<mvnd.builder.rule>camel-quarkus-core-xml-deployment,camel-quarkus-log-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-timer-deployment</mvnd.builder.rule>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
package org.apache.camel.quarkus.component.xslt.deployment;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.quarkus.component.xslt.CamelXsltConfig;
import org.apache.camel.support.ResourceHelper;
Expand All @@ -45,25 +46,35 @@ List<ReflectiveClassBuildItem> generatedReflectiveClasses(List<XsltGeneratedClas
}

@BuildStep
List<NativeImageResourceBuildItem> xsltResources(CamelXsltConfig config) {
void xsltResources(
CamelXsltConfig config,
BuildProducer<NativeImageResourceBuildItem> nativeResources,
BuildProducer<NativeImageResourceBundleBuildItem> nativeResourceBundles) {
if (!config.sources.isPresent()) {
return Collections.emptyList();
return;
}

List<NativeImageResourceBuildItem> items = new ArrayList<>(config.sources.get().size());

for (String source : config.sources.get()) {
final List<String> sources = config.sources.get();
List<String> paths = new ArrayList<>(sources.size() + 5);
for (String source : sources) {
String scheme = ResourceHelper.getScheme(source);

if (Objects.isNull(scheme) || Objects.equals(scheme, CLASSPATH_SCHEME)) {
if (Objects.equals(scheme, CLASSPATH_SCHEME)) {
source = source.substring(CLASSPATH_SCHEME.length() + 1);
}

items.add(new NativeImageResourceBuildItem(source));
paths.add(source);
}
}
paths.add("org/apache/xml/serializer/Encodings.properties");
paths.add("org/apache/xml/serializer/output_html.properties");
paths.add("org/apache/xml/serializer/output_text.properties");
paths.add("org/apache/xml/serializer/output_unknown.properties");
paths.add("org/apache/xml/serializer/output_xml.properties");
nativeResources.produce(new NativeImageResourceBuildItem(paths));

return items;
nativeResourceBundles.produce(new NativeImageResourceBundleBuildItem("org.apache.xml.serializer.HTMLEntities"));
nativeResourceBundles.produce(new NativeImageResourceBundleBuildItem("org.apache.xml.serializer.XMLEntities"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void xsltResources(
tf.setErrorListener(new CamelXsltErrorListener());
tf.newTemplates(resolvedUri.source);
} catch (TransformerException e) {
throw new RuntimeException(e);
throw new RuntimeException("Could not compile XSLT " + uri, e);
}
}

Expand All @@ -135,4 +135,5 @@ void xsltResources(
.forEach(File::delete);
}
}

}
3 changes: 1 addition & 2 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,11 @@
<module>snakeyaml</module>
<module>sql</module>
<module>stream</module>
<module>tagsoup</module>
<module>tarfile</module>
<module>telegram</module>
<module>twitter</module>
<module>validator</module>
<module>xslt</module>
<module>xml</module>
<module>zipfile</module>
</modules>

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>camel-quarkus-integration-test-tagsoup</artifactId>
<name>Camel Quarkus :: Integration Tests :: TagSoup</name>
<description>Integration tests for Camel Quarkus TagSoup extension</description>
<artifactId>camel-quarkus-integration-test-xml</artifactId>
<name>Camel Quarkus :: Integration Tests :: XML</name>
<description>Integration tests for various XML related extensions</description>

<properties>
<!-- mvnd, a.k.a. Maven Daemon: https://github.com/gnodet/mvnd -->
Expand All @@ -36,14 +36,18 @@
<!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. -->
<!-- Please update rule whenever you change the dependencies of this module by running -->
<!-- mvn process-resources -Pformat from the root directory -->
<mvnd.builder.rule>camel-quarkus-direct-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-tagsoup-deployment</mvnd.builder.rule>
<mvnd.builder.rule>camel-quarkus-direct-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-tagsoup-deployment,camel-quarkus-xslt-deployment</mvnd.builder.rule>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-tagsoup</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-xslt</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct</artifactId>
Expand All @@ -52,10 +56,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.tagsoup.it;
package org.apache.camel.quarkus.component.xml.it;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
Expand All @@ -27,11 +27,11 @@
import org.apache.camel.ProducerTemplate;
import org.jboss.logging.Logger;

@Path("/tagsoup")
@Path("/xml")
@ApplicationScoped
public class TagSoupResource {
public class XmlResource {

private static final Logger LOG = Logger.getLogger(TagSoupResource.class);
private static final Logger LOG = Logger.getLogger(XmlResource.class);

@Inject
ProducerTemplate producerTemplate;
Expand All @@ -43,8 +43,40 @@ public class TagSoupResource {
public String htmlParse(String html) {
LOG.debugf("Parsing HTML %s", html);
return producerTemplate.requestBody(
TagSoupRouteBuilder.DIRECT_HTML_TO_DOM,
XmlRouteBuilder.DIRECT_HTML_TO_DOM,
html,
String.class);
}

@Path("/xslt")
@POST
@Produces(MediaType.TEXT_PLAIN)
public String classpath(String body) throws Exception {
return producerTemplate.requestBody("xslt:xslt/classpath-transform.xsl", body, String.class);
}

@Path("/html-transform")
@POST
@Consumes(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_PLAIN)
public String htmlTransform(String html) {
LOG.debugf("Parsing HTML %s", html);
return producerTemplate.requestBody(
XmlRouteBuilder.DIRECT_HTML_TRANSFORM,
html,
String.class);
}

@Path("/html-to-text")
@POST
@Consumes(MediaType.TEXT_HTML)
@Produces(MediaType.TEXT_PLAIN)
public String htmlToText(String html) {
LOG.debugf("Parsing HTML %s", html);
return producerTemplate.requestBody(
XmlRouteBuilder.DIRECT_HTML_TO_TEXT,
html,
String.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.tagsoup.it;
package org.apache.camel.quarkus.component.xml.it;

import org.w3c.dom.Document;
import org.w3c.dom.Node;

import org.apache.camel.builder.RouteBuilder;

public class TagSoupRouteBuilder extends RouteBuilder {
public class XmlRouteBuilder extends RouteBuilder {
public static final String DIRECT_HTML_TO_DOM = "direct:html-to-dom";
public static final String DIRECT_HTML_TRANSFORM = "direct:html-transfrom";
public static final String DIRECT_HTML_TO_TEXT = "direct:html-to-text";

@Override
public void configure() {
Expand Down Expand Up @@ -50,5 +52,15 @@ public void configure() {
}
exchange.getIn().setBody(text.getTextContent());
});

from(DIRECT_HTML_TRANSFORM)
.unmarshal().tidyMarkup()
// tagSoup produces DOM that is then consumed by XSLT
.to("xslt:xslt/html-transform.xsl");

from(DIRECT_HTML_TO_TEXT)
.unmarshal().tidyMarkup()
// tagSoup produces DOM that is then consumed by XSLT
.to("xslt:xslt/html-to-text.xsl");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ quarkus.log.category."org.apache.camel.quarkus.core.deployment".level = INFO
#
# Quarkus - Camel
#
quarkus.camel.xslt.sources = xslt/classpath-transform.xsl
quarkus.camel.xslt.sources = xslt/classpath-transform.xsl,xslt/html-transform.xsl,xslt/html-to-text.xsl
32 changes: 32 additions & 0 deletions integration-tests/xml/src/main/resources/xslt/html-to-text.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--

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.

-->
<xsl:stylesheet
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version='1.0'>

<xsl:output method="text"/>

<xsl:template match="/">
= <xsl:value-of select="/html/head/title"/><xsl:text>&#xa;</xsl:text>
<xsl:text>&#xa;</xsl:text>
<xsl:value-of select="/html/body/p"/>
</xsl:template>

</xsl:stylesheet>