DevfileParser { public void resolveReference(DevfileImpl devfile, FileContentProvider fileContentProvider) throws DevfileException { List<ComponentImpl> toResolve = devfile .getComponents() .stream() .filter( c -> c.getType().equals(KUBERNETES_COMPONENT_TYPE) || c.getType().equals(OPENSHIFT_COMPONENT_TYPE)) .filter(c -> !isNullOrEmpty(c.getReference())) .collect(Collectors.toList()); for (ComponentImpl c : toResolve) { try { c.setReferenceContent(fileContentProvider.fetchContent(c.getReference())); } catch (IOException e) { throw new DevfileException( format( "Unable to resolve reference of component: %s", firstNonNull(c.getAlias(), c.getReference())), e); } } } @Inject  DevfileParser(
      DevfileSchemaValidator schemaValidator, DevfileIntegrityValidator integrityValidator); @VisibleForTesting  DevfileParser(
      DevfileSchemaValidator schemaValidator,
      DevfileIntegrityValidator integrityValidator,
      ObjectMapper yamlMapper,
      ObjectMapper jsonMapper); DevfileImpl parseYaml(String devfileContent); DevfileImpl parseYaml(String devfileContent, Map<String, String> overrideProperties); DevfileImpl parseJson(String devfileContent); DevfileImpl parseJson(String devfileContent, Map<String, String> overrideProperties); void resolveReference(DevfileImpl devfile, FileContentProvider fileContentProvider);  }
@Test public void shouldResolveReferencesIntoReferenceContentForFactories() throws Exception { String referenceContent = "my_content_yaml_v3"; when(contentProvider.fetchContent(anyString())).thenReturn(referenceContent); ComponentImpl component = new ComponentImpl(); component.setType(KUBERNETES_COMPONENT_TYPE); component.setReference("myfile.yaml"); devfile.getComponents().add(component); devfileParser.resolveReference(devfile, contentProvider); verify(contentProvider).fetchContent(eq("myfile.yaml")); assertEquals(devfile.getComponents().get(0).getReferenceContent(), referenceContent); }
@Test( expectedExceptions = DevfileException.class, expectedExceptionsMessageRegExp = "Unable to resolve reference of component: test") public void shouldThrowDevfileExceptionWhenReferenceIsNotResolvable() throws Exception { when(contentProvider.fetchContent(anyString())).thenThrow(IOException.class); ComponentImpl component = new ComponentImpl(); component.setType(KUBERNETES_COMPONENT_TYPE); component.setAlias("test"); component.setReference("myfile.yaml"); devfile.getComponents().add(component); devfileParser.resolveReference(devfile, contentProvider); }