Skip to content

Commit afee31e

Browse files
danidemipivovarit
authored andcommitted
BAEL-554 - JUnit test that run server and clients (eugenp#1233)
* Burlap & Hessian server added * Burlap & Hessian client work * Fixed main * Fixed formatting * Spring Remote example based on Burlap & Hessian runs in a JUnit test * Fixed main * Fixed formatting * Spring Remote example based on Burlap & Hessian runs in a JUnit test
1 parent d260fb2 commit afee31e

4 files changed

Lines changed: 99 additions & 1 deletion

File tree

‎spring-remoting/remoting-hessian-burlap/client/pom.xml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,29 @@
3131
<artifactId>hessian</artifactId>
3232
<version>4.0.38</version>
3333
</dependency>
34+
35+
<!-- test -->
36+
<dependency>
37+
<groupId>${project.groupId}</groupId>
38+
<artifactId>remoting-hessian-burlap-server</artifactId>
39+
<version>${project.version}</version>
40+
<scope>test</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>javax.servlet</groupId>
44+
<artifactId>javax.servlet-api</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-starter-test</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-starter-tomcat</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
<!-- test -->
3458
</dependencies>
3559
</project>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.baeldung.client;
2+
3+
import com.baeldung.api.Booking;
4+
import com.baeldung.api.BookingException;
5+
import com.baeldung.api.CabBookingService;
6+
import com.baeldung.server.Server;
7+
import org.junit.AfterClass;
8+
import org.junit.BeforeClass;
9+
import org.junit.runner.RunWith;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.beans.factory.annotation.Qualifier;
14+
import org.springframework.boot.test.context.SpringBootTest;
15+
import org.springframework.test.context.junit4.SpringRunner;
16+
17+
import static java.lang.Thread.sleep;
18+
19+
@SpringBootTest(classes = {BurlapClient.class, HessianClient.class})
20+
@RunWith(SpringRunner.class)
21+
public class CabBookingServiceTest {
22+
23+
static Logger log = LoggerFactory.getLogger(CabBookingServiceTest.class);
24+
@Autowired @Qualifier("burlapInvoker") CabBookingService burlapClient;
25+
@Autowired @Qualifier("hessianInvoker") CabBookingService hessianClient;
26+
static Thread serverThread;
27+
28+
@BeforeClass
29+
public static void startServer() throws InterruptedException {
30+
serverThread = serverThread();
31+
log.info("Starting server.");
32+
serverThread.start();
33+
sleep(4000);
34+
}
35+
36+
@org.junit.Test
37+
public void bookACabWithBurlapClient() throws InterruptedException {
38+
bookACab(this.burlapClient);
39+
}
40+
41+
@org.junit.Test
42+
public void bookACabWithHessianClient() throws InterruptedException {
43+
bookACab(this.hessianClient);
44+
}
45+
46+
private void bookACab(CabBookingService burlapClient) {
47+
Booking booking;
48+
try {
49+
booking = burlapClient.bookRide("Duomo place");
50+
log.info("Booking success: {}", booking);
51+
} catch (BookingException e) {
52+
log.info("Booking failed: {}", e.getMessage());
53+
}
54+
}
55+
56+
@AfterClass
57+
public static void stopServer() throws InterruptedException {
58+
serverThread.interrupt();
59+
serverThread.join();
60+
log.info("Server terminated.");
61+
}
62+
63+
static Thread serverThread() {
64+
Thread serverThread = new Thread(()-> {
65+
log.info("Starting Burlap and Hessian server");
66+
Server.main(new String[]{});
67+
log.info("Burlap and Hessian server terminated");
68+
});
69+
serverThread.setDaemon(true);
70+
return serverThread;
71+
}
72+
73+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
application.properties=9999

‎spring-remoting/remoting-hessian-burlap/server/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<dependency>
1616
<groupId>com.baeldung</groupId>
1717
<artifactId>spring-remoting-http-server</artifactId>
18-
<version>1.0-SNAPSHOT</version>
18+
<version>${project.version}</version>
1919
</dependency>
2020
<dependency>
2121
<groupId>org.springframework.boot</groupId>

0 commit comments

Comments
 (0)