Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
language: java | ||
|
||
jdk: | ||
- oraclejdk8 | ||
- oraclejdk8 | ||
|
||
services: | ||
- mysql | ||
|
||
before_script: | ||
- mysql -e 'CREATE DATABASE IF NOT EXISTS microservice_test;' -uroot |
77 changes: 77 additions & 0 deletions
77
...icroservice/src/test/java/io/vertx/blueprint/microservice/inventory/InventoryApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package io.vertx.blueprint.microservice.inventory; | ||
|
||
import io.restassured.response.Response; | ||
import io.vertx.core.Vertx; | ||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import redis.embedded.RedisServer; | ||
|
||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static io.restassured.RestAssured.*; | ||
import static org.assertj.core.api.Assertions.*; | ||
import static org.hamcrest.Matchers.*; | ||
import static com.jayway.awaitility.Awaitility.await; | ||
import static org.hamcrest.core.Is.is; | ||
|
||
/** | ||
* Test case for {@link InventoryRestAPIVerticle}. | ||
* | ||
* @author Eric Zhao | ||
*/ | ||
public class InventoryApiTest { | ||
|
||
private static RedisServer server; | ||
|
||
private Vertx vertx; | ||
|
||
@BeforeClass | ||
static public void startRedis() throws Exception { | ||
server = new RedisServer(6379); | ||
System.out.println("Created embedded redis server on port 6379"); | ||
server.start(); | ||
} | ||
|
||
@AfterClass | ||
static public void stopRedis() throws Exception { | ||
server.stop(); | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
vertx = Vertx.vertx(); | ||
AtomicBoolean completed = new AtomicBoolean(); | ||
vertx.deployVerticle(new InventoryRestAPIVerticle(), ar -> completed.set(ar.succeeded())); | ||
await().untilAtomic(completed, is(true)); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
AtomicBoolean completed = new AtomicBoolean(); | ||
vertx.close((v) -> completed.set(true)); | ||
await().untilAtomic(completed, is(true)); | ||
} | ||
|
||
@Test | ||
public void testGetAndAdd() throws Exception { | ||
int productId = ThreadLocalRandom.current().nextInt(); | ||
Response response = given().port(8086).get("/inventory/" + productId); | ||
assertThat(response.getStatusCode()).isEqualTo(200); | ||
assertThat(response.asString()).isEqualTo("0"); | ||
|
||
int inc = 10; | ||
response = given().port(8086).put("/inventory/" + productId + "/increase?n=" + inc); | ||
assertThat(response.getStatusCode()).isEqualTo(200); | ||
assertThat(response.asString()).isEqualTo(String.valueOf(inc)); | ||
|
||
int dec = 8; | ||
response = given().port(8086).put("/inventory/" + productId + "/decrease?n=" + dec); | ||
assertThat(response.getStatusCode()).isEqualTo(200); | ||
assertThat(response.asString()).isEqualTo(String.valueOf(inc - dec)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters