UserManagementServiceImpl implements UserManagementService { @POST @Path("/enrollment-invite") @Override public Response inviteToEnrollDevice(EnrollmentInvitation enrollmentInvitation) { if (log.isDebugEnabled()) { log.debug("Sending enrollment invitation mail to existing user."); } DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); try { Set<String> recipients = new HashSet<>(); recipients.addAll(enrollmentInvitation.getRecipients()); Properties props = new Properties(); String username = DeviceMgtAPIUtils.getAuthenticatedUser(); String firstName = getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME); String lastName = getClaimValue(username, Constants.USER_CLAIM_LAST_NAME); if (firstName == null) { firstName = username; } if (lastName == null) { lastName = ""; } props.setProperty("first-name", firstName); props.setProperty("last-name", lastName); props.setProperty("device-type", enrollmentInvitation.getDeviceType()); EmailMetaInfo metaInfo = new EmailMetaInfo(recipients, props); dms.sendEnrolmentInvitation(getEnrollmentTemplateName(enrollmentInvitation.getDeviceType()), metaInfo); } catch (DeviceManagementException e) { String msg = "Error occurred while inviting user to enrol their device"; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } catch (UserStoreException e) { String msg = "Error occurred while getting claim values to invite user"; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } catch (ConfigurationManagementException e) { String msg = "Error occurred while sending the email invitations. Mail server not configured."; return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build(); }  @POST @Override Response addUser(UserInfo userInfo); @GET @Path("/{username}") @Override Response getUser(@PathParam("username") String username, @QueryParam("domain") String domain,
                            @HeaderParam("If-Modified-Since") String ifModifiedSince); @PUT @Path("/{username}") @Override Response updateUser(@PathParam("username") String username, @QueryParam("domain") String domain, UserInfo userInfo); @DELETE @Path("/{username}") @Override Response removeUser(@PathParam("username") String username, @QueryParam("domain") String domain); @GET @Path("/{username}/roles") @Override Response getRolesOfUser(@PathParam("username") String username, @QueryParam("domain") String domain); @GET @Override Response getUsers(@QueryParam("filter") String filter, @HeaderParam("If-Modified-Since") String timestamp,
                             @QueryParam("offset") int offset,
                             @QueryParam("limit") int limit); @GET @Path("/count") @Override Response getUserCount(); @GET @Path("/checkUser") @Override Response isUserExists(@QueryParam("username") String userName); @GET @Path("/search/usernames") @Override Response getUserNames(@QueryParam("filter") String filter, @QueryParam("domain") String domain,
                                 @HeaderParam("If-Modified-Since") String timestamp,
                                 @QueryParam("offset") int offset, @QueryParam("limit") int limit); @PUT @Path("/credentials") @Override Response resetPassword(OldPasswordResetWrapper credentials); @POST @Path("/send-invitation") @Produces({MediaType.APPLICATION_JSON}) Response inviteExistingUsersToEnrollDevice(List<String> usernames); @POST @Path("/enrollment-invite") @Override Response inviteToEnrollDevice(EnrollmentInvitation enrollmentInvitation);  }
@Test(description = "This method tests the inviteToEnrollDevice method of UserManagementService", dependsOnMethods = "testGetUsers") public void testInviteToEnrollDevice() { URL resourceUrl = ClassLoader.getSystemResource("testng.xml"); System.setProperty("carbon.home", resourceUrl.getPath()); PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getUserStoreManager")) .toReturn(this.userStoreManager); PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getAuthenticatedUser")).toReturn(TEST_USERNAME); PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService")) .toReturn(this.deviceManagementProviderService); EnrollmentInvitation enrollmentInvitation = new EnrollmentInvitation(); List<String> recipients = new ArrayList<>(); recipients.add(TEST_USERNAME); enrollmentInvitation.setDeviceType("android"); enrollmentInvitation.setRecipients(recipients); Response response = userManagementService.inviteToEnrollDevice(enrollmentInvitation); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "Inviting users to enroll device failed"); }