use of org.hamcrest.Matchers.containsString in project jetty.project by eclipse.
the class HttpFieldsTest method testPutTo.
@Test
public void testPutTo() throws Exception {
HttpFields header = new HttpFields();
header.put("name0", "value0");
header.put("name1", "value:A");
header.add("name1", "value:B");
header.add("name2", "");
ByteBuffer buffer = BufferUtil.allocate(1024);
BufferUtil.flipToFill(buffer);
HttpGenerator.putTo(header, buffer);
BufferUtil.flipToFlush(buffer, 0);
String result = BufferUtil.toString(buffer);
assertThat(result, Matchers.containsString("name0: value0"));
assertThat(result, Matchers.containsString("name1: value:A"));
assertThat(result, Matchers.containsString("name1: value:B"));
}
use of org.hamcrest.Matchers.containsString in project spring-integration by spring-projects.
the class MessagingAnnotationsWithBeanAnnotationTests method testMessagingAnnotationsFlow.
@Test
public void testMessagingAnnotationsFlow() {
Stream.of(this.sourcePollingChannelAdapters).forEach(a -> a.start());
// this.sourcePollingChannelAdapter.start();
for (int i = 0; i < 10; i++) {
Message<?> receive = this.discardChannel.receive(10000);
assertNotNull(receive);
assertTrue(((Integer) receive.getPayload()) % 2 == 0);
receive = this.counterErrorChannel.receive(10000);
assertNotNull(receive);
assertThat(receive, instanceOf(ErrorMessage.class));
assertThat(receive.getPayload(), instanceOf(MessageRejectedException.class));
MessageRejectedException exception = (MessageRejectedException) receive.getPayload();
assertThat(exception.getMessage(), containsString("MessageFilter " + "'messagingAnnotationsWithBeanAnnotationTests.ContextConfiguration.filter.filter.handler'" + " rejected Message"));
}
for (Message<?> message : collector) {
assertFalse(((Integer) message.getPayload()) % 2 == 0);
MessageHistory messageHistory = MessageHistory.read(message);
assertNotNull(messageHistory);
String messageHistoryString = messageHistory.toString();
assertThat(messageHistoryString, Matchers.containsString("routerChannel"));
assertThat(messageHistoryString, Matchers.containsString("filterChannel"));
assertThat(messageHistoryString, Matchers.containsString("aggregatorChannel"));
assertThat(messageHistoryString, Matchers.containsString("splitterChannel"));
assertThat(messageHistoryString, Matchers.containsString("serviceChannel"));
assertThat(messageHistoryString, Matchers.not(Matchers.containsString("discardChannel")));
}
assertNull(this.skippedServiceActivator);
assertNull(this.skippedMessageHandler);
assertNull(this.skippedChannel);
assertNull(this.skippedChannel2);
assertNull(this.skippedMessageSource);
}
use of org.hamcrest.Matchers.containsString in project spring-integration by spring-projects.
the class SftpTests method testSftpMgetFlow.
@Test
@SuppressWarnings("unchecked")
public void testSftpMgetFlow() {
QueueChannel out = new QueueChannel();
IntegrationFlow flow = f -> f.handle(Sftp.outboundGateway(sessionFactory(), AbstractRemoteFileOutboundGateway.Command.MGET, "payload").options(AbstractRemoteFileOutboundGateway.Option.RECURSIVE).regexFileNameFilter("(subSftpSource|.*1.txt)").localDirectoryExpression("'" + getTargetLocalDirectoryName() + "' + #remoteDirectory").localFilenameExpression("#remoteFileName.replaceFirst('sftpSource', 'localTarget')")).channel(out);
String dir = "sftpSource/";
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
registration.getInputChannel().send(new GenericMessage<>(dir + "*"));
Message<?> result = out.receive(10_000);
assertNotNull(result);
List<File> localFiles = (List<File>) result.getPayload();
// should have filtered sftpSource2.txt
assertEquals(2, localFiles.size());
for (File file : localFiles) {
assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), Matchers.containsString(dir));
}
assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), Matchers.containsString(dir + "subSftpSource"));
registration.destroy();
}
use of org.hamcrest.Matchers.containsString in project gocd by gocd.
the class DiskSpaceWarningCheckerTest method shouldFormatLowDiskSpaceWarningMailWithHelpLinksHttpAndSiteUrl.
@Test
public void shouldFormatLowDiskSpaceWarningMailWithHelpLinksHttpAndSiteUrl() throws URISyntaxException {
String expectedHelpUrl = docsUrl("/installation/configuring_server_details.html");
GoConfigService goConfigService = mockGoConfigServiceToHaveSiteUrl();
SystemDiskSpaceChecker checker = mock(SystemDiskSpaceChecker.class);
when(checker.getUsableSpace(any(File.class))).thenReturn(1000000L);
ArtifactsDiskSpaceWarningChecker diskSpaceWarningChecker = new ArtifactsDiskSpaceWarningChecker(new SystemEnvironment(), null, goConfigService, checker, serverHealthService) {
@Override
protected String targetFolderCanonicalPath() {
return ".";
}
};
SendEmailMessage actual = diskSpaceWarningChecker.createEmail();
ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
diskSpaceWarningChecker.check(result);
assertThat(actual.getBody(), Matchers.containsString(expectedHelpUrl));
assertThat(result.getServerHealthState().isSuccess(), is(true));
assertThat(result.getServerHealthState().getMessage(), is("GoCD Server's artifact repository is running low on disk space"));
assertThat(result.getServerHealthState().getType(), is(HealthStateType.artifactsDiskFull()));
}
use of org.hamcrest.Matchers.containsString in project knox by apache.
the class GatewayBasicFuncTest method testXForwardHeadersRewrite.
@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testXForwardHeadersRewrite() throws Exception {
LOG_ENTER();
String username = "hdfs";
String password = "hdfs-password";
String host = "whatsinaname";
String port = "8889";
String scheme = "https";
// Test rewriting of body with X-Forwarded headers (using storm)
String resourceName = "storm/topology-id.json";
String path = "/api/v1/topology/WordCount-1-1424792039";
String gatewayPath = driver.getUrl("STORM") + path;
driver.getMock("STORM").expect().method("GET").header("X-Forwarded-Host", host).header("X-Forwarded-Proto", scheme).header("X-Forwarded-Port", port).header("X-Forwarded-Context", "/gateway/cluster").header("X-Forwarded-Server", host).header("X-Forwarded-For", Matchers.containsString("what, boo")).pathInfo(path).queryParam("user.name", username).respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resourceName)).contentType(ContentType.JSON.toString());
Response response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").header("Accept", ContentType.JSON.toString()).header("X-Forwarded-Host", host).header("X-Forwarded-Proto", scheme).header("X-Forwarded-Port", port).header("X-Forwarded-Server", "what").header("X-Forwarded-For", "what, boo").then().statusCode(HttpStatus.SC_OK).contentType(ContentType.JSON.toString()).when().get(gatewayPath);
String link = response.getBody().jsonPath().getString("spouts[0].errorWorkerLogLink");
assertThat(link, is(startsWith(scheme + "://" + host + ":" + port + "/")));
assertThat(link, containsString("/storm/logviewer"));
driver.assertComplete();
resourceName = "storm/topology-component-id.json";
path = "/api/v1/topology/WordCount-1-1424792039/component/spout";
gatewayPath = driver.getUrl("STORM") + path;
driver.getMock("STORM").expect().method("GET").header("X-Forwarded-Host", host).header("X-Forwarded-Proto", scheme).header("X-Forwarded-Port", port).header("X-Forwarded-Context", "/gateway/cluster").header("X-Forwarded-Server", host).header("X-Forwarded-For", Matchers.containsString("what, boo")).pathInfo(path).queryParam("user.name", username).respond().status(HttpStatus.SC_OK).content(driver.getResourceBytes(resourceName)).contentType(ContentType.JSON.toString());
response = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").header("Accept", ContentType.JSON.toString()).header("X-Forwarded-Host", host).header("X-Forwarded-Proto", scheme).header("X-Forwarded-Port", port).header("X-Forwarded-Server", host).header("X-Forwarded-For", "what, boo").then().statusCode(HttpStatus.SC_OK).contentType(ContentType.JSON.toString()).when().get(gatewayPath);
link = response.getBody().jsonPath().getString("executorStats[0].workerLogLink");
assertThat(link, is(startsWith(scheme + "://" + host + ":" + port + "/")));
assertThat(link, containsString("/storm/logviewer"));
driver.assertComplete();
// Test header rewrite using webhdfs
String root = "/tmp/GatewayBasicFuncTest/testBasicOutboundHeaderUseCase";
driver.getMock("WEBHDFS").expect().method("PUT").pathInfo("/v1" + root + "/dir/file").header("Host", driver.getRealAddr("WEBHDFS")).header("X-Forwarded-Host", host).header("X-Forwarded-Proto", scheme).header("X-Forwarded-Port", port).header("X-Forwarded-Context", "/gateway/cluster").header("X-Forwarded-Server", host).header("X-Forwarded-For", Matchers.containsString("what, boo")).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 = given().auth().preemptive().basic(username, password).header("X-XSRF-Header", "jksdhfkhdsf").header("X-Forwarded-Host", host).header("X-Forwarded-Proto", scheme).header("X-Forwarded-Port", port).header("X-Forwarded-Server", host).header("X-Forwarded-For", "what, boo").queryParam("op", "CREATE").then().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, is(startsWith(scheme + "://" + host + ":" + port + "/")));
assertThat(location, containsString("?_="));
}
assertThat(location, not(containsString("host=")));
assertThat(location, not(containsString("port=")));
LOG_EXIT();
}
Aggregations