use of io.cdap.cdap.client.app.FakeApp in project cdap by caskdata.
the class CLITestBase method testMetadata.
@Test
public void testMetadata() throws Exception {
testCommandOutputContains("cli render as csv", "Now rendering as CSV");
// Since metadata indexing is asynchronous, and the FakeApp has just been deployed, we need to
// wait for all entities to be indexed. Knowing that the workflow is the last program to be processed
// by the metadata message subscriber, we can wait until its tag "Batch" is returned in queries.
// This is not elegant because it depends on implementation, but seems better than adding a waitFor()
// for each of the following lines.
Tasks.waitFor(true, () -> {
String output = getCommandOutput(String.format("get metadata-tags %s scope system", FAKE_WORKFLOW_ID));
return Arrays.asList(output.split("\\r?\\n")).contains("Batch");
}, 10, TimeUnit.SECONDS);
// verify system metadata
testCommandOutputContains(String.format("get metadata %s scope system", FAKE_APP_ID), FakeApp.class.getSimpleName());
testCommandOutputContains(String.format("get metadata-tags %s scope system", FAKE_WORKFLOW_ID), FakeWorkflow.FakeAction.class.getSimpleName());
testCommandOutputContains(String.format("get metadata-tags %s scope system", FAKE_WORKFLOW_ID), FakeWorkflow.FakeAction.ANOTHER_FAKE_NAME);
testCommandOutputContains(String.format("get metadata-tags %s scope system", FAKE_DS_ID), "batch");
testCommandOutputContains(String.format("get metadata-tags %s scope system", FAKE_DS_ID), "explore");
testCommandOutputContains(String.format("add metadata-properties %s appKey=appValue", FAKE_APP_ID), "Successfully added metadata properties");
testCommandOutputContains(String.format("get metadata-properties %s", FAKE_APP_ID), "appKey,appValue");
testCommandOutputContains(String.format("add metadata-tags %s 'wfTag1 wfTag2'", FAKE_WORKFLOW_ID), "Successfully added metadata tags");
String output = getCommandOutput(String.format("get metadata-tags %s", FAKE_WORKFLOW_ID));
List<String> lines = Arrays.asList(output.split("\\r?\\n"));
Assert.assertTrue(lines.contains("wfTag1") && lines.contains("wfTag2"));
testCommandOutputContains(String.format("add metadata-properties %s dsKey=dsValue", FAKE_DS_ID), "Successfully added metadata properties");
testCommandOutputContains(String.format("get metadata-properties %s", FAKE_DS_ID), "dsKey,dsValue");
// test search
testCommandOutputContains(String.format("search metadata %s filtered by target-type artifact", FakeApp.class.getSimpleName()), FAKE_ARTIFACT_ID.toString());
testCommandOutputContains("search metadata appKey:appValue", FAKE_APP_ID.toString());
testCommandOutputContains("search metadata fake* filtered by target-type application", FAKE_APP_ID.toString());
output = getCommandOutput("search metadata fake* filtered by target-type program");
lines = Arrays.asList(output.split("\\r?\\n"));
List<String> expected = ImmutableList.of("Entity", FAKE_WORKFLOW_ID.toString(), FAKE_SPARK_ID.toString());
Assert.assertTrue(lines.containsAll(expected) && expected.containsAll(lines));
testCommandOutputContains("search metadata fake* filtered by target-type dataset", FAKE_DS_ID.toString());
testCommandOutputContains(String.format("search metadata %s", FakeApp.TIME_SCHEDULE_NAME), FAKE_APP_ID.toString());
testCommandOutputContains(String.format("search metadata %s filtered by target-type application", PingService.NAME), FAKE_APP_ID.toString());
testCommandOutputContains(String.format("search metadata %s filtered by target-type program", PrefixedEchoHandler.NAME), PREFIXED_ECHO_HANDLER_ID.toString());
testCommandOutputContains("search metadata batch* filtered by target-type dataset", FAKE_DS_ID.toString());
testCommandOutputNotContains("search metadata batchwritable filtered by target-type dataset", FAKE_DS_ID.toString());
testCommandOutputContains("search metadata bat* filtered by target-type dataset", FAKE_DS_ID.toString());
output = getCommandOutput("search metadata batch filtered by target-type program");
lines = Arrays.asList(output.split("\\r?\\n"));
expected = ImmutableList.of("Entity", FAKE_SPARK_ID.toString(), FAKE_WORKFLOW_ID.toString());
Assert.assertTrue(lines.containsAll(expected) && expected.containsAll(lines));
output = getCommandOutput("search metadata fake* filtered by target-type dataset,application");
lines = Arrays.asList(output.split("\\r?\\n"));
expected = ImmutableList.of("Entity", FAKE_DS_ID.toString(), FAKE_APP_ID.toString());
Assert.assertTrue(lines.containsAll(expected) && expected.containsAll(lines));
output = getCommandOutput("search metadata wfTag* filtered by target-type program");
lines = Arrays.asList(output.split("\\r?\\n"));
expected = ImmutableList.of("Entity", FAKE_WORKFLOW_ID.toString());
Assert.assertTrue(lines.containsAll(expected) && expected.containsAll(lines));
MetadataEntity fieldEntity = MetadataEntity.builder(FAKE_DS_ID.toMetadataEntity()).appendAsType("field", "empName").build();
testCommandOutputContains(String.format("add metadata-tags %s 'fieldTag1 fieldTag2 fieldTag3'", MetadataCommandHelper.toCliString(fieldEntity)), "Successfully added metadata tags");
output = getCommandOutput(String.format("get metadata-tags %s", MetadataCommandHelper.toCliString(fieldEntity)));
lines = Arrays.asList(output.split("\\r?\\n"));
Assert.assertTrue(lines.contains("fieldTag1") && lines.contains("fieldTag2") && lines.contains("fieldTag3"));
testCommandOutputContains(String.format("add metadata-properties %s fieldKey=fieldValue", MetadataCommandHelper.toCliString(fieldEntity)), "Successfully added metadata properties");
testCommandOutputContains(String.format("get metadata-properties %s", MetadataCommandHelper.toCliString(fieldEntity)), "fieldKey,fieldValue");
// test get metadata for custom entity and verify that return is in new format
testCommandOutputContains(String.format("get metadata %s", MetadataCommandHelper.toCliString(fieldEntity)), fieldEntity.toString());
// test remove
testCommandOutputContains(String.format("remove metadata-tag %s 'fieldTag3'", MetadataCommandHelper.toCliString(fieldEntity)), "Successfully removed metadata tag");
output = getCommandOutput(String.format("get metadata-tags %s", MetadataCommandHelper.toCliString(fieldEntity)));
lines = Arrays.asList(output.split("\\r?\\n"));
// should not contain the removed tag
Assert.assertTrue(lines.contains("fieldTag1") && lines.contains("fieldTag2") && !lines.contains("fieldTag3"));
testCommandOutputContains(String.format("remove metadata-tags %s", MetadataCommandHelper.toCliString(fieldEntity)), "Successfully removed metadata tags");
output = getCommandOutput(String.format("get metadata-tags %s", MetadataCommandHelper.toCliString(fieldEntity)));
lines = Arrays.asList(output.split("\\r?\\n"));
// should not contain any tags except the header added by cli
Assert.assertTrue(lines.size() == 1 && lines.contains("tags"));
testCommandOutputContains(String.format("remove metadata-properties %s", MetadataCommandHelper.toCliString(fieldEntity)), "Successfully removed metadata properties");
// test remove properties
output = getCommandOutput(String.format("get metadata-properties %s", MetadataCommandHelper.toCliString(fieldEntity)));
lines = Arrays.asList(output.split("\\r?\\n"));
// should not contain any properties except the header added by cli
Assert.assertTrue(lines.size() == 1 && lines.contains("key,value"));
}
Aggregations