FactoryBaseValidator { protected void validateProjects(FactoryDto factory) throws BadRequestException { for (ProjectConfigDto project : factory.getWorkspace().getProjects()) { final String projectName = project.getName(); if (null != projectName && !PROJECT_NAME_VALIDATOR.matcher(projectName).matches()) { throw new BadRequestException( "Project name must contain only Latin letters, " + "digits or these following special characters -._."); } if (project.getPath().indexOf('/', 1) == -1) { if (project.getSource() == null) { throw new BadRequestException( format(FactoryConstants.MISSING_MANDATORY_MESSAGE, "project.source")); } final String location = project.getSource().getLocation(); final String parameterLocationName = "project.source.location"; if (isNullOrEmpty(location)) { throw new BadRequestException( format( FactoryConstants.PARAMETRIZED_ILLEGAL_PARAMETER_VALUE_MESSAGE, parameterLocationName, location)); } try { URLDecoder.decode(location, "UTF-8"); } catch (IllegalArgumentException | UnsupportedEncodingException e) { throw new BadRequestException( format( FactoryConstants.PARAMETRIZED_ILLEGAL_PARAMETER_VALUE_MESSAGE, parameterLocationName, location)); } } } }    }
@Test public void shouldBeAbleToValidateFactoryUrlObject() throws ApiException { factory = prepareFactoryWithGivenStorage("git", VALID_REPOSITORY_URL, VALID_PROJECT_PATH); validator.validateProjects(factory); validator.validateProjects(factory); }
@Test public void shouldBeAbleToValidateFactoryUrlObjectIfStorageIsESBWSO2() throws ApiException { factory = prepareFactoryWithGivenStorage("esbwso2", VALID_REPOSITORY_URL, VALID_PROJECT_PATH); validator.validateProjects(factory); validator.validateProjects(factory); }
@Test( expectedExceptions = ApiException.class, expectedExceptionsMessageRegExp = "The parameter project.source.location has a value submitted http: + "unexpected. " + "For more information, please visit https: public void shouldNotValidateIfStorageLocationContainIncorrectEncodedSymbol() throws ApiException { factory = prepareFactoryWithGivenStorage("git", "http: validator.validateProjects(factory); }
@Test public void shouldValidateIfStorageLocationIsCorrectSsh() throws ApiException { factory = prepareFactoryWithGivenStorage( "git", "ssh: "example-project"); validator.validateProjects(factory); }
@Test public void shouldValidateIfStorageLocationIsCorrectHttps() throws ApiException { factory = prepareFactoryWithGivenStorage("git", "https: validator.validateProjects(factory); }
@Test public void shouldValidateSubProjectWithNoLocation() throws ApiException { factory = prepareFactoryWithGivenStorage("git", "null", "/cloudide/core"); validator.validateProjects(factory); }
@Test(dataProvider = "badAdvancedFactoryUrlProvider", expectedExceptions = ApiException.class) public void shouldNotValidateIfStorageOrStorageLocationIsInvalid(FactoryDto factory) throws ApiException { validator.validateProjects(factory); }
@Test( dataProvider = "invalidProjectNamesProvider", expectedExceptions = ApiException.class, expectedExceptionsMessageRegExp = "Project name must contain only Latin letters, " + "digits or these following special characters -._.") public void shouldThrowFactoryUrlExceptionIfProjectNameInvalid(String projectName) throws Exception { factory.withWorkspace( newDto(WorkspaceConfigDto.class) .withProjects( singletonList( newDto(ProjectConfigDto.class).withType("type").withName(projectName)))); validator.validateProjects(factory); }
@Test(dataProvider = "validProjectNamesProvider") public void shouldBeAbleToValidateValidProjectName(String projectName) throws Exception { prepareFactoryWithGivenStorage("git", VALID_REPOSITORY_URL, VALID_PROJECT_PATH); factory.withWorkspace( newDto(WorkspaceConfigDto.class) .withProjects( singletonList( newDto(ProjectConfigDto.class) .withType("type") .withName(projectName) .withSource( newDto(SourceStorageDto.class) .withType("git") .withLocation(VALID_REPOSITORY_URL)) .withPath(VALID_PROJECT_PATH)))); validator.validateProjects(factory); }