use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldToStringDoNotMakeInfinityCycleWithHasManyFieldWithoutId.
@Test
public final void shouldToStringDoNotMakeInfinityCycleWithHasManyFieldWithoutId() {
// 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(BELONGS_TO_FIELD_NAME, secondEntity);
firstEntity.setField(STRING_FIELD_NAME, L_FIRST);
secondEntity.setField(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(firstEntity));
secondEntity.setField(BELONGS_TO_FIELD_NAME, firstEntity);
secondEntity.setField(STRING_FIELD_NAME, L_SECOND);
// 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 shouldHashCodeDoNotMakeInfinityCycleWith2Entities.
@Test
public final void shouldHashCodeDoNotMakeInfinityCycleWith2Entities() {
// given
final Entity firstEntity = new DefaultEntity(dataDefinition);
final Entity secondEntity = new DefaultEntity(dataDefinition);
secondEntity.setField(BELONGS_TO_FIELD_NAME, firstEntity);
secondEntity.setId(2L);
firstEntity.setField(BELONGS_TO_FIELD_NAME, secondEntity);
firstEntity.setId(1L);
// when
try {
firstEntity.hashCode();
} catch (StackOverflowError e) {
Assert.fail();
}
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldCopyDoNotMakeInfinityCycleWith2DeeplyNestedEntitiesWithoutId.
@Test
public final void shouldCopyDoNotMakeInfinityCycleWith2DeeplyNestedEntitiesWithoutId() {
// 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
Entity copy = null;
try {
copy = firstEntity.copy();
} catch (StackOverflowError e) {
Assert.fail();
}
// then
assertNotSame(firstEntity, copy);
assertEquals(firstEntity, copy);
assertEquals(secondEntity, copy.getBelongsToField(BELONGS_TO_FIELD_NAME));
assertNotSame(secondEntity, copy.getBelongsToField(BELONGS_TO_FIELD_NAME));
assertEquals(thirdEntity, copy.getBelongsToField(BELONGS_TO_FIELD_NAME).getBelongsToField(BELONGS_TO_FIELD_NAME));
assertNotSame(thirdEntity, copy.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));
assertNotSame(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 shouldHashCodeDoNotMakeInfinityCycleWithHasManyFields.
@Test
public final void shouldHashCodeDoNotMakeInfinityCycleWithHasManyFields() {
// given
final Entity firstEntity = new DefaultEntity(dataDefinition);
final Entity secondEntity = new DefaultEntity(dataDefinition);
firstEntity.setField(BELONGS_TO_FIELD_NAME, secondEntity);
firstEntity.setField(HAS_MANY_FIELD_NAME, Lists.newArrayList(secondEntity));
firstEntity.setId(1L);
secondEntity.setField(BELONGS_TO_FIELD_NAME, firstEntity);
secondEntity.setField(HAS_MANY_FIELD_NAME, Lists.newArrayList(firstEntity));
secondEntity.setId(2L);
// when
try {
firstEntity.hashCode();
} catch (StackOverflowError e) {
Assert.fail();
}
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldToStringDoNotMakeInfinityCycleWithTwoDeeplyNestedManyToManyFields.
@Test
public final void shouldToStringDoNotMakeInfinityCycleWithTwoDeeplyNestedManyToManyFields() {
// 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(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(fourthEntity));
thirdEntity.setField(SECOND_MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(fourthEntity));
thirdEntity.setId(3L);
fourthEntity.setField(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(thirdEntity));
fourthEntity.setField(SECOND_MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(thirdEntity));
fourthEntity.setId(4L);
// when
try {
firstEntity.toString();
} catch (StackOverflowError e) {
Assert.fail();
}
}
Aggregations