JAMES-2183 Add util to build Flags from list of String We need it to enable invalid keyword testing in JMAP integration tests.
Previously, cucumber generated flags relied on JMAP Keyword, thus we could not create invalid keyword. Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/747e3f19 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/747e3f19 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/747e3f19 Branch: refs/heads/master Commit: 747e3f19dd03fba3e18c47d89507a743507b1132 Parents: 3fabba9 Author: quynhn <qngu...@linagora.com> Authored: Fri Oct 13 10:22:01 2017 +0700 Committer: benwa <btell...@linagora.com> Committed: Wed Oct 18 09:00:38 2017 +0700 ---------------------------------------------------------------------- .../cucumber/GetMessagesMethodStepdefs.java | 8 +- .../integration/cucumber/StringListToFlags.java | 62 +++++++++++++++ .../cucumber/StringListToFlagsTest.java | 80 ++++++++++++++++++++ 3 files changed, 144 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/747e3f19/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java index 05657a2..cc9f465 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java @@ -42,7 +42,6 @@ import org.apache.http.HttpResponse; import org.apache.http.client.fluent.Request; import org.apache.james.jmap.DefaultMailboxes; import org.apache.james.jmap.methods.integration.cucumber.util.TableRow; -import org.apache.james.jmap.model.Keywords; import org.apache.james.jmap.model.MessagePreviewGenerator; import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxId; @@ -248,11 +247,8 @@ public class GetMessagesMethodStepdefs { } @Given("^the user has a message \"([^\"]*)\" in the \"([^\"]*)\" mailbox with flags \"([^\"]*)\"$") - public void appendMessageWithFlags(String messageName, String mailbox, List<String> keywords) throws Exception { - Flags flags = Keywords.factory() - .fromList(keywords) - .asFlags(); - appendMessage(messageName, flags); + public void appendMessageWithFlags(String messageName, String mailbox, List<String> flagList) throws Exception { + appendMessage(messageName, FlagListToFlags.fromFlagList(flagList)); } private void appendMessage(String messageName, Flags flags) throws Exception { http://git-wip-us.apache.org/repos/asf/james-project/blob/747e3f19/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlags.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlags.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlags.java new file mode 100644 index 0000000..36a273f --- /dev/null +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlags.java @@ -0,0 +1,62 @@ +/**************************************************************** + * 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.methods.integration.cucumber; + +import java.util.List; + +import javax.mail.Flags; + +import org.apache.james.jmap.model.Keyword; +import org.apache.james.mailbox.FlagsBuilder; + +import com.github.steveash.guavate.Guavate; +import com.google.common.collect.ImmutableList; + +public class StringListToFlags { + public static Flags fromFlagList(List<String> flagList) { + ImmutableList<Flags> flags = flagList.stream() + .map(StringListToFlags::toFlags) + .collect(Guavate.toImmutableList()); + return new FlagsBuilder().add(flags) + .build(); + } + + private static Flags toFlags(String flag) { + if (Keyword.ANSWERED.getFlagName().equals(flag)) { + return new Flags(Flags.Flag.ANSWERED); + } + if (Keyword.DELETED.getFlagName().equals(flag)) { + return new Flags(Flags.Flag.DELETED); + } + if (Keyword.DRAFT.getFlagName().equals(flag)) { + return new Flags(Flags.Flag.DRAFT); + } + if (Keyword.RECENT.getFlagName().equals(flag)) { + return new Flags(Flags.Flag.RECENT); + } + if (Keyword.FLAGGED.getFlagName().equals(flag)) { + return new Flags(Flags.Flag.FLAGGED); + } + if (Keyword.SEEN.getFlagName().equals(flag)) { + return new Flags(Flags.Flag.SEEN); + } + return new Flags(flag); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/747e3f19/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlagsTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlagsTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlagsTest.java new file mode 100644 index 0000000..9ae5aa0 --- /dev/null +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/StringListToFlagsTest.java @@ -0,0 +1,80 @@ +/**************************************************************** + * 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.methods.integration.cucumber; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.mail.Flags; +import javax.mail.Flags.Flag; + +import org.apache.james.jmap.model.Keyword; +import org.junit.Test; +import org.testcontainers.shaded.com.google.common.collect.ImmutableList; + +public class StringListToFlagsTest { + @Test + public void fromFlagListShouldConvertAnwseredFlag() throws Exception { + assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.ANSWERED.getFlagName()))) + .isEqualTo(new Flags(Flag.ANSWERED)); + } + + @Test + public void fromFlagListShouldConvertSeenFlag() throws Exception { + assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.SEEN.getFlagName()))) + .isEqualTo(new Flags(Flag.SEEN)); + } + + @Test + public void fromFlagListShouldConvertDraftFlag() throws Exception { + assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.DRAFT.getFlagName()))) + .isEqualTo(new Flags(Flag.DRAFT)); + } + + @Test + public void fromFlagListShouldConvertRecentFlag() throws Exception { + assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.RECENT.getFlagName()))) + .isEqualTo(new Flags(Flag.RECENT)); + } + + @Test + public void fromFlagListShouldConvertDeletedFlag() throws Exception { + assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.DELETED.getFlagName()))) + .isEqualTo(new Flags(Flag.DELETED)); + } + + @Test + public void fromFlagListShouldConvertFlaggedFlag() throws Exception { + assertThat(StringListToFlags.fromFlagList(ImmutableList.of(Keyword.FLAGGED.getFlagName()))) + .isEqualTo(new Flags(Flag.FLAGGED)); + } + + @Test + public void fromFlagListShouldConvertValidJMAPFlag() throws Exception { + assertThat(StringListToFlags.fromFlagList(ImmutableList.of("$Any"))) + .isEqualTo(new Flags("$Any")); + } + + @Test + public void fromFlagListShouldConvertInvalidJMAPFlag() throws Exception { + assertThat(StringListToFlags.fromFlagList(ImmutableList.of("op§"))) + .isEqualTo(new Flags("op§")); + } + +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org