use of org.eclipse.che.api.factory.shared.dto.FactoryMetaDto 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.FactoryMetaDto 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.FactoryMetaDto in project devspaces-images by redhat-developer.
the class FactoryService method resolveFactory.
@POST
@Path("/resolver")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Operation(summary = "Create factory by providing map of parameters. Get JSON with factory information", responses = { @ApiResponse(responseCode = "200", description = "Factory successfully built from parameters"), @ApiResponse(responseCode = "400", description = "Missed required parameters, failed to validate factory"), @ApiResponse(responseCode = "500", description = "Internal server error") })
public FactoryMetaDto resolveFactory(@Parameter(description = "Parameters provided to create factories") Map<String, String> parameters, @Parameter(description = "Whether or not to validate values like it is done when accepting a Factory") @DefaultValue("false") @QueryParam(VALIDATE_QUERY_PARAMETER) Boolean validate) throws ApiException {
// check parameter
requiredNotNull(parameters, "Factory build parameters");
// search matching resolver and create factory from matching resolver
FactoryMetaDto resolvedFactory = factoryParametersResolverHolder.getFactoryParametersResolver(parameters).createFactory(parameters);
if (resolvedFactory == null) {
throw new BadRequestException(FACTORY_NOT_RESOLVABLE);
}
if (validate) {
acceptValidator.validateOnAccept(resolvedFactory);
}
resolvedFactory = injectLinks(resolvedFactory, parameters);
return resolvedFactory;
}
use of org.eclipse.che.api.factory.shared.dto.FactoryMetaDto 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.FactoryMetaDto 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);
}
Aggregations