Search in sources :

Example 21 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project microservice_framework by CJSCommonPlatform.

the class JsonSchemaPropertyMatcher method hasProperty.

/**
 * Matcher to validate if a given property exists in the given json schema
 *
 * @param jsonpathToRequiredProperty json path of the property that should exist in the schema (i.e. case.offences.offenceId)
 * @return matcher
 */
public static Matcher<String> hasProperty(final String jsonpathToRequiredProperty) {
    return new TypeSafeMatcher<String>() {

        private String pathToJsonFile = null;

        @Override
        protected boolean matchesSafely(final String pathToJsonFile) {
            this.pathToJsonFile = pathToJsonFile;
            final JsonPath jsonPath = JsonPath.of(jsonpathToRequiredProperty);
            final ObjectSchema parentObjectSchema = getObjectSchemaFromFile(pathToJsonFile);
            return getObjectSchemaWithPath(parentObjectSchema, jsonPath).getPropertySchemas().containsKey(jsonPath.getProperty());
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText("property ").appendValue(jsonpathToRequiredProperty).appendText(" should exist in JSON Schema ").appendValue(pathToJsonFile);
        }

        @Override
        protected void describeMismatchSafely(final String pathToJsonFile, final Description mismatchDescription) {
            mismatchDescription.appendText("property ").appendValue(jsonpathToRequiredProperty).appendText(" doesn't exist in schema");
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ObjectSchema(org.everit.json.schema.ObjectSchema)

Example 22 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project microservice_framework by CJSCommonPlatform.

the class JsonSchemaValidationInterceptorTest method inputStreamEqualTo.

private Matcher<InputStream> inputStreamEqualTo(final String input) throws IOException {
    return new TypeSafeMatcher<InputStream>() {

        @Override
        protected boolean matchesSafely(final InputStream item) {
            try {
                final String actual = CharStreams.toString(new InputStreamReader(item));
                item.reset();
                return input.equals(actual);
            } catch (IOException ex) {
                return false;
            }
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(input);
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 23 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project goodies by sonatype.

the class FileMatchers method containsEntry.

public static Matcher<ZipFile> containsEntry(final String entryName) {
    return new TypeSafeMatcher<ZipFile>() {

        @Override
        protected boolean matchesSafely(ZipFile item) {
            Enumeration<? extends ZipEntry> entries = item.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entry.getName().equals(entryName)) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("zip archive contains entry named ");
            description.appendValue(entryName);
        }

        @Override
        protected void describeMismatchSafely(ZipFile item, Description mismatchDescription) {
            mismatchDescription.appendText(" archive contained these entries:\n");
            Enumeration<? extends ZipEntry> entries = item.entries();
            while (entries.hasMoreElements()) {
                mismatchDescription.appendValue(entries.nextElement().getName());
                if (entries.hasMoreElements()) {
                    mismatchDescription.appendText("\n");
                }
            }
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry)

Example 24 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project data-access by pentaho.

the class DatasourceResourceIT method testImportZipFile.

private void testImportZipFile(String filePath, final String expectedSchemaName, boolean annotated) throws Exception {
    FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
    File f = new File(filePath);
    when(schemaFileInfo.getFileName()).thenReturn(f.getName());
    Mockery mockery = new Mockery();
    final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
    mp.defineInstance(IPlatformImporter.class, mockImporter);
    if (annotated) {
        mockery.checking(new Expectations() {

            {
                exactly(2).of(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {

                    public boolean matchesSafely(IPlatformImportBundle bundle) {
                        return true;
                    }

                    public void describeTo(Description description) {
                        description.appendText("bundle with zipped mondrian schema");
                    }
                })));
            }
        });
    } else {
        mockery.checking(new Expectations() {

            {
                oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {

                    public boolean matchesSafely(IPlatformImportBundle bundle) {
                        return bundle.getProperty("domain-id").equals(expectedSchemaName);
                    }

                    public void describeTo(Description description) {
                        description.appendText("bundle with zipped mondrian schema");
                    }
                })));
            }
        });
    }
    AnalysisService service = new AnalysisService();
    FileInputStream in = new FileInputStream(filePath);
    try {
        service.putMondrianSchema(in, schemaFileInfo, null, null, null, false, false, "Datasource=SampleData;overwrite=false", null);
        mockery.assertIsSatisfied();
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : Expectations(org.jmock.Expectations) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) AnalysisService(org.pentaho.platform.dataaccess.datasource.api.AnalysisService) ZipFile(java.util.zip.ZipFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) Mockery(org.jmock.Mockery) FileInputStream(java.io.FileInputStream)

Example 25 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project data-access by pentaho.

the class DatasourceResourceIT method testImportFile.

private void testImportFile(String filePath, final String expectedSchemaName) throws Exception {
    FormDataContentDisposition schemaFileInfo = mock(FormDataContentDisposition.class);
    when(schemaFileInfo.getFileName()).thenReturn("stubFileName");
    Mockery mockery = new Mockery();
    final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
    mp.defineInstance(IPlatformImporter.class, mockImporter);
    mockery.checking(new Expectations() {

        {
            oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {

                public boolean matchesSafely(IPlatformImportBundle bundle) {
                    return bundle.getProperty("domain-id").equals(expectedSchemaName) && bundle.getMimeType().equals("application/vnd.pentaho.mondrian+xml");
                }

                public void describeTo(Description description) {
                    description.appendText("bundle with mondrian schema");
                }
            })));
        }
    });
    AnalysisService service = new AnalysisService();
    FileInputStream in = new FileInputStream(filePath);
    try {
        service.putMondrianSchema(in, schemaFileInfo, null, null, null, false, false, "Datasource=SampleData;overwrite=false", null);
        mockery.assertIsSatisfied();
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : Expectations(org.jmock.Expectations) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) AnalysisService(org.pentaho.platform.dataaccess.datasource.api.AnalysisService) Mockery(org.jmock.Mockery) FileInputStream(java.io.FileInputStream)

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