Skip to content

Commit fcbd867

Browse files
Sarthak160nehagup
andauthored
feat: add steps to run keploy in karaf (#484)
* feat: add steps to run keploy in karaf Signed-off-by: Sarthak Shyngle <[email protected]> * refactor: update the karaf steps Signed-off-by: Sarthak160 <[email protected]> * refactor: update the karaf steps Signed-off-by: Sarthak160 <[email protected]> * refactor: update the karaf steps Signed-off-by: Sarthak160 <[email protected]> --------- Signed-off-by: Sarthak Shyngle <[email protected]> Signed-off-by: Sarthak160 <[email protected]> Co-authored-by: Neha Gupta <[email protected]>
1 parent b7dadf6 commit fcbd867

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
id: keploy-karaf-example
3+
title: Keploy Karaf Example
4+
sidebar_label: Keploy Karaf Example
5+
description: This section documents how to run keploy with Karaf
6+
tags:
7+
- keploy
8+
- keploy karaf
9+
keywords:
10+
- keploy
11+
- documentation
12+
- running-guide
13+
---
14+
15+
# Setting Up Keploy Agent in Apache Karaf for Local Development
16+
17+
Follow these steps to set up and run the Keploy agent in Apache Karaf for your local development environment.
18+
19+
---
20+
21+
## Step 1: Download Required JARs
22+
23+
Use `wget` to download the necessary JAR files:
24+
25+
- [java-agent-1.0-SNAPSHOT.jar](https://keploy-enterprise.s3.us-west-2.amazonaws.com/agent-jars/java-agent-1.0-SNAPSHOT.jar)
26+
- [org.jacoco.agent-0.8.12-runtime.jar](https://keploy-enterprise.s3.us-west-2.amazonaws.com/agent-jars/org.jacoco.agent-0.8.12-runtime.jar)
27+
28+
Run the following commands to download the files:
29+
30+
```bash
31+
wget https://keploy-enterprise.s3.us-west-2.amazonaws.com/agent-jars/java-agent-1.0-SNAPSHOT.jar
32+
wget https://keploy-enterprise.s3.us-west-2.amazonaws.com/agent-jars/org.jacoco.agent-0.8.12-runtime.jar
33+
```
34+
35+
---
36+
37+
## Step 2: Configure Apache Karaf
38+
39+
### Update `JAVA_OPTS` for linux/mac in `setenv` File
40+
41+
1. Navigate to the `bin` directory of your Apache Karaf installation.
42+
2. Open the `setenv` file for editing.
43+
3. Add the paths of the downloaded agents under the `JAVA_OPTS` section. For example:
44+
45+
```bash
46+
export JAVA_OPTS="-javaagent:/path/to/java-agent-1.0-SNAPSHOT.jar"
47+
export JAVA_OPTS="$JAVA_OPTS -javaagent:/path/to/org.jacoco.agent-0.8.12-runtime.jar=address=*,port=36320,destfile=jacoco-it.exec,output=tcpserver"
48+
```
49+
50+
### Update `JAVA_OPTS` for windows in `setenv.bat` File
51+
52+
1. Navigate to the `bin` directory of your Apache Karaf installation.
53+
2. Open the `setenv.bat` file for editing.
54+
3. Add the paths of the downloaded agents under the `JAVA_OPTS` section. For example:
55+
56+
```bash
57+
set JAVA_OPTS=-javaagent:/path/to/java-agent-1.0-SNAPSHOT.jar
58+
set JAVA_OPTS=%JAVA_OPTS% -javaagent:/path/to/org.jacoco.agent-0.8.12-runtime.jar=address=*,port=36320,destfile=jacoco-it.exec,output=tcpserver
59+
```
60+
61+
Replace `/path/to/` with the actual paths where you downloaded the JAR files.
62+
63+
### Update `config.properties`
64+
65+
1. Navigate to the `etc/config.properties` file in your Karaf installation.
66+
2. Add the following entry under the `bootdelegation` section to allow OSGi bundles to access Keploy artifacts:
67+
68+
```properties
69+
org.osgi.framework.bootdelegation = \
70+
com.sun.*, \
71+
javax.transaction, \
72+
javax.transaction.xa, \
73+
javax.xml.crypto, \
74+
javax.xml.crypto.*, \
75+
javax.security.cert, \
76+
jdk.nashorn.*, \
77+
sun.*, \
78+
jdk.internal.reflect, \
79+
jdk.internal.reflect.*, \
80+
org.apache.karaf.jaas.boot, \
81+
org.apache.karaf.jaas.boot.principal, \
82+
io.keploy.*
83+
```
84+
85+
---
86+
87+
## Step 3: Start Apache Karaf and Export Environment Variables
88+
89+
1. Start Apache Karaf by navigating to the `bin` directory and running:
90+
91+
```bash
92+
./karaf
93+
```
94+
95+
2. Export the API key required for Keploy to function by running the following command in the same terminal session:
96+
97+
```bash
98+
export API_KEY="<API_KEY>"
99+
```
100+
101+
Replace the `API_KEY` value with your actual API key if different.
102+
103+
3. Export the application path to point to your target folder containing Java classes:
104+
105+
```bash
106+
export APP_PATH="/Users/sarthak_1/Downloads/karaf-sample/user-service"
107+
```
108+
109+
Replace the `APP_PATH` value with the absolute path to your application's target folder.
110+
111+
---
112+
113+
## Step 4: Import Postman Collection
114+
115+
1. Ensure you have a Postman collection ready for your application.
116+
2. Run the following command to import the Postman collection as Keploy tests:
117+
118+
```bash
119+
keploy import postman --path="/path/to/YourPostmanCollection.json"
120+
```
121+
122+
Replace `/path/to/YourPostmanCollection.json` with the actual path to your Postman collection.
123+
124+
---
125+
126+
## Step 5: Run Keploy Tests
127+
128+
Use the following command to run the imported tests:
129+
130+
```bash
131+
keploy test --base-path="http://localhost:8181"
132+
```
133+
134+
This assumes your Karaf application is running locally on port 8181.
135+
136+
After running the tests, a `coverage.xml` file will be generated in the root directory of your project. This file contains the test coverage report, which can be used for further analysis or integrated with CI/CD pipelines.

0 commit comments

Comments
 (0)