Java 类org.junit.matchers.JUnitMatchers 实例源码

项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseInvalidRootElement() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation2 type=\"submit\">\n")
        .append("</operation2>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
        // correct behavior
        Assert.assertEquals(SxmpErrorCode.INVALID_XML, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("Root element must be an [operation]"));
        Assert.assertNull(e.getOperation());
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseUnsupportedOperationType() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"submit2\">\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
        // correct behavior
        Assert.assertEquals(SxmpErrorCode.UNSUPPORTED_OPERATION, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("Unsupported operation type"));
        Assert.assertNull(e.getOperation());
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseUnsupportedChildElement() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"submit\">\n")
        .append("  <test></test>\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
        // correct behavior
        Assert.assertEquals(SxmpErrorCode.UNSUPPORTED_ELEMENT, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("Unsupported [test] element"));
        // this should also contain an operation since the root element was parsed
        Assert.assertNotNull(e.getOperation());
        PartialOperation partial = (PartialOperation)e.getOperation();
        Assert.assertEquals(Operation.Type.SUBMIT, partial.getType());
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseTwoAccounts() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"submit\">\n")
        .append(" <account username=\"customer1\" password=\"test1\"/>\n")
        .append(" <account username=\"customer2\" password=\"test2\"/>\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
        // correct behavior
        Assert.assertEquals(SxmpErrorCode.MULTIPLE_ELEMENTS_NOT_SUPPORTED, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("Multiple [account] elements are not supported"));
        // this should also contain an operation since the root element was parsed
        Assert.assertNotNull(e.getOperation());
        PartialOperation partial = (PartialOperation)e.getOperation();
        Assert.assertEquals(Operation.Type.SUBMIT, partial.getType());
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseAccountOnly() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"submit\">\n")
        .append(" <account username=\"customer1\" password=\"test1\"/>\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
        // correct behavior
        Assert.assertEquals(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("The operation type [submit] requires a request element"));
        Assert.assertNotNull(e.getOperation());
        PartialOperation partial = (PartialOperation)e.getOperation();
        Assert.assertEquals(Operation.Type.SUBMIT, partial.getType());
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseAccountWithMissingUsernameAttribute() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"submit\">\n")
        .append(" <account password=\"test1\"/>\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
        // correct behavior
        Assert.assertEquals(SxmpErrorCode.MISSING_REQUIRED_ATTRIBUTE, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("The attribute [username] is required with the [account] element"));
        Assert.assertNotNull(e.getOperation());
        PartialOperation partial = (PartialOperation)e.getOperation();
        Assert.assertEquals(Operation.Type.SUBMIT, partial.getType());
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseAccountWithMissingPasswordAttribute() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"submit\">\n")
        .append(" <account username=\"test1\"/>\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
        // correct behavior
        Assert.assertEquals(SxmpErrorCode.MISSING_REQUIRED_ATTRIBUTE, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("The attribute [password] is required with the [account] element"));
        Assert.assertNotNull(e.getOperation());
        PartialOperation partial = (PartialOperation)e.getOperation();
        Assert.assertEquals(Operation.Type.SUBMIT, partial.getType());
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseAccountWithEmptyUsernameAttribute() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"submit\">\n")
        .append(" <account username=\"\" password=\"test1\"/>\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
        // correct behavior
        Assert.assertEquals(SxmpErrorCode.EMPTY_VALUE, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("The [username] attribute was empty in the [account] element"));
        Assert.assertNotNull(e.getOperation());
        PartialOperation partial = (PartialOperation)e.getOperation();
        Assert.assertEquals(Operation.Type.SUBMIT, partial.getType());
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseOperationOnly() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"submit\">\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
        // correct behavior
        Assert.assertEquals(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("The operation type [submit] requires a request element"));
        Assert.assertNotNull(e.getOperation());
        PartialOperation partial = (PartialOperation)e.getOperation();
        Assert.assertEquals(Operation.Type.SUBMIT, partial.getType());
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseStartEndTagMismatch() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"deliver\">\n")
        .append(" <account username=\"customer1\" password=\"test1\"/>\n")
        .append(" <deliverRequest referenceId=\"MYREF102020022\">\n")
        .append("  <operatorId>10</operatorId>\n")
        .append("  <sourceAddress type=\"network\">40404</sourceAddress>\n")
        .append("  <destinationAddress type=\"international\">+12065551212</destinationAddress>\n")
        .append("  <text encoding=\"ISO-8859-1\">48656c6c6f20576f726c64</text>\n")
        .append(" </submitRequest>\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SAXParseException e) {
        // correct behavior
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("must be terminated by the matching end-tag"));
    }
}
项目:beyondj    文件:SxmpSessionTest.java   
@Test
public void processThrowsSxmpParsingExceptionWithNoOperationType() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation2 type=\"submit\">\n")
        .append("</operation2>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());

    MockSxmpRequestProcessor processor = new MockSxmpRequestProcessor();
    SxmpSession session = new SxmpSession(processor, SxmpParser.VERSION_1_0);

    Response response = null;
    try {
        response = session.process(is);
        Assert.fail();
    } catch (SAXException e) {
        // correct behavior
        //Assert.assertEquals(SxmpErrorCode.INVALID_XML, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("Root element must be an [operation]"));
        //Assert.assertNull(e.getOperation());
    }
}
项目:envelope    文件:TestMorphlineUtils.java   
@Test
public void convertToRowInvalidNullValue(
    final @Mocked RowUtils utils
) throws Exception {

  Record record = new Record();
  record.put("field1", null);

  StructType schema = DataTypes.createStructType(Lists.newArrayList(
      DataTypes.createStructField("field1", DataTypes.StringType, false))
  );

  try {
    MorphlineUtils.convertToRow(schema, record);
    fail("Did not throw a RuntimeException");
  } catch (Exception e) {
    assertThat(e.getMessage(), JUnitMatchers.containsString("DataType cannot contain 'null'"));
  }

  new Verifications() {{
    RowUtils.toRowValue(any, (DataType) any); times = 0;
  }};
}
项目:envelope    文件:TestMorphlineUtils.java   
@Test
public void convertToRowInvalidTypeNotNullable(
    final @Mocked RowUtils utils
) throws Exception {

  Record record = new Record();
  record.put("field1", "one");

  StructType schema = DataTypes.createStructType(Lists.newArrayList(
      DataTypes.createStructField("field1", DataTypes.StringType, false))
  );

  new Expectations() {{
    RowUtils.toRowValue("one", DataTypes.StringType); result = new RuntimeException("Conversion exception");
  }};

  try {
    MorphlineUtils.convertToRow(schema, record);
    fail("Did not throw a RuntimeException");
  } catch (Exception e) {
    assertThat(e.getMessage(), JUnitMatchers.containsString("Error converting Field"));
  }
}
项目:envelope    文件:TestMorphlineUtils.java   
@Test
public void convertToRowInvalidTypeNullable(
    final @Mocked RowUtils utils
) throws Exception {

  Record record = new Record();
  record.put("field1", "one");

  StructType schema = DataTypes.createStructType(Lists.newArrayList(
      DataTypes.createStructField("field1", DataTypes.StringType, true))
  );

  new Expectations() {{
    RowUtils.toRowValue("one", DataTypes.StringType); result = new RuntimeException("Conversion exception");
  }};

  try {
    MorphlineUtils.convertToRow(schema, record);
    fail("Did not throw a RuntimeException");
  } catch (Exception e) {
    assertThat(e.getMessage(), JUnitMatchers.containsString("Error converting Field"));
  }
}
项目:envelope    文件:TestMorphlineUtils.java   
@Test
public void convertToRowMissingColumnNotNullable(
    final @Mocked RowUtils utils
) throws Exception {

  Record record = new Record();
  record.put("foo", "one");

  StructType schema = DataTypes.createStructType(Lists.newArrayList(
      DataTypes.createStructField("field1", DataTypes.StringType, false))
  );

  try {
    MorphlineUtils.convertToRow(schema, record);
    fail("Did not throw a RuntimeException");
  } catch (Exception e) {
    assertThat(e.getMessage(), JUnitMatchers.containsString("Error converting Record"));
  }

  new Verifications() {{
    RowUtils.toRowValue(any, (DataType) any); times = 0;
  }};
}
项目:envelope    文件:TestMorphlineUtils.java   
@Test
public void convertToRowMissingColumnNullable(
    final @Mocked RowUtils utils
) throws Exception {

  Record record = new Record();
  record.put("foo", "one");

  StructType schema = DataTypes.createStructType(Lists.newArrayList(
      DataTypes.createStructField("field1", DataTypes.StringType, true))
  );

  try {
    MorphlineUtils.convertToRow(schema, record);
    fail("Did not throw a RuntimeException");
  } catch (Exception e) {
    assertThat(e.getMessage(), JUnitMatchers.containsString("Error converting Record"));
  }

  new Verifications() {{
    RowUtils.toRowValue(any, (DataType) any); times = 0;
  }};
}
项目:envelope    文件:TestRowUtils.java   
@Test
public void testToRowValueBoolean() {
  DataType field = DataTypes.BooleanType;

  assertEquals("Invalid Boolean", true, RowUtils.toRowValue(true, field));
  assertEquals("Invalid 'true'", true, RowUtils.toRowValue("true", field));
  assertEquals("Invalid 'true'", true, RowUtils.toRowValue("TrUe", field));
  assertEquals("Invalid 'false'", false, RowUtils.toRowValue("false", field));
  assertEquals("Invalid 'false'", false, RowUtils.toRowValue("FaLsE", field));

  try {
    RowUtils.toRowValue(123, field);
    fail("Expected a RuntimeException for invalid type");
  } catch (RuntimeException e) {
    assertThat(e.getMessage(), JUnitMatchers.containsString("Invalid or unrecognized input format"));
  }
}
项目:envelope    文件:TestRowUtils.java   
@Test
public void testToRowValueDate() {
  DataType field = DataTypes.DateType;

  DateTime dateObj = DateTime.parse("2017-01-01T00:00:00"); // Pass-thru the TZ
  Date sqlDate = new Date(dateObj.getMillis());

  assertEquals("Invalid Long", sqlDate, RowUtils.toRowValue(dateObj.getMillis(), field));
  assertEquals("Invalid String", sqlDate, RowUtils.toRowValue("2017-001", field)); // ISO Date format
  assertEquals("Invalid Date", sqlDate, RowUtils.toRowValue(dateObj.toDate(), field));
  assertEquals("Invalid DateTime", sqlDate, RowUtils.toRowValue(dateObj, field));

  thrown.expect(RuntimeException.class);
  thrown.expectMessage(JUnitMatchers.containsString("Invalid or unrecognized input format"));
  RowUtils.toRowValue(123, field);
}
项目:envelope    文件:TestRowUtils.java   
@Test
public void testToRowValueTimestamp() {
  DataType field = DataTypes.TimestampType;

  DateTime dateObj = DateTime.parse("2017-01-01T00:00:00"); // Pass-thru the TZ
  Timestamp sqlTimestamp = new Timestamp(dateObj.getMillis());

  assertEquals("Invalid Long", sqlTimestamp, RowUtils.toRowValue(dateObj.getMillis(), field));
  assertEquals("Invalid String", sqlTimestamp, RowUtils.toRowValue("2017-001", field)); // ISO Date format
  assertEquals("Invalid Date", sqlTimestamp, RowUtils.toRowValue(dateObj.toDate(), field));
  assertEquals("Invalid DateTime", sqlTimestamp, RowUtils.toRowValue(dateObj, field));

  thrown.expect(RuntimeException.class);
  thrown.expectMessage(JUnitMatchers.containsString("Invalid or unrecognized input format"));
  RowUtils.toRowValue(123, field);
}
项目:cassandra-kmean    文件:BatchlogEndpointFilterTest.java   
@Test
public void shouldSelect2hostsFromNonLocalRacks() throws UnknownHostException
{
    Multimap<String, InetAddress> endpoints = ImmutableMultimap.<String, InetAddress> builder()
            .put(LOCAL, InetAddress.getByName("0"))
            .put(LOCAL, InetAddress.getByName("00"))
            .put("1", InetAddress.getByName("1"))
            .put("1", InetAddress.getByName("11"))
            .put("2", InetAddress.getByName("2"))
            .put("2", InetAddress.getByName("22"))
            .build();
    Collection<InetAddress> result = new TestEndpointFilter(LOCAL, endpoints).filter();
    assertThat(result.size(), is(2));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("11")));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("22")));
}
项目:datacollector    文件:TestDriftRuleEL.java   
@Test
@SuppressWarnings("deprecation")
public void testDriftNamesIncompatibleTypes() throws Exception {
  ELVars vars = new ELVariables();

  Record record = new RecordImpl("creator", "id", null, null);
  record.set(Field.create(1));

  RecordEL.setRecordInContext(vars, record);

  vars.addContextVariable(DataRuleEvaluator.PIPELINE_CONTEXT, new HashMap<>());
  vars.addContextVariable(DataRuleEvaluator.RULE_ID_CONTEXT, "ID");

  ELEval elEval = new ELEvaluator("", DriftRuleEL.class, AlertInfoEL.class);

  Assert.assertFalse(elEval.eval(vars, "${drift:names('/', true)}", Boolean.TYPE));
  Assert.assertThat(elEval.eval(vars, "${alert:info()}", String.class), JUnitMatchers.containsString("Field / have unsupported type of INTEGER."));
}
项目:datacollector    文件:TestDriftRuleEL.java   
@Test
@SuppressWarnings("deprecation")
public void testDriftOrderIncompatibleTypes() throws Exception {
  ELVars vars = new ELVariables();

  Record record = new RecordImpl("creator", "id", null, null);
  record.set(Field.create(1));

  RecordEL.setRecordInContext(vars, record);

  vars.addContextVariable(DataRuleEvaluator.PIPELINE_CONTEXT, new HashMap<>());
  vars.addContextVariable(DataRuleEvaluator.RULE_ID_CONTEXT, "ID");

  ELEval elEval = new ELEvaluator("", DriftRuleEL.class, AlertInfoEL.class);

  Assert.assertFalse(elEval.eval(vars, "${drift:order('/', true)}", Boolean.TYPE));
  Assert.assertThat(elEval.eval(vars, "${alert:info()}", String.class), JUnitMatchers.containsString("Field / have unsupported type of INTEGER."));
}
项目:scylla-tools-java    文件:BatchlogEndpointFilterTest.java   
@Test
public void shouldSelect2hostsFromNonLocalRacks() throws UnknownHostException
{
    Multimap<String, InetAddress> endpoints = ImmutableMultimap.<String, InetAddress> builder()
            .put(LOCAL, InetAddress.getByName("0"))
            .put(LOCAL, InetAddress.getByName("00"))
            .put("1", InetAddress.getByName("1"))
            .put("1", InetAddress.getByName("11"))
            .put("2", InetAddress.getByName("2"))
            .put("2", InetAddress.getByName("22"))
            .build();
    Collection<InetAddress> result = new TestEndpointFilter(LOCAL, endpoints).filter();
    assertThat(result.size(), is(2));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("11")));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("22")));
}
项目:GraphTrek    文件:BatchlogEndpointFilterTest.java   
@Test
public void shouldSelect2hostsFromNonLocalRacks() throws UnknownHostException
{
    Multimap<String, InetAddress> endpoints = ImmutableMultimap.<String, InetAddress> builder()
            .put(LOCAL, InetAddress.getByName("0"))
            .put(LOCAL, InetAddress.getByName("00"))
            .put("1", InetAddress.getByName("1"))
            .put("1", InetAddress.getByName("11"))
            .put("2", InetAddress.getByName("2"))
            .put("2", InetAddress.getByName("22"))
            .build();
    Collection<InetAddress> result = new TestEndpointFilter(LOCAL, endpoints).filter();
    assertThat(result.size(), is(2));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("11")));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("22")));
}
项目:sqlite-jdbc    文件:ErrorMessageTest.java   
@Test
public void moved() throws SQLException, IOException {
    File from = File.createTempFile("error-message-test-moved-from", ".sqlite");
    from.deleteOnExit();

    Connection conn = DriverManager.getConnection("jdbc:sqlite:" + from.getAbsolutePath());
    Statement stmt = conn.createStatement();
    stmt.executeUpdate("create table sample(id, name)");
    stmt.executeUpdate("insert into sample values(1, \"foo\")");

    File to = File.createTempFile("error-message-test-moved-from", ".sqlite");
    assumeTrue(to.delete());
    assumeTrue(from.renameTo(to));

    thrown.expectMessage(JUnitMatchers.containsString("[SQLITE_READONLY_DBMOVED]"));
    stmt.executeUpdate("insert into sample values(2, \"bar\")");

    stmt.close();
    conn.close();
}
项目:sqlite-jdbc    文件:ErrorMessageTest.java   
@Test
public void writeProtected() throws SQLException, IOException {
    File file = File.createTempFile("error-message-test-write-protected", ".sqlite");
    file.deleteOnExit();

    Connection conn = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
    Statement stmt = conn.createStatement();
    stmt.executeUpdate("create table sample(id, name)");
    stmt.executeUpdate("insert into sample values(1, \"foo\")");
    stmt.close();
    conn.close();

    assumeTrue(file.setReadOnly());

    conn = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
    stmt = conn.createStatement();
    thrown.expectMessage(JUnitMatchers.containsString("[SQLITE_READONLY]"));
    stmt.executeUpdate("insert into sample values(2, \"bar\")");
    stmt.close();
    conn.close();
}
项目:sqlite-jdbc    文件:ErrorMessageTest.java   
@Test
public void shouldUsePlainErrorCodeAsVendorCodeAndExtendedAsResultCode() throws SQLException, IOException {
    File from = File.createTempFile("error-message-test-plain-1", ".sqlite");
    from.deleteOnExit();

    Connection conn = DriverManager.getConnection("jdbc:sqlite:" + from.getAbsolutePath());
    Statement stmt = conn.createStatement();
    stmt.executeUpdate("create table sample(id, name)");
    stmt.executeUpdate("insert into sample values(1, \"foo\")");

    File to = File.createTempFile("error-message-test-plain-2", ".sqlite");
    assumeTrue(to.delete());
    assumeTrue(from.renameTo(to));

    thrown.expectMessage(JUnitMatchers.containsString("[SQLITE_READONLY_DBMOVED]"));
    thrown.expect(new VendorCodeMatcher(SQLiteErrorCode.SQLITE_READONLY));
    thrown.expect(new ResultCodeMatcher(SQLiteErrorCode.SQLITE_READONLY_DBMOVED));
    stmt.executeUpdate("insert into sample values(2, \"bar\")");

    stmt.close();
    conn.close();
}
项目:stratio-cassandra    文件:BatchlogEndpointFilterTest.java   
@Test
public void shouldSelect2hostsFromNonLocalRacks() throws UnknownHostException
{
    Multimap<String, InetAddress> endpoints = ImmutableMultimap.<String, InetAddress> builder()
            .put(LOCAL, InetAddress.getByName("0"))
            .put(LOCAL, InetAddress.getByName("00"))
            .put("1", InetAddress.getByName("1"))
            .put("1", InetAddress.getByName("11"))
            .put("2", InetAddress.getByName("2"))
            .put("2", InetAddress.getByName("22"))
            .build();
    Collection<InetAddress> result = new TestEndpointFilter(LOCAL, endpoints).filter();
    assertThat(result.size(), is(2));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("11")));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("22")));
}
项目:pentaho-kettle    文件:PrivateDatabasesTestTemplate.java   
protected void doTest_OnePrivate_TwoShared() throws Exception {
  T meta = createMeta();
  DatabaseMeta privateMeta = createDatabase( "privateMeta" );
  meta.addDatabase( privateMeta );

  String xml = toXml( meta );

  DatabaseMeta meta1 = createDatabase( "meta1" );
  meta1.setShared( true );
  DatabaseMeta meta2 = createDatabase( "meta2" );
  meta2.setShared( true );

  SharedObjects fakeSharedObjects = createFakeSharedObjects( meta1, meta2 );

  T loaded = fromXml( xml, fakeSharedObjects );

  List<String> loadedDbs = Arrays.asList( loaded.getDatabaseNames() );
  assertEquals( 3, loadedDbs.size() );
  assertThat( loadedDbs, JUnitMatchers.hasItems( "meta1", "meta2", "privateMeta" ) );

  Set<String> privateDatabases = loaded.getPrivateDatabases();
  assertNotNull( privateDatabases );
  assertEquals( 1, privateDatabases.size() );
  assertTrue( privateDatabases.contains( "privateMeta" ) );
}
项目:pentaho-kettle    文件:MappingUnitTest.java   
@SuppressWarnings( "unchecked" )
@Test
public void pickupTargetStepsFor_OutputIsNotDefined() throws Exception {
  StepMeta singleMeta = new StepMeta( "single", null );
  StepMeta copiedMeta = new StepMeta( "copied", null );
  Mockito.when( mockHelper.transMeta.findNextSteps( mockHelper.stepMeta ) ).thenReturn( Arrays.asList( singleMeta, copiedMeta ) );

  StepInterface single = Mockito.mock( StepInterface.class );
  Mockito.when( mockHelper.trans.findStepInterfaces( "single" ) ).thenReturn( Collections.singletonList( single ) );

  StepInterface copy1 = Mockito.mock( StepInterface.class );
  StepInterface copy2 = Mockito.mock( StepInterface.class );
  Mockito.when( mockHelper.trans.findStepInterfaces( "copied" ) ).thenReturn( Arrays.asList( copy1, copy2 ) );

  MappingIODefinition definition = new MappingIODefinition( null, null );
  StepInterface[] targetSteps = mapping.pickupTargetStepsFor( definition );

  assertThat( Arrays.asList( targetSteps ), JUnitMatchers.hasItems( is( single ), is( copy1 ), is( copy2 ) ) );
}
项目:EatDubbo    文件:RouteRuleTest.java   
@org.junit.Test
public void testParse_EmptyThen() {
    String expr = "service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1&consumer.version != 1.0.0";
    try{
        RouteRule.parse(expr, "");
        Assert.fail();
    }catch(ParseException expected){
        assertThat(expected.getMessage(), JUnitMatchers.containsString("Illegal route rule without then express"));
    }
}
项目:dubbo2    文件:RouteRuleTest.java   
@org.junit.Test
public void testParse_EmptyThen() {
    String expr = "service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1&consumer.version != 1.0.0";
    try{
        RouteRule.parse(expr, "");
        Assert.fail();
    }catch(ParseException expected){
        assertThat(expected.getMessage(), JUnitMatchers.containsString("Illegal route rule without then express"));
    }
}
项目:github-test    文件:RouteRuleTest.java   
@org.junit.Test
public void testParse_EmptyThen() {
    String expr = "service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1&consumer.version != 1.0.0";
    try {
        RouteRule.parse(expr, "");
        Assert.fail();
    } catch (ParseException expected) {
        assertThat(expected.getMessage(), JUnitMatchers.containsString("Illegal route rule without then express"));
    }
}
项目:dubbox-hystrix    文件:RouteRuleTest.java   
@org.junit.Test
public void testParse_EmptyThen() {
    String expr = "service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1&consumer.version != 1.0.0";
    try{
        RouteRule.parse(expr, "");
        Assert.fail();
    }catch(ParseException expected){
        assertThat(expected.getMessage(), JUnitMatchers.containsString("Illegal route rule without then express"));
    }
}
项目:dubbocloud    文件:RouteRuleTest.java   
@org.junit.Test
public void testParse_EmptyThen() {
    String expr = "service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1&consumer.version != 1.0.0";
    try{
        RouteRule.parse(expr, "");
        Assert.fail();
    }catch(ParseException expected){
        assertThat(expected.getMessage(), JUnitMatchers.containsString("Illegal route rule without then express"));
    }
}
项目:dubbos    文件:RouteRuleTest.java   
@org.junit.Test
public void testParse_EmptyThen() {
    String expr = "service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1&consumer.version != 1.0.0";
    try{
        RouteRule.parse(expr, "");
        Assert.fail();
    }catch(ParseException expected){
        assertThat(expected.getMessage(), JUnitMatchers.containsString("Illegal route rule without then express"));
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseOperationRequestMismatch() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"deliver\">\n")
        .append(" <account username=\"customer1\" password=\"test1\"/>\n")
        .append(" <submitRequest referenceId=\"MYREF102020022\">\n")
        .append("  <operatorId>10</operatorId>\n")
        .append("  <sourceAddress type=\"network\">40404</sourceAddress>\n")
        .append("  <destinationAddress type=\"international\">+12065551212</destinationAddress>\n")
        .append("  <text encoding=\"ISO-8859-1\">48656c6c6f20576f726c64</text>\n")
        .append(" </submitRequest>\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
        // correct behavior
        Assert.assertEquals(SxmpErrorCode.OPTYPE_MISMATCH, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("The operation type [deliver] does not match the [submitRequest] element"));
        Assert.assertNotNull(e.getOperation());
        PartialOperation partial = (PartialOperation)e.getOperation();
        Assert.assertEquals(Operation.Type.DELIVER, partial.getType());
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseSubmitMissingAccount() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"submit\">\n")
        .append(" <submitRequest referenceId=\"MYREF102020022\">\n")
        .append("  <operatorId>10</operatorId>\n")
        .append("  <deliveryReport>true</deliveryReport>\n")
        .append("  <sourceAddress type=\"network\">40404</sourceAddress>\n")
        .append("  <destinationAddress type=\"international\">+12065551212</destinationAddress>\n")
        .append("  <text encoding=\"ISO-8859-1\">48656c6c6f20576f726c64</text>\n")
        .append(" </submitRequest>\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
        // correct behavior
        Assert.assertEquals(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("The [account] element is required before a [submitRequest] element"));
        Assert.assertNotNull(e.getOperation());
        PartialOperation partial = (PartialOperation)e.getOperation();
        Assert.assertEquals(Operation.Type.SUBMIT, partial.getType());
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseSubmitEmptyOperatorId() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"submit\">\n")
        .append(" <account username=\"customer1\" password=\"test1\"/>\n")
        .append(" <submitRequest referenceId=\"MYREF102020022\">\n")
        .append("  <operatorId></operatorId>\n")
        .append("  <deliveryReport>true</deliveryReport>\n")
        .append("  <sourceAddress type=\"network\">40f404</sourceAddress>\n")
        .append("  <destinationAddress type=\"international\">+12065551212</destinationAddress>\n")
        .append("  <text encoding=\"ISO-8859-1\">48656c6c6f20576f726c64</text>\n")
        .append(" </submitRequest>\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
         // correct behavior
        Assert.assertEquals(SxmpErrorCode.EMPTY_VALUE, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("The element [operatorId] must contain a value"));
        Assert.assertNotNull(e.getOperation());
        SubmitRequest submitRequest = (SubmitRequest)e.getOperation();
        Assert.assertEquals(Operation.Type.SUBMIT, submitRequest.getType());
    }
}
项目:beyondj    文件:SxmpParserTest.java   
@Test
public void parseSubmitBadOperatorIdValue() throws Exception {
    StringBuilder string0 = new StringBuilder(200)
        .append("<?xml version=\"1.0\"?>\n")
        .append("<operation type=\"submit\">\n")
        .append(" <account username=\"customer1\" password=\"test1\"/>\n")
        .append(" <submitRequest referenceId=\"MYREF102020022\">\n")
        .append("  <operatorId>f</operatorId>\n")
        .append("  <deliveryReport>true</deliveryReport>\n")
        .append("  <sourceAddress type=\"network\">40f404</sourceAddress>\n")
        .append("  <destinationAddress type=\"international\">+12065551212</destinationAddress>\n")
        .append("  <text encoding=\"ISO-8859-1\">48656c6c6f20576f726c64</text>\n")
        .append(" </submitRequest>\n")
        .append("</operation>\n")
        .append("");

    ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
    SxmpParser parser = new SxmpParser();

    try {
        Operation operation = parser.parse(is);
        Assert.fail();
    } catch (SxmpParsingException e) {
         // correct behavior
        Assert.assertEquals(SxmpErrorCode.UNABLE_TO_CONVERT_VALUE, e.getErrorCode());
        Assert.assertThat(e.getMessage(), JUnitMatchers.containsString("Unable to convert [f] to an integer for [operatorId]"));
        Assert.assertNotNull(e.getOperation());
        SubmitRequest submitRequest = (SubmitRequest)e.getOperation();
        Assert.assertEquals(Operation.Type.SUBMIT, submitRequest.getType());
    }
}