use of org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation in project devspaces-images by redhat-developer.
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.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation in project devspaces-images by redhat-developer.
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.factory.server.urlfactory.RemoteFactoryUrl.DevfileLocation in project devspaces-images by redhat-developer.
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);
}
Aggregations