Search in sources :

Example 6 with FetcherEntity

use of io.gravitee.management.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()).thenReturn(Collections.singleton(fetcherEntity));
    when(fetcherService.getSchema(anyString())).thenReturn("schema");
    final Response response = target().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();
    verify(fetcherService, times(0)).getSchema(anyString());
}
Also used : Response(javax.ws.rs.core.Response) Set(java.util.Set) FetcherEntity(io.gravitee.management.model.FetcherEntity) Matchers.anyString(org.mockito.Matchers.anyString) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 7 with FetcherEntity

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

the class FetcherServiceImpl method findAll.

@Override
public Set<FetcherEntity> findAll() {
    try {
        LOGGER.debug("List all fetchers");
        final Collection<FetcherPlugin> fetcherDefinitions = fetcherPluginManager.findAll();
        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 : Logger(org.slf4j.Logger) PluginEntity(io.gravitee.management.model.PluginEntity) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) IOException(java.io.IOException) FetcherService(io.gravitee.management.service.FetcherService) FetcherPluginManager(io.gravitee.plugin.fetcher.FetcherPluginManager) Collectors(java.util.stream.Collectors) FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) Component(org.springframework.stereotype.Component) Plugin(io.gravitee.plugin.core.api.Plugin) FetcherNotFoundException(io.gravitee.management.service.exceptions.FetcherNotFoundException) FetcherEntity(io.gravitee.management.model.FetcherEntity) FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) IOException(java.io.IOException) FetcherNotFoundException(io.gravitee.management.service.exceptions.FetcherNotFoundException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Aggregations

FetcherEntity (io.gravitee.management.model.FetcherEntity)7 Response (javax.ws.rs.core.Response)5 Test (org.junit.Test)5 Matchers.anyString (org.mockito.Matchers.anyString)5 LinkedHashMap (java.util.LinkedHashMap)4 Set (java.util.Set)4 PluginEntity (io.gravitee.management.model.PluginEntity)2 Plugin (io.gravitee.plugin.core.api.Plugin)2 FetcherPlugin (io.gravitee.plugin.fetcher.FetcherPlugin)2 FetcherService (io.gravitee.management.service.FetcherService)1 FetcherNotFoundException (io.gravitee.management.service.exceptions.FetcherNotFoundException)1 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)1 FetcherPluginManager (io.gravitee.plugin.fetcher.FetcherPluginManager)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1