### Question:
DatabaseMetadataService { @GET @Produces( MediaType.APPLICATION_JSON ) public Response getRelationshipTypes( @QueryParam( "in_use" ) @DefaultValue( "true" ) boolean inUse ) { try { GraphDatabaseAPI db = database.getGraph(); Iterable<RelationshipType> relationshipTypes = inUse ? db.getAllRelationshipTypesInUse() : db.getAllRelationshipTypes(); return Response.ok() .type( MediaType.APPLICATION_JSON ) .entity( generateJsonRepresentation( relationshipTypes ) ) .build(); } finally { representationWriteHandler.onRepresentationFinal(); } } DatabaseMetadataService( @Context Database database ); @GET @Produces( MediaType.APPLICATION_JSON ) Response getRelationshipTypes( @QueryParam( "in_use" ) @DefaultValue( "true" ) boolean inUse ); void setRepresentationWriteHandler( RepresentationWriteHandler representationWriteHandler );  }### Answer:
@Test public void shouldAdvertiseRelationshipTypesThatCurrentlyExistInTheDatabase() throws Throwable { try ( Transaction tx = db.beginTx() ) { db.getRelationshipById( relId ).delete(); tx.success(); } Database database = new WrappedDatabase( db ); DatabaseMetadataService service = new DatabaseMetadataService( database ); try ( Transaction tx = db.beginTx() ) { Response response = service.getRelationshipTypes( false ); assertEquals( 200, response.getStatus() ); List<Map<String,Object>> jsonList = JsonHelper.jsonToList( response.getEntity() .toString() ); assertEquals( 3, jsonList.size() ); } database.stop(); }
@Test public void shouldAdvertiseRelationshipTypesThatCurrentlyInUseInTheDatabase() throws Throwable { try ( Transaction tx = db.beginTx() ) { db.getRelationshipById( relId ).delete(); tx.success(); } Database database = new WrappedDatabase( db ); DatabaseMetadataService service = new DatabaseMetadataService( database ); try ( Transaction tx = db.beginTx() ) { Response response = service.getRelationshipTypes( true ); assertEquals( 200, response.getStatus() ); List<Map<String,Object>> jsonList = JsonHelper.jsonToList( response.getEntity() .toString() ); assertEquals( 2, jsonList.size() ); } database.stop(); }