Search in sources :

Example 1 with UuidGenerator

use of org.codice.ddf.platform.util.uuidgenerator.UuidGenerator in project ddf by codice.

the class TestMetacardGroomerPlugin method setUp.

@Before
public void setUp() {
    uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    plugin = new StandardMetacardGroomerPlugin();
    plugin.setUuidGenerator(uuidGenerator);
}
Also used : UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) StandardMetacardGroomerPlugin(ddf.catalog.plugin.groomer.metacard.StandardMetacardGroomerPlugin) Before(org.junit.Before)

Example 2 with UuidGenerator

use of org.codice.ddf.platform.util.uuidgenerator.UuidGenerator in project ddf by codice.

the class TestRestEndpoint method testAddDocumentWithMetadataPositiveCase.

@Test
public void testAddDocumentWithMetadataPositiveCase() throws IOException, CatalogTransformerException, IngestException, SourceUnavailableException, URISyntaxException, InvalidSyntaxException, MimeTypeResolutionException {
    CatalogFramework framework = givenCatalogFramework(SAMPLE_ID);
    HttpHeaders headers = createHeaders(Arrays.asList(MediaType.APPLICATION_JSON));
    BundleContext bundleContext = mock(BundleContext.class);
    Collection<ServiceReference<InputTransformer>> serviceReferences = new ArrayList<>();
    ServiceReference serviceReference = mock(ServiceReference.class);
    InputTransformer inputTransformer = mock(InputTransformer.class);
    when(inputTransformer.transform(any())).thenReturn(new MetacardImpl());
    when(bundleContext.getService(serviceReference)).thenReturn(inputTransformer);
    serviceReferences.add(serviceReference);
    when(bundleContext.getServiceReferences(InputTransformer.class, "(id=xml)")).thenReturn(serviceReferences);
    RESTEndpoint rest = new RESTEndpoint(framework) {

        @Override
        BundleContext getBundleContext() {
            return bundleContext;
        }
    };
    UuidGenerator uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    rest.setUuidGenerator(uuidGenerator);
    rest.setMetacardTypes(Collections.singletonList(BasicTypes.BASIC_METACARD));
    MimeTypeMapper mimeTypeMapper = mock(MimeTypeMapper.class);
    when(mimeTypeMapper.getMimeTypeForFileExtension("txt")).thenReturn("text/plain");
    when(mimeTypeMapper.getMimeTypeForFileExtension("xml")).thenReturn("text/xml");
    rest.setMimeTypeMapper(mimeTypeMapper);
    addMatchingService(rest, Arrays.asList(getSimpleTransformer()));
    UriInfo info = givenUriInfo(SAMPLE_ID);
    List<Attachment> attachments = new ArrayList<>();
    ContentDisposition contentDisposition = new ContentDisposition("form-data; name=parse.resource; filename=C:\\DDF\\metacard.txt");
    Attachment attachment = new Attachment("parse.resource", new ByteArrayInputStream("Some Text".getBytes()), contentDisposition);
    attachments.add(attachment);
    ContentDisposition contentDisposition1 = new ContentDisposition("form-data; name=parse.metadata; filename=C:\\DDF\\metacard.xml");
    Attachment attachment1 = new Attachment("parse.metadata", new ByteArrayInputStream("Some Text Again".getBytes()), contentDisposition1);
    attachments.add(attachment1);
    ContentDisposition contentDisposition2 = new ContentDisposition("form-data; name=metadata; filename=C:\\DDF\\metacard.xml");
    Attachment attachment2 = new Attachment("metadata", new ByteArrayInputStream("<meta>beta</meta>".getBytes()), contentDisposition2);
    attachments.add(attachment2);
    MultipartBody multipartBody = new MultipartBody(attachments);
    Response response = rest.addDocument(headers, info, mock(HttpServletRequest.class), multipartBody, null, new ByteArrayInputStream("".getBytes()));
    LOGGER.debug(ToStringBuilder.reflectionToString(response));
    assertThat(response.getStatus(), equalTo(201));
    assertThat(response.getMetadata(), notNullValue());
    assertThat(response.getMetadata().get(Metacard.ID).get(0).toString(), equalTo(SAMPLE_ID));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) MimeTypeMapper(ddf.mime.MimeTypeMapper) ArrayList(java.util.ArrayList) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) InputTransformer(ddf.catalog.transform.InputTransformer) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ServiceReference(org.osgi.framework.ServiceReference) QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) ContentDisposition(org.apache.cxf.jaxrs.ext.multipart.ContentDisposition) ByteArrayInputStream(java.io.ByteArrayInputStream) MultipartBody(org.apache.cxf.jaxrs.ext.multipart.MultipartBody) CatalogFramework(ddf.catalog.CatalogFramework) UriInfo(javax.ws.rs.core.UriInfo) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 3 with UuidGenerator

use of org.codice.ddf.platform.util.uuidgenerator.UuidGenerator in project ddf by codice.

the class FederationStrategyTest method testQueryTimeout.

/**
     * Tests that the framework properly times out using the default federation strategy.
     */
@Test
public void testQueryTimeout() throws Exception {
    long queryDelay = 100;
    UuidGenerator uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    MockDelayProvider provider = new MockDelayProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
    provider.setQueryDelayMillis(queryDelay);
    // Mock register the provider in the container
    SourcePollerRunner runner = new SourcePollerRunner();
    SourcePoller poller = new SourcePoller(runner);
    runner.bind(provider);
    // Must have more than one thread or sleeps will block the monitor
    SortedFederationStrategy fedStrategy = new SortedFederationStrategy(executor, new ArrayList<>(), new ArrayList<>());
    FrameworkProperties props = new FrameworkProperties();
    props.setCatalogProviders(Collections.singletonList(provider));
    props.setFederationStrategy(fedStrategy);
    props.setSourcePoller(poller);
    props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    props.setFilterBuilder(new GeotoolsFilterBuilder());
    props.setDefaultAttributeValueRegistry(new DefaultAttributeValueRegistryImpl());
    OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
    MetacardFactory metacardFactory = new MetacardFactory(props.getMimeTypeToTransformerMapper(), uuidGenerator);
    OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(props, metacardFactory);
    Historian historian = new Historian();
    historian.setHistoryEnabled(false);
    SourceOperations sourceOperations = new SourceOperations(props);
    QueryOperations queryOperations = new QueryOperations(props, sourceOperations, opsSecurity, opsMetacard);
    OperationsStorageSupport opsStorage = new OperationsStorageSupport(sourceOperations, queryOperations);
    OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(props, sourceOperations);
    CreateOperations createOperations = new CreateOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
    UpdateOperations updateOperations = new UpdateOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
    DeleteOperations deleteOperations = new DeleteOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard);
    opsStorage.setHistorian(historian);
    updateOperations.setHistorian(historian);
    deleteOperations.setHistorian(historian);
    deleteOperations.setOpsCatStoreSupport(opsCatStore);
    CatalogFrameworkImpl framework = new CatalogFrameworkImpl(createOperations, updateOperations, deleteOperations, queryOperations, null, null, null);
    sourceOperations.bind(provider);
    List<Metacard> metacards = new ArrayList<Metacard>();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    metacards.add(newCard);
    CreateResponse createResponse = null;
    try {
        try {
            createResponse = framework.create(new CreateRequestImpl(metacards, null));
        } catch (SourceUnavailableException e) {
            long timeout = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10);
            //this is a hack because the unit test is flaky and should be removed once a better test is possible
            while (System.currentTimeMillis() < timeout) {
                Thread.sleep(1000);
                try {
                    createResponse = framework.create(new CreateRequestImpl(metacards, null));
                    break;
                } catch (SourceUnavailableException e1) {
                //ignore
                }
            }
        }
        if (createResponse == null) {
            fail();
        }
    } catch (IngestException e) {
        fail();
    }
    assertEquals(createResponse.getCreatedMetacards().size(), provider.size());
    for (Metacard curCard : createResponse.getCreatedMetacards()) {
        assertNotNull(curCard.getId());
    }
    QueryImpl query = new QueryImpl(filterFactory.equals(filterFactory.property(Metacard.ID), filterFactory.literal(createResponse.getCreatedMetacards().get(0).getId())));
    query.setTimeoutMillis(SHORT_TIMEOUT);
    query.setSortBy(new FilterFactoryImpl().sort(Result.RELEVANCE, SortOrder.ASCENDING));
    QueryRequest fedQueryRequest = new QueryRequestImpl(query);
    try {
        QueryResponse response = framework.query(fedQueryRequest);
        assertEquals("Timeout should happen before results return", 0, response.getHits());
    } catch (UnsupportedQueryException e) {
        fail();
    } catch (FederationException e) {
        LOGGER.error("Unexpected federation exception during test", e);
        fail();
    }
}
Also used : OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) ContentType(ddf.catalog.data.ContentType) CreateResponse(ddf.catalog.operation.CreateResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) QueryResponsePostProcessor(ddf.catalog.impl.QueryResponsePostProcessor) SourcePoller(ddf.catalog.util.impl.SourcePoller) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) QueryImpl(ddf.catalog.operation.impl.QueryImpl) OperationsStorageSupport(ddf.catalog.impl.operations.OperationsStorageSupport) SourcePollerRunner(ddf.catalog.util.impl.SourcePollerRunner) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) IngestException(ddf.catalog.source.IngestException) Historian(ddf.catalog.history.Historian) FrameworkProperties(ddf.catalog.impl.FrameworkProperties) DefaultAttributeValueRegistryImpl(ddf.catalog.data.defaultvalues.DefaultAttributeValueRegistryImpl) MockDelayProvider(ddf.catalog.impl.MockDelayProvider) SourceOperations(ddf.catalog.impl.operations.SourceOperations) QueryRequest(ddf.catalog.operation.QueryRequest) FederationException(ddf.catalog.federation.FederationException) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) CatalogFrameworkImpl(ddf.catalog.impl.CatalogFrameworkImpl) Metacard(ddf.catalog.data.Metacard) QueryOperations(ddf.catalog.impl.operations.QueryOperations) UpdateOperations(ddf.catalog.impl.operations.UpdateOperations) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) CreateOperations(ddf.catalog.impl.operations.CreateOperations) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with UuidGenerator

use of org.codice.ddf.platform.util.uuidgenerator.UuidGenerator in project alliance by codice.

the class RolloverStreamCreationPluginTest method testOnCreate.

@Test
public void testOnCreate() throws StreamCreationException {
    Context context = mock(Context.class);
    UdpStreamProcessor udpStreamProcessor = mock(UdpStreamProcessor.class);
    when(context.getUdpStreamProcessor()).thenReturn(udpStreamProcessor);
    when(udpStreamProcessor.getFilenameGenerator()).thenReturn(mock(FilenameGenerator.class));
    when(udpStreamProcessor.getFilenameTemplate()).thenReturn("template");
    when(udpStreamProcessor.getCatalogFramework()).thenReturn(mock(CatalogFramework.class));
    when(udpStreamProcessor.getParentMetacardUpdater()).thenReturn(mock(MetacardUpdater.class));
    UuidGenerator uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn("anId");
    when(udpStreamProcessor.getUuidGenerator()).thenReturn(uuidGenerator);
    RolloverStreamCreationPlugin rolloverStreamCreationPlugin = new RolloverStreamCreationPlugin();
    rolloverStreamCreationPlugin.onCreate(context);
    verify(udpStreamProcessor).setRolloverAction(any());
}
Also used : Context(org.codice.alliance.video.stream.mpegts.Context) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) MetacardUpdater(org.codice.alliance.video.stream.mpegts.metacard.MetacardUpdater) FilenameGenerator(org.codice.alliance.video.stream.mpegts.filename.FilenameGenerator) CatalogFramework(ddf.catalog.CatalogFramework) UdpStreamProcessor(org.codice.alliance.video.stream.mpegts.netty.UdpStreamProcessor) Test(org.junit.Test)

Example 5 with UuidGenerator

use of org.codice.ddf.platform.util.uuidgenerator.UuidGenerator in project ddf by codice.

the class RemoteDeleteOperationsTest method setUpMocks.

private void setUpMocks() throws IOException, CatalogTransformerException {
    String localProviderName = "ddf";
    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));
    mockSourceActionRegistry = mock(ActionRegistry.class);
    when(mockSourceActionRegistry.list(any())).thenReturn(Collections.emptyList());
}
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) ActionRegistry(ddf.action.ActionRegistry) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MimeType(javax.activation.MimeType) MimeTypeResolver(ddf.mime.MimeTypeResolver) CatalogProvider(ddf.catalog.source.CatalogProvider)

Aggregations

UuidGenerator (org.codice.ddf.platform.util.uuidgenerator.UuidGenerator)20 Before (org.junit.Before)11 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)10 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 CatalogFramework (ddf.catalog.CatalogFramework)6 InputTransformer (ddf.catalog.transform.InputTransformer)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ActionRegistry (ddf.action.ActionRegistry)3 Metacard (ddf.catalog.data.Metacard)3 DefaultAttributeValueRegistryImpl (ddf.catalog.data.defaultvalues.DefaultAttributeValueRegistryImpl)3 Historian (ddf.catalog.history.Historian)3 CreateOperations (ddf.catalog.impl.operations.CreateOperations)3 DeleteOperations (ddf.catalog.impl.operations.DeleteOperations)3 MetacardFactory (ddf.catalog.impl.operations.MetacardFactory)3 OperationsCatalogStoreSupport (ddf.catalog.impl.operations.OperationsCatalogStoreSupport)3 QueryResponse (ddf.catalog.operation.QueryResponse)3 PostIngestPlugin (ddf.catalog.plugin.PostIngestPlugin)3