@Test public void test2() throws Exception { ObjectViews views = this.unmarshal("com/axelor/meta/WSTest.xml", ObjectViews.class); MetaStore.resister(views); Action action = MetaStore.getAction("export.sale.order"); Map<String, Object> context = Maps.newHashMap(); context.put("name", "SO001"); context.put("orderDate", new LocalDate()); context.put("customer", ImmutableMap.of("name", "John Smith")); List<Object> items = Lists.newArrayList(); context.put("items", items); items.add( ImmutableMap.of("product", ImmutableMap.of("name", "PC1"), "price", 250, "quantity", 1)); items.add( ImmutableMap.of("product", ImmutableMap.of("name", "PC2"), "price", 550, "quantity", 1)); items.add( ImmutableMap.of("product", ImmutableMap.of("name", "Laptop"), "price", 690, "quantity", 1)); ActionHandler handler = createHandler("export.sale.order", context); action.evaluate(handler); }
@Test public void testGroup() { Action action = MetaStore.getAction("action.group.test"); Map<String, Object> context = Maps.newHashMap(); context.put("id", 1); context.put("firstName", "John"); context.put("lastName", "Smith"); ActionHandler handler = createHandler(action, context); Object value = action.evaluate(handler); Assert.assertNotNull(value); Assert.assertTrue(value instanceof List); Assert.assertFalse(((List<?>) value).isEmpty()); Assert.assertNotNull(((List<?>) value).get(0)); Assert.assertFalse(value.toString().contains("pending")); handler.getContext().update("firstName", "J"); handler.getContext().update("email", "*****@*****.**"); value = action.evaluate(handler); Assert.assertNotNull(value); Assert.assertTrue(value instanceof List); Assert.assertFalse(((List<?>) value).isEmpty()); Assert.assertNotNull(((List<?>) value).get(0)); Assert.assertTrue(value.toString().contains("pending")); }
@Test public void testView() { Action action = MetaStore.getAction("action-view-contact"); Map<String, Object> context = Maps.newHashMap(); context.put("id", 1); context.put("firstName", "John"); context.put("lastName", "Smith"); ActionHandler handler = createHandler(action, context); Object value = action.evaluate(handler); assertNotNull(value); }
@Test public void testRecord() { Action action = MetaStore.getAction("action-contact-defaults"); ActionHandler handler = createHandler(action, null); Object value = action.evaluate(handler); assertTrue(value instanceof Contact); Contact c = (Contact) value; assertNotNull(c.getTitle()); assertEquals("Mr. John Smith", c.getFullName()); // System.err.println("XXX: " + c); }
@Test @SuppressWarnings("all") public void testCondition() { Action action = MetaStore.getAction("check.dates"); Map<String, Object> context = Maps.newHashMap(); context.put("orderDate", new LocalDate("2012-12-10")); context.put("createDate", new LocalDate("2012-12-11")); ActionHandler handler = createHandler(action, context); Object value = action.evaluate(handler); assertNotNull(value); assertTrue(value instanceof Map); assertTrue(!((Map) value).isEmpty()); }
@Test @SuppressWarnings("all") public void testMethod() { Action action = MetaStore.getAction("action-contact-greetings"); Map<String, Object> context = Maps.newHashMap(); context.put("id", 1); context.put("firstName", "John"); context.put("lastName", "Smith"); ActionHandler handler = createHandler(action, context); Object value = action.evaluate(handler); assertNotNull(value); assertEquals( "Hello World!!!", ((Map) ((List<?>) ((ActionResponse) value).getData()).get(0)).get("flash")); }
@Test @SuppressWarnings("all") public void testAttrs() { Action action = MetaStore.getAction("action-contact-attrs"); ActionHandler handler = createHandler(action, null); Object value = action.evaluate(handler); assertTrue(value instanceof Map); Map<String, Object> map = (Map) value; Map<String, Object> attrs = (Map) map.get("lastName"); assertTrue(attrs instanceof Map); assertEquals(true, attrs.get("readonly")); assertEquals(true, attrs.get("hidden")); attrs = (Map) map.get("notes"); assertTrue(attrs instanceof Map); }
@Test public void test1() throws Exception { ObjectViews views = this.unmarshal("com/axelor/meta/WSTest.xml", ObjectViews.class); List<Action> actions = views.getActions(); Assert.assertNotNull(actions); Assert.assertEquals(4, actions.size()); MetaStore.resister(views); Action action = MetaStore.getAction("data.import.1"); Map<String, Object> context = Maps.newHashMap(); DateTime dt = new DateTime(); dt = dt.plus(Period.days(20)); context.put("dt", dt); ActionHandler handler = createHandler("data.import.1", context); action.evaluate(handler); }
@Test public void testRpc() { Action action = MetaStore.getAction("action-contact-greetings-rpc"); Map<String, Object> context = Maps.newHashMap(); context.put("id", 1); context.put("firstName", "John"); context.put("lastName", "Smith"); context.put("fullName", "John Smith"); ActionHandler handler = createHandler(action, context); Object value = action.evaluate(handler); assertNotNull(value); assertEquals("Say: John Smith", value); value = handler.evaluate("call: com.axelor.meta.web.Hello:say(fullName)"); assertNotNull(value); assertEquals("Say: John Smith", value); }
@Test public void testMultiRecord() { Action action = MetaStore.getAction("action-contact-defaults-multi"); ActionHandler handler = createHandler(action, null); Object value = action.evaluate(handler); assertTrue(value instanceof Contact); Contact c = (Contact) value; assertNotNull(c.getLastName()); assertNotNull(c.getFirstName()); assertEquals(c.getFirstName(), c.getLastName()); assertEquals("Smith", c.getLastName()); assertEquals("Mr. Smith Smith", c.getFullName()); assertNotNull(c.getEmail()); assertNotNull(c.getProEmail()); assertEquals(c.getProEmail(), c.getEmail()); assertEquals("*****@*****.**", c.getEmail()); }
@Test @SuppressWarnings("all") public void testAttrsMutli() { Action action = MetaStore.getAction("action-contact-attrs-multi"); ActionHandler handler = createHandler(action, null); Object value = action.evaluate(handler); assertTrue(value instanceof Map); Map<String, Object> map = (Map) value; Map<String, Object> attrs = (Map) map.get("lastName"); assertTrue(attrs instanceof Map); assertEquals(true, attrs.get("readonly")); assertEquals(true, attrs.get("hidden")); attrs = (Map) map.get("notes"); assertTrue(attrs instanceof Map); assertEquals("About Me", attrs.get("title")); Map<String, Object> attrsPhone = (Map) map.get("phone"); Map<String, Object> attrsNotes = (Map) map.get("notes"); Map<String, Object> attrsBirth = (Map) map.get("dateOfBirth"); assertTrue(attrs instanceof Map); assertEquals(true, attrsPhone.get("hidden")); assertEquals(attrsPhone.get("hidden"), attrsNotes.get("hidden")); assertEquals(attrsBirth.get("hidden"), attrsNotes.get("hidden")); Map<String, Object> attrsFisrtName = (Map) map.get("firstName"); Map<String, Object> attrsLastName = (Map) map.get("lastName"); assertTrue(attrs instanceof Map); assertEquals(true, attrsFisrtName.get("readonly")); assertEquals(attrsFisrtName.get("readonly"), attrsLastName.get("readonly")); assertEquals(true, attrsLastName.get("hidden")); }
private ActionHandler createHandler(Action action, Map<String, Object> context) { Preconditions.checkArgument(action != null, "action is null"); return createHandler(action.getName(), context); }