I am not familiar with groovy script and SOAP UI, this is the reason I am looking for help here for this issue. I have a java class which will send an email, groovy script within SOAP UI has to use this method. I have placed the jar file in the bin/ext folder. Please advise how can rectify this issue. Thanks!
Below is my groovy script
import com.test.email.SendEmail;
String allPorts = testRunner.testCase.testSteps["Properties"].getPropertyValue("all_ports");
log.info(" all ports "+allPorts);
String[] ports = allPorts.split(",");
String placeHolderUrl = "https://test.com:port/ServiceAssuranceService/15.09?wsdl";
String url;
String[] apis = "queryProblem,getProblem".split(",");
String[] scenarios = "EROne,CRTicket".split(",");
for(String port : ports) {
url = placeHolderUrl.replace("port",port);
//log.info(" url "+url);
for(String api : apis){
for(String scenario : scenarios) {
testRunner.testCase.getTestStepByName(api+" - "+scenario).getHttpRequest().setEndpoint(url);
try {
testRunner.runTestStepByName(api+" - "+scenario);
} catch (Exception e){
e.printStackTrace();
log.error(" Failed : "+api+" - "+scenario+" : "+url);
}
}
}
SendEmail mail = new SendEmail();
try{
mail.send("test","abc","abc.txt");
}
catch(Exception e){
log.error(e);
}
}
my java class
package com.test.email;
public class SendEmail {
private Log log = LogFactory.getLog(SendEmail.class);
@Value("${mailHost}")
private String mailHost;
@Value("${mailAuth}")
private String mailAuth;
@Value("${smtpAuth}")
private String smtpAuth;
@Value("${mailPort}")
private String mailPort;
@Value("${mailFallBack}")
private String mailFallBack;
@Value("${commaDelimitedRecepients}")
private String commaDelimitedRecepients;
public void send(String subject,String body,String fileName) {
String from = "ops@test.com";
Properties properties = new Properties();
properties.put("mail.smtp.host",mailHost);
properties.put("mail.smtp.auth", mailAuth);
properties.put("mail.smtp.socketFactory.port", mailPort);
properties.put("mail.smtp.socketFactory.fallback", mailFallBack);
Session session = Session.getDefaultInstance(properties);
try {
InternetAddress fromAddress = new InternetAddress(from);
MimeMessage message = new MimeMessage(session);
message.setFrom(fromAddress);
message.setSubject(subject);
String[] recepients = commaDelimitedRecepients.split(",");
for(String recepient : recepients){
message.addRecipients(RecipientType.TO,recepient);
}
Multipart multiPart = new MimeMultipart();
MimeBodyPart attachment = new MimeBodyPart();
if(fileName!=null) {
DataSource source = new FileDataSource(fileName);
attachment.setDataHandler(new DataHandler(source));
attachment.setFileName("EolSync.log");
multiPart.addBodyPart(attachment);
}
if(body!=null){
MimeBodyPart content = new MimeBodyPart();
content.setContent(body,"text/html");
multiPart.addBodyPart(content);
}
message.setContent(multiPart);
message.setRecipients(RecipientType.TO, message.getAllRecipients());
Transport transport = session.getTransport("smtp");
transport.connect();
transport.sendMessage(message, message.getAllRecipients());
transport.close();
} catch (Exception e) {
log.error(" unable to send mailer ",e);
}
}
public static void main(String[] args){
String[] recepients = "ia".split(",");
for(String recepient : recepients){
System.out.println(" recepient "+recepient);
}
}
}
below is the error message
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script4.groovy: 1: unable to resolve class com.test.SendEmail @ line 1, column 1. import com.test.SendEmail; ^ org.codehaus.groovy.syntax.SyntaxException: unable to resolve class com.test.SendEmail @ line 1, column 1. at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:146) at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1145) at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141) at org.codehaus.groovy.control.CompilationUnit$10.call(CompilationUnit.java:632) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:912) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:574) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:523) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:613) at groovy.lang.GroovyShell.parse(GroovyShell.java:625) at groovy.lang.GroovyShell.parse(GroovyShell.java:652) at groovy.lang.GroovyShell.parse(GroovyShell.java:643) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:138) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:89) at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141) at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) 1 error
Aucun commentaire:
Enregistrer un commentaire