GraphConfigurationServiceV2 implements IGraphConfigurationServiceV2 { @SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user") @Override public Response 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 Response.ok(fields) .header(GAFFER_MEDIA_TYPE_HEADER, GAFFER_MEDIA_TYPE) .build(); } GraphConfigurationServiceV2(); static void initialise(); @Override Response getSchema(); @Override Response getFilterFunction(); @SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user") @Override Response getFilterFunction(final String inputClass); @SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user") @Override Response getSerialisedFields(final String className); @SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user") @Override Response getSerialisedFieldClasses(final String className); @Override Response getDescription(); @Override Response getTransformFunctions(); @Override Response getStoreTraits(); @Override Response getElementGenerators(); @Override Response getObjectGenerators();  }
@Test public void shouldGetSerialisedFields() { final Set<String> fields = (Set<String>) service.getSerialisedFields(IsA.class.getName()).getEntity(); assertEquals(1, fields.size()); assertTrue(fields.contains("type")); }
@Test public void shouldGetSerialisedFieldsForGetElementsClass() { final Set<String> fields = (Set<String>) service.getSerialisedFields(GetElements.class.getName()).getEntity(); final Set<String> expectedFields = new HashSet<>(); expectedFields.add("input"); expectedFields.add("view"); expectedFields.add("includeIncomingOutGoing"); expectedFields.add("seedMatching"); expectedFields.add("options"); expectedFields.add("directedType"); expectedFields.add("views"); assertEquals(expectedFields, fields); }
@Test public void shouldThrowExceptionWhenGetSerialisedFieldsWithUnknownClassName() { try { service.getSerialisedFields("unknown className"); fail("Exception expected"); } catch (final IllegalArgumentException e) { assertNotNull(e.getMessage()); assertTrue(e.getMessage().contains("Class name was not recognised:")); } }