Search in sources :

Example 6 with CustomTypeSafeMatcher

use of org.hamcrest.CustomTypeSafeMatcher in project beam by apache.

the class DisplayDataTest method testJsonSerializationAnonymousClassNamespace.

@Test
public void testJsonSerializationAnonymousClassNamespace() throws IOException {
    HasDisplayData component = new HasDisplayData() {

        @Override
        public void populateDisplayData(Builder builder) {
            builder.add(DisplayData.item("foo", "bar"));
        }
    };
    DisplayData data = DisplayData.from(component);
    JsonNode json = MAPPER.readTree(MAPPER.writeValueAsBytes(data));
    String namespace = json.elements().next().get("namespace").asText();
    final Pattern anonClassRegex = Pattern.compile(Pattern.quote(DisplayDataTest.class.getName()) + "\\$\\d+$");
    assertThat(namespace, new CustomTypeSafeMatcher<String>("anonymous class regex: " + anonClassRegex) {

        @Override
        protected boolean matchesSafely(String item) {
            java.util.regex.Matcher m = anonClassRegex.matcher(item);
            return m.matches();
        }
    });
}
Also used : Pattern(java.util.regex.Pattern) CustomTypeSafeMatcher(org.hamcrest.CustomTypeSafeMatcher) FeatureMatcher(org.hamcrest.FeatureMatcher) Matcher(org.hamcrest.Matcher) Builder(org.apache.beam.sdk.transforms.display.DisplayData.Builder) JsonNode(com.fasterxml.jackson.databind.JsonNode) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Test(org.junit.Test)

Aggregations

CustomTypeSafeMatcher (org.hamcrest.CustomTypeSafeMatcher)6 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 DockerClient (com.spotify.docker.client.DockerClient)1 Container (com.spotify.docker.client.messages.Container)1 Version (com.spotify.docker.client.messages.Version)1 JobId (com.spotify.helios.common.descriptors.JobId)1 ServiceEndpoint (com.spotify.helios.common.descriptors.ServiceEndpoint)1 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)1 Endpoint (com.spotify.helios.serviceregistration.ServiceRegistration.Endpoint)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 URI (java.net.URI)1 Pattern (java.util.regex.Pattern)1 Builder (org.apache.beam.sdk.transforms.display.DisplayData.Builder)1 Item (org.apache.beam.sdk.transforms.display.DisplayData.Item)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)1 IndexRequest (org.elasticsearch.action.index.IndexRequest)1 Description (org.hamcrest.Description)1