コード例 #1
0
  /**
   * Given that I want to execute a groovy business rule that uses the persistence api
   *
   * <p>When I call {@link ApplicationController#runOperation(ExecutionContext)}
   *
   * <p>Then I must check the resulting ExecutionContext with all the uses checked
   *
   * @throws Exception
   */
  @Test
  public void testPersistenceAPIGroovyOperation() throws Exception {
    DomainObject dObj = findDomainObject("Conta", windApp);
    ModelReference instance = bean.createNewInstance(new CommonUserContext("TEST_SESSID"), dObj);
    IStorage storage = windApp.getBean(IStorage.BEAN_NAME, IStorage.class);
    Reflect.on(instance).set("nome", "Itau");
    Reflect.on(instance).set("tipo", "Credito");
    Reflect.on(instance).set("saldo", 154.54d);
    storage.save(instance);

    PlatformMessageRegistry pmr = new PlatformMessageRegistry();
    pmr.init();

    Locale ptBrLoc = new Locale("pt", "BR");
    windApp.addResourceBundle(
        ptBrLoc,
        new PropertyResourceBundle(
            getClass().getResourceAsStream("/wind-app-controller-messages-mock.properties")));
    windApp.setCurrentLocale(ptBrLoc);

    ExecutionContext<ModelReference> ctx = new ExecutionContext<ModelReference>();
    ctx.setOperation(dObj.getOperation("UsesOfPersistenceAPI"));
    ctx.setUserContext(new CommonUserContext("TEST_SESSID"));
    ctx.setMeta(dObj);

    ctx = bean.runOperation(ctx);

    List cList = (List) ctx.getSession().get("cList");
    assertNotNull(cList);
    assertEquals(1, cList.size());
  }
コード例 #2
0
  /**
   * Given that I want to open an object instance
   *
   * <p>When I call {@link ApplicationController#openObjectInstance(java.io.Serializable,
   * ModelReference)}
   *
   * <p>Then I must check the fully loaded instance.
   */
  @Test
  public void testOpenObjectInstance() throws Exception {
    DataSource ds = windApp.getBean("datasource", DataSource.class);
    JdbcTemplate jdbcTemplate = new JdbcTemplate(ds, false);
    jdbcTemplate.execute("delete from conta");

    DomainObject dObj = findDomainObject("Conta", windApp);
    ModelReference instance = bean.createNewInstance(new CommonUserContext("TEST_SESSID"), dObj);

    IStorage storage = windApp.getBean(IStorage.BEAN_NAME, IStorage.class);
    Reflect.on(instance).set("nome", "Itau");
    Reflect.on(instance).set("tipo", "Credito");
    Reflect.on(instance).set("saldo", 154.54d);
    storage.save(instance);

    ModelReference opened = bean.openObjectInstance(new CommonUserContext("TEST_SESSID"), instance);

    assertNotNull(opened);
    assertEquals(opened.getAppId(), "testApp");
    assertEquals(opened.getObjId(), "Conta");
    assertEquals(Reflect.on(opened).get("nome"), "Itau");
    assertEquals(Reflect.on(opened).get("tipo"), "Credito");
    assertEquals(Reflect.on(opened).get("saldo"), 154.54d);
  }