@Test public void testCreateDirectoryFailure() { String companyId = UUID.randomUUID().toString(); String interalId = UUID.randomUUID().toString(); when(companyRepo.existsById(companyId)).thenReturn(false); String name = "testAccount"; String email = "test001@staffjoy.xyz"; String phoneNumber = "18001981226"; Instant memberSince = Instant.now().minusSeconds(24 * 3600 * 30); String photoUrl = "https: NewDirectoryEntry newDirectoryEntry = NewDirectoryEntry.builder() .internalId(interalId) .companyId(companyId) .name(name) .email(email) .phoneNumber(phoneNumber) .build(); GenericDirectoryResponse genericDirectoryResponse = companyClient.createDirectory(AuthConstant.AUTHORIZATION_WWW_SERVICE, newDirectoryEntry); log.info(genericDirectoryResponse.toString()); assertThat(genericDirectoryResponse.isSuccess()).isFalse(); assertThat(genericDirectoryResponse.getCode()).isEqualTo(ResultCode.NOT_FOUND); when(companyRepo.existsById(companyId)).thenReturn(true); when(accountClient.getOrCreateAccount(anyString(), any(GetOrCreateRequest.class))) .thenThrow(new RuntimeException("mock exception")); genericDirectoryResponse = companyClient.createDirectory(AuthConstant.AUTHORIZATION_WWW_SERVICE, newDirectoryEntry); log.info(genericDirectoryResponse.toString()); assertThat(genericDirectoryResponse.isSuccess()).isFalse(); assertThat(genericDirectoryResponse.getCode()).isEqualTo(ResultCode.FAILURE); GenericAccountResponse genericAccountResponse = new GenericAccountResponse(); genericAccountResponse.setCode(ResultCode.FAILURE); genericAccountResponse.setMessage("mock view message"); when(accountClient.getOrCreateAccount(anyString(), any(GetOrCreateRequest.class))) .thenReturn(genericAccountResponse); genericDirectoryResponse = companyClient.createDirectory(AuthConstant.AUTHORIZATION_WWW_SERVICE, newDirectoryEntry); log.info(genericDirectoryResponse.toString()); assertThat(genericDirectoryResponse.isSuccess()).isFalse(); assertThat(genericDirectoryResponse.getCode()).isEqualTo(ResultCode.FAILURE); }
@PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) public GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(request.getCompanyId()); } DirectoryEntryDto directoryEntryDto = directoryService.createDirectory(request); return new GenericDirectoryResponse(directoryEntryDto); }
DirectoryController { @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) public GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(request.getCompanyId()); } DirectoryEntryDto directoryEntryDto = directoryService.createDirectory(request); return new GenericDirectoryResponse(directoryEntryDto); } }
DirectoryController { @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) public GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(request.getCompanyId()); } DirectoryEntryDto directoryEntryDto = directoryService.createDirectory(request); return new GenericDirectoryResponse(directoryEntryDto); }  }
DirectoryController { @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) public GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(request.getCompanyId()); } DirectoryEntryDto directoryEntryDto = directoryService.createDirectory(request); return new GenericDirectoryResponse(directoryEntryDto); }  @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request); @GetMapping(path = "/list") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) ListDirectoryResponse listDirectories(@RequestParam String companyId,
                                                 @RequestParam(defaultValue = "0") int offset,
                                                 @RequestParam(defaultValue = "0") int limit); @GetMapping(path = "/get") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WHOAMI_SERVICE, AuthConstant.AUTHORIZATION_WWW_SERVICE }) GenericDirectoryResponse getDirectoryEntry(@RequestParam String companyId, @RequestParam String userId); @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericDirectoryResponse updateDirectoryEntry(@RequestBody @Validated DirectoryEntryDto request); @GetMapping(path = "/get_associations") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GetAssociationResponse getAssociations(@RequestParam String companyId,
                                                  @RequestParam(defaultValue = "0") int offset,
                                                  @RequestParam(defaultValue = "0") int limit); }
DirectoryController { @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) public GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(request.getCompanyId()); } DirectoryEntryDto directoryEntryDto = directoryService.createDirectory(request); return new GenericDirectoryResponse(directoryEntryDto); }  @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) GenericDirectoryResponse createDirectory(@RequestBody @Validated NewDirectoryEntry request); @GetMapping(path = "/list") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) ListDirectoryResponse listDirectories(@RequestParam String companyId,
                                                 @RequestParam(defaultValue = "0") int offset,
                                                 @RequestParam(defaultValue = "0") int limit); @GetMapping(path = "/get") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WHOAMI_SERVICE, AuthConstant.AUTHORIZATION_WWW_SERVICE }) GenericDirectoryResponse getDirectoryEntry(@RequestParam String companyId, @RequestParam String userId); @PutMapping(path = "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericDirectoryResponse updateDirectoryEntry(@RequestBody @Validated DirectoryEntryDto request); @GetMapping(path = "/get_associations") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GetAssociationResponse getAssociations(@RequestParam String companyId,
                                                  @RequestParam(defaultValue = "0") int offset,
                                                  @RequestParam(defaultValue = "0") int limit);  }