@Test public void registerAccountFailedWithOtherException() { AccountDto accountDto = new AccountDto(); accountDto.setName("name"); accountDto.setAccountType(AccountType.Normal); accountDto.setUsername("admin"); char[] password = "password".toCharArray(); accountDto.setPassword(password); when(accountService.registerNewAccount(accountDto, "admin", password)) .thenThrow( new IllegalStateException()); assertThatThrownBy(() -> accountResource.registerNewAccount(accountDto)) .isInstanceOf(MTException.class); }
@ValidatePayload(AccountDto.class) @POST @CheckRole("admin") public Response registerNewAccount(AccountDto accountDto) { AccountDto dto = tryApplyChange(() -> accountService.registerNewAccount( accountDto, accountDto.getUsername(), accountDto.getPassword())); accountCreatedEvent .fire(new AccountCreated(dto.getEmail(), dto.getRoles())); return Response.created(uriInfo.getRequestUriBuilder().path("id") .path(dto.getId().toString()).build()).build(); }
AccountResourceImpl { @ValidatePayload(AccountDto.class) @POST @CheckRole("admin") public Response registerNewAccount(AccountDto accountDto) { AccountDto dto = tryApplyChange(() -> accountService.registerNewAccount( accountDto, accountDto.getUsername(), accountDto.getPassword())); accountCreatedEvent .fire(new AccountCreated(dto.getEmail(), dto.getRoles())); return Response.created(uriInfo.getRequestUriBuilder().path("id") .path(dto.getId().toString()).build()).build(); } }
AccountResourceImpl { @ValidatePayload(AccountDto.class) @POST @CheckRole("admin") public Response registerNewAccount(AccountDto accountDto) { AccountDto dto = tryApplyChange(() -> accountService.registerNewAccount( accountDto, accountDto.getUsername(), accountDto.getPassword())); accountCreatedEvent .fire(new AccountCreated(dto.getEmail(), dto.getRoles())); return Response.created(uriInfo.getRequestUriBuilder().path("id") .path(dto.getId().toString()).build()).build(); } @Inject  AccountResourceImpl(AccountService accountService,
        AuthenticatedAccount authenticatedAccount,
        Event<AccountCreated> accountCreatedEvent); @SuppressWarnings("unused")  AccountResourceImpl(); }
AccountResourceImpl { @ValidatePayload(AccountDto.class) @POST @CheckRole("admin") public Response registerNewAccount(AccountDto accountDto) { AccountDto dto = tryApplyChange(() -> accountService.registerNewAccount( accountDto, accountDto.getUsername(), accountDto.getPassword())); accountCreatedEvent .fire(new AccountCreated(dto.getEmail(), dto.getRoles())); return Response.created(uriInfo.getRequestUriBuilder().path("id") .path(dto.getId().toString()).build()).build(); } @Inject  AccountResourceImpl(AccountService accountService,
        AuthenticatedAccount authenticatedAccount,
        Event<AccountCreated> accountCreatedEvent); @SuppressWarnings("unused")  AccountResourceImpl(); @GET @CheckRole("admin") List<AccountDto> getAllAccounts(@QueryParam("enabledOnly") boolean enabledOnly); @ValidatePayload(AccountDto.class) @POST @CheckRole("admin") Response registerNewAccount(AccountDto accountDto); @ValidatePayload(AccountDto.class) @PUT @CheckRole("admin") Response updateAccount(AccountDto accountDto); @POST @Path("/login") Response login(@HeaderParam("Authorization") String authHeader); @POST @Path("/logout") Response logout(); }
AccountResourceImpl { @ValidatePayload(AccountDto.class) @POST @CheckRole("admin") public Response registerNewAccount(AccountDto accountDto) { AccountDto dto = tryApplyChange(() -> accountService.registerNewAccount( accountDto, accountDto.getUsername(), accountDto.getPassword())); accountCreatedEvent .fire(new AccountCreated(dto.getEmail(), dto.getRoles())); return Response.created(uriInfo.getRequestUriBuilder().path("id") .path(dto.getId().toString()).build()).build(); } @Inject  AccountResourceImpl(AccountService accountService,
        AuthenticatedAccount authenticatedAccount,
        Event<AccountCreated> accountCreatedEvent); @SuppressWarnings("unused")  AccountResourceImpl(); @GET @CheckRole("admin") List<AccountDto> getAllAccounts(@QueryParam("enabledOnly") boolean enabledOnly); @ValidatePayload(AccountDto.class) @POST @CheckRole("admin") Response registerNewAccount(AccountDto accountDto); @ValidatePayload(AccountDto.class) @PUT @CheckRole("admin") Response updateAccount(AccountDto accountDto); @POST @Path("/login") Response login(@HeaderParam("Authorization") String authHeader); @POST @Path("/logout") Response logout(); final static String AUTH_HEADER; }