Author: btellier Date: Mon Jun 22 08:19:39 2015 New Revision: 1686808 URL: http://svn.apache.org/r1686808 Log: MPT-16 Add Cyrus tests - contributed by Antoine Duprat
Added: james/mpt/trunk/impl/imap-mailbox/cyrus/ james/mpt/trunk/impl/imap-mailbox/cyrus/pom.xml james/mpt/trunk/impl/imap-mailbox/cyrus/src/ james/mpt/trunk/impl/imap-mailbox/cyrus/src/reporting-site/ james/mpt/trunk/impl/imap-mailbox/cyrus/src/reporting-site/site.xml james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTest.java james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTestModule.java james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusUserAdder.java james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/Docker.java Modified: james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/base/BaseAuthenticatedState.java james/mpt/trunk/impl/imap-mailbox/pom.xml Modified: james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/base/BaseAuthenticatedState.java URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/base/BaseAuthenticatedState.java?rev=1686808&r1=1686807&r2=1686808&view=diff ============================================================================== --- james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/base/BaseAuthenticatedState.java (original) +++ james/mpt/trunk/impl/imap-mailbox/core/src/main/java/org/apache/james/mpt/imapmailbox/suite/base/BaseAuthenticatedState.java Mon Jun 22 08:19:39 2015 @@ -79,7 +79,7 @@ public class BaseAuthenticatedState exte protected void addLogin(String username, String password) { preElements.CL("a001 LOGIN " + username + " " + password); - preElements.SL("a001 OK LOGIN completed.", - "AbstractTestForAuthenticatedState.java:53"); + preElements.SL("a001 OK .*", + "BaseAuthenticatedState.java:83"); } } Added: james/mpt/trunk/impl/imap-mailbox/cyrus/pom.xml URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/cyrus/pom.xml?rev=1686808&view=auto ============================================================================== --- james/mpt/trunk/impl/imap-mailbox/cyrus/pom.xml (added) +++ james/mpt/trunk/impl/imap-mailbox/cyrus/pom.xml Mon Jun 22 08:19:39 2015 @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<project + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <artifactId>apache-james-mpt-imapmailbox</artifactId> + <groupId>org.apache.james</groupId> + <version>0.2-SNAPSHOT</version> + </parent> + + <artifactId>apache-james-mpt-imapmailbox-cyrus</artifactId> + <name>Apache James MPT Imap Mailbox - Cyrus</name> + + <dependencies> + <dependency> + <groupId>com.spotify</groupId> + <artifactId>docker-client</artifactId> + <version>2.7.6</version> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> + <artifactId>apache-james-mpt-imapmailbox-core</artifactId> + </dependency> + </dependencies> +</project> + Added: james/mpt/trunk/impl/imap-mailbox/cyrus/src/reporting-site/site.xml URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/cyrus/src/reporting-site/site.xml?rev=1686808&view=auto ============================================================================== --- james/mpt/trunk/impl/imap-mailbox/cyrus/src/reporting-site/site.xml (added) +++ james/mpt/trunk/impl/imap-mailbox/cyrus/src/reporting-site/site.xml Mon Jun 22 08:19:39 2015 @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + 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. +--> +<project name="${project.name}"> + + <body> + + <menu ref="reports" /> + + </body> + +</project> Added: james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTest.java URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTest.java?rev=1686808&view=auto ============================================================================== --- james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTest.java (added) +++ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTest.java Mon Jun 22 08:19:39 2015 @@ -0,0 +1,33 @@ +package org.apache.james.mpt.imapmailbox.cyrus; + +import org.apache.onami.test.OnamiSuite; +import org.apache.onami.test.annotation.GuiceModules; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; + +@Ignore("JWC-156 create mailbox in Cyrus") +@RunWith(OnamiSuite.class) +@SuiteClasses({ +// AuthenticatedState.class, +// ConcurrentSessions.class, +// Events.class, +// Expunge.class, +// Fetch.class, +// FetchBodySection.class, +// FetchBodyStructure.class, +// FetchHeaders.class, +// Listing.class, +// NonAuthenticatedState.class, +// PartialFetch.class, +// Rename.class, +// Search.class, +// Security.class, +// Select.class, +// SelectedInbox.class, +// SelectedState.class, +// UidSearch.class +}) +@GuiceModules({CyrusMailboxTestModule.class}) +public class CyrusMailboxTest { +} Added: james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTestModule.java URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTestModule.java?rev=1686808&view=auto ============================================================================== --- james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTestModule.java (added) +++ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/CyrusMailboxTestModule.java Mon Jun 22 08:19:39 2015 @@ -0,0 +1,23 @@ +package org.apache.james.mpt.imapmailbox.cyrus; + +import org.apache.james.mpt.api.HostSystem; +import org.apache.james.mpt.api.UserAdder; +import org.apache.james.mpt.host.ExternalHostSystem; +import org.apache.james.mpt.imapmailbox.cyrus.host.CyrusHostSystem; +import org.apache.james.mpt.imapmailbox.cyrus.host.CyrusUserAdder; +import org.apache.james.mpt.imapmailbox.cyrus.host.Docker; + +import com.google.inject.AbstractModule; +import com.spotify.docker.client.messages.ContainerCreation; + +public class CyrusMailboxTestModule extends AbstractModule { + + @Override + protected void configure() { + bind(Docker.class).toInstance(new Docker("linagora/cyrus-imap")); + bind(ContainerCreation.class).toProvider(CyrusHostSystem.class); + bind(HostSystem.class).to(CyrusHostSystem.class); + bind(ExternalHostSystem.class).to(CyrusHostSystem.class); + bind(UserAdder.class).to(CyrusUserAdder.class); + } +} Added: james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java?rev=1686808&view=auto ============================================================================== --- james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java (added) +++ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusHostSystem.java Mon Jun 22 08:19:39 2015 @@ -0,0 +1,74 @@ +/**************************************************************** + * 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.mpt.imapmailbox.cyrus.host; + +import java.net.InetSocketAddress; + +import org.apache.james.mpt.api.UserAdder; +import org.apache.james.mpt.host.ExternalHostSystem; +import org.apache.james.mpt.monitor.NullMonitor; + +import com.google.common.base.Supplier; +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.google.inject.Singleton; +import com.spotify.docker.client.messages.ContainerCreation; + +@Singleton +public class CyrusHostSystem extends ExternalHostSystem implements Provider<ContainerCreation> { + + private static final String SHABANG = "* OK IMAP4rev1 Server ready"; + private final Docker docker; + private Supplier<InetSocketAddress> addressSupplier; + private ContainerCreation container; + + @Inject + private CyrusHostSystem(Docker docker, UserAdder userAdder) { + super(new NullMonitor(), SHABANG, userAdder); + this.docker = docker; + + } + + @Override + protected InetSocketAddress getAddress() { + return addressSupplier.get(); + } + + public void beforeTest() throws Exception { + container = docker.start(); + addressSupplier = new Supplier<InetSocketAddress>() { + + @Override + public InetSocketAddress get() { + return new InetSocketAddress(docker.getHost(container), docker.getIMAPPort(container)); + } + }; + } + + public void afterTest() throws Exception { + docker.stop(container); + container = null; + addressSupplier = null; + } + + @Override + public ContainerCreation get() { + return container; + } +} Added: james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusUserAdder.java URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusUserAdder.java?rev=1686808&view=auto ============================================================================== --- james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusUserAdder.java (added) +++ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/CyrusUserAdder.java Mon Jun 22 08:19:39 2015 @@ -0,0 +1,44 @@ +/**************************************************************** + * 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.mpt.imapmailbox.cyrus.host; + +import org.apache.james.mpt.api.UserAdder; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.google.inject.Singleton; +import com.spotify.docker.client.messages.ContainerCreation; + +@Singleton +public class CyrusUserAdder implements UserAdder { + + private final Provider<ContainerCreation> container; + private final Docker docker; + + @Inject + private CyrusUserAdder(Docker docker, Provider<ContainerCreation> container) { + this.docker = docker; + this.container = container; + } + + @Override + public void addUser(String user, String password) throws Exception { + this.docker.createUser(container.get(), user, password); + } +} \ No newline at end of file Added: james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/Docker.java URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/Docker.java?rev=1686808&view=auto ============================================================================== --- james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/Docker.java (added) +++ james/mpt/trunk/impl/imap-mailbox/cyrus/src/test/java/org/apache/james/mpt/imapmailbox/cyrus/host/Docker.java Mon Jun 22 08:19:39 2015 @@ -0,0 +1,106 @@ +/**************************************************************** + * 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.mpt.imapmailbox.cyrus.host; + +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.spotify.docker.client.DefaultDockerClient; +import com.spotify.docker.client.DockerException; +import com.spotify.docker.client.messages.ContainerConfig; +import com.spotify.docker.client.messages.ContainerCreation; +import com.spotify.docker.client.messages.HostConfig; + +public class Docker { + + private static final int IMAP_PORT = 143; + private static final String EXPOSED_IMAP_PORT = IMAP_PORT + "/tcp"; + private static final HostConfig ALL_PORTS_HOST_CONFIG = HostConfig.builder() + .publishAllPorts(true) + .build(); + + + private final DefaultDockerClient dockerClient; + private final ContainerConfig containerConfig; + + public Docker(String imageName) { + containerConfig = ContainerConfig.builder() + .image(imageName) + .networkDisabled(false) + .exposedPorts(ImmutableSet.of(EXPOSED_IMAP_PORT)) + .build(); + + dockerClient = new DefaultDockerClient(DefaultDockerClient.DEFAULT_UNIX_ENDPOINT); + + try { + dockerClient.pull(imageName); + } catch (DockerException e) { + throw Throwables.propagate(e); + } catch (InterruptedException e) { + throw Throwables.propagate(e); + } catch (Throwable e) { + throw Throwables.propagate(e); + } + } + + public ContainerCreation start() throws Exception { + ContainerCreation container = dockerClient.createContainer(containerConfig); + dockerClient.startContainer(container.id(), ALL_PORTS_HOST_CONFIG); + return container; + } + + public void stop(ContainerCreation container) { + try { + dockerClient.killContainer(container.id()); + dockerClient.removeContainer(container.id(), true); + } catch (DockerException e) { + Throwables.propagate(e); + } catch (InterruptedException e) { + Throwables.propagate(e); + } + } + + public String getHost(ContainerCreation container) { + return "localhost"; + } + + public int getIMAPPort(ContainerCreation container) { + try { + return Integer.valueOf( + Iterables.getOnlyElement( + dockerClient.inspectContainer( + container.id()) + .networkSettings() + .ports() + .get(EXPOSED_IMAP_PORT)) + .hostPort()); + } catch (NumberFormatException e) { + throw Throwables.propagate(e); + } catch (DockerException e) { + throw Throwables.propagate(e); + } catch (InterruptedException e) { + throw Throwables.propagate(e); } + } + + public void createUser(ContainerCreation container, String user, String password) throws DockerException, InterruptedException { + String createUserCommand = String.format("echo %s | saslpasswd2 -u test -c %s -p", password, user); + String execId = dockerClient.execCreate(container.id(), new String[] {"/bin/bash", "-c", createUserCommand}); + dockerClient.execStart(execId); + } +} Modified: james/mpt/trunk/impl/imap-mailbox/pom.xml URL: http://svn.apache.org/viewvc/james/mpt/trunk/impl/imap-mailbox/pom.xml?rev=1686808&r1=1686807&r2=1686808&view=diff ============================================================================== --- james/mpt/trunk/impl/imap-mailbox/pom.xml (original) +++ james/mpt/trunk/impl/imap-mailbox/pom.xml Mon Jun 22 08:19:39 2015 @@ -43,6 +43,7 @@ <module>jcr</module> <module>jpa</module> <module>maildir</module> + <module>cyrus</module> </modules> <dependencyManagement> @@ -89,6 +90,12 @@ <version>${project.version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mpt-imapmailbox-cyrus</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> </dependencies> </dependencyManagement> @@ -218,6 +225,26 @@ </includes> <excludes> <exclude>**/suite/*.java</exclude> + <exclude>**/suite/**/*.java</exclude> + </excludes> + </configuration> + </plugin> + </plugins> + </build> + </profile> + <profile> + <id>cyrus</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <includes> + <include>**/cyrus/**/*.java</include> + </includes> + <excludes> + <exclude>**/suite/*.java</exclude> <exclude>**/suite/**/*.java</exclude> </excludes> </configuration> --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org