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