Skip to content

Commit 5c5bc61

Browse files
author
Philip Z
committed
fix(tfp): create mutation entities through metadata factory
1 parent 7cfa2eb commit 5c5bc61

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎teaql-tfp-endpoint/src/main/java/io/teaql/tfp/TfpEndpointHandler.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private Map<String, Object> handleMutationActive(UserContext context, TrustedFed
318318
throw new IllegalArgumentException("Unknown entity: " + entityName);
319319
}
320320

321-
Entity entity = descriptor.getTargetType().getDeclaredConstructor().newInstance();
321+
Entity entity = descriptor.createEntity();
322322
java.util.Iterator<Map.Entry<String, JsonNode>> mutationFields =
323323
mappedPayload.fields();
324324
while (mutationFields.hasNext()) {

‎teaql-tfp-endpoint/src/test/java/io/teaql/tfp/TfpEndpointPolicyTest.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public void metadata() {
4949
EntityDescriptor descriptor = new EntityDescriptor();
5050
descriptor.setType("Probe"); descriptor.setTargetType(Probe.class);
5151
descriptor.addSimpleProperty("id", Long.class);
52+
descriptor.withEntitySupplier(() -> {
53+
Probe probe = new Probe();
54+
probe.factoryCreated = true;
55+
return probe;
56+
});
5257
descriptor.addSimpleProperty("status", String.class);
5358
metadata.register(descriptor);
5459
EntityDescriptor status = new EntityDescriptor();
@@ -105,6 +110,7 @@ public void updateLoadsIdentityAndExpectedVersionWithoutJacksonSetters() throws
105110
io.teaql.runtime.EntityPersistenceMutation request =
106111
(io.teaql.runtime.EntityPersistenceMutation) capturedMutation;
107112
Probe entity = (Probe) request.getEntity();
113+
org.junit.Assert.assertTrue(entity.factoryCreated);
108114
org.junit.Assert.assertEquals(Long.valueOf(42), entity.getId());
109115
org.junit.Assert.assertEquals(Long.valueOf(3), entity.getVersion());
110116
org.junit.Assert.assertEquals("PAID", entity.getStatus());
@@ -321,6 +327,7 @@ private void assertCode(String code, Throwing action) {
321327
private interface Throwing { void run() throws Exception; }
322328
public static final class Probe extends BaseEntity {
323329
private String status;
330+
private boolean factoryCreated;
324331
public String typeName() { return "Probe"; }
325332
public String getStatus() { return status; }
326333
public void setStatus(String value) { status = value; }

0 commit comments

Comments
 (0)