use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldEqualsReturnFalseIfBelongsToFieldIsNullOnlyOnOneSide.
@Test
public final void shouldEqualsReturnFalseIfBelongsToFieldIsNullOnlyOnOneSide() {
// given
final Entity firstEntity = new DefaultEntity(dataDefinition);
final Entity secondEntity = new DefaultEntity(dataDefinition);
final Entity firstOtherEntity = new DefaultEntity(dataDefinition);
final Entity secondOtherEntity = null;
firstEntity.setField(BELONGS_TO_FIELD_NAME, secondEntity);
firstEntity.setField(STRING_FIELD_NAME, L_FIRST);
firstOtherEntity.setField(BELONGS_TO_FIELD_NAME, secondOtherEntity);
firstOtherEntity.setField(STRING_FIELD_NAME, L_FIRST);
// when
final boolean result = firstEntity.equals(firstOtherEntity);
// then
assertFalse(result);
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldToStringDoNotMakeInfinityCycleWith3Entities.
@Test
public final void shouldToStringDoNotMakeInfinityCycleWith3Entities() {
// given
final Entity firstEntity = new DefaultEntity(dataDefinition);
final Entity secondEntity = new DefaultEntity(dataDefinition);
final Entity thirdEntity = new DefaultEntity(dataDefinition);
firstEntity.setField(BELONGS_TO_FIELD_NAME, secondEntity);
firstEntity.setId(1L);
secondEntity.setField(BELONGS_TO_FIELD_NAME, thirdEntity);
secondEntity.setId(2L);
thirdEntity.setField(BELONGS_TO_FIELD_NAME, firstEntity);
thirdEntity.setId(3L);
// when
try {
firstEntity.toString();
} catch (StackOverflowError e) {
Assert.fail();
}
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldEqualsReturnTrueAndDoNotMakeInfinityCycleWithTwoManyToManyFields.
@Test
public final void shouldEqualsReturnTrueAndDoNotMakeInfinityCycleWithTwoManyToManyFields() {
// given
final Entity firstEntity = new DefaultEntity(dataDefinition);
final Entity secondEntity = new DefaultEntity(dataDefinition);
final Entity firstOtherEntity = new DefaultEntity(dataDefinition);
final Entity secondOtherEntity = new DefaultEntity(dataDefinition);
firstEntity.setField(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(secondEntity));
firstEntity.setField(SECOND_MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(secondEntity));
firstEntity.setId(1L);
secondEntity.setField(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(firstEntity));
secondEntity.setField(SECOND_MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(firstEntity));
secondEntity.setId(2L);
firstOtherEntity.setField(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(secondOtherEntity));
firstOtherEntity.setField(SECOND_MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(secondOtherEntity));
firstOtherEntity.setId(1L);
secondOtherEntity.setField(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(firstOtherEntity));
secondOtherEntity.setField(SECOND_MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(firstOtherEntity));
secondOtherEntity.setId(2L);
// when
boolean result = true;
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 shouldCopyDoNotMakeInfinityCycleWith4Entities.
@Test
public final void shouldCopyDoNotMakeInfinityCycleWith4Entities() {
// 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.setId(1L);
secondEntity.setField(BELONGS_TO_FIELD_NAME, thirdEntity);
secondEntity.setId(2L);
thirdEntity.setField(BELONGS_TO_FIELD_NAME, fourthEntity);
thirdEntity.setId(3L);
fourthEntity.setField(BELONGS_TO_FIELD_NAME, firstEntity);
fourthEntity.setId(4L);
// when
Entity copy = null;
try {
copy = firstEntity.copy();
} catch (StackOverflowError e) {
Assert.fail();
}
assertNotSame(firstEntity, copy);
assertEquals(firstEntity, copy);
assertNotSame(secondEntity, copy.getBelongsToField(BELONGS_TO_FIELD_NAME));
assertEquals(secondEntity, copy.getBelongsToField(BELONGS_TO_FIELD_NAME));
assertNotSame(thirdEntity, copy.getBelongsToField(BELONGS_TO_FIELD_NAME).getBelongsToField(BELONGS_TO_FIELD_NAME));
assertEquals(thirdEntity, copy.getBelongsToField(BELONGS_TO_FIELD_NAME).getBelongsToField(BELONGS_TO_FIELD_NAME));
assertNotSame(fourthEntity, copy.getBelongsToField(BELONGS_TO_FIELD_NAME).getBelongsToField(BELONGS_TO_FIELD_NAME).getBelongsToField(BELONGS_TO_FIELD_NAME));
assertEquals(fourthEntity, copy.getBelongsToField(BELONGS_TO_FIELD_NAME).getBelongsToField(BELONGS_TO_FIELD_NAME).getBelongsToField(BELONGS_TO_FIELD_NAME));
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldCopyDoNotMakeInfinityCycleWithTwoManyToManyFields.
@Test
public final void shouldCopyDoNotMakeInfinityCycleWithTwoManyToManyFields() {
// given
final Entity firstEntity = new DefaultEntity(dataDefinition);
final Entity secondEntity = new DefaultEntity(dataDefinition);
firstEntity.setField(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(secondEntity));
firstEntity.setField(SECOND_MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(secondEntity));
firstEntity.setId(1L);
secondEntity.setField(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(firstEntity));
secondEntity.setField(SECOND_MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(firstEntity));
secondEntity.setId(2L);
// when
Entity copy = null;
try {
copy = firstEntity.copy();
} catch (StackOverflowError e) {
Assert.fail();
}
// then
assertNotSame(firstEntity, copy);
assertEquals(firstEntity, copy);
assertSame(secondEntity, firstEntity.getManyToManyField(MANY_TO_MANY_FIELD_NAME).get(0));
assertSame(secondEntity, firstEntity.getManyToManyField(SECOND_MANY_TO_MANY_FIELD_NAME).get(0));
}
Aggregations