FactoryBuilder { public void checkValid(FactoryDto factory) throws ConflictException { checkValid(factory, false); } @Inject  FactoryBuilder(SourceStorageParametersValidator sourceStorageParametersValidator); FactoryDto build(Reader json); FactoryDto build(String json); FactoryDto build(InputStream json); void checkValid(FactoryDto factory); void checkValid(FactoryDto factory, boolean isUpdate); FactoryDto convertToLatest(FactoryDto factory);  }
@Test public void shouldBeAbleToValidateV4_0() throws Exception { factoryBuilder.checkValid(actual); verify(sourceProjectParametersValidator).validate(any(), eq(FactoryParameter.Version.V4_0)); }
@Test(expectedExceptions = ApiException.class) public void shouldNotValidateUnparseableFactory() throws Exception { factoryBuilder.checkValid(null); }
@Test( expectedExceptions = ApiException.class, dataProvider = "setByServerParamsProvider", expectedExceptionsMessageRegExp = "You have provided an invalid parameter .* for this version of Factory parameters.*") public void shouldNotAllowUsingParamsThatCanBeSetOnlyByServer(FactoryDto factory) throws Exception { factoryBuilder.checkValid(factory); }
@Test(dataProvider = "setByServerParamsProvider") public void shouldAllowUsingParamsThatCanBeSetOnlyByServerDuringUpdate(FactoryDto factory) throws Exception { factoryBuilder.checkValid(factory, true); }
@Test(expectedExceptions = ApiException.class, dataProvider = "notValidParamsProvider") public void shouldNotAllowUsingNotValidParams(FactoryDto factory) throws InvocationTargetException, IllegalAccessException, ApiException, NoSuchMethodException { factoryBuilder.checkValid(factory); }
@Test public void shouldBeAbleToValidateV4_0WithTrackedParamsWithoutAccountIdIfOnPremisesIsEnabled() throws Exception { factoryBuilder = new FactoryBuilder(sourceProjectParametersValidator); FactoryDto factory = prepareFactory() .withPolicies( dto.createDto(PoliciesDto.class) .withReferer("referrer") .withSince(123L) .withUntil(123L)); factoryBuilder.checkValid(factory); }
@Test( expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "You are missing a mandatory parameter \"workspace.projects\\[1\\].path\". .*") public void shouldThrowExceptionWithMessagePointingToMissingMandatoryParameter() throws Exception { factoryBuilder = new FactoryBuilder(sourceProjectParametersValidator); ProjectConfigDto project = dto.createDto(ProjectConfigDto.class) .withSource( dto.createDto(SourceStorageDto.class).withType("git").withLocation("location")) .withType("type") .withAttributes(singletonMap("key", singletonList("value"))) .withDescription("description") .withName("name") .withPath("/path"); ProjectConfigDto project2 = dto.createDto(ProjectConfigDto.class) .withSource( dto.createDto(SourceStorageDto.class).withType("git").withLocation("location")) .withType("") .withAttributes(singletonMap("key", singletonList("value"))) .withDescription("description") .withName("test") .withPath(""); FactoryDto factory = prepareFactory(); factory.getWorkspace().setProjects(asList(project, project2)); factoryBuilder.checkValid(factory); }