Search in sources :

Example 1 with FileContentProvider

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

the class URLFactoryBuilderTest method checkThatDtoHasCorrectNames.

@Test(dataProvider = "devfiles")
public void checkThatDtoHasCorrectNames(DevfileImpl devfile, String expectedGenerateName) throws ApiException, IOException, OverrideParameterException, DevfileException {
    DefaultFactoryUrl defaultFactoryUrl = mock(DefaultFactoryUrl.class);
    FileContentProvider fileContentProvider = mock(FileContentProvider.class);
    when(defaultFactoryUrl.devfileFileLocations()).thenReturn(singletonList(new DevfileLocation() {

        @Override
        public Optional<String> filename() {
            return Optional.empty();
        }

        @Override
        public String location() {
            return "http://foo.bar/anything";
        }
    }));
    when(fileContentProvider.fetchContent(anyString())).thenReturn("anything");
    when(devfileParser.parseYamlRaw("anything")).thenReturn(new ObjectNode(JsonNodeFactory.instance));
    when(devfileParser.parseJsonNode(any(JsonNode.class), anyMap())).thenReturn(devfile);
    when(devfileVersionDetector.devfileMajorVersion(any(JsonNode.class))).thenReturn(1);
    FactoryDto factory = (FactoryDto) urlFactoryBuilder.createFactoryFromDevfile(defaultFactoryUrl, fileContentProvider, emptyMap()).get();
    assertNull(factory.getDevfile().getMetadata().getName());
    assertEquals(factory.getDevfile().getMetadata().getGenerateName(), expectedGenerateName);
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DevfileLocation(org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation) Test(org.testng.annotations.Test)

Example 2 with FileContentProvider

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

the class URLFactoryBuilderTest method checkCorrectExceptionThrownDependingOnCause.

@Test(dataProvider = "devfileExceptions")
public void checkCorrectExceptionThrownDependingOnCause(Throwable cause, Class expectedClass, String expectedMessage, Map<String, String> expectedAttributes) throws IOException, DevfileException {
    DefaultFactoryUrl defaultFactoryUrl = mock(DefaultFactoryUrl.class);
    FileContentProvider fileContentProvider = mock(FileContentProvider.class);
    when(defaultFactoryUrl.devfileFileLocations()).thenReturn(singletonList(new DevfileLocation() {

        @Override
        public Optional<String> filename() {
            return Optional.empty();
        }

        @Override
        public String location() {
            return "http://foo.bar/anything";
        }
    }));
    when(fileContentProvider.fetchContent(anyString())).thenThrow(new DevfileException("", cause));
    // when
    try {
        urlFactoryBuilder.createFactoryFromDevfile(defaultFactoryUrl, fileContentProvider, emptyMap());
    } catch (ApiException e) {
        assertTrue(e.getClass().isAssignableFrom(expectedClass));
        assertEquals(e.getMessage(), expectedMessage);
        if (e.getServiceError() instanceof ExtendedError)
            assertEquals(((ExtendedError) e.getServiceError()).getAttributes(), expectedAttributes);
    }
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) ExtendedError(org.eclipse.che.api.core.rest.shared.dto.ExtendedError) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) DevfileLocation(org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation) ApiException(org.eclipse.che.api.core.ApiException) Test(org.testng.annotations.Test)

Example 3 with FileContentProvider

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

the class DevfileConverterTest method shouldUseDevfileNameForWorkspaceNameDuringConvertingDevfileToWorkspaceConfig.

@Test
public void shouldUseDevfileNameForWorkspaceNameDuringConvertingDevfileToWorkspaceConfig() throws Exception {
    // given
    FileContentProvider fileContentProvider = mock(FileContentProvider.class);
    DevfileImpl devfile = newDevfile("petclinic");
    // when
    WorkspaceConfigImpl workspaceConfig = devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
    // then
    assertEquals(workspaceConfig.getName(), "petclinic");
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) Test(org.testng.annotations.Test)

Example 4 with FileContentProvider

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

the class DevfileConverterTest method shouldThrowAnExceptionIfDevfileApiVersionIsNotSupportedDuringConvertingDevfileToWorkspaceConfig.

@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Provided Devfile has unsupported version '1\\.0\\.0-non-supported'. The following versions are supported: .*")
public void shouldThrowAnExceptionIfDevfileApiVersionIsNotSupportedDuringConvertingDevfileToWorkspaceConfig() throws Exception {
    // given
    FileContentProvider fileContentProvider = mock(FileContentProvider.class);
    DevfileImpl devfile = new DevfileImpl();
    devfile.setApiVersion("1.0.0-non-supported");
    devfile.setName("petclinic");
    // when
    devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) Test(org.testng.annotations.Test)

Example 5 with FileContentProvider

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

the class DevfileConverterTest method shouldConvertCommandsDuringConvertingDevfileToWorkspaceConfig.

@Test
public void shouldConvertCommandsDuringConvertingDevfileToWorkspaceConfig() throws Exception {
    // given
    FileContentProvider fileContentProvider = mock(FileContentProvider.class);
    DevfileImpl devfile = newDevfile("petclinic");
    CommandImpl devfileCommand = mock(CommandImpl.class);
    devfile.getCommands().add(devfileCommand);
    org.eclipse.che.api.workspace.server.model.impl.CommandImpl workspaceCommand = mock(org.eclipse.che.api.workspace.server.model.impl.CommandImpl.class);
    when(commandConverter.toWorkspaceCommand(any(), any())).thenReturn(workspaceCommand);
    // when
    WorkspaceConfigImpl workspaceConfig = devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
    // then
    assertEquals(workspaceConfig.getCommands().size(), 1);
    assertSame(workspaceConfig.getCommands().get(0), workspaceCommand);
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) Test(org.testng.annotations.Test)

Aggregations

FileContentProvider (org.eclipse.che.api.workspace.server.devfile.FileContentProvider)38 Test (org.testng.annotations.Test)30 DevfileImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl)18 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)14 URLFetcher (org.eclipse.che.api.workspace.server.devfile.URLFetcher)10 DevfileException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)8 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)8 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)6 Inject (javax.inject.Inject)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Named (javax.inject.Named)4 DevfileLocation (org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation)4 EDITOR_COMPONENT_TYPE (org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE)4 ComponentFQNParser (org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentFQNParser)4 ExtendedPluginFQN (org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 String.format (java.lang.String.format)3 ComponentToWorkspaceApplier (org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier)3