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;
}
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);
}
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());
}
}
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());
}
}
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);
}
Aggregations