mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Merge branch 'dev' into feature/CTLE-434-oms-update-business-logic
# Conflicts: # qqq-middleware-api/src/test/java/com/kingsrook/qqq/api/javalin/QJavalinApiHandlerTest.java
This commit is contained in:
@ -33,6 +33,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.kingsrook.qqq.api.actions.ApiImplementation;
|
||||
import com.kingsrook.qqq.api.actions.GenerateOpenApiSpecAction;
|
||||
import com.kingsrook.qqq.api.model.APILog;
|
||||
@ -297,7 +298,7 @@ public class QJavalinApiHandler
|
||||
}
|
||||
|
||||
context.contentType(ContentType.APPLICATION_JSON);
|
||||
context.result(JsonUtils.toJson(rs));
|
||||
context.result(toJson(rs));
|
||||
}
|
||||
|
||||
|
||||
@ -312,7 +313,7 @@ public class QJavalinApiHandler
|
||||
rs.put("currentVersion", apiInstanceMetaData.getCurrentVersion().toString());
|
||||
|
||||
context.contentType(ContentType.APPLICATION_JSON);
|
||||
context.result(JsonUtils.toJson(rs));
|
||||
context.result(toJson(rs));
|
||||
}
|
||||
|
||||
|
||||
@ -655,7 +656,7 @@ public class QJavalinApiHandler
|
||||
Map<String, Serializable> outputRecord = ApiImplementation.get(apiInstanceMetaData, version, tableApiName, primaryKey);
|
||||
|
||||
QJavalinAccessLogger.logEndSuccess();
|
||||
String resultString = JsonUtils.toJson(outputRecord);
|
||||
String resultString = toJson(outputRecord);
|
||||
context.result(resultString);
|
||||
storeApiLog(apiLog.withStatusCode(context.statusCode()).withResponseBody(resultString));
|
||||
}
|
||||
@ -668,6 +669,21 @@ public class QJavalinApiHandler
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Define standard way we'll make JSON objects for the API.
|
||||
**
|
||||
** Specifically, changes QQQ's default to include null values
|
||||
*******************************************************************************/
|
||||
private static String toJson(Object object)
|
||||
{
|
||||
return JsonUtils.toJson(object, mapper ->
|
||||
{
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@ -880,7 +896,7 @@ public class QJavalinApiHandler
|
||||
Map<String, Serializable> output = ApiImplementation.query(apiInstanceMetaData, version, tableApiName, context.queryParamMap());
|
||||
|
||||
QJavalinAccessLogger.logEndSuccess(logPair("recordCount", () -> ((List<?>) output.get("records")).size()), QJavalinAccessLogger.logPairIfSlow("filter", filter, SLOW_LOG_THRESHOLD_MS));
|
||||
String resultString = JsonUtils.toJson(output);
|
||||
String resultString = toJson(output);
|
||||
context.result(resultString);
|
||||
storeApiLog(apiLog.withStatusCode(context.statusCode()).withResponseBody(resultString));
|
||||
}
|
||||
@ -911,7 +927,7 @@ public class QJavalinApiHandler
|
||||
|
||||
QJavalinAccessLogger.logEndSuccess();
|
||||
context.status(HttpStatus.Code.CREATED.getCode());
|
||||
String resultString = JsonUtils.toJson(outputRecord);
|
||||
String resultString = toJson(outputRecord);
|
||||
context.result(resultString);
|
||||
storeApiLog(apiLog.withStatusCode(context.statusCode()).withResponseBody(resultString));
|
||||
}
|
||||
@ -941,7 +957,7 @@ public class QJavalinApiHandler
|
||||
List<Map<String, Serializable>> response = ApiImplementation.bulkInsert(apiInstanceMetaData, version, tableApiName, context.body());
|
||||
|
||||
context.status(HttpStatus.Code.MULTI_STATUS.getCode());
|
||||
String resultString = JsonUtils.toJson(response);
|
||||
String resultString = toJson(response);
|
||||
context.result(resultString);
|
||||
storeApiLog(apiLog.withStatusCode(context.statusCode()).withResponseBody(resultString));
|
||||
}
|
||||
@ -972,7 +988,7 @@ public class QJavalinApiHandler
|
||||
|
||||
QJavalinAccessLogger.logEndSuccess(logPair("recordCount", response.size()));
|
||||
context.status(HttpStatus.Code.MULTI_STATUS.getCode());
|
||||
String resultString = JsonUtils.toJson(response);
|
||||
String resultString = toJson(response);
|
||||
context.result(resultString);
|
||||
storeApiLog(apiLog.withStatusCode(context.statusCode()).withResponseBody(resultString));
|
||||
}
|
||||
@ -1003,7 +1019,7 @@ public class QJavalinApiHandler
|
||||
|
||||
QJavalinAccessLogger.logEndSuccess(logPair("recordCount", response.size()));
|
||||
context.status(HttpStatus.Code.MULTI_STATUS.getCode());
|
||||
String resultString = JsonUtils.toJson(response);
|
||||
String resultString = toJson(response);
|
||||
context.result(resultString);
|
||||
storeApiLog(apiLog.withStatusCode(context.statusCode()).withResponseBody(resultString));
|
||||
}
|
||||
@ -1176,7 +1192,7 @@ public class QJavalinApiHandler
|
||||
///////////////////////////
|
||||
}
|
||||
|
||||
String responseBody = JsonUtils.toJson(Map.of("error", errorMessage));
|
||||
String responseBody = toJson(Map.of("error", errorMessage));
|
||||
context.result(responseBody);
|
||||
|
||||
if(apiLog != null)
|
||||
|
@ -201,6 +201,8 @@ class QJavalinApiHandlerTest extends BaseTest
|
||||
assertEquals(1, jsonObject.getInt("id"));
|
||||
assertEquals("Homer", jsonObject.getString("firstName"));
|
||||
assertEquals("Simpson", jsonObject.getString("lastName"));
|
||||
assertTrue(jsonObject.isNull("noOfShoes"));
|
||||
assertFalse(jsonObject.has("someNonField"));
|
||||
}
|
||||
|
||||
|
||||
@ -374,6 +376,8 @@ class QJavalinApiHandlerTest extends BaseTest
|
||||
assertEquals(1, jsonObject.getInt("id"));
|
||||
assertEquals("Homer", jsonObject.getString("firstName"));
|
||||
assertEquals("Simpson", jsonObject.getString("lastName"));
|
||||
assertTrue(jsonObject.isNull("noOfShoes"));
|
||||
assertFalse(jsonObject.has("someNonField"));
|
||||
}
|
||||
|
||||
|
||||
@ -938,42 +942,6 @@ class QJavalinApiHandlerTest extends BaseTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testUpdateAssociations() throws QException
|
||||
{
|
||||
insert1Order3Lines4LineExtrinsicsAnd1OrderExtrinsic();
|
||||
|
||||
HttpResponse<String> response = Unirest.patch(BASE_URL + "/api/" + VERSION + "/order/1")
|
||||
.body("""
|
||||
{"orderLines":
|
||||
[
|
||||
{"id": 1, "lineNumber": 1, "sku": "BASIC1", "quantity": 47},
|
||||
{"id": 2},
|
||||
{"id": 3}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.asString();
|
||||
assertErrorResponse(HttpStatus.NO_CONTENT_204, null, response);
|
||||
|
||||
QRecord orderRecord = getRecord(TestUtils.TABLE_NAME_ORDER, 1);
|
||||
List<QRecord> orderLines = orderRecord.getAssociatedRecords().get("orderLines");
|
||||
assertThat(orderLines)
|
||||
.withFailMessage("order lines should be found on order").isNotNull().isNotEmpty()
|
||||
.withFailMessage("Should have a line with id 1").filteredOn(r -> r.getValueInteger("id").equals(1)).hasSize(1)
|
||||
.withFailMessage("line with id 1 should have quantity updated to 47").first().matches(r -> r.getValue("quantity").equals(47));
|
||||
|
||||
assertThat(orderLines)
|
||||
.withFailMessage("order lines should be found on order").isNotNull().isNotEmpty()
|
||||
.withFailMessage("Should have a line with id 2").filteredOn(r -> r.getValueInteger("id").equals(2)).hasSize(1)
|
||||
.withFailMessage("line with id 2 should have original quantity (42)").first().matches(r -> r.getValue("quantity").equals(42));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@ -1025,6 +993,42 @@ class QJavalinApiHandlerTest extends BaseTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testUpdateAssociations() throws QException
|
||||
{
|
||||
insert1Order3Lines4LineExtrinsicsAnd1OrderExtrinsic();
|
||||
|
||||
HttpResponse<String> response = Unirest.patch(BASE_URL + "/api/" + VERSION + "/order/1")
|
||||
.body("""
|
||||
{"orderLines":
|
||||
[
|
||||
{"id": 1, "lineNumber": 1, "sku": "BASIC1", "quantity": 47},
|
||||
{"id": 2},
|
||||
{"id": 3}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.asString();
|
||||
assertErrorResponse(HttpStatus.NO_CONTENT_204, null, response);
|
||||
|
||||
QRecord orderRecord = getRecord(TestUtils.TABLE_NAME_ORDER, 1);
|
||||
List<QRecord> orderLines = orderRecord.getAssociatedRecords().get("orderLines");
|
||||
assertThat(orderLines)
|
||||
.withFailMessage("order lines should be found on order").isNotNull().isNotEmpty()
|
||||
.withFailMessage("Should have a line with id 1").filteredOn(r -> r.getValueInteger("id").equals(1)).hasSize(1)
|
||||
.withFailMessage("line with id 1 should have quantity updated to 47").first().matches(r -> r.getValue("quantity").equals(47));
|
||||
|
||||
assertThat(orderLines)
|
||||
.withFailMessage("order lines should be found on order").isNotNull().isNotEmpty()
|
||||
.withFailMessage("Should have a line with id 2").filteredOn(r -> r.getValueInteger("id").equals(2)).hasSize(1)
|
||||
.withFailMessage("line with id 2 should have original quantity (42)").first().matches(r -> r.getValue("quantity").equals(42));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@ -1055,7 +1059,7 @@ class QJavalinApiHandlerTest extends BaseTest
|
||||
|
||||
assertEquals(HttpStatus.BAD_REQUEST_400, jsonArray.getJSONObject(2).getInt("statusCode"));
|
||||
assertEquals("Error updating Person: Missing value in primary key field", jsonArray.getJSONObject(2).getString("error"));
|
||||
assertFalse(jsonArray.getJSONObject(2).has("id"));
|
||||
assertTrue(jsonArray.getJSONObject(2).isNull("id"));
|
||||
|
||||
assertEquals(HttpStatus.NOT_FOUND_404, jsonArray.getJSONObject(3).getInt("statusCode"));
|
||||
assertEquals("Error updating Person: No record was found to update for Id = 256", jsonArray.getJSONObject(3).getString("error"));
|
||||
|
Reference in New Issue
Block a user