Ejemplo n.º 1
0
 @Override
 public void write(Record record) throws IOException {
   if (closed) {
     throw new IOException("writer has been closed");
   }
   generator.writeObject(BeanHelper.wrapRecord(record));
   generator.writeRaw('\n');
 }
  @Test
  public void testDataRuleDefinitionBean() {
    com.streamsets.datacollector.config.DataRuleDefinition dataRuleDefinition =
        new com.streamsets.datacollector.config.DataRuleDefinition(
            "nameNotNull",
            "nameNotNull",
            "lane",
            100,
            10,
            "${record:value(\"/name\")==null}",
            true,
            "nameNotNull",
            com.streamsets.datacollector.config.ThresholdType.COUNT,
            "2",
            5,
            true,
            false,
            true);

    DataRuleDefinitionJson dataRuleDefinitionJsonBean =
        new DataRuleDefinitionJson(dataRuleDefinition);

    Assert.assertEquals(dataRuleDefinition.getLabel(), dataRuleDefinitionJsonBean.getLabel());
    Assert.assertEquals(dataRuleDefinition.getLane(), dataRuleDefinitionJsonBean.getLane());
    Assert.assertEquals(
        dataRuleDefinition.getMinVolume(), dataRuleDefinitionJsonBean.getMinVolume());
    Assert.assertTrue(
        dataRuleDefinition.getSamplingPercentage()
            == dataRuleDefinitionJsonBean.getSamplingPercentage());
    Assert.assertEquals(
        dataRuleDefinition.getSamplingRecordsToRetain(),
        dataRuleDefinitionJsonBean.getSamplingRecordsToRetain());
    Assert.assertEquals(
        dataRuleDefinition.getThresholdType(),
        BeanHelper.unwrapThresholdType(dataRuleDefinitionJsonBean.getThresholdType()));
    Assert.assertEquals(
        dataRuleDefinition.getThresholdValue(), dataRuleDefinitionJsonBean.getThresholdValue());
    Assert.assertEquals(
        dataRuleDefinition.getAlertText(), dataRuleDefinitionJsonBean.getAlertText());
    Assert.assertEquals(dataRuleDefinition.getId(), dataRuleDefinitionJsonBean.getId());
    Assert.assertEquals(
        dataRuleDefinition.getCondition(), dataRuleDefinitionJsonBean.getCondition());
    Assert.assertEquals(
        dataRuleDefinition.isAlertEnabled(), dataRuleDefinitionJsonBean.isAlertEnabled());
    Assert.assertEquals(
        dataRuleDefinition.isMeterEnabled(), dataRuleDefinitionJsonBean.isMeterEnabled());
    Assert.assertEquals(dataRuleDefinition.isSendEmail(), dataRuleDefinitionJsonBean.isSendEmail());
    Assert.assertEquals(dataRuleDefinition.isValid(), dataRuleDefinitionJsonBean.isValid());
    Assert.assertEquals(dataRuleDefinition.isEnabled(), dataRuleDefinitionJsonBean.isEnabled());
  }