BAEL-554 - JUnit test that run server and clients (#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
This commit is contained in:
parent
d260fb2ad6
commit
afee31e081
@ -31,5 +31,29 @@
|
|||||||
<artifactId>hessian</artifactId>
|
<artifactId>hessian</artifactId>
|
||||||
<version>4.0.38</version>
|
<version>4.0.38</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>remoting-hessian-burlap-server</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- test -->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -0,0 +1,73 @@
|
|||||||
|
package com.baeldung.client;
|
||||||
|
|
||||||
|
import com.baeldung.api.Booking;
|
||||||
|
import com.baeldung.api.BookingException;
|
||||||
|
import com.baeldung.api.CabBookingService;
|
||||||
|
import com.baeldung.server.Server;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import static java.lang.Thread.sleep;
|
||||||
|
|
||||||
|
@SpringBootTest(classes = {BurlapClient.class, HessianClient.class})
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
public class CabBookingServiceTest {
|
||||||
|
|
||||||
|
static Logger log = LoggerFactory.getLogger(CabBookingServiceTest.class);
|
||||||
|
@Autowired @Qualifier("burlapInvoker") CabBookingService burlapClient;
|
||||||
|
@Autowired @Qualifier("hessianInvoker") CabBookingService hessianClient;
|
||||||
|
static Thread serverThread;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void startServer() throws InterruptedException {
|
||||||
|
serverThread = serverThread();
|
||||||
|
log.info("Starting server.");
|
||||||
|
serverThread.start();
|
||||||
|
sleep(4000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.junit.Test
|
||||||
|
public void bookACabWithBurlapClient() throws InterruptedException {
|
||||||
|
bookACab(this.burlapClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.junit.Test
|
||||||
|
public void bookACabWithHessianClient() throws InterruptedException {
|
||||||
|
bookACab(this.hessianClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bookACab(CabBookingService burlapClient) {
|
||||||
|
Booking booking;
|
||||||
|
try {
|
||||||
|
booking = burlapClient.bookRide("Duomo place");
|
||||||
|
log.info("Booking success: {}", booking);
|
||||||
|
} catch (BookingException e) {
|
||||||
|
log.info("Booking failed: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void stopServer() throws InterruptedException {
|
||||||
|
serverThread.interrupt();
|
||||||
|
serverThread.join();
|
||||||
|
log.info("Server terminated.");
|
||||||
|
}
|
||||||
|
|
||||||
|
static Thread serverThread() {
|
||||||
|
Thread serverThread = new Thread(()-> {
|
||||||
|
log.info("Starting Burlap and Hessian server");
|
||||||
|
Server.main(new String[]{});
|
||||||
|
log.info("Burlap and Hessian server terminated");
|
||||||
|
});
|
||||||
|
serverThread.setDaemon(true);
|
||||||
|
return serverThread;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
application.properties=9999
|
@ -15,7 +15,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>spring-remoting-http-server</artifactId>
|
<artifactId>spring-remoting-http-server</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user