### Question:
ApplicationV1FilterTransformer { public void transformJson(final JsonValue jsonValue, final Subject callingSubject, final String realm) throws EntitlementException { final Map<String, Boolean> actions = new HashMap<>(); final Set<String> resources = new HashSet<>(); final Set<String> resourceTypeUuids = jsonValue .get(RESOURCE_TYPE_UUIDS) .required() .asSet(String.class); for (String resourceTypeUuid : resourceTypeUuids) { final ResourceType resourceType = resourceTypeService .getResourceType(callingSubject, realm, resourceTypeUuid); if (resourceType == null) { throw new EntitlementException(EntitlementException.NO_SUCH_RESOURCE_TYPE, resourceTypeUuid); } actions.putAll(resourceType.getActions()); resources.addAll(resourceType.getPatterns()); } jsonValue.remove(RESOURCE_TYPE_UUIDS); jsonValue.remove(APPLICATION_DISPLAY_NAME); jsonValue.add(ACTIONS, actions); jsonValue.add(RESOURCES, resources); jsonValue.add(REALM, realm); } @Inject  ApplicationV1FilterTransformer(ContextHelper contextHelper, ResourceTypeService resourceTypeService,
            ExceptionMappingHandler<EntitlementException, ResourceException> resourceErrorHandler); void transformJson(final JsonValue jsonValue, final Subject callingSubject, final String realm); Promise<ResourceResponse, ResourceException> transform(Promise<ResourceResponse, ResourceException> promise,
                                                                   final Context context); Promise<QueryResponse, ResourceException> transform(Promise<QueryResponse, ResourceException> promise,
                                                                final Context context, final QueryRequest request,
                                                                final QueryResourceHandler handler,
                                                                final Collection<ResourceResponse> resources);  }### Answer:
@Test (expectedExceptions = JsonValueException.class) public void failWithNoUUIDs() throws EntitlementException { JsonValue jsonValue = json(object(field("noUUID", "no, really"))); Subject subject = new Subject(); transformer.transformJson(jsonValue, subject, "realm"); }
@Test (expectedExceptions = EntitlementException.class) public void failWithNoResourceType() throws EntitlementException { JsonValue jsonValue = json(object(field(RESOURCE_TYPE_UUIDS, array("abc-def-ghi", "def-ghj-kli")))); Subject subject = new Subject(); given(mockResourceTypeService.getResourceType(eq(subject), eq("realm"), eq("abc-def-ghi"))) .willReturn(null); transformer.transformJson(jsonValue, subject, "realm"); }
@Test public void testSuccessfulTransformation() throws EntitlementException { JsonValue jsonValue = json(object(field(RESOURCE_TYPE_UUIDS, array("abc-def-ghi", "def-ghj-kli")))); Subject subject = new Subject(); ResourceType resourceType = ResourceType.builder().setName("name").setUUID("uuid").addAction("action", true) .addPattern("pattern").build(); ResourceType resourceType2 = ResourceType.builder().setName("name2").setUUID("uuid2").addAction("action2", true) .addPattern("pattern2").build(); given(mockResourceTypeService.getResourceType(eq(subject), eq("realm"), eq("abc-def-ghi"))) .willReturn(resourceType); given(mockResourceTypeService.getResourceType(eq(subject), eq("realm"), eq("def-ghj-kli"))) .willReturn(resourceType2); transformer.transformJson(jsonValue, subject, "realm"); assertTrue(jsonValue.get(RESOURCE_TYPE_UUIDS).isNull()); assertTrue(jsonValue.get("actions").get("action").asBoolean()); assertTrue(jsonValue.get("actions").get("action2").asBoolean()); assertTrue(jsonValue.get("resources").contains("pattern")); assertTrue(jsonValue.get("resources").contains("pattern2")); }