Search in sources :

Example 6 with Content

use of org.asqatasun.entity.audit.Content 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;
}
Also used : Site(org.asqatasun.entity.subject.Site) Content(org.asqatasun.entity.audit.Content) ArrayList(java.util.ArrayList) WebResource(org.asqatasun.entity.subject.WebResource) Page(org.asqatasun.entity.subject.Page)

Example 7 with Content

use of org.asqatasun.entity.audit.Content 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);
}
Also used : Content(org.asqatasun.entity.audit.Content) ContentLoader(org.asqatasun.contentloader.ContentLoader) ArrayList(java.util.ArrayList) WebResource(org.asqatasun.entity.subject.WebResource) Downloader(org.asqatasun.contentloader.Downloader) ContentLoaderFactory(org.asqatasun.contentloader.ContentLoaderFactory) DateFactory(org.asqatasun.util.factory.DateFactory) ContentDataService(org.asqatasun.entity.service.audit.ContentDataService) DownloaderFactory(org.asqatasun.contentloader.DownloaderFactory)

Example 8 with Content

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;
}
Also used : AuditImpl(org.asqatasun.entity.audit.AuditImpl) Audit(org.asqatasun.entity.audit.Audit) Content(org.asqatasun.entity.audit.Content) WebResource(org.asqatasun.entity.subject.WebResource)

Example 9 with Content

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);
}
Also used : Audit(org.asqatasun.entity.audit.Audit) ScenarioLoader(org.asqatasun.scenarioloader.ScenarioLoader) Content(org.asqatasun.entity.audit.Content) WebResourceDataService(org.asqatasun.entity.service.subject.WebResourceDataService) ArrayList(java.util.ArrayList) WebResource(org.asqatasun.entity.subject.WebResource) ScenarioLoaderFactory(org.asqatasun.scenarioloader.ScenarioLoaderFactory) ContentDataService(org.asqatasun.entity.service.audit.ContentDataService)

Example 10 with Content

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;
}
Also used : Audit(org.asqatasun.entity.audit.Audit) ScenarioLoader(org.asqatasun.scenarioloader.ScenarioLoader) Content(org.asqatasun.entity.audit.Content)

Aggregations

Content (org.asqatasun.entity.audit.Content)17 WebResource (org.asqatasun.entity.subject.WebResource)11 ArrayList (java.util.ArrayList)7 SSP (org.asqatasun.entity.audit.SSP)5 Audit (org.asqatasun.entity.audit.Audit)4 ContentDataService (org.asqatasun.entity.service.audit.ContentDataService)3 ContentLoader (org.asqatasun.contentloader.ContentLoader)2 ContentLoaderFactory (org.asqatasun.contentloader.ContentLoaderFactory)2 AuditImpl (org.asqatasun.entity.audit.AuditImpl)2 ProcessResult (org.asqatasun.entity.audit.ProcessResult)2 RelatedContent (org.asqatasun.entity.audit.RelatedContent)2 Test (org.asqatasun.entity.reference.Test)2 Page (org.asqatasun.entity.subject.Page)2 Site (org.asqatasun.entity.subject.Site)2 ScenarioLoader (org.asqatasun.scenarioloader.ScenarioLoader)2 DateFactory (org.asqatasun.util.factory.DateFactory)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1