JobRequestHelper { public JobResult createSpace(final String jobId, final String spaceName, final String spaceDescription, final String spaceOwner, final String defaultGroupId) { JobResult result = new JobResult(); result.setJobId(jobId); if (spaceName == null || spaceOwner == null) { result.setStatus(JobStatus.BAD_REQUEST); result.setResult("Space name and owner must be provided"); return result; } String _defaultGroupId = null; if (defaultGroupId == null || defaultGroupId.trim().isEmpty()) { _defaultGroupId = organizationalUnitService.getSanitizedDefaultGroupId(spaceName); logger.warn("No default group id was provided, reverting to the space unit name"); } else { if (!organizationalUnitService.isValidGroupId(defaultGroupId)) { result.setStatus(JobStatus.BAD_REQUEST); result.setResult("Invalid default group id, only alphanumerical characters are admitted, " + "as well as '\"_\"', '\"-\"' or '\".\"'."); return result; } else { _defaultGroupId = defaultGroupId; } } OrganizationalUnit organizationalUnit = organizationalUnitService.getOrganizationalUnit(spaceName); if (organizationalUnit != null) { result.setStatus(JobStatus.BAD_REQUEST); result.setResult("Space with name " + spaceName + " already exists"); return result; } organizationalUnit = organizationalUnitService.createOrganizationalUnit(spaceName, _defaultGroupId, Collections.emptyList(), Collections.singletonList(new Contributor(spaceOwner, ContributorType.OWNER)), spaceDescription); if (organizationalUnit != null) { result.setResult("Space " + organizationalUnit.getName() + " is created successfully."); result.setStatus(JobStatus.SUCCESS); } else { 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 testCreateSpace() { when(organizationalUnitService.isValidGroupId("org.space.newspace")).thenReturn(true); when(organizationalUnitService.createOrganizationalUnit(any(), any(), any(), any(), any())).thenReturn(mock(OrganizationalUnit.class)); JobResult jobResult = helper.createSpace(null, space.getName(), "this is a new space", "admin", "org.space.newspace"); assertEquals(JobStatus.SUCCESS, jobResult.getStatus()); }