Java Code Examples for com.jayway.restassured.RestAssured#baseURI()

The following examples show how to use com.jayway.restassured.RestAssured#baseURI() . 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: ClusteredBounceProxyControllerTest.java    From joynr with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore("Ignore until servers are started in a separate JVM. Guice static problem")
public void testBounceProxyRegistrationAtBpc2() throws InterruptedException {

    RestAssured.baseURI = bpcUrl2;
    Response responseRegister = given().log()
                                       .all()
                                       .queryParam("url4cc", "http://testurl/url4cc")
                                       .and()
                                       .queryParam("url4bpc", "http://testurl/url4bpc")
                                       .when()
                                       .put("bounceproxies/?bpid=1.0");

    assertEquals(201 /* Created */, responseRegister.getStatusCode());

    waitForReplication();

    RestAssured.baseURI = bpcUrl1;
    JsonPath listBps = given().log().all().get("bounceproxies").body().jsonPath();

    assertThat(listBps, containsBounceProxy("1.0", "ALIVE"));
}
 
Example 2
Source File: MessagingLoadDistributionTest.java    From joynr with Apache License 2.0 6 votes vote down vote up
private void postMessageToBounceProxy(BounceProxyCommunicationMock bpMock,
                                      String channelUrl,
                                      String channelId,
                                      long relativeTtlMs,
                                      byte[] payload) throws Exception {

    String previousBaseUri = RestAssured.baseURI;
    RestAssured.baseURI = Utilities.getUrlWithoutSessionId(channelUrl, "jsessionid");
    String sessionId = Utilities.getSessionId(channelUrl, "jsessionid");

    byte[] serializedMessage = bpMock.createImmutableMessage(relativeTtlMs, payload).getSerializedMessage();
    /* @formatter:off */
    bpMock.onrequest().with().body(serializedMessage).expect().statusCode(201).when().post("message;jsessionid="
            + sessionId);
    /* @formatter:on */
    RestAssured.baseURI = previousBaseUri;
}
 
Example 3
Source File: E2EBase.java    From pivotal-bank-demo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {

    RestAssured.baseURI = this.applicationUrl;
    RestAssured.useRelaxedHTTPSValidation();
    RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter(), new ErrorLoggingFilter());

}
 
Example 4
Source File: RealEnvironmentAT.java    From nakadi with MIT License 5 votes vote down vote up
public RealEnvironmentAT() {
    oauthToken = ofNullable(System.getenv("NAKADI_OAUTH_TOKEN"));
    owningApp = ofNullable(System.getenv("NAKADI_OWNING_APP")).orElse("dummy-app");

    RestAssured.baseURI = ofNullable(System.getenv("NAKADI_BASE_URL"))
            .orElse(RestAssured.DEFAULT_URI);

    RestAssured.port = Integer.parseInt(ofNullable(System.getenv("NAKADI_PORT"))
            .orElse(Integer.toString(RestAssured.DEFAULT_PORT)));
}
 
Example 5
Source File: CostCenterEmployeesServiceTest.java    From cloud-s4-sdk-examples with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    RestAssured.config().httpClient(HttpClientConfig.httpClientConfig().setParam("CONNECTION_MANAGER_TIMEOUT", 3600*1000));
    RestAssured.baseURI = baseUrl.toExternalForm();

    mockUtil.mockErpDestination(mockUtil.getErpSystem());
    mockUtil.mockDestination("SuccessFactorsODataEndpoint", "sfsf");
}
 
Example 6
Source File: VersionIT.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testVersion() {
    String versionExpected = System.getProperty("jolokia.version");
    String jolokiaUrl = System.getProperty("jolokia.url");

    RestAssured.baseURI = jolokiaUrl;
    RestAssured.defaultParser = Parser.JSON;
    System.out.println("Checking URL: " + jolokiaUrl);

    // Need to do it that way since Jolokia doesnt return application/json as mimetype by default
    JsonPath json = with(get("/version").asString());
    json.prettyPrint();
    assertEquals(versionExpected, json.get("value.agent"));

    // Alternatively, set the mime type before, then Rest-assured's fluent API can be used
    given()
            .param("mimeType", "application/json")
            .get("/version")
    .then().assertThat()
            .header("content-type", containsString("application/json"))
            .body("value.agent", equalTo(versionExpected))
            .body("timestamp", lessThanOrEqualTo((int) (System.currentTimeMillis() / 1000)))
            .body("status", equalTo(200))
            .body("value.protocol", equalTo("7.2"))
            .body("value.config",notNullValue());

}
 
Example 7
Source File: RestAssuredTest.java    From raml-tester with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithRestAssured() {
    RestAssured.baseURI = "http://test.server/path";
    RamlDefinition api = RamlLoaders.fromClasspath(getClass()).load("api.yaml");
    Assert.assertThat(api.validate(), validates());

    RestAssuredClient restAssured = api.createRestAssured();
    restAssured.given().get("/base/data").andReturn();
    Assert.assertTrue(restAssured.getLastReport().isEmpty());
}
 
Example 8
Source File: ServersUtil.java    From joynr with Apache License 2.0 5 votes vote down vote up
private static Response getBounceProxies(String bpControllerUrl) {

        String previousBaseUri = RestAssured.baseURI;
        RestAssured.baseURI = bpControllerUrl;
        Response bounceProxiesResponse = RestAssured.given().get("bounceproxies");
        RestAssured.baseURI = previousBaseUri;
        return bounceProxiesResponse;
    }
 
Example 9
Source File: RestAssuredTest.java    From raml-tester with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    RestAssured.baseURI = baseUrlWithPort();
    api = RamlLoaders.fromClasspath(RestAssuredTest.class).load("restAssured.raml")
            .assumingBaseUri("http://nidi.guru/raml/v1");
    restAssured = api.createRestAssured();
}
 
Example 10
Source File: MicroServiceApplicationTest.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	projectApp = MicroServiceApplication.startProjectApplication();
	taskApp = MicroServiceApplication.startTaskApplication();

	String url = "http://127.0.0.1:" + MicroServiceApplication.TASK_PORT;
	taskClient = new CrnkClient(url);
	RestAssured.baseURI = url;
}
 
Example 11
Source File: VersionIT.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testVersion() {
    String versionExpected = System.getProperty("jolokia.version");
    String jolokiaUrl = System.getProperty("jolokia.url");

    RestAssured.baseURI = jolokiaUrl;
    RestAssured.defaultParser = Parser.JSON;
    System.out.println("Checking URL: " + jolokiaUrl);

    // Need to do it that way since Jolokia doesnt return application/json as mimetype by default
    JsonPath json = with(get("/version").asString());
    json.prettyPrint();
    assertEquals(versionExpected, json.get("value.agent"));

    // Alternatively, set the mime type before, then Rest-assured's fluent API can be used
    given()
            .param("mimeType", "application/json")
            .get("/version")
    .then().assertThat()
            .header("content-type", containsString("application/json"))
            .body("value.agent", equalTo(versionExpected))
            .body("timestamp", lessThanOrEqualTo((int) (System.currentTimeMillis() / 1000)))
            .body("status", equalTo(200))
            .body("value.protocol", equalTo("7.1"))
            .body("value.config",notNullValue());

}
 
Example 12
Source File: ControlledBounceProxyServerTest.java    From joynr with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
@Ignore("need cleanup of other tests (i.e. implementation of delete channel")
public void testNormalMessagingWithOneMessagePendingBeforeChannelWasOpened() throws Exception {

    final String channelId = "channel-testNormalMessagingWithOneMessagePendingBeforeChannelWasOpened";
    final String trackingId = "trackingId-testNormalMessagingWithOneMessagePendingBeforeChannelWasOpened";

    // create channel on bounce proxy
    /* @formatter:off */
    Response responseCreateChannel = given().header(X_ATMOSPHERE_TRACKING_ID, trackingId)
                                            .post("channels?ccid=" + channelId);
    /* @formatter:on */

    assertEquals(201 /* Created */, responseCreateChannel.getStatusCode());
    assertNotNull(responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID));

    String channelUrl = responseCreateChannel.getHeader(HEADER_LOCATION);

    String bpId = responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID);
    String bpUrl = configuration.getBounceProxyUrl(bpId);

    assertThat(channelUrl, isChannelUrlwithJsessionId(bpUrl, channelId, SESSIONID_NAME));

    String sessionId = Utilities.getSessionId(channelUrl, SESSIONID_NAME);
    RestAssured.baseURI = Utilities.getUrlWithoutSessionId(channelUrl, SESSIONID_NAME);

    // post messages to long polling channel before opening channel
    byte[] expectedPayload = "message-123".getBytes(StandardCharsets.UTF_8);
    byte[] serializedMessage = bpMock.createImmutableMessage(100000l, expectedPayload).getSerializedMessage();

    /* @formatter:off */
    Response responsePostMessage = given().when()
                                          .contentType(ContentType.BINARY)
                                          .body(serializedMessage)
                                          .post("message" + SESSIONID_APPENDIX + sessionId);
    /* @formatter:on */
    assertEquals(201 /* Created */, responsePostMessage.getStatusCode());
    assertThat(responsePostMessage.getHeader(HEADER_LOCATION),
               isMessageUrlwithJsessionId(bpUrl, "message-123", sessionId, SESSIONID_NAME));
    assertEquals("message-123", responsePostMessage.getHeader(HEADER_MSG_ID));

    // open long polling channel
    /* @formatter:off */
    Response responseOpenChannel = given().when()
                                          .contentType(ContentType.BINARY)
                                          .header("X-Atmosphere-tracking-id", trackingId)
                                          .get(SESSIONID_APPENDIX + sessionId);
    /* @formatter:on */
    assertEquals(200 /* OK */, responseOpenChannel.getStatusCode());

    List<ImmutableMessage> messages = bpMock.getJoynrMessagesFromResponse(responseOpenChannel);
    assertEquals(1, messages.size());
    assertEquals(expectedPayload, messages.get(0).getUnencryptedBody());
}
 
Example 13
Source File: GatewayBaseTest.java    From apiman-cli with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
    RestAssured.baseURI = getApimanUrl();
}
 
Example 14
Source File: BaseTest.java    From apiman-cli with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
    RestAssured.baseURI = getApimanUrl();
}
 
Example 15
Source File: MyRestIT.java    From df_data_service with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void configureRestAssured() {
  RestAssured.baseURI = "http://localhost";
  RestAssured.port = Integer.getInteger("http.port", 8082);
}
 
Example 16
Source File: BooksEndpointInteractionTest.java    From Test-Driven-Java-Development-Second-Edition with MIT License 4 votes vote down vote up
public BooksEndpointInteractionTest() {
    TDD_IN_JAVA = getBookProperties(TITLE_BOOK_1, AUTHOR_BOOK_1);
    RestAssured.baseURI = FULL_PATH.toString();
}
 
Example 17
Source File: BounceProxyServerTest.java    From joynr with Apache License 2.0 4 votes vote down vote up
@Override
protected String getBounceProxyBaseUri() {
    // using single bounce proxy only
    return RestAssured.baseURI;
}
 
Example 18
Source File: RestAssuredManager.java    From movieapp-dialog with Apache License 2.0 4 votes vote down vote up
@Override
  protected void before() throws Throwable {
RestAssured.baseURI = SetupMethod.serverUnderTest() + RestAPI.restURL;
      RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());
  }
 
Example 19
Source File: SingleControlledBounceProxyTest.java    From joynr with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
@Ignore("Ignore until servers are started in a separate JVM. Guice static problem")
public void testSimpleChannelSetupAndDeletion() throws Exception {

    String bpUrl = configuration.getBounceProxyUrl(SingleControlledBounceProxy.ID);

    // get bounce proxies list
    JsonPath listBps = given().get("bounceproxies").body().jsonPath();
    assertThat(listBps,
               anyOf(containsBounceProxy(SingleControlledBounceProxy.ID, "ALIVE"),
                     containsBounceProxy(SingleControlledBounceProxy.ID, "ACTIVE")));

    // create channel on bounce proxy
    /* @formatter:off */
    Response responseCreateChannel = //
            given().header(X_ATMOSPHERE_TRACKING_ID, "test-trackingId").post("channels?ccid=test-channel");
    /* @formatter:on */
    assertEquals(201 /* Created */, responseCreateChannel.getStatusCode());
    assertEquals(SingleControlledBounceProxy.ID, responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID));

    String channelUrl = responseCreateChannel.getHeader(HEADER_LOCATION);
    assertThat(channelUrl, isChannelUrlwithJsessionId(bpUrl, "test-channel", SESSIONID_NAME));
    String sessionId = Utilities.getSessionId(channelUrl, SESSIONID_NAME);

    // list channels
    JsonPath listChannels = given().get("channels").getBody().jsonPath();
    // TODO uncomment as soon as channel deletion is implemented
    // assertThat(listChannels, is(numberOfChannels(1)));
    assertThat(listChannels, containsChannel("test-channel"));

    RestAssured.baseURI = bpUrl;

    JsonPath listBpChannels = given().get("channels" + SESSIONID_APPENDIX + sessionId).getBody().jsonPath();
    // TODO uncomment as soon as channel deletion is implemented
    // assertThat(listBpChannels, is(numberOfChannels(2)));
    assertThat(listBpChannels, containsChannel("test-channel"));
    assertThat(listBpChannels, containsChannel("/*"));

    assertEquals(200 /* OK */,
                 given().delete("channels/test-channel" + SESSIONID_APPENDIX + sessionId + "/")
                        .thenReturn()
                        .statusCode());
    JsonPath listBpChannelsAfterDelete = given().get("channels" + SESSIONID_APPENDIX + sessionId)
                                                .getBody()
                                                .jsonPath();
    // TODO uncomment as soon as channel deletion is implemented
    // assertThat(listBpChannelsAfterDelete, is(numberOfChannels(1)));
    assertThat(listBpChannelsAfterDelete, not(containsChannel("test-channel")));
}
 
Example 20
Source File: TestSupport.java    From p3-batchrefine with Apache License 2.0 4 votes vote down vote up
private void startTransformerServer(Transformer transformer) throws Exception {
    final int port = findFreePort();
    RestAssured.baseURI = "http://localhost:" + port + "/";
    TransformerServer server = new TransformerServer(port, false);
    server.start(transformer);
}