コード例 #1
0
ファイル: ZApiTest.java プロジェクト: Grendel2501/Zilla-J
  public void testZUpdate()
      throws RemoteException, UnexpectedErrorFault, InvalidTypeFault, MalformedQueryFault,
          InvalidQueryLocatorFault {
    try {
      ZApi zapi = new ZApi();
      assertTrue("Logged in", zapi.isLoggedIn);

      QueryResult qres =
          zapi.zQuery("Select Id,Description From Product Where Name='JTest Product'");
      ZObject[] zprods = qres.getRecords();
      Product p1 = (Product) zprods[0];
      assertTrue("Found JTest Product", p1.getDescription().equals("JTest Description"));

      p1.setDescription("JTest Description 2");
      SaveResult[] sr = zapi.zUpdate(new ZObject[] {p1});
      if (!sr[0].getSuccess()) {
        System.out.println(sr[0].getErrors()[0].getMessage());
      }
      assertTrue("Updated Product", sr[0].getSuccess());

      QueryResult qres2 =
          zapi.zQuery("Select Id,Description From Product Where Name='JTest Product'");
      ZObject[] zprods2 = qres2.getRecords();
      Product p2 = (Product) zprods2[0];
      assertTrue("Found Updated JTest Product", p2.getDescription().equals("JTest Description 2"));

    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
コード例 #2
0
ファイル: ZApiTest.java プロジェクト: Grendel2501/Zilla-J
  public void testZCreate() throws RemoteException, UnexpectedErrorFault, InvalidTypeFault {
    try {
      ZApi zapi = new ZApi();
      assertTrue("Logged in", zapi.isLoggedIn);

      Product testProd = new Product();
      testProd.setName("JTest Product");
      testProd.setDescription("JTest Description");
      Calendar sdate = Calendar.getInstance();
      Calendar edate = Calendar.getInstance();
      sdate.add(Calendar.YEAR, -50);
      edate.add(Calendar.YEAR, 50);
      testProd.setEffectiveStartDate(sdate);
      testProd.setEffectiveEndDate(edate);

      SaveResult[] sr = zapi.zCreate(new ZObject[] {testProd});
      assertTrue("Created Product", sr[0].getSuccess());

    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
コード例 #3
0
  public void testPropertyValidatorsAsBeanValidationAnnotation() throws Exception {
    Product p = new Product();
    p.setNumber(66);
    p.setDescription("MOTO");
    p.setFamilyNumber(1);
    p.setSubfamilyNumber(1);
    p.setWarehouseKey(new Warehouse());
    p.setUnitPrice(new BigDecimal("900"));

    XPersistence.getManager().persist(p);
    try {
      XPersistence.commit();
    } catch (RollbackException ex) {
      if (ex.getCause() instanceof ConstraintViolationException) {
        ConstraintViolationException cex = (ConstraintViolationException) ex.getCause();
        assertEquals("1 constraint violation expected", 1, cex.getConstraintViolations().size());
        ConstraintViolation v = cex.getConstraintViolations().iterator().next();
        assertEquals("Property", "description", v.getPropertyPath().toString());
        assertEquals("Message text", "", v.getMessage());
        return;
      }
    }
    fail("A constraint violation exception should be thrown");
  }
コード例 #4
0
  public void testEntityValidatorsAsHibernateAnnotation() throws Exception {
    Product p = new Product();
    p.setNumber(66);
    p.setDescription("BUENO, BONITO, BARATO"); // It's cheap ('BARATO') thus...
    p.setFamilyNumber(1);
    p.setSubfamilyNumber(1);
    p.setWarehouseKey(new Warehouse());
    p.setUnitPrice(new BigDecimal("900")); // ... it cannot cost 900 (max 100)

    XPersistence.getManager().persist(p);
    try {
      XPersistence.commit();
    } catch (RollbackException ex) {
      if (ex.getCause() instanceof ConstraintViolationException) {
        ConstraintViolationException cex = (ConstraintViolationException) ex.getCause();
        assertEquals("1 constraint violation expected", 1, cex.getConstraintViolations().size());
        ConstraintViolation v = cex.getConstraintViolations().iterator().next();
        assertEquals("Bean", "Product", v.getRootBean().getClass().getSimpleName());
        assertEquals("Message text", "", v.getMessage());
        return;
      }
    }
    fail("A constraint violation exception should be thrown");
  }