use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class ContentLoaderServiceImplTest method testLoadContent_WebResource_Map.
/**
* Test of loadContent method, of class ContentLoaderServiceImpl.
*/
public void testLoadContent_WebResource_Map() {
System.out.println("loadContent with file Map");
WebResource mockWebResource = EasyMock.createMock(WebResource.class);
ContentDataService mockContentDataService = EasyMock.createMock(ContentDataService.class);
ContentLoaderFactory mockContentLoaderFactory = EasyMock.createMock(ContentLoaderFactory.class);
DateFactory mockDateFactory = EasyMock.createMock(DateFactory.class);
ContentLoader mockContentLoader = EasyMock.createMock(ContentLoader.class);
Map<String, String> fileMap = new HashMap<>();
EasyMock.expect(mockContentLoaderFactory.create(mockContentDataService, null, mockDateFactory, fileMap)).andReturn(mockContentLoader).once();
mockContentLoader.setWebResource(mockWebResource);
EasyMock.expectLastCall().once();
mockContentLoader.run();
EasyMock.expectLastCall().once();
List<Content> contentList = new ArrayList<>();
Content mockContent = EasyMock.createMock(Content.class);
contentList.add(mockContent);
EasyMock.expect(mockContentLoader.getResult()).andReturn(contentList).once();
EasyMock.replay(mockContent);
EasyMock.replay(mockContentDataService);
EasyMock.replay(mockContentLoader);
EasyMock.replay(mockContentLoaderFactory);
EasyMock.replay(mockDateFactory);
ContentLoaderServiceImpl instance = new ContentLoaderServiceImpl();
instance.setContentDataService(mockContentDataService);
instance.setContentLoaderFactory(mockContentLoaderFactory);
instance.setDateFactory(mockDateFactory);
assertEquals(contentList, instance.loadContent(mockWebResource, fileMap));
EasyMock.verify(mockContent);
EasyMock.verify(mockContentDataService);
EasyMock.verify(mockContentLoader);
EasyMock.verify(mockContentLoaderFactory);
EasyMock.verify(mockDateFactory);
}
use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class ConsolidatorImpl method initialize.
private void initialize() {
if (initialized) {
return;
}
groupedProcessResultMap = new HashMap<WebResource, List<ProcessResult>>();
for (ProcessResult processResult : grossResultList) {
WebResource webResource = processResult.getSubject();
WebResource parent;
List<ProcessResult> processResultList;
parent = webResource.getParent();
do {
if (parent == null) {
processResultList = groupedProcessResultMap.get(webResource);
if (processResultList == null) {
processResultList = new ArrayList<ProcessResult>();
groupedProcessResultMap.put(webResource, processResultList);
}
} else {
processResultList = groupedProcessResultMap.get(parent);
if (processResultList == null) {
processResultList = new ArrayList<ProcessResult>();
groupedProcessResultMap.put(parent, processResultList);
}
webResource = parent;
parent = parent.getParent();
}
processResultList.add(processResult);
} while (parent != null);
}
initialized = true;
}
use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class CrawlerServiceImplTest method testCrawl_Page.
/**
* Test the crawl of a page
*/
public void testCrawl_Page() {
System.out.println("crawl_page");
crawlerFactory.setCrawlConfigFilePath(PAGE_CRAWL_CONF_FILE_PATH);
String siteUrl = bundle.getString(FULL_SITE_CRAWL_URL_KEY);
Audit audit = new AuditImpl();
audit.setParameterSet(setCrawlParameters("3", "", "", "", ""));
WebResource page = crawlerService.crawlPage(audit, siteUrl);
Collection<Long> contentListId = mockContentDataService.getSSPIdsFromWebResource(page.getId(), HttpStatus.SC_OK, 0, 10);
List<Content> contentList = new ArrayList<>();
for (Long id : contentListId) {
contentList.add(mockContentDataService.readWithRelatedContent(id, false));
}
assertEquals(1, contentList.size());
Set<String> urlSet = getUrlSet(contentList);
assertTrue(urlSet.contains(siteUrl));
assertFalse(urlSet.contains(siteUrl + PAGE_NAME_LEVEL1));
assertFalse(urlSet.contains(siteUrl + PAGE_NAME_LEVEL2));
assertFalse(urlSet.contains(siteUrl + FORBIDDEN_PAGE_NAME));
}
use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class WebResourceDAOImplTest method testFindByUrlAndParentWebResource.
public void testFindByUrlAndParentWebResource() {
WebResource parentWr = webresourceDAO.read(Long.valueOf(1));
WebResource wr = webresourceDAO.findByUrlAndParentWebResource(URL2, parentWr);
assertEquals(Long.valueOf(2), wr.getId());
wr = webresourceDAO.findByUrlAndParentWebResource(URL1, parentWr);
assertNull(wr);
}
use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class WebResourceDAOImplTest method testRetrieveWebResourceFromItsParent.
public void testRetrieveWebResourceFromItsParent() {
WebResource parentWr = webresourceDAO.read(Long.valueOf(1));
assertEquals(Long.valueOf(3), webresourceDAO.findNumberOfChildWebResource(parentWr));
List<WebResource> wrList = webresourceDAO.findWebResourceFromItsParent(parentWr, 0, 1);
assertEquals(1, wrList.size());
assertEquals(Long.valueOf(2), ((WebResource) wrList.iterator().next()).getId());
wrList = webresourceDAO.findWebResourceFromItsParent(parentWr, 1, 10);
assertEquals(2, wrList.size());
Iterator iter = wrList.iterator();
assertEquals(Long.valueOf(3), ((WebResource) iter.next()).getId());
assertEquals(Long.valueOf(4), ((WebResource) iter.next()).getId());
}
Aggregations