@Test @Ignore public void testRuleOnBody() throws Exception { Person person = new Person(); person.setName("Young Scott"); person.setAge(18); Cheese cheese = new Cheese(); cheese.setPrice(10); cheese.setType("Stilton"); // Add cheese ruleOnBodyEndpoint.requestBody(cheese, Cheese.class); // Check If Person can Drink Person response = ruleOnBodyEndpoint.requestBody(person, Person.class); assertNotNull(response); assertFalse(person.isCanDrink()); // Test for alternative result person.setName("Scott"); person.setAge(21); response = ruleOnBodyEndpoint.requestBody(person, Person.class); assertNotNull(response); assertTrue(person.isCanDrink()); }
@Test @Ignore // TODO drools-camel component should be improved to allow to set Global value on the session public void testRuleOnCommand() throws Exception { Person person = new Person(); person.setName("Young Scott"); person.setAge(18); Cheese cheese = new Cheese(); cheese.setPrice(10); cheese.setType("Stilton"); // Add a Person ruleOnBodyEndpoint.requestBody(cheese, Cheese.class); // Add cheese ruleOnBodyEndpoint.requestBody(cheese, Cheese.class); // Remark : passing person here is not required ExecutionResultImpl response = ruleOnCommandEndpoint.requestBody(person, ExecutionResultImpl.class); assertNotNull(response); // Expecting single result value of type Person Collection<String> identifiers = response.getIdentifiers(); assertNotNull(identifiers); assertTrue(identifiers.size() >= 1); for (String identifier : identifiers) { final Object value = response.getValue(identifier); assertNotNull(value); assertIsInstanceOf(Person.class, value); assertFalse(((Person) value).isCanDrink()); System.out.println(identifier + " = " + value); } // Test for alternative result person.setName("Scott"); person.setAge(21); response = ruleOnCommandEndpoint.requestBody(person, ExecutionResultImpl.class); assertNotNull(response); // Expecting single result value of type Person identifiers = response.getIdentifiers(); assertNotNull(identifiers); assertTrue(identifiers.size() >= 1); for (String identifier : identifiers) { final Object value = response.getValue(identifier); assertNotNull(value); assertIsInstanceOf(Person.class, value); assertTrue(((Person) value).isCanDrink()); System.out.println(identifier + " = " + value); } }
/** * Queries the UIData for the current row of data to get the current cheese. * * @return String for the cheese name. * @throws NullPointerException if the rowdata returns a null Cheese. */ private String getSelectedCheeseName() { Cheese cheese = (Cheese) cheeseList.getRowData(); // make sure it still exists if (cheese == null) { throw new NullPointerException("cheese"); } return cheese.getName(); }
public String removeCheese() { Cheese tempCheese = new Cheese(getSelectedCheeseName(), ""); Cheese storedCheese = service.find(tempCheese); if (storedCheese == null) { FacesContext.getCurrentInstance() .addMessage(null, new FacesMessage("Cheese " + tempCheese.getName() + " Not Found!")); return "delete error"; } service.remove(storedCheese); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Cheese Removed")); return "ok"; }
public void testDataConverterStrictMode() throws Exception { OptimizerFactory.setDefaultOptimizer("ASM"); DataConversion.addConversionHandler(Date.class, new MVELDateCoercion()); ParserContext ctx = new ParserContext(); ctx.addImport("Cheese", Cheese.class); ctx.setStrongTyping(true); ctx.setStrictTypeEnforcement(true); Locale.setDefault(Locale.US); Cheese expectedCheese = new Cheese(); expectedCheese.setUseBy(new SimpleDateFormat("dd-MMM-yyyy").parse("10-Jul-1974")); ExpressionCompiler compiler = new ExpressionCompiler("c = new Cheese(); c.useBy = '10-Jul-1974'; return c"); Cheese actualCheese = (Cheese) executeExpression(compiler.compile(ctx), createTestMap()); assertEquals(expectedCheese.getUseBy(), actualCheese.getUseBy()); }
public void remove(Cheese cheese) { cheeses.remove(cheese.getName()); }
public void save(Cheese cheese) { cheeses.put(cheese.getName(), cheese); }