TimelinePreviewsServiceImpl extends AbstractJobProducer implements
TimelinePreviewsService, ManagedService { @Override public void updated(Dictionary<String, ?> properties) throws ConfigurationException { if (properties == null) { return; } logger.debug("Configuring the timeline previews service"); if (properties.get(OPT_RESOLUTION_X) != null) { String res = (String) properties.get(OPT_RESOLUTION_X); try { resolutionX = Integer.parseInt(res); logger.info("Horizontal resolution set to {} pixels", resolutionX); } catch (Exception e) { throw new ConfigurationException(OPT_RESOLUTION_X, "Found illegal value '" + res + "' for timeline previews horizontal resolution"); } } if (properties.get(OPT_RESOLUTION_Y) != null) { String res = (String) properties.get(OPT_RESOLUTION_Y); try { resolutionY = Integer.parseInt(res); logger.info("Vertical resolution set to {} pixels", resolutionY); } catch (Exception e) { throw new ConfigurationException(OPT_RESOLUTION_Y, "Found illegal value '" + res + "' for timeline previews vertical resolution"); } } if (properties.get(OPT_OUTPUT_FORMAT) != null) { String format = (String) properties.get(OPT_OUTPUT_FORMAT); try { outputFormat = format; logger.info("Output file format set to \"{}\"", outputFormat); } catch (Exception e) { throw new ConfigurationException(OPT_OUTPUT_FORMAT, "Found illegal value '" + format + "' for timeline previews output file format"); } } if (properties.get(OPT_MIMETYPE) != null) { String type = (String) properties.get(OPT_MIMETYPE); try { mimetype = type; logger.info("Mime type set to \"{}\"", mimetype); } catch (Exception e) { throw new ConfigurationException(OPT_MIMETYPE, "Found illegal value '" + type + "' for timeline previews mimetype"); } } timelinepreviewsJobLoad = LoadUtil.getConfiguredLoadValue(properties, TIMELINEPREVIEWS_JOB_LOAD_KEY, DEFAULT_TIMELINEPREVIEWS_JOB_LOAD, serviceRegistry); } TimelinePreviewsServiceImpl(); @Override void activate(ComponentContext cc); @Override void updated(Dictionary<String, ?> properties); @Override Job createTimelinePreviewImages(Track track, int imageCount); void setSecurityService(SecurityService securityService); void setUserDirectoryService(
      UserDirectoryService userDirectoryService); void setOrganizationDirectoryService(
      OrganizationDirectoryService organizationDirectory); static final String COLLECTION_ID; static final String FFMPEG_BINARY_CONFIG; static final String FFMPEG_BINARY_DEFAULT; static final String OPT_RESOLUTION_X; static final int DEFAULT_RESOLUTION_X; static final String OPT_RESOLUTION_Y; static final int DEFAULT_RESOLUTION_Y; static final String OPT_OUTPUT_FORMAT; static final String DEFAULT_OUTPUT_FORMAT; static final String OPT_MIMETYPE; static final String DEFAULT_MIMETYPE; static final float DEFAULT_TIMELINEPREVIEWS_JOB_LOAD; static final String TIMELINEPREVIEWS_JOB_LOAD_KEY; }
@Test public void testUpdated() throws Exception { Dictionary<String, String> properties = new Hashtable<>(); properties.put(TimelinePreviewsServiceImpl.OPT_RESOLUTION_X, "200"); properties.put(TimelinePreviewsServiceImpl.OPT_RESOLUTION_Y, "90"); properties.put(TimelinePreviewsServiceImpl.OPT_OUTPUT_FORMAT, ".jpg"); properties.put(TimelinePreviewsServiceImpl.OPT_MIMETYPE, "image/jpg"); ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class); EasyMock.expect(serviceRegistry.getHostRegistrations()).andReturn(new ArrayList()); EasyMock.replay(serviceRegistry); TimelinePreviewsServiceImpl instance = new TimelinePreviewsServiceImpl(); instance.setServiceRegistry(serviceRegistry); try { instance.updated(properties); assertEquals(200, instance.resolutionX); assertEquals(90, instance.resolutionY); assertEquals(".jpg", instance.outputFormat); assertEquals("image/jpg", instance.mimetype); } catch (Exception e) { fail("updated method should not throw any exceptions but has thrown: " + ExceptionUtils.getStackTrace(e)); } }