@Test public void outputDisplaysResultsFromComplexRegion() throws Exception { String result = gfsh.execute("query --query='select c.name, c.address from /complexRegion c'"); String[] resultLines = splitOnLineBreaks(result); assertThat(resultLines[0]).containsPattern("Result\\s+:\\s+true"); assertThat(resultLines[1]).containsPattern("Limit\\s+:\\s+100"); assertThat(resultLines[2]).containsPattern("Rows\\s+:\\s+100"); assertThat(resultLines[3]).containsPattern("name\\s+\\|\\s+address"); Arrays.asList(resultLines).subList(5, resultLines.length) .forEach(line -> assertThat(line).matches("name\\d+.*\"city\":\"Hometown\".*")); }
/** * Verifies that the gfsh output contains the given key, value pair. * * For example, given the following gfsh output: * * <pre> * {@code * Result : true * Key Class : java.lang.String * Key : key92 * Locations Found : 2 * } * </pre> * * We might assert that: * * <pre> * <code> containsKeyValuePair("Key Class", "java.lang.String"); </code> * </pre> */ public CommandResultAssert containsKeyValuePair(String key, String value) { assertThat(actual.getOutput()).containsPattern(key + "\\s+: " + value); return this; }
@Test public void canOutputComplexRegionToFile() throws Exception { File outputFile = temporaryFolder.newFile("queryOutput.txt"); FileUtils.deleteQuietly(outputFile); gfsh.executeAndAssertThat( "query --query='select c.name, c.address from /complexRegion c' --file=" + outputFile.getAbsolutePath()) .statusIsSuccess().containsOutput(outputFile.getAbsolutePath()); assertThat(outputFile).exists(); List<String> lines = Files.readLines(outputFile, StandardCharsets.UTF_8); assertThat(lines.get(7)).containsPattern("name\\s+\\|\\s+address"); lines.subList(9, lines.size()) .forEach(line -> assertThat(line).matches("name\\d+.*\"city\":\"Hometown\".*")); }
private void assertLowMemoryException(LowMemoryException exception) { assertThat(exception).isExactlyInstanceOf(LowMemoryException.class); assertThat(exception.getMessage()).containsPattern(LOW_MEMORY_REGEX); }
@Test public void execute_nonexistentAeqId_returnsError() throws Throwable { when(cache.getAsyncEventQueue(TEST_AEQ_ID)).thenReturn(null); function.execute(mockContext); verify(resultSender).lastResult(resultCaptor.capture()); CliFunctionResult result = resultCaptor.getValue(); assertThat(result.isSuccessful()).isFalse(); assertThat(result.getMessage()).containsPattern(TEST_AEQ_ID + ".*not found"); }
@Test public void execute_nonexistentAeqIdIfExists_returnsSuccess() throws Throwable { when(cache.getAsyncEventQueue(TEST_AEQ_ID)).thenReturn(null); when(mockArgs.isIfExists()).thenReturn(true); function.execute(mockContext); verify(resultSender).lastResult(resultCaptor.capture()); CliFunctionResult result = resultCaptor.getValue(); assertThat(result.isSuccessful()).isTrue(); assertThat(result.getMessage()).containsPattern("Skipping:.*" + TEST_AEQ_ID + ".*not found"); } }
@Test public void testMixMarshall() throws Exception { CacheConfig cache = new CacheConfig(); setBasicValues(cache); cache.getCustomCacheElements().add(new ElementOne("testOne")); xml = service.marshall(cache); System.out.println(xml); assertThat(xml).contains("custom-one>"); unmarshalled = service2.unMarshall(xml); unmarshalled.getCustomCacheElements().add(new ElementTwo("testTwo")); // xml generated wtih CacheConfigTwo has both elements in there. xml = service.marshall(unmarshalled); System.out.println(xml); assertThat(xml).contains("custom-one>"); assertThat(xml).contains("custom-two>"); assertThat(xml).containsPattern("xmlns=\"http://geode.apache.org/schema/cache\""); assertThat(xml).containsPattern("xmlns:ns\\d=\"http://geode.apache.org/schema/CustomOne\""); assertThat(xml).containsPattern("xmlns:ns\\d=\"http://geode.apache.org/schema/CustomTwo\""); }
assertThat(content).containsPattern( multilinePattern("server_request_duration_seconds_count", "{handler=\"Bar\",hostnamePattern=\"*\",httpStatus=\"200\",", "method=\"hello\",pathMapping=\"exact:/bar\",} 1.0")); assertThat(content).containsPattern( multilinePattern("server_request_length_count", "{handler=\"Bar\",hostnamePattern=\"*\",httpStatus=\"200\",", "method=\"hello\",pathMapping=\"exact:/bar\",} 1.0")); assertThat(content).containsPattern( multilinePattern("server_response_length_count", "{handler=\"Bar\",hostnamePattern=\"*\",httpStatus=\"200\",", "method=\"hello\",pathMapping=\"exact:/bar\",} 1.0")); assertThat(content).containsPattern( multilinePattern("client_request_duration_seconds_count", "{handler=\"Bar\",httpStatus=\"200\",method=\"hello\",} 1.0")); assertThat(content).containsPattern( multilinePattern("client_request_length_count", "{handler=\"Bar\",httpStatus=\"200\",method=\"hello\",} 1.0")); assertThat(content).containsPattern( multilinePattern("client_response_length_count", "{handler=\"Bar\",httpStatus=\"200\",method=\"hello\",} 1.0")); assertThat(content).containsPattern( multilinePattern("server_requests_total", "{handler=\"Bar\",hostnamePattern=\"*\",httpStatus=\"200\",", "method=\"hello\",pathMapping=\"exact:/bar\",", "result=\"success\",} 1.0")); assertThat(content).containsPattern(
assertThat(content).containsPattern( multilinePattern("server_request_duration_seconds_count", "{handler=\"Foo\",hostnamePattern=\"*\",httpStatus=\"200\",", "method=\"hello\",pathMapping=\"exact:/foo\",} 7.0")); assertThat(content).containsPattern( multilinePattern("server_request_length_count", "{handler=\"Foo\",hostnamePattern=\"*\",httpStatus=\"200\",", "method=\"hello\",pathMapping=\"exact:/foo\",} 7.0")); assertThat(content).containsPattern( multilinePattern("server_response_length_count", "{handler=\"Foo\",hostnamePattern=\"*\",httpStatus=\"200\",", "method=\"hello\",pathMapping=\"exact:/foo\",} 7.0")); assertThat(content).containsPattern( multilinePattern("client_request_duration_seconds_count", "{handler=\"Foo\",httpStatus=\"200\",method=\"hello\",} 7.0")); assertThat(content).containsPattern( multilinePattern("client_request_length_count", "{handler=\"Foo\",httpStatus=\"200\",method=\"hello\",} 7.0")); assertThat(content).containsPattern( multilinePattern("client_response_length_count", "{handler=\"Foo\",httpStatus=\"200\",method=\"hello\",} 7.0")); assertThat(content).containsPattern( multilinePattern("server_requests_total", "{handler=\"Foo\",hostnamePattern=\"*\",httpStatus=\"200\",", "method=\"hello\",pathMapping=\"exact:/foo\",", "result=\"failure\",} 3.0")); assertThat(content).containsPattern(
@Test public void testNeitherHasToString() { handle.registerArgument(new FooArgumentFactory()); handle.createUpdate(INSERT_POSITIONAL).bind(0, new Foo()).execute(); assertThat(positional).containsPattern("@[0-9a-f]{1,8}$"); }
@Test public void shouldTriggerJob() { final ResponseEntity<String> postResponse = restTemplate.postForEntity("/internal/jobs/Foo", "", String.class); assertThat(postResponse.getStatusCodeValue()).isEqualTo(204); final ResponseEntity<String> jobResponse = restTemplate.getForEntity(postResponse.getHeaders().getLocation(), String.class); assertThat(jobResponse.getStatusCodeValue()).isEqualTo(200); assertThat(jobResponse.getBody()).containsPattern(("\"state\"( )*:( )*\"Running\"")); // contains ignoring whitespaces assertThat(jobResponse.getBody()).containsPattern("\"jobType\"( )*:( )*\"Foo\""); // contains ignoring whitespaces }
@Test public void shouldLogToStdOut() { final Appender<ILoggingEvent> appender = Mockito.mock(Appender.class); final Logger logger = (Logger) LoggerFactory.getLogger("hoverfly"); logger.addAppender(appender); logger.setLevel(Level.INFO); systemOut.enableLog(); hoverfly = new Hoverfly(localConfigs().logToStdOut(), SIMULATE); hoverfly.start(); verify(appender, never()).doAppend(any()); assertThat(systemOut.getLogWithNormalizedLineSeparator()).containsPattern("Default proxy port has been overwritten [^\n]*port[^\n]*="); }
@Test public void shouldAllowTLSVerificationToBeDisabled() { systemOut.enableLog(); hoverfly = new Hoverfly(localConfigs().logToStdOut().disableTlsVerification(), SIMULATE); hoverfly.start(); assertThat(systemOut.getLogWithNormalizedLineSeparator()) .containsPattern("TLS certificate verification has been disabled"); }