@Test
  public void testValidate() throws Exception {
    getKiji().createTable(KijiTableLayouts.getLayout(KijiTableLayouts.COUNTER_TEST));
    final KijiFreshnessManager manager = KijiFreshnessManager.create(getKiji());
    manager.storePolicy("user", "info:name", TestProducer.class, new AlwaysFreshen());
    assertEquals(
        BaseTool.SUCCESS,
        runTool(
            new FreshTool(),
            KijiURI.newBuilder(getKiji().getURI()).withTableName("user").build().toString(),
            "--do=validate-all"));

    KijiFreshnessPolicyRecord record =
        KijiFreshnessPolicyRecord.newBuilder()
            .setRecordVersion(ProtocolVersion.parse("policyrecord-0.1").toCanonicalString())
            .setProducerClass(TestProducer.class.getName())
            .setFreshnessPolicyClass(AlwaysFreshen.class.getName())
            .setFreshnessPolicyState("")
            .build();

    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    final EncoderFactory encoderFactory = EncoderFactory.get();
    Encoder encoder = encoderFactory.directBinaryEncoder(outputStream, null);
    final DatumWriter<KijiFreshnessPolicyRecord> recordWriter =
        new SpecificDatumWriter<KijiFreshnessPolicyRecord>(KijiFreshnessPolicyRecord.SCHEMA$);
    recordWriter.write(record, encoder);
    getKiji()
        .getMetaTable()
        .putValue("user", "kiji.scoring.fresh.columnName", outputStream.toByteArray());

    assertEquals(
        BaseTool.FAILURE,
        runTool(
            new FreshTool(),
            KijiURI.newBuilder(getKiji().getURI()).withTableName("user").build().toString(),
            "--do=validate-all"));
    assertEquals(
        "Freshness policy attached to column: columnName is not valid.", mToolOutputLines[1]);
    assertEquals(
        "NO_FAMILY_IN_TABLE: java.lang.IllegalArgumentException: Table: user does not "
            + "contain family: columnName",
        mToolOutputLines[2]);
  }
  @Test
  public void testRegister() throws Exception {
    getKiji().createTable(KijiTableLayouts.getLayout(KijiTableLayouts.COUNTER_TEST));
    assertEquals(
        BaseTool.SUCCESS,
        runTool(
            new FreshTool(),
            KijiURI.newBuilder(getKiji().getURI())
                .withTableName("user")
                .withColumnNames(Lists.newArrayList("info:name"))
                .build()
                .toString(),
            "--do=register",
            "--policy-class=org.kiji.scoring.lib.ShelfLife",
            "--policy-state={\"shelfLife\":10}",
            "--producer-class=org.kiji.scoring.tools.TestFreshTool$TestProducer"));

    final KijiFreshnessPolicyRecord record =
        KijiFreshnessPolicyRecord.newBuilder()
            .setRecordVersion("policyrecord-0.1.0")
            .setProducerClass(TestProducer.class.getName())
            .setFreshnessPolicyClass(
                Class.forName("org.kiji.scoring.lib.ShelfLife")
                    .asSubclass(KijiFreshnessPolicy.class)
                    .getName())
            .setFreshnessPolicyState("{\"shelfLife\":10}")
            .build();
    final KijiFreshnessManager manager = KijiFreshnessManager.create(getKiji());
    assertEquals(record, manager.retrievePolicy("user", "info:name"));
    assertEquals(
        "Freshness policy: org.kiji.scoring.lib.ShelfLife with state: {\"shelfLife\":10} "
            + "and producer: org.kiji.scoring.tools.TestFreshTool$TestProducer\n"
            + "attached to column: info:name in table: user",
        mToolOutputStr);

    // Test another ordering for arguments
    assertEquals(
        BaseTool.SUCCESS,
        runTool(
            new FreshTool(),
            "--do=register",
            KijiURI.newBuilder(getKiji().getURI())
                .withTableName("user")
                .withColumnNames(Lists.newArrayList("info:visits"))
                .build()
                .toString(),
            "--policy-state={\"shelfLife\":10}",
            "--producer-class=org.kiji.scoring.tools.TestFreshTool$TestProducer",
            "--policy-class=org.kiji.scoring.lib.ShelfLife"));

    final KijiFreshnessPolicyRecord record2 =
        KijiFreshnessPolicyRecord.newBuilder()
            .setRecordVersion("policyrecord-0.1.0")
            .setProducerClass(TestProducer.class.getName())
            .setFreshnessPolicyClass(
                Class.forName("org.kiji.scoring.lib.ShelfLife")
                    .asSubclass(KijiFreshnessPolicy.class)
                    .getName())
            .setFreshnessPolicyState("{\"shelfLife\":10}")
            .build();
    assertEquals(record2, manager.retrievePolicy("user", "info:visits"));
    assertEquals(
        "Freshness policy: org.kiji.scoring.lib.ShelfLife with state: {\"shelfLife\":10} "
            + "and producer: org.kiji.scoring.tools.TestFreshTool$TestProducer\n"
            + "attached to column: info:visits in table: user",
        mToolOutputStr);
  }