moresandeep commented on a change in pull request #211: KNOX-2144 - Alias API 
KnoxShell support should provide response types…
URL: https://github.com/apache/knox/pull/211#discussion_r354395020
 
 

 ##########
 File path: 
gateway-shell/src/test/java/org/apache/knox/gateway/shell/alias/AbstractResponseTest.java
 ##########
 @@ -0,0 +1,158 @@
+/*
+ * 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.knox.gateway.shell.alias;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.StatusLine;
+import org.apache.http.entity.StringEntity;
+import org.apache.knox.gateway.shell.KnoxShellException;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public abstract class AbstractResponseTest<T extends AliasResponse> {
+
+  @Test
+  public void testInvalidResponseStatus() {
+    // Anything other than the expected response status
+    HttpResponse httpResponse =
+        createTestResponse(createTestStatusLine(HttpStatus.SC_BAD_REQUEST, 
"Bad Request"), null);
+
+    try {
+      createResponse(httpResponse);
+    } catch (KnoxShellException e) {
+      // Expected
+      assertEquals("Unexpected response: " + 
httpResponse.getStatusLine().getReasonPhrase(), e.getMessage());
+    } catch (Exception e) {
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void testMissingResponseEntity() {
+    HttpResponse httpResponse = 
createTestResponse(createTestStatusLine(getExpectedResponseStatusCode()), null);
+
+    try {
+      createResponse(httpResponse);
+    } catch (KnoxShellException e) {
+      // Expected
+      assertEquals("Missing expected response content", e.getMessage());
+    } catch (Exception e) {
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void testInvalidResponseJSON() {
+    StringEntity entity = null;
+    try {
+      entity = new StringEntity("{ \"topology\": \"testInvalidJSONCluster\", 
\"aliases\" : [ ");
+      entity.setContentType("application/json");
+    } catch (UnsupportedEncodingException e) {
+      fail(e.getMessage());
+    }
+
+    HttpResponse httpResponse = 
createTestResponse(createTestStatusLine(getExpectedResponseStatusCode()), 
entity);
+
+    try {
+      createResponse(httpResponse);
+    } catch (KnoxShellException e) {
+      // Expected
+      assertEquals("Unable to process response content", e.getMessage());
+      assertTrue(e.getCause().getMessage().contains("Unexpected 
end-of-input"));
+    } catch (Exception e) {
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void testInvalidResponseContentType() {
+    StringEntity entity = null;
+    try {
+      entity = new StringEntity("{ \"topology\": \"testInvalidJSONCluster\", 
\"aliases\" : [ ");
 
 Review comment:
   The json object is invalid.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to