Search in sources :

Example 6 with UuidGenerator

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

the class ContentProducerDataAccessObjectTest method setUp.

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

Example 7 with UuidGenerator

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

the class HistorianTest method setup.

@Before
public void setup() {
    historian = new Historian();
    uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    historian.setUuidGenerator(uuidGenerator);
    catalogProvider = mock(CatalogProvider.class);
    historian.setCatalogProviders(Collections.singletonList(catalogProvider));
    storageProvider = new InMemoryStorageProvider();
    historian.setStorageProviders(Collections.singletonList(storageProvider));
    historian.setMetacardTypes(Collections.singletonList(MetacardImpl.BASIC_METACARD));
    SubjectIdentity subjectIdentity = mock(SubjectIdentity.class);
    when(subjectIdentity.getUniqueIdentifier(any())).thenReturn("test");
    historian.setSubjectIdentity(subjectIdentity);
    SubjectOperations subjectOperations = mock(SubjectOperations.class);
    when(subjectOperations.getEmailAddress(any(Subject.class))).thenReturn("test@test.com");
    when(subjectOperations.getName(any(Subject.class))).thenReturn("test");
    historian.setSubjectOperations(subjectOperations);
    historian.setSecurityLogger(mock(SecurityLogger.class));
    Security security = mock(Security.class);
    Subject subject = mock(MockSubject.class);
    when(subject.execute(any(Callable.class))).thenCallRealMethod();
    when(security.runAsAdmin(any(PrivilegedAction.class))).thenReturn(subject);
    historian.setSecurity(security);
}
Also used : SubjectOperations(ddf.security.SubjectOperations) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) CatalogProvider(ddf.catalog.source.CatalogProvider) PrivilegedAction(java.security.PrivilegedAction) SubjectIdentity(ddf.security.SubjectIdentity) Security(org.codice.ddf.security.Security) Subject(ddf.security.Subject) Callable(java.util.concurrent.Callable) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Example 8 with UuidGenerator

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

the class CatalogServiceImplTest method testAddDocumentWithAttributeOverrides.

@Test
@SuppressWarnings({ "unchecked" })
public void testAddDocumentWithAttributeOverrides() throws Exception {
    CatalogFramework framework = givenCatalogFramework();
    AttributeDescriptor descriptor = new AttributeDescriptorImpl("custom.attribute", true, true, false, false, BasicTypes.STRING_TYPE);
    HttpHeaders headers = createHeaders(Collections.singletonList(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);
    when(attributeRegistry.lookup("custom.attribute")).thenReturn(Optional.of(descriptor));
    CatalogServiceImpl catalogService = new CatalogServiceImpl(framework, attachmentParser, attributeRegistry) {

        @Override
        protected BundleContext getBundleContext() {
            return bundleContext;
        }
    };
    UuidGenerator uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    catalogService.setUuidGenerator(uuidGenerator);
    addMatchingService(catalogService, Collections.singletonList(getSimpleTransformer()));
    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 contentDisposition2 = new ContentDisposition("form-data; name=custom.attribute; ");
    Attachment attachment2 = new Attachment(descriptor.getName(), new ByteArrayInputStream("CustomValue".getBytes()), contentDisposition2);
    attachments.add(attachment2);
    MultipartBody multipartBody = new MultipartBody(attachments);
    String response = catalogService.addDocument(headers.getRequestHeader(HttpHeaders.CONTENT_TYPE), multipartBody, null, new ByteArrayInputStream("".getBytes()));
    LOGGER.debug(ToStringBuilder.reflectionToString(response));
    ArgumentCaptor<CreateStorageRequest> captor = ArgumentCaptor.forClass(CreateStorageRequest.class);
    verify(framework, times(1)).create(captor.capture());
    assertThat(captor.getValue().getContentItems().get(0).getMetacard().getMetacardType().getAttributeDescriptor(descriptor.getName()), equalTo(descriptor));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InputTransformer(ddf.catalog.transform.InputTransformer) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ServiceReference(org.osgi.framework.ServiceReference) ContentDisposition(org.apache.cxf.jaxrs.ext.multipart.ContentDisposition) ByteArrayInputStream(java.io.ByteArrayInputStream) MultipartBody(org.apache.cxf.jaxrs.ext.multipart.MultipartBody) CatalogFramework(ddf.catalog.CatalogFramework) BundleContext(org.osgi.framework.BundleContext) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Test(org.junit.Test)

Example 9 with UuidGenerator

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

the class CatalogServiceImplTest method testAddDocumentWithMetadataNoMcardId.

@Test
@SuppressWarnings({ "unchecked" })
public void testAddDocumentWithMetadataNoMcardId() throws Exception {
    MetacardImpl inputMcard = new MetacardImpl();
    UuidGenerator uuidGenerator = mock(UuidGenerator.class);
    String response = mcardIdTest(inputMcard, uuidGenerator);
    assertThat(response, notNullValue());
    verify(uuidGenerator, times(1)).generateUuid();
}
Also used : UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 10 with UuidGenerator

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

the class GeoNamesCatalogIndexerTest method setUp.

@Before
public void setUp() throws Exception {
    geoEntryCreator = mock(GeoEntryCreator.class);
    when(geoEntryCreator.createGeoEntry(anyString(), anyString())).thenReturn(GEO_ENTRY);
    geoEntryExtractor = new GeoNamesFileExtractor();
    geoEntryExtractor.setGeoEntryCreator(geoEntryCreator);
    catalogFramework = mock(CatalogFramework.class);
    uuidGenerator = mock(UuidGenerator.class);
    createResponse = mock(CreateResponse.class);
    when(createResponse.getCreatedMetacards()).thenReturn(Collections.singletonList(METACARD));
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    catalogProvider = mock(CatalogProvider.class);
    DeleteResponse deleteResponse = mock(DeleteResponse.class);
    when(deleteResponse.getDeletedMetacards()).thenReturn(Collections.singletonList(METACARD));
    when(catalogProvider.delete(any(DeleteRequest.class))).thenReturn(deleteResponse);
    queryResponse = mock(QueryResponse.class);
    when(queryResponse.getResults()).thenReturn(Collections.singletonList(new ResultImpl(new MetacardImpl())));
    when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponse);
    progressCallback = progress -> {
    };
    geoNamesCatalogIndexer = new GeoNamesCatalogIndexer(catalogFramework, uuidGenerator, new GeoEntryAttributes(), new GeotoolsFilterBuilder(), Collections.singletonList(catalogProvider));
}
Also used : UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) QueryRequest(ddf.catalog.operation.QueryRequest) GeoEntryAttributes(org.codice.ddf.spatial.geocoding.GeoEntryAttributes) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequest(ddf.catalog.operation.CreateRequest) ResultImpl(ddf.catalog.data.impl.ResultImpl) GeoEntryCreator(org.codice.ddf.spatial.geocoding.GeoEntryCreator) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeoNamesFileExtractor(org.codice.ddf.spatial.geocoding.extract.GeoNamesFileExtractor) CatalogFramework(ddf.catalog.CatalogFramework) DeleteRequest(ddf.catalog.operation.DeleteRequest) Before(org.junit.Before)

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