GroupRest { @POST @RolesAllowed("admin") @ApiOperation("Create a new Mobi Group") @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.MULTIPART_FORM_DATA) public Response createGroup(@FormDataParam("title") String title, @FormDataParam("description") String description, @FormDataParam("roles") List<FormDataBodyPart> roles, @FormDataParam("members") List<FormDataBodyPart> members) { checkStringParam(title, "Group title is required"); try { if (engineManager.groupExists(title)) { throw ErrorUtils.sendError("Group " + title + " already exists", Response.Status.BAD_REQUEST); } GroupConfig.Builder builder = new GroupConfig.Builder(title); if (members != null && members.size() > 0) { builder.members(members.stream() .map(part -> engineManager.retrieveUser(part.getValue())) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toSet())); } if (description != null) { builder.description(description); } if (roles != null && roles.size() > 0) { Set<String> roleSet = roles.stream().map(FormDataBodyPart::getValue).collect(Collectors.toSet()); builder.roles(roleSet); } Group group = engineManager.createGroup(rdfEngine.getEngineName(), builder.build()); engineManager.storeGroup(rdfEngine.getEngineName(), group); logger.info("Created group " + title); Value createGroupTitle = group.getProperty(vf.createIRI(DCTERMS.TITLE.stringValue())).orElseThrow(() -> ErrorUtils.sendError("Group title must be present in created group", Response.Status.BAD_REQUEST)); return Response.status(201).entity(createGroupTitle.stringValue()).build(); } catch (IllegalArgumentException ex) { throw ErrorUtils.sendError(ex.getMessage(), Response.Status.BAD_REQUEST); } }  @GET @RolesAllowed("user") @Produces(MediaType.APPLICATION_JSON) @ApiOperation("Get all Mobi Groups") Response getGroups(); @POST @RolesAllowed("admin") @ApiOperation("Create a new Mobi Group") @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.MULTIPART_FORM_DATA) Response createGroup(@FormDataParam("title") String title,
                         @FormDataParam("description") String description,
                         @FormDataParam("roles") List<FormDataBodyPart> roles,
                         @FormDataParam("members") List<FormDataBodyPart> members); @GET @Path("{groupTitle}") @RolesAllowed("user") @Produces(MediaType.APPLICATION_JSON) @ApiOperation("Get a single Mobi Group") Response getGroup(@PathParam("groupTitle") String groupTitle); @PUT @Path("{groupTitle}") @RolesAllowed("admin") @ApiOperation("Update a Mobi Group's information") @Consumes(MediaType.APPLICATION_JSON) Response updateGroup(@PathParam("groupTitle") String groupTitle, String newGroupStr); @DELETE @Path("{groupTitle}") @RolesAllowed("admin") @ApiOperation("Remove a Mobi Group") Response deleteGroup(@PathParam("groupTitle") String groupTitle); @GET @Path("{groupTitle}/roles") @RolesAllowed("user") @Produces(MediaType.APPLICATION_JSON) @ApiOperation("List roles of a Mobi Group") Response getGroupRoles(@PathParam("groupTitle") String groupTitle); @PUT @Path("{groupTitle}/roles") @RolesAllowed("admin") @ApiOperation("Add roles to a Mobi Group") Response addGroupRoles(@PathParam("groupTitle") String groupTitle, @QueryParam("roles") List<String> roles); @DELETE @Path("{groupTitle}/roles") @RolesAllowed("admin") @ApiOperation("Remove role from a Mobi Group") Response removeGroupRole(@PathParam("groupTitle") String groupTitle, @QueryParam("role") String role); @GET @Path("{groupTitle}/users") @RolesAllowed("user") @Produces(MediaType.APPLICATION_JSON) @ApiOperation("List users of a Mobi Group") Response getGroupUsers(@PathParam("groupTitle") String groupTitle); @PUT @Path("{groupTitle}/users") @RolesAllowed("admin") @ApiOperation("Add a Mobi User to a Group") Response addGroupUser(@PathParam("groupTitle") String groupTitle, 
                                 @QueryParam("users") List<String> usernames); @DELETE @Path("{groupTitle}/users") @RolesAllowed("admin") @ApiOperation("Remove a Mobi User from a Group") Response removeGroupUser(@PathParam("groupTitle") String groupTitle, @QueryParam("user") String username);  }
@Test public void createGroupTest() { when(engineManager.groupExists(anyString())).thenReturn(false); FormDataMultiPart fd = new FormDataMultiPart(); fd.field("title", "newGroup"); fd.field("description", "This is a description"); fd.field("members", "John Doe"); fd.field("members", "Jane Doe"); fd.field("roles", "admin"); Response response = target().path("groups") .request().post(Entity.entity(fd, MediaType.MULTIPART_FORM_DATA)); assertEquals(response.getStatus(), 201); verify(engineManager).storeGroup(eq(ENGINE_NAME), any(Group.class)); }