use of org.eclipse.che.api.workspace.server.devfile.DevfileParser in project devspaces-images by redhat-developer.
the class DefaultFactoryParameterResolverTest method shouldResolveRelativeFiles.
@Test
public void shouldResolveRelativeFiles() throws Exception {
// given
// we need to set up an "almost real" devfile converter which is a little bit involved
DevfileSchemaValidator validator = new DevfileSchemaValidator(new DevfileSchemaProvider(), new DevfileVersionDetector());
Map<String, ComponentIntegrityValidator> validators = new HashMap<>();
validators.put(EDITOR_COMPONENT_TYPE, new NoopComponentIntegrityValidator());
validators.put(PLUGIN_COMPONENT_TYPE, new NoopComponentIntegrityValidator());
validators.put(KUBERNETES_COMPONENT_TYPE, new NoopComponentIntegrityValidator());
validators.put(OPENSHIFT_COMPONENT_TYPE, new NoopComponentIntegrityValidator());
DevfileIntegrityValidator integrityValidator = new DevfileIntegrityValidator(validators);
DevfileParser devfileParser = new DevfileParser(validator, integrityValidator);
URLFactoryBuilder factoryBuilder = new URLFactoryBuilder("editor", "plugin", false, devfileParser, new DevfileVersionDetector());
DefaultFactoryParameterResolver res = new DefaultFactoryParameterResolver(factoryBuilder, urlFetcher);
// set up our factory with the location of our devfile that is referencing our localfile
Map<String, String> factoryParameters = new HashMap<>();
factoryParameters.put(URL_PARAMETER_NAME, "http://myloc.com/aa/bb/devfile");
doReturn(DEVFILE).when(urlFetcher).fetch(eq("http://myloc.com/aa/bb/devfile"));
doReturn("localfile").when(urlFetcher).fetch("http://myloc.com/aa/localfile");
// when
res.createFactory(factoryParameters);
// then
verify(urlFetcher).fetch(eq("http://myloc.com/aa/localfile"));
}
use of org.eclipse.che.api.workspace.server.devfile.DevfileParser in project devspaces-images by redhat-developer.
the class URLFactoryBuilderTest method testShouldReturnV2WithDevworkspacesDisabled.
@Test
public void testShouldReturnV2WithDevworkspacesDisabled() throws ApiException, DevfileException {
String myLocation = "http://foo-location/";
Map<String, Object> devfileAsMap = Map.of("hello", "there", "how", "are", "you", "?");
JsonNode devfile = new ObjectNode(JsonNodeFactory.instance);
when(devfileParser.parseYamlRaw(anyString())).thenReturn(devfile);
when(devfileParser.convertYamlToMap(devfile)).thenReturn(devfileAsMap);
when(devfileVersionDetector.devfileMajorVersion(devfile)).thenReturn(2);
URLFactoryBuilder localUrlFactoryBuilder = new URLFactoryBuilder(defaultEditor, defaultPlugin, false, devfileParser, devfileVersionDetector);
FactoryMetaDto factory = localUrlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(myLocation), s -> myLocation + ".list", emptyMap()).get();
assertNotNull(factory);
assertTrue(factory instanceof FactoryDevfileV2Dto);
assertEquals(((FactoryDevfileV2Dto) factory).getDevfile(), devfileAsMap);
}
use of org.eclipse.che.api.workspace.server.devfile.DevfileParser in project che-server by eclipse-che.
the class DefaultFactoryParameterResolverTest method shouldResolveRelativeFiles.
@Test
public void shouldResolveRelativeFiles() throws Exception {
// given
// we need to set up an "almost real" devfile converter which is a little bit involved
DevfileSchemaValidator validator = new DevfileSchemaValidator(new DevfileSchemaProvider(), new DevfileVersionDetector());
Map<String, ComponentIntegrityValidator> validators = new HashMap<>();
validators.put(EDITOR_COMPONENT_TYPE, new NoopComponentIntegrityValidator());
validators.put(PLUGIN_COMPONENT_TYPE, new NoopComponentIntegrityValidator());
validators.put(KUBERNETES_COMPONENT_TYPE, new NoopComponentIntegrityValidator());
validators.put(OPENSHIFT_COMPONENT_TYPE, new NoopComponentIntegrityValidator());
DevfileIntegrityValidator integrityValidator = new DevfileIntegrityValidator(validators);
DevfileParser devfileParser = new DevfileParser(validator, integrityValidator);
URLFactoryBuilder factoryBuilder = new URLFactoryBuilder("editor", "plugin", false, devfileParser, new DevfileVersionDetector());
DefaultFactoryParameterResolver res = new DefaultFactoryParameterResolver(factoryBuilder, urlFetcher);
// set up our factory with the location of our devfile that is referencing our localfile
Map<String, String> factoryParameters = new HashMap<>();
factoryParameters.put(URL_PARAMETER_NAME, "http://myloc.com/aa/bb/devfile");
doReturn(DEVFILE).when(urlFetcher).fetch(eq("http://myloc.com/aa/bb/devfile"));
doReturn("localfile").when(urlFetcher).fetch("http://myloc.com/aa/localfile");
// when
res.createFactory(factoryParameters);
// then
verify(urlFetcher).fetch(eq("http://myloc.com/aa/localfile"));
}
use of org.eclipse.che.api.workspace.server.devfile.DevfileParser in project che-server by eclipse-che.
the class URLFactoryBuilderTest method testShouldReturnV2WithDevworkspacesDisabled.
@Test
public void testShouldReturnV2WithDevworkspacesDisabled() throws ApiException, DevfileException {
String myLocation = "http://foo-location/";
Map<String, Object> devfileAsMap = Map.of("hello", "there", "how", "are", "you", "?");
JsonNode devfile = new ObjectNode(JsonNodeFactory.instance);
when(devfileParser.parseYamlRaw(anyString())).thenReturn(devfile);
when(devfileParser.convertYamlToMap(devfile)).thenReturn(devfileAsMap);
when(devfileVersionDetector.devfileMajorVersion(devfile)).thenReturn(2);
URLFactoryBuilder localUrlFactoryBuilder = new URLFactoryBuilder(defaultEditor, defaultPlugin, false, devfileParser, devfileVersionDetector);
FactoryMetaDto factory = localUrlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(myLocation), s -> myLocation + ".list", emptyMap()).get();
assertNotNull(factory);
assertTrue(factory instanceof FactoryDevfileV2Dto);
assertEquals(((FactoryDevfileV2Dto) factory).getDevfile(), devfileAsMap);
}
Aggregations