Checkpoint: Added Update (edit) action; Load definition from JSON

This commit is contained in:
Darin Kelkhoff
2022-03-01 18:29:59 -06:00
parent 200a0b7ccf
commit 154468bdf3
8 changed files with 807 additions and 186 deletions

View File

@ -198,10 +198,11 @@ class QPicoCliImplementationTest
TestOutput testOutput = testCli("person", "query", "--skip=1", "--limit=2", "--criteria", "id NOT_EQUALS 3");
JSONObject queryResult = JsonUtils.toJSONObject(testOutput.getOutput());
assertNotNull(queryResult);
assertEquals(2, queryResult.getJSONArray("records").length());
JSONArray records = queryResult.getJSONArray("records");
assertEquals(2, records.length());
// query for id != 3, and skipping 1, expect to get back rows 2 & 4
assertEquals(2, queryResult.getJSONArray("records").getJSONObject(0).getInt("primaryKey"));
assertEquals(4, queryResult.getJSONArray("records").getJSONObject(1).getInt("primaryKey"));
assertEquals(2, records.getJSONObject(0).getJSONObject("values").getInt("id"));
assertEquals(4, records.getJSONObject(1).getJSONObject("values").getInt("id"));
}
@ -232,7 +233,7 @@ class QPicoCliImplementationTest
JSONObject insertResult = JsonUtils.toJSONObject(testOutput.getOutput());
assertNotNull(insertResult);
assertEquals(1, insertResult.getJSONArray("records").length());
assertEquals(6, insertResult.getJSONArray("records").getJSONObject(0).getInt("primaryKey"));
assertEquals(6, insertResult.getJSONArray("records").getJSONObject(0).getJSONObject("values").getInt("id"));
}
@ -256,7 +257,7 @@ class QPicoCliImplementationTest
JSONObject insertResult = JsonUtils.toJSONObject(testOutput.getOutput());
assertNotNull(insertResult);
assertEquals(1, insertResult.getJSONArray("records").length());
assertEquals(6, insertResult.getJSONArray("records").getJSONObject(0).getInt("primaryKey"));
assertEquals(6, insertResult.getJSONArray("records").getJSONObject(0).getJSONObject("values").getInt("id"));
assertEquals("Chester", insertResult.getJSONArray("records").getJSONObject(0).getJSONObject("values").getString("firstName"));
assertEquals("Cheese", insertResult.getJSONArray("records").getJSONObject(0).getJSONObject("values").getString("lastName"));
}
@ -287,8 +288,8 @@ class QPicoCliImplementationTest
assertNotNull(insertResult);
JSONArray records = insertResult.getJSONArray("records");
assertEquals(2, records.length());
assertEquals(6, records.getJSONObject(0).getInt("primaryKey"));
assertEquals(7, records.getJSONObject(1).getInt("primaryKey"));
assertEquals(6, insertResult.getJSONArray("records").getJSONObject(0).getJSONObject("values").getInt("id"));
assertEquals(7, insertResult.getJSONArray("records").getJSONObject(1).getJSONObject("values").getInt("id"));
assertEquals("Charlie", records.getJSONObject(0).getJSONObject("values").getString("firstName"));
assertEquals("Bear", records.getJSONObject(0).getJSONObject("values").getString("lastName"));
assertEquals("Coco", records.getJSONObject(1).getJSONObject("values").getString("firstName"));
@ -323,8 +324,8 @@ class QPicoCliImplementationTest
assertNotNull(insertResult);
JSONArray records = insertResult.getJSONArray("records");
assertEquals(2, records.length());
assertEquals(6, records.getJSONObject(0).getInt("primaryKey"));
assertEquals(7, records.getJSONObject(1).getInt("primaryKey"));
assertEquals(6, insertResult.getJSONArray("records").getJSONObject(0).getJSONObject("values").getInt("id"));
assertEquals(7, insertResult.getJSONArray("records").getJSONObject(1).getJSONObject("values").getInt("id"));
assertEquals("Louis", records.getJSONObject(0).getJSONObject("values").getString("firstName"));
assertEquals("Willikers", records.getJSONObject(0).getJSONObject("values").getString("lastName"));
assertEquals("Nestle", records.getJSONObject(1).getJSONObject("values").getString("firstName"));
@ -333,6 +334,56 @@ class QPicoCliImplementationTest
/*******************************************************************************
** test running an update w/o specifying any fields, prints usage
**
*******************************************************************************/
@Test
public void test_tableUpdateNoFieldsPrintsUsage()
{
TestOutput testOutput = testCli("person", "update");
assertTestOutputContains(testOutput, "Usage: " + CLI_NAME + " person update");
}
/*******************************************************************************
** test running an update w/ fields as arguments
**
*******************************************************************************/
@Test
public void test_tableUpdateFieldArguments() throws Exception
{
assertRowValueById("person", "first_name", "Garret", 5);
TestOutput testOutput = testCli("person", "update",
"--primaryKey=5",
"--field-firstName=Lucy",
"--field-lastName=Lu");
JSONObject updateResult = JsonUtils.toJSONObject(testOutput.getOutput());
assertNotNull(updateResult);
assertEquals(1, updateResult.getJSONArray("records").length());
assertEquals(5, updateResult.getJSONArray("records").getJSONObject(0).getJSONObject("values").getInt("id"));
assertRowValueById("person", "first_name", "Lucy", 5);
}
private void assertRowValueById(String tableName, String columnName, String value, Integer id) throws Exception
{
TestUtils.runTestSql("SELECT " + columnName + " FROM " + tableName + " WHERE id=" + id, (rs -> {
if(rs.next())
{
assertEquals(value, rs.getString(1));
}
else
{
fail("Row not found");
}
}));
}
/*******************************************************************************
** test running a delete against a table
**
@ -343,9 +394,10 @@ class QPicoCliImplementationTest
TestOutput testOutput = testCli("person", "delete", "--primaryKey", "2,4");
JSONObject deleteResult = JsonUtils.toJSONObject(testOutput.getOutput());
assertNotNull(deleteResult);
assertEquals(2, deleteResult.getJSONArray("records").length());
assertEquals(2, deleteResult.getJSONArray("records").getJSONObject(0).getInt("primaryKey"));
assertEquals(4, deleteResult.getJSONArray("records").getJSONObject(1).getInt("primaryKey"));
JSONArray records = deleteResult.getJSONArray("records");
assertEquals(2, records.length());
assertEquals(2, records.getJSONObject(0).getJSONObject("values").getInt("id"));
assertEquals(4, records.getJSONObject(1).getJSONObject("values").getInt("id"));
TestUtils.runTestSql("SELECT id FROM person", (rs -> {
int rowsFound = 0;
while(rs.next())

View File

@ -9,13 +9,13 @@ import java.io.InputStream;
import java.sql.Connection;
import java.util.List;
import com.kingsrook.qqq.backend.core.model.metadata.QAuthenticationMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.QCodeType;
import com.kingsrook.qqq.backend.core.model.metadata.QCodeUsage;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.QFieldType;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.QTableMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QFunctionInputMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QFunctionMetaData;

View File

@ -0,0 +1,156 @@
{
"authentication": {
"name": "mock",
"type": "mock",
"values": null
},
"tables": {
"person": {
"name": "person",
"label": "Person",
"backendName": "default",
"primaryKeyField": "id",
"fields": {
"id": {
"name": "id",
"label": null,
"backendName": null,
"type": "INTEGER",
"possibleValueSourceName": null
},
"createDate": {
"name": "createDate",
"label": null,
"backendName": null,
"type": "DATE_TIME",
"possibleValueSourceName": null
},
"modifyDate": {
"name": "modifyDate",
"label": null,
"backendName": null,
"type": "DATE_TIME",
"possibleValueSourceName": null
},
"firstName": {
"name": "firstName",
"label": null,
"backendName": null,
"type": "STRING",
"possibleValueSourceName": null
},
"lastName": {
"name": "lastName",
"label": null,
"backendName": null,
"type": "STRING",
"possibleValueSourceName": null
},
"birthDate": {
"name": "birthDate",
"label": null,
"backendName": null,
"type": "DATE",
"possibleValueSourceName": null
},
"email": {
"name": "email",
"label": null,
"backendName": null,
"type": "STRING",
"possibleValueSourceName": null
},
"homeState": {
"name": "homeState",
"label": null,
"backendName": null,
"type": "STRING",
"possibleValueSourceName": "state"
}
}
}
},
"possibleValueSources": {
"state": {
"name": "state",
"type": "ENUM",
"enumValues": [
"IL",
"MO"
]
}
},
"processes": {
"greet": {
"name": "greet",
"tableName": "person",
"functionList": [
{
"name": "prepare",
"label": null,
"inputMetaData": {
"recordListMetaData": {
"tableName": "person",
"fields": null
},
"fieldList": [
{
"name": "greetingPrefix",
"label": null,
"backendName": null,
"type": "STRING",
"possibleValueSourceName": null
},
{
"name": "greetingSuffix",
"label": null,
"backendName": null,
"type": "STRING",
"possibleValueSourceName": null
}
]
},
"outputMetaData": {
"recordListMetaData": {
"tableName": "person",
"fields": {
"fullGreeting": {
"name": "fullGreeting",
"label": null,
"backendName": null,
"type": "STRING",
"possibleValueSourceName": null
}
}
},
"fieldList": [
{
"name": "outputMessage",
"label": null,
"backendName": null,
"type": "STRING",
"possibleValueSourceName": null
}
]
},
"code": {
"name": "com.kingsrook.qqq.backend.core.interfaces.mock.MockFunctionBody",
"codeType": "JAVA",
"codeUsage": "FUNCTION"
},
"outputView": {
"messageField": "outputMessage",
"recordListView": {
"fieldNames": [
"id",
"firstName",
"lastName",
"fullGreeting"
]
}
}
}
]
}
}
}

View File

@ -0,0 +1,163 @@
{
"tables": {
"person": {
"primaryKeyField": "id",
"name": "person",
"backendName": "default",
"label": "Person",
"fields": {
"firstName": {
"name": "firstName",
"backendName": null,
"label": null,
"type": "STRING",
"possibleValueSourceName": null
},
"lastName": {
"name": "lastName",
"backendName": null,
"label": null,
"type": "STRING",
"possibleValueSourceName": null
},
"modifyDate": {
"name": "modifyDate",
"backendName": null,
"label": null,
"type": "DATE_TIME",
"possibleValueSourceName": null
},
"homeState": {
"name": "homeState",
"backendName": null,
"label": null,
"type": "STRING",
"possibleValueSourceName": "state"
},
"id": {
"name": "id",
"backendName": null,
"label": null,
"type": "INTEGER",
"possibleValueSourceName": null
},
"birthDate": {
"name": "birthDate",
"backendName": null,
"label": null,
"type": "DATE",
"possibleValueSourceName": null
},
"email": {
"name": "email",
"backendName": null,
"label": null,
"type": "STRING",
"possibleValueSourceName": null
},
"createDate": {
"name": "createDate",
"backendName": null,
"label": null,
"type": "DATE_TIME",
"possibleValueSourceName": null
}
}
}
},
"processes": {
"greet": {
"functionList": [
{
"code": {
"codeUsage": "FUNCTION",
"codeType": "JAVA",
"name": "com.kingsrook.qqq.backend.core.interfaces.mock.MockFunctionBody"
},
"inputMetaData": {
"recordListMetaData": {
"fields": null,
"tableName": "person"
},
"fieldList": [
{
"name": "greetingPrefix",
"backendName": null,
"label": null,
"type": "STRING",
"possibleValueSourceName": null
},
{
"name": "greetingSuffix",
"backendName": null,
"label": null,
"type": "STRING",
"possibleValueSourceName": null
}
]
},
"outputMetaData": {
"recordListMetaData": {
"fields": {
"fullGreeting": {
"name": "fullGreeting",
"backendName": null,
"label": null,
"type": "STRING",
"possibleValueSourceName": null
}
},
"tableName": "person"
},
"fieldList": [
{
"name": "outputMessage",
"backendName": null,
"label": null,
"type": "STRING",
"possibleValueSourceName": null
}
]
},
"outputView": {
"messageField": "outputMessage",
"recordListView": {
"fieldNames": [
"id",
"firstName",
"lastName",
"fullGreeting"
]
}
},
"name": "prepare",
"label": null
}
],
"name": "greet",
"tableName": "person"
}
},
"possibleValueSources": {
"state": {
"name": "state",
"type": "ENUM",
"enumValues": [
"IL",
"MO"
]
}
},
"backends": {
"default": {
"values": null,
"name": "default",
"type": "mock"
}
},
"authentication": {
"values": null,
"name": "mock",
"type": "mock"
}
}

View File

@ -0,0 +1,70 @@
{
"tables": {
"series": {
"primaryKeyField": "id",
"name": "series",
"backendName": "wherenooneMysql",
"label": "Person",
"fields": {
"name": {
"name": "name",
"backendName": null,
"label": null,
"type": "STRING",
"possibleValueSourceName": null
},
"abbreviation": {
"name": "abbreviation",
"backendName": null,
"label": null,
"type": "STRING",
"possibleValueSourceName": null
},
"id": {
"name": "id",
"backendName": null,
"label": null,
"type": "INTEGER",
"possibleValueSourceName": null
},
"createDate": {
"name": "createDate",
"backendName": "create_date",
"label": "Create Date",
"type": "DATE_TIME",
"possibleValueSourceName": null
},
"modifyDate": {
"name": "modifyDate",
"backendName": "modify_date",
"label": "Modify Date",
"type": "DATE_TIME",
"possibleValueSourceName": null
}
}
}
},
"processes": {
},
"possibleValueSources": {
},
"backends": {
"wherenooneMysql": {
"values": {
"vendor": "mysql",
"hostName": "localhost",
"port": "3306",
"databaseName": "wherenoone",
"username": "root",
"password": "password"
},
"name": "wherenooneMysql",
"type": "rdbms"
}
},
"authentication": {
"values": null,
"name": "mock",
"type": "mock"
}
}