GraphConfigurationService implements IGraphConfigurationService { @SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user") @Override public Set<String> getSerialisedFields(final String className) { final Class<?> clazz; try { clazz = Class.forName(SimpleClassNameIdResolver.getClassName(className)); } catch (final Exception e) { throw new IllegalArgumentException("Class name was not recognised: " + className, e); } final ObjectMapper mapper = new ObjectMapper(); final JavaType type = mapper.getTypeFactory().constructType(clazz); final BeanDescription introspection = mapper.getSerializationConfig().introspect(type); final List<BeanPropertyDefinition> properties = introspection.findProperties(); final Set<String> fields = new HashSet<>(); for (final BeanPropertyDefinition property : properties) { fields.add(property.getName()); } return fields; } GraphConfigurationService(); static void initialise(); @Override Schema getSchema(); @Override String getDescription(); @Override Set<Class> getFilterFunctions(); @SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user") @Override Set<Class> getFilterFunctions(final String inputClass); @SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user") @Override Set<String> getSerialisedFields(final String className); @Override Set<Class> getTransformFunctions(); @Override Set<StoreTrait> getStoreTraits(); @Override Set<Class> getNextOperations(final String operationClassName); @Override Set<Class> getElementGenerators(); @Override Set<Class> getObjectGenerators(); @Override Set<Class> getOperations(); @Override Boolean isOperationSupported(final Class operation);  }
@Test public void shouldGetSerialisedFields() throws IOException { final Set<String> fields = service.getSerialisedFields(IsA.class.getName()); assertEquals(1, fields.size()); assertTrue(fields.contains("type")); }
@Test public void shouldThrowExceptionWhenGetSerialisedFieldsWithUnknownClassName() throws IOException { try { service.getSerialisedFields("an unknown class name"); fail("Exception expected"); } catch (final IllegalArgumentException e) { assertNotNull(e.getMessage()); } }