use of org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto 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.factory.shared.dto.FactoryDevfileV2Dto 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.factory.shared.dto.FactoryDevfileV2Dto in project che-server by eclipse-che.
the class GithubFactoryParametersResolverTest method shouldSetScmInfoIntoDevfileV2.
@Test
public void shouldSetScmInfoIntoDevfileV2() throws Exception {
String githubUrl = "https://github.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, githubUrl);
// when
FactoryDevfileV2Dto factory = (FactoryDevfileV2Dto) githubFactoryParametersResolver.createFactory(params);
// then
ScmInfo scmInfo = factory.getScmInfo();
assertNotNull(scmInfo);
assertEquals(scmInfo.getScmProviderName(), "github");
assertEquals(scmInfo.getRepositoryUrl(), "https://github.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 FactoryLinksHelper method createLinks.
/**
* Creates factory links.
*
* @param serviceContext the context to retrieve factory service base URI
* @return list of factory links
*/
public static List<Link> createLinks(FactoryMetaDto factory, ServiceContext serviceContext, AdditionalFilenamesProvider additionalFilenamesProvider, String userName, String repositoryUrl) {
final List<Link> links = new LinkedList<>();
final UriBuilder uriBuilder = serviceContext.getServiceUriBuilder();
final String factoryId = factory.getId();
if (factoryId != null) {
// creation of link to retrieve factory
links.add(createLink(HttpMethod.GET, uriBuilder.clone().path(FactoryService.class, "getFactory").build(factoryId).toString(), null, APPLICATION_JSON, RETRIEVE_FACTORY_REL_ATT));
// creation of accept factory link
final Link createWorkspace = createLink(HttpMethod.GET, uriBuilder.clone().replacePath("f").queryParam("id", factoryId).build().toString(), null, TEXT_HTML, FACTORY_ACCEPTANCE_REL_ATT);
links.add(createWorkspace);
}
if (!isNullOrEmpty(factory.getName()) && !isNullOrEmpty(userName)) {
// creation of accept factory link by name and creator
final Link createWorkspaceFromNamedFactory = createLink(HttpMethod.GET, uriBuilder.clone().replacePath("f").queryParam("name", factory.getName()).queryParam("user", userName).build().toString(), null, TEXT_HTML, NAMED_FACTORY_ACCEPTANCE_REL_ATT);
links.add(createWorkspaceFromNamedFactory);
}
if (factory instanceof FactoryDevfileV2Dto) {
// link to devfile source
if (!isNullOrEmpty(factory.getSource())) {
links.add(createLink(HttpMethod.GET, uriBuilder.clone().replacePath("api").path(ScmService.class).path(ScmService.class, "resolveFile").queryParam("repository", repositoryUrl).queryParam("file", factory.getSource()).build(factoryId).toString(), factory.getSource() + " content"));
}
if (((FactoryDevfileV2Dto) factory).getScmInfo() != null) {
// additional files links
for (String additionalFile : additionalFilenamesProvider.get()) {
links.add(createLink(HttpMethod.GET, uriBuilder.clone().replacePath("api").path(ScmService.class).path(ScmService.class, "resolveFile").queryParam("repository", repositoryUrl).queryParam("file", additionalFile).build(factoryId).toString(), additionalFile + " content"));
}
}
}
return links;
}
use of org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto in project devspaces-images by redhat-developer.
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");
}
Aggregations