use of org.asqatasun.entity.subject.Page in project Asqatasun by Asqatasun.
the class UploadAuditCommandImplTest method testLoadContent1.
/**
* Test of loadContent method, of class UploadAuditCommandImpl.
*/
public void testLoadContent1() {
System.out.println("LoadContent with 1 file");
mockInitialisationCalls(false, AuditStatus.CONTENT_LOADING);
fileMap.put("My File Name", "MyFileContent");
EasyMock.expect(mockAudit.getStatus()).andReturn(AuditStatus.CONTENT_LOADING).once();
Page mockPage = EasyMock.createMock(Page.class);
EasyMock.expect(mockWebResourceDataService.createPage("My File Name")).andReturn(mockPage).once();
mockPage.setAudit(mockAudit);
EasyMock.expectLastCall().once();
EasyMock.expect(mockWebResourceDataService.saveOrUpdate(mockPage)).andReturn(mockPage).once();
mockAudit.setSubject(mockPage);
EasyMock.expectLastCall().once();
EasyMock.expect(mockAudit.getSubject()).andReturn(mockPage).once();
EasyMock.expect(mockContentLoaderService.loadContent(mockPage, fileMap)).andReturn(new ArrayList<Content>()).once();
mockAudit.setStatus(AuditStatus.CONTENT_ADAPTING);
EasyMock.expectLastCall().once();
EasyMock.expect(mockAuditDataService.saveOrUpdate(mockAudit)).andReturn(mockAudit).once();
EasyMock.replay(mockPage);
setReplayMode();
UploadAuditCommandImpl instance = getInstance();
instance.loadContent();
EasyMock.verify(mockPage);
setVerifyMode();
}
use of org.asqatasun.entity.subject.Page in project Asqatasun by Asqatasun.
the class UploadAuditCommandImplTest method testLoadContent2.
/**
* Test of loadContent method, of class UploadAuditCommandImpl.
*/
public void testLoadContent2() {
System.out.println("LoadContent with several file");
mockInitialisationCalls(false, AuditStatus.CONTENT_LOADING);
fileMap.put("file:///My_File_Name1", "MyFileContent1");
fileMap.put("file:///My_File_Name2", "MyFileContent2");
EasyMock.expect(mockAudit.getStatus()).andReturn(AuditStatus.CONTENT_LOADING).once();
Site mockSite = EasyMock.createMock(Site.class);
Page mockPage1 = EasyMock.createMock(Page.class);
Page mockPage2 = EasyMock.createMock(Page.class);
EasyMock.expect(mockWebResourceDataService.createSite("file:///My_File_Name1")).andReturn(mockSite).once();
EasyMock.expect(mockWebResourceDataService.createPage("file:///My_File_Name1")).andReturn(mockPage1).once();
EasyMock.expect(mockWebResourceDataService.createPage("file:///My_File_Name2")).andReturn(mockPage2).once();
mockSite.addChild(mockPage1);
EasyMock.expectLastCall().once();
mockSite.addChild(mockPage2);
EasyMock.expectLastCall().once();
mockSite.setAudit(mockAudit);
EasyMock.expectLastCall().once();
EasyMock.expect(mockWebResourceDataService.saveOrUpdate(mockSite)).andReturn(mockSite).times(2);
EasyMock.expect(mockWebResourceDataService.saveOrUpdate(mockPage1)).andReturn(mockSite).once();
EasyMock.expect(mockWebResourceDataService.saveOrUpdate(mockPage2)).andReturn(mockSite).once();
mockAudit.setSubject(mockSite);
EasyMock.expectLastCall().once();
EasyMock.expect(mockAudit.getSubject()).andReturn(mockSite).once();
EasyMock.expect(mockContentLoaderService.loadContent(mockSite, fileMap)).andReturn(new ArrayList<Content>()).once();
mockAudit.setStatus(AuditStatus.CONTENT_ADAPTING);
EasyMock.expectLastCall().once();
EasyMock.expect(mockAuditDataService.saveOrUpdate(mockAudit)).andReturn(mockAudit).once();
EasyMock.replay(mockSite);
EasyMock.replay(mockPage1);
EasyMock.replay(mockPage2);
setReplayMode();
UploadAuditCommandImpl instance = getInstance();
instance.loadContent();
EasyMock.verify(mockSite);
EasyMock.verify(mockPage1);
EasyMock.verify(mockPage2);
setVerifyMode();
}
use of org.asqatasun.entity.subject.Page in project Asqatasun by Asqatasun.
the class AuditCommandImpl method createEmptyPageResource.
/**
* Create a webResource of page type and associate it with the current audit
* @param url
*/
protected void createEmptyPageResource(String url) {
Page page = getWebResourceDataService().createPage(url);
getAudit().setSubject(page);
getWebResourceDataService().saveOrUpdate(page);
}
use of org.asqatasun.entity.subject.Page in project Asqatasun by Asqatasun.
the class CrawlerImpl method saveWebResourceFromFetchedPage.
/**
*
* @param curi
* @param charset
* @param fetchStatus
* @param sourceCode
* @param successfullFetch
* @return
*/
private SSP saveWebResourceFromFetchedPage(String uri, String charset, int fetchStatus, String sourceCode, boolean successfullFetch) {
Page page;
if (mainWebResource instanceof Page) {
if (!isPageAlreadyFetched) {
page = (Page) mainWebResource;
// in case of redirection, we modify the URI of the webresource
// to ensure the webresource and its SSP have the same URI.
page.setURL(uri);
if (successfullFetch) {
isPageAlreadyFetched = true;
SSP ssp = createSSPFromPage(uri, charset, page, sourceCode);
if (persistOnTheFly) {
persistSSP(ssp, uri, fetchStatus, page);
}
return ssp;
} else {
return lastFetchedSSP;
}
} else {
// we don't create SSP anymore.
return lastFetchedSSP;
}
} else {
page = webResourceDataService.createPage(uri);
page.setParent((Site) mainWebResource);
page.setRank(pageRankCounter);
pageRankCounter++;
SSP ssp = createSSPFromPage(uri, charset, page, sourceCode);
if (persistOnTheFly) {
persistSSP(ssp, uri, fetchStatus, page);
}
return ssp;
}
}
use of org.asqatasun.entity.subject.Page in project Asqatasun by Asqatasun.
the class PageFactoryImpl method create.
@Override
public Page create(String url) {
Page page = new PageImpl();
page.setURL(url);
return page;
}
Aggregations