use of org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto in project devspaces-images by redhat-developer.
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.factory.shared.dto.FactoryDevfileV2Dto 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.factory.shared.dto.FactoryDevfileV2Dto in project che-server by eclipse-che.
the class GitlabFactoryParametersResolverTest method shouldSetScmInfoIntoDevfileV2.
@Test
public void shouldSetScmInfoIntoDevfileV2() throws Exception {
String gitlabUrl = "http://gitlab.2mcl.com/eclipse/che/-/tree/foobar";
FactoryDevfileV2Dto computedFactory = generateDevfileV2Factory();
when(urlFactoryBuilder.createFactoryFromDevfile(any(RemoteFactoryUrl.class), any(), anyMap())).thenReturn(Optional.of(computedFactory));
Map<String, String> params = ImmutableMap.of(URL_PARAMETER_NAME, gitlabUrl);
// when
FactoryDevfileV2Dto factory = (FactoryDevfileV2Dto) gitlabFactoryParametersResolver.createFactory(params);
// then
ScmInfo scmInfo = factory.getScmInfo();
assertNotNull(scmInfo);
assertEquals(scmInfo.getScmProviderName(), "gitlab");
assertEquals(scmInfo.getRepositoryUrl(), "http://gitlab.2mcl.com/eclipse/che.git");
assertEquals(scmInfo.getBranch(), "foobar");
}
use of org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto 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);
}
use of org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto in project che-server by eclipse-che.
the class URLFactoryBuilderTest method testDevfileV2.
@Test
public void testDevfileV2() 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);
FactoryMetaDto factory = urlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(myLocation), s -> myLocation + ".list", emptyMap()).get();
assertNotNull(factory);
assertNull(factory.getSource());
assertTrue(factory instanceof FactoryDevfileV2Dto);
assertEquals(((FactoryDevfileV2Dto) factory).getDevfile(), devfileAsMap);
}
Aggregations