@Test public void shouldSendEventWhenProviderWasUpdated() { Type type = new TypeToken<TaskDataProvider>() {}.getType(); List<TaskDataProviderObject> objects = new ArrayList<>(); List<LookupFieldsParameter> lookupFields = asList(new LookupFieldsParameter("lookupField",asList("lookupField"))); List<FieldParameter> fields = asList(new FieldParameter("displayName", "fieldKey")); objects.add(new TaskDataProviderObject("displayName", "type", lookupFields, fields)); TaskDataProvider provider = new TaskDataProvider(PROVIDER_NAME, objects); List<TaskDataProviderObject> updatedObjects = new ArrayList<>(objects); updatedObjects.add(new TaskDataProviderObject("displayName2", "type2", lookupFields, fields)); TaskDataProvider updatedProvider = new TaskDataProvider(PROVIDER_NAME, updatedObjects); when(motechJsonReader.readFromStream(inputStream, type)).thenReturn(updatedProvider); when(dataProviderDataService.findByName(PROVIDER_NAME)).thenReturn(provider); ArgumentCaptor<MotechEvent> captor = ArgumentCaptor.forClass(MotechEvent.class); taskDataProviderService.registerProvider(inputStream); ArgumentCaptor<TaskDataProvider> taskDataProviderArgumentCaptor = ArgumentCaptor.forClass(TaskDataProvider.class); verify(dataProviderDataService).update(taskDataProviderArgumentCaptor.capture()); assertEquals(PROVIDER_NAME, taskDataProviderArgumentCaptor.getValue().getName()); verify(dataProviderDataService).update(provider); verify(eventRelay).sendEventMessage(captor.capture()); MotechEvent event = captor.getValue(); assertEquals(DATA_PROVIDER_UPDATE_SUBJECT, event.getSubject()); assertEquals(PROVIDER_NAME, event.getParameters().get(DATA_PROVIDER_NAME)); }
@Override @Transactional public void registerProvider(final String body) { byte[] bytes = body.getBytes(Charset.forName("UTF-8")); InputStream stream = new ByteArrayInputStream(bytes); registerProvider(stream); }
TaskDataProviderServiceImpl implements TaskDataProviderService, OsgiServiceLifecycleListener { @Override @Transactional public void registerProvider(final String body) { byte[] bytes = body.getBytes(Charset.forName("UTF-8")); InputStream stream = new ByteArrayInputStream(bytes); registerProvider(stream); } }
TaskDataProviderServiceImpl implements TaskDataProviderService, OsgiServiceLifecycleListener { @Override @Transactional public void registerProvider(final String body) { byte[] bytes = body.getBytes(Charset.forName("UTF-8")); InputStream stream = new ByteArrayInputStream(bytes); registerProvider(stream); } @Autowired  TaskDataProviderServiceImpl(EventRelay eventRelay);  TaskDataProviderServiceImpl(EventRelay eventRelay, MotechJsonReader motechJsonReader); }
TaskDataProviderServiceImpl implements TaskDataProviderService, OsgiServiceLifecycleListener { @Override @Transactional public void registerProvider(final String body) { byte[] bytes = body.getBytes(Charset.forName("UTF-8")); InputStream stream = new ByteArrayInputStream(bytes); registerProvider(stream); } @Autowired  TaskDataProviderServiceImpl(EventRelay eventRelay);  TaskDataProviderServiceImpl(EventRelay eventRelay, MotechJsonReader motechJsonReader); @Override @Transactional void registerProvider(final String body); @Override @Transactional void registerProvider(final InputStream stream); @Override @Transactional TaskDataProvider getProvider(String name); @Override @Transactional TaskDataProvider getProviderById(Long providerId); @Override @Transactional List<TaskDataProvider> getProviders(); @Override @Transactional void bind(Object service, Map properties); @Override void unbind(Object service, Map properties); @Override @Transactional void unregister(String providerName); }
TaskDataProviderServiceImpl implements TaskDataProviderService, OsgiServiceLifecycleListener { @Override @Transactional public void registerProvider(final String body) { byte[] bytes = body.getBytes(Charset.forName("UTF-8")); InputStream stream = new ByteArrayInputStream(bytes); registerProvider(stream); } @Autowired  TaskDataProviderServiceImpl(EventRelay eventRelay);  TaskDataProviderServiceImpl(EventRelay eventRelay, MotechJsonReader motechJsonReader); @Override @Transactional void registerProvider(final String body); @Override @Transactional void registerProvider(final InputStream stream); @Override @Transactional TaskDataProvider getProvider(String name); @Override @Transactional TaskDataProvider getProviderById(Long providerId); @Override @Transactional List<TaskDataProvider> getProviders(); @Override @Transactional void bind(Object service, Map properties); @Override void unbind(Object service, Map properties); @Override @Transactional void unregister(String providerName);  }