Integration for Java
Build configuration
Find the latest release of the Keploy Java SDK at maven central and add keploy-sdk as a dependency to your
pom.xml
:<dependency> <groupId>io.keploy</groupId> <artifactId>keploy-sdk</artifactId> <version>1.0.13</version> <!-- use latest release --> </dependency>
Sync dependencies or to build.gradle:
compile 'io.keploy:keploy-sdk:1.0.13'
Install Keploy Jar
Download the latest jar from here (eg: 1.2.6) to mock external/internal dependency calls like DB queries, GMaps, S3 etc..
Add the jar into the
main
directoryAdd
-javaagent:
prefix with absolute classpath of Keploy jar downloaded above(For example:
-javaagent:/Users/jhon/project/src/main/agent-1.2.5.jar
)You can set this through 3 ways:-
Using Intellij
Go to
Edit Configuration
->add VM options
-> paste-javaagent:/Users/jhon/project/src/main/agent-1.2.5.jar
->OK
.Using Command Line
export JAVA_OPTS="$JAVA_OPTS -javaagent:/Users/jhon/project/src/main/agent-1.2.5.jar"
Running via Tomcat Server
export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/Users/jhon/project/src/main/agent-1.2.5.jar"
Supported Frameworks
For Spring based application
Add
@Import(KeployMiddleware.class)
below@SpringBootApplication
in your main class.... import io.keploy.servlet.KeployMiddleware; ... @SpringBootApplication @Import(KeployMiddleware.class) public class SamplesJavaApplication { public static void main(String[] args) { ... } }
For Java EE application
Specify the below filter above all other filters and servlets in the web.xml file.
<filter> <filter-name>middleware</filter-name> <filter-class>io.keploy.servlet.KeployMiddleware</filter-class> </filter> <filter-mapping> <filter-name>middleware</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Configure Environment Variables (optional)
APP_NAME
(default APP_NAME = myApp)APP_PORT
(default APP_PORT = 6789)KEPLOY_URL
(default KEPLOY_URL = http://localhost:6789/api)KEPLOY_MODE
(default KEPLOY_MODE = record/test)KTESTS_PATH
(default test directory of your application)DENOISE
(default DENOISE = false) Note: By enabling denoise, it will filter out noisy fields for that testcases.