Search in sources :

Example 1 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.

the class TransactionMatchers method rowContainsDeletedEntities.

public static Matcher<? super HTTP.Response> rowContainsDeletedEntities(final int nodes, final int rels) {
    return new TypeSafeMatcher<HTTP.Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> meta = getJsonNodeWithName(response, "meta").iterator();
                int nodeCounter = 0;
                int relCounter = 0;
                for (int i = 0; i < nodes + rels; ++i) {
                    assertTrue(meta.hasNext());
                    JsonNode node = meta.next();
                    assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.TRUE));
                    String type = node.get("type").getTextValue();
                    switch(type) {
                        case "node":
                            ++nodeCounter;
                            break;
                        case "relationship":
                            ++relCounter;
                            break;
                        default:
                            fail("Unexpected type: " + type);
                            break;
                    }
                }
                assertEquals(nodes, nodeCounter);
                assertEquals(rels, relCounter);
                while (meta.hasNext()) {
                    JsonNode node = meta.next();
                    assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.FALSE));
                }
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) HTTP(org.neo4j.test.server.HTTP) JsonNode(org.codehaus.jackson.JsonNode) JsonParseException(org.neo4j.server.rest.domain.JsonParseException)

Example 2 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.

the class TransactionMatchers method graphContainsDeletedRelationships.

public static Matcher<? super HTTP.Response> graphContainsDeletedRelationships(final int amount) {
    return new TypeSafeMatcher<HTTP.Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> relationships = getJsonNodeWithName(response, "graph").get("relationships").iterator();
                for (int i = 0; i < amount; ++i) {
                    assertTrue(relationships.hasNext());
                    JsonNode node = relationships.next();
                    assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.TRUE));
                }
                if (relationships.hasNext()) {
                    JsonNode node = relationships.next();
                    fail("Expected no more nodes, but got a node with id " + node.get("id"));
                }
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) HTTP(org.neo4j.test.server.HTTP) JsonNode(org.codehaus.jackson.JsonNode) JsonParseException(org.neo4j.server.rest.domain.JsonParseException)

Example 3 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.

the class TransactionMatchers method hasErrors.

public static Matcher<? super HTTP.Response> hasErrors(final Status... expectedErrors) {
    return new TypeSafeMatcher<HTTP.Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> errors = response.get("errors").iterator();
                Iterator<Status> expected = iterator(expectedErrors);
                while (expected.hasNext()) {
                    assertTrue(errors.hasNext());
                    assertThat(errors.next().get("code").asText(), equalTo(expected.next().code().serialize()));
                }
                if (errors.hasNext()) {
                    JsonNode error = errors.next();
                    fail("Expected no more errors, but got " + error.get("code") + " - '" + error.get("message") + "'.");
                }
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) HTTP(org.neo4j.test.server.HTTP) JsonNode(org.codehaus.jackson.JsonNode) JsonParseException(org.neo4j.server.rest.domain.JsonParseException)

Example 4 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.

the class TransactionMatchers method restContainsDeletedEntities.

public static Matcher<? super HTTP.Response> restContainsDeletedEntities(final int amount) {
    return new TypeSafeMatcher<HTTP.Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> entities = getJsonNodeWithName(response, "rest").iterator();
                for (int i = 0; i < amount; ++i) {
                    assertTrue(entities.hasNext());
                    JsonNode node = entities.next();
                    assertThat(node.get("metadata").get("deleted").asBoolean(), equalTo(Boolean.TRUE));
                }
                if (entities.hasNext()) {
                    fail("Expected no more entities");
                }
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) HTTP(org.neo4j.test.server.HTTP) JsonNode(org.codehaus.jackson.JsonNode) JsonParseException(org.neo4j.server.rest.domain.JsonParseException)

Example 5 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.

the class TransactionMatchers method rowContainsDeletedEntitiesInPath.

public static Matcher<? super HTTP.Response> rowContainsDeletedEntitiesInPath(final int nodes, final int rels) {
    return new TypeSafeMatcher<HTTP.Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> meta = getJsonNodeWithName(response, "meta").iterator();
                int nodeCounter = 0;
                int relCounter = 0;
                assertTrue("Expected to find a JSON node, but there was none", meta.hasNext());
                JsonNode node = meta.next();
                assertTrue("Expected the node to be a list (for a path)", node.isArray());
                for (JsonNode inner : node) {
                    String type = inner.get("type").getTextValue();
                    switch(type) {
                        case "node":
                            if (inner.get("deleted").asBoolean()) {
                                ++nodeCounter;
                            }
                            break;
                        case "relationship":
                            if (inner.get("deleted").asBoolean()) {
                                ++relCounter;
                            }
                            break;
                        default:
                            fail("Unexpected type: " + type);
                            break;
                    }
                }
                assertEquals(nodes, nodeCounter);
                assertEquals(rels, relCounter);
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) HTTP(org.neo4j.test.server.HTTP) JsonNode(org.codehaus.jackson.JsonNode) JsonParseException(org.neo4j.server.rest.domain.JsonParseException)

Aggregations

TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)82 Description (org.hamcrest.Description)79 View (android.view.View)44 ViewParent (android.view.ViewParent)33 ViewGroup (android.view.ViewGroup)30 Espresso.onView (android.support.test.espresso.Espresso.onView)25 TextView (android.widget.TextView)9 Test (org.junit.Test)9 ViewMatchers.withContentDescription (android.support.test.espresso.matcher.ViewMatchers.withContentDescription)7 JsonNode (org.codehaus.jackson.JsonNode)6 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)6 HTTP (org.neo4j.test.server.HTTP)6 Resources (android.content.res.Resources)5 StringDescription (org.hamcrest.StringDescription)5 AdapterView (android.widget.AdapterView)4 RecyclerView (android.support.v7.widget.RecyclerView)3 Adapter (android.widget.Adapter)3 Espresso.onView (com.google.android.apps.common.testing.ui.espresso.Espresso.onView)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3