Author: matthieu
Date: Fri Dec 11 10:08:25 2015
New Revision: 1719322
URL: http://svn.apache.org/viewvc?rev=1719322&view=rev
Log:
JAMES-1644 Implement Jmap Servlet for generic request handling
Added:
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServlet.java
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolRequest.java
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolResponse.java
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolRequestTest.java
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolResponseTest.java
Added:
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServlet.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServlet.java?rev=1719322&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServlet.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServlet.java
Fri Dec 11 10:08:25 2015
@@ -0,0 +1,79 @@
+/****************************************************************
+ * 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 javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import javax.inject.Inject;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.james.jmap.methods.RequestHandler;
+import org.apache.james.jmap.model.ProtocolRequest;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.annotations.VisibleForTesting;
+
+public class JMAPServlet extends HttpServlet {
+
+ public static final String JSON_CONTENT_TYPE = "application/json";
+ public static final String JSON_CONTENT_TYPE_UTF8 = "application/json;
charset=UTF-8";
+
+ private final RequestHandler requestHandler;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ @VisibleForTesting JMAPServlet(RequestHandler requestHandler) {
+ this.requestHandler = requestHandler;
+ this.objectMapper = new ObjectMapper();
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException {
+ try {
+ List<Object[]> responses =
+ requestAsJsonStream(req)
+ .map(ProtocolRequest::deserialize)
+ .map(requestHandler::process)
+ .map(protocolResponse ->
protocolResponse.asProtocolSpecification())
+ .collect(Collectors.toList());
+
+ objectMapper.writeValue(resp.getOutputStream(), responses);
+ } catch (IOException e) {
+ resp.setStatus(SC_BAD_REQUEST);
+ }
+ }
+
+ private Stream<JsonNode[]> requestAsJsonStream(HttpServletRequest req)
throws IOException, JsonParseException, JsonMappingException {
+ return Arrays.stream(
+ objectMapper.readValue(req.getInputStream(),
JsonNode[][].class));
+ }
+
+}
Added:
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java?rev=1719322&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java
Fri Dec 11 10:08:25 2015
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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;
+
+import org.apache.james.jmap.model.ProtocolRequest;
+import org.apache.james.jmap.model.ProtocolResponse;
+
+public interface RequestHandler {
+
+ ProtocolResponse process(ProtocolRequest request);
+}
Added:
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolRequest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolRequest.java?rev=1719322&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolRequest.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolRequest.java
Fri Dec 11 10:08:25 2015
@@ -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.model;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Preconditions;
+
+public class ProtocolRequest {
+
+ public static ProtocolRequest deserialize(JsonNode[] json) {
+ Preconditions.checkState(json.length == 3, "should have three
elements");
+ 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 ProtocolRequest(json[0].textValue(), (ObjectNode) json[1],
json[2].textValue());
+ }
+
+ private final String method;
+ private final ObjectNode parameters;
+ private final String clientId;
+
+ private ProtocolRequest(String method, ObjectNode parameters, String
clientId) {
+ this.method = method;
+ this.parameters = parameters;
+ this.clientId = clientId;
+ }
+
+ public String getMethod() {
+ return method;
+ }
+
+ public ObjectNode getParameters() {
+ return parameters;
+ }
+
+ public String getClientId() {
+ return clientId;
+ }
+}
\ No newline at end of file
Added:
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolResponse.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolResponse.java?rev=1719322&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolResponse.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolResponse.java
Fri Dec 11 10:08:25 2015
@@ -0,0 +1,55 @@
+/****************************************************************
+ * 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 com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
+public class ProtocolResponse {
+
+ private final String method;
+ private final ObjectNode results;
+ private final String clientId;
+
+ public ProtocolResponse(String method, ObjectNode results, String
clientId) {
+ Preconditions.checkState(!Strings.isNullOrEmpty(method), "method is
mandatory");
+ Preconditions.checkState(results != null, "results is mandatory");
+ Preconditions.checkState(!Strings.isNullOrEmpty(clientId), "clientId
is mandatory");
+ this.method = method;
+ this.results = results;
+ this.clientId = clientId;
+ }
+
+ public String getMethod() {
+ return method;
+ }
+
+ public ObjectNode getResults() {
+ return results;
+ }
+
+ public String getClientId() {
+ return clientId;
+ }
+
+ public Object[] asProtocolSpecification() {
+ return new Object[] { getMethod(), getResults(), getClientId() };
+ }
+}
\ No newline at end of file
Added:
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java?rev=1719322&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
Fri Dec 11 10:08:25 2015
@@ -0,0 +1,139 @@
+/****************************************************************
+ * 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 com.jayway.restassured.RestAssured.given;
+import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
+import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
+import static org.hamcrest.Matchers.equalTo;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.james.http.jetty.Configuration;
+import org.apache.james.http.jetty.JettyHttpServer;
+import org.apache.james.jmap.methods.RequestHandler;
+import org.apache.james.jmap.model.ProtocolResponse;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Charsets;
+import com.jayway.restassured.RestAssured;
+import com.jayway.restassured.http.ContentType;
+
+public class JMAPServletTest {
+
+ private JettyHttpServer server;
+ private RequestHandler requestHandler;
+
+ @Before
+ public void setup() throws Exception {
+ requestHandler = mock(RequestHandler.class);
+ JMAPServlet jmapServlet = new JMAPServlet(requestHandler);
+
+ server = JettyHttpServer.create(
+ Configuration.builder()
+ .serve("/*")
+ .with(jmapServlet)
+ .randomPort()
+ .build());
+
+
+ server.start();
+
+ RestAssured.port = server.getPort();
+ RestAssured.config =
newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8));
+ }
+
+
+ @After
+ public void teardown() throws Exception {
+ server.stop();
+ }
+
+ @Test
+ public void mustReturnBadRequestOnMalformedRequest() {
+ String missingAnOpeningBracket = "[\"getAccounts\", {\"state\":false},
\"#0\"]]";
+
+ given()
+ .accept(ContentType.JSON)
+ .contentType(ContentType.JSON)
+ .body(missingAnOpeningBracket)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400);
+ }
+
+ @Test
+ public void mustReturnInvalidArgumentOnInvalidState() {
+ ObjectNode json = new ObjectNode(new JsonNodeFactory(false));
+ json.put("type", "invalidArgument");
+
+ when(requestHandler.process(any()))
+ .thenReturn(new ProtocolResponse("error", json, "#0"));
+
+ given()
+ .accept(ContentType.JSON)
+ .contentType(ContentType.JSON)
+ .body("[[\"getAccounts\", {\"state\":false}, \"#0\"]]")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+
.content(equalTo("[[\"error\",{\"type\":\"invalidArgument\"},\"#0\"]]"));
+ }
+
+ @Test
+ public void mustReturnAccountsOnValidRequest() {
+ ObjectNode json = new ObjectNode(new JsonNodeFactory(false));
+ json.put("state", "f6a7e214");
+ ArrayNode arrayNode = json.putArray("list");
+ ObjectNode list = new ObjectNode(new JsonNodeFactory(false));
+ list.put("id", "6asf5");
+ list.put("name", "roger@barcamp");
+ arrayNode.add(list);
+
+ when(requestHandler.process(any()))
+ .thenReturn(new ProtocolResponse("accounts", json, "#0"));
+
+ given()
+ .accept(ContentType.JSON)
+ .contentType(ContentType.JSON)
+ .body("[[\"getAccounts\", {}, \"#0\"]]")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .content(equalTo("[[\"accounts\",{" +
+ "\"state\":\"f6a7e214\"," +
+ "\"list\":[" +
+ "{" +
+ "\"id\":\"6asf5\"," +
+ "\"name\":\"roger@barcamp\"" +
+ "}" +
+ "]" +
+ "},\"#0\"]]"));
+ }
+
+}
Added:
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolRequestTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolRequestTest.java?rev=1719322&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolRequestTest.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolRequestTest.java
Fri Dec 11 10:08:25 2015
@@ -0,0 +1,93 @@
+/****************************************************************
+ * 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.io.IOException;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class ProtocolRequestTest {
+
+ @Test(expected=IllegalStateException.class)
+ public void deserializedRequestsShouldThrowWhenNotEnoughElements() throws
Exception {
+ JsonNode[] nodes = new JsonNode[] { new ObjectNode(new
JsonNodeFactory(false)).textNode("getAccounts"),
+ new ObjectNode(new JsonNodeFactory(false)).putObject("{}")} ;
+
+ ProtocolRequest.deserialize(nodes);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void deserializedRequestsShouldThrowWhenTooMuchElements() throws
Exception {
+ JsonNode[] nodes = new JsonNode[] { new ObjectNode(new
JsonNodeFactory(false)).textNode("getAccounts"),
+ new ObjectNode(new JsonNodeFactory(false)).putObject("{}"),
+ new ObjectNode(new JsonNodeFactory(false)).textNode("#0"),
+ new ObjectNode(new
JsonNodeFactory(false)).textNode("tooMuch")} ;
+
+ ProtocolRequest.deserialize(nodes);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void deserializedRequestsShouldThrowWhenFirstParameterIsNotString()
throws JsonParseException, JsonMappingException, IOException {
+ JsonNode[] nodes = new JsonNode[] { new ObjectNode(new
JsonNodeFactory(false)).booleanNode(true),
+ new ObjectNode(new JsonNodeFactory(false)).putObject("{}"),
+ new ObjectNode(new JsonNodeFactory(false)).textNode("#0")} ;
+
+ ProtocolRequest.deserialize(nodes);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void deserializedRequestsShouldThrowWhenSecondParameterIsNotJson()
throws JsonParseException, JsonMappingException, IOException {
+ JsonNode[] nodes = new JsonNode[] { new ObjectNode(new
JsonNodeFactory(false)).textNode("getAccounts"),
+ new ObjectNode(new JsonNodeFactory(false)).textNode("true"),
+ new ObjectNode(new JsonNodeFactory(false)).textNode("#0")} ;
+
+ ProtocolRequest.deserialize(nodes);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void deserializedRequestsShouldThrowWhenThirdParameterIsNotString()
throws JsonParseException, JsonMappingException, IOException {
+ JsonNode[] nodes = new JsonNode[] { new ObjectNode(new
JsonNodeFactory(false)).textNode("getAccounts"),
+ new ObjectNode(new JsonNodeFactory(false)).putObject("{}"),
+ new ObjectNode(new JsonNodeFactory(false)).booleanNode(true)} ;
+
+ ProtocolRequest.deserialize(nodes);
+ }
+
+ @Test
+ public void deserializedRequestsShouldWorkWhenSingleRequest() throws
JsonParseException, JsonMappingException, IOException {
+ JsonNode[] nodes = new JsonNode[] { new ObjectNode(new
JsonNodeFactory(false)).textNode("getAccounts"),
+ new ObjectNode(new JsonNodeFactory(false)).putObject("{\"id\":
\"id\"}"),
+ new ObjectNode(new JsonNodeFactory(false)).textNode("#1")} ;
+
+ ProtocolRequest request = ProtocolRequest.deserialize(nodes);
+
+ assertThat(request.getMethod()).isEqualTo("getAccounts");
+ assertThat(request.getParameters()).isNotNull();
+ assertThat(request.getClientId()).isEqualTo("#1");
+ }
+}
Added:
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolResponseTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolResponseTest.java?rev=1719322&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolResponseTest.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolResponseTest.java
Fri Dec 11 10:08:25 2015
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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;
+
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class ProtocolResponseTest {
+
+ @Test(expected=IllegalStateException.class)
+ public void newInstanceShouldThrowWhenMethodIsNull() {
+ new ProtocolResponse(null, null, null);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void newInstanceShouldThrowWhenMethodIsEmpty() {
+ new ProtocolResponse("", null, null);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void newInstanceShouldThrowWhenResultsIsNull() {
+ new ProtocolResponse("method", null, null);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void newInstanceShouldThrowWhenClientIdIsNull() {
+ new ProtocolResponse("method", new ObjectNode(new
JsonNodeFactory(false)).putObject("{}"), null);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void newInstanceShouldThrowWhenClientIdIsEmpty() {
+ new ProtocolResponse("method", new ObjectNode(new
JsonNodeFactory(false)).putObject("{}"), "");
+ }
+
+ @Test
+ public void asProtocolSpecificationShouldReturnAnArrayWithThreeElements() {
+ Object[] asProtocolSpecification = new ProtocolResponse("method", new
ObjectNode(new JsonNodeFactory(false)).putObject("{}"), "#1")
+ .asProtocolSpecification();
+
+ assertThat(asProtocolSpecification).hasSize(3);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]