geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [04/15] geode git commit: GEODE-2294: When attempting to execute a function via Dev Rest API, error messages are being lost
Date Mon, 30 Jan 2017 20:52:51 GMT
GEODE-2294: When attempting to execute a function via Dev Rest API, error messages are being
lost


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

Branch: refs/heads/feature/GEODE-1930-2
Commit: c39585395af20cc9d9174e00cd156d6f2c2ef9ae
Parents: 3db075c
Author: Kevin J. Duling <kduling@pivotal.io>
Authored: Thu Jan 26 08:38:37 2017 -0800
Committer: Kevin J. Duling <kduling@pivotal.io>
Committed: Fri Jan 27 13:27:27 2017 -0800

----------------------------------------------------------------------
 geode-web-api/build.gradle                      |  2 +
 .../web/controllers/AbstractBaseController.java |  9 +--
 .../AbstractBaseControllerJUnitTest.java        | 80 ++++++++++++++++++++
 3 files changed, 84 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/c3958539/geode-web-api/build.gradle
----------------------------------------------------------------------
diff --git a/geode-web-api/build.gradle b/geode-web-api/build.gradle
index f74b86f..9c491a0 100755
--- a/geode-web-api/build.gradle
+++ b/geode-web-api/build.gradle
@@ -61,6 +61,8 @@ dependencies {
     exclude module: 'spring-beans'
   }
 
+  testCompile project(':geode-junit')
+
   provided 'javax.servlet:javax.servlet-api:' + project.'javax.servlet-api.version'
   provided project(':geode-core')
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/c3958539/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseController.java
----------------------------------------------------------------------
diff --git a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseController.java
b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseController.java
index dab4cd9..68080a3 100644
--- a/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseController.java
+++ b/geode-web-api/src/main/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseController.java
@@ -67,8 +67,6 @@ import org.springframework.util.StringUtils;
 import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
 
 import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URLDecoder;
@@ -739,14 +737,11 @@ public abstract class AbstractBaseController {
   }
 
   protected String convertErrorAsJson(String errorMessage) {
-    return ("{" + "\"cause\"" + ":" + "\"" + errorMessage + "\"" + "}");
+    return ("{" + "\"message\"" + ":" + "\"" + errorMessage + "\"" + "}");
   }
 
   protected String convertErrorAsJson(Throwable t) {
-    StringWriter writer = new StringWriter();
-    t.printStackTrace(new PrintWriter(writer));
-    return String.format("{\"message\" : \"%1$s\", \"stackTrace\" : \"%2$s\"}", t.getMessage(),
-        writer.toString());
+    return String.format("{\"message\" : \"%1$s\"}", t.getMessage());
   }
 
   protected Map<?, ?> convertJsonToMap(final String jsonString) {

http://git-wip-us.apache.org/repos/asf/geode/blob/c3958539/geode-web-api/src/test/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseControllerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-web-api/src/test/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseControllerJUnitTest.java
b/geode-web-api/src/test/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseControllerJUnitTest.java
new file mode 100644
index 0000000..7ebfbcf
--- /dev/null
+++ b/geode-web-api/src/test/java/org/apache/geode/rest/internal/web/controllers/AbstractBaseControllerJUnitTest.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.geode.rest.internal.web.controllers;
+
+import static org.junit.Assert.assertEquals;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.geode.rest.internal.web.exception.GemfireRestException;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * AbstractBaseController Tester.
+ */
+@Category(UnitTest.class)
+public class AbstractBaseControllerJUnitTest {
+
+  AbstractBaseController abstractBaseController = new AbstractBaseController() {
+    @Override
+    protected String getRestApiVersion() {
+      return "1.0";
+    }
+  };
+  ObjectMapper mapper = new ObjectMapper();
+
+  /**
+   * Method: convertErrorAsJson(String errorMessage)
+   */
+  @Test
+  public void testConvertErrorAsJsonErrorMessage() throws Exception {
+    String message = "This is an error message";
+    String json = abstractBaseController.convertErrorAsJson(message);
+    ErrorMessage errorMessage = mapper.readValue(json, ErrorMessage.class);
+    assertEquals(message, errorMessage.message);
+  }
+
+  /**
+   * Method: convertErrorAsJson(Throwable t)
+   */
+  @Test
+  public void testConvertErrorAsJsonT() throws Exception {
+    String message = "This is an error message";
+    Exception e = new GemfireRestException(message, new NullPointerException());
+    String json = abstractBaseController.convertErrorAsJson(e);
+    ErrorMessage errorMessage = mapper.readValue(json, ErrorMessage.class);
+    assertEquals(message, errorMessage.message);
+  }
+
+  public static class ErrorMessage {
+    private String message;
+
+    public ErrorMessage() {}
+
+    public ErrorMessage(String message) {
+      this.message = message;
+    }
+
+    public String getMessage() {
+      return message;
+    }
+
+    public void setMessage(final String message) {
+      this.message = message;
+    }
+  }
+
+}


Mime
View raw message