@Before public void beforeTest() { f.clearTestTables(); Database testDb = Fixtures.createTestDatabase(); f.insertDatabase(testDb); RestAssured.basePath = "/" + testDb.name(); }
/** Tests that the PUT /{databases}/{table} endpoint properly updates a table. */ @Test public void putTableTest() { Table testTable = Fixtures.createTestTable(); f.insertTable(testTable); String newDesciption = "this is a new description"; String tableStr = "{" + "\"description\" : \"" + newDesciption + "\"," + "\"name\" : \"" + testTable.name() + "\"}"; // act given().body(tableStr).expect().statusCode(204).when().put(testTable.name()); // check expect() .statusCode(200) .body("name", equalTo(testTable.name())) .body("description", equalTo(newDesciption)) .body("createdAt", notNullValue()) .body("updatedAt", notNullValue()) .when() .get(testTable.name()); }
/** Tests that the DELETE /{databases}/{table} endpoint properly deletes a table. */ @Test public void deleteTableTest() { Table testTable = Fixtures.createTestTable(); f.insertTable(testTable); // act given().expect().statusCode(204).when().delete(testTable.name()); // check expect().statusCode(404).when().get(testTable.name()); }
/** Tests that the GET /{databases}/{table} properly retrieves an existing table. */ @Test public void getTableTest() { Table testTable = Fixtures.createTestTable(); f.insertTable(testTable); expect() .statusCode(200) .body("name", equalTo(testTable.name())) .body("description", equalTo(testTable.description())) .body("createdAt", notNullValue()) .body("updatedAt", notNullValue()) .when() .get(testTable.name()); }
/** Tests that the POST /{databases}/{table} endpoint properly creates a table. */ @Test public void postTableTest() { Table testTable = Fixtures.createTestTable(); String tableStr = "{" + "\"description\" : \"" + testTable.description() + "\"," + "\"name\" : \"" + testTable.name() + "\"}"; // act given() .body(tableStr) .expect() .statusCode(201) // .header("Location", startsWith(RestAssured.basePath + "/")) .body("name", equalTo(testTable.name())) .body("description", equalTo(testTable.description())) .body("createdAt", notNullValue()) .body("updatedAt", notNullValue()) .when() .post(testTable.name()); // check expect() .statusCode(200) .body("name", equalTo(testTable.name())) .body("description", equalTo(testTable.description())) .body("createdAt", notNullValue()) .body("updatedAt", notNullValue()) .when() .get(testTable.name()); }
/** Cleanup that is performed after each test is executed. */ @After public void afterTest() { f.clearTestTables(); }
public TableControllerTest() throws Exception { f = Fixtures.getInstance(false); }