You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ch...@apache.org on 2017/09/28 11:01:04 UTC

[6/7] flink git commit: [FLINK-7725] [REST] Add testbase for requests / allow exceptions

[FLINK-7725] [REST] Add testbase for requests / allow exceptions


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/426137f5
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/426137f5
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/426137f5

Branch: refs/heads/master
Commit: 426137f5100d213c9c9c2f05c81f63f1f52ed33e
Parents: 40948d3
Author: zentol <ch...@apache.org>
Authored: Thu Sep 28 10:25:58 2017 +0200
Committer: zentol <ch...@apache.org>
Committed: Thu Sep 28 11:28:33 2017 +0200

----------------------------------------------------------------------
 .../RestRequestMarshallingTestBase.java         | 63 ++++++++++++++++++++
 .../RestResponseMarshallingTestBase.java        |  6 +-
 2 files changed, 65 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/426137f5/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/messages/RestRequestMarshallingTestBase.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/messages/RestRequestMarshallingTestBase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/messages/RestRequestMarshallingTestBase.java
new file mode 100644
index 0000000..2eb37cb
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/messages/RestRequestMarshallingTestBase.java
@@ -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.flink.runtime.rest.handler.legacy.messages;
+
+import org.apache.flink.runtime.rest.messages.RequestBody;
+import org.apache.flink.runtime.rest.util.RestMapperUtils;
+import org.apache.flink.util.TestLogger;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test base for verifying that marshalling / unmarshalling REST {@link RequestBody}s work properly.
+ */
+public abstract class RestRequestMarshallingTestBase<R extends RequestBody> extends TestLogger {
+
+	/**
+	 * Returns the class of the test response.
+	 *
+	 * @return class of the test response type
+	 */
+	protected abstract Class<R> getTestRequestClass();
+
+	/**
+	 * Returns an instance of a response to be tested.
+	 *
+	 * @return instance of the expected test response
+	 */
+	protected abstract R getTestRequestInstance() throws Exception;
+
+	/**
+	 * Tests that we can marshal and unmarshal the response.
+	 */
+	@Test
+	public void testJsonMarshalling() throws Exception {
+		final R expected = getTestRequestInstance();
+
+		ObjectMapper objectMapper = RestMapperUtils.getStrictObjectMapper();
+		JsonNode json = objectMapper.valueToTree(expected);
+
+		final R unmarshalled = objectMapper.treeToValue(json, getTestRequestClass());
+		Assert.assertEquals(expected, unmarshalled);
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/flink/blob/426137f5/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/messages/RestResponseMarshallingTestBase.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/messages/RestResponseMarshallingTestBase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/messages/RestResponseMarshallingTestBase.java
index fce60ac..db44b08 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/messages/RestResponseMarshallingTestBase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/messages/RestResponseMarshallingTestBase.java
@@ -22,10 +22,8 @@ import org.apache.flink.runtime.rest.messages.ResponseBody;
 import org.apache.flink.runtime.rest.util.RestMapperUtils;
 import org.apache.flink.util.TestLogger;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
-
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -46,13 +44,13 @@ public abstract class RestResponseMarshallingTestBase<R extends ResponseBody> ex
 	 *
 	 * @return instance of the expected test response
 	 */
-	protected abstract R getTestResponseInstance();
+	protected abstract R getTestResponseInstance() throws Exception;
 
 	/**
 	 * Tests that we can marshal and unmarshal the response.
 	 */
 	@Test
-	public void testJsonMarshalling() throws JsonProcessingException {
+	public void testJsonMarshalling() throws Exception {
 		final R expected = getTestResponseInstance();
 
 		ObjectMapper objectMapper = RestMapperUtils.getStrictObjectMapper();