CreateIndexServiceImpl extends ComponentSupport implements CreateIndexService { @Nullable public Content buildIndexYaml(final Repository repository) { HelmContentFacet helmFacet = repository.facet(HelmContentFacet.class); ChartIndex index = new ChartIndex(); for (Asset asset : helmFacet.browseAssets()) { if (AssetKind.HELM_PACKAGE.toString().equals(asset.kind())) { parseAssetIntoChartEntry(index, asset); } } index.setApiVersion(API_VERSION); index.setGenerated(new DateTime()); return new Content(new StringPayload(yamlParser.getYamlContent(index), INDEX_YAML_CONTENT_TYPE)); } @Inject  CreateIndexServiceImpl(final YamlParser yamlParser); @Nullable Content buildIndexYaml(final Repository repository);  }
@Test public void testBuildIndexYaml() { List<FluentAsset> list = Arrays.asList(asset); when(asset.attributes()).thenReturn(formatAttributes); Map<String, String> shaMap = new HashMap<>(); shaMap.put("sha256", "12345"); when(assetBlob.checksums()).thenReturn(shaMap); when(helmFacet.browseAssets()).thenReturn(list); when(yamlParser.getYamlContent(anyObject())).thenReturn("index.yaml"); Content result = underTest.buildIndexYaml(repository); assertThat(result, is(notNullValue())); }
@Test public void testIndexYamlBuiltEvenWhenNoAssets() { when(assets.iterator()).thenReturn(assetIterator); when(assetIterator.next()).thenReturn(asset); when(helmFacet.browseAssets()).thenReturn(Collections.emptyList()); when(yamlParser.getYamlContent(anyObject())).thenReturn("index.yaml"); Content result = underTest.buildIndexYaml(repository); assertThat(result, is(notNullValue())); }