use of org.apache.myfaces.test.el.MockValueExpression in project myfaces by apache.
the class MessageUtilsTest method testGetLabelFromValueExpression.
public void testGetLabelFromValueExpression() {
facesContext.getExternalContext().getRequestMap().put("lbl", "testLabel");
HtmlInputText inputText = new HtmlInputText();
ValueExpression expression = new MockValueExpression("#{requestScope.lbl}", String.class);
inputText.setValueExpression("label", expression);
Object label = MessageUtils.getLabel(facesContext, inputText);
Assert.assertEquals("testLabel", label);
}
use of org.apache.myfaces.test.el.MockValueExpression in project myfaces by apache.
the class _SharedRendererUtilsTest method testGetConvertedUISelectManyValueNonPrimitiveFloatArray.
/**
* Test case for the case that UISelectMany has a ValueExpression pointing to a non-primitive
* Float array and uses a standard jsf converter.
*/
@SuppressWarnings("unchecked")
public void testGetConvertedUISelectManyValueNonPrimitiveFloatArray() {
externalContext.getApplicationMap().put("bean", new Bean());
ValueExpression expr = new MockValueExpression("#{bean.floatArrayValue}", Float[].class);
uiSelectMany.setValueExpression("value", expr);
Object target = SharedRendererUtils.getConvertedUISelectManyValue(facesContext, uiSelectMany, submittedValue);
Assert.assertTrue(target instanceof Float[]);
Float[] array = (Float[]) target;
Assert.assertTrue(new Float(submittedValue[0]).equals(array[0]));
Assert.assertTrue(new Float(submittedValue[1]).equals(array[1]));
}
use of org.apache.myfaces.test.el.MockValueExpression in project myfaces by apache.
the class _SharedRendererUtilsTest method testGetConvertedUISelectManyValuePOJOArray.
/**
* Test case for the case that UISelectMany has a ValueExpression pointing to a
* POJO array and uses a provided converter.
*/
@SuppressWarnings("unchecked")
public void testGetConvertedUISelectManyValuePOJOArray() {
externalContext.getApplicationMap().put("bean", new Bean());
ValueExpression expr = new MockValueExpression("#{bean.pojoArrayValue}", POJO[].class);
uiSelectMany.setValueExpression("value", expr);
uiSelectMany.setConverter(pojoConverter);
Object target = SharedRendererUtils.getConvertedUISelectManyValue(facesContext, uiSelectMany, submittedValue);
Assert.assertTrue(target instanceof POJO[]);
POJO[] array = (POJO[]) target;
Assert.assertTrue(pojoConverter.getAsObject(facesContext, uiSelectMany, submittedValue[0]).equals(array[0]));
Assert.assertTrue(pojoConverter.getAsObject(facesContext, uiSelectMany, submittedValue[1]).equals(array[1]));
}
use of org.apache.myfaces.test.el.MockValueExpression in project myfaces by apache.
the class _SharedRendererUtilsTest method testGetConvertedUISelectManyValueWrongCollectionType.
/**
* In this test case the method gets a wrong hint for a collection type
* (java.util.Collection can not be instantiated). So it throws a FacesException.
*/
@SuppressWarnings("unchecked")
public void testGetConvertedUISelectManyValueWrongCollectionType() {
externalContext.getApplicationMap().put("bean", new Bean());
ValueExpression expr = new MockValueExpression("#{bean.pojoCollectionValue}", Collection.class);
uiSelectMany.setValueExpression("value", expr);
uiSelectMany.setConverter(pojoConverter);
uiSelectMany.getAttributes().put("collectionType", "java.util.Collection");
try {
SharedRendererUtils.getConvertedUISelectManyValue(facesContext, uiSelectMany, submittedValue);
Assert.fail();
} catch (FacesException fe) {
// success
}
}
use of org.apache.myfaces.test.el.MockValueExpression in project myfaces by apache.
the class _SharedRendererUtilsTest method testGetConvertedUISelectManyValuePOJOCollectionWithoutCollectionType.
/**
* Test case for the case that UISelectMany has a ValueExpression pointing to a
* Collection of POJOs and uses a provided converter.
* In this scenario the method does not get a hint for the right collection type, so it
* retrieves #{bean.pojoCollectionValue} and clones that Collection.
*/
@SuppressWarnings("unchecked")
public void testGetConvertedUISelectManyValuePOJOCollectionWithoutCollectionType() {
externalContext.getApplicationMap().put("bean", new Bean());
ValueExpression expr = new MockValueExpression("#{bean.pojoCollectionValue}", Collection.class);
uiSelectMany.setValueExpression("value", expr);
uiSelectMany.setConverter(pojoConverter);
Object target = SharedRendererUtils.getConvertedUISelectManyValue(facesContext, uiSelectMany, submittedValue);
Assert.assertTrue(target instanceof Collection);
Collection collection = (Collection) target;
Assert.assertTrue(collection.contains(pojoConverter.getAsObject(facesContext, uiSelectMany, submittedValue[0])));
Assert.assertTrue(collection.contains(pojoConverter.getAsObject(facesContext, uiSelectMany, submittedValue[1])));
}
Aggregations