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);
}
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);
}
}
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");
}
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);
}
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);
}
Aggregations