james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [4/7] james-project git commit: JAMES-1983 Split WebAdmin to match orthogonal Guice architecture
Date Mon, 03 Apr 2017 08:34:27 GMT
http://git-wip-us.apache.org/repos/asf/james-project/blob/cca0f398/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/RandomPortTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/RandomPortTest.java b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/RandomPortTest.java
deleted file mode 100644
index 07d1996..0000000
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/RandomPortTest.java
+++ /dev/null
@@ -1,34 +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.webadmin;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.Test;
-
-public class RandomPortTest {
-
-    @Test
-    public void toIntShouldReturnTwoTimeTheSameResult() {
-        RandomPort testee = new RandomPort();
-        assertThat(testee.toInt()).isEqualTo(testee.toInt());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/cca0f398/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/TlsConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/TlsConfigurationTest.java b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/TlsConfigurationTest.java
deleted file mode 100644
index 2d93282..0000000
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/TlsConfigurationTest.java
+++ /dev/null
@@ -1,88 +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.webadmin;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import nl.jqno.equalsverifier.EqualsVerifier;
-
-public class TlsConfigurationTest {
-
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
-    @Test
-    public void buildShouldThrowWhenNotEnabled() {
-        expectedException.expect(IllegalStateException.class);
-
-        TlsConfiguration.builder().build();
-    }
-
-    @Test
-    public void buildShouldThrowWhenEnableWithoutKeystore() {
-        expectedException.expect(IllegalStateException.class);
-
-        TlsConfiguration.builder().build();
-    }
-
-    @Test
-    public void selfSignedShouldThrowOnNullKeyStorePath() {
-        expectedException.expect(NullPointerException.class);
-
-        TlsConfiguration.builder()
-            .selfSigned(null, "abc");
-    }
-
-    @Test
-    public void selfSignedShouldThrowOnNullKeyStorePassword() {
-        expectedException.expect(NullPointerException.class);
-
-        TlsConfiguration.builder()
-            .selfSigned("abc", null);
-    }
-
-    @Test
-    public void buildShouldWorkOnSelfSignedHttps() {
-        assertThat(
-            TlsConfiguration.builder()
-                .selfSigned("abcd", "efgh")
-                .build())
-            .isEqualTo(new TlsConfiguration("abcd", "efgh", null, null));
-    }
-
-    @Test
-    public void buildShouldWorkOnTrustedHttps() {
-        assertThat(
-            TlsConfiguration.builder()
-                .raw("a", "b", "c", "d")
-                .build())
-            .isEqualTo(new TlsConfiguration("a", "b", "c", "d"));
-    }
-
-    @Test
-    public void shouldRespectBeanContract() {
-        EqualsVerifier.forClass(TlsConfiguration.class).verify();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/cca0f398/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/WebAdminConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/WebAdminConfigurationTest.java b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/WebAdminConfigurationTest.java
deleted file mode 100644
index 1030dcf..0000000
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/WebAdminConfigurationTest.java
+++ /dev/null
@@ -1,181 +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.webadmin;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import nl.jqno.equalsverifier.EqualsVerifier;
-
-public class WebAdminConfigurationTest {
-
-    public static final FixedPort PORT = new FixedPort(80);
-
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
-    @Test
-    public void buildShouldThrowWhenNoPortButEnabled() {
-        expectedException.expect(IllegalStateException.class);
-
-        WebAdminConfiguration.builder().enabled().build();
-    }
-
-    @Test
-    public void buildShouldWorkWithoutPortWhenDisabled() {
-        assertThat(WebAdminConfiguration.builder()
-            .disabled()
-            .build())
-            .extracting(WebAdminConfiguration::isEnabled)
-            .containsExactly(false);
-    }
-
-    @Test
-    public void buildShouldFailOnNoEnable() {
-        expectedException.expect(IllegalStateException.class);
-
-        WebAdminConfiguration.builder().port(PORT).build();
-    }
-
-    @Test
-    public void builderShouldBuildWithRightPort() {
-        assertThat(
-            WebAdminConfiguration.builder()
-                .enabled()
-                .port(PORT)
-                .build())
-            .extracting(WebAdminConfiguration::getPort)
-            .containsExactly(PORT);
-    }
-
-
-    @Test
-    public void builderShouldBuildWithEnable() {
-        assertThat(
-            WebAdminConfiguration.builder()
-                .enabled()
-                .port(PORT)
-                .build())
-            .extracting(WebAdminConfiguration::isEnabled)
-            .containsExactly(true);
-    }
-
-    @Test
-    public void builderShouldAcceptHttps() {
-        TlsConfiguration tlsConfiguration = TlsConfiguration.builder()
-            .selfSigned("abcd", "efgh")
-            .build();
-
-        assertThat(
-            WebAdminConfiguration.builder()
-                .enabled()
-                .tls(tlsConfiguration)
-                .port(PORT)
-                .build())
-            .extracting(WebAdminConfiguration::getTlsConfiguration)
-            .containsExactly(tlsConfiguration);
-    }
-
-    @Test
-    public void builderShouldReturnTlsEnableWhenTlsConfiguration() {
-        TlsConfiguration tlsConfiguration = TlsConfiguration.builder()
-            .selfSigned("abcd", "efgh")
-            .build();
-
-        assertThat(
-            WebAdminConfiguration.builder()
-                .enabled()
-                .tls(tlsConfiguration)
-                .port(PORT)
-                .build())
-            .extracting(WebAdminConfiguration::getTlsConfiguration)
-            .containsExactly(tlsConfiguration);
-    }
-
-    @Test
-    public void builderShouldReturnTlsDisableWhenNoTlsConfiguration() {
-        assertThat(
-            WebAdminConfiguration.builder()
-                .enabled()
-                .port(PORT)
-                .build())
-            .extracting(WebAdminConfiguration::isTlsEnabled)
-            .containsExactly(false);
-    }
-
-    @Test
-    public void builderShouldCORSEnabled() {
-        assertThat(
-            WebAdminConfiguration.builder()
-                .enabled()
-                .port(PORT)
-                .CORSenabled()
-                .build())
-            .extracting(WebAdminConfiguration::isEnableCORS)
-            .containsExactly(true);
-    }
-
-    @Test
-    public void builderShouldAcceptAllOriginsByDefault() {
-        assertThat(
-            WebAdminConfiguration.builder()
-                .enabled()
-                .port(PORT)
-                .CORSenabled()
-                .build())
-            .extracting(WebAdminConfiguration::getUrlCORSOrigin)
-            .containsExactly("*");
-    }
-
-    @Test
-    public void builderShouldCORSDisabled() {
-        assertThat(
-            WebAdminConfiguration.builder()
-                .enabled()
-                .port(PORT)
-                .CORSdisabled()
-                .build())
-            .extracting(WebAdminConfiguration::isEnableCORS)
-            .containsExactly(false);
-    }
-
-    @Test
-    public void builderShouldCORSWithOrigin() {
-        String origin = "linagora.com";
-        assertThat(
-            WebAdminConfiguration.builder()
-                .enabled()
-                .port(PORT)
-                .CORSenabled()
-                .urlCORSOrigin(origin)
-                .build())
-            .extracting(WebAdminConfiguration::getUrlCORSOrigin)
-            .containsExactly(origin);
-    }
-
-    @Test
-    public void shouldMatchBeanContract() {
-        EqualsVerifier.forClass(WebAdminConfiguration.class).verify();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/cca0f398/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/authentication/JwtFilterTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/authentication/JwtFilterTest.java b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/authentication/JwtFilterTest.java
deleted file mode 100644
index 6512ddb..0000000
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/authentication/JwtFilterTest.java
+++ /dev/null
@@ -1,124 +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.webadmin.authentication;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.apache.james.jwt.JwtTokenVerifier;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import com.google.common.collect.ImmutableSet;
-
-import spark.HaltException;
-import spark.Request;
-import spark.Response;
-
-public class JwtFilterTest {
-
-    public static final Matcher<HaltException> STATUS_CODE_MATCHER_401 = new BaseMatcher<HaltException>() {
-        @Override
-        public boolean matches(Object o) {
-            if (o instanceof HaltException) {
-                HaltException haltException = (HaltException) o;
-                return haltException.statusCode() == 401;
-            }
-            return false;
-        }
-
-        @Override
-        public void describeTo(Description description) {}
-    };
-
-    private JwtTokenVerifier jwtTokenVerifier;
-    private JwtFilter jwtFilter;
-
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
-    @Before
-    public void setUp() {
-        jwtTokenVerifier = mock(JwtTokenVerifier.class);
-        jwtFilter = new JwtFilter(jwtTokenVerifier);
-    }
-
-    @Test
-    public void handleShouldRejectRequestWithHeaders() throws Exception {
-        Request request = mock(Request.class);
-        when(request.headers()).thenReturn(ImmutableSet.of());
-
-        expectedException.expect(HaltException.class);
-        expectedException.expect(STATUS_CODE_MATCHER_401);
-
-        jwtFilter.handle(request, mock(Response.class));
-    }
-
-    @Test
-    public void handleShouldRejectRequestWithBearersHeaders() throws Exception {
-        Request request = mock(Request.class);
-        when(request.headers(JwtFilter.AUTHORIZATION_HEADER_NAME)).thenReturn("Invalid value");
-
-        expectedException.expect(HaltException.class);
-        expectedException.expect(STATUS_CODE_MATCHER_401);
-
-        jwtFilter.handle(request, mock(Response.class));
-    }
-
-    @Test
-    public void handleShouldRejectRequestWithInvalidBearerHeaders() throws Exception {
-        Request request = mock(Request.class);
-        when(request.headers(JwtFilter.AUTHORIZATION_HEADER_NAME)).thenReturn("Bearer value");
-        when(jwtTokenVerifier.verify("value")).thenReturn(false);
-
-        expectedException.expect(HaltException.class);
-        expectedException.expect(STATUS_CODE_MATCHER_401);
-
-        jwtFilter.handle(request, mock(Response.class));
-    }
-
-    @Test
-    public void handleShouldRejectRequestWithoutAdminClaim() throws Exception {
-        Request request = mock(Request.class);
-        when(request.headers(JwtFilter.AUTHORIZATION_HEADER_NAME)).thenReturn("Bearer value");
-        when(jwtTokenVerifier.verify("value")).thenReturn(true);
-        when(jwtTokenVerifier.hasAttribute("admin", true, "value")).thenReturn(false);
-
-        expectedException.expect(HaltException.class);
-        expectedException.expect(STATUS_CODE_MATCHER_401);
-
-        jwtFilter.handle(request, mock(Response.class));
-    }
-
-    @Test
-    public void handleShouldAcceptValidJwt() throws Exception {
-        Request request = mock(Request.class);
-        when(request.headers(JwtFilter.AUTHORIZATION_HEADER_NAME)).thenReturn("Bearer value");
-        when(jwtTokenVerifier.verify("value")).thenReturn(true);
-        when(jwtTokenVerifier.hasAttribute("admin", true, "value")).thenReturn(true);
-
-        jwtFilter.handle(request, mock(Response.class));
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/cca0f398/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/dto/QuotaRequestTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/dto/QuotaRequestTest.java b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/dto/QuotaRequestTest.java
deleted file mode 100644
index 34df209..0000000
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/dto/QuotaRequestTest.java
+++ /dev/null
@@ -1,59 +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.webadmin.dto;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-public class QuotaRequestTest {
-
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
-    @Test
-    public void parseShouldThrowWhenNotANumber() {
-        expectedException.expect(NumberFormatException.class);
-
-        QuotaRequest.parse("invalid");
-    }
-
-    @Test
-    public void parseShouldThrowOnNegativeNumber() {
-        expectedException.expect(IllegalArgumentException.class);
-
-        QuotaRequest.parse("-1");
-    }
-
-    @Test
-    public void parseShouldParseZero() {
-        assertThat(QuotaRequest.parse("0").getValue())
-            .isEqualTo(0);
-    }
-
-    @Test
-    public void parseShouldParsePositiveValue() {
-        assertThat(QuotaRequest.parse("42").getValue())
-            .isEqualTo(42);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/cca0f398/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/DomainRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/DomainRoutesTest.java b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/DomainRoutesTest.java
deleted file mode 100644
index 1df89d2..0000000
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/DomainRoutesTest.java
+++ /dev/null
@@ -1,326 +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.webadmin.routes;
-
-import static com.jayway.restassured.RestAssured.given;
-import static com.jayway.restassured.RestAssured.when;
-import static com.jayway.restassured.RestAssured.with;
-import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
-import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
-import static org.apache.james.webadmin.Constants.SEPARATOR;
-import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.is;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.net.InetAddress;
-
-import org.apache.james.dnsservice.api.DNSService;
-import org.apache.james.domainlist.api.DomainList;
-import org.apache.james.domainlist.api.DomainListException;
-import org.apache.james.domainlist.memory.MemoryDomainList;
-import org.apache.james.metrics.logger.DefaultMetricFactory;
-import org.apache.james.webadmin.WebAdminServer;
-import org.apache.james.webadmin.utils.JsonTransformer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Charsets;
-import com.jayway.restassured.RestAssured;
-import com.jayway.restassured.builder.RequestSpecBuilder;
-import com.jayway.restassured.http.ContentType;
-
-import de.bechte.junit.runners.context.HierarchicalContextRunner;
-
-@RunWith(HierarchicalContextRunner.class)
-public class DomainRoutesTest {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(DomainRoutesTest.class);
-    public static final String DOMAIN = "domain";
-
-    private WebAdminServer webAdminServer;
-
-    private void createServer(DomainList domainList) throws Exception {
-        webAdminServer = new WebAdminServer(
-            new DefaultMetricFactory(),
-            new DomainRoutes(domainList, new JsonTransformer()));
-        webAdminServer.configure(NO_CONFIGURATION);
-        webAdminServer.await();
-
-        RestAssured.requestSpecification = new RequestSpecBuilder()
-        		.setContentType(ContentType.JSON)
-        		.setAccept(ContentType.JSON)
-        		.setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
-        		.setPort(webAdminServer.getPort().toInt())
-        		.setBasePath(DomainRoutes.DOMAINS)
-        		.build();
-
-    }
-
-    @After
-    public void stop() {
-        webAdminServer.destroy();
-    }
-
-    public class NormalBehaviour {
-
-        @Before
-        public void setUp() throws Exception {
-            DNSService dnsService = mock(DNSService.class);
-            when(dnsService.getHostName(any())).thenReturn("localhost");
-            when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("localhost"));
-
-            MemoryDomainList domainList = new MemoryDomainList();
-            domainList.setDNSService(dnsService);
-            domainList.setLog(LOGGER);
-            domainList.setAutoDetectIP(false);
-            createServer(domainList);
-        }
-
-        @Test
-        public void getDomainsShouldBeEmptyByDefault() {
-            given()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(is("[]"));
-        }
-
-        @Test
-        public void putShouldReturnErrorWhenUsedWithEmptyDomain() {
-            given()
-                .put(SEPARATOR)
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void deleteShouldReturnErrorWhenUsedWithEmptyDomain() {
-            given()
-                .delete(SEPARATOR)
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void putShouldBeOk() {
-            given()
-                .put(DOMAIN)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void getDomainsShouldDisplayAddedDomains() {
-            with()
-                .put(DOMAIN);
-
-            when()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(containsString(DOMAIN));
-        }
-
-        @Test
-        public void putShouldReturnUserErrorWhenNameContainsAT() {
-            when()
-                .put(DOMAIN + "@" + DOMAIN)
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void putShouldReturnUserErrorWhenNameContainsUrlSeparator() {
-            when()
-                .put(DOMAIN + "/" + DOMAIN)
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void putShouldReturnUserErrorWhenNameIsTooLong() {
-            when()
-                .put(DOMAIN + "0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789." +
-                    "0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789." +
-                    "0123456789.0123456789.0123456789.")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void putShouldWorkOnTheSecondTimeForAGivenValue() {
-            with()
-                .put(DOMAIN);
-
-            when()
-                .put(DOMAIN)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void deleteShouldRemoveTheGivenDomain() {
-            with()
-                .put(DOMAIN);
-
-            when()
-                .delete(DOMAIN)
-            .then()
-                .statusCode(204);
-
-            when()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(is("[]"));
-        }
-
-        @Test
-        public void deleteShouldBeOkWhenTheDomainIsNotPresent() {
-            given()
-                .delete(DOMAIN)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void getDomainShouldReturnOkWhenTheDomainIsPresent() {
-            with()
-                .put(DOMAIN);
-
-            when()
-                .get(DOMAIN)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void getDomainShouldReturnNotFoundWhenTheDomainIsAbsent() {
-            given()
-                .get(DOMAIN)
-            .then()
-                .statusCode(404);
-        }
-
-    }
-
-    public class ExceptionHandling {
-
-        private DomainList domainList;
-        private String domain;
-
-        @Before
-        public void setUp() throws Exception {
-            domainList = mock(DomainList.class);
-            createServer(domainList);
-            domain = "domain";
-        }
-
-        @Test
-        public void deleteShouldReturnErrorOnUnknownException() throws Exception {
-            doThrow(new RuntimeException()).when(domainList).removeDomain(domain);
-
-            when()
-                .delete(DOMAIN)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void putShouldReturnErrorOnUnknownException() throws Exception {
-            doThrow(new RuntimeException()).when(domainList).addDomain(domain);
-
-            when()
-                .put(DOMAIN)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void getDomainShouldReturnErrorOnUnknownException() throws Exception {
-            when(domainList.containsDomain(domain)).thenThrow(new RuntimeException());
-
-            when()
-                .get(DOMAIN)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void getDomainsShouldReturnErrorOnUnknownException() throws Exception {
-            when(domainList.getDomains()).thenThrow(new RuntimeException());
-
-            when()
-                .get()
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void deleteShouldReturnOkWhenDomainListException() throws Exception {
-            doThrow(new DomainListException("message")).when(domainList).removeDomain(domain);
-
-            when()
-                .delete(DOMAIN)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void putShouldReturnOkWhenDomainListException() throws Exception {
-            doThrow(new DomainListException("message")).when(domainList).addDomain(domain);
-
-            when()
-                .put(DOMAIN)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void getDomainShouldReturnErrorOnDomainListException() throws Exception {
-            when(domainList.containsDomain(domain)).thenThrow(new DomainListException("message"));
-
-            when()
-                .get(DOMAIN)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void getDomainsShouldReturnErrorOnDomainListException() throws Exception {
-            when(domainList.getDomains()).thenThrow(new DomainListException("message"));
-
-            when()
-                .get()
-            .then()
-                .statusCode(500);
-        }
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/cca0f398/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java
deleted file mode 100644
index 16a9d3e..0000000
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/GlobalQuotaRoutesTest.java
+++ /dev/null
@@ -1,261 +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.webadmin.routes;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static com.jayway.restassured.RestAssured.given;
-import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
-import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
-import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
-import static org.hamcrest.CoreMatchers.is;
-
-import org.apache.james.mailbox.inmemory.quota.InMemoryPerUserMaxQuotaManager;
-import org.apache.james.mailbox.model.Quota;
-import org.apache.james.metrics.logger.DefaultMetricFactory;
-import org.apache.james.webadmin.WebAdminServer;
-import org.apache.james.webadmin.utils.JsonTransformer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.base.Charsets;
-import com.jayway.restassured.RestAssured;
-import com.jayway.restassured.builder.RequestSpecBuilder;
-import com.jayway.restassured.http.ContentType;
-
-public class GlobalQuotaRoutesTest {
-
-    private WebAdminServer webAdminServer;
-    private InMemoryPerUserMaxQuotaManager maxQuotaManager;
-
-    @Before
-    public void setUp() throws Exception {
-        maxQuotaManager = new InMemoryPerUserMaxQuotaManager();
-        webAdminServer = new WebAdminServer(
-            new DefaultMetricFactory(),
-            new GlobalQuotaRoutes(maxQuotaManager, new JsonTransformer()));
-        webAdminServer.configure(NO_CONFIGURATION);
-        webAdminServer.await();
-
-        RestAssured.requestSpecification = new RequestSpecBuilder()
-            .setContentType(ContentType.JSON)
-            .setAccept(ContentType.JSON)
-            .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
-            .setPort(webAdminServer.getPort().toInt())
-            .build();
-    }
-
-    @After
-    public void stop() {
-        webAdminServer.destroy();
-    }
-
-    @Test
-    public void getCountQuotaCountShouldReturnUnlimitedByDefault() {
-        given()
-            .get(GlobalQuotaRoutes.COUNT_ENDPOINT)
-        .then()
-            .statusCode(200)
-            .body(is(String.valueOf(Quota.UNLIMITED)));
-    }
-
-    @Test
-    public void getCountShouldReturnStoredValue() throws Exception{
-        int value = 42;
-        maxQuotaManager.setDefaultMaxMessage(value);
-
-        given()
-            .get(GlobalQuotaRoutes.COUNT_ENDPOINT)
-        .then()
-            .statusCode(200)
-            .body(is(String.valueOf(value)));
-    }
-
-    @Test
-    public void putCountShouldRejectInvalid() throws Exception {
-        given()
-            .body("invalid")
-            .put(GlobalQuotaRoutes.COUNT_ENDPOINT)
-        .then()
-            .statusCode(400);
-    }
-
-    @Test
-    public void putCountShouldRejectNegative() throws Exception {
-        given()
-            .body("-1")
-            .put(GlobalQuotaRoutes.COUNT_ENDPOINT)
-        .then()
-            .statusCode(400);
-    }
-
-    @Test
-    public void putCountShouldAcceptValidValue() throws Exception {
-        given()
-            .body("42")
-            .put(GlobalQuotaRoutes.COUNT_ENDPOINT)
-        .then()
-            .statusCode(204);
-
-        assertThat(maxQuotaManager.getDefaultMaxMessage()).isEqualTo(42);
-    }
-
-    @Test
-    public void deleteCountShouldSetQuotaToUnlimited() throws Exception {
-        maxQuotaManager.setDefaultMaxMessage(42);
-
-        given()
-            .delete(GlobalQuotaRoutes.COUNT_ENDPOINT)
-        .then()
-            .statusCode(204);
-
-        assertThat(maxQuotaManager.getDefaultMaxMessage()).isEqualTo(Quota.UNLIMITED);
-    }
-
-    @Test
-    public void getSizeQuotaCountShouldReturnUnlimitedByDefault() {
-        given()
-            .get(GlobalQuotaRoutes.SIZE_ENDPOINT)
-        .then()
-            .statusCode(200)
-            .body(is(String.valueOf(Quota.UNLIMITED)));
-    }
-
-    @Test
-    public void getSizeShouldReturnStoredValue() throws Exception{
-        int value = 42;
-        maxQuotaManager.setDefaultMaxStorage(value);
-
-        given()
-            .get(GlobalQuotaRoutes.SIZE_ENDPOINT)
-        .then()
-            .statusCode(200)
-            .body(is(String.valueOf(value)));
-    }
-
-    @Test
-    public void putSizeShouldRejectInvalid() throws Exception {
-        given()
-            .body("invalid")
-            .put(GlobalQuotaRoutes.SIZE_ENDPOINT)
-        .then()
-            .statusCode(400);
-    }
-
-    @Test
-    public void putSizeShouldRejectNegative() throws Exception {
-        given()
-            .body("-1")
-            .put(GlobalQuotaRoutes.SIZE_ENDPOINT)
-        .then()
-            .statusCode(400);
-    }
-
-    @Test
-    public void putSizeShouldAcceptValidValue() throws Exception {
-        given()
-            .body("42")
-            .put(GlobalQuotaRoutes.SIZE_ENDPOINT)
-        .then()
-            .statusCode(204);
-
-        assertThat(maxQuotaManager.getDefaultMaxStorage()).isEqualTo(42);
-    }
-
-    @Test
-    public void deleteSizeShouldSetQuotaToUnlimited() throws Exception {
-        maxQuotaManager.setDefaultMaxStorage(42);
-
-        given()
-            .delete(GlobalQuotaRoutes.COUNT_ENDPOINT)
-        .then()
-            .statusCode(204);
-
-        assertThat(maxQuotaManager.getDefaultMaxMessage()).isEqualTo(Quota.UNLIMITED);
-    }
-
-    @Test
-    public void getQuotaShouldReturnBothWhenValueSpecified() throws Exception {
-        maxQuotaManager.setDefaultMaxStorage(42);
-        maxQuotaManager.setDefaultMaxMessage(52);
-
-        given()
-            .get(GlobalQuotaRoutes.QUOTA_ENDPOINT)
-        .then()
-            .statusCode(200)
-            .body(is("{\"count\":52,\"size\":42}"));
-    }
-
-    @Test
-    public void getQuotaShouldReturnBothDefaultValues() throws Exception {
-        given()
-            .get(GlobalQuotaRoutes.QUOTA_ENDPOINT)
-        .then()
-            .statusCode(200)
-            .body(is("{\"count\":-1,\"size\":-1}"));
-    }
-
-    @Test
-    public void getQuotaShouldReturnBothWhenNoCount() throws Exception {
-        maxQuotaManager.setDefaultMaxStorage(42);
-
-        given()
-            .get(GlobalQuotaRoutes.QUOTA_ENDPOINT)
-        .then()
-            .statusCode(200)
-            .body(is("{\"count\":-1,\"size\":42}"));
-    }
-
-    @Test
-    public void getQuotaShouldReturnBothWhenNoSize() throws Exception {
-        maxQuotaManager.setDefaultMaxMessage(42);
-
-        given()
-            .get(GlobalQuotaRoutes.QUOTA_ENDPOINT)
-        .then()
-            .statusCode(200)
-            .body(is("{\"count\":42,\"size\":-1}"));
-    }
-
-    @Test
-    public void putQuotaShouldUpdateBothQuota() throws Exception {
-        given()
-            .body("{\"count\":52,\"size\":42}")
-            .put(GlobalQuotaRoutes.QUOTA_ENDPOINT)
-        .then()
-            .statusCode(204);
-
-        assertThat(maxQuotaManager.getDefaultMaxMessage()).isEqualTo(52);
-        assertThat(maxQuotaManager.getDefaultMaxStorage()).isEqualTo(42);
-    }
-
-    @Test
-    public void putQuotaShouldBeAbleToRemoveBothQuota() throws Exception {
-        given()
-            .body("{\"count\":-1,\"size\":-1}")
-            .put(GlobalQuotaRoutes.QUOTA_ENDPOINT)
-        .then()
-            .statusCode(204);
-
-        assertThat(maxQuotaManager.getDefaultMaxMessage()).isEqualTo(Quota.UNLIMITED);
-        assertThat(maxQuotaManager.getDefaultMaxStorage()).isEqualTo(Quota.UNLIMITED);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/cca0f398/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
deleted file mode 100644
index 3db15b1..0000000
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UserMailboxesRoutesTest.java
+++ /dev/null
@@ -1,779 +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.webadmin.routes;
-
-import static com.jayway.restassured.RestAssured.when;
-import static com.jayway.restassured.RestAssured.with;
-import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
-import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
-import static org.apache.james.webadmin.Constants.SEPARATOR;
-import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
-import static org.hamcrest.CoreMatchers.is;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
-import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.exception.MailboxExistsException;
-import org.apache.james.mailbox.exception.MailboxNotFoundException;
-import org.apache.james.mailbox.inmemory.InMemoryId;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
-import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MailboxQuery;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.store.FakeAuthorizator;
-import org.apache.james.mailbox.store.JVMMailboxPathLocker;
-import org.apache.james.mailbox.store.SimpleMailboxMetaData;
-import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
-import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-import org.apache.james.metrics.logger.DefaultMetricFactory;
-import org.apache.james.user.api.UsersRepository;
-import org.apache.james.webadmin.WebAdminServer;
-import org.apache.james.webadmin.service.UserMailboxesService;
-import org.apache.james.webadmin.utils.JsonTransformer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import com.google.common.base.Charsets;
-import com.google.common.collect.ImmutableList;
-import com.jayway.restassured.RestAssured;
-import com.jayway.restassured.builder.RequestSpecBuilder;
-import com.jayway.restassured.http.ContentType;
-
-import de.bechte.junit.runners.context.HierarchicalContextRunner;
-
-@RunWith(HierarchicalContextRunner.class)
-public class UserMailboxesRoutesTest {
-
-    public static final String USERNAME = "username";
-    public static final String MAILBOX_NAME = "myMailboxName";
-    private WebAdminServer webAdminServer;
-    private UsersRepository usersRepository;
-
-    private void createServer(MailboxManager mailboxManager) throws Exception {
-        usersRepository = mock(UsersRepository.class);
-        when(usersRepository.contains(USERNAME)).thenReturn(true);
-
-        webAdminServer = new WebAdminServer(
-            new DefaultMetricFactory(),
-            new UserMailboxesRoutes(new UserMailboxesService(mailboxManager, usersRepository), new JsonTransformer()));
-        webAdminServer.configure(NO_CONFIGURATION);
-        webAdminServer.await();
-
-        RestAssured.requestSpecification = new RequestSpecBuilder()
-        		.setContentType(ContentType.JSON)
-        		.setAccept(ContentType.JSON)
-        		.setBasePath(UserRoutes.USERS + SEPARATOR + USERNAME + SEPARATOR + UserMailboxesRoutes.MAILBOXES)
-        		.setPort(webAdminServer.getPort().toInt())
-        		.setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
-        		.build();
-    }
-
-    @After
-    public void tearDown() {
-        webAdminServer.destroy();
-    }
-
-    public class NormalBehaviour {
-
-        @Before
-        public void setUp() throws Exception {
-            MessageId.Factory messageIdFactory = new DefaultMessageId.Factory();
-            InMemoryMailboxManager mailboxManager = new InMemoryMailboxManager(new InMemoryMailboxSessionMapperFactory(),
-                (userid, passwd) -> true,
-                FakeAuthorizator.defaultReject(),
-                new JVMMailboxPathLocker(),
-                new UnionMailboxACLResolver(),
-                new SimpleGroupMembershipResolver(),
-                new MessageParser(),
-                messageIdFactory);
-            mailboxManager.init();
-
-            createServer(mailboxManager);
-        }
-
-        @Test
-        public void getMailboxesShouldUserErrorFoundWithNonExistingUser() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .get()
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void getShouldReturnNotFoundWithNonExistingUser() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .get(MAILBOX_NAME)
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void putShouldReturnNotFoundWithNonExistingUser() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .put(MAILBOX_NAME)
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void deleteShouldReturnNotFoundWithNonExistingUser() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .put(MAILBOX_NAME)
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void getShouldReturnUserErrorWithInvalidWildcardMailboxName() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .get(MAILBOX_NAME + "*")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void putShouldReturnUserErrorWithInvalidWildcardMailboxName() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .put(MAILBOX_NAME+ "*")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void deleteShouldReturnUserErrorWithInvalidWildcardMailboxName() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .put(MAILBOX_NAME + "*")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void getShouldReturnUserErrorWithInvalidPercentMailboxName() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .get(MAILBOX_NAME + "%")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void putShouldReturnUserErrorWithInvalidPercentMailboxName() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .put(MAILBOX_NAME+ "%")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void deleteShouldReturnUserErrorWithInvalidPercentMailboxName() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .put(MAILBOX_NAME + "%")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void getShouldReturnUserErrorWithInvalidSharpMailboxName() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .get(MAILBOX_NAME + "#")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void putShouldReturnUserErrorWithInvalidSharpMailboxName() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .put(MAILBOX_NAME+ "#")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void deleteShouldReturnUserErrorWithInvalidSharpMailboxName() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .put(MAILBOX_NAME + "#")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void getShouldReturnUserErrorWithInvalidAndMailboxName() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .get(MAILBOX_NAME + "&")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void putShouldReturnUserErrorWithInvalidAndMailboxName() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .put(MAILBOX_NAME+ "&")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void deleteShouldReturnUserErrorWithInvalidAndMailboxName() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .put(MAILBOX_NAME + "&")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void deleteMailboxesShouldReturnUserErrorWithNonExistingUser() throws Exception {
-            when(usersRepository.contains(USERNAME)).thenReturn(false);
-
-            when()
-                .delete()
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void getMailboxesShouldReturnEmptyListByDefault() {
-            when()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(is("[]"));
-        }
-
-        @Test
-        public void putShouldReturnNotFoundWhenNoMailboxName() {
-            when()
-                .put()
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void putShouldReturnNotFoundWhenJustSeparator() {
-            when()
-                .put(SEPARATOR)
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void putShouldReturnOk() {
-            when()
-                .put(MAILBOX_NAME)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void putShouldReturnOkWhenIssuedTwoTimes() {
-            with()
-                .put(MAILBOX_NAME);
-
-            when()
-                .put(MAILBOX_NAME)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void putShouldAddAMailbox() {
-            with()
-                .put(MAILBOX_NAME);
-
-            when()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(is("[{\"mailboxName\":\"myMailboxName\"}]"));
-        }
-
-        @Test
-        public void getShouldReturnNotFoundWhenMailboxDoesNotExist() {
-            when()
-                .get(MAILBOX_NAME)
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void getShouldReturnOkWhenMailboxExists() {
-            with()
-                .put(MAILBOX_NAME);
-
-            when()
-                .get(MAILBOX_NAME)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void deleteShouldReturnOkWhenMailboxDoesNotExist() {
-            when()
-                .delete(MAILBOX_NAME)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void deleteShouldReturnOkWhenMailboxExists() {
-            with()
-                .put(MAILBOX_NAME);
-
-            when()
-                .delete(MAILBOX_NAME)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void deleteShouldRemoveMailbox() {
-            with()
-                .put(MAILBOX_NAME);
-
-            with()
-                .delete(MAILBOX_NAME);
-
-            when()
-                .get(MAILBOX_NAME)
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void deleteMailboxesShouldReturnOkWhenNoMailboxes() {
-            when()
-                .delete()
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void deleteMailboxesShouldReturnOkWhenMailboxes() {
-            with()
-                .put(MAILBOX_NAME);
-
-            when()
-                .delete()
-                .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void deleteMailboxesShouldRemoveAllUserMailboxes() {
-            with()
-                .put(MAILBOX_NAME);
-
-            with()
-                .put("otherMailbox");
-
-            with()
-                .delete();
-
-            when()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(is("[]"));
-        }
-
-        @Test
-        public void deleteShouldReturnOkWhenMailboxHasChildren() {
-            with()
-                .put(MAILBOX_NAME);
-
-            with()
-                .put(MAILBOX_NAME + ".child");
-
-            when()
-                .delete(MAILBOX_NAME)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void deleteShouldDeleteAMailboxAndItsChildren() {
-            with()
-                .put(MAILBOX_NAME);
-
-            with()
-                .put(MAILBOX_NAME + ".child");
-
-            with()
-                .delete(MAILBOX_NAME);
-
-            when()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(is("[]"));
-        }
-
-        @Test
-        public void deleteShouldNotDeleteUnrelatedMailbox() {
-            String mailboxName = MAILBOX_NAME + "!child";
-            with()
-                .put(MAILBOX_NAME);
-
-            with()
-                .put(mailboxName);
-
-            with()
-                .delete(MAILBOX_NAME);
-
-            when()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(is("[{\"mailboxName\":\"" + mailboxName + "\"}]"));
-        }
-
-        @Test
-        public void deleteShouldReturnOkWhenDeletingChildMailboxes() {
-            with()
-                .put(MAILBOX_NAME);
-
-            with()
-                .put(MAILBOX_NAME + ".child");
-
-            when()
-                .delete(MAILBOX_NAME + ".child")
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void deleteShouldBeAbleToRemoveChildMailboxes() {
-            with()
-                .put(MAILBOX_NAME);
-
-            with()
-                .put(MAILBOX_NAME + ".child");
-
-            with()
-                .delete(MAILBOX_NAME + ".child");
-
-            when()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(is("[{\"mailboxName\":\"myMailboxName\"}]"));
-        }
-    }
-
-    public class ExceptionHandling {
-
-        private MailboxManager mailboxManager;
-
-        @Before
-        public void setUp() throws Exception {
-            mailboxManager = mock(MailboxManager.class);
-            when(mailboxManager.createSystemSession(any(), any())).thenReturn(mock(MailboxSession.class));
-
-            createServer(mailboxManager);
-        }
-
-        @Test
-        public void putShouldGenerateInternalErrorOnUnknownException() throws Exception {
-            doThrow(new RuntimeException()).when(mailboxManager).createMailbox(any(), any());
-
-            when()
-                .put(MAILBOX_NAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void putShouldGenerateInternalErrorOnUnknownMailboxException() throws Exception {
-            doThrow(new MailboxException()).when(mailboxManager).createMailbox(any(), any());
-
-            when()
-                .put(MAILBOX_NAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void putShouldReturnOkOnMailboxExists() throws Exception {
-            doThrow(new MailboxExistsException(MAILBOX_NAME)).when(mailboxManager).createMailbox(any(), any());
-
-            when()
-                .put(MAILBOX_NAME)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void deleteShouldGenerateInternalErrorOnUnknownExceptionOnDelete() throws Exception {
-            MailboxId mailboxId = InMemoryId.of(12);
-            when(mailboxManager.search(any(MailboxQuery.class), any()))
-                .thenReturn(
-                        ImmutableList.of(
-                                new SimpleMailboxMetaData(
-                                        new MailboxPath("#private", USERNAME, MAILBOX_NAME), mailboxId, '.')));
-            doThrow(new RuntimeException()).when(mailboxManager).deleteMailbox(any(), any());
-
-            when()
-                .delete(MAILBOX_NAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void deleteShouldGenerateInternalErrorOnUnknownExceptionOnSearch() throws Exception {
-            when(mailboxManager.search(any(MailboxQuery.class), any())).thenThrow(new RuntimeException());
-
-            when()
-                .delete(MAILBOX_NAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void deleteShouldGenerateInternalErrorOnUnknownMailboxExceptionOnDelete() throws Exception {
-            MailboxId mailboxId = InMemoryId.of(12);
-            when(mailboxManager.search(any(MailboxQuery.class), any()))
-                .thenReturn(
-                        ImmutableList.of(
-                                new SimpleMailboxMetaData(new MailboxPath("#private", USERNAME, MAILBOX_NAME), mailboxId, '.')));
-            doThrow(new MailboxException()).when(mailboxManager).deleteMailbox(any(), any());
-
-            when()
-                .delete(MAILBOX_NAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void deleteShouldGenerateInternalErrorOnUnknownMailboxExceptionOnSearch() throws Exception {
-            when(mailboxManager.search(any(MailboxQuery.class), any())).thenThrow(new MailboxException());
-
-            when()
-                .delete(MAILBOX_NAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void deleteShouldReturnOkOnMailboxDoesNotExists() throws Exception {
-            doThrow(new MailboxNotFoundException(MAILBOX_NAME)).when(mailboxManager).deleteMailbox(any(), any());
-
-            when()
-                .delete(MAILBOX_NAME)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void deleteShouldGenerateInternalErrorOnUnknownExceptionWhenListingMailboxes() throws Exception {
-            doThrow(new RuntimeException()).when(mailboxManager).search(any(MailboxQuery.class), any());
-
-            when()
-                .delete()
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void deleteShouldGenerateInternalErrorOnMailboxExceptionWhenListingMailboxes() throws Exception {
-            doThrow(new MailboxException()).when(mailboxManager).search(any(MailboxQuery.class), any());
-
-            when()
-                .delete()
-                .then()
-                .statusCode(500);
-        }
-
-
-        @Test
-        public void deleteShouldGenerateInternalErrorOnUnknownExceptionWhenRemovingMailboxes() throws Exception {
-            MailboxId mailboxId = InMemoryId.of(12);
-            when(mailboxManager.search(any(MailboxQuery.class), any()))
-                .thenReturn(
-                        ImmutableList.of(
-                                new SimpleMailboxMetaData(new MailboxPath("#private", USERNAME, "any"), mailboxId, '.')));
-            doThrow(new RuntimeException()).when(mailboxManager).deleteMailbox(any(), any());
-
-            when()
-                .delete()
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void deleteShouldReturnOkOnMailboxNotFoundExceptionWhenRemovingMailboxes() throws Exception {
-            MailboxId mailboxId = InMemoryId.of(12);
-            when(mailboxManager.search(any(MailboxQuery.class), any()))
-                .thenReturn(
-                        ImmutableList.of(new SimpleMailboxMetaData(new MailboxPath("#private", USERNAME, "any"), mailboxId, '.')));
-            doThrow(new MailboxNotFoundException("any")).when(mailboxManager).deleteMailbox(any(), any());
-
-            when()
-                .delete()
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void deleteShouldReturnInternalErrorOnMailboxExceptionWhenRemovingMailboxes() throws Exception {
-            MailboxId mailboxId = InMemoryId.of(12);
-            when(mailboxManager.search(any(MailboxQuery.class), any()))
-                .thenReturn(
-                        ImmutableList.of(new SimpleMailboxMetaData(new MailboxPath("#private", USERNAME, "any"), mailboxId, '.')));
-            doThrow(new MailboxException()).when(mailboxManager).deleteMailbox(any(), any());
-
-            when()
-                .delete()
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void getShouldGenerateInternalErrorOnUnknownException() throws Exception {
-            doThrow(new RuntimeException()).when(mailboxManager).mailboxExists(any(), any());
-
-            when()
-                .get(MAILBOX_NAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void getShouldGenerateInternalErrorOnUnknownMailboxException() throws Exception {
-            doThrow(new MailboxException()).when(mailboxManager).mailboxExists(any(), any());
-
-            when()
-                .get(MAILBOX_NAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void getMailboxesShouldGenerateInternalErrorOnUnknownException() throws Exception {
-            doThrow(new RuntimeException()).when(mailboxManager).search(any(MailboxQuery.class), any());
-
-            when()
-                .get()
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void getMailboxesShouldGenerateInternalErrorOnUnknownMailboxException() throws Exception {
-            doThrow(new MailboxException()).when(mailboxManager).search(any(MailboxQuery.class), any());
-
-            when()
-                .get()
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void getMailboxesShouldGenerateInternalErrorOnRepositoryException() throws Exception {
-            doThrow(new RuntimeException()).when(usersRepository).contains(USERNAME);
-
-            when()
-                .get()
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void getShouldGenerateInternalErrorOnRepositoryException() throws Exception {
-            doThrow(new RuntimeException()).when(usersRepository).contains(USERNAME);
-
-            when()
-                .get(MAILBOX_NAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void putShouldGenerateInternalErrorOnRepositoryException() throws Exception {
-            doThrow(new RuntimeException()).when(usersRepository).contains(USERNAME);
-
-            when()
-                .put(MAILBOX_NAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void deleteShouldGenerateInternalErrorOnRepositoryException() throws Exception {
-            doThrow(new RuntimeException()).when(usersRepository).contains(USERNAME);
-
-            when()
-                .delete(MAILBOX_NAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void deleteMailboxesShouldGenerateInternalErrorOnRepositoryException() throws Exception {
-            doThrow(new RuntimeException()).when(usersRepository).contains(USERNAME);
-
-            when()
-                .delete()
-                .then()
-                .statusCode(500);
-        }
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/cca0f398/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java
deleted file mode 100644
index 684ea9b..0000000
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/routes/UsersRoutesTest.java
+++ /dev/null
@@ -1,422 +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.webadmin.routes;
-
-import static com.jayway.restassured.RestAssured.given;
-import static com.jayway.restassured.RestAssured.when;
-import static com.jayway.restassured.RestAssured.with;
-import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
-import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
-import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.apache.james.domainlist.api.DomainList;
-import org.apache.james.metrics.logger.DefaultMetricFactory;
-import org.apache.james.user.api.UsersRepository;
-import org.apache.james.user.api.UsersRepositoryException;
-import org.apache.james.user.api.model.User;
-import org.apache.james.user.memory.MemoryUsersRepository;
-import org.apache.james.webadmin.WebAdminServer;
-import org.apache.james.webadmin.service.UserService;
-import org.apache.james.webadmin.utils.JsonTransformer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import com.google.common.base.Charsets;
-import com.jayway.restassured.RestAssured;
-import com.jayway.restassured.builder.RequestSpecBuilder;
-import com.jayway.restassured.http.ContentType;
-
-import de.bechte.junit.runners.context.HierarchicalContextRunner;
-
-@RunWith(HierarchicalContextRunner.class)
-public class UsersRoutesTest {
-
-    public static final String DOMAIN = "domain";
-    public static final String USERNAME = "username@" + DOMAIN;
-    private WebAdminServer webAdminServer;
-
-    private void createServer(UsersRepository usersRepository) throws Exception {
-        webAdminServer = new WebAdminServer(
-            new DefaultMetricFactory(),
-            new UserRoutes(new UserService(usersRepository), new JsonTransformer()));
-        webAdminServer.configure(NO_CONFIGURATION);
-        webAdminServer.await();
-
-        RestAssured.requestSpecification = new RequestSpecBuilder()
-        		.setContentType(ContentType.JSON)
-        		.setAccept(ContentType.JSON)
-        		.setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)))
-        		.setPort(webAdminServer.getPort().toInt())
-        		.setBasePath(UserRoutes.USERS)
-        		.build();
-    }
-
-    @After
-    public void stop() {
-        webAdminServer.destroy();
-    }
-
-    public class NormalBehaviour {
-
-        @Before
-        public void setUp() throws Exception {
-            DomainList domainList = mock(DomainList.class);
-            when(domainList.containsDomain(DOMAIN)).thenReturn(true);
-
-            MemoryUsersRepository usersRepository = MemoryUsersRepository.withVirtualHosting();
-            usersRepository.setDomainList(domainList);
-
-            createServer(usersRepository);
-        }
-
-        @Test
-        public void getUsersShouldBeEmptyByDefault() {
-            when()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(is("[]"));
-        }
-
-        @Test
-        public void putShouldReturnUserErrorWhenNoBody() {
-            when()
-                .put(USERNAME)
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void postShouldReturnUserErrorWhenEmptyJsonBody() {
-            given()
-                .body("{}")
-            .when()
-                .put(USERNAME)
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void postShouldReturnUserErrorWhenWrongJsonBody() {
-            given()
-                .body("{\"bad\":\"any\"}")
-            .when()
-                .put(USERNAME)
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void postShouldReturnOkWhenValidJsonBody() {
-            given()
-                .body("{\"password\":\"password\"}")
-            .when()
-                .put(USERNAME)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void postShouldReturnRequireNonNullPassword() {
-            given()
-                .body("{\"password\":null}")
-            .when()
-                .put(USERNAME)
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void postShouldAddTheUser() {
-            with()
-                .body("{\"password\":\"password\"}")
-            .put(USERNAME);
-
-            when()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(equalTo("[{\"username\":\"" + USERNAME + "\"}]"));
-        }
-
-        @Test
-        public void postingTwoTimesShouldBeAllowed() {
-            // Given
-            with()
-                .body("{\"password\":\"password\"}")
-            .put(USERNAME);
-
-            // When
-            given()
-                .body("{\"password\":\"password\"}")
-            .when()
-                .put(USERNAME)
-            .then()
-                .statusCode(204);
-
-            // Then
-            when()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(equalTo("[{\"username\":\"" + USERNAME + "\"}]"));
-        }
-
-        @Test
-        public void deleteShouldReturnOk() {
-            when()
-                .delete(USERNAME)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void deleteShouldReturnBadRequestWhenEmptyUserName() {
-            when()
-                .delete("/")
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void deleteShouldReturnBadRequestWhenUsernameIsTooLong() {
-            when()
-                .delete(USERNAME + "0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789." +
-                    "0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789." +
-                    "0123456789.0123456789.0123456789.")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void deleteShouldReturnNotFoundWhenUsernameContainsSlash() {
-            given()
-                .body("{\"password\":\"password\"}")
-            .when()
-                .put(USERNAME + "/" + USERNAME)
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void putShouldReturnBadRequestWhenEmptyUserName() {
-            given()
-                .body("{\"password\":\"password\"}")
-            .when()
-                .put("/")
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void putShouldReturnBadRequestWhenUsernameIsTooLong() {
-            given()
-                .body("{\"password\":\"password\"}")
-            .when()
-                .put(USERNAME + "0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789." +
-                    "0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789.0123456789." +
-                    "0123456789.0123456789.0123456789.")
-            .then()
-                .statusCode(400);
-        }
-
-        @Test
-        public void putShouldReturnNotFoundWhenUsernameContainsSlash() {
-            given()
-                .body("{\"password\":\"password\"}")
-            .when()
-                .put(USERNAME + "/" + USERNAME)
-            .then()
-                .statusCode(404);
-        }
-
-        @Test
-        public void deleteShouldRemoveAssociatedUser() {
-            // Given
-            with()
-                .body("{\"password\":\"password\"}")
-            .put(USERNAME);
-
-            // When
-            when()
-                .delete(USERNAME)
-            .then()
-                .statusCode(204);
-
-            // Then
-            when()
-                .get()
-            .then()
-                .statusCode(200)
-                .body(equalTo("[]"));
-        }
-
-        @Test
-        public void deleteShouldStillBeValidWithExtraBody() {
-            given()
-                .body("{\"bad\":\"any\"}")
-            .when()
-                .delete(USERNAME)
-            .then()
-                .statusCode(204);
-        }
-    }
-
-    public class ErrorHandling {
-
-        private UsersRepository usersRepository;
-        private String username;
-        private String password;
-
-        @Before
-        public void setUp() throws Exception {
-            usersRepository = mock(UsersRepository.class);
-            createServer(usersRepository);
-            username = "username@domain";
-            password = "password";
-        }
-
-        @Test
-        public void deleteShouldStillBeOkWhenNoUser() throws Exception {
-            doThrow(new UsersRepositoryException("message")).when(usersRepository).removeUser(username);
-
-            when()
-                .delete(USERNAME)
-            .then()
-                .statusCode(204);
-        }
-
-        @Test
-        public void getShouldFailOnRepositoryException() throws Exception {
-            when(usersRepository.list()).thenThrow(new UsersRepositoryException("message"));
-
-            when()
-                .get()
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void postShouldFailOnRepositoryExceptionOnGetUserByName() throws Exception {
-            when(usersRepository.getUserByName(username)).thenThrow(new UsersRepositoryException("message"));
-
-            given()
-                .body("{\"password\":\"password\"}")
-            .when()
-                .put(USERNAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void postShouldNotFailOnRepositoryExceptionOnAddUser() throws Exception {
-            when(usersRepository.getUserByName(username)).thenReturn(null);
-            doThrow(new UsersRepositoryException("message")).when(usersRepository).addUser(username, password);
-
-            given()
-                .body("{\"password\":\"password\"}")
-            .when()
-                .put(USERNAME)
-            .then()
-                .statusCode(409);
-        }
-
-        @Test
-        public void postShouldFailOnRepositoryExceptionOnUpdateUser() throws Exception {
-            when(usersRepository.getUserByName(username)).thenReturn(mock(User.class));
-            doThrow(new UsersRepositoryException("message")).when(usersRepository).updateUser(any());
-
-            given()
-                .body("{\"password\":\"password\"}")
-            .when()
-                .put(USERNAME)
-            .then()
-                .statusCode(409);
-        }
-
-
-        @Test
-        public void deleteShouldFailOnUnknownException() throws Exception {
-            doThrow(new RuntimeException()).when(usersRepository).removeUser(username);
-
-            when()
-                .delete(USERNAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void getShouldFailOnUnknownException() throws Exception {
-            when(usersRepository.list()).thenThrow(new RuntimeException());
-
-            when()
-                .get()
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void postShouldFailOnUnknownExceptionOnGetUserByName() throws Exception {
-            when(usersRepository.getUserByName(username)).thenThrow(new RuntimeException());
-
-            given()
-                .body("{\"password\":\"password\"}")
-            .when()
-                .put(USERNAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void postShouldFailOnUnknownExceptionOnAddUser() throws Exception {
-            when(usersRepository.getUserByName(username)).thenReturn(null);
-            doThrow(new RuntimeException()).when(usersRepository).addUser(username, password);
-
-            given()
-                .body("{\"password\":\"password\"}")
-            .when()
-                .put(USERNAME)
-            .then()
-                .statusCode(500);
-        }
-
-        @Test
-        public void postShouldFailOnUnknownExceptionOnGetUpdateUser() throws Exception {
-            when(usersRepository.getUserByName(username)).thenReturn(mock(User.class));
-            doThrow(new RuntimeException()).when(usersRepository).updateUser(any());
-
-            given()
-                .body("{\"password\":\"password\"}")
-            .when()
-                .put(USERNAME)
-            .then()
-                .statusCode(500);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/cca0f398/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/utils/JsonExtractorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/utils/JsonExtractorTest.java b/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/utils/JsonExtractorTest.java
deleted file mode 100644
index ff5f2cb..0000000
--- a/server/protocols/webadmin/src/test/java/org/apache/james/webadmin/utils/JsonExtractorTest.java
+++ /dev/null
@@ -1,114 +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.webadmin.utils;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.base.Preconditions;
-
-public class JsonExtractorTest {
-
-    private JsonExtractor<Request> jsonExtractor;
-
-    @Before
-    public void setUp() {
-        jsonExtractor = new JsonExtractor<>(Request.class);
-    }
-
-    @Test
-    public void parseShouldThrowOnNullInput() throws Exception {
-        assertThatThrownBy(() -> jsonExtractor.parse(null)).isInstanceOf(NullPointerException.class);
-    }
-
-    @Test
-    public void parseShouldThrowOnEmptyInput() throws Exception {
-        assertThatThrownBy(() -> jsonExtractor.parse("")).isInstanceOf(JsonExtractException.class);
-    }
-
-    @Test
-    public void parseShouldThrowOnBrokenJson() throws Exception {
-        assertThatThrownBy(() -> jsonExtractor.parse("{\"field1\":\"broken")).isInstanceOf(JsonExtractException.class);
-    }
-
-    @Test
-    public void parseShouldThrowOnEmptyJson() throws Exception {
-        assertThatThrownBy(() -> jsonExtractor.parse("{}")).isInstanceOf(JsonExtractException.class);
-    }
-
-    @Test
-    public void parseShouldThrowOnMissingMandatoryField() throws Exception {
-        assertThatThrownBy(() -> jsonExtractor.parse("{\"field1\":\"any\"}")).isInstanceOf(JsonExtractException.class);
-    }
-
-    @Test
-    public void parseShouldThrowOnValidationProblemIllegalArgumentException() throws Exception {
-        assertThatThrownBy(() -> jsonExtractor.parse("{\"field1\":\"\",\"field2\":\"any\"}")).isInstanceOf(JsonExtractException.class);
-    }
-
-    @Test
-    public void parseShouldThrowOnValidationProblemNPE() throws Exception {
-        assertThatThrownBy(() -> jsonExtractor.parse("{\"field1\":null,\"field2\":\"any\"}")).isInstanceOf(JsonExtractException.class);
-    }
-
-    @Test
-    public void parseShouldThrowOnExtraFiled() throws Exception {
-        assertThatThrownBy(() -> jsonExtractor.parse("{\"field1\":\"value\",\"field2\":\"any\",\"extra\":\"extra\"}")).isInstanceOf(JsonExtractException.class);
-    }
-
-    @Test
-    public void parseShouldInstantiateDestinationClass() throws Exception {
-        String field1 = "value1";
-        String field2 = "value2";
-        Request request = jsonExtractor.parse("{\"field1\":\"" + field1 + "\",\"field2\":\"" + field2 + "\"}");
-
-        assertThat(request.getField1()).isEqualTo(field1);
-        assertThat(request.getField2()).isEqualTo(field2);
-    }
-
-    static class Request {
-        private final String field1;
-        private final String field2;
-
-        @JsonCreator
-        public Request(@JsonProperty("field1") String field1,
-                       @JsonProperty("field2") String field2) {
-            Preconditions.checkNotNull(field1);
-            Preconditions.checkNotNull(field2);
-            Preconditions.checkArgument(!field1.isEmpty());
-            this.field1 = field1;
-            this.field2 = field2;
-        }
-
-        public String getField1() {
-            return field1;
-        }
-
-        public String getField2() {
-            return field2;
-        }
-    }
-
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message