@Test(groups = {TLS, PROFILE_SPECIFIC_TESTS}) public void testHttpPortIsClosed() throws Exception { assertThat(httpPort).isNotNull(); assertThat(httpsPort).isNotNull(); waitForNodeRefresh(); List<String> activeNodesUrls = getActiveNodesUrls(); assertThat(activeNodesUrls).hasSize(3); List<String> hosts = activeNodesUrls.stream() .map((uri) -> URI.create(uri).getHost()) .collect(toList()); for (String host : hosts) { assertPortIsOpen(host, httpsPort); assertPortIsClosed(host, httpPort); } }
@Test public void postMono() { URI uri = URI.create("http://localhost:" + port + "/mono"); Person person = new Person("Jack"); RequestEntity<Person> requestEntity = RequestEntity.post(uri).body(person); ResponseEntity<Person> result = restTemplate.exchange(requestEntity, Person.class); assertEquals(HttpStatus.OK, result.getStatusCode()); assertEquals("Jack", result.getBody().getName()); }
@Test public void testInvalidURIGetFileSystem() { final URI newRepo = URI.create( "git:///new-repo-name" ); try { PROVIDER.getFileSystem( newRepo ); failBecauseExceptionWasNotThrown( IllegalArgumentException.class ); } catch ( final IllegalArgumentException ex ) { assertThat( ex.getMessage() ).isEqualTo( "Parameter named 'uri' is invalid, missing host repository!" ); } }
@Test public void testRewriteURI() { DruidLeaderClient druidLeaderClient = EasyMock.createMock(DruidLeaderClient.class); EasyMock.expect(druidLeaderClient.findCurrentLeader()).andReturn("https://overlord:port"); HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class); EasyMock.expect(request.getQueryString()).andReturn("param1=test¶m2=test2").anyTimes(); // %3A is a colon; test to make sure urlencoded paths work right. EasyMock.expect(request.getRequestURI()).andReturn("/druid/over%3Alord/worker").anyTimes(); EasyMock.replay(druidLeaderClient, request); URI uri = URI.create(new OverlordProxyServlet(druidLeaderClient, null, null).rewriteTarget(request)); Assert.assertEquals("https://overlord:port/druid/over%3Alord/worker?param1=test¶m2=test2", uri.toString()); }
@Test public void pathPredicates() { PathPatternParser parser = new PathPatternParser(); parser.setCaseSensitive(false); Function<String, RequestPredicate> pathPredicates = RequestPredicates.pathPredicates(parser); URI uri = URI.create("http://localhost/path"); RequestPredicate predicate = pathPredicates.apply("/P*"); MockServerRequest request = MockServerRequest.builder().uri(uri).build(); assertTrue(predicate.test(request)); }
@Test public void shouldSetTheBaseUriToTheSameValueAsTheXForwardHostHeader() { // given final String xForwardHostAndPort = "jimwebber.org:1234"; XForwardFilter filter = new XForwardFilter(); InBoundHeaders headers = new InBoundHeaders(); headers.add( X_FORWARD_HOST_HEADER_KEY, xForwardHostAndPort ); ContainerRequest request = new ContainerRequest( WEB_APPLICATION, "GET", URI.create( "http://iansrobinson.com" ), URI.create( "http://iansrobinson.com/foo/bar" ), headers, INPUT_STREAM ); // when ContainerRequest result = filter.filter( request ); // then assertThat( result.getBaseUri().toString(), containsString( xForwardHostAndPort ) ); }
@Test public void testExplicitPropertyMappingsMultipleMetastores() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("hive.metastore.uri", "thrift://localhost:9083,thrift://192.0.2.3:8932") .put("hive.metastore.username", "presto") .build(); StaticMetastoreConfig expected = new StaticMetastoreConfig() .setMetastoreUris("thrift://localhost:9083,thrift://192.0.2.3:8932") .setMetastoreUsername("presto"); assertFullMapping(properties, expected); assertEquals(expected.getMetastoreUris(), ImmutableList.of( URI.create("thrift://localhost:9083"), URI.create("thrift://192.0.2.3:8932"))); assertEquals(expected.getMetastoreUsername(), "presto"); } }
public void testListVolumes() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-volumes"); VolumeApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_list.json")).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); Set<? extends Volume> volumes = api.list().toSet(); assertEquals(volumes, ImmutableSet.of(testVolume())); }
private void testSetSessionWithParameters(String property, Expression expression, String expectedValue, List<Expression> parameters) { QualifiedName qualifiedPropName = QualifiedName.of(CATALOG_NAME, property); QueryStateMachine stateMachine = QueryStateMachine.begin( format("set %s = 'old_value'", qualifiedPropName), TEST_SESSION, URI.create("fake://uri"), new ResourceGroupId("test"), false, transactionManager, accessControl, executor, metadata, WarningCollector.NOOP); getFutureValue(new SetSessionTask().execute(new SetSession(qualifiedPropName, expression), transactionManager, metadata, accessControl, stateMachine, parameters)); Map<String, String> sessionProperties = stateMachine.getSetSessionProperties(); assertEquals(sessionProperties, ImmutableMap.of(qualifiedPropName.toString(), expectedValue)); } }
@Test public void forwardedHeaders() { // One integration test to verify triggering of Forwarded header support. // More fine-grained tests in ForwardedHeaderTransformerTests. RequestEntity<Void> request = RequestEntity .get(URI.create("http://localhost:" + this.port + "/uri")) .header("Forwarded", "host=84.198.58.199;proto=https") .build(); ResponseEntity<String> entity = getRestTemplate().exchange(request, String.class); assertEquals("https://84.198.58.199/uri", entity.getBody()); }
@Test public void checkNewInputStream() throws IOException { final File temp = File.createTempFile( "foo", "bar" ); final SimpleFileSystemProvider fsProvider = new SimpleFileSystemProvider(); final Path path = GeneralPathImpl.newFromFile( fsProvider.getFileSystem( URI.create( "file:///" ) ), temp ); final InputStream stream = fsProvider.newInputStream( path ); assertThat( stream ).isNotNull(); stream.close(); }
@Test public void captureAndClaim() { ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, "/test"); ClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK); ClientHttpConnector connector = (method, uri, fn) -> fn.apply(request).then(Mono.just(response)); ClientRequest clientRequest = ClientRequest.create(HttpMethod.GET, URI.create("/test")) .header(WebTestClient.WEBTESTCLIENT_REQUEST_ID, "1").build(); WiretapConnector wiretapConnector = new WiretapConnector(connector); ExchangeFunction function = ExchangeFunctions.create(wiretapConnector); function.exchange(clientRequest).block(ofMillis(0)); WiretapConnector.Info actual = wiretapConnector.claimRequest("1"); ExchangeResult result = actual.createExchangeResult(Duration.ZERO, null); assertEquals(HttpMethod.GET, result.getMethod()); assertEquals("/test", result.getUrl().toString()); }
@Test public void created() { URI location = URI.create("http://example.com"); Mono<ServerResponse> result = ServerResponse.created(location).build(); StepVerifier.create(result) .expectNextMatches(response -> HttpStatus.CREATED.equals(response.statusCode()) && location.equals(response.headers().getLocation())) .expectComplete() .verify(); }
@Test public void shouldSetTheRequestUriToTheSameValueAsTheXForwardHostHeader() { // given final String xForwardHostAndPort = "jimwebber.org:1234"; XForwardFilter filter = new XForwardFilter(); InBoundHeaders headers = new InBoundHeaders(); headers.add( X_FORWARD_HOST_HEADER_KEY, xForwardHostAndPort ); ContainerRequest request = new ContainerRequest( WEB_APPLICATION, "GET", URI.create( "http://iansrobinson.com" ), URI.create( "http://iansrobinson.com/foo/bar" ), headers, INPUT_STREAM ); // when ContainerRequest result = filter.filter( request ); // then assertTrue( result.getRequestUri().toString().startsWith( "http://" + xForwardHostAndPort ) ); }
@Test public void testExplicitPropertyMappingsSingleMetastore() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("hive.metastore.uri", "thrift://localhost:9083") .put("hive.metastore.username", "presto") .build(); StaticMetastoreConfig expected = new StaticMetastoreConfig() .setMetastoreUris("thrift://localhost:9083") .setMetastoreUsername("presto"); assertFullMapping(properties, expected); assertEquals(expected.getMetastoreUris(), ImmutableList.of(URI.create("thrift://localhost:9083"))); assertEquals(expected.getMetastoreUsername(), "presto"); }
public void testListSnapshots() { URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-snapshots"); VolumeApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_list.json")).build() ).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); Set<? extends VolumeSnapshot> snapshots = api.listSnapshots().toSet(); assertEquals(snapshots, ImmutableSet.of(testSnapshot())); }
@Test public void testExplicitPropertyMappings() { Map<String, String> properties = new ImmutableMap.Builder<String, String>() .put("metadata-uri", "file://test.json") .build(); ExampleConfig expected = new ExampleConfig() .setMetadata(URI.create("file://test.json")); ConfigAssertions.assertFullMapping(properties, expected); } }
@Test public void expandUriTemplateVariablesFromExchangeAttribute() { String url = "http://url.somewhere.com?foo={foo}"; Map<String, String> attributes = Collections.singletonMap("foo", "bar"); this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, attributes); RedirectView view = new RedirectView(url); view.render(new HashMap<>(), MediaType.TEXT_HTML, exchange).block(); assertEquals(URI.create("http://url.somewhere.com?foo=bar"), this.exchange.getResponse().getHeaders().getLocation()); }