Search in sources :

Example 1 with FetcherEntity

use of io.gravitee.rest.api.model.FetcherEntity in project gravitee-management-rest-api by gravitee-io.

the class FetchersResourceTest method shouldGetFetcherWithUnknownExpand.

@Test
public void shouldGetFetcherWithUnknownExpand() {
    Mockito.reset(fetcherService);
    FetcherEntity fetcherEntity = new FetcherEntity();
    fetcherEntity.setId("my-id");
    when(fetcherService.findAll(false)).thenReturn(Collections.singleton(fetcherEntity));
    when(fetcherService.getSchema(anyString())).thenReturn("my-schema");
    final Response response = envTarget().queryParam("expand", "unknown").request().get();
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(HttpStatusCode.OK_200);
    Set set = response.readEntity(Set.class);
    assertThat(set).isNotEmpty();
    assertThat(set).hasSize(1);
    Object o = set.iterator().next();
    assertThat(o).isNotNull();
    assertThat(o).isInstanceOf(LinkedHashMap.class);
    LinkedHashMap<String, String> elt = (LinkedHashMap<String, String>) o;
    assertThat(elt).hasSize(1);
    assertThat(elt.get("id")).isEqualTo("my-id");
    verify(fetcherService, times(1)).findAll(false);
    verify(fetcherService, times(0)).getSchema(anyString());
}
Also used : Response(javax.ws.rs.core.Response) Set(java.util.Set) FetcherEntity(io.gravitee.rest.api.model.FetcherEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 2 with FetcherEntity

use of io.gravitee.rest.api.model.FetcherEntity in project gravitee-management-rest-api by gravitee-io.

the class FetchersResourceTest method shouldGetFetcherWithoutSchema.

@Test
public void shouldGetFetcherWithoutSchema() {
    Mockito.reset(fetcherService);
    FetcherEntity fetcherEntity = new FetcherEntity();
    fetcherEntity.setId("my-id");
    when(fetcherService.findAll(false)).thenReturn(Collections.singleton(fetcherEntity));
    when(fetcherService.getSchema(anyString())).thenReturn("schema");
    final Response response = envTarget().request().get();
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(HttpStatusCode.OK_200);
    Set set = response.readEntity(Set.class);
    assertThat(set).isNotEmpty();
    assertThat(set).hasSize(1);
    Object o = set.iterator().next();
    assertThat(o).isNotNull();
    assertThat(o).isInstanceOf(LinkedHashMap.class);
    LinkedHashMap<String, String> elt = (LinkedHashMap<String, String>) o;
    assertThat(elt).hasSize(1);
    assertThat(elt.get("id")).isEqualTo("my-id");
    verify(fetcherService, times(1)).findAll(false);
    verify(fetcherService, times(0)).getSchema(anyString());
}
Also used : Response(javax.ws.rs.core.Response) Set(java.util.Set) FetcherEntity(io.gravitee.rest.api.model.FetcherEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 3 with FetcherEntity

use of io.gravitee.rest.api.model.FetcherEntity in project gravitee-management-rest-api by gravitee-io.

the class FetcherResourceTest method shouldGetFetcherWithoutSchema.

@Test
public void shouldGetFetcherWithoutSchema() {
    Mockito.reset(fetcherService);
    FetcherEntity fetcherEntity = new FetcherEntity();
    fetcherEntity.setId("my-id");
    when(fetcherService.findById("my-id")).thenReturn(fetcherEntity);
    when(fetcherService.getSchema(anyString())).thenReturn("schema");
    final Response response = envTarget().request().get();
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(HttpStatusCode.OK_200);
    Object o = response.readEntity(Object.class);
    assertThat(o).isNotNull();
    assertThat(o).isInstanceOf(LinkedHashMap.class);
    LinkedHashMap<String, String> elt = (LinkedHashMap<String, String>) o;
    assertThat(elt).hasSize(1);
    assertThat(elt.get("id")).isEqualTo("my-id");
    verify(fetcherService, times(1)).findById("my-id");
    verify(fetcherService, times(0)).getSchema(anyString());
}
Also used : Response(javax.ws.rs.core.Response) FetcherEntity(io.gravitee.rest.api.model.FetcherEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 4 with FetcherEntity

use of io.gravitee.rest.api.model.FetcherEntity in project gravitee-management-rest-api by gravitee-io.

the class FetcherServiceImpl method convert.

private FetcherEntity convert(FetcherPlugin fetcherPlugin, boolean withPlugin) {
    FetcherEntity entity = new FetcherEntity();
    entity.setId(fetcherPlugin.id());
    entity.setDescription(fetcherPlugin.manifest().description());
    entity.setName(fetcherPlugin.manifest().name());
    entity.setVersion(fetcherPlugin.manifest().version());
    if (withPlugin) {
        // Plugin information
        Plugin plugin = fetcherPlugin;
        PluginEntity pluginEntity = new PluginEntity();
        pluginEntity.setPlugin(plugin.clazz());
        pluginEntity.setPath(plugin.path().toString());
        pluginEntity.setType(plugin.type().toString().toLowerCase());
        pluginEntity.setDependencies(plugin.dependencies());
    // TODO: check the purpose of this
    // entity.setPlugin(pluginEntity);
    }
    return entity;
}
Also used : PluginEntity(io.gravitee.rest.api.model.PluginEntity) FetcherEntity(io.gravitee.rest.api.model.FetcherEntity) Plugin(io.gravitee.plugin.core.api.Plugin) FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin)

Example 5 with FetcherEntity

use of io.gravitee.rest.api.model.FetcherEntity in project gravitee-management-rest-api by gravitee-io.

the class FetcherServiceImpl method findAll.

@Override
public Set<FetcherEntity> findAll(boolean onlyFilesFetchers) {
    try {
        Set<FetcherPlugin> fetcherDefinitions = super.list();
        if (onlyFilesFetchers) {
            Class<?> filesFetcherClass = FilesFetcher.class;
            fetcherDefinitions = fetcherDefinitions.stream().filter(fetcherPlugin -> filesFetcherClass.isAssignableFrom(fetcherPlugin.fetcher())).collect(Collectors.toSet());
        }
        return fetcherDefinitions.stream().map(fetcherDefinition -> convert(fetcherDefinition, false)).collect(Collectors.toSet());
    } catch (Exception ex) {
        logger.error("An error occurs while trying to list all fetchers", ex);
        throw new TechnicalManagementException("An error occurs while trying to list all fetchers", ex);
    }
}
Also used : FetcherService(io.gravitee.rest.api.service.FetcherService) Component(org.springframework.stereotype.Component) Plugin(io.gravitee.plugin.core.api.Plugin) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) FilesFetcher(io.gravitee.fetcher.api.FilesFetcher) Set(java.util.Set) PluginEntity(io.gravitee.rest.api.model.PluginEntity) FetcherEntity(io.gravitee.rest.api.model.FetcherEntity) Collectors(java.util.stream.Collectors) FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) FilesFetcher(io.gravitee.fetcher.api.FilesFetcher) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

FetcherEntity (io.gravitee.rest.api.model.FetcherEntity)7 Response (javax.ws.rs.core.Response)5 Test (org.junit.Test)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 LinkedHashMap (java.util.LinkedHashMap)4 Set (java.util.Set)4 Plugin (io.gravitee.plugin.core.api.Plugin)2 FetcherPlugin (io.gravitee.plugin.fetcher.FetcherPlugin)2 PluginEntity (io.gravitee.rest.api.model.PluginEntity)2 FilesFetcher (io.gravitee.fetcher.api.FilesFetcher)1 FetcherService (io.gravitee.rest.api.service.FetcherService)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 Collectors (java.util.stream.Collectors)1 Component (org.springframework.stereotype.Component)1