You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2021/08/12 20:58:54 UTC

[sling-org-apache-sling-commons-messaging-mail] 05/06: test component lifecycle

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

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-messaging-mail.git

commit 1edee72c83ae111eb480c0c40bf888054ce91f93
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Thu Aug 12 22:54:55 2021 +0200

    test component lifecycle
---
 pom.xml                                            | 12 +++++
 .../mail/internal/SimpleMessageIdProviderTest.java | 56 ++++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/pom.xml b/pom.xml
index 5952ff0..4451226 100644
--- a/pom.xml
+++ b/pom.xml
@@ -214,6 +214,12 @@
       <version>2.8.0</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>3.12.0</version>
+      <scope>test</scope>
+    </dependency>
     <!-- Apache Felix -->
     <dependency>
       <groupId>org.apache.felix</groupId>
@@ -284,6 +290,12 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <version>3.11.2</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>com.icegreen</groupId>
       <artifactId>greenmail</artifactId>
       <version>2.0.0-alpha-1</version>
diff --git a/src/test/java/org/apache/sling/commons/messaging/mail/internal/SimpleMessageIdProviderTest.java b/src/test/java/org/apache/sling/commons/messaging/mail/internal/SimpleMessageIdProviderTest.java
new file mode 100644
index 0000000..ef189b0
--- /dev/null
+++ b/src/test/java/org/apache/sling/commons/messaging/mail/internal/SimpleMessageIdProviderTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.messaging.mail.internal;
+
+import jakarta.mail.internet.MimeMessage;
+import org.apache.commons.lang3.reflect.MethodUtils;
+import org.junit.Test;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class SimpleMessageIdProviderTest {
+
+    @Test
+    public void testComponentLifecycle() throws Exception {
+        final MimeMessage message = mock(MimeMessage.class);
+        final SimpleMessageIdProvider provider = new SimpleMessageIdProvider();
+        { // activate
+            final String host = "author.cms.example.org";
+            final SimpleMessageIdProviderConfiguration configuration = mock(SimpleMessageIdProviderConfiguration.class);
+            when(configuration.host()).thenReturn(host);
+            MethodUtils.invokeMethod(provider, true, "activate", configuration);
+            assertThat(provider.getMessageId(message)).endsWith("@".concat(host));
+        }
+        { // modified
+            final String host = "publish.cms.example.org";
+            final SimpleMessageIdProviderConfiguration configuration = mock(SimpleMessageIdProviderConfiguration.class);
+            when(configuration.host()).thenReturn(host);
+            MethodUtils.invokeMethod(provider, true, "modified", configuration);
+            assertThat(provider.getMessageId(message)).endsWith("@".concat(host));
+        }
+        { // deactivate
+            final String host = "publish.cms.example.org";
+            MethodUtils.invokeMethod(provider, true, "deactivate");
+            assertThat(provider.getMessageId(message)).endsWith("@".concat(host));
+        }
+    }
+
+}