Search in sources :

Example 1 with MockServer

use of org.apache.knox.test.mock.MockServer in project knox by apache.

the class GatewayPortMappingFuncTest method setup.

/**
 * Creates a deployment of a gateway instance that all test methods will share.  This method also creates a
 * registry of sorts for all of the services that will be used by the test methods.
 * The createTopology method is used to create the topology file that would normally be read from disk.
 * The driver.setupGateway invocation is where the creation of GATEWAY_HOME occurs.
 * <p/>
 * This would normally be done once for this suite but the failure tests start affecting each other depending
 * on the state the last 'active' url
 *
 * @throws Exception Thrown if any failure occurs.
 */
@BeforeClass
public static void setup() throws Exception {
    LOG_ENTER();
    eeriePort = getAvailablePort(1240, 49151);
    ConcurrentHashMap<String, Integer> topologyPortMapping = new ConcurrentHashMap<String, Integer>();
    topologyPortMapping.put("eerie", eeriePort);
    masterServer = new MockServer("master", true);
    GatewayTestConfig config = new GatewayTestConfig();
    config.setGatewayPath("gateway");
    config.setTopologyPortMapping(topologyPortMapping);
    // Enable default topology
    config.setDefaultTopologyName("eerie");
    driver.setResourceBase(WebHdfsHaFuncTest.class);
    driver.setupLdap(0);
    driver.setupService("WEBHDFS", "http://vm.local:50070/webhdfs", "/eerie/webhdfs", USE_MOCK_SERVICES);
    driver.setupGateway(config, "eerie", createTopology("WEBHDFS", driver.getLdapUrl(), masterServer.getPort()), USE_GATEWAY);
    LOG_EXIT();
}
Also used : MockServer(org.apache.knox.test.mock.MockServer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BeforeClass(org.junit.BeforeClass)

Example 2 with MockServer

use of org.apache.knox.test.mock.MockServer in project knox by apache.

the class WebHdfsHaFuncTest method setup.

/**
 * Creates a deployment of a gateway instance that all test methods will share.  This method also creates a
 * registry of sorts for all of the services that will be used by the test methods.
 * The createTopology method is used to create the topology file that would normally be read from disk.
 * The driver.setupGateway invocation is where the creation of GATEWAY_HOME occurs.
 * <p/>
 * This would normally be done once for this suite but the failure tests start affecting each other depending
 * on the state the last 'active' url
 *
 * @throws Exception Thrown if any failure occurs.
 */
@Before
public void setup() throws Exception {
    LOG_ENTER();
    // Log.setLog(new NoOpLogger());
    masterServer = new MockServer("master", true);
    standbyServer = new MockServer("standby", true);
    GatewayTestConfig config = new GatewayTestConfig();
    config.setGatewayPath("gateway");
    driver.setResourceBase(WebHdfsHaFuncTest.class);
    driver.setupLdap(0);
    driver.setupService("WEBHDFS", "http://vm.local:50070/webhdfs", "/cluster/webhdfs", USE_MOCK_SERVICES);
    driver.setupGateway(config, "cluster", createTopology(), USE_GATEWAY);
    LOG_EXIT();
}
Also used : MockServer(org.apache.knox.test.mock.MockServer) Before(org.junit.Before)

Example 3 with MockServer

use of org.apache.knox.test.mock.MockServer in project knox by apache.

the class GatewayMultiFuncTest method testDefaultJsonMimeTypeHandlingKnox678.

@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testDefaultJsonMimeTypeHandlingKnox678() throws Exception {
    LOG_ENTER();
    MockServer mock = new MockServer("REPEAT", true);
    params = new Properties();
    params.put("LDAP_URL", driver.getLdapUrl());
    params.put("MOCK_SERVER_PORT", mock.getPort());
    String topoStr = TestUtils.merge(DAT, "topologies/test-knox678-utf8-chars-topology.xml", params);
    File topoFile = new File(config.getGatewayTopologyDir(), "knox678.xml");
    FileUtils.writeStringToFile(topoFile, topoStr);
    topos.reloadTopologies();
    String uname = "guest";
    String pword = uname + "-password";
    mock.expect().method("GET").respond().contentType("application/json").contentLength(-1).content("{\"msg\":\"H\u00eallo\"}", Charset.forName("UTF-8"));
    String json = given().auth().preemptive().basic(uname, pword).then().statusCode(HttpStatus.SC_OK).contentType("application/json; charset=UTF-8").when().get(gatewayUrl + "/knox678/repeat").andReturn().asString();
    assertThat(json, is("{\"msg\":\"H\u00eallo\"}"));
    assertThat(mock.isEmpty(), is(true));
    mock.expect().method("GET").respond().contentType("application/octet-stream").contentLength(-1).content("H\u00eallo".getBytes());
    byte[] bytes = given().auth().preemptive().basic(uname, pword).then().statusCode(HttpStatus.SC_OK).contentType("application/octet-stream").when().get(gatewayUrl + "/knox678/repeat").andReturn().asByteArray();
    assertThat(bytes, is(equalTo("H\u00eallo".getBytes())));
    assertThat(mock.isEmpty(), is(true));
    mock.stop();
    LOG_EXIT();
}
Also used : MockServer(org.apache.knox.test.mock.MockServer) Properties(java.util.Properties) File(java.io.File) ReleaseTest(org.apache.knox.test.category.ReleaseTest) Test(org.junit.Test)

Example 4 with MockServer

use of org.apache.knox.test.mock.MockServer in project knox by apache.

the class GatewayMultiFuncTest method testPostWithContentTypeKnox681.

@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testPostWithContentTypeKnox681() throws Exception {
    LOG_ENTER();
    MockServer mock = new MockServer("REPEAT", true);
    params = new Properties();
    params.put("MOCK_SERVER_PORT", mock.getPort());
    params.put("LDAP_URL", driver.getLdapUrl());
    String topoStr = TestUtils.merge(DAT, "topologies/test-knox678-utf8-chars-topology.xml", params);
    File topoFile = new File(config.getGatewayTopologyDir(), "knox681.xml");
    FileUtils.writeStringToFile(topoFile, topoStr);
    topos.reloadTopologies();
    mock.expect().method("PUT").pathInfo("/repeat-context/").respond().status(HttpStatus.SC_CREATED).content("{\"name\":\"value\"}".getBytes()).contentLength(-1).contentType("application/json; charset=UTF-8").header("Location", gatewayUrl + "/knox681/repeat");
    String uname = "guest";
    String pword = uname + "-password";
    HttpHost targetHost = new HttpHost("localhost", gatewayPort, "http");
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(uname, pword));
    AuthCache authCache = new BasicAuthCache();
    BasicScheme basicAuth = new BasicScheme();
    authCache.put(targetHost, basicAuth);
    HttpClientContext context = HttpClientContext.create();
    context.setCredentialsProvider(credsProvider);
    context.setAuthCache(authCache);
    CloseableHttpClient client = HttpClients.createDefault();
    HttpPut request = new HttpPut(gatewayUrl + "/knox681/repeat");
    request.addHeader("X-XSRF-Header", "jksdhfkhdsf");
    request.addHeader("Content-Type", "application/json");
    CloseableHttpResponse response = client.execute(request, context);
    assertThat(response.getStatusLine().getStatusCode(), is(HttpStatus.SC_CREATED));
    assertThat(response.getFirstHeader("Location").getValue(), endsWith("/gateway/knox681/repeat"));
    assertThat(response.getFirstHeader("Content-Type").getValue(), is("application/json; charset=UTF-8"));
    String body = new String(IOUtils.toByteArray(response.getEntity().getContent()), Charset.forName("UTF-8"));
    assertThat(body, is("{\"name\":\"value\"}"));
    response.close();
    client.close();
    mock.expect().method("PUT").pathInfo("/repeat-context/").respond().status(HttpStatus.SC_CREATED).content("<test-xml/>".getBytes()).contentType("application/xml; charset=UTF-8").header("Location", gatewayUrl + "/knox681/repeat");
    client = HttpClients.createDefault();
    request = new HttpPut(gatewayUrl + "/knox681/repeat");
    request.addHeader("X-XSRF-Header", "jksdhfkhdsf");
    request.addHeader("Content-Type", "application/xml");
    response = client.execute(request, context);
    assertThat(response.getStatusLine().getStatusCode(), is(HttpStatus.SC_CREATED));
    assertThat(response.getFirstHeader("Location").getValue(), endsWith("/gateway/knox681/repeat"));
    assertThat(response.getFirstHeader("Content-Type").getValue(), is("application/xml; charset=UTF-8"));
    body = new String(IOUtils.toByteArray(response.getEntity().getContent()), Charset.forName("UTF-8"));
    assertThat(the(body), hasXPath("/test-xml"));
    response.close();
    client.close();
    mock.stop();
    LOG_EXIT();
}
Also used : BasicScheme(org.apache.http.impl.auth.BasicScheme) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) AuthCache(org.apache.http.client.AuthCache) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) Properties(java.util.Properties) HttpPut(org.apache.http.client.methods.HttpPut) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) MockServer(org.apache.knox.test.mock.MockServer) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) File(java.io.File) ReleaseTest(org.apache.knox.test.category.ReleaseTest) Test(org.junit.Test)

Example 5 with MockServer

use of org.apache.knox.test.mock.MockServer in project knox by apache.

the class GatewayPortMappingDisableFeatureTest method setup.

/**
 * Creates a deployment of a gateway instance that all test methods will share.  This method also creates a
 * registry of sorts for all of the services that will be used by the test methods.
 * The createTopology method is used to create the topology file that would normally be read from disk.
 * The driver.setupGateway invocation is where the creation of GATEWAY_HOME occurs.
 * <p/>
 * This would normally be done once for this suite but the failure tests start affecting each other depending
 * on the state the last 'active' url
 *
 * @throws Exception Thrown if any failure occurs.
 */
@Before
public void setup() throws Exception {
    LOG_ENTER();
    eeriePort = getAvailablePort(1240, 49151);
    ConcurrentHashMap<String, Integer> topologyPortMapping = new ConcurrentHashMap<String, Integer>();
    topologyPortMapping.put("eerie", eeriePort);
    masterServer = new MockServer("master", true);
    GatewayTestConfig config = new GatewayTestConfig();
    config.setGatewayPath("gateway");
    config.setTopologyPortMapping(topologyPortMapping);
    // disable the feature
    config.setGatewayPortMappingEnabled(false);
    driver.setResourceBase(WebHdfsHaFuncTest.class);
    driver.setupLdap(0);
    driver.setupService("WEBHDFS", "http://vm.local:50070/webhdfs", "/eerie/webhdfs", USE_MOCK_SERVICES);
    driver.setupGateway(config, "eerie", createTopology("WEBHDFS"), USE_GATEWAY);
    LOG_EXIT();
}
Also used : MockServer(org.apache.knox.test.mock.MockServer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Before(org.junit.Before)

Aggregations

MockServer (org.apache.knox.test.mock.MockServer)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 File (java.io.File)2 Properties (java.util.Properties)2 ReleaseTest (org.apache.knox.test.category.ReleaseTest)2 Before (org.junit.Before)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 HttpHost (org.apache.http.HttpHost)1 AuthScope (org.apache.http.auth.AuthScope)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 AuthCache (org.apache.http.client.AuthCache)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPut (org.apache.http.client.methods.HttpPut)1 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)1 BasicScheme (org.apache.http.impl.auth.BasicScheme)1 BasicAuthCache (org.apache.http.impl.client.BasicAuthCache)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1