Search in sources :

Example 1 with Audit

use of org.asqatasun.entity.audit.Audit in project Asqatasun by Asqatasun.

the class AuditServiceImplTest method testAuditGroupOfPages.

/**
     * Test of auditPage method, of class AuditServiceImpl.
     */
public void testAuditGroupOfPages() {
    System.out.println("auditGroupOfPages");
    String siteUrl = "http://My.testUrl.org";
    String pageUrl = "http://My.testUrlPage1.org";
    Set<Parameter> paramSet = null;
    List<String> urlList = new ArrayList<>();
    urlList.add(pageUrl);
    AuditServiceImpl instance = initialiseAuditService();
    Audit auditCreateByAuditCommand = EasyMock.createMock(Audit.class);
    AuditCommand mockAuditCommand = EasyMock.createMock(AuditCommand.class);
    EasyMock.expect(mockAuditCommand.getAudit()).andReturn(auditCreateByAuditCommand).anyTimes();
    EasyMock.replay(mockAuditCommand);
    AuditCommandFactory mockAuditCommandFactory = EasyMock.createMock(AuditCommandFactory.class);
    EasyMock.expect(mockAuditCommandFactory.create(siteUrl, urlList, paramSet)).andReturn(mockAuditCommand).anyTimes();
    EasyMock.replay(mockAuditCommandFactory);
    instance.setAuditCommandFactory(mockAuditCommandFactory);
    // anyTimes the audit is created and set-up, the auditServiceThreadQueue is 
    // called to effectively launch the site audit
    AuditServiceThreadQueue mockAuditServiceThreadQueue = EasyMock.createMock(AuditServiceThreadQueue.class);
    mockAuditServiceThreadQueue.add(instance);
    EasyMock.expectLastCall().anyTimes();
    mockAuditServiceThreadQueue.addPageAudit(mockAuditCommand);
    EasyMock.expectLastCall().anyTimes();
    EasyMock.replay(mockAuditServiceThreadQueue);
    instance.setAuditServiceThreadQueue(mockAuditServiceThreadQueue);
    Audit result = instance.auditSite(siteUrl, urlList, paramSet);
    assertEquals(auditCreateByAuditCommand, result);
    EasyMock.verify(mockAuditServiceThreadQueue);
    EasyMock.verify(mockAuditCommand);
    EasyMock.verify(mockAuditCommandFactory);
}
Also used : Audit(org.asqatasun.entity.audit.Audit) AuditCommandFactory(org.asqatasun.service.command.factory.AuditCommandFactory) Parameter(org.asqatasun.entity.parameterization.Parameter) AuditCommand(org.asqatasun.service.command.AuditCommand)

Example 2 with Audit

use of org.asqatasun.entity.audit.Audit in project Asqatasun by Asqatasun.

the class AuditServiceImplTest method testAuditScenario.

/**
     * Test of auditPage method, of class AuditServiceImpl.
     */
public void testAuditScenario() {
    System.out.println("auditScenario");
    String scenarioName = "MyScenario";
    String scenario = "";
    AuditServiceImpl instance = initialiseAuditService();
    Audit auditCreateByAuditCommand = EasyMock.createMock(Audit.class);
    AuditCommand mockAuditCommand = EasyMock.createMock(AuditCommand.class);
    EasyMock.expect(mockAuditCommand.getAudit()).andReturn(auditCreateByAuditCommand).anyTimes();
    EasyMock.replay(mockAuditCommand);
    AuditCommandFactory mockAuditCommandFactory = EasyMock.createMock(AuditCommandFactory.class);
    EasyMock.expect(mockAuditCommandFactory.create(scenarioName, scenario, null)).andReturn(mockAuditCommand).anyTimes();
    EasyMock.replay(mockAuditCommandFactory);
    instance.setAuditCommandFactory(mockAuditCommandFactory);
    // anyTimes the audit is created and set-up, the auditServiceThreadQueue is 
    // called to effectively launch the pageUpload audit
    AuditServiceThreadQueue mockAuditServiceThreadQueue = EasyMock.createMock(AuditServiceThreadQueue.class);
    mockAuditServiceThreadQueue.add(instance);
    EasyMock.expectLastCall().anyTimes();
    mockAuditServiceThreadQueue.addScenarioAudit(mockAuditCommand);
    EasyMock.expectLastCall().anyTimes();
    EasyMock.replay(mockAuditServiceThreadQueue);
    instance.setAuditServiceThreadQueue(mockAuditServiceThreadQueue);
    Audit result = instance.auditScenario(scenarioName, scenario, null);
    assertEquals(auditCreateByAuditCommand, result);
    EasyMock.verify(mockAuditServiceThreadQueue);
    EasyMock.verify(mockAuditCommand);
    EasyMock.verify(mockAuditCommandFactory);
}
Also used : Audit(org.asqatasun.entity.audit.Audit) AuditCommandFactory(org.asqatasun.service.command.factory.AuditCommandFactory) AuditCommand(org.asqatasun.service.command.AuditCommand)

Example 3 with Audit

use of org.asqatasun.entity.audit.Audit 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 4 with Audit

use of org.asqatasun.entity.audit.Audit 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 5 with Audit

use of org.asqatasun.entity.audit.Audit 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

Audit (org.asqatasun.entity.audit.Audit)51 WebResource (org.asqatasun.entity.subject.WebResource)12 Test (org.junit.Test)12 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 Parameter (org.asqatasun.entity.parameterization.Parameter)8 Site (org.asqatasun.entity.subject.Site)8 AuditCommand (org.asqatasun.service.command.AuditCommand)7 Secured (org.springframework.security.access.annotation.Secured)7 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)6 Contract (org.asqatasun.entity.contract.Contract)5 AuditCommandFactory (org.asqatasun.service.command.factory.AuditCommandFactory)5 Content (org.asqatasun.entity.audit.Content)4 ProcessResult (org.asqatasun.entity.audit.ProcessResult)4 Page (org.asqatasun.entity.subject.Page)4 AuditImpl (org.asqatasun.entity.audit.AuditImpl)3 SSP (org.asqatasun.entity.audit.SSP)2 Act (org.asqatasun.entity.contract.Act)2 Test (org.asqatasun.entity.reference.Test)2 ScenarioLoader (org.asqatasun.scenarioloader.ScenarioLoader)2