use of ddf.catalog.data.ContentType in project ddf by codice.
the class CatalogFrameworkImplTest method testNullFederatedQuery.
/**
* Tests that the framework properly throws a catalog exception when the federated query being
* passed in is null.
*
* @throws UnsupportedQueryException
*/
@Test(expected = UnsupportedQueryException.class)
public void testNullFederatedQuery() throws UnsupportedQueryException {
boolean isAvailable = false;
CatalogProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), isAvailable, new Date());
createDefaultFederatedSourceList(isAvailable);
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, null, true);
try {
framework.query(null, null);
} catch (FederationException e) {
fail();
} catch (SourceUnavailableException e) {
fail();
}
}
use of ddf.catalog.data.ContentType in project ddf by codice.
the class CatalogFrameworkImplTest method testNullEntriesCreate.
@Test(expected = IngestException.class)
public void testNullEntriesCreate() throws IngestException {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
// call framework with null request
try {
framework.create((CreateRequest) null);
} catch (SourceUnavailableException e) {
fail();
}
}
use of ddf.catalog.data.ContentType in project ddf by codice.
the class CatalogFrameworkImplTest method testNullQuery.
/**
* Tests that the framework properly throws a catalog exception when the query being passed in
* is null.
*
* @throws UnsupportedQueryException
*/
@Test(expected = UnsupportedQueryException.class)
public void testNullQuery() throws UnsupportedQueryException {
boolean isAvailable = false;
CatalogProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), isAvailable, new Date());
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, null, true);
try {
framework.query(null);
} catch (FederationException e) {
fail();
} catch (SourceUnavailableException e) {
fail();
}
}
use of ddf.catalog.data.ContentType in project ddf by codice.
the class TestRestEndpoint method testGetDocumentSourcesSuccess.
/**
* Tests getting source information
*
* @throws Exception
*/
@Test
public void testGetDocumentSourcesSuccess() throws Exception {
final String localSourceId = "local";
final String fed1SourceId = "fed1";
final String fed2SourceId = "fed2";
final String version = "4.0";
final String jsonMimeTypeString = "application/json";
Set<ContentType> contentTypes = new HashSet<ContentType>();
contentTypes.add(new ContentTypeImpl("ct1", "v1"));
contentTypes.add(new ContentTypeImpl("ct2", "v2"));
contentTypes.add(new ContentTypeImpl("ct3", null));
JSONArray contentTypesInJSON = new JSONArray();
for (ContentType ct : contentTypes) {
JSONObject ob = new JSONObject();
ob.put("name", ct.getName());
ob.put("version", ct.getVersion() != null ? ct.getVersion() : "");
contentTypesInJSON.add(ob);
}
Set<SourceDescriptor> sourceDescriptors = new HashSet<SourceDescriptor>();
SourceDescriptorImpl localDescriptor = new SourceDescriptorImpl(localSourceId, contentTypes);
localDescriptor.setVersion(version);
localDescriptor.setAvailable(true);
SourceDescriptorImpl fed1Descriptor = new SourceDescriptorImpl(fed1SourceId, contentTypes);
fed1Descriptor.setVersion(version);
fed1Descriptor.setAvailable(true);
SourceDescriptorImpl fed2Descriptor = new SourceDescriptorImpl(fed2SourceId, null);
fed2Descriptor.setAvailable(true);
sourceDescriptors.add(localDescriptor);
sourceDescriptors.add(fed1Descriptor);
sourceDescriptors.add(fed2Descriptor);
SourceInfoResponse sourceInfoResponse = new SourceInfoResponseImpl(null, null, sourceDescriptors);
CatalogFramework framework = mock(CatalogFramework.class);
when(framework.getSourceInfo(isA(SourceInfoRequestEnterprise.class))).thenReturn(sourceInfoResponse);
RESTEndpoint restEndpoint = new RESTEndpoint(framework);
Response response = restEndpoint.getDocument(null, null);
assertEquals(OK, response.getStatus());
assertEquals(jsonMimeTypeString, response.getMetadata().get("Content-Type").get(0));
String responseMessage = IOUtils.toString((ByteArrayInputStream) response.getEntity());
JSONArray srcList = (JSONArray) new JSONParser().parse(responseMessage);
assertEquals(3, srcList.size());
for (Object o : srcList) {
JSONObject src = (JSONObject) o;
assertEquals(true, src.get("available"));
String id = (String) src.get("id");
if (id.equals(localSourceId)) {
assertThat((Iterable<Object>) src.get("contentTypes"), hasItems(contentTypesInJSON.toArray()));
assertEquals(contentTypes.size(), ((JSONArray) src.get("contentTypes")).size());
assertEquals(version, src.get("version"));
} else if (id.equals(fed1SourceId)) {
assertThat((Iterable<Object>) src.get("contentTypes"), hasItems(contentTypesInJSON.toArray()));
assertEquals(contentTypes.size(), ((JSONArray) src.get("contentTypes")).size());
assertEquals(version, src.get("version"));
} else if (id.equals(fed2SourceId)) {
assertEquals(0, ((JSONArray) src.get("contentTypes")).size());
assertEquals("", src.get("version"));
} else {
fail("Invalid ID returned");
}
}
}
use of ddf.catalog.data.ContentType in project ddf by codice.
the class RESTEndpoint method getDocument.
/**
* REST Get. Retrieves information regarding sources available.
*
* @param uriInfo
* @param httpRequest
* @return
*/
@GET
@Path(SOURCES_PATH)
public Response getDocument(@Context UriInfo uriInfo, @Context HttpServletRequest httpRequest) {
BinaryContent content;
ResponseBuilder responseBuilder;
String sourcesString = null;
JSONArray resultsList = new JSONArray();
SourceInfoResponse sources;
try {
SourceInfoRequestEnterprise sourceInfoRequestEnterprise = new SourceInfoRequestEnterprise(true);
sources = catalogFramework.getSourceInfo(sourceInfoRequestEnterprise);
for (SourceDescriptor source : sources.getSourceInfo()) {
JSONObject sourceObj = new JSONObject();
sourceObj.put("id", source.getSourceId());
sourceObj.put("version", source.getVersion() != null ? source.getVersion() : "");
sourceObj.put("available", Boolean.valueOf(source.isAvailable()));
JSONArray contentTypesObj = new JSONArray();
if (source.getContentTypes() != null) {
for (ContentType contentType : source.getContentTypes()) {
if (contentType != null && contentType.getName() != null) {
JSONObject contentTypeObj = new JSONObject();
contentTypeObj.put("name", contentType.getName());
contentTypeObj.put("version", contentType.getVersion() != null ? contentType.getVersion() : "");
contentTypesObj.add(contentTypeObj);
}
}
}
sourceObj.put("contentTypes", contentTypesObj);
resultsList.add(sourceObj);
}
} catch (SourceUnavailableException e) {
LOGGER.info("Unable to retrieve Sources. {}", e.getMessage());
LOGGER.debug("Unable to retrieve Sources", e);
}
sourcesString = JSONValue.toJSONString(resultsList);
content = new BinaryContentImpl(new ByteArrayInputStream(sourcesString.getBytes(StandardCharsets.UTF_8)), jsonMimeType);
responseBuilder = Response.ok(content.getInputStream(), content.getMimeTypeValue());
// Add the Accept-ranges header to let the client know that we accept ranges in bytes
responseBuilder.header(HEADER_ACCEPT_RANGES, BYTES);
return responseBuilder.build();
}
Aggregations