use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class URLFactoryBuilderTest method testDevfileV2WithFilename.
@Test
public void testDevfileV2WithFilename() 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);
RemoteFactoryUrl githubLikeRemoteUrl = new RemoteFactoryUrl() {
@Override
public String getProviderName() {
return null;
}
@Override
public List<DevfileLocation> devfileFileLocations() {
return Collections.singletonList(new DevfileLocation() {
@Override
public Optional<String> filename() {
return Optional.of("devfile.yaml");
}
@Override
public String location() {
return myLocation;
}
});
}
@Override
public String rawFileLocation(String filename) {
return null;
}
@Override
public String getHostName() {
return null;
}
@Override
public String getBranch() {
return null;
}
@Override
public void setDevfileFilename(String devfileName) {
}
};
FactoryMetaDto factory = urlFactoryBuilder.createFactoryFromDevfile(githubLikeRemoteUrl, s -> myLocation + ".list", emptyMap()).get();
assertNotNull(factory);
assertEquals(factory.getSource(), "devfile.yaml");
assertTrue(factory instanceof FactoryDevfileV2Dto);
assertEquals(((FactoryDevfileV2Dto) factory).getDevfile(), devfileAsMap);
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class URLFactoryBuilderTest method testDevfileSpecifyingFilename.
@Test
public void testDevfileSpecifyingFilename() 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);
RemoteFactoryUrl githubLikeRemoteUrl = new RemoteFactoryUrl() {
private String devfileName = "default-devfile.yaml";
@Override
public String getProviderName() {
return null;
}
@Override
public List<DevfileLocation> devfileFileLocations() {
return Collections.singletonList(new DevfileLocation() {
@Override
public Optional<String> filename() {
return Optional.of(devfileName);
}
@Override
public String location() {
return myLocation;
}
});
}
@Override
public String rawFileLocation(String filename) {
return null;
}
@Override
public String getHostName() {
return null;
}
@Override
public String getBranch() {
return null;
}
@Override
public void setDevfileFilename(String devfileName) {
this.devfileName = devfileName;
}
};
String pathToDevfile = "my-custom-devfile-path.yaml";
Map<String, String> propertiesMap = singletonMap(URLFactoryBuilder.DEVFILE_FILENAME, pathToDevfile);
FactoryMetaDto factory = urlFactoryBuilder.createFactoryFromDevfile(githubLikeRemoteUrl, s -> myLocation + ".list", propertiesMap).get();
assertNotNull(factory);
// Check that we didn't fetch from default files but from the parameter
assertEquals(factory.getSource(), pathToDevfile);
assertTrue(factory instanceof FactoryDevfileV2Dto);
assertEquals(((FactoryDevfileV2Dto) factory).getDevfile(), devfileAsMap);
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException 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.exception.DevfileException in project che-server by eclipse-che.
the class DevfileToApiExceptionMapperTest method shouldReturnServerExceptionWhenCauseIsUnknownProvider.
@Test
public void shouldReturnServerExceptionWhenCauseIsUnknownProvider() {
UnknownScmProviderException scmProviderException = new UnknownScmProviderException("unknown", "http://gitlab.com/oauth/authenticate");
ApiException exception = DevfileToApiExceptionMapper.toApiException(new DevfileException("text", scmProviderException));
assertTrue(exception instanceof ServerException);
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplier method provisionVolumes.
private void provisionVolumes(ComponentImpl component, Container container, MachineConfigImpl config) throws DevfileException {
for (org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl componentVolume : component.getVolumes()) {
Optional<VolumeMount> sameNameMount = container.getVolumeMounts().stream().filter(vm -> vm.getName().equals(componentVolume.getName())).findFirst();
if (sameNameMount.isPresent() && sameNameMount.get().getMountPath().equals(componentVolume.getContainerPath())) {
continue;
} else if (sameNameMount.isPresent()) {
throw new DevfileException(format("Conflicting volume with same name ('%s') but different path ('%s') found for component '%s' and its container '%s'.", componentVolume.getName(), componentVolume.getContainerPath(), getIdentifiableComponentName(component), container.getName()));
}
if (container.getVolumeMounts().stream().anyMatch(vm -> vm.getMountPath().equals(componentVolume.getContainerPath()))) {
throw new DevfileException(format("Conflicting volume with same path ('%s') but different name ('%s') found for component '%s' and its container '%s'.", componentVolume.getContainerPath(), componentVolume.getName(), getIdentifiableComponentName(component), container.getName()));
}
config.getVolumes().put(componentVolume.getName(), new VolumeImpl().withPath(componentVolume.getContainerPath()));
}
}
Aggregations