From server-dev-return-67507-apmail-james-server-dev-archive=james.apache.org@james.apache.org Mon Jun 18 02:43:06 2018 Return-Path: X-Original-To: apmail-james-server-dev-archive@www.apache.org Delivered-To: apmail-james-server-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8F46818D78 for ; Mon, 18 Jun 2018 02:43:06 +0000 (UTC) Received: (qmail 63403 invoked by uid 500); 18 Jun 2018 02:43:06 -0000 Delivered-To: apmail-james-server-dev-archive@james.apache.org Received: (qmail 63369 invoked by uid 500); 18 Jun 2018 02:43:06 -0000 Mailing-List: contact server-dev-help@james.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "James Developers List" Reply-To: "James Developers List" Delivered-To: mailing list server-dev@james.apache.org Received: (qmail 62827 invoked by uid 99); 18 Jun 2018 02:43:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Jun 2018 02:43:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 45C8AC04BC for ; Mon, 18 Jun 2018 02:43:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.381 X-Spam-Level: X-Spam-Status: No, score=-1.381 tagged_above=-999 required=6.31 tests=[RCVD_IN_DNSWL_MED=-2.3, SPF_FAIL=0.919] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id Odtji6Js9FTc for ; Mon, 18 Jun 2018 02:43:03 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id C5AC75F5B4 for ; Mon, 18 Jun 2018 02:43:02 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id CDE63E0E3E for ; Mon, 18 Jun 2018 02:43:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 0263421848 for ; Mon, 18 Jun 2018 02:43:01 +0000 (UTC) Date: Mon, 18 Jun 2018 02:43:01 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: server-dev@james.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (JAMES-2149) Create domain mappings via webadmin MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/JAMES-2149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16515299#comment-16515299 ] ASF GitHub Bot commented on JAMES-2149: --------------------------------------- Github user chibenwa commented on a diff in the pull request: https://github.com/apache/james-project/pull/119#discussion_r195954037 --- Diff: server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/DomainMappingsRoutesTest.java --- @@ -0,0 +1,387 @@ +/**************************************************************** + * 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.delete; +import static com.jayway.restassured.RestAssured.given; +import static com.jayway.restassured.RestAssured.put; +import static com.jayway.restassured.RestAssured.when; +import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.isEmptyString; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.jayway.restassured.RestAssured; +import com.jayway.restassured.filter.log.LogDetail; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.response.Response; +import com.jayway.restassured.specification.RequestSpecification; +import org.apache.james.core.Domain; +import org.apache.james.metrics.logger.DefaultMetricFactory; +import org.apache.james.rrt.api.RecipientRewriteTable; +import org.apache.james.rrt.api.RecipientRewriteTableException; +import org.apache.james.rrt.lib.MappingSource; +import org.apache.james.rrt.lib.Mappings; +import org.apache.james.rrt.lib.MappingsImpl; +import org.apache.james.rrt.memory.MemoryRecipientRewriteTable; +import org.apache.james.webadmin.WebAdminServer; +import org.apache.james.webadmin.WebAdminUtils; +import org.apache.james.webadmin.utils.ErrorResponder; +import org.apache.james.webadmin.utils.JsonTransformer; +import org.eclipse.jetty.http.HttpStatus; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +class DomainMappingsRoutesTest { + private RecipientRewriteTable recipientRewriteTable; + private WebAdminServer webAdminServer; + + private void createServer(DomainMappingsRoutes domainMappingsRoutes) throws Exception { + webAdminServer = WebAdminUtils.createWebAdminServer(new DefaultMetricFactory(), domainMappingsRoutes); + webAdminServer.configure(NO_CONFIGURATION); + webAdminServer.await(); + + RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer) + .setBasePath("/domainMappings") + .log(LogDetail.METHOD) + .build(); + } + + @BeforeEach + void setUp() throws Exception { + recipientRewriteTable = spy(new MemoryRecipientRewriteTable()); + + createServer(new DomainMappingsRoutes(recipientRewriteTable, new JsonTransformer())); + } + + @AfterEach + void tearDown() { + webAdminServer.destroy(); + } + + @Nested + class NormalBehaviour { + + @Test + void addDomainMappingShouldRespondWithNoContent() { + given() + .body("to.com") + .when() + .put("from.com") + .then() + .statusCode(HttpStatus.NO_CONTENT_204) + .body(isEmptyString()); + } + + @Test + void getDomainMappings() throws RecipientRewriteTableException { + String alias1 = "to_1.com"; + String alias2 = "to_2.com"; + String alias3 = "to_3.com"; + + Domain expectedDomain = Domain.of("abc.com"); + MappingSource mappingSource = MappingSource.fromDomain(expectedDomain); + + recipientRewriteTable.addAliasDomainMapping(mappingSource, Domain.of(alias1)); + recipientRewriteTable.addAliasDomainMapping(mappingSource, Domain.of(alias2)); + recipientRewriteTable.addAliasDomainMapping(mappingSource, Domain.of(alias3)); + + Map> map = + when() + .get() + .then() + .contentType(ContentType.JSON) + .statusCode(HttpStatus.OK_200) + .extract() + .body() + .jsonPath() + .getMap("."); + + assertThat(map) + .containsOnly(entry(expectedDomain.name(), ImmutableList.of(alias1, alias2, alias3))); + } + + @Test + void getDomainMappingsEmptyMappingsAreFilteredOut() throws RecipientRewriteTableException { --- End diff -- Here I would suggest `getDomainMappingShouldFilterOutEmptyMappings` BTW semantic change from passive form into active form is interesting, as the test name implies we know where the action is taken ;-). > Create domain mappings via webadmin > ----------------------------------- > > Key: JAMES-2149 > URL: https://issues.apache.org/jira/browse/JAMES-2149 > Project: James Server > Issue Type: New Feature > Components: webadmin > Affects Versions: master > Reporter: Tellier Benoit > Priority: Major > Labels: feature, newbie > > Nowadays, the Rewrite Table engine supports domain redirections. That is to say any@domain.com will be rewritten as any@otherDomain.com. > However, such a feature is not exposed via webadmin. > You will need to : > - Create a new **DomainMappingsRoutes** in webadmin-data > - You will expose in this routes, using directly RecipientsRewriteTable, the endpoitns for adding, removing and listing domain mappings. > {code:java} > GET /domainMappings/ > {"fromDomain1":"toDomain1", "fromDomain2": "toDomain2"} > PUT /domainMappings/fromDomain > "toDomain" > DELETE /domainMappings/fromDomain > "toDomain" > {code} > You will write a test class from your endpoints. See *GroupsRoutesTest*. > Don't hesitate to ask for help on the *Gitter* chat. -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org For additional commands, e-mail: server-dev-help@james.apache.org