use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class ProcessResultDAOImplTest method testRetrieveGrossResultFromAuditAndWebResource.
public void testRetrieveGrossResultFromAuditAndWebResource() {
Audit audit = auditDAO.read(Long.valueOf(1));
WebResource wr = webresourceDAO.read(Long.valueOf(1));
Collection<ProcessResult> processResultList = processResultDAO.retrieveNetResultFromAuditAndWebResource(audit, wr);
assertEquals(6, processResultList.size());
wr = webresourceDAO.read(Long.valueOf(2));
processResultList = processResultDAO.retrieveNetResultFromAuditAndWebResource(audit, wr);
assertEquals(0, processResultList.size());
}
use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class ContentLoaderImpl method run.
private List<Content> run(WebResource webResource) {
// TODO Handle exceptions like 404, 403, 500, ...
List<Content> localResult = new ArrayList<>();
if (webResource instanceof Page) {
downloader.setURL(webResource.getURL());
downloader.run();
String stringContent = downloader.getResult();
Content content = contentDataService.getSSP(dateFactory.createDate(), webResource.getURL(), stringContent, (Page) webResource, HTTP_CODE_OK);
localResult.add(content);
}
if (webResource instanceof Site) {
Site site = (Site) webResource;
for (WebResource component : site.getComponentList()) {
localResult.addAll(run(component));
}
}
return localResult;
}
use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class FileContentLoaderImpl method run.
/**
*
* @param webResource
* @return
*/
private List<Content> run(WebResource webResource) {
List<Content> localResult = new ArrayList<>();
if (webResource instanceof Page) {
Content content = contentDataService.getSSP(dateFactory.createDate(), webResource.getURL(), fileMap.get(FileNaming.removeFilePrefix(webResource.getURL())), (Page) webResource, HttpStatus.SC_OK);
localResult.add(content);
} else if (webResource instanceof Site) {
Site site = (Site) webResource;
for (WebResource component : site.getComponentList()) {
localResult.addAll(run(component));
}
}
return localResult;
}
use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class ContentLoaderServiceImplTest method testLoadContent_WebResource.
/**
* Test of loadContent method, of class ContentLoaderServiceImpl.
*/
public void testLoadContent_WebResource() {
System.out.println("loadContent");
WebResource mockWebResource = EasyMock.createMock(WebResource.class);
ContentDataService mockContentDataService = EasyMock.createMock(ContentDataService.class);
Downloader mockDownloader = EasyMock.createMock(Downloader.class);
DownloaderFactory mockDownloaderFactory = EasyMock.createMock(DownloaderFactory.class);
ContentLoaderFactory mockContentLoaderFactory = EasyMock.createMock(ContentLoaderFactory.class);
ContentLoader mockContentLoader = EasyMock.createMock(ContentLoader.class);
DateFactory mockDateFactory = EasyMock.createMock(DateFactory.class);
EasyMock.expect(mockDownloaderFactory.create()).andReturn(mockDownloader).once();
EasyMock.expect(mockContentLoaderFactory.create(mockContentDataService, mockDownloader, mockDateFactory, null)).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(mockDownloader);
EasyMock.replay(mockDownloaderFactory);
EasyMock.replay(mockDateFactory);
ContentLoaderServiceImpl instance = new ContentLoaderServiceImpl();
instance.setContentDataService(mockContentDataService);
instance.setContentLoaderFactory(mockContentLoaderFactory);
instance.setDownloaderFactory(mockDownloaderFactory);
instance.setDateFactory(mockDateFactory);
assertEquals(contentList, instance.loadContent(mockWebResource));
EasyMock.verify(mockContent);
EasyMock.verify(mockContentDataService);
EasyMock.verify(mockContentLoader);
EasyMock.verify(mockContentLoaderFactory);
EasyMock.verify(mockDownloader);
EasyMock.verify(mockDownloaderFactory);
EasyMock.verify(mockDateFactory);
}
use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.
the class CrawlerServiceImpl method crawl.
/**
*
* @param crawler
* @param audit
* @return
*/
private WebResource crawl(Crawler crawler, Audit audit, boolean persistOnTheFly) {
crawler.run();
WebResource wr = crawler.getResult();
wr.setAudit(audit);
audit.setSubject(wr);
if (persistOnTheFly) {
//the relation from webresource to audit is refresh, the audit has to
// be persisted first
auditDataService.saveOrUpdate(audit);
setAuditToContent(wr, audit);
removeSummerRomance(audit);
removePageExcedent(wr, audit);
}
return wr;
}
Aggregations