@Test public void testSplitYamlWithSingleYaml() { String yamlInput = sampleYamlDefinition; List<String> expectedOutput = new ArrayList<>(); expectedOutput.add(sampleYamlDefinition); List<String> actualOutput = YamlMapper.splitYaml(yamlInput); assertEquals(1, actualOutput.size()); assertEquals(expectedOutput.get(0), actualOutput.get(0)); }
@Test public void testSplitYamlWithMultipleYamls() { String yamlInput = sampleYamlDefinition + "\n" + sampleYamlDefinition; List<String> expectedOutput = new ArrayList<>(); expectedOutput.add(sampleYamlDefinition); expectedOutput.add(sampleYamlDefinition); List<String> actualOutput = YamlMapper.splitYaml(yamlInput); assertEquals(2, actualOutput.size()); assertEquals(expectedOutput.get(0), actualOutput.get(0)); assertEquals(expectedOutput.get(1), actualOutput.get(1)); }
@Test public void testSplitYamlWithComments() { String yamlInput = "# comment 1 \n" + "#comment 2 \n" + sampleYamlDefinition + " # comment 3\n" + sampleYamlDefinition; List<String> expectedOutput = new ArrayList<>(); expectedOutput.add(sampleYamlDefinition); expectedOutput.add(sampleYamlDefinition); List<String> actualOutput = YamlMapper.splitYaml(yamlInput); assertEquals(2, actualOutput.size()); assertEquals(expectedOutput.get(0), actualOutput.get(0)); assertEquals(expectedOutput.get(1), actualOutput.get(1)); }
@Override public void handlePost(Operation post) { if (!post.hasBody()) { post.fail(new LocalizableValidationException("body is required", "compute.body" + ".required")); return; } List<String> kubernetesDefinitions = splitYaml(post.getBody(String.class)); OperationJoin.create(createOperations(kubernetesDefinitions)) .setCompletion((ops, errors) -> { List<String> resourceLinks = new ArrayList<>(); ops.values().forEach(o -> { if (o == null) { return; } KubernetesDescription desc = o.getBody(KubernetesDescription.class); if (!isNullOrEmpty(desc.documentSelfLink)) { resourceLinks.add(desc.documentSelfLink); } }); if (errors != null) { errors.values().forEach(e -> logWarning("Failed to create " + "KubernetesDescription: %s", Utils.toString(e))); cleanKubernetesDescriptionsAndFail(resourceLinks, errors, post); } else { post.setBody(resourceLinks); post.complete(); } }).sendWith(this); }
boolean isMultiYaml = YamlMapper.isMultiYaml(yaml); if (isMultiYaml) { List<String> yamls = YamlMapper.splitYaml(yaml);
assertNotNull(rs.resourceLinks); long numberOfDeployments = YamlMapper.splitYaml(template).stream() .filter(entity -> entity.contains(KubernetesUtil.DEPLOYMENT_TYPE)) .count();