Repository: camel Updated Branches: refs/heads/master c261bad16 -> 01056c16e
Added new component Camel-chunk Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7cf04221 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7cf04221 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7cf04221 Branch: refs/heads/master Commit: 7cf0422174d58d469d7fd03566958ae6c209bfae Parents: c261bad Author: ancosen <anco...@gmail.com> Authored: Sun Nov 30 10:14:35 2014 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Dec 2 11:13:57 2014 +0100 ---------------------------------------------------------------------- components/camel-chunk/README.md | 101 ++++++++ components/camel-chunk/pom.xml | 68 +++++ .../camel/component/chunk/ChunkComponent.java | 58 +++++ .../camel/component/chunk/ChunkConstants.java | 48 ++++ .../camel/component/chunk/ChunkEndpoint.java | 248 +++++++++++++++++++ .../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++++++ .../src/main/resources/META-INF/NOTICE.txt | 11 + .../services/org/apache/camel/component/chunk | 18 ++ .../chunk/ChunkComponentLayersTest.java | 67 +++++ .../chunk/ChunkComponentNestedLayersTest.java | 68 +++++ .../chunk/ChunkComponentNestedTest.java | 67 +++++ .../chunk/ChunkComponentTemplateTest.java | 67 +++++ .../component/chunk/ChunkComponentTest.java | 100 ++++++++ ...unkDifferentThemeFolderAndSubfolderTest.java | 67 +++++ ...entThemeFolderSubfolderAndExtensionTest.java | 67 +++++ ...fferentThemeFolderSubfolderAndLayerTest.java | 67 +++++ .../chunk/ChunkDifferentThemeFolderTest.java | 67 +++++ .../camel/component/chunk/ChunkLetterTest.java | 64 +++++ .../resources/folderexample/file_example.chtml | 1 + .../subfolderexample/diff_template.chtml | 10 + .../subfolderexample/subfile_example.chtml | 1 + .../subfolderexample/subfile_example.file | 1 + .../src/test/resources/log4j.properties | 14 ++ .../src/test/resources/themes/example.chtml | 10 + .../src/test/resources/themes/file.chtml | 1 + .../src/test/resources/themes/file_nested.chtml | 2 + .../src/test/resources/themes/hello.chtml | 1 + .../src/test/resources/themes/letter.chtml | 6 + .../src/test/resources/themes/nested.chtml | 1 + .../resources/themes/subfolder/theme1.chtml | 1 + .../resources/themes/subfolder/theme2.chtml | 1 + components/pom.xml | 1 + parent/pom.xml | 3 +- 33 files changed, 1509 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/README.md ---------------------------------------------------------------------- diff --git a/components/camel-chunk/README.md b/components/camel-chunk/README.md new file mode 100644 index 0000000..340a8a8 --- /dev/null +++ b/components/camel-chunk/README.md @@ -0,0 +1,101 @@ +# Chunk Component + +# Introduction + +This component use the Java Chunk library: http://www.x5software.com/chunk/examples/ChunkExample?loc=en_US + +Chunk is a Template Engine for Java similar to Apache Velocity, Mustache Java and Freemarker + +The **chunk:** component allows for processing a message using a Chunk template. This can be useful when using Templating to build responses for requests. + +Maven users will need to add the following dependency to their pom.xml for this component: + +```xml + +<dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-chunk</artifactId> + <version>x.x.x</version> + <!-- use the same version as your Camel core version --> +</dependency> + +``` + +# URI format + +``` + +chunk:templateName[?options] + +``` + +# Options + +By default the chunk library will scan a default folder "themes" for a specific template, however is possible to define a differente folder to scan using the specific option. +Default extension of template file are .chtml and .cxml, however is possible to define different extension using the specific option. + +| Option | Default | Description | +|---------------------|---------|------------------------------------------------------------------------------------------------------------------------| +| encoding | null | Character encoding of the resource content. | +| themesFolder | null | Alternative folder to scan for a template name. | +| themeSubfolder | null | Alternative subfolder to scan for a template name if themeFolder parameter is set. | +| themeLayer | null | A specific layer of a template file to use as template. | +| extension | null | Alternative extension to scan for a template name if themeFolder and themeSubfolder are set | + +# Dynamic Templates + +Camel-chunk component provides two headers by which you can define a different resource location for a template or the template content itself. If any of these headers is set then Camel-chunk component uses this over the endpoint configured resource. This allows you to provide a dynamic template at runtime. + +| Header | Type | Description | Support Version | +|----------------------------------------------|-----------|----------------------------------------------------------------------------|-----------------| +| ChunkConstants.CHUNK_RESOURCE_URI | String | A URI for the template resource to use instead of the endpoint configured. | | +| ChunkConstants.CHUNK_TEMPLATE | String | The template to use instead of the endpoint configured. | | + +# Examples + +**Example 1** + +```java + from("direct:in") + .to("chunk://file") + .to("direct:out"); +``` + +In this example the chunk component will look for file.chtml template in themes folder and it will use it as template. + +**Example 2** + +```java + from("direct:in") + .to("chunk:example?themeLayer=example_1") +``` + +In this example the chunk component will look for example.chtml in themes folder and will use the #example_1 layer + +**Example 3** + +```java + from("direct:in") + .to("chunk://hello") + .to("chunk://subfolder/theme1") +``` + +In this example the chunk component will look for hello.chtml template in themes folder and for theme1.chtml in themes/subfolder/ + +**Example 4** + +```java + from("direct:in") + .to("chunk:subfile_example?themeFolder=folderexample&themeSubfolder=subfolderexample") +``` + +In this example the chunk component will look for subfile_example.chtml in folderexample/subfolderexample/ folder and not in the default themes folder. + +**Example 5** + +```java + from("direct:in") + .to("chunk:subfile_example?themeFolder=folderexample&themeSubfolder=subfolderexample&extension=file") +``` + +In this example the chunk component will look for subfile_example.file (not .chtml or .cxml) in folderexample/subfolderexample/ folder and not in the default themes folder. http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-chunk/pom.xml b/components/camel-chunk/pom.xml new file mode 100644 index 0000000..8876b93 --- /dev/null +++ b/components/camel-chunk/pom.xml @@ -0,0 +1,68 @@ +<?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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <artifactId>components</artifactId> + <groupId>org.apache.camel</groupId> + <version>2.15-SNAPSHOT</version> + </parent> + + <artifactId>camel-chunk</artifactId> + <packaging>bundle</packaging> + <name>Camel :: Chunk</name> + <description>Camel Chunk support</description> + + <properties> + <camel.osgi.export.pkg>org.apache.camel.component.chunk.*</camel.osgi.export.pkg> + <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=chunk</camel.osgi.export.service> + </properties> + + <dependencies> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + </dependency> + <dependency> + <groupId>com.x5dev</groupId> + <artifactId>chunk-templates</artifactId> + <version>${chunk-templates-version}</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>${commons-io-version}</version> + </dependency> + + <!-- testing --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + +</project> http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkComponent.java b/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkComponent.java new file mode 100644 index 0000000..24648a8 --- /dev/null +++ b/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkComponent.java @@ -0,0 +1,58 @@ +/** + * 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.camel.component.chunk; + +import java.util.Map; + +import org.apache.camel.Endpoint; +import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.util.ObjectHelper; + +/** + * Represents the component that manages {@link ChunksEndpoint}. + * + * @version + */ +public class ChunkComponent extends DefaultComponent { + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + ChunkEndpoint endpoint = new ChunkEndpoint(uri, this, remaining); + String encoding = getAndRemoveParameter(parameters, "encoding", String.class); + if (ObjectHelper.isNotEmpty(encoding)) { + endpoint.setEncoding(encoding); + } + String themesFolder = getAndRemoveParameter(parameters, "themesFolder", String.class); + if (ObjectHelper.isNotEmpty(themesFolder)) { + endpoint.setThemeFolder(themesFolder); + } + String themeSubfolder = getAndRemoveParameter(parameters, "themeSubfolder", String.class); + if (ObjectHelper.isNotEmpty(themeSubfolder)) { + endpoint.setThemeSubfolder(themeSubfolder); + } + String themeLayer = getAndRemoveParameter(parameters, "themeLayer", String.class); + if (ObjectHelper.isNotEmpty(themeLayer)) { + endpoint.setThemeLayer(themeLayer); + } + String extension = getAndRemoveParameter(parameters, "extension", String.class); + if (ObjectHelper.isNotEmpty(extension)) { + endpoint.setExtension(extension); + } + setProperties(endpoint, parameters); + return endpoint; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkConstants.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkConstants.java b/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkConstants.java new file mode 100644 index 0000000..113cb15 --- /dev/null +++ b/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkConstants.java @@ -0,0 +1,48 @@ +/** + * 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.camel.component.chunk; + +/** + * Chunk component constants + */ +public final class ChunkConstants { + + /** + * Header containing a Chunk template location + */ + public static final String CHUNK_RESOURCE_URI = "ChunkResourceUri"; + + /** + * Header containing the Chunk template code + */ + public static final String CHUNK_TEMPLATE = "ChunkTemplate"; + + /** + * Chunk endpoint URI prefix + */ + public static final String CHUNK_ENDPOINT_URI_PREFIX = "chunk:"; + + /** + * Chunk Template extension + */ + public static final String CHUNK_LAYER_SEPARATOR = "#"; + + private ChunkConstants() { + // Utility class + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkEndpoint.java b/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkEndpoint.java new file mode 100644 index 0000000..4a9cd93 --- /dev/null +++ b/components/camel-chunk/src/main/java/org/apache/camel/component/chunk/ChunkEndpoint.java @@ -0,0 +1,248 @@ +/** + * 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.camel.component.chunk; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.net.URL; +import java.util.Map; + +import com.x5.template.Chunk; +import com.x5.template.Theme; + +import org.apache.camel.Component; +import org.apache.camel.Exchange; +import org.apache.camel.ExchangePattern; +import org.apache.camel.Message; +import org.apache.camel.component.ResourceEndpoint; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.util.ExchangeHelper; +import org.apache.commons.io.IOUtils; + +import static org.apache.camel.component.chunk.ChunkConstants.CHUNK_ENDPOINT_URI_PREFIX; +import static org.apache.camel.component.chunk.ChunkConstants.CHUNK_LAYER_SEPARATOR; +import static org.apache.camel.component.chunk.ChunkConstants.CHUNK_RESOURCE_URI; +import static org.apache.camel.component.chunk.ChunkConstants.CHUNK_TEMPLATE; + +/** + * Represents a Camel Chunk endpoint + */ +@UriEndpoint(scheme = "chunk", label = "templating") +public class ChunkEndpoint extends ResourceEndpoint { + + private Theme theme; + private Chunk chunk; + + @UriParam(description = "Define the encoding of the body") + private String encoding; + + @UriParam(description = "Define the themes folder to scan") + private String themeFolder; + + @UriParam(description = "Define the themes subfolder to scan") + private String themeSubfolder; + + @UriParam(description = "Define the theme layer to elaborate") + private String themeLayer; + + @UriParam(description = "Define the file extension of the template") + private String extension; + + public ChunkEndpoint() { + } + + public ChunkEndpoint(String endpointUri, Component component, String resourceUri) { + super(endpointUri, component, resourceUri); + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + public ExchangePattern getExchangePattern() { + return ExchangePattern.InOut; + } + + @Override + protected String createEndpointUri() { + return CHUNK_ENDPOINT_URI_PREFIX + getResourceUri(); + } + + @Override + public void clearContentCache() { + this.chunk = null; + super.clearContentCache(); + } + + @Override + protected void onExchange(Exchange exchange) throws Exception { + boolean fromTemplate = false; + String newResourceUri = exchange.getIn().getHeader(CHUNK_RESOURCE_URI, String.class); + if (theme == null) { + theme = getOrCreateTheme(); + } + if (newResourceUri == null) { + String newTemplate = exchange.getIn().getHeader(CHUNK_TEMPLATE, String.class); + Chunk newChunk; + if (newTemplate == null) { + fromTemplate = false; + newChunk = getOrCreateChunk(theme, fromTemplate); + } else { + fromTemplate = true; + newChunk = createChunk(new StringReader(newTemplate), theme, fromTemplate); + exchange.getIn().removeHeader(CHUNK_TEMPLATE); + } + + // Execute Chunk + Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange); + StringWriter writer = new StringWriter(); + newChunk.putAll(variableMap); + newChunk.render(writer); + writer.flush(); + + // Fill out message + Message out = exchange.getOut(); + out.setBody(newChunk.toString()); + out.setHeaders(exchange.getIn().getHeaders()); + out.setAttachments(exchange.getIn().getAttachments()); + } else { + exchange.getIn().removeHeader(ChunkConstants.CHUNK_RESOURCE_URI); + ChunkEndpoint newEndpoint = getCamelContext().getEndpoint(CHUNK_ENDPOINT_URI_PREFIX + newResourceUri, ChunkEndpoint.class); + newEndpoint.onExchange(exchange); + } + } + + /** + * Create a Chunk template + * + * @param resourceReader Reader used to get template + * @param Theme The theme + * @return Chunk + */ + private Chunk createChunk(Reader resourceReader, Theme theme, boolean fromTemplate) throws IOException { + ClassLoader oldcl = Thread.currentThread().getContextClassLoader(); + try { + ClassLoader apcl = getCamelContext().getApplicationContextClassLoader(); + if (apcl != null) { + Thread.currentThread().setContextClassLoader(apcl); + } + Chunk newChunk = null; + if (fromTemplate) { + newChunk = theme.makeChunk(); + String targetString = IOUtils.toString(resourceReader); + newChunk.append(targetString); + } else { + String targetString = IOUtils.toString(resourceReader); + newChunk = theme.makeChunk(targetString); + } + return newChunk; + } finally { + resourceReader.close(); + if (oldcl != null) { + Thread.currentThread().setContextClassLoader(oldcl); + } + } + } + + private Chunk getOrCreateChunk(Theme theme, boolean fromTemplate) throws IOException { + if (chunk == null) { + chunk = createChunk(new StringReader(getResourceUriExtended()), theme, fromTemplate); + } + return chunk; + } + + private Theme getOrCreateTheme() throws IOException { + if (theme == null) { + if (themeFolder == null && themeSubfolder == null) { + theme = new Theme(); + } else if (themeFolder != null && themeSubfolder == null) { + ClassLoader apcl = getCamelContext().getApplicationContextClassLoader(); + URL url = apcl.getResource(themeFolder); + theme = new Theme(url.getPath(), ""); + } else { + ClassLoader apcl = getCamelContext().getApplicationContextClassLoader(); + URL url = apcl.getResource(themeFolder); + theme = new Theme(url.getPath(), themeSubfolder); + } + if (encoding != null) { + theme.setEncoding(encoding); + } + } + return theme; + } + + @Override + public String getResourceUri() { + String uri = super.getResourceUri(); + if (uri != null && (uri.startsWith("/") || uri.startsWith("\\"))) { + return uri.substring(1); + } else { + return uri; + } + } + + private String getResourceUriExtended() throws IOException { + return themeLayer == null + ? getResourceUri() + : getResourceUri() + CHUNK_LAYER_SEPARATOR + themeLayer; + } + + public String getEncoding() { + return encoding; + } + + public void setEncoding(String encoding) { + this.encoding = encoding; + } + + public String getThemeFolder() { + return themeFolder; + } + + public void setThemeFolder(String themeFolder) { + this.themeFolder = themeFolder; + } + + public String getThemeSubfolder() { + return themeSubfolder; + } + + public void setThemeSubfolder(String themeSubfolder) { + this.themeSubfolder = themeSubfolder; + } + + public String getThemeLayer() { + return themeLayer; + } + + public void setThemeLayer(String themeLayer) { + this.themeLayer = themeLayer; + } + + public String getExtension() { + return extension; + } + + public void setExtension(String extension) { + this.extension = extension; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/main/resources/META-INF/LICENSE.txt ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/main/resources/META-INF/LICENSE.txt b/components/camel-chunk/src/main/resources/META-INF/LICENSE.txt new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/components/camel-chunk/src/main/resources/META-INF/LICENSE.txt @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/main/resources/META-INF/NOTICE.txt ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/main/resources/META-INF/NOTICE.txt b/components/camel-chunk/src/main/resources/META-INF/NOTICE.txt new file mode 100644 index 0000000..2e215bf --- /dev/null +++ b/components/camel-chunk/src/main/resources/META-INF/NOTICE.txt @@ -0,0 +1,11 @@ + ========================================================================= + == NOTICE file corresponding to the section 4 d of == + == the Apache License, Version 2.0, == + == in this case for the Apache Camel distribution. == + ========================================================================= + + This product includes software developed by + The Apache Software Foundation (http://www.apache.org/). + + Please read the different LICENSE files present in the licenses directory of + this distribution. http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/main/resources/META-INF/services/org/apache/camel/component/chunk ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/main/resources/META-INF/services/org/apache/camel/component/chunk b/components/camel-chunk/src/main/resources/META-INF/services/org/apache/camel/component/chunk new file mode 100644 index 0000000..a07813d --- /dev/null +++ b/components/camel-chunk/src/main/resources/META-INF/services/org/apache/camel/component/chunk @@ -0,0 +1,18 @@ +# +# 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. +# + +class=org.apache.camel.component.chunk.ChunkComponent http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentLayersTest.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentLayersTest.java b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentLayersTest.java new file mode 100644 index 0000000..300c9ee --- /dev/null +++ b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentLayersTest.java @@ -0,0 +1,67 @@ +/** + * 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.camel.component.chunk; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * Unit test for {@link ChunkComponent} and {@link ChunkEndpoint} + */ +public class ChunkComponentLayersTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:endSimple") + protected MockEndpoint endSimpleMock; + + @Produce(uri = "direct:startSimple") + protected ProducerTemplate startSimpleProducerTemplate; + + /** + * Test using themeLayer parameter without Resource URI header defined + */ + @Test + public void testChunkLayer() throws Exception { + // Prepare + Exchange exchange = createExchangeWithBody("The Body"); + exchange.getIn().setHeader("name", "Andrew"); + endSimpleMock.expectedMessageCount(1); + endSimpleMock.expectedBodiesReceived("<div>\nEarth to Andrew. Come in, Andrew.\n</div>\n"); + // Act + startSimpleProducerTemplate.send(exchange); + // Verify + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:startSimple") + .to("chunk:example?themeLayer=example_1") + .to("mock:endSimple"); + } + }; + } +} + http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentNestedLayersTest.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentNestedLayersTest.java b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentNestedLayersTest.java new file mode 100644 index 0000000..4e909c7 --- /dev/null +++ b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentNestedLayersTest.java @@ -0,0 +1,68 @@ +/** + * 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.camel.component.chunk; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * Unit test for {@link ChunkComponent} and {@link ChunkEndpoint} + */ +public class ChunkComponentNestedLayersTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:endSimple") + protected MockEndpoint endSimpleMock; + + @Produce(uri = "direct:startSimple") + protected ProducerTemplate startSimpleProducerTemplate; + + /** + * Test using two following distinct themeLayer of the same theme without Resource URI header defined + */ + @Test + public void testChunkDoubleLayers() throws Exception { + // Prepare + Exchange exchange = createExchangeWithBody("The Body"); + exchange.getIn().setHeader("name", "Andrew"); + endSimpleMock.expectedMessageCount(1); + endSimpleMock.expectedBodiesReceived("<div>\nMars to Andrew. Come in, Andrew. This is the body: <div>\nEarth to Andrew. Come in, Andrew.\n</div>\n\n</div>\n"); + // Act + startSimpleProducerTemplate.send(exchange); + // Verify + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:startSimple") + .to("chunk:example?themeLayer=example_1") + .to("chunk:example?themeLayer=example_2") + .to("mock:endSimple"); + } + }; + } +} + http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentNestedTest.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentNestedTest.java b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentNestedTest.java new file mode 100644 index 0000000..ee0c78a --- /dev/null +++ b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentNestedTest.java @@ -0,0 +1,67 @@ +/** + * 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.camel.component.chunk; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * Unit test for {@link ChunkComponent} and {@link ChunkEndpoint} + */ +public class ChunkComponentNestedTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:endSimple") + protected MockEndpoint endSimpleMock; + + @Produce(uri = "direct:startSimple") + protected ProducerTemplate startSimpleProducerTemplate; + + /** + * Test using two following different theme from different folder without Resource URI header defined + */ + @Test + public void testChunkSubfolder() throws Exception { + // Prepare + endSimpleMock.expectedMessageCount(1); + endSimpleMock.expectedBodiesReceived("This the result of last call to chunk Earth to Andrew. Come in, Andrew.\n\n"); + // Act + startSimpleProducerTemplate.sendBodyAndHeader("The Body", "name", "Andrew"); + // Verify + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:startSimple") + .setHeader("result", constant("ok")) + .to("chunk://hello") + .to("chunk://subfolder/theme1") + .to("mock:endSimple"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentTemplateTest.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentTemplateTest.java b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentTemplateTest.java new file mode 100644 index 0000000..1f6c751 --- /dev/null +++ b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentTemplateTest.java @@ -0,0 +1,67 @@ +/** + * 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.camel.component.chunk; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * Unit test for {@link ChunkComponent} and {@link ChunkEndpoint} + */ +public class ChunkComponentTemplateTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:endSimple") + protected MockEndpoint endSimpleMock; + + @Produce(uri = "direct:startSimple") + protected ProducerTemplate startSimpleProducerTemplate; + + /** + * Test using code Template header + */ + @Test + public void testChunkWithTemplateHeader() throws Exception { + // Prepare + Exchange exchange = createExchangeWithBody("The Body"); + exchange.getIn().setHeader("someHeader", "Some Header"); + exchange.getIn().setHeader(ChunkConstants.CHUNK_TEMPLATE, "Body='{$body}'|SomeHeader='{$headers.someHeader}'"); + endSimpleMock.expectedMessageCount(1); + endSimpleMock.expectedBodiesReceived("Body='The Body'|SomeHeader='Some Header'"); + // Act + startSimpleProducerTemplate.send(exchange); + // Verify + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:startSimple") + .to("chunk://hello") + .to("mock:endSimple"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentTest.java b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentTest.java new file mode 100644 index 0000000..6f71f2d --- /dev/null +++ b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkComponentTest.java @@ -0,0 +1,100 @@ +/** + * 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.camel.component.chunk; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.util.StopWatch; +import org.junit.Test; +import org.slf4j.LoggerFactory; + +/** + * Unit test for {@link ChunkComponent} and {@link ChunkEndpoint} + */ +public class ChunkComponentTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:endSimple") + protected MockEndpoint endSimpleMock; + + @Produce(uri = "direct:startSimple") + protected ProducerTemplate startSimpleProducerTemplate; + + /** + * Test without Resource URI header defined + */ + @Test + public void testChunk() throws Exception { + // Prepare + endSimpleMock.expectedMessageCount(1); + endSimpleMock.expectedBodiesReceived("Earth to Andrew. Come in, Andrew.\n"); + // Act + startSimpleProducerTemplate.sendBodyAndHeader("The Body", "name", "Andrew"); + // Verify + assertMockEndpointsSatisfied(); + } + + /** + * Test using Resource URI header + */ + @Test + public void testChunkWithResourceUriHeader() throws Exception { + // Prepare + Exchange exchange = createExchangeWithBody("The Body"); + exchange.getIn().setHeader("name", "Andrew"); + exchange.getIn().setHeader(ChunkConstants.CHUNK_RESOURCE_URI, "hello"); + endSimpleMock.expectedMessageCount(1); + endSimpleMock.expectedBodiesReceived("Earth to Andrew. Come in, Andrew.\n"); + // Act + startSimpleProducerTemplate.send(exchange); + // Verify + assertMockEndpointsSatisfied(); + } + + /** + * Performance test + */ + @Test + public void testChunkPerformance() throws Exception { + int messageCount = 10000; + endSimpleMock.expectedMessageCount(messageCount); + StopWatch stopwatch = new StopWatch(true); + for (int i = 0; i < messageCount; i++) { + startSimpleProducerTemplate.sendBodyAndHeader("The Body", "name", "Andrew"); + } + assertMockEndpointsSatisfied(); + LoggerFactory.getLogger(getClass()).info("Chunk performance: " + stopwatch.stop() + "ms for " + messageCount + " messages"); + + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:startSimple") + .to("chunk://file") + .to("mock:endSimple"); + } + }; + } +} + http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderAndSubfolderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderAndSubfolderTest.java b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderAndSubfolderTest.java new file mode 100644 index 0000000..0a22a9e --- /dev/null +++ b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderAndSubfolderTest.java @@ -0,0 +1,67 @@ +/** + * 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.camel.component.chunk; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * Unit test for {@link ChunkComponent} and {@link ChunkEndpoint} + */ +public class ChunkDifferentThemeFolderAndSubfolderTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:endSimple") + protected MockEndpoint endSimpleMock; + + @Produce(uri = "direct:startSimple") + protected ProducerTemplate startSimpleProducerTemplate; + + /** + * Test using themeFolder and themeSubfolder parameters + */ + @Test + public void testChunkSubfolder() throws Exception { + // Prepare + Exchange exchange = createExchangeWithBody("The Body"); + exchange.getIn().setHeader("name", "Andrew"); + endSimpleMock.expectedMessageCount(1); + endSimpleMock.expectedBodiesReceived("Earth to Andrew. Come in, Andrew.\n"); + // Act + startSimpleProducerTemplate.send(exchange); + // Verify + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:startSimple") + .to("chunk:subfile_example?themeFolder=folderexample&themeSubfolder=subfolderexample") + .to("mock:endSimple"); + } + }; + } +} + http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderSubfolderAndExtensionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderSubfolderAndExtensionTest.java b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderSubfolderAndExtensionTest.java new file mode 100644 index 0000000..afd0c02 --- /dev/null +++ b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderSubfolderAndExtensionTest.java @@ -0,0 +1,67 @@ +/** + * 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.camel.component.chunk; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * Unit test for {@link ChunkComponent} and {@link ChunkEndpoint} + */ +public class ChunkDifferentThemeFolderSubfolderAndExtensionTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:endSimple") + protected MockEndpoint endSimpleMock; + + @Produce(uri = "direct:startSimple") + protected ProducerTemplate startSimpleProducerTemplate; + + /** + * Test using themeFolder, themeSubfolder and extension parameters + */ + @Test + public void testChunkSubfolder() throws Exception { + // Prepare + Exchange exchange = createExchangeWithBody("The Body"); + exchange.getIn().setHeader("name", "Andrew"); + endSimpleMock.expectedMessageCount(1); + endSimpleMock.expectedBodiesReceived("Earth to Andrew. Come in, Andrew.\n"); + // Act + startSimpleProducerTemplate.send(exchange); + // Verify + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:startSimple") + .to("chunk:subfile_example?themeFolder=folderexample&themeSubfolder=subfolderexample&extension=file") + .to("mock:endSimple"); + } + }; + } +} + http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderSubfolderAndLayerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderSubfolderAndLayerTest.java b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderSubfolderAndLayerTest.java new file mode 100644 index 0000000..b3f1f7a --- /dev/null +++ b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderSubfolderAndLayerTest.java @@ -0,0 +1,67 @@ +/** + * 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.camel.component.chunk; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * Unit test for {@link ChunkComponent} and {@link ChunkEndpoint} + */ +public class ChunkDifferentThemeFolderSubfolderAndLayerTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:endSimple") + protected MockEndpoint endSimpleMock; + + @Produce(uri = "direct:startSimple") + protected ProducerTemplate startSimpleProducerTemplate; + + /** + * Test using themeFolder, themeSubfolder and themeLayer parameters + */ + @Test + public void testChunkSubfolder() throws Exception { + // Prepare + Exchange exchange = createExchangeWithBody("The Body"); + exchange.getIn().setHeader("name", "Andrew"); + endSimpleMock.expectedMessageCount(1); + endSimpleMock.expectedBodiesReceived("<div>\nEarth to Andrew. Come in, Andrew.\n</div>\n"); + // Act + startSimpleProducerTemplate.send(exchange); + // Verify + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:startSimple") + .to("chunk:diff_template?themeFolder=folderexample&themeSubfolder=subfolderexample&themeLayer=example_1") + .to("mock:endSimple"); + } + }; + } +} + http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderTest.java b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderTest.java new file mode 100644 index 0000000..472642c --- /dev/null +++ b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkDifferentThemeFolderTest.java @@ -0,0 +1,67 @@ +/** + * 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.camel.component.chunk; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * Unit test for {@link ChunkComponent} and {@link ChunkEndpoint} + */ +public class ChunkDifferentThemeFolderTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:endSimple") + protected MockEndpoint endSimpleMock; + + @Produce(uri = "direct:startSimple") + protected ProducerTemplate startSimpleProducerTemplate; + + /** + * Test using themeFolder parameter + */ + @Test + public void testChunkSingleLayer() throws Exception { + // Prepare + Exchange exchange = createExchangeWithBody("The Body"); + exchange.getIn().setHeader("name", "Andrew"); + endSimpleMock.expectedMessageCount(1); + endSimpleMock.expectedBodiesReceived("Earth to Andrew. Come in, Andrew.\n"); + // Act + startSimpleProducerTemplate.send(exchange); + // Verify + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:startSimple") + .to("chunk:file_example?themeFolder=folderexample") + .to("mock:endSimple"); + } + }; + } +} + http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkLetterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkLetterTest.java b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkLetterTest.java new file mode 100644 index 0000000..eae104d --- /dev/null +++ b/components/camel-chunk/src/test/java/org/apache/camel/component/chunk/ChunkLetterTest.java @@ -0,0 +1,64 @@ +/** + * 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.camel.component.chunk; + +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.junit.Test; + +/** + * Unit test for wiki documentation (same as Mustache component) + */ +public class ChunkLetterTest extends CamelTestSupport { + + private Exchange createLetter() { + Exchange exchange = context.getEndpoint("direct:a").createExchange(); + + Message msg = exchange.getIn(); + msg.setHeader("firstName", "Claus"); + msg.setHeader("lastName", "Ibsen"); + msg.setHeader("item", "Camel in Action"); + msg.setBody("PS: Next beer is on me, James"); + + return exchange; + } + + @Test + public void testChunkLetter() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(1); + mock.expectedBodiesReceived("Dear Ibsen, Claus\n\nThanks for the order of Camel in Action." + + "\n\nRegards Camel Riders Bookstore\nPS: Next beer is on me, James\n"); + + template.send("direct:a", createLetter()); + + mock.assertIsSatisfied(); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("direct:a") + .to("chunk:letter") + .to("mock:result"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/folderexample/file_example.chtml ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/folderexample/file_example.chtml b/components/camel-chunk/src/test/resources/folderexample/file_example.chtml new file mode 100644 index 0000000..fbc5edb --- /dev/null +++ b/components/camel-chunk/src/test/resources/folderexample/file_example.chtml @@ -0,0 +1 @@ +Earth to {$headers.name}. Come in, {$headers.name}. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/folderexample/subfolderexample/diff_template.chtml ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/folderexample/subfolderexample/diff_template.chtml b/components/camel-chunk/src/test/resources/folderexample/subfolderexample/diff_template.chtml new file mode 100644 index 0000000..f2f9826 --- /dev/null +++ b/components/camel-chunk/src/test/resources/folderexample/subfolderexample/diff_template.chtml @@ -0,0 +1,10 @@ +{#example_1} +<div> +Earth to {$headers.name}. Come in, {$headers.name}. +</div> +{#} +{#example_2} +<div> +Mars to {$headers.name}. Come in, {$headers.name}. This is the body: {$body} +</div> +{#} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/folderexample/subfolderexample/subfile_example.chtml ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/folderexample/subfolderexample/subfile_example.chtml b/components/camel-chunk/src/test/resources/folderexample/subfolderexample/subfile_example.chtml new file mode 100644 index 0000000..fbc5edb --- /dev/null +++ b/components/camel-chunk/src/test/resources/folderexample/subfolderexample/subfile_example.chtml @@ -0,0 +1 @@ +Earth to {$headers.name}. Come in, {$headers.name}. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/folderexample/subfolderexample/subfile_example.file ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/folderexample/subfolderexample/subfile_example.file b/components/camel-chunk/src/test/resources/folderexample/subfolderexample/subfile_example.file new file mode 100644 index 0000000..fbc5edb --- /dev/null +++ b/components/camel-chunk/src/test/resources/folderexample/subfolderexample/subfile_example.file @@ -0,0 +1 @@ +Earth to {$headers.name}. Come in, {$headers.name}. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/log4j.properties b/components/camel-chunk/src/test/resources/log4j.properties new file mode 100644 index 0000000..3b1bd38 --- /dev/null +++ b/components/camel-chunk/src/test/resources/log4j.properties @@ -0,0 +1,14 @@ +# +# The logging properties used +# +log4j.rootLogger=INFO, out + +# uncomment the following line to turn on Camel debugging +#log4j.logger.org.apache.camel=DEBUG + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/themes/example.chtml ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/themes/example.chtml b/components/camel-chunk/src/test/resources/themes/example.chtml new file mode 100644 index 0000000..f2f9826 --- /dev/null +++ b/components/camel-chunk/src/test/resources/themes/example.chtml @@ -0,0 +1,10 @@ +{#example_1} +<div> +Earth to {$headers.name}. Come in, {$headers.name}. +</div> +{#} +{#example_2} +<div> +Mars to {$headers.name}. Come in, {$headers.name}. This is the body: {$body} +</div> +{#} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/themes/file.chtml ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/themes/file.chtml b/components/camel-chunk/src/test/resources/themes/file.chtml new file mode 100644 index 0000000..fbc5edb --- /dev/null +++ b/components/camel-chunk/src/test/resources/themes/file.chtml @@ -0,0 +1 @@ +Earth to {$headers.name}. Come in, {$headers.name}. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/themes/file_nested.chtml ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/themes/file_nested.chtml b/components/camel-chunk/src/test/resources/themes/file_nested.chtml new file mode 100644 index 0000000..361f35b --- /dev/null +++ b/components/camel-chunk/src/test/resources/themes/file_nested.chtml @@ -0,0 +1,2 @@ +This is the body {$body} and the result {$headers.result} +{% include file %} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/themes/hello.chtml ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/themes/hello.chtml b/components/camel-chunk/src/test/resources/themes/hello.chtml new file mode 100644 index 0000000..fbc5edb --- /dev/null +++ b/components/camel-chunk/src/test/resources/themes/hello.chtml @@ -0,0 +1 @@ +Earth to {$headers.name}. Come in, {$headers.name}. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/themes/letter.chtml ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/themes/letter.chtml b/components/camel-chunk/src/test/resources/themes/letter.chtml new file mode 100644 index 0000000..1135882 --- /dev/null +++ b/components/camel-chunk/src/test/resources/themes/letter.chtml @@ -0,0 +1,6 @@ +Dear {$headers.lastName}, {$headers.firstName} + +Thanks for the order of {$headers.item}. + +Regards Camel Riders Bookstore +{$body} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/themes/nested.chtml ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/themes/nested.chtml b/components/camel-chunk/src/test/resources/themes/nested.chtml new file mode 100644 index 0000000..508e10a --- /dev/null +++ b/components/camel-chunk/src/test/resources/themes/nested.chtml @@ -0,0 +1 @@ +This is the body {$body} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/themes/subfolder/theme1.chtml ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/themes/subfolder/theme1.chtml b/components/camel-chunk/src/test/resources/themes/subfolder/theme1.chtml new file mode 100644 index 0000000..c0dc206 --- /dev/null +++ b/components/camel-chunk/src/test/resources/themes/subfolder/theme1.chtml @@ -0,0 +1 @@ +This the result of last call to chunk {$body} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/camel-chunk/src/test/resources/themes/subfolder/theme2.chtml ---------------------------------------------------------------------- diff --git a/components/camel-chunk/src/test/resources/themes/subfolder/theme2.chtml b/components/camel-chunk/src/test/resources/themes/subfolder/theme2.chtml new file mode 100644 index 0000000..508e10a --- /dev/null +++ b/components/camel-chunk/src/test/resources/themes/subfolder/theme2.chtml @@ -0,0 +1 @@ +This is the body {$body} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index 5a98fa3..6fba7c9 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -73,6 +73,7 @@ <module>camel-cache</module> <module>camel-castor</module> <module>camel-cdi</module> + <module>camel-chunk</module> <module>camel-cmis</module> <module>camel-cometd</module> <module>camel-context</module> http://git-wip-us.apache.org/repos/asf/camel/blob/7cf04221/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 0098b24..9fdafb1 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -79,6 +79,7 @@ <cdi-api-version>1.2</cdi-api-version> <cglib-bundle-version>2.1_3_7</cglib-bundle-version> <cglib-version>2.2</cglib-version> + <chunk-templates-version>2.5</chunk-templates-version> <classmate-version>1.0.0</classmate-version> <cmis-version>0.8.0</cmis-version> <cometd-bayeux-version>6.1.11</cometd-bayeux-version> @@ -100,7 +101,7 @@ <commons-digester-version>2.1</commons-digester-version> <commons-exec-version>1.3</commons-exec-version> <commons-httpclient-bundle-version>3.1_7</commons-httpclient-bundle-version> - <commons-io-version>1.4</commons-io-version> + <commons-io-version>2.4</commons-io-version> <commons-jexl2-version>2.1.1</commons-jexl2-version> <commons-jxpath-version>1.3</commons-jxpath-version> <commons-lang-version>2.6</commons-lang-version>