Search in sources :

Example 31 with WebResource

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

Example 32 with WebResource

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

Example 33 with WebResource

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));
}
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 34 with WebResource

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

Example 35 with WebResource

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());
}
Also used : Iterator(java.util.Iterator) WebResource(org.asqatasun.entity.subject.WebResource)

Aggregations

WebResource (org.asqatasun.entity.subject.WebResource)43 Audit (org.asqatasun.entity.audit.Audit)11 Content (org.asqatasun.entity.audit.Content)11 Site (org.asqatasun.entity.subject.Site)9 ArrayList (java.util.ArrayList)8 ProcessResult (org.asqatasun.entity.audit.ProcessResult)8 Page (org.asqatasun.entity.subject.Page)7 NoResultException (javax.persistence.NoResultException)6 Query (javax.persistence.Query)6 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)6 List (java.util.List)5 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 NonUniqueResultException (javax.persistence.NonUniqueResultException)3 SSP (org.asqatasun.entity.audit.SSP)3 ContentDataService (org.asqatasun.entity.service.audit.ContentDataService)3 Contract (org.asqatasun.webapp.entity.contract.Contract)3 Map (java.util.Map)2 ContentLoader (org.asqatasun.contentloader.ContentLoader)2 ContentLoaderFactory (org.asqatasun.contentloader.ContentLoaderFactory)2