WorkloadDao extends BaseDao<Workload> { @Nullable @Override public Workload findById(@Nonnull Integer id) { Workload workload = null; try { begin(); workload = getEntityManager().find(Workload.class, id); if(workload != null) { workload.getJobConfiguration(); for ( TestPlan tp : workload.getTestPlans() ) { for (ScriptGroup sg : tp.getScriptGroups() ) { sg.getScriptGroupSteps(); } } } commit(); } catch (Exception e) { rollback(); e.printStackTrace(); throw new RuntimeException(e); } finally { cleanup(); } return workload; } WorkloadDao(); @Nullable @Override Workload findById(@Nonnull Integer id); Workload loadScriptsForWorkload(Workload workload);  }
@Test @Tag(TestGroups.FUNCTIONAL) public void testScriptGroupOrder() throws Exception { Workload workload = DaoTestUtil.createWorkload(); TestPlan tp = TestPlan.builder().name("default test plan").usersPercentage(100).build(); workload.addTestPlan(tp); tp.addScriptGroup(DaoTestUtil.createScriptGroup(10)); tp.addScriptGroup(DaoTestUtil.createScriptGroup(10)); tp.addScriptGroup(DaoTestUtil.createScriptGroup(10)); Workload persistedWorkload = dao.saveOrUpdate(workload); Integer id = persistedWorkload.getId(); try { List<ScriptGroup> scriptGroups = persistedWorkload.getTestPlans().get(0).getScriptGroups(); ArrayList<ScriptGroup> originalOrder = new ArrayList<ScriptGroup>(scriptGroups); ScriptGroup removed = scriptGroups.remove(2); scriptGroups.add(0, removed); persistedWorkload = dao.saveOrUpdate(persistedWorkload); persistedWorkload = dao.findById(id); assertNotEquals(persistedWorkload.getTestPlans().get(0).getScriptGroups().get(0), originalOrder.get(0)); assertEquals(persistedWorkload.getTestPlans().get(0).getScriptGroups().get(0), originalOrder.get(2)); assertEquals(persistedWorkload.getTestPlans().get(0).getScriptGroups().get(1), originalOrder.get(0)); assertEquals(persistedWorkload.getTestPlans().get(0).getScriptGroups().get(2), originalOrder.get(1)); originalOrder = new ArrayList<ScriptGroup>(persistedWorkload.getTestPlans().get(0).getScriptGroups()); persistedWorkload.getTestPlans().get(0).getScriptGroups().remove(2); persistedWorkload.getTestPlans().get(0).getScriptGroups().remove(0); persistedWorkload = dao.saveOrUpdate(persistedWorkload); persistedWorkload = dao.findById(id); assertEquals(persistedWorkload.getTestPlans().get(0).getScriptGroups().get(0), originalOrder.get(1)); assertEquals(1, persistedWorkload.getTestPlans().size()); } finally { dao.delete(id); } }
@Test @Tag(TestGroups.FUNCTIONAL) public void testBasicCreateUpdateDelete() throws Exception { List<Workload> all = dao.findAll(); int originalSize = all.size(); Workload workload = DaoTestUtil.createWorkload(); TestPlan tp = TestPlan.builder().name("default test plan").usersPercentage(100).build(); workload.addTestPlan(tp); tp.addScriptGroup(DaoTestUtil.createScriptGroup(10)); Workload persistedWorkload = dao.saveOrUpdate(workload); validateWorkload(workload, persistedWorkload, false); workload = dao.findById(persistedWorkload.getId()); workload.setName("New Workload Name"); persistedWorkload = dao.saveOrUpdate(workload); validateWorkload(workload, persistedWorkload, true); all = dao.findAll(); assertNotNull(all); assertEquals(originalSize + 1, all.size()); all = dao.findAll(); assertNotNull(all); assertEquals(originalSize + 1, all.size()); dao.delete(persistedWorkload); workload = dao.findById(workload.getId()); assertNull(workload); all = dao.findAll(); assertEquals(originalSize, all.size()); }