ServiceAccountsControllerV2 { @ApiOperation(value = "${ServiceAccountsControllerV2.addAWSRole.value}", notes = "${ServiceAccountsControllerV2.addAWSRole.notes}") @PostMapping (value="/v2/serviceaccounts/role",consumes="application/json",produces="application/json") public ResponseEntity<String> addAwsRoleToSvcacc(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestBody ServiceAccountAWSRole serviceAccountAWSRole){ UserDetails userDetails = (UserDetails) ((HttpServletRequest) request).getAttribute("UserDetails"); return serviceAccountsService.addAwsRoleToSvcacc(userDetails, token, serviceAccountAWSRole); }  @ApiOperation(value = "${ServiceAccountsControllerV2.getADServiceAccounts.value}", notes = "${ServiceAccountsControllerV2.getADServiceAccounts.notes}") @GetMapping(value="/v2/ad/serviceaccounts", produces="application/json") ResponseEntity<ADServiceAccountObjects> getADServiceAccounts(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestParam("serviceAccountName" ) String serviceAccountName, @RequestParam(value="excludeOnboarded", defaultValue="true") boolean excludeOnboarded ); @ApiOperation(value = "${ServiceAccountsControllerV2.getServiceAccounts.value}", notes = "${ServiceAccountsControllerV2.getServiceAccounts.notes}") @GetMapping(value="/v2/serviceaccounts", produces="application/json") ResponseEntity<String> getServiceAccounts(HttpServletRequest request, @RequestHeader(value="vault-token") String token); @ApiOperation(value = "${ServiceAccountsControllerV2.getServiceAccountDetails.value}", notes = "${ServiceAccountsControllerV2.getServiceAccountDetails.notes}") @GetMapping(value="/v2/serviceaccounts/{service_account_name}", produces="application/json") ResponseEntity<String> getServiceAccounts(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @PathVariable("service_account_name" ) String svcAccName); @ApiOperation(value = "${ServiceAccountsControllerV2.onboardServiceAccount.value}", notes = "${ServiceAccountsControllerV2.onboardServiceAccount.notes}") @PostMapping(value="/v2/serviceaccounts/onboard", produces="application/json") ResponseEntity<String> onboardServiceAccount( HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestBody @Valid ServiceAccount serviceAccount ); @ApiOperation(value = "${ServiceAccountsControllerV2.addUserToServiceAccount.value}", notes = "${ServiceAccountsControllerV2.addUserToServiceAccount.notes}") @PostMapping(value="/v2/serviceaccounts/user", produces="application/json") ResponseEntity<String> addUserToSvcAcc( HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody ServiceAccountUser serviceAccountUser ); @ApiOperation(value = "${ServiceAccountsControllerV2.removeUserServiceAccount.value}", notes = "${ServiceAccountsControllerV2.removeUserServiceAccount.notes}") @DeleteMapping(value="/v2/serviceaccounts/user", produces="application/json") ResponseEntity<String> removeUserServiceAccount( HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody ServiceAccountUser serviceAccountUser ); @ApiOperation(value = "${ServiceAccountsControllerV2.resetPassword.value}", notes = "${ServiceAccountsControllerV2.resetPassword.notes}") @PutMapping(value="/v2/serviceaccounts/password", produces="application/json") ResponseEntity<String> resetSvcAccPwd( HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestParam("serviceAccountName" ) String serviceAccountName ); @ApiOperation(value = "${ServiceAccountsControllerV2.readPassword.value}", notes = "${ServiceAccountsControllerV2.readPassword.notes}") @GetMapping(value="/v2/serviceaccounts/password", produces="application/json") ResponseEntity<String> readSvcAccPwd( HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestParam("serviceAccountName" ) String serviceAccountName ); @ApiOperation(value = "${ServiceAccountsControllerV2.offboardServiceAccount.value}", notes = "${ServiceAccountsControllerV2.offboardServiceAccount.notes}") @PostMapping(value="/v2/serviceaccounts/offboard", produces="application/json") ResponseEntity<String> offboardServiceAccount( HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestBody OnboardedServiceAccount serviceAccount ); @ApiOperation(value = "${ServiceAccountsControllerV2.addGroupToServiceAccount.value}", notes = "${ServiceAccountsControllerV2.addGroupToServiceAccount.notes}") @PostMapping(value="/v2/serviceaccounts/group", produces="application/json") ResponseEntity<String> addGroupToSvcAcc( HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody ServiceAccountGroup serviceAccountGroup ); @ApiOperation(value = "${ServiceAccountsControllerV2.removeGroupFromServiceAccount.value}", notes = "${ServiceAccountsControllerV2.removeGroupFromServiceAccount.notes}") @DeleteMapping(value="/v2/serviceaccounts/group", produces="application/json") ResponseEntity<String> removeGroupFromSvcAcc( HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody ServiceAccountGroup serviceAccountGroup ); @ApiOperation(value = "${ServiceAccountsControllerV2.associateApprole.value}", notes = "${ServiceAccountsControllerV2.associateApprole.notes}") @PostMapping(value="/v2/serviceaccounts/approle",consumes="application/json",produces="application/json") ResponseEntity<String> associateApproletoSvcAcc(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody ServiceAccountApprole serviceAccountApprole); @ApiOperation(value = "${ServiceAccountsControllerV2.removeApprole.value}", notes = "${ServiceAccountsControllerV2.removeApprole.notes}") @DeleteMapping(value="/v2/serviceaccounts/approle",consumes="application/json",produces="application/json") ResponseEntity<String> removeApproleFromSvcAcc(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @Valid @RequestBody ServiceAccountApprole serviceAccountApprole); @ApiOperation(value = "${ServiceAccountsControllerV2.getServiceAccountsMeta.value}", notes = "${ServiceAccountsControllerV2.getServiceAccountsMeta.notes}", hidden=true) @GetMapping(value="/v2/serviceaccounts/meta", produces="application/json") ResponseEntity<String> getServiceAccountMeta(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestParam("path" ) String path); @ApiOperation(value = "${ServiceAccountsControllerV2.createAWSRole.value}", notes = "${ServiceAccountsControllerV2.createAWSRole.notes}") @PostMapping(value="/v2/serviceaccounts/aws/role",consumes="application/json",produces="application/json") ResponseEntity<String> createAWSRole(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestBody AWSLoginRole awsLoginRole); @ApiOperation(value = "${ServiceAccountsControllerV2.createIamRole.value}", notes = "${ServiceAccountsControllerV2.createIamRole.notes}") @PostMapping(value="/v2/serviceaccounts/aws/iam/role",produces="application/json") ResponseEntity<String> createIAMRole(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestBody AWSIAMRole awsiamRole); @ApiOperation(value = "${ServiceAccountsControllerV2.addAWSRole.value}", notes = "${ServiceAccountsControllerV2.addAWSRole.notes}") @PostMapping (value="/v2/serviceaccounts/role",consumes="application/json",produces="application/json") ResponseEntity<String> addAwsRoleToSvcacc(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestBody ServiceAccountAWSRole serviceAccountAWSRole); @ApiOperation(value = "${ServiceAccountsControllerV2.removeAWSRole.value}", notes = "${ServiceAccountsControllerV2.removeAWSRole.notes}") @DeleteMapping (value="/v2/serviceaccounts/role",consumes="application/json",produces="application/json") ResponseEntity<String> removeAWSRoleFromSvcacc(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestBody ServiceAccountAWSRole serviceAccountAWSRole); @ApiOperation(value = "${ServiceAccountsControllerV2.updateOnboardServiceAccount.value}", notes = "${ServiceAccountsControllerV2.updateOnboardServiceAccount.notes}") @PutMapping(value="/v2/serviceaccounts/onboard", produces="application/json") ResponseEntity<String> updateOnboardedServiceAccount( HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestBody @Valid ServiceAccount serviceAccount ); @ApiOperation(value = "${ServiceAccountsControllerV2.transferSvcAccountOwner.value}", notes = "${ServiceAccountsControllerV2.transferSvcAccountOwner.notes}") @PostMapping (value="/v2/serviceaccounts/transfer",produces="application/json") ResponseEntity<String> transferSvcAccountOwner(HttpServletRequest request, @RequestHeader(value="vault-token") String token, @RequestParam("serviceAccountName" ) String serviceAccountName); @ApiOperation(value = "${ServiceAccountsControllerV2.transferSvcAccountOwner.value}", notes = "${ServiceAccountsControllerV2.transferSvcAccountOwner.notes}",hidden = true) @GetMapping (value="/v2/serviceaccounts/list",produces="application/json") ResponseEntity<String> getServiceAccountsList(HttpServletRequest request, @RequestHeader(value="vault-token") String token);  }
@Test public void test_associateAWSroletoSvcAcc() throws Exception { ServiceAccountApprole serviceAccountApprole = new ServiceAccountApprole("testacc02", "role1","write"); String inputJson =new ObjectMapper().writeValueAsString(serviceAccountApprole); String responseJson = "{\"messages\":[\"AWS Role successfully associated with Service Account\"]}"; ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body(responseJson); UserDetails userDetails = getMockUser(false); when(serviceAccountsService.addAwsRoleToSvcacc(eq(userDetails), eq("5PDrOhsy4ig8L3EpsJZSLAMg"), Mockito.any(ServiceAccountAWSRole.class))).thenReturn(responseEntityExpected); mockMvc.perform(MockMvcRequestBuilders.post("/v2/serviceaccounts/role").requestAttr("UserDetails", userDetails) .header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg") .header("Content-Type", "application/json;charset=UTF-8") .content(inputJson)) .andExpect(status().isOk()) .andExpect(content().string(containsString(responseJson))); }