Search in sources :

Example 6 with MimeTypeToTransformerMapper

use of ddf.mime.MimeTypeToTransformerMapper in project ddf by codice.

the class TestMimeTypeToTransformerMapperImpl method testNullBundleContext.

/**
     * We expect an empty services list to be returned when no bundleContext is provided
     *
     * @throws MimeTypeParseException
     */
@Test
public void testNullBundleContext() throws MimeTypeParseException {
    // given
    final BundleContext context = null;
    // when
    MimeTypeToTransformerMapper matcher = new MimeTypeToTransformerMapperImpl() {

        @Override
        protected BundleContext getContext() {
            return context;
        }
    };
    List<Object> matches = matcher.findMatches(Object.class, null);
    // then
    assertThat(matches.isEmpty(), is(true));
}
Also used : MimeTypeToTransformerMapper(ddf.mime.MimeTypeToTransformerMapper) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 7 with MimeTypeToTransformerMapper

use of ddf.mime.MimeTypeToTransformerMapper in project ddf by codice.

the class TestMimeTypeToTransformerMapperImpl method testSingleIdMatch.

/**
     * Tests if a single id match will return only one item
     *
     * @throws MimeTypeParseException
     * @throws InvalidSyntaxException
     */
@Test
public void testSingleIdMatch() throws MimeTypeParseException, InvalidSyntaxException {
    // given
    final BundleContext context = mock(BundleContext.class);
    ServiceReference ref1 = createMockReference(1, Arrays.asList(MediaType.APPLICATION_JSON), "");
    ServiceReference ref2 = createMockReference(2, Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON), "a1");
    ServiceReference ref3 = createMockReference(3, null, null);
    ServiceReference[] refs = { ref2, ref3, ref1 };
    Object simpleTransformer1 = new Object();
    Object simpleTransformer2 = new Object();
    Object simpleTransformer3 = new Object();
    // when
    when(context.getService(ref1)).thenReturn(simpleTransformer1);
    when(context.getService(ref2)).thenReturn(simpleTransformer2);
    when(context.getService(ref3)).thenReturn(simpleTransformer3);
    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));
}
Also used : MimeTypeToTransformerMapper(ddf.mime.MimeTypeToTransformerMapper) MimeType(javax.activation.MimeType) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 8 with MimeTypeToTransformerMapper

use of ddf.mime.MimeTypeToTransformerMapper in project ddf by codice.

the class TestMimeTypeToTransformerMapperImpl method testSingleMimeTypeServiceProperty.

/**
     * Tests the case where the ServiceReference Properties does not have a list of MimeTypes,
     * instead it provides a single String for the MimeType
     *
     * @throws MimeTypeParseException
     * @throws InvalidSyntaxException
     */
@Test
public void testSingleMimeTypeServiceProperty() throws MimeTypeParseException, InvalidSyntaxException {
    // given
    final BundleContext context = mock(BundleContext.class);
    ServiceReference ref = mock(ServiceReference.class);
    ServiceReference[] refs = { ref };
    when(ref.getProperty(Constants.SERVICE_RANKING)).thenReturn(0);
    when(ref.getProperty(MimeTypeToTransformerMapper.MIME_TYPE_KEY)).thenReturn(MediaType.APPLICATION_JSON);
    Object simpleTransformer1 = new Object();
    // when
    when(context.getService(ref)).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_JSON));
    // then
    assertThat(matches.size(), is(1));
}
Also used : MimeTypeToTransformerMapper(ddf.mime.MimeTypeToTransformerMapper) MimeType(javax.activation.MimeType) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 9 with MimeTypeToTransformerMapper

use of ddf.mime.MimeTypeToTransformerMapper in project ddf by codice.

the class TestMimeTypeToTransformerMapperImpl method testOnlyBaseTypeMatch.

/**
     * Tests if a basetype matches that the list will return the correct sorted list.
     *
     * @throws MimeTypeParseException
     * @throws InvalidSyntaxException
     */
@Test
public void testOnlyBaseTypeMatch() throws MimeTypeParseException, InvalidSyntaxException {
    // given
    final BundleContext context = mock(BundleContext.class);
    ServiceReference ref1 = createMockReference(1, Arrays.asList(MediaType.APPLICATION_ATOM_XML), "a1");
    ServiceReference ref2 = createMockReference(2, Arrays.asList(MediaType.APPLICATION_JSON), "a2");
    ServiceReference ref3 = createMockReference(3, null, null);
    ServiceReference[] refs = { ref2, ref3, ref1 };
    Object simpleTransformer1 = new Object();
    Object simpleTransformer2 = new Object();
    Object simpleTransformer3 = new Object();
    // when
    when(context.getService(ref1)).thenReturn(simpleTransformer1);
    when(context.getService(ref2)).thenReturn(simpleTransformer2);
    when(context.getService(ref3)).thenReturn(simpleTransformer3);
    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));
    // then
    assertThat(matches.size(), is(1));
    assertThat(matches.get(0), is(simpleTransformer2));
}
Also used : MimeTypeToTransformerMapper(ddf.mime.MimeTypeToTransformerMapper) MimeType(javax.activation.MimeType) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 10 with MimeTypeToTransformerMapper

use of ddf.mime.MimeTypeToTransformerMapper in project ddf by codice.

the class RemoteDeleteOperationsTest method setUpMocks.

private void setUpMocks() throws IOException, CatalogTransformerException {
    String localProviderName = "ddf";
    mockPoller = mock(SourcePoller.class);
    when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);
    provider = mock(CatalogProvider.class);
    when(provider.getId()).thenReturn(localProviderName);
    when(provider.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
    when(provider.isAvailable()).thenReturn(true);
    mockPostResourcePlugin = mock(PostResourcePlugin.class);
    mockPostResourcePlugins = new ArrayList<PostResourcePlugin>();
    mockPostResourcePlugins.add(mockPostResourcePlugin);
    mockFederationStrategy = mock(FederationStrategy.class);
    postIngestPlugins = new ArrayList<>();
    storageProvider = new MockMemoryStorageProvider();
    mimeTypeResolver = mock(MimeTypeResolver.class);
    mimeTypeToTransformerMapper = mock(MimeTypeToTransformerMapper.class);
    uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    inputTransformer = mock(InputTransformer.class);
    when(inputTransformer.transform(any(InputStream.class))).thenReturn(new MetacardImpl());
    when(mimeTypeToTransformerMapper.findMatches(any(Class.class), any(MimeType.class))).thenReturn(Collections.singletonList(inputTransformer));
}
Also used : MimeTypeToTransformerMapper(ddf.mime.MimeTypeToTransformerMapper) PostResourcePlugin(ddf.catalog.plugin.PostResourcePlugin) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) FederationStrategy(ddf.catalog.federation.FederationStrategy) InputStream(java.io.InputStream) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) InputTransformer(ddf.catalog.transform.InputTransformer) SourceMonitor(ddf.catalog.source.SourceMonitor) Source(ddf.catalog.source.Source) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MimeType(javax.activation.MimeType) SourcePoller(ddf.catalog.util.impl.SourcePoller) MimeTypeResolver(ddf.mime.MimeTypeResolver) CatalogProvider(ddf.catalog.source.CatalogProvider)

Aggregations

MimeTypeToTransformerMapper (ddf.mime.MimeTypeToTransformerMapper)22 MimeType (javax.activation.MimeType)18 Test (org.junit.Test)18 BundleContext (org.osgi.framework.BundleContext)15 ServiceReference (org.osgi.framework.ServiceReference)14 InputTransformer (ddf.catalog.transform.InputTransformer)6 InputStream (java.io.InputStream)5 MockMemoryStorageProvider (ddf.catalog.content.impl.MockMemoryStorageProvider)3 Metacard (ddf.catalog.data.Metacard)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3 CatalogProvider (ddf.catalog.source.CatalogProvider)3 FederationStrategy (ddf.catalog.federation.FederationStrategy)2 CreateOperations (ddf.catalog.impl.operations.CreateOperations)2 MetacardFactory (ddf.catalog.impl.operations.MetacardFactory)2 OperationsCatalogStoreSupport (ddf.catalog.impl.operations.OperationsCatalogStoreSupport)2 OperationsMetacardSupport (ddf.catalog.impl.operations.OperationsMetacardSupport)2 OperationsSecuritySupport (ddf.catalog.impl.operations.OperationsSecuritySupport)2 OperationsStorageSupport (ddf.catalog.impl.operations.OperationsStorageSupport)2 QueryOperations (ddf.catalog.impl.operations.QueryOperations)2 ResourceOperations (ddf.catalog.impl.operations.ResourceOperations)2