Java Code Examples for io.restassured.RestAssured#port()

The following examples show how to use io.restassured.RestAssured#port() . 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: BaseTckTest.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static final void setUp() throws Exception {
    String portEnv = System.getProperty("smallrye.openapi.server.port");
    if (portEnv == null || portEnv.isEmpty()) {
        portEnv = "8082";
    }
    HTTP_PORT = Integer.valueOf(portEnv);
    // Set RestAssured default port directly. A bit nasty, but we have no easy way to change
    // AppTestBase#callEndpoint in the upstream. They also seem to do it this way, so it's no worse
    // than what's there.
    RestAssured.port = HTTP_PORT;
    // Set up a little HTTP server so that Rest assured has something to pull /openapi from
    System.out.println("Starting TCK test server on port " + HTTP_PORT);
    server = HttpServer.create(new InetSocketAddress(HTTP_PORT), 0);
    server.createContext("/openapi", new MyHandler());
    server.setExecutor(null);
    server.start();

    // Register a filter that performs YAML to JSON conversion
    // Called here because the TCK's AppTestBase#setUp() is not called. (Remove for 2.0)
    RestAssured.filters(new YamlToJsonFilter());
}
 
Example 2
Source File: MainDeployTest.java    From okapi with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp(TestContext context) {
  System.setProperty("vertx.logger-delegate-factory-class-name",
      "io.vertx.core.logging.Log4jLogDelegateFactory");
  // can't set Verticle options so we set a property instead
  System.setProperty("port", Integer.toString(port));
  async = context.async();
  api = RamlLoaders.fromFile("src/main/raml").load("okapi.raml");
  RestAssured.port = port;
  async.complete();
}
 
Example 3
Source File: ReusedMetricsTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@BeforeClass
static public void setup() throws MalformedURLException {
    // set base URI and port number to use for all requests
    String serverUrl = System.getProperty("test.url");
    String protocol = DEFAULT_PROTOCOL;
    String host = DEFAULT_HOST;
    int port = DEFAULT_PORT;

    if (serverUrl != null) {
        URL url = new URL(serverUrl);
        protocol = url.getProtocol();
        host = url.getHost();
        port = (url.getPort() == -1) ? DEFAULT_PORT : url.getPort();
    }

    RestAssured.baseURI = protocol + "://" + host;
    RestAssured.port = port;

    // set user name and password to use for basic authentication for all requests
    String userName = System.getProperty("test.user");
    String password = System.getProperty("test.pwd");

    if (userName != null && password != null) {
        RestAssured.authentication = RestAssured.basic(userName, password);
        RestAssured.useRelaxedHTTPSValidation();
    }

}
 
Example 4
Source File: RestAssuredXML2IntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@BeforeClass
public static void before() throws Exception {
    System.out.println("Setting up!");
    final int port = Util.getAvailablePort();
    wireMockServer = new WireMockServer(port);
    wireMockServer.start();
    RestAssured.port = port;
    configureFor("localhost", port);
    stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
      aResponse().withStatus(200)
        .withHeader("Content-Type", APPLICATION_XML)
        .withBody(TEACHERS)));
}
 
Example 5
Source File: DockerTest.java    From okapi with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp(TestContext context) {
  Async async = context.async();
  VertxOptions options = new VertxOptions();
  options.setBlockedThreadCheckInterval(60000); // in ms
  options.setWarningExceptionTime(60000); // in ms
  options.setPreferNativeTransport(true);
  vertx = Vertx.vertx(options);
  RestAssured.port = port;
  client = vertx.createHttpClient();

  checkDocker(res -> {
    haveDocker = res.succeeded();
    if (res.succeeded()) {
      dockerImages = res.result();
      logger.info("Docker found");
    } else {
      logger.warn("No docker: " + res.cause().getMessage());
    }
    DeploymentOptions opt = new DeploymentOptions()
      .setConfig(new JsonObject()
        .put("containerHost", "localhost")
        .put("port", Integer.toString(port))
        .put("port_start", Integer.toString(port + 4))
        .put("port_end", Integer.toString(port + 6)));

    vertx.deployVerticle(MainVerticle.class.getName(),
      opt, x -> async.complete());
  });
}
 
Example 6
Source File: ReadTimeoutTestCase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void init() throws IOException {
    int port = RestAssured.port;
    host = URI.create(RestAssured.baseURI).getHost();
    InetSocketAddress hostAddress = new InetSocketAddress(host, port);
    client = SocketChannel.open(hostAddress);
    TimeoutTestServlet.reset();
}
 
Example 7
Source File: RestAssuredXMLIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@BeforeClass
public static void before() throws Exception {
    System.out.println("Setting up!");
    final int port = Util.getAvailablePort();
    wireMockServer = new WireMockServer(port);
    wireMockServer.start();
    configureFor("localhost", port);
    RestAssured.port = port;
    stubFor(post(urlEqualTo(EVENTS_PATH)).willReturn(
      aResponse().withStatus(200)
        .withHeader("Content-Type", APPLICATION_XML)
        .withBody(EMPLOYEES)));
}
 
Example 8
Source File: JdbcComponentTestIT.java    From components with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    db = new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.DERBY).setName("testdb")
            .setScriptEncoding("UTF-8").addScript("/org/talend/components/service/rest/schema.sql")
            .addScript("/org/talend/components/service/rest/data_users.sql").build();
    // addresss: Starting embedded database:
    // url='jdbc:derby:memory:2dc86c66-5d3a-48fd-b903-56aa27d20e3b;create=true',
    // username='sa'
    try (Connection connection = db.getConnection()) {
        dbUrl = connection.getMetaData().getURL();
    }

    RestAssured.port = localServerPort;
}
 
Example 9
Source File: RestAssuredIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@BeforeClass
public static void before() throws Exception {
    System.out.println("Setting up!");
    final int port = Util.getAvailablePort();
    wireMockServer = new WireMockServer(port);
    wireMockServer.start();
    RestAssured.port = port;
    configureFor("localhost", port);
    stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
      aResponse().withStatus(200)
        .withHeader("Content-Type", APPLICATION_JSON)
        .withBody(GAME_ODDS)));
}
 
Example 10
Source File: MpMetricOptionalTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@BeforeClass
static public void setup() throws MalformedURLException {
    // set base URI and port number to use for all requests
    String serverUrl = System.getProperty("test.url");
    String protocol = DEFAULT_PROTOCOL;
    String host = DEFAULT_HOST;
    int port = DEFAULT_PORT;

    if (serverUrl != null) {
        URL url = new URL(serverUrl);
        protocol = url.getProtocol();
        host = url.getHost();
        port = (url.getPort() == -1) ? DEFAULT_PORT : url.getPort();
    }

    RestAssured.baseURI = protocol + "://" + host;
    RestAssured.port = port;

    // set user name and password to use for basic authentication for all requests
    String userName = System.getProperty("test.user");
    String password = System.getProperty("test.pwd");

    if (userName != null && password != null) {
        RestAssured.authentication = RestAssured.basic(userName, password);
        RestAssured.useRelaxedHTTPSValidation();
    }

    contextRoot = System.getProperty("context.root", "/optionalTCK");

    applicationPort = Integer.parseInt(System.getProperty("application.port", Integer.toString(port)));

}
 
Example 11
Source File: LoginIntegrationTest.java    From api-layer with Eclipse Public License 2.0 4 votes vote down vote up
@BeforeEach
public void setUp() {
    RestAssured.port = PORT;
    RestAssured.useRelaxedHTTPSValidation();
}
 
Example 12
Source File: RestAssuredAdvancedLiveTest.java    From tutorials with MIT License 4 votes vote down vote up
@Before
public void setup(){
    RestAssured.baseURI = "https://api.github.com";
    RestAssured.port = 443;
}
 
Example 13
Source File: ModuleTenantsTest.java    From okapi with Apache License 2.0 4 votes vote down vote up
@Test
public void test666() {
  final String okapiTenant = "roskilde";
  RestAssured.port = port;
  RestAssuredClient c;
  Response r;

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

  final String docProv_1_0_0 = "{" + LS
    + "  \"id\" : \"prov-1.0.0-alpha\"," + LS
    + "  \"name\" : \"prov module\"," + LS
    + "  \"provides\" : [ {" + LS
    + "    \"id\" : \"i1\"," + LS
    + "    \"version\" : \"1.0\"," + LS
    + "    \"handlers\" : [ {" + LS
    + "      \"methods\" : [ \"GET\", \"POST\" ]," + LS
    + "      \"pathPattern\" : \"/foo\"," + LS
    + "      \"permissionsRequired\" : [ ]" + LS
    + "    } ]" + LS
    + "  } ]" + LS
    + "}";
  c = api.createRestAssured3();
  c.given()
    .header("Content-Type", "application/json")
    .body(docProv_1_0_0)
    .post("/_/proxy/modules")
    .then().statusCode(201).log().ifValidationFails();
  Assert.assertTrue(
    "raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());

  final String docReq1 = "{" + LS
    + "  \"id\" : \"req-1.0.0\"," + LS
    + "  \"name\" : \"req module\"," + LS
    + "  \"provides\" : [ ]," + LS
    + "  \"requires\" : [ { \"id\" : \"i1\", \"version\" : \"1.0\" } ]" + LS
    + "}";
  System.out.println(docReq1);
  c = api.createRestAssured3();
  c.given()
    .header("Content-Type", "application/json")
    .body(docReq1)
    .post("/_/proxy/modules")
    .then().statusCode(201).log().ifValidationFails();
  Assert.assertTrue(
    "raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());
  StringBuilder b = new StringBuilder();
  b.append("[ ");
  b.append("{" + LS
    + "  \"id\" : \"req-1.0.0\"," + LS + ""
    + "  \"action\" : \"enable\"" + LS
    + "} ]");
  System.out.println(b);

  r = c.given()
    .header("Content-Type", "application/json")
    .body(b.toString())
    .post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true&preRelease=true")
    .then().statusCode(200).log().ifValidationFails()
    .extract().response();
  Assert.assertTrue(
    "raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());
  String s = r.getBody().asString();
  JsonArray a = new JsonArray(s);
  Assert.assertEquals("prov-1.0.0-alpha", a.getJsonObject(0).getString("id"));
  Assert.assertEquals("req-1.0.0", a.getJsonObject(1).getString("id"));

  c = api.createRestAssured3();
  r = c.given()
    .header("Content-Type", "application/json")
    .body(b.toString())
    .post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true&preRelease=false")
    .then().statusCode(400).log().ifValidationFails().extract().response();
}
 
Example 14
Source File: ValidationExceptionHandlerAcceptanceTest.java    From edison-microservice with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setUp() {
    RestAssured.port = port;
    RestAssured.basePath = servletContext.getContextPath();
}
 
Example 15
Source File: BindingReactiveBase.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@BeforeEach
void setUp() {
	RestAssured.baseURI = "http://localhost";
	RestAssured.port = this.port;
}
 
Example 16
Source File: ModuleTenantsTest.java    From okapi with Apache License 2.0 4 votes vote down vote up
@Test
public void testNpmRelease() {
  final String okapiTenant = "roskilde";
  RestAssured.port = port;
  RestAssuredClient c;
  Response r;

  final String docNpmSnapshot = "{" + LS
    + "  \"id\" : \"users-1.0.12345\"," + LS
    + "  \"provides\" : [ {" + LS
    + "    \"id\" : \"bint\"," + LS
    + "    \"version\" : \"1.0\"," + LS
    + "    \"handlers\" : [ {" + LS
    + "      \"methods\" : [ \"GET\", \"POST\" ]," + LS
    + "      \"pathPattern\" : \"/foo\"," + LS
    + "      \"permissionsRequired\" : [ ]" + LS
    + "    } ]" + LS
    + "  } ]," + LS
    + "  \"requires\" : [ ]," + 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(docNpmSnapshot)
    // even though this is an npmSnapshot, the module itself may be posted.
    .post("/_/proxy/modules?npmSnapshot=false")
    .then().statusCode(201)
    .log().ifValidationFails()
    .extract().response();
  Assert.assertTrue(
    "raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());

  final String docSampleModule_1_2_0 = "{" + LS
    + "  \"id\" : \"sample-module-1.2.0\"," + LS
    + "  \"name\" : \"this module\"," + LS
    + "  \"provides\" : [ {" + LS
    + "    \"id\" : \"_tenant\"," + LS
    + "    \"version\" : \"1.0\"," + LS
    + "    \"interfaceType\" : \"system\"," + LS
    + "    \"handlers\" : [ {" + LS
    + "      \"methods\" : [ \"POST\", \"DELETE\" ]," + LS
    + "      \"pathPattern\" : \"/_/tenant\"," + LS
    + "      \"permissionsRequired\" : [ ]" + LS
    + "    } ]" + LS
    + "  } ]," + LS
    + "  \"requires\" : [ { \"id\" : \"bint\", \"version\" : \"1.0\" } ]," + LS
    + "  \"launchDescriptor\" : {" + LS
    + "    \"exec\" : "
    + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS
    + "  }" + LS
    + "}";

  // first post will fail because we do not include npmSnapshot in dep check
  c = api.createRestAssured3();
  c.given()
    .header("Content-Type", "application/json")
    .body(docSampleModule_1_2_0)
    .post("/_/proxy/modules?npmSnapshot=false&check=true")
    .then().statusCode(400).log().ifValidationFails();
  Assert.assertTrue(
    "raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());

  // second post should succeed because we allow NPM snapshots
  c = api.createRestAssured3();
  c.given()
    .header("Content-Type", "application/json")
    .body(docSampleModule_1_2_0)
    .post("/_/proxy/modules?npmSnapshot=true&check=true")
    .then().statusCode(201).log().ifValidationFails();
  Assert.assertTrue(
    "raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());

}
 
Example 17
Source File: CalorieTrackingApiTest.java    From springboot-rest-h2-swagger with GNU General Public License v3.0 4 votes vote down vote up
@Before
public void setup() {
	RestAssured.port = port;
}
 
Example 18
Source File: BindingServletBase.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@BeforeEach
void setUp() {
	RestAssured.baseURI = "http://localhost";
	RestAssured.port = this.port;
}
 
Example 19
Source File: FullExampleComponentTestIT.java    From components with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    RestAssured.port = localServerPort;
}
 
Example 20
Source File: ModuleTenantsTest.java    From okapi with Apache License 2.0 4 votes vote down vote up
@Test
public void test4() {
  final String okapiTenant = "roskilde";
  RestAssured.port = port;
  RestAssuredClient c;
  Response r;

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

  final String doc1 = "{" + LS
    + "  \"id\" : \"sample-module-1.0.0\"," + LS
    + "  \"name\" : \"this module\"," + LS
    + "  \"provides\" : [ {" + LS
    + "    \"id\" : \"sample\"," + LS
    + "    \"version\" : \"1.0\"," + LS
    + "    \"handlers\" : [ {" + LS
    + "      \"methods\" : [ \"GET\", \"POST\", \"DELETE\" ]," + LS
    + "      \"pathPattern\" : \"/testb\"," + LS
    + "      \"type\" : \"request-response\"," + LS
    + "      \"permissionsRequired\" : [ ]" + LS
    + "    } ]" + LS
    + "  } ]," + LS
    + "  \"requires\" : [ ]," + 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(doc1).post("/_/proxy/modules").then().statusCode(201)
    .log().ifValidationFails().extract().response();
  Assert.assertTrue(
    "raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());

  c = api.createRestAssured3();
  c.given()
    .header("Content-Type", "application/json")
    .body("[ {\"id\" : \"sample-module-1.0.0\", \"action\" : \"enable\"} ]")
    .post("/_/proxy/tenants/" + okapiTenant + "/install?deploy=true")
    .then().statusCode(200).log().ifValidationFails()
    .body(equalTo("[ {" + LS
      + "  \"id\" : \"sample-module-1.0.0\"," + LS
      + "  \"action\" : \"enable\"" + LS
      + "} ]"));
  Assert.assertTrue(
    "raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());

  c.given()
    .header("X-Okapi-Tenant", okapiTenant)
    .header("X-delay", "600")
    .get("/testb")
    .then()
    .statusCode(200)
    .log().ifValidationFails();

  c = api.createRestAssured3();
  c.given()
    .header("Content-Type", "application/json")
    .body("[ {\"id\" : \"sample-module-1.0.0\", \"action\" : \"disable\"} ]")
    .post("/_/proxy/tenants/" + okapiTenant + "/install?deploy=true")
    .then().statusCode(200).log().ifValidationFails()
    .body(equalTo("[ {" + LS
      + "  \"id\" : \"sample-module-1.0.0\"," + LS
      + "  \"action\" : \"disable\"" + LS
      + "} ]"));
  Assert.assertTrue(
    "raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());

  c = api.createRestAssured3();
  c.given()
    .header("Content-Type", "application/json")
    .get("/_/discovery/modules")
    .then()
    .statusCode(200).log().ifValidationFails()
    .body(equalTo("[ ]"));
  Assert.assertTrue("raml: " + c.getLastReport().toString(),
    c.getLastReport().isEmpty());
}