JAMES-2553 Rewrite AbstractJmapJamesServer test in JUNIT 5
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/dedcf9de Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/dedcf9de Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/dedcf9de Branch: refs/heads/master Commit: dedcf9de044b83672851ee1439492a5cf4c133d6 Parents: a57a91d Author: Benoit Tellier <[email protected]> Authored: Mon Oct 1 09:34:16 2018 +0700 Committer: Benoit Tellier <[email protected]> Committed: Thu Oct 4 17:48:42 2018 +0700 ---------------------------------------------------------------------- .../james/CassandraJmapJamesServerTest.java | 42 ++++----- .../james/CassandraLdapJamesServerTest.java | 65 +++++-------- .../james/CassandraLdapJmapJamesServerTest.java | 45 +++------ .../apache/james/CassandraLdapJmapTestRule.java | 97 -------------------- .../org/apache/james/LdapTestExtention.java | 73 +++++++++++++++ .../apache/james/MemoryJmapJamesServerTest.java | 29 +++--- .../james/AbstractJmapJamesServerTest.java | 86 ----------------- .../apache/james/JmapJamesServerContract.java | 66 +++++++++++++ .../apache/james/utils/IMAPMessageReader.java | 9 +- 9 files changed, 217 insertions(+), 295 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java index f2d9d91..f85f1d4 100644 --- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java +++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java @@ -19,26 +19,24 @@ package org.apache.james; -import java.io.IOException; - -import org.junit.ClassRule; -import org.junit.Rule; - -public class CassandraJmapJamesServerTest extends AbstractJmapJamesServerTest { - - @ClassRule - public static DockerCassandraRule cassandra = new DockerCassandraRule(); - - @Rule - public CassandraJmapTestRule cassandraJmap = CassandraJmapTestRule.defaultTestRule(); - - @Override - protected GuiceJamesServer createJamesServer() throws IOException { - return cassandraJmap.jmapServer(cassandra.getModule()); - } - - @Override - protected void clean() { - } - +import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE; + +import org.apache.james.mailbox.extractor.TextExtractor; +import org.apache.james.mailbox.store.search.PDFTextExtractor; +import org.apache.james.modules.TestJMAPServerModule; +import org.junit.jupiter.api.extension.RegisterExtension; + +class CassandraJmapJamesServerTest implements JmapJamesServerContract { + private static final int LIMIT_TO_10_MESSAGES = 10; + + @RegisterExtension + static JamesServerExtension testExtension = new JamesServerExtensionBuilder() + .extension(new EmbeddedElasticSearchExtension()) + .extension(new CassandraExtension()) + .server(configuration -> GuiceJamesServer.forConfiguration(configuration) + .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE) + .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class)) + .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES)) + .overrideWith(DOMAIN_LIST_CONFIGURATION_MODULE)) + .build(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java index 9009a21..c198fc6 100644 --- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java +++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java @@ -22,28 +22,24 @@ package org.apache.james; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Duration.ONE_HUNDRED_MILLISECONDS; -import java.io.IOException; - import org.apache.commons.net.imap.IMAPClient; import org.apache.james.core.Domain; +import org.apache.james.modules.TestJMAPServerModule; import org.apache.james.modules.protocols.ImapGuiceProbe; import org.apache.james.modules.protocols.SmtpGuiceProbe; -import org.apache.james.user.ldap.LdapGenericContainer; import org.apache.james.utils.IMAPMessageReader; import org.apache.james.utils.SMTPMessageSender; import org.apache.james.utils.SpoolerProbe; import org.awaitility.Awaitility; import org.awaitility.Duration; import org.awaitility.core.ConditionFactory; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.RuleChain; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; -public class CassandraLdapJamesServerTest extends AbstractJmapJamesServerTest { +class CassandraLdapJamesServerTest implements JmapJamesServerContract { + private static final int LIMIT_TO_10_MESSAGES = 10; private static final String JAMES_USER = "james-user"; private static final String PASSWORD = "secret"; - private static final String DOMAIN = "james.org"; - private static final String ADMIN_PASSWORD = "mysecretpassword"; private static Duration slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS; private static ConditionFactory calmlyAwait = Awaitility.with() .pollInterval(slowPacedPollInterval) @@ -51,50 +47,32 @@ public class CassandraLdapJamesServerTest extends AbstractJmapJamesServerTest { .with() .pollDelay(slowPacedPollInterval) .await(); - - private LdapGenericContainer ldapContainer = LdapGenericContainer.builder() - .domain(DOMAIN) - .password(ADMIN_PASSWORD) - .build(); - private CassandraLdapJmapTestRule cassandraLdapJmap = CassandraLdapJmapTestRule.defaultTestRule(); private IMAPClient imapClient = new IMAPClient(); - @Rule - public RuleChain ruleChain = RuleChain.outerRule(ldapContainer).around(cassandraLdapJmap); - - @Rule - public IMAPMessageReader imapMessageReader = new IMAPMessageReader(); - @Rule - public SMTPMessageSender messageSender = new SMTPMessageSender(Domain.LOCALHOST.asString()); - - @Override - protected GuiceJamesServer createJamesServer() throws IOException { - ldapContainer.start(); - return cassandraLdapJmap.jmapServer(ldapContainer.getLdapHost(), DOMAIN_LIST_CONFIGURATION_MODULE); - } - - @Override - protected void clean() { - if (ldapContainer != null) { - ldapContainer.stop(); - } - - try { - imapClient.disconnect(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + @RegisterExtension + IMAPMessageReader imapMessageReader = new IMAPMessageReader(); + SMTPMessageSender messageSender = new SMTPMessageSender(Domain.LOCALHOST.asString()); + + @RegisterExtension + static JamesServerExtension testExtension = new JamesServerExtensionBuilder() + .extension(new EmbeddedElasticSearchExtension()) + .extension(new CassandraExtension()) + .extension(new LdapTestExtention()) + .server(configuration -> GuiceJamesServer.forConfiguration(configuration) + .combineWith(CassandraLdapJamesServerMain.cassandraLdapServerModule) + .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES)) + .overrideWith(DOMAIN_LIST_CONFIGURATION_MODULE)) + .build(); @Test - public void userFromLdapShouldLoginViaImapProtocol() throws Exception { + void userFromLdapShouldLoginViaImapProtocol(GuiceJamesServer server) throws Exception { imapClient.connect(JAMES_SERVER_HOST, server.getProbe(ImapGuiceProbe.class).getImapPort()); assertThat(imapClient.login(JAMES_USER, PASSWORD)).isTrue(); } @Test - public void mailsShouldBeWellReceivedBeforeFirstUserConnectionWithLdap() throws Exception { + void mailsShouldBeWellReceivedBeforeFirstUserConnectionWithLdap(GuiceJamesServer server) throws Exception { messageSender.connect(JAMES_SERVER_HOST, server.getProbe(SmtpGuiceProbe.class).getSmtpPort()) .sendMessage("[email protected]", JAMES_USER + "@localhost"); @@ -105,5 +83,4 @@ public class CassandraLdapJamesServerTest extends AbstractJmapJamesServerTest { .select("INBOX") .awaitMessage(calmlyAwait); } - } http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java index 14a965d..c604b23 100644 --- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java +++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java @@ -19,35 +19,20 @@ package org.apache.james; -import java.io.IOException; - -import org.apache.james.user.ldap.LdapGenericContainer; -import org.junit.Rule; -import org.junit.rules.RuleChain; - -public class CassandraLdapJmapJamesServerTest extends AbstractJmapJamesServerTest { - private static final String DOMAIN = "james.org"; - private static final String ADMIN_PASSWORD = "mysecretpassword"; - - private LdapGenericContainer ldapContainer = LdapGenericContainer.builder() - .domain(DOMAIN) - .password(ADMIN_PASSWORD) +import org.apache.james.modules.TestJMAPServerModule; +import org.junit.jupiter.api.extension.RegisterExtension; + +class CassandraLdapJmapJamesServerTest implements JmapJamesServerContract { + private static final int LIMIT_TO_10_MESSAGES = 10; + + @RegisterExtension + static JamesServerExtension testExtension = new JamesServerExtensionBuilder() + .extension(new EmbeddedElasticSearchExtension()) + .extension(new CassandraExtension()) + .extension(new LdapTestExtention()) + .server(configuration -> GuiceJamesServer.forConfiguration(configuration) + .combineWith(CassandraLdapJamesServerMain.cassandraLdapServerModule) + .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES)) + .overrideWith(DOMAIN_LIST_CONFIGURATION_MODULE)) .build(); - private CassandraLdapJmapTestRule cassandraLdapJmap = CassandraLdapJmapTestRule.defaultTestRule(); - - @Rule - public RuleChain ruleChain = RuleChain.outerRule(ldapContainer).around(cassandraLdapJmap); - - @Override - protected GuiceJamesServer createJamesServer() throws IOException { - ldapContainer.start(); - return cassandraLdapJmap.jmapServer(ldapContainer.getLdapHost()); - } - - @Override - protected void clean() { - if (ldapContainer != null) { - ldapContainer.stop(); - } - } } http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java deleted file mode 100644 index 58da40a..0000000 --- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************** - * 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; - -import java.io.IOException; - -import org.apache.commons.configuration.ConfigurationException; -import org.apache.james.modules.TestJMAPServerModule; -import org.apache.james.server.core.configuration.Configuration; -import org.apache.james.user.ldap.LdapRepositoryConfiguration; -import org.junit.rules.TemporaryFolder; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - -import com.google.inject.Module; - -public class CassandraLdapJmapTestRule implements TestRule { - private static final int LIMIT_TO_3_MESSAGES = 3; - - public static CassandraLdapJmapTestRule defaultTestRule() { - return new CassandraLdapJmapTestRule( - AggregateGuiceModuleTestRule.of(new EmbeddedElasticSearchRule(), new DockerCassandraRule())); - } - - private final TemporaryFolder temporaryFolder; - private final GuiceModuleTestRule guiceModuleTestRule; - - public CassandraLdapJmapTestRule(GuiceModuleTestRule... guiceModuleTestRule) { - TempFilesystemTestRule tempFilesystemTestRule = new TempFilesystemTestRule(); - temporaryFolder = tempFilesystemTestRule.getTemporaryFolder(); - this.guiceModuleTestRule = - AggregateGuiceModuleTestRule - .of(guiceModuleTestRule) - .aggregate(tempFilesystemTestRule); - } - - public GuiceJamesServer jmapServer(String ldapIp, Module... additionals) throws IOException { - Configuration configuration = Configuration.builder() - .workingDirectory(temporaryFolder.newFolder()) - .configurationFromClasspath() - .build(); - - return GuiceJamesServer.forConfiguration(configuration) - .combineWith(CassandraLdapJamesServerMain.cassandraLdapServerModule) - .overrideWith(new TestJMAPServerModule(LIMIT_TO_3_MESSAGES)) - .overrideWith(guiceModuleTestRule.getModule()) - .overrideWith(additionals) - .overrideWith(binder -> binder.bind(LdapRepositoryConfiguration.class) - .toInstance(computeConfiguration(ldapIp))); - } - - private LdapRepositoryConfiguration computeConfiguration(String ldapIp) { - try { - return LdapRepositoryConfiguration.builder() - .ldapHost(ldapIp) - .principal("cn=admin,dc=james,dc=org") - .credentials("mysecretpassword") - .userBase("ou=People,dc=james,dc=org") - .userIdAttribute("uid") - .userObjectClass("inetOrgPerson") - .maxRetries(4) - .retryStartInterval(0) - .retryMaxInterval(8) - .scale(1000) - .build(); - } catch (ConfigurationException e) { - throw new RuntimeException(e); - } - } - - @Override - public Statement apply(Statement base, Description description) { - return guiceModuleTestRule.apply(base, description); - } - - public void await() { - guiceModuleTestRule.await(); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtention.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtention.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtention.java new file mode 100644 index 0000000..a0aaea5 --- /dev/null +++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/LdapTestExtention.java @@ -0,0 +1,73 @@ +/**************************************************************** + * 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; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.james.user.ldap.LdapGenericContainer; +import org.apache.james.user.ldap.LdapRepositoryConfiguration; +import org.junit.jupiter.api.extension.ExtensionContext; + +import com.google.inject.Module; + +public class LdapTestExtention implements GuiceModuleTestExtension { + private static final String DOMAIN = "james.org"; + private static final String ADMIN_PASSWORD = "mysecretpassword"; + + private LdapGenericContainer ldapContainer; + + @Override + public void beforeAll(ExtensionContext extensionContext) { + ldapContainer = LdapGenericContainer.builder() + .domain(DOMAIN) + .password(ADMIN_PASSWORD) + .build(); + ldapContainer.start(); + } + + @Override + public void afterAll(ExtensionContext extensionContext) { + ldapContainer.stop(); + } + + @Override + public Module getModule() { + return binder -> binder.bind(LdapRepositoryConfiguration.class) + .toInstance(computeConfiguration(ldapContainer.getLdapHost())); + } + + private LdapRepositoryConfiguration computeConfiguration(String ldapIp) { + try { + return LdapRepositoryConfiguration.builder() + .ldapHost(ldapIp) + .principal("cn=admin,dc=james,dc=org") + .credentials("mysecretpassword") + .userBase("ou=People,dc=james,dc=org") + .userIdAttribute("uid") + .userObjectClass("inetOrgPerson") + .maxRetries(4) + .retryStartInterval(0) + .retryMaxInterval(8) + .scale(1000) + .build(); + } catch (ConfigurationException e) { + throw new RuntimeException(e); + } + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapJamesServerTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapJamesServerTest.java index eb3ca00..a1d551d 100644 --- a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapJamesServerTest.java +++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapJamesServerTest.java @@ -19,21 +19,20 @@ package org.apache.james; -import java.io.IOException; +import org.apache.james.mailbox.extractor.TextExtractor; +import org.apache.james.mailbox.store.search.PDFTextExtractor; +import org.apache.james.modules.TestJMAPServerModule; +import org.junit.jupiter.api.extension.RegisterExtension; -import org.junit.Rule; +class MemoryJmapJamesServerTest implements JmapJamesServerContract { + private static final int LIMIT_TO_10_MESSAGES = 10; -public class MemoryJmapJamesServerTest extends AbstractJmapJamesServerTest { - - @Rule - public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule(); - - @Override - protected GuiceJamesServer createJamesServer() throws IOException { - return memoryJmap.jmapServer(); - } - - @Override - protected void clean() { - } + @RegisterExtension + static JamesServerExtension jamesServerExtension = new JamesServerExtensionBuilder() + .server(configuration -> GuiceJamesServer.forConfiguration(configuration) + .combineWith(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE) + .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES)) + .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class)) + .overrideWith(DOMAIN_LIST_CONFIGURATION_MODULE)) + .build(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java deleted file mode 100644 index 318e15b..0000000 --- a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************** - * 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; - -import static io.restassured.RestAssured.given; -import static io.restassured.config.EncoderConfig.encoderConfig; -import static io.restassured.config.RestAssuredConfig.newConfig; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; - -import org.apache.james.domainlist.lib.DomainListConfiguration; -import org.apache.james.utils.JmapGuiceProbe; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.google.inject.Module; - -import io.restassured.RestAssured; -import io.restassured.builder.RequestSpecBuilder; -import io.restassured.http.ContentType; - -public abstract class AbstractJmapJamesServerTest { - - public static final Module DOMAIN_LIST_CONFIGURATION_MODULE = binder -> binder.bind(DomainListConfiguration.class) - .toInstance(DomainListConfiguration.builder() - .autoDetect(true) - .autoDetectIp(false) - .build()); - - protected static final String JAMES_SERVER_HOST = "127.0.0.1"; - - protected GuiceJamesServer server; - - @Before - public void setup() throws Exception { - server = createJamesServer(); - server.start(); - - RestAssured.requestSpecification = new RequestSpecBuilder() - .setContentType(ContentType.JSON) - .setAccept(ContentType.JSON) - .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8))) - .setPort(server.getProbe(JmapGuiceProbe.class).getJmapPort()) - .build(); - } - - protected abstract GuiceJamesServer createJamesServer() throws IOException; - - protected abstract void clean(); - - @After - public void tearDown() throws Exception { - if (server != null) { - server.stop(); - } - clean(); - } - - @Test - public void connectJMAPServerShouldRespondBadRequest() throws Exception { - given() - .body("{\"badAttributeName\": \"value\"}") - .when() - .post("/authentication") - .then() - .statusCode(400); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/container/guice/protocols/jmap/src/test/java/org/apache/james/JmapJamesServerContract.java ---------------------------------------------------------------------- diff --git a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/JmapJamesServerContract.java b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/JmapJamesServerContract.java new file mode 100644 index 0000000..5562871 --- /dev/null +++ b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/JmapJamesServerContract.java @@ -0,0 +1,66 @@ +/**************************************************************** + * 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; + +import static io.restassured.RestAssured.given; +import static io.restassured.config.EncoderConfig.encoderConfig; +import static io.restassured.config.RestAssuredConfig.newConfig; + +import java.nio.charset.StandardCharsets; + +import org.apache.james.domainlist.lib.DomainListConfiguration; +import org.apache.james.utils.JmapGuiceProbe; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.google.inject.Module; + +import io.restassured.RestAssured; +import io.restassured.builder.RequestSpecBuilder; +import io.restassured.http.ContentType; + +public interface JmapJamesServerContract { + Module DOMAIN_LIST_CONFIGURATION_MODULE = binder -> binder.bind(DomainListConfiguration.class) + .toInstance(DomainListConfiguration.builder() + .autoDetect(true) + .autoDetectIp(false) + .build()); + String JAMES_SERVER_HOST = "127.0.0.1"; + + @BeforeEach + default void setup(GuiceJamesServer server) throws Exception { + + RestAssured.requestSpecification = new RequestSpecBuilder() + .setContentType(ContentType.JSON) + .setAccept(ContentType.JSON) + .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8))) + .setPort(server.getProbe(JmapGuiceProbe.class).getJmapPort()) + .build(); + } + + @Test + default void connectJMAPServerShouldRespondBadRequest() { + given() + .body("{\"badAttributeName\": \"value\"}") + .when() + .post("/authentication") + .then() + .statusCode(400); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/dedcf9de/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java ---------------------------------------------------------------------- diff --git a/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java b/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java index 078b583..7e80983 100644 --- a/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java +++ b/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java @@ -25,12 +25,14 @@ import java.util.List; import org.apache.commons.net.imap.IMAPClient; import org.awaitility.core.ConditionFactory; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.rules.ExternalResource; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Splitter; -public class IMAPMessageReader extends ExternalResource implements Closeable { +public class IMAPMessageReader extends ExternalResource implements Closeable, AfterEachCallback { public static final String INBOX = "INBOX"; @@ -189,6 +191,11 @@ public class IMAPMessageReader extends ExternalResource implements Closeable { } } + @Override + public void afterEach(ExtensionContext extensionContext) { + after(); + } + public void copyFirstMessage(String destMailbox) throws IOException { imapClient.copy("1", destMailbox); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
