You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/03/13 08:12:49 UTC
[08/13] james-project git commit: JAMES-2346 Model for MDN related
data
JAMES-2346 Model for MDN related data
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/4e7d6a00
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/4e7d6a00
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/4e7d6a00
Branch: refs/heads/master
Commit: 4e7d6a000942771f4125601c9c02238d2bf4b9a5
Parents: 857074e
Author: benwa <bt...@linagora.com>
Authored: Thu Mar 8 10:56:03 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Tue Mar 13 15:11:54 2018 +0700
----------------------------------------------------------------------
.../java/org/apache/james/jmap/model/MDN.java | 148 +++++++++++++++++++
.../apache/james/jmap/model/MDNDisposition.java | 119 +++++++++++++++
.../james/jmap/model/MDNDispositionTest.java | 84 +++++++++++
.../org/apache/james/jmap/model/MDNTest.java | 125 ++++++++++++++++
4 files changed, 476 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/4e7d6a00/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MDN.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MDN.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MDN.java
new file mode 100644
index 0000000..cf54031
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MDN.java
@@ -0,0 +1,148 @@
+/****************************************************************
+ * 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.james.jmap.model;
+
+import java.util.Objects;
+
+import org.apache.james.mailbox.model.MessageId;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+@JsonDeserialize(builder = MDN.Builder.class)
+public class MDN {
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ @JsonPOJOBuilder(withPrefix = "")
+ public static class Builder {
+ private MessageId messageId;
+ private String subject;
+ private String textBody;
+ private String reportingUA;
+ private MDNDisposition disposition;
+
+ public Builder messageId(MessageId messageId) {
+ this.messageId = messageId;
+ return this;
+ }
+
+ public Builder subject(String subject) {
+ this.subject = subject;
+ return this;
+ }
+
+ public Builder textBody(String textBody) {
+ this.textBody = textBody;
+ return this;
+ }
+
+ public Builder reportingUA(String reportingUA) {
+ this.reportingUA = reportingUA;
+ return this;
+ }
+
+ public Builder disposition(MDNDisposition disposition) {
+ this.disposition = disposition;
+ return this;
+ }
+
+ public MDN build() {
+ Preconditions.checkState(messageId != null, "'messageId' is mandatory");
+ Preconditions.checkState(subject != null, "'subject' is mandatory");
+ Preconditions.checkState(textBody != null, "'textBody' is mandatory");
+ Preconditions.checkState(reportingUA != null, "'reportingUA' is mandatory");
+ Preconditions.checkState(disposition != null, "'disposition' is mandatory");
+
+ return new MDN(messageId, subject, textBody, reportingUA, disposition);
+ }
+
+ }
+
+ private final MessageId messageId;
+ private final String subject;
+ private final String textBody;
+ private final String reportingUA;
+ private final MDNDisposition disposition;
+
+ @VisibleForTesting
+ MDN(MessageId messageId, String subject, String textBody, String reportingUA, MDNDisposition disposition) {
+ this.messageId = messageId;
+ this.subject = subject;
+ this.textBody = textBody;
+ this.reportingUA = reportingUA;
+ this.disposition = disposition;
+ }
+
+ public MessageId getMessageId() {
+ return messageId;
+ }
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public String getTextBody() {
+ return textBody;
+ }
+
+ public String getReportingUA() {
+ return reportingUA;
+ }
+
+ public MDNDisposition getDisposition() {
+ return disposition;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof MDN) {
+ MDN that = (MDN) o;
+
+ return Objects.equals(this.messageId, that.messageId)
+ && Objects.equals(this.subject, that.subject)
+ && Objects.equals(this.textBody, that.textBody)
+ && Objects.equals(this.reportingUA, that.reportingUA)
+ && Objects.equals(this.disposition, that.disposition);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(messageId, subject, textBody, reportingUA, disposition);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("messageId", messageId)
+ .add("subject", subject)
+ .add("textBody", textBody)
+ .add("reportingUA", reportingUA)
+ .add("mdnDisposition", disposition)
+ .toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4e7d6a00/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MDNDisposition.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MDNDisposition.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MDNDisposition.java
new file mode 100644
index 0000000..f13bc5b
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MDNDisposition.java
@@ -0,0 +1,119 @@
+/****************************************************************
+ * 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.james.jmap.model;
+
+import java.util.Objects;
+
+import org.apache.james.mdn.action.mode.DispositionActionMode;
+import org.apache.james.mdn.sending.mode.DispositionSendingMode;
+import org.apache.james.mdn.type.DispositionType;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+@JsonDeserialize(builder = MDNDisposition.Builder.class)
+public class MDNDisposition {
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ @JsonPOJOBuilder(withPrefix = "")
+ public static class Builder {
+ private DispositionActionMode actionMode;
+ private DispositionSendingMode sendingMode;
+ private DispositionType type;
+
+ public Builder actionMode(DispositionActionMode actionMode) {
+ this.actionMode = actionMode;
+ return this;
+ }
+
+ public Builder sendingMode(DispositionSendingMode sendingMode) {
+ this.sendingMode = sendingMode;
+ return this;
+ }
+
+ public Builder type(DispositionType type) {
+ this.type = type;
+ return this;
+ }
+
+ public MDNDisposition build() {
+ Preconditions.checkState(actionMode != null, "'actionMode' is mandatory");
+ Preconditions.checkState(sendingMode != null, "'sendingMode' is mandatory");
+ Preconditions.checkState(type != null, "'type' is mandatory");
+
+ return new MDNDisposition(actionMode, sendingMode, type);
+ }
+ }
+
+ private final DispositionActionMode actionMode;
+ private final DispositionSendingMode sendingMode;
+ private final DispositionType type;
+
+ @VisibleForTesting
+ MDNDisposition(DispositionActionMode actionMode, DispositionSendingMode sendingMode, DispositionType type) {
+ this.actionMode = actionMode;
+ this.sendingMode = sendingMode;
+ this.type = type;
+ }
+
+ public DispositionActionMode getActionMode() {
+ return actionMode;
+ }
+
+ public DispositionSendingMode getSendingMode() {
+ return sendingMode;
+ }
+
+ public DispositionType getType() {
+ return type;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof MDNDisposition) {
+ MDNDisposition that = (MDNDisposition) o;
+
+ return Objects.equals(this.actionMode, that.actionMode)
+ && Objects.equals(this.sendingMode, that.sendingMode)
+ && Objects.equals(this.type, that.type);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(actionMode, sendingMode, type);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("actionMode", actionMode)
+ .add("sendingMode", sendingMode)
+ .add("type", type)
+ .toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/4e7d6a00/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNDispositionTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNDispositionTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNDispositionTest.java
new file mode 100644
index 0000000..f5f5d57
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNDispositionTest.java
@@ -0,0 +1,84 @@
+/****************************************************************
+ * 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.james.jmap.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.james.mdn.action.mode.DispositionActionMode;
+import org.apache.james.mdn.sending.mode.DispositionSendingMode;
+import org.apache.james.mdn.type.DispositionType;
+import org.junit.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class MDNDispositionTest {
+
+ @Test
+ public void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(MDNDisposition.class)
+ .allFieldsShouldBeUsed()
+ .verify();
+ }
+
+ @Test
+ public void builderShouldReturnObjectWhenAllFieldsAreValid() {
+ assertThat(
+ MDNDisposition.builder()
+ .actionMode(DispositionActionMode.Automatic)
+ .sendingMode(DispositionSendingMode.Automatic)
+ .type(DispositionType.Processed)
+ .build())
+ .isEqualTo(new MDNDisposition(DispositionActionMode.Automatic,
+ DispositionSendingMode.Automatic,
+ DispositionType.Processed));
+ }
+
+ @Test
+ public void actionModeIsCompulsory() {
+ assertThatThrownBy(() ->
+ MDNDisposition.builder()
+ .sendingMode(DispositionSendingMode.Automatic)
+ .type(DispositionType.Processed)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ public void sendingModeIsCompulsory() {
+ assertThatThrownBy(() ->
+ MDNDisposition.builder()
+ .actionMode(DispositionActionMode.Automatic)
+ .type(DispositionType.Processed)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ public void typeIsCompulsory() {
+ assertThatThrownBy(() ->
+ MDNDisposition.builder()
+ .actionMode(DispositionActionMode.Automatic)
+ .sendingMode(DispositionSendingMode.Automatic)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/4e7d6a00/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNTest.java
new file mode 100644
index 0000000..1527719
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MDNTest.java
@@ -0,0 +1,125 @@
+/****************************************************************
+ * 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.james.jmap.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.james.mailbox.model.TestMessageId;
+import org.apache.james.mdn.action.mode.DispositionActionMode;
+import org.apache.james.mdn.sending.mode.DispositionSendingMode;
+import org.apache.james.mdn.type.DispositionType;
+import org.junit.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class MDNTest {
+
+ public static final String TEXT_BODY = "text body";
+ public static final String SUBJECT = "subject";
+ public static final String REPORTING_UA = "reportingUA";
+ public static final MDNDisposition DISPOSITION = MDNDisposition.builder()
+ .actionMode(DispositionActionMode.Automatic)
+ .sendingMode(DispositionSendingMode.Automatic)
+ .type(DispositionType.Processed)
+ .build();
+ public static final TestMessageId MESSAGE_ID = TestMessageId.of(45);
+
+ @Test
+ public void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(MDN.class)
+ .allFieldsShouldBeUsed()
+ .verify();
+ }
+
+ @Test
+ public void builderShouldReturnObjectWhenAllFieldsAreValid() {
+ assertThat(
+ MDN.builder()
+ .disposition(DISPOSITION)
+ .messageId(MESSAGE_ID)
+ .reportingUA(REPORTING_UA)
+ .subject(SUBJECT)
+ .textBody(TEXT_BODY)
+ .build())
+ .isEqualTo(new MDN(MESSAGE_ID, SUBJECT, TEXT_BODY, REPORTING_UA, DISPOSITION));
+ }
+
+ @Test
+ public void dispositionIsCompulsory() {
+ assertThatThrownBy(() ->
+ MDN.builder()
+ .messageId(MESSAGE_ID)
+ .reportingUA(REPORTING_UA)
+ .subject(SUBJECT)
+ .textBody(TEXT_BODY)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ public void messageIdIsCompulsory() {
+ assertThatThrownBy(() ->
+ MDN.builder()
+ .disposition(DISPOSITION)
+ .reportingUA(REPORTING_UA)
+ .subject(SUBJECT)
+ .textBody(TEXT_BODY)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ public void reportingUAIsCompulsory() {
+ assertThatThrownBy(() ->
+ MDN.builder()
+ .disposition(DISPOSITION)
+ .messageId(MESSAGE_ID)
+ .subject(SUBJECT)
+ .textBody(TEXT_BODY)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ public void subjectIsCompulsory() {
+ assertThatThrownBy(() ->
+ MDN.builder()
+ .disposition(DISPOSITION)
+ .messageId(MESSAGE_ID)
+ .reportingUA(REPORTING_UA)
+ .textBody(TEXT_BODY)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+ @Test
+ public void textBodyIsCompulsory() {
+ assertThatThrownBy(() ->
+ MDN.builder()
+ .disposition(DISPOSITION)
+ .messageId(MESSAGE_ID)
+ .reportingUA(REPORTING_UA)
+ .subject(SUBJECT)
+ .build())
+ .isInstanceOf(IllegalStateException.class);
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org