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");
}
};
}
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);
}
};
}
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");
}
}
}
};
}
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);
}
}
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);
}
}
Aggregations