This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit fcd852ac89288b292cfd4e50715a16f31d1cc842
Author: Craig Ziesman <[email protected]>
AuthorDate: Thu Sep 7 13:35:13 2023 -0500

    Working on unit tests
---
 .../component/thymeleaf/ThymeleafEndpoint.java     |   5 +
 .../thymeleaf/ThymeleafAbstractBaseTest.java       |  18 ++--
 .../thymeleaf/ThymeleafBodyAsDomainObjectTest.java |  10 +-
 .../thymeleaf/ThymeleafComponentTest.java          | 101 +++++++++++----------
 .../thymeleaf/ThymeleafConcurrentTest.java         |   6 +-
 .../thymeleaf/ThymeleafContentCacheTest.java       |  13 ++-
 ...ymeleafWebApplicationResolverAllParamsTest.java |   9 +-
 .../ThymeleafWebApplicationResolverTest.java       |   7 +-
 8 files changed, 87 insertions(+), 82 deletions(-)

diff --git 
a/components/camel-thymeleaf/src/main/java/org/apache/camel/component/thymeleaf/ThymeleafEndpoint.java
 
b/components/camel-thymeleaf/src/main/java/org/apache/camel/component/thymeleaf/ThymeleafEndpoint.java
index f68a9d67a74..833e956e03b 100644
--- 
a/components/camel-thymeleaf/src/main/java/org/apache/camel/component/thymeleaf/ThymeleafEndpoint.java
+++ 
b/components/camel-thymeleaf/src/main/java/org/apache/camel/component/thymeleaf/ThymeleafEndpoint.java
@@ -330,6 +330,11 @@ public class ThymeleafEndpoint extends ResourceEndpoint {
         this.jakartaServletWebApplication = jakartaServletWebApplication;
     }
 
+    public void setTemplate(String template) {
+
+        this.template = template;
+    }
+
     @Override
     public void clearContentCache() {
 
diff --git 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafAbstractBaseTest.java
 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafAbstractBaseTest.java
index 525a949a8a7..f80064448a9 100644
--- 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafAbstractBaseTest.java
+++ 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafAbstractBaseTest.java
@@ -16,14 +16,14 @@
  */
 package org.apache.camel.component.thymeleaf;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.test.junit5.CamelTestSupport;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import static java.util.Map.entry;
 
 public abstract class ThymeleafAbstractBaseTest extends CamelTestSupport {
@@ -147,12 +147,12 @@ public abstract class ThymeleafAbstractBaseTest extends 
CamelTestSupport {
     protected String expected() {
 
         return "\n\n" +
-               "Dear Doe, Jane\n" +
-               "\n" +
-               "Thank you for your order number 7 of Widgets for Dummies.\n" +
-               "\n" +
-               "Regards Camel Riders Bookstore\n" +
-               "Spazz Testing Service";
+                "Dear Doe, Jane\n" +
+                "\n" +
+                "Thank you for your order number 7 of Widgets for Dummies.\n" +
+                "\n" +
+                "Regards Camel Riders Bookstore\n" +
+                "Spazz Testing Service";
     }
 
     @Override
diff --git 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafBodyAsDomainObjectTest.java
 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafBodyAsDomainObjectTest.java
index 8dfac7e68b3..b7d6447382b 100644
--- 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafBodyAsDomainObjectTest.java
+++ 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafBodyAsDomainObjectTest.java
@@ -121,11 +121,11 @@ public class ThymeleafBodyAsDomainObjectTest extends 
ThymeleafAbstractBaseTest {
         public String toString() {
 
             return "Letter{" +
-                   "firstName='" + firstName + '\'' +
-                   ", lastName='" + lastName + '\'' +
-                   ", item='" + item + '\'' +
-                   ", closing='" + closing + '\'' +
-                   '}';
+                    "firstName='" + firstName + '\'' +
+                    ", lastName='" + lastName + '\'' +
+                    ", item='" + item + '\'' +
+                    ", closing='" + closing + '\'' +
+                    '}';
         }
 
     }
diff --git 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafComponentTest.java
 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafComponentTest.java
index a1b403673f7..e2578b165a6 100644
--- 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafComponentTest.java
+++ 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafComponentTest.java
@@ -16,49 +16,77 @@
  */
 package org.apache.camel.component.thymeleaf;
 
-import java.util.UUID;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.support.PropertyBindingListener;
+import org.apache.camel.test.junit5.CamelTestSupport;
 import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.thymeleaf.templatemode.TemplateMode;
 import org.thymeleaf.templateresolver.ITemplateResolver;
 import org.thymeleaf.templateresolver.StringTemplateResolver;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import static java.util.Map.entry;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.spy;
 
-public class ThymeleafComponentTest extends ThymeleafAbstractBaseTest {
-
-    private static final Logger LOG = 
LoggerFactory.getLogger(ThymeleafComponentTest.class);
+public class ThymeleafComponentTest extends CamelTestSupport {
 
     private String templateMode;
 
-    @Test
-    public void testThymeleaf() throws InterruptedException {
+    protected static String stringTemplate() {
 
-        ThymeleafComponent component = context.getComponent("thymeleaf", 
ThymeleafComponent.class);
-        assertNotNull(component);
+        return """
+                <!--/*-->
+                    Licensed to the Apache Software Foundation (ASF) under one 
or more
+                    contributor license agreements.  See the NOTICE file 
distributed with
+                    this work for additional information regarding copyright 
ownership.
+                    The ASF licenses this file to You under the Apache 
License, Version 2.0
+                    (the "License"); you may not use this file except in 
compliance with
+                    the License.  You may obtain a copy of the License at
 
-        ThymeleafEndpoint thymeleafEndpoint = context.getEndpoint(
-                
"thymeleaf:dontcare?templateMode=CSS&allowContextMapAll=true&resolver=STRING",
-                ThymeleafEndpoint.class);
+                         http://www.apache.org/licenses/LICENSE-2.0
 
-        ThymeleafEndpoint spy = spy(thymeleafEndpoint);
-        LOG.info("foo: {}",
-                
thymeleafEndpoint.getComponent().getEndpointPropertyConfigurer().getClass());
+                    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 code will be removed at thymeleaf parsing time! 
*/-->
+                Dear [(${headers.lastName})], [(${headers.firstName})]
 
-        MockEndpoint mock = getMockEndpoint(MOCK_RESULT);
-        mock.expectedMessageCount(1);
+                Thank you for your order number 
[(${exchange.properties.orderNumber})] of [(${headers.item})].
 
-        template.request(DIRECT_START, templateHeaderProcessor);
+                Regards Camel Riders Bookstore
+                [(${body})]""";
+    }
+
+    @Test
+    public void testThymeleaf() throws Exception {
+
+        /*
+         * Listens for the templateMode property binding to allow verification 
of the <code>createEndpoint()</code>
+         * method in <code>ThymeleafComponent</code>.
+         */
+        context.getRegistry().bind(UUID.randomUUID().toString(),
+                (PropertyBindingListener) (target, key, value) -> {
+                    if ("templateMode".equals(key)) {
+                        templateMode = (String) value;
+                    }
+                });
+
+        ThymeleafComponent component = new ThymeleafComponent();
+        assertNotNull(component);
+        component.setCamelContext(context);
+
+        Map<String, Object> parameters = new HashMap<>(
+                Map.ofEntries(entry("templateMode", "CSS"), 
entry("allowContextMapAll", true), entry("resolver", "STRING")));
 
-        mock.assertIsSatisfied();
+        ThymeleafEndpoint thymeleafEndpoint = (ThymeleafEndpoint) 
component.createEndpoint("thymeleaf", "dontcare", parameters);
+        thymeleafEndpoint.setTemplate(stringTemplate());
 
         assertEquals(TemplateMode.CSS.name(), 
thymeleafEndpoint.getTemplateMode());
 
@@ -71,29 +99,4 @@ public class ThymeleafComponentTest extends 
ThymeleafAbstractBaseTest {
         assertEquals(TemplateMode.CSS.name(), templateMode);
     }
 
-    @Override
-    protected RouteBuilder createRouteBuilder() {
-
-        return new RouteBuilder() {
-
-            public void configure() {
-
-                from(DIRECT_START)
-                        .setBody(simple(SPAZZ_TESTING_SERVICE))
-                        
.to("thymeleaf:dontcare?templateMode=CSS&allowContextMapAll=true&resolver=STRING")
-                        .to(MOCK_RESULT);
-
-                /*
-                 * Listens for the templateMode property binding to allow 
verification of the <code>createEndpoint()</code>
-                 * method in <code>ThymeleafComponent</code>.
-                 */
-                
getCamelContext().getRegistry().bind(UUID.randomUUID().toString(),
-                        (PropertyBindingListener) (target, key, value) -> {
-                            if ("templateMode".equals(key)) {
-                                templateMode = (String) value;
-                            }
-                        });
-            }
-        };
-    }
 }
diff --git 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafConcurrentTest.java
 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafConcurrentTest.java
index d38f6796379..220939065d3 100644
--- 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafConcurrentTest.java
+++ 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafConcurrentTest.java
@@ -16,13 +16,13 @@
  */
 package org.apache.camel.component.thymeleaf;
 
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
 import static org.apache.camel.test.junit5.TestSupport.body;
 
 public class ThymeleafConcurrentTest extends ThymeleafAbstractBaseTest {
diff --git 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafContentCacheTest.java
 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafContentCacheTest.java
index 950836a1fa6..42039d7194c 100644
--- 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafContentCacheTest.java
+++ 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafContentCacheTest.java
@@ -16,13 +16,6 @@
  */
 package org.apache.camel.component.thymeleaf;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -30,6 +23,12 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.TestInstance;
 
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
 import static java.util.Map.entry;
 
 @TestInstance(TestInstance.Lifecycle.PER_METHOD)
diff --git 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafWebApplicationResolverAllParamsTest.java
 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafWebApplicationResolverAllParamsTest.java
index 9be2eeb6179..2c35934fc66 100644
--- 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafWebApplicationResolverAllParamsTest.java
+++ 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafWebApplicationResolverAllParamsTest.java
@@ -16,12 +16,7 @@
  */
 package org.apache.camel.component.thymeleaf;
 
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-
 import jakarta.servlet.ServletContext;
-
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -34,6 +29,10 @@ import org.thymeleaf.templateresolver.ITemplateResolver;
 import org.thymeleaf.templateresolver.WebApplicationTemplateResolver;
 import org.thymeleaf.web.servlet.JakartaServletWebApplication;
 
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+
 import static org.junit.jupiter.api.Assertions.assertAll;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
diff --git 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafWebApplicationResolverTest.java
 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafWebApplicationResolverTest.java
index e16270a2962..d75768e8aa0 100644
--- 
a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafWebApplicationResolverTest.java
+++ 
b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafWebApplicationResolverTest.java
@@ -16,11 +16,7 @@
  */
 package org.apache.camel.component.thymeleaf;
 
-import java.io.File;
-import java.io.InputStream;
-
 import jakarta.servlet.ServletContext;
-
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -33,6 +29,9 @@ import org.thymeleaf.templateresolver.ITemplateResolver;
 import org.thymeleaf.templateresolver.WebApplicationTemplateResolver;
 import org.thymeleaf.web.servlet.JakartaServletWebApplication;
 
+import java.io.File;
+import java.io.InputStream;
+
 import static org.junit.jupiter.api.Assertions.assertAll;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;

Reply via email to