use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class DynamicAttributesTest method testCollectionOfEntitiesAttribute.
@Test
public void testCollectionOfEntitiesAttribute() {
LoadContext<User> loadContext = LoadContext.create(User.class).setId(user.getId()).setLoadDynamicAttributes(true);
User loadedUser = dataManager.load(loadContext);
List<Group> groupsCollection = loadedUser.getValue("+userGroupCollectionAttribute");
assertEquals(2, groupsCollection.size());
loadedUser.setValue("+userGroupCollectionAttribute", Lists.newArrayList(group));
dataManager.commit(loadedUser);
loadedUser = dataManager.load(loadContext);
groupsCollection = loadedUser.getValue("+userGroupCollectionAttribute");
assertEquals(1, groupsCollection.size());
assertEquals(group, groupsCollection.get(0));
loadedUser.setValue("+userGroupCollectionAttribute", Lists.newArrayList(group, group2));
dataManager.commit(loadedUser);
groupsCollection = loadedUser.getValue("+userGroupCollectionAttribute");
assertEquals(2, groupsCollection.size());
}
use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class EclipseLinkQueriesTest method testJoinOnWithToManyView2.
// join on, view contains ToMany attribute, fetch = JOIN
@Test
public void testJoinOnWithToManyView2() throws Exception {
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.entityManager();
View view = new View(Group.class).addProperty("constraints", new View(Constraint.class, View.LOCAL), FetchMode.JOIN);
TypedQuery<Group> query = em.createQuery("select g from sec$Group g join sys$QueryResult qr on qr.entityId = g.id where qr.queryKey = 1", Group.class);
query.setView(view);
List<Group> result = query.getResultList();
tx.commit();
}
}
use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class EclipseLinkQueriesTest method testJoinOnWithParentReference.
// join on, view contains parent attribute
@Test
public void testJoinOnWithParentReference() throws Exception {
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.entityManager();
View view = new View(Group.class).addProperty("parent");
TypedQuery<Group> query = em.createQuery("select g from sec$Group g join sys$QueryResult qr on qr.entityId = g.id where qr.queryKey = 1", Group.class);
query.setView(view);
List<Group> result = query.getResultList();
tx.commit();
}
}
use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class EclipseLinkQueriesTest method testCrossJoinViewParentReference.
// cross join, view with the reference to the parent entity
@Test
public void testCrossJoinViewParentReference() throws Exception {
List<Group> result;
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.entityManager();
View view = new View(Group.class).addProperty("parent");
TypedQuery<Group> query = em.createQuery("select g from sec$Group g, sec$User u where u.group = g", Group.class);
query.setView(view);
result = query.getResultList();
tx.commit();
}
for (Group g : result) {
g = reserialize(g);
if (g.equals(rootGroup))
assertNull(g.getParent());
else if (g.equals(group))
assertEquals(rootGroup, g.getParent());
}
}
use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class EclipseLinkQueriesTest method testCrossJoinWithToManyView.
// cross join, view has ToMany reference
@Test
public void testCrossJoinWithToManyView() throws Exception {
List<Group> result;
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.entityManager();
View view = new View(Group.class).addProperty("constraints");
TypedQuery<Group> query = em.createQuery("select g from sec$Group g, sec$User u where u.group = g", Group.class);
query.setView(view);
result = query.getResultList();
tx.commit();
}
for (Group group : result) {
group = reserialize(group);
group.getConstraints().size();
}
}
Aggregations