org.junit.internal.matchers.ThrowableMessageMatcher Java Examples

The following examples show how to use org.junit.internal.matchers.ThrowableMessageMatcher. 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: TableChangeParserTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Test
public void noMetadataContentAllowedAfterFirstLine1() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("Instead, found this section in between")));

    TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), getChangeType);
    String fileContent = "\n" +
            "//// METADATA\n" +
            "//// CHANGE name=chng1\n" +
            "CREATE TABLE;\n" +
            "//// METADATA\n" +
            "//// CHANGE name=chng1\n" +
            "CREATE TABLE;\n" +
            "";

    parser.value(tableChangeType, null, fileContent, objectName, "schema", null);
}
 
Example #2
Source File: DirectRunnerTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void transformDisplayDataExceptionShouldFail() {
  DoFn<Integer, Integer> brokenDoFn =
      new DoFn<Integer, Integer>() {
        @ProcessElement
        public void processElement(ProcessContext c) throws Exception {}

        @Override
        public void populateDisplayData(DisplayData.Builder builder) {
          throw new RuntimeException("oh noes!");
        }
      };

  Pipeline p = getPipeline();
  p.apply(Create.of(1, 2, 3)).apply(ParDo.of(brokenDoFn));

  thrown.expectMessage(brokenDoFn.getClass().getName());
  thrown.expectCause(ThrowableMessageMatcher.hasMessage(is("oh noes!")));
  p.run();
}
 
Example #3
Source File: TableChangeParserTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Test
public void noMetadataContentAllowedAfterFirstLine3() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("Instead, found this section in between")));

    TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), getChangeType);
    String fileContent = "\n" +
            "//// METADATA\n" +
            "//// METADATA\n" +
            "//// CHANGE name=chng1\n" +
            "CREATE TABLE;\n" +
            "//// METADATA\n" +
            "";

    parser.value(tableChangeType, null, fileContent, objectName, "schema", null);
}
 
Example #4
Source File: DataflowViewTest.java    From beam with Apache License 2.0 6 votes vote down vote up
private void testViewUnbounded(
    Pipeline pipeline,
    PTransform<PCollection<KV<String, Integer>>, ? extends PCollectionView<?>> view) {
  thrown.expect(IllegalStateException.class);
  thrown.expectMessage("Unable to create a side-input view from input");
  thrown.expectCause(
      ThrowableMessageMatcher.hasMessage(Matchers.containsString("non-bounded PCollection")));
  pipeline
      .apply(
          new PTransform<PBegin, PCollection<KV<String, Integer>>>() {
            @Override
            public PCollection<KV<String, Integer>> expand(PBegin input) {
              return PCollection.createPrimitiveOutputInternal(
                  input.getPipeline(),
                  WindowingStrategy.globalDefault(),
                  PCollection.IsBounded.UNBOUNDED,
                  KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of()));
            }
          })
      .apply(view);
}
 
Example #5
Source File: ViewTest.java    From beam with Apache License 2.0 6 votes vote down vote up
private void testViewUnbounded(
    Pipeline pipeline,
    PTransform<PCollection<KV<String, Integer>>, ? extends PCollectionView<?>> view) {
  thrown.expect(IllegalStateException.class);
  thrown.expectMessage("Unable to create a side-input view from input");
  thrown.expectCause(
      ThrowableMessageMatcher.hasMessage(Matchers.containsString("non-bounded PCollection")));
  pipeline
      .apply(
          new PTransform<PBegin, PCollection<KV<String, Integer>>>() {
            @Override
            public PCollection<KV<String, Integer>> expand(PBegin input) {
              return PCollection.createPrimitiveOutputInternal(
                  input.getPipeline(),
                  WindowingStrategy.globalDefault(),
                  PCollection.IsBounded.UNBOUNDED,
                  KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of()));
            }
          })
      .apply(view);
}
 
Example #6
Source File: RerunnableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void noMultipleMetadataSections1() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("found these extra sections instances: [METADATA")));

    RerunnableChangeParser parser = new RerunnableChangeParser();
    String fileContent = "\n" +
            "//// METADATA\n" +
            "//// DROP\n" +
            "//// METADATA\n" +
            "";

    parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null);
}
 
Example #7
Source File: MultipleJGitEnvironmentRepositoryIntegrationTests.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Test
public void nonWritableBasedir() throws IOException {
	String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
	this.expected.expectCause(ThrowableMessageMatcher
			.hasMessage(containsString("Cannot write parent")));
	this.context = new SpringApplicationBuilder(TestConfiguration.class)
			.web(WebApplicationType.NONE)
			.properties("spring.cloud.config.server.git.uri:" + defaultRepoUri,
					"spring.cloud.config.server.git.basedir:/tmp")
			.run();
}
 
Example #8
Source File: BulkOutputCallerTest.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
@Test
public void bulkOutputCallerWithNullConsumer() {
    OutputEndpoint loadEndpt = OutputEndpoint.on(IOTestUtil.db, new JacksonHandle(apiObj));
    OutputEndpoint.BulkOutputCaller loader = loadEndpt.bulkCaller();

    expectedException.expect(IllegalStateException.class);
    expectedException.expect(new ThrowableMessageMatcher(new StringContains("Output consumer is null")));
    loader.awaitCompletion();
}
 
Example #9
Source File: BulkInputCallerTest.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
@Test
public void bulkInputEndpointInterruptTest() throws Exception {
    String apiName = "bulkInputCallerImpl.api";

    String endpointState = "{\"next\":"+startValue+"}";
    String workUnit      = "{\"max\":"+workMax+"}";
    ObjectNode apiObj     = IOTestUtil.readApi(apiName);
    String     scriptPath = IOTestUtil.getScriptPath(apiObj);
    String     apiPath    = IOTestUtil.getApiPath(scriptPath);
    IOTestUtil.load(apiName, apiObj, scriptPath, apiPath);
    InputEndpoint loadEndpt = InputEndpoint.on(IOTestUtil.db, new JacksonHandle(apiObj));

    InputEndpoint.BulkInputCaller loader = loadEndpt.bulkCaller();
    loader.setEndpointState(new ByteArrayInputStream(endpointState.getBytes()));
    loader.setWorkUnit(new ByteArrayInputStream(workUnit.getBytes()));

    Stream<InputStream> input         = Stream.of(
            IOTestUtil.asInputStream("{\"docNum\":1, \"docName\":\"doc1\"}"),
            IOTestUtil.asInputStream("{\"docNum\":2, \"docName\":\"doc2\"}"),
            IOTestUtil.asInputStream("{\"docNum\":3, \"docName\":\"doc3\"}")
    );

    Stream<InputStream> input2         = Stream.of(
            IOTestUtil.asInputStream("{\"docNum\":4, \"docName\":\"doc4\"}"),
            IOTestUtil.asInputStream("{\"docNum\":5, \"docName\":\"doc5\"}"),
            IOTestUtil.asInputStream("{\"docNum\":6, \"docName\":\"doc6\"}"));

    input.forEach(loader::accept);
    loader.interrupt();

    expectedException.expect(IllegalStateException.class);
    expectedException.expect(new ThrowableMessageMatcher(new StringContains("cannot accept more input as current phase is  INTERRUPTING")));
    input2.forEach(loader::accept);
}
 
Example #10
Source File: DataflowViewTest.java    From beam with Apache License 2.0 5 votes vote down vote up
private void testViewNonmerging(
    Pipeline pipeline,
    PTransform<PCollection<KV<String, Integer>>, ? extends PCollectionView<?>> view) {
  thrown.expect(IllegalStateException.class);
  thrown.expectMessage("Unable to create a side-input view from input");
  thrown.expectCause(
      ThrowableMessageMatcher.hasMessage(Matchers.containsString("Consumed by GroupByKey")));
  pipeline
      .apply(Create.of(KV.of("hello", 5)))
      .apply(
          Window.into(
              new InvalidWindows<>(
                  "Consumed by GroupByKey", FixedWindows.of(Duration.standardHours(1)))))
      .apply(view);
}
 
Example #11
Source File: ViewTest.java    From beam with Apache License 2.0 5 votes vote down vote up
private void testViewNonmerging(
    Pipeline pipeline,
    PTransform<PCollection<KV<String, Integer>>, ? extends PCollectionView<?>> view) {
  thrown.expect(IllegalStateException.class);
  thrown.expectMessage("Unable to create a side-input view from input");
  thrown.expectCause(
      ThrowableMessageMatcher.hasMessage(Matchers.containsString("Consumed by GroupByKey")));
  pipeline
      .apply(Create.of(KV.of("hello", 5)))
      .apply(
          Window.into(
              new InvalidWindows<>(
                  "Consumed by GroupByKey", FixedWindows.of(Duration.standardHours(1)))))
      .apply(view);
}
 
Example #12
Source File: ViewTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
@Category(NeedsRunner.class)
public void testMapSideInputWithNullValuesCatchesDuplicates() {

  final PCollectionView<Map<String, Integer>> view =
      pipeline
          .apply(
              "CreateSideInput",
              Create.of(KV.of("a", (Integer) null), KV.of("a", (Integer) null))
                  .withCoder(
                      KvCoder.of(StringUtf8Coder.of(), NullableCoder.of(VarIntCoder.of()))))
          .apply(View.asMap());

  PCollection<KV<String, Integer>> output =
      pipeline
          .apply("CreateMainInput", Create.of("apple", "banana", "blackberry"))
          .apply(
              "OutputSideInputs",
              ParDo.of(
                      new DoFn<String, KV<String, Integer>>() {
                        @ProcessElement
                        public void processElement(ProcessContext c) {
                          c.output(
                              KV.of(
                                  c.element(),
                                  c.sideInput(view)
                                      .getOrDefault(c.element().substring(0, 1), 0)));
                        }
                      })
                  .withSideInputs(view));

  PAssert.that(output)
      .containsInAnyOrder(KV.of("apple", 1), KV.of("banana", 3), KV.of("blackberry", 3));

  // PipelineExecutionException is thrown with cause having a message stating that a
  // duplicate is not allowed.
  thrown.expectCause(
      ThrowableMessageMatcher.hasMessage(Matchers.containsString("Duplicate values for a")));
  pipeline.run();
}
 
Example #13
Source File: RerunnableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void noMultipleDropSections() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("found these extra sections instances: [DROP_COMMAND")));

    RerunnableChangeParser parser = new RerunnableChangeParser();
    String fileContent = "\n" +
            "//// METADATA\n" +
            "//// DROP_COMMAND\n" +
            "//// DROP_COMMAND\n" +
            "";

    parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null);
}
 
Example #14
Source File: RerunnableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void noMultipleMetadataSections2() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("found these extra sections instances: [METADATA")));

    RerunnableChangeParser parser = new RerunnableChangeParser();
    String fileContent = "\n" +
            "//// METADATA\n" +
            "//// METADATA\n" +
            "";

    parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null);
}
 
Example #15
Source File: TableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void invalidNoContentAllowedInMetadata() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("First content of the file must be the")));

    TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), getChangeType);
    String fileContent = "contentNotAllowedHere\n" +
            "//// METADATA\n" +
            "invalid content\n" +
            "//// CHANGE name=chng1\n" +
            "CREATE TABLE;\n" +
            "";

    parser.value(tableChangeType, null, fileContent, objectName, "schema", null);
}
 
Example #16
Source File: RerunnableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void noChangeSectionAllowed2() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("found these disallowed sections")));

    RerunnableChangeParser parser = new RerunnableChangeParser();
    String fileContent = "\n" +
            "//// CHANGE name=abc";

    parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null);
}
 
Example #17
Source File: RerunnableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void noChangeSectionAllowed1() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("found these disallowed sections")));

    RerunnableChangeParser parser = new RerunnableChangeParser();
    String fileContent = "\n" +
            "//// METADATA\n" +
            "//// CHANGE name=abc";

    parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null);
}
 
Example #18
Source File: RerunnableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void noContentInPrologue() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("Improper section ordering: METADATA section must come before the content section")));

    RerunnableChangeParser parser = new RerunnableChangeParser();
    String fileContent = "\n" +
            "prologueContentBeforeSections" +
            "//// METADATA\n" +
            "";

    parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null);
}
 
Example #19
Source File: TableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void noContentAtAll2() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("No //// " + TextMarkupDocumentReader.TAG_CHANGE + " sections found; at least one is required")));

    TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), getChangeType);
    String fileContent = "\n" +
            "//// METADATA\n" +
            "";

    parser.value(tableChangeType, null, fileContent, objectName, "schema", null);
}
 
Example #20
Source File: TableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void noContentAtAll1() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("No //// " + TextMarkupDocumentReader.TAG_CHANGE + " sections found; at least one is required")));

    TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), getChangeType);
    String fileContent = "";

    parser.value(tableChangeType, null, fileContent, objectName, "schema", null);
}
 
Example #21
Source File: TableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void noMetadataContentAllowedAfterFirstLine2() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("Instead, found this section in between")));

    TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), getChangeType);
    String fileContent = "\n" +
            "//// CHANGE name=chng1\n" +
            "CREATE TABLE;\n" +
            "//// METADATA\n" +
            "";

    parser.value(tableChangeType, null, fileContent, objectName, "schema", null);
}
 
Example #22
Source File: TableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void invalidNoContentAllowedInPrologue3() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("No //// CHANGE sections found")));

    TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), getChangeType);
    String fileContent = "contentNotAllowedHere\n" +
            "CREATE TABLE;\n" +
            "";

    parser.value(tableChangeType, null, fileContent, objectName, "schema", null);
}
 
Example #23
Source File: TableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void invalidNoContentAllowedInPrologue2() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("First content of the file must be the")));

    TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), getChangeType);
    String fileContent = "contentNotAllowedHere\n" +
            "//// CHANGE name=chng1\n" +
            "CREATE TABLE;\n" +
            "";

    parser.value(tableChangeType, null, fileContent, objectName, "schema", null);
}
 
Example #24
Source File: TableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void invalidNoContentAllowedInPrologue1() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expect(new ThrowableMessageMatcher<Throwable>(containsString("First content of the file must be the")));

    TableChangeParser parser = new TableChangeParser(new EmptyContentHashStrategy(), getChangeType);
    String fileContent = "contentNotAllowedHere\n" +
            "//// METADATA\n" +
            "//// CHANGE name=chng1\n" +
            "CREATE TABLE;\n" +
            "";

    parser.value(tableChangeType, null, fileContent, objectName, "schema", null);
}