use of javax.activation.MimeType in project ddf by codice.
the class TestMimeTypeToTransformerMapperImpl method testBaseTypeMatchIdMismatch.
/**
* Testing a negative case where the mimetype ids don't match.
*
* Tests if
* <p>
* InputTransformer Registered: <br/>
* {BaseType1+id1}. <br/>
* <br/>
* User MimeType Provided: <br/>
* {BaseType1} <br/>
* <br/>
* Empty Set should be returned.
* </p>
*
* @throws MimeTypeParseException
* @throws InvalidSyntaxException
*/
@Test
public void testBaseTypeMatchIdMismatch() throws MimeTypeParseException, InvalidSyntaxException {
// given
final BundleContext context = mock(BundleContext.class);
ServiceReference ref1 = createMockReference(1, Arrays.asList(MediaType.APPLICATION_ATOM_XML), "a1");
ServiceReference[] refs = { ref1 };
Object simpleTransformer1 = new Object();
// when
when(context.getService(ref1)).thenReturn(simpleTransformer1);
when(context.getServiceReferences(isA(String.class), isNull(String.class))).thenReturn(refs);
MimeTypeToTransformerMapper matcher = new MimeTypeToTransformerMapperImpl() {
@Override
protected BundleContext getContext() {
return context;
}
};
List<Object> matches = matcher.findMatches(Object.class, new MimeType(MediaType.APPLICATION_ATOM_XML + "; id=a2"));
// then
assertThat(matches.size(), is(0));
}
use of javax.activation.MimeType in project ddf by codice.
the class TestMimeTypeToTransformerMapperImpl method testInvalidMimeTypeServicePropertyWithMatch.
@Test
public void testInvalidMimeTypeServicePropertyWithMatch() throws MimeTypeParseException, InvalidSyntaxException {
// given
final BundleContext context = mock(BundleContext.class);
ServiceReference ref1 = createMockReference(1, Arrays.asList("!INVALID!"), null);
ServiceReference ref2 = createMockReference(2, Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON), "a1");
ServiceReference[] refs = { ref2, ref1 };
Object simpleTransformer1 = new Object();
Object simpleTransformer2 = new Object();
// when
when(context.getService(ref1)).thenReturn(simpleTransformer1);
when(context.getService(ref2)).thenReturn(simpleTransformer2);
when(context.getServiceReferences(isA(String.class), isNull(String.class))).thenReturn(refs);
MimeTypeToTransformerMapper matcher = new MimeTypeToTransformerMapperImpl() {
@Override
protected BundleContext getContext() {
return context;
}
};
List<Object> matches = matcher.findMatches(Object.class, new MimeType(MediaType.APPLICATION_JSON + "; id=a1"));
// then
assertThat(matches.size(), is(1));
assertThat(matches.get(0), is(simpleTransformer2));
}
Aggregations