use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldHashCodeDoNotMakeInfinityCycleWith4Entities.
@Test
public final void shouldHashCodeDoNotMakeInfinityCycleWith4Entities() {
// 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.setId(1L);
firstEntity.setField(BELONGS_TO_FIELD_NAME, secondEntity);
secondEntity.setId(2L);
secondEntity.setField(BELONGS_TO_FIELD_NAME, thirdEntity);
thirdEntity.setId(3L);
thirdEntity.setField(BELONGS_TO_FIELD_NAME, fourthEntity);
fourthEntity.setId(4L);
fourthEntity.setField(BELONGS_TO_FIELD_NAME, firstEntity);
// 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 shouldToStringDoNotMakeInfinityCycleWithHasManyField.
@Test
public final void shouldToStringDoNotMakeInfinityCycleWithHasManyField() {
// 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.setId(1L);
secondEntity.setField(HAS_MANY_FIELD_NAME, Lists.newArrayList(firstEntity));
secondEntity.setField(BELONGS_TO_FIELD_NAME, firstEntity);
secondEntity.setId(2L);
// 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 shouldEqualsReturnTrueAndDoNotMakeInfinityCycleWithManyToManyField.
@Test
public final void shouldEqualsReturnTrueAndDoNotMakeInfinityCycleWithManyToManyField() {
// 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.setId(1L);
secondEntity.setField(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(firstEntity));
secondEntity.setId(2L);
firstOtherEntity.setField(MANY_TO_MANY_FIELD_NAME, Lists.newArrayList(secondOtherEntity));
firstOtherEntity.setId(1L);
secondOtherEntity.setField(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 shouldHashCodeDoNotMakeInfinityCycleWithTwoDeeplyNestedManyToManyFields.
@Test
public final void shouldHashCodeDoNotMakeInfinityCycleWithTwoDeeplyNestedManyToManyFields() {
// 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.hashCode();
} catch (StackOverflowError e) {
Assert.fail();
}
}
use of com.qcadoo.model.api.Entity in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldHashCodeDoNotMakeInfinityCycleWithDeeplyNestedHasManyFields.
@Test
public final void shouldHashCodeDoNotMakeInfinityCycleWithDeeplyNestedHasManyFields() {
// 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.setField(HAS_MANY_FIELD_NAME, Lists.newArrayList(fourthEntity));
thirdEntity.setId(3L);
fourthEntity.setField(BELONGS_TO_FIELD_NAME, thirdEntity);
fourthEntity.setField(HAS_MANY_FIELD_NAME, Lists.newArrayList(thirdEntity));
fourthEntity.setId(4L);
// when
try {
firstEntity.hashCode();
} catch (StackOverflowError e) {
Assert.fail();
}
}
Aggregations