GitlabFactoryParametersResolver implements FactoryParametersResolver { @Override public FactoryDto createFactory(@NotNull final Map<String, String> factoryParameters) throws BadRequestException { final GitlabUrl gitlabUrl = gitlabUrlParser.parse(factoryParameters.get("url")); FactoryDto factory = urlFactoryBuilder.createFactory(gitlabUrl.factoryJsonFileLocation()); if (factory.getWorkspace() == null) { factory.setWorkspace( urlFactoryBuilder.buildWorkspaceConfig( gitlabUrl.getRepository(), gitlabUrl.getUsername(), gitlabUrl.dockerFileLocation())); } ProjectConfigDto projectConfigDto = newDto(ProjectConfigDto.class) .withSource(gitlabSourceStorageBuilder.build(gitlabUrl)) .withName(gitlabUrl.getRepository()) .withType("blank") .withPath("/".concat(gitlabUrl.getRepository())); return projectConfigDtoMerger.merge(factory, projectConfigDto); }  @Override boolean accept(@NotNull final Map<String, String> factoryParameters); @Override FactoryDto createFactory(@NotNull final Map<String, String> factoryParameters);  }
@Test public void shouldReturnGitHubSimpleFactory() throws Exception { String gitlabUrl = "https: String gitlabUrlRepository = gitlabUrl + ".git"; FactoryDto computedFactory = newDto(FactoryDto.class).withV("4.0"); when(urlFactoryBuilder.createFactory(anyString())).thenReturn(computedFactory); gitlabFactoryParametersResolver.createFactory(singletonMap(URL_PARAMETER_NAME, gitlabUrl)); verify(urlFactoryBuilder).createFactory(createFactoryParamsArgumentCaptor.capture()); assertEquals( createFactoryParamsArgumentCaptor.getValue(), "https: verify(urlFactoryBuilder) .buildWorkspaceConfig( eq("che"), eq("eclipse"), eq("https: verify(projectConfigDtoMerger) .merge(any(FactoryDto.class), projectConfigDtoArgumentCaptor.capture()); ProjectConfigDto projectConfigDto = projectConfigDtoArgumentCaptor.getValue(); SourceStorageDto sourceStorageDto = projectConfigDto.getSource(); assertNotNull(sourceStorageDto); assertEquals(sourceStorageDto.getType(), "git"); assertEquals(sourceStorageDto.getLocation(), gitlabUrlRepository); Map<String, String> sourceParameters = sourceStorageDto.getParameters(); assertEquals(sourceParameters.size(), 1); assertEquals(sourceParameters.get("branch"), "master"); }
@Test public void shouldReturnGitHubBranchFactory() throws Exception { String gitlabUrl = "https: String gitlabCloneUrl = "https: String gitlabBranch = "4.2.x"; String gitlabCloneUrlRespository = gitlabCloneUrl + ".git"; FactoryDto computedFactory = newDto(FactoryDto.class).withV("4.0"); when(urlFactoryBuilder.createFactory(anyString())).thenReturn(computedFactory); gitlabFactoryParametersResolver.createFactory(singletonMap(URL_PARAMETER_NAME, gitlabUrl)); verify(urlFactoryBuilder).createFactory(createFactoryParamsArgumentCaptor.capture()); assertEquals( createFactoryParamsArgumentCaptor.getValue(), "https: verify(urlFactoryBuilder) .buildWorkspaceConfig( eq("che"), eq("eclipse"), eq("https: verify(projectConfigDtoMerger) .merge(any(FactoryDto.class), projectConfigDtoArgumentCaptor.capture()); ProjectConfigDto projectConfigDto = projectConfigDtoArgumentCaptor.getValue(); SourceStorageDto sourceStorageDto = projectConfigDto.getSource(); assertNotNull(sourceStorageDto); assertEquals(sourceStorageDto.getType(), "git"); assertEquals(sourceStorageDto.getLocation(), gitlabCloneUrlRespository); Map<String, String> sourceParameters = sourceStorageDto.getParameters(); assertEquals(sourceParameters.size(), 1); assertEquals(sourceParameters.get("branch"), gitlabBranch); }
@Test public void shouldReturnGitHubBranchAndKeepdirFactory() throws Exception { String gitlabUrl = "https: String gitlabCloneUrl = "https: String gitlabBranch = "4.2.x"; String gitlabKeepdir = "dashboard"; String gitlabCloneUrlRespository = gitlabCloneUrl + ".git"; FactoryDto computedFactory = newDto(FactoryDto.class).withV("4.0"); when(urlFactoryBuilder.createFactory(anyString())).thenReturn(computedFactory); gitlabFactoryParametersResolver.createFactory(singletonMap(URL_PARAMETER_NAME, gitlabUrl)); verify(urlFactoryBuilder).createFactory(createFactoryParamsArgumentCaptor.capture()); assertEquals( createFactoryParamsArgumentCaptor.getValue(), "https: verify(urlFactoryBuilder) .buildWorkspaceConfig( eq("che"), eq("eclipse"), eq("https: verify(projectConfigDtoMerger) .merge(any(FactoryDto.class), projectConfigDtoArgumentCaptor.capture()); ProjectConfigDto projectConfigDto = projectConfigDtoArgumentCaptor.getValue(); SourceStorageDto sourceStorageDto = projectConfigDto.getSource(); assertNotNull(sourceStorageDto); assertEquals(sourceStorageDto.getType(), "git"); assertEquals(sourceStorageDto.getLocation(), gitlabCloneUrlRespository); Map<String, String> sourceParameters = sourceStorageDto.getParameters(); assertEquals(sourceParameters.size(), 2); assertEquals(sourceParameters.get("branch"), gitlabBranch); assertEquals(sourceParameters.get("keepDir"), gitlabKeepdir); }