This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 1f027922ef53485858c7d3d4e63b3def8c812b2e Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Wed Aug 21 16:13:55 2019 +0700 JAMES-2866 Store SMTP behaviors --- .../mock/smtp/server/SMTPBehaviorRepository.java | 43 ++++++++++++++ .../mock/smtp/server/MockSmtpBehaviorsTest.java | 2 +- .../smtp/server/SMTPBehaviorRepositoryTest.java | 68 ++++++++++++++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/SMTPBehaviorRepository.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/SMTPBehaviorRepository.java new file mode 100644 index 0000000..23084cd --- /dev/null +++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/SMTPBehaviorRepository.java @@ -0,0 +1,43 @@ +/**************************************************************** + * 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.mock.smtp.server; + +import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; + +public class SMTPBehaviorRepository { + private final AtomicReference<MockSmtpBehaviors> behaviors; + + public SMTPBehaviorRepository() { + this.behaviors = new AtomicReference<>(); + } + + public Optional<MockSmtpBehaviors> getBehaviors() { + return Optional.ofNullable(this.behaviors.get()); + } + + public void clearBehaviors() { + this.behaviors.set(null); + } + + public void setBehaviors(MockSmtpBehaviors behaviors) { + this.behaviors.set(behaviors); + } +} diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSmtpBehaviorsTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSmtpBehaviorsTest.java index 83ffaaf..8507a0f 100644 --- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSmtpBehaviorsTest.java +++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSmtpBehaviorsTest.java @@ -41,7 +41,7 @@ class MockSmtpBehaviorsTest { private static final String JSON = "[" + MockSMTPBehaviorTest.JSON_ALL_FIELDS + ", " + MockSMTPBehaviorTest.JSON_COMPULSORY_FIELDS + "]"; - private static final MockSmtpBehaviors POJO = new MockSmtpBehaviors(ImmutableList.of( + static final MockSmtpBehaviors POJO = new MockSmtpBehaviors(ImmutableList.of( MockSMTPBehaviorTest.POJO_ALL_FIELDS, MockSMTPBehaviorTest.POJO_COMPULSORY_FIELDS)); diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/SMTPBehaviorRepositoryTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/SMTPBehaviorRepositoryTest.java new file mode 100644 index 0000000..0ce87f0 --- /dev/null +++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/SMTPBehaviorRepositoryTest.java @@ -0,0 +1,68 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mock.smtp.server; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.google.common.collect.ImmutableList; + +class SMTPBehaviorRepositoryTest { + private SMTPBehaviorRepository testee; + + @BeforeEach + void setUp() { + testee = new SMTPBehaviorRepository(); + } + + @Test + void getBehaviorsShouldReturnEmptyWhenNoValueStored() { + assertThat(testee.getBehaviors()) + .isEmpty(); + } + + @Test + void getBehaviorsShouldReturnPreviouslyStoredValue() { + testee.setBehaviors(MockSmtpBehaviorsTest.POJO); + + assertThat(testee.getBehaviors()).contains(MockSmtpBehaviorsTest.POJO); + } + + @Test + void getBehaviorsShouldReturnLatestStoredValue() { + MockSmtpBehaviors newPojo = new MockSmtpBehaviors(ImmutableList.of(MockSMTPBehaviorTest.POJO_COMPULSORY_FIELDS)); + + testee.setBehaviors(MockSmtpBehaviorsTest.POJO); + testee.setBehaviors(newPojo); + + assertThat(testee.getBehaviors()).contains(newPojo); + } + + @Test + void getBehaviorsShouldReturnEmptyWhenCleared() { + testee.setBehaviors(MockSmtpBehaviorsTest.POJO); + + testee.clearBehaviors(); + + assertThat(testee.getBehaviors()).isEmpty(); + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org