Search in sources :

Example 21 with SampleSimpleDatabaseObject

use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.

the class PriorityTest method shouldNotMoveToPositionAboveMax.

@Test
public void shouldNotMoveToPositionAboveMax() throws Exception {
    // given
    SampleSimpleDatabaseObject databaseObject = new SampleSimpleDatabaseObject(1L);
    databaseObject.setPriority(11);
    given(session.get(any(Class.class), Matchers.anyInt())).willReturn(databaseObject);
    given(criteria.uniqueResult()).willReturn(5);
    given(criteria.list()).willReturn(Lists.newArrayList());
    // when
    dataDefinition.moveTo(1L, 10);
    // then
    SampleSimpleDatabaseObject movedDatabaseObject = new SampleSimpleDatabaseObject(1L);
    movedDatabaseObject.setPriority(5);
    verify(session).update(movedDatabaseObject);
}
Also used : SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 22 with SampleSimpleDatabaseObject

use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.

the class PriorityTest method shouldNotMoveIfPositionDoesNotChange.

@Test
public void shouldNotMoveIfPositionDoesNotChange() throws Exception {
    // given
    SampleSimpleDatabaseObject databaseObject = new SampleSimpleDatabaseObject(1L);
    databaseObject.setPriority(11);
    given(criteria.uniqueResult()).willReturn(databaseObject, 11);
    given(criteria.list()).willReturn(Lists.newArrayList());
    // when
    dataDefinition.moveTo(1L, 15);
    // then
    verify(session, never()).update(Mockito.any(SampleSimpleDatabaseObject.class));
}
Also used : SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 23 with SampleSimpleDatabaseObject

use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.

the class PriorityTest method shouldChangeEntitiesBetweenCurrentAndTargetPriorityWhileMovingTo.

@Test
public void shouldChangeEntitiesBetweenCurrentAndTargetPriorityWhileMovingTo() throws Exception {
    // given
    SampleSimpleDatabaseObject existingDatabaseObject = new SampleSimpleDatabaseObject(1L);
    existingDatabaseObject.setPriority(5);
    SampleSimpleDatabaseObject otherDatabaseObject = new SampleSimpleDatabaseObject(2L);
    otherDatabaseObject.setPriority(6);
    given(session.get(any(Class.class), Matchers.anyInt())).willReturn(existingDatabaseObject);
    given(criteria.uniqueResult()).willReturn(6);
    given(criteria.list()).willReturn(Lists.newArrayList(otherDatabaseObject));
    // when
    dataDefinition.moveTo(1L, 6);
    // then
    SampleSimpleDatabaseObject movedDatabaseObject = new SampleSimpleDatabaseObject(1L);
    movedDatabaseObject.setPriority(6);
    verify(session).update(movedDatabaseObject);
    SampleSimpleDatabaseObject updatedDatabaseObject = new SampleSimpleDatabaseObject(2L);
    updatedDatabaseObject.setPriority(5);
    verify(session).update(updatedDatabaseObject);
}
Also used : SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 24 with SampleSimpleDatabaseObject

use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.

the class PriorityTest method shouldNotMoveToOffsetAboveMax.

@Test
public void shouldNotMoveToOffsetAboveMax() throws Exception {
    // given
    SampleSimpleDatabaseObject databaseObject = new SampleSimpleDatabaseObject(1L);
    databaseObject.setPriority(11);
    given(session.get(any(Class.class), Matchers.anyInt())).willReturn(databaseObject);
    given(criteria.uniqueResult()).willReturn(15);
    given(criteria.list()).willReturn(Lists.newArrayList());
    // when
    dataDefinition.moveTo(1L, 20);
    // then
    SampleSimpleDatabaseObject movedDatabaseObject = new SampleSimpleDatabaseObject(1L);
    movedDatabaseObject.setPriority(15);
    verify(session).update(movedDatabaseObject);
}
Also used : SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 25 with SampleSimpleDatabaseObject

use of com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject in project qcadoo by qcadoo.

the class DataAccessServiceFindTest method createDatabaseObject.

private SampleSimpleDatabaseObject createDatabaseObject(final Long id, final String name, final int age) {
    SampleSimpleDatabaseObject simpleDatabaseObject = new SampleSimpleDatabaseObject(id);
    simpleDatabaseObject.setName(name);
    simpleDatabaseObject.setAge(age);
    return simpleDatabaseObject;
}
Also used : SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)

Aggregations

SampleSimpleDatabaseObject (com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject)50 Test (org.junit.Test)49 Entity (com.qcadoo.model.api.Entity)27 SampleParentDatabaseObject (com.qcadoo.model.beans.sample.SampleParentDatabaseObject)13 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)8 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)8 EntityHookDefinitionImpl (com.qcadoo.model.internal.hooks.EntityHookDefinitionImpl)7 Criteria (org.hibernate.Criteria)7 UniqueValidator (com.qcadoo.model.internal.validators.UniqueValidator)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)3 FieldHookDefinition (com.qcadoo.model.internal.api.FieldHookDefinition)3 HasManyEntitiesType (com.qcadoo.model.internal.types.HasManyEntitiesType)2 IntegerType (com.qcadoo.model.internal.types.IntegerType)2 List (java.util.List)2 EntityList (com.qcadoo.model.api.EntityList)1 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)1 SearchResult (com.qcadoo.model.api.search.SearchResult)1 EntityHookDefinition (com.qcadoo.model.internal.api.EntityHookDefinition)1 StringType (com.qcadoo.model.internal.types.StringType)1 ArrayList (java.util.ArrayList)1