Search in sources :

Example 6 with PageSource

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

the class PageService_AutoFetchTest method shouldFetch_SourcePage_AutoFetch.

@Test
public void shouldFetch_SourcePage_AutoFetch() throws Exception {
    PageSource pageSource = new PageSource();
    pageSource.setType("type");
    pageSource.setConfiguration("{\"autoFetch\": true, \"fetchCron\" : \"* * * * * *\"}");
    when(mockPage.getReferenceType()).thenReturn(PageReferenceType.ENVIRONMENT);
    when(mockPage.getReferenceId()).thenReturn("envId");
    when(mockPage.getSource()).thenReturn(pageSource);
    when(mockPage.getUpdatedAt()).thenReturn(new Date(Instant.now().minus(2, ChronoUnit.SECONDS).toEpochMilli()));
    when(mockPage.getVisibility()).thenReturn("PUBLIC");
    when(pageRepository.search(any())).thenReturn(Arrays.asList(mockPage));
    when(pageRepository.update(any())).thenReturn(mockPage);
    FetcherPlugin fetcherPlugin = mock(FetcherPlugin.class);
    when(fetcherPlugin.clazz()).thenReturn("io.gravitee.rest.api.service.PageService_ImportSimplePageMockFetcher");
    when(fetcherPlugin.configuration()).thenReturn(PageService_MockSinglePageFetcherConfiguration.class);
    when(fetcherPluginManager.get(any())).thenReturn(fetcherPlugin);
    Class<PageService_ImportSimplePageMockFetcher> mockFetcherClass = PageService_ImportSimplePageMockFetcher.class;
    when(fetcherPlugin.fetcher()).thenReturn(mockFetcherClass);
    PageService_MockSinglePageFetcherConfiguration fetcherConfiguration = new PageService_MockSinglePageFetcherConfiguration();
    when(fetcherConfigurationFactory.create(eq(PageService_MockSinglePageFetcherConfiguration.class), anyString())).thenReturn(fetcherConfiguration);
    AutowireCapableBeanFactory mockAutowireCapableBeanFactory = mock(AutowireCapableBeanFactory.class);
    when(applicationContext.getAutowireCapableBeanFactory()).thenReturn(mockAutowireCapableBeanFactory);
    long pages = pageService.execAutoFetch(GraviteeContext.getCurrentEnvironment());
    assertEquals(1, pages);
    verify(pageRepository, times(1)).update(any());
    verify(pageRepository, times(0)).create(any());
}
Also used : FetcherPlugin(io.gravitee.plugin.fetcher.FetcherPlugin) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) Date(java.util.Date) PageSource(io.gravitee.repository.management.model.PageSource) Test(org.junit.Test)

Aggregations

FetcherPlugin (io.gravitee.plugin.fetcher.FetcherPlugin)6 PageSource (io.gravitee.repository.management.model.PageSource)6 Test (org.junit.Test)6 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)6 Date (java.util.Date)3 Page (io.gravitee.repository.management.model.Page)2 ImportPageEntity (io.gravitee.rest.api.model.ImportPageEntity)2 PageEntity (io.gravitee.rest.api.model.PageEntity)2 PageSourceEntity (io.gravitee.rest.api.model.PageSourceEntity)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PluginManager (io.gravitee.plugin.core.api.PluginManager)1 PageRepository (io.gravitee.repository.management.api.PageRepository)1 PageReferenceType (io.gravitee.repository.management.model.PageReferenceType)1 FetcherConfigurationFactory (io.gravitee.rest.api.fetcher.FetcherConfigurationFactory)1 Visibility (io.gravitee.rest.api.model.Visibility)1 GraviteeContext (io.gravitee.rest.api.service.common.GraviteeContext)1 UuidString (io.gravitee.rest.api.service.common.UuidString)1 PageServiceImpl (io.gravitee.rest.api.service.impl.PageServiceImpl)1 SearchEngineService (io.gravitee.rest.api.service.search.SearchEngineService)1 ImportConfiguration (io.gravitee.rest.api.service.spring.ImportConfiguration)1