knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject knox git commit: KNOX-978 - Add a test for the SOLR REST API
Date Tue, 29 Aug 2017 13:50:49 GMT
Repository: knox
Updated Branches:
  refs/heads/master ac532bd73 -> d2f0fc0e5


KNOX-978 - Add a test for the SOLR REST API


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

Branch: refs/heads/master
Commit: d2f0fc0e5ec07d0e8d4633ce8bc0f0723a34efbe
Parents: ac532bd
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Tue Jun 27 11:13:56 2017 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Tue Aug 29 14:50:24 2017 +0100

----------------------------------------------------------------------
 .../hadoop/gateway/GatewayBasicFuncTest.java    | 39 +++++++++++++++++++-
 .../solr/query_response.xml                     | 20 ++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/d2f0fc0e/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
index 2cc1573..d8f1352 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
@@ -92,6 +92,7 @@ import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.text.IsEmptyString.isEmptyString;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
 import static org.xmlmatchers.XmlMatchers.isEquivalentTo;
 import static org.xmlmatchers.transform.XmlConverters.the;
 import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
@@ -161,6 +162,7 @@ public class GatewayBasicFuncTest {
     driver.setupService( "FALCON", "http://" + TEST_HOST + ":15000", "/cluster/falcon", USE_MOCK_SERVICES
);
     driver.setupService( "STORM", "http://" + TEST_HOST + ":8477", "/cluster/storm", USE_MOCK_SERVICES
);
     driver.setupService( "STORM-LOGVIEWER", "http://" + TEST_HOST + ":8477", "/cluster/storm",
USE_MOCK_SERVICES );
+    driver.setupService( "SOLR", "http://" + TEST_HOST + ":8983", "/cluster/solr", USE_MOCK_SERVICES
);
     driver.setupGateway( config, "cluster", createTopology(), USE_GATEWAY );
     LOG_EXIT();
   }
@@ -263,6 +265,9 @@ public class GatewayBasicFuncTest {
             .addTag("role").addText("STORM-LOGVIEWER")
             .addTag("url").addText(driver.getRealUrl("STORM-LOGVIEWER")).gotoParent()
         .addTag("service")
+            .addTag("role").addText("SOLR")
+            .addTag("url").addText(driver.getRealUrl("SOLR")).gotoParent()
+        .addTag("service")
         .addTag("role").addText("SERVICE-TEST")
         .gotoRoot();
 //     System.out.println( "GATEWAY=" + xml.toString() );
@@ -3703,6 +3708,38 @@ public class GatewayBasicFuncTest {
     LOG_EXIT();
   }
 
+  @Test( timeout = TestUtils.MEDIUM_TIMEOUT )
+  public void testSolrRESTAPI() throws Exception {
+    LOG_ENTER();
+    String resourceName = "solr/query_response.xml";
+    String username = "hdfs";
+    String password = "hdfs-password";
+
+    String gatewayPath = driver.getUrl( "SOLR" ) + "/gettingstarted/select?q=author_s:William+Shakespeare";
+    driver.getMock("SOLR")
+        .expect()
+        .method("GET")
+        .pathInfo("/gettingstarted/select")
+        .queryParam("q", "author_s:William+Shakespeare")
+        .respond()
+        .status(HttpStatus.SC_OK)
+        .content(driver.getResourceBytes(resourceName))
+        .contentType(ContentType.XML.toString());
+
+    Response response = given()
+        .auth().preemptive().basic(username, password)
+        .header("X-XSRF-Header", "jksdhfkhdsf")
+        .header("Accept", ContentType.XML.toString())
+        .expect()
+        .statusCode(HttpStatus.SC_OK)
+        .contentType( ContentType.XML.toString() )
+        .when().get( gatewayPath );
+
+    assertTrue(response.getBody().asString().contains("The Merchant of Venice"));
+
+    driver.assertComplete();
+    LOG_EXIT();
+  }
 
   void setupResource(String serviceRole, String path){
     driver.getMock(serviceRole)
@@ -3750,7 +3787,7 @@ public class GatewayBasicFuncTest {
       System.out.println(e.getMessage());
     }
   }
-  
+
   private String createFileNN( String user, String password, String file, String permsOctal,
int status ) throws IOException {
     if( status == HttpStatus.SC_TEMPORARY_REDIRECT ) {
       driver.getMock( "WEBHDFS" )

http://git-wip-us.apache.org/repos/asf/knox/blob/d2f0fc0e/gateway-test/src/test/resources/org/apache/hadoop/gateway/GatewayBasicFuncTest/solr/query_response.xml
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/resources/org/apache/hadoop/gateway/GatewayBasicFuncTest/solr/query_response.xml
b/gateway-test/src/test/resources/org/apache/hadoop/gateway/GatewayBasicFuncTest/solr/query_response.xml
new file mode 100644
index 0000000..dd79042
--- /dev/null
+++ b/gateway-test/src/test/resources/org/apache/hadoop/gateway/GatewayBasicFuncTest/solr/query_response.xml
@@ -0,0 +1,20 @@
+<!--
+   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.
+-->
+<?xml version="1.0" encoding="UTF-8"?>
+<response>
+<lst name="responseHeader"><bool name="zkConnected">true</bool><int
name="status">0</int><int name="QTime">9</int><lst name="params"><str
name="q">author_s:William Shakespeare</str></lst></lst><result name="response"
numFound="2" start="0" maxScore="0.62191015"><doc><str name="id">book2</str><arr
name="title_t"><str>The Merchant of Venice</str></arr><str name="author_s">William
Shakespeare</str><long name="_version_">1571258160735322112</long></doc><doc><str
name="id">book1</str><arr name="title_t"><str>The Merchant of Venice</str></arr><str
name="author_s">William Shakespeare</str><long name="_version_">1571258154399825920</long></doc></result>
+</response>
\ No newline at end of file


Mime
View raw message