Maven/Spring/MVC Web app - error cannot TalendJob (third party Talend - spring

I'm developing a Spring/MVC/Maven Web app in Eclipse. The use case is for the app to call Talend jobs on an adhoc basis with parameters. The user enters time frame information (years, months) on a form page. Everything worked (form, validation, model, configuration, error checking, etc) until I added the required Talend jars.
Some background - I successfully created a simple Web app in Eclipse that has the same use case. For this app, I needed to place the Talend jars into the WEB-INF\lib folder. For various reasons, I need to build a Web app that uses Spring/MVC/Maven technologies. I loaded all the required Talend jars into the WEB-INF\lib folder (exactly like I did with the previous Web app). I ran a successful Maven clean install. But running the embedded Tomcat (version 7.2.2) produced this error:
[ERROR] COMPILATION ERROR:
[ERROR]C:\Documents\TalendAdHoc\src\main\java\com\validator\UserValidator.java:[13]
error: package talenddev1.job_gl_master_ad_hoc_0_3 does not exist
[ERROR]
C:\Documents\TalendAdHoc\src\main\java\com\validator\UserValidator.java:[141,7]
error: cannot find symbol.
I then followed the steps from this site:
https://cleanprogrammer.net/adding-3rd-party-jar-to-maven-projects/
to add the third party jars to Maven projects (installed the jar into the local repository, added repository and dependency into the pom.xml, etc). Running the embedded Tomcat produced this error:
[ERROR] COMPILATION ERROR: [ERROR]
C:\Documents\TalendAdHoc\src\main\java\com\validator\UserValidator.java:[155,16]
error: cannot access TalendJob
`
TalendJob` is located in the `UserValidator.java`:
job_GL_Master_Ad_Hoc TalendJob=new job_GL_Master_Ad_Hoc();
String[]
context=new String[] \{params...}
TalendJob.runJob(context);
I realize this maybe a Talend issue so I've been also working with the Talend community as well.
Any support will be greatly appreciated. Let me know if you need more information.
Thanks
Here is my pom.xml
`<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>TalendAdHoc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<!-- Spring MVC Dependency -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- JSTL Dependency -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- Servlet Dependency -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- JSP Dependency -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.talend</groupId>
<artifactId>job_gl_master_ad_hoc_0_3</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/lib/job_gl_master_ad_hoc_0_3.jar
</systemPath>
</dependency>
<dependency>
<groupId>org.talend</groupId>
<artifactId>job_gl_refresh_transaction_ad_hoc_0_2</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}
/src/lib/job_gl_refresh_transaction_ad_hoc_0_2.jar
</systemPath>
</dependency>
<dependency>
<groupId>org.talend</groupId>
<artifactId>job_gl_load_transaction_ad_hoc_0_2</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}
/src/lib/job_gl_load_transaction_ad_hoc_0_2.jar
</systemPath>
</dependency>
<dependency>
<groupId>org.talend</groupId>
<artifactId>job_gl_load_summary_ad_hoc_0_1</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}
/src/lib/job_gl_load_summary_ad_hoc_0_1.jar
</systemPath>
</dependency>
<dependency>
<groupId>org.talend</groupId>
<artifactId>job_gl_load_project_ad_hoc_0_1</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}
/src/lib/job_gl_load_project_ad_hoc_0_1.jar
</systemPath>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.8.0_201\bin\javac.exe
</executable>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- Embedded Apache Tomcat required for testing war -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</project>`
And here is the UserValidator.java:
`package com.validator;
import java.util.Calendar;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import com.model.User;
import talenddev1.job_gl_master_ad_hoc_0_3.job_GL_Master_Ad_Hoc;
#Component
public class UserValidator implements Validator {
#Override
public boolean supports(Class<?> clazz) {
return User.class.equals(clazz);
}
#Override
public void validate(Object obj, Errors err) {
User user = (User) obj;
Calendar cal = Calendar.getInstance();
set vars...
validation code...
error handling code...
}
job_GL_Master_Ad_Hoc talendJob = new job_GL_Master_Ad_Hoc();
String[] context = new String[] {
"--context_param Host_Analytics_CurrentYear=" + currentYear,
"--context_param Host_Analytics_CurrentYearStart=" +
currentYearStart,
"--context_param Host_Analytics_CurrentYearEnd=" + currentYearEnd,
"--context_param Host_Analytics_PreviousYear=" + previousYear,
"--context_param Host_Analytics_PreviousYearStart=" +
previousYearStart,
"--context_param Host_Analytics_PreviousYearEnd=" +
previousYearEnd,
"--context_param Host_Analytics_Transaction_Flag=" +
transactionFlag,
"--context_param Host_Analytics_Summary_Flag=" + summaryFlag,
"--context_param Host_Analytics_Project_Flag=" + projectFlag };
talendJob.runJob(context);
}
}`

Related

Maven Surefire does not give correct test counts when executing Spock tests in parallel

My project contains a series of Groovy integration test scripts for a few APIs. Previously, these tests executed concurrently and took up to 3 hours to execute. I was able to reduce this time to just 5 minutes by using Spock's parallel execution feature.
The new problem is that the Maven Surefire reports no longer give the correct test counts for each test suite. The total test count is correct (more or less), but Surefire is mixing up which tests go in which report.
Here is my pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.dsg.payments</groupId>
<artifactId>e2e</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>This will be used to execute normal credit card End2End test cases</description>
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<build-helper-maven-plugin.version>3.1.0</build-helper-maven-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-surefire-plugin.version>3.0.0-M3</maven-surefire-plugin.version>
<gmavenplus-plugin.version>1.11.0</gmavenplus-plugin.version>
<swagger-annotations-version>1.6.0</swagger-annotations-version>
<groovy.version>3.0.7</groovy.version>
<spock.version>2.0-M4-groovy-3.0</spock.version>
</properties>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>${groovy.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>${spock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>0.15</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<testSourceDirectory>${project.basedir}/src/test/groovy</testSourceDirectory>
<resources>
<resource>
<directory>src/test/groovy</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/groovy</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<!-- Groovy compiler -->
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>${gmavenplus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>addTestSources</goal>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Java compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- Unit Tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<includes>
<include>**/*.java</include>
</includes>
<skipTests>false</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here is an example of a test class
package com.dsg.payments.e2e.creditcard
import com.dsg.payments.paygate.ApiClient
import com.dsg.payments.paygate.api.AuthorizationApi
import com.dsg.payments.paygate.model.PaygateAuthorizationRequest
import com.dsg.payments.paygate.model.PaygateAuthorizationResponse
import com.dsg.payments.paygate.model.PaygateEncryptedCardTenderResult
import org.junit.Test
import org.springframework.http.HttpStatus
import org.springframework.web.client.HttpClientErrorException
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Title
import spock.lang.Unroll
import util.Constants
import util.CreditCardType
import util.EntityFactory
#Title("CreditCard-Authorization")
class Authorization extends Specification {
// Constants
#Shared
private static final applicationName = Constants.APPLICATION_NAME
#Shared
private static final referer = Constants.REFERER
#Shared
private static final basePath = Constants.BASE_PATH
#Shared
private AuthorizationApi authorizationApi
def setupSpec() {
// Setup ApiClient to make requests to stage AN01
ApiClient authApiClient = new ApiClient()
authApiClient.setBasePath(basePath)
authorizationApi = new AuthorizationApi(authApiClient)
}
#Test
#Unroll
def "Auth request with valid #cardType card returns authorized response"(CreditCardType cardType) {
when:
PaygateAuthorizationResponse authorizationResponse = authorizationApi.authorize(applicationName, EntityFactory.getPaygateAuthorizationRequest(cardType), referer)
PaygateEncryptedCardTenderResult tenderResult = authorizationResponse.getTenderResults().getEncryptedCardTenderResults().get(0)
then:
// No exception thrown by authorization api client means successful 201 response
authorizationResponse != null
where:
cardType << [
CreditCardType.VISA_Credit_1,
CreditCardType.VISA_Debit,
CreditCardType.VISA_Commercial_Debit,
CreditCardType.VISA_Commercial_Credit,
CreditCardType.VISA_Purchasing_Credit,
CreditCardType.VISA_3DS_Not_Enrolled,
CreditCardType.DISCOVER,
CreditCardType.AMERICANEXPRESS_1,
CreditCardType.MASTERCARD_Debit,
CreditCardType.MASTERCARD_Credit,
CreditCardType.MASTERCARD_Premium_Credit,
CreditCardType.DINERS,
CreditCardType.JAPANCREDITBUREAU
]
}
#Test
#Unroll
def "Auth request with valid cvv for #cardType returns cvv response M"(CreditCardType cardType) {
when:
PaygateAuthorizationResponse authorizationResponse = authorizationApi.authorize(applicationName, EntityFactory.getPaygateAuthorizationRequest(cardType), referer)
PaygateEncryptedCardTenderResult tenderResult = authorizationResponse.getTenderResults().getEncryptedCardTenderResults().get(0)
then:
// No exception thrown by authorization api client means successful 201 response
authorizationResponse != null
tenderResult.getCvvResponse() == "M" // Raw CVV result code for "match"
where:
cardType << [
CreditCardType.VISA_Credit_2,
CreditCardType.VISA_Debit,
CreditCardType.VISA_Commercial_Debit,
CreditCardType.VISA_Commercial_Credit,
CreditCardType.VISA_Purchasing_Credit,
CreditCardType.VISA_3DS_Not_Enrolled,
CreditCardType.DISCOVER,
CreditCardType.AMERICANEXPRESS_2,
CreditCardType.MASTERCARD_Debit,
CreditCardType.MASTERCARD_Credit,
CreditCardType.MASTERCARD_Premium_Credit,
CreditCardType.DINERS,
CreditCardType.JAPANCREDITBUREAU
]
}
// ...
}
There are 3 more test classes (Capture, Refund, and Cancel) with a similar structure that use the #Unroll annotation to re-run the same test with different credit card numbers.
Interestingly, when using Spock parallel execution, Surefire adds an extra test to the report for each test method - one for each credit card and an additional test for the method itself. This is not a huge problem in itself, but it is less than ideal. The real problem is that the Surefire report mixes the classes together (for example, Capture tests end up in the Refund, Cancel, or Authorization reports). This makes it hard to tell from the report which tests failed.
I'll also include my SpockConfig.groovy, which configures the parallel execution:
runner {
filterStackTrace false
optimizeRunOrder true
parallel {
enabled true
dynamic(4.0)
}
}
It has taken much trial and error to get the pom in a state where the tests are all executing correctly in parallel fashion. This is the only combination of dependencies, plugins, and versions that works so far. The only thing that is wrong are the Surefire reports. Any ideas what I am missing?
First: I notice the surefire version in the POM shown is 3.0.0-M3. The mvnrepository.com maven-surefire-plugin list shows the latest is 3.0.0-M5 and a lot of the changes in the newer versions appear to be report related.
Second: check the Maven output log to see if the maven-surefire-report-plugin is being used. If it's there, ensure it is using the same version of Surefire as was used to run the tests. You can do that by adding this to the POM:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
You may not be using Failsafe for integration tests yet, but it's a good idea to keep the Surefire family of plugins using the same version. So when I need to adjust Surefire version, I set them all in the hope of saving someone future troubleshooting pain.

How to instantiate groovy.sql.Sql with parameters from spring datasource setup from test application.yml in a SpringBoot application test context?

I have a SpringBoot maven project, and it has a repository related jar sub-module, which stores the DB related executions, the repository classes with JdbcTemplate and etc.
I want to test the database with Spock Groovy.
This is my pom.xml:
...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<!-- Spock Dependencies -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-spring</artifactId>
<scope>test</scope>
</dependency>
<!-- enables mocking of classes (in addition to interfaces) -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<scope>test</scope>
</dependency>
<!-- enables mocking of classes without default constructor (together with CGLIB) -->
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy.modules.http-builder</groupId>
<artifactId>http-builder</artifactId>
<scope>test</scope>
</dependency>
<!-- Spock End -->
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Spec.*</include>
<include>**/*Test.*</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
This is the application.yml from test/resources:
spring:
datasource:
platform: sqlserver
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://localhost;databaseName=mydatabase;integratedSecurity=true
server:
address: 127.0.0.1
port: 9000
This is the application config in main/java/mypackage:
#Configuration
#ComponentScan
#EnableAutoConfiguration
public class RepositoryConfig {
}
This is the groovy test spec which should setup the groovy.sql.Sql:
#SpringBootTest(classes = RepositoryConfig.class, webEnvironment = WebEnvironment.MOCK)
#Configuration
#EnableConfigurationProperties
#Transactional
class BaseSpringBootTestSpec extends Specification {
String url
String username
String password
String driverClassName
protected groovy.sql.Sql sql
def setup() {
sql = groovy.sql.Sql.newInstance(url, username, password, driverClassName)
}
def cleanup() {
sql.close()
}
}
But here I get NullPointerException because the properties are all null (url, driverClassName, etc).
And I don't know how to get them from yml properties in text context.
Any idea? Thanks.
Blockquote
You're never telling Spring to actually inject those values. Adding #Value annotations to your fields should fix your problem. E.g.:
#Value("#{spring.datasource.url}")
String url
Probably easiest to use theSql.newInstance(...) constructor, passing along a DataSource automatically injected from your Spring Boot config.
#Autowired
DataSource apexDatasoure
...And later when you want to perform some Sql:
Sql.newInstance(apexDatasoure).with { db ->
...
}

CAS Maven Overlay And Spring Boot do not work together

I create a spring boot application from spring.io, then add CAS dependecy to pom file of project as below.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.apereo.cas</groupId>
<artifactId>cas-server-webapp</artifactId>
<version>${cas.version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<overlays>
<overlay>
<groupId>org.apereo.cas</groupId>
<artifactId>cas-server-webapp</artifactId>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
after that start spring boot application, but CAS does not start in spring boot application.
what is the main problem in this usage of CAS?
Is the method of using the CAS at this way wrong?
_____________________________________________________________
finaly I solve my problem. I change the pom file as below
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<javaparser-core.version>3.12.0</javaparser-core.version>
<start.class>org.apereo.cas.web.CasWebApplication</start.class>
<start.class2>x.y.sso.SingleSignOnApplication</start.class2>
<h2.version>1.4.197</h2.version>
<cas.version>6.0.1</cas.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apereo.cas</groupId>
<artifactId>cas-server-webapp-tomcat</artifactId>
<version>${cas.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.github.javaparser</groupId>
<artifactId>javaparser-core</artifactId>
<version>${javaparser-core.version}</version>
</dependency>
<dependency>
<groupId>org.apereo.cas</groupId>
<artifactId>cas-server-core-configuration</artifactId>
<version>${cas.version}</version>
</dependency>
<dependency>
<groupId>org.apereo.cas</groupId>
<artifactId>cas-server-core-configuration</artifactId>
<version>${cas.version}</version>
</dependency>
</dependencies>
<build>
<finalName>cas</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start.class2}</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!--<recompressZippedFiles>false</recompressZippedFiles>-->
<archive>
<compress>false</compress>
<manifestFile>
${project.build.directory}/war/work/org.apereo.cas/cas-server-webapp-tomcat/META-INF/MANIFEST.MF
</manifestFile>
</archive>
<overlays>
<overlay>
<groupId>org.apereo.cas</groupId>
<artifactId>cas-server-webapp-tomcat</artifactId>
</overlay>
</overlays>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
then I create a Application class
#EnableDiscoveryClient
#SpringBootApplication(exclude = {
HibernateJpaAutoConfiguration.class,
JerseyAutoConfiguration.class,
JmxAutoConfiguration.class,
DataSourceAutoConfiguration.class,
DataSourceHealthIndicatorAutoConfiguration.class,
RedisAutoConfiguration.class,
MongoAutoConfiguration.class,
MongoDataAutoConfiguration.class,
CassandraAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
RedisRepositoriesAutoConfiguration.class})
#EnableConfigurationProperties({CasConfigurationProperties.class})
#EnableAsync
#EnableTransactionManagement(proxyTargetClass = true)
#EnableScheduling
public class SingleSignOnApplication {
public static void main(String[] args) {
SpringApplication.run(SingleSignOnApplication.class, args);
}
}
by this configuration, build maven goal and execution project by spring boot work correctly.
CAS is already a spring boot web application. Therefor have a look into cas-server-webapp-init-6.0.1.jar and look CasWebApplication.java.
#EnableDiscoveryClient
#SpringBootApplication(exclude={HibernateJpaAutoConfiguration.class, JerseyAutoConfiguration.class, GroovyTemplateAutoConfiguration.class, JmxAutoConfiguration.class, DataSourceAutoConfiguration.class, DataSourceHealthIndicatorAutoConfiguration.class, RedisAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class, CassandraAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, RedisRepositoriesAutoConfiguration.class})
#EnableConfigurationProperties({CasConfigurationProperties.class})
#EnableAsync
#EnableTransactionManagement(proxyTargetClass=true)
#EnableScheduling
public class CasWebApplication
{
public static void main(String[] args)
{
Map<String, Object> properties = CasEmbeddedContainerUtils.getRuntimeProperties(Boolean.TRUE);
Banner banner = CasEmbeddedContainerUtils.getCasBannerInstance();
new SpringApplicationBuilder(new Class[] { CasWebApplication.class })
.banner(banner)
.web(WebApplicationType.SERVLET)
.properties(properties)
.logStartupInfo(true)
.contextClass(CasWebApplicationContext.class)
.run(args);
}
}
Remove the spring-boot-starter dependencies and CAS should start itself as a web application.
For further investigation I would recommend you to download the war from https://search.maven.org/artifact/org.apereo.cas/cas-server-webapp/6.0.1/war and inspect it with a tool like jd-gui.

Maven/ TestNg can't find allure #step annotation

Having a problem to implement allure #Step annotation into my maven project (tetsng, java).
(Updated) Sharing pom file:
eproject xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>src</groupId>
<artifactId>AutomationTestSuit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.11.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src\main\resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src\test\resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<suiteXmlFiles>
<file>${project.basedir}/suites/smoke.xml</file>
</suiteXmlFiles>
<systemPropertyVariables>
<environment.properties>/environment.properties</environment.properties>
</systemPropertyVariables>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.1/aspectjweaver-1.9.1.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>e
I'm trying to add Step annotation to the page class but it gets the failure:
package com.pages.login_page;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
public class LoginPageElements {
private WebDriver driver;
#FindBy(how = How.ID, using = "test")
private WebElement logonID;
#FindBy(how = How.ID, using = "test")
private WebElement logonPassword;
#FindBy(how = How.ID, using = "test")
private WebElement logonSubmit;
public LoginPageElements(WebDriver driver)
{
this.driver = driver;
PageFactory.initElements(driver,this);
}
#Step("login step") //step is underlined on this place with can't resolve symbol Step error
public void Login_as(String sUsername, String sPassword) {
logonID.sendKeys(sUsername);
logonPassword.sendKeys(sPassword);
logonSubmit.click();
}
#Step error example
the same problem I'm having with #Attachments while implementing it inside of MytestListener class:
see the screenshot
Please help me to figure out the problem.
I noticed that you are using out dated version of Allure. Here is correct import
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.6.0</version>
</dependency>
With Allure 2 you do not need to configure Listener, but you need to configure AspectJ instead. Here you can find example for Maven + TestNG: https://docs.qameta.io/allure/#_testng
THE PROBLEM was with the idea community version. It appears that it doesn't support aspectj plugin. If someone will struggle with same issue please tale a look: https://www.jetbrains.com/help/idea/java-compiler.html
I my case the problem was in <scope>test</scope>.
I removed it from dependancy:
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>LAST_VERSION</version>
<scope>test</scope>
</dependency>
and #Step annotation starts to be recognized.

Get console output an screenshot attached to allure report- selenium webdriver, testng, maven

I am using allure reporting. My report is generated correctly, but i screenshots and console output is not attached to report.
Here is my pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testproject</groupId>
<artifactId>tests</artifactId>
<version>0.1-SNAPSHOT</version>
<properties>
<aspectj.version>1.8.10</aspectj.version>
</properties>
<dependencies>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.0-BETA14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.16</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.16</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Please find screenshot attached of
It shows status pass/fail/broken and time taken to run test. But console output is not attached to it. Also screenshots for failed test cases are stored in folder surefire-reports/screenshots. I need to attach them too to allure reports.Can someone please help in knowing what i need to add to get this output?
Thanks!!
I am assuming that you are getting the failure screenshot using TestNG listener and you have access to the testNG listener. Else see how to create a TestNG listener (http://testng.org/doc/documentation-main.html#listeners-testng-xml) by overriding the TestListenerAdapter.
It seems you can create a method like the following for saving screenshot
#Attachment(value = "Page screenshot", type = "image/png")
public byte[] saveScreenshot() {
// Use selenium screenshot code to take screenshot and convert into byte[]
return byte[];
}
You can then call this method in your testNG listener used to take screenshot on test failure.
#Override
public void onTestFailure(ITestResult testResult) {
saveScreenshot();
super.onTestFailure(testResult);
}
For getting the console output to report, create the following method
#Attachment
public String logOutput(List<String> outputList) {
String output = "";
for (String o : outputList)
output += o + "<br/>";
return output
}
Call the method onTest(success, failure, skip) and onConfiguration (success, failure, skip) in the testNG listener
#Override
public void onTestSuccess(ITestResult testResult) {
// Reporter.getOutput(testResult)will give the output logged in testng reporter
logOutput(Reporter.getOutput(testResult));
super.onTestSuccess(testResult);
}
https://github.com/allure-framework/allure1/wiki/Attachments

Resources