org.hamcrest.core.StringStartsWith Java Examples
The following examples show how to use
org.hamcrest.core.StringStartsWith.
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: DataStreamTest.java From Flink-CEPplus with 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 #2
Source File: DataStreamTest.java From Flink-CEPplus with 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 #3
Source File: DataStreamTest.java From flink with 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 File: DataStreamTest.java From flink with 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 File: DataStreamTest.java From flink with 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 File: JsonPathResultMatchers.java From java-technology-stack with 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 File: DataStreamTest.java From flink with 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 File: JsonPathResultMatchers.java From spring-analysis-note with 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 #9
Source File: DataStreamTest.java From flink with Apache License 2.0 | 5 votes |
private <K> void assertArrayKeyRejection(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 File: MapboxIsochroneTest.java From mapbox-java with 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 #11
Source File: RowCellExtractorTest.java From TomboloDigitalConnector with 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 #12
Source File: RowCellExtractorTest.java From TomboloDigitalConnector with 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 #13
Source File: RowCellExtractorTest.java From TomboloDigitalConnector with 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 #14
Source File: RqFromTest.java From takes with 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 #15
Source File: RqFromTest.java From takes with 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 #16
Source File: RqFromTest.java From takes with 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 #17
Source File: RqFromTest.java From takes with 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() ) ); }
Example #18
Source File: MapboxTilequeryTest.java From mapbox-java with 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 #19
Source File: DataStreamTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testEnumKeyRejection() { KeySelector<Tuple2<TestEnum, String>, TestEnum> keySelector = value -> value.f0; StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); DataStream<Tuple2<TestEnum, String>> input = env.fromElements( Tuple2.of(TestEnum.FOO, "Foo"), Tuple2.of(TestEnum.BAR, "Bar")); expectedException.expect(InvalidProgramException.class); expectedException.expectMessage(new StringStartsWith("Type " + EnumTypeInfo.of(TestEnum.class) + " cannot be used as key.")); input.keyBy(keySelector); }
Example #20
Source File: TestLockProcedure.java From hbase with Apache License 2.0 | 5 votes |
private void validateLockRequestException(LockRequest lockRequest, String message) throws Exception { exception.expect(ServiceException.class); exception.expectCause(IsInstanceOf.instanceOf(DoNotRetryIOException.class)); exception.expectMessage( StringStartsWith.startsWith("org.apache.hadoop.hbase.DoNotRetryIOException: " + "java.lang.IllegalArgumentException: " + message)); masterRpcService.requestLock(null, lockRequest); }
Example #21
Source File: MapOfTest.java From cactoos with 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 #22
Source File: DataStreamTest.java From Flink-CEPplus with 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 #23
Source File: DataStreamTest.java From flink with 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 #24
Source File: RtLogsITCase.java From docker-java-api with 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 #25
Source File: RtLogsITCase.java From docker-java-api with 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 #26
Source File: HeartbeatActionTest.java From emissary with 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 #27
Source File: RestfulServerTest.java From shardingsphere-elasticjob-cloud with 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 #28
Source File: TaskContextTest.java From shardingsphere-elasticjob-cloud with 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 #29
Source File: MapboxIsochroneTest.java From mapbox-java with 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 #30
Source File: PathPrunnerTest.java From yang2swagger with 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")))); }