Java Code Examples for org.hamcrest.core.StringStartsWith
The following examples show how to use
org.hamcrest.core.StringStartsWith. These examples are extracted from open source projects.
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 Project: spring-analysis-note Source File: JsonPathResultMatchers.java License: MIT License | 6 votes |
private String getContent(MvcResult result) throws UnsupportedEncodingException { String content = result.getResponse().getContentAsString(); if (StringUtils.hasLength(this.prefix)) { try { String reason = String.format("Expected a JSON payload prefixed with \"%s\" but found: %s", this.prefix, StringUtils.quote(content.substring(0, this.prefix.length()))); MatcherAssert.assertThat(reason, content, StringStartsWith.startsWith(this.prefix)); return content.substring(this.prefix.length()); } catch (StringIndexOutOfBoundsException ex) { throw new AssertionError("JSON prefix \"" + this.prefix + "\" not found", ex); } } else { return content; } }
Example 2
Source Project: Flink-CEPplus Source File: DataStreamTest.java License: Apache License 2.0 | 6 votes |
@Test public void testPOJOWithNestedArrayNoHashCodeKeyRejection() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<POJOWithHashCode> input = env.fromElements( new POJOWithHashCode(new int[] {1, 2})); TypeInformation<?> expectedTypeInfo = new TupleTypeInfo<Tuple1<int[]>>( PrimitiveArrayTypeInfo.INT_PRIMITIVE_ARRAY_TYPE_INFO); // adjust the rule expectedException.expect(InvalidProgramException.class); expectedException.expectMessage(new StringStartsWith("Type " + expectedTypeInfo + " cannot be used as key.")); input.keyBy("id"); }
Example 3
Source Project: Flink-CEPplus Source File: DataStreamTest.java License: Apache License 2.0 | 6 votes |
@Test public void testTupleNestedArrayKeyRejection() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<Tuple2<Integer[], String>> input = env.fromElements( new Tuple2<>(new Integer[] {1, 2}, "test-test")); TypeInformation<?> expectedTypeInfo = new TupleTypeInfo<Tuple2<Integer[], String>>( BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO); // adjust the rule expectedException.expect(InvalidProgramException.class); expectedException.expectMessage(new StringStartsWith("Type " + expectedTypeInfo + " cannot be used as key.")); input.keyBy(new KeySelector<Tuple2<Integer[], String>, Tuple2<Integer[], String>>() { @Override public Tuple2<Integer[], String> getKey(Tuple2<Integer[], String> value) throws Exception { return value; } }); }
Example 4
Source Project: flink Source File: DataStreamTest.java License: Apache License 2.0 | 6 votes |
@Test public void testPOJOWithNestedArrayNoHashCodeKeyRejection() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<POJOWithHashCode> input = env.fromElements( new POJOWithHashCode(new int[] {1, 2})); TypeInformation<?> expectedTypeInfo = new TupleTypeInfo<Tuple1<int[]>>( PrimitiveArrayTypeInfo.INT_PRIMITIVE_ARRAY_TYPE_INFO); // adjust the rule expectedException.expect(InvalidProgramException.class); expectedException.expectMessage(new StringStartsWith("Type " + expectedTypeInfo + " cannot be used as key.")); input.keyBy("id"); }
Example 5
Source Project: flink Source File: DataStreamTest.java License: Apache License 2.0 | 6 votes |
@Test public void testTupleNestedArrayKeyRejection() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<Tuple2<Integer[], String>> input = env.fromElements( new Tuple2<>(new Integer[] {1, 2}, "test-test")); TypeInformation<?> expectedTypeInfo = new TupleTypeInfo<Tuple2<Integer[], String>>( BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO); // adjust the rule expectedException.expect(InvalidProgramException.class); expectedException.expectMessage(new StringStartsWith("Type " + expectedTypeInfo + " cannot be used as key.")); input.keyBy(new KeySelector<Tuple2<Integer[], String>, Tuple2<Integer[], String>>() { @Override public Tuple2<Integer[], String> getKey(Tuple2<Integer[], String> value) throws Exception { return value; } }); }
Example 6
Source Project: java-technology-stack Source File: JsonPathResultMatchers.java License: MIT License | 6 votes |
private String getContent(MvcResult result) throws UnsupportedEncodingException { String content = result.getResponse().getContentAsString(); if (StringUtils.hasLength(this.prefix)) { try { String reason = String.format("Expected a JSON payload prefixed with \"%s\" but found: %s", this.prefix, StringUtils.quote(content.substring(0, this.prefix.length()))); MatcherAssert.assertThat(reason, content, StringStartsWith.startsWith(this.prefix)); return content.substring(this.prefix.length()); } catch (StringIndexOutOfBoundsException ex) { throw new AssertionError("JSON prefix \"" + this.prefix + "\" not found", ex); } } else { return content; } }
Example 7
Source Project: flink Source File: DataStreamTest.java License: Apache License 2.0 | 6 votes |
@Test public void testPOJOWithNestedArrayNoHashCodeKeyRejection() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<POJOWithHashCode> input = env.fromElements( new POJOWithHashCode(new int[] {1, 2})); TypeInformation<?> expectedTypeInfo = new TupleTypeInfo<Tuple1<int[]>>( PrimitiveArrayTypeInfo.INT_PRIMITIVE_ARRAY_TYPE_INFO); // adjust the rule expectedException.expect(InvalidProgramException.class); expectedException.expectMessage(new StringStartsWith("Type " + expectedTypeInfo + " cannot be used as key.")); input.keyBy("id"); }
Example 8
Source Project: flink Source File: DataStreamTest.java License: Apache License 2.0 | 6 votes |
@Test public void testTupleNestedArrayKeyRejection() { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<Tuple2<Integer[], String>> input = env.fromElements( new Tuple2<>(new Integer[] {1, 2}, "test-test")); TypeInformation<?> expectedTypeInfo = new TupleTypeInfo<Tuple2<Integer[], String>>( BasicArrayTypeInfo.INT_ARRAY_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO); // adjust the rule expectedException.expect(InvalidProgramException.class); expectedException.expectMessage(new StringStartsWith("Type " + expectedTypeInfo + " cannot be used as key.")); input.keyBy(new KeySelector<Tuple2<Integer[], String>, Tuple2<Integer[], String>>() { @Override public Tuple2<Integer[], String> getKey(Tuple2<Integer[], String> value) throws Exception { return value; } }); }
Example 9
Source Project: Flink-CEPplus Source File: DataStreamTest.java License: Apache License 2.0 | 5 votes |
private <K> void testKeyRejection(KeySelector<Tuple2<Integer[], String>, K> keySelector, TypeInformation<K> expectedKeyType) { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<Tuple2<Integer[], String>> input = env.fromElements( new Tuple2<>(new Integer[] {1, 2}, "barfoo") ); Assert.assertEquals(expectedKeyType, TypeExtractor.getKeySelectorTypes(keySelector, input.getType())); // adjust the rule expectedException.expect(InvalidProgramException.class); expectedException.expectMessage(new StringStartsWith("Type " + expectedKeyType + " cannot be used as key.")); input.keyBy(keySelector); }
Example 10
Source Project: flink Source File: DataStreamTest.java License: Apache License 2.0 | 5 votes |
private <K> void testKeyRejection(KeySelector<Tuple2<Integer[], String>, K> keySelector, TypeInformation<K> expectedKeyType) { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<Tuple2<Integer[], String>> input = env.fromElements( new Tuple2<>(new Integer[] {1, 2}, "barfoo") ); Assert.assertEquals(expectedKeyType, TypeExtractor.getKeySelectorTypes(keySelector, input.getType())); // adjust the rule expectedException.expect(InvalidProgramException.class); expectedException.expectMessage(new StringStartsWith("Type " + expectedKeyType + " cannot be used as key.")); input.keyBy(keySelector); }
Example 11
Source Project: docker-java-api Source File: RtLogsITCase.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * RtLogs can fetch the Container's logs (return them as a String). * @throws Exception If something goes wrong. */ @Test public void fetchesLogs() throws Exception { final Container container = new UnixDocker( new File("/var/run/docker.sock") ).images().pull("hello-world", "latest").run(); final String logs = container.logs().fetch(); MatcherAssert.assertThat( logs, new StringStartsWith("\nHello from Docker!") ); }
Example 12
Source Project: docker-java-api Source File: RtLogsITCase.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * RtLogs can follow the Container's logs (return them as a Reader). * @throws Exception If something goes wrong. */ @Test @Ignore public void followsLogs() throws Exception { final Container container = new UnixDocker( new File("/var/run/docker.sock") ).images().pull("ubuntu", "latest").run(); final String logs = IOUtils.toString(container.logs().follow()); MatcherAssert.assertThat( logs.trim(), new StringStartsWith("Hello from Docker!") ); }
Example 13
Source Project: emissary Source File: HeartbeatActionTest.java License: Apache License 2.0 | 5 votes |
@Theory public void badParams(String badValue) { // setup formParams.put(HeartbeatAdapter.FROM_PLACE_NAME, Arrays.asList(badValue)); formParams.put(HeartbeatAdapter.TO_PLACE_NAME, Arrays.asList(badValue)); // test final Response response = target(HEARTBEAT_ACTION).request().post(Entity.form(formParams)); // verify final int status = response.getStatus(); assertThat(status, equalTo(500)); final String result = response.readEntity(String.class); assertThat(result, StringStartsWith.startsWith("Heartbeat failed")); }
Example 14
Source Project: shardingsphere-elasticjob-cloud Source File: RestfulServerTest.java License: Apache License 2.0 | 5 votes |
@Test public void assertCallFailure() throws Exception { ContentExchange actual = sentRequest("{\"string\":\"test\",\"integer\":\"invalid_number\"}"); Assert.assertThat(actual.getResponseStatus(), Is.is(500)); Assert.assertThat(actual.getResponseContent(), StringStartsWith.startsWith("java.lang.NumberFormatException")); Mockito.verify(caller).call("test"); }
Example 15
Source Project: shardingsphere-elasticjob-cloud Source File: TaskContextTest.java License: Apache License 2.0 | 5 votes |
@Test public void assertNew() { TaskContext actual = new TaskContext("test_job", Lists.newArrayList(0), ExecutionType.READY, "slave-S0"); Assert.assertThat(actual.getMetaInfo().getJobName(), Is.is("test_job")); Assert.assertThat(actual.getMetaInfo().getShardingItems().get(0), Is.is(0)); Assert.assertThat(actual.getType(), Is.is(ExecutionType.READY)); Assert.assertThat(actual.getSlaveId(), Is.is("slave-S0")); Assert.assertThat(actual.getId(), StringStartsWith.startsWith(TaskNode.builder().build().getTaskNodeValue().substring(0, TaskNode.builder().build().getTaskNodeValue().length() - 1))); }
Example 16
Source Project: cactoos Source File: MapOfTest.java License: MIT License | 5 votes |
@Test public void convertsIterableToMap() { MatcherAssert.assertThat( "Can't convert iterable to map", new MapOf<Integer, String>( new MapEntry<>(0, "hello, "), new MapEntry<>(1, "world!") ), new IsMapContaining<>( new IsEqual<>(0), new StringStartsWith("hello") ) ); }
Example 17
Source Project: yang2swagger Source File: PathPrunnerTest.java License: Eclipse Public License 1.0 | 5 votes |
@Test public void prunePathB() { int orgPathsCnt = swagger.getPaths().size(); int orgDefCnt = swagger.getDefinitions().size(); new PathPrunner() .prunePath("/b") .accept(swagger); assertEquals(orgPathsCnt - 4, swagger.getPaths().size()); assertEquals(orgDefCnt, swagger.getDefinitions().size()); Assert.assertThat(swagger.getPaths().keySet(), Every.everyItem(not(StringStartsWith.startsWith("/b")))); }
Example 18
Source Project: yang2swagger Source File: PathPrunnerTest.java License: Eclipse Public License 1.0 | 5 votes |
@Test public void prunePathBA() { int orgPathsCnt = swagger.getPaths().size(); int orgDefCnt = swagger.getDefinitions().size(); new PathPrunner() .prunePath("/b/propE") .prunePath("/a") .accept(swagger); assertEquals(orgPathsCnt - 3, swagger.getPaths().size()); assertEquals(orgDefCnt, swagger.getDefinitions().size()); Assert.assertThat(swagger.getPaths().keySet(), Every.everyItem(not(StringStartsWith.startsWith("/b/propE")))); Assert.assertThat(swagger.getPaths().keySet(), Every.everyItem(not(StringStartsWith.startsWith("/a")))); Assert.assertThat(swagger.getPaths().keySet(), hasItem(StringStartsWith.startsWith("/b"))); }
Example 19
Source Project: mapbox-java Source File: MapboxDirectionsTest.java License: MIT License | 5 votes |
@Test public void build_invalidAccessTokenExceptionThrown() throws ServicesException { thrown.expect(ServicesException.class); thrown.expectMessage(StringStartsWith.startsWith("Using Mapbox Services requires setting a valid access token")); MapboxDirections.builder() .accessToken("") .origin(Point.fromLngLat(1.0, 1.0)) .destination(Point.fromLngLat(2.0, 2.0)) .build(); }
Example 20
Source Project: mapbox-java Source File: MapboxTilequeryTest.java License: MIT License | 5 votes |
@Test public void build_invalidAccessTokenExceptionThrown() throws ServicesException { thrown.expect(ServicesException.class); thrown.expectMessage(StringStartsWith.startsWith("Using Mapbox Services requires setting a valid access token")); MapboxTilequery.builder() .accessToken("") .query("-122.42901,37.80633") .tilesetIds("mapbox.mapbox-streets-v7") .baseUrl(mockUrl.toString()) .build(); }
Example 21
Source Project: mapbox-java Source File: MapboxTilequeryTest.java License: MIT License | 5 votes |
@Test public void build_invalidQueryExceptionThrown() throws ServicesException { thrown.expect(ServicesException.class); thrown.expectMessage(StringStartsWith.startsWith("A query with latitude and longitude values is required")); MapboxTilequery.builder() .accessToken(ACCESS_TOKEN) .query("") .tilesetIds("mapbox.mapbox-streets-v7") .baseUrl(mockUrl.toString()) .build(); }
Example 22
Source Project: mapbox-java Source File: MapboxIsochroneTest.java License: MIT License | 5 votes |
@Test public void build_invalidAccessTokenExceptionThrown() throws ServicesException { thrown.expect(ServicesException.class); thrown.expectMessage(StringStartsWith.startsWith("Using the Mapbox Isochrone API requires setting a valid access token.")); MapboxIsochrone.builder() .accessToken("") .addContoursMinutes(5,30,55) .coordinates(testPoint) .profile(testProfile) .baseUrl(mockUrl.toString()) .build(); }
Example 23
Source Project: mapbox-java Source File: MapboxIsochroneTest.java License: MIT License | 5 votes |
@Test public void build_contoursAndColorsAmountMismatchExceptionThrown() throws ServicesException { thrown.expect(ServicesException.class); thrown.expectMessage(StringStartsWith.startsWith("Number of color elements must match number of minute elements provided.")); MapboxIsochrone.builder() .accessToken(ACCESS_TOKEN) .addContoursMinutes(5,30,55) .addContoursColors("6706ce") .coordinates(testPoint) .profile(testProfile) .baseUrl(mockUrl.toString()) .build(); }
Example 24
Source Project: TomboloDigitalConnector Source File: RowCellExtractorTest.java License: MIT License | 5 votes |
@Test public void extractSillyValue() throws Exception { RowCellExtractor extractor = new RowCellExtractor(3, CellType.NUMERIC); extractor.setRow(workbook.getSheet("sheet").getRow(0)); thrown.expect(BlankCellException.class); thrown.expectMessage(new StringStartsWith("Could not extract value")); extractor.extract(); extractor.setRow(workbook.getSheet("sheet").getRow(1)); assertEquals("7.0", extractor.extract()); }
Example 25
Source Project: TomboloDigitalConnector Source File: RowCellExtractorTest.java License: MIT License | 5 votes |
@Test public void extractUnhandledCellType() throws Exception { RowCellExtractor extractor = new RowCellExtractor(4, CellType.FORMULA); extractor.setRow(workbook.getSheet("sheet").getRow(0)); thrown.expect(ExtractorException.class); thrown.expectMessage(new StringStartsWith("Unhandled cell type")); extractor.extract(); }
Example 26
Source Project: TomboloDigitalConnector Source File: RowCellExtractorTest.java License: MIT License | 5 votes |
@Test public void extractNonExistingColumn() throws Exception { RowCellExtractor extractor = new RowCellExtractor(4, CellType.FORMULA); extractor.setRow(workbook.getSheet("sheet").getRow(1)); thrown.expect(ExtractorException.class); thrown.expectMessage(new StringStartsWith("Column with index 4 does not exit")); extractor.extract(); }
Example 27
Source Project: takes Source File: RqFromTest.java License: MIT License | 5 votes |
@Test public void defaultMethodForAFakeResquestIsGet() throws IOException { MatcherAssert.assertThat( "Can't add a method to a servlet request", new RqPrint( new RqFrom( new HttpServletRequestFake( new RqFake() ) ) ).printHead(), new StringStartsWith(RqFromTest.GET_METHOD) ); }
Example 28
Source Project: takes Source File: RqFromTest.java License: MIT License | 5 votes |
@Test public void containsMethodAndHeader() throws IOException { final String method = "GET /a-test"; final String header = "foo: bar"; MatcherAssert.assertThat( "Can't add a header to a servlet request", new RqPrint( new RqFrom( new HttpServletRequestFake( new RqFake( new ListOf<>( method, header ), "" ) ) ) ).printHead(), new StringStartsWith( new Joined( RqFromTest.EOL, method, "Host: localhost", header, RqFromTest.LOCAL_ADDRESS, RqFromTest.REMOTE_ADDRESS ).asString() ) ); }
Example 29
Source Project: takes Source File: RqFromTest.java License: MIT License | 5 votes |
@Test public void containsHostHeaderInHeader() throws IOException { final String method = "GET /one-more-test"; final String header = "Host: www.thesite.com"; MatcherAssert.assertThat( "Can't set a host in a servlet request", new RqPrint( new RqFrom( new HttpServletRequestFake( new RqFake( new ListOf<>( method, header ), "" ) ) ) ).printHead(), new StringStartsWith( new Joined( RqFromTest.EOL, method, header, RqFromTest.LOCAL_ADDRESS, RqFromTest.REMOTE_ADDRESS ).asString() ) ); }
Example 30
Source Project: takes Source File: RqFromTest.java License: MIT License | 5 votes |
@Test public void containsHostAndPortInHeader() throws IOException { final String method = "GET /b-test"; final String header = "Host: 192.168.0.1:12345"; MatcherAssert.assertThat( "Can't set a host and port in a servlet request", new RqPrint( new RqFrom( new HttpServletRequestFake( new RqFake( new ListOf<>( method, header ), "" ) ) ) ).printHead(), new StringStartsWith( new Joined( RqFromTest.EOL, method, header, RqFromTest.LOCAL_ADDRESS, RqFromTest.REMOTE_ADDRESS ).asString() ) ); }