Skip to content

Commit 79f1f9a

Browse files
Ruben NoguerolesRuben Nogueroles
Ruben Nogueroles
authored and
Ruben Nogueroles
committed
First commit
1 parent 826403e commit 79f1f9a

22 files changed

+643
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target/
2+
*/target/**

pom.xml

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.wizeline</groupId>
6+
<artifactId>karateproject</artifactId>
7+
<version>1.0</version>
8+
<packaging>jar</packaging>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<java.version>1.8</java.version>
13+
<maven.compiler.version>3.8.1</maven.compiler.version>
14+
<maven.surefire.version>2.22.2</maven.surefire.version>
15+
<karate.version>1.2.0</karate.version>
16+
<cucumber.reporting.version>5.7.1</cucumber.reporting.version>
17+
<spring.jdbc.version>5.3.20</spring.jdbc.version>
18+
<mysql.connector.java.version>8.0.29</mysql.connector.java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>com.intuit.karate</groupId>
24+
<artifactId>karate-junit5</artifactId>
25+
<version>${karate.version}</version>
26+
<scope>test</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>net.masterthought</groupId>
30+
<artifactId>cucumber-reporting</artifactId>
31+
<version>${cucumber.reporting.version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework</groupId>
35+
<artifactId>spring-jdbc</artifactId>
36+
<version>${spring.jdbc.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>mysql</groupId>
40+
<artifactId>mysql-connector-java</artifactId>
41+
<version>${mysql.connector.java.version}</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.apache.commons</groupId>
45+
<artifactId>commons-lang3</artifactId>
46+
<version>3.12.0</version>
47+
</dependency>
48+
</dependencies>
49+
50+
<build>
51+
<testResources>
52+
<testResource>
53+
<directory>src/test/java</directory>
54+
<excludes>
55+
<exclude>**/*.java</exclude>
56+
</excludes>
57+
</testResource>
58+
</testResources>
59+
<plugins>
60+
<plugin>
61+
<groupId>org.apache.maven.plugins</groupId>
62+
<artifactId>maven-compiler-plugin</artifactId>
63+
<version>${maven.compiler.version}</version>
64+
<configuration>
65+
<encoding>UTF-8</encoding>
66+
<source>${java.version}</source>
67+
<target>${java.version}</target>
68+
<compilerArgument>-Werror</compilerArgument>
69+
</configuration>
70+
</plugin>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-surefire-plugin</artifactId>
74+
<version>${maven.surefire.version}</version>
75+
<configuration>
76+
<argLine>-Dfile.encoding=UTF-8</argLine>
77+
</configuration>
78+
</plugin>
79+
</plugins>
80+
</build>
81+
82+
</project>

src/.DS_Store

6 KB
Binary file not shown.

src/test/.DS_Store

6 KB
Binary file not shown.

src/test/java/.DS_Store

6 KB
Binary file not shown.

src/test/java/helpers/.DS_Store

6 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package helpers.JavaFiles;
2+
3+
import org.apache.commons.lang3.RandomStringUtils;
4+
import java.util.Random;
5+
6+
public class DataGenerator {
7+
8+
/**
9+
* Creates a random string whose length is from 1 up to 100 characters.
10+
* Characters will be chosen from the set of all characters.
11+
* @return the random string
12+
*/
13+
public static String getRandomString(){
14+
15+
Random random = new Random();
16+
return RandomStringUtils.random(1+random.nextInt(100));
17+
18+
}
19+
20+
/**
21+
* Creates a random string whose length is the number of characters specified.
22+
* Characters will be chosen from the set of all characters.
23+
* @param count the length of random string to create
24+
* @return the random string
25+
*/
26+
public static String getRandomString(int count){
27+
28+
return RandomStringUtils.random(count);
29+
30+
}
31+
32+
/**
33+
* Creates a random string whose length is from 1 up to 100 characters.
34+
* Characters will be chosen from the set of Latin alphabetic characters (a-z, A-Z).
35+
* @param count the length of random string to create
36+
* @return the random string
37+
*/
38+
public static String getRandomAlphabeticString(){
39+
40+
Random random = new Random();
41+
return RandomStringUtils.randomAlphabetic(1+random.nextInt(100));
42+
43+
}
44+
45+
/**
46+
* Creates a random string whose length is the number of characters specified.
47+
* Characters will be chosen from the set of Latin alphabetic characters (a-z, A-Z).
48+
* @param count the length of random string to create
49+
* @return the random string
50+
*/
51+
public static String getRandomAlphabeticString(int count){
52+
53+
return RandomStringUtils.randomAlphabetic(count);
54+
55+
}
56+
57+
/**
58+
* Creates a random string whose length is from 1 up to 100 characters.
59+
* Characters will be chosen from the set of Latin alphabetic characters (a-z, A-Z) and the digits 0-9.
60+
* @return the random string
61+
*/
62+
public static String getRandomAlphaNumericString(){
63+
64+
Random random = new Random();
65+
return RandomStringUtils.randomAlphanumeric(1+random.nextInt(100));
66+
67+
}
68+
69+
/**
70+
* Creates a random string whose length is the number of characters specified.
71+
* Characters will be chosen from the set of Latin alphabetic characters (a-z, A-Z) and the digits 0-9.
72+
* @param count the length of random string to create
73+
* @return the random string
74+
*/
75+
public static String getRandomAlphaNumericString(int count){
76+
77+
return RandomStringUtils.randomAlphanumeric(count);
78+
79+
}
80+
81+
/**
82+
* Creates a random string whose length is from 1 up to 100 characters.
83+
* Characters will be chosen from the set of numeric characters.
84+
* @return the random string
85+
*/
86+
public static String getRandomNumericString(){
87+
88+
Random random = new Random();
89+
return RandomStringUtils.randomNumeric(random.nextInt(100));
90+
91+
}
92+
93+
/**
94+
* Creates a random string whose length is the number of characters specified.
95+
* Characters will be chosen from the set of numeric characters.
96+
* @param count the length of random string to create
97+
* @return the random string
98+
*/
99+
public static String getRandomNumericString(int count){
100+
101+
return RandomStringUtils.randomNumeric(count);
102+
103+
}
104+
105+
/**
106+
* Creates a random string following an email format.
107+
* @return the random email
108+
*/
109+
public static String getRandomEmail(){
110+
111+
return RandomStringUtils.randomAlphanumeric(10)+"@"+RandomStringUtils.randomAlphanumeric(10)+".com";
112+
113+
}
114+
115+
/**
116+
* Creates a random Password whose length is 12 characters.
117+
* @return the random password
118+
*/
119+
public static String getRandomPassword(){
120+
121+
Random random = new Random();
122+
return RandomStringUtils.random(random.nextInt(12));
123+
124+
}
125+
126+
/**
127+
* Creates a random phone number with 9 digits.
128+
* @return the randonm phone number
129+
*/
130+
public static String getRandomPhoneNumber(){
131+
132+
return getRandomNumericString(9);
133+
134+
}
135+
136+
137+
138+
139+
140+
141+
142+
143+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package helpers.JavaFiles;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.jdbc.core.JdbcTemplate;
6+
import org.springframework.jdbc.datasource.DriverManagerDataSource;
7+
8+
import java.util.List;
9+
import java.util.Map;
10+
11+
public class DbUtils {
12+
13+
private static final Logger logger = LoggerFactory.getLogger(DbUtils.class);
14+
15+
private final JdbcTemplate jdbc;
16+
17+
private static DbUtils dbUtils;
18+
19+
public static DbUtils getInstance(Map<String, Object> config) {
20+
if (dbUtils==null) {
21+
dbUtils= new DbUtils(config);
22+
}
23+
return dbUtils;
24+
}
25+
26+
private DbUtils(Map<String, Object> config) {
27+
String url = (String) config.get("url");
28+
String username = (String) config.get("username");
29+
String password = (String) config.get("password");
30+
String driver = (String) config.get("driverClassName");
31+
DriverManagerDataSource dataSource = new DriverManagerDataSource();
32+
dataSource.setDriverClassName(driver);
33+
dataSource.setUrl(url);
34+
dataSource.setUsername(username);
35+
dataSource.setPassword(password);
36+
jdbc = new JdbcTemplate(dataSource);
37+
logger.info("init jdbc template: {}", url);
38+
39+
}
40+
41+
/**
42+
* Returns a specific single value from the datatable
43+
* @param query sql sentence that you want to execute
44+
* @return the concrete value
45+
*/
46+
public Object readValue(String query) {
47+
return jdbc.queryForObject(query, Object.class);
48+
}
49+
50+
/**
51+
* Returns one row from the database
52+
* @param query sql sentence that you want to execute
53+
* @return Object that contains data result
54+
*/
55+
public Map<String, Object> readRow(String query) {
56+
return jdbc.queryForMap(query);
57+
}
58+
59+
/**
60+
* Returns multiple rows from the datatable
61+
* @param query sql sentence that you want to execute
62+
* @return list that contains the results
63+
*/
64+
public List<Map<String, Object>> readRows(String query) {
65+
return jdbc.queryForList(query);
66+
}
67+
68+
/**
69+
* Execute an 'insert into' sql sentence
70+
* @param sql sql sentence that you want to execute
71+
*/
72+
public void insertRows(final String sql){
73+
jdbc.batchUpdate(new String[]{sql});
74+
}
75+
76+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
//Validation date format function
3+
function fn(s) {
4+
var SimpleDateFormat = Java.type("java.text.SimpleDateFormat");
5+
var sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.ms'Z'");
6+
try {
7+
sdf.parse(s).time;
8+
return true;
9+
} catch(e) {
10+
karate.log('*** invalid date string:', s);
11+
return false;
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"id": "#number",
3+
"order": "##number",
4+
"color": "#number",
5+
"name": "#string",
6+
"comment_count": "#number",
7+
"shared": "#boolean",
8+
"favorite": "#boolean",
9+
"sync_id": "#number",
10+
"inbox_project": "##boolean",
11+
"url": "#string"
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"id": "#number",
3+
"assigner": "#number",
4+
"project_id": "#number",
5+
"section_id": "#number",
6+
"parent": "##number",
7+
"parent_id": "##number",
8+
"order": "#number",
9+
"content": "#string",
10+
"description": "#string",
11+
"completed": "#boolean",
12+
"label_ids": "#array",
13+
"priority": "#number",
14+
"comment_count": "#number",
15+
"creator": "#number",
16+
"created": "#? isValidTime(_)",
17+
"due": "##object",
18+
"url": "#string"
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"date": "#string",
3+
"string": "#string",
4+
"lang": "#string",
5+
"recurring": "#boolean"
6+
}

src/test/java/karate-config.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function fn() {
2+
var env = karate.properties['karate.env']; // get system property 'karate.env'
3+
var database = karate.properties['karate.database']; // get system property 'karate.database'
4+
karate.log('karate.env system property was:', env);
5+
karate.log('karate.database system property was:', database);
6+
if (!env) {
7+
env = 'dev';
8+
}
9+
var config = {
10+
11+
}
12+
13+
//Config to use Demo examples
14+
config.apiUrl= 'https://api.todoist.com/rest/v1/';
15+
config.auth = '[yourBearerToken]';
16+
//Connection string database
17+
config.dbConfig = { username: 'root', password: '', url: 'jdbc:mysql://localhost:3306/[yourDbName]', driverClassName: 'com.mysql.cj.jdbc.Driver' }
18+
//Adding auth - use it only when it will be needed e.g to execute Demo examples
19+
karate.configure('headers', {Authorization: config.auth})
20+
21+
return config;
22+
}

src/test/java/karateProject/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)