SourceProjectParametersValidator implements FactoryParameterValidator<ImportSourceDescriptor> { @Override public void validate(ImportSourceDescriptor source, FactoryParameter.Version version) throws ConflictException { if ("git".equals(source.getType()) || "esbwso2".equals(source.getType())) { for (Map.Entry<String, String> entry : source.getParameters().entrySet()) { switch (entry.getKey()) { case "keepVcs": final String keepVcs = entry.getValue(); if (!"true".equals(keepVcs) && !"false".equals(keepVcs)) { throw new ConflictException( format(PARAMETRIZED_ILLEGAL_PARAMETER_VALUE_MESSAGE, "source.project.parameters.keepVcs", entry.getValue())); } break; case "branch": case "commitId": case "keepDirectory": case "remoteOriginFetch": case "branchMerge": break; default: throw new ConflictException(format(PARAMETRIZED_INVALID_PARAMETER_MESSAGE, "source.project.parameters." + entry.getKey(), version)); } } } else { throw new ConflictException(format(PARAMETRIZED_ILLEGAL_PARAMETER_VALUE_MESSAGE, "source.project.type", source.getType())); } }  @Override void validate(ImportSourceDescriptor source, FactoryParameter.Version version);  }
@Test public void shouldBeAbleValidateGitSource() throws Exception { validator.validate(sourceDescriptor, FactoryParameter.Version.V2_0); }
@Test public void shouldBeAbleValidateESBWSO2Source() throws Exception { sourceDescriptor.setType("esbwso2"); validator.validate(sourceDescriptor, FactoryParameter.Version.V2_0); }
@Test(expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "The parameter .* has a value submitted .* with a value.*") public void shouldThrowExceptionIfTypeIsNotGit() throws Exception { validator.validate(sourceDescriptor.withType("zip"), FactoryParameter.Version.V2_0); }
@Test(expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "You have provided an invalid parameter .* for this version of Factory parameters.*") public void shouldThrowExceptionIfUnknownParameterIsUsed() throws Exception { sourceDescriptor.getParameters().put("other", "value"); validator.validate(sourceDescriptor, FactoryParameter.Version.V2_0); }
@Test(expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "The parameter .* has a value submitted .* with a value that is unexpected.*") public void shouldThrowExceptionIfKeepVcsIsNotTrueOrFalse() throws Exception { sourceDescriptor.getParameters().put("keepVcs", "qwerty"); validator.validate(sourceDescriptor, FactoryParameter.Version.V2_0); }