Search in sources :

Example 1 with URLFetcher

use of org.eclipse.che.api.workspace.server.devfile.URLFetcher in project che-server by eclipse-che.

the class DefaultFactoryParameterResolverTest method shouldFilterAndProvideOverrideParameters.

@Test
@SuppressWarnings("unchecked")
public void shouldFilterAndProvideOverrideParameters() throws Exception {
    URLFactoryBuilder urlFactoryBuilder = mock(URLFactoryBuilder.class);
    URLFetcher urlFetcher = mock(URLFetcher.class);
    DefaultFactoryParameterResolver res = new DefaultFactoryParameterResolver(urlFactoryBuilder, urlFetcher);
    Map<String, String> factoryParameters = new HashMap<>();
    factoryParameters.put(URL_PARAMETER_NAME, "http://myloc/devfile");
    factoryParameters.put("override.param.foo", "bar");
    factoryParameters.put("override.param.bar", "foo");
    factoryParameters.put("ignored.non-override.property", "baz");
    ArgumentCaptor<Map<String, String>> captor = ArgumentCaptor.forClass(Map.class);
    // when
    res.createFactory(factoryParameters);
    verify(urlFactoryBuilder).createFactoryFromDevfile(any(RemoteFactoryUrl.class), any(URLFileContentProvider.class), captor.capture());
    Map<String, String> filteredOverrides = captor.getValue();
    assertEquals(2, filteredOverrides.size());
    assertEquals("bar", filteredOverrides.get("param.foo"));
    assertEquals("foo", filteredOverrides.get("param.bar"));
    assertFalse(filteredOverrides.containsKey("ignored.non-override.property"));
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) URLFactoryBuilder(org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) RemoteFactoryUrl(org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl) URLFileContentProvider(org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider) Test(org.testng.annotations.Test)

Example 2 with URLFetcher

use of org.eclipse.che.api.workspace.server.devfile.URLFetcher in project che-server by eclipse-che.

the class DefaultFactoryParameterResolverTest method shouldThrowExceptionOnInvalidURL.

@Test(dataProvider = "invalidURLsProvider")
public void shouldThrowExceptionOnInvalidURL(String url, String message) throws Exception {
    URLFactoryBuilder urlFactoryBuilder = mock(URLFactoryBuilder.class);
    URLFetcher urlFetcher = mock(URLFetcher.class);
    DefaultFactoryParameterResolver res = new DefaultFactoryParameterResolver(urlFactoryBuilder, urlFetcher);
    Map<String, String> factoryParameters = new HashMap<>();
    factoryParameters.put(URL_PARAMETER_NAME, url);
    // when
    try {
        res.createFactory(factoryParameters);
        fail("Exception is expected");
    } catch (BadRequestException e) {
        assertEquals(e.getMessage(), format("Unable to process provided factory URL. Please check its validity and try again. Parser message: %s", message));
    }
}
Also used : HashMap(java.util.HashMap) BadRequestException(org.eclipse.che.api.core.BadRequestException) URLFactoryBuilder(org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) Test(org.testng.annotations.Test)

Example 3 with URLFetcher

use of org.eclipse.che.api.workspace.server.devfile.URLFetcher in project che-server by eclipse-che.

the class GithubAuthorizingFileContentProviderTest method shouldThrowNotFoundForPublicRepos.

@Test(expectedExceptions = FileNotFoundException.class)
public void shouldThrowNotFoundForPublicRepos() throws Exception {
    URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
    String url = "https://raw.githubusercontent.com/foo/bar/devfile.yaml";
    when(urlFetcher.fetch(eq(url))).thenThrow(FileNotFoundException.class);
    when(urlFetcher.fetch(eq("https://api.github.com/repos/eclipse/che"))).thenReturn("OK");
    GithubUrl githubUrl = new GithubUrl().withUsername("eclipse").withRepository("che");
    FileContentProvider fileContentProvider = new GithubAuthorizingFileContentProvider(githubUrl, urlFetcher, gitCredentialManager, personalAccessTokenManager);
    fileContentProvider.fetchContent(url);
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) Test(org.testng.annotations.Test)

Example 4 with URLFetcher

use of org.eclipse.che.api.workspace.server.devfile.URLFetcher in project che-server by eclipse-che.

the class GitlabAuthorizingFileContentProviderTest method shouldExpandRelativePaths.

@Test
public void shouldExpandRelativePaths() throws Exception {
    URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
    GitlabUrl gitlabUrl = new GitlabUrl().withHostName("https://gitlab.net").withUsername("eclipse").withProject("che");
    FileContentProvider fileContentProvider = new GitlabAuthorizingFileContentProvider(gitlabUrl, urlFetcher, gitCredentialsManager, personalAccessTokenManager);
    fileContentProvider.fetchContent("devfile.yaml");
    verify(urlFetcher).fetch(eq("https://gitlab.net/api/v4/projects/eclipse%2Fche/repository/files/devfile.yaml/raw"));
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) Test(org.testng.annotations.Test)

Example 5 with URLFetcher

use of org.eclipse.che.api.workspace.server.devfile.URLFetcher in project devspaces-images by redhat-developer.

the class GithubAuthorizingFileContentProviderTest method shouldPreserveAbsolutePaths.

@Test
public void shouldPreserveAbsolutePaths() throws Exception {
    URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
    GithubUrl githubUrl = new GithubUrl().withUsername("eclipse").withRepository("che");
    FileContentProvider fileContentProvider = new GithubAuthorizingFileContentProvider(githubUrl, urlFetcher, gitCredentialManager, personalAccessTokenManager);
    String url = "https://raw.githubusercontent.com/foo/bar/devfile.yaml";
    fileContentProvider.fetchContent(url);
    verify(urlFetcher).fetch(eq(url));
}
Also used : FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) URLFetcher(org.eclipse.che.api.workspace.server.devfile.URLFetcher) Test(org.testng.annotations.Test)

Aggregations

URLFetcher (org.eclipse.che.api.workspace.server.devfile.URLFetcher)14 Test (org.testng.annotations.Test)14 FileContentProvider (org.eclipse.che.api.workspace.server.devfile.FileContentProvider)10 HashMap (java.util.HashMap)4 URLFactoryBuilder (org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder)4 Map (java.util.Map)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2 RemoteFactoryUrl (org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl)2 URLFileContentProvider (org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider)2