From 32036ae2884c87e39697bb6fa3ec7572c42830fc Mon Sep 17 00:00:00 2001
From: gaborflorian <114913193+gaborflorian@users.noreply.github.com>
Date: Fri, 10 Jan 2025 15:11:26 +0100
Subject: [PATCH] JNG-6081 Default relation elements arent transform in Entity
(#340)
* add test for entity defaults
* upadate version
* Add optinal default entitiy and transfer variation test
* add jira tickets
---
.../EntityRelationWithDefaultsModelTest.java | 263 +++++++++++-
...TransferRelationWithDefaultsModelTest.java | 373 ++++++++++++++++--
.../resources/RelationWithDefaultsModel.jsl | 44 ++-
pom.xml | 2 +-
4 files changed, 634 insertions(+), 48 deletions(-)
diff --git a/judo-runtime-core-jsl-itest/models/RelationWithDefaultsModel/src/test/java/hu/blackbelt/judo/runtime/core/jsl/entity/EntityRelationWithDefaultsModelTest.java b/judo-runtime-core-jsl-itest/models/RelationWithDefaultsModel/src/test/java/hu/blackbelt/judo/runtime/core/jsl/entity/EntityRelationWithDefaultsModelTest.java
index 567ddf13..d5358ab3 100644
--- a/judo-runtime-core-jsl-itest/models/RelationWithDefaultsModel/src/test/java/hu/blackbelt/judo/runtime/core/jsl/entity/EntityRelationWithDefaultsModelTest.java
+++ b/judo-runtime-core-jsl-itest/models/RelationWithDefaultsModel/src/test/java/hu/blackbelt/judo/runtime/core/jsl/entity/EntityRelationWithDefaultsModelTest.java
@@ -24,20 +24,26 @@
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelation.CollectorWithSingleOptionalDefaultRelation;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelation.CollectorWithSingleOptionalDefaultRelationDao;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelation.CollectorWithSingleOptionalDefaultRelationForCreate;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationextended.CollectorWithSingleOptionalDefaultRelationExtended;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationextended.CollectorWithSingleOptionalDefaultRelationExtendedDao;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationextended.CollectorWithSingleOptionalDefaultRelationExtendedForCreate;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsinglerequireddefaultrelation.CollectorWithSingleRequiredDefaultRelation;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsinglerequireddefaultrelation.CollectorWithSingleRequiredDefaultRelationDao;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsinglerequireddefaultrelation.CollectorWithSingleRequiredDefaultRelationForCreate;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsinglerequireddefaultrelationextended.CollectorWithSingleRequiredDefaultRelationExtended;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsinglerequireddefaultrelationextended.CollectorWithSingleRequiredDefaultRelationExtendedDao;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsinglerequireddefaultrelationextended.CollectorWithSingleRequiredDefaultRelationExtendedForCreate;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.item.Item;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.item.ItemDao;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.item.ItemForCreate;
import hu.blackbelt.judo.psm.generator.sdk.core.test.guice.RelationWithDefaultsModelDaoModules;
import hu.blackbelt.judo.runtime.core.jsl.fixture.JudoRuntimeExtension;
+import hu.blackbelt.judo.sdk.query.StringFilter;
import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
@Slf4j
public class EntityRelationWithDefaultsModelTest {
@@ -52,32 +58,277 @@ public class EntityRelationWithDefaultsModelTest {
CollectorWithSingleOptionalDefaultRelationDao collectorWithSingleOptionalDefaultRelationDao;
@Test
- @Disabled("https://blackbelt.atlassian.net/browse/JNG-6081")
public void singleOptionalDefaultRelationTest() {
// shortname
CollectorWithSingleOptionalDefaultRelationDao collectorDao = collectorWithSingleOptionalDefaultRelationDao;
- Item item = itemDao.create(ItemForCreate.builder().withName("A").withNumber(1).build());
+ // The Default element is defined and no value added during the creation
+ Item item = itemDao.create(ItemForCreate.builder().withName("A").withNumber(1).build());
CollectorWithSingleOptionalDefaultRelation collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationForCreate.builder().build());
assertEquals(item.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+ itemDao.delete(item);
+
+ // Default element is undefined and no value added during the creation
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationForCreate.builder().build());
+
+ assertTrue(collectorDao.queryOptItem(collector).isEmpty());
+
+ // No matching default element and no value added during the creation
+ item = itemDao.create(ItemForCreate.builder().withName("A").withNumber(5).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationForCreate.builder().build());
+
+ assertTrue(collectorDao.queryOptItem(collector).isEmpty());
+
+ // Default element is undefined and value added during the creation
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationForCreate.builder()
+ .withOptItem(Item.builder().withName("A1").withNumber(5).build())
+ .build()
+ );
+
+ Item itemA1 = itemDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ itemDao.delete(itemA1);
+
+ // Default element is not undefined and value added during the creation
+ item = itemDao.create(ItemForCreate.builder().withName("A").withNumber(1).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationForCreate.builder()
+ .withOptItem(Item.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+ itemA1 = itemDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ itemDao.deleteAll(item, itemA1);
+
+ // No matching default element and value added during the creation
+ item = itemDao.create(ItemForCreate.builder().withName("A").withNumber(5).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationForCreate.builder()
+ .withOptItem(Item.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+ itemA1 = itemDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
}
@Inject
CollectorWithSingleRequiredDefaultRelationDao collectorWithSingleRequiredDefaultRelationDao;
@Test
- @Disabled("https://blackbelt.atlassian.net/browse/JNG-6081")
public void singleRequiredDefaultRelationTest() {
// shortname
CollectorWithSingleRequiredDefaultRelationDao collectorDao = collectorWithSingleRequiredDefaultRelationDao;
+ // Default element is not undefined and no value added during the creation
+ Item item = itemDao
+ .create(ItemForCreate.builder().withName("A").withNumber(1).build());
+ CollectorWithSingleRequiredDefaultRelation collector = collectorDao.create(CollectorWithSingleRequiredDefaultRelationForCreate.builder().build());
+
+ assertEquals(item.identifier(), collectorDao.queryReqItem(collector).identifier());
+
+ // Default element is undefined and no value added during the creation
+ collectorDao.delete(collector);
+ itemDao
+ .delete(item);
+
+ // Error
+ IllegalStateException thrown = assertThrows(IllegalStateException.class, () -> collectorDao.create(CollectorWithSingleRequiredDefaultRelationForCreate.builder().build()));
+ assertTrue(thrown.getMessage().contains("Default reference value is undefined"));
+
+ // No matching default element and no value added during the creation // Error
+ item = itemDao
+ .create(ItemForCreate.builder().withName("A").withNumber(5).build());
+ thrown = assertThrows(IllegalStateException.class, () -> collectorDao.create(CollectorWithSingleRequiredDefaultRelationForCreate.builder().build()));
+ assertTrue(thrown.getMessage().contains("Default reference value is undefined"));
+
+ itemDao
+ .delete(item);
+ // Default element is not undefined and value added during the creation
+ item = itemDao
+ .create(ItemForCreate.builder().withName("A").withNumber(1).build());
+ collector = collectorDao.create(CollectorWithSingleRequiredDefaultRelationForCreate.builder()
+ .withReqItem(Item.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+
+ Item itemA1 = itemDao
+ .query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryReqItem(collector).identifier());
+
+ collectorDao.delete(collector);
+ itemDao
+ .deleteAll(item, itemA1);
+
+ // Default element is undefined and value added during the creation
+ // TODO Default is undefined, IllegalStateException Default reference value is undefined
+ // TODO JNG-4194
+// collector = collectorDao.create(CollectorWithSingleRequiredDefaultRelationForCreate.builder()
+// .withReqItem(Item.builder().withName("A1").withNumber(11).build())
+// .build()
+// );
+//
+// itemA1 = itemDao
+// .query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+// assertEquals(itemA1.identifier(), collectorDao.queryReqItem(collector).identifier());
+// itemDao
+// .delete(itemA1);
+
+ // TODO Default is undefined, IllegalStateException Default reference value is undefined
+ // TODO JNG-4194
+ // No matching default element and value added during the creation
+// item = itemDao
+// .create(ItemForCreate.builder().withName("A").withNumber(5).build());
+// collector = collectorDao.create(CollectorWithSingleRequiredDefaultRelationForCreate.builder()
+// .withReqItem(Item.builder().withName("A1").withNumber(11).build())
+// .build()
+// );
+//
+// itemA1 = itemDao
+// .query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+// assertEquals(itemA1.identifier(), collectorDao.queryReqItem(collector).identifier());
+// itemDao.delete(itemA1);
+ }
+
+ // Inherited default on entity
+ @Inject
+ CollectorWithSingleOptionalDefaultRelationExtendedDao collectorWithSingleOptionalDefaultRelationExtendedDao;
+
+ @Test
+ public void singleOptionalDefaultRelationInheritedTest() {
+ // shortname
+ CollectorWithSingleOptionalDefaultRelationExtendedDao collectorDao = collectorWithSingleOptionalDefaultRelationExtendedDao;
+
+ // Default element is not undefined and no value added during the creation
Item item = itemDao.create(ItemForCreate.builder().withName("A").withNumber(1).build());
+ CollectorWithSingleOptionalDefaultRelationExtended collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationExtendedForCreate.builder().build());
- CollectorWithSingleRequiredDefaultRelation collector = collectorDao.create(CollectorWithSingleRequiredDefaultRelationForCreate.builder().build());
+ assertEquals(item.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ itemDao.delete(item);
+
+ // Default element is undefined and no value added during the creation
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationExtendedForCreate.builder().build());
+
+ assertTrue(collectorDao.queryOptItem(collector).isEmpty());
+
+ // No matching default element and no value added during the creation
+ item = itemDao.create(ItemForCreate.builder().withName("A").withNumber(5).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationExtendedForCreate.builder().build());
+
+ assertTrue(collectorDao.queryOptItem(collector).isEmpty());
+
+ // Default element is undefined and value added during the creation
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationExtendedForCreate.builder()
+ .withOptItem(Item.builder().withName("A1").withNumber(5).build())
+ .build()
+ );
+
+ Item itemA1 = itemDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ itemDao.delete(itemA1);
+
+ // Default element is not undefined and value added during the creation
+ item = itemDao.create(ItemForCreate.builder().withName("A").withNumber(1).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationExtendedForCreate.builder()
+ .withOptItem(Item.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+ itemA1 = itemDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ itemDao.deleteAll(item, itemA1);
+
+ // No matching default element and value added during the creation
+ item = itemDao.create(ItemForCreate.builder().withName("A").withNumber(5).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationExtendedForCreate.builder()
+ .withOptItem(Item.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+ itemA1 = itemDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ }
+
+ @Inject
+ CollectorWithSingleRequiredDefaultRelationExtendedDao collectorWithSingleRequiredDefaultRelationExtendedDao;
+
+ @Test
+ public void singleRequiredDefaultRelationInheritedTest() {
+ // shortname
+ CollectorWithSingleRequiredDefaultRelationExtendedDao collectorDao = collectorWithSingleRequiredDefaultRelationExtendedDao;
+
+ // Default element is not undefined and no value added during the creation
+ Item item = itemDao
+ .create(ItemForCreate.builder().withName("A").withNumber(1).build());
+ CollectorWithSingleRequiredDefaultRelationExtended collector = collectorDao.create(CollectorWithSingleRequiredDefaultRelationExtendedForCreate.builder().build());
assertEquals(item.identifier(), collectorDao.queryReqItem(collector).identifier());
+ // Default element is undefined and no value added during the creation
+ collectorDao.delete(collector);
+ itemDao
+ .delete(item);
+
+ // Error
+ IllegalStateException thrown = assertThrows(IllegalStateException.class, () -> collectorDao.create(CollectorWithSingleRequiredDefaultRelationExtendedForCreate.builder().build()));
+ assertTrue(thrown.getMessage().contains("Default reference value is undefined"));
+
+ // No matching default element and no value added during the creation // Error
+ item = itemDao
+ .create(ItemForCreate.builder().withName("A").withNumber(5).build());
+ thrown = assertThrows(IllegalStateException.class, () -> collectorDao.create(CollectorWithSingleRequiredDefaultRelationExtendedForCreate.builder().build()));
+ assertTrue(thrown.getMessage().contains("Default reference value is undefined"));
+
+ itemDao
+ .delete(item);
+ // Default element is not undefined and value added during the creation
+ item = itemDao
+ .create(ItemForCreate.builder().withName("A").withNumber(1).build());
+ collector = collectorDao.create(CollectorWithSingleRequiredDefaultRelationExtendedForCreate.builder()
+ .withReqItem(Item.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+
+ Item itemA1 = itemDao
+ .query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryReqItem(collector).identifier());
+
+ collectorDao.delete(collector);
+ itemDao
+ .deleteAll(item, itemA1);
+
+ // Default element is undefined and value added during the creation
+ // TODO Default is undefined, IllegalStateException Default reference value is undefined
+ // TODO JNG-4194
+// collector = collectorDao.create(CollectorWithSingleRequiredDefaultRelationExtendedForCreate.builder()
+// .withReqItem(Item.builder().withName("A1").withNumber(11).build())
+// .build()
+// );
+//
+// itemA1 = itemDao
+// .query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+// assertEquals(itemA1.identifier(), collectorDao.queryReqItem(collector).identifier());
+// itemDao
+// .delete(itemA1);
+
+ // TODO Default is undefined, IllegalStateException Default reference value is undefined
+ // TODO JNG-4194
+ // No matching default element and value added during the creation
+// item = itemDao
+// .create(ItemForCreate.builder().withName("A").withNumber(5).build());
+// collector = collectorDao.create(CollectorWithSingleRequiredDefaultRelationExtendedForCreate.builder()
+// .withReqItem(Item.builder().withName("A1").withNumber(11).build())
+// .build()
+// );
+//
+// itemA1 = itemDao
+// .query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+// assertEquals(itemA1.identifier(), collectorDao.queryReqItem(collector).identifier());
+// itemDao.delete(itemA1);
+
}
}
diff --git a/judo-runtime-core-jsl-itest/models/RelationWithDefaultsModel/src/test/java/hu/blackbelt/judo/runtime/core/jsl/entity/TransferRelationWithDefaultsModelTest.java b/judo-runtime-core-jsl-itest/models/RelationWithDefaultsModel/src/test/java/hu/blackbelt/judo/runtime/core/jsl/entity/TransferRelationWithDefaultsModelTest.java
index fe697be2..d91f6eff 100644
--- a/judo-runtime-core-jsl-itest/models/RelationWithDefaultsModel/src/test/java/hu/blackbelt/judo/runtime/core/jsl/entity/TransferRelationWithDefaultsModelTest.java
+++ b/judo-runtime-core-jsl-itest/models/RelationWithDefaultsModel/src/test/java/hu/blackbelt/judo/runtime/core/jsl/entity/TransferRelationWithDefaultsModelTest.java
@@ -21,6 +21,18 @@
*/
import com.google.inject.Inject;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationoptionaldefaulttransfer.CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransfer;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationoptionaldefaulttransfer.CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransferDao;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationoptionaldefaulttransfer.CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransferForCreate;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationoptionaltransfer.CollectorWithSingleOptionalDefaultRelationOptionalTransfer;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationoptionaltransfer.CollectorWithSingleOptionalDefaultRelationOptionalTransferDao;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationoptionaltransfer.CollectorWithSingleOptionalDefaultRelationOptionalTransferForCreate;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationrequireddefaulttransfer.CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransfer;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationrequireddefaulttransfer.CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransferDao;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationrequireddefaulttransfer.CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransferForCreate;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationrequiredtransfer.CollectorWithSingleOptionalDefaultRelationRequiredTransfer;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationrequiredtransfer.CollectorWithSingleOptionalDefaultRelationRequiredTransferDao;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionaldefaultrelationrequiredtransfer.CollectorWithSingleOptionalDefaultRelationRequiredTransferForCreate;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionalrelationoptionaldefaulttransfer.CollectorWithSingleOptionalRelationOptionalDefaultTransfer;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionalrelationoptionaldefaulttransfer.CollectorWithSingleOptionalRelationOptionalDefaultTransferDao;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.collectorwithsingleoptionalrelationoptionaldefaulttransfer.CollectorWithSingleOptionalRelationOptionalDefaultTransferForCreate;
@@ -47,9 +59,11 @@
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.itemtransfer.ItemTransfer;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.itemtransfer.ItemTransferDao;
import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.itemtransfer.ItemTransferForCreate;
+import hu.blackbelt.judo.psm.generator.sdk.core.test.api.relationwithdefaultsmodel.relationwithdefaultsmodel.itemtransfer.ItemTransferQueryCustomizer;
import hu.blackbelt.judo.psm.generator.sdk.core.test.guice.RelationWithDefaultsModelDaoModules;
import hu.blackbelt.judo.runtime.core.exception.ValidationException;
import hu.blackbelt.judo.runtime.core.jsl.fixture.JudoRuntimeExtension;
+import hu.blackbelt.judo.sdk.query.NumberFilter;
import hu.blackbelt.judo.sdk.query.StringFilter;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Disabled;
@@ -75,16 +89,16 @@ public class TransferRelationWithDefaultsModelTest {
// Variations
/*
- op - op
- op - op default
- op - req
- op - req default
+ opt - opt
+ opt - opt default
+ opt - req
+ opt - req default
*/
@Inject
CollectorWithSingleOptionalRelationOptionalTransferDao collectorWithSingleOptionalRelationOptionalTransferDao;
- // op - op
+ // opt - opt
@Test
public void singleOptionalRelationOptionalTransferTest() {
@@ -93,7 +107,7 @@ public void singleOptionalRelationOptionalTransferTest() {
CollectorWithSingleOptionalRelationOptionalTransfer collector = collectorDao.create(CollectorWithSingleOptionalRelationOptionalTransferForCreate.builder().build());
- assertTrue(collectorDao.queryOpItem(collector).isEmpty());
+ assertTrue(collectorDao.queryOptItem(collector).isEmpty());
}
@@ -101,7 +115,7 @@ public void singleOptionalRelationOptionalTransferTest() {
CollectorWithSingleOptionalRelationOptionalDefaultTransferDao collectorWithSingleOptionalDefaultRelationTransferDao;
- // op - op default
+ // opt - opt default
@Test
public void singleOptionalRelationOptionalDefaultTransferTest() {
@@ -112,58 +126,58 @@ public void singleOptionalRelationOptionalDefaultTransferTest() {
ItemTransfer item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(1).build());
CollectorWithSingleOptionalRelationOptionalDefaultTransfer collector = collectorDao.create(CollectorWithSingleOptionalRelationOptionalDefaultTransferForCreate.builder().build());
- assertEquals(item.identifier(), collectorDao.queryOpItem(collector).orElseThrow().identifier());
+ assertEquals(item.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
// Default element is undefined and no value added during the creation
itemTransferDao.delete(item);
collector = collectorDao.create(CollectorWithSingleOptionalRelationOptionalDefaultTransferForCreate.builder().build());
- assertTrue(collectorDao.queryOpItem(collector).isEmpty());
+ assertTrue(collectorDao.queryOptItem(collector).isEmpty());
// No matching default element and no value added during the creation
item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(5).build());
collector = collectorDao.create(CollectorWithSingleOptionalRelationOptionalDefaultTransferForCreate.builder().build());
- assertTrue(collectorDao.queryOpItem(collector).isEmpty());
+ assertTrue(collectorDao.queryOptItem(collector).isEmpty());
itemTransferDao.delete(item);
// Default element is not undefined and value added during the creation
item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(1).build());
collector = collectorDao.create(CollectorWithSingleOptionalRelationOptionalDefaultTransferForCreate.builder()
- .withOpItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .withOptItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
.build()
);
ItemTransfer itemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
- assertEquals(itemA1.identifier(), collectorDao.queryOpItem(collector).orElseThrow().identifier());
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
itemTransferDao.deleteAll(item, itemA1);
// Default element is undefined and value added during the creation
collector = collectorDao.create(CollectorWithSingleOptionalRelationOptionalDefaultTransferForCreate.builder()
- .withOpItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .withOptItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
.build()
);
itemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
- assertEquals(itemA1.identifier(), collectorDao.queryOpItem(collector).orElseThrow().identifier());
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
itemTransferDao.delete(itemA1);
// No matching default element and value added during the creation
item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(5).build());
collector = collectorDao.create(CollectorWithSingleOptionalRelationOptionalDefaultTransferForCreate.builder()
- .withOpItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .withOptItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
.build()
);
itemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
- assertEquals(itemA1.identifier(), collectorDao.queryOpItem(collector).orElseThrow().identifier());
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
}
@Inject
CollectorWithSingleOptionalRelationRequiredTransferDao singleOptionalRelationRequiredTransferDao;
- // op - req
+ // opt - req
@Test
public void singleRequiredRelationRequiredTransferTest() {
@@ -182,7 +196,7 @@ public void singleRequiredRelationRequiredTransferTest() {
@Inject
CollectorWithSingleOptionalRelationRequiredDefaultTransferDao collectorWithSingleOptionalRelationRequiredDefaultTransferDao;
- // op - req default
+ // opt - req default
@Test
public void singleOptionalRelationRequiredDefaultTransferTest() {
@@ -250,8 +264,8 @@ public void singleOptionalRelationRequiredDefaultTransferTest() {
// Variations
/*
- req - op
- req - op default
+ req - opt
+ req - opt default
req - req
req - req default
*/
@@ -262,7 +276,7 @@ public void singleOptionalRelationRequiredDefaultTransferTest() {
@Inject
CollectorWithSingleRequiredRelationDao collectorWithSingleRequiredRelationDao;
- // req - op
+ // req - opt
// TODO: Creation should throw an error if the required entity relation remains empty in the transfer optional.
@Test
@@ -274,7 +288,7 @@ public void singleRequiredRelationOptionalTransfer() {
// Should throw error
CollectorWithSingleRequiredRelationOptionalTransfer collector = collectorDao.create(CollectorWithSingleRequiredRelationOptionalTransferForCreate.builder().build());
- assertTrue(collectorDao.queryOpItem(collector).isEmpty());
+ assertTrue(collectorDao.queryOptItem(collector).isEmpty());
// Empty query result for required reference: reqItem
collectorWithSingleRequiredRelationDao.queryReqItem((UUID) collector.identifier().getIdentifier());
@@ -285,7 +299,7 @@ public void singleRequiredRelationOptionalTransfer() {
@Inject
CollectorWithSingleRequiredRelationOptionalDefaultTransferDao collectorWithSingleRequiredRelationOptionalDefaultTransferDao;
- // req - op default
+ // req - opt default
@Test
public void singleRequiredRelationOptionalDefaultTransferTest() {
@@ -296,24 +310,26 @@ public void singleRequiredRelationOptionalDefaultTransferTest() {
ItemTransfer item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(1).build());
CollectorWithSingleRequiredRelationOptionalDefaultTransfer collector = collectorDao.create(CollectorWithSingleRequiredRelationOptionalDefaultTransferForCreate.builder().build());
- assertEquals(item.identifier(), collectorDao.queryOpItem(collector).orElseThrow().identifier());
+ assertEquals(item.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
// Default element is undefined and no value added during the creation
collectorDao.delete(collector);
itemTransferDao.delete(item);
// TODO Should throw error
+ // TODO JNG-6083
collector = collectorDao.create(CollectorWithSingleRequiredRelationOptionalDefaultTransferForCreate.builder().build());
- //assertTrue(collectorDao.queryOpItem(collector).isEmpty());
+ //assertTrue(collectorDao.queryOptItem(collector).isEmpty());
// Empty query result for required reference: reqItem
//collectorWithSingleRequiredRelationDao.queryReqItem((UUID) collector.identifier().getIdentifier());
// No matching default element and no value added during the creation
item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(5).build());
// TODO Should throw error
+ // TODO JNG-6083
collector = collectorDao.create(CollectorWithSingleRequiredRelationOptionalDefaultTransferForCreate.builder().build());
- //assertTrue(collectorDao.queryOpItem(collector).isEmpty());
+ //assertTrue(collectorDao.queryOptItem(collector).isEmpty());
//collectorWithSingleRequiredRelationDao.queryReqItem((UUID) collector.identifier().getIdentifier());
itemTransferDao.delete(item);
@@ -321,22 +337,22 @@ public void singleRequiredRelationOptionalDefaultTransferTest() {
// Default element is not undefined and value added during the creation
item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(1).build());
collector = collectorDao.create(CollectorWithSingleRequiredRelationOptionalDefaultTransferForCreate.builder()
- .withOpItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .withOptItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
.build()
);
ItemTransfer itemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
- assertEquals(itemA1.identifier(), collectorDao.queryOpItem(collector).orElseThrow().identifier());
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
collectorDao.delete(collector);
itemTransferDao.deleteAll(item, itemA1);
// Default element is undefined and value added during the creation
collector = collectorDao.create(CollectorWithSingleRequiredRelationOptionalDefaultTransferForCreate.builder()
- .withOpItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .withOptItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
.build()
);
itemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
- assertEquals(itemA1.identifier(), collectorDao.queryOpItem(collector).orElseThrow().identifier());
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
collectorDao.delete(collector);
itemTransferDao.delete(itemA1);
@@ -344,11 +360,11 @@ public void singleRequiredRelationOptionalDefaultTransferTest() {
// No matching default element and value added during the creation
item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(5).build());
collector = collectorDao.create(CollectorWithSingleRequiredRelationOptionalDefaultTransferForCreate.builder()
- .withOpItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .withOptItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
.build()
);
itemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
- assertEquals(itemA1.identifier(), collectorDao.queryOpItem(collector).orElseThrow().identifier());
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
}
@@ -441,4 +457,297 @@ public void SingleOptionalRelationRequiredDefaultTransferTest() {
}
+ @Inject
+ CollectorWithSingleOptionalDefaultRelationOptionalTransferDao collectorWithSingleOptionalDefaultRelationOptionalTransferDao;
+
+ // Variations
+ /*
+ opt default - opt
+ opt default - opt default
+ opt default - req
+ opt default - req default
+ */
+
+ // opt default - opt
+
+ @Test
+ public void SingleOptionalDefaultRelationOptionalTransferTest() {
+ CollectorWithSingleOptionalDefaultRelationOptionalTransferDao collectorDao = collectorWithSingleOptionalDefaultRelationOptionalTransferDao;
+
+ // Default element is not undefined and no value added during the creation
+ ItemTransfer item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(1).build());
+ CollectorWithSingleOptionalDefaultRelationOptionalTransfer collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationOptionalTransferForCreate.builder().build());
+
+ assertEquals(item.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ // Default element is undefined and no value added during the creation
+ itemTransferDao.delete(item);
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationOptionalTransferForCreate.builder().build());
+
+ assertTrue(collectorDao.queryOptItem(collector).isEmpty());
+
+ // No matching default element and no value added during the creation
+ item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(5).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationOptionalTransferForCreate.builder().build());
+
+ assertTrue(collectorDao.queryOptItem(collector).isEmpty());
+
+ itemTransferDao.delete(item);
+
+ // Default element is not undefined and value added during the creation
+ item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(1).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationOptionalTransferForCreate.builder()
+ .withOptItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+ ItemTransfer itemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ itemTransferDao.deleteAll(item, itemA1);
+
+ // Default element is undefined and value added during the creation
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationOptionalTransferForCreate.builder()
+ .withOptItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+ itemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ itemTransferDao.delete(itemA1);
+
+ // No matching default element and value added during the creation
+ item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(5).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationOptionalTransferForCreate.builder()
+ .withOptItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+ itemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ }
+
+ @Inject
+ CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransferDao collectorWithSingleOptionalDefaultRelationOptionalDefaultTransferDao;
+
+ // opt default - opt default
+
+ @Test
+ public void SingleOptionalDefaultRelationOptionalDefaultTransferTest() {
+ CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransferDao collectorDao = collectorWithSingleOptionalDefaultRelationOptionalDefaultTransferDao;
+
+ // Default element is not undefined and no value added during the creation
+ ItemTransfer item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A1").withNumber(1).build());
+ CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransfer collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransferForCreate.builder().build());
+
+ assertEquals(item.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ // Default element is undefined and no value added during the creation
+ itemTransferDao.delete(item);
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransferForCreate.builder().build());
+
+ assertTrue(collectorDao.queryOptItem(collector).isEmpty());
+
+ // No matching default element and no value added during the creation
+ item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(1).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransferForCreate.builder().build());
+
+ //TODO should be null instead of entity default
+ // TODO JNG-6106
+ //assertTrue(collectorDao.queryOptItem(collector).isEmpty());
+
+ itemTransferDao.delete(item);
+
+ // Default element is not undefined and value added during the creation
+ item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A1").withNumber(1).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransferForCreate.builder()
+ .withOptItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+ ItemTransfer itemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).filterByNumber(NumberFilter.equalTo(11)).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ itemTransferDao.deleteAll(item, itemA1);
+
+ // Default element is undefined and value added during the creation
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransferForCreate.builder()
+ .withOptItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+ itemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ itemTransferDao.delete(itemA1);
+
+ // No matching default element and value added during the creation
+ item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(5).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransferForCreate.builder()
+ .withOptItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+ itemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryOptItem(collector).orElseThrow().identifier());
+
+ }
+
+ @Inject
+ CollectorWithSingleOptionalDefaultRelationRequiredTransferDao collectorWithSingleOptionalDefaultRelationRequiredTransferDao;
+
+ // opt default - req
+
+ @Test
+ @Disabled("JNG-6103")
+ // TODO should refactor after default rework
+ public void SingleOptionalDefaultRelationRequiredTransferTest() {
+ // shortname
+ CollectorWithSingleOptionalDefaultRelationRequiredTransferDao collectorDao = collectorWithSingleOptionalDefaultRelationRequiredTransferDao;
+
+ // Default element is not undefined and no value added during the creation
+ ItemTransfer item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(1).build());
+
+ // TODO should use the entity default here, instead of validation error
+ // TODO JNG-6104
+ CollectorWithSingleOptionalDefaultRelationRequiredTransfer collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationRequiredTransferForCreate.builder().build());
+
+ assertEquals(item.identifier(), collectorDao.queryReqItem(collector).identifier());
+
+ // Default element is undefined and no value added during the creation
+ collectorDao.delete(collector);
+ itemTransferDao.delete(item);
+
+ // Error
+ IllegalStateException thrown = assertThrows(IllegalStateException.class, () -> collectorDao.create(CollectorWithSingleOptionalDefaultRelationRequiredTransferForCreate.builder().build()));
+ assertTrue(thrown.getMessage().contains("Default reference value is undefined"));
+
+ // No matching default element and no value added during the creation // Error
+ item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(5).build());
+ thrown = assertThrows(IllegalStateException.class, () -> collectorDao.create(CollectorWithSingleOptionalDefaultRelationRequiredTransferForCreate.builder().build()));
+ assertTrue(thrown.getMessage().contains("Default reference value is undefined"));
+
+ itemTransferDao.delete(item);
+ // Default element is not undefined and value added during the creation
+ item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(1).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationRequiredTransferForCreate.builder()
+ .withReqItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+
+ ItemTransferQueryCustomizer filterItemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).filterByNumber(NumberFilter.equalTo(11));
+ ItemTransfer itemA1 = filterItemA1.selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryReqItem(collector).identifier());
+
+ collectorDao.delete(collector);
+ itemTransferDao.deleteAll(item, itemA1);
+
+ // Default element is undefined and value added during the creation
+ // TODO Default is undefined, IllegalStateException Default reference value is undefined
+ // TODO JNG-4194
+// collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationRequiredTransferForCreate.builder()
+// .withReqItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+// .build()
+// );
+//
+// itemA1 = filterItemA1.selectOne().orElseThrow();
+// assertEquals(itemA1.identifier(), collectorDao.queryReqItem(collector).identifier());
+// itemTransferDao.delete(itemA1);
+
+ // TODO Default is undefined, IllegalStateException Default reference value is undefined
+ // TODO JNG-4194
+ // No matching default element and value added during the creation
+// item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(5).build());
+// collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationRequiredTransferForCreate.builder()
+// .withReqItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+// .build()
+// );
+//
+// itemA1 = filterItemA1.selectOne().orElseThrow();
+// assertEquals(itemA1.identifier(), collectorDao.queryReqItem(collector).identifier());
+// itemTransferDao.delete(itemA1);
+
+ }
+
+ @Inject
+ CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransferDao collectorWithSingleOptionalDefaultRelationRequiredDefaultTransferDao;
+
+ // opt default - req
+
+ @Test
+ public void SingleOptionalDefaultRelationRequiredDefaultTransferTest() {
+ // shortname
+ CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransferDao collectorDao = collectorWithSingleOptionalDefaultRelationRequiredDefaultTransferDao;
+
+ // Default element is not undefined and no value added during the creation
+ ItemTransfer item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A1").withNumber(1).build());
+
+ // TODO should use the entity default here, instead of validation error
+ // TODO JNG-6104
+ CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransfer collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransferForCreate.builder().build());
+
+ assertEquals(item.identifier(), collectorDao.queryReqItem(collector).identifier());
+
+ // Default element is undefined and no value added during the creation
+ collectorDao.delete(collector);
+ itemTransferDao.delete(item);
+
+ // Error
+ IllegalStateException thrown = assertThrows(IllegalStateException.class, () -> collectorDao.create(CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransferForCreate.builder().build()));
+ assertTrue(thrown.getMessage().contains("Default reference value is undefined"));
+
+ // No matching default element and no value added during the creation // Error
+ item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(5).build());
+ thrown = assertThrows(IllegalStateException.class, () -> collectorDao.create(CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransferForCreate.builder().build()));
+ assertTrue(thrown.getMessage().contains("Default reference value is undefined"));
+
+ itemTransferDao.delete(item);
+ // Default element is not undefined and value added during the creation
+ item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A1").withNumber(1).build());
+ collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransferForCreate.builder()
+ .withReqItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+ .build()
+ );
+
+ ItemTransferQueryCustomizer filterItemA1 = itemTransferDao.query().filterByName(StringFilter.equalTo("A1")).filterByNumber(NumberFilter.equalTo(11));
+ ItemTransfer itemA1 = filterItemA1.selectOne().orElseThrow();
+ assertEquals(itemA1.identifier(), collectorDao.queryReqItem(collector).identifier());
+
+ collectorDao.delete(collector);
+ itemTransferDao.deleteAll(item, itemA1);
+
+ // Default element is undefined and value added during the creation
+ // TODO Default is undefined, IllegalStateException Default reference value is undefined
+ // TODO JNG-4194
+// collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransferForCreate.builder()
+// .withReqItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+// .build()
+// );
+//
+// itemA1 = filterItemA1.selectOne().orElseThrow();
+// assertEquals(itemA1.identifier(), collectorDao.queryReqItem(collector).identifier());
+// itemTransferDao.delete(itemA1);
+
+ // TODO Default is undefined, IllegalStateException Default reference value is undefined
+ // TODO JNG-4194
+ // No matching default element and value added during the creation
+// item = itemTransferDao.create(ItemTransferForCreate.builder().withName("A").withNumber(5).build());
+// collector = collectorDao.create(CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransferForCreate.builder()
+// .withReqItem(ItemTransfer.builder().withName("A1").withNumber(11).build())
+// .build()
+// );
+//
+// itemA1 = filterItemA1.selectOne().orElseThrow();
+// assertEquals(itemA1.identifier(), collectorDao.queryReqItem(collector).identifier());
+// itemTransferDao.delete(itemA1);
+
+ }
+
+ // TODO Should add after or during the default rework
+ // TODO JNG-6105
+ // Variations
+ /*
+ req default - opt
+ req default - opt default
+ req default - req
+ req default - req default
+ */
+
+
}
diff --git a/judo-runtime-core-jsl-itest/models/RelationWithDefaultsModel/src/test/resources/RelationWithDefaultsModel.jsl b/judo-runtime-core-jsl-itest/models/RelationWithDefaultsModel/src/test/resources/RelationWithDefaultsModel.jsl
index ee3a0942..7cfb985d 100644
--- a/judo-runtime-core-jsl-itest/models/RelationWithDefaultsModel/src/test/resources/RelationWithDefaultsModel.jsl
+++ b/judo-runtime-core-jsl-itest/models/RelationWithDefaultsModel/src/test/resources/RelationWithDefaultsModel.jsl
@@ -21,25 +21,25 @@ transfer ItemTransfer(Item i) {
// optional entity without default
entity CollectorWithSingleOptionalRelation {
- relation Item opItem;
+ relation Item optItem;
}
// related transfers (optional, optional with default, required, required with default)
transfer CollectorWithSingleOptionalRelationOptionalTransfer(CollectorWithSingleOptionalRelation c) {
- relation ItemTransfer opItem <= c.opItem create:true;
+ relation ItemTransfer optItem <= c.optItem create:true;
}
transfer CollectorWithSingleOptionalRelationOptionalDefaultTransfer(CollectorWithSingleOptionalRelation c) {
- relation ItemTransfer opItem <= c.opItem create:true default: Item.all().filter(i | i.number < 4).any();
+ relation ItemTransfer optItem <= c.optItem create:true default: Item.all().filter(i | i.number < 4).any();
}
transfer CollectorWithSingleOptionalRelationRequiredTransfer(CollectorWithSingleOptionalRelation c) {
- relation ItemTransfer reqItem <= c.opItem required;
+ relation ItemTransfer reqItem <= c.optItem required;
}
transfer CollectorWithSingleOptionalRelationRequiredDefaultTransfer(CollectorWithSingleOptionalRelation c) {
- relation ItemTransfer reqItem <= c.opItem create:true default: Item.all().filter(i | i.number < 4).any() required;
+ relation ItemTransfer reqItem <= c.optItem create:true default: Item.all().filter(i | i.number < 4).any() required;
}
// required entity without default
@@ -51,11 +51,11 @@ entity CollectorWithSingleRequiredRelation {
// related transfers (optional, optional with default, required, required with default)
transfer CollectorWithSingleRequiredRelationOptionalTransfer(CollectorWithSingleRequiredRelation c) {
- relation ItemTransfer opItem <= c.reqItem create:true;
+ relation ItemTransfer optItem <= c.reqItem create:true;
}
transfer CollectorWithSingleRequiredRelationOptionalDefaultTransfer(CollectorWithSingleRequiredRelation c) {
- relation ItemTransfer opItem <= c.reqItem create:true default: Item.all().filter(i | i.number < 4).any();
+ relation ItemTransfer optItem <= c.reqItem create:true default: Item.all().filter(i | i.number < 4).any();
}
transfer CollectorWithSingleRequiredRelationRequiredTransfer(CollectorWithSingleRequiredRelation c) {
@@ -73,8 +73,34 @@ entity CollectorWithSingleOptionalDefaultRelation {
relation Item optItem default: Item.all().filter(i | i.number < 4).any();
}
-// optional entity with default
+// inherited relation default
+entity CollectorWithSingleOptionalDefaultRelationExtended extends CollectorWithSingleOptionalDefaultRelation {
+}
+
+// transfer
+
+transfer CollectorWithSingleOptionalDefaultRelationOptionalTransfer(CollectorWithSingleOptionalDefaultRelation c) {
+ relation ItemTransfer optItem <= c.optItem create:true;
+}
+
+transfer CollectorWithSingleOptionalDefaultRelationOptionalDefaultTransfer(CollectorWithSingleOptionalDefaultRelation c) {
+ relation ItemTransfer optItem <= c.optItem create:true default: Item.all().filter(i | i.name == "A1").any();
+}
+transfer CollectorWithSingleOptionalDefaultRelationRequiredTransfer(CollectorWithSingleOptionalDefaultRelation c) {
+ relation ItemTransfer reqItem <= c.optItem create:true required;
+}
+
+transfer CollectorWithSingleOptionalDefaultRelationRequiredDefaultTransfer(CollectorWithSingleOptionalDefaultRelation c) {
+ relation ItemTransfer reqItem <= c.optItem create:true default: Item.all().filter(i | i.name == "A1").any() required;
+}
+
+// required entity with default
entity CollectorWithSingleRequiredDefaultRelation {
relation Item reqItem default: Item.all().filter(i | i.number < 4).any() required;
-}
\ No newline at end of file
+}
+
+// inherited relation default
+entity CollectorWithSingleRequiredDefaultRelationExtended extends CollectorWithSingleRequiredDefaultRelation {
+}
+
diff --git a/pom.xml b/pom.xml
index 374dc726..c77f1114 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,7 +43,7 @@
javax.resource;version="[1.6,2)"
- 1.1.4.20250108_125648_5669c1a9_develop
+ 1.1.4.20250110_103837_8a62d874_feature_JNG_6081_Default_relation_elements_arent_transform_in_Entity
1.0.6.20250108_115741_c8a3626a_develop
1.0.0.20241216_144906_8009d231_develop