[
https://issues.apache.org/jira/browse/KNOX-2144?focusedWorklogId=354408&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-354408
]
ASF GitHub Bot logged work on KNOX-2144:
----------------------------------------
Author: ASF GitHub Bot
Created on: 05/Dec/19 15:56
Start Date: 05/Dec/19 15:56
Worklog Time Spent: 10m
Work Description: moresandeep commented on 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 entity 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]
Issue Time Tracking
-------------------
Worklog Id: (was: 354408)
Time Spent: 0.5h (was: 20m)
> Alias API KnoxShell support should provide response types better than raw JSON
> ------------------------------------------------------------------------------
>
> Key: KNOX-2144
> URL: https://issues.apache.org/jira/browse/KNOX-2144
> Project: Apache Knox
> Issue Type: Improvement
> Components: KnoxShell
> Affects Versions: 1.3.0
> Reporter: Philip Zampino
> Assignee: Philip Zampino
> Priority: Minor
> Attachments: ExampleAliases.groovy
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> Like many of the other KnoxShell classes, the responses are essentially JSON,
> which the client has to process itself. For the Alias API interactions, the
> responses could be processed by the KnoxShell classes themselves, especially
> since it's a Knox API.
> So, instead of
> {code:java}
> response = Alias.list(session, clusterName).now()
> json = (new JsonSlurper()).parseText( response.string )
> cluster = json.topology
> aliases = json.aliases
> {code}
> the response type would provide methods for getting the response details
> {code:java}
> response = Alias.list(session, clusterName).now()
> cluster = response.getCluster()
> aliases = response.getAliases(){code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)