Report builder says Cucumber is not a valid report - selenium-webdriver

I have used below code for creating html reports , this code is present in after class of Junit Runner in a cucumber framework , but am getting error saying cucumber.json is not a valid cucumber report. I am assuming that report builder is trying to get the cucumber.json even before it is created completely,
I kept code in cucumber options to create Json file
#CucumberOptions(features = "features/",
glue = { "report"},
format = {"pretty","json:target/cucumber.json"},
tags = {"#testing" }, monochrome = true)
private void generateReportForJsonFiles(File reportOutputDirectory,
List<String> jsonFiles) {
String jenkinsBasePath = "";
String buildNumber = "1";
String projectName = project.getName();
Configuration configuration = new Configuration(reportOutputDirectory, projectName);
configuration.setParallelTesting(false);
configuration.setJenkinsBasePath(jenkinsBasePath);
configuration.setRunWithJenkins(false);
configuration.setBuildNumber(buildNumber);
ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
reportBuilder.generateReports();
}
Below is the error:
File 'target/cucumber.json' is not proper Cucumber report!

you should provide a small example (MCVE) which others can use to reproduce your problem
your code snippet configuration.setParallelTesting(false) and your answer cucumber report version is <version>4.2.0</version> do not match, as the method configuration.setParallelTesting was removed in version 4.1.0
Have a look at this small working snippet (based on the few information you provided).
Assume the following structure
pom.xml
src/main/java/CreateReport.java
src/main/resources/log4j2.properties
src/test/java/TestRunner.java
src/test/java/stepdefs/StepDefinitions.java
src/test/resource/features/demo.feature
pom.xml
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<!--
info.cukes:cucumber-java:1.2.5 is quite old and has been superseded by
io.cucumber:cucumber-java see: https://mvnrepository.com/artifact/io.cucumber/cucumber-java
-->
<version.cucumber>1.2.5</version.cucumber>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
...
CreateReport.java
import java.io.File;
import java.util.Arrays;
import java.util.List;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
public class CreateReport {
private void generateReportForJsonFiles(File reportOutputDirectory, List<String> jsonFiles) {
String buildNumber = "1";
String projectName = "StackOverflow example";
Configuration configuration = new Configuration(reportOutputDirectory, projectName);
configuration.setParallelTesting(false);
// configuration.setJenkinsBasePath(jenkinsBasePath);
configuration.setRunWithJenkins(false);
configuration.setBuildNumber(buildNumber);
ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
reportBuilder.generateReports();
}
public static void main(String[] args) {
new CreateReport().generateReportForJsonFiles(new File("target/"),
Arrays.asList("target/cucumber.json"));
}
}
log4j2.properties
status = info
name = PropertiesConfig
appenders = console
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%level] %m%n
rootLogger.level = info
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
TestRunner.java
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"src/test/resource/features"},
glue = {"stepdefs"},
plugin = {"json:target/cucumber.json"}
)
public class TestRunner {
}
StepDefinitions.java
package stepdefs;
import org.junit.Assert;
import cucumber.api.java.en.Given;
public class StepDefinitions {
#Given("^a successful step$")
public void aSuccessfulStep() throws Throwable {
System.out.println("a successful step");
}
#Given("^a not successful step$")
public void aNotSuccessfulStep() throws Throwable {
System.out.println("a not successful step");
Assert.fail();
}
}
demo.feature
Feature: Test cucumber reporting plugin
Scenario: Run a non failing scenario
Given a successful step
Scenario: Run a failing scenario
Given a not successful step
run the Cucumber test (this creates the target/cucumber.json file)
$ mvn clean test
run the report creator (
$ mvn exec:java -Dexec.mainClass=CreateReport
...
12:55:21 [INFO] --- exec-maven-plugin:1.6.0:java (default-cli) # cuke-test23.so ---
Dec 18, 2018 12:55:22 PM net.masterthought.cucumber.ReportParser parseJsonFiles
INFO: File 'target/cucumber.json' contains 1 features
the report is generated in target/cucumber-html-reports/overview-features.html

Related

Read a csv file in Flink 1.15 using Table API

I'm doing a simple tutorial with flink + java using Table API. What I want to do is really simple - I want to read a csv file from a local filesystem, using a schema and print it out.
The way I'm doing this is this(the code below is compiled from samples from Flink's website tutorial section):
package p1;
import org.apache.flink.table.api.*;
import org.apache.flink.api.java.utils.ParameterTool;
public class CabAggregation {
public static void main(String[] args) throws Exception {
ParameterTool params = ParameterTool.fromArgs(args);
EnvironmentSettings settings = EnvironmentSettings
.newInstance()
.inBatchMode()
.build();
TableEnvironment tableEnv = TableEnvironment.create(settings);
final Schema schema = Schema.newBuilder()
.column("cab_id", DataTypes.INT())
.column("cab_plate", DataTypes.STRING())
.column("cab_make", DataTypes.STRING())
.column("cab_driver", DataTypes.STRING())
.column("active_trip", DataTypes.STRING())
.column("pickup_location", DataTypes.STRING())
.column("target_location", DataTypes.STRING())
.column("num_pass", DataTypes.INT())
.build();
tableEnv.createTemporaryTable("cabs",
TableDescriptor
.forConnector("filesystem")
.schema(schema)
.option("path", "file:///Users/virtual/Downloads/cabs.csv")
.format(FormatDescriptor.forFormat("csv").build())
.build());
Table result = tableEnv.from("cabs").select("*");
result.execute().print();
}
}
Running this gives me this:
Caused by: org.apache.flink.table.api.ValidationException: Could not find any factory for identifier 'filesystem' that implements 'org.apache.flink.table.factories.DynamicTableFactory' in the classpath.
Available factory identifiers are:
blackhole
datagen
print
Now, it seems evident that somehow CSV is not available as a factory identifier. I can't figure out why.
I'm building the project with maven.
You'll be needing these dependencies. Have you added them?
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-files</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-csv</artifactId>
<version>${flink.version}</version>
</dependency>

java.lang.NoClassDefFoundError: feign/Request$Body in feign while adding support for multipart/form-data

I am trying to proxy multipart request via feign.
#PostMapping(value = "{pathUri1}/{pathUri2}",consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<BaseResponse<?>> uploadFileCall(#PathVariable(value = "pathUri1") String pathUri1, #PathVariable(value = "pathUri2") String pathUri2, #RequestPart(name = "file") MultipartFile file, #RequestParam Map<Object,Object> requestParam, #RequestHeader HttpHeaders httpHeaders);
this is service call.
#Configuration
class MultipartSupportConfig {
#Autowired
ObjectFactory<HttpMessageConverters> messageConverters;
#Bean
#Primary
#Scope("prototype")
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}
added encoder config for multipart/form-data .
I have followed this
https://github.com/OpenFeign/feign-form
But I am getting hystrixRunTimeException which is caused because of
java.lang.NoClassDefFoundError: feign/Request$Body error.
Use feign-form-spring 3.4.1 version.
Gradle
compile(group: 'io.github.openfeign.form', name: 'feign-form-spring', version: '3.4.1')
Maven
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>3.4.1</version>
</dependency>
Check requirements https://github.com/OpenFeign/feign-form#requirements
According to the open-feign's github document, Please Note the feign-form's versions:
all feign-form releases before 3.5.0 works with OpenFeign 9.* versions;
starting from feign-form's version 3.5.0, the module works with OpenFeign 10.1.0 versions and greater.
The following config works for me:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
<version>${feign.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
<version>${feign.version}</version>
</dependency>
Where:
<feign.version>11.0</feign.version>
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>

Spring AOP No visible constructors in class

Error: java.lang.IllegalArgumentException: No visible constructors in class org.springframework.hateoas.config.HypermediaSupportBeanDefinitionRegistrar$DefaultObjectMapperCustomizer
Mostly, I used example given in link, and the following code can be found at github repository
Annotation:
#Retention(RetentionPolicy.RUNTIME)
#Target(ElementType.TYPE)
public #interface NeedTestClass {
}
Aspect:
#After("#args(NeedTestClass)")
public void afterReturningAtArgs() {
log.info("aspect: after #args {}");
}
Service:
#Slf4j
#Component
public class BusinessService {
public void logicWithAnnotatedArgs1(Child c) {
log.info("service");
}
}
Pojo (top class, not sub class):
#NoArgsConstructor // tried with or without
#NeedTestClass
public class Child {}
Test:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration
#WebAppConfiguration
#SpringBootTest
public class AopTest {
#Autowired
private BusinessService myBusinessService;
#Test
public void testAtArgsPCD() {
myBusinessService.logicWithAnnotatedArgs1(new Child());
}
I attempted to examine aop and annotated class inheritance, but it seems the first step could not be ok. I have tried #annotation() and this() PCD both ok.
EDIT:
So far I am wondering maybe the error is related with the bean loading sequence.
Your GitHub project does not even compile. Have you even tested it? First by trial and error I had to add all of these dependencies:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.alibaba.druid</groupId>
<artifactId>druid-wrapper</artifactId>
<version>0.2.9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
Next, I noticed that the Maven build does not seem to start the local (127.0.0.1) database because Spring Boot says this at start-up:
(...)
2018-01-02 17:57:18.882 INFO 14480 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited
2018-01-02 17:57:20.007 ERROR 14480 --- [tionPool-Create] com.alibaba.druid.pool.DruidDataSource : create connection error
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:590) ~[mysql-connector-java-6.0.6.jar:6.0.6]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:57) ~[mysql-connector-java-6.0.6.jar:6.0.6]
(...)
Would you mind refactoring your GitHub project into an MCVE first before I can check on your actual problem? This way the error is not reproducible.
But having said this, I did notice something in your POM and Java files: Maybe the problem is not where you think it is. I can see that you want to use Lombok in combination with Spring AOP. According to my answer here, there are compatibility problems between AspectJ and Lombok. Maybe they also affect Spring AOP. So can you temporarily test without #Slf4j and other Lombok stuff? As soon as you will have fixed your project I can also test by myself.
Update after GitHub repo project has been repaired:
Now I can build and run your program, thanks. It seems that the parameter is somehow passed through to internal Spring classes you do not wish to target. So just modify your pointcut like this:
#After("#args(com.example.demosm.my.aop.NeedTestClass) && within(com.example.demosm..*)")

Exception : java.lang.ClassNotFoundException on MS Access Database [duplicate]

I have created an MS Access database and assigned a DSN to it. I want to access it through my Java application.
This is what I am doing:
public class AccessDbConnection {
public static void main(String[] args) {
System.out.println("**ACCESS DB CONNECTION**");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // for MS Access ... MS access driver loading
String conURL = "jdbc:odbc:sampleDNS";
Connection con = DriverManager.getConnection(conURL);
Statement statement = con.createStatement();
String qry = "SELECT * FROM Table1";
ResultSet rs = statement.executeQuery(qry);
while(rs.next()) {
String id = rs.getString("ID") ;
String fname = rs.getString("First_Name");
String lname = rs.getString("Last_Name");
System.out.println(id + fname + lname);
}
} catch (ClassNotFoundException ex) {
System.out.println("Classforname Exception!!");
Logger.getLogger(AccessDbConnection.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
System.out.println("DriverManager Exception!!");
Logger.getLogger(AccessDbConnection.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
I am getting the exception at the first line of try block. That is class.forname("..");. Why am I having this Exception?
For Java 7 you can simply omit the Class.forName() statement as it is not really required.
For Java 8 you cannot use the JDBC-ODBC Bridge because it has been removed. You will need to use something like UCanAccess instead. For more information, see
Manipulating an Access database from Java without ODBC
in JDK 8, jdbc odbc bridge is no longer used and thus removed fro the JDK. to use Microsoft Access database in JAVA, you need 5 extra JAR libraries.
1- hsqldb.jar
2- jackcess 2.0.4.jar
3- commons-lang-2.6.jar
4- commons-logging-1.1.1.jar
5- ucanaccess-2.0.8.jar
add these libraries to your java project and start with following lines.
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://<Path to your database i.e. MS Access DB>");
Statement s = conn.createStatement();
path could be like E:/Project/JAVA/DBApp
and then your query to be executed. Like
ResultSet rs = s.executeQuery("SELECT * FROM Course");
while(rs.next())
System.out.println(rs.getString("Title") + " " + rs.getString("Code") + " " + rs.getString("Credits"));
certain imports to be used. try catch block must be used and some necessary things no to be forgotten.
Remember, no need of bridging drivers like jdbc odbc or any stuff.
Setup:
My OS windows 8 64bit
Eclipse version Standard/SDK Kepler Service Release 2
My JDK is jdk-8u5-windows-i586
My JRE is jre-8u5-windows-i586
This how I overcome my error.
At the very first my Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") also didn't work.
Then I login to this website and downloaded the UCanAccess 2.0.8 zip (as Mr.Gord Thompson said) file and unzip it.
Then you will also able to find these *.jar files in that unzip folder:
ucanaccess-2.0.8.jar
commons-lang-2.6.jar
commons-logging-1.1.1.jar
hsqldb.jar
jackcess-2.0.4.jar
Then what I did was I copied all these 5 files and paste them in these 2 locations:
C:\Program Files (x86)\eclipse\lib
C:\Program Files (x86)\eclipse\lib\ext
(I did that funny thing becoz I was unable to import these libraries to my project)
Then I reopen the eclipse with my project.then I see all that *.jar files in my project's JRE System Library folder.
Finally my code works.
public static void main(String[] args)
{
try
{
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\Hasith\\Documents\\JavaDatabase1.mdb");
Statement stment = conn.createStatement();
String qry = "SELECT * FROM Table1";
ResultSet rs = stment.executeQuery(qry);
while(rs.next())
{
String id = rs.getString("ID") ;
String fname = rs.getString("Nama");
System.out.println(id + fname);
}
}
catch(Exception err)
{
System.out.println(err);
}
//System.out.println("Hasith Sithila");
}
add these dependecies to your .pom file:
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.healthmarketscience.jackcess</groupId>
<artifactId>jackcess-encrypt</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>net.sf.ucanaccess</groupId>
<artifactId>ucanaccess</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
and add to your code to call a driver:
Connection conn = DriverManager.getConnection("jdbc:ucanaccess://{file_location}/{accessdb_file_name.mdb};memory=false");
Make sure you have closed your MSAccess file before running the java program.

Configuring Jetty component in Camel 2.15

I'm trying to start using Jetty with Camel.
I have added the dependency to my pom:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
<version>2.15.5</version>
</dependency>
My CamelContext is initialized as follows:
public void startCamelContext() throws Exception {
CamelContext camelContext = new DefaultCamelContext();
camelContext.addComponent("jetty", new JettyHttpComponent8());
camelContext.start();
}
When I try to start up my service, which has a route with endpoint defined as:
jetty:http://0.0.0.0:9000/httpInput
I get an exception:
java.lang.NullPointerException: null
at org.apache.camel.component.jetty8.JettyHttpComponent8.createConnectorJettyInternal(JettyHttpComponent8.java:48)
at org.apache.camel.component.jetty.JettyHttpComponent.createConnector(JettyHttpComponent.java:585)
at org.apache.camel.component.jetty.JettyHttpComponent.getSocketConnector(JettyHttpComponent.java:527)
at org.apache.camel.component.jetty.JettyHttpComponent.getConnector(JettyHttpComponent.java:517)
at org.apache.camel.component.jetty.JettyHttpComponent.connect(JettyHttpComponent.java:320)
at org.apache.camel.component.http.HttpEndpoint.connect(HttpEndpoint.java:185)
at org.apache.camel.component.http.HttpConsumer.doStart(HttpConsumer.java:53)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:2885)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(DefaultCamelContext.java:3179)
at org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers(DefaultCamelContext.java:3115)
at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3045)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:2813)
at org.apache.camel.impl.DefaultCamelContext.startAllRoutes(DefaultCamelContext.java:865)
The documentation on how to set up the Jetty component is lacking at best. I found a mailing-list entry where it was said that JettyHttpComponent has been made abstract since Camel 2.15 and now that component has to be configured using JettyHttpComponent8 or 9. link
In my case, I'm using Camel 2.15.5 and the JettyHttpComponent9 isn't available in the classpath, and using 8 gives the exception described above.
I also found related discussion here with no information on how to actually use that component.
That's typically not how the CamelContext is initialized/started. Please consider using an archetype to get started, then add the Jetty Maven dependency and see if the error can be reproduced.
Camel archetypes can be found here: http://camel.apache.org/camel-maven-archetypes.html
To start a camel context outside spring you need to create a continuous thread to keep camel alive, as explaine here: http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
Don't worry, I have below some code that will setup a jetty on localhost:8081 for you:
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.16.1</version>
</dependency>
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.main.Main;
import org.apache.camel.main.MainListenerSupport;
import org.apache.camel.main.MainSupport;
import java.util.Date;
/**
* Created by mkbrv on 22/06/16.
*/
public class CamelJetty {
private Main main;
public static void main(String[] args) throws Exception {
CamelJetty example = new CamelJetty();
example.boot();
}
public void boot() throws Exception {
// create a Main instance
main = new Main();
// bind MyBean into the registry
main.bind("foo", new MyBean());
// add routes
main.addRouteBuilder(new MyJettyRouteBuilder());
// add event listener
main.addMainListener(new Events());
// run until you terminate the JVM
System.out.println("Starting Camel. Use ctrl + c to terminate the JVM.\n");
main.run();
}
private static class MyJettyRouteBuilder extends RouteBuilder {
#Override
public void configure() throws Exception {
from("jetty:http://localhost:8081")
.process(exchange -> {
System.out.println("Invoked timer at " + new Date());
exchange.getOut().setBody("Hi, this is Camel!");
})
.bean("foo");
}
}
public static class MyBean {
public void callMe() {
System.out.println("MyBean.callMe method has been called");
}
}
public static class Events extends MainListenerSupport {
#Override
public void afterStart(MainSupport main) {
System.out.println("MainExample with Camel is now started!");
}
#Override
public void beforeStop(MainSupport main) {
System.out.println("MainExample with Camel is now being stopped!");
}
}
}
Next just go to http://localhost:8081 and you should see a welcome message.
Have fun tweaking this further more.

Resources