This is an automated email from the ASF dual-hosted git repository. rcordier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 43bfc1d60716dedc2c884f60c402bdb023dc8c0d Author: Rene Cordier <rcord...@linagora.com> AuthorDate: Tue Mar 17 14:47:15 2020 +0700 JAMES-3092 Implement Version, Verb and Endpoint --- .../main/java/org/apache/james/jmap/Endpoint.java | 56 +++++++++++++++++ .../src/main/java/org/apache/james/jmap/Verb.java | 27 +++++++++ .../main/java/org/apache/james/jmap/Version.java | 70 ++++++++++++++++++++++ .../java/org/apache/james/jmap/EndpointTest.java | 33 ++++++++++ .../java/org/apache/james/jmap/VersionTest.java | 64 ++++++++++++++++++++ 5 files changed, 250 insertions(+) diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/Endpoint.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/Endpoint.java new file mode 100644 index 0000000..1c4680c --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/Endpoint.java @@ -0,0 +1,56 @@ +/**************************************************************** + * 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; + +import java.util.Objects; + +public class Endpoint { + private final Verb verb; + private final String path; + + public Endpoint(Verb verb, String path) { + this.verb = verb; + this.path = path; + } + + public Verb getVerb() { + return verb; + } + + public String getPath() { + return path; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof Endpoint) { + Endpoint endpoint = (Endpoint) o; + + return Objects.equals(this.verb, endpoint.verb) + && Objects.equals(this.path, endpoint.path); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(verb, path); + } +} diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/Verb.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/Verb.java new file mode 100644 index 0000000..f37ea9a --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/Verb.java @@ -0,0 +1,27 @@ +/**************************************************************** + * 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; + +public enum Verb { + GET, + POST, + DELETE, + OPTIONS +} diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/Version.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/Version.java new file mode 100644 index 0000000..61fd102 --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/Version.java @@ -0,0 +1,70 @@ +/**************************************************************** + * 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; + +import java.util.List; +import java.util.Objects; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +public class Version { + public static final Version DRAFT = new Version("draft"); + public static final Version RFC8621 = new Version("rfc-8621"); + + private static final List<Version> AVAILABLE_VERSIONS = ImmutableList.of( + DRAFT, + RFC8621 + ); + + public static Version of(String version) { + Preconditions.checkNotNull(version); + + return AVAILABLE_VERSIONS.stream() + .filter(jmapVersion -> jmapVersion.version.equalsIgnoreCase(version)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException(version + " is not a supported version")); + } + + private final String version; + + Version(String version) { + this.version = version; + } + + public String asString() { + return version; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof Version) { + Version version = (Version) o; + + return Objects.equals(this.version, version.version); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(version); + } +} diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/EndpointTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/EndpointTest.java new file mode 100644 index 0000000..1ce9b1d --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/EndpointTest.java @@ -0,0 +1,33 @@ +/**************************************************************** + * 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; + +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +class EndpointTest { + @Test + void shouldRespectBeanContract() { + EqualsVerifier.forClass(Endpoint.class) + .withIgnoredFields("uriPathTemplate") + .verify(); + } +} diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/VersionTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/VersionTest.java new file mode 100644 index 0000000..c94a8f7 --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/VersionTest.java @@ -0,0 +1,64 @@ +/**************************************************************** + * 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; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +class VersionTest { + @Test + void shouldRespectBeanContract() { + EqualsVerifier.forClass(Version.class) + .verify(); + } + + @Test + void ofShouldReturnCorrectValue() { + String version = "rfc-8621"; + + assertThat(Version.of(version)).isEqualTo(Version.RFC8621); + } + + @Test + void ofShouldThrowWhenVersionNotKnown() { + String version = "unknown"; + + assertThatThrownBy(() -> Version.of(version)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void ofShouldThrowWhenVersionIsNull() { + assertThatThrownBy(() -> Version.of(null)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void ofShouldThrowWhenVersionIsEmpty() { + String version = ""; + + assertThatThrownBy(() -> Version.of(version)) + .isInstanceOf(IllegalArgumentException.class); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org