Search in sources :

Example 16 with Matcher

use of org.hamcrest.Matcher in project ddf by codice.

the class TestCswUnmarshallHelper method testConvertRecordPropertyToMetacardAttribute.

@Test
public void testConvertRecordPropertyToMetacardAttribute() {
    valueMap.put(AttributeType.AttributeFormat.BINARY, "TEST_BINARY");
    valueMap.put(AttributeType.AttributeFormat.GEOMETRY, TEST_BOUNDING_BOX);
    matcherMap.put(AttributeType.AttributeFormat.BINARY, notNullValue());
    matcherMap.put(AttributeType.AttributeFormat.GEOMETRY, is("POLYGON ((44.792 -6.171, 44.792 -2.228, 51.126 -2.228, 51.126 -6.171, 44.792 -6.171))"));
    AttributeType.AttributeFormat[] attributeFormats = AttributeType.AttributeFormat.values();
    for (AttributeType.AttributeFormat attributeFormat : attributeFormats) {
        HierarchicalStreamReader reader = getReader(attributeFormat);
        Serializable ser = CswUnmarshallHelper.convertRecordPropertyToMetacardAttribute(attributeFormat, reader, CswAxisOrder.LAT_LON);
        Matcher m = matcherMap.get(attributeFormat);
        assertThat(ser, m);
    }
}
Also used : Serializable(java.io.Serializable) Matcher(org.hamcrest.Matcher) AttributeType(ddf.catalog.data.AttributeType) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) Test(org.junit.Test)

Example 17 with Matcher

use of org.hamcrest.Matcher in project ddf by codice.

the class TestFederation method testCswQueryWithValidationCheckerPlugin.

@Test
public void testCswQueryWithValidationCheckerPlugin() throws Exception {
    // Construct a query to search for all metacards
    String query = new CswQueryBuilder().addAttributeFilter(CswQueryBuilder.PROPERTY_IS_LIKE, "AnyText", "*").getQuery();
    // Declare array of matchers so we can be sure we use the same matchers in each assertion
    Matcher[] assertion = new Matcher[] { hasXPath("/GetRecordsResponse/SearchResults/Record/identifier[text()='" + metacardIds[GEOJSON_RECORD_INDEX] + "']"), hasXPath("/GetRecordsResponse/SearchResults/Record/identifier[text()='" + metacardIds[XML_RECORD_INDEX] + "']"), hasXPath("/GetRecordsResponse/SearchResults/@numberOfRecordsReturned", is("2")), hasXPath("/GetRecordsResponse/SearchResults/Record/relation", containsString("/services/catalog/sources/")) };
    // Run a normal federated query to the CSW source and assert response
    given().contentType(ContentType.XML).body(query).when().post(CSW_PATH.getUrl()).then().assertThat().body(assertion[0], assertion);
    // Assert that response is the same as without the plugin
    given().contentType(ContentType.XML).body(query).when().post(CSW_PATH.getUrl()).then().assertThat().body(assertion[0], assertion);
}
Also used : CswQueryBuilder(org.codice.ddf.itests.common.csw.CswQueryBuilder) Matcher(org.hamcrest.Matcher) Matchers.containsString(org.hamcrest.Matchers.containsString) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) Test(org.junit.Test) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest)

Example 18 with Matcher

use of org.hamcrest.Matcher in project elasticsearch by elastic.

the class DeprecationHttpIT method doTestDeprecationWarningsAppearInHeaders.

/**
     * Run a request that receives a predictably randomized number of deprecation warnings.
     * <p>
     * Re-running this back-to-back helps to ensure that warnings are not being maintained across requests.
     */
private void doTestDeprecationWarningsAppearInHeaders() throws IOException {
    final boolean useDeprecatedField = randomBoolean();
    final boolean useNonDeprecatedSetting = randomBoolean();
    // deprecated settings should also trigger a deprecation warning
    final List<Setting<Boolean>> settings = new ArrayList<>(3);
    settings.add(TEST_DEPRECATED_SETTING_TRUE1);
    if (randomBoolean()) {
        settings.add(TEST_DEPRECATED_SETTING_TRUE2);
    }
    if (useNonDeprecatedSetting) {
        settings.add(TEST_NOT_DEPRECATED_SETTING);
    }
    Collections.shuffle(settings, random());
    // trigger all deprecations
    Response response = getRestClient().performRequest("GET", "/_test_cluster/deprecated_settings", Collections.emptyMap(), buildSettingsRequest(settings, useDeprecatedField));
    assertThat(response.getStatusLine().getStatusCode(), equalTo(OK.getStatus()));
    final List<String> deprecatedWarnings = getWarningHeaders(response.getHeaders());
    final List<Matcher<String>> headerMatchers = new ArrayList<>(4);
    headerMatchers.add(equalTo(TestDeprecationHeaderRestAction.DEPRECATED_ENDPOINT));
    if (useDeprecatedField) {
        headerMatchers.add(equalTo(TestDeprecationHeaderRestAction.DEPRECATED_USAGE));
    }
    for (Setting<?> setting : settings) {
        if (setting.isDeprecated()) {
            headerMatchers.add(equalTo("[" + setting.getKey() + "] setting was deprecated in Elasticsearch and will be removed in a future release! " + "See the breaking changes documentation for the next major version."));
        }
    }
    assertThat(deprecatedWarnings, hasSize(headerMatchers.size()));
    for (final String deprecatedWarning : deprecatedWarnings) {
        assertThat(deprecatedWarning, matches(WARNING_HEADER_PATTERN.pattern()));
    }
    final List<String> actualWarningValues = deprecatedWarnings.stream().map(DeprecationLogger::extractWarningValueFromWarningHeader).collect(Collectors.toList());
    for (Matcher<String> headerMatcher : headerMatchers) {
        assertThat(actualWarningValues, hasItem(headerMatcher));
    }
}
Also used : Response(org.elasticsearch.client.Response) Matcher(org.hamcrest.Matcher) Setting(org.elasticsearch.common.settings.Setting) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 19 with Matcher

use of org.hamcrest.Matcher in project iosched by google.

the class MatchersHelper method getNumberOfDescendantsForViewGroupDescendant.

/**
     * This returns the number of descendants of the {@code parentViewWithMultipleChildren} that
     * have an id of {@code idOfDescendantViewToGetTextFor}}. The parent view is expected to be a
     * {@link ViewGroup}. This is used when there is a certain randomness in the elements shown in a
     * collection view, even with mock data, but we want to check the number of elements inside the
     * parent view.
     *
     * @see com.google.samples.apps.iosched.explore.ExploreIOActivityTest
     */
public static int getNumberOfDescendantsForViewGroupDescendant(final Matcher<View> parentViewWithMultipleChildren, final int idOfDescendantViewToGetTextFor) {
    /**
         * We cannot use a int directly as we need to make it final to access it inside the
         * inner method but we cannot reassign a value to a final int.
         */
    final int[] intHolder = { 0 };
    onView(parentViewWithMultipleChildren).perform(new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(ViewGroup.class);
        }

        @Override
        public String getDescription() {
            return "getting text from a TextView with a known id and that is a descendant of " + "the nth child of a viewgroup";
        }

        @Override
        public void perform(UiController uiController, View view) {
            ViewGroup vg = (ViewGroup) view;
            int descendants = vg.getChildCount();
            for (int i = 0; i < descendants; i++) {
                View ithDescendant = vg.getChildAt(i);
                View matchedView = ithDescendant.findViewById(idOfDescendantViewToGetTextFor);
                if (matchedView != null) {
                    intHolder[0] += 1;
                }
            }
        }
    });
    return intHolder[0];
}
Also used : ViewAction(android.support.test.espresso.ViewAction) BaseMatcher(org.hamcrest.BaseMatcher) Matcher(org.hamcrest.Matcher) ViewGroup(android.view.ViewGroup) UiController(android.support.test.espresso.UiController) TextView(android.widget.TextView) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View)

Example 20 with Matcher

use of org.hamcrest.Matcher in project iosched by google.

the class MatchersHelper method getText.

/**
     * This returns the text for the view that has been matched with {@code matcher}. The matched
     * view is expected to be a {@link TextView}. This is different from matching a view by text,
     * this is intended to be used when matching a view by another mean (for example, by id) but
     * when we need to know the text of that view, for use later in a test.
     * <p/>
     * In general, this isn't good practice as tests should be written using mock data (so we always
     * know what the data is) but this enables us to write tests that are written using real data
     * (so we don't always know what the data is but we want to verify something later in a test).
     * This is enables us to write UI tests before refactoring a feature to make it easier to mock
     * the data.
     */
public static String getText(final Matcher<View> matcher) {
    /**
         * We cannot use a String directly as we need to make it final to access it inside the
         * inner method but we cannot reassign a value to a final String.
         */
    final String[] stringHolder = { null };
    onView(matcher).perform(new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(TextView.class);
        }

        @Override
        public String getDescription() {
            return "getting text from a TextView";
        }

        @Override
        public void perform(UiController uiController, View view) {
            TextView tv = (TextView) view;
            stringHolder[0] = tv.getText().toString();
        }
    });
    return stringHolder[0];
}
Also used : ViewAction(android.support.test.espresso.ViewAction) BaseMatcher(org.hamcrest.BaseMatcher) Matcher(org.hamcrest.Matcher) UiController(android.support.test.espresso.UiController) TextView(android.widget.TextView) TextView(android.widget.TextView) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View)

Aggregations

Matcher (org.hamcrest.Matcher)28 Description (org.hamcrest.Description)7 View (android.view.View)6 Test (org.junit.Test)6 Espresso.onView (android.support.test.espresso.Espresso.onView)4 UiController (android.support.test.espresso.UiController)4 ViewAction (android.support.test.espresso.ViewAction)4 TextView (android.widget.TextView)4 MockedPulsarServiceBaseTest (com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)4 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)4 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)4 URL (java.net.URL)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Test (org.testng.annotations.Test)4 RestException (com.yahoo.pulsar.broker.web.RestException)3 ArrayList (java.util.ArrayList)3 Resources (android.content.res.Resources)2 ColorInt (android.support.annotation.ColorInt)2 MediumTest (android.support.test.filters.MediumTest)2 ViewGroup (android.view.ViewGroup)2