Search in sources :

Example 1 with URLFactoryBuilder

use of org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder 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 URLFactoryBuilder

use of org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder 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 URLFactoryBuilder

use of org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder in project devspaces-images by redhat-developer.

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 4 with URLFactoryBuilder

use of org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder in project devspaces-images by redhat-developer.

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 5 with URLFactoryBuilder

use of org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder in project devspaces-images by redhat-developer.

the class DefaultFactoryParameterResolverTest method shouldResolveRelativeFiles.

@Test
public void shouldResolveRelativeFiles() throws Exception {
    // given
    // we need to set up an "almost real" devfile converter which is a little bit involved
    DevfileSchemaValidator validator = new DevfileSchemaValidator(new DevfileSchemaProvider(), new DevfileVersionDetector());
    Map<String, ComponentIntegrityValidator> validators = new HashMap<>();
    validators.put(EDITOR_COMPONENT_TYPE, new NoopComponentIntegrityValidator());
    validators.put(PLUGIN_COMPONENT_TYPE, new NoopComponentIntegrityValidator());
    validators.put(KUBERNETES_COMPONENT_TYPE, new NoopComponentIntegrityValidator());
    validators.put(OPENSHIFT_COMPONENT_TYPE, new NoopComponentIntegrityValidator());
    DevfileIntegrityValidator integrityValidator = new DevfileIntegrityValidator(validators);
    DevfileParser devfileParser = new DevfileParser(validator, integrityValidator);
    URLFactoryBuilder factoryBuilder = new URLFactoryBuilder("editor", "plugin", false, devfileParser, new DevfileVersionDetector());
    DefaultFactoryParameterResolver res = new DefaultFactoryParameterResolver(factoryBuilder, urlFetcher);
    // set up our factory with the location of our devfile that is referencing our localfile
    Map<String, String> factoryParameters = new HashMap<>();
    factoryParameters.put(URL_PARAMETER_NAME, "http://myloc.com/aa/bb/devfile");
    doReturn(DEVFILE).when(urlFetcher).fetch(eq("http://myloc.com/aa/bb/devfile"));
    doReturn("localfile").when(urlFetcher).fetch("http://myloc.com/aa/localfile");
    // when
    res.createFactory(factoryParameters);
    // then
    verify(urlFetcher).fetch(eq("http://myloc.com/aa/localfile"));
}
Also used : HashMap(java.util.HashMap) DevfileVersionDetector(org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector) NoopComponentIntegrityValidator(org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator.NoopComponentIntegrityValidator) ComponentIntegrityValidator(org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator) DevfileSchemaProvider(org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider) DevfileParser(org.eclipse.che.api.workspace.server.devfile.DevfileParser) NoopComponentIntegrityValidator(org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator.NoopComponentIntegrityValidator) DevfileIntegrityValidator(org.eclipse.che.api.workspace.server.devfile.validator.DevfileIntegrityValidator) URLFactoryBuilder(org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder) DevfileSchemaValidator(org.eclipse.che.api.workspace.server.devfile.validator.DevfileSchemaValidator) Test(org.testng.annotations.Test)

Aggregations

HashMap (java.util.HashMap)6 URLFactoryBuilder (org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder)6 Test (org.testng.annotations.Test)6 URLFetcher (org.eclipse.che.api.workspace.server.devfile.URLFetcher)4 Map (java.util.Map)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2 RemoteFactoryUrl (org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl)2 DevfileParser (org.eclipse.che.api.workspace.server.devfile.DevfileParser)2 DevfileVersionDetector (org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector)2 URLFileContentProvider (org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider)2 DevfileSchemaProvider (org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider)2 ComponentIntegrityValidator (org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator)2 NoopComponentIntegrityValidator (org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator.NoopComponentIntegrityValidator)2 DevfileIntegrityValidator (org.eclipse.che.api.workspace.server.devfile.validator.DevfileIntegrityValidator)2 DevfileSchemaValidator (org.eclipse.che.api.workspace.server.devfile.validator.DevfileSchemaValidator)2