Search in sources :

Example 1 with Chainr

use of com.bazaarvoice.jolt.Chainr in project gocd by gocd.

the class MigrationTest method shouldTransformToNewMessageLayout.

@Test
public void shouldTransformToNewMessageLayout() {
    List chainrSpecJSON = JsonUtils.jsonToList("[\n" + " {\n" + "  \"operation\": \"shift\",\n" + "  \"spec\": {\n" + "   \"pipelines\": {\n" + "    \"@\": \"configuration.pipelines\"\n" + "   },\n" + "   \"environments\": {\n" + "    \"@\": \"configuration.environments\"\n" + "   }\n" + "  }\n" + " },\n" + " {\n" + "  \"operation\": \"default\",\n" + "  \"spec\": {\n" + "   \"warnings\": [\n" + "    \"migrated from V1\"\n" + "   ]\n" + "  }\n" + " }\n" + "]");
    Chainr chainr = Chainr.fromSpec(chainrSpecJSON);
    Object inputJSON = JsonUtils.jsonToMap("  {\n" + "    \"pipelines\": [\n" + "      {\n" + "        \"name\": \"firstpipe\",\n" + "        \"environment_variables\": [],\n" + "        \"group\": \"configrepo-example\",\n" + "        \"materials\": [\n" + "          {\n" + "            \"url\": \"https://github.com/tomzo/gocd-json-config-example.git\",\n" + "            \"type\": \"git\"\n" + "          }\n" + "        ],\n" + "        \"stages\": [\n" + "          {\n" + "            \"name\": \"build\",\n" + "            \"fetch_materials\": true,\n" + "            \"never_cleanup_artifacts\": false,\n" + "            \"clean_working_directory\": false,\n" + "            \"environment_variables\": [],\n" + "            \"jobs\": [\n" + "              {\n" + "                \"name\": \"build\",\n" + "                \"environment_variables\": [],\n" + "                \"tabs\": [],\n" + "                \"resources\": [],\n" + "                \"artifacts\": [],\n" + "                \"properties\": [],\n" + "                \"run_instance_count\": null,\n" + "                \"timeout\": 0,\n" + "                \"tasks\": [\n" + "                  {\n" + "                    \"type\": \"rake\"\n" + "                  }\n" + "                ]\n" + "              }\n" + "            ]\n" + "          }\n" + "        ]\n" + "      }\n" + "    ]\n" + "  }");
    Object transformedOutput = chainr.transform(inputJSON);
    String migratedMessage = JsonUtils.toJsonString(transformedOutput);
    PluginMessageV2 v2Message = new GsonCodec().getGson().fromJson(migratedMessage, PluginMessageV2.class);
    assertThat(v2Message.warnings.size(), is(1));
    assertThat(v2Message.configuration.pipelines.size(), is(1));
}
Also used : GsonCodec(com.thoughtworks.go.plugin.access.configrepo.codec.GsonCodec) List(java.util.List) ArrayList(java.util.ArrayList) Chainr(com.bazaarvoice.jolt.Chainr) Test(org.junit.Test)

Example 2 with Chainr

use of com.bazaarvoice.jolt.Chainr in project nifi by apache.

the class TestTransformFactory method testGetChainTransform.

@Test
public void testGetChainTransform() throws Exception {
    final String chainrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformFactory/chainrSpec.json")));
    JoltTransform transform = TransformFactory.getTransform(getClass().getClassLoader(), "jolt-transform-chain", JsonUtils.jsonToObject(chainrSpec));
    assertTrue(transform instanceof Chainr);
}
Also used : JoltTransform(com.bazaarvoice.jolt.JoltTransform) Chainr(com.bazaarvoice.jolt.Chainr) Test(org.junit.Test)

Example 3 with Chainr

use of com.bazaarvoice.jolt.Chainr in project gocd by gocd.

the class ConfigRepoMigrator method migrate.

public String migrate(String oldJSON, int targetVersion) {
    LOGGER.debug("Migrating to version {}: {}", targetVersion, oldJSON);
    Chainr transform = getTransformerFor(targetVersion);
    Object transformedObject = transform.transform(JsonUtils.jsonToMap(oldJSON), getContextMap(targetVersion));
    String transformedJSON = JsonUtils.toJsonString(transformedObject);
    LOGGER.debug("After migration to version {}: {}", targetVersion, transformedJSON);
    return transformedJSON;
}
Also used : Chainr(com.bazaarvoice.jolt.Chainr)

Aggregations

Chainr (com.bazaarvoice.jolt.Chainr)3 Test (org.junit.Test)2 JoltTransform (com.bazaarvoice.jolt.JoltTransform)1 GsonCodec (com.thoughtworks.go.plugin.access.configrepo.codec.GsonCodec)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1