FileSender implements Serializable { public static <PRODUCER extends AbstractConfigProducer<?>> void sendUserConfiguredFiles(PRODUCER producer, Collection<? extends AbstractService> services, DeployLogger logger) { if (services.isEmpty()) return; UserConfigRepo userConfigs = producer.getUserConfigs(); Map<String, FileReference> sentFiles = new HashMap<>(); for (ConfigDefinitionKey key : userConfigs.configsProduced()) { ConfigPayloadBuilder builder = userConfigs.get(key); try { sendUserConfiguredFiles(builder, sentFiles, services, key, logger); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Unable to send files for " + key, e); } } }  static FileReference sendFileToServices(String relativePath,
                                                   Collection<? extends AbstractService> services); static FileReference sendUriToServices(String uri, Collection<? extends AbstractService> services); static void sendUserConfiguredFiles(PRODUCER producer, Collection<? extends AbstractService> services, DeployLogger logger);  }
@Test public void require_that_simple_file_fields_are_modified() { def.addFileDef("fileVal"); def.addStringDef("stringVal"); builder.setField("fileVal", "foo.txt"); builder.setField("stringVal", "foo.txt"); service.pathToRef.put("foo.txt", new FileNode("fooshash").value()); FileSender.sendUserConfiguredFiles(producer, serviceList, new BaseDeployLogger()); assertThat(builder.getObject("fileVal").getValue(), is("fooshash")); assertThat(builder.getObject("stringVal").getValue(), is("foo.txt")); }
@Test public void require_that_simple_path_fields_are_modified() { def.addPathDef("fileVal"); def.addStringDef("stringVal"); builder.setField("fileVal", "foo.txt"); builder.setField("stringVal", "foo.txt"); service.pathToRef.put("foo.txt", new FileNode("fooshash").value()); FileSender.sendUserConfiguredFiles(producer, serviceList, new BaseDeployLogger()); assertThat(builder.getObject("fileVal").getValue(), is("fooshash")); assertThat(builder.getObject("stringVal").getValue(), is("foo.txt")); }
@Test public void require_that_fields_in_inner_arrays_are_modified() { def.innerArrayDef("inner").addFileDef("fileVal"); def.innerArrayDef("inner").addStringDef("stringVal"); ConfigPayloadBuilder inner = builder.getArray("inner").append(); inner.setField("fileVal", "bar.txt"); inner.setField("stringVal", "bar.txt"); service.pathToRef.put("bar.txt", new FileNode("barhash").value()); FileSender.sendUserConfiguredFiles(producer, serviceList, new BaseDeployLogger()); assertThat(builder.getArray("inner").get(0).getObject("fileVal").getValue(), is("barhash")); assertThat(builder.getArray("inner").get(0).getObject("stringVal").getValue(), is("bar.txt")); }
@Test public void require_that_arrays_are_modified() { def.arrayDef("fileArray").setTypeSpec(new ConfigDefinition.TypeSpec("fileArray", "file", null, null, null, null)); def.arrayDef("pathArray").setTypeSpec(new ConfigDefinition.TypeSpec("pathArray", "path", null, null, null, null)); def.arrayDef("stringArray").setTypeSpec(new ConfigDefinition.TypeSpec("stringArray", "string", null, null, null, null)); builder.getArray("fileArray").append("foo.txt"); builder.getArray("fileArray").append("bar.txt"); builder.getArray("pathArray").append("path.txt"); builder.getArray("stringArray").append("foo.txt"); service.pathToRef.put("foo.txt", new FileNode("foohash").value()); service.pathToRef.put("bar.txt", new FileNode("barhash").value()); service.pathToRef.put("path.txt", new FileNode("pathhash").value()); FileSender.sendUserConfiguredFiles(producer, serviceList, new BaseDeployLogger()); assertThat(builder.getArray("fileArray").get(0).getValue(), is("foohash")); assertThat(builder.getArray("fileArray").get(1).getValue(), is("barhash")); assertThat(builder.getArray("pathArray").get(0).getValue(), is("pathhash")); assertThat(builder.getArray("stringArray").get(0).getValue(), is("foo.txt")); }
@Test public void require_that_structs_are_modified() { def.structDef("struct").addFileDef("fileVal"); def.structDef("struct").addStringDef("stringVal"); builder.getObject("struct").setField("fileVal", "foo.txt"); builder.getObject("struct").setField("stringVal", "foo.txt"); service.pathToRef.put("foo.txt", new FileNode("foohash").value()); FileSender.sendUserConfiguredFiles(producer, serviceList, new BaseDeployLogger()); assertThat(builder.getObject("struct").getObject("fileVal").getValue(), is("foohash")); assertThat(builder.getObject("struct").getObject("stringVal").getValue(), is("foo.txt")); }
@Test public void require_that_leaf_maps_are_modified() { def.leafMapDef("fileMap").setTypeSpec(new ConfigDefinition.TypeSpec("fileMap", "file", null, null, null, null)); def.leafMapDef("pathMap").setTypeSpec(new ConfigDefinition.TypeSpec("pathMap", "path", null, null, null, null)); def.leafMapDef("stringMap").setTypeSpec(new ConfigDefinition.TypeSpec("stringMap", "string", null, null, null, null)); builder.getMap("fileMap").put("foo", "foo.txt"); builder.getMap("fileMap").put("bar", "bar.txt"); builder.getMap("pathMap").put("path", "path.txt"); builder.getMap("stringMap").put("bar", "bar.txt"); service.pathToRef.put("foo.txt", new FileNode("foohash").value()); service.pathToRef.put("bar.txt", new FileNode("barhash").value()); service.pathToRef.put("path.txt", new FileNode("pathhash").value()); FileSender.sendUserConfiguredFiles(producer, serviceList, new BaseDeployLogger()); assertThat(builder.getMap("fileMap").get("foo").getValue(), is("foohash")); assertThat(builder.getMap("fileMap").get("bar").getValue(), is("barhash")); assertThat(builder.getMap("pathMap").get("path").getValue(), is("pathhash")); assertThat(builder.getMap("stringMap").get("bar").getValue(), is("bar.txt")); }
@Test public void require_that_fields_in_inner_maps_are_modified() { def.structMapDef("inner").addFileDef("fileVal"); def.structMapDef("inner").addStringDef("stringVal"); ConfigPayloadBuilder inner = builder.getMap("inner").put("foo"); inner.setField("fileVal", "bar.txt"); inner.setField("stringVal", "bar.txt"); service.pathToRef.put("bar.txt", new FileNode("barhash").value()); FileSender.sendUserConfiguredFiles(producer, serviceList, new BaseDeployLogger()); assertThat(builder.getMap("inner").get("foo").getObject("fileVal").getValue(), is("barhash")); assertThat(builder.getMap("inner").get("foo").getObject("stringVal").getValue(), is("bar.txt")); }
@Test(expected = IllegalArgumentException.class) public void require_that_null_files_are_not_sent() { def.addFileDef("fileVal"); service.pathToRef.put("foo.txt", new FileNode("fooshash").value()); FileSender.sendUserConfiguredFiles(producer, serviceList, new BaseDeployLogger()); }