From a61521f09c9ccc10cfa16fd03e810f9110cd43e6 Mon Sep 17 00:00:00 2001 From: cjmamo <823038+cjmamo@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:57:59 +0100 Subject: [PATCH] refactor!: remove deprecated SmooksComponent, SmooksProcessor, and SmooksDataFormat since these classes were migrated to the Apache Camel codebase (#253) Refs: https://github.com/smooks/smooks-camel-cartridge/issues/211 --- README.adoc | 10 +- .../camel/component/SmooksComponent.java | 77 ---- .../camel/component/SmooksEndpoint.java | 84 ----- .../camel/converters/SinkConverter.java | 156 --------- .../camel/converters/SourceConverter.java | 114 ------ .../camel/dataformat/SmooksDataFormat.java | 171 --------- .../camel/processor/SmooksProcessor.java | 330 ------------------ .../org/apache/camel/component/smooks | 1 - .../camel/component/SmooksComponentTest.java | 96 ----- .../camel/converters/CoordinateConverter.java | 76 ---- .../camel/converters/CustomerConverter.java | 83 ----- .../camel/converters/SinkConverterTest.java | 87 ----- .../camel/converters/SourceConverterTest.java | 80 ----- .../cartridges/camel/dataformat/Customer.java | 145 -------- .../dataformat/SmooksCSVDataFormatTest.java | 160 --------- .../dataformat/SmooksDataFormatTest.java | 167 --------- .../camel/processor/SmooksProcessorTest.java | 249 ------------- .../SmooksProcessor_BeanRouting_Test.java | 145 -------- ...mooksProcessor_CharacterEncoding_Test.java | 95 ----- ...ksProcessor_File_In_StringResult_Test.java | 89 ----- .../SmooksProcessor_JavaResult_Test.java | 140 -------- .../processor/SmooksProcessor_Null_Test.java | 77 ---- .../SmooksProcessor_StringResult_Test.java | 93 ----- .../gender/Gender.java | 2 +- .../gender/GenderTypeConverterFactory.java | 2 +- src/test/resources/EBCDIC-input-message | 1 - ....smooks.api.converter.TypeConverterFactory | 2 +- src/test/resources/bean_routing_01.xml | 65 ---- .../resources/csv-smooks-marshal-config.xml | 70 ---- .../resources/csv-smooks-unmarshal-config.xml | 57 --- src/test/resources/data/order.edi | 4 - src/test/resources/edi-mapping-model.dfdl.xsd | 61 ---- .../resources/edi-to-xml-smooks-config.xml | 60 ---- .../camel/dataformat/customer-expected.xml | 49 --- .../cartridges/camel/dataformat/customer.xml | 49 --- .../camel/dataformat/smooks-config.xml | 62 ---- src/test/resources/xml/expected-order.xml | 76 ---- 37 files changed, 8 insertions(+), 3277 deletions(-) delete mode 100644 src/main/java/org/smooks/cartridges/camel/component/SmooksComponent.java delete mode 100644 src/main/java/org/smooks/cartridges/camel/component/SmooksEndpoint.java delete mode 100644 src/main/java/org/smooks/cartridges/camel/converters/SinkConverter.java delete mode 100644 src/main/java/org/smooks/cartridges/camel/converters/SourceConverter.java delete mode 100644 src/main/java/org/smooks/cartridges/camel/dataformat/SmooksDataFormat.java delete mode 100644 src/main/java/org/smooks/cartridges/camel/processor/SmooksProcessor.java delete mode 100644 src/main/resources/META-INF/services/org/apache/camel/component/smooks delete mode 100644 src/test/java/org/smooks/cartridges/camel/component/SmooksComponentTest.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/converters/CoordinateConverter.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/converters/CustomerConverter.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/converters/SinkConverterTest.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/converters/SourceConverterTest.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/dataformat/Customer.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/dataformat/SmooksCSVDataFormatTest.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/dataformat/SmooksDataFormatTest.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessorTest.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_BeanRouting_Test.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_CharacterEncoding_Test.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_File_In_StringResult_Test.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_JavaResult_Test.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_Null_Test.java delete mode 100644 src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_StringResult_Test.java rename src/test/java/org/smooks/cartridges/camel/{dataformat => routing}/gender/Gender.java (97%) rename src/test/java/org/smooks/cartridges/camel/{dataformat => routing}/gender/GenderTypeConverterFactory.java (97%) delete mode 100644 src/test/resources/EBCDIC-input-message delete mode 100644 src/test/resources/bean_routing_01.xml delete mode 100644 src/test/resources/csv-smooks-marshal-config.xml delete mode 100644 src/test/resources/csv-smooks-unmarshal-config.xml delete mode 100644 src/test/resources/data/order.edi delete mode 100644 src/test/resources/edi-mapping-model.dfdl.xsd delete mode 100644 src/test/resources/edi-to-xml-smooks-config.xml delete mode 100644 src/test/resources/org/smooks/cartridges/camel/dataformat/customer-expected.xml delete mode 100644 src/test/resources/org/smooks/cartridges/camel/dataformat/customer.xml delete mode 100644 src/test/resources/org/smooks/cartridges/camel/dataformat/smooks-config.xml delete mode 100644 src/test/resources/xml/expected-order.xml diff --git a/README.adoc b/README.adoc index f5275f5..8cca48d 100644 --- a/README.adoc +++ b/README.adoc @@ -46,7 +46,7 @@ Using Smooks in Camel can be done in three ways: === SmooksComponent -WARNING: SmooksComponent is deprecated and superseded by the https://camel.apache.org/components/next/smooks-component.html[Camel Smooks Component]. +WARNING: SmooksComponent is removed in v4 of the cartridge and superseded by the https://camel.apache.org/components/next/smooks-component.html[Camel Smooks Component]. The `+SmooksComponent+` is a Camel https://camel.apache.org/component.html[Component] which can used when you want to process the Camel Message Body using Smooks. You can do this by adding a route in your Camel route configuration: @@ -69,7 +69,7 @@ An Apache Component can take options that are specified after the Smooks configu === SmooksDataFormat -WARNING: SmooksDataFormat is deprecated and superseded by the https://camel.apache.org/components/next/dataformats/smooks-dataformat.html[Camel Smooks Data Format]. +WARNING: SmooksDataFormat is removed in v4 of the cartridge and superseded by the https://camel.apache.org/components/next/dataformats/smooks-dataformat.html[Camel Smooks Data Format]. `+SmooksDataFormat+` is a Camel DataFormat which is capable of transforming from one data format to another and back again. You would use this when you are only interested in transforming from one format to another and not interested in other Smooks features. @@ -86,7 +86,7 @@ from("direct:unmarshal") === SmooksProcessor -WARNING: SmooksProcessor is deprecated and superseded by the https://camel.apache.org/components/next/smooks-component.html[Camel Smooks Component]. +WARNING: SmooksProcessor is removed in v4 of the cartridge and superseded by the https://camel.apache.org/components/next/smooks-component.html[Camel Smooks Component]. Using `+SmooksProcessor+` gives you full control over Smooks, for example if you want to programmatically create the underlying Smooks instance you’d use `+SmooksProcessor+`. When using `+SmooksProcessor+`, you can pass a Smooks instance to its constructor and prior to that programmatically configure Smooks. @@ -118,7 +118,7 @@ from("file://input?noop=true") .to("mock:result"); ---- -TIP: See the https://github.com/smooks/smooks-examples/tree/v2/camel[Apache Camel examples] in the examples page. +TIP: See the https://github.com/smooks/smooks-examples/tree/v4/camel[Apache Camel examples] in the examples page. == Maven Coordinates @@ -128,7 +128,7 @@ TIP: See the https://github.com/smooks/smooks-examples/tree/v2/camel[Apache Came org.smooks.cartridges smooks-camel-cartridge - 3.0.0 + 4.0.0 ---- // end::smooks-camel-cartridge[] diff --git a/src/main/java/org/smooks/cartridges/camel/component/SmooksComponent.java b/src/main/java/org/smooks/cartridges/camel/component/SmooksComponent.java deleted file mode 100644 index 80d39ac..0000000 --- a/src/main/java/org/smooks/cartridges/camel/component/SmooksComponent.java +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.component; - -import org.apache.camel.Endpoint; -import org.apache.camel.support.DefaultComponent; -import org.smooks.cartridges.camel.processor.SmooksProcessor; - -import java.util.Map; - -/** - * Smook Camel Component. - *

- *

- * Example usage: - * - *

- * from("direct:a").to("smooks://edi-to-xml-smooks-config.xml")
- * 
- * - * @author Christian Mueller - * @author Daniel Bevenius - */ -@Deprecated(forRemoval = true, since = "2.0.0") -public class SmooksComponent extends DefaultComponent { - protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { - SmooksProcessor smooksProcessor = new SmooksProcessor(remaining, getCamelContext()); - configureSmooksProcessor(smooksProcessor, uri, remaining, parameters); - return new SmooksEndpoint(uri, this, smooksProcessor); - } - - protected void configureSmooksProcessor(SmooksProcessor smooksProcessor, String uri, String remaining, - Map parameters) throws Exception { - setProperties(smooksProcessor, parameters); - } - -} diff --git a/src/main/java/org/smooks/cartridges/camel/component/SmooksEndpoint.java b/src/main/java/org/smooks/cartridges/camel/component/SmooksEndpoint.java deleted file mode 100644 index 2241b3b..0000000 --- a/src/main/java/org/smooks/cartridges/camel/component/SmooksEndpoint.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.component; - -import org.apache.camel.Component; -import org.apache.camel.Service; -import org.apache.camel.support.ProcessorEndpoint; -import org.smooks.api.SmooksException; -import org.smooks.cartridges.camel.processor.SmooksProcessor; - -/** - * SmooksEndpoint is a wrapper around a {@link SmooksProcessor} instance and - * adds lifecycle support by implementing Service. This enables a SmooksEndpoint - * to be stopped and started. - *

- * - * @author Daniel Bevenius - */ -@Deprecated(forRemoval = true, since = "2.0.0") -public class SmooksEndpoint extends ProcessorEndpoint implements Service { - private final SmooksProcessor smooksProcessor; - - public SmooksEndpoint(String endpointUri, Component component, SmooksProcessor processor) { - super(endpointUri, component, processor); - this.smooksProcessor = processor; - } - - public void start() { - try { - smooksProcessor.start(); - } catch (Exception e) { - throw new SmooksException(e.getMessage(), e); - } - } - - public void stop() { - try { - smooksProcessor.stop(); - } catch (Exception e) { - throw new SmooksException(e.getMessage(), e); - } - } - -} diff --git a/src/main/java/org/smooks/cartridges/camel/converters/SinkConverter.java b/src/main/java/org/smooks/cartridges/camel/converters/SinkConverter.java deleted file mode 100644 index 4e468ba..0000000 --- a/src/main/java/org/smooks/cartridges/camel/converters/SinkConverter.java +++ /dev/null @@ -1,156 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.converters; - -import org.apache.camel.Converter; -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.spi.TypeConverterRegistry; -import org.smooks.io.sink.DOMSink; -import org.smooks.io.sink.JavaSink; -import org.smooks.io.sink.StringSink; -import org.smooks.io.source.StringSource; -import org.w3c.dom.Node; - -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -/** - * ResultConverter converts from different {@link Result} types. - * - * @author Daniel Bevenius - */ -@Converter(generateLoader = true) -@Deprecated(forRemoval = true, since = "2.0.0") -public class SinkConverter { - public static final String SMOOKS_RESULT_KEY = "SmooksResultKeys"; - - private SinkConverter() { - } - - @Converter - public static Node toDocument(DOMSink domSink) { - return domSink.getNode(); - } - - @SuppressWarnings("rawtypes") - @Converter - public static List toList(JavaSink.ResultMap javaResult, Exchange exchange) { - String resultKey = (String) exchange.getProperty(SMOOKS_RESULT_KEY); - if (resultKey != null) { - return (List) getResultsFromJavaSink(javaResult, resultKey); - } else { - return (List) getSingleObjectFromJavaSink(javaResult); - } - } - - @SuppressWarnings("rawtypes") - @Converter - public static Integer toInteger(JavaSink.ResultMap result) { - return (Integer) getSingleObjectFromJavaSink(result); - } - - @SuppressWarnings("rawtypes") - @Converter - public static Double toDouble(JavaSink.ResultMap sink) { - return (Double) getSingleObjectFromJavaSink(sink); - } - - @Converter - public static String toString(StringSink sink) { - return sink.getResult(); - } - - - @SuppressWarnings("rawtypes") - public static Map toMap(JavaSink.ResultMap resultBeans, Exchange exchange) { - Message outMessage = exchange.getOut(); - outMessage.setBody(resultBeans); - - @SuppressWarnings("unchecked") - Set> entrySet = resultBeans.entrySet(); - for (Entry entry : entrySet) { - outMessage.setBody(entry.getValue(), entry.getValue().getClass()); - } - return resultBeans; - } - - @SuppressWarnings("rawtypes") - private static Object getResultsFromJavaSink(JavaSink.ResultMap resultMap, String resultKey) { - return resultMap.get(resultKey); - } - - private static Object getSingleObjectFromJavaSink(@SuppressWarnings("rawtypes") JavaSink.ResultMap resultMap) { - if (resultMap.size() == 1) { - return resultMap.values().iterator().next(); - } - return null; - } - - @Converter - public static StringSource toStringSource(StringSink stringSink) { - String result = stringSink.getResult(); - if (result != null) { - return new StringSource(result); - } - - return null; - } - - - @SuppressWarnings("rawtypes") - @Converter(fallback = true) - public static T convertTo(Class type, Exchange exchange, Object value, TypeConverterRegistry registry) { - if (value instanceof JavaSink.ResultMap) { - for (Object mapValue : ((Map) value).values()) { - if (type.isInstance(mapValue)) { - return type.cast(mapValue); - } - } - } - - return null; - } -} diff --git a/src/main/java/org/smooks/cartridges/camel/converters/SourceConverter.java b/src/main/java/org/smooks/cartridges/camel/converters/SourceConverter.java deleted file mode 100644 index fd18a5f..0000000 --- a/src/main/java/org/smooks/cartridges/camel/converters/SourceConverter.java +++ /dev/null @@ -1,114 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.converters; - -import org.apache.camel.Converter; -import org.apache.camel.component.file.GenericFile; -import org.smooks.api.SmooksException; -import org.smooks.api.io.Source; -import org.smooks.io.sink.JavaSink; -import org.smooks.io.source.JavaSource; -import org.smooks.io.source.JavaSourceWithoutEventStream; -import org.smooks.io.source.ReaderSource; -import org.smooks.io.source.StreamSource; -import org.smooks.io.source.StringSource; -import org.smooks.io.source.URLSource; - -import java.io.File; -import java.io.InputStream; -import java.io.Reader; -import java.net.MalformedURLException; -import java.net.URL; - -/** - * SourceConverter is a Camel {@link Converter} that converts from different - * formats to {@link Source} instances.

- * - * @author Daniel Bevenius - */ -@Converter(generateLoader = true) -@Deprecated(forRemoval = true, since = "2.0.0") -public class SourceConverter { - private SourceConverter() { - } - - @Converter - public static JavaSourceWithoutEventStream toJavaSourceWithoutEventStream(Object payload) { - return new JavaSourceWithoutEventStream(payload); - } - - @Converter - public static JavaSource toJavaSource(Object payload) { - return new JavaSource(payload); - } - - @Converter - public static Source toStreamSource(InputStream in) { - return new StreamSource<>(in); - } - - @Converter - public static Source toReaderSource(Reader reader) { - return new ReaderSource<>(reader); - } - - @Converter - public static JavaSource toJavaSource(JavaSink result) { - return new JavaSource(result.getResultMap().values()); - } - - @Converter - public static Source toStringSource(String string) { - return new StringSource(string); - } - - @Converter - public static Source toURISource(GenericFile genericFile) { - String systemId = new javax.xml.transform.stream.StreamSource((File) genericFile.getBody()).getSystemId(); - try { - return new URLSource(new URL(systemId)); - } catch (MalformedURLException e) { - throw new SmooksException(e); - } - } -} diff --git a/src/main/java/org/smooks/cartridges/camel/dataformat/SmooksDataFormat.java b/src/main/java/org/smooks/cartridges/camel/dataformat/SmooksDataFormat.java deleted file mode 100644 index af24a08..0000000 --- a/src/main/java/org/smooks/cartridges/camel/dataformat/SmooksDataFormat.java +++ /dev/null @@ -1,171 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.dataformat; - -import org.apache.camel.*; -import org.apache.camel.spi.DataFormat; -import org.apache.camel.support.processor.MarshalProcessor; -import org.apache.camel.support.processor.UnmarshalProcessor; -import org.smooks.Smooks; -import org.smooks.SmooksFactory; -import org.smooks.api.ExecutionContext; -import org.smooks.api.SmooksException; -import org.smooks.api.io.Sink; -import org.smooks.cartridges.camel.component.SmooksComponent; -import org.smooks.cartridges.camel.processor.SmooksProcessor; -import org.smooks.engine.lookup.ExportsLookup; -import org.smooks.io.payload.Exports; -import org.smooks.io.sink.StringSink; -import org.smooks.io.source.JavaSource; -import org.smooks.io.source.StreamSource; -import org.xml.sax.SAXException; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.List; - -/** - * SmooksDataFormat is a Camel data format which is a pluggable transformer - * capable of transforming from one dataformat to another and back again. - * This means that what is marshaled can be unmarshaled by an instance of this - * class. - *

- *

- * A smooks configuration for a SmooksDataFormat should not utilize Smooks - * features such as routing that might allocated system resources. The reason - * for this is that there is no functionality in the SmooksDataFormat which will - * close those resources. If you need to use these Smooks features please take a - * look at the {@link SmooksComponent} or {@link SmooksProcessor} as they hook - * into Camels lifecycle manegment and will close resources correctly. - *

- * - * @author Christian Mueller - * @author Daniel Bevenius - */ -@Deprecated(forRemoval = true, since = "3.0.0") -public class SmooksDataFormat implements DataFormat, CamelContextAware, Service { - private Smooks smooks; - private CamelContext camelContext; - private final String smooksConfig; - - public SmooksDataFormat(final String smooksConfig) throws Exception { - this.smooksConfig = smooksConfig; - } - - /** - * Marshals the Object 'fromBody' to an OutputStream 'toStream' - *

- *

- * The Camel framework will call this method from {@link MarshalProcessor#process(Exchange)} - * and it will take care of setting the Out Message's body to the bytes written to the toStream - * OutputStream. - * - * @param exchange The Camel {@link Exchange}. - * @param fromBody The object to be marshalled into the output stream. - * @param toStream The output stream that will be written to. - */ - public void marshal(final Exchange exchange, final Object fromBody, final OutputStream toStream) throws Exception { - final ExecutionContext execContext = smooks.createExecutionContext(); - final TypeConverter typeConverter = exchange.getContext().getTypeConverter(); - final JavaSource source = typeConverter.mandatoryConvertTo(JavaSource.class, exchange, fromBody); - final StringSink stringSink = new StringSink(); - smooks.filterSource(execContext, source, stringSink); - - toStream.write(stringSink.getResult().getBytes(execContext.getContentEncoding())); - } - - /** - * Unmarshals the fromStream to an Object. - *

- * The Camel framework will call this method from {@link UnmarshalProcessor#process(Exchange)} - * and it will take care of setting the returned Object on the Out Message's body. - * - * @param exchange The Camel {@link Exchange}. - * @param fromStream The InputStream that will be unmarshalled into an Object instance. - */ - public Object unmarshal(final Exchange exchange, final InputStream fromStream) { - final ExecutionContext execContext = smooks.createExecutionContext(); - final Exports exports = smooks.getApplicationContext().getRegistry().lookup(new ExportsLookup()); - final Sink[] sinks = exports.createSinks(); - smooks.filterSource(execContext, new StreamSource(fromStream), sinks); - return getResult(exports, sinks, exchange); - } - - protected Object getResult(final Exports exports, final Sink[] sinks, final Exchange exchange) { - final List objects = Exports.extractSinks(sinks, exports); - if (objects.size() == 1) { - return objects.get(0); - } else { - return objects; - } - } - - public void setCamelContext(CamelContext camelContext) { - this.camelContext = camelContext; - } - - public CamelContext getCamelContext() { - return camelContext; - } - - public void start() { - final SmooksFactory smooksFactory = (SmooksFactory) camelContext.getRegistry().lookupByName(SmooksFactory.class.getName()); - try { - if (smooksFactory != null) { - smooks = smooksFactory.createInstance(smooksConfig); - } else { - smooks = new Smooks(smooksConfig); - } - } catch (IOException | SAXException e) { - throw new SmooksException(e.getMessage(), e); - } - } - - public void stop() { - if (smooks != null) { - smooks.close(); - } - } - -} diff --git a/src/main/java/org/smooks/cartridges/camel/processor/SmooksProcessor.java b/src/main/java/org/smooks/cartridges/camel/processor/SmooksProcessor.java deleted file mode 100644 index d8c5a5e..0000000 --- a/src/main/java/org/smooks/cartridges/camel/processor/SmooksProcessor.java +++ /dev/null @@ -1,330 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.processor; - -import org.apache.camel.CamelContext; -import org.apache.camel.CamelContextAware; -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.camel.Service; -import org.apache.camel.WrappedFile; -import org.apache.camel.attachment.Attachment; -import org.apache.camel.attachment.AttachmentMessage; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.smooks.Smooks; -import org.smooks.SmooksFactory; -import org.smooks.api.ExecutionContext; -import org.smooks.api.SmooksException; -import org.smooks.api.TypedKey; -import org.smooks.api.delivery.VisitorAppender; -import org.smooks.api.io.Sink; -import org.smooks.api.io.Source; -import org.smooks.api.resource.visitor.Visitor; -import org.smooks.engine.lookup.ExportsLookup; -import org.smooks.engine.report.HtmlReportGenerator; -import org.smooks.io.payload.Exports; -import org.smooks.io.source.DOMSource; -import org.smooks.io.source.ReaderSource; -import org.smooks.io.source.StreamSource; -import org.smooks.io.source.URLSource; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; - -import javax.xml.transform.sax.SAXSource; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; - -/** - * Smooks {@link Processor} for Camel. - * - * @author Christian Mueller - * @author Daniel Bevenius - */ -@Deprecated(forRemoval = true, since = "2.0.0") -public class SmooksProcessor implements Processor, Service, CamelContextAware { - public static final String SMOOKS_EXECUTION_CONTEXT = "CamelSmooksExecutionContext"; - public static final String CAMEL_CHARACTER_ENCODING = "CamelCharsetName"; - private static final Logger LOGGER = LoggerFactory.getLogger(SmooksProcessor.class); - public static final TypedKey EXCHANGE_TYPED_KEY = TypedKey.of(); - - private Smooks smooks; - private String configUri; - private String reportPath; - - private Set visitorAppenders = new HashSet<>(); - private Map selectorVisitorMap = new HashMap<>(); - private CamelContext camelContext; - private boolean attachmentsSupported = false; - - public SmooksProcessor(final CamelContext camelContext) { - this.camelContext = camelContext; - } - - public SmooksProcessor(final Smooks smooks, final CamelContext camelContext) { - this(camelContext); - this.smooks = smooks; - } - - public SmooksProcessor(final String configUri, final CamelContext camelContext) throws IOException, SAXException { - this(camelContext); - this.configUri = configUri; - } - - public void process(final Exchange exchange) { - //forward headers - exchange.getMessage().setHeaders(exchange.getIn().getHeaders()); - - if (attachmentsSupported) { - //forward attachments - if (exchange.getIn(AttachmentMessage.class).hasAttachments()) { - for (Entry attachmentObject : exchange.getIn(AttachmentMessage.class).getAttachmentObjects().entrySet()) { - exchange.getMessage(AttachmentMessage.class).addAttachmentObject(attachmentObject.getKey(), attachmentObject.getValue()); - } - } - } - - final ExecutionContext executionContext = smooks.createExecutionContext(); - executionContext.put(EXCHANGE_TYPED_KEY, exchange); - String charsetName = (String) exchange.getProperty(CAMEL_CHARACTER_ENCODING); - if (charsetName != null) //if provided use the came character encoding - { - executionContext.setContentEncoding(charsetName); - } - exchange.getIn().setHeader(SMOOKS_EXECUTION_CONTEXT, executionContext); - setupSmooksReporting(executionContext); - - final Exports exports = smooks.getApplicationContext().getRegistry().lookup(new ExportsLookup()); - if (exports.hasExports()) { - final Sink[] sinks = exports.createSinks(); - smooks.filterSource(executionContext, getSource(exchange, executionContext), sinks); - setResultOnBody(exports, sinks, exchange); - } else { - smooks.filterSource(executionContext, getSource(exchange, executionContext)); - } - - executionContext.remove(EXCHANGE_TYPED_KEY); - } - - protected void setResultOnBody(final Exports exports, final Sink[] sinks, final Exchange exchange) { - final Message message = exchange.getMessage(); - final List objects = Exports.extractSinks(sinks, exports); - if (objects.size() == 1) { - Object value = objects.get(0); - message.setBody(value); - } else { - message.setBody(objects); - } - } - - private void setupSmooksReporting(final ExecutionContext executionContext) { - if (reportPath != null) { - try { - executionContext.getContentDeliveryRuntime().addExecutionEventListener(new HtmlReportGenerator(reportPath, executionContext.getApplicationContext())); - } catch (final IOException e) { - LOGGER.info("Could not generate Smooks Report. The reportPath specified was [" + reportPath + "].", e); - } - } - } - - private Source getSource(Exchange exchange, ExecutionContext executionContext) { - Object payload = exchange.getIn().getBody(); - - if (payload instanceof SAXSource) { - return new ReaderSource<>((Reader) ((SAXSource) payload).getXMLReader()); - } - - if (payload instanceof Source) { - return (Source) payload; - } - - if (payload instanceof Node) { - return new DOMSource((Node) payload); - } - - if (payload instanceof InputStream) { - return new StreamSource<>((InputStream) payload); - } - - if (payload instanceof Reader) { - return new ReaderSource<>((Reader) payload); - } - - if (payload instanceof WrappedFile) { - String systemId = new javax.xml.transform.stream.StreamSource((File) exchange.getIn().getBody(WrappedFile.class).getFile()).getSystemId(); - try { - return new URLSource(new URL(systemId)); - } catch (MalformedURLException e) { - throw new SmooksException(e); - } - } - - return exchange.getIn().getBody(Source.class); - } - - public String getSmooksConfig() { - return configUri; - } - - public void setSmooksConfig(String smooksConfig) { - this.configUri = smooksConfig; - } - - /** - * Add a visitor instance. - * - * @param visitor The visitor implementation. - * @param targetSelector The message fragment target selector. - * @return This instance. - */ - public SmooksProcessor addVisitor(Visitor visitor, String targetSelector) { - selectorVisitorMap.put(targetSelector, visitor); - return this; - } - - /** - * Add a visitor instance to this Smooks instance via a - * {@link VisitorAppender}. - * - * @param appender The visitor appender. - * @return This instance. - */ - public SmooksProcessor addVisitor(VisitorAppender appender) { - visitorAppenders.add(appender); - return this; - } - - public void setReportPath(String reportPath) { - this.reportPath = reportPath; - } - - @Override - public void start() { - try { - if (smooks == null) { - smooks = createSmooks(); - if (configUri != null) { - smooks.addResourceConfigs(configUri); - } - smooks.getApplicationContext().getRegistry().registerObject(CamelContext.class, camelContext); - } - - addAppenders(smooks, visitorAppenders); - addVisitors(smooks, selectorVisitorMap); - - InputStream inputStream = null; - try { - inputStream = camelContext.getClassResolver().loadResourceAsStream("META-INF/services/org/apache/camel/other.properties"); - if (inputStream != null) { - final Properties properties = new Properties(); - properties.load(inputStream); - if (properties.getProperty("name") != null && properties.getProperty("name").equals("attachments")) { - attachmentsSupported = true; - } - } - } finally { - if (!attachmentsSupported) { - LOGGER.warn("Attachments module could not be found: attachments will not be propagated"); - } - if (inputStream != null) { - inputStream.close(); - } - } - - LOGGER.info(this + " Started"); - } catch (SAXException | IOException e) { - throw new SmooksException(e.getMessage(), e); - } - } - - private Smooks createSmooks() { - final SmooksFactory smooksFactory = (SmooksFactory) camelContext.getRegistry().lookupByName(SmooksFactory.class.getName()); - return smooksFactory != null ? smooksFactory.createInstance() : new Smooks(); - } - - private void addAppenders(Smooks smooks, Set visitorAppenders) { - for (VisitorAppender appender : visitorAppenders) - smooks.addVisitors(appender); - } - - private void addVisitors(Smooks smooks, Map selectorVisitorMap) { - for (Entry entry : selectorVisitorMap.entrySet()) - smooks.addVisitor(entry.getValue(), entry.getKey()); - } - - public void stop() { - if (smooks != null) { - smooks.close(); - smooks = null; - } - LOGGER.info(this + " Stopped"); - } - - @Override - public String toString() { - return "SmooksProcessor [configUri=" + configUri + "]"; - } - - public void setCamelContext(CamelContext camelContext) { - this.camelContext = camelContext; - } - - public CamelContext getCamelContext() { - return camelContext; - } - -} \ No newline at end of file diff --git a/src/main/resources/META-INF/services/org/apache/camel/component/smooks b/src/main/resources/META-INF/services/org/apache/camel/component/smooks deleted file mode 100644 index d9940c8..0000000 --- a/src/main/resources/META-INF/services/org/apache/camel/component/smooks +++ /dev/null @@ -1 +0,0 @@ -class=org.smooks.cartridges.camel.component.SmooksComponent diff --git a/src/test/java/org/smooks/cartridges/camel/component/SmooksComponentTest.java b/src/test/java/org/smooks/cartridges/camel/component/SmooksComponentTest.java deleted file mode 100644 index fe3f790..0000000 --- a/src/test/java/org/smooks/cartridges/camel/component/SmooksComponentTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.component; - -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; -import org.smooks.support.StreamUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.xmlunit.builder.DiffBuilder; - -import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied; -import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; -import static org.junit.jupiter.api.Assertions.assertFalse; - -/** - * Unit test for {@link SmooksComponent}. - * - * @author Christian Mueller - * @author Daniel Bevenius - */ -public class SmooksComponentTest extends CamelTestSupport { - @EndpointInject(value = "mock:result") - private MockEndpoint mockEndpoint; - - @Test - public void unmarshalEDI() throws Exception { - mockEndpoint.expectedMessageCount(1); - assertIsSatisfied(mockEndpoint); - - Exchange exchange = mockEndpoint.assertExchangeReceived(0); - - assertIsInstanceOf(Document.class, exchange.getIn().getBody()); - assertFalse(DiffBuilder.compare(StreamUtils.readStreamAsString(getClass().getResourceAsStream("/xml/expected-order.xml"), "UTF-8")). - withTest(exchange.getIn().getBody(String.class)). - ignoreComments(). - ignoreWhitespace(). - build(). - hasDifferences()); - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() throws Exception { - from("file://src/test/resources/data?noop=true") - .to("smooks://edi-to-xml-smooks-config.xml") - .convertBodyTo(Node.class).to("mock:result"); - } - }; - } -} diff --git a/src/test/java/org/smooks/cartridges/camel/converters/CoordinateConverter.java b/src/test/java/org/smooks/cartridges/camel/converters/CoordinateConverter.java deleted file mode 100644 index 093b330..0000000 --- a/src/test/java/org/smooks/cartridges/camel/converters/CoordinateConverter.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.converters; - -import org.apache.camel.Converter; -import org.smooks.cartridges.camel.Coordinate; -import org.smooks.io.sink.JavaSink; - -import java.util.Map; - -/** - * Converts a JavaResult to a Coordinate object. - *

- * This converter is only intended for testing purposes. - * - * @author Daniel Bevenius - */ -@Converter(generateLoader = true) -public class CoordinateConverter { - private CoordinateConverter() { - } - - @Converter - public static Coordinate toCoordinate(JavaSink sink) { - Object singleObject = getSingleObjectFromJavaResult(sink); - return (Coordinate) singleObject; - } - - private static Object getSingleObjectFromJavaResult(JavaSink sink) { - Map resultMap = sink.getResultMap(); - if (resultMap.size() == 1) { - return resultMap.values().iterator().next(); - } - return null; - } -} diff --git a/src/test/java/org/smooks/cartridges/camel/converters/CustomerConverter.java b/src/test/java/org/smooks/cartridges/camel/converters/CustomerConverter.java deleted file mode 100644 index e07d950..0000000 --- a/src/test/java/org/smooks/cartridges/camel/converters/CustomerConverter.java +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.converters; - -import org.apache.camel.Converter; -import org.smooks.api.io.Source; -import org.smooks.cartridges.camel.dataformat.Customer; -import org.smooks.io.sink.JavaSink; -import org.smooks.io.source.JavaSource; - -import java.util.Map; - -/** - * Converts a JavaResult to a Customer object. - *

- * This converter is only intended for testing purposes. - * - * @author Daniel Bevenius - */ -@Converter(generateLoader = true) -public class CustomerConverter { - private CustomerConverter() { - } - - @Converter - public static Customer toCoordinate(JavaSink sink) { - Object singleObject = getSingleObjectFromJavaResult(sink); - return (Customer) singleObject; - } - - private static Object getSingleObjectFromJavaResult(JavaSink sink) { - Map resultMap = sink.getResultMap(); - if (resultMap.size() == 1) { - return resultMap.values().iterator().next(); - } - return null; - } - - @Converter - public static Source getSource(Customer customer) { - return new JavaSource(customer); - } -} diff --git a/src/test/java/org/smooks/cartridges/camel/converters/SinkConverterTest.java b/src/test/java/org/smooks/cartridges/camel/converters/SinkConverterTest.java deleted file mode 100644 index 1ae9d6d..0000000 --- a/src/test/java/org/smooks/cartridges/camel/converters/SinkConverterTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.converters; - -import java.io.BufferedReader; - -import org.apache.camel.CamelContext; -import org.apache.camel.TypeConverter; -import org.apache.camel.impl.DefaultCamelContext; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.smooks.io.sink.StringSink; -import org.smooks.io.source.ReaderSource; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * Unit test for {@link SinkConverter}. - * - * @author Daniel Bevenius - */ -public class SinkConverterTest { - private TypeConverter typeConverter; - - @BeforeEach - public void beforeEach() { - CamelContext camelContext = new DefaultCamelContext(); - typeConverter = camelContext.getTypeConverter(); - } - - @Test - public void convertStringSinkToReaderSource() throws Exception { - StringSink writerSink = createStringSink("Bajja"); - - ReaderSource streamSource = typeConverter.convertTo(ReaderSource.class, writerSink); - - BufferedReader reader = new BufferedReader(streamSource.getReader()); - assertEquals("Bajja", reader.readLine()); - } - - private StringSink createStringSink(final String string) { - StringSink writerSink = new StringSink(); - writerSink.getStringWriter().write(string); - return writerSink; - } - -} diff --git a/src/test/java/org/smooks/cartridges/camel/converters/SourceConverterTest.java b/src/test/java/org/smooks/cartridges/camel/converters/SourceConverterTest.java deleted file mode 100644 index 0be098a..0000000 --- a/src/test/java/org/smooks/cartridges/camel/converters/SourceConverterTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.converters; - -import org.apache.camel.CamelContext; -import org.apache.camel.TypeConverter; -import org.apache.camel.impl.DefaultCamelContext; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.smooks.io.source.JavaSourceWithoutEventStream; - -import java.util.Map; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -/** - * Unit test for {@link SourceConverter}.

- * - * @author Daniel Bevenius - */ -public class SourceConverterTest { - private TypeConverter typeConverter; - - @BeforeEach - public void beforeEach() { - CamelContext camelContext = new DefaultCamelContext(); - typeConverter = camelContext.getTypeConverter(); - } - - @Test - public void convertStringToJavaSourceWithoutEventStream() { - final String payload = "dummyPayload"; - final JavaSourceWithoutEventStream javaSource = typeConverter.convertTo(JavaSourceWithoutEventStream.class, payload); - final Map beans = javaSource.getBeans(); - final String actualPayload = (String) beans.get("string"); - - assertThat(payload, is(actualPayload)); - } -} diff --git a/src/test/java/org/smooks/cartridges/camel/dataformat/Customer.java b/src/test/java/org/smooks/cartridges/camel/dataformat/Customer.java deleted file mode 100644 index 791371a..0000000 --- a/src/test/java/org/smooks/cartridges/camel/dataformat/Customer.java +++ /dev/null @@ -1,145 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.dataformat; - -import org.smooks.cartridges.camel.dataformat.gender.Gender; - -public class Customer { - - private String firstName; - private String lastName; - private Gender gender; - private Integer age; - private String country; - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + age; - result = prime * result + ((country == null) ? 0 : country.hashCode()); - result = prime * result - + ((firstName == null) ? 0 : firstName.hashCode()); - result = prime * result + ((gender == null) ? 0 : gender.hashCode()); - result = prime * result - + ((lastName == null) ? 0 : lastName.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Customer other = (Customer) obj; - if (age != other.age) - return false; - if (country == null) { - if (other.country != null) - return false; - } else if (!country.equals(other.country)) - return false; - if (firstName == null) { - if (other.firstName != null) - return false; - } else if (!firstName.equals(other.firstName)) - return false; - if (gender != other.gender) - return false; - if (lastName == null) { - if (other.lastName != null) - return false; - } else if (!lastName.equals(other.lastName)) - return false; - return true; - } - - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public Gender getGender() { - return gender; - } - - public void setGender(Gender gender) { - this.gender = gender; - } - - public Integer getAge() { - return age; - } - - public void setAge(Integer age) { - this.age = age; - } - - public String toString() { - return "[" + firstName + ", " + lastName + ", " + gender + ", " + age + ", " + country + "]"; - } -} - diff --git a/src/test/java/org/smooks/cartridges/camel/dataformat/SmooksCSVDataFormatTest.java b/src/test/java/org/smooks/cartridges/camel/dataformat/SmooksCSVDataFormatTest.java deleted file mode 100644 index e81d183..0000000 --- a/src/test/java/org/smooks/cartridges/camel/dataformat/SmooksCSVDataFormatTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.dataformat; - - -import org.apache.camel.Endpoint; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.smooks.cartridges.camel.dataformat.gender.Gender; -import org.smooks.io.source.JavaSourceWithoutEventStream; - -import java.util.ArrayList; -import java.util.List; - -import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied; -import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * Smooks CSV DataFormat unit test. - */ -public class SmooksCSVDataFormatTest extends CamelTestSupport { - - private static Customer charlesExpected; - private static Customer chrisExpected; - - @EndpointInject(value = "direct:unmarshal") - private Endpoint unmarshal; - - @EndpointInject(value = "direct:marshal") - private Endpoint marshal; - - @EndpointInject(value = "mock:result") - private MockEndpoint result; - - @Test - public void unmarshalCSV() throws Exception { - result.expectedMessageCount(1); - - template.send(unmarshal, new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getIn().setBody("christian,mueller,Male,33,germany\n" + - "charles,moulliard,Male,43,belgium\n"); - } - }); - - assertIsSatisfied(); - Exchange exchange = result.assertExchangeReceived(0); - assertIsInstanceOf(List.class, exchange.getIn().getBody()); - @SuppressWarnings("rawtypes") - List customerList = exchange.getIn().getBody(List.class); - assertEquals(2, customerList.size()); - - Customer chrisActual = (Customer) customerList.get(0); - assertEquals(chrisActual, chrisActual); - - Customer charlesActual = (Customer) customerList.get(1); - assertEquals(charlesExpected, charlesActual); - } - - @Test - public void marshalCSV() throws Exception { - result.expectedMessageCount(1); - - final List customerList = new ArrayList(); - customerList.add(chrisExpected); - customerList.add(charlesExpected); - - template.send(marshal, new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getIn().setBody(customerList); - } - }); - - assertIsSatisfied(); - Exchange exchange = result.assertExchangeReceived(0); - assertEquals("christian,mueller,Male,33,germany\n" + - "charles,moulliard,Male,43,belgium\n", exchange.getIn().getBody(String.class)); - } - - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() throws Exception { - SmooksDataFormat csvUnmarshal = new SmooksDataFormat("csv-smooks-unmarshal-config.xml"); - - from("direct:unmarshal") - .unmarshal(csvUnmarshal).convertBodyTo(List.class) - .to("mock:result"); - - SmooksDataFormat csvMarshal = new SmooksDataFormat("csv-smooks-marshal-config.xml"); - from("direct:marshal").convertBodyTo(JavaSourceWithoutEventStream.class) - .marshal(csvMarshal) - .to("mock:result"); - } - }; - } - - @BeforeAll - public static void beforeAll() { - charlesExpected = new Customer(); - charlesExpected.setFirstName("charles"); - charlesExpected.setLastName("moulliard"); - charlesExpected.setAge(43); - charlesExpected.setGender(Gender.Male); - charlesExpected.setCountry("belgium"); - - chrisExpected = new Customer(); - chrisExpected.setFirstName("christian"); - chrisExpected.setLastName("mueller"); - chrisExpected.setAge(33); - chrisExpected.setGender(Gender.Male); - chrisExpected.setCountry("germany"); - } -} diff --git a/src/test/java/org/smooks/cartridges/camel/dataformat/SmooksDataFormatTest.java b/src/test/java/org/smooks/cartridges/camel/dataformat/SmooksDataFormatTest.java deleted file mode 100644 index 34d11cb..0000000 --- a/src/test/java/org/smooks/cartridges/camel/dataformat/SmooksDataFormatTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.dataformat; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.impl.DefaultCamelContext; -import org.apache.camel.support.DefaultExchange; -import org.apache.camel.support.processor.MarshalProcessor; -import org.apache.camel.support.processor.UnmarshalProcessor; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.smooks.cartridges.camel.dataformat.gender.Gender; -import org.smooks.io.source.JavaSource; -import org.smooks.support.StreamUtils; -import org.xmlunit.builder.DiffBuilder; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; - -/** - * Unit test for {@link SmooksDataFormat} - * - * @author Daniel Bevenius - */ -public class SmooksDataFormatTest extends CamelTestSupport { - private static final String SMOOKS_CONFIG = "/org/smooks/cartridges/camel/dataformat/smooks-config.xml"; - private static final String CUSTOMER_XML = "/org/smooks/cartridges/camel/dataformat/customer.xml"; - private static final String CUSTOMER_XML_EXPECTED = "/org/smooks/cartridges/camel/dataformat/customer-expected.xml"; - private DefaultCamelContext camelContext; - private SmooksDataFormat dataFormatter; - - @BeforeEach - public void beforeEach() throws Exception { - camelContext = new DefaultCamelContext(); - dataFormatter = new SmooksDataFormat(SMOOKS_CONFIG); - dataFormatter.setCamelContext(camelContext); - dataFormatter.start(); - } - - @AfterEach - public void afterEach() { - dataFormatter.stop(); - } - - @Override - public boolean isUseRouteBuilder() { - // each unit test include their own route builder - return false; - } - - @Test - public void unmarshal() throws Exception { - final UnmarshalProcessor unmarshalProcessor = new UnmarshalProcessor(dataFormatter); - final DefaultExchange exchange = new DefaultExchange(camelContext); - exchange.getIn().setBody(getCustomerInputStream(CUSTOMER_XML)); - - unmarshalProcessor.process(exchange); - - assertEquals(Customer.class, exchange.getOut().getBody().getClass()); - } - - @Test - public void marshal() throws Exception { - final MarshalProcessor marshalProcessor = new MarshalProcessor(dataFormatter); - final DefaultExchange exchange = new DefaultExchange(camelContext); - final Customer customer = new Customer(); - customer.setFirstName("John"); - customer.setLastName("Cocktolstol"); - customer.setGender(Gender.Male); - customer.setAge(35); - customer.setCountry("USA"); - - exchange.getIn().setBody(customer, JavaSource.class); - - marshalProcessor.process(exchange); - - assertFalse(DiffBuilder.compare(getCustomerXml(CUSTOMER_XML_EXPECTED)). - withTest(exchange.getOut().getBody(String.class)). - ignoreComments(). - ignoreWhitespace(). - build(). - hasDifferences()); - } - - @Test - public void unmarshalMarshalThroughCamel() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:a") - .unmarshal(dataFormatter) - .marshal(dataFormatter); - } - }); - - context.start(); - - final Exchange exchange = template.request("direct:a", new Processor() { - public void process(final Exchange exchange) throws Exception { - exchange.getIn().setBody(getCustomerInputStream(CUSTOMER_XML)); - } - }); - - assertFalse(DiffBuilder.compare(getCustomerXml(CUSTOMER_XML_EXPECTED)).withTest(exchange.getOut().getBody(String.class)). - ignoreComments(). - ignoreWhitespace(). - build(). - hasDifferences()); - } - - private InputStream getCustomerInputStream(final String resource) { - return getClass().getResourceAsStream(resource); - } - - private String getCustomerXml(final String resource) throws IOException { - return StreamUtils.readStream(new InputStreamReader(getCustomerInputStream(resource))); - } - -} diff --git a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessorTest.java b/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessorTest.java deleted file mode 100644 index 31621f5..0000000 --- a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessorTest.java +++ /dev/null @@ -1,249 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.processor; - -import jakarta.activation.DataHandler; -import jakarta.activation.DataSource; -import org.apache.camel.CamelExecutionException; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.attachment.AttachmentMessage; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.spi.ManagementAgent; -import org.apache.camel.support.DefaultExchange; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.smooks.support.StreamUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.xmlunit.builder.DiffBuilder; - -import javax.management.MBeanServer; -import javax.management.ObjectInstance; -import javax.management.ObjectName; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.util.Set; - -import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied; -import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * Unit test for {@link SmooksProcessor}. - * - * @author Christian Mueller - * @author Daniel Bevenius - */ -public class SmooksProcessorTest extends CamelTestSupport { - @EndpointInject(value = "mock:result") - private MockEndpoint result; - private MBeanServer mbeanServer; - - @BeforeEach - public void beforeEach() { - ManagementAgent managementAgent = context.getManagementStrategy().getManagementAgent(); - mbeanServer = managementAgent.getMBeanServer(); - } - - @Override - protected boolean useJmx() { - return true; - } - - @Test - public void process() throws Exception { - assertOneProcessedMessage(); - } - - private void assertOneProcessedMessage() throws Exception { - result.expectedMessageCount(1); - template.sendBody("direct://input", getOrderEdi()); - - assertIsSatisfied(); - - Exchange exchange = result.assertExchangeReceived(0); - assertIsInstanceOf(Document.class, exchange.getIn().getBody()); - assertFalse(DiffBuilder.compare(getExpectedOrderXml()).withTest(exchange.getIn().getBody(String.class)). - ignoreComments(). - ignoreWhitespace(). - build(). - hasDifferences()); - } - - @Test - public void processWithAttachment() throws CamelExecutionException, IOException { - final Exchange exchange = new DefaultExchange(context); - final String attachmentContent = "A dummy attachment"; - final String attachmentId = "testAttachment"; - addAttachment(attachmentContent, attachmentId, exchange); - exchange.getIn().setBody(getOrderEdi()); - - template.send("direct://input", exchange); - - final DataHandler datahandler = result.assertExchangeReceived(0).getIn(AttachmentMessage.class).getAttachment(attachmentId); - assertThat(datahandler, is(notNullValue())); - assertThat(datahandler.getContent(), is(instanceOf(ByteArrayInputStream.class))); - - final String actualAttachmentContent = getAttachmentContent(datahandler); - assertThat(actualAttachmentContent, is(equalTo(attachmentContent))); - } - - private void addAttachment(final String attachment, final String id, final Exchange exchange) { - final DataSource ds = new StringDataSource(attachment); - final DataHandler dataHandler = new DataHandler(ds); - exchange.getIn(AttachmentMessage.class).addAttachment(id, dataHandler); - } - - private String getAttachmentContent(final DataHandler datahandler) throws IOException { - final ByteArrayInputStream bs = (ByteArrayInputStream) datahandler.getContent(); - return new String(StreamUtils.readStream(bs)); - } - - @Test - public void assertSmooksReportWasCreated() throws Exception { - assertOneProcessedMessage(); - - File report = new File("target/smooks-report.html"); - report.deleteOnExit(); - assertTrue(report.exists(), "Smooks report was not generated."); - } - - @Test - @Disabled - public void stopStartContext() throws Exception { - ObjectInstance smooksProcessorMBean = getSmooksProcessorObjectInstance(); - - assertOneProcessedMessage(); - stopSmooksProcessor(smooksProcessorMBean.getObjectName()); - Thread.sleep(500); - - startSmooksProcessor(smooksProcessorMBean.getObjectName()); - Thread.sleep(500); - - assertOneProcessedMessage(); - } - - private void stopSmooksProcessor(ObjectName objectName) throws Exception { - invokeVoidNoArgsMethod(objectName, "stop"); - } - - private void invokeVoidNoArgsMethod(ObjectName objectName, String methodName) throws Exception { - mbeanServer.invoke(objectName, methodName, null, null); - } - - private void startSmooksProcessor(ObjectName objectName) throws Exception { - invokeVoidNoArgsMethod(objectName, "start"); - } - - private ObjectInstance getSmooksProcessorObjectInstance() throws Exception { - ObjectInstance mbean = null; - Set queryMBeans = mbeanServer.queryMBeans(new ObjectName("*:*,type=processors"), null); - for (ObjectInstance objectInstance : queryMBeans) { - if (objectInstance.getObjectName().toString().contains(SmooksProcessor.class.getSimpleName())) { - mbean = objectInstance; - } - } - assertNotNull(mbean); - return mbean; - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - SmooksProcessor processor = new SmooksProcessor("edi-to-xml-smooks-config.xml", context); - processor.setReportPath("target/smooks-report.html"); - - from("direct:input").process(processor).convertBodyTo(Node.class).to("mock:result"); - } - }; - } - - private String getExpectedOrderXml() throws IOException { - return StreamUtils.readStream(new InputStreamReader(getClass().getResourceAsStream("/xml/expected-order.xml"))); - } - - private String getOrderEdi() throws IOException { - return StreamUtils.readStream(new InputStreamReader(getClass().getResourceAsStream("/data/order.edi"))); - } - - private static class StringDataSource implements DataSource { - private final String string; - - private StringDataSource(final String string) { - this.string = string; - - } - - public String getContentType() { - return "text/plain"; - } - - public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream(string.getBytes()); - } - - public String getName() { - return "StringDataSource"; - } - - public OutputStream getOutputStream() throws IOException { - throw new IOException("Method 'getOutputStream' is not implmeneted"); - } - - } -} diff --git a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_BeanRouting_Test.java b/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_BeanRouting_Test.java deleted file mode 100644 index 168cc9f..0000000 --- a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_BeanRouting_Test.java +++ /dev/null @@ -1,145 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.processor; - -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.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; -import org.smooks.Smooks; -import org.smooks.cartridges.camel.Coordinate; -import org.smooks.cartridges.camel.routing.BeanRouter; -import org.smooks.cartridges.javabean.Bean; -import org.smooks.io.source.StringSource; - -import java.util.ArrayList; -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasItems; - -/** - * Functional test for {@link SmooksProcessor} which test bean routing configured - * via Smooks XML and Smooks programmatic configuration. - *

- * - * @author tom.fennelly@gmail.com - * @author daniel.bevenius@gmail.com - */ -public class SmooksProcessor_BeanRouting_Test extends CamelTestSupport { - - private static final String CORRELATION_ID = "correlationId"; - - @Test - public void processSmooksProgrammaticConfigure() throws Exception { - final String fromEndpoint = "direct:a"; - final String toEndpoint = "mock:to"; - context.addRoutes(new RouteBuilder() { - public void configure() { - Smooks smooks = new Smooks(); - final SmooksProcessor smooksProcessor = new SmooksProcessor(smooks, context); - - // Smooks JavaBean programmatic configuration - final String beanId = "coordinate"; - final String selector = "coords/coord"; - final Bean bean = new Bean(Coordinate.class, beanId, selector, smooks.getApplicationContext().getRegistry()); - bean.bindTo("x", "coords/coord/@x").bindTo("y", "coords/coord/@y"); - smooksProcessor.addVisitor(bean); - - // Smooks Camel BeanRouter programmatic configuration - final BeanRouter camelBeanRouter = new BeanRouter(context); - camelBeanRouter.setBeanId(beanId).setToEndpoint(toEndpoint) - .setCorrelationIdName(CORRELATION_ID).setCorrelationIdPattern("${PUUID.execContext}"); - smooksProcessor.addVisitor(camelBeanRouter, selector); - - from(fromEndpoint).process(smooksProcessor); - } - }); - context.start(); - sendBody(fromEndpoint, new StringSource("")); - - final List bodies = getBodies(getMockEndpoint(toEndpoint).getExchanges()); - assertThat(bodies, hasItems(new Coordinate(1, 2), new Coordinate(3, 4))); - } - - @Test - public void processSmooksXmlConfigured() throws Exception { - final String fromEndpoint = "direct:a2"; - context.addRoutes(new RouteBuilder() { - @Override - public void configure() { - from(fromEndpoint).to("smooks://bean_routing_01.xml"); - } - }); - context.start(); - sendBody(fromEndpoint, new StringSource("")); - - final Message messageB = getExchange(getMockEndpoint("mock:b")); - assertThat((Coordinate) messageB.getBody(), equalTo(new Coordinate(1, 2))); - - final Message messageC = getExchange(getMockEndpoint("mock:c")); - assertThat((Coordinate) messageC.getBody(), equalTo(new Coordinate(300, 400))); - assertThat(messageB.getHeader(CORRELATION_ID), equalTo(messageC.getHeader(CORRELATION_ID))); - } - - private Message getExchange(final MockEndpoint mockEndpoint) { - return mockEndpoint.getExchanges().get(0).getIn(); - } - - private List getBodies(final List exchanges) { - List bodies = new ArrayList<>(); - for (Exchange exchange : exchanges) { - bodies.add((Coordinate) exchange.getIn().getBody()); - } - return bodies; - } - - @Override - public boolean isUseRouteBuilder() { - return false; - } - -} diff --git a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_CharacterEncoding_Test.java b/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_CharacterEncoding_Test.java deleted file mode 100644 index f1a70ba..0000000 --- a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_CharacterEncoding_Test.java +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.processor; - -import java.io.InputStream; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; -import org.smooks.Smooks; -import org.smooks.cartridges.javabean.Value; -import org.smooks.io.payload.Exports; -import org.smooks.io.sink.JavaSink; -import org.smooks.io.source.StreamSource; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author sorin7486@gmail.com - */ -public class SmooksProcessor_CharacterEncoding_Test extends CamelTestSupport { - - @Override - public boolean isUseRouteBuilder() { - // each unit test include their own route builder - return false; - } - - @Test - public void test_single_value() throws Exception { - - context.addRoutes(new RouteBuilder() { - @Override - public void configure() { - Smooks smooks = new Smooks().setExports(new Exports(JavaSink.class)); - from("direct:a") - .process(new SmooksProcessor(smooks, context) - .addVisitor(new Value("customer", "/order/header/customer", String.class, smooks.getApplicationContext().getRegistry()))); - } - - }); - enableJMX(); - context.start(); - Exchange response = template.request("direct:a", new Processor() { - public void process(Exchange exchange) { - InputStream in = this.getClass().getResourceAsStream("/EBCDIC-input-message"); - exchange.getIn().setBody(new StreamSource<>(in)); - exchange.setProperty("CamelCharsetName", "Cp1047"); - } - }); - assertEquals("Joe", response.getMessage().getBody(String.class)); - } -} diff --git a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_File_In_StringResult_Test.java b/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_File_In_StringResult_Test.java deleted file mode 100644 index 3779dd5..0000000 --- a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_File_In_StringResult_Test.java +++ /dev/null @@ -1,89 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.processor; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; -import org.smooks.Smooks; -import org.smooks.io.payload.Exports; -import org.smooks.io.sink.StringSink; - -import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied; -import static org.apache.camel.test.junit5.TestSupport.deleteDirectory; -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author tom.fennelly@gmail.com - */ -public class SmooksProcessor_File_In_StringResult_Test extends CamelTestSupport { - - @Test - public void test() throws Exception { - deleteDirectory("target/smooks"); - template.sendBody("file://target/smooks", ""); - - MockEndpoint mockEndpoint = getMockEndpoint("mock:a"); - mockEndpoint.expectedMessageCount(1); - - assertIsSatisfied(mockEndpoint); - - assertEquals("", mockEndpoint.getExchanges().get(0).getIn().getBody(String.class)); - } - - /* (non-Javadoc) - * @see org.apache.camel.test.junit4.CamelTestSupport#createRouteBuilder() - */ - @Override - protected RouteBuilder createRouteBuilder() { - - return new RouteBuilder() { - public void configure() { - from("file://target/smooks"). - process(new SmooksProcessor(new Smooks().setExports(new Exports(StringSink.class)), context)). - to("mock:a"); - } - }; - } -} diff --git a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_JavaResult_Test.java b/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_JavaResult_Test.java deleted file mode 100644 index e596f05..0000000 --- a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_JavaResult_Test.java +++ /dev/null @@ -1,140 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.processor; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; -import org.smooks.Smooks; -import org.smooks.cartridges.javabean.Bean; -import org.smooks.cartridges.javabean.Value; -import org.smooks.io.payload.Exports; -import org.smooks.cartridges.camel.Coordinate; -import org.smooks.io.sink.JavaSink; -import org.smooks.io.source.StringSource; - -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author tom.fennelly@gmail.com - */ -public class SmooksProcessor_JavaResult_Test extends CamelTestSupport { - - @Override - public boolean isUseRouteBuilder() { - // each unit test include their own route builder - return false; - } - - @Test - public void test_single_value() throws Exception { - Smooks smooks = new Smooks().setExports(new Exports(JavaSink.class)); - context.addRoutes(new RouteBuilder() { - @Override - public void configure() { - from("direct:a") - .process(new SmooksProcessor(smooks, context) - .addVisitor(new Value("x", "/coord/@x", Integer.class, smooks.getApplicationContext().getRegistry()))); - } - - }); - enableJMX(); - context.start(); - Exchange response = template.request("direct:a", exchange -> exchange.getIn().setBody(new StringSource(""))); - assertEquals(1234, response.getMessage().getBody(Integer.class)); - } - - @Test - public void test_multi_value() throws Exception { - Smooks smooks = new Smooks().setExports(new Exports(JavaSink.class)); - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:b").process(new SmooksProcessor(smooks, context). - addVisitor(new Value("x", "/coord/@x", Integer.class, smooks.getApplicationContext().getRegistry())). - addVisitor(new Value("y", "/coord/@y", Double.class, smooks.getApplicationContext().getRegistry()))); - } - }); - context.start(); - Exchange response = template.request("direct:b", new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getIn().setBody(new StringSource("")); - } - }); - Map javaResult = response.getOut().getBody(Map.class); - Integer x = (Integer) javaResult.get("x"); - assertEquals(1234, (int) x); - Double y = (Double) javaResult.get("y"); - assertEquals(98765.76D, (double) y, 0.01D); - } - - @Test - public void test_bean() throws Exception { - Smooks smooks = new Smooks().setExports(new Exports(JavaSink.class)); - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:c").process(new SmooksProcessor(smooks, context). - addVisitor(new Bean(Coordinate.class, "coordinate", smooks.getApplicationContext().getRegistry()). - bindTo("x", "/coord/@x"). - bindTo("y", "/coord/@y"))); - } - }); - context.start(); - Exchange response = template.request("direct:c", new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getIn().setBody(new StringSource("")); - } - }); - - Coordinate coord = response.getMessage().getBody(Coordinate.class); - - assertEquals((Integer) 111, coord.getX()); - assertEquals((Integer) 222, coord.getY()); - } - -} diff --git a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_Null_Test.java b/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_Null_Test.java deleted file mode 100644 index cbd3c2f..0000000 --- a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_Null_Test.java +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.processor; - -import org.apache.camel.Exchange; -import org.apache.camel.ExchangePattern; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; -import org.smooks.Smooks; -import org.smooks.io.source.StringSource; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author tom.fennelly@gmail.com - */ -public class SmooksProcessor_Null_Test extends CamelTestSupport { - - @Test - public void test() throws Exception { - Exchange response = template.send("direct:blah", ExchangePattern.InOut, exchange -> exchange.getIn().setBody(new StringSource(""))); - assertEquals("", response.getMessage().getBody(String.class)); - } - - /* (non-Javadoc) - * @see org.apache.camel.test.junit4.CamelTestSupport#createRouteBuilder() - */ - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() { - from("direct:blah").process(new SmooksProcessor(new Smooks(), context)); - } - }; - } -} diff --git a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_StringResult_Test.java b/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_StringResult_Test.java deleted file mode 100644 index b7b0cae..0000000 --- a/src/test/java/org/smooks/cartridges/camel/processor/SmooksProcessor_StringResult_Test.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * smooks-camel-cartridge - * %% - * Copyright (C) 2020 Smooks - * %% - * Licensed under the terms of the Apache License Version 2.0, or - * the GNU Lesser General Public License version 3.0 or later. - * - * SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later - * - * ====================================================================== - * - * 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. - * - * ====================================================================== - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * =========================LICENSE_END================================== - */ -package org.smooks.cartridges.camel.processor; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; -import org.smooks.Smooks; -import org.smooks.io.payload.Exports; -import org.smooks.io.sink.StringSink; -import org.smooks.io.source.StringSource; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * @author tom.fennelly@gmail.com - */ -public class SmooksProcessor_StringResult_Test extends CamelTestSupport { - - @Test - public void test() throws Exception { - template.request("direct:a", exchange -> exchange.getIn().setBody(new StringSource(""))); - - assertEquals("", DirectBProcessor.inMessage); - } - - /* (non-Javadoc) - * @see org.apache.camel.test.junit4.CamelTestSupport#createRouteBuilder() - */ - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() { - from("direct:a") - .process(new SmooksProcessor(new Smooks().setExports(new Exports(StringSink.class)), context)) - .to("direct:b"); - - from("direct:b").convertBodyTo(String.class).process(new DirectBProcessor()); - } - }; - } - - private static class DirectBProcessor implements Processor { - - private static String inMessage; - - public void process(Exchange exchange) { - inMessage = (String) exchange.getIn().getBody(); - } - } -} diff --git a/src/test/java/org/smooks/cartridges/camel/dataformat/gender/Gender.java b/src/test/java/org/smooks/cartridges/camel/routing/gender/Gender.java similarity index 97% rename from src/test/java/org/smooks/cartridges/camel/dataformat/gender/Gender.java rename to src/test/java/org/smooks/cartridges/camel/routing/gender/Gender.java index 1fc81c6..88ecee7 100644 --- a/src/test/java/org/smooks/cartridges/camel/dataformat/gender/Gender.java +++ b/src/test/java/org/smooks/cartridges/camel/routing/gender/Gender.java @@ -40,7 +40,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * =========================LICENSE_END================================== */ -package org.smooks.cartridges.camel.dataformat.gender; +package org.smooks.cartridges.camel.routing.gender; public enum Gender { Male, diff --git a/src/test/java/org/smooks/cartridges/camel/dataformat/gender/GenderTypeConverterFactory.java b/src/test/java/org/smooks/cartridges/camel/routing/gender/GenderTypeConverterFactory.java similarity index 97% rename from src/test/java/org/smooks/cartridges/camel/dataformat/gender/GenderTypeConverterFactory.java rename to src/test/java/org/smooks/cartridges/camel/routing/gender/GenderTypeConverterFactory.java index df071a5..546131f 100644 --- a/src/test/java/org/smooks/cartridges/camel/dataformat/gender/GenderTypeConverterFactory.java +++ b/src/test/java/org/smooks/cartridges/camel/routing/gender/GenderTypeConverterFactory.java @@ -40,7 +40,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * =========================LICENSE_END================================== */ -package org.smooks.cartridges.camel.dataformat.gender; +package org.smooks.cartridges.camel.routing.gender; import org.smooks.api.converter.TypeConverter; import org.smooks.api.converter.TypeConverterDescriptor; diff --git a/src/test/resources/EBCDIC-input-message b/src/test/resources/EBCDIC-input-message deleted file mode 100644 index bd37c16..0000000 --- a/src/test/resources/EBCDIC-input-message +++ /dev/null @@ -1 +0,0 @@ -L–™„…™n@@@@Lˆ…„…™n@@@@@@@@L„£…nζ…„@Υ–₯@ρυ@ρσzτυzςψ@Εβγ@ςππφLa„£…n@@@@@@@@Lƒ€’£–”…™@•€”‚…™~ρςσρςσnΡ–…Laƒ€’£–”…™n@@@@Laˆ…„…™n@@@@L–™„…™`‰£…”’n@@@@@@@@L–™„…™`‰£…”n@@@@@@@@@@@@L—™–„€ƒ£nυLa—™–„€ƒ£n@@@@@@@@@@@@L˜€•£‰£¨nςLa˜€•£‰£¨n@@@@@@@@@@@@L—™‰ƒ…nψKωπLa—™‰ƒ…n@@@@@@@@La–™„…™`‰£…”n@@@@@@@@L–™„…™`‰£…”n@@@@@@@@@@@@L—™–„€ƒ£nυLa—™–„€ƒ£n@@@@@@@@@@@@L˜€•£‰£¨nχLa˜€•£‰£¨n@@@@@@@@@@@@L—™‰ƒ…nυKςπLa—™‰ƒ…n@@@@@@@@La–™„…™`‰£…”n@@@@La–™„…™`‰£…”’nLa–™„…™n \ No newline at end of file diff --git a/src/test/resources/META-INF/services/org.smooks.api.converter.TypeConverterFactory b/src/test/resources/META-INF/services/org.smooks.api.converter.TypeConverterFactory index f3f7e17..321b5e9 100644 --- a/src/test/resources/META-INF/services/org.smooks.api.converter.TypeConverterFactory +++ b/src/test/resources/META-INF/services/org.smooks.api.converter.TypeConverterFactory @@ -1 +1 @@ -org.smooks.cartridges.camel.dataformat.gender.GenderTypeConverterFactory \ No newline at end of file +org.smooks.cartridges.camel.routing.gender.GenderTypeConverterFactory \ No newline at end of file diff --git a/src/test/resources/bean_routing_01.xml b/src/test/resources/bean_routing_01.xml deleted file mode 100644 index 2fc73f7..0000000 --- a/src/test/resources/bean_routing_01.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/src/test/resources/csv-smooks-marshal-config.xml b/src/test/resources/csv-smooks-marshal-config.xml deleted file mode 100644 index fa53ff4..0000000 --- a/src/test/resources/csv-smooks-marshal-config.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/resources/csv-smooks-unmarshal-config.xml b/src/test/resources/csv-smooks-unmarshal-config.xml deleted file mode 100644 index c2d67e0..0000000 --- a/src/test/resources/csv-smooks-unmarshal-config.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - diff --git a/src/test/resources/data/order.edi b/src/test/resources/data/order.edi deleted file mode 100644 index 060c242..0000000 --- a/src/test/resources/data/order.edi +++ /dev/null @@ -1,4 +0,0 @@ -HDR*1*0*59.97*64.92*4.95*Wed Nov 15 13:45:28 EST 2006 -CUS*user1*Harry^Fletcher*SD -ORD*1*1*364*The 40-Year-Old Virgin*29.98 -ORD*2*1*299*Pulp Fiction*29.99 diff --git a/src/test/resources/edi-mapping-model.dfdl.xsd b/src/test/resources/edi-mapping-model.dfdl.xsd deleted file mode 100644 index 1a8c83d..0000000 --- a/src/test/resources/edi-mapping-model.dfdl.xsd +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/resources/edi-to-xml-smooks-config.xml b/src/test/resources/edi-to-xml-smooks-config.xml deleted file mode 100644 index 357baa0..0000000 --- a/src/test/resources/edi-to-xml-smooks-config.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/test/resources/org/smooks/cartridges/camel/dataformat/customer-expected.xml b/src/test/resources/org/smooks/cartridges/camel/dataformat/customer-expected.xml deleted file mode 100644 index 0b1962f..0000000 --- a/src/test/resources/org/smooks/cartridges/camel/dataformat/customer-expected.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - John - Cocktolstol - Male - 35 - USA - diff --git a/src/test/resources/org/smooks/cartridges/camel/dataformat/customer.xml b/src/test/resources/org/smooks/cartridges/camel/dataformat/customer.xml deleted file mode 100644 index 20b65b2..0000000 --- a/src/test/resources/org/smooks/cartridges/camel/dataformat/customer.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - John - Cocktolstol - Male - 35 - USA - diff --git a/src/test/resources/org/smooks/cartridges/camel/dataformat/smooks-config.xml b/src/test/resources/org/smooks/cartridges/camel/dataformat/smooks-config.xml deleted file mode 100644 index 12f6e4f..0000000 --- a/src/test/resources/org/smooks/cartridges/camel/dataformat/smooks-config.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/src/test/resources/xml/expected-order.xml b/src/test/resources/xml/expected-order.xml deleted file mode 100644 index e70d0fe..0000000 --- a/src/test/resources/xml/expected-order.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - -
- 1 - 0 - 59.97 - 64.92 - 4.95 - Wed Nov 15 13:45:28 EST 2006 -
- - user1 - - Harry - Fletcher - - SD - - - 1 - 1 - 364 - The 40-Year-Old Virgin - 29.98 - - - 2 - 1 - 299 - Pulp Fiction - 29.99 - -