This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit c6c7a18d825a2d3940b4b141a059f43a6d82b624 Author: cketti <[email protected]> AuthorDate: Sun Sep 15 22:09:24 2019 +0200 JAMES-2884 Rename ClientId to MethodCallId Rename class to match the name in RFC 8620. --- .../apache/james/jmap/methods/GetFilterMethod.java | 22 +++++----- .../james/jmap/methods/GetMailboxesMethod.java | 10 ++--- .../james/jmap/methods/GetMessageListMethod.java | 16 +++---- .../james/jmap/methods/GetMessagesMethod.java | 6 +-- .../jmap/methods/GetVacationResponseMethod.java | 8 ++-- .../apache/james/jmap/methods/JmapResponse.java | 26 +++++------ .../james/jmap/methods/JmapResponseWriterImpl.java | 4 +- .../java/org/apache/james/jmap/methods/Method.java | 4 +- .../apache/james/jmap/methods/RequestHandler.java | 6 +-- .../apache/james/jmap/methods/SetFilterMethod.java | 34 +++++++-------- .../james/jmap/methods/SetMailboxesMethod.java | 8 ++-- .../james/jmap/methods/SetMessagesMethod.java | 6 +-- .../jmap/methods/SetVacationResponseMethod.java | 20 ++++----- .../james/jmap/model/AuthenticatedRequest.java | 2 +- .../apache/james/jmap/model/InvocationRequest.java | 12 +++--- .../james/jmap/model/InvocationResponse.java | 14 +++--- .../model/{ClientId.java => MethodCallId.java} | 12 +++--- .../org/apache/james/jmap/JMAPServletTest.java | 6 +-- .../james/jmap/methods/GetMailboxesMethodTest.java | 30 ++++++------- .../james/jmap/methods/GetMessagesMethodTest.java | 50 +++++++++++----------- .../methods/GetVacationResponseMethodTest.java | 28 ++++++------ .../jmap/methods/JmapResponseWriterImplTest.java | 48 ++++++++++----------- .../james/jmap/methods/RequestHandlerTest.java | 8 ++-- .../james/jmap/methods/SetMailboxesMethodTest.java | 22 +++++----- .../methods/SetVacationResponseMethodTest.java | 34 +++++++-------- .../james/jmap/model/InvocationRequestTest.java | 2 +- .../james/jmap/model/InvocationResponseTest.java | 10 ++--- .../{ClientIdTest.java => MethodCallIdTest.java} | 10 ++--- 28 files changed, 229 insertions(+), 229 deletions(-) diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetFilterMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetFilterMethod.java index 56a3cd7..724b741 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetFilterMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetFilterMethod.java @@ -27,9 +27,9 @@ import javax.inject.Inject; import org.apache.james.core.User; import org.apache.james.jmap.api.filtering.FilteringManagement; import org.apache.james.jmap.api.filtering.Rule; -import org.apache.james.jmap.model.ClientId; import org.apache.james.jmap.model.GetFilterRequest; import org.apache.james.jmap.model.GetFilterResponse; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.SetError; import org.apache.james.mailbox.MailboxSession; import org.apache.james.metrics.api.MetricFactory; @@ -65,9 +65,9 @@ public class GetFilterMethod implements Method { } @Override - public Stream<JmapResponse> process(JmapRequest request, ClientId clientId, MailboxSession mailboxSession) { + public Stream<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) { Preconditions.checkNotNull(request); - Preconditions.checkNotNull(clientId); + Preconditions.checkNotNull(methodCallId); Preconditions.checkNotNull(mailboxSession); Preconditions.checkArgument(request instanceof GetFilterRequest); @@ -76,20 +76,20 @@ public class GetFilterMethod implements Method { return metricFactory.runPublishingTimerMetric(JMAP_PREFIX + METHOD_NAME.getName(), MDCBuilder.create() .addContext(MDCBuilder.ACTION, "GET_FILTER") - .wrapArround(() -> process(clientId, mailboxSession, filterRequest))); + .wrapArround(() -> process(methodCallId, mailboxSession, filterRequest))); } - private Stream<JmapResponse> process(ClientId clientId, MailboxSession mailboxSession, GetFilterRequest request) { + private Stream<JmapResponse> process(MethodCallId methodCallId, MailboxSession mailboxSession, GetFilterRequest request) { try { - return retrieveFilter(clientId, mailboxSession.getUser()); + return retrieveFilter(methodCallId, mailboxSession.getUser()); } catch (Exception e) { LOGGER.warn("Failed to retrieve filter"); - return Stream.of(unKnownError(clientId)); + return Stream.of(unKnownError(methodCallId)); } } - private Stream<JmapResponse> retrieveFilter(ClientId clientId, User user) { + private Stream<JmapResponse> retrieveFilter(MethodCallId methodCallId, User user) { List<Rule> rules = filteringManagement.listRulesForUser(user); GetFilterResponse getFilterResponse = GetFilterResponse.builder() @@ -97,15 +97,15 @@ public class GetFilterMethod implements Method { .build(); return Stream.of(JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .response(getFilterResponse) .responseName(RESPONSE_NAME) .build()); } - private JmapResponse unKnownError(ClientId clientId) { + private JmapResponse unKnownError(MethodCallId methodCallId) { return JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(RESPONSE_NAME) .response(ErrorResponse.builder() .type(SetError.Type.ERROR.asString()) diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java index 485d364..3dc9065 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java @@ -27,11 +27,11 @@ import java.util.stream.Stream; import javax.inject.Inject; -import org.apache.james.jmap.model.ClientId; import org.apache.james.jmap.model.GetMailboxesRequest; import org.apache.james.jmap.model.GetMailboxesResponse; import org.apache.james.jmap.model.MailboxFactory; import org.apache.james.jmap.model.MailboxProperty; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.mailbox.Mailbox; import org.apache.james.jmap.utils.quotas.QuotaLoader; import org.apache.james.jmap.utils.quotas.QuotaLoaderWithDefaultPreloaded; @@ -88,7 +88,7 @@ public class GetMailboxesMethod implements Method { } @Override - public Stream<JmapResponse> process(JmapRequest request, ClientId clientId, MailboxSession mailboxSession) { + public Stream<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) { Preconditions.checkArgument(request instanceof GetMailboxesRequest); GetMailboxesRequest mailboxesRequest = (GetMailboxesRequest) request; return metricFactory.runPublishingTimerMetric(JMAP_PREFIX + METHOD_NAME.getName(), @@ -97,12 +97,12 @@ public class GetMailboxesMethod implements Method { .addContext("accountId", mailboxesRequest.getAccountId()) .addContext("mailboxIds", mailboxesRequest.getIds()) .addContext("properties", mailboxesRequest.getProperties()) - .wrapArround(() -> process(clientId, mailboxSession, mailboxesRequest))); + .wrapArround(() -> process(methodCallId, mailboxSession, mailboxesRequest))); } - private Stream<JmapResponse> process(ClientId clientId, MailboxSession mailboxSession, GetMailboxesRequest mailboxesRequest) { + private Stream<JmapResponse> process(MethodCallId methodCallId, MailboxSession mailboxSession, GetMailboxesRequest mailboxesRequest) { return Stream.of( - JmapResponse.builder().clientId(clientId) + JmapResponse.builder().methodCallId(methodCallId) .response(getMailboxesResponse(mailboxesRequest, mailboxSession)) .properties(mailboxesRequest.getProperties().map(this::ensureContainsId)) .responseName(RESPONSE_NAME) diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java index 4743ce3..b399631 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java @@ -28,12 +28,12 @@ import java.util.stream.Stream; import javax.inject.Inject; import javax.inject.Named; -import org.apache.james.jmap.model.ClientId; import org.apache.james.jmap.model.Filter; import org.apache.james.jmap.model.FilterCondition; import org.apache.james.jmap.model.GetMessageListRequest; import org.apache.james.jmap.model.GetMessageListResponse; import org.apache.james.jmap.model.GetMessagesRequest; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.Number; import org.apache.james.jmap.utils.FilterToSearchQuery; import org.apache.james.jmap.utils.SortConverter; @@ -89,7 +89,7 @@ public class GetMessageListMethod implements Method { } @Override - public Stream<JmapResponse> process(JmapRequest request, ClientId clientId, MailboxSession mailboxSession) { + public Stream<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) { Preconditions.checkArgument(request instanceof GetMessageListRequest); GetMessageListRequest messageListRequest = (GetMessageListRequest) request; @@ -107,17 +107,17 @@ public class GetMessageListMethod implements Method { .addContext("isFetchMessage", messageListRequest.isFetchMessages()) .addContext("isCollapseThread", messageListRequest.isCollapseThreads()) .wrapArround( - () -> process(clientId, mailboxSession, messageListRequest))); + () -> process(methodCallId, mailboxSession, messageListRequest))); } - private Stream<JmapResponse> process(ClientId clientId, MailboxSession mailboxSession, GetMessageListRequest messageListRequest) { + private Stream<JmapResponse> process(MethodCallId methodCallId, MailboxSession mailboxSession, GetMessageListRequest messageListRequest) { GetMessageListResponse messageListResponse = getMessageListResponse(messageListRequest, mailboxSession); - Stream<JmapResponse> jmapResponse = Stream.of(JmapResponse.builder().clientId(clientId) + Stream<JmapResponse> jmapResponse = Stream.of(JmapResponse.builder().methodCallId(methodCallId) .response(messageListResponse) .responseName(RESPONSE_NAME) .build()); return Stream.concat(jmapResponse, - processGetMessages(messageListRequest, messageListResponse, clientId, mailboxSession)); + processGetMessages(messageListRequest, messageListResponse, methodCallId, mailboxSession)); } private GetMessageListResponse getMessageListResponse(GetMessageListRequest messageListRequest, MailboxSession mailboxSession) { @@ -172,13 +172,13 @@ public class GetMessageListMethod implements Method { }); } - private Stream<JmapResponse> processGetMessages(GetMessageListRequest messageListRequest, GetMessageListResponse messageListResponse, ClientId clientId, MailboxSession mailboxSession) { + private Stream<JmapResponse> processGetMessages(GetMessageListRequest messageListRequest, GetMessageListResponse messageListResponse, MethodCallId methodCallId, MailboxSession mailboxSession) { if (shouldChainToGetMessages(messageListRequest)) { GetMessagesRequest getMessagesRequest = GetMessagesRequest.builder() .ids(messageListResponse.getMessageIds()) .properties(messageListRequest.getFetchMessageProperties()) .build(); - return getMessagesMethod.process(getMessagesRequest, clientId, mailboxSession); + return getMessagesMethod.process(getMessagesRequest, methodCallId, mailboxSession); } return Stream.empty(); } diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java index ca05d89..876aa5b 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java @@ -29,7 +29,6 @@ import javax.inject.Inject; import org.apache.james.jmap.JmapFieldNotSupportedException; import org.apache.james.jmap.json.FieldNamePropertyFilter; -import org.apache.james.jmap.model.ClientId; import org.apache.james.jmap.model.GetMessagesRequest; import org.apache.james.jmap.model.GetMessagesResponse; import org.apache.james.jmap.model.Keywords; @@ -38,6 +37,7 @@ import org.apache.james.jmap.model.MessageFactory; import org.apache.james.jmap.model.MessageFactory.MetaDataWithContent; import org.apache.james.jmap.model.MessageProperties; import org.apache.james.jmap.model.MessageProperties.HeaderProperty; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.utils.KeywordsCombiner; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageIdManager; @@ -92,7 +92,7 @@ public class GetMessagesMethod implements Method { } @Override - public Stream<JmapResponse> process(JmapRequest request, ClientId clientId, MailboxSession mailboxSession) { + public Stream<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) { Preconditions.checkNotNull(request); Preconditions.checkNotNull(mailboxSession); Preconditions.checkArgument(request instanceof GetMessagesRequest); @@ -107,7 +107,7 @@ public class GetMessagesMethod implements Method { .addContext("ids", getMessagesRequest.getIds()) .addContext("properties", getMessagesRequest.getProperties()) .wrapArround( - () -> Stream.of(JmapResponse.builder().clientId(clientId) + () -> Stream.of(JmapResponse.builder().methodCallId(methodCallId) .response(getMessagesResponse(mailboxSession, getMessagesRequest)) .responseName(RESPONSE_NAME) .properties(outputProperties.getOptionalMessageProperties()) diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetVacationResponseMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetVacationResponseMethod.java index 6e722b5..a42dc38 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetVacationResponseMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetVacationResponseMethod.java @@ -26,9 +26,9 @@ import javax.inject.Inject; import org.apache.james.jmap.api.vacation.AccountId; import org.apache.james.jmap.api.vacation.Vacation; import org.apache.james.jmap.api.vacation.VacationRepository; -import org.apache.james.jmap.model.ClientId; import org.apache.james.jmap.model.GetVacationRequest; import org.apache.james.jmap.model.GetVacationResponse; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.VacationResponse; import org.apache.james.mailbox.MailboxSession; import org.apache.james.metrics.api.MetricFactory; @@ -64,9 +64,9 @@ public class GetVacationResponseMethod implements Method { } @Override - public Stream<JmapResponse> process(JmapRequest request, ClientId clientId, MailboxSession mailboxSession) { + public Stream<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) { Preconditions.checkNotNull(request); - Preconditions.checkNotNull(clientId); + Preconditions.checkNotNull(methodCallId); Preconditions.checkNotNull(mailboxSession); Preconditions.checkArgument(request instanceof GetVacationRequest); @@ -75,7 +75,7 @@ public class GetVacationResponseMethod implements Method { .addContext(MDCBuilder.ACTION, "VACATION") .wrapArround( () -> Stream.of(JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(RESPONSE_NAME) .response(process(mailboxSession)) .build()))); diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java index 6a80c43..e012f43 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java @@ -22,7 +22,7 @@ package org.apache.james.jmap.methods; import java.util.Optional; import java.util.Set; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.Property; import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; @@ -39,7 +39,7 @@ public class JmapResponse { public static class Builder { private Method.Response.Name responseName; - private ClientId id; + private MethodCallId methodCallId; private Method.Response response; private Optional<? extends Set<? extends Property>> properties = Optional.empty(); private Optional<SimpleFilterProvider> filterProvider = Optional.empty(); @@ -52,8 +52,8 @@ public class JmapResponse { return this; } - public Builder clientId(ClientId id) { - this.id = id; + public Builder methodCallId(MethodCallId methodCallId) { + this.methodCallId = methodCallId; return this; } @@ -96,19 +96,19 @@ public class JmapResponse { public JmapResponse build() { - return new JmapResponse(responseName, id, response, properties, filterProvider); + return new JmapResponse(responseName, methodCallId, response, properties, filterProvider); } } private final Method.Response.Name method; - private final ClientId clientId; + private final MethodCallId methodCallId; private final Method.Response response; private final Optional<? extends Set<? extends Property>> properties; private final Optional<SimpleFilterProvider> filterProvider; - private JmapResponse(Method.Response.Name method, ClientId clientId, Method.Response response, Optional<? extends Set<? extends Property>> properties, Optional<SimpleFilterProvider> filterProvider) { + private JmapResponse(Method.Response.Name method, MethodCallId methodCallId, Method.Response response, Optional<? extends Set<? extends Property>> properties, Optional<SimpleFilterProvider> filterProvider) { this.method = method; - this.clientId = clientId; + this.methodCallId = methodCallId; this.response = response; this.properties = properties; this.filterProvider = filterProvider; @@ -122,8 +122,8 @@ public class JmapResponse { return response; } - public ClientId getClientId() { - return clientId; + public MethodCallId getMethodCallId() { + return methodCallId; } public Optional<? extends Set<? extends Property>> getProperties() { @@ -136,7 +136,7 @@ public class JmapResponse { @Override public int hashCode() { - return Objects.hashCode(method, clientId, response, properties, filterProvider); + return Objects.hashCode(method, methodCallId, response, properties, filterProvider); } @Override @@ -144,7 +144,7 @@ public class JmapResponse { if (object instanceof JmapResponse) { JmapResponse that = (JmapResponse) object; return Objects.equal(this.method, that.method) - && Objects.equal(this.clientId, that.clientId) + && Objects.equal(this.methodCallId, that.methodCallId) && Objects.equal(this.response, that.response) && Objects.equal(this.properties, that.properties) && Objects.equal(this.filterProvider, that.filterProvider); @@ -157,7 +157,7 @@ public class JmapResponse { return MoreObjects.toStringHelper(getClass()) .add("method", method) .add("response", response) - .add("clientId", clientId) + .add("methodCallId", methodCallId) .add("properties", properties) .add("filterProvider", filterProvider) .toString(); diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java index d4bc420..2328ed9 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java @@ -26,8 +26,8 @@ import java.util.stream.Stream; import javax.inject.Inject; import org.apache.james.jmap.json.ObjectMapperFactory; -import org.apache.james.jmap.model.Property; import org.apache.james.jmap.model.InvocationResponse; +import org.apache.james.jmap.model.Property; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ser.FilterProvider; @@ -54,7 +54,7 @@ public class JmapResponseWriterImpl implements JmapResponseWriter { return new InvocationResponse( jmapResponse.getResponseName(), objectMapper.valueToTree(jmapResponse.getResponse()), - jmapResponse.getClientId()); + jmapResponse.getMethodCallId()); }); } diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/Method.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/Method.java index 059373c..07d5747 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/Method.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/Method.java @@ -24,7 +24,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; import java.util.Objects; import java.util.stream.Stream; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.mailbox.MailboxSession; import com.fasterxml.jackson.annotation.JsonValue; @@ -124,6 +124,6 @@ public interface Method { Class<? extends JmapRequest> requestType(); - Stream<JmapResponse> process(JmapRequest request, ClientId clientId, MailboxSession mailboxSession); + Stream<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession); } diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java index 1836eb3..0af6ba5 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java @@ -75,7 +75,7 @@ public class RequestHandler { return (Method method) -> { try { JmapRequest jmapRequest = jmapRequestParser.extractJmapRequest(request, method.requestType()); - return method.process(jmapRequest, request.getClientId(), mailboxSession); + return method.process(jmapRequest, request.getMethodCallId(), mailboxSession); } catch (IOException e) { LOGGER.error("Error occured while parsing the request.", e); if (e.getCause() instanceof JmapFieldNotSupportedException) { @@ -98,7 +98,7 @@ public class RequestHandler { private Stream<JmapResponse> errorNotImplemented(JmapFieldNotSupportedException error, AuthenticatedRequest request) { return Stream.of( JmapResponse.builder() - .clientId(request.getClientId()) + .methodCallId(request.getMethodCallId()) .error(generateInvalidArgumentError("The field '" + error.getField() + "' of '" + error.getIssuer() + "' is not supported")) .build()); } @@ -106,7 +106,7 @@ public class RequestHandler { private Stream<JmapResponse> error(AuthenticatedRequest request, ErrorResponse error) { return Stream.of( JmapResponse.builder() - .clientId(request.getClientId()) + .methodCallId(request.getMethodCallId()) .error(error) .build()); } diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetFilterMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetFilterMethod.java index 221638c..b2f056d 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetFilterMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetFilterMethod.java @@ -30,8 +30,8 @@ import javax.inject.Inject; import org.apache.james.core.User; import org.apache.james.jmap.api.filtering.FilteringManagement; import org.apache.james.jmap.api.filtering.Rule; -import org.apache.james.jmap.model.ClientId; import org.apache.james.jmap.model.JmapRuleDTO; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.SetError; import org.apache.james.jmap.model.SetFilterRequest; import org.apache.james.jmap.model.SetFilterResponse; @@ -102,9 +102,9 @@ public class SetFilterMethod implements Method { } @Override - public Stream<JmapResponse> process(JmapRequest request, ClientId clientId, MailboxSession mailboxSession) { + public Stream<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) { Preconditions.checkNotNull(request); - Preconditions.checkNotNull(clientId); + Preconditions.checkNotNull(methodCallId); Preconditions.checkNotNull(mailboxSession); Preconditions.checkArgument(request instanceof SetFilterRequest); @@ -116,25 +116,25 @@ public class SetFilterMethod implements Method { .addContext(MDCBuilder.ACTION, "SET_FILTER") .addContext("update", setFilterRequest.getSingleton()) .wrapArround( - () -> process(clientId, mailboxSession, setFilterRequest))); + () -> process(methodCallId, mailboxSession, setFilterRequest))); } - private Stream<JmapResponse> process(ClientId clientId, MailboxSession mailboxSession, SetFilterRequest request) { + private Stream<JmapResponse> process(MethodCallId methodCallId, MailboxSession mailboxSession, SetFilterRequest request) { try { - return updateFilter(clientId, request, mailboxSession.getUser()); + return updateFilter(methodCallId, request, mailboxSession.getUser()); } catch (MultipleMailboxIdException e) { LOGGER.debug("Rule targeting several mailboxes", e); - return Stream.of(multipleMailboxesError(clientId, e)); + return Stream.of(multipleMailboxesError(methodCallId, e)); } catch (DuplicatedRuleException e) { LOGGER.debug("Duplicated rules", e); - return Stream.of(duplicatedIdsError(clientId, e)); + return Stream.of(duplicatedIdsError(methodCallId, e)); } catch (Exception e) { LOGGER.warn("Failed setting Rules", e); - return Stream.of(unKnownError(clientId)); + return Stream.of(unKnownError(methodCallId)); } } - private Stream<JmapResponse> updateFilter(ClientId clientId, SetFilterRequest request, User user) throws DuplicatedRuleException, MultipleMailboxIdException { + private Stream<JmapResponse> updateFilter(MethodCallId methodCallId, SetFilterRequest request, User user) throws DuplicatedRuleException, MultipleMailboxIdException { ImmutableList<Rule> rules = request.getSingleton().stream() .map(JmapRuleDTO::toRule) .collect(ImmutableList.toImmutableList()); @@ -145,7 +145,7 @@ public class SetFilterMethod implements Method { filteringManagement.defineRulesForUser(user, rules); return Stream.of(JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(RESPONSE_NAME) .response(SetFilterResponse.updated()) .build()); @@ -179,9 +179,9 @@ public class SetFilterMethod implements Method { } } - private JmapResponse unKnownError(ClientId clientId) { + private JmapResponse unKnownError(MethodCallId methodCallId) { return JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(RESPONSE_NAME) .response(ErrorResponse.builder() .type(SetError.Type.ERROR.asString()) @@ -190,9 +190,9 @@ public class SetFilterMethod implements Method { .build(); } - private JmapResponse duplicatedIdsError(ClientId clientId, DuplicatedRuleException e) { + private JmapResponse duplicatedIdsError(MethodCallId methodCallId, DuplicatedRuleException e) { return JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(RESPONSE_NAME) .response(SetFilterResponse.notUpdated(SetError.builder() .type(SetError.Type.INVALID_ARGUMENTS) @@ -201,9 +201,9 @@ public class SetFilterMethod implements Method { .build(); } - private JmapResponse multipleMailboxesError(ClientId clientId, MultipleMailboxIdException e) { + private JmapResponse multipleMailboxesError(MethodCallId methodCallId, MultipleMailboxIdException e) { return JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(RESPONSE_NAME) .response(SetFilterResponse.notUpdated(SetError.builder() .type(SetError.Type.INVALID_ARGUMENTS) diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesMethod.java index def34f3..a56f731 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesMethod.java @@ -24,7 +24,7 @@ import java.util.stream.Stream; import javax.inject.Inject; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.SetMailboxesRequest; import org.apache.james.jmap.model.SetMailboxesResponse; import org.apache.james.mailbox.MailboxSession; @@ -59,9 +59,9 @@ public class SetMailboxesMethod implements Method { } @Override - public Stream<JmapResponse> process(JmapRequest request, ClientId clientId, MailboxSession mailboxSession) { + public Stream<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) { Preconditions.checkNotNull(request); - Preconditions.checkNotNull(clientId); + Preconditions.checkNotNull(methodCallId); Preconditions.checkNotNull(mailboxSession); Preconditions.checkArgument(request instanceof SetMailboxesRequest); @@ -75,7 +75,7 @@ public class SetMailboxesMethod implements Method { .addContext("destroy", setMailboxesRequest.getDestroy()) .wrapArround( () -> Stream.of( - JmapResponse.builder().clientId(clientId) + JmapResponse.builder().methodCallId(methodCallId) .response(setMailboxesResponse(setMailboxesRequest, mailboxSession)) .responseName(RESPONSE_NAME) .build()))); diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesMethod.java index 19175e7..8dce492 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesMethod.java @@ -24,7 +24,7 @@ import java.util.stream.Stream; import javax.inject.Inject; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.SetMessagesRequest; import org.apache.james.jmap.model.SetMessagesResponse; import org.apache.james.mailbox.MailboxSession; @@ -59,7 +59,7 @@ public class SetMessagesMethod implements Method { } @Override - public Stream<JmapResponse> process(JmapRequest request, ClientId clientId, MailboxSession mailboxSession) { + public Stream<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) { Preconditions.checkArgument(request instanceof SetMessagesRequest); SetMessagesRequest setMessagesRequest = (SetMessagesRequest) request; @@ -72,7 +72,7 @@ public class SetMessagesMethod implements Method { .addContext("ifInState", setMessagesRequest.getIfInState()) .wrapArround( () -> Stream.of( - JmapResponse.builder().clientId(clientId) + JmapResponse.builder().methodCallId(methodCallId) .response(setMessagesResponse(setMessagesRequest, mailboxSession)) .responseName(RESPONSE_NAME) .build()))); diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetVacationResponseMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetVacationResponseMethod.java index 7164db8..adc6182 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetVacationResponseMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetVacationResponseMethod.java @@ -27,7 +27,7 @@ import org.apache.james.jmap.api.vacation.AccountId; import org.apache.james.jmap.api.vacation.NotificationRegistry; import org.apache.james.jmap.api.vacation.Vacation; import org.apache.james.jmap.api.vacation.VacationRepository; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.SetError; import org.apache.james.jmap.model.SetVacationRequest; import org.apache.james.jmap.model.SetVacationResponse; @@ -69,9 +69,9 @@ public class SetVacationResponseMethod implements Method { } @Override - public Stream<JmapResponse> process(JmapRequest request, ClientId clientId, MailboxSession mailboxSession) { + public Stream<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) { Preconditions.checkNotNull(request); - Preconditions.checkNotNull(clientId); + Preconditions.checkNotNull(methodCallId); Preconditions.checkNotNull(mailboxSession); Preconditions.checkArgument(request instanceof SetVacationRequest); SetVacationRequest setVacationRequest = (SetVacationRequest) request; @@ -81,14 +81,14 @@ public class SetVacationResponseMethod implements Method { .addContext(MDCBuilder.ACTION, "SET_VACATION") .addContext("update", setVacationRequest.getUpdate()) .wrapArround( - () -> process(clientId, mailboxSession, setVacationRequest))); + () -> process(methodCallId, mailboxSession, setVacationRequest))); } - private Stream<JmapResponse> process(ClientId clientId, MailboxSession mailboxSession, SetVacationRequest setVacationRequest) { + private Stream<JmapResponse> process(MethodCallId methodCallId, MailboxSession mailboxSession, SetVacationRequest setVacationRequest) { if (!setVacationRequest.isValid()) { return Stream.of(JmapResponse .builder() - .clientId(clientId) + .methodCallId(methodCallId) .error(ErrorResponse.builder() .type(INVALID_ARGUMENTS1) .description(INVALID_ARGUMENT_DESCRIPTION) @@ -96,18 +96,18 @@ public class SetVacationResponseMethod implements Method { .build()); } - return process(clientId, + return process(methodCallId, AccountId.fromString(mailboxSession.getUser().asString()), setVacationRequest.getUpdate().get(Vacation.ID)); } - private Stream<JmapResponse> process(ClientId clientId, AccountId accountId, VacationResponse vacationResponse) { + private Stream<JmapResponse> process(MethodCallId methodCallId, AccountId accountId, VacationResponse vacationResponse) { if (vacationResponse.isValid()) { vacationRepository.modifyVacation(accountId, vacationResponse.getPatch()).block(); notificationRegistry.flush(accountId).block(); return Stream.of(JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(RESPONSE_NAME) .response(SetVacationResponse.builder() .updatedId(Vacation.ID) @@ -115,7 +115,7 @@ public class SetVacationResponseMethod implements Method { .build()); } else { return Stream.of(JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(RESPONSE_NAME) .response(SetVacationResponse.builder() .notUpdated(Vacation.ID, diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/AuthenticatedRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/AuthenticatedRequest.java index 92f9605..4788334 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/AuthenticatedRequest.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/AuthenticatedRequest.java @@ -32,7 +32,7 @@ public class AuthenticatedRequest extends InvocationRequest { private final HttpServletRequest httpServletRequest; private AuthenticatedRequest(InvocationRequest request, HttpServletRequest httpServletRequest) { - super(request.getMethodName(), request.getParameters(), request.getClientId()); + super(request.getMethodName(), request.getParameters(), request.getMethodCallId()); this.httpServletRequest = httpServletRequest; } diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/InvocationRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/InvocationRequest.java index 84ee07b..629b12f 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/InvocationRequest.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/InvocationRequest.java @@ -31,17 +31,17 @@ public class InvocationRequest { Preconditions.checkState(json[0].isTextual(), "first element should be a String"); Preconditions.checkState(json[1].isObject(), "second element should be a Json"); Preconditions.checkState(json[2].isTextual(), "third element should be a String"); - return new InvocationRequest(Method.Request.name(json[0].textValue()), (ObjectNode) json[1], ClientId.of(json[2].textValue())); + return new InvocationRequest(Method.Request.name(json[0].textValue()), (ObjectNode) json[1], MethodCallId.of(json[2].textValue())); } private final Method.Request.Name method; private final ObjectNode parameters; - private final ClientId clientId; + private final MethodCallId methodCallId; - protected InvocationRequest(Method.Request.Name method, ObjectNode parameters, ClientId clientId) { + protected InvocationRequest(Method.Request.Name method, ObjectNode parameters, MethodCallId methodCallId) { this.method = method; this.parameters = parameters; - this.clientId = clientId; + this.methodCallId = methodCallId; } public Method.Request.Name getMethodName() { @@ -52,7 +52,7 @@ public class InvocationRequest { return parameters; } - public ClientId getClientId() { - return clientId; + public MethodCallId getMethodCallId() { + return methodCallId; } } \ No newline at end of file diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/InvocationResponse.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/InvocationResponse.java index 822d92c..cbe3ee7 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/InvocationResponse.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/InvocationResponse.java @@ -27,15 +27,15 @@ public class InvocationResponse { private final Method.Response.Name name; private final ObjectNode results; - private final ClientId clientId; + private final MethodCallId methodCallId; - public InvocationResponse(Method.Response.Name name, ObjectNode results, ClientId clientId) { + public InvocationResponse(Method.Response.Name name, ObjectNode results, MethodCallId methodCallId) { Preconditions.checkNotNull(name, "method is mandatory"); Preconditions.checkNotNull(results, "results is mandatory"); - Preconditions.checkNotNull(clientId, "clientId is mandatory"); + Preconditions.checkNotNull(methodCallId, "methodCallId is mandatory"); this.name = name; this.results = results; - this.clientId = clientId; + this.methodCallId = methodCallId; } public Method.Response.Name getResponseName() { @@ -46,11 +46,11 @@ public class InvocationResponse { return results; } - public ClientId getClientId() { - return clientId; + public MethodCallId getMethodCallId() { + return methodCallId; } public Object[] asProtocolSpecification() { - return new Object[] { getResponseName(), getResults(), getClientId() }; + return new Object[] { getResponseName(), getResults(), getMethodCallId() }; } } \ No newline at end of file diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ClientId.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MethodCallId.java similarity index 87% rename from server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ClientId.java rename to server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MethodCallId.java index 85cb773..402155b 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ClientId.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MethodCallId.java @@ -23,15 +23,15 @@ import java.util.Objects; import com.fasterxml.jackson.annotation.JsonValue; import com.google.common.base.Preconditions; -public class ClientId { +public class MethodCallId { - public static ClientId of(String clientId) { - return new ClientId(clientId); + public static MethodCallId of(String methodCallId) { + return new MethodCallId(methodCallId); } private final String id; - private ClientId(String id) { + private MethodCallId(String id) { Preconditions.checkNotNull(id); Preconditions.checkArgument(!id.isEmpty()); this.id = id; @@ -44,8 +44,8 @@ public class ClientId { @Override public boolean equals(Object obj) { - if (obj instanceof ClientId) { - ClientId other = (ClientId) obj; + if (obj instanceof MethodCallId) { + MethodCallId other = (MethodCallId) obj; return Objects.equals(this.id, other.id); } return false; diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java index 3a0e7fa..0e8de17 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java @@ -34,7 +34,7 @@ import org.apache.james.http.jetty.JettyHttpServer; import org.apache.james.jmap.methods.ErrorResponse; import org.apache.james.jmap.methods.Method; import org.apache.james.jmap.methods.RequestHandler; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.InvocationResponse; import org.apache.james.metrics.api.NoopMetricFactory; import org.junit.After; @@ -99,7 +99,7 @@ public class JMAPServletTest { json.put("type", "invalidArgument"); when(requestHandler.handle(any())) - .thenReturn(Stream.of(new InvocationResponse(ErrorResponse.ERROR_METHOD, json, ClientId.of("#0")))); + .thenReturn(Stream.of(new InvocationResponse(ErrorResponse.ERROR_METHOD, json, MethodCallId.of("#0")))); given() .body("[[\"getAccounts\", {\"state\":false}, \"#0\"]]") @@ -121,7 +121,7 @@ public class JMAPServletTest { arrayNode.add(list); when(requestHandler.handle(any())) - .thenReturn(Stream.of(new InvocationResponse(Method.Response.name("accounts"), json, ClientId.of("#0")))); + .thenReturn(Stream.of(new InvocationResponse(Method.Response.name("accounts"), json, MethodCallId.of("#0")))); given() .body("[[\"getAccounts\", {}, \"#0\"]]") diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java index ae0f9aa..fb2812e 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java @@ -30,7 +30,7 @@ import java.util.stream.Collectors; import javax.mail.Flags; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.GetMailboxesRequest; import org.apache.james.jmap.model.GetMailboxesResponse; import org.apache.james.jmap.model.MailboxFactory; @@ -63,7 +63,7 @@ public class GetMailboxesMethodTest { private StoreMailboxManager mailboxManager; private GetMailboxesMethod getMailboxesMethod; - private ClientId clientId; + private MethodCallId methodCallId; private MailboxFactory mailboxFactory; private QuotaRootResolver quotaRootResolver; @@ -71,7 +71,7 @@ public class GetMailboxesMethodTest { @Before public void setup() throws Exception { - clientId = ClientId.of("#0"); + methodCallId = MethodCallId.of("#0"); mailboxManager = InMemoryIntegrationResources.defaultResources().getMailboxManager(); quotaRootResolver = mailboxManager.getQuotaComponents().getQuotaRootResolver(); quotaManager = mailboxManager.getQuotaComponents().getQuotaManager(); @@ -87,7 +87,7 @@ public class GetMailboxesMethodTest { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); - List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); + List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) @@ -111,7 +111,7 @@ public class GetMailboxesMethodTest { .build(); MailboxSession session = MailboxSessionUtil.create(USERNAME); - List<JmapResponse> getMailboxesResponse = testee.process(getMailboxesRequest, clientId, session).collect(Collectors.toList()); + List<JmapResponse> getMailboxesResponse = testee.process(getMailboxesRequest, methodCallId, session).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) @@ -141,7 +141,7 @@ public class GetMailboxesMethodTest { GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); - List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); + List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) @@ -166,7 +166,7 @@ public class GetMailboxesMethodTest { GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); - List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, userSession).collect(Collectors.toList()); + List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, methodCallId, userSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) @@ -187,7 +187,7 @@ public class GetMailboxesMethodTest { GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); - List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); + List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) @@ -208,7 +208,7 @@ public class GetMailboxesMethodTest { GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); - List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); + List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) @@ -229,7 +229,7 @@ public class GetMailboxesMethodTest { GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); - List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); + List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) @@ -257,7 +257,7 @@ public class GetMailboxesMethodTest { GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); - List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); + List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) @@ -287,7 +287,7 @@ public class GetMailboxesMethodTest { GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); - List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); + List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) @@ -317,7 +317,7 @@ public class GetMailboxesMethodTest { GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); - List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); + List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) @@ -356,7 +356,7 @@ public class GetMailboxesMethodTest { GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); - List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); + List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) @@ -386,7 +386,7 @@ public class GetMailboxesMethodTest { GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); - List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); + List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, methodCallId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java index 9f384d6..f9f1b2d 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java @@ -36,7 +36,7 @@ import javax.mail.Flags.Flag; import org.apache.commons.lang3.NotImplementedException; import org.apache.james.core.User; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.GetMessagesRequest; import org.apache.james.jmap.model.GetMessagesResponse; import org.apache.james.jmap.model.Message; @@ -93,11 +93,11 @@ public class GetMessagesMethodTest { private MailboxSession session; private MailboxPath inboxPath; private MailboxPath customMailboxPath; - private ClientId clientId; + private MethodCallId methodCallId; @Before public void setup() throws Exception { - clientId = ClientId.of("#0"); + methodCallId = MethodCallId.of("#0"); HtmlTextExtractor htmlTextExtractor = new JsoupHtmlTextExtractor(); MessagePreviewGenerator messagePreview = new MessagePreviewGenerator(); MessageContentExtractor messageContentExtractor = new MessageContentExtractor(); @@ -134,25 +134,25 @@ public class GetMessagesMethodTest { @Test public void processShouldThrowWhenNullRequest() { GetMessagesRequest request = null; - assertThatThrownBy(() -> testee.process(request, mock(ClientId.class), mock(MailboxSession.class))).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> testee.process(request, mock(MethodCallId.class), mock(MailboxSession.class))).isInstanceOf(NullPointerException.class); } @Test public void processShouldThrowWhenNullSession() { MailboxSession mailboxSession = null; - assertThatThrownBy(() -> testee.process(mock(GetMessagesRequest.class), mock(ClientId.class), mailboxSession)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> testee.process(mock(GetMessagesRequest.class), mock(MethodCallId.class), mailboxSession)).isInstanceOf(NullPointerException.class); } @Test - public void processShouldThrowWhenNullClientId() { - ClientId clientId = null; - assertThatThrownBy(() -> testee.process(mock(GetMessagesRequest.class), clientId, mock(MailboxSession.class))).isInstanceOf(NullPointerException.class); + public void processShouldThrowWhenNullMethodCallId() { + MethodCallId methodCallId = null; + assertThatThrownBy(() -> testee.process(mock(GetMessagesRequest.class), methodCallId, mock(MailboxSession.class))).isInstanceOf(NullPointerException.class); } @Test public void processShouldThrowWhenRequestHasAccountId() { assertThatThrownBy(() -> testee.process( - GetMessagesRequest.builder().accountId("abc").build(), mock(ClientId.class), mock(MailboxSession.class))).isInstanceOf(NotImplementedException.class); + GetMessagesRequest.builder().accountId("abc").build(), mock(MethodCallId.class), mock(MailboxSession.class))).isInstanceOf(NotImplementedException.class); } @Test @@ -169,7 +169,7 @@ public class GetMessagesMethodTest { message3.getMessageId())) .build(); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1) .extracting(JmapResponse::getResponse) @@ -198,7 +198,7 @@ public class GetMessagesMethodTest { .ids(ImmutableList.of(message.getMessageId())) .build(); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1) .extracting(JmapResponse::getResponse) @@ -219,7 +219,7 @@ public class GetMessagesMethodTest { .properties(ImmutableList.of()) .build(); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1); assertThat(result.get(0).getProperties()) @@ -236,7 +236,7 @@ public class GetMessagesMethodTest { .ids(ImmutableList.of(message1.getMessageId())) .build(); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1); assertThat(result.get(0).getProperties()) .isEqualTo(Optional.of(MessageProperty.allOutputProperties())); @@ -255,7 +255,7 @@ public class GetMessagesMethodTest { Set<MessageProperty> expected = Sets.newHashSet(MessageProperty.id, MessageProperty.subject); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1); assertThat(result.get(0).getProperties()) .isEqualTo(Optional.of(expected)); @@ -274,7 +274,7 @@ public class GetMessagesMethodTest { Set<MessageProperty> expected = Sets.newHashSet(MessageProperty.id, MessageProperty.textBody); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1); assertThat(result.get(0).getProperties()) @@ -297,7 +297,7 @@ public class GetMessagesMethodTest { .ids(ImmutableList.of(message.getMessageId())) .build(); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1) .extracting(JmapResponse::getResponse) @@ -323,7 +323,7 @@ public class GetMessagesMethodTest { .ids(ImmutableList.of(message.getMessageId())) .build(); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1) .extracting(JmapResponse::getResponse) @@ -355,7 +355,7 @@ public class GetMessagesMethodTest { .ids(ImmutableList.of(message.getMessageId())) .build(); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1) .extracting(JmapResponse::getResponse) @@ -387,7 +387,7 @@ public class GetMessagesMethodTest { Set<MessageProperty> expected = Sets.newHashSet(MessageProperty.id, MessageProperty.headers); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1); assertThat(result.get(0).getProperties()) @@ -413,7 +413,7 @@ public class GetMessagesMethodTest { .properties(ImmutableList.of("headers.from", "headers.heADER2")) .build(); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result) .hasSize(1) @@ -450,7 +450,7 @@ public class GetMessagesMethodTest { .properties(ImmutableList.of("mailboxIds")) .build(); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1); Method.Response response = result.get(0).getResponse(); @@ -485,7 +485,7 @@ public class GetMessagesMethodTest { .properties(ImmutableList.of("mailboxIds")) .build(); - List<JmapResponse> responses = testee.process(request, clientId, session).collect(Guavate.toImmutableList()); + List<JmapResponse> responses = testee.process(request, methodCallId, session).collect(Guavate.toImmutableList()); assertThat(responses).hasSize(1); Method.Response response = responses.get(0).getResponse(); @@ -522,7 +522,7 @@ public class GetMessagesMethodTest { message3.getMessageId())) .build(); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1) .extracting(JmapResponse::getResponse) @@ -579,7 +579,7 @@ public class GetMessagesMethodTest { message3.getMessageId())) .build(); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1) .extracting(JmapResponse::getResponse) @@ -619,7 +619,7 @@ public class GetMessagesMethodTest { .ids(ImmutableList.of(message1.getMessageId())) .build(); - List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList()); + List<JmapResponse> result = testee.process(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1) .extracting(JmapResponse::getResponse) diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java index 95b9c56..f4b0794 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java @@ -31,7 +31,7 @@ import org.apache.james.core.User; import org.apache.james.jmap.api.vacation.AccountId; import org.apache.james.jmap.api.vacation.Vacation; import org.apache.james.jmap.api.vacation.VacationRepository; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.GetMailboxesRequest; import org.apache.james.jmap.model.GetVacationRequest; import org.apache.james.jmap.model.GetVacationResponse; @@ -71,27 +71,27 @@ public class GetVacationResponseMethodTest { @Test(expected = NullPointerException.class) public void processShouldThrowOnNullRequest() { - testee.process(null, mock(ClientId.class), mock(MailboxSession.class)); + testee.process(null, mock(MethodCallId.class), mock(MailboxSession.class)); } @Test(expected = NullPointerException.class) - public void processShouldThrowOnNullClientId() { + public void processShouldThrowOnNullMethodCallId() { testee.process(mock(GetMailboxesRequest.class), null, mock(MailboxSession.class)); } @Test(expected = NullPointerException.class) public void processShouldThrowOnNullMailboxSession() { - testee.process(mock(GetMailboxesRequest.class), mock(ClientId.class), null); + testee.process(mock(GetMailboxesRequest.class), mock(MethodCallId.class), null); } @Test(expected = IllegalArgumentException.class) public void processShouldThrowOnWrongRequestType() { - testee.process(mock(SetMailboxesRequest.class), mock(ClientId.class), mock(MailboxSession.class)); + testee.process(mock(SetMailboxesRequest.class), mock(MethodCallId.class), mock(MailboxSession.class)); } @Test public void processShouldReturnTheAppropriateVacationResponse() { - ClientId clientId = mock(ClientId.class); + MethodCallId methodCallId = mock(MethodCallId.class); Vacation vacation = Vacation.builder() .enabled(true) .textBody("I am in vacation") @@ -105,10 +105,10 @@ public class GetVacationResponseMethodTest { GetVacationRequest getVacationRequest = GetVacationRequest.builder().build(); - Stream<JmapResponse> result = testee.process(getVacationRequest, clientId, mailboxSession); + Stream<JmapResponse> result = testee.process(getVacationRequest, methodCallId, mailboxSession); JmapResponse expected = JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(GetVacationResponseMethod.RESPONSE_NAME) .response(GetVacationResponse.builder() .accountId(USERNAME) @@ -123,7 +123,7 @@ public class GetVacationResponseMethodTest { @Test public void processShouldReturnUnActivatedVacationResponseWhenBeforeDate() { - ClientId clientId = mock(ClientId.class); + MethodCallId methodCallId = mock(MethodCallId.class); Vacation vacation = Vacation.builder() .enabled(true) .textBody("I am in vacation") @@ -137,10 +137,10 @@ public class GetVacationResponseMethodTest { GetVacationRequest getVacationRequest = GetVacationRequest.builder().build(); - Stream<JmapResponse> result = testee.process(getVacationRequest, clientId, mailboxSession); + Stream<JmapResponse> result = testee.process(getVacationRequest, methodCallId, mailboxSession); JmapResponse expected = JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(GetVacationResponseMethod.RESPONSE_NAME) .response(GetVacationResponse.builder() .accountId(USERNAME) @@ -157,7 +157,7 @@ public class GetVacationResponseMethodTest { @Test public void processShouldReturnUnActivatedVacationResponseWhenAfterDate() { - ClientId clientId = mock(ClientId.class); + MethodCallId methodCallId = mock(MethodCallId.class); Vacation vacation = Vacation.builder() .enabled(true) .textBody("I am in vacation") @@ -171,10 +171,10 @@ public class GetVacationResponseMethodTest { GetVacationRequest getVacationRequest = GetVacationRequest.builder().build(); - Stream<JmapResponse> result = testee.process(getVacationRequest, clientId, mailboxSession); + Stream<JmapResponse> result = testee.process(getVacationRequest, methodCallId, mailboxSession); JmapResponse expected = JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(GetVacationResponseMethod.RESPONSE_NAME) .response(GetVacationResponse.builder() .accountId(USERNAME) diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java index cb63463..17d4a8a 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java @@ -28,7 +28,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.james.jmap.json.ObjectMapperFactory; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.Property; import org.apache.james.jmap.model.InvocationRequest; import org.apache.james.jmap.model.InvocationResponse; @@ -58,24 +58,24 @@ public class JmapResponseWriterImplTest { @Test(expected = IllegalStateException.class) public void formatMethodResponseShouldWorkWhenNullJmapResponse() { String expectedMethod = "nwonMethod"; - String expectedClientId = "#1"; + String expectedMethodCallId = "#1"; String expectedId = "myId"; Stream<InvocationResponse> response = testee.formatMethodResponse(Stream.of(JmapResponse .builder() - .clientId(ClientId.of(expectedClientId)) + .methodCallId(MethodCallId.of(expectedMethodCallId)) .response(null) .build())); List<InvocationResponse> responseList = response.collect(Collectors.toList()); assertThat(responseList).hasSize(1) - .extracting(InvocationResponse::getResponseName, x -> x.getResults().get("id").asText(), InvocationResponse::getClientId) - .containsExactly(tuple(expectedMethod, expectedId, expectedClientId)); + .extracting(InvocationResponse::getResponseName, x -> x.getResults().get("id").asText(), InvocationResponse::getMethodCallId) + .containsExactly(tuple(expectedMethod, expectedId, expectedMethodCallId)); } @Test public void formatMethodResponseShouldWork() { - String expectedClientId = "#1"; + String expectedMethodCallId = "#1"; String expectedId = "myId"; ResponseClass responseClass = new ResponseClass(); @@ -85,14 +85,14 @@ public class JmapResponseWriterImplTest { Stream.of(JmapResponse .builder() .responseName(Method.Response.name("unknownMethod")) - .clientId(ClientId.of(expectedClientId)) + .methodCallId(MethodCallId.of(expectedMethodCallId)) .response(responseClass) .build())) .collect(Collectors.toList()); assertThat(response).hasSize(1) - .extracting(InvocationResponse::getResponseName, x -> x.getResults().get("id").asText(), InvocationResponse::getClientId) - .containsExactly(tuple(Method.Response.name("unknownMethod"), expectedId, ClientId.of(expectedClientId))); + .extracting(InvocationResponse::getResponseName, x -> x.getResults().get("id").asText(), InvocationResponse::getMethodCallId) + .containsExactly(tuple(Method.Response.name("unknownMethod"), expectedId, MethodCallId.of(expectedMethodCallId))); } private static class ResponseClass implements Method.Response { @@ -112,7 +112,7 @@ public class JmapResponseWriterImplTest { Stream.of(JmapResponse .builder() .responseName(Method.Response.name("unknownMethod")) - .clientId(ClientId.of("#1")) + .methodCallId(MethodCallId.of("#1")) .properties(ImmutableSet.of(property)) .response(responseClass) .build())) @@ -137,7 +137,7 @@ public class JmapResponseWriterImplTest { Stream.of(JmapResponse .builder() .responseName(Method.Response.name("unknownMethod")) - .clientId(ClientId.of("#1")) + .methodCallId(MethodCallId.of("#1")) .properties(ImmutableSet.of(property)) .response(responseClass) .build())); @@ -146,7 +146,7 @@ public class JmapResponseWriterImplTest { Stream.of(JmapResponse .builder() .responseName(Method.Response.name("unknownMethod")) - .clientId(ClientId.of("#1")) + .methodCallId(MethodCallId.of("#1")) .response(responseClass) .build())) .collect(Collectors.toList()); @@ -169,14 +169,14 @@ public class JmapResponseWriterImplTest { Stream.of(JmapResponse .builder() .responseName(Method.Response.name("unknownMethod")) - .clientId(ClientId.of("#1")) + .methodCallId(MethodCallId.of("#1")) .properties(ImmutableSet.of(idProperty, nameProperty)) .response(responseClass) .build(), JmapResponse .builder() .responseName(Method.Response.name("unknownMethod")) - .clientId(ClientId.of("#1")) + .methodCallId(MethodCallId.of("#1")) .properties(ImmutableSet.of(idProperty)) .response(responseClass) .build())) @@ -208,41 +208,41 @@ public class JmapResponseWriterImplTest { @Test public void formatErrorResponseShouldWork() { - String expectedClientId = "#1"; + String expectedMethodCallId = "#1"; ObjectNode parameters = new ObjectNode(new JsonNodeFactory(false)); parameters.put("id", "myId"); JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode("unknwonMethod"), parameters, - new ObjectNode(new JsonNodeFactory(false)).textNode(expectedClientId)}; + new ObjectNode(new JsonNodeFactory(false)).textNode(expectedMethodCallId)}; List<InvocationResponse> response = testee.formatMethodResponse( Stream.of(JmapResponse .builder() - .clientId(InvocationRequest.deserialize(nodes).getClientId()) + .methodCallId(InvocationRequest.deserialize(nodes).getMethodCallId()) .error() .build())) .collect(Collectors.toList()); assertThat(response).hasSize(1) - .extracting(InvocationResponse::getResponseName, x -> x.getResults().get("type").asText(), InvocationResponse::getClientId) - .containsExactly(tuple(ErrorResponse.ERROR_METHOD, ErrorResponse.DEFAULT_ERROR_MESSAGE, ClientId.of(expectedClientId))); + .extracting(InvocationResponse::getResponseName, x -> x.getResults().get("type").asText(), InvocationResponse::getMethodCallId) + .containsExactly(tuple(ErrorResponse.ERROR_METHOD, ErrorResponse.DEFAULT_ERROR_MESSAGE, MethodCallId.of(expectedMethodCallId))); } @Test public void formatErrorResponseShouldWorkWithTypeAndDescription() { - String expectedClientId = "#1"; + String expectedMethodCallId = "#1"; ObjectNode parameters = new ObjectNode(new JsonNodeFactory(false)); parameters.put("id", "myId"); JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode("unknwonMethod"), parameters, - new ObjectNode(new JsonNodeFactory(false)).textNode(expectedClientId)}; + new ObjectNode(new JsonNodeFactory(false)).textNode(expectedMethodCallId)}; List<InvocationResponse> response = testee.formatMethodResponse( Stream.of(JmapResponse .builder() - .clientId(InvocationRequest.deserialize(nodes).getClientId()) + .methodCallId(InvocationRequest.deserialize(nodes).getMethodCallId()) .error(ErrorResponse .builder() .type("errorType") @@ -252,8 +252,8 @@ public class JmapResponseWriterImplTest { .collect(Collectors.toList()); assertThat(response).hasSize(1) - .extracting(InvocationResponse::getResponseName, x -> x.getResults().get("type").asText(), x -> x.getResults().get("description").asText(), InvocationResponse::getClientId) - .containsExactly(tuple(ErrorResponse.ERROR_METHOD, "errorType", "complete description", ClientId.of(expectedClientId))); + .extracting(InvocationResponse::getResponseName, x -> x.getResults().get("type").asText(), x -> x.getResults().get("description").asText(), InvocationResponse::getMethodCallId) + .containsExactly(tuple(ErrorResponse.ERROR_METHOD, "errorType", "complete description", MethodCallId.of(expectedMethodCallId))); } } diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java index 1f54023..91b6070 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java @@ -32,7 +32,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.james.jmap.json.ObjectMapperFactory; import org.apache.james.jmap.model.AuthenticatedRequest; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.InvocationRequest; import org.apache.james.jmap.model.InvocationResponse; import org.apache.james.mailbox.MailboxSession; @@ -106,14 +106,14 @@ public class RequestHandlerTest { } @Override - public Stream<JmapResponse> process(JmapRequest request, ClientId clientId, MailboxSession mailboxSession) { + public Stream<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) { Preconditions.checkArgument(request instanceof TestJmapRequest); TestJmapRequest typedRequest = (TestJmapRequest) request; return Stream.of( JmapResponse.builder() .response(new TestJmapResponse(typedRequest.getId(), typedRequest.getName(), "works")) .responseName(Response.name("test")) - .clientId(ClientId.of("#0")) + .methodCallId(MethodCallId.of("#0")) .build()); } } @@ -193,7 +193,7 @@ public class RequestHandlerTest { } @Override - public Stream<JmapResponse> process(JmapRequest request, ClientId clientId, MailboxSession mailboxSession) { + public Stream<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) { return null; } } diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java index 13da25e..1b90f31 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java @@ -26,7 +26,7 @@ import static org.mockito.Mockito.when; import java.util.stream.Stream; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.GetMailboxesRequest; import org.apache.james.jmap.model.MailboxCreationId; import org.apache.james.jmap.model.SetMailboxesRequest; @@ -61,16 +61,16 @@ public class SetMailboxesMethodTest { public void processShouldThrowWhenNullJmapRequest() { MailboxSession session = mock(MailboxSession.class); JmapRequest nullJmapRequest = null; - assertThatThrownBy(() -> new SetMailboxesMethod(NO_PROCESSOR, TIME_METRIC_FACTORY).process(nullJmapRequest, ClientId.of("clientId"), session)) + assertThatThrownBy(() -> new SetMailboxesMethod(NO_PROCESSOR, TIME_METRIC_FACTORY).process(nullJmapRequest, MethodCallId.of("methodCallId"), session)) .isInstanceOf(NullPointerException.class); } @Test - public void processShouldThrowWhenNullClientId() { + public void processShouldThrowWhenNullMethodCallId() { MailboxSession session = mock(MailboxSession.class); JmapRequest jmapRequest = mock(JmapRequest.class); - ClientId nullClientId = null; - assertThatThrownBy(() -> new SetMailboxesMethod(NO_PROCESSOR, TIME_METRIC_FACTORY).process(jmapRequest, nullClientId, session)) + MethodCallId nullMethodCallId = null; + assertThatThrownBy(() -> new SetMailboxesMethod(NO_PROCESSOR, TIME_METRIC_FACTORY).process(jmapRequest, nullMethodCallId, session)) .isInstanceOf(NullPointerException.class); } @@ -78,7 +78,7 @@ public class SetMailboxesMethodTest { public void processShouldThrowWhenNullMailboxSession() { MailboxSession nullMailboxSession = null; JmapRequest jmapRequest = mock(JmapRequest.class); - assertThatThrownBy(() -> new SetMailboxesMethod(NO_PROCESSOR, TIME_METRIC_FACTORY).process(jmapRequest, ClientId.of("clientId"), nullMailboxSession)) + assertThatThrownBy(() -> new SetMailboxesMethod(NO_PROCESSOR, TIME_METRIC_FACTORY).process(jmapRequest, MethodCallId.of("methodCallId"), nullMailboxSession)) .isInstanceOf(NullPointerException.class); } @@ -86,7 +86,7 @@ public class SetMailboxesMethodTest { public void processShouldThrowWhenJmapRequestTypeMismatch() { MailboxSession session = mock(MailboxSession.class); JmapRequest getMailboxesRequest = GetMailboxesRequest.builder().build(); - assertThatThrownBy(() -> new SetMailboxesMethod(NO_PROCESSOR, TIME_METRIC_FACTORY).process(getMailboxesRequest, ClientId.of("clientId"), session)) + assertThatThrownBy(() -> new SetMailboxesMethod(NO_PROCESSOR, TIME_METRIC_FACTORY).process(getMailboxesRequest, MethodCallId.of("methodCallId"), session)) .isInstanceOf(IllegalArgumentException.class); } @@ -100,7 +100,7 @@ public class SetMailboxesMethodTest { SetMailboxesResponse creationResponse = SetMailboxesResponse.builder().created(creationId, createdfooFolder).build(); JmapResponse jmapResponse = JmapResponse.builder() .response(creationResponse) - .clientId(ClientId.of("clientId")) + .methodCallId(MethodCallId.of("methodCallId")) .responseName(SetMailboxesMethod.RESPONSE_NAME) .build(); @@ -110,7 +110,7 @@ public class SetMailboxesMethodTest { Stream<JmapResponse> actual = new SetMailboxesMethod(ImmutableSet.of(creatorProcessor), TIME_METRIC_FACTORY) - .process(creationRequest, ClientId.of("clientId"), session); + .process(creationRequest, MethodCallId.of("methodCallId"), session); assertThat(actual).contains(jmapResponse); } @@ -123,7 +123,7 @@ public class SetMailboxesMethodTest { SetMailboxesResponse destructionResponse = SetMailboxesResponse.builder().destroyed(deletions).build(); JmapResponse jmapResponse = JmapResponse.builder() .response(destructionResponse) - .clientId(ClientId.of("clientId")) + .methodCallId(MethodCallId.of("methodCallId")) .responseName(SetMailboxesMethod.RESPONSE_NAME) .build(); @@ -133,7 +133,7 @@ public class SetMailboxesMethodTest { Stream<JmapResponse> actual = new SetMailboxesMethod(ImmutableSet.of(destructorProcessor), TIME_METRIC_FACTORY) - .process(destructionRequest, ClientId.of("clientId"), session); + .process(destructionRequest, MethodCallId.of("methodCallId"), session); assertThat(actual).contains(jmapResponse); } diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetVacationResponseMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetVacationResponseMethodTest.java index 712fc80..5c451b3 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetVacationResponseMethodTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetVacationResponseMethodTest.java @@ -35,7 +35,7 @@ import org.apache.james.jmap.api.vacation.AccountId; import org.apache.james.jmap.api.vacation.NotificationRegistry; import org.apache.james.jmap.api.vacation.Vacation; import org.apache.james.jmap.api.vacation.VacationRepository; -import org.apache.james.jmap.model.ClientId; +import org.apache.james.jmap.model.MethodCallId; import org.apache.james.jmap.model.GetMailboxesRequest; import org.apache.james.jmap.model.SetError; import org.apache.james.jmap.model.SetMailboxesRequest; @@ -59,13 +59,13 @@ public class SetVacationResponseMethodTest { private SetVacationResponseMethod testee; private VacationRepository vacationRepository; - private ClientId clientId; + private MethodCallId methodCallId; private MailboxSession mailboxSession; private NotificationRegistry notificationRegistry; @Before public void setUp() { - clientId = mock(ClientId.class); + methodCallId = mock(MethodCallId.class); mailboxSession = mock(MailboxSession.class); vacationRepository = mock(VacationRepository.class); notificationRegistry = mock(NotificationRegistry.class); @@ -74,22 +74,22 @@ public class SetVacationResponseMethodTest { @Test(expected = NullPointerException.class) public void processShouldThrowOnNullRequest() { - testee.process(null, mock(ClientId.class), mock(MailboxSession.class)); + testee.process(null, mock(MethodCallId.class), mock(MailboxSession.class)); } @Test(expected = NullPointerException.class) - public void processShouldThrowOnNullClientId() { + public void processShouldThrowOnNullMethodCallId() { testee.process(mock(SetMailboxesRequest.class), null, mock(MailboxSession.class)); } @Test(expected = NullPointerException.class) public void processShouldThrowOnNullMailboxSession() { - testee.process(mock(SetMailboxesRequest.class), mock(ClientId.class), null); + testee.process(mock(SetMailboxesRequest.class), mock(MethodCallId.class), null); } @Test(expected = IllegalArgumentException.class) public void processShouldThrowOnWrongRequestType() { - testee.process(mock(GetMailboxesRequest.class), mock(ClientId.class), mock(MailboxSession.class)); + testee.process(mock(GetMailboxesRequest.class), mock(MethodCallId.class), mock(MailboxSession.class)); } @Test @@ -98,10 +98,10 @@ public class SetVacationResponseMethodTest { .update(ImmutableMap.of()) .build(); - Stream<JmapResponse> result = testee.process(setVacationRequest, clientId, mock(MailboxSession.class)); + Stream<JmapResponse> result = testee.process(setVacationRequest, methodCallId, mock(MailboxSession.class)); JmapResponse expected = JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .error(ErrorResponse.builder() .type(SetVacationResponseMethod.INVALID_ARGUMENTS) .description(SetVacationResponseMethod.INVALID_ARGUMENT_DESCRIPTION) @@ -121,10 +121,10 @@ public class SetVacationResponseMethodTest { .build())) .build(); - Stream<JmapResponse> result = testee.process(setVacationRequest, clientId, mock(MailboxSession.class)); + Stream<JmapResponse> result = testee.process(setVacationRequest, methodCallId, mock(MailboxSession.class)); JmapResponse expected = JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .error(ErrorResponse.builder() .type(SetVacationResponseMethod.INVALID_ARGUMENTS) .description(SetVacationResponseMethod.INVALID_ARGUMENT_DESCRIPTION) @@ -149,10 +149,10 @@ public class SetVacationResponseMethodTest { .build())) .build(); - Stream<JmapResponse> result = testee.process(setVacationRequest, clientId, mock(MailboxSession.class)); + Stream<JmapResponse> result = testee.process(setVacationRequest, methodCallId, mock(MailboxSession.class)); JmapResponse expected = JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .error(ErrorResponse.builder() .type(SetVacationResponseMethod.INVALID_ARGUMENTS) .description(SetVacationResponseMethod.INVALID_ARGUMENT_DESCRIPTION) @@ -179,10 +179,10 @@ public class SetVacationResponseMethodTest { when(notificationRegistry.flush(any())) .thenReturn(Mono.empty()); - Stream<JmapResponse> result = testee.process(setVacationRequest, clientId, mailboxSession); + Stream<JmapResponse> result = testee.process(setVacationRequest, methodCallId, mailboxSession); JmapResponse expected = JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(SetVacationResponseMethod.RESPONSE_NAME) .response(SetVacationResponse.builder() .updatedId(Vacation.ID) @@ -206,10 +206,10 @@ public class SetVacationResponseMethodTest { .build(); when(mailboxSession.getUser()).thenReturn(USER); - Stream<JmapResponse> result = testee.process(setVacationRequest, clientId, mailboxSession); + Stream<JmapResponse> result = testee.process(setVacationRequest, methodCallId, mailboxSession); JmapResponse expected = JmapResponse.builder() - .clientId(clientId) + .methodCallId(methodCallId) .responseName(SetVacationResponseMethod.RESPONSE_NAME) .response(SetVacationResponse.builder() .notUpdated(Vacation.ID, SetError.builder() diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/InvocationRequestTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/InvocationRequestTest.java index 4122857..234f9d1 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/InvocationRequestTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/InvocationRequestTest.java @@ -89,6 +89,6 @@ public class InvocationRequestTest { assertThat(request.getMethodName()).isEqualTo(Method.Request.name("getAccounts")); assertThat(request.getParameters()).isNotNull(); - assertThat(request.getClientId()).isEqualTo(ClientId.of("#1")); + assertThat(request.getMethodCallId()).isEqualTo(MethodCallId.of("#1")); } } diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/InvocationResponseTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/InvocationResponseTest.java index 5af92e2..ed609a9 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/InvocationResponseTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/InvocationResponseTest.java @@ -31,27 +31,27 @@ public class InvocationResponseTest { @Test(expected = NullPointerException.class) public void newInstanceShouldThrowWhenMethodIsNull() { - new InvocationResponse(null, new ObjectNode(JsonNodeFactory.instance), ClientId.of("id")); + new InvocationResponse(null, new ObjectNode(JsonNodeFactory.instance), MethodCallId.of("id")); } @Test(expected = IllegalArgumentException.class) public void newInstanceShouldThrowWhenMethodIsEmpty() { - new InvocationResponse(Method.Response.name(""), new ObjectNode(JsonNodeFactory.instance), ClientId.of("id")); + new InvocationResponse(Method.Response.name(""), new ObjectNode(JsonNodeFactory.instance), MethodCallId.of("id")); } @Test(expected = NullPointerException.class) public void newInstanceShouldThrowWhenResultsIsNull() { - new InvocationResponse(Method.Response.name("method"), null, ClientId.of("id")); + new InvocationResponse(Method.Response.name("method"), null, MethodCallId.of("id")); } @Test(expected = NullPointerException.class) - public void newInstanceShouldThrowWhenClientIdIsNull() { + public void newInstanceShouldThrowWhenMethodCallIdIsNull() { new InvocationResponse(Method.Response.name("method"), new ObjectNode(new JsonNodeFactory(false)).putObject("{}"), null); } @Test public void asProtocolSpecificationShouldReturnAnArrayWithThreeElements() { - Object[] asProtocolSpecification = new InvocationResponse(Method.Response.name("method"), new ObjectNode(new JsonNodeFactory(false)).putObject("{}"), ClientId.of("#1")) + Object[] asProtocolSpecification = new InvocationResponse(Method.Response.name("method"), new ObjectNode(new JsonNodeFactory(false)).putObject("{}"), MethodCallId.of("#1")) .asProtocolSpecification(); assertThat(asProtocolSpecification).hasSize(3); diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ClientIdTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MethodCallIdTest.java similarity index 82% rename from server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ClientIdTest.java rename to server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MethodCallIdTest.java index ee9ecbe..b863f46 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ClientIdTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MethodCallIdTest.java @@ -23,22 +23,22 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.Test; -public class ClientIdTest { +public class MethodCallIdTest { @Test public void nullInputShouldThrow() { - assertThatThrownBy(() -> ClientId.of(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> MethodCallId.of(null)).isInstanceOf(NullPointerException.class); } @Test public void emptyInputShouldThrow() { - assertThatThrownBy(() -> ClientId.of("")).isInstanceOf(IllegalArgumentException.class); + assertThatThrownBy(() -> MethodCallId.of("")).isInstanceOf(IllegalArgumentException.class); } @Test - public void validInputShouldCreateClientId() { - ClientId testee = ClientId.of("valid"); + public void validInputShouldCreateMethodCallId() { + MethodCallId testee = MethodCallId.of("valid"); assertThat(testee).isNotNull(); assertThat(testee.getId()).isEqualTo("valid"); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
