use of com.entwinemedia.fn.data.json.SimpleSerializer in project opencast by opencast.
the class JSONUtilsTest method testFiltersToJSON.
/**
* Test method for
* {@link JSONUtils#filtersToJSON(org.opencastproject.index.service.resources.list.api.ResourceListQuery, org.opencastproject.index.service.resources.list.api.ListProvidersService, org.opencastproject.security.api.Organization)}
* (filters, listProviderService, query, org)}
*/
@Test
public void testFiltersToJSON() throws Exception {
String expectedJSON = IOUtils.toString(getClass().getResource("/filters.json"));
JaxbOrganization defaultOrganization = new DefaultOrganization();
ListProvidersServiceImpl listProvidersService = new ListProvidersServiceImpl();
SimpleSerializer serializer = new SimpleSerializer();
final Map<String, String> license = new HashMap<String, String>();
license.put("contributor1", "My first contributor");
license.put("contributor2", "My second contributor");
license.put("contributor3", "My third contributor");
// Create test list provider
listProvidersService.addProvider(new ResourceListProvider() {
@Override
public String[] getListNames() {
return new String[] { ContributorsListProvider.DEFAULT };
}
@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
return ListProviderUtil.filterMap(license, query);
}
@Override
public boolean isTranslatable(String listName) {
return false;
}
@Override
public String getDefault() {
return null;
}
});
// Prepare mock query
List<ResourceListFilter<?>> filters = new ArrayList<ResourceListFilter<?>>();
filters.add(SeriesListQuery.createContributorsFilter(Option.<String>none()));
filters.add(new StringListFilter(""));
ResourceListQueryImpl query = EasyMock.createNiceMock(ResourceListQueryImpl.class);
EasyMock.expect(query.getAvailableFilters()).andReturn(filters).anyTimes();
EasyMock.expect(query.getFilters()).andReturn(new ArrayList<ResourceListFilter<?>>()).anyTimes();
EasyMock.expect(query.getLimit()).andReturn(Option.<Integer>none()).anyTimes();
EasyMock.expect(query.getOffset()).andReturn(Option.<Integer>none()).anyTimes();
EasyMock.replay(query);
JValue result = JSONUtils.filtersToJSON(query, listProvidersService, defaultOrganization);
StreamingOutput stream = RestUtils.stream(serializer.fn.toJson(result));
ByteArrayOutputStream resultStream = new ByteArrayOutputStream();
try {
stream.write(resultStream);
assertThat(expectedJSON, SameJSONAs.sameJSONAs(resultStream.toString()));
} finally {
IOUtils.closeQuietly(resultStream);
}
}
use of com.entwinemedia.fn.data.json.SimpleSerializer in project opencast by opencast.
the class SeriesRestService method getSeriesElements.
@GET
@Path("{seriesId}/elements.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getSeriesElements", description = "Returns all the element types of a series", returnDescription = "Returns a JSON array with all the types of elements of the given series.", pathParameters = { @RestParameter(name = "seriesId", description = "The series identifier", type = STRING, isRequired = true) }, reponses = { @RestResponse(responseCode = SC_OK, description = "Series found"), @RestResponse(responseCode = SC_NOT_FOUND, description = "Series not found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error while processing the request") })
public Response getSeriesElements(@PathParam("seriesId") String seriesId) {
try {
Opt<Map<String, byte[]>> optSeriesElements = seriesService.getSeriesElements(seriesId);
if (optSeriesElements.isSome()) {
Map<String, byte[]> seriesElements = optSeriesElements.get();
JValue jsonArray = Jsons.arr(Stream.$(seriesElements.keySet()).map(Jsons.Functions.stringToJValue));
return Response.ok(new SimpleSerializer().toJson(jsonArray)).build();
} else {
return R.notFound();
}
} catch (SeriesException e) {
logger.warn("Error while retrieving elements for sieres '{}': {}", seriesId, ExceptionUtils.getStackTrace(e));
return R.serverError();
}
}
use of com.entwinemedia.fn.data.json.SimpleSerializer in project opencast by opencast.
the class MetadataListTest method testLocked.
@Test
public void testLocked() throws WebApplicationException, Exception {
InputStream stream = SeriesEndpointTest.class.getResourceAsStream("/metadata-list-input-locked.json");
InputStreamReader reader = new InputStreamReader(stream);
JSONArray inputJson = (JSONArray) new JSONParser().parse(reader);
MetadataList metadataList = new MetadataList();
metadataList.add(episodeDublinCoreCatalogUIAdapter, episodeDublinCoreCatalogUIAdapter.getRawFields());
metadataList.setLocked(Locked.WORKFLOW_RUNNING);
assertThat(inputJson.toJSONString(), SameJSONAs.sameJSONAs(new SimpleSerializer().toJson(metadataList.toJSON())).allowingAnyArrayOrdering());
}
Aggregations