src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
PartnerOrganisationRestServiceImpl extends BaseRestService implements PartnerOrganisationRestService { public RestResult<List<PartnerOrganisationResource>> getProjectPartnerOrganisations(Long projectId) { return getWithRestResult(projectRestURL + "/" + projectId + "/partner-organisation", partnerOrganisationResourceList()); } RestResult<List<PartnerOrganisationResource>> getProjectPartnerOrganisations(Long projectId); @Override RestResult<PartnerOrganisationResource> getPartnerOrganisation(long projectId, long organisationId); @Override RestResult<Void> removePartnerOrganisation(long projectId, long organisationId); }
@Test public void testGetProjectPartnerOrganisations(){ Long projectId = 123L; List<PartnerOrganisationResource> partnerOrganisations = Arrays.asList(1,2,3).stream().map(i -> { PartnerOrganisationResource x = new PartnerOrganisationResource(); x.setProject(projectId); return x; }).collect(Collectors.toList()); setupGetWithRestResultExpectations(projectRestURL + "/123/partner-organisation", partnerOrganisationResourceList(), partnerOrganisations); RestResult result = service.getProjectPartnerOrganisations(projectId); assertTrue(result.isSuccess()); }
PartnerOrganisationRestServiceImpl extends BaseRestService implements PartnerOrganisationRestService { @Override public RestResult<PartnerOrganisationResource> getPartnerOrganisation(long projectId, long organisationId) { return getWithRestResult(projectRestURL + "/" + projectId + "/partner/" + organisationId, PartnerOrganisationResource.class); } RestResult<List<PartnerOrganisationResource>> getProjectPartnerOrganisations(Long projectId); @Override RestResult<PartnerOrganisationResource> getPartnerOrganisation(long projectId, long organisationId); @Override RestResult<Void> removePartnerOrganisation(long projectId, long organisationId); }
@Test public void testGetPartnerOrganisation() { long projectId = 1L; long organisationId = 2L; PartnerOrganisationResource partnerOrganisationResource = PartnerOrganisationResourceBuilder.newPartnerOrganisationResource().build(); setupGetWithRestResultExpectations(projectRestURL + "/" + projectId + "/partner/" + organisationId, PartnerOrganisationResource.class, partnerOrganisationResource); RestResult<PartnerOrganisationResource> result = service.getPartnerOrganisation(projectId, organisationId); assertTrue(result.isSuccess()); assertEquals(partnerOrganisationResource, result.getSuccess()); setupGetWithRestResultVerifications(projectRestURL + "/" + projectId + "/partner/" + organisationId, null, PartnerOrganisationResource.class); }
PartnerOrganisationRestServiceImpl extends BaseRestService implements PartnerOrganisationRestService { @Override public RestResult<Void> removePartnerOrganisation(long projectId, long organisationId) { return postWithRestResult(projectRestURL + "/" + projectId + "/remove-organisation/" + organisationId, Void.class); } RestResult<List<PartnerOrganisationResource>> getProjectPartnerOrganisations(Long projectId); @Override RestResult<PartnerOrganisationResource> getPartnerOrganisation(long projectId, long organisationId); @Override RestResult<Void> removePartnerOrganisation(long projectId, long organisationId); }
@Test public void removePartnerOrganisation() { long projectId = 1L; long organisationId = 2L; setupPostWithRestResultExpectations(projectRestURL + "/" + projectId + "/remove-organisation/" + organisationId, HttpStatus.OK); RestResult<Void> result = service.removePartnerOrganisation(projectId, organisationId); assertTrue(result.isSuccess()); }
ProjectDetailsRestServiceImpl extends BaseRestService implements ProjectDetailsRestService { @Override public RestResult<Void> updateProjectDuration(long projectId, long durationInMonths) { return postWithRestResult(projectRestURL + "/" + projectId + "/duration/" + durationInMonths, Void.class); } @Override RestResult<Void> updateProjectManager(Long projectId, Long projectManagerUserId); @Override RestResult<Void> updateProjectStartDate(Long projectId, LocalDate projectStartDate); @Override RestResult<Void> updateProjectDuration(long projectId, long durationInMonths); @Override RestResult<Void> updateProjectAddress(long projectId, AddressResource address); @Override RestResult<Void> updateFinanceContact(ProjectOrganisationCompositeId composite, Long financeContactUserId); @Override RestResult<Void> updatePartnerProjectLocation(long projectId, long organisationId, PostcodeAndTownResource postcodeAndTown); }
@Test public void testUpdateProjectDuration() { long projectId = 3L; long durationInMonths = 18L; setupPostWithRestResultExpectations(projectRestURL + "/" + projectId + "/duration/" + durationInMonths, null, OK); RestResult<Void> result = service.updateProjectDuration(projectId, durationInMonths); assertTrue(result.isSuccess()); setupPostWithRestResultVerifications(projectRestURL + "/" + projectId + "/duration/" + durationInMonths, Void.class, null); }
UsersRolesServiceImpl extends BaseTransactionalService implements UsersRolesService { @Override public ServiceResult<ProcessRoleResource> getProcessRoleByUserIdAndApplicationId(long userId, long applicationId) { return find(processRoleRepository.findOneByUserIdAndRoleInAndApplicationId(userId, applicantProcessRoles(), applicationId), notFoundError(ProcessRole.class, "User", userId, "Application", applicationId)) .andOnSuccessReturn(processRoleMapper::mapToResource); } @Override ServiceResult<ProcessRoleResource> getProcessRoleById(long id); @Override ServiceResult<List<ProcessRoleResource>> getProcessRolesByIds(Long[] ids); @Override ServiceResult<List<ProcessRoleResource>> getProcessRolesByApplicationId(long applicationId); @Override ServiceResult<ProcessRoleResource> getProcessRoleByUserIdAndApplicationId(long userId, long applicationId); @Override ServiceResult<List<ProcessRoleResource>> getProcessRolesByUserId(long userId); @Override ServiceResult<List<ProcessRoleResource>> getAssignableProcessRolesByApplicationId(long applicationId); @Override ServiceResult<Boolean> userHasApplicationForCompetition(long userId, long competitionId); }
@Test public void getProcessRoleByUserIdAndApplicationId() { ProcessRole processRole = newProcessRole().build(); ProcessRoleResource processRoleResource = newProcessRoleResource().build(); when(processRoleRepositoryMock.findOneByUserIdAndRoleInAndApplicationId(1L, applicantProcessRoles(), 1L)).thenReturn(processRole); when(processRoleMapperMock.mapToResource(same(processRole))).thenReturn(processRoleResource); ServiceResult<ProcessRoleResource> result = service.getProcessRoleByUserIdAndApplicationId(1L, 1L); assertTrue(result.isSuccess()); assertEquals(processRoleResource, result.getSuccess()); verify(processRoleRepositoryMock, only()).findOneByUserIdAndRoleInAndApplicationId(1L, applicantProcessRoles(), 1L); }
ProjectDetailsRestServiceImpl extends BaseRestService implements ProjectDetailsRestService { @Override public RestResult<Void> updateFinanceContact(ProjectOrganisationCompositeId composite, Long financeContactUserId) { return postWithRestResult(projectRestURL + "/" + composite.getProjectId() + "/organisation/" + composite.getOrganisationId() + "/finance-contact?financeContact=" + financeContactUserId, Void.class); } @Override RestResult<Void> updateProjectManager(Long projectId, Long projectManagerUserId); @Override RestResult<Void> updateProjectStartDate(Long projectId, LocalDate projectStartDate); @Override RestResult<Void> updateProjectDuration(long projectId, long durationInMonths); @Override RestResult<Void> updateProjectAddress(long projectId, AddressResource address); @Override RestResult<Void> updateFinanceContact(ProjectOrganisationCompositeId composite, Long financeContactUserId); @Override RestResult<Void> updatePartnerProjectLocation(long projectId, long organisationId, PostcodeAndTownResource postcodeAndTown); }
@Test public void testUpdateFinanceContact() { setupPostWithRestResultExpectations(projectRestURL + "/123/organisation/5/finance-contact?financeContact=6", null, OK); RestResult<Void> result = service.updateFinanceContact(new ProjectOrganisationCompositeId(123L, 5L), 6L); assertTrue(result.isSuccess()); }
ProjectDetailsRestServiceImpl extends BaseRestService implements ProjectDetailsRestService { @Override public RestResult<Void> updatePartnerProjectLocation(long projectId, long organisationId, PostcodeAndTownResource postcodeAndTown) { return postWithRestResult(projectRestURL + "/" + projectId + "/organisation/" + organisationId + "/partner-project-location", postcodeAndTown, Void.class); } @Override RestResult<Void> updateProjectManager(Long projectId, Long projectManagerUserId); @Override RestResult<Void> updateProjectStartDate(Long projectId, LocalDate projectStartDate); @Override RestResult<Void> updateProjectDuration(long projectId, long durationInMonths); @Override RestResult<Void> updateProjectAddress(long projectId, AddressResource address); @Override RestResult<Void> updateFinanceContact(ProjectOrganisationCompositeId composite, Long financeContactUserId); @Override RestResult<Void> updatePartnerProjectLocation(long projectId, long organisationId, PostcodeAndTownResource postcodeAndTown); }
@Test public void testUpdatePartnerProjectLocation() { long projectId = 1L; long organisationId = 2L; PostcodeAndTownResource postcodeAndTown = new PostcodeAndTownResource("TW14 9QG", null); setupPostWithRestResultExpectations(projectRestURL + "/" + projectId + "/organisation/" + organisationId + "/partner-project-location", postcodeAndTown, OK); RestResult<Void> result = service.updatePartnerProjectLocation(projectId, organisationId, postcodeAndTown); assertTrue(result.isSuccess()); setupPostWithRestResultVerifications(projectRestURL + "/" + projectId + "/organisation/" + organisationId + "/partner-project-location", Void.class, postcodeAndTown); }
ProjectDetailsRestServiceImpl extends BaseRestService implements ProjectDetailsRestService { @Override public RestResult<Void> updateProjectAddress(long projectId, AddressResource address) { return postWithRestResult(projectRestURL + "/" + projectId + "/address", address, Void.class); } @Override RestResult<Void> updateProjectManager(Long projectId, Long projectManagerUserId); @Override RestResult<Void> updateProjectStartDate(Long projectId, LocalDate projectStartDate); @Override RestResult<Void> updateProjectDuration(long projectId, long durationInMonths); @Override RestResult<Void> updateProjectAddress(long projectId, AddressResource address); @Override RestResult<Void> updateFinanceContact(ProjectOrganisationCompositeId composite, Long financeContactUserId); @Override RestResult<Void> updatePartnerProjectLocation(long projectId, long organisationId, PostcodeAndTownResource postcodeAndTown); }
@Test public void testUpdateProjectAddress() { long projectId = 456L; AddressResource addressResource = new AddressResource(); setupPostWithRestResultExpectations(projectRestURL + "/" + projectId + "/address", addressResource, OK); RestResult<Void> result = service.updateProjectAddress(projectId, addressResource); assertTrue(result.isSuccess()); }
DocumentsRestServiceImpl extends BaseRestService implements DocumentsRestService { @Override public RestResult<FileEntryResource> uploadDocument(long projectId, long documentConfigId, String contentType, long contentLength, String originalFilename, byte[] bytes) { String url = String.format("%s/%s/document/config/%s/upload?filename=%s", projectRestURL, projectId, documentConfigId, originalFilename); return postWithRestResult(url, bytes, createFileUploadHeader(contentType, contentLength), FileEntryResource.class); } @Override RestResult<FileEntryResource> uploadDocument(long projectId, long documentConfigId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Optional<ByteArrayResource>> getFileContents(long projectId, long documentConfigId); @Override RestResult<Optional<FileEntryResource>> getFileEntryDetails(long projectId, long documentConfigId); @Override RestResult<Void> deleteDocument(long projectId, long documentConfigId); @Override RestResult<Void> submitDocument(long projectId, long documentConfigId); @Override RestResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision); }
@Test public void uploadDocument() { String fileName = "filename.txt"; String url = String.format("%s/%s/document/config/%s/upload?filename=%s", projectRestURL, projectId, documentConfigId, fileName); String fileContentString = "12345678901234567"; byte[] fileContent = fileContentString.getBytes(); FileEntryResource response = new FileEntryResource(); setupFileUploadWithRestResultExpectations(url, FileEntryResource.class, fileContentString, "text/plain", 17, response, CREATED); RestResult<FileEntryResource> result = service.uploadDocument(projectId, documentConfigId, "text/plain", 17, fileName, fileContent); assertTrue(result.isSuccess()); assertEquals(response, result.getSuccess()); }
DocumentsRestServiceImpl extends BaseRestService implements DocumentsRestService { @Override public RestResult<Optional<ByteArrayResource>> getFileContents(long projectId, long documentConfigId) { String url = String.format("%s/%s/document/config/%s/file-contents", projectRestURL, projectId, documentConfigId); return getWithRestResult(url, ByteArrayResource.class).toOptionalIfNotFound(); } @Override RestResult<FileEntryResource> uploadDocument(long projectId, long documentConfigId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Optional<ByteArrayResource>> getFileContents(long projectId, long documentConfigId); @Override RestResult<Optional<FileEntryResource>> getFileEntryDetails(long projectId, long documentConfigId); @Override RestResult<Void> deleteDocument(long projectId, long documentConfigId); @Override RestResult<Void> submitDocument(long projectId, long documentConfigId); @Override RestResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision); }
@Test public void getFileContents() { String url = String.format("%s/%s/document/config/%s/file-contents", projectRestURL, projectId, documentConfigId); ByteArrayResource expectedFileContents = new ByteArrayResource("Retrieved content".getBytes()); setupGetWithRestResultExpectations(url, ByteArrayResource.class, expectedFileContents, OK); ByteArrayResource retrievedFileContents = service.getFileContents(projectId, documentConfigId).getSuccess().get(); assertEquals(expectedFileContents, retrievedFileContents); }
DocumentsRestServiceImpl extends BaseRestService implements DocumentsRestService { @Override public RestResult<Optional<FileEntryResource>> getFileEntryDetails(long projectId, long documentConfigId) { String url = String.format("%s/%s/document/config/%s/file-entry-details", projectRestURL, projectId, documentConfigId); return getWithRestResult(url, FileEntryResource.class).toOptionalIfNotFound(); } @Override RestResult<FileEntryResource> uploadDocument(long projectId, long documentConfigId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Optional<ByteArrayResource>> getFileContents(long projectId, long documentConfigId); @Override RestResult<Optional<FileEntryResource>> getFileEntryDetails(long projectId, long documentConfigId); @Override RestResult<Void> deleteDocument(long projectId, long documentConfigId); @Override RestResult<Void> submitDocument(long projectId, long documentConfigId); @Override RestResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision); }
@Test public void getFileEntryDetails() { String url = String.format("%s/%s/document/config/%s/file-entry-details", projectRestURL, projectId, documentConfigId); FileEntryResource expectedFileEntry = new FileEntryResource(); setupGetWithRestResultExpectations(url, FileEntryResource.class, expectedFileEntry, OK); FileEntryResource retrievedFileEntry = service.getFileEntryDetails(projectId, documentConfigId).getSuccess().get(); Assert.assertEquals(expectedFileEntry, retrievedFileEntry); }
DocumentsRestServiceImpl extends BaseRestService implements DocumentsRestService { @Override public RestResult<Void> deleteDocument(long projectId, long documentConfigId) { String url = String.format("%s/%s/document/config/%s/delete", projectRestURL, projectId, documentConfigId); return deleteWithRestResult(url); } @Override RestResult<FileEntryResource> uploadDocument(long projectId, long documentConfigId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Optional<ByteArrayResource>> getFileContents(long projectId, long documentConfigId); @Override RestResult<Optional<FileEntryResource>> getFileEntryDetails(long projectId, long documentConfigId); @Override RestResult<Void> deleteDocument(long projectId, long documentConfigId); @Override RestResult<Void> submitDocument(long projectId, long documentConfigId); @Override RestResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision); }
@Test public void deleteDocument() { String url = String.format("%s/%s/document/config/%s/delete", projectRestURL, projectId, documentConfigId); setupDeleteWithRestResultExpectations(url); service.deleteDocument(projectId, documentConfigId); setupDeleteWithRestResultVerifications(url); }
DocumentsRestServiceImpl extends BaseRestService implements DocumentsRestService { @Override public RestResult<Void> submitDocument(long projectId, long documentConfigId) { String url = String.format("%s/%s/document/config/%s/submit", projectRestURL, projectId, documentConfigId); return postWithRestResult(url); } @Override RestResult<FileEntryResource> uploadDocument(long projectId, long documentConfigId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Optional<ByteArrayResource>> getFileContents(long projectId, long documentConfigId); @Override RestResult<Optional<FileEntryResource>> getFileEntryDetails(long projectId, long documentConfigId); @Override RestResult<Void> deleteDocument(long projectId, long documentConfigId); @Override RestResult<Void> submitDocument(long projectId, long documentConfigId); @Override RestResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision); }
@Test public void submitDocument() { String url = String.format("%s/%s/document/config/%s/submit", projectRestURL, projectId, documentConfigId); setupPostWithRestResultExpectations(url, null, OK); RestResult<Void> result = service.submitDocument(projectId, documentConfigId); assertTrue(result.isSuccess()); }
DocumentsRestServiceImpl extends BaseRestService implements DocumentsRestService { @Override public RestResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision) { String url = String.format("%s/%s/document/config/%s/decision", projectRestURL, projectId, documentConfigId); return postWithRestResult(url, decision, Void.class); } @Override RestResult<FileEntryResource> uploadDocument(long projectId, long documentConfigId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Optional<ByteArrayResource>> getFileContents(long projectId, long documentConfigId); @Override RestResult<Optional<FileEntryResource>> getFileEntryDetails(long projectId, long documentConfigId); @Override RestResult<Void> deleteDocument(long projectId, long documentConfigId); @Override RestResult<Void> submitDocument(long projectId, long documentConfigId); @Override RestResult<Void> documentDecision(long projectId, long documentConfigId, ProjectDocumentDecision decision); }
@Test public void documentDecision() { String url = String.format("%s/%s/document/config/%s/decision", projectRestURL, projectId, documentConfigId); ProjectDocumentDecision decision = new ProjectDocumentDecision(true, null); setupPostWithRestResultExpectations(url, decision, OK); RestResult<Void> result = service.documentDecision(projectId, documentConfigId, decision); setupPostWithRestResultVerifications(url, Void.class, decision); assertTrue(result.isSuccess()); }
BankDetailsRestServiceImpl extends BaseRestService implements BankDetailsRestService { @Override public RestResult<BankDetailsResource> getByProjectIdAndBankDetailsId(final Long projectId, final Long bankDetailsId){ return getWithRestResult(projectRestURL + "/" + projectId + "/bank-details?bankDetailsId=" + bankDetailsId, BankDetailsResource.class); } @Override RestResult<BankDetailsResource> getByProjectIdAndBankDetailsId(final Long projectId, final Long bankDetailsId); @Override RestResult<Void> submitBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<Void> updateBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<BankDetailsResource> getBankDetailsByProjectAndOrganisation(Long projectId, Long organisationId); @Override RestResult<ProjectBankDetailsStatusSummary> getBankDetailsStatusSummaryByProject(Long projectId); @Override RestResult<ByteArrayResource> downloadByCompetition(Long competitionId); @Override RestResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override RestResult<Long> countPendingBankDetailsApprovals(); }
@Test public void testGetById(){ Long projectId = 123L; Long bankDetailsId = 1L; BankDetailsResource returnedResponse = newBankDetailsResource().build(); setupGetWithRestResultExpectations(projectRestURL + "/" + projectId + "/bank-details?bankDetailsId=" + bankDetailsId, BankDetailsResource.class, returnedResponse); BankDetailsResource response = service.getByProjectIdAndBankDetailsId(projectId, bankDetailsId).getSuccess(); assertEquals(response, returnedResponse); }
UsersRolesServiceImpl extends BaseTransactionalService implements UsersRolesService { @Override public ServiceResult<List<ProcessRoleResource>> getProcessRolesByUserId(long userId) { return serviceSuccess(processRolesToResources(processRoleRepository.findByUserId(userId))); } @Override ServiceResult<ProcessRoleResource> getProcessRoleById(long id); @Override ServiceResult<List<ProcessRoleResource>> getProcessRolesByIds(Long[] ids); @Override ServiceResult<List<ProcessRoleResource>> getProcessRolesByApplicationId(long applicationId); @Override ServiceResult<ProcessRoleResource> getProcessRoleByUserIdAndApplicationId(long userId, long applicationId); @Override ServiceResult<List<ProcessRoleResource>> getProcessRolesByUserId(long userId); @Override ServiceResult<List<ProcessRoleResource>> getAssignableProcessRolesByApplicationId(long applicationId); @Override ServiceResult<Boolean> userHasApplicationForCompetition(long userId, long competitionId); }
@Test public void getProcessRolesByUserId() { List<ProcessRole> processRoles = newProcessRole().build(2); List<ProcessRoleResource> processRoleResources = newProcessRoleResource().build(2); when(processRoleRepositoryMock.findByUserId(1L)).thenReturn(processRoles); zip(processRoles, processRoleResources, (pr, prr) -> when(processRoleMapperMock.mapToResource(same(pr))).thenReturn(prr)); ServiceResult<List<ProcessRoleResource>> result = service.getProcessRolesByUserId(1L); assertTrue(result.isSuccess()); assertEquals(processRoleResources, result.getSuccess()); verify(processRoleRepositoryMock, only()).findByUserId(1L); }
BankDetailsRestServiceImpl extends BaseRestService implements BankDetailsRestService { @Override public RestResult<BankDetailsResource> getBankDetailsByProjectAndOrganisation(Long projectId, Long organisationId) { return getWithRestResult(projectRestURL + "/" + projectId + "/bank-details?organisationId=" + organisationId, BankDetailsResource.class); } @Override RestResult<BankDetailsResource> getByProjectIdAndBankDetailsId(final Long projectId, final Long bankDetailsId); @Override RestResult<Void> submitBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<Void> updateBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<BankDetailsResource> getBankDetailsByProjectAndOrganisation(Long projectId, Long organisationId); @Override RestResult<ProjectBankDetailsStatusSummary> getBankDetailsStatusSummaryByProject(Long projectId); @Override RestResult<ByteArrayResource> downloadByCompetition(Long competitionId); @Override RestResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override RestResult<Long> countPendingBankDetailsApprovals(); }
@Test public void testGetBankDetailsByProjectAndOrganisation(){ Long projectId = 123L; Long organisationId = 100L; BankDetailsResource returnedResponse = newBankDetailsResource().build(); setupGetWithRestResultExpectations(projectRestURL + "/" + projectId + "/bank-details?organisationId=" + organisationId, BankDetailsResource.class, returnedResponse); BankDetailsResource response = service.getBankDetailsByProjectAndOrganisation(projectId, organisationId).getSuccess(); assertEquals(response, returnedResponse); } @Test public void testGetBankDetailsByProjectAndOrganisationReturnsNotFoundWhenBankDetailsDontExist(){ Long projectId = 123L; Long organisationId = 100L; setupGetWithRestResultExpectations(projectRestURL + "/" + projectId + "/bank-details?organisationId=" + organisationId, BankDetailsResource.class, null, NOT_FOUND); RestResult<BankDetailsResource> response = service.getBankDetailsByProjectAndOrganisation(projectId, organisationId); assertTrue(response.isFailure()); assertEquals(response.getFailure().getStatusCode(), HttpStatus.NOT_FOUND); }
BankDetailsRestServiceImpl extends BaseRestService implements BankDetailsRestService { @Override public RestResult<Void> updateBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource){ return postWithRestResult(projectRestURL + "/" + projectId + "/bank-details", bankDetailsResource, Void.class); } @Override RestResult<BankDetailsResource> getByProjectIdAndBankDetailsId(final Long projectId, final Long bankDetailsId); @Override RestResult<Void> submitBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<Void> updateBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<BankDetailsResource> getBankDetailsByProjectAndOrganisation(Long projectId, Long organisationId); @Override RestResult<ProjectBankDetailsStatusSummary> getBankDetailsStatusSummaryByProject(Long projectId); @Override RestResult<ByteArrayResource> downloadByCompetition(Long competitionId); @Override RestResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override RestResult<Long> countPendingBankDetailsApprovals(); }
@Test public void testUpdateBankDetails(){ Long projectId = 123L; BankDetailsResource bankDetailsResource = newBankDetailsResource().build(); setupPostWithRestResultExpectations(projectRestURL + "/" + projectId + "/bank-details", bankDetailsResource, OK); RestResult result = service.updateBankDetails(projectId, bankDetailsResource); assertTrue(result.isSuccess()); }
BankDetailsRestServiceImpl extends BaseRestService implements BankDetailsRestService { @Override public RestResult<Void> submitBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource){ return putWithRestResult(projectRestURL + "/" + projectId + "/bank-details", bankDetailsResource, Void.class); } @Override RestResult<BankDetailsResource> getByProjectIdAndBankDetailsId(final Long projectId, final Long bankDetailsId); @Override RestResult<Void> submitBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<Void> updateBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<BankDetailsResource> getBankDetailsByProjectAndOrganisation(Long projectId, Long organisationId); @Override RestResult<ProjectBankDetailsStatusSummary> getBankDetailsStatusSummaryByProject(Long projectId); @Override RestResult<ByteArrayResource> downloadByCompetition(Long competitionId); @Override RestResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override RestResult<Long> countPendingBankDetailsApprovals(); }
@Test public void testSubmitBankDetails(){ Long projectId = 123L; BankDetailsResource bankDetailsResource = newBankDetailsResource().build(); setupPutWithRestResultExpectations(projectRestURL + "/" + projectId + "/bank-details", bankDetailsResource, OK); RestResult result = service.submitBankDetails(projectId, bankDetailsResource); assertTrue(result.isSuccess()); }
BankDetailsRestServiceImpl extends BaseRestService implements BankDetailsRestService { @Override public RestResult<ProjectBankDetailsStatusSummary> getBankDetailsStatusSummaryByProject(Long projectId) { return getWithRestResult(projectRestURL + "/" + projectId + "/bank-details/status-summary", ProjectBankDetailsStatusSummary.class); } @Override RestResult<BankDetailsResource> getByProjectIdAndBankDetailsId(final Long projectId, final Long bankDetailsId); @Override RestResult<Void> submitBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<Void> updateBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<BankDetailsResource> getBankDetailsByProjectAndOrganisation(Long projectId, Long organisationId); @Override RestResult<ProjectBankDetailsStatusSummary> getBankDetailsStatusSummaryByProject(Long projectId); @Override RestResult<ByteArrayResource> downloadByCompetition(Long competitionId); @Override RestResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override RestResult<Long> countPendingBankDetailsApprovals(); }
@Test public void testgetBankDetailsByProject(){ Long projectId = 123L; ProjectBankDetailsStatusSummary projectBankDetailsStatusSummary = newProjectBankDetailsStatusSummary().build(); setupGetWithRestResultExpectations(projectRestURL + "/" + projectId + "/bank-details/status-summary", ProjectBankDetailsStatusSummary.class, projectBankDetailsStatusSummary, OK); RestResult<ProjectBankDetailsStatusSummary> response = service.getBankDetailsStatusSummaryByProject(projectId); assertTrue(response.isSuccess()); assertEquals(projectBankDetailsStatusSummary, response.getSuccess()); }
BankDetailsRestServiceImpl extends BaseRestService implements BankDetailsRestService { @Override public RestResult<ByteArrayResource> downloadByCompetition(Long competitionId) { String url = competitionRestURL + "/" + competitionId + "/bank-details/export"; return getWithRestResult(url, ByteArrayResource.class); } @Override RestResult<BankDetailsResource> getByProjectIdAndBankDetailsId(final Long projectId, final Long bankDetailsId); @Override RestResult<Void> submitBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<Void> updateBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<BankDetailsResource> getBankDetailsByProjectAndOrganisation(Long projectId, Long organisationId); @Override RestResult<ProjectBankDetailsStatusSummary> getBankDetailsStatusSummaryByProject(Long projectId); @Override RestResult<ByteArrayResource> downloadByCompetition(Long competitionId); @Override RestResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override RestResult<Long> countPendingBankDetailsApprovals(); }
@Test public void testDownloadByCompetition() { Long competitionId = 123L; ByteArrayResource returnedFileContents = new ByteArrayResource("Retrieved content".getBytes()); String url = competitionRestURL + "/" + competitionId + "/bank-details/export"; setupGetWithRestResultExpectations(url, ByteArrayResource.class, returnedFileContents, OK); ByteArrayResource retrievedFileEntry = service.downloadByCompetition(123L).getSuccess(); assertEquals(returnedFileContents, retrievedFileEntry); }
BankDetailsRestServiceImpl extends BaseRestService implements BankDetailsRestService { @Override public RestResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals() { return getWithRestResult(competitionsRestURL + "/pending-bank-details-approvals", bankDetailsReviewResourceListType()); } @Override RestResult<BankDetailsResource> getByProjectIdAndBankDetailsId(final Long projectId, final Long bankDetailsId); @Override RestResult<Void> submitBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<Void> updateBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<BankDetailsResource> getBankDetailsByProjectAndOrganisation(Long projectId, Long organisationId); @Override RestResult<ProjectBankDetailsStatusSummary> getBankDetailsStatusSummaryByProject(Long projectId); @Override RestResult<ByteArrayResource> downloadByCompetition(Long competitionId); @Override RestResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override RestResult<Long> countPendingBankDetailsApprovals(); }
@Test public void getPendingBankDetailsApprovals() { List<BankDetailsReviewResource> returnedResponse = singletonList(new BankDetailsReviewResource()); setupGetWithRestResultExpectations(competitionsRestURL + "/pending-bank-details-approvals", bankDetailsReviewResourceListType(), returnedResponse); List<BankDetailsReviewResource> response = service.getPendingBankDetailsApprovals().getSuccess(); assertNotNull(response); Assert.assertEquals(returnedResponse, response); }
BankDetailsRestServiceImpl extends BaseRestService implements BankDetailsRestService { @Override public RestResult<Long> countPendingBankDetailsApprovals() { return getWithRestResult(competitionsRestURL + "/count-pending-bank-details-approvals", Long.class); } @Override RestResult<BankDetailsResource> getByProjectIdAndBankDetailsId(final Long projectId, final Long bankDetailsId); @Override RestResult<Void> submitBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<Void> updateBankDetails(final Long projectId, final BankDetailsResource bankDetailsResource); @Override RestResult<BankDetailsResource> getBankDetailsByProjectAndOrganisation(Long projectId, Long organisationId); @Override RestResult<ProjectBankDetailsStatusSummary> getBankDetailsStatusSummaryByProject(Long projectId); @Override RestResult<ByteArrayResource> downloadByCompetition(Long competitionId); @Override RestResult<List<BankDetailsReviewResource>> getPendingBankDetailsApprovals(); @Override RestResult<Long> countPendingBankDetailsApprovals(); }
@Test public void countPendingBankDetailsApprovals() { Long pendingBankDetailsCount = 8L; setupGetWithRestResultExpectations(competitionsRestURL + "/count-pending-bank-details-approvals", Long.class, pendingBankDetailsCount); Long response = service.countPendingBankDetailsApprovals().getSuccess(); assertNotNull(response); Assert.assertEquals(pendingBankDetailsCount, response); }
GrantOfferLetterRestServiceImpl extends BaseRestService implements GrantOfferLetterRestService { @Override public RestResult<Optional<ByteArrayResource>> getSignedGrantOfferLetterFile(Long projectId) { return getWithRestResult(projectRestURL + "/" + projectId + "/signed-grant-offer", ByteArrayResource.class).toOptionalIfNotFound(); } @Override RestResult<Void> sendGrantOfferLetter(Long projectId); @Override RestResult<Optional<FileEntryResource>> getSignedGrantOfferLetterFileDetails(Long projectId); @Override RestResult<FileEntryResource> addSignedGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<FileEntryResource> addGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Void> removeGrantOfferLetter(Long projectId); @Override RestResult<Void> removeAdditionalContractFile(Long projectId); @Override RestResult<Void> removeSignedGrantOfferLetter(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getGrantOfferFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getGrantOfferFileDetails(Long projectId); @Override RestResult<Void> submitGrantOfferLetter(Long projectId); @Override RestResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getSignedGrantOfferLetterFile(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getAdditionalContractFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getAdditionalContractFileDetails(Long projectId); @Override RestResult<FileEntryResource> addAdditionalContractFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<StringResource> getDocusignUrl(long projectId); @Override RestResult<Void> importSignedOfferLetter(long projectId); }
@Test public void testGetSignedGrantOfferLetterFileContent() { String expectedUrl = projectRestURL + "/123/signed-grant-offer"; ByteArrayResource returnedFileContents = new ByteArrayResource("Retrieved content".getBytes()); setupGetWithRestResultExpectations(expectedUrl, ByteArrayResource.class, returnedFileContents, OK); ByteArrayResource retrievedFileEntry = service.getSignedGrantOfferLetterFile(123L).getSuccess().get(); assertEquals(returnedFileContents, retrievedFileEntry); } @Test public void testGetSignedGrantOfferLetterFileContentEmptyIfNotFound() { String expectedUrl = projectRestURL + "/123/signed-grant-offer"; setupGetWithRestResultExpectations(expectedUrl, ByteArrayResource.class, null, NOT_FOUND); Optional<ByteArrayResource> retrievedFileEntry = service.getSignedGrantOfferLetterFile(123L).getSuccess(); assertFalse(retrievedFileEntry.isPresent()); }
UsersRolesServiceImpl extends BaseTransactionalService implements UsersRolesService { @Override public ServiceResult<List<ProcessRoleResource>> getAssignableProcessRolesByApplicationId(long applicationId) { List<ProcessRole> processRoles = processRoleRepository.findByApplicationId(applicationId); Set<ProcessRoleResource> assignableProcessRoleResources = processRoles.stream() .filter(r -> LEADAPPLICANT == r.getRole() || COLLABORATOR == r.getRole()) .map(processRoleMapper::mapToResource) .collect(Collectors.toSet()); return serviceSuccess(new ArrayList<>(assignableProcessRoleResources)); } @Override ServiceResult<ProcessRoleResource> getProcessRoleById(long id); @Override ServiceResult<List<ProcessRoleResource>> getProcessRolesByIds(Long[] ids); @Override ServiceResult<List<ProcessRoleResource>> getProcessRolesByApplicationId(long applicationId); @Override ServiceResult<ProcessRoleResource> getProcessRoleByUserIdAndApplicationId(long userId, long applicationId); @Override ServiceResult<List<ProcessRoleResource>> getProcessRolesByUserId(long userId); @Override ServiceResult<List<ProcessRoleResource>> getAssignableProcessRolesByApplicationId(long applicationId); @Override ServiceResult<Boolean> userHasApplicationForCompetition(long userId, long competitionId); }
@Test public void getAssignableProcessRolesByApplicationIdForLeadApplicant() { List<ProcessRole> processRoles = newProcessRole().withRole(Role.LEADAPPLICANT).build(2); List<ProcessRoleResource> processRoleResources = newProcessRoleResource().build(2); when(processRoleRepositoryMock.findByApplicationId(1L)).thenReturn(processRoles); zip(processRoles, processRoleResources, (pr, prr) -> when(processRoleMapperMock.mapToResource(same(pr))).thenReturn(prr)); ServiceResult<List<ProcessRoleResource>> result = service.getAssignableProcessRolesByApplicationId(1L); assertTrue(result.isSuccess()); assertEquals(processRoleResources.size(), result.getSuccess().size()); verify(processRoleRepositoryMock, only()).findByApplicationId(1L); } @Test public void getAssignableProcessRolesByApplicationIdForCollaborator() { List<ProcessRole> processRoles = newProcessRole().withRole(Role.COLLABORATOR).build(2); List<ProcessRoleResource> processRoleResources = newProcessRoleResource().build(2); when(processRoleRepositoryMock.findByApplicationId(1L)).thenReturn(processRoles); zip(processRoles, processRoleResources, (pr, prr) -> when(processRoleMapperMock.mapToResource(same(pr))).thenReturn(prr)); ServiceResult<List<ProcessRoleResource>> result = service.getAssignableProcessRolesByApplicationId(1L); assertTrue(result.isSuccess()); assertEquals(processRoleResources.size(), result.getSuccess().size()); verify(processRoleRepositoryMock, only()).findByApplicationId(1L); }
GrantOfferLetterRestServiceImpl extends BaseRestService implements GrantOfferLetterRestService { @Override public RestResult<Optional<ByteArrayResource>> getGrantOfferFile(Long projectId) { return getWithRestResult(projectRestURL + "/" + projectId + "/grant-offer", ByteArrayResource.class).toOptionalIfNotFound(); } @Override RestResult<Void> sendGrantOfferLetter(Long projectId); @Override RestResult<Optional<FileEntryResource>> getSignedGrantOfferLetterFileDetails(Long projectId); @Override RestResult<FileEntryResource> addSignedGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<FileEntryResource> addGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Void> removeGrantOfferLetter(Long projectId); @Override RestResult<Void> removeAdditionalContractFile(Long projectId); @Override RestResult<Void> removeSignedGrantOfferLetter(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getGrantOfferFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getGrantOfferFileDetails(Long projectId); @Override RestResult<Void> submitGrantOfferLetter(Long projectId); @Override RestResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getSignedGrantOfferLetterFile(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getAdditionalContractFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getAdditionalContractFileDetails(Long projectId); @Override RestResult<FileEntryResource> addAdditionalContractFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<StringResource> getDocusignUrl(long projectId); @Override RestResult<Void> importSignedOfferLetter(long projectId); }
@Test public void testGetGeneratedGrantOfferLetterFileContent() { String expectedUrl = projectRestURL + "/123/grant-offer"; ByteArrayResource returnedFileContents = new ByteArrayResource("Retrieved content".getBytes()); setupGetWithRestResultExpectations(expectedUrl, ByteArrayResource.class, returnedFileContents, OK); ByteArrayResource retrievedFileEntry = service.getGrantOfferFile(123L).getSuccess().get(); assertEquals(returnedFileContents, retrievedFileEntry); } @Test public void testGetGeneratedGrantOfferLetterFileContentEmptyIfNotFound() { String expectedUrl = projectRestURL + "/123/grant-offer"; setupGetWithRestResultExpectations(expectedUrl, ByteArrayResource.class, null, NOT_FOUND); Optional<ByteArrayResource> retrievedFileEntry = service.getGrantOfferFile(123L).getSuccess(); assertFalse(retrievedFileEntry.isPresent()); }
GrantOfferLetterRestServiceImpl extends BaseRestService implements GrantOfferLetterRestService { @Override public RestResult<Void> removeGrantOfferLetter(Long projectId) { return deleteWithRestResult(projectRestURL + "/" + projectId + "/grant-offer"); } @Override RestResult<Void> sendGrantOfferLetter(Long projectId); @Override RestResult<Optional<FileEntryResource>> getSignedGrantOfferLetterFileDetails(Long projectId); @Override RestResult<FileEntryResource> addSignedGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<FileEntryResource> addGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Void> removeGrantOfferLetter(Long projectId); @Override RestResult<Void> removeAdditionalContractFile(Long projectId); @Override RestResult<Void> removeSignedGrantOfferLetter(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getGrantOfferFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getGrantOfferFileDetails(Long projectId); @Override RestResult<Void> submitGrantOfferLetter(Long projectId); @Override RestResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getSignedGrantOfferLetterFile(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getAdditionalContractFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getAdditionalContractFileDetails(Long projectId); @Override RestResult<FileEntryResource> addAdditionalContractFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<StringResource> getDocusignUrl(long projectId); @Override RestResult<Void> importSignedOfferLetter(long projectId); }
@Test public void testRemoveGeneratedGrantOfferLetter() { Long projectId = 123L; String nonBaseUrl = projectRestURL + "/" + projectId + "/grant-offer"; setupDeleteWithRestResultExpectations(nonBaseUrl); RestResult<Void> result = service.removeGrantOfferLetter(projectId); assertTrue(result.isSuccess()); setupDeleteWithRestResultVerifications(nonBaseUrl); }
GrantOfferLetterRestServiceImpl extends BaseRestService implements GrantOfferLetterRestService { @Override public RestResult<Void> removeAdditionalContractFile(Long projectId) { return deleteWithRestResult(projectRestURL + "/" + projectId + "/additional-contract"); } @Override RestResult<Void> sendGrantOfferLetter(Long projectId); @Override RestResult<Optional<FileEntryResource>> getSignedGrantOfferLetterFileDetails(Long projectId); @Override RestResult<FileEntryResource> addSignedGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<FileEntryResource> addGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Void> removeGrantOfferLetter(Long projectId); @Override RestResult<Void> removeAdditionalContractFile(Long projectId); @Override RestResult<Void> removeSignedGrantOfferLetter(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getGrantOfferFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getGrantOfferFileDetails(Long projectId); @Override RestResult<Void> submitGrantOfferLetter(Long projectId); @Override RestResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getSignedGrantOfferLetterFile(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getAdditionalContractFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getAdditionalContractFileDetails(Long projectId); @Override RestResult<FileEntryResource> addAdditionalContractFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<StringResource> getDocusignUrl(long projectId); @Override RestResult<Void> importSignedOfferLetter(long projectId); }
@Test public void testRemoveAdditionalContractFile() { Long projectId = 123L; String nonBaseUrl = projectRestURL + "/" + projectId + "/additional-contract"; setupDeleteWithRestResultExpectations(nonBaseUrl); RestResult<Void> result = service.removeAdditionalContractFile(projectId); assertTrue(result.isSuccess()); setupDeleteWithRestResultVerifications(nonBaseUrl); }
GrantOfferLetterRestServiceImpl extends BaseRestService implements GrantOfferLetterRestService { @Override public RestResult<Void> removeSignedGrantOfferLetter(Long projectId) { return deleteWithRestResult(projectRestURL + "/" + projectId + "/signed-grant-offer-letter"); } @Override RestResult<Void> sendGrantOfferLetter(Long projectId); @Override RestResult<Optional<FileEntryResource>> getSignedGrantOfferLetterFileDetails(Long projectId); @Override RestResult<FileEntryResource> addSignedGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<FileEntryResource> addGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Void> removeGrantOfferLetter(Long projectId); @Override RestResult<Void> removeAdditionalContractFile(Long projectId); @Override RestResult<Void> removeSignedGrantOfferLetter(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getGrantOfferFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getGrantOfferFileDetails(Long projectId); @Override RestResult<Void> submitGrantOfferLetter(Long projectId); @Override RestResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getSignedGrantOfferLetterFile(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getAdditionalContractFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getAdditionalContractFileDetails(Long projectId); @Override RestResult<FileEntryResource> addAdditionalContractFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<StringResource> getDocusignUrl(long projectId); @Override RestResult<Void> importSignedOfferLetter(long projectId); }
@Test public void testRemoveSignedGrantOfferLetter() { Long projectId = 123L; String nonBaseUrl = projectRestURL + "/" + projectId + "/signed-grant-offer-letter"; setupDeleteWithRestResultExpectations(nonBaseUrl); RestResult<Void> result = service.removeSignedGrantOfferLetter(projectId); assertTrue(result.isSuccess()); setupDeleteWithRestResultVerifications(nonBaseUrl); }
GrantOfferLetterRestServiceImpl extends BaseRestService implements GrantOfferLetterRestService { @Override public RestResult<Void> submitGrantOfferLetter(Long projectId) { return postWithRestResult(projectRestURL + "/" + projectId + "/grant-offer/submit", Void.class); } @Override RestResult<Void> sendGrantOfferLetter(Long projectId); @Override RestResult<Optional<FileEntryResource>> getSignedGrantOfferLetterFileDetails(Long projectId); @Override RestResult<FileEntryResource> addSignedGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<FileEntryResource> addGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Void> removeGrantOfferLetter(Long projectId); @Override RestResult<Void> removeAdditionalContractFile(Long projectId); @Override RestResult<Void> removeSignedGrantOfferLetter(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getGrantOfferFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getGrantOfferFileDetails(Long projectId); @Override RestResult<Void> submitGrantOfferLetter(Long projectId); @Override RestResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getSignedGrantOfferLetterFile(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getAdditionalContractFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getAdditionalContractFileDetails(Long projectId); @Override RestResult<FileEntryResource> addAdditionalContractFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<StringResource> getDocusignUrl(long projectId); @Override RestResult<Void> importSignedOfferLetter(long projectId); }
@Test public void testSubmitGrantOfferLetter() { long projectId = 123L; String expectedUrl = projectRestURL + "/" + projectId + "/grant-offer/submit"; setupPostWithRestResultExpectations(expectedUrl, OK); RestResult<Void> result = service.submitGrantOfferLetter(projectId); assertTrue(result.isSuccess()); }
GrantOfferLetterRestServiceImpl extends BaseRestService implements GrantOfferLetterRestService { @Override public RestResult<Void> sendGrantOfferLetter(Long projectId) { return postWithRestResult(projectRestURL + "/" + projectId + "/grant-offer/send", Void.class); } @Override RestResult<Void> sendGrantOfferLetter(Long projectId); @Override RestResult<Optional<FileEntryResource>> getSignedGrantOfferLetterFileDetails(Long projectId); @Override RestResult<FileEntryResource> addSignedGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<FileEntryResource> addGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Void> removeGrantOfferLetter(Long projectId); @Override RestResult<Void> removeAdditionalContractFile(Long projectId); @Override RestResult<Void> removeSignedGrantOfferLetter(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getGrantOfferFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getGrantOfferFileDetails(Long projectId); @Override RestResult<Void> submitGrantOfferLetter(Long projectId); @Override RestResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getSignedGrantOfferLetterFile(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getAdditionalContractFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getAdditionalContractFileDetails(Long projectId); @Override RestResult<FileEntryResource> addAdditionalContractFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<StringResource> getDocusignUrl(long projectId); @Override RestResult<Void> importSignedOfferLetter(long projectId); }
@Test public void testSendGrantOfferLetter() { long projectId = 123L; String expectedUrl = projectRestURL + "/" + projectId + "/grant-offer/send"; setupPostWithRestResultExpectations(expectedUrl, OK); RestResult<Void> result = service.sendGrantOfferLetter(projectId); assertTrue(result.isSuccess()); }
GrantOfferLetterRestServiceImpl extends BaseRestService implements GrantOfferLetterRestService { @Override public RestResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource) { return postWithRestResult(projectRestURL + "/" + projectId + "/signed-grant-offer-letter/approval/", grantOfferLetterApprovalResource, Void.class); } @Override RestResult<Void> sendGrantOfferLetter(Long projectId); @Override RestResult<Optional<FileEntryResource>> getSignedGrantOfferLetterFileDetails(Long projectId); @Override RestResult<FileEntryResource> addSignedGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<FileEntryResource> addGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Void> removeGrantOfferLetter(Long projectId); @Override RestResult<Void> removeAdditionalContractFile(Long projectId); @Override RestResult<Void> removeSignedGrantOfferLetter(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getGrantOfferFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getGrantOfferFileDetails(Long projectId); @Override RestResult<Void> submitGrantOfferLetter(Long projectId); @Override RestResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getSignedGrantOfferLetterFile(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getAdditionalContractFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getAdditionalContractFileDetails(Long projectId); @Override RestResult<FileEntryResource> addAdditionalContractFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<StringResource> getDocusignUrl(long projectId); @Override RestResult<Void> importSignedOfferLetter(long projectId); }
@Test public void testApproveSignedGrantOfferLetter() { long projectId = 123L; GrantOfferLetterApprovalResource grantOfferLetterApprovalResource = new GrantOfferLetterApprovalResource(ApprovalType.APPROVED, null); String expectedUrl = projectRestURL + "/" + projectId + "/signed-grant-offer-letter/approval/"; setupPostWithRestResultExpectations(expectedUrl, grantOfferLetterApprovalResource, OK); RestResult<Void> result = service.approveOrRejectSignedGrantOfferLetter(projectId, grantOfferLetterApprovalResource); setupPostWithRestResultVerifications(expectedUrl, Void.class, grantOfferLetterApprovalResource); assertTrue(result.isSuccess()); }
GrantOfferLetterRestServiceImpl extends BaseRestService implements GrantOfferLetterRestService { @Override public RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId) { return getWithRestResult(projectRestURL + "/" + projectId + "/grant-offer-letter/current-state", GrantOfferLetterStateResource.class); } @Override RestResult<Void> sendGrantOfferLetter(Long projectId); @Override RestResult<Optional<FileEntryResource>> getSignedGrantOfferLetterFileDetails(Long projectId); @Override RestResult<FileEntryResource> addSignedGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<FileEntryResource> addGrantOfferLetterFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<Void> removeGrantOfferLetter(Long projectId); @Override RestResult<Void> removeAdditionalContractFile(Long projectId); @Override RestResult<Void> removeSignedGrantOfferLetter(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getGrantOfferFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getGrantOfferFileDetails(Long projectId); @Override RestResult<Void> submitGrantOfferLetter(Long projectId); @Override RestResult<Void> approveOrRejectSignedGrantOfferLetter(Long projectId, GrantOfferLetterApprovalResource grantOfferLetterApprovalResource); @Override RestResult<GrantOfferLetterStateResource> getGrantOfferLetterState(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getSignedGrantOfferLetterFile(Long projectId); @Override RestResult<Optional<ByteArrayResource>> getAdditionalContractFile(Long projectId); @Override RestResult<Optional<FileEntryResource>> getAdditionalContractFileDetails(Long projectId); @Override RestResult<FileEntryResource> addAdditionalContractFile(Long projectId, String contentType, long contentLength, String originalFilename, byte[] bytes); @Override RestResult<StringResource> getDocusignUrl(long projectId); @Override RestResult<Void> importSignedOfferLetter(long projectId); }
@Test public void testGetGrantOfferLetterState() { long projectId = 123L; String nonBaseUrl = projectRestURL + "/" + projectId + "/grant-offer-letter/current-state"; GrantOfferLetterStateResource state = GrantOfferLetterStateResource.stateInformationForNonPartnersView(GrantOfferLetterState.APPROVED, GrantOfferLetterEvent.SIGNED_GOL_APPROVED); setupGetWithRestResultExpectations(nonBaseUrl, GrantOfferLetterStateResource.class, state, OK); RestResult<GrantOfferLetterStateResource> result = service.getGrantOfferLetterState(projectId); assertTrue(result.isSuccess()); assertSame(state, result.getSuccess()); }
FinanceCheckRestServiceImpl extends BaseRestService implements FinanceCheckRestService { @Override public RestResult<Void> approveFinanceCheck(Long projectId, Long organisationId) { String url = FinanceCheckURIs.BASE_URL + "/" + projectId + FinanceCheckURIs.ORGANISATION_PATH + "/" + organisationId + FinanceCheckURIs.PATH + "/approve"; return postWithRestResult(url, Void.class); } @Override RestResult<FinanceCheckResource> getByProjectAndOrganisation(Long projectId, Long organisationId); @Override RestResult<Void> update(FinanceCheckResource financeCheckResource); @Override RestResult<FinanceCheckSummaryResource> getFinanceCheckSummary(Long projectId); @Override RestResult<FinanceCheckOverviewResource> getFinanceCheckOverview(Long projectId); @Override RestResult<Void> approveFinanceCheck(Long projectId, Long organisationId); @Override RestResult<FinanceCheckEligibilityResource> getFinanceCheckEligibilityDetails(Long projectId, Long organisationId); }
@Test public void testApprove() { setupPostWithRestResultExpectations("/project/123/partner-organisation/456/finance-check/approve", OK); service.approveFinanceCheck(123L, 456L); setupPostWithRestResultVerifications("/project/123/partner-organisation/456/finance-check/approve", Void.class); }
FinanceCheckRestServiceImpl extends BaseRestService implements FinanceCheckRestService { @Override public RestResult<FinanceCheckEligibilityResource> getFinanceCheckEligibilityDetails(Long projectId, Long organisationId) { String url = FinanceCheckURIs.BASE_URL + "/" + projectId + FinanceCheckURIs.ORGANISATION_PATH + "/" + organisationId + FinanceCheckURIs.PATH + "/eligibility"; return getWithRestResult(url, FinanceCheckEligibilityResource.class); } @Override RestResult<FinanceCheckResource> getByProjectAndOrganisation(Long projectId, Long organisationId); @Override RestResult<Void> update(FinanceCheckResource financeCheckResource); @Override RestResult<FinanceCheckSummaryResource> getFinanceCheckSummary(Long projectId); @Override RestResult<FinanceCheckOverviewResource> getFinanceCheckOverview(Long projectId); @Override RestResult<Void> approveFinanceCheck(Long projectId, Long organisationId); @Override RestResult<FinanceCheckEligibilityResource> getFinanceCheckEligibilityDetails(Long projectId, Long organisationId); }
@Test public void testGetFinanceCheckEligibility() { FinanceCheckEligibilityResource processStatus = new FinanceCheckEligibilityResource(); setupGetWithRestResultExpectations("/project/123/partner-organisation/456/finance-check/eligibility", FinanceCheckEligibilityResource.class, processStatus); Assert.assertEquals(processStatus, service.getFinanceCheckEligibilityDetails(123L, 456L).getSuccess()); }
FinanceCheckRestServiceImpl extends BaseRestService implements FinanceCheckRestService { @Override public RestResult<FinanceCheckOverviewResource> getFinanceCheckOverview(Long projectId) { String url = FinanceCheckURIs.BASE_URL + "/" + projectId + FinanceCheckURIs.PATH + "/overview"; return getWithRestResult(url, FinanceCheckOverviewResource.class); } @Override RestResult<FinanceCheckResource> getByProjectAndOrganisation(Long projectId, Long organisationId); @Override RestResult<Void> update(FinanceCheckResource financeCheckResource); @Override RestResult<FinanceCheckSummaryResource> getFinanceCheckSummary(Long projectId); @Override RestResult<FinanceCheckOverviewResource> getFinanceCheckOverview(Long projectId); @Override RestResult<Void> approveFinanceCheck(Long projectId, Long organisationId); @Override RestResult<FinanceCheckEligibilityResource> getFinanceCheckEligibilityDetails(Long projectId, Long organisationId); }
@Test public void testGetFinanceCheckOverview() { FinanceCheckOverviewResource processStatus = new FinanceCheckOverviewResource(); setupGetWithRestResultExpectations("/project/123/finance-check/overview", FinanceCheckOverviewResource.class, processStatus); Assert.assertEquals(processStatus, service.getFinanceCheckOverview(123L).getSuccess()); }
ProjectFinanceRestServiceImpl extends BaseRestService implements ProjectFinanceRestService { @Override public RestResult<List<ProjectFinanceResource>> getProjectFinances(Long projectId) { return getWithRestResult(PROJECT_FINANCE_REST_URL + "/" + projectId + "/project-finances", projectFinanceResourceListType()); } @Override RestResult<List<ProjectFinanceResource>> getProjectFinances(Long projectId); @Override RestResult<ProjectFinanceResource> getProjectFinance(Long projectId, Long organisationId); @Override RestResult<ViabilityResource> getViability(Long projectId, Long organisationId); @PostMapping("/{projectId}/partner-organisation/{organisationId}/viability/{viability}") RestResult<Void> saveViability(Long projectId, Long organisationId, ViabilityState viability, ViabilityRagStatus viabilityRagStatus); @Override RestResult<EligibilityResource> getEligibility(Long projectId, Long organisationId); @Override RestResult<Void> saveEligibility(Long projectId, Long organisationId, EligibilityState eligibility, EligibilityRagStatus eligibilityRagStatus); @Override RestResult<Boolean> isCreditReportConfirmed(Long projectId, Long organisationId); @Override RestResult<Void> saveCreditReportConfirmed(Long projectId, Long organisationId, boolean confirmed); @Override RestResult<List<ProjectFinanceResource>> getFinanceTotals(Long applicationId); @Override RestResult<ProjectFinanceResource> addProjectFinanceForOrganisation(Long projectId, Long organisationId); @Override RestResult<Boolean> hasAnyProjectOrganisationSizeChangedFromApplication(long projectId); }
@Test public void getProjectFinances() { Long projectId = 123L; List<ProjectFinanceResource> results = newProjectFinanceResource().build(2); setupGetWithRestResultExpectations(projectFinanceRestURL + "/" + projectId + "/project-finances", projectFinanceResourceListType(), results); RestResult<List<ProjectFinanceResource>> result = service.getProjectFinances(projectId); assertEquals(results, result.getSuccess()); }
ProjectFinanceRestServiceImpl extends BaseRestService implements ProjectFinanceRestService { @Override public RestResult<ViabilityResource> getViability(Long projectId, Long organisationId) { return getWithRestResult(PROJECT_FINANCE_REST_URL + "/" + projectId + "/partner-organisation/" + organisationId + "/viability", ViabilityResource.class); } @Override RestResult<List<ProjectFinanceResource>> getProjectFinances(Long projectId); @Override RestResult<ProjectFinanceResource> getProjectFinance(Long projectId, Long organisationId); @Override RestResult<ViabilityResource> getViability(Long projectId, Long organisationId); @PostMapping("/{projectId}/partner-organisation/{organisationId}/viability/{viability}") RestResult<Void> saveViability(Long projectId, Long organisationId, ViabilityState viability, ViabilityRagStatus viabilityRagStatus); @Override RestResult<EligibilityResource> getEligibility(Long projectId, Long organisationId); @Override RestResult<Void> saveEligibility(Long projectId, Long organisationId, EligibilityState eligibility, EligibilityRagStatus eligibilityRagStatus); @Override RestResult<Boolean> isCreditReportConfirmed(Long projectId, Long organisationId); @Override RestResult<Void> saveCreditReportConfirmed(Long projectId, Long organisationId, boolean confirmed); @Override RestResult<List<ProjectFinanceResource>> getFinanceTotals(Long applicationId); @Override RestResult<ProjectFinanceResource> addProjectFinanceForOrganisation(Long projectId, Long organisationId); @Override RestResult<Boolean> hasAnyProjectOrganisationSizeChangedFromApplication(long projectId); }
@Test public void getViability() { ViabilityResource viability = new ViabilityResource(ViabilityState.APPROVED, ViabilityRagStatus.GREEN); setupGetWithRestResultExpectations(projectFinanceRestURL + "/123/partner-organisation/456/viability", ViabilityResource.class, viability); RestResult<ViabilityResource> results = service.getViability(123L, 456L); assertEquals(ViabilityState.APPROVED, results.getSuccess().getViability()); assertEquals(ViabilityRagStatus.GREEN, results.getSuccess().getViabilityRagStatus()); }
ProjectFinanceRestServiceImpl extends BaseRestService implements ProjectFinanceRestService { @PostMapping("/{projectId}/partner-organisation/{organisationId}/viability/{viability}") public RestResult<Void> saveViability(Long projectId, Long organisationId, ViabilityState viability, ViabilityRagStatus viabilityRagStatus) { String postUrl = PROJECT_FINANCE_REST_URL + "/" + projectId + "/partner-organisation/" + organisationId + "/viability/" + viability.name() + "/" + viabilityRagStatus.name(); return postWithRestResult(postUrl, Void.class); } @Override RestResult<List<ProjectFinanceResource>> getProjectFinances(Long projectId); @Override RestResult<ProjectFinanceResource> getProjectFinance(Long projectId, Long organisationId); @Override RestResult<ViabilityResource> getViability(Long projectId, Long organisationId); @PostMapping("/{projectId}/partner-organisation/{organisationId}/viability/{viability}") RestResult<Void> saveViability(Long projectId, Long organisationId, ViabilityState viability, ViabilityRagStatus viabilityRagStatus); @Override RestResult<EligibilityResource> getEligibility(Long projectId, Long organisationId); @Override RestResult<Void> saveEligibility(Long projectId, Long organisationId, EligibilityState eligibility, EligibilityRagStatus eligibilityRagStatus); @Override RestResult<Boolean> isCreditReportConfirmed(Long projectId, Long organisationId); @Override RestResult<Void> saveCreditReportConfirmed(Long projectId, Long organisationId, boolean confirmed); @Override RestResult<List<ProjectFinanceResource>> getFinanceTotals(Long applicationId); @Override RestResult<ProjectFinanceResource> addProjectFinanceForOrganisation(Long projectId, Long organisationId); @Override RestResult<Boolean> hasAnyProjectOrganisationSizeChangedFromApplication(long projectId); }
@Test public void saveViability() { String postUrl = projectFinanceRestURL + "/123/partner-organisation/456/viability/" + ViabilityState.APPROVED.name() + "/" + ViabilityRagStatus.RED.name(); setupPostWithRestResultExpectations(postUrl, OK); RestResult<Void> result = service.saveViability(123L, 456L, ViabilityState.APPROVED, ViabilityRagStatus.RED); assertTrue(result.isSuccess()); setupPostWithRestResultVerifications(postUrl, Void.class); }
ProjectFinanceRestServiceImpl extends BaseRestService implements ProjectFinanceRestService { @Override public RestResult<EligibilityResource> getEligibility(Long projectId, Long organisationId) { return getWithRestResult(PROJECT_FINANCE_REST_URL + "/" + projectId + "/partner-organisation/" + organisationId + "/eligibility", EligibilityResource.class); } @Override RestResult<List<ProjectFinanceResource>> getProjectFinances(Long projectId); @Override RestResult<ProjectFinanceResource> getProjectFinance(Long projectId, Long organisationId); @Override RestResult<ViabilityResource> getViability(Long projectId, Long organisationId); @PostMapping("/{projectId}/partner-organisation/{organisationId}/viability/{viability}") RestResult<Void> saveViability(Long projectId, Long organisationId, ViabilityState viability, ViabilityRagStatus viabilityRagStatus); @Override RestResult<EligibilityResource> getEligibility(Long projectId, Long organisationId); @Override RestResult<Void> saveEligibility(Long projectId, Long organisationId, EligibilityState eligibility, EligibilityRagStatus eligibilityRagStatus); @Override RestResult<Boolean> isCreditReportConfirmed(Long projectId, Long organisationId); @Override RestResult<Void> saveCreditReportConfirmed(Long projectId, Long organisationId, boolean confirmed); @Override RestResult<List<ProjectFinanceResource>> getFinanceTotals(Long applicationId); @Override RestResult<ProjectFinanceResource> addProjectFinanceForOrganisation(Long projectId, Long organisationId); @Override RestResult<Boolean> hasAnyProjectOrganisationSizeChangedFromApplication(long projectId); }
@Test public void getEligibility() { EligibilityResource eligibility = new EligibilityResource(EligibilityState.APPROVED, EligibilityRagStatus.GREEN); setupGetWithRestResultExpectations(projectFinanceRestURL + "/123/partner-organisation/456/eligibility", EligibilityResource.class, eligibility); RestResult<EligibilityResource> results = service.getEligibility(123L, 456L); assertEquals(EligibilityState.APPROVED, results.getSuccess().getEligibility()); assertEquals(EligibilityRagStatus.GREEN, results.getSuccess().getEligibilityRagStatus()); }
ProjectFinanceRestServiceImpl extends BaseRestService implements ProjectFinanceRestService { @Override public RestResult<Void> saveEligibility(Long projectId, Long organisationId, EligibilityState eligibility, EligibilityRagStatus eligibilityRagStatus) { String postUrl = PROJECT_FINANCE_REST_URL + "/" + projectId + "/partner-organisation/" + organisationId + "/eligibility/" + eligibility.name() + "/" + eligibilityRagStatus.name(); return postWithRestResult(postUrl, Void.class); } @Override RestResult<List<ProjectFinanceResource>> getProjectFinances(Long projectId); @Override RestResult<ProjectFinanceResource> getProjectFinance(Long projectId, Long organisationId); @Override RestResult<ViabilityResource> getViability(Long projectId, Long organisationId); @PostMapping("/{projectId}/partner-organisation/{organisationId}/viability/{viability}") RestResult<Void> saveViability(Long projectId, Long organisationId, ViabilityState viability, ViabilityRagStatus viabilityRagStatus); @Override RestResult<EligibilityResource> getEligibility(Long projectId, Long organisationId); @Override RestResult<Void> saveEligibility(Long projectId, Long organisationId, EligibilityState eligibility, EligibilityRagStatus eligibilityRagStatus); @Override RestResult<Boolean> isCreditReportConfirmed(Long projectId, Long organisationId); @Override RestResult<Void> saveCreditReportConfirmed(Long projectId, Long organisationId, boolean confirmed); @Override RestResult<List<ProjectFinanceResource>> getFinanceTotals(Long applicationId); @Override RestResult<ProjectFinanceResource> addProjectFinanceForOrganisation(Long projectId, Long organisationId); @Override RestResult<Boolean> hasAnyProjectOrganisationSizeChangedFromApplication(long projectId); }
@Test public void saveEligibility() { String postUrl = projectFinanceRestURL + "/123/partner-organisation/456/eligibility/" + EligibilityState.APPROVED.name() + "/" + EligibilityRagStatus.RED.name(); setupPostWithRestResultExpectations(postUrl, OK); RestResult<Void> result = service.saveEligibility(123L, 456L, EligibilityState.APPROVED, EligibilityRagStatus.RED); assertTrue(result.isSuccess()); setupPostWithRestResultVerifications(postUrl, Void.class); }
ProjectFinanceRestServiceImpl extends BaseRestService implements ProjectFinanceRestService { @Override public RestResult<Boolean> isCreditReportConfirmed(Long projectId, Long organisationId) { String url = PROJECT_FINANCE_REST_URL + "/" + projectId + "/partner-organisation/" + organisationId + "/credit-report"; return getWithRestResult(url, Boolean.class); } @Override RestResult<List<ProjectFinanceResource>> getProjectFinances(Long projectId); @Override RestResult<ProjectFinanceResource> getProjectFinance(Long projectId, Long organisationId); @Override RestResult<ViabilityResource> getViability(Long projectId, Long organisationId); @PostMapping("/{projectId}/partner-organisation/{organisationId}/viability/{viability}") RestResult<Void> saveViability(Long projectId, Long organisationId, ViabilityState viability, ViabilityRagStatus viabilityRagStatus); @Override RestResult<EligibilityResource> getEligibility(Long projectId, Long organisationId); @Override RestResult<Void> saveEligibility(Long projectId, Long organisationId, EligibilityState eligibility, EligibilityRagStatus eligibilityRagStatus); @Override RestResult<Boolean> isCreditReportConfirmed(Long projectId, Long organisationId); @Override RestResult<Void> saveCreditReportConfirmed(Long projectId, Long organisationId, boolean confirmed); @Override RestResult<List<ProjectFinanceResource>> getFinanceTotals(Long applicationId); @Override RestResult<ProjectFinanceResource> addProjectFinanceForOrganisation(Long projectId, Long organisationId); @Override RestResult<Boolean> hasAnyProjectOrganisationSizeChangedFromApplication(long projectId); }
@Test public void isCreditReportConfirmed() { setupGetWithRestResultExpectations(projectFinanceRestURL + "/123/partner-organisation/456/credit-report", Boolean.class, true); RestResult<Boolean> results = service.isCreditReportConfirmed(123L, 456L); assertTrue(results.getSuccess()); }
ProjectFinanceRestServiceImpl extends BaseRestService implements ProjectFinanceRestService { @Override public RestResult<Void> saveCreditReportConfirmed(Long projectId, Long organisationId, boolean confirmed) { String url = PROJECT_FINANCE_REST_URL + "/" + projectId + "/partner-organisation/" + organisationId + "/credit-report/" + confirmed; return postWithRestResult(url); } @Override RestResult<List<ProjectFinanceResource>> getProjectFinances(Long projectId); @Override RestResult<ProjectFinanceResource> getProjectFinance(Long projectId, Long organisationId); @Override RestResult<ViabilityResource> getViability(Long projectId, Long organisationId); @PostMapping("/{projectId}/partner-organisation/{organisationId}/viability/{viability}") RestResult<Void> saveViability(Long projectId, Long organisationId, ViabilityState viability, ViabilityRagStatus viabilityRagStatus); @Override RestResult<EligibilityResource> getEligibility(Long projectId, Long organisationId); @Override RestResult<Void> saveEligibility(Long projectId, Long organisationId, EligibilityState eligibility, EligibilityRagStatus eligibilityRagStatus); @Override RestResult<Boolean> isCreditReportConfirmed(Long projectId, Long organisationId); @Override RestResult<Void> saveCreditReportConfirmed(Long projectId, Long organisationId, boolean confirmed); @Override RestResult<List<ProjectFinanceResource>> getFinanceTotals(Long applicationId); @Override RestResult<ProjectFinanceResource> addProjectFinanceForOrganisation(Long projectId, Long organisationId); @Override RestResult<Boolean> hasAnyProjectOrganisationSizeChangedFromApplication(long projectId); }
@Test public void saveCreditReportConfirmed() { String postUrl = projectFinanceRestURL + "/123/partner-organisation/456/credit-report/true"; setupPostWithRestResultExpectations(postUrl, OK); RestResult<Void> result = service.saveCreditReportConfirmed(123L, 456L, true); assertTrue(result.isSuccess()); setupPostWithRestResultVerifications(postUrl, Void.class); }
ProjectFinanceRestServiceImpl extends BaseRestService implements ProjectFinanceRestService { @Override public RestResult<ProjectFinanceResource> getProjectFinance(Long projectId, Long organisationId) { return getWithRestResult(PROJECT_FINANCE_REST_URL + "/" + projectId + "/organisation/" + organisationId + "/finance-details", ProjectFinanceResource.class); } @Override RestResult<List<ProjectFinanceResource>> getProjectFinances(Long projectId); @Override RestResult<ProjectFinanceResource> getProjectFinance(Long projectId, Long organisationId); @Override RestResult<ViabilityResource> getViability(Long projectId, Long organisationId); @PostMapping("/{projectId}/partner-organisation/{organisationId}/viability/{viability}") RestResult<Void> saveViability(Long projectId, Long organisationId, ViabilityState viability, ViabilityRagStatus viabilityRagStatus); @Override RestResult<EligibilityResource> getEligibility(Long projectId, Long organisationId); @Override RestResult<Void> saveEligibility(Long projectId, Long organisationId, EligibilityState eligibility, EligibilityRagStatus eligibilityRagStatus); @Override RestResult<Boolean> isCreditReportConfirmed(Long projectId, Long organisationId); @Override RestResult<Void> saveCreditReportConfirmed(Long projectId, Long organisationId, boolean confirmed); @Override RestResult<List<ProjectFinanceResource>> getFinanceTotals(Long applicationId); @Override RestResult<ProjectFinanceResource> addProjectFinanceForOrganisation(Long projectId, Long organisationId); @Override RestResult<Boolean> hasAnyProjectOrganisationSizeChangedFromApplication(long projectId); }
@Test public void getProjectFinance() { Long projectId = 123L; Long organisationId = 456L; ProjectFinanceResource expectedResult = newProjectFinanceResource().build(); setupGetWithRestResultExpectations(projectFinanceRestURL + "/" + projectId + "/organisation/" + organisationId + "/finance-details", ProjectFinanceResource.class, expectedResult); RestResult<ProjectFinanceResource> result = service.getProjectFinance(projectId, organisationId); assertEquals(expectedResult, result.getSuccess()); }
ScheduledJesOrganisationListImporterOrganisationExtractor { ServiceResult<List<String>> extractOrganisationsFromFile(File downloadedFile) { try { List<String> organisationNames = FileUtils.readLines(downloadedFile, Charset.defaultCharset()); return serviceSuccess(organisationNames.subList(1, organisationNames.size())); } catch (IOException e) { return createServiceFailureFromIoException(e); } } }
@Test public void extractOrganisationsFromFile() throws IOException { ScheduledJesOrganisationListImporterOrganisationExtractor extractor = new ScheduledJesOrganisationListImporterOrganisationExtractor(); File testFile = File.createTempFile("jestest", "jestest"); FileUtils.writeLines(testFile, asList("Organisation names", "Org 1", "Org 2", "Org 3")); ServiceResult<List<String>> organisationExtractionResult = extractor.extractOrganisationsFromFile(testFile); assertThat(organisationExtractionResult.isSuccess()).isTrue(); List<String> organisationNames = organisationExtractionResult.getSuccess(); assertThat(organisationNames).containsExactly("Org 1", "Org 2", "Org 3"); }
ProjectFinanceRestServiceImpl extends BaseRestService implements ProjectFinanceRestService { @Override public RestResult<Boolean> hasAnyProjectOrganisationSizeChangedFromApplication(long projectId) { return getWithRestResult(format(PROJECT_FINANCE_REST_URL + "/" + projectId + "/finance/has-organisation-size-changed"), Boolean.class); } @Override RestResult<List<ProjectFinanceResource>> getProjectFinances(Long projectId); @Override RestResult<ProjectFinanceResource> getProjectFinance(Long projectId, Long organisationId); @Override RestResult<ViabilityResource> getViability(Long projectId, Long organisationId); @PostMapping("/{projectId}/partner-organisation/{organisationId}/viability/{viability}") RestResult<Void> saveViability(Long projectId, Long organisationId, ViabilityState viability, ViabilityRagStatus viabilityRagStatus); @Override RestResult<EligibilityResource> getEligibility(Long projectId, Long organisationId); @Override RestResult<Void> saveEligibility(Long projectId, Long organisationId, EligibilityState eligibility, EligibilityRagStatus eligibilityRagStatus); @Override RestResult<Boolean> isCreditReportConfirmed(Long projectId, Long organisationId); @Override RestResult<Void> saveCreditReportConfirmed(Long projectId, Long organisationId, boolean confirmed); @Override RestResult<List<ProjectFinanceResource>> getFinanceTotals(Long applicationId); @Override RestResult<ProjectFinanceResource> addProjectFinanceForOrganisation(Long projectId, Long organisationId); @Override RestResult<Boolean> hasAnyProjectOrganisationSizeChangedFromApplication(long projectId); }
@Test public void hasAnyProjectOrganisationSizeChangedFromApplication() { long projectId = 123L; setupGetWithRestResultExpectations(projectFinanceRestURL + "/" + projectId + "/finance/has-organisation-size-changed", Boolean.class, true); RestResult<Boolean> results = service.hasAnyProjectOrganisationSizeChangedFromApplication(projectId); assertTrue(results.getSuccess()); }
SpendProfileRestServiceImpl extends BaseRestService implements SpendProfileRestService { @Override public RestResult<Void> generateSpendProfile(Long projectId) { String url = PROJECT_REST_URL + "/" + projectId + "/spend-profile/generate"; return postWithRestResult(url, Void.class); } @Override RestResult<Void> generateSpendProfile(Long projectId); @Override RestResult<Void> acceptOrRejectSpendProfile(Long projectId, ApprovalType approvalType); @Override RestResult<ApprovalType> getSpendProfileStatusByProjectId(Long projectId); @Override RestResult<SpendProfileTableResource> getSpendProfileTable(Long projectId, Long organisationId); @Override RestResult<SpendProfileCSVResource> getSpendProfileCSV(Long projectId, Long organisationId); @Override RestResult<SpendProfileResource> getSpendProfile(Long projectId, Long organisationId); @Override RestResult<Void> saveSpendProfile(Long projectId, Long organisationId, SpendProfileTableResource table); @Override RestResult<Void> markSpendProfileComplete(Long projectId, Long organisationId); @Override RestResult<Void> markSpendProfileIncomplete(Long projectId, Long organisationId); @Override RestResult<Void> completeSpendProfilesReview(Long projectId); }
@Test public void testGenerateSpendProfile() { setupPostWithRestResultExpectations("/project/123/spend-profile/generate", Void.class, null, null, CREATED); service.generateSpendProfile(123L); setupPostWithRestResultVerifications("/project/123/spend-profile/generate", Void.class, null); }
SpendProfileRestServiceImpl extends BaseRestService implements SpendProfileRestService { @Override public RestResult<Void> saveSpendProfile(Long projectId, Long organisationId, SpendProfileTableResource table) { return postWithRestResult(PROJECT_REST_URL + "/" + projectId + "/partner-organisation/" + organisationId + "/spend-profile", table, Void.class); } @Override RestResult<Void> generateSpendProfile(Long projectId); @Override RestResult<Void> acceptOrRejectSpendProfile(Long projectId, ApprovalType approvalType); @Override RestResult<ApprovalType> getSpendProfileStatusByProjectId(Long projectId); @Override RestResult<SpendProfileTableResource> getSpendProfileTable(Long projectId, Long organisationId); @Override RestResult<SpendProfileCSVResource> getSpendProfileCSV(Long projectId, Long organisationId); @Override RestResult<SpendProfileResource> getSpendProfile(Long projectId, Long organisationId); @Override RestResult<Void> saveSpendProfile(Long projectId, Long organisationId, SpendProfileTableResource table); @Override RestResult<Void> markSpendProfileComplete(Long projectId, Long organisationId); @Override RestResult<Void> markSpendProfileIncomplete(Long projectId, Long organisationId); @Override RestResult<Void> completeSpendProfilesReview(Long projectId); }
@Test public void saveSpendProfile() { Long projectId = 1L; Long organisationId = 2L; SpendProfileTableResource table = new SpendProfileTableResource(); setupPostWithRestResultExpectations(projectRestURL + "/" + projectId + "/partner-organisation/" + organisationId + "/spend-profile", table, OK); RestResult<Void> result = service.saveSpendProfile(projectId, organisationId, table); setupPostWithRestResultVerifications("/project/1/partner-organisation/2/spend-profile", Void.class, table); assertTrue(result.isSuccess()); }
SpendProfileRestServiceImpl extends BaseRestService implements SpendProfileRestService { @Override public RestResult<Void> markSpendProfileComplete(Long projectId, Long organisationId) { return postWithRestResult(PROJECT_REST_URL + "/" + projectId + "/partner-organisation/" + organisationId + "/spend-profile/complete", Void.class); } @Override RestResult<Void> generateSpendProfile(Long projectId); @Override RestResult<Void> acceptOrRejectSpendProfile(Long projectId, ApprovalType approvalType); @Override RestResult<ApprovalType> getSpendProfileStatusByProjectId(Long projectId); @Override RestResult<SpendProfileTableResource> getSpendProfileTable(Long projectId, Long organisationId); @Override RestResult<SpendProfileCSVResource> getSpendProfileCSV(Long projectId, Long organisationId); @Override RestResult<SpendProfileResource> getSpendProfile(Long projectId, Long organisationId); @Override RestResult<Void> saveSpendProfile(Long projectId, Long organisationId, SpendProfileTableResource table); @Override RestResult<Void> markSpendProfileComplete(Long projectId, Long organisationId); @Override RestResult<Void> markSpendProfileIncomplete(Long projectId, Long organisationId); @Override RestResult<Void> completeSpendProfilesReview(Long projectId); }
@Test public void markSpendProfileComplete() { Long projectId = 1L; Long organisationId = 2L; setupPostWithRestResultExpectations(projectRestURL + "/" + projectId + "/partner-organisation/" + organisationId + "/spend-profile/complete", OK); RestResult<Void> result = service.markSpendProfileComplete(projectId, organisationId); setupPostWithRestResultVerifications("/project/1/partner-organisation/2/spend-profile/complete", Void.class, null); assertTrue(result.isSuccess()); }
SpendProfileRestServiceImpl extends BaseRestService implements SpendProfileRestService { @Override public RestResult<Void> markSpendProfileIncomplete(Long projectId, Long organisationId) { return postWithRestResult(PROJECT_REST_URL + "/" + projectId + "/partner-organisation/" + organisationId + "/spend-profile/incomplete", Void.class); } @Override RestResult<Void> generateSpendProfile(Long projectId); @Override RestResult<Void> acceptOrRejectSpendProfile(Long projectId, ApprovalType approvalType); @Override RestResult<ApprovalType> getSpendProfileStatusByProjectId(Long projectId); @Override RestResult<SpendProfileTableResource> getSpendProfileTable(Long projectId, Long organisationId); @Override RestResult<SpendProfileCSVResource> getSpendProfileCSV(Long projectId, Long organisationId); @Override RestResult<SpendProfileResource> getSpendProfile(Long projectId, Long organisationId); @Override RestResult<Void> saveSpendProfile(Long projectId, Long organisationId, SpendProfileTableResource table); @Override RestResult<Void> markSpendProfileComplete(Long projectId, Long organisationId); @Override RestResult<Void> markSpendProfileIncomplete(Long projectId, Long organisationId); @Override RestResult<Void> completeSpendProfilesReview(Long projectId); }
@Test public void markSpendProfileIncomplete() { Long projectId = 1L; Long organisationId = 2L; setupPostWithRestResultExpectations(projectRestURL + "/" + projectId + "/partner-organisation/" + organisationId + "/spend-profile/incomplete", OK); RestResult<Void> result = service.markSpendProfileIncomplete(projectId, organisationId); setupPostWithRestResultVerifications("/project/1/partner-organisation/2/spend-profile/incomplete", Void.class, null); assertTrue(result.isSuccess()); }
SpendProfileRestServiceImpl extends BaseRestService implements SpendProfileRestService { @Override public RestResult<Void> completeSpendProfilesReview(Long projectId) { return postWithRestResult(PROJECT_REST_URL + "/" + projectId + "/complete-spend-profiles-review/", Void.class); } @Override RestResult<Void> generateSpendProfile(Long projectId); @Override RestResult<Void> acceptOrRejectSpendProfile(Long projectId, ApprovalType approvalType); @Override RestResult<ApprovalType> getSpendProfileStatusByProjectId(Long projectId); @Override RestResult<SpendProfileTableResource> getSpendProfileTable(Long projectId, Long organisationId); @Override RestResult<SpendProfileCSVResource> getSpendProfileCSV(Long projectId, Long organisationId); @Override RestResult<SpendProfileResource> getSpendProfile(Long projectId, Long organisationId); @Override RestResult<Void> saveSpendProfile(Long projectId, Long organisationId, SpendProfileTableResource table); @Override RestResult<Void> markSpendProfileComplete(Long projectId, Long organisationId); @Override RestResult<Void> markSpendProfileIncomplete(Long projectId, Long organisationId); @Override RestResult<Void> completeSpendProfilesReview(Long projectId); }
@Test public void testCompleteSpendProfilesReview() { Long projectId = 1L; setupPostWithRestResultExpectations(projectRestURL + "/" + projectId + "/complete-spend-profiles-review/", OK); RestResult<Void> result = service.completeSpendProfilesReview(projectId); setupPostWithRestResultVerifications("/project/1/complete-spend-profiles-review/", Void.class, null); assertTrue(result.isSuccess()); }
SpendProfileRestServiceImpl extends BaseRestService implements SpendProfileRestService { @Override public RestResult<SpendProfileCSVResource> getSpendProfileCSV(Long projectId, Long organisationId) { String url = PROJECT_REST_URL + "/" + projectId + "/partner-organisation/" + organisationId + "/spend-profile-csv"; return getWithRestResult(url, SpendProfileCSVResource.class); } @Override RestResult<Void> generateSpendProfile(Long projectId); @Override RestResult<Void> acceptOrRejectSpendProfile(Long projectId, ApprovalType approvalType); @Override RestResult<ApprovalType> getSpendProfileStatusByProjectId(Long projectId); @Override RestResult<SpendProfileTableResource> getSpendProfileTable(Long projectId, Long organisationId); @Override RestResult<SpendProfileCSVResource> getSpendProfileCSV(Long projectId, Long organisationId); @Override RestResult<SpendProfileResource> getSpendProfile(Long projectId, Long organisationId); @Override RestResult<Void> saveSpendProfile(Long projectId, Long organisationId, SpendProfileTableResource table); @Override RestResult<Void> markSpendProfileComplete(Long projectId, Long organisationId); @Override RestResult<Void> markSpendProfileIncomplete(Long projectId, Long organisationId); @Override RestResult<Void> completeSpendProfilesReview(Long projectId); }
@Test public void getSpendProfileCSV() { Long projectId = 1L; Long organisationId = 1L; setupGetWithRestResultExpectations(projectRestURL + "/" + projectId + "/partner-organisation/" + organisationId + "/spend-profile-csv", SpendProfileCSVResource.class, null); RestResult<SpendProfileCSVResource> result = service.getSpendProfileCSV(projectId, organisationId); assertTrue(result.isSuccess()); }
SpendProfileRestServiceImpl extends BaseRestService implements SpendProfileRestService { @Override public RestResult<Void> acceptOrRejectSpendProfile(Long projectId, ApprovalType approvalType) { return postWithRestResult(PROJECT_REST_URL + "/" + projectId + "/spend-profile/approval/" + approvalType, Void.class); } @Override RestResult<Void> generateSpendProfile(Long projectId); @Override RestResult<Void> acceptOrRejectSpendProfile(Long projectId, ApprovalType approvalType); @Override RestResult<ApprovalType> getSpendProfileStatusByProjectId(Long projectId); @Override RestResult<SpendProfileTableResource> getSpendProfileTable(Long projectId, Long organisationId); @Override RestResult<SpendProfileCSVResource> getSpendProfileCSV(Long projectId, Long organisationId); @Override RestResult<SpendProfileResource> getSpendProfile(Long projectId, Long organisationId); @Override RestResult<Void> saveSpendProfile(Long projectId, Long organisationId, SpendProfileTableResource table); @Override RestResult<Void> markSpendProfileComplete(Long projectId, Long organisationId); @Override RestResult<Void> markSpendProfileIncomplete(Long projectId, Long organisationId); @Override RestResult<Void> completeSpendProfilesReview(Long projectId); }
@Test public void acceptOrRejectSpendProfile() { Long projectId = 1L; setupPostWithRestResultExpectations(projectRestURL + "/" + projectId + "/spend-profile/approval/" + ApprovalType.APPROVED, OK); RestResult<Void> result = service.acceptOrRejectSpendProfile(projectId, ApprovalType.APPROVED); setupPostWithRestResultVerifications("/project/1/spend-profile/approval/APPROVED", Void.class, null); assertTrue(result.isSuccess()); }
SpendProfileRestServiceImpl extends BaseRestService implements SpendProfileRestService { @Override public RestResult<ApprovalType> getSpendProfileStatusByProjectId(Long projectId) { return getWithRestResult(PROJECT_REST_URL + "/" + projectId + "/spend-profile/approval", ApprovalType.class); } @Override RestResult<Void> generateSpendProfile(Long projectId); @Override RestResult<Void> acceptOrRejectSpendProfile(Long projectId, ApprovalType approvalType); @Override RestResult<ApprovalType> getSpendProfileStatusByProjectId(Long projectId); @Override RestResult<SpendProfileTableResource> getSpendProfileTable(Long projectId, Long organisationId); @Override RestResult<SpendProfileCSVResource> getSpendProfileCSV(Long projectId, Long organisationId); @Override RestResult<SpendProfileResource> getSpendProfile(Long projectId, Long organisationId); @Override RestResult<Void> saveSpendProfile(Long projectId, Long organisationId, SpendProfileTableResource table); @Override RestResult<Void> markSpendProfileComplete(Long projectId, Long organisationId); @Override RestResult<Void> markSpendProfileIncomplete(Long projectId, Long organisationId); @Override RestResult<Void> completeSpendProfilesReview(Long projectId); }
@Test public void getSpendProfileStatusByProjectId() { Long projectId = 1L; setupGetWithRestResultExpectations(projectRestURL + "/" + projectId + "/spend-profile/approval", ApprovalType.class, ApprovalType.APPROVED, OK); RestResult<ApprovalType> result = service.getSpendProfileStatusByProjectId(projectId); assertTrue(result.isSuccess()); assertEquals(ApprovalType.APPROVED, result.getSuccess()); }
ProjectPartnerInviteRestServiceImpl extends BaseRestService implements ProjectPartnerInviteRestService { @Override public RestResult<Void> invitePartnerOrganisation(long projectId, SendProjectPartnerInviteResource invite) { return postWithRestResult(format(baseUrl, projectId), invite, Void.class); } @Override RestResult<Void> invitePartnerOrganisation(long projectId, SendProjectPartnerInviteResource invite); @Override RestResult<List<SentProjectPartnerInviteResource>> getPartnerInvites(long projectId); @Override RestResult<Void> resendInvite(long projectId, long inviteId); @Override RestResult<Void> deleteInvite(long projectId, long inviteId); @Override RestResult<SentProjectPartnerInviteResource> getInviteByHash(long projectId, String hash); @Override RestResult<Void> acceptInvite(long projectId, long inviteId, long organisationId); }
@Test public void invitePartnerOrganisation() { long projectId = 1L; SendProjectPartnerInviteResource invite = new SendProjectPartnerInviteResource("", "", ""); setupPostWithRestResultExpectations(format("/project/%d/project-partner-invite", projectId), invite, HttpStatus.OK); RestResult<Void> result = service.invitePartnerOrganisation(projectId, invite); assertTrue(result.isSuccess()); setupPostWithRestResulVerifications(format("/project/%d/project-partner-invite", projectId), invite); }
ScheduledJesOrganisationListImporterFileDownloader { ServiceResult<File> copyJesSourceFile(URL jesSourceFile, int connectionTimeoutMillis, int readTimeoutMillis) { return createTemporaryDownloadFile().andOnSuccess(temporaryDownloadFile -> { try { FileUtils.copyURLToFile(jesSourceFile, temporaryDownloadFile, connectionTimeoutMillis, readTimeoutMillis); return serviceSuccess(temporaryDownloadFile); } catch (IOException e) { return createServiceFailureFromIoException(e); } }); } }
@Test public void downloadFile() throws IOException { ScheduledJesOrganisationListImporterFileDownloader fileDownloader = new ScheduledJesOrganisationListImporterFileDownloader(); URL dummyFileUrl = currentThread().getContextClassLoader().getResource("test-jes-download.csv"); ServiceResult<File> fileDownloadResult = fileDownloader.copyJesSourceFile(dummyFileUrl, 5000, 500); assertThat(fileDownloadResult.isSuccess()).isTrue(); File dummyFile = fileDownloadResult.getSuccess(); List<String> fileContents = FileUtils.readLines(dummyFile, Charset.defaultCharset()); assertThat(fileContents).containsExactly( "Organisation name", "AB Agri Ltd", "Aberystwyth University", "Abriachan Forest Trust"); } @Test public void downloadFileWhenFileNotFound() throws IOException { ScheduledJesOrganisationListImporterFileDownloader fileDownloader = new ScheduledJesOrganisationListImporterFileDownloader(); String nonExistentFileUrl = File.createTempFile("jestest", "jestest").getAbsolutePath() + "does-not-exist"; URL dummyFileUrl = new File(nonExistentFileUrl).toURI().toURL(); ServiceResult<File> fileDownloadResult = fileDownloader.copyJesSourceFile(dummyFileUrl, 5000, 500); assertThat(fileDownloadResult.isFailure()).isTrue(); List<Error> errors = fileDownloadResult.getFailure().getErrors(); assertThat(errors).hasSize(1); assertThat(errors.get(0).getStatusCode()).isEqualTo(BAD_REQUEST); }
ProjectPartnerInviteRestServiceImpl extends BaseRestService implements ProjectPartnerInviteRestService { @Override public RestResult<List<SentProjectPartnerInviteResource>> getPartnerInvites(long projectId) { return getWithRestResult(format(baseUrl, projectId), sentProjectPartnerInviteResourceListType()); } @Override RestResult<Void> invitePartnerOrganisation(long projectId, SendProjectPartnerInviteResource invite); @Override RestResult<List<SentProjectPartnerInviteResource>> getPartnerInvites(long projectId); @Override RestResult<Void> resendInvite(long projectId, long inviteId); @Override RestResult<Void> deleteInvite(long projectId, long inviteId); @Override RestResult<SentProjectPartnerInviteResource> getInviteByHash(long projectId, String hash); @Override RestResult<Void> acceptInvite(long projectId, long inviteId, long organisationId); }
@Test public void getPartnerInvites() { long projectId = 1L; List<SentProjectPartnerInviteResource> invites = newSentProjectPartnerInviteResource().build(1); setupGetWithRestResultExpectations(format("/project/%d/project-partner-invite", projectId), sentProjectPartnerInviteResourceListType(), invites); RestResult<List<SentProjectPartnerInviteResource>> result = service.getPartnerInvites(projectId); assertTrue(result.isSuccess()); assertEquals(invites, result.getSuccess()); }
ProjectPartnerInviteRestServiceImpl extends BaseRestService implements ProjectPartnerInviteRestService { @Override public RestResult<Void> resendInvite(long projectId, long inviteId) { return postWithRestResult(format(inviteIdUrl, projectId, inviteId) + "/resend", Void.class); } @Override RestResult<Void> invitePartnerOrganisation(long projectId, SendProjectPartnerInviteResource invite); @Override RestResult<List<SentProjectPartnerInviteResource>> getPartnerInvites(long projectId); @Override RestResult<Void> resendInvite(long projectId, long inviteId); @Override RestResult<Void> deleteInvite(long projectId, long inviteId); @Override RestResult<SentProjectPartnerInviteResource> getInviteByHash(long projectId, String hash); @Override RestResult<Void> acceptInvite(long projectId, long inviteId, long organisationId); }
@Test public void resendInvite() { long projectId = 1L; long inviteId = 2L; setupPostWithRestResultExpectations(format("/project/%d/project-partner-invite/%d/resend", projectId, inviteId), HttpStatus.OK); RestResult<Void> result = service.resendInvite(projectId, inviteId); assertTrue(result.isSuccess()); }
ProjectPartnerInviteRestServiceImpl extends BaseRestService implements ProjectPartnerInviteRestService { @Override public RestResult<Void> deleteInvite(long projectId, long inviteId) { return deleteWithRestResult(format(inviteIdUrl, projectId, inviteId), Void.class); } @Override RestResult<Void> invitePartnerOrganisation(long projectId, SendProjectPartnerInviteResource invite); @Override RestResult<List<SentProjectPartnerInviteResource>> getPartnerInvites(long projectId); @Override RestResult<Void> resendInvite(long projectId, long inviteId); @Override RestResult<Void> deleteInvite(long projectId, long inviteId); @Override RestResult<SentProjectPartnerInviteResource> getInviteByHash(long projectId, String hash); @Override RestResult<Void> acceptInvite(long projectId, long inviteId, long organisationId); }
@Test public void deleteInvite() { long projectId = 1L; long inviteId = 2L; setupDeleteWithRestResultExpectations(format("/project/%d/project-partner-invite/%d", projectId, inviteId), HttpStatus.OK); RestResult<Void> result = service.deleteInvite(projectId, inviteId); assertTrue(result.isSuccess()); }
ProjectPartnerInviteRestServiceImpl extends BaseRestService implements ProjectPartnerInviteRestService { @Override public RestResult<SentProjectPartnerInviteResource> getInviteByHash(long projectId, String hash) { return getWithRestResultAnonymous(format(inviteIdUrl, projectId, hash), SentProjectPartnerInviteResource.class); } @Override RestResult<Void> invitePartnerOrganisation(long projectId, SendProjectPartnerInviteResource invite); @Override RestResult<List<SentProjectPartnerInviteResource>> getPartnerInvites(long projectId); @Override RestResult<Void> resendInvite(long projectId, long inviteId); @Override RestResult<Void> deleteInvite(long projectId, long inviteId); @Override RestResult<SentProjectPartnerInviteResource> getInviteByHash(long projectId, String hash); @Override RestResult<Void> acceptInvite(long projectId, long inviteId, long organisationId); }
@Test public void getInviteByHash() { long projectId = 1L; String hash = "hash"; SentProjectPartnerInviteResource resource = newSentProjectPartnerInviteResource().build(); setupGetWithRestResultAnonymousExpectations(format("/project/%d/project-partner-invite/%s", projectId, hash), SentProjectPartnerInviteResource.class, resource); RestResult<SentProjectPartnerInviteResource> result = service.getInviteByHash(projectId, hash); assertEquals(resource, result.getSuccess()); }
ProjectPartnerInviteRestServiceImpl extends BaseRestService implements ProjectPartnerInviteRestService { @Override public RestResult<Void> acceptInvite(long projectId, long inviteId, long organisationId) { return postWithRestResultAnonymous(format(inviteIdUrl + "/organisation/%d/accept", projectId, inviteId, organisationId), Void.class); } @Override RestResult<Void> invitePartnerOrganisation(long projectId, SendProjectPartnerInviteResource invite); @Override RestResult<List<SentProjectPartnerInviteResource>> getPartnerInvites(long projectId); @Override RestResult<Void> resendInvite(long projectId, long inviteId); @Override RestResult<Void> deleteInvite(long projectId, long inviteId); @Override RestResult<SentProjectPartnerInviteResource> getInviteByHash(long projectId, String hash); @Override RestResult<Void> acceptInvite(long projectId, long inviteId, long organisationId); }
@Test public void acceptInvite() { long projectId = 1L; long inviteId = 2L; long organisationId = 3L; setupPostWithRestResultAnonymousExpectations(format("/project/%d/project-partner-invite/%d/organisation/%d/accept", projectId, inviteId, organisationId), Void.class, null, null, HttpStatus.OK); RestResult<Void> result = service.acceptInvite(projectId, inviteId, organisationId); assertTrue(result.isSuccess()); }
AffiliationRestServiceImpl extends BaseRestService implements AffiliationRestService { @Override public RestResult<AffiliationListResource> getUserAffiliations(long userId) { return getWithRestResult(format("%s/id/%s/get-user-affiliations", profileRestURL, userId), AffiliationListResource.class); } @Override RestResult<AffiliationListResource> getUserAffiliations(long userId); @Override RestResult<Void> updateUserAffiliations(long userId, AffiliationListResource affiliations); }
@Test public void getUserAffiliations() { Long userId = 1L; List<AffiliationResource> affiliationResources = newAffiliationResource().build(2); AffiliationListResource expected = newAffiliationListResource() .withAffiliationList(affiliationResources) .build(); setupGetWithRestResultExpectations(format("%s/id/%s/get-user-affiliations", affiliationUrl, userId), AffiliationListResource.class, expected); AffiliationListResource response = service.getUserAffiliations(userId).getSuccess(); assertEquals(expected, response); }
AffiliationRestServiceImpl extends BaseRestService implements AffiliationRestService { @Override public RestResult<Void> updateUserAffiliations(long userId, AffiliationListResource affiliations) { return putWithRestResult(format("%s/id/%s/update-user-affiliations", profileRestURL, userId), affiliations, Void.class); } @Override RestResult<AffiliationListResource> getUserAffiliations(long userId); @Override RestResult<Void> updateUserAffiliations(long userId, AffiliationListResource affiliations); }
@Test public void updateUserAffiliations() { Long userId = 1L; List<AffiliationResource> affiliationResources = newAffiliationResource().build(2); AffiliationListResource expected = newAffiliationListResource() .withAffiliationList(affiliationResources) .build(); setupPutWithRestResultExpectations(format("%s/id/%s/update-user-affiliations", affiliationUrl, userId), expected, OK); RestResult<Void> response = service.updateUserAffiliations(userId, expected); assertTrue(response.isSuccess()); }
ApplicationKtaInviteRestServiceImpl extends BaseRestService implements ApplicationKtaInviteRestService { @Override public RestResult<Void> saveKtaInvite(ApplicationKtaInviteResource inviteResource) { String url = KTA_INVITE_REST_URL + "/save-kta-invite"; return postWithRestResult(url, inviteResource, Void.class); } @Override RestResult<Void> saveKtaInvite(ApplicationKtaInviteResource inviteResource); @Override RestResult<ApplicationKtaInviteResource> getKtaInviteByApplication(long applicationId); @Override RestResult<Void> removeKtaInviteByApplication(long applicationId); @Override RestResult<Void> resendKtaInvite(ApplicationKtaInviteResource inviteResource); @Override RestResult<ApplicationKtaInviteResource> getKtaInviteByHash(String hash); @Override RestResult<Void> acceptInvite(String hash); }
@Test public void saveKtaInvite() { final ApplicationKtaInviteResource invite = newApplicationKtaInviteResource().build(); setupPostWithRestResultExpectations(inviteKtaRestURL + "/save-kta-invite", invite, OK); RestResult<Void> response = service.saveKtaInvite(invite); assertTrue(response.isSuccess()); setupPostWithRestResultVerifications(inviteKtaRestURL + "/save-kta-invite", Void.class, invite); }
ApplicationKtaInviteRestServiceImpl extends BaseRestService implements ApplicationKtaInviteRestService { @Override public RestResult<Void> resendKtaInvite(ApplicationKtaInviteResource inviteResource) { String url = KTA_INVITE_REST_URL + "/resend-kta-invite"; return postWithRestResult(url, inviteResource, Void.class); } @Override RestResult<Void> saveKtaInvite(ApplicationKtaInviteResource inviteResource); @Override RestResult<ApplicationKtaInviteResource> getKtaInviteByApplication(long applicationId); @Override RestResult<Void> removeKtaInviteByApplication(long applicationId); @Override RestResult<Void> resendKtaInvite(ApplicationKtaInviteResource inviteResource); @Override RestResult<ApplicationKtaInviteResource> getKtaInviteByHash(String hash); @Override RestResult<Void> acceptInvite(String hash); }
@Test public void resendKtaInvite() { final ApplicationKtaInviteResource invite = newApplicationKtaInviteResource().build(); setupPostWithRestResultExpectations(inviteKtaRestURL + "/resend-kta-invite", invite, OK); RestResult<Void> response = service.resendKtaInvite(invite); assertTrue(response.isSuccess()); setupPostWithRestResultVerifications(inviteKtaRestURL + "/resend-kta-invite", Void.class, invite); }
ApplicationKtaInviteRestServiceImpl extends BaseRestService implements ApplicationKtaInviteRestService { @Override public RestResult<Void> removeKtaInviteByApplication(long applicationId) { String url = KTA_INVITE_REST_URL + String.format("/remove-kta-invite-by-application/%s", applicationId); return deleteWithRestResult(url); } @Override RestResult<Void> saveKtaInvite(ApplicationKtaInviteResource inviteResource); @Override RestResult<ApplicationKtaInviteResource> getKtaInviteByApplication(long applicationId); @Override RestResult<Void> removeKtaInviteByApplication(long applicationId); @Override RestResult<Void> resendKtaInvite(ApplicationKtaInviteResource inviteResource); @Override RestResult<ApplicationKtaInviteResource> getKtaInviteByHash(String hash); @Override RestResult<Void> acceptInvite(String hash); }
@Test public void removeKtaInvite() { final Long applicationId = 20310L; setupDeleteWithRestResultExpectations(inviteKtaRestURL + String.format("/remove-kta-invite-by-application/%s", applicationId), OK); RestResult<Void> response = service.removeKtaInviteByApplication(applicationId); assertTrue(response.isSuccess()); }
ApplicationKtaInviteRestServiceImpl extends BaseRestService implements ApplicationKtaInviteRestService { @Override public RestResult<ApplicationKtaInviteResource> getKtaInviteByApplication(long applicationId) { String url = KTA_INVITE_REST_URL + "/get-kta-invite-by-application-id/"+ applicationId; return getWithRestResult(url, ApplicationKtaInviteResource.class); } @Override RestResult<Void> saveKtaInvite(ApplicationKtaInviteResource inviteResource); @Override RestResult<ApplicationKtaInviteResource> getKtaInviteByApplication(long applicationId); @Override RestResult<Void> removeKtaInviteByApplication(long applicationId); @Override RestResult<Void> resendKtaInvite(ApplicationKtaInviteResource inviteResource); @Override RestResult<ApplicationKtaInviteResource> getKtaInviteByHash(String hash); @Override RestResult<Void> acceptInvite(String hash); }
@Test public void getKtaInvitesByApplication() { Long applicationId = 2341L; ApplicationKtaInviteResource expected = newApplicationKtaInviteResource().build(); String url = inviteKtaRestURL + "/get-kta-invite-by-application-id/" + applicationId; setupGetWithRestResultExpectations(url, ApplicationKtaInviteResource.class, expected, OK); RestResult<ApplicationKtaInviteResource> response = service.getKtaInviteByApplication(applicationId); assertTrue(response.isSuccess()); assertEquals(expected, response.getSuccess()); }
ApplicationKtaInviteRestServiceImpl extends BaseRestService implements ApplicationKtaInviteRestService { @Override public RestResult<ApplicationKtaInviteResource> getKtaInviteByHash(String hash) { String url = KTA_INVITE_REST_URL + "/hash/" + hash; return getWithRestResultAnonymous(url, ApplicationKtaInviteResource.class); } @Override RestResult<Void> saveKtaInvite(ApplicationKtaInviteResource inviteResource); @Override RestResult<ApplicationKtaInviteResource> getKtaInviteByApplication(long applicationId); @Override RestResult<Void> removeKtaInviteByApplication(long applicationId); @Override RestResult<Void> resendKtaInvite(ApplicationKtaInviteResource inviteResource); @Override RestResult<ApplicationKtaInviteResource> getKtaInviteByHash(String hash); @Override RestResult<Void> acceptInvite(String hash); }
@Test public void getKtaInviteByHash() { String hash = "hash"; ApplicationKtaInviteResource expected = newApplicationKtaInviteResource().build(); String url = inviteKtaRestURL + "/hash/" + hash; setupGetWithRestResultAnonymousExpectations(url, ApplicationKtaInviteResource.class, expected, OK); RestResult<ApplicationKtaInviteResource> response = service.getKtaInviteByHash(hash); assertTrue(response.isSuccess()); assertEquals(expected, response.getSuccess()); }
ApplicationKtaInviteRestServiceImpl extends BaseRestService implements ApplicationKtaInviteRestService { @Override public RestResult<Void> acceptInvite(String hash) { String url = KTA_INVITE_REST_URL + "/hash/" + hash; return postWithRestResult(url, Void.class); } @Override RestResult<Void> saveKtaInvite(ApplicationKtaInviteResource inviteResource); @Override RestResult<ApplicationKtaInviteResource> getKtaInviteByApplication(long applicationId); @Override RestResult<Void> removeKtaInviteByApplication(long applicationId); @Override RestResult<Void> resendKtaInvite(ApplicationKtaInviteResource inviteResource); @Override RestResult<ApplicationKtaInviteResource> getKtaInviteByHash(String hash); @Override RestResult<Void> acceptInvite(String hash); }
@Test public void acceptInvite() { final String hash = "Hash"; setupPostWithRestResultExpectations(inviteKtaRestURL + "/hash/" + hash, OK); RestResult<Void> response = service.acceptInvite(hash); assertTrue(response.isSuccess()); setupPostWithRestResultVerifications(inviteKtaRestURL + "/hash/" + hash, Void.class); }
InviteUserRestServiceImpl extends BaseRestService implements InviteUserRestService { @Override public RestResult<Void> saveUserInvite(InviteUserResource inviteUserResource) { String url = INVITE_REST_URL + "/save-invite"; return postWithRestResult(url, inviteUserResource, Void.class); } @Override RestResult<Void> saveUserInvite(InviteUserResource inviteUserResource); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<RoleInviteResource> getInvite(String inviteHash); @Override RestResult<RoleInvitePageResource> getPendingInternalUserInvites(String filter, int pageNumber, int pageSize); @Override RestResult<List<ExternalInviteResource>> findExternalInvites(String searchString, SearchCategory searchCategory); @Override RestResult<Void> resendInternalUserInvite(long inviteId); }
@Test public void saveUserInvite() { InviteUserResource inviteUserResource = new InviteUserResource(); String url = inviteRestBaseUrl + "/save-invite"; setupPostWithRestResultExpectations(url, inviteUserResource, HttpStatus.OK); RestResult<Void> result = service.saveUserInvite(inviteUserResource); assertTrue(result.isSuccess()); }
InviteUserRestServiceImpl extends BaseRestService implements InviteUserRestService { @Override public RestResult<RoleInviteResource> getInvite(String inviteHash) { return getWithRestResultAnonymous(format("%s/%s/%s", INVITE_REST_URL, "get-invite", inviteHash), RoleInviteResource.class); } @Override RestResult<Void> saveUserInvite(InviteUserResource inviteUserResource); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<RoleInviteResource> getInvite(String inviteHash); @Override RestResult<RoleInvitePageResource> getPendingInternalUserInvites(String filter, int pageNumber, int pageSize); @Override RestResult<List<ExternalInviteResource>> findExternalInvites(String searchString, SearchCategory searchCategory); @Override RestResult<Void> resendInternalUserInvite(long inviteId); }
@Test public void getInvite() { RoleInviteResource roleInviteResource = new RoleInviteResource(); String url = inviteRestBaseUrl + "/get-invite/"; String inviteHash = "hash"; setupGetWithRestResultAnonymousExpectations(url + inviteHash, RoleInviteResource.class, roleInviteResource); RestResult<RoleInviteResource> result = service.getInvite(inviteHash); assertTrue(result.isSuccess()); assertEquals(roleInviteResource, result.getSuccess()); }
InviteUserRestServiceImpl extends BaseRestService implements InviteUserRestService { @Override public RestResult<Boolean> checkExistingUser(String inviteHash) { return getWithRestResultAnonymous(format("%s/%s/%s", INVITE_REST_URL, "check-existing-user", inviteHash), Boolean.class); } @Override RestResult<Void> saveUserInvite(InviteUserResource inviteUserResource); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<RoleInviteResource> getInvite(String inviteHash); @Override RestResult<RoleInvitePageResource> getPendingInternalUserInvites(String filter, int pageNumber, int pageSize); @Override RestResult<List<ExternalInviteResource>> findExternalInvites(String searchString, SearchCategory searchCategory); @Override RestResult<Void> resendInternalUserInvite(long inviteId); }
@Test public void checkExistingUser() { String url = inviteRestBaseUrl + "/check-existing-user/"; String inviteHash = "hash"; setupGetWithRestResultAnonymousExpectations(url + inviteHash, Boolean.class, true); RestResult<Boolean> returnedResponse = service.checkExistingUser(inviteHash); assertTrue(returnedResponse.isSuccess()); assertTrue(returnedResponse.getSuccess()); }
InviteUserRestServiceImpl extends BaseRestService implements InviteUserRestService { @Override public RestResult<RoleInvitePageResource> getPendingInternalUserInvites(String filter, int pageNumber, int pageSize) { MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("filter", filter); String uriWithParams = buildPaginationUri(INVITE_REST_URL + "/internal/pending", pageNumber, pageSize, null, params); return getWithRestResult(uriWithParams, RoleInvitePageResource.class); } @Override RestResult<Void> saveUserInvite(InviteUserResource inviteUserResource); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<RoleInviteResource> getInvite(String inviteHash); @Override RestResult<RoleInvitePageResource> getPendingInternalUserInvites(String filter, int pageNumber, int pageSize); @Override RestResult<List<ExternalInviteResource>> findExternalInvites(String searchString, SearchCategory searchCategory); @Override RestResult<Void> resendInternalUserInvite(long inviteId); }
@Test public void getPendingInternalUsers() { RoleInvitePageResource expected = new RoleInvitePageResource(); MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("filter", ""); setupGetWithRestResultExpectations(buildPaginationUri(inviteRestBaseUrl + "/internal/pending", 0, 5, null, params), RoleInvitePageResource.class, expected, OK); RoleInvitePageResource result = service.getPendingInternalUserInvites("", 0, 5).getSuccess(); assertEquals(expected, result); }
InviteUserRestServiceImpl extends BaseRestService implements InviteUserRestService { @Override public RestResult<List<ExternalInviteResource>> findExternalInvites(String searchString, SearchCategory searchCategory) { return getWithRestResult(INVITE_REST_URL + "/find-external-invites?searchString=" + searchString + "&searchCategory=" + searchCategory.name(), externalInviteResourceListType()); } @Override RestResult<Void> saveUserInvite(InviteUserResource inviteUserResource); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<RoleInviteResource> getInvite(String inviteHash); @Override RestResult<RoleInvitePageResource> getPendingInternalUserInvites(String filter, int pageNumber, int pageSize); @Override RestResult<List<ExternalInviteResource>> findExternalInvites(String searchString, SearchCategory searchCategory); @Override RestResult<Void> resendInternalUserInvite(long inviteId); }
@Test public void findExternalInvites() { String searchString = "%a%"; SearchCategory searchCategory = SearchCategory.NAME; List<ExternalInviteResource> expected = Collections.singletonList(new ExternalInviteResource()); setupGetWithRestResultExpectations(inviteRestBaseUrl + "/find-external-invites?searchString=" + searchString + "&searchCategory=" + searchCategory.name(), externalInviteResourceListType(), expected, OK); List<ExternalInviteResource> result = service.findExternalInvites(searchString, searchCategory).getSuccess(); assertEquals(expected, result); }
InviteUserRestServiceImpl extends BaseRestService implements InviteUserRestService { @Override public RestResult<Void> resendInternalUserInvite(long inviteId) { return putWithRestResult(INVITE_REST_URL + "/internal/pending/" + inviteId + "/resend", Void.class); } @Override RestResult<Void> saveUserInvite(InviteUserResource inviteUserResource); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<RoleInviteResource> getInvite(String inviteHash); @Override RestResult<RoleInvitePageResource> getPendingInternalUserInvites(String filter, int pageNumber, int pageSize); @Override RestResult<List<ExternalInviteResource>> findExternalInvites(String searchString, SearchCategory searchCategory); @Override RestResult<Void> resendInternalUserInvite(long inviteId); }
@Test public void resendInternalUserInvite() { setupPutWithRestResultExpectations(inviteRestBaseUrl + "/internal/pending/123/resend", OK); RestResult<Void> result = service.resendInternalUserInvite(123L); assertTrue(result.isSuccess()); setupPutWithRestResultVerifications(inviteRestBaseUrl + "/internal/pending/123/resend"); }
RejectionReasonRestServiceImpl extends BaseRestService implements RejectionReasonRestService { @Override public RestResult<List<RejectionReasonResource>> findAllActive() { return getWithRestResultAnonymous(format("%s/find-all-active", rejectionReasonRestUrl), rejectionReasonResourceListType()); } @Override RestResult<List<RejectionReasonResource>> findAllActive(); }
@Test public void findAllActive() throws Exception { List<RejectionReasonResource> expected = Stream.of(1, 2).map(i -> new RejectionReasonResource()).collect(Collectors.toList()); setupGetWithRestResultAnonymousExpectations(format("%s/find-all-active", rejectionReasonRestUrl), rejectionReasonResourceListType(), expected, OK); List<RejectionReasonResource> response = service.findAllActive().getSuccess(); assertSame(expected, response); }
ScheduledJesOrganisationListImporter { @Transactional @Scheduled(cron = "${ifs.data.service.jes.organisation.importer.cron.expression}") public ServiceResult<List<String>> importJesList() { if (!importEnabled) { LOG.debug("Je-S organisation list import currently disabled"); return serviceSuccess(emptyList()); } ServiceResult<URL> jesSourceFileUrlResult = getUrlFromString(jesSourceFileUrl); ServiceResult<URL> archiveLocationUrlResult = getUrlFromString(archiveLocation); if (jesSourceFileUrlResult.isFailure()) { LOG.warn("Could not determine Je-S organisation list file URI. Got " + jesSourceFileUrlResult.getFailure()); return serviceFailure(jesSourceFileUrlResult.getFailure()); } if (archiveLocationUrlResult.isFailure()) { LOG.warn("Could not determine archive file URI. Got " + archiveLocationUrlResult.getFailure()); return serviceFailure(archiveLocationUrlResult.getFailure()); } URL jesFileToDownload = jesSourceFileUrlResult.getSuccess(); URL archiveFile = archiveLocationUrlResult.getSuccess(); if (!fileDownloader.jesSourceFileExists(jesFileToDownload)) { LOG.debug("No Je-S organisation list file to import"); return serviceSuccess(emptyList()); } LOG.info("Importing Je-S organisation list..."); ServiceResult<List<String>> downloadResult = downloadFile(jesFileToDownload). andOnSuccess(downloadedFile -> archiveJesSourceFileIfExists(jesFileToDownload, archiveFile). andOnSuccess(() -> readDownloadedFile(downloadedFile)). andOnSuccessDo(organisationNames -> logDownloadedOrganisations(organisationNames)). andOnSuccessDo(organisationNames -> deleteExistingAcademicEntries()). andOnSuccessDo(organisationNames -> importNewAcademicEntries(organisationNames))); return downloadResult.handleSuccessOrFailureNoReturn( this::logFailure, this::logSuccess); } @Autowired ScheduledJesOrganisationListImporter(@Autowired AcademicRepository academicRepository, @Autowired ScheduledJesOrganisationListImporterFileDownloader fileDownloader, @Autowired ScheduledJesOrganisationListImporterOrganisationExtractor organisationExtractor, @Autowired TransactionalHelper transactionalHelper, @Value("${ifs.data.service.jes.organisation.importer.connection.timeout.millis}") int connectionTimeoutMillis, @Value("${ifs.data.service.jes.organisation.importer.read.timeout.millis}") int readTimeoutMillis, @Value("${ifs.data.service.jes.organisation.importer.enabled}") boolean importEnabled, @Value("${ifs.data.service.jes.organisation.importer.download.url}") String jesSourceFileUrl, @Value("${ifs.data.service.jes.organisation.importer.archive.location}") String archiveLocation, @Value("${ifs.data.service.jes.organisation.importer.archive.source.file}") boolean deleteJesSourceFile); @Transactional @Scheduled(cron = "${ifs.data.service.jes.organisation.importer.cron.expression}") ServiceResult<List<String>> importJesList(); }
@Test public void importJesList() throws IOException { ScheduledJesOrganisationListImporter job = new ScheduledJesOrganisationListImporter( academicRepositoryMock, fileDownloaderMock, organisationExtractorMock, transactionalHelperMock, CONNECTION_TIMEOUT, READ_TIMEOUT, true, JES_FILE_STRING, ARCHIVE_FILE_STRING, true); List<String> expectedDownloadedOrganisations = asList("Org 1", "Org 2", "Org 3"); List<Academic> expectedAcademicsToSave = simpleMap(expectedDownloadedOrganisations, Academic::new); File downloadedFile = File.createTempFile("jestest", "jestest"); when(fileDownloaderMock.jesSourceFileExists(JES_FILE_URL)).thenReturn(true); when(fileDownloaderMock.copyJesSourceFile(JES_FILE_URL, CONNECTION_TIMEOUT, READ_TIMEOUT)).thenReturn(serviceSuccess(downloadedFile)); when(fileDownloaderMock.archiveSourceFile(JES_FILE_URL, ARCHIVE_FILE_URL)).thenReturn(serviceSuccess()); when(organisationExtractorMock.extractOrganisationsFromFile(downloadedFile)).thenReturn(serviceSuccess(expectedDownloadedOrganisations)); ServiceResult<List<String>> result = job.importJesList(); assertThat(result.isSuccess()).isTrue(); assertThat(result.getSuccess()).isEqualTo(expectedDownloadedOrganisations); verify(fileDownloaderMock, times(2)).jesSourceFileExists(JES_FILE_URL); verify(fileDownloaderMock, times(1)).copyJesSourceFile(JES_FILE_URL, CONNECTION_TIMEOUT, READ_TIMEOUT); verify(fileDownloaderMock, times(1)).archiveSourceFile(JES_FILE_URL, ARCHIVE_FILE_URL); verify(organisationExtractorMock, times(1)).extractOrganisationsFromFile(downloadedFile); verify(academicRepositoryMock, times(1)).deleteAll(); verify(academicRepositoryMock, times(1)).saveAll(expectedAcademicsToSave); } @Test public void importJesListWhenImportIsDisabled() { ScheduledJesOrganisationListImporter job = new ScheduledJesOrganisationListImporter( academicRepositoryMock, fileDownloaderMock, organisationExtractorMock, transactionalHelperMock, CONNECTION_TIMEOUT, READ_TIMEOUT, false, JES_FILE_STRING, ARCHIVE_FILE_STRING, true); ServiceResult<List<String>> result = job.importJesList(); assertThat(result.isSuccess()).isTrue(); assertThat(result.getSuccess()).isEqualTo(emptyList()); verifyZeroInteractions(fileDownloaderMock, organisationExtractorMock, academicRepositoryMock); } @Test public void importJesListWhenDownloadFileFails() throws IOException { ScheduledJesOrganisationListImporter job = new ScheduledJesOrganisationListImporter( academicRepositoryMock, fileDownloaderMock, organisationExtractorMock, transactionalHelperMock, CONNECTION_TIMEOUT, READ_TIMEOUT, true, JES_FILE_STRING, ARCHIVE_FILE_STRING, true); ServiceResult<File> downloadFileFailure = serviceFailure(new Error("Service was unavailable", SERVICE_UNAVAILABLE)); when(fileDownloaderMock.jesSourceFileExists(JES_FILE_URL)).thenReturn(true); when(fileDownloaderMock.copyJesSourceFile(JES_FILE_URL, CONNECTION_TIMEOUT, READ_TIMEOUT)).thenReturn(downloadFileFailure); ServiceResult<List<String>> result = job.importJesList(); assertThatServiceFailureIs(result, new Error("Service was unavailable", SERVICE_UNAVAILABLE)); verify(fileDownloaderMock, times(1)).jesSourceFileExists(JES_FILE_URL); verify(fileDownloaderMock, times(1)).copyJesSourceFile(JES_FILE_URL, CONNECTION_TIMEOUT, READ_TIMEOUT); verify(fileDownloaderMock, never()).archiveSourceFile(JES_FILE_URL, ARCHIVE_FILE_URL); verifyZeroInteractions(organisationExtractorMock, academicRepositoryMock); } @Test public void importJesListWhenExtractOrganisationsFails() throws IOException { ScheduledJesOrganisationListImporter job = new ScheduledJesOrganisationListImporter( academicRepositoryMock, fileDownloaderMock, organisationExtractorMock, transactionalHelperMock, CONNECTION_TIMEOUT, READ_TIMEOUT, true, JES_FILE_STRING, ARCHIVE_FILE_STRING, true); File downloadedFile = File.createTempFile("jestest", "jestest"); when(fileDownloaderMock.jesSourceFileExists(JES_FILE_URL)).thenReturn(true); when(fileDownloaderMock.copyJesSourceFile(JES_FILE_URL, CONNECTION_TIMEOUT, READ_TIMEOUT)).thenReturn(serviceSuccess(downloadedFile)); when(fileDownloaderMock.archiveSourceFile(JES_FILE_URL, ARCHIVE_FILE_URL)).thenReturn(serviceSuccess()); when(organisationExtractorMock.extractOrganisationsFromFile(downloadedFile)).thenReturn(serviceFailure(new Error("Extract fails ", BAD_REQUEST))); ServiceResult<List<String>> result = job.importJesList(); assertThatServiceFailureIs(result, new Error("Extract fails ", BAD_REQUEST)); verify(fileDownloaderMock, times(2)).jesSourceFileExists(JES_FILE_URL); verify(fileDownloaderMock, times(1)).copyJesSourceFile(JES_FILE_URL, CONNECTION_TIMEOUT, READ_TIMEOUT); verify(fileDownloaderMock, times(1)).archiveSourceFile(JES_FILE_URL, ARCHIVE_FILE_URL); verify(organisationExtractorMock, times(1)).extractOrganisationsFromFile(downloadedFile); verifyZeroInteractions(academicRepositoryMock); }
InviteRestServiceImpl extends BaseRestService implements InviteRestService { @Override public RestResult<Void> createInvitesByInviteOrganisation(String organisationName, List<ApplicationInviteResource> invites) { InviteOrganisationResource inviteOrganisation = new InviteOrganisationResource(); inviteOrganisation.setOrganisationName(organisationName); inviteOrganisation.setInviteResources(invites); String url = inviteRestUrl + "/create-application-invites"; return postWithRestResult(url, inviteOrganisation, Void.class); } @Override RestResult<Void> createInvitesByInviteOrganisation(String organisationName, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisation(Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisationForApplication(Long applicationId, Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> saveInvites(List<ApplicationInviteResource> inviteResources); @Override RestResult<Void> resendInvite(ApplicationInviteResource inviteResource); @Override RestResult<Void> acceptInvite(String inviteHash, long userId); @Override RestResult<Void> acceptInvite(String inviteHash, long userId, long organisationId); @Override RestResult<Void> removeApplicationInvite(Long inviteId); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ApplicationInviteResource> getInviteByHash(String hash); @Override RestResult<InviteOrganisationResource> getInviteOrganisationByHash(String hash); @Override RestResult<List<InviteOrganisationResource>> getInvitesByApplication(Long applicationId); }
@Test public void createInvitesByInviteOrganisation() { final String organisationName = "OrganisationName"; final List<ApplicationInviteResource> invites = singletonList(new ApplicationInviteResource()); InviteOrganisationResource inviteOrganisationResource = new InviteOrganisationResource(); inviteOrganisationResource.setOrganisationName(organisationName); inviteOrganisationResource.setInviteResources(invites); setupPostWithRestResultExpectations(inviteRestURL + "/create-application-invites", inviteOrganisationResource, CREATED); RestResult<Void> response = service.createInvitesByInviteOrganisation(organisationName, invites); assertTrue(response.isSuccess()); setupPostWithRestResultVerifications(inviteRestURL + "/create-application-invites", Void.class, inviteOrganisationResource); }
InviteRestServiceImpl extends BaseRestService implements InviteRestService { @Override public RestResult<Void> createInvitesByOrganisation(Long organisationId, List<ApplicationInviteResource> invites) { InviteOrganisationResource inviteOrganisation = new InviteOrganisationResource(); inviteOrganisation.setOrganisation(organisationId); inviteOrganisation.setInviteResources(invites); String url = inviteRestUrl + "/create-application-invites"; return postWithRestResult(url, inviteOrganisation, Void.class); } @Override RestResult<Void> createInvitesByInviteOrganisation(String organisationName, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisation(Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisationForApplication(Long applicationId, Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> saveInvites(List<ApplicationInviteResource> inviteResources); @Override RestResult<Void> resendInvite(ApplicationInviteResource inviteResource); @Override RestResult<Void> acceptInvite(String inviteHash, long userId); @Override RestResult<Void> acceptInvite(String inviteHash, long userId, long organisationId); @Override RestResult<Void> removeApplicationInvite(Long inviteId); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ApplicationInviteResource> getInviteByHash(String hash); @Override RestResult<InviteOrganisationResource> getInviteOrganisationByHash(String hash); @Override RestResult<List<InviteOrganisationResource>> getInvitesByApplication(Long applicationId); }
@Test public void createInvitesByOrganisation() { final Long organisationId = 1289124L; final List<ApplicationInviteResource> invites = newApplicationInviteResource().build(42); InviteOrganisationResource inviteOrganisationResource = new InviteOrganisationResource(); inviteOrganisationResource.setOrganisation(organisationId); inviteOrganisationResource.setInviteResources(invites); setupPostWithRestResultExpectations(inviteRestURL + "/create-application-invites", inviteOrganisationResource, CREATED); RestResult<Void> response = service.createInvitesByOrganisation(organisationId, invites); assertTrue(response.isSuccess()); setupPostWithRestResultVerifications(inviteRestURL + "/create-application-invites", Void.class, inviteOrganisationResource); }
InviteRestServiceImpl extends BaseRestService implements InviteRestService { @Override public RestResult<Void> saveInvites(List<ApplicationInviteResource> inviteResources) { String url = inviteRestUrl + "/save-invites"; return postWithRestResult(url, inviteResources, Void.class); } @Override RestResult<Void> createInvitesByInviteOrganisation(String organisationName, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisation(Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisationForApplication(Long applicationId, Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> saveInvites(List<ApplicationInviteResource> inviteResources); @Override RestResult<Void> resendInvite(ApplicationInviteResource inviteResource); @Override RestResult<Void> acceptInvite(String inviteHash, long userId); @Override RestResult<Void> acceptInvite(String inviteHash, long userId, long organisationId); @Override RestResult<Void> removeApplicationInvite(Long inviteId); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ApplicationInviteResource> getInviteByHash(String hash); @Override RestResult<InviteOrganisationResource> getInviteOrganisationByHash(String hash); @Override RestResult<List<InviteOrganisationResource>> getInvitesByApplication(Long applicationId); }
@Test public void saveInvites() { final List<ApplicationInviteResource> invites = newApplicationInviteResource().build(42); setupPostWithRestResultExpectations(inviteRestURL + "/save-invites", invites, OK); RestResult<Void> response = service.saveInvites(invites); assertTrue(response.isSuccess()); setupPostWithRestResultVerifications(inviteRestURL + "/save-invites", Void.class, invites); }
InviteRestServiceImpl extends BaseRestService implements InviteRestService { @Override public RestResult<Void> resendInvite(ApplicationInviteResource inviteResource) { String url = inviteRestUrl + "/resend-invite"; return postWithRestResult(url, inviteResource, Void.class); } @Override RestResult<Void> createInvitesByInviteOrganisation(String organisationName, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisation(Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisationForApplication(Long applicationId, Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> saveInvites(List<ApplicationInviteResource> inviteResources); @Override RestResult<Void> resendInvite(ApplicationInviteResource inviteResource); @Override RestResult<Void> acceptInvite(String inviteHash, long userId); @Override RestResult<Void> acceptInvite(String inviteHash, long userId, long organisationId); @Override RestResult<Void> removeApplicationInvite(Long inviteId); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ApplicationInviteResource> getInviteByHash(String hash); @Override RestResult<InviteOrganisationResource> getInviteOrganisationByHash(String hash); @Override RestResult<List<InviteOrganisationResource>> getInvitesByApplication(Long applicationId); }
@Test public void resendInvites() { final ApplicationInviteResource invite = newApplicationInviteResource().build(); setupPostWithRestResultExpectations(inviteRestURL + "/resend-invite", invite, OK); RestResult<Void> response = service.resendInvite(invite); assertTrue(response.isSuccess()); setupPostWithRestResultVerifications(inviteRestURL + "/resend-invite", Void.class, invite); }
InviteRestServiceImpl extends BaseRestService implements InviteRestService { @Override public RestResult<Void> acceptInvite(String inviteHash, long userId) { String url = inviteRestUrl + String.format("/accept-invite/%s/%s", inviteHash, userId); return putWithRestResultAnonymous(url, Void.class); } @Override RestResult<Void> createInvitesByInviteOrganisation(String organisationName, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisation(Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisationForApplication(Long applicationId, Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> saveInvites(List<ApplicationInviteResource> inviteResources); @Override RestResult<Void> resendInvite(ApplicationInviteResource inviteResource); @Override RestResult<Void> acceptInvite(String inviteHash, long userId); @Override RestResult<Void> acceptInvite(String inviteHash, long userId, long organisationId); @Override RestResult<Void> removeApplicationInvite(Long inviteId); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ApplicationInviteResource> getInviteByHash(String hash); @Override RestResult<InviteOrganisationResource> getInviteOrganisationByHash(String hash); @Override RestResult<List<InviteOrganisationResource>> getInvitesByApplication(Long applicationId); }
@Test public void acceptInvite() { final long userId = 124214L; setupPutWithRestResultAnonymousExpectations(inviteRestURL + String.format("/accept-invite/%s/%s", inviteHash, userId), null, OK); RestResult<Void> response = service.acceptInvite(inviteHash, userId); assertTrue(response.isSuccess()); } @Test public void acceptInvite_OrganisationId() { final long userId = 124214L; final long organisationId = 23L; setupPutWithRestResultAnonymousExpectations(inviteRestURL + String.format("/accept-invite/%s/%s/%s", inviteHash, userId, organisationId), null, OK); RestResult<Void> response = service.acceptInvite(inviteHash, userId, organisationId); assertTrue(response.isSuccess()); }
InviteRestServiceImpl extends BaseRestService implements InviteRestService { @Override public RestResult<Void> removeApplicationInvite(Long inviteId) { String url = inviteRestUrl + String.format("/remove-invite/%s", inviteId); return deleteWithRestResult(url); } @Override RestResult<Void> createInvitesByInviteOrganisation(String organisationName, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisation(Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisationForApplication(Long applicationId, Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> saveInvites(List<ApplicationInviteResource> inviteResources); @Override RestResult<Void> resendInvite(ApplicationInviteResource inviteResource); @Override RestResult<Void> acceptInvite(String inviteHash, long userId); @Override RestResult<Void> acceptInvite(String inviteHash, long userId, long organisationId); @Override RestResult<Void> removeApplicationInvite(Long inviteId); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ApplicationInviteResource> getInviteByHash(String hash); @Override RestResult<InviteOrganisationResource> getInviteOrganisationByHash(String hash); @Override RestResult<List<InviteOrganisationResource>> getInvitesByApplication(Long applicationId); }
@Test public void removeApplicationInvite() { final Long inviteId = 20310L; setupDeleteWithRestResultExpectations(inviteRestURL + String.format("/remove-invite/%s", inviteId), OK); RestResult<Void> response = service.removeApplicationInvite(inviteId); assertTrue(response.isSuccess()); }
InviteRestServiceImpl extends BaseRestService implements InviteRestService { @Override public RestResult<Boolean> checkExistingUser(String inviteHash) { String url = inviteRestUrl + String.format("/check-existing-user/%s", inviteHash); return getWithRestResultAnonymous(url, Boolean.class); } @Override RestResult<Void> createInvitesByInviteOrganisation(String organisationName, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisation(Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisationForApplication(Long applicationId, Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> saveInvites(List<ApplicationInviteResource> inviteResources); @Override RestResult<Void> resendInvite(ApplicationInviteResource inviteResource); @Override RestResult<Void> acceptInvite(String inviteHash, long userId); @Override RestResult<Void> acceptInvite(String inviteHash, long userId, long organisationId); @Override RestResult<Void> removeApplicationInvite(Long inviteId); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ApplicationInviteResource> getInviteByHash(String hash); @Override RestResult<InviteOrganisationResource> getInviteOrganisationByHash(String hash); @Override RestResult<List<InviteOrganisationResource>> getInvitesByApplication(Long applicationId); }
@Test public void checkExistingUser() { String url = inviteRestURL + String.format("/check-existing-user/%s", inviteHash); setupGetWithRestResultAnonymousExpectations(url, Boolean.class, TRUE); RestResult<Boolean> response = service.checkExistingUser(inviteHash); assertTrue(response.isSuccess()); assertEquals(TRUE, response.getSuccess()); }
InviteRestServiceImpl extends BaseRestService implements InviteRestService { @Override public RestResult<UserResource> getUser(String inviteHash) { String url = inviteRestUrl + String.format(GET_USER_BY_HASH_MAPPING + "%s", inviteHash); return getWithRestResultAnonymous(url, UserResource.class); } @Override RestResult<Void> createInvitesByInviteOrganisation(String organisationName, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisation(Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisationForApplication(Long applicationId, Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> saveInvites(List<ApplicationInviteResource> inviteResources); @Override RestResult<Void> resendInvite(ApplicationInviteResource inviteResource); @Override RestResult<Void> acceptInvite(String inviteHash, long userId); @Override RestResult<Void> acceptInvite(String inviteHash, long userId, long organisationId); @Override RestResult<Void> removeApplicationInvite(Long inviteId); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ApplicationInviteResource> getInviteByHash(String hash); @Override RestResult<InviteOrganisationResource> getInviteOrganisationByHash(String hash); @Override RestResult<List<InviteOrganisationResource>> getInvitesByApplication(Long applicationId); }
@Test public void getUser() { UserResource expected = new UserResource(); String url = inviteRestURL + String.format("/get-user/" + "%s", inviteHash); setupGetWithRestResultAnonymousExpectations(url, UserResource.class, expected); RestResult<UserResource> response = service.getUser(inviteHash); assertTrue(response.isSuccess()); assertEquals(expected, response.getSuccess()); }
InviteRestServiceImpl extends BaseRestService implements InviteRestService { @Override public RestResult<ApplicationInviteResource> getInviteByHash(String hash) { return getWithRestResultAnonymous(inviteRestUrl + "/get-invite-by-hash/" + hash, ApplicationInviteResource.class); } @Override RestResult<Void> createInvitesByInviteOrganisation(String organisationName, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisation(Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisationForApplication(Long applicationId, Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> saveInvites(List<ApplicationInviteResource> inviteResources); @Override RestResult<Void> resendInvite(ApplicationInviteResource inviteResource); @Override RestResult<Void> acceptInvite(String inviteHash, long userId); @Override RestResult<Void> acceptInvite(String inviteHash, long userId, long organisationId); @Override RestResult<Void> removeApplicationInvite(Long inviteId); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ApplicationInviteResource> getInviteByHash(String hash); @Override RestResult<InviteOrganisationResource> getInviteOrganisationByHash(String hash); @Override RestResult<List<InviteOrganisationResource>> getInvitesByApplication(Long applicationId); }
@Test public void getInviteByHash() { ApplicationInviteResource expected = new ApplicationInviteResource(); String url = inviteRestURL + "/get-invite-by-hash/" + inviteHash; setupGetWithRestResultAnonymousExpectations(url, ApplicationInviteResource.class, expected); RestResult<ApplicationInviteResource> response = service.getInviteByHash(inviteHash); assertTrue(response.isSuccess()); assertEquals(expected, response.getSuccess()); }
InviteRestServiceImpl extends BaseRestService implements InviteRestService { @Override public RestResult<InviteOrganisationResource> getInviteOrganisationByHash(String hash) { return getWithRestResultAnonymous(inviteRestUrl + "/get-invite-organisation-by-hash/" + hash, InviteOrganisationResource.class); } @Override RestResult<Void> createInvitesByInviteOrganisation(String organisationName, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisation(Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisationForApplication(Long applicationId, Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> saveInvites(List<ApplicationInviteResource> inviteResources); @Override RestResult<Void> resendInvite(ApplicationInviteResource inviteResource); @Override RestResult<Void> acceptInvite(String inviteHash, long userId); @Override RestResult<Void> acceptInvite(String inviteHash, long userId, long organisationId); @Override RestResult<Void> removeApplicationInvite(Long inviteId); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ApplicationInviteResource> getInviteByHash(String hash); @Override RestResult<InviteOrganisationResource> getInviteOrganisationByHash(String hash); @Override RestResult<List<InviteOrganisationResource>> getInvitesByApplication(Long applicationId); }
@Test public void getInviteOrganisationByHash() { InviteOrganisationResource expected = new InviteOrganisationResource(); expected.setId(1234L); String url = inviteRestURL + "/get-invite-organisation-by-hash/" + inviteHash; setupGetWithRestResultAnonymousExpectations(url, InviteOrganisationResource.class, expected); RestResult<InviteOrganisationResource> response = service.getInviteOrganisationByHash(inviteHash); assertTrue(response.isSuccess()); assertEquals(expected, response.getSuccess()); }
InviteRestServiceImpl extends BaseRestService implements InviteRestService { @Override public RestResult<List<InviteOrganisationResource>> getInvitesByApplication(Long applicationId) { String url = inviteRestUrl + "/get-invites-by-application-id/"+ applicationId; return getWithRestResult(url, inviteOrganisationResourceListType()); } @Override RestResult<Void> createInvitesByInviteOrganisation(String organisationName, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisation(Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> createInvitesByOrganisationForApplication(Long applicationId, Long organisationId, List<ApplicationInviteResource> invites); @Override RestResult<Void> saveInvites(List<ApplicationInviteResource> inviteResources); @Override RestResult<Void> resendInvite(ApplicationInviteResource inviteResource); @Override RestResult<Void> acceptInvite(String inviteHash, long userId); @Override RestResult<Void> acceptInvite(String inviteHash, long userId, long organisationId); @Override RestResult<Void> removeApplicationInvite(Long inviteId); @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ApplicationInviteResource> getInviteByHash(String hash); @Override RestResult<InviteOrganisationResource> getInviteOrganisationByHash(String hash); @Override RestResult<List<InviteOrganisationResource>> getInvitesByApplication(Long applicationId); }
@Test public void getInvitesByApplication() { Long applicationId = 2341L; List<InviteOrganisationResource> expected = newInviteOrganisationResource().build(2); String url = inviteRestURL + "/get-invites-by-application-id/" + applicationId; setupGetWithRestResultExpectations(url, inviteOrganisationResourceListType(), expected, OK); RestResult<List<InviteOrganisationResource>> response = service.getInvitesByApplication(applicationId); assertTrue(response.isSuccess()); assertEquals(expected, response.getSuccess()); }
ProjectInviteRestServiceImpl extends BaseRestService implements ProjectInviteRestService { @Override public RestResult<Void> acceptInvite(String inviteHash, Long userId) { String url = PROJECT_INVITE_BASE_URL + ACCEPT_INVITE + inviteHash + "/" + userId; return putWithRestResultAnonymous(url, Void.class); } @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ProjectUserInviteResource> getInviteByHash(String hash); @Override RestResult<Void> acceptInvite(String inviteHash, Long userId); @Override RestResult<List<ProjectUserInviteResource>> getInvitesByProject(Long projectId); }
@Test public void testGetProjectById() { String inviteHash = "hash"; Long userId = 1L; setupPutWithRestResultAnonymousExpectations(PROJECT_INVITE_BASE_URL + ACCEPT_INVITE + inviteHash + "/" + userId, null, OK); RestResult<Void> returnedResponse = service.acceptInvite(inviteHash, userId); assertTrue(returnedResponse.isSuccess()); }
ProjectInviteRestServiceImpl extends BaseRestService implements ProjectInviteRestService { @Override public RestResult<Boolean> checkExistingUser(String inviteHash) { String url = PROJECT_INVITE_BASE_URL + CHECK_EXISTING_USER_URL + inviteHash; return getWithRestResultAnonymous(url, Boolean.class); } @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ProjectUserInviteResource> getInviteByHash(String hash); @Override RestResult<Void> acceptInvite(String inviteHash, Long userId); @Override RestResult<List<ProjectUserInviteResource>> getInvitesByProject(Long projectId); }
@Test public void testCheckExistingUser() { String inviteHash = "hash"; setupGetWithRestResultAnonymousExpectations(PROJECT_INVITE_BASE_URL + CHECK_EXISTING_USER_URL + inviteHash, Boolean.class, true); RestResult<Boolean> returnedResponse = service.checkExistingUser(inviteHash); assertTrue(returnedResponse.isSuccess()); assertTrue(returnedResponse.getSuccess()); }
ProjectInviteRestServiceImpl extends BaseRestService implements ProjectInviteRestService { @Override public RestResult<ProjectUserInviteResource> getInviteByHash(String hash) { String url = PROJECT_INVITE_BASE_URL + GET_INVITE_BY_HASH + hash; return getWithRestResultAnonymous(url, ProjectUserInviteResource.class); } @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ProjectUserInviteResource> getInviteByHash(String hash); @Override RestResult<Void> acceptInvite(String inviteHash, Long userId); @Override RestResult<List<ProjectUserInviteResource>> getInvitesByProject(Long projectId); }
@Test public void testGetInviteByHash() { ProjectUserInviteResource invite = new ProjectUserInviteResource(); invite.setHash("hash"); setupGetWithRestResultAnonymousExpectations(PROJECT_INVITE_BASE_URL + GET_INVITE_BY_HASH + invite.getHash(), ProjectUserInviteResource.class, invite); RestResult<ProjectUserInviteResource> returnedResponse = service.getInviteByHash(invite.getHash()); assertTrue(returnedResponse.isSuccess()); assertEquals(invite, returnedResponse.getSuccess()); }
ProjectInviteRestServiceImpl extends BaseRestService implements ProjectInviteRestService { @Override public RestResult<UserResource> getUser(String inviteHash) { String url = PROJECT_INVITE_BASE_URL + GET_USER_BY_HASH_MAPPING + inviteHash; return getWithRestResultAnonymous(url, UserResource.class); } @Override RestResult<Boolean> checkExistingUser(String inviteHash); @Override RestResult<UserResource> getUser(String inviteHash); @Override RestResult<ProjectUserInviteResource> getInviteByHash(String hash); @Override RestResult<Void> acceptInvite(String inviteHash, Long userId); @Override RestResult<List<ProjectUserInviteResource>> getInvitesByProject(Long projectId); }
@Test public void testGetUser() { UserResource user = new UserResource(); String inviteHash = "hash"; setupGetWithRestResultAnonymousExpectations(PROJECT_INVITE_BASE_URL + GET_USER_BY_HASH_MAPPING + inviteHash, UserResource.class, user); RestResult<UserResource> returnedResponse = service.getUser(inviteHash); assertTrue(returnedResponse.isSuccess()); assertEquals(user, returnedResponse.getSuccess()); }
InviteOrganisationRestServiceImpl extends BaseRestService implements InviteOrganisationRestService { @Override public RestResult<InviteOrganisationResource> getById(long id) { return getWithRestResult(format("%s/%s", restUrl, id), InviteOrganisationResource.class); } @Override RestResult<InviteOrganisationResource> getById(long id); @Override RestResult<InviteOrganisationResource> getByIdForAnonymousUserFlow(long id); @Override RestResult<InviteOrganisationResource> getByOrganisationIdWithInvitesForApplication(long organisationId, long applicationId); @Override RestResult<Void> put(InviteOrganisationResource inviteOrganisation); }
@Test public void getById() throws Exception { long inviteOrganisationId = 1L; InviteOrganisationResource expected = newInviteOrganisationResource().build(); setupGetWithRestResultExpectations(format("%s/%s", restUrl, inviteOrganisationId), InviteOrganisationResource.class, expected); InviteOrganisationResource actual = service.getById(inviteOrganisationId).getSuccess(); assertEquals(expected, actual); }
InviteOrganisationRestServiceImpl extends BaseRestService implements InviteOrganisationRestService { @Override public RestResult<InviteOrganisationResource> getByIdForAnonymousUserFlow(long id) { return getWithRestResultAnonymous(format("%s/%s", restUrl, id), InviteOrganisationResource.class); } @Override RestResult<InviteOrganisationResource> getById(long id); @Override RestResult<InviteOrganisationResource> getByIdForAnonymousUserFlow(long id); @Override RestResult<InviteOrganisationResource> getByOrganisationIdWithInvitesForApplication(long organisationId, long applicationId); @Override RestResult<Void> put(InviteOrganisationResource inviteOrganisation); }
@Test public void getByIdForAnonymousUserFlow() throws Exception { long inviteOrganisationId = 1L; InviteOrganisationResource expected = newInviteOrganisationResource().build(); setupGetWithRestResultAnonymousExpectations(format("%s/%s", restUrl, inviteOrganisationId), InviteOrganisationResource.class, expected); InviteOrganisationResource actual = service.getByIdForAnonymousUserFlow(inviteOrganisationId).getSuccess(); assertEquals(expected, actual); }
InviteOrganisationRestServiceImpl extends BaseRestService implements InviteOrganisationRestService { @Override public RestResult<InviteOrganisationResource> getByOrganisationIdWithInvitesForApplication(long organisationId, long applicationId) { return getWithRestResult(format("%s/organisation/%s/application/%s", restUrl, organisationId, applicationId), InviteOrganisationResource.class); } @Override RestResult<InviteOrganisationResource> getById(long id); @Override RestResult<InviteOrganisationResource> getByIdForAnonymousUserFlow(long id); @Override RestResult<InviteOrganisationResource> getByOrganisationIdWithInvitesForApplication(long organisationId, long applicationId); @Override RestResult<Void> put(InviteOrganisationResource inviteOrganisation); }
@Test public void getByOrganisationIdWithInvitesForApplication() throws Exception { long organisationId = 1L; long applicationId = 2L; InviteOrganisationResource expected = newInviteOrganisationResource().build(); setupGetWithRestResultExpectations(format("%s/organisation/%s/application/%s", restUrl, organisationId, applicationId), InviteOrganisationResource.class, expected); InviteOrganisationResource actual = service.getByOrganisationIdWithInvitesForApplication(organisationId, applicationId) .getSuccess(); assertEquals(expected, actual); }
InviteOrganisationRestServiceImpl extends BaseRestService implements InviteOrganisationRestService { @Override public RestResult<Void> put(InviteOrganisationResource inviteOrganisation) { return putWithRestResult(restUrl + "/save", inviteOrganisation, Void.class); } @Override RestResult<InviteOrganisationResource> getById(long id); @Override RestResult<InviteOrganisationResource> getByIdForAnonymousUserFlow(long id); @Override RestResult<InviteOrganisationResource> getByOrganisationIdWithInvitesForApplication(long organisationId, long applicationId); @Override RestResult<Void> put(InviteOrganisationResource inviteOrganisation); }
@Test public void put() throws Exception { InviteOrganisationResource inviteOrganisationResource = newInviteOrganisationResource().build(); setupPutWithRestResultExpectations(format("%s/save", restUrl), inviteOrganisationResource, OK); RestResult<Void> result = service.put(inviteOrganisationResource); assertTrue(result.isSuccess()); }
ActionTypeRestServiceImpl extends BaseRestService implements ActionTypeRestService { @Override public RestResult<List<EuActionTypeResource>> findAll() { return getWithRestResult(baseURL + "/find-all", euActionTypeResourceListType()); } @Override RestResult<List<EuActionTypeResource>> findAll(); @Override RestResult<EuActionTypeResource> getById(long id); static ParameterizedTypeReference<List<EuActionTypeResource>> euActionTypeResourceListType(); }
@Test public void findAll() { List<EuActionTypeResource> expected = emptyList(); setupGetWithRestResultExpectations(format("%s/%s", REST_URL, "find-all"), euActionTypeResourceListType(), expected, OK); List<EuActionTypeResource> response = service.findAll().getSuccess(); assertSame(expected, response); }
ActionTypeRestServiceImpl extends BaseRestService implements ActionTypeRestService { @Override public RestResult<EuActionTypeResource> getById(long id) { return getWithRestResult(baseURL + "/get-by-id/" + id, EuActionTypeResource.class); } @Override RestResult<List<EuActionTypeResource>> findAll(); @Override RestResult<EuActionTypeResource> getById(long id); static ParameterizedTypeReference<List<EuActionTypeResource>> euActionTypeResourceListType(); }
@Test public void getById() { long id = 1L; EuActionTypeResource expected = new EuActionTypeResource(); setupGetWithRestResultExpectations(format("%s/%s/%d", REST_URL, "get-by-id", id), EuActionTypeResource.class, expected, OK); EuActionTypeResource response = service.getById(id).getSuccess(); assertSame(expected, response); }
EuGrantTransferRestServiceImpl extends BaseRestService implements EuGrantTransferRestService { @Override public RestResult<FileEntryResource> findGrantAgreement(long applicationId) { String url = format("%s/%s/%s", REST_URL, "grant-agreement-details", applicationId); return getWithRestResult(url, FileEntryResource.class); } @Override RestResult<Void> uploadGrantAgreement(long applicationId, String contentType, long size, String originalFilename, byte[] multipartFileBytes); @Override RestResult<Void> deleteGrantAgreement(long applicationId); @Override RestResult<ByteArrayResource> downloadGrantAgreement(long applicationId); @Override RestResult<FileEntryResource> findGrantAgreement(long applicationId); @Override RestResult<EuGrantTransferResource> findDetailsByApplicationId(long applicationId); @Override RestResult<Void> updateGrantTransferDetails(EuGrantTransferResource euGrantResource, long applicationId); }
@Test public void findGrantAgreement() { long applicationId = 1L; FileEntryResource expected = new FileEntryResource(); setupGetWithRestResultExpectations(format("%s/%s/%s", REST_URL, "grant-agreement-details", applicationId), FileEntryResource.class, expected, OK); final FileEntryResource response = service.findGrantAgreement(applicationId).getSuccess(); assertSame(expected, response); }
EuGrantTransferRestServiceImpl extends BaseRestService implements EuGrantTransferRestService { @Override public RestResult<Void> uploadGrantAgreement(long applicationId, String contentType, long size, String originalFilename, byte[] multipartFileBytes) { String url = format("%s/%s/%s?filename=%s", REST_URL, "grant-agreement", applicationId, originalFilename); return postWithRestResult(url, multipartFileBytes, createFileUploadHeader(contentType, size), Void.class); } @Override RestResult<Void> uploadGrantAgreement(long applicationId, String contentType, long size, String originalFilename, byte[] multipartFileBytes); @Override RestResult<Void> deleteGrantAgreement(long applicationId); @Override RestResult<ByteArrayResource> downloadGrantAgreement(long applicationId); @Override RestResult<FileEntryResource> findGrantAgreement(long applicationId); @Override RestResult<EuGrantTransferResource> findDetailsByApplicationId(long applicationId); @Override RestResult<Void> updateGrantTransferDetails(EuGrantTransferResource euGrantResource, long applicationId); }
@Test public void uploadGrantAgreement() { String fileContentString = "keDFjFGrueurFGy3456efhjdg3"; byte[] fileContent = fileContentString.getBytes(); final String originalFilename = "testFile.pdf"; final String contentType = "text/pdf"; final long applicationId = 77L; setupFileUploadWithRestResultExpectations(format("%s/%s/%s?filename=%s", REST_URL, "grant-agreement", applicationId, originalFilename), fileContentString, contentType, fileContent.length, CREATED); RestResult<Void> result = service.uploadGrantAgreement(applicationId, contentType, fileContent.length, originalFilename, fileContent); assertTrue(result.isSuccess()); }