Skip to content

Commit

Permalink
Modify CI test env
Browse files Browse the repository at this point in the history
  • Loading branch information
sczyh30 committed Aug 8, 2016
1 parent 5ef1a4f commit fa71639
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
@@ -1,4 +1,10 @@
language: java

jdk:
- oraclejdk8
- oraclejdk8

services:
- mysql

before_script:
- mysql -e 'CREATE DATABASE IF NOT EXISTS microservice_test;' -uroot
@@ -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));
}

}
7 changes: 6 additions & 1 deletion pom.xml
Expand Up @@ -123,7 +123,12 @@
<version>1.7.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down

0 comments on commit fa71639

Please sign in to comment.