Skip to content

Commit b7432c5

Browse files
committed
Add basic vagrant/rspec/spark integration testing harness.
1 parent 357a803 commit b7432c5

File tree

22 files changed

+1098
-1
lines changed

22 files changed

+1098
-1
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
.gradle/*
2-
build/*
2+
build/*
3+
example-app/build/*
4+
example-app/.gradle/*
5+
.DS_Store

Gemfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source "https://rubygems.org"
2+
3+
gem 'redis'
4+
gem 'rspec'
5+
gem 'httparty'

Gemfile.lock

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
diff-lcs (1.2.5)
5+
httparty (0.12.0)
6+
json (~> 1.8)
7+
multi_xml (>= 0.5.2)
8+
json (1.8.1)
9+
multi_xml (0.5.5)
10+
redis (3.1.0)
11+
rspec (3.1.0)
12+
rspec-core (~> 3.1.0)
13+
rspec-expectations (~> 3.1.0)
14+
rspec-mocks (~> 3.1.0)
15+
rspec-core (3.1.4)
16+
rspec-support (~> 3.1.0)
17+
rspec-expectations (3.1.1)
18+
diff-lcs (>= 1.2.0, < 2.0)
19+
rspec-support (~> 3.1.0)
20+
rspec-mocks (3.1.1)
21+
rspec-support (~> 3.1.0)
22+
rspec-support (3.1.0)
23+
24+
PLATFORMS
25+
ruby
26+
27+
DEPENDENCIES
28+
httparty
29+
redis
30+
rspec

example-app/build.gradle

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apply plugin: 'java'
2+
apply plugin: 'war'
3+
4+
version = '0.1'
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
providedCompile group: 'org.apache.tomcat', name: 'tomcat-catalina', version: '7.0.27'
12+
compile group: 'redis.clients', name: 'jedis', version: '2.5.2'
13+
compile group: 'com.sparkjava', name: 'spark-core', version: '1.1.1'
14+
compile group: 'com.google.code.gson', name: 'gson', version: '2.3'
15+
compile group: 'org.slf4j', name: 'slf4j-simple',version: '1.7.5'
16+
providedCompile project(":tomcat-redis-session-manager")
17+
}
18+
19+
war {
20+
//webAppDirName = 'source/main/'
21+
22+
//from 'src/rootContent' // adds a file-set to the root of the archive
23+
//webInf { from 'src/additionalWebInf' } // adds a file-set to the WEB-INF dir.
24+
//classpath fileTree('additionalLibs') // adds a file-set to the WEB-INF/lib dir.
25+
//classpath configurations.moreLibs // adds a configuration to the WEB-INF/lib dir.
26+
}

example-app/settings.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include ":tomcat-redis-session-manager"
2+
project(":tomcat-redis-session-manager").projectDir = new File(rootDir, "../")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.orangefunction.tomcatredissessionmanager.exampleapp;
2+
3+
import com.google.gson.Gson;
4+
import com.radiadesign.catalina.session.RedisSession;
5+
import java.util.HashMap;
6+
import java.util.Collections;
7+
import spark.ResponseTransformerRoute;
8+
import spark.Session;
9+
import javax.servlet.http.HttpSession;
10+
11+
public abstract class JsonTransformerRoute extends ResponseTransformerRoute {
12+
13+
private Gson gson = new Gson();
14+
15+
protected JsonTransformerRoute(String path) {
16+
super(path);
17+
}
18+
19+
protected JsonTransformerRoute(String path, String acceptType) {
20+
super(path, acceptType);
21+
}
22+
23+
@Override
24+
public String render(Object jsonObject) {
25+
return gson.toJson(jsonObject);
26+
}
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.orangefunction.tomcatredissessionmanager.exampleapp;
2+
3+
import com.google.gson.Gson;
4+
import com.radiadesign.catalina.session.RedisSession;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
import java.util.Collections;
8+
import spark.ResponseTransformerRoute;
9+
import spark.Session;
10+
import javax.servlet.http.HttpSession;
11+
12+
public abstract class SessionJsonTransformerRoute extends ResponseTransformerRoute {
13+
14+
private Gson gson = new Gson();
15+
16+
protected SessionJsonTransformerRoute(String path) {
17+
super(path);
18+
}
19+
20+
protected SessionJsonTransformerRoute(String path, String acceptType) {
21+
super(path, acceptType);
22+
}
23+
24+
@Override
25+
public String render(Object object) {
26+
if (object instanceof Object[]) {
27+
Object[] tuple = (Object[])object;
28+
Session sparkSession = (Session)tuple[0];
29+
HttpSession session = (HttpSession)(sparkSession).raw();
30+
HashMap<String, Object> map = new HashMap<String, Object>();
31+
map.putAll((Map<String, Object>)tuple[1]);
32+
map.put("sessionId", session.getId());
33+
return gson.toJson(map);
34+
} else if (object instanceof Session) {
35+
Session sparkSession = (Session)object;
36+
HashMap<String, Object> sessionMap = new HashMap<String, Object>();
37+
if (null != sparkSession) {
38+
HttpSession session = (HttpSession)(sparkSession).raw();
39+
sessionMap.put("sessionId", session.getId());
40+
HashMap<String, Object> attributesMap = new HashMap<String, Object>();
41+
for (String key : Collections.list(session.getAttributeNames())) {
42+
attributesMap.put(key, session.getAttribute(key));
43+
}
44+
sessionMap.put("attributes", attributesMap);
45+
}
46+
return gson.toJson(sessionMap);
47+
} else {
48+
return "{}";
49+
}
50+
}
51+
52+
}

0 commit comments

Comments
 (0)