FactoryBuilder { public Factory convertToLatest(Factory factory) throws ApiException { Factory resultFactory = DtoFactory.getInstance().clone(factory); resultFactory.setV("2.1"); for (LegacyConverter converter : LEGACY_CONVERTERS) { converter.convert(resultFactory); } return resultFactory; } @Inject  FactoryBuilder(SourceProjectParametersValidator sourceProjectParametersValidator); Factory buildEncoded(Reader json); Factory buildEncoded(String json); Factory buildEncoded(InputStream json); void checkValid(Factory factory); Factory convertToLatest(Factory factory);  }
@Test public void shouldBeAbleToConvert2_0ActionsToNewFormat2_1() throws ApiException { Factory given = dto.createDto(Factory.class).withV("2.0") .withSource(dto.createDto(Source.class) .withProject(dto.createDto(ImportSourceDescriptor.class) .withType("git") .withLocation("location") .withParameters(singletonMap("key", "value"))) .withRunners(singletonMap("runEnv", dto.createDto(RunnerSource.class) .withLocation("location") .withParameters(singletonMap("key", "value"))))) .withProject(dto.createDto(NewProject.class) .withType("type") .withAttributes(singletonMap("key", singletonList("value"))) .withBuilders(dto.createDto(BuildersDescriptor.class).withDefault("default")) .withDescription("description") .withName("name") .withVisibility("private") .withRunners(dto.createDto(RunnersDescriptor.class) .withDefault("default") .withConfigs( singletonMap("key", dto.createDto(RunnerConfiguration.class) .withRam(768) .withOptions(singletonMap("key", "value")) .withVariables(singletonMap("key", "value")))))) .withCreator(dto.createDto(Author.class) .withAccountId("accountId") .withEmail("email") .withName("name")) .withPolicies(dto.createDto(Policies.class) .withRefererHostname("referrer") .withValidSince(123L) .withValidUntil(123L)) .withActions(dto.createDto(Actions.class) .withFindReplace(singletonList(dto.createDto(ReplacementSet.class) .withFiles(singletonList("file")) .withEntries(singletonList( dto.createDto(Variable.class) .withFind("find") .withReplace("replace") .withReplacemode("mode"))))) .withOpenFile("openFile") .withWarnOnClose(true) .withWelcome(dto.createDto(WelcomePage.class) .withAuthenticated(dto.createDto(WelcomeConfiguration.class) .withContenturl("url") .withNotification("notification") .withTitle("title")) .withNonauthenticated(dto.createDto(WelcomeConfiguration.class) .withContenturl("url") .withNotification("notification") .withTitle("title")))); expected.withV("2.1") .withSource(dto.createDto(Source.class) .withProject(dto.createDto(ImportSourceDescriptor.class) .withType("git") .withLocation("location") .withParameters(singletonMap("key", "value"))) .withRunners(singletonMap("runEnv", dto.createDto(RunnerSource.class) .withLocation("location") .withParameters( singletonMap("key", "value"))))) .withProject(dto.createDto(NewProject.class) .withType("type") .withAttributes(singletonMap("key", singletonList("value"))) .withBuilders(dto.createDto(BuildersDescriptor.class).withDefault("default")) .withDescription("description") .withName("name") .withRunners(dto.createDto(RunnersDescriptor.class) .withDefault("default") .withConfigs(singletonMap("key", dto.createDto(RunnerConfiguration.class) .withRam(768) .withOptions(singletonMap("key", "value")) .withVariables(singletonMap("key", "value"))))) .withVisibility("private")) .withCreator(dto.createDto(Author.class) .withAccountId("accountId") .withEmail("email") .withName("name")) .withPolicies(dto.createDto(Policies.class) .withRefererHostname("referrer") .withValidSince(123L) .withValidUntil(123L)) .withIde(dto.createDto(Ide.class) .withOnAppLoaded(dto.createDto(OnAppLoaded.class) .withActions(singletonList(dto.createDto(Action.class) .withId("openWelcomePage") .withProperties(ImmutableMap.<String, String>builder() .put("authenticatedTitle", "title") .put("authenticatedContentUrl", "url") .put("authenticatedNotification", "notification") .put("nonAuthenticatedTitle", "title") .put("nonAuthenticatedContentUrl", "url") .put("nonAuthenticatedNotification", "notification") .build())))) .withOnAppClosed( dto.createDto(OnAppClosed.class) .withActions( singletonList(dto.createDto(Action.class).withId("warnOnClose")))) .withOnProjectOpened(dto.createDto(OnProjectOpened.class) .withActions(Arrays.asList( dto.createDto(Action.class) .withId("openFile") .withProperties(singletonMap("file", "openFile")), dto.createDto(Action.class) .withId("findReplace") .withProperties(ImmutableMap.of("in", "file", "find", "find", "replace", "replace", "replaceMode", "mode" )))))); assertEquals(factoryBuilder.convertToLatest(given), expected); }