Java Code Examples for io.restassured.response.Response#getHeader()

The following examples show how to use io.restassured.response.Response#getHeader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractBasicLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenResourceWasRetrieved_whenRetrievingAgainWithEtag_thenNotModifiedReturned() {
    // Given
    final String uriOfResource = createAsUri();
    final Response findOneResponse = RestAssured.given()
        .header("Accept", "application/json")
        .get(uriOfResource);
    final String etagValue = findOneResponse.getHeader(HttpHeaders.ETAG);

    // When
    final Response secondFindOneResponse = RestAssured.given()
        .header("Accept", "application/json")
        .headers("If-None-Match", etagValue)
        .get(uriOfResource);

    // Then
    assertTrue(secondFindOneResponse.getStatusCode() == 304);
}
 
Example 2
Source File: AbstractBasicLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenResourceWasRetrievedThenModified_whenRetrievingAgainWithEtag_thenResourceIsReturned() {
    // Given
    final String uriOfResource = createAsUri();
    final Response firstFindOneResponse = RestAssured.given()
        .header("Accept", "application/json")
        .get(uriOfResource);
    final String etagValue = firstFindOneResponse.getHeader(HttpHeaders.ETAG);
    final long createdId = firstFindOneResponse.jsonPath().getLong("id");

    Foo updatedFoo = new Foo("updated value");
    updatedFoo.setId(createdId);
    Response updatedResponse = RestAssured.given().contentType(ContentType.JSON).body(updatedFoo)
        .put(uriOfResource);
    assertThat(updatedResponse.getStatusCode() == 200);

    // When
    final Response secondFindOneResponse = RestAssured.given()
        .header("Accept", "application/json")
        .headers("If-None-Match", etagValue)
        .get(uriOfResource);

    // Then
    assertTrue(secondFindOneResponse.getStatusCode() == 200);
}
 
Example 3
Source File: ImplicitFlowLiveTest.java    From spring-security-oauth with MIT License 6 votes vote down vote up
private String obtainAccessToken(String clientId, String username, String password) {
    final String redirectUrl = "http://www.example.com";
    final String authorizeUrl = AUTH_SERVER + "/oauth/authorize";

    // user login
    Response response = RestAssured.given().formParams("username", username, "password", password).post(AUTH_SERVER + "/login");
    final String cookieValue = response.getCookie("JSESSIONID");

    // get access token
    final Map<String, String> params = new HashMap<String, String>();
    params.put("response_type", "token");
    params.put("client_id", clientId);
    params.put("redirect_uri", redirectUrl);
    response = RestAssured.given().cookie("JSESSIONID", cookieValue).formParams(params).post(authorizeUrl);

    final String location = response.getHeader(HttpHeaders.LOCATION);
    System.out.println("Location => " + location);

    assertEquals(HttpStatus.FOUND.value(), response.getStatusCode());
    final String accessToken = location.split("#|=|&")[2];
    return accessToken;
}
 
Example 4
Source File: AbstractDiscoverabilityLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void whenResourceIsCreated_thenUriOfTheNewlyCreatedResourceIsDiscoverable() {
    // When
    final Foo newResource = new Foo(randomAlphabetic(6));
    final Response createResp = RestAssured.given()
        .contentType(MediaType.APPLICATION_JSON_VALUE)
        .body(newResource)
        .post(getURL());
    final String uriOfNewResource = createResp.getHeader(HttpHeaders.LOCATION);

    // Then
    final Response response = RestAssured.given()
        .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
        .get(uriOfNewResource);

    final Foo resourceFromServer = response.body().as(Foo.class);
    assertThat(newResource, equalTo(resourceFromServer));
}
 
Example 5
Source File: EtagIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenResourceWasRetrievedThenModified_whenRetrievingAgainWithEtag_thenResourceIsReturned() {
	// Given
	final String uriOfResource = createAsUri();
	final Response firstFindOneResponse = RestAssured.given().header("Accept", "application/json")
			.get(uriOfResource);
	final String etagValue = firstFindOneResponse.getHeader(HttpHeaders.ETAG);
	final long createdId = firstFindOneResponse.jsonPath().getLong("id");

	Foo updatedFoo = new Foo("updated value");
	updatedFoo.setId(createdId);
	Response updatedResponse = RestAssured.given().contentType(ContentType.JSON).body(updatedFoo)
			.put(uriOfResource);
	assertThat(updatedResponse.getStatusCode() == 200);

	// When
	final Response secondFindOneResponse = RestAssured.given().header("Accept", "application/json")
			.headers("If-None-Match", etagValue).get(uriOfResource);

	// Then
	assertTrue(secondFindOneResponse.getStatusCode() == 200);
}
 
Example 6
Source File: ServiceHaMode.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
private void routeAndVerifyRetry(List<String> gatewayUrls, int timeoutSec) {
    final long time0 = System.currentTimeMillis();

    for (String gatewayUrl : gatewayUrls) {
        while (true) {
            String url = gatewayUrl + "/application/instance";

            try {
                Response response = given().when()
                    .get(url)
                    .andReturn();
                if (response.getStatusCode() != HttpStatus.SC_OK) {
                    fail();
                }
                StringTokenizer retryList = new StringTokenizer(response.getHeader("RibbonRetryDebug"), "|");
                assertThat(retryList.countTokens(), is(greaterThan(1)));
                break;
            }
            catch (RuntimeException | AssertionError e) {
                if (System.currentTimeMillis() - time0 > timeoutSec * 1000) throw e;
                await().timeout(1, TimeUnit.SECONDS);
            }
        }
    }
}
 
Example 7
Source File: AuthorizationServerLiveTest.java    From spring-security-oauth with MIT License 5 votes vote down vote up
private String obtainAccessToken() {
	final String redirectUrl = "http://localhost:8082/jwt-client/login/oauth2/code/custom";
	final String authorizeUrl = "http://localhost:8083/auth/realms/baeldung/protocol/openid-connect/auth?response_type=code&client_id=jwtClient&scope=read&redirect_uri="
			+ redirectUrl;
	final String tokenUrl = "http://localhost:8083/auth/realms/baeldung/protocol/openid-connect/token";
	// obtain authentication url with custom codes
	Response response = RestAssured.given().redirects().follow(false).get(authorizeUrl);
	String authSessionId = response.getCookie("AUTH_SESSION_ID");
	String kcPostAuthenticationUrl = response.asString().split("action=\"")[1].split("\"")[0].replace("&amp;", "&");

	// obtain authentication code and state
	response = RestAssured.given().redirects().follow(false).cookie("AUTH_SESSION_ID", authSessionId)
			.formParams("username", "[email protected]", "password", "123", "credentialId", "")
			.post(kcPostAuthenticationUrl);
	assertThat(HttpStatus.FOUND.value()).isEqualTo(response.getStatusCode());

	// extract authorization code
	String location = response.getHeader(HttpHeaders.LOCATION);
	String code = location.split("code=")[1].split("&")[0];

	// get access token
	Map<String, String> params = new HashMap<String, String>();
	params.put("grant_type", "authorization_code");
	params.put("code", code);
	params.put("client_id", "jwtClient");
	params.put("redirect_uri", redirectUrl);
	params.put("client_secret", "jwtClientSecret");
	response = RestAssured.given().formParams(params).post(tokenUrl);
	return response.jsonPath().getString("access_token");
}
 
Example 8
Source File: GatewayBasicFuncTest.java    From knox with Apache License 2.0 5 votes vote down vote up
private String createFileNN( String user, String password, String file, String permsOctal, int status ) throws IOException {
  if( status == HttpStatus.SC_TEMPORARY_REDIRECT ) {
    driver.getMock( "WEBHDFS" )
        .expect()
        .method( "PUT" )
        .pathInfo( "/v1" + file )
        .queryParam( "user.name", user )
        .queryParam( "op", "CREATE" )
        .respond()
        .status( status )
        .header( "Location", driver.getRealUrl("DATANODE") + file + "?op=CREATE&user.name="+user );
  } else {
    driver.getMock( "WEBHDFS" )
        .expect()
        .method( "PUT" )
        .pathInfo( "/v1" + file )
        .queryParam( "user.name", user )
        .queryParam( "op", "CREATE" )
        .respond()
        .status( status );
  }
  Response response = given()
      //.log().headers()
      //.log().parameters()
      .auth().preemptive().basic( user, password )
      .header( "X-XSRF-Header", "jksdhfkhdsf" )
      .queryParam( "op", "CREATE" )
      .queryParam( "permission", permsOctal )
      .then()
      //.log().all()
      .statusCode( status )
      .when().put( driver.getUrl( "WEBHDFS" ) + "/v1" + file + ( driver.isUseGateway() ? "" : "?user.name=" + user ) );
  String location = response.getHeader( "Location" );
  log.trace( "Redirect location: " + response.getHeader( "Location" ) );
  return location;
}
 
Example 9
Source File: GatewayBasicFuncTest.java    From knox with Apache License 2.0 5 votes vote down vote up
@Test( timeout = TestUtils.MEDIUM_TIMEOUT )
  public void testBasicOutboundEncodedHeaderUseCase() throws IOException {
    LOG_ENTER();
    String root = "/tmp/GatewayBasicFuncTest/testBasicOutboundHeaderUseCase";
    String username = "hdfs";
    String password = "hdfs-password";

    driver.getMock( "WEBHDFS" )
        .expect()
        .method( "PUT" )
        .pathInfo( "/v1" + root + "/dir/fileレポー" )
        .header( "Host", driver.getRealAddr( "WEBHDFS" ) )
        .queryParam( "op", "CREATE" )
        .queryParam( "user.name", username )
        .respond()
        .status( HttpStatus.SC_TEMPORARY_REDIRECT )
        .header("Location", driver.getRealUrl("DATANODE") + "/v1" + root + "/dir/file%E3%83%AC%E3%83%9D%E3%83%BC?op=CREATE&user.name=hdfs");
    Response response = given()
        //.log().all()
        .auth().preemptive().basic( username, password )
        .header("X-XSRF-Header", "jksdhfkhdsf")
        .queryParam( "op", "CREATE" )
        .then()
        //.log().ifError()
        .statusCode( HttpStatus.SC_TEMPORARY_REDIRECT )
        .when().put( driver.getUrl("WEBHDFS") + "/v1" + root + "/dir/fileレポー" );
//        .when().put( driver.getUrl("WEBHDFS") + "/v1" + root + "/dir/file%E3%83%AC%E3%83%9D%E3%83%BC" );
    String location = response.getHeader( "Location" );
    log.debug( "Redirect location: " + response.getHeader( "Location" ) );
    if( driver.isUseGateway() ) {
      assertThat( location, containsString("/dir/file%E3%83%AC%E3%83%9D%E3%83%BC") );
    }
    LOG_EXIT();
  }
 
Example 10
Source File: EtagIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenResourceWasRetrieved_whenRetrievingAgainWithEtag_thenNotModifiedReturned() {
	// Given
	final String uriOfResource = createAsUri();
	final Response findOneResponse = RestAssured.given().header("Accept", "application/json").get(uriOfResource);
	final String etagValue = findOneResponse.getHeader(HttpHeaders.ETAG);

	// When
	final Response secondFindOneResponse = RestAssured.given().header("Accept", "application/json")
			.headers("If-None-Match", etagValue).get(uriOfResource);

	// Then
	assertTrue(secondFindOneResponse.getStatusCode() == 304);
}
 
Example 11
Source File: AbstractDiscoverabilityLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenInvalidPOSTIsSentToValidURIOfResource_thenAllowHeaderListsTheAllowedActions() {
    // Given
    final String uriOfExistingResource = createAsUri();

    // When
    final Response res = RestAssured.post(uriOfExistingResource);

    // Then
    final String allowHeader = res.getHeader(HttpHeaders.ALLOW);
    assertThat(allowHeader, AnyOf.anyOf(containsString("GET"), containsString("PUT"), containsString("DELETE")));
}
 
Example 12
Source File: ImplicitFlowLiveTest.java    From spring-security-oauth with MIT License 5 votes vote down vote up
private String obtainAccessToken(String clientId, String username, String password) {
	String authorizeUrl = AUTH_SERVER + "/auth";

	Map<String, String> loginParams = new HashMap<String, String>();
	loginParams.put("grant_type", "implicit");
	loginParams.put("client_id", clientId);
	loginParams.put("response_type", "token");
	loginParams.put("redirect_uri", REDIRECT_URL);
	loginParams.put("scope", "read write");

	// user login
	Response response = RestAssured.given().formParams(loginParams).get(authorizeUrl);
	String cookieValue = response.getCookie("AUTH_SESSION_ID");

	String authUrlWithCode = response.htmlPath().getString("'**'.find{node -> node.name()=='form'}*.@action");
	
	// get access token
	Map<String, String> tokenParams = new HashMap<String, String>();
	tokenParams.put("username", username);
	tokenParams.put("password", password);
	tokenParams.put("client_id", clientId);
	tokenParams.put("redirect_uri", REDIRECT_URL);
	response = RestAssured.given().cookie("AUTH_SESSION_ID", cookieValue).formParams(tokenParams)
			.post(authUrlWithCode);

	final String location = response.getHeader(HttpHeaders.LOCATION);

	assertEquals(HttpStatus.FOUND.value(), response.getStatusCode());
	final String accessToken = location.split("#|=|&")[4];
	return accessToken;

}
 
Example 13
Source File: AppControllerIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenCallingWelcomeEndpoint_thenCorrect() {

    get(uri + "/welcome").then()
        .assertThat()
        .header("sessionId", notNullValue())
        .cookie("token", notNullValue());

    Response response = get(uri + "/welcome");

    String headerName = response.getHeader("sessionId");
    String cookieValue = response.getCookie("token");
    assertThat(headerName).isNotBlank();
    assertThat(cookieValue).isNotBlank();
}
 
Example 14
Source File: AbstractLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
protected final String createAsUri(final T resource) {
    final Response response = createAsResponse(resource);
    Preconditions.checkState(response.getStatusCode() == 201, "create operation: " + response.getStatusCode());

    final String locationOfCreatedResource = response.getHeader(HttpHeaders.LOCATION);
    Preconditions.checkNotNull(locationOfCreatedResource);
    return locationOfCreatedResource;
}
 
Example 15
Source File: AuthorizationCodeLiveTest.java    From spring-security-oauth with MIT License 4 votes vote down vote up
private String obtainAccessTokenWithAuthorizationCode(String username, String password) {
  	

String authorizeUrl = AUTH_SERVER + "/auth";
String tokenUrl = AUTH_SERVER + "/token";

Map<String, String> loginParams = new HashMap<String, String>();
loginParams.put("client_id", CLIENT_ID);
loginParams.put("response_type", "code");
loginParams.put("redirect_uri", REDIRECT_URL);
loginParams.put("scope", "read write");

// user login
Response response = RestAssured.given().formParams(loginParams).get(authorizeUrl);
String cookieValue = response.getCookie("AUTH_SESSION_ID");
	
String authUrlWithCode = response.htmlPath().getString("'**'.find{node -> node.name()=='form'}*.@action");

// get code
Map<String, String> codeParams = new HashMap<String, String>();
codeParams.put("username", username);
codeParams.put("password", password);
response = RestAssured.given().cookie("AUTH_SESSION_ID", cookieValue).formParams(codeParams)
		.post(authUrlWithCode);

final String location = response.getHeader(HttpHeaders.LOCATION);

assertEquals(HttpStatus.FOUND.value(), response.getStatusCode());
final String code = location.split("#|=|&")[3];

//get access token
Map<String, String> tokenParams = new HashMap<String, String>();
tokenParams.put("grant_type", "authorization_code");
tokenParams.put("client_id", CLIENT_ID);
tokenParams.put("client_secret", CLIENT_SECRET);
tokenParams.put("redirect_uri", REDIRECT_URL);
tokenParams.put("code", code);

response = RestAssured.given().formParams(tokenParams)
		.post(tokenUrl);

return response.jsonPath().getString("access_token");	
  }
 
Example 16
Source File: ModuleTenantsTest.java    From okapi with Apache License 2.0 4 votes vote down vote up
@Test
public void testDepCheck() {
  RestAssured.port = port;
  RestAssuredClient c;
  Response r;

  // create basic 1.0.0
  final String docBasic_1_0_0 = "{" + LS
    + "  \"id\" : \"basic-module-1.0.0-alpha\"," + LS
    + "  \"name\" : \"this module\"," + LS
    + "  \"provides\" : [ {" + LS
    + "    \"id\" : \"_tenant\"," + LS
    + "    \"version\" : \"1.1\"," + LS
    + "    \"interfaceType\" : \"system\"," + LS
    + "    \"handlers\" : [ {" + LS
    + "      \"methods\" : [ \"POST\", \"DELETE\" ]," + LS
    + "      \"pathPattern\" : \"/_/tenant\"," + LS
    + "      \"permissionsRequired\" : [ ]" + LS
    + "    }, {" + LS
    + "      \"methods\" : [ \"POST\" ]," + LS
    + "      \"pathPattern\" : \"/_/tenant/disable\"," + LS
    + "      \"permissionsRequired\" : [ ]" + LS
    + "    } ]" + LS
    + "  }, {" + LS
    + "    \"id\" : \"bint\"," + LS
    + "    \"version\" : \"1.0\"," + LS
    + "    \"handlers\" : [ {" + LS
    + "      \"methods\" : [ \"GET\", \"POST\" ]," + LS
    + "      \"pathPattern\" : \"/foo\"," + LS
    + "      \"permissionsRequired\" : [ ]" + LS
    + "    } ]" + LS
    + "  } ]," + LS
    + "  \"requires\" : [ { " + LS
    + "    \"id\" : \"unknown1\", \"version\" : \"1.0\""
    + "  }, {"
    + "    \"id\" : \"unknown2\", \"version\" : \"2.0\""
    + "  } ]," + LS
    + "  \"launchDescriptor\" : {" + LS
    + "    \"exec\" : "
    + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS
    + "  }" + LS
    + "}";
  c = api.createRestAssured3();
  r = c.given()
    .header("Content-Type", "application/json")
    .body(docBasic_1_0_0)
    .post("/_/proxy/modules?check=true")
    .then().statusCode(400).log().ifValidationFails().extract().response();
  Assert.assertTrue(
    "raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());
  Assert.assertEquals("Missing dependency: basic-module-1.0.0-alpha requires unknown1: 1.0" + ". "
    + "Missing dependency: basic-module-1.0.0-alpha requires unknown2: 2.0", r.getBody().asString());
  c = api.createRestAssured3();
  r = c.given()
    .header("Content-Type", "application/json")
    .body(docBasic_1_0_0)
    .post("/_/proxy/modules?check=false")
    .then().statusCode(201).log().ifValidationFails().extract().response();
  Assert.assertTrue(
    "raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());
  final String location = r.getHeader("Location");

  c = api.createRestAssured3();
  c.given()
    .delete(location)
    .then().statusCode(204).log().ifValidationFails();
  Assert.assertTrue(
    "raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());
}
 
Example 17
Source File: ResponseUtils.java    From pnc with Apache License 2.0 4 votes vote down vote up
public static Integer getIdFromLocationHeader(Response response) {
    String location = response.getHeader("Location");
    return Integer.valueOf(location.substring(location.lastIndexOf("/") + 1));
}
 
Example 18
Source File: GatewayBasicFuncTest.java    From knox with Apache License 2.0 4 votes vote down vote up
@Test( timeout = TestUtils.MEDIUM_TIMEOUT )
public void testBasicOutboundHeaderUseCase() throws IOException {
  LOG_ENTER();
  String root = "/tmp/GatewayBasicFuncTest/testBasicOutboundHeaderUseCase";
  String username = "hdfs";
  String password = "hdfs-password";
  InetSocketAddress gatewayAddress = driver.gateway.getAddresses()[0];
  String gatewayHostName = gatewayAddress.getHostName();
  String gatewayAddrName = InetAddress.getByName(gatewayHostName).getHostAddress();

  driver.getMock( "WEBHDFS" )
      .expect()
      .method( "PUT" )
      .pathInfo( "/v1" + root + "/dir/file" )
      .header( "Host", driver.getRealAddr( "WEBHDFS" ) )
      .queryParam( "op", "CREATE" )
      .queryParam( "user.name", username )
      .respond()
      .status( HttpStatus.SC_TEMPORARY_REDIRECT )
      .header("Location", driver.getRealUrl("DATANODE") + "/v1" + root + "/dir/file?op=CREATE&user.name=hdfs");
  Response response = given()
      //.log().all()
      .auth().preemptive().basic( username, password )
      .header("X-XSRF-Header", "jksdhfkhdsf")
      .queryParam( "op", "CREATE" )
      .then()
      //.log().ifError()
      .statusCode( HttpStatus.SC_TEMPORARY_REDIRECT )
      .when().put( driver.getUrl("WEBHDFS") + "/v1" + root + "/dir/file" );
  String location = response.getHeader( "Location" );
  log.debug( "Redirect location: " + response.getHeader( "Location" ) );
  if( driver.isUseGateway() ) {
    assertThat( location, anyOf(
        startsWith( "http://" + gatewayHostName + ":" + gatewayAddress.getPort() + "/" ),
        startsWith( "http://" + gatewayAddrName + ":" + gatewayAddress.getPort() + "/" ) ) );
    assertThat( location, containsString( "?_=" ) );
  }
  assertThat(location, not(containsString("host=")));
  assertThat(location, not(containsString("port=")));
  LOG_EXIT();
}
 
Example 19
Source File: ModuleTest.java    From okapi with Apache License 2.0 4 votes vote down vote up
@Test
public void testUiModule(TestContext context) {
  async = context.async();
  Response r;

  final String docUiModuleInput = "{" + LS
    + "  \"id\" : \"ui-1\"," + LS
    + "  \"name\" : \"sample-ui\"," + LS
    + "  \"uiDescriptor\" : {" + LS
    + "    \"npm\" : \"name-of-module-in-npm\"" + LS
    + "  }" + LS
    + "}";

  final String docUiModuleOutput = "{" + LS
    + "  \"id\" : \"ui-1\"," + LS
    + "  \"name\" : \"sample-ui\"," + LS
    + "  \"uiDescriptor\" : {" + LS
    + "    \"npm\" : \"name-of-module-in-npm\"" + LS
    + "  }" + LS
    + "}";

  RestAssuredClient c;

  c = api.createRestAssured3();
  r = c.given()
    .header("Content-Type", "application/json")
    .body(docUiModuleInput).post("/_/proxy/modules").then().statusCode(201)
    .body(equalTo(docUiModuleOutput)).extract().response();
  Assert.assertTrue("raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());

  String location = r.getHeader("Location");

  c = api.createRestAssured3();
  c.given()
    .get(location)
    .then().statusCode(200).body(equalTo(docUiModuleOutput));
  Assert.assertTrue("raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());

  given().delete(location)
    .then().statusCode(204);
  checkDbIsEmpty("testUiModule done", context);

  async.complete();
}
 
Example 20
Source File: ModuleTest.java    From okapi with Apache License 2.0 4 votes vote down vote up
@Test
public void testNotFound(TestContext context) {
  async = context.async();
  Response r;
  ValidatableResponse then;

  final String docTenantRoskilde = "{" + LS
    + "  \"id\" : \"" + okapiTenant + "\"," + LS
    + "  \"name\" : \"" + okapiTenant + "\"," + LS
    + "  \"description\" : \"Roskilde bibliotek\"" + LS
    + "}";
  r = given()
    .header("Content-Type", "application/json")
    .body(docTenantRoskilde).post("/_/proxy/tenants")
    .then().statusCode(201)
    .body(equalTo(docTenantRoskilde))
    .extract().response();
  final String locationTenantRoskilde = r.getHeader("Location");

  for (String type : Arrays.asList("request-response", "request-only", "headers")) {
    final String docSampleModule = "{" + LS
      + "  \"id\" : \"sample-module-1\"," + LS
      + "  \"filters\" : [ {" + LS
      + "    \"methods\" : [ \"GET\", \"POST\" ]," + LS
      + "    \"path\" : \"/test2\"," + LS
      + "    \"level\" : \"20\"," + LS
      + "    \"type\" : \"" + type + "\"," + LS
      + "    \"permissionsRequired\" : [ ]" + LS
      + "  } ]" + LS
      + "}";
    r = given()
      .header("Content-Type", "application/json")
      .body(docSampleModule).post("/_/proxy/modules").then().statusCode(201)
      .extract().response();
    final String locationSampleModule = r.getHeader("Location");

    final String docLaunch1 = "{" + LS
      + "  \"srvcId\" : \"sample-module-1\"," + LS
      + "  \"nodeId\" : \"localhost\"," + LS
      + "  \"descriptor\" : {" + LS
      + "    \"exec\" : "
      + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS
      + "  }" + LS
      + "}";

    r = given().header("Content-Type", "application/json")
      .body(docLaunch1).post("/_/discovery/modules")
      .then().statusCode(201)
      .extract().response();
    locationSampleDeployment = r.getHeader("Location");

    final String docEnableSample = "{" + LS
      + "  \"id\" : \"sample-module-1\"" + LS
      + "}";
    r = given()
      .header("Content-Type", "application/json")
      .body(docEnableSample).post("/_/proxy/tenants/" + okapiTenant + "/modules")
      .then().statusCode(201)
      .body(equalTo(docEnableSample)).extract().response();
    final String enableLoc = r.getHeader("Location");

    given().header("X-Okapi-Tenant", okapiTenant)
      .body("bar").post("/test2")
      .then().statusCode(404);

    given().delete(enableLoc).then().statusCode(204);
    given().delete(locationSampleModule).then().statusCode(204);
    given().delete(locationSampleDeployment).then().statusCode(204);
    locationSampleDeployment = null;
  }
  given().delete(locationTenantRoskilde)
    .then().statusCode(204);

  async.complete();
}