Skip to content

Commit

Permalink
JAMES-1864 use @rule for server start in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaechler committed Nov 21, 2016
1 parent 644ecaa commit 2a30769
Show file tree
Hide file tree
Showing 24 changed files with 212 additions and 283 deletions.
Expand Up @@ -19,57 +19,20 @@

package org.apache.james;

import org.apache.james.backends.cassandra.CassandraCluster;
import org.apache.james.backends.cassandra.components.CassandraModule;
import org.apache.james.jmap.methods.GetMessageListMethod;
import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
import org.apache.james.modules.TestElasticSearchModule;
import org.apache.james.modules.TestFilesystemModule;
import org.apache.james.modules.TestJMAPServerModule;
import org.junit.Rule;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;

import com.datastax.driver.core.Session;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;

public class CassandraJamesServerTest extends AbstractJmapJamesServerTest {

private TemporaryFolder temporaryFolder = new TemporaryFolder();
private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
private CassandraCluster cassandra;

@Rule
public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
public CassandraJmapTestRule cassandraJmap = new CassandraJmapTestRule();

@Override
protected JmapJamesServer createJamesServer() {
return new JmapJamesServer()
.combineWith(CassandraJamesServerMain.cassandraServerModule)
.overrideWith(new TestElasticSearchModule(embeddedElasticSearch),
new TestFilesystemModule(temporaryFolder),
new TestJMAPServerModule(GetMessageListMethod.DEFAULT_MAXIMUM_LIMIT),
new AbstractModule() {

@Override
protected void configure() {
}

@Provides
@Singleton
Session provideSession(CassandraModule cassandraModule) {
cassandra = CassandraCluster.create(cassandraModule);
return cassandra.getConf();
}
});
return cassandraJmap.jmapServer();
}

@Override
protected void clean() {
cassandra.clearAllTables();
}


}
@@ -0,0 +1,60 @@
/****************************************************************
* 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.james.backends.cassandra.EmbeddedCassandra;
import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
import org.apache.james.modules.CassandraJmapServerModule;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;


public class CassandraJmapTestRule implements TestRule {

private TemporaryFolder temporaryFolder = new TemporaryFolder();
private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
private EmbeddedCassandra cassandra = EmbeddedCassandra.createStartServer();

public RuleChain chain = RuleChain
.outerRule(temporaryFolder)
.around(embeddedElasticSearch);

public JmapJamesServer jmapServer() {
return new JmapJamesServer()
.combineWith(CassandraJamesServerMain.cassandraServerModule)
.overrideWith(new CassandraJmapServerModule(temporaryFolder, embeddedElasticSearch, cassandra));
}

@Override
public Statement apply(Statement base, Description description) {
return chain.apply(base, description);
}


public EmbeddedElasticSearch getElasticSearch() {
return embeddedElasticSearch;
}

public void await() {
embeddedElasticSearch.awaitForElasticSearch();
}
}
Expand Up @@ -33,7 +33,7 @@ public JmapJamesServer() {
super();
}

public JmapJamesServer(Module module) {
private JmapJamesServer(Module module) {
super(module);
}

Expand Down
Expand Up @@ -19,23 +19,16 @@

package org.apache.james;

import org.apache.james.jmap.methods.GetMessageListMethod;
import org.apache.james.modules.TestFilesystemModule;
import org.apache.james.modules.TestJMAPServerModule;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;

public class MemoryJamesServerTest extends AbstractJmapJamesServerTest {

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();

@Override
protected JmapJamesServer createJamesServer() {
return new JmapJamesServer()
.combineWith(MemoryJamesServerMain.inMemoryServerModule)
.overrideWith(new TestFilesystemModule(temporaryFolder),
new TestJMAPServerModule(GetMessageListMethod.DEFAULT_MAXIMUM_LIMIT));
return memoryJmap.jmapServer();
}

@Override
Expand Down
@@ -0,0 +1,47 @@
/****************************************************************
* 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.james.modules.TestFilesystemModule;
import org.apache.james.modules.TestJMAPServerModule;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

public class MemoryJmapTestRule implements TestRule {

private static final int LIMIT_TO_3_MESSAGES = 3;

public TemporaryFolder temporaryFolder = new TemporaryFolder();

public JmapJamesServer jmapServer() {
return new JmapJamesServer()
.combineWith(MemoryJamesServerMain.inMemoryServerModule)
.overrideWith(new TestFilesystemModule(temporaryFolder),
new TestJMAPServerModule(LIMIT_TO_3_MESSAGES));
}

@Override
public Statement apply(Statement base, Description description) {
return temporaryFolder.apply(base, description);
}

}
6 changes: 6 additions & 0 deletions server/pom.xml
Expand Up @@ -591,6 +591,12 @@
<artifactId>james-server-memory-guice</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>james-server-memory-guice</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>james-server-jmap</artifactId>
Expand Down
Expand Up @@ -19,33 +19,20 @@

package org.apache.james.jmap.cassandra;

import org.apache.james.CassandraJamesServerMain;
import org.apache.james.CassandraJmapTestRule;
import org.apache.james.JmapJamesServer;
import org.apache.james.backends.cassandra.EmbeddedCassandra;
import org.apache.james.jmap.methods.integration.GetMailboxesMethodTest;
import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
import org.apache.james.modules.CassandraJmapServerModule;
import org.junit.Rule;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;


public class CassandraGetMailboxesMethodTest extends GetMailboxesMethodTest {

private TemporaryFolder temporaryFolder = new TemporaryFolder();
private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
private EmbeddedCassandra cassandra = EmbeddedCassandra.createStartServer();

@Rule
public RuleChain chain = RuleChain
.outerRule(temporaryFolder)
.around(embeddedElasticSearch);

@Rule
public CassandraJmapTestRule rule = new CassandraJmapTestRule();

@Override
protected JmapJamesServer createJmapServer() {
return new JmapJamesServer()
.combineWith(CassandraJamesServerMain.cassandraServerModule)
.overrideWith(new CassandraJmapServerModule(temporaryFolder, embeddedElasticSearch, cassandra));
return rule.jmapServer();
}

}
Expand Up @@ -19,36 +19,23 @@

package org.apache.james.jmap.cassandra;

import org.apache.james.CassandraJamesServerMain;
import org.apache.james.CassandraJmapTestRule;
import org.apache.james.JmapJamesServer;
import org.apache.james.backends.cassandra.EmbeddedCassandra;
import org.apache.james.jmap.methods.integration.GetMessageListMethodTest;
import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
import org.apache.james.modules.CassandraJmapServerModule;
import org.junit.Rule;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;

public class CassandraGetMessageListMethodTest extends GetMessageListMethodTest {

private TemporaryFolder temporaryFolder = new TemporaryFolder();
private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
private EmbeddedCassandra cassandra = EmbeddedCassandra.createStartServer();

@Rule
public RuleChain chain = RuleChain
.outerRule(temporaryFolder)
.around(embeddedElasticSearch);
@Rule
public CassandraJmapTestRule rule = new CassandraJmapTestRule();

@Override
protected JmapJamesServer createJmapServer() {
return new JmapJamesServer()
.combineWith(CassandraJamesServerMain.cassandraServerModule)
.overrideWith(new CassandraJmapServerModule(temporaryFolder, embeddedElasticSearch, cassandra));
return rule.jmapServer();
}

@Override
protected void await() {
embeddedElasticSearch.awaitForElasticSearch();
rule.await();
}
}
Expand Up @@ -19,38 +19,25 @@

package org.apache.james.jmap.cassandra;

import org.apache.james.CassandraJamesServerMain;
import org.apache.james.CassandraJmapTestRule;
import org.apache.james.JmapJamesServer;
import org.apache.james.backends.cassandra.EmbeddedCassandra;
import org.apache.james.jmap.methods.integration.GetVacationResponseTest;
import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
import org.apache.james.modules.CassandraJmapServerModule;
import org.apache.james.util.date.ZonedDateTimeProvider;
import org.junit.Rule;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;

public class CassandraGetVacationResponseTest extends GetVacationResponseTest {

private TemporaryFolder temporaryFolder = new TemporaryFolder();
private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
private EmbeddedCassandra cassandra = EmbeddedCassandra.createStartServer();

@Rule
public RuleChain chain = RuleChain
.outerRule(temporaryFolder)
.around(embeddedElasticSearch);

@Rule
public CassandraJmapTestRule rule = new CassandraJmapTestRule();

@Override
protected JmapJamesServer createJmapServer(ZonedDateTimeProvider zonedDateTimeProvider) {
return new JmapJamesServer()
.combineWith(CassandraJamesServerMain.cassandraServerModule)
.overrideWith(new CassandraJmapServerModule(temporaryFolder, embeddedElasticSearch, cassandra),
binder -> binder.bind(ZonedDateTimeProvider.class).toInstance(zonedDateTimeProvider));
return rule.jmapServer()
.overrideWith(binder -> binder.bind(ZonedDateTimeProvider.class).toInstance(zonedDateTimeProvider));
}

@Override
protected void await() {
embeddedElasticSearch.awaitForElasticSearch();
rule.await();
}
}
Expand Up @@ -18,35 +18,22 @@
****************************************************************/
package org.apache.james.jmap.cassandra;

import org.apache.james.CassandraJamesServerMain;
import org.apache.james.CassandraJmapTestRule;
import org.apache.james.JmapJamesServer;
import org.apache.james.backends.cassandra.EmbeddedCassandra;
import org.apache.james.jmap.FixedDateZonedDateTimeProvider;
import org.apache.james.jmap.JMAPAuthenticationTest;
import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
import org.apache.james.modules.CassandraJmapServerModule;
import org.apache.james.util.date.ZonedDateTimeProvider;
import org.junit.Rule;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;

public class CassandraJmapAuthenticationTest extends JMAPAuthenticationTest {

private TemporaryFolder temporaryFolder = new TemporaryFolder();
private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
private EmbeddedCassandra cassandra = EmbeddedCassandra.createStartServer();

@Rule
public RuleChain chain = RuleChain
.outerRule(temporaryFolder)
.around(embeddedElasticSearch);

@Rule
public CassandraJmapTestRule rule = new CassandraJmapTestRule();

@Override
protected JmapJamesServer createJmapServer(FixedDateZonedDateTimeProvider zonedDateTimeProvider) {
return new JmapJamesServer()
.combineWith(CassandraJamesServerMain.cassandraServerModule)
.overrideWith(new CassandraJmapServerModule(temporaryFolder, embeddedElasticSearch, cassandra),
(binder) -> binder.bind(ZonedDateTimeProvider.class).toInstance(zonedDateTimeProvider));
return rule.jmapServer()
.overrideWith(binder -> binder.bind(ZonedDateTimeProvider.class).toInstance(zonedDateTimeProvider));
}

}

0 comments on commit 2a30769

Please sign in to comment.