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

The following examples show how to use com.jayway.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: AbstractGoalTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Before
public void start() {
	server = new StubServer().run();
	RestAssured.port = server.getPort();
	
	testTenant = this.buildTestTenant();
	testSpace = this.buildTestSpace();
	testApp = this.buildTestApplication();
	
	// App context
	System.setProperty(CoreConfiguration.APP_CTX_GROUP, testApp.getMvnGroup());
	System.setProperty(CoreConfiguration.APP_CTX_ARTIF, testApp.getArtifact());
	System.setProperty(CoreConfiguration.APP_CTX_VERSI, testApp.getVersion());

	// Identify app code
	System.setProperty(CoreConfiguration.BACKEND_CONNECT, CoreConfiguration.ConnectType.READ_WRITE.toString());
	
	// Identify app code
	System.setProperty(CoreConfiguration.APP_PREFIXES, "com.acme");
}
 
Example 2
Source File: NvdRestServiceMockup.java    From steady with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the server and registers URIs for the different vulnerabilities in {@link NvdRestServiceMockup#CVES}.
 * @throws IOException
 */
public NvdRestServiceMockup() {
	server = new StubServer().run();
	RestAssured.port = server.getPort();
	System.setProperty(VulasConfiguration.getServiceUrlKey(Service.CVE), "http://localhost:" + server.getPort() + "/nvdrest/vulnerabilities/<ID>");
	int cves_registered = 0;
	for(String cve: CVES) {
		try {
			whenHttp(server).
			match(composite(method(Method.GET), uri("/nvdrest/vulnerabilities/" + cve))).
			then(
					stringContent(FileUtil.readFile(Paths.get("./src/test/resources/cves/" + cve + "-new.json"))),
					contentType("application/json"),
					charset("UTF-8"),
					status(HttpStatus.OK_200));
			cves_registered++;
		} catch (IOException e) {
			System.err.println("Could not register URI for cve [" + cve + "]: " + e.getMessage());
		}
	}
	if(cves_registered==0) {
		throw new IllegalStateException("None of the CVEs could be registered");
	}
}
 
Example 3
Source File: IT02_CoverageControllerIT.java    From steady with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
	this.mockMvc = webAppContextSetup(webApplicationContext).build();

	// CVE service
	cveService = new StubServer().run();
	RestAssured.port = cveService.getPort();
	StringBuffer b = new StringBuffer();
	b.append("http://localhost:").append(cveService.getPort()).append("/cves/");
	VulasConfiguration.getGlobal().setProperty(VulasConfiguration.getServiceUrlKey(Service.CVE), b.toString());
	
	// JIRA service
	jiraService = new StubServer().run();
	RestAssured.port = jiraService.getPort();
	b = new StringBuffer();
	b.append("http://localhost:").append(cveService.getPort()).append("/rest/api/2/search");
	VulasConfiguration.getGlobal().setProperty(VulasConfiguration.getServiceUrlKey(Service.JIRA), b.toString());
}
 
Example 4
Source File: StubServerSetup.java    From steady with Apache License 2.0 6 votes vote down vote up
public StubServerSetup(String group, String artifact, String version) {
    server = new StubServer().run();
    RestAssured.port = server.getPort();

    testTenant = this.buildTestTenant();
    testSpace = this.buildTestSpace();
    testApp = this.buildTestApplication(group, artifact, version);

    // App context
    System.setProperty(CoreConfiguration.APP_CTX_GROUP, testApp.getMvnGroup());
    System.setProperty(CoreConfiguration.APP_CTX_ARTIF, testApp.getArtifact());
    System.setProperty(CoreConfiguration.APP_CTX_VERSI, testApp.getVersion());

    // Identify app code
    System.setProperty(CoreConfiguration.BACKEND_CONNECT, CoreConfiguration.ConnectType.READ_WRITE.toString());

    // Identify app code
    System.setProperty(CoreConfiguration.APP_PREFIXES, "com.acme");
}
 
Example 5
Source File: AbstractGoalTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Before
public void start() {
	server = new StubServer().run();
	RestAssured.port = server.getPort();
	
	testTenant = this.buildTestTenant();
	testSpace = this.buildTestSpace();
	testApp = this.buildTestApplication();
	
	// Clear and set properties
	this.clearVulasProperties();
	
	// App context
	System.setProperty(CoreConfiguration.APP_CTX_GROUP, testApp.getMvnGroup());
	System.setProperty(CoreConfiguration.APP_CTX_ARTIF, testApp.getArtifact());
	System.setProperty(CoreConfiguration.APP_CTX_VERSI, testApp.getVersion());

	// Identify app code
	System.setProperty(CoreConfiguration.BACKEND_CONNECT, CoreConfiguration.ConnectType.READ_WRITE.toString());
	
	// Identify app code
	System.setProperty(CoreConfiguration.APP_PREFIXES, "com.acme");
}
 
Example 6
Source File: ExampleApplicationTest.java    From crnk-example with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    RestAssured.port = port;

    docs = setupAsciidoc();

    client = new CrnkClient("http://localhost:" + port + "/api");
    client.addModule(docs);
    client.addModule(new PlainJsonFormatModule());
    client.findModules();

    // NPE fix
    if (AuthConfigFactory.getFactory() == null) {
        AuthConfigFactory.setFactory(new AuthConfigFactoryImpl());
    }
}
 
Example 7
Source File: EverrestJetty.java    From everrest with Eclipse Public License 2.0 6 votes vote down vote up
public void onStart(ITestContext context) {

        ITestNGMethod[] allTestMethods = context.getAllTestMethods();
        if (allTestMethods == null) {
            return;
        }
        if (httpServer == null && hasEverrestJettyListenerTestHierarchy(allTestMethods)) {
            httpServer = new JettyHttpServer();

            context.setAttribute(JETTY_PORT, httpServer.getPort());
            context.setAttribute(JETTY_SERVER, httpServer);

            try {
                httpServer.start();
                httpServer.resetFactories();
                httpServer.resetFilter();
                RestAssured.port = httpServer.getPort();
                RestAssured.basePath = JettyHttpServer.UNSECURE_REST;
            } catch (Exception e) {
                LOG.error(e.getLocalizedMessage(), e);
                throw new RuntimeException(e.getLocalizedMessage(), e);
            }
        }
    }
 
Example 8
Source File: ServiceBaseTest.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    if (!environmentSet) {
        RestAssured.baseURI = RestAssured.DEFAULT_URI;
        RestAssured.port = port;

        // Overrides connection information with random port value
        String url = RestAssured.baseURI + ":" + port;
        MockPropertySource connectionInformation = new MockPropertySource()
                .withProperty("dataset.service.url", url)
                .withProperty("transformation.service.url", url)
                .withProperty("preparation.service.url", url)
                .withProperty("async_store.service.url", url)
                .withProperty("gateway.service.url", url)
                .withProperty("fullrun.service.url", url);
        environment.getPropertySources().addFirst(connectionInformation);
        environmentSet = true;
    }
}
 
Example 9
Source File: BaseTest.java    From katharsis-framework with Apache License 2.0 5 votes vote down vote up
@Before
public final void before() {
	RestAssured.port = port;
	loadJsonApiSchema();

	client = new KatharsisClient("http://localhost:" + port + "/api");
	client.addModule(JpaModule.newClientModule("io.katharsis.example.springboot.simple.domain.jpa"));
}
 
Example 10
Source File: RestAssuredTest.java    From raml-tester with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithPortAndPath() throws IOException {
    RestAssured.baseURI = baseUrl();
    RestAssured.port = PORT;
    restAssured.given().get("/base/data").andReturn();
    assertThat(restAssured.getLastReport(), checks());
}
 
Example 11
Source File: EventStreamReadingAT.java    From nakadi with MIT License 5 votes vote down vote up
@Test(timeout = 10000)
public void whenMemoryOverflowEventsDumped() throws IOException {
    // Create event type
    final EventType loadEt = EventTypeTestBuilder.builder()
            .defaultStatistic(new EventTypeStatistics(PARTITIONS_NUM, PARTITIONS_NUM))
            .build();
    NakadiTestUtils.createEventTypeInNakadi(loadEt);

    // Publish events to event type, that are not fitting memory
    final String evt = "{\"foo\":\"barbarbar\"}";
    final int eventCount = 2 * (10000 / evt.length());
    NakadiTestUtils.publishEvents(loadEt.getName(), eventCount, i -> evt);

    // Configure streaming so it will:(more than 10s and batch_limit
    // - definitely wait for more than test timeout (10s)
    // - collect batch, which size is greater than events published to this event type
    final String url = RestAssured.baseURI + ":" + RestAssured.port + createStreamEndpointUrl(loadEt.getName())
            + "?batch_limit=" + (10 * eventCount)
            + "&stream_limit=" + (10 * eventCount)
            + "&batch_flush_timeout=11"
            + "&stream_timeout=11";
    final HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
    // Start from the begin.
    connection.setRequestProperty("X-Nakadi-Cursors",
            "[" + IntStream.range(0, PARTITIONS_NUM)
                    .mapToObj(i -> "{\"partition\": \"" + i + "\",\"offset\":\"begin\"}")
                    .collect(Collectors.joining(",")) + "]");
    Assert.assertEquals(HttpServletResponse.SC_OK, connection.getResponseCode());

    try (InputStream inputStream = connection.getInputStream()){
        final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charsets.UTF_8));

        final String line = reader.readLine();
        // If we read at least one line, than it means, that we were able to read data before test timeout reached.
        Assert.assertNotNull(line);
    }
}
 
Example 12
Source File: RestAssuredTest.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void configureRestAssured() {
    RestAssured.baseURI = RestAssuredConfig.config().baseURI;
    RestAssured.port = RestAssuredConfig.config().port;
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    RestAssured.config = RestAssured.config().encoderConfig(encoderConfig().defaultContentCharset("UTF-8"));
    RestAssured.config = RestAssured.config().decoderConfig(decoderConfig().defaultContentCharset("UTF-8"));
}
 
Example 13
Source File: TransformationServiceUrlRuntimeUpdater.java    From data-prep with Apache License 2.0 5 votes vote down vote up
/**
 * This method should be called before each test.
 */
@Override
public void setUp() {

    RestAssured.port = port;

    // set the service url @runtime
    for (BaseTransformationService service : transformationServices) {
        setField(service, "datasetServiceUrl", "http://localhost:" + port);
        setField(service, "preparationServiceUrl", "http://localhost:" + port);
    }
}
 
Example 14
Source File: BaseTest.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Before
public final void before() {
	RestAssured.port = port;
	loadJsonApiSchema();

	client = new CrnkClient("http://localhost:" + port);
}
 
Example 15
Source File: AbstractGoalTest.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * Before every test:
 * - Create sample tenant, space and application
 * - Start HTTP server and register a corresponding backend URL (unless there's one already)
 */
@Before
public void start() {
	server = new StubServer().run();
	RestAssured.port = server.getPort();
	
	testTenant = this.buildTestTenant();
	testSpace = this.buildTestSpace();
	testApp = this.buildTestApplication();
	
	this.vulasConfiguration = new VulasConfiguration();
}
 
Example 16
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 17
Source File: SearchSteps.java    From movie-service with Apache License 2.0 4 votes vote down vote up
@Before
public void configurePorts() {
    RestAssured.port = port;
}
 
Example 18
Source File: CatalogSteps.java    From movie-service with Apache License 2.0 4 votes vote down vote up
@Before
public void configurePorts() {
    RestAssured.port = port;
}
 
Example 19
Source File: ServiceBrokerV2IntegrationTestBase.java    From s3-cf-service-broker with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    RestAssured.port = port;
}
 
Example 20
Source File: MyRestIT.java    From my-vertx-first-app 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);
}