use of ddf.catalog.operation.SourceInfoRequest in project ddf by codice.
the class SourceOperationsTest method testGettingSourceActions.
@Test
public void testGettingSourceActions() throws SourceUnavailableException {
Action action = mock(Action.class);
FrameworkProperties frameworkProperties = mock(FrameworkProperties.class);
CatalogProvider catalogProvider = mock(CatalogProvider.class);
when(frameworkProperties.getCatalogProviders()).thenReturn(Collections.singletonList(catalogProvider));
ActionRegistry actionRegistry = mock(ActionRegistry.class);
when(actionRegistry.list(any(Source.class))).thenReturn(Collections.singletonList(action));
final SourcePoller<SourceStatus> mockStatusSourcePoller = mock(SourcePoller.class);
when(mockStatusSourcePoller.getCachedValueForSource(isA(Source.class))).thenReturn(Optional.empty());
SourceOperations sourceOperations = new SourceOperations(frameworkProperties, actionRegistry, mockStatusSourcePoller, mock(SourcePoller.class));
sourceOperations.bind((CatalogProvider) null);
SourceInfoRequest sourceInfoRequest = mock(SourceInfoRequest.class);
SourceInfoResponse sourceInfoResponse = sourceOperations.getSourceInfo(sourceInfoRequest, true);
assertThat(sourceInfoResponse.getSourceInfo(), hasSize(1));
SourceDescriptor sourceDescriptor = sourceInfoResponse.getSourceInfo().toArray(new SourceDescriptor[0])[0];
assertThat(sourceDescriptor.getActions(), is(Collections.singletonList(action)));
}
use of ddf.catalog.operation.SourceInfoRequest in project ddf by codice.
the class CatalogFrameworkImplTest method testGetSites.
@Test
public void testGetSites() {
framework.setId("ddf");
framework.getSourceOperations().setId("ddf");
Set<String> ids = new HashSet<String>();
for (FederatedSource source : federatedSources) {
ids.add(source.getId());
}
ids.add(framework.getId());
SourceInfoRequest request = new SourceInfoRequestSources(true, ids);
SourceInfoResponse response = null;
try {
response = framework.getSourceInfo(request);
} catch (SourceUnavailableException e) {
fail();
}
Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
List<String> siteNames = new ArrayList<String>();
for (SourceDescriptor descriptor : sourceDescriptors) {
LOGGER.debug("Descriptor id: {}", descriptor.getSourceId());
siteNames.add(descriptor.getSourceId());
}
// add a plus one for now to simulate that the framework is ad
// assertTrue( sourceDescriptor.containsAll( federatedSources ) );
// assertTrue( sourceDescriptor.containsAll( expectedSourceSet ) );
assertEquals(ids.size(), sourceDescriptors.size());
String[] expectedOrdering = { "A", "B", "C", framework.getId() };
assertArrayEquals(expectedOrdering, siteNames.toArray(new String[siteNames.size()]));
}
use of ddf.catalog.operation.SourceInfoRequest in project ddf by codice.
the class FanoutCatalogFrameworkTest method testNullContentTypesInGetSourceInfo.
/**
* This test is to verify that an NPE will not be thrown if {@code source.getContentTypes} returns
* null.
*
* @throws SourceUnavailableException
*/
@Test
public void testNullContentTypesInGetSourceInfo() throws SourceUnavailableException {
ArrayList<PostIngestPlugin> postIngestPlugins = new ArrayList<PostIngestPlugin>();
SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
List<FederatedSource> fedSources = new ArrayList<FederatedSource>();
FederatedSource mockFederatedSource = mock(FederatedSource.class);
when(mockFederatedSource.isAvailable()).thenReturn(true);
when(mockFederatedSource.getContentTypes()).thenReturn(Collections.emptySet());
fedSources.add(mockFederatedSource);
FrameworkProperties frameworkProperties = new FrameworkProperties();
frameworkProperties.setFederationStrategy(new MockFederationStrategy());
frameworkProperties.setPostIngest(postIngestPlugins);
List<FederatedSource> sourceList = new ArrayList<>(fedSources);
frameworkProperties.setFederatedSources(sourceList);
CatalogFrameworkImpl framework = createCatalogFramework(frameworkProperties);
// Assert not null simply to prove that we returned an object.
assertNotNull(framework.getSourceInfo(request));
}
use of ddf.catalog.operation.SourceInfoRequest in project ddf by codice.
the class SourceOperations method getFanoutSourceInfo.
/**
* Retrieves the {@link SourceDescriptor} info for all {@link FederatedSource}s in the fanout
* configuration, but the all of the source info, e.g., content types, for all of the available
* {@link FederatedSource}s is packed into one {@link SourceDescriptor} for the fanout
* configuration with the fanout's site name in it. This keeps the individual {@link
* FederatedSource}s' source info hidden from the external client.
*/
private SourceInfoResponse getFanoutSourceInfo(SourceInfoRequest sourceInfoRequest) throws SourceUnavailableException {
SourceInfoResponse response;
SourceDescriptorImpl sourceDescriptor;
try {
// request
if (sourceInfoRequest == null) {
throw new IllegalArgumentException("SourceInfoRequest was null");
}
Set<SourceDescriptor> sourceDescriptors = new LinkedHashSet<>();
Set<String> ids = sourceInfoRequest.getSourceIds();
// specified
if (ids != null) {
Optional<String> notLocal = ids.stream().filter(s -> !s.equals(getId())).findFirst();
if (notLocal.isPresent()) {
SourceUnavailableException sourceUnavailableException = new SourceUnavailableException("Unknown source: " + notLocal.get());
LOGGER.debug("Throwing SourceUnavailableException for unknown source: {}", notLocal.get(), sourceUnavailableException);
throw sourceUnavailableException;
}
}
// Fanout will only add one source descriptor with all the contents
// Using a List here instead of a Set because we should not rely on how Sources are compared
final List<Source> availableSources = frameworkProperties.getFederatedSources().stream().filter(this::isSourceAvailable).collect(Collectors.toList());
final Set<ContentType> contentTypes = availableSources.stream().map(source -> contentTypesCache.getCachedValueForSource(source).orElseGet(() -> {
LOGGER.debug("Unknown content types for source id={}", source.getId());
return Collections.emptySet();
})).flatMap(Collection::stream).collect(Collectors.toSet());
if (isSourceAvailable(catalog)) {
availableSources.add(catalog);
final Optional<Set<ContentType>> catalogContentTypes = contentTypesCache.getCachedValueForSource(catalog);
if (catalogContentTypes.isPresent()) {
contentTypes.addAll(catalogContentTypes.get());
} else {
LOGGER.debug("Unknown content types for the localSource");
}
}
List<Action> actions = getSourceActions(catalog);
// only reveal this sourceDescriptor, not the federated sources
sourceDescriptor = new SourceDescriptorImpl(this.getId(), contentTypes, actions);
if (this.getVersion() != null) {
sourceDescriptor.setVersion(this.getVersion());
}
sourceDescriptor.setAvailable(!availableSources.isEmpty());
sourceDescriptors.add(sourceDescriptor);
response = new SourceInfoResponseImpl(sourceInfoRequest, null, sourceDescriptors);
} catch (RuntimeException re) {
throw new SourceUnavailableException(GET_SOURCE_EXCEPTION_MSG, re);
}
return response;
}
use of ddf.catalog.operation.SourceInfoRequest in project ddf by codice.
the class CatalogFrameworkImplTest method testGetAllSiteNames.
@Test
public void testGetAllSiteNames() {
String frameworkName = "DDF";
CatalogProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
List<FederatedSource> federatedSources = createDefaultFederatedSourceList(true);
// Expected Set of Names
Set<String> expectedNameSet = new HashSet<String>();
for (FederatedSource curSite : federatedSources) {
expectedNameSet.add(curSite.getId());
}
expectedNameSet.add(frameworkName);
FrameworkProperties frameworkProperties = new FrameworkProperties();
frameworkProperties.setFederatedSources(federatedSources);
frameworkProperties.setCatalogProviders(Collections.singletonList(provider));
CatalogFrameworkImpl framework = createFramework(frameworkProperties);
framework.setId(frameworkName);
// Returned Set of Names
// Returned Sites
SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
SourceInfoResponse response = null;
try {
response = framework.getSourceInfo(request);
} catch (SourceUnavailableException e) {
LOGGER.debug("SourceUnavailable", e);
fail();
}
assert (response != null);
Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
// should contain the original federated sites and the framework
assertEquals(expectedNameSet.size(), sourceDescriptors.size());
Set<String> returnedSourceIds = new HashSet<String>();
for (SourceDescriptor sd : sourceDescriptors) {
returnedSourceIds.add(sd.getSourceId());
}
for (String id : returnedSourceIds) {
LOGGER.debug("returned sourceId: {}", id);
}
assertTrue(expectedNameSet.equals(returnedSourceIds));
}
Aggregations