FactoryBaseValidator { protected void validateSource(Factory factory) throws ApiException { String type = factory.getSource().getProject().getType(); String location = factory.getSource().getProject().getLocation(); String parameterTypeName = "source.project.type"; String parameterLocationName = "source.project.location"; if (!("git".equals(type) || "esbwso2".equals(type))) { throw new ConflictException("Parameter '" + parameterTypeName + "' has illegal value."); } if (isNullOrEmpty(location)) { throw new ConflictException( format(FactoryConstants.PARAMETRIZED_ILLEGAL_PARAMETER_VALUE_MESSAGE, parameterLocationName, location)); } else { try { URLDecoder.decode(location, "UTF-8"); } catch (IllegalArgumentException | UnsupportedEncodingException e) { throw new ConflictException( format(FactoryConstants.PARAMETRIZED_ILLEGAL_PARAMETER_VALUE_MESSAGE, parameterLocationName, location)); } } } FactoryBaseValidator(AccountDao accountDao,
                                UserDao userDao,
                                PreferenceDao preferenceDao);   }
@Test(expectedExceptions = ApiException.class, expectedExceptionsMessageRegExp = "The parameter source.project.location has a value submitted http: "unexpected. " + "For more information, please visit http: public void shouldNotValidateIfVcsurlContainIncorrectEncodedSymbol() throws ApiException { factory = factory.withSource(dto.createDto(Source.class) .withProject(dto.createDto(ImportSourceDescriptor.class) .withType("git") .withLocation("http: validator.validateSource(factory); }
@Test public void shouldValidateIfVcsurlIsCorrectSsh() throws ApiException { factory = factory.withSource(dto.createDto(Source.class) .withProject(dto.createDto(ImportSourceDescriptor.class) .withType("git") .withLocation("ssh: validator.validateSource(factory); }
@Test public void shouldValidateIfVcsurlIsCorrectHttps() throws ApiException { factory = factory.withSource(dto.createDto(Source.class) .withProject(dto.createDto(ImportSourceDescriptor.class) .withType("git") .withLocation("https: validator.validateSource(factory); }
@Test(dataProvider = "badAdvancedFactoryUrlProvider", expectedExceptions = ApiException.class) public void shouldNotValidateIfVcsOrVcsUrlIsInvalid(Factory factory) throws ApiException { validator.validateSource(factory); }