JAMES-1717 Introduce JMAP vacation data model
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8aaaab0b Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8aaaab0b Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8aaaab0b Branch: refs/heads/master Commit: 8aaaab0b792128ee5d8ac42658a5c1c81c4ee009 Parents: 04978a9 Author: Benoit Tellier <[email protected]> Authored: Tue Apr 5 16:08:29 2016 +0700 Committer: Benoit Tellier <[email protected]> Committed: Fri Apr 22 15:28:55 2016 +0700 ---------------------------------------------------------------------- .../james/jmap/model/GetVacationRequest.java | 50 +++++++ .../james/jmap/model/GetVacationResponse.java | 89 ++++++++++++ .../james/jmap/model/SetVacationRequest.java | 73 ++++++++++ .../james/jmap/model/SetVacationResponse.java | 98 +++++++++++++ .../james/jmap/model/VacationResponse.java | 143 +++++++++++++++++++ .../jmap/model/GetVacationRequestTest.java | 32 +++++ .../jmap/model/GetVacationResponseTest.java | 51 +++++++ .../jmap/model/SetVacationRequestTest.java | 53 +++++++ .../jmap/model/SetVacationResponseTest.java | 46 ++++++ .../james/jmap/model/VacationResponseTest.java | 61 ++++++++ 10 files changed, 696 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/8aaaab0b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationRequest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationRequest.java new file mode 100644 index 0000000..9f77319 --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationRequest.java @@ -0,0 +1,50 @@ +/**************************************************************** + * 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.jmap.model; + +import org.apache.commons.lang.NotImplementedException; +import org.apache.james.jmap.methods.JmapRequest; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; + +@JsonDeserialize(builder = GetVacationRequest.Builder.class) +public class GetVacationRequest implements JmapRequest { + + public static Builder builder() { + return new Builder(); + } + + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + public Builder accountId(String accountId) { + throw new NotImplementedException(); + } + + public GetVacationRequest build() { + return new GetVacationRequest(); + } + } + + private GetVacationRequest() { + + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8aaaab0b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationResponse.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationResponse.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationResponse.java new file mode 100644 index 0000000..05768f2 --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetVacationResponse.java @@ -0,0 +1,89 @@ +/**************************************************************** + * 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.jmap.model; + +import java.util.List; +import java.util.Objects; + +import org.apache.james.jmap.methods.Method; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +public class GetVacationResponse implements Method.Response { + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private String accountId; + private VacationResponse vacationResponse; + + public Builder accountId(String accountId) { + this.accountId = accountId; + return this; + } + + public Builder vacationResponse(VacationResponse vacationResponse) { + this.vacationResponse = vacationResponse; + return this; + } + + public GetVacationResponse build() { + Preconditions.checkArgument(vacationResponse != null, "Account should contain exactly one vacation response"); + return new GetVacationResponse(accountId, vacationResponse); + } + } + + private final String accountId; + private final List<VacationResponse> list; + + private GetVacationResponse(String accountId, VacationResponse vacationResponse) { + this.accountId = accountId; + this.list = ImmutableList.of(vacationResponse); + } + + public String getAccountId() { + return accountId; + } + + public List<VacationResponse> getList() { + return list; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) { + return false; + } + + GetVacationResponse that = (GetVacationResponse) o; + + return Objects.equals(this.accountId, that.accountId) + && Objects.equals(this.list, that.list); + } + + @Override + public int hashCode() { + return Objects.hash(accountId, list); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8aaaab0b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationRequest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationRequest.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationRequest.java new file mode 100644 index 0000000..1ae21ef --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationRequest.java @@ -0,0 +1,73 @@ +/**************************************************************** + * 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.jmap.model; + +import java.util.Map; + +import org.apache.commons.lang.NotImplementedException; +import org.apache.james.jmap.methods.JmapRequest; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; + +@JsonDeserialize(builder = SetVacationRequest.Builder.class) +public class SetVacationRequest implements JmapRequest { + + public static Builder builder() { + return new Builder(); + } + + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + private Map<String, VacationResponse> update = Maps.newHashMap(); + + public Builder accountId(String accountId) { + throw new NotImplementedException(); + } + + public Builder update(Map<String, VacationResponse> update) { + this.update.putAll(update); + return this; + } + + @JsonIgnore + public Builder update(String id, VacationResponse vacationResponse) { + this.update.put(id, vacationResponse); + return this; + } + + public SetVacationRequest build() { + return new SetVacationRequest(ImmutableMap.copyOf(update)); + } + } + + private final Map<String, VacationResponse> update; + + private SetVacationRequest(Map<String, VacationResponse> update) { + this.update = update; + } + + public Map<String, VacationResponse> getUpdate() { + return update; + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8aaaab0b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationResponse.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationResponse.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationResponse.java new file mode 100644 index 0000000..5c8cac4 --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/SetVacationResponse.java @@ -0,0 +1,98 @@ +/**************************************************************** + * 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.jmap.model; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +import org.apache.james.jmap.methods.Method; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +public class SetVacationResponse implements Method.Response { + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private Optional<String> updatedId = Optional.empty(); + private Optional<String> notUpdatedId = Optional.empty(); + private Optional<SetError> setError = Optional.empty(); + + public Builder updatedId(String updatedId) { + Preconditions.checkNotNull(updatedId); + this.updatedId = Optional.of(updatedId); + return this; + } + + public Builder notUpdated(String id, SetError setError) { + Preconditions.checkNotNull(id); + Preconditions.checkNotNull(setError); + this.notUpdatedId = Optional.of(id); + this.setError = Optional.of(setError); + return this; + } + + public SetVacationResponse build() { + return new SetVacationResponse( + updatedId.map(ImmutableList::of), + notUpdatedId.map(id -> ImmutableMap.of(id, setError.get()))); + } + } + + private final Optional<List<String>> updated; + private final Optional<Map<String, SetError>> notUpdated; + + private SetVacationResponse(Optional<List<String>> updated, Optional<Map<String, SetError>> notUpdated) { + this.updated = updated; + this.notUpdated = notUpdated; + } + + public Optional<List<String>> getUpdated() { + return updated; + } + + public Optional<Map<String, SetError>> getNotUpdated() { + return notUpdated; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) { + return false; + } + + SetVacationResponse that = (SetVacationResponse) o; + + return Objects.equals(this.updated, that.updated) + && Objects.equals(this.notUpdated, that.notUpdated); + } + + @Override + public int hashCode() { + return Objects.hash(updated, notUpdated); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8aaaab0b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java new file mode 100644 index 0000000..4af3c5f --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java @@ -0,0 +1,143 @@ +/**************************************************************** + * 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.jmap.model; + +import java.time.ZonedDateTime; +import java.util.Objects; +import java.util.Optional; + +import org.apache.james.jmap.api.vacation.Vacation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.google.common.base.Preconditions; + +@JsonDeserialize(builder = VacationResponse.Builder.class) +public class VacationResponse { + + public static Builder builder() { + return new Builder(); + } + + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + private String id; + private boolean isEnabled; + private Optional<ZonedDateTime> fromDate = Optional.empty(); + private Optional<ZonedDateTime> toDate = Optional.empty(); + private String textBody; + + public Builder id(String id) { + this.id = id; + return this; + } + + @JsonProperty("isEnabled") + public Builder enabled(boolean enabled) { + isEnabled = enabled; + return this; + } + + public Builder fromDate(Optional<ZonedDateTime> fromDate) { + this.fromDate = fromDate; + return this; + } + + public Builder toDate(Optional<ZonedDateTime> toDate) { + this.toDate = toDate; + return this; + } + + public Builder textBody(String textBody) { + this.textBody = textBody; + return this; + } + + public Builder fromVacation(Vacation vacation) { + this.id = vacation.getId(); + this.isEnabled = vacation.isEnabled(); + this.fromDate = vacation.getFromDate(); + this.toDate = vacation.getToDate(); + this.textBody = vacation.getTextBody(); + return this; + } + + public VacationResponse build() { + Preconditions.checkState(textBody != null, "textBody property of vacationResponse object should not be null"); + return new VacationResponse(id, isEnabled, fromDate, toDate, textBody); + } + } + + private final String id; + private final boolean isEnabled; + private final Optional<ZonedDateTime> fromDate; + private final Optional<ZonedDateTime> toDate; + private final String textBody; + + private VacationResponse(String id, boolean isEnabled, Optional<ZonedDateTime> fromDate, Optional<ZonedDateTime> toDate, String textBody) { + this.id = id; + this.isEnabled = isEnabled; + this.fromDate = fromDate; + this.toDate = toDate; + this.textBody = textBody; + } + + public String getId() { + return id; + } + + @JsonProperty("isEnabled") + public boolean isEnabled() { + return isEnabled; + } + + public Optional<ZonedDateTime> getFromDate() { + return fromDate; + } + + public Optional<ZonedDateTime> getToDate() { + return toDate; + } + + public String getTextBody() { + return textBody; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) { + return false; + } + + VacationResponse that = (VacationResponse) o; + + return Objects.equals(this.id, that.id) + && Objects.equals(this.isEnabled, that.isEnabled) + && Objects.equals(this.fromDate, that.fromDate) + && Objects.equals(this.toDate, that.toDate) + && Objects.equals(this.textBody, that.textBody); + } + + @Override + public int hashCode() { + return Objects.hash(id, isEnabled, fromDate, toDate, textBody); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8aaaab0b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetVacationRequestTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetVacationRequestTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetVacationRequestTest.java new file mode 100644 index 0000000..c9d4293 --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetVacationRequestTest.java @@ -0,0 +1,32 @@ +/**************************************************************** + * 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.jmap.model; + +import org.apache.commons.lang.NotImplementedException; +import org.junit.Test; + +public class GetVacationRequestTest { + + @Test(expected = NotImplementedException.class) + public void accountIdHandlingIsNotImplementedYet() { + GetVacationRequest.builder() + .accountId("any"); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8aaaab0b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetVacationResponseTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetVacationResponseTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetVacationResponseTest.java new file mode 100644 index 0000000..4351513 --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetVacationResponseTest.java @@ -0,0 +1,51 @@ +/**************************************************************** + * 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.jmap.model; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class GetVacationResponseTest { + + public static final String IDENTIFIER = "identifier"; + + @Test + public void getVacationResponseShouldBeConstructedWithTheRightInformation() { + VacationResponse vacationResponse = VacationResponse.builder() + .textBody("Any text") + .id("singleton") + .build(); + GetVacationResponse getVacationResponse = GetVacationResponse.builder() + .accountId(IDENTIFIER) + .vacationResponse(vacationResponse) + .build(); + + assertThat(getVacationResponse.getAccountId()).isEqualTo(IDENTIFIER); + assertThat(getVacationResponse.getList()).containsExactly(vacationResponse); + } + + @Test(expected = IllegalArgumentException.class) + public void getVacationResponseShouldThrowIfNoVacationResponse() { + GetVacationResponse.builder() + .accountId(IDENTIFIER) + .build(); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8aaaab0b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetVacationRequestTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetVacationRequestTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetVacationRequestTest.java new file mode 100644 index 0000000..b46a6bd --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetVacationRequestTest.java @@ -0,0 +1,53 @@ +/**************************************************************** + * 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.jmap.model; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.AbstractMap; + +import org.apache.commons.lang.NotImplementedException; +import org.junit.Test; + +import com.google.common.collect.ImmutableMap; + +public class SetVacationRequestTest { + + public static final String VACATION_ID = "singleton"; + + @Test + public void setVacationRequestShouldBeConstructedWithTheRightInformation() { + VacationResponse vacationResponse = VacationResponse.builder().id(VACATION_ID).textBody("any message").build(); + SetVacationRequest setVacationRequest = SetVacationRequest.builder() + .update(ImmutableMap.of(VACATION_ID, vacationResponse)) + .build(); + + assertThat(setVacationRequest.getUpdate()).containsExactly(new AbstractMap.SimpleEntry<>(VACATION_ID, vacationResponse)); + } + + @Test(expected = NotImplementedException.class) + public void accountIdIsNotImplemented() { + VacationResponse vacationResponse = VacationResponse.builder().id(VACATION_ID).textBody("any message").build(); + SetVacationRequest.builder() + .accountId("any") + .update(ImmutableMap.of(VACATION_ID, vacationResponse)) + .build(); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8aaaab0b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetVacationResponseTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetVacationResponseTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetVacationResponseTest.java new file mode 100644 index 0000000..4d79ba4 --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetVacationResponseTest.java @@ -0,0 +1,46 @@ +/**************************************************************** + * 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.jmap.model; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.AbstractMap; + +import org.junit.Test; + +public class SetVacationResponseTest { + + public static final String UPDATED_VACATION_ID = "updatedVacationId"; + public static final String NOT_UPDATED_VACATION_ID = "notUpdatedVacationId"; + public static final String ERROR_TYPE = "Test Error"; + public static final String ERROR_DESCRIPTION = "Because an error is needed"; + + @Test + public void setVacationResponseShouldBeConstructedWithTheRightInformation() { + SetError setError = SetError.builder().type(ERROR_TYPE).description(ERROR_DESCRIPTION).build(); + SetVacationResponse setVacationResponse = SetVacationResponse.builder() + .updatedId(UPDATED_VACATION_ID) + .notUpdated(NOT_UPDATED_VACATION_ID, setError) + .build(); + + assertThat(setVacationResponse.getUpdated().get()).containsExactly(UPDATED_VACATION_ID); + assertThat(setVacationResponse.getNotUpdated().get()).containsExactly(new AbstractMap.SimpleEntry<>(NOT_UPDATED_VACATION_ID, setError)); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8aaaab0b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java new file mode 100644 index 0000000..c4d8aa7 --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java @@ -0,0 +1,61 @@ +/**************************************************************** + * 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.jmap.model; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.ZonedDateTime; +import java.util.Optional; + +import org.junit.Test; + +public class VacationResponseTest { + + public static final String IDENTIFIER = "identifier"; + public static final String MESSAGE = "A message explaining I am in vacation"; + public static final ZonedDateTime FROM_DATE = ZonedDateTime.parse("2016-04-15T11:56:32.224+07:00[Asia/Vientiane]"); + public static final ZonedDateTime TO_DATE = ZonedDateTime.parse("2016-04-16T11:56:32.224+07:00[Asia/Vientiane]"); + + @Test + public void vacationResponseBuilderShouldBeConstructedWithTheRightInformation() { + VacationResponse vacationResponse = VacationResponse.builder() + .id(IDENTIFIER) + .enabled(true) + .fromDate(Optional.of(FROM_DATE)) + .toDate(Optional.of(TO_DATE)) + .textBody(MESSAGE) + .build(); + + assertThat(vacationResponse.getId()).isEqualTo(IDENTIFIER); + assertThat(vacationResponse.isEnabled()).isEqualTo(true); + assertThat(vacationResponse.getTextBody()).isEqualTo(MESSAGE); + assertThat(vacationResponse.getFromDate()).contains(FROM_DATE); + assertThat(vacationResponse.getToDate()).contains(TO_DATE); + } + + @Test(expected = IllegalStateException.class) + public void vacationResponseBuilderRequiresABodyText() { + VacationResponse.builder() + .id(IDENTIFIER) + .enabled(true) + .build(); + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
