Skip to content

Commit 0d2aa5a

Browse files
author
Philip Z
committed
fix(tfp): create mutation entities through metadata factory
1 parent 0649723 commit 0d2aa5a

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
@@ -314,7 +314,7 @@ private Map<String, Object> handleMutationActive(UserContext context, TrustedFed
314314
throw new IllegalArgumentException("Unknown entity: " + entityName);
315315
}
316316

317-
Entity entity = descriptor.getTargetType().getDeclaredConstructor().newInstance();
317+
Entity entity = descriptor.createEntity();
318318
java.util.Iterator<Map.Entry<String, JsonNode>> mutationFields =
319319
mappedPayload.fields();
320320
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
@@ -45,6 +45,11 @@ public void metadata() {
4545
SimpleEntityMetaFactory metadata = new SimpleEntityMetaFactory();
4646
EntityDescriptor descriptor = new EntityDescriptor();
4747
descriptor.setType("Probe"); descriptor.setTargetType(Probe.class);
48+
descriptor.withEntitySupplier(() -> {
49+
Probe probe = new Probe();
50+
probe.factoryCreated = true;
51+
return probe;
52+
});
4853
descriptor.addSimpleProperty("status", String.class);
4954
metadata.register(descriptor);
5055
EntityDescriptor status = new EntityDescriptor();
@@ -89,6 +94,7 @@ public void updateLoadsIdentityAndExpectedVersionWithoutJacksonSetters() throws
8994
io.teaql.runtime.EntityPersistenceMutation request =
9095
(io.teaql.runtime.EntityPersistenceMutation) capturedMutation;
9196
Probe entity = (Probe) request.getEntity();
97+
org.junit.Assert.assertTrue(entity.factoryCreated);
9298
org.junit.Assert.assertEquals(Long.valueOf(42), entity.getId());
9399
org.junit.Assert.assertEquals(Long.valueOf(3), entity.getVersion());
94100
org.junit.Assert.assertEquals("PAID", entity.getStatus());
@@ -244,6 +250,7 @@ private void assertCode(String code, Throwing action) {
244250
private interface Throwing { void run() throws Exception; }
245251
public static final class Probe extends BaseEntity {
246252
private String status;
253+
private boolean factoryCreated;
247254
public String typeName() { return "Probe"; }
248255
public String getStatus() { return status; }
249256
public void setStatus(String value) { status = value; }

0 commit comments

Comments
 (0)