Search in sources :

Example 16 with WebResource

use of org.asqatasun.entity.subject.WebResource 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 17 with WebResource

use of org.asqatasun.entity.subject.WebResource 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 18 with WebResource

use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.

the class AuditResultController method displaySourceCodeFromContract.

/**
     *
     * @param webresourceId
     * @param request
     * @param response
     * @param model
     * @return
     */
@RequestMapping(value = TgolKeyStore.SOURCE_CODE_CONTRACT_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displaySourceCodeFromContract(@RequestParam(TgolKeyStore.WEBRESOURCE_ID_KEY) String webresourceId, HttpServletRequest request, HttpServletResponse response, Model model) {
    WebResource webResource;
    try {
        webResource = getWebResourceDataService().ligthRead(Long.valueOf(webresourceId));
    } catch (NumberFormatException nfe) {
        throw new ForbiddenPageException();
    }
    if (webResource instanceof Site) {
        throw new ForbiddenPageException();
    }
    Audit audit = getAuditFromWebResource(webResource);
    if (isUserAllowedToDisplayResult(audit)) {
        Page page = (Page) webResource;
        SSP ssp = getContentDataService().findSSP(page, page.getURL());
        model.addAttribute(TgolKeyStore.SOURCE_CODE_KEY, highlightSourceCode(ssp));
        ScopeEnum scope = getActDataService().getActFromAudit(audit).getScope().getCode();
        if (scope.equals(ScopeEnum.GROUPOFPAGES) || scope.equals(ScopeEnum.PAGE)) {
            model.addAttribute(TgolKeyStore.IS_GENERATED_HTML_KEY, true);
        }
        return TgolKeyStore.SOURCE_CODE_PAGE_VIEW_NAME;
    } else {
        throw new ForbiddenUserException(getCurrentUser());
    }
}
Also used : Site(org.asqatasun.entity.subject.Site) Audit(org.asqatasun.entity.audit.Audit) SSP(org.asqatasun.entity.audit.SSP) ScopeEnum(org.asqatasun.webapp.entity.contract.ScopeEnum) WebResource(org.asqatasun.entity.subject.WebResource) Page(org.asqatasun.entity.subject.Page) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) Secured(org.springframework.security.access.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with WebResource

use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.

the class AbstractAuditResultController method dispatchDisplayResultRequest.

/**
     * Regarding the page type, this method collects data, set them up and
     * display the appropriate result page.
     *
     * @param webResourceId
     * @param auditResultSortCommand
     * @param model
     * @param request
     * @param isManualAudit
     * @param manualAuditCommand
     * @return
     */
protected String dispatchDisplayResultRequest(Long webResourceId, AuditResultSortCommand auditResultSortCommand, Model model, HttpServletRequest request, boolean isManualAudit, ManualAuditCommand manualAuditCommand) {
    // We first check that the current user is allowed to display the result
    // of this audit
    WebResource webResource = getWebResourceDataService().ligthRead(webResourceId);
    if (webResource == null) {
        throw new ForbiddenPageException();
    }
    Audit audit = getAuditFromWebResource(webResource);
    // data are retrieved to be prepared and displayed
    if (isUserAllowedToDisplayResult(audit)) {
        this.callGc(webResource);
        String displayScope = computeDisplayScope(request, auditResultSortCommand);
        addAuditStatisticsToModel(webResource, model, displayScope);
        // The page is displayed with sort option. Form needs to be set up
        prepareDataForSortConsole(webResourceId, displayScope, auditResultSortCommand, model, isManualAudit);
        // Data need to be prepared regarding the audit type
        return prepareSuccessfullAuditData(webResource, audit, model, displayScope, getLocaleResolver().resolveLocale(request), isManualAudit, manualAuditCommand);
    } else {
        throw new ForbiddenUserException(getCurrentUser());
    }
}
Also used : Audit(org.asqatasun.entity.audit.Audit) WebResource(org.asqatasun.entity.subject.WebResource) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 20 with WebResource

use of org.asqatasun.entity.subject.WebResource in project Asqatasun by Asqatasun.

the class AbstractGroupRuleImplementation method consolidateImpl.

/**
     * This is the implementation of the method declared in
     * {@link AbstractRuleImplementation}. It encapsulates the main algorithm of
     * the consolidation operation of concrete {@link RuleImplementation}
     * classes for tests with group scope. It calls the method
     * {@link #consolidateGroup(org.asqatasun.entity.subject.Site, java.util.Set)}
     * which should consolidate gross results by group. In common cases, this
     * method should not be overriden.
     *
     * @param grossResultMap
     *            the gross result map to consolidate.
     * @return the list of net results from the gross result list.
     */
@Override
protected List<ProcessResult> consolidateImpl(Map<WebResource, List<ProcessResult>> grossResultMap, ProcessRemarkService processRemarkService) {
    List<ProcessResult> netResultList = new ArrayList<>();
    for (Map.Entry<WebResource, List<ProcessResult>> entry : grossResultMap.entrySet()) {
        WebResource key = entry.getKey();
        List<ProcessResult> grossResultList = entry.getValue();
        if (entry.getKey() instanceof Page) {
            DefiniteResult netResult = processResultDataService.getDefiniteResult(test, key);
            netResult.setDefiniteValue(TestSolution.NOT_APPLICABLE);
            for (ProcessResult grossResult : grossResultList) {
                //                    netResult.addChildResult(grossResult);
                netResult.setNetResultAudit(grossResult.getGrossResultAudit());
            }
            netResultList.add(netResult);
            continue;
        } else {
            netResultList.add(consolidateGroup((Site) key, grossResultList, processRemarkService));
        }
    }
    return consolidateSite(netResultList, processRemarkService);
}
Also used : Site(org.asqatasun.entity.subject.Site) ArrayList(java.util.ArrayList) ProcessResult(org.asqatasun.entity.audit.ProcessResult) WebResource(org.asqatasun.entity.subject.WebResource) List(java.util.List) ArrayList(java.util.ArrayList) Page(org.asqatasun.entity.subject.Page) Map(java.util.Map) DefiniteResult(org.asqatasun.entity.audit.DefiniteResult)

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