Added delete

This commit is contained in:
Darin Kelkhoff
2021-11-30 18:09:53 -06:00
parent 6fbf3563dd
commit c2fbca18a7
3 changed files with 68 additions and 2 deletions

View File

@ -16,6 +16,8 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -98,6 +100,7 @@ class QJavalinImplementationTest
}
/*******************************************************************************
**
*******************************************************************************/
@ -106,7 +109,7 @@ class QJavalinImplementationTest
{
HttpResponse<String> response = Unirest.get(BASE_URL + "/metaData/notAnActualTable").asString();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, response.getStatus()); // todo 404?
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
assertEquals(1, jsonObject.keySet().size(), "Number of top-level keys");
String error = jsonObject.getString("error");
@ -137,6 +140,7 @@ class QJavalinImplementationTest
}
/*******************************************************************************
**
*******************************************************************************/
@ -186,4 +190,33 @@ class QJavalinImplementationTest
assertTrue(values0.has("firstName"));
assertEquals("Bobby", values0.getString("firstName"));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
public void test_dataDelete() throws Exception
{
HttpResponse<String> response = Unirest.delete(BASE_URL + "/data/person/3")
.header("Content-Type", "application/json")
.asString();
assertEquals(200, response.getStatus());
JSONObject jsonObject = JsonUtils.toJSONObject(response.getBody());
assertNotNull(jsonObject);
assertEquals(1, jsonObject.getJSONArray("records").length());
assertEquals(3, jsonObject.getJSONArray("records").getJSONObject(0).getInt("primaryKey"));
TestUtils.runTestSql("SELECT id FROM person", (rs -> {
int rowsFound = 0;
while(rs.next())
{
rowsFound++;
assertFalse(rs.getInt(1) == 3);
}
assertEquals(4, rowsFound);
}));
}
}

View File

@ -41,6 +41,18 @@ public class TestUtils
/*******************************************************************************
**
*******************************************************************************/
public static void runTestSql(String sql, QueryManager.ResultSetProcessor resultSetProcessor) throws Exception
{
ConnectionManager connectionManager = new ConnectionManager();
Connection connection = connectionManager.getConnection(new RDBSMBackendMetaData(defineBackend()));
QueryManager.executeStatement(connection, sql, resultSetProcessor);
}
/*******************************************************************************
**
*******************************************************************************/