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());
}
Aggregations