DevfileParser { public DevfileImpl parseYaml(String devfileContent) throws DevfileFormatException { try { return parse(devfileContent, yamlMapper, emptyMap()); } catch (OverrideParameterException e) { throw new RuntimeException(e.getMessage()); } } @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 testValidateAndParse() throws Exception { DevfileImpl parsed = devfileParser.parseYaml(DEVFILE_YAML_CONTENT); assertEquals(parsed, devfile); verify(yamlMapper).treeToValue(devfileJsonNode, DevfileImpl.class); verify(schemaValidator).validate(eq(devfileJsonNode)); verify(integrityValidator).validateDevfile(devfile); }
@Test public void testInitializingDevfileMapsAfterParsing() throws Exception { CommandImpl command = new CommandImpl(); command.getActions().add(new ActionImpl()); devfile.getCommands().add(command); ComponentImpl component = new ComponentImpl(); component.getEndpoints().add(new EndpointImpl()); devfile.getComponents().add(component); DevfileImpl parsed = devfileParser.parseYaml(DEVFILE_YAML_CONTENT); assertNotNull(parsed.getCommands().get(0).getAttributes()); assertNotNull(parsed.getComponents().get(0).getSelector()); assertNotNull(parsed.getComponents().get(0).getEndpoints().get(0).getAttributes()); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "non valid") public void shouldThrowExceptionWhenExceptionOccurredDuringSchemaValidation() throws Exception { doThrow(new DevfileFormatException("non valid")).when(schemaValidator).validate(any()); devfileParser.parseYaml(DEVFILE_YAML_CONTENT); }