예제 #1
0
  @Test(groups = {"functional"})
  public void testBasicCreateUpdateDelete() throws Exception {
    List<Script> all = dao.findAll();
    int originalSize = all.size();
    Script entity = DaoTestUtil.createScript();
    entity.addStep(DaoTestUtil.createScriptStep());
    Script persisted = dao.saveOrUpdate(entity);

    validate(entity, persisted, false);
    entity = dao.findById(persisted.getId());
    entity = dao.loadScriptSteps(entity);
    entity.setName("New Workload Name");
    persisted = dao.saveOrUpdate(entity);
    validate(entity, persisted, true);

    all = dao.findAll();
    Assert.assertNotNull(all);
    Assert.assertEquals(originalSize + 1, all.size());

    all = dao.findAll();
    Assert.assertNotNull(all);
    Assert.assertEquals(originalSize + 1, all.size());

    // delete it
    dao.delete(persisted);
    entity = dao.findById(entity.getId());
    Assert.assertNull(entity);
    all = dao.findAll();
    Assert.assertEquals(originalSize, all.size());
  }
예제 #2
0
  @Test(groups = {"functional"})
  public void testChildOrder() throws Exception {
    Script entity = DaoTestUtil.createScript();
    entity.addStep(DaoTestUtil.createScriptStep());
    entity.addStep(DaoTestUtil.createScriptStep());
    entity.addStep(DaoTestUtil.createScriptStep());
    Script persisted = dao.saveOrUpdate(entity);
    Integer id = persisted.getId();
    try {
      List<ScriptStep> children = persisted.getScriptSteps();
      ArrayList<ScriptStep> originalOrder = new ArrayList<ScriptStep>(children);
      ScriptStep removed = children.remove(2);
      children.add(0, removed);
      persisted = dao.saveOrUpdate(persisted);
      persisted = dao.findById(id);
      Assert.assertFalse(persisted.getScriptSteps().get(0).equals(originalOrder.get(0)));
      Assert.assertTrue(persisted.getScriptSteps().get(0).equals(originalOrder.get(2)));
      Assert.assertTrue(persisted.getScriptSteps().get(1).equals(originalOrder.get(0)));
      Assert.assertTrue(persisted.getScriptSteps().get(2).equals(originalOrder.get(1)));

      originalOrder = new ArrayList<ScriptStep>(persisted.getScriptSteps());
      persisted.getScriptSteps().remove(2);
      persisted.getScriptSteps().remove(0);
      persisted = dao.saveOrUpdate(persisted);
      persisted = dao.findById(id);
      Assert.assertTrue(persisted.getScriptSteps().get(0).equals(originalOrder.get(1)));
      Assert.assertEquals(1, persisted.getScriptSteps().size());

    } finally {
      // delete it
      dao.delete(id);
    }
  }
예제 #3
0
 @Test(
     groups = {"functional"},
     dataProvider = "validations")
 public void testValidation(Script entity, String property, String messageContains)
     throws Exception {
   try {
     dao.saveOrUpdate(entity);
     Assert.fail("Should have failed validation.");
   } catch (ConstraintViolationException e) {
     // expected validation
     DaoTestUtil.checkConstraintViolation(e, property, messageContains);
   }
 }
예제 #4
0
  @Test(groups = {"functional"})
  public void testFilter() throws Exception {
    Calendar calendar = Calendar.getInstance();
    Script first = DaoTestUtil.createScript();
    first = dao.saveOrUpdate(first);

    Script third = DaoTestUtil.createScript();
    calendar.add(Calendar.DAY_OF_YEAR, -10); // 10 days ago
    third.setForceCreateDate(calendar.getTime());
    third = dao.saveOrUpdate(third);

    Script second = DaoTestUtil.createScript();
    calendar.add(Calendar.DAY_OF_YEAR, 7); // 3 days ago
    second.setForceCreateDate(calendar.getTime());
    second = dao.saveOrUpdate(second);

    Script fourth = DaoTestUtil.createScript();
    calendar.add(Calendar.MONTH, -1); // 1 month and 3 days ago
    fourth.setForceCreateDate(calendar.getTime());
    fourth = dao.saveOrUpdate(fourth);

    List<Script> list = dao.findAll();
    Assert.assertEquals(4, list.size());
    Assert.assertEquals(first.getId(), list.get(0).getId());
    Assert.assertEquals(second.getId(), list.get(2).getId());
    Assert.assertEquals(third.getId(), list.get(1).getId());
    Assert.assertEquals(fourth.getId(), list.get(3).getId());

    // run our queries
    list = dao.findFiltered(ViewFilterType.LAST_TWO_WEEKS);
    Assert.assertEquals(3, list.size());
    Assert.assertEquals(first.getId(), list.get(0).getId());
    Assert.assertEquals(second.getId(), list.get(1).getId());

    list = dao.findFiltered(ViewFilterType.ALL);
    Assert.assertEquals(4, list.size());
    Assert.assertEquals(first.getId(), list.get(0).getId());
    Assert.assertEquals(second.getId(), list.get(1).getId());
    Assert.assertEquals(third.getId(), list.get(2).getId());
    Assert.assertEquals(fourth.getId(), list.get(3).getId());
  }