use of org.asqatasun.entity.audit.Content in project Asqatasun by Asqatasun.
the class CrawlerServiceImplTest method initialiseAndLaunchCrawl.
/**
*
* @param siteUrl
* @param depth
* @param regexp
* @param maxDuration
* @param maxDocuments
* @param proxyHost
* @param proxyPort
* @return
*/
private List<Content> initialiseAndLaunchCrawl(String siteUrl, String depth, String exlusionRegexp, String inlusionRegexp, String maxDuration, String maxDocuments) {
Audit audit = new AuditImpl();
audit.setParameterSet(setCrawlParameters(depth, exlusionRegexp, inlusionRegexp, maxDuration, maxDocuments));
WebResource site = crawlerService.crawlSite(audit, siteUrl);
Collection<Long> contentListId = mockContentDataService.getSSPIdsFromWebResource(site.getId(), HttpStatus.SC_OK, 0, 10);
List<Content> contentList = new ArrayList();
for (Long id : contentListId) {
Content content = mockContentDataService.readWithRelatedContent(id, false);
if (content != null) {
System.out.println(content.getURI() + " " + content.getClass());
contentList.add(content);
}
}
return contentList;
}
use of org.asqatasun.entity.audit.Content in project Asqatasun by Asqatasun.
the class ScenarioLoaderServiceImplTest method testLoadScenario.
/**
* Test of loadScenario method, of class ScenarioLoaderServiceImpl.
*/
public void testLoadScenario() {
System.out.println("loadScenario");
String scenarioFile = "My Scenario";
WebResource mockWebResource = createMock(WebResource.class);
Audit mockAudit = createMock(Audit.class);
expect(mockWebResource.getAudit()).andReturn(mockAudit).once();
ScenarioLoaderFactory mockScenarioLoaderFactory = createMock(ScenarioLoaderFactory.class);
ScenarioLoader mockScenarioLoader = createMock(ScenarioLoader.class);
expect(mockScenarioLoaderFactory.create(mockWebResource, scenarioFile)).andReturn(mockScenarioLoader).once();
mockScenarioLoader.run();
expectLastCall().once();
List<Content> contentList = new ArrayList<Content>();
expect(mockScenarioLoader.getResult()).andReturn(contentList).once();
ContentDataService mockContentDataService = createMock(ContentDataService.class);
WebResourceDataService mockWebResourceDataService = createMock(WebResourceDataService.class);
expect(mockWebResourceDataService.saveOrUpdate(mockWebResource)).andReturn(mockWebResource).once();
replay(mockAudit);
replay(mockWebResource);
replay(mockWebResourceDataService);
replay(mockContentDataService);
replay(mockScenarioLoader);
replay(mockScenarioLoaderFactory);
ScenarioLoaderServiceImpl instance = new ScenarioLoaderServiceImpl();
instance.setContentDataService(mockContentDataService);
instance.setScenarioLoaderFactory(mockScenarioLoaderFactory);
instance.setWebResourceDataService(mockWebResourceDataService);
instance.loadScenario(mockWebResource, scenarioFile);
verify(mockAudit);
verify(mockWebResource);
verify(mockWebResourceDataService);
verify(mockContentDataService);
verify(mockScenarioLoader);
verify(mockScenarioLoaderFactory);
}
use of org.asqatasun.entity.audit.Content in project Asqatasun by Asqatasun.
the class ScenarioLoaderServiceImpl method loadScenario.
@Override
public List<Content> loadScenario(WebResource webResource, String scenarioFile) {
Audit audit = webResource.getAudit();
ScenarioLoader scenarioLoader = scenarioLoaderFactory.create(webResource, scenarioFile);
scenarioLoader.run();
List<Content> contentList = scenarioLoader.getResult();
for (Content content : contentList) {
// content.setAudit(audit);
contentDataService.saveAuditToContent(content.getId(), audit.getId());
}
// Before returning the list of content we save the webResource
webResourceDataService.saveOrUpdate(webResource);
return contentList;
}
use of org.asqatasun.entity.audit.Content in project Asqatasun by Asqatasun.
the class ContentsAdapterImpl method run.
private Collection<Content> run(Collection<Content> contentList) {
Collection<Content> localResult = new ArrayList<>();
for (Content content : contentList) {
// We only handle here the fetched content (HttpStatus=200)
if (content instanceof SSP && content.getHttpStatusCode() == 200) {
LOGGER.debug("Adapting " + content.getURI());
SSP ssp = (SSP) content;
htmlCleaner.setDirtyHTML(ssp.getSource());
htmlCleaner.run();
ssp.setAdaptedContent(htmlCleaner.getResult());
htmlCleaner.setDirtyHTML(null);
writeCleanDomInFile(ssp);
if (parseAndRetrievelRelatedContent) {
htmlParser.setSSP(ssp);
htmlParser.run();
} else {
LOGGER.debug("no Html parse executed for the current audit");
}
if (xmlizeContent) {
AbstractHTMLCleaner cleaner = new HTMLCleanerImpl();
cleaner.setDirtyHTML(ssp.getAdaptedContent());
cleaner.run();
ssp.setAdaptedContent(DocumentCaseInsensitiveAdapter.removeLowerCaseTags(cleaner.getResult()));
}
localResult.add(ssp);
}
}
return localResult;
}
use of org.asqatasun.entity.audit.Content in project Asqatasun by Asqatasun.
the class ContentDAOImplTest method testFindOrphanContentList.
@Test
public void testFindOrphanContentList() {
WebResource wr = webresourceDAO.read(Long.valueOf(1));
assertEquals(Long.valueOf(2), contentDAO.findNumberOfOrphanContentFromWebResource(wr));
List<Content> contentList = contentDAO.findOrphanContentList(wr, 0, 100);
assertEquals(2, contentList.size());
assertEquals(Long.valueOf(3), contentDAO.findNumberOfOrphanRelatedContentFromWebResource(wr));
contentList = contentDAO.findOrphanRelatedContentList(wr, 0, 10);
assertEquals(3, contentList.size());
wr = webresourceDAO.read(Long.valueOf(2));
contentList = contentDAO.findOrphanContentList(wr, 0, 10);
assertEquals(1, contentList.size());
contentList = contentDAO.findOrphanRelatedContentList(wr, 0, 10);
assertEquals(1, contentList.size());
}
Aggregations