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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations