ProjectService { public void createProject(ProjectModel model) throws NameTakenException, RepositoryUnavailableException, RepositoryParsingException { validateIfNameAvailable(model.getNamespace(), model.getName()); Namespace namespace = namespaceDao.findByName(model.getNamespace()).get(); Project project = new Project.Builder() .withRef(model.getRef()) .withName(model.getName()) .withNamespace(namespace) .withDescription(model.getDescription()) .withRepository(model.getRepository()) .withRepositoryHost(RepositoryMapper.getHost(model.getRepository())) .withRepositoryPath(RepositoryMapper.getPath(model.getRepository())) .withEnvironmentVariables(getEnvironment(model)) .build(); validateIfRepositoryAvailable(project); projectDao.save(project); }  void createProject(ProjectModel model); List<ProjectModel> getProjects(List<Long> ids); List<ProjectModel> getProjectsLikeName(String name, int page, int size); List<ProjectModel> getProjects(int page, int size); ProjectModel getProject(String namespaceName, String name); void updateProject(Long projectId, ProjectModel model); void renameProject(Long projectId, ProjectModel model); void moveProject(Long projectId, ProjectModel model); @Transactional void deleteProject(Long projectId); @Transactional void deleteProject(Project project);  }
@Test public void shouldCreateProject() throws NameTakenException, RepositoryUnavailableException, RepositoryParsingException { ProjectModel model = getProjectModel("test-namespace", "some-semi-random-name"); projectService.createProject(model); Optional<Project> project = projectDao.findByNamespaceNameAndName("test-namespace", "some-semi-random-name"); assertThat(project.get().getRef()).isEqualTo("master"); assertThat(project.get().getCreationDate()).isNotNull(); }
@Test(expected = NameTakenException.class) public void shouldThrowNameTakenException() throws NameTakenException, RepositoryUnavailableException, RepositoryParsingException { ProjectModel model = getProjectModel("test-namespace", "some-semi-random-name-2"); projectService.createProject(model); projectService.createProject(model); }
@Test public void shouldAllowCreatingTheSameProjectWithDifferentNamespace() throws NameTakenException, RepositoryUnavailableException, RepositoryParsingException { ProjectModel model = getProjectModel("test-namespace", "some-semi-random-name-3"); projectService.createProject(model); model = getProjectModel("other-namespace", "some-semi-random-name"); projectService.createProject(model); Optional<Project> project = projectDao.findByNamespaceNameAndName("test-namespace", "some-semi-random-name-3"); assertThat(project.isPresent()).isTrue(); project = projectDao.findByNamespaceNameAndName("other-namespace", "some-semi-random-name"); assertThat(project.isPresent()).isTrue(); }
@Test(expected = RepositoryUnavailableException.class) public void shouldThrowRepoUnavailableException() throws NameTakenException, RepositoryUnavailableException, RepositoryParsingException { ProjectModel model = getProjectModel("test-namespace", "some-semi-random-name-4"); model.setRepository("https: projectService.createProject(model); }