use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class PersistenceHelperTest method testCheckLoaded.
@Test
public void testCheckLoaded() {
Server server = new Server();
persistence.runInTransaction((em) -> {
em.persist(server);
});
FetchPlan view = new View(Server.class).addProperty("name").addProperty("data").setLoadPartialEntities(true);
Server reloadedServer = persistence.callInTransaction((em) -> {
return em.find(Server.class, server.getId(), view);
});
// fine
entityStates.checkLoaded(reloadedServer, "name");
try {
entityStates.checkLoaded(reloadedServer, "data", "running");
Assertions.fail("Must throw exception");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("Server.running"));
}
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class UpdateDetachedTest method test.
@Test
public void test() throws Exception {
Permission p;
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
FetchPlan view = new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name"));
p = em.find(Permission.class, permissionId, view);
tx.commitRetaining();
assertNotNull(p);
p.setTarget("newTarget");
em = persistence.getEntityManager();
p = em.merge(p);
tx.commit();
} finally {
tx.end();
}
p = testSupport.reserialize(p);
assertTrue(entityStates.isDetached(p));
assertNotNull(p.getRole());
assertTrue(entityStates.isDetached(p.getRole()));
assertTrue(entityStates.isLoaded(p, "role"));
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class UpdateDetachedTest method testRollback.
@Test
public void testRollback() {
Permission p = null;
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
FetchPlan view = new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name"));
p = em.find(Permission.class, permissionId, view);
tx.commitRetaining();
p.setTarget("newTarget");
em = persistence.getEntityManager();
p = em.merge(p);
throwException();
tx.commit();
} catch (RuntimeException e) {
// ok
} finally {
tx.end();
assertNotNull(p);
}
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class ViewBuilderTest method testBase.
@Test
public void testBase() {
FetchPlan view = ViewBuilder.of(Pet.class).addView(FetchPlan.BASE).build();
assertTrue(containsSystemProperties(view));
assertTrue(view.containsProperty("name"));
}
use of io.jmix.core.FetchPlan in project jmix by jmix-framework.
the class ViewBuilderTest method testLocalAndRef.
@Test
public void testLocalAndRef() {
FetchPlan view = ViewBuilder.of(Pet.class).addView(FetchPlan.LOCAL).add("owner").build();
assertTrue(containsSystemProperties(view));
assertTrue(view.containsProperty("name"));
assertNotNull(view.getProperty("owner"));
FetchPlan ownerView = view.getProperty("owner").getFetchPlan();
assertNotNull(ownerView);
assertFalse(containsSystemProperties(ownerView));
assertFalse(ownerView.containsProperty("name"));
assertFalse(ownerView.containsProperty("address"));
view = ViewBuilder.of(Pet.class).addView(FetchPlan.LOCAL).add("owner.name").add("owner.address.city").build();
assertTrue(containsSystemProperties(view));
assertTrue(view.containsProperty("name"));
assertNotNull(view.getProperty("owner"));
ownerView = view.getProperty("owner").getFetchPlan();
assertNotNull(ownerView);
assertFalse(containsSystemProperties(ownerView));
assertTrue(ownerView.containsProperty("name"));
assertTrue(ownerView.containsProperty("address"));
FetchPlan addressView = ownerView.getProperty("address").getFetchPlan();
assertTrue(addressView.containsProperty("city"));
}
Aggregations