Search in sources :

Example 1 with GsonCodec

use of com.thoughtworks.go.plugin.access.configrepo.codec.GsonCodec 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 GsonCodec

use of com.thoughtworks.go.plugin.access.configrepo.codec.GsonCodec in project gocd by gocd.

the class CRBaseTest method SetUp.

@Before
public void SetUp() {
    GsonBuilder builder = new GsonBuilder();
    if (printExamples)
        builder.setPrettyPrinting();
    GsonCodec codec = new GsonCodec(builder);
    gson = codec.getGson();
}
Also used : GsonCodec(com.thoughtworks.go.plugin.access.configrepo.codec.GsonCodec) Before(org.junit.Before)

Aggregations

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