@Test public void shouldRegisterProviderFromString() throws IOException { String fieldParameterAsJson = "{ displayName: 'displayName', fieldKey: 'fieldKey' }"; String lookupFieldsAsJson = "['lookupField']"; String objectAsJson = String.format("{ displayName: 'displayName', type: 'type', lookupFields: %s, fields: [%s]}", lookupFieldsAsJson, fieldParameterAsJson); String providerAsJson = String.format("{ name: '%s', objects: [%s] }", PROVIDER_NAME, objectAsJson); Type type = new TypeToken<TaskDataProvider>() { }.getType(); StringWriter writer = new StringWriter(); List<LookupFieldsParameter> lookupFields = asList(new LookupFieldsParameter("lookupField", asList("lookupField"))); List<FieldParameter> fields = asList(new FieldParameter("displayName", "fieldKey")); List<TaskDataProviderObject> objects = new ArrayList<>(); objects.add(new TaskDataProviderObject("displayName", "type", lookupFields, fields)); TaskDataProvider provider = new TaskDataProvider(PROVIDER_NAME, objects); when(motechJsonReader.readFromStream(any(InputStream.class), eq(type))).thenReturn(provider); taskDataProviderService.registerProvider(providerAsJson); ArgumentCaptor<InputStream> captor = ArgumentCaptor.forClass(InputStream.class); verify(motechJsonReader).readFromStream(captor.capture(), eq(type)); verify(dataProviderDataService).create(provider); InputStream value = captor.getValue(); IOUtils.copy(value, writer); assertTrue(value instanceof ByteArrayInputStream); assertEquals(providerAsJson, writer.toString()); }
@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);  }