Skip to content

Commit

Permalink
JNG-6081 Default relation elements arent transform in Entity (#340)
Browse files Browse the repository at this point in the history
* add test for entity defaults

* upadate version

* Add optinal default entitiy and transfer variation test

* add jira tickets
  • Loading branch information
gaborflorian authored Jan 10, 2025
1 parent 2baba45 commit 32036ae
Show file tree
Hide file tree
Showing 4 changed files with 634 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);

}

}
Loading

0 comments on commit 32036ae

Please sign in to comment.