JobRequestHelper { public JobResult installProject(final String jobId, final String spaceName, final String projectName, final String branchName) { PortablePreconditions.checkNotNull("jobId", jobId); PortablePreconditions.checkNotNull("spaceName", spaceName); PortablePreconditions.checkNotNull("projectName", projectName); JobResult result = new JobResult(); result.setJobId(jobId); final OrganizationalUnit organizationalUnit = organizationalUnitService.getOrganizationalUnit(spaceName); if (organizationalUnit == null) { result.setStatus(JobStatus.RESOURCE_NOT_EXIST); result.setResult("Space [" + spaceName + "] does not exist"); return result; } final WorkspaceProject workspaceProject = workspaceProjectService.resolveProject( spacesAPI.getSpace(spaceName), projectName, branchName); if (workspaceProject == null) { return projectDoesNotExistError(jobId, projectName); } final Module module = workspaceProject.getMainModule(); if (module == null) { if (branchName == null) { return projectHasNoMainModuleError(jobId, projectName); } return projectHasNoModuleError(jobId, projectName, branchName); } try { BuildResults buildResults = buildService.buildAndDeploy(module); result.setDetailedResult(buildResults == null ? null : deployResultToDetailedStringMessages(buildResults)); result.setStatus(buildResults != null && buildResults.getErrorMessages().isEmpty() ? JobStatus.SUCCESS : JobStatus.FAIL); } catch (Throwable t) { Optional<GAVAlreadyExistsException> gaeOpt = findCause(t, GAVAlreadyExistsException.class); if (gaeOpt.isPresent()) { GAVAlreadyExistsException gae = gaeOpt.get(); result.setStatus(JobStatus.DUPLICATE_RESOURCE); result.setResult("Project's GAV [" + gae.getGAV() + "] already exists at [" + toString(gae.getRepositories()) + "]"); } else { List<String> errorResult = new ArrayList<>(); errorResult.add(t.getMessage()); result.setDetailedResult(errorResult); result.setStatus(JobStatus.FAIL); } } return result; }  JobResult cloneProject(final String jobId,
                                  final String spaceName,
                                  final CloneProjectRequest cloneProjectRequest); JobResult createProject(final String jobId,
                                   final String spaceName,
                                   final String projectName,
                                   String projectGroupId,
                                   String projectVersion,
                                   String projectDescription); JobResult deleteProject(final String jobId,
                                   final String spaceName,
                                   final String projectName); JobResult compileProject(final String jobId,
                                    final String spaceName,
                                    final String projectName,
                                    final String branchName); JobResult installProject(final String jobId,
                                    final String spaceName,
                                    final String projectName,
                                    final String branchName); JobResult testProject(final String jobId,
                                 final String spaceName,
                                 final String projectName,
                                 final String branchName); JobResult deployProject(final String jobId,
                                   final String spaceName,
                                   final String projectName,
                                   final String branchName); JobResult removeSpace(final String jobId,
                                 final String spaceName); JobResult createSpace(final String jobId,
                                 final String spaceName,
                                 final String spaceDescription,
                                 final String spaceOwner,
                                 final String defaultGroupId); JobResult updateSpace(final String jobId,
                                 final String spaceName,
                                 final String spaceDescription,
                                 final String spaceOwner,
                                 final String defaultGroupId); JobResult addBranch(final String jobId,
                               final String spaceName,
                               final String projectName,
                               final String newBranchName,
                               final String baseBranchName,
                               final String userIdentifier); JobResult removeBranch(final String jobId,
                                  final String spaceName,
                                  final String projectName,
                                  final String branchName,
                                  final String userIdentifier); JobResult addProjectToSpace(final String jobId,
                                       final String spaceName,
                                       final String projectName);  }
@Test public void testInstallProject() { whenProjectExists(); doReturn(mock(OrganizationalUnit.class)).when(organizationalUnitService).getOrganizationalUnit("space"); BuildResults buildResults = mock(BuildResults.class); when(buildResults.getGAV()).thenReturn(mock(GAV.class)); when(buildService.buildAndDeploy(any())).thenReturn(buildResults); JobResult jobResult = helper.installProject("job123", space.getName(), "project", null); assertEquals(JobStatus.SUCCESS, jobResult.getStatus()); }
@Test public void testInstallProjectFail() { whenProjectExists(); doReturn(mock(OrganizationalUnit.class)).when(organizationalUnitService).getOrganizationalUnit("space"); BuildResults buildResults = mock(BuildResults.class); when(buildResults.getGAV()).thenReturn(mock(GAV.class)); when(buildResults.getErrorMessages()).thenReturn(Arrays.asList(mock(BuildMessage.class))); when(buildService.buildAndDeploy(any())).thenReturn(buildResults); JobResult jobResult = helper.installProject("job123", space.getName(), "project", null); assertEquals(JobStatus.FAIL, jobResult.getStatus()); }