Search in sources :

Example 1 with DevfileVersionDetector

use of org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector in project che-server by eclipse-che.

the class DevfileSchemaValidatorTest method setUp.

@BeforeClass
public void setUp() {
    yamlMapper = new ObjectMapper(new YAMLFactory());
    schemaValidator = new DevfileSchemaValidator(new DevfileSchemaProvider(), new DevfileVersionDetector());
}
Also used : DevfileSchemaProvider(org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider) DevfileVersionDetector(org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with DevfileVersionDetector

use of org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector 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"));
}
Also used : HashMap(java.util.HashMap) DevfileVersionDetector(org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector) NoopComponentIntegrityValidator(org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator.NoopComponentIntegrityValidator) ComponentIntegrityValidator(org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator) DevfileSchemaProvider(org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider) DevfileParser(org.eclipse.che.api.workspace.server.devfile.DevfileParser) NoopComponentIntegrityValidator(org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator.NoopComponentIntegrityValidator) DevfileIntegrityValidator(org.eclipse.che.api.workspace.server.devfile.validator.DevfileIntegrityValidator) URLFactoryBuilder(org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder) DevfileSchemaValidator(org.eclipse.che.api.workspace.server.devfile.validator.DevfileSchemaValidator) Test(org.testng.annotations.Test)

Example 3 with DevfileVersionDetector

use of org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector 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);
}
Also used : UnknownScmProviderException(org.eclipse.che.api.factory.server.scm.exception.UnknownScmProviderException) Listeners(org.testng.annotations.Listeners) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) Test(org.testng.annotations.Test) Collections.singletonList(java.util.Collections.singletonList) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DevfileLocation(org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation) DevfileVersionDetector(org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector) FactoryMetaDto(org.eclipse.che.api.factory.shared.dto.FactoryMetaDto) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) MetadataImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.MetadataImpl) List(java.util.List) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Optional(java.util.Optional) FactoryDevfileV2Dto(org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KUBERNETES_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE) Assert.assertNull(org.testng.Assert.assertNull) DataProvider(org.testng.annotations.DataProvider) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) ScmCommunicationException(org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException) Mock(org.mockito.Mock) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) Assert.assertEquals(org.testng.Assert.assertEquals) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DevfileParser(org.eclipse.che.api.workspace.server.devfile.DevfileParser) ApiException(org.eclipse.che.api.core.ApiException) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) Collections.singletonMap(java.util.Collections.singletonMap) ExtendedError(org.eclipse.che.api.core.rest.shared.dto.ExtendedError) Collections.emptyMap(java.util.Collections.emptyMap) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) WORKSPACE_TOOLING_EDITOR_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) ScmUnauthorizedException(org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException) ServerException(org.eclipse.che.api.core.ServerException) OverrideParameterException(org.eclipse.che.api.workspace.server.devfile.exception.OverrideParameterException) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FactoryDevfileV2Dto(org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FactoryMetaDto(org.eclipse.che.api.factory.shared.dto.FactoryMetaDto) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 4 with DevfileVersionDetector

use of org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector 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"));
}
Also used : HashMap(java.util.HashMap) DevfileVersionDetector(org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector) NoopComponentIntegrityValidator(org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator.NoopComponentIntegrityValidator) ComponentIntegrityValidator(org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator) DevfileSchemaProvider(org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider) DevfileParser(org.eclipse.che.api.workspace.server.devfile.DevfileParser) NoopComponentIntegrityValidator(org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator.NoopComponentIntegrityValidator) DevfileIntegrityValidator(org.eclipse.che.api.workspace.server.devfile.validator.DevfileIntegrityValidator) URLFactoryBuilder(org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder) DevfileSchemaValidator(org.eclipse.che.api.workspace.server.devfile.validator.DevfileSchemaValidator) Test(org.testng.annotations.Test)

Example 5 with DevfileVersionDetector

use of org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector 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);
}
Also used : UnknownScmProviderException(org.eclipse.che.api.factory.server.scm.exception.UnknownScmProviderException) Listeners(org.testng.annotations.Listeners) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) Test(org.testng.annotations.Test) Collections.singletonList(java.util.Collections.singletonList) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) DevfileLocation(org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation) DevfileVersionDetector(org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector) FactoryMetaDto(org.eclipse.che.api.factory.shared.dto.FactoryMetaDto) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) MetadataImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.MetadataImpl) List(java.util.List) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Optional(java.util.Optional) FactoryDevfileV2Dto(org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto) RecipeImpl(org.eclipse.che.api.workspace.server.model.impl.RecipeImpl) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KUBERNETES_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.KUBERNETES_COMPONENT_TYPE) Assert.assertNull(org.testng.Assert.assertNull) DataProvider(org.testng.annotations.DataProvider) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) ScmCommunicationException(org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException) Mock(org.mockito.Mock) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) Assert.assertEquals(org.testng.Assert.assertEquals) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DevfileParser(org.eclipse.che.api.workspace.server.devfile.DevfileParser) ApiException(org.eclipse.che.api.core.ApiException) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) Collections.singletonMap(java.util.Collections.singletonMap) ExtendedError(org.eclipse.che.api.core.rest.shared.dto.ExtendedError) Collections.emptyMap(java.util.Collections.emptyMap) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) WORKSPACE_TOOLING_EDITOR_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) ScmUnauthorizedException(org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException) ServerException(org.eclipse.che.api.core.ServerException) OverrideParameterException(org.eclipse.che.api.workspace.server.devfile.exception.OverrideParameterException) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FactoryDevfileV2Dto(org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FactoryMetaDto(org.eclipse.che.api.factory.shared.dto.FactoryMetaDto) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Aggregations

DevfileVersionDetector (org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector)6 HashMap (java.util.HashMap)4 DevfileParser (org.eclipse.che.api.workspace.server.devfile.DevfileParser)4 DevfileSchemaProvider (org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider)4 Test (org.testng.annotations.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Collections.singletonList (java.util.Collections.singletonList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 ApiException (org.eclipse.che.api.core.ApiException)2 ServerException (org.eclipse.che.api.core.ServerException)2