You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/08/21 07:58:09 UTC
[camel] 14/20: Improve HTTP test. Add Spring XML test.
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 64f3273e48e3e552a5e64538bf02ff268f92b9d2
Author: Roberto Flores <be...@gmail.com>
AuthorDate: Sun Aug 4 00:27:11 2019 -0500
Improve HTTP test.
Add Spring XML test.
---
components/camel-any23/pom.xml | 11 +++++
.../dataformat/any23/Any23DataFormatHTTPTest.java | 12 ++---
...TTPTest.java => Any23DataFormatSpringTest.java} | 30 +++++++------
.../any23/spring/SpringAny23DataFormatTest.xml | 51 ++++++++++++++++++++++
.../modules/ROOT/pages/any23-dataformat.adoc | 11 +++--
5 files changed, 93 insertions(+), 22 deletions(-)
diff --git a/components/camel-any23/pom.xml b/components/camel-any23/pom.xml
index dcc19fc..9e10141 100644
--- a/components/camel-any23/pom.xml
+++ b/components/camel-any23/pom.xml
@@ -77,5 +77,16 @@
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-runtime</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-http</artifactId>
+ <scope>test</scope>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-spring</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/components/camel-any23/src/test/java/org/apache/camel/dataformat/any23/Any23DataFormatHTTPTest.java b/components/camel-any23/src/test/java/org/apache/camel/dataformat/any23/Any23DataFormatHTTPTest.java
index 086ae00..4a39606 100644
--- a/components/camel-any23/src/test/java/org/apache/camel/dataformat/any23/Any23DataFormatHTTPTest.java
+++ b/components/camel-any23/src/test/java/org/apache/camel/dataformat/any23/Any23DataFormatHTTPTest.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.dataformat.any23;
-import java.io.File;
import java.util.List;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
@@ -33,13 +32,12 @@ public class Any23DataFormatHTTPTest extends CamelTestSupport {
@Test
public void test() throws Exception {
MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
- //String contenhtml = Any23TestSupport.loadFileAsString(new File("src/test/resources/org/apache/camel/dataformat/any23/microformat/vcard.html"));
- //template.sendBody("direct:start", contenhtml);
+ template.sendBody("direct:start", "bar");
List<Exchange> list = resultEndpoint.getReceivedExchanges();
for (Exchange exchange : list) {
Message in = exchange.getIn();
Model resultingRDF = in.getBody(Model.class);
- assertEquals(resultingRDF.size(), 28);
+ assertEquals(resultingRDF.size(), 1762);
}
}
@@ -47,7 +45,11 @@ public class Any23DataFormatHTTPTest extends CamelTestSupport {
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
- from("http://dbpedia.org/page/Ecuador").unmarshal().any23(BASEURI).to("mock:result");
+ from("direct:start")
+ .to("http://dbpedia.org/page/Ecuador")
+ .unmarshal()
+ .any23(BASEURI)
+ .to("mock:result");
}
};
}
diff --git a/components/camel-any23/src/test/java/org/apache/camel/dataformat/any23/Any23DataFormatHTTPTest.java b/components/camel-any23/src/test/java/org/apache/camel/dataformat/any23/Any23DataFormatSpringTest.java
similarity index 60%
copy from components/camel-any23/src/test/java/org/apache/camel/dataformat/any23/Any23DataFormatHTTPTest.java
copy to components/camel-any23/src/test/java/org/apache/camel/dataformat/any23/Any23DataFormatSpringTest.java
index 086ae00..a164a82 100644
--- a/components/camel-any23/src/test/java/org/apache/camel/dataformat/any23/Any23DataFormatHTTPTest.java
+++ b/components/camel-any23/src/test/java/org/apache/camel/dataformat/any23/Any23DataFormatSpringTest.java
@@ -16,40 +16,42 @@
*/
package org.apache.camel.dataformat.any23;
-import java.io.File;
+import java.io.InputStream;
import java.util.List;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
-import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.apache.commons.io.IOUtils;
import org.eclipse.rdf4j.model.Model;
+import org.eclipse.rdf4j.rio.RDFFormat;
+import org.eclipse.rdf4j.rio.Rio;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
-public class Any23DataFormatHTTPTest extends CamelTestSupport {
+public class Any23DataFormatSpringTest extends CamelSpringTestSupport {
private final String BASEURI = "http://mock.foo/bar";
@Test
public void test() throws Exception {
MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
- //String contenhtml = Any23TestSupport.loadFileAsString(new File("src/test/resources/org/apache/camel/dataformat/any23/microformat/vcard.html"));
- //template.sendBody("direct:start", contenhtml);
+ template.sendBody("direct:start", "bar");
List<Exchange> list = resultEndpoint.getReceivedExchanges();
for (Exchange exchange : list) {
Message in = exchange.getIn();
- Model resultingRDF = in.getBody(Model.class);
- assertEquals(resultingRDF.size(), 28);
+ String resultingRDF = in.getBody(String.class);
+ InputStream toInputStream = IOUtils.toInputStream(resultingRDF);
+ Model parse = Rio.parse(toInputStream, BASEURI, RDFFormat.TURTLE);
+ assertEquals(parse.size(), 1);
}
}
@Override
- protected RouteBuilder createRouteBuilder() {
- return new RouteBuilder() {
- public void configure() {
- from("http://dbpedia.org/page/Ecuador").unmarshal().any23(BASEURI).to("mock:result");
- }
- };
+ protected AbstractApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/any23/spring/SpringAny23DataFormatTest.xml");
}
}
diff --git a/components/camel-any23/src/test/resources/org/apache/camel/dataformat/any23/spring/SpringAny23DataFormatTest.xml b/components/camel-any23/src/test/resources/org/apache/camel/dataformat/any23/spring/SpringAny23DataFormatTest.xml
new file mode 100644
index 0000000..6ef43db
--- /dev/null
+++ b/components/camel-any23/src/test/resources/org/apache/camel/dataformat/any23/spring/SpringAny23DataFormatTest.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: e1 -->
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+
+ <dataFormats>
+ <any23 id="any23" baseURI ="http://mock.foo/bar" outputFormat="TURTLE" >
+ <configurations>
+ <entry>
+ <key>any23.extraction.metadata.nesting</key>
+ <value>off</value>
+ </entry>
+ </configurations>
+ <extractors>html-head-title</extractors>
+ </any23>
+ </dataFormats>
+
+ <route>
+ <from uri="direct:start"/>
+ <to uri="http://microformats.org/2009/08"/>
+ <unmarshal>
+ <custom ref="any23"/>
+ </unmarshal>
+ <to uri="mock:result"/>
+ </route>
+
+ </camelContext>
+ <!-- END SNIPPET: e1 -->
+
+</beans>
\ No newline at end of file
diff --git a/docs/components/modules/ROOT/pages/any23-dataformat.adoc b/docs/components/modules/ROOT/pages/any23-dataformat.adoc
index 5a8b0ad..7e51ad2 100644
--- a/docs/components/modules/ROOT/pages/any23-dataformat.adoc
+++ b/docs/components/modules/ROOT/pages/any23-dataformat.adoc
@@ -1,6 +1,11 @@
[[any23-dataformat]]
== Any23 DataFormat
-== Any23 DataFormat
+Camel Any23 is a DataFormat that uses the Apache Anything To Triples (Any23) library to extract structured data in RDF from a variety of documents on the web.
+*Available as of Camel version 3.0*
+
+The main functionality of this DataFormat focuses on its Unmarshal method which extracts RDF triplets from compatible pages, in a wide variety of RDF syntaxes.
+
+
*Available as of Camel version 3.0*
Any23 is a Data Format that is intended to convert HTML from a site (or file) into rdf.
@@ -62,7 +67,7 @@ An example where the consumer provides some HTML
[source,java]
---------------------------------------------------------------------------
-from("file://site/inbox").unmarshal().tidyMarkup().to("file://site/blogs");
+from("direct:start").unmarshal().any23("http://mock.foo/bar").to("mock:result");
---------------------------------------------------------------------------
### Spring XML Example
@@ -99,4 +104,4 @@ the download page for the latest versions).
<artifactId>camel-tagsoup</artifactId>
<version>x.x.x</version>
</dependency>
-----------------------------------------
+----------------------------------------
\ No newline at end of file