use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldEqualsReturnTrueAndDoNotMakeInfinityCycleWith3Entities.
@Test
public final void shouldEqualsReturnTrueAndDoNotMakeInfinityCycleWith3Entities() {
// given
final Entity firstEntity = new DefaultEntity(dataDefinition);
final Entity secondEntity = new DefaultEntity(dataDefinition);
final Entity thirdEntity = new DefaultEntity(dataDefinition);
final Entity firstOtherEntity = new DefaultEntity(dataDefinition);
// introduce another instance with the same values to prevent comparing references instead of entity's values
final Entity firstOtherEntityB = new DefaultEntity(dataDefinition);
final Entity secondOtherEntity = new DefaultEntity(dataDefinition);
final Entity thirdOtherEntity = new DefaultEntity(dataDefinition);
firstEntity.setField(BELONGS_TO_FIELD_NAME, secondEntity);
firstEntity.setField(STRING_FIELD_NAME, L_FIRST);
secondEntity.setField(BELONGS_TO_FIELD_NAME, thirdEntity);
secondEntity.setField(STRING_FIELD_NAME, L_SECOND);
thirdEntity.setField(BELONGS_TO_FIELD_NAME, firstEntity);
thirdEntity.setField(STRING_FIELD_NAME, L_THIRD);
firstOtherEntity.setField(BELONGS_TO_FIELD_NAME, secondOtherEntity);
firstOtherEntity.setField(STRING_FIELD_NAME, L_FIRST);
firstOtherEntityB.setField(BELONGS_TO_FIELD_NAME, secondOtherEntity);
firstOtherEntityB.setField(STRING_FIELD_NAME, L_FIRST);
secondOtherEntity.setField(BELONGS_TO_FIELD_NAME, thirdOtherEntity);
secondOtherEntity.setField(STRING_FIELD_NAME, L_SECOND);
thirdOtherEntity.setField(BELONGS_TO_FIELD_NAME, firstOtherEntityB);
thirdOtherEntity.setField(STRING_FIELD_NAME, L_THIRD);
// when
boolean result = false;
try {
result = firstEntity.equals(firstOtherEntity);
} catch (StackOverflowError e) {
Assert.fail();
}
// then
assertTrue(result);
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldEqualsReturnsFalseAndDoNotMakeInfinityCycleWithHasManyFieldWithoutId.
@Test
public final void shouldEqualsReturnsFalseAndDoNotMakeInfinityCycleWithHasManyFieldWithoutId() {
// given
final Entity firstEntity = new DefaultEntity(dataDefinition);
final Entity secondEntity = new DefaultEntity(dataDefinition);
firstEntity.setField(HAS_MANY_FIELD_NAME, Lists.newArrayList(secondEntity));
firstEntity.setField(BELONGS_TO_FIELD_NAME, secondEntity);
firstEntity.setField(STRING_FIELD_NAME, L_FIRST);
secondEntity.setField(HAS_MANY_FIELD_NAME, Lists.newArrayList(firstEntity));
secondEntity.setField(BELONGS_TO_FIELD_NAME, firstEntity);
secondEntity.setField(STRING_FIELD_NAME, L_SECOND);
// when
boolean result = true;
try {
result = firstEntity.equals(secondEntity);
} catch (StackOverflowError e) {
Assert.fail();
}
// then
assertFalse(result);
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldReturnDetachedEntityListImpl.
@Test
public final void shouldReturnDetachedEntityListImpl() throws Exception {
// given
final String hasManyFieldName = "hasManyDetachedField";
List<Entity> listOfMockEntities = getListOfMockEntities();
defaultEntity.setField(hasManyFieldName, listOfMockEntities);
// when
EntityList resultList = defaultEntity.getHasManyField(hasManyFieldName);
// then
Assert.assertTrue(resultList instanceof DetachedEntityListImpl);
Assert.assertEquals(listOfMockEntities.size(), resultList.size());
Assert.assertArrayEquals(listOfMockEntities.toArray(), resultList.toArray());
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldCopyDoNotMakeInfinityCycleWith2EntitiesWithoutId.
@Test
public final void shouldCopyDoNotMakeInfinityCycleWith2EntitiesWithoutId() {
// given
final Entity firstEntity = new DefaultEntity(dataDefinition);
final Entity secondEntity = new DefaultEntity(dataDefinition);
firstEntity.setField(BELONGS_TO_FIELD_NAME, secondEntity);
firstEntity.setField(STRING_FIELD_NAME, L_FIRST);
secondEntity.setField(BELONGS_TO_FIELD_NAME, firstEntity);
secondEntity.setField(STRING_FIELD_NAME, L_SECOND);
// when
Entity copy = null;
try {
copy = firstEntity.copy();
} catch (StackOverflowError e) {
Assert.fail();
}
// then
assertNotSame(firstEntity, copy);
assertEquals(firstEntity, copy);
assertNotSame(secondEntity, copy.getBelongsToField(BELONGS_TO_FIELD_NAME));
assertEquals(secondEntity, copy.getBelongsToField(BELONGS_TO_FIELD_NAME));
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldHashCodeDoNotMakeInfinityCycleWith2DeeplyNestedEntitiesWithoutId.
@Test
public final void shouldHashCodeDoNotMakeInfinityCycleWith2DeeplyNestedEntitiesWithoutId() {
// given
final Entity firstEntity = new DefaultEntity(dataDefinition);
final Entity secondEntity = new DefaultEntity(dataDefinition);
final Entity thirdEntity = new DefaultEntity(dataDefinition);
final Entity fourthEntity = new DefaultEntity(dataDefinition);
firstEntity.setField(BELONGS_TO_FIELD_NAME, secondEntity);
firstEntity.setField(STRING_FIELD_NAME, L_FIRST);
secondEntity.setField(BELONGS_TO_FIELD_NAME, thirdEntity);
secondEntity.setField(STRING_FIELD_NAME, L_SECOND);
thirdEntity.setField(BELONGS_TO_FIELD_NAME, fourthEntity);
thirdEntity.setField(STRING_FIELD_NAME, L_THIRD);
fourthEntity.setField(BELONGS_TO_FIELD_NAME, thirdEntity);
fourthEntity.setField(STRING_FIELD_NAME, L_FOURTH);
// when
try {
firstEntity.hashCode();
} catch (StackOverflowError e) {
Assert.fail();
}
}
Aggregations