use of org.asqatasun.entity.parameterization.Parameter in project Asqatasun by Asqatasun.
the class ParameterDataServiceDecoratorImpl method getParameterSetFromOptionElementSet.
@Override
public Collection<Parameter> getParameterSetFromOptionElementSet(Collection<OptionElement> optionElementSet) {
Set<Parameter> paramSet = new HashSet<>();
for (OptionElement optionElement : optionElementSet) {
ParameterElement pe = parameterElementDataService.getParameterElement(optionElement.getOption().getCode());
if (pe != null) {
Parameter p = decoratedParameterDataService.getParameter(pe, optionElement.getValue());
p = saveOrUpdate(p);
paramSet.add(p);
}
}
return paramSet;
}
use of org.asqatasun.entity.parameterization.Parameter in project Asqatasun by Asqatasun.
the class AuditServiceImplTest method testAuditSite.
/**
* Test of auditPage method, of class AuditServiceImpl.
*/
public void testAuditSite() {
System.out.println("auditSite");
String siteUrl = "http://My.testUrl.org";
Set<Parameter> paramSet = null;
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, paramSet, true)).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.addSiteAudit(mockAuditCommand);
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(mockAuditServiceThreadQueue);
instance.setAuditServiceThreadQueue(mockAuditServiceThreadQueue);
Audit result = instance.auditSite(siteUrl, paramSet);
assertEquals(auditCreateByAuditCommand, result);
EasyMock.verify(mockAuditServiceThreadQueue);
EasyMock.verify(mockAuditCommand);
EasyMock.verify(mockAuditCommandFactory);
}
use of org.asqatasun.entity.parameterization.Parameter in project Asqatasun by Asqatasun.
the class AuditServiceImplTest method testAuditPage.
/**
* Test of auditPage method, of class AuditServiceImpl.
*/
public void testAuditPage() {
System.out.println("auditPage");
String pageUrl = "http://My.testUrl.org";
Set<Parameter> paramSet = null;
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(pageUrl, paramSet, false)).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 page 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.auditPage(pageUrl, paramSet);
assertEquals(auditCreateByAuditCommand, result);
EasyMock.verify(mockAuditServiceThreadQueue);
EasyMock.verify(mockAuditCommand);
EasyMock.verify(mockAuditCommandFactory);
}
use of org.asqatasun.entity.parameterization.Parameter in project Asqatasun by Asqatasun.
the class AuditServiceImplTest method testAuditPageUploadWithOneFile.
/**
* Test of auditPageUpload method, of class AuditServiceImpl.
*/
public void testAuditPageUploadWithOneFile() {
System.out.println("auditPageUploadWithOneFile");
Set<Parameter> paramSet = null;
// test we only one file is passed as argument to be tested
String file1Name = "file://test1";
Map<String, String> fileMap = new HashMap<>();
fileMap.put(file1Name, "");
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(fileMap, 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 pageUpload audit
AuditServiceThreadQueue mockAuditServiceThreadQueue = EasyMock.createMock(AuditServiceThreadQueue.class);
mockAuditServiceThreadQueue.add(instance);
EasyMock.expectLastCall().anyTimes();
mockAuditServiceThreadQueue.addPageUploadAudit(mockAuditCommand);
EasyMock.replay(mockAuditServiceThreadQueue);
instance.setAuditServiceThreadQueue(mockAuditServiceThreadQueue);
Audit result = instance.auditPageUpload(fileMap, paramSet);
assertEquals(auditCreateByAuditCommand, result);
EasyMock.verify(mockAuditServiceThreadQueue);
EasyMock.verify(mockAuditCommand);
EasyMock.verify(mockAuditCommandFactory);
}
use of org.asqatasun.entity.parameterization.Parameter in project Asqatasun by Asqatasun.
the class AsqatasunCrawlJob method initializeCrawlContext.
/**
*
* @param url
* @param crawlParameterSet
* @param heritrixFileName
* @return
*/
private File initializeCrawlContext(Collection<String> urlList, Set<Parameter> crawlParameterSet, String heritrixFileName) {
buildOutputDirectory();
BufferedReader in = null;
FileWriter fw = null;
try {
LOGGER.debug("crawlConfigFilePath: " + crawlConfigFilePath + " for copy");
String filepath = crawlConfigFilePath + "/" + heritrixFileName;
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(filepath);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("filepath : " + filepath);
for (Parameter param : crawlParameterSet) {
LOGGER.debug(param.getParameterElement().getParameterElementCode() + " " + param.getValue());
}
}
doc = setOptionToDocument(urlList, crawlParameterSet, doc);
//write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
String resultFileName = currentJobOutputDir.getPath() + "/" + heritrixFileName;
StreamResult result = new StreamResult(new File(resultFileName));
transformer.transform(source, result);
} catch (IOException | ParserConfigurationException | SAXException ex) {
LOGGER.error(ex);
throw new CrawlerException(ex);
} catch (TransformerConfigurationException ex) {
LOGGER.error(ex);
throw new CrawlerException(ex);
} catch (TransformerException ex) {
LOGGER.error(ex);
throw new CrawlerException(ex);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ex) {
LOGGER.error(ex);
throw new CrawlerException(ex);
}
}
if (fw != null) {
try {
fw.close();
} catch (IOException ex) {
LOGGER.error(ex);
throw new CrawlerException(ex);
}
}
}
return new File(currentJobOutputDir.getPath() + "/" + heritrixFileName);
}
Aggregations