You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2018/07/26 14:56:54 UTC
[sling-whiteboard] 01/06: Karate skeleton, from mvn archetype
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
commit 63c34606841a1bb1fb7c6f1f2c92037f8551700a
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Jul 26 16:05:50 2018 +0200
Karate skeleton, from mvn archetype
---
literate-http-testing/karate/pom.xml | 56 ++++++++++++++++++++++
.../src/test/java/examples/ExamplesTest.java | 11 +++++
.../src/test/java/examples/users/UsersRunner.java | 9 ++++
.../src/test/java/examples/users/users.feature | 54 +++++++++++++++++++++
.../karate/src/test/java/karate-config.js | 18 +++++++
.../karate/src/test/java/logback-test.xml | 24 ++++++++++
6 files changed, 172 insertions(+)
diff --git a/literate-http-testing/karate/pom.xml b/literate-http-testing/karate/pom.xml
new file mode 100644
index 0000000..8c17fba
--- /dev/null
+++ b/literate-http-testing/karate/pom.xml
@@ -0,0 +1,56 @@
+<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>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.httptesting.karate</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <java.version>1.8</java.version>
+ <maven.compiler.version>3.6.0</maven.compiler.version>
+ <karate.version>0.8.0</karate.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.intuit.karate</groupId>
+ <artifactId>karate-apache</artifactId>
+ <version>${karate.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.intuit.karate</groupId>
+ <artifactId>karate-junit4</artifactId>
+ <version>${karate.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <testResources>
+ <testResource>
+ <directory>src/test/java</directory>
+ <excludes>
+ <exclude>**/*.java</exclude>
+ </excludes>
+ </testResource>
+ </testResources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${maven.compiler.version}</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <source>${java.version}</source>
+ <target>${java.version}</target>
+ <compilerArgument>-Werror</compilerArgument>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/literate-http-testing/karate/src/test/java/examples/ExamplesTest.java b/literate-http-testing/karate/src/test/java/examples/ExamplesTest.java
new file mode 100644
index 0000000..7dc66d0
--- /dev/null
+++ b/literate-http-testing/karate/src/test/java/examples/ExamplesTest.java
@@ -0,0 +1,11 @@
+package examples;
+
+import com.intuit.karate.junit4.Karate;
+import org.junit.runner.RunWith;
+
+@RunWith(Karate.class)
+public class ExamplesTest {
+ // this will run all *.feature files that exist in sub-directories
+ // refer to https://github.com/intuit/karate#naming-conventions
+ // for folder-structure recommendations and naming conventions
+}
\ No newline at end of file
diff --git a/literate-http-testing/karate/src/test/java/examples/users/UsersRunner.java b/literate-http-testing/karate/src/test/java/examples/users/UsersRunner.java
new file mode 100644
index 0000000..02992f4
--- /dev/null
+++ b/literate-http-testing/karate/src/test/java/examples/users/UsersRunner.java
@@ -0,0 +1,9 @@
+package examples.users;
+
+import com.intuit.karate.junit4.Karate;
+import org.junit.runner.RunWith;
+
+@RunWith(Karate.class)
+public class UsersRunner {
+
+}
\ No newline at end of file
diff --git a/literate-http-testing/karate/src/test/java/examples/users/users.feature b/literate-http-testing/karate/src/test/java/examples/users/users.feature
new file mode 100644
index 0000000..ddba1d0
--- /dev/null
+++ b/literate-http-testing/karate/src/test/java/examples/users/users.feature
@@ -0,0 +1,54 @@
+Feature: sample karate test script
+ If you are using Eclipse, install the free Cucumber-Eclipse plugin from
+ https://cucumber.io/cucumber-eclipse/
+ Then you will see syntax-coloring for this file. But best of all,
+ you will be able to right-click within this file and [Run As -> Cucumber Feature].
+ If you see warnings like "does not have a matching glue code",
+ go to the Eclipse preferences, find the 'Cucumber User Settings'
+ and enter the following Root Package Name: com.intuit.karate
+ Refer to the Cucumber-Eclipse wiki for more: http://bit.ly/2mDaXeV
+
+Background:
+* url 'https://jsonplaceholder.typicode.com'
+
+Scenario: get all users and then get the first user by id
+
+Given path 'users'
+When method get
+Then status 200
+
+* def first = response[0]
+
+Given path 'users', first.id
+When method get
+Then status 200
+
+Scenario: create a user and then get it by id
+
+* def user =
+"""
+{
+ "name": "Test User",
+ "username": "testuser",
+ "email": "test@user.com",
+ "address": {
+ "street": "Has No Name",
+ "suite": "Apt. 123",
+ "city": "Electri",
+ "zipcode": "54321-6789"
+ }
+}
+"""
+
+Given url 'https://jsonplaceholder.typicode.com/users'
+And request user
+When method post
+Then status 201
+
+* def id = response.id
+* print 'created id is: ' + id
+
+Given path id
+# When method get
+# Then status 200
+# And match response contains user
\ No newline at end of file
diff --git a/literate-http-testing/karate/src/test/java/karate-config.js b/literate-http-testing/karate/src/test/java/karate-config.js
new file mode 100644
index 0000000..1c5e763
--- /dev/null
+++ b/literate-http-testing/karate/src/test/java/karate-config.js
@@ -0,0 +1,18 @@
+function() {
+ var env = karate.env; // get system property 'karate.env'
+ karate.log('karate.env system property was:', env);
+ if (!env) {
+ env = 'dev';
+ }
+ var config = {
+ env: env,
+ myVarName: 'someValue'
+ }
+ if (env == 'dev') {
+ // customize
+ // e.g. config.foo = 'bar';
+ } else if (env == 'e2e') {
+ // customize
+ }
+ return config;
+}
\ No newline at end of file
diff --git a/literate-http-testing/karate/src/test/java/logback-test.xml b/literate-http-testing/karate/src/test/java/logback-test.xml
new file mode 100644
index 0000000..fea195e
--- /dev/null
+++ b/literate-http-testing/karate/src/test/java/logback-test.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>target/karate.log</file>
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="com.intuit" level="DEBUG"/>
+
+ <root level="info">
+ <appender-ref ref="STDOUT" />
+ <appender-ref ref="FILE" />
+ </root>
+
+</configuration>
\ No newline at end of file