WaveformServiceImpl extends AbstractJobProducer implements WaveformService, ManagedService { @Override protected String process(Job job) throws Exception { Operation op = null; String operation = job.getOperation(); List<String> arguments = job.getArguments(); try { op = Operation.valueOf(operation); switch (op) { case Waveform: Track track = (Track) MediaPackageElementParser.getFromXml(arguments.get(0)); int pixelsPerMinute = Integer.parseInt(arguments.get(1)); int minWidth = Integer.parseInt(arguments.get(2)); int maxWidth = Integer.parseInt(arguments.get(3)); int height = Integer.parseInt(arguments.get(4)); String color = arguments.get(5); Attachment waveformMpe = extractWaveform(track, pixelsPerMinute, minWidth, maxWidth, height, color); return MediaPackageElementParser.getAsXml(waveformMpe); default: throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'"); } } catch (IndexOutOfBoundsException e) { throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e); } catch (MediaPackageException | WaveformServiceException e) { throw new ServiceRegistryException("Error handling operation '" + op + "'", e); } } WaveformServiceImpl(); @Override void activate(ComponentContext cc); @Override void updated(Dictionary<String, ?> properties); @Override Job createWaveformImage(Track sourceTrack, int pixelsPerMinute, int minWidth, int maxWidth, int height, String color); void setServiceRegistry(ServiceRegistry serviceRegistry); void setSecurityService(SecurityService securityService); void setUserDirectoryService(UserDirectoryService userDirectoryService); void setOrganizationDirectoryService(OrganizationDirectoryService organizationDirectoryService); void setWorkspace(Workspace workspace); static final String WAVEFORM_JOB_LOAD_CONFIG_KEY; static final float DEFAULT_WAVEFORM_JOB_LOAD; static final String FFMPEG_BINARY_CONFIG_KEY; static final String DEFAULT_FFMPEG_BINARY; static final String DEFAULT_WAVEFORM_SCALE; static final String WAVEFORM_SCALE_CONFIG_KEY; static final boolean DEFAULT_WAVEFORM_SPLIT_CHANNELS; static final String WAVEFORM_SPLIT_CHANNELS_CONFIG_KEY; static final String[] DEFAULT_WAVEFORM_COLOR; static final String WAVEFORM_COLOR_CONFIG_KEY; static final String DEFAULT_WAVEFORM_FILTER_PRE; static final String WAVEFORM_FILTER_PRE_CONFIG_KEY; static final String DEFAULT_WAVEFORM_FILTER_POST; static final String WAVEFORM_FILTER_POST_CONFIG_KEY; static final String COLLECTION_ID; }
@Test public void testProcess() throws Exception { Workspace workspace = EasyMock.createNiceMock(Workspace.class); EasyMock.expect(workspace.get(EasyMock.anyObject())) .andReturn(new File(audioTrack.getURI())); Capture<String> filenameCapture = Capture.newInstance(); EasyMock.expect(workspace.putInCollection( EasyMock.anyString(), EasyMock.capture(filenameCapture), EasyMock.anyObject())) .andReturn(new URI("waveform.png")); EasyMock.replay(workspace); WaveformServiceImpl instance = new WaveformServiceImpl(); instance.setWorkspace(workspace); String audioTrackXml = MediaPackageElementParser.getAsXml(audioTrack); Job job = new JobImpl(1); job.setJobType(WaveformServiceImpl.JOB_TYPE); job.setOperation(WaveformServiceImpl.Operation.Waveform.toString()); job.setArguments(Arrays.asList(audioTrackXml, "200", "5000", "20000", "500", "black")); String result = instance.process(job); assertNotNull(result); MediaPackageElement waveformAttachment = MediaPackageElementParser.getFromXml(result); assertEquals(new URI("waveform.png"), waveformAttachment.getURI()); assertTrue(filenameCapture.hasCaptured()); }