mojarra-2.0.3.orig/ 0000755 0000000 0000000 00000000000 11413023352 010766 5 ustar mojarra-2.0.3.orig/nbproject/ 0000755 0000000 0000000 00000000000 11412443310 012753 5 ustar mojarra-2.0.3.orig/nbproject/project.xml 0000644 0000000 0000000 00000010242 11412443310 015142 0 ustar
this
and event
* objects.
*
* @param f the function to execute
* @param t this of the calling function
* @param e event of the calling function
* @return object that f returns
*/
mojarra.jsfcbk = function jsfcbk(f, t, e) {
return f.call(t,e);
};
/*
* This is called by the AjaxBehaviorRenderer script to
* trigger a jsf.ajax.request() call.
*
* @param s the source element or id
* @param e event of the calling function
* @param n name of the behavior event that has fired
* @param ex execute list
* @param re render list
* @param op options object
*/
mojarra.ab = function ab(s, e, n, ex, re, op) {
if (!op) {
op = {};
}
if (n) {
op["javax.faces.behavior.event"] = n;
}
if (ex) {
op["execute"] = ex;
}
if (re) {
op["render"] = re;
}
jsf.ajax.request(s, e, op);
} mojarra-2.0.3.orig/jsf-ri/resources/empty-faces-config.xml 0000644 0000000 0000000 00000004210 11412443622 020376 0 ustar
*/ public class TestConverters extends JspFacesTestCase { // // Protected Constants // // // Class Variables // // // Instance Variables // private FacesContextFactory facesContextFactory = null; // Attribute Instance Variables // Relationship Instance Variables protected Application application; // // Constructors and Initializers // public TestConverters() { super("TestConverters"); } public TestConverters(String name) { super(name); } // // Class methods // // // Methods from TestCase // public void setUp() { super.setUp(); ApplicationFactory aFactory = (ApplicationFactory) FactoryFinder.getFactory( FactoryFinder.APPLICATION_FACTORY); application = aFactory.getApplication(); UIViewRoot viewRoot = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null); viewRoot.setViewId("viewId"); viewRoot.setLocale(Locale.US); getFacesContext().setViewRoot(viewRoot); } public void beginConverters(WebRequest theRequest) { } public void testConverters() { try { // create a dummy root for the tree. UIViewRoot root = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null); root.setId("root"); testDateConverter(root); testNumberConverter(root); testConverterInheritance(root); testBooleanConverter(root); testConverterInheritance(root); //assertTrue(verifyExpectedOutput()); testDoubleConverter(root); } catch (Throwable t) { t.printStackTrace(); assertTrue(false); return; } } public static class TestBean extends Object { boolean[] booleans = null; public TestBean() { super(); } public boolean[] getBooleans() { return booleans; } public void setBooleans(boolean[] newBooleans) { booleans = newBooleans; } byte[] bytes = null; public byte[] getBytes() { return bytes; } public void setBytes(byte[] newBytes) { bytes = newBytes; } char[] chars = null; public char[] getChars() { return chars; } public void setChars(char[] newChars) { chars = newChars; } short[] shorts = null; public short[] getShorts() { return shorts; } public void setShorts(short[] newShorts) { shorts = newShorts; } int[] ints = null; public int[] getInts() { return ints; } public void setInts(int[] newInts) { ints = newInts; } long[] longs = null; public long[] getLongs() { return longs; } public void setLongs(long[] newLongs) { longs = newLongs; } float[] floats = null; public float[] getFloats() { return floats; } public void setFloats(float[] newFloats) { floats = newFloats; } double[] doubles = null; public double[] getDoubles() { return doubles; } public void setDoubles(double[] newDoubles) { doubles = newDoubles; } String[] strings = null; public String[] getStrings() { return strings; } public void setStrings(String[] newStrings) { strings = newStrings; } Date[] dates = null; public Date[] getDates() { return dates; } public void setDates(Date[] newDates) { dates = newDates; } Number[] numbers = null; public Number[] getNumbers() { return numbers; } public void setNumbers(Number[] newNumbers) { numbers = newNumbers; } List stringList = null; public List getStringList() { return stringList; } public void setStringList(List newStringList) { stringList = newStringList; } } public void beginUISelectMany(WebRequest theRequest) { // primitives theRequest.addParameter("bool", "false"); theRequest.addParameter("bool", "true"); theRequest.addParameter("bool", "false"); theRequest.addParameter("bool2", "false"); theRequest.addParameter("byte", Byte.toString(Byte.MIN_VALUE)); theRequest.addParameter("byte", Byte.toString(Byte.MAX_VALUE)); theRequest.addParameter("byte", "1"); theRequest.addParameter("char", "Q"); theRequest.addParameter("char", "A"); theRequest.addParameter("char", "z"); theRequest.addParameter("short", Short.toString(Short.MIN_VALUE)); theRequest.addParameter("short", Short.toString(Short.MAX_VALUE)); theRequest.addParameter("short", Short.toString((short) (Byte.MAX_VALUE + 1))); theRequest.addParameter("int", Integer.toString(Integer.MIN_VALUE)); theRequest.addParameter("int", Integer.toString(Integer.MAX_VALUE)); theRequest.addParameter("int", Integer.toString(Short.MAX_VALUE + 1)); theRequest.addParameter("float", Float.toString(Float.MIN_VALUE)); theRequest.addParameter("float", Float.toString(Float.MAX_VALUE)); theRequest.addParameter("float", Float.toString(Integer.MAX_VALUE + 1)); theRequest.addParameter("long", Long.toString(Long.MIN_VALUE)); theRequest.addParameter("long", Long.toString(Long.MAX_VALUE)); theRequest.addParameter("long", Long.toString(Integer.MAX_VALUE + 1)); theRequest.addParameter("double", Double.toString(Double.MIN_VALUE)); theRequest.addParameter("double", Double.toString(Double.MAX_VALUE)); theRequest.addParameter("double", Double.toString(Long.MAX_VALUE + 1)); // Objects theRequest.addParameter("str", "value1"); theRequest.addParameter("str", "value2"); theRequest.addParameter("str", "value3"); theRequest.addParameter("str2", ""); theRequest.addParameter("date", "Jan 1, 1967"); theRequest.addParameter("date", "May 26, 2003"); theRequest.addParameter("date", "Aug 19, 1946"); theRequest.addParameter("num", "12%"); theRequest.addParameter("num", "3.14"); theRequest.addParameter("num", "49.99"); theRequest.addParameter("stringList", "value1"); theRequest.addParameter("stringList", "value2"); theRequest.addParameter("stringList", "value3"); } public void testUISelectMany() throws Exception { // create the test bean TestBean bean = new TestBean(); getFacesContext().getExternalContext().getRequestMap().put("bean", bean); // create a dummy root for the tree. UIViewRoot root = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null); root.setId("root"); root.setLocale(Locale.US); getFacesContext().setViewRoot(root); // test model type of boolean [] UISelectMany booleanv = new UISelectMany(); booleanv.setId("bool"); booleanv.setRendererType("javax.faces.Checkbox"); booleanv.setValueExpression("value", (getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(), "#{bean.booleans}", Boolean.class))); root.getChildren().add(booleanv); booleanv.getChildren().add(newUISelectItem(Boolean.TRUE)); booleanv.getChildren().add(newUISelectItem(Boolean.FALSE)); booleanv.decode(getFacesContext()); booleanv.validate(getFacesContext()); booleanv.updateModel(getFacesContext()); assertNotNull(bean.getBooleans()); assertTrue(bean.getBooleans()[0] == false); assertTrue(bean.getBooleans()[1] == true); assertTrue(bean.getBooleans()[2] == false); // test model type of boolean [] booleanv = new UISelectMany(); booleanv.setId("bool2"); booleanv.setRendererType("javax.faces.Checkbox"); booleanv.setValueExpression("value", (getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),"#{bean.booleans}", Object.class))); root.getChildren().add(booleanv); booleanv.getChildren().add(newUISelectItem(Boolean.TRUE)); booleanv.getChildren().add(newUISelectItem(Boolean.FALSE)); booleanv.decode(getFacesContext()); booleanv.validate(getFacesContext()); booleanv.updateModel(getFacesContext()); assertNotNull(bean.getBooleans()); assertTrue(bean.getBooleans()[0] == false); assertTrue(bean.getBooleans().length == 1); // test model type of byte [] UISelectMany bytev = new UISelectMany(); bytev.setId("byte"); bytev.setRendererType("javax.faces.Checkbox"); bytev.setValueExpression("value", getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(), "#{bean.bytes}", Object.class)); bytev.getChildren().add(newUISelectItem(new Byte(Byte.MIN_VALUE))); bytev.getChildren().add(newUISelectItem(new Byte(Byte.MAX_VALUE))); bytev.getChildren().add(newUISelectItem(new Byte((byte) 1))); bytev.getChildren().add(newUISelectItem(new Byte((byte) -1))); root.getChildren().add(bytev); bytev.decode(getFacesContext()); bytev.validate(getFacesContext()); bytev.updateModel(getFacesContext()); assertNotNull(bean.getBytes()); assertTrue(bean.getBytes()[0] == Byte.MIN_VALUE); assertTrue(bean.getBytes()[1] == Byte.MAX_VALUE); assertTrue(bean.getBytes()[2] == 1); // test model type of char [] UISelectMany charv = new UISelectMany(); charv.setId("char"); charv.setRendererType("javax.faces.Checkbox"); charv.setValueExpression("value", getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),"#{bean.chars}", Object.class)); root.getChildren().add(charv); charv.getChildren().add(newUISelectItem(new Character('Q'))); charv.getChildren().add(newUISelectItem(new Character('A'))); charv.getChildren().add(newUISelectItem(new Character('Z'))); charv.getChildren().add(newUISelectItem(new Character('z'))); charv.decode(getFacesContext()); charv.validate(getFacesContext()); charv.updateModel(getFacesContext()); assertNotNull(bean.getChars()); assertTrue(bean.getChars()[0] == 'Q'); assertTrue(bean.getChars()[1] == 'A'); assertTrue(bean.getChars()[2] == 'z'); // test model type of short [] UISelectMany shortv = new UISelectMany(); shortv.setId("short"); shortv.setRendererType("javax.faces.Checkbox"); shortv.setValueExpression("value", getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),"#{bean.shorts}", Object.class)); root.getChildren().add(shortv); shortv.getChildren().add( newUISelectItem(new Short((short) (Byte.MAX_VALUE + 1)))); shortv.getChildren().add(newUISelectItem(new Short((short) 100))); shortv.getChildren().add(newUISelectItem(new Short(Short.MIN_VALUE))); shortv.getChildren().add(newUISelectItem(new Short(Short.MAX_VALUE))); shortv.decode(getFacesContext()); shortv.validate(getFacesContext()); shortv.updateModel(getFacesContext()); assertNotNull(bean.getShorts()); assertTrue(bean.getShorts()[0] == Short.MIN_VALUE); assertTrue(bean.getShorts()[1] == Short.MAX_VALUE); assertTrue(bean.getShorts()[2] == Byte.MAX_VALUE + 1); // test model type of int [] UISelectMany intv = new UISelectMany(); intv.setId("int"); intv.setRendererType("javax.faces.Checkbox"); intv.setValueExpression("value", getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),"#{bean.ints}", Object.class)); root.getChildren().add(intv); intv.getChildren().add( newUISelectItem(new Integer(Short.MAX_VALUE + 1))); intv.getChildren().add(newUISelectItem(new Integer(100))); intv.getChildren().add(newUISelectItem(new Integer(Integer.MIN_VALUE))); intv.getChildren().add(newUISelectItem(new Integer(Integer.MAX_VALUE))); intv.decode(getFacesContext()); intv.validate(getFacesContext()); intv.updateModel(getFacesContext()); assertNotNull(bean.getInts()); assertTrue(bean.getInts()[0] == Integer.MIN_VALUE); assertTrue(bean.getInts()[1] == Integer.MAX_VALUE); assertTrue(bean.getInts()[2] == Short.MAX_VALUE + 1); // test model type of float [] UISelectMany floatv = new UISelectMany(); floatv.setId("float"); floatv.setRendererType("javax.faces.Checkbox"); floatv.setValueExpression("value", getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),"#{bean.floats}", Object.class)); root.getChildren().add(floatv); floatv.getChildren().add( newUISelectItem(new Float(Integer.MAX_VALUE + 1))); floatv.getChildren().add(newUISelectItem(new Float(100))); floatv.getChildren().add(newUISelectItem(new Float(Float.MIN_VALUE))); floatv.getChildren().add(newUISelectItem(new Float(Float.MAX_VALUE))); floatv.decode(getFacesContext()); floatv.validate(getFacesContext()); floatv.updateModel(getFacesContext()); assertNotNull(bean.getFloats()); assertTrue(bean.getFloats()[0] == Float.MIN_VALUE); assertTrue(bean.getFloats()[1] == Float.MAX_VALUE); assertTrue(bean.getFloats()[2] == Integer.MAX_VALUE + 1); // test model type of long [] UISelectMany longv = new UISelectMany(); longv.setId("long"); longv.setRendererType("javax.faces.Checkbox"); longv.setValueExpression("value", getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),"#{bean.longs}", Object.class)); root.getChildren().add(longv); longv.getChildren().add( newUISelectItem(new Long(Integer.MAX_VALUE + 1))); longv.getChildren().add(newUISelectItem(new Long(100))); longv.getChildren().add(newUISelectItem(new Long(Long.MIN_VALUE))); longv.getChildren().add(newUISelectItem(new Long(Long.MAX_VALUE))); longv.decode(getFacesContext()); longv.validate(getFacesContext()); longv.updateModel(getFacesContext()); assertNotNull(bean.getLongs()); assertTrue(bean.getLongs()[0] == Long.MIN_VALUE); assertTrue(bean.getLongs()[1] == Long.MAX_VALUE); assertTrue(bean.getLongs()[2] == Integer.MAX_VALUE + 1); // test model type of double [] UISelectMany doublev = new UISelectMany(); doublev.setId("double"); doublev.setRendererType("javax.faces.Checkbox"); doublev.setValueExpression("value", getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),"#{bean.doubles}", Object.class)); root.getChildren().add(doublev); doublev.getChildren().add( newUISelectItem(new Double(Long.MAX_VALUE + 1))); doublev.getChildren().add(newUISelectItem(new Double(100))); doublev.getChildren().add( newUISelectItem(new Double(Double.MIN_VALUE))); doublev.getChildren().add( newUISelectItem(new Double(Double.MAX_VALUE))); doublev.decode(getFacesContext()); doublev.validate(getFacesContext()); doublev.updateModel(getFacesContext()); assertNotNull(bean.getDoubles()); assertTrue(bean.getDoubles()[0] == Double.MIN_VALUE); assertTrue(bean.getDoubles()[1] == Double.MAX_VALUE); assertTrue(bean.getDoubles()[2] == Long.MAX_VALUE + 1); // test model type of String [] UISelectMany str = new UISelectMany(); str.setId("str"); str.setRendererType("javax.faces.Checkbox"); str.setValueExpression("value", getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),"#{bean.strings}", Object.class)); root.getChildren().add(str); str.getChildren().add(newUISelectItem("value1")); str.getChildren().add(newUISelectItem("value2")); str.getChildren().add(newUISelectItem("value3")); str.getChildren().add(newUISelectItem("value4")); str.decode(getFacesContext()); str.validate(getFacesContext()); str.updateModel(getFacesContext()); assertNotNull(bean.getStrings()); assertTrue("value1".equals(bean.getStrings()[0])); // test model type of Date [] UISelectMany date = new UISelectMany(); Converter dateConv = Util.getConverterForIdentifer( "javax.faces.DateTime", getFacesContext()); assertNotNull(dateConv); date.setConverter(dateConv); date.setId("date"); date.setRendererType("javax.faces.Checkbox"); date.setValueExpression("value", getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),"#{bean.dates}", Object.class)); root.getChildren().add(date); try { SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd"); df.setTimeZone(TimeZone.getTimeZone("GMT")); date.getChildren().add(newUISelectItem(df.parse("19670101"))); date.getChildren().add(newUISelectItem(df.parse("20030526"))); date.getChildren().add(newUISelectItem(df.parse("19460819"))); date.getChildren().add(newUISelectItem(df.parse("17760704"))); } catch (ParseException e) { assertTrue(e.getMessage(), false); } date.decode(getFacesContext()); date.validate(getFacesContext()); date.updateModel(getFacesContext()); assertNotNull(bean.getDates()); Object expected = null; try { SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd"); df.setTimeZone(TimeZone.getTimeZone("GMT")); expected = df.parse("19460819"); } catch (ParseException e) { assertTrue(e.getMessage(), false); } assertEquals("bean.getDates()[2] not as expected: ", expected, bean.getDates()[2]); // test model type of Number [] UISelectMany number = new UISelectMany(); Converter numberConv = Util.getConverterForIdentifer( "javax.faces.Number", getFacesContext()); assertNotNull(numberConv); number.setConverter(numberConv); number.setId("num"); number.setRendererType("javax.faces.Checkbox"); number.setValueExpression("value", getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),"#{bean.numbers}", Object.class)); root.getChildren().add(number); number.getChildren().add(newUISelectItem(new Double(3.14))); number.getChildren().add(newUISelectItem(new Double(49.99))); number.getChildren().add(newUISelectItem(new Long(12))); number.getChildren().add(newUISelectItem(new Double(-145.5))); number.decode(getFacesContext()); number.validate(getFacesContext()); number.updateModel(getFacesContext()); assertNotNull(bean.getNumbers()); try { DecimalFormat df = new DecimalFormat("'$'##.##", new DecimalFormatSymbols(Locale.US)); expected = df.parse("$49.99"); } catch (ParseException e) { assertTrue(e.getMessage(), false); } assertTrue(expected.equals(bean.getNumbers()[2])); // test model type of List of Strings UISelectMany stringList = new UISelectMany(); stringList.setId("stringList"); stringList.setRendererType("javax.faces.Checkbox"); stringList.setValueExpression("value", getFacesContext().getApplication().getExpressionFactory().createValueExpression(getFacesContext().getELContext(),"#{bean.stringList}", Object.class)); root.getChildren().add(stringList); stringList.getChildren().add(newUISelectItem("value1")); stringList.getChildren().add(newUISelectItem("value2")); stringList.getChildren().add(newUISelectItem("value3")); stringList.getChildren().add(newUISelectItem("value4")); stringList.decode(getFacesContext()); stringList.validate(getFacesContext()); stringList.updateModel(getFacesContext()); assertNotNull(bean.getStringList()); assertTrue(bean.getStringList().get(0).equals("value1")); assertTrue(bean.getStringList().get(1).equals("value2")); assertTrue(bean.getStringList().get(2).equals("value3")); } // // General Methods // public void testDateConverter(UIViewRoot root) throws ConverterException, InstantiationException, IllegalAccessException, ClassNotFoundException { System.out.println("Testing DateConverter"); UIInput text = new UIInput(); text.setId("my_input_date"); root.getChildren().add(text); Converter converter = null; converter = application.createConverter("javax.faces.DateTime"); // date String stringToConvert = "Jan 1, 1967"; Object obj = converter.getAsObject(getFacesContext(), text, stringToConvert); assertTrue(obj instanceof java.util.Date); String str = converter.getAsString(getFacesContext(), text, obj); // make sure we end up with the same string we started with.. assertTrue(str.equals(stringToConvert)); // time converter = application.createConverter("javax.faces.DateTime"); ((DateTimeConverter) converter).setType("time"); text = new UIInput(); text.setId("my_input_time"); stringToConvert = "10:10:10 AM"; obj = converter.getAsObject(getFacesContext(), text, stringToConvert); assertTrue(obj instanceof java.util.Date); str = converter.getAsString(getFacesContext(), text, obj); // make sure we end up with the same string we started with.. assertTrue(str.equals(stringToConvert)); // datetime converter = application.createConverter("javax.faces.DateTime"); ((DateTimeConverter) converter).setType("both"); text = new UIInput(); text.setId("my_input_datetime"); stringToConvert = "Jan 1, 1967 10:10:10 AM"; obj = converter.getAsObject(getFacesContext(), text, stringToConvert); assertTrue(obj instanceof java.util.Date); str = converter.getAsString(getFacesContext(), text, obj); // make sure we end up with the same string we started with.. assertTrue(str.equals(stringToConvert)); // test bogus type.... boolean exceptionThrown = false; try { ((DateTimeConverter)converter).setType("foobar"); obj = converter.getAsObject(getFacesContext(), text, stringToConvert); } catch (Exception e) { exceptionThrown = true; } assertTrue(exceptionThrown); // test NullPointerException (if either context or component arg is null) exceptionThrown = false; try { obj = converter.getAsObject(null, text, stringToConvert); } catch (NullPointerException npe) { exceptionThrown= true; } assertTrue(exceptionThrown); exceptionThrown = false; try { obj = converter.getAsObject(getFacesContext(), null, stringToConvert); } catch (NullPointerException npe) { exceptionThrown= true; } assertTrue(exceptionThrown); exceptionThrown = false; try { str = converter.getAsString(null, text, obj); } catch (NullPointerException npe) { exceptionThrown= true; } assertTrue(exceptionThrown); exceptionThrown = false; try { str = converter.getAsString(getFacesContext(), null, obj); } catch (NullPointerException npe) { exceptionThrown= true; } assertTrue(exceptionThrown); } public void testDateTimeConverterGMTTimeZone() throws Exception { UIInput input = new UIInput(); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.ENGLISH); df.setTimeZone(TimeZone.getTimeZone("GMT")); Date now = new Date(); String formatted = df.format(now); Date parsed = df.parse(formatted); // control setup, now test the converter. Application app = getFacesContext().getApplication(); DateTimeConverter converter = (DateTimeConverter) app.createConverter("javax.faces.DateTime"); converter.setType("both"); assertNotNull(converter); assertTrue(TimeZone.getTimeZone("GMT").toString(), TimeZone.getTimeZone("GMT").equals(converter.getTimeZone())); assertTrue(formatted, formatted.equals(converter.getAsString(getFacesContext(), input, parsed))); assertTrue(parsed.toString(), parsed.equals(converter.getAsObject(getFacesContext(), input, formatted))); app.addConverter(java.util.Date.class, "javax.faces.convert.DateTimeConverter"); converter = (DateTimeConverter) app.createConverter(java.util.Date.class); converter.setType("both"); assertNotNull(converter); assertTrue(TimeZone.getTimeZone("GMT").toString(), TimeZone.getTimeZone("GMT").equals(converter.getTimeZone())); assertTrue(formatted, formatted.equals(converter.getAsString(getFacesContext(), input, parsed))); assertTrue(parsed.toString(), parsed.equals(converter.getAsObject(getFacesContext(), input, formatted))); } public void testDateTimeConverterDefaultTimeZone() throws Exception { TestingUtil.setPrivateField("passDefaultTimeZone", ApplicationImpl.class, application, Boolean.TRUE); TestingUtil.setPrivateField("systemTimeZone", ApplicationImpl.class, application, TimeZone.getDefault()); UIInput input = new UIInput(); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.ENGLISH); df.setTimeZone(TimeZone.getDefault()); Date now = new Date(); String formatted = df.format(now); Date parsed = df.parse(formatted); // control setup, now test the converter. Application app = getFacesContext().getApplication(); DateTimeConverter converter = (DateTimeConverter) app.createConverter("javax.faces.DateTime"); converter.setType("both"); assertNotNull(converter); assertTrue(TimeZone.getDefault().toString(), TimeZone.getDefault().equals(converter.getTimeZone())); assertTrue(formatted, formatted.equals(converter.getAsString(getFacesContext(), input, parsed))); assertTrue(parsed.toString(), parsed.equals(converter.getAsObject(getFacesContext(), input, formatted))); app.addConverter(java.util.Date.class, "javax.faces.convert.DateTimeConverter"); converter = (DateTimeConverter) app.createConverter(java.util.Date.class); converter.setType("both"); assertNotNull(converter); assertTrue(TimeZone.getDefault().toString(), TimeZone.getDefault().equals(converter.getTimeZone())); assertTrue(formatted, formatted.equals(converter.getAsString(getFacesContext(), input, parsed))); assertTrue(parsed.toString(), parsed.equals(converter.getAsObject(getFacesContext(), input, formatted))); } public void testNumberConverter(UIViewRoot root) throws ConverterException, InstantiationException, IllegalAccessException, ClassNotFoundException { System.out.println("Tesing NumberConverter"); UIInput text = new UIInput(); text.setId("my_input_number"); root.getChildren().add(text); Converter converter = application.createConverter("javax.faces.Number"); String stringToConvert = "99.9"; Object obj = converter.getAsObject(getFacesContext(), text, stringToConvert); assertTrue(obj instanceof java.lang.Number); String str = converter.getAsString(getFacesContext(), text, obj); assertTrue(str.equals(stringToConvert)); } public void testNumberConverterSpacesNBSP() throws Exception { UIInput text = new UIInput(); NumberConverter converter = (NumberConverter) application.createConverter("javax.faces.Number"); converter.setType("currency"); converter.setLocale(Locale.FRANCE); String toConv = "12 345,68 " + '\u20aC'; Number number = (Number) converter.getAsObject(getFacesContext(), text, toConv); assertTrue(number != null); converter.setType("number"); toConv = "5" + "\u00a0" + "000" + "\u00a0" + "000,01"; number = (Number) converter.getAsObject(getFacesContext(), text, toConv); assertTrue("Number was: " + number.toString() + ", expected 5000000.01", "5000000.01".equals(number.toString())); } public void testDoubleConverter(UIViewRoot root) throws ConverterException, InstantiationException, IllegalAccessException, ClassNotFoundException { System.out.println("Tesing DoubleConverter"); Converter converter = application.createConverter("javax.faces.Double"); assertNotNull(converter); } public void testBooleanConverter(UIViewRoot root) throws ConverterException, InstantiationException, IllegalAccessException, ClassNotFoundException { System.out.println("Tesing BooleanConverter"); UIInput text = new UIInput(); text.setId("my_input_boolean"); root.getChildren().add(text); Converter converter = application.createConverter( java.lang.Boolean.class); String stringToConvert = "true"; Object obj = converter.getAsObject(getFacesContext(), text, stringToConvert); assertTrue(obj instanceof java.lang.Boolean); String str = converter.getAsString(getFacesContext(), text, obj); assertTrue(str.equals(stringToConvert)); } /** * Test to verify that a class that registers itself is properly found * using the search mechanism. The J2SE classes are used for their * inheritance hierarchy to test that converters registered to * interfaces and superclasses are properly found. *
* This test is meant for inheritance lookup only. */ public void testConverterInheritance(UIViewRoot root) throws ConverterException, InstantiationException, IllegalAccessException, ClassNotFoundException { System.out.println("Testing ConverterInheritance"); Converter converter; UIInput text = new UIInput(); text.setId("my_date_converter"); root.getChildren().add(text); //java.lang.Integer extends java.lang.Number. //Test to show that the standard converter registered to //java.lang.Integer should chosen over the inherited //java.lang.Number converter application.addConverter(java.lang.Number.class, "javax.faces.convert.NumberConverter"); converter = application.createConverter(java.lang.Integer.class); assertTrue(converter != null); assertTrue(converter instanceof javax.faces.convert.IntegerConverter); //java.sql.Date extends java.util.Date //Test to find converter registered to java.util.Date application.addConverter(java.util.Date.class, "javax.faces.convert.DateTimeConverter"); converter = null; converter = application.createConverter(java.sql.Date.class); assertTrue(converter != null); //java.util.HashSet is a subclass of java.util.AbstractSet which is //a subclass of java.util.AbstractCollection //Test to find the converter registered to java.util.AbstractCollection application.addConverter(java.util.AbstractCollection.class, "javax.faces.convert.DateTimeConverter"); converter = null; try { converter = application.createConverter(java.util.HashSet.class); } catch (javax.faces.FacesException fe) { } assertTrue(converter != null); //java.lang.String implements java.lang.CharSequence //Test to find the converter registered to java.lang.CharSequence application.addConverter(java.text.CharacterIterator.class, "javax.faces.convert.CharacterConverter"); converter = null; converter = application.createConverter( java.text.StringCharacterIterator.class); assertTrue(converter != null); //java.text.StringCharacterIterator implements //java.text.CharacterIterator which has a super-interface //java.lang.Cloneable //Test to find the converter registered to java.lang.Cloneable application.addConverter(java.lang.Cloneable.class, "javax.faces.convert.CharacterConverter"); converter = null; converter = application.createConverter( java.text.StringCharacterIterator.class); assertTrue(converter != null); } static private UISelectItem newUISelectItem(Object value) { UISelectItem item = new UISelectItem(); item.setItemValue(value); item.setItemLabel(value.toString()); return item; } } // end of class TestConverters mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/TestBean.java 0000644 0000000 0000000 00000004773 11412443352 020173 0 ustar /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can obtain * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. * Sun designates this particular file as subject to the "Classpath" exception * as provided by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the License * Header, with the fields enclosed by brackets [] replaced by your own * identifying information: "Portions Copyrighted [year] * [name of copyright owner]" * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package com.sun.faces; import com.sun.faces.util.Util; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Map; import javax.el.ELException; public class TestBean extends com.sun.faces.cactus.TestBean { public TestBean() { } protected CustomerBean customerBean; public CustomerBean getCustomerBean() { return customerBean; } public void setCustomerBean(CustomerBean newCustomerBean) { customerBean = newCustomerBean; } } mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/mock/ 0000755 0000000 0000000 00000000000 11412443350 016537 5 ustar mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/mock/MockServletContext.java 0000644 0000000 0000000 00000030520 11412443350 023205 0 ustar /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can obtain * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. * Sun designates this particular file as subject to the "Classpath" exception * as provided by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the License * Header, with the fields enclosed by brackets [] replaced by your own * identifying information: "Portions Copyrighted [year] * [name of copyright owner]" * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package com.sun.faces.mock; import javax.servlet.RequestDispatcher; import javax.servlet.Servlet; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration; import javax.servlet.FilterRegistration; import javax.servlet.Filter; import javax.servlet.SessionCookieConfig; import javax.servlet.SessionTrackingMode; import javax.servlet.descriptor.JspConfigDescriptor; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.Enumeration; import java.util.Hashtable; import java.util.Set; import java.util.Collections; import java.util.Map; import java.util.EventListener; // Mock Object for ServletContext (Version 2.3) public class MockServletContext implements ServletContext { // ------------------------------------------------------------ Constructors // Zero-args constructor for no associated directory public MockServletContext() { ; } // Constructor with File object for associated directory public MockServletContext(File directory) { setDirectory(directory); } // ------------------------------------------------------ Instance Variables private Hashtable attributes = new Hashtable(); private Hashtable parameters = new Hashtable(); private String name = "MockServletContext"; // -------------------------------------------------------------- Properties // The directory that is the base of our application resources private File directory = null; public File getDirectory() { return (this.directory); } public void setDirectory(File directory) { if (!directory.exists() || !directory.isDirectory()) { throw new IllegalArgumentException (directory.getAbsolutePath() + " is not an existing directory"); } this.directory = directory; } // ---------------------------------------------------------- Public Methods // Add a context innitialization parameter public void addInitParameter(String name, String value) { parameters.put(name, value); } // Set the servlet context name public void setServletContextName(String name) { this.name = name; } // -------------------------------------------------- ServletContext Methods public Object getAttribute(String name) { return (attributes.get(name)); } public Enumeration getAttributeNames() { return (attributes.keys()); } public ServletContext getContext(String uripath) { throw new UnsupportedOperationException(); } public String getContextPath() { return ('/' + name); } public String getInitParameter(String name) { return ((String) parameters.get(name)); } public Enumeration getInitParameterNames() { return (parameters.keys()); } public int getMajorVersion() { return (2); } public String getMimeType(String path) { throw new UnsupportedOperationException(); } public int getMinorVersion() { return (5); } public RequestDispatcher getNamedDispatcher(String name) { throw new UnsupportedOperationException(); } public String getRealPath(String path) { if (!path.startsWith("/") || (directory == null)) { return (null); } File file = new File(directory, path.substring(1)); if (!file.exists() || !file.isFile()) { return (null); } return (file.getAbsolutePath()); } public RequestDispatcher getRequestDispatcher(String path) { throw new UnsupportedOperationException(); } public URL getResource(String path) throws MalformedURLException { if (!path.startsWith("/") || (directory == null)) { return (null); } File file = new File(directory, path.substring(1)); if (!file.exists() || !file.isFile()) { return (null); } return (file.toURL()); } public InputStream getResourceAsStream(String path) { URL url = null; try { url = getResource(path); } catch (MalformedURLException e) { return (null); } if (url == null) { return (null); } try { return (url.openStream()); } catch (IOException e) { return (null); } } public Set getResourcePaths(String path) { return Collections.emptySet(); // PENDING(craigmcc) - Flesh out the following implementation /* if (!path.startsWith("/") || (directory == null)) { return (null); } File base = new File(directory, path.substring(1)); if (!base.exists() || !base.isDirectory()) { return (false); } Set results = new HashSet(); // PENDING(craigmcc) recursive descent search return (results); */ } public Servlet getServlet(String name) throws ServletException { throw new UnsupportedOperationException(); } public String getServletContextName() { return (name); } public String getServerInfo() { return ("MockServletContext"); } public Enumeration getServlets() { throw new UnsupportedOperationException(); } public Enumeration getServletNames() { throw new UnsupportedOperationException(); } public void log(String message) { throw new UnsupportedOperationException(); } public void log(Exception exception, String message) { throw new UnsupportedOperationException(); } public void log(String message, Throwable exception) { throw new UnsupportedOperationException(); } public void removeAttribute(String name) { attributes.remove(name); } public void setAttribute(String name, Object value) { attributes.put(name, value); } public int getEffectiveMajorVersion() { return 0; //To change body of implemented methods use File | Settings | File Templates. } public int getEffectiveMinorVersion() { return 0; //To change body of implemented methods use File | Settings | File Templates. } public boolean setInitParameter(String s, String s1) { return false; //To change body of implemented methods use File | Settings | File Templates. } public ServletRegistration.Dynamic addServlet(String s, String s1) { return null; //To change body of implemented methods use File | Settings | File Templates. } public ServletRegistration.Dynamic addServlet(String s, Servlet servlet) { return null; //To change body of implemented methods use File | Settings | File Templates. } public ServletRegistration.Dynamic addServlet(String s, Class extends Servlet> aClass) { return null; //To change body of implemented methods use File | Settings | File Templates. } publicThe purpose of this class is to call the package private * getThreadLocalServletContext() method to set the ServletContext into * ThreadLocalStorage, if IS_UNIT_TEST_MODE == true.
*/ public class StoreServletContext extends Object { ExternalContext ec = null; public void setServletContext(ServletContext sc) { ec = new ServletContextAdapter(sc); ThreadLocalUnit tests for ConfigureListener
.
Unit tests for Configuration File processing.
*/ public class TestConfigListener extends ServletFacesTestCase { // ----------------------------------------------------- Instance Variables // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public TestConfigListener(String name) { super(name); } // --------------------------------------------------- Overall Test Methods // ------------------------------------------------ Individual Test Methods // this method manually invokes the ContextListener contextInitialized method // multiple times to ensure the parsing logic only gets executed once // (for the same webapp). // public void testContextInitialized() { ConfigureListener cl = new ConfigureListener(); ServletContextEvent e = new ServletContextEvent( getConfig().getServletContext()); cl.contextInitialized(e); cl.contextInitialized(e); } } mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/config/SimpleBean.java 0000644 0000000 0000000 00000006260 11412443352 021743 0 ustar /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can obtain * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. * Sun designates this particular file as subject to the "Classpath" exception * as provided by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the License * Header, with the fields enclosed by brackets [] replaced by your own * identifying information: "Portions Copyrighted [year] * [name of copyright owner]" * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package com.sun.faces.config; public class SimpleBean { private String simpleProperty; public SimpleBean() { } public String getSimpleProperty() { return simpleProperty; } public void setSimpleProperty(String simpleProperty) { this.simpleProperty = simpleProperty; } Integer intProp = null; public void setIntProperty(Integer newVal) { intProp = newVal; } public Integer getIntProperty() { return intProp; } public boolean getTrueValue() { return true; } public boolean getFalseValue() { return false; } private NonManagedBean nonManagedBean = null; public NonManagedBean getNonManagedBean() { return nonManagedBean; } public void setNonManagedBean(NonManagedBean nmb) { nonManagedBean = nmb; } private String headerClass = "column-header"; public String getHeaderClass() { return headerClass; } public void setHeaderClass(String headerClass) { this.headerClass = headerClass; } private String footerClass = "column-footer"; public String getFooterClass() { return footerClass; } public void setFooterClass(String footerClass) { this.footerClass = footerClass; } } mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/config/TestManagedBeanFactory.java 0000644 0000000 0000000 00000130034 11412443352 024233 0 ustar /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can obtain * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. * Sun designates this particular file as subject to the "Classpath" exception * as provided by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the License * Header, with the fields enclosed by brackets [] replaced by your own * identifying information: "Portions Copyrighted [year] * [name of copyright owner]" * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package com.sun.faces.config; import com.sun.faces.cactus.ServletFacesTestCase; import com.sun.faces.cactus.TestingUtil; import com.sun.faces.TestBean; import com.sun.faces.application.ApplicationAssociate; import com.sun.faces.mgbean.ManagedBeanInfo; import com.sun.faces.mgbean.BeanManager; import com.sun.faces.mgbean.BeanBuilder; import com.sun.faces.el.ELUtils; import javax.el.ValueExpression; import javax.faces.FacesException; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** *Unit tests for Managed Bean Factory.
*/ public class TestManagedBeanFactory extends ServletFacesTestCase { public static String beanName = "com.sun.faces.TestBean"; // ----------------------------------------------------- Instance Variables TestBean testBean; // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. */ public TestManagedBeanFactory() { super("TestManagedBeanFactory"); } /** * Construct a new instance of this test case. * * @param name Name of the test case */ public TestManagedBeanFactory(String name) { super(name); } // --------------------------------------------------- Overall Test Methods // ------------------------------------------------ Individual Test Methods // Test managed bean public void testNoProperty() throws Exception { //Testing with no properties set ManagedBeanInfo bean = new ManagedBeanInfo(beanName, beanName, "session", null, null, null, null); BeanManager beanManager = ApplicationAssociate.getCurrentInstance().getBeanManager(); beanManager.register(bean); assertNotNull(beanManager.create(beanName, getFacesContext())); BeanBuilder builder = beanManager.getBuilder(beanName); assertTrue(ELUtils.Scope.SESSION.toString().equals(builder.getScope())); } public void testSimpleProperty() throws Exception { ManagedBeanInfo.ManagedProperty property = new ManagedBeanInfo.ManagedProperty("one", null, "one", null, null); List* */ public class TestMethodRef extends ServletFacesTestCase { // // Protected Constants // // // Class Variables // // // Instance Variables // // Attribute Instance Variables // Relationship Instance Variables // // Constructors and Initializers // public TestMethodRef() { super("TestMethodRef"); } public TestMethodRef(String name) { super(name); } // // Class methods // // // General Methods // protected MethodBinding create(String ref, Class[] params) throws Exception { return (getFacesContext().getApplication().createMethodBinding(ref, params)); } public void testNullReference() throws Exception { try { create(null, null); fail(); } catch (NullPointerException npe) {} catch (Exception e) { fail("Should have thrown an NPE"); }; } public void testInvalidMethod() throws Exception { try { create("#{foo > 1}", null); fail(); } catch (ReferenceSyntaxException rse) {} catch (Exception e) { fail("Should have thrown a ReferenceSyntaxException"); } } public void testLiteralReference() throws Exception { try { create("some.method", null); fail(); } catch (ReferenceSyntaxException rse) {} catch (Exception e) { fail("Should have thrown a ReferenceSyntaxException"); } } public void testInvalidTrailing() throws Exception { MethodBinding mb = this.create( "#{NewCustomerFormHandler.redLectroidsMmmm}", new Class[0]); boolean exceptionThrown = false; try { mb.invoke(getFacesContext(), new Object[0]); } catch (MethodNotFoundException e) { exceptionThrown = true; } assertTrue(exceptionThrown); mb = this.create("#{nonexistentBean.redLectroidsMmmm}", new Class[0]); // page 80 of the EL Spec, since nonexistentBean is null, the target // method is never reached and should catch a PropertyNotFoundException // and rethrow as a MethodNotFoundException exceptionThrown = false; try { mb.invoke(getFacesContext(), new Object[0]); } catch (MethodNotFoundException e) { exceptionThrown = true; } catch (EvaluationException e) { //TODO remove once adaptor is fixed exceptionThrown = true; } assertTrue(exceptionThrown); } } // end of class TestMethodRef mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/TestPropertyResolverImpl.java 0000644 0000000 0000000 00000067047 11412443352 024121 0 ustar /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can obtain * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. * Sun designates this particular file as subject to the "Classpath" exception * as provided by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the License * Header, with the fields enclosed by brackets [] replaced by your own * identifying information: "Portions Copyrighted [year] * [name of copyright owner]" * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ // TestPropertyResolverImpl.java package com.sun.faces.el; import com.sun.faces.cactus.ServletFacesTestCase; import com.sun.faces.TestBean; import com.sun.faces.util.Util; import javax.faces.FacesException; import javax.faces.component.UIViewRoot; import javax.faces.context.ExternalContext; import javax.faces.el.EvaluationException; import javax.faces.el.PropertyNotFoundException; import javax.faces.el.PropertyResolver; import java.math.BigDecimal; import java.math.BigInteger; import java.util.List; /** * TestPropertyResolverImpl is a class ... *
* Lifetime And Scope* */ public class TestPropertyResolverImpl extends ServletFacesTestCase { // // Protected Constants // // // Class Variables // // // Instance Variables // // Attribute Instance Variables // Relationship Instance Variables private ElBean bean = null; private PropertyResolver resolver = null; // // Constructors and Initializers // public TestPropertyResolverImpl() { super("TestFacesContext"); } public TestPropertyResolverImpl(String name) { super(name); } // // Class methods // // // Methods from TestCase // public void setUp() { super.setUp(); bean = new ElBean(); resolver = getFacesContext().getApplication().getPropertyResolver(); } public void tearDown() { resolver = null; bean = null; super.tearDown(); } // // General Methods // // Negative getValue() tests on a JavaBean base object public void testNegative() throws Exception { Object value = null; // ---------- Should Return Null ---------- value = resolver.getValue(bean, null); assertNull(value); value = resolver.getValue(null, "booleanProperty"); assertNull(value); boolean exceptionThrown = false; try { value = resolver.getValue(null, null); } catch (javax.faces.el.EvaluationException ee) { exceptionThrown = true; } exceptionThrown = false; try { value = resolver.getValue(bean.getIntArray(), -1); } catch (javax.faces.el.EvaluationException ee) { exceptionThrown = true; } exceptionThrown = false; try { value = resolver.getValue(bean.getIntArray(), 3); } catch (javax.faces.el.EvaluationException ee) { exceptionThrown = true; } exceptionThrown = false; try { value = resolver.getValue(bean.getIntList(), -1); } catch (javax.faces.el.EvaluationException ee) { exceptionThrown = true; } exceptionThrown = false; try { value = resolver.getValue(bean.getIntList(), 5); } catch (javax.faces.el.EvaluationException ee) { exceptionThrown = true; } exceptionThrown = false; // ---------- Should throw EvaluationException try { value = resolver.getValue(bean, "nullStringProperty"); fail("Should have thrown EvaluationException"); } catch (EvaluationException e) { ; // Expected result } // ---------- Should Throw PropertyNotFoundException try { value = resolver.getValue(bean, "dontExist"); fail("Should have thrown EvaluationException"); } catch (EvaluationException e) { ; // Expected result } } public void testPristine() { // PENDING - test pristine condition of a new instance } // -------------------------------------------------- Indexed Variant Tests // Positive getValue() tests for the indexed variant against an array public void testIndexedGetArray() throws Exception { Object value = null; int intArray[] = bean.getIntArray(); assertEquals(3, intArray.length); value = resolver.getValue(intArray, -1); assertNull(value); value = resolver.getValue(null, 0); assertNull(value); value = resolver.getValue(intArray, 0); assertNotNull(value); assertTrue(value instanceof Integer); assertEquals(1, ((Integer) value).intValue()); value = resolver.getValue(intArray, 1); assertNotNull(value); assertTrue(value instanceof Integer); assertEquals(2, ((Integer) value).intValue()); value = resolver.getValue(intArray, 2); assertNotNull(value); assertTrue(value instanceof Integer); assertEquals(3, ((Integer) value).intValue()); } // Positive getValue() tests for the indexed variant against a List public void testIndexedGetList() throws Exception { Object value = null; List intList = bean.getIntList(); assertEquals(5, intList.size()); value = resolver.getValue(intList, -1); assertNull(value); value = resolver.getValue(null, 0); assertNull(value); value = resolver.getValue(intList, 0); assertNotNull(value); assertTrue(value instanceof Integer); assertEquals(10, ((Integer) value).intValue()); value = resolver.getValue(intList, 1); assertNotNull(value); assertTrue(value instanceof Integer); assertEquals(20, ((Integer) value).intValue()); value = resolver.getValue(intList, 2); assertNotNull(value); assertTrue(value instanceof Integer); assertEquals(30, ((Integer) value).intValue()); value = resolver.getValue(intList, 3); assertNotNull(value); assertTrue(value instanceof Integer); assertEquals(40, ((Integer) value).intValue()); value = resolver.getValue(intList, 4); assertNotNull(value); assertTrue(value instanceof Integer); assertEquals(50, ((Integer) value).intValue()); } // Positive setValue() tests for the indexed variant against an array public void testIndexedSetArray() throws Exception { Object value = new Integer(300); int intArray[] = bean.getIntArray(); assertEquals(3, intArray.length); resolver.setValue(intArray, 0, value); assertEquals(300, intArray[0]); Object[] objArray = new Object[] {"val"}; resolver.setValue(objArray, 0, null); assertNull(objArray[0]); try { resolver.setValue(null, 0, value); fail(); } catch (PropertyNotFoundException pnfe) {} try { resolver.setValue(intArray, -1, value); fail(); } catch (PropertyNotFoundException pnfe) {} try { resolver.setValue(intArray, 100, value); fail(); } catch (PropertyNotFoundException pnfe) {} } // Positive setValue() tests for the indexed variant against a List public void testIndexedSetList() throws Exception { Object value = new Object(); List intList = bean.getIntList(); assertEquals(5, intList.size()); resolver.setValue(intList, 0, value); assertNotNull(intList.get(0)); resolver.setValue(intList, 0, null); assertNull(intList.get(0)); try { resolver.setValue(null, 0, value); fail(); } catch (PropertyNotFoundException pnfe) {} try { resolver.setValue(intList, -1, value); fail(); } catch (PropertyNotFoundException pnfe) {} try { resolver.setValue(intList, 100, value); fail(); } catch (PropertyNotFoundException pnfe) {} } // Positive getType() tests for the indexed variant against an array public void testIndexedTypeArray() throws Exception { Class type = null; int intArray[] = bean.getIntArray(); assertEquals(3, intArray.length); type = resolver.getType(intArray, 0); assertEquals(Integer.TYPE, type); try { resolver.getType(null, 0); fail(); } catch (PropertyNotFoundException pnfe) {} try { resolver.getType(intArray, -1); fail(); } catch (PropertyNotFoundException pnfe) {} try { // do we really need to check this? resolver.getType(intArray, 100); //fail(); } catch (PropertyNotFoundException pnfe) {} } // Positive getType() tests for the indexed variant against a List public void testIndexedTypeList() throws Exception { Class type = null; List intList = bean.getIntList(); assertEquals(5, intList.size()); type = resolver.getType(intList, 0); assertEquals(Integer.class, type); try { resolver.getType(null, 0); fail(); } catch (PropertyNotFoundException pnfe) {} try { resolver.getType(intList, -1); fail(); } catch (PropertyNotFoundException pnfe) {} try { resolver.getType(intList, 100); fail(); } catch (PropertyNotFoundException pnfe) {} } // --------------------------------------------------- String Variant Tests // Postitive getValue() tests on a JavaBean base object public void testStringGetBean() throws Exception { Object value = null; value = resolver.getValue(bean, "booleanProperty"); assertNotNull(value); assertTrue(value instanceof Boolean); assertEquals(true, ((Boolean) value).booleanValue()); value = resolver.getValue(bean, "byteProperty"); assertNotNull(value); assertTrue(value instanceof Byte); assertEquals((byte) 123, ((Byte) value).byteValue()); value = resolver.getValue(bean, "doubleProperty"); assertNotNull(value); assertTrue(value instanceof Double); assertEquals((double) 654.321, ((Double) value).doubleValue(), 0.005); value = resolver.getValue(bean, "floatProperty"); assertNotNull(value); assertTrue(value instanceof Float); assertEquals((float) 123.45, ((Float) value).floatValue(), 0.5); value = resolver.getValue(bean, "intProperty"); assertNotNull(value); assertTrue(value instanceof Integer); assertEquals((int) 1234, ((Integer) value).intValue()); value = resolver.getValue(bean, "longProperty"); assertNotNull(value); assertTrue(value instanceof Long); assertEquals((long) 54321, ((Long) value).longValue()); value = resolver.getValue(bean, "nestedProperty"); assertNotNull(value); assertTrue(value instanceof ElBean); assertEquals("This is a String", ((ElBean) value).getStringProperty()); value = resolver.getValue(bean, "shortProperty"); assertNotNull(value); assertTrue(value instanceof Short); assertEquals((short) 321, ((Short) value).shortValue()); value = resolver.getValue(bean, "stringProperty"); assertNotNull(value); assertTrue(value instanceof String); assertEquals("This is a String", (String) value); } // Positive getValue() tests on a Map base object public void testStringGetMap() throws Exception { getFacesContext().getExternalContext().getRequestMap().put("testValue", this); assertTrue(this == resolver.getValue( getFacesContext().getExternalContext().getRequestMap(), "testValue")); } // Postitive setValue() tests on a JavaBean base object public void testStringSetBean() throws Exception { Object value = null; resolver.setValue(bean, "booleanProperty", Boolean.FALSE); value = resolver.getValue(bean, "booleanProperty"); assertNotNull(value); assertTrue(value instanceof Boolean); assertEquals(false, ((Boolean) value).booleanValue()); resolver.setValue(bean, "byteProperty", new Byte((byte) 124)); value = resolver.getValue(bean, "byteProperty"); assertNotNull(value); assertTrue(value instanceof Byte); assertEquals((byte) 124, ((Byte) value).byteValue()); resolver.setValue(bean, "doubleProperty", new Double(333.333)); value = resolver.getValue(bean, "doubleProperty"); assertNotNull(value); assertTrue(value instanceof Double); assertEquals((double) 333.333, ((Double) value).doubleValue(), 0.005); resolver.setValue(bean, "floatProperty", new Float(22.11)); value = resolver.getValue(bean, "floatProperty"); assertNotNull(value); assertTrue(value instanceof Float); assertEquals((float) 22.11, ((Float) value).floatValue(), 0.5); resolver.setValue(bean, "intProperty", new Integer(4321)); value = resolver.getValue(bean, "intProperty"); assertNotNull(value); assertTrue(value instanceof Integer); assertEquals((int) 4321, ((Integer) value).intValue()); resolver.setValue(bean, "longProperty", new Long(12345)); value = resolver.getValue(bean, "longProperty"); assertNotNull(value); assertTrue(value instanceof Long); assertEquals((long) 12345, ((Long) value).longValue()); resolver.setValue(bean, "nestedProperty", new ElBean()); value = resolver.getValue(bean, "nestedProperty"); assertNotNull(value); assertTrue(value instanceof ElBean); resolver.setValue(bean, "shortProperty", new Short((short) 123)); value = resolver.getValue(bean, "shortProperty"); assertNotNull(value); assertTrue(value instanceof Short); assertEquals((short) 123, ((Short) value).shortValue()); resolver.setValue(bean, "stringProperty", "That was a STRING"); value = resolver.getValue(bean, "stringProperty"); assertNotNull(value); assertTrue(value instanceof String); assertEquals("That was a STRING", (String) value); } // Positive setValue() tests on a Map base object public void testStringSetMap() throws Exception { // PENDING - insert tests here } // Postitive getValue() tests on a JavaBean base object public void testStringTypeBean() throws Exception { Class value = null; value = resolver.getType(bean, "booleanProperty"); assertNotNull(value); assertEquals(Boolean.TYPE, value); value = resolver.getType(bean, "byteProperty"); assertNotNull(value); assertEquals(Byte.TYPE, value); value = resolver.getType(bean, "doubleProperty"); assertNotNull(value); assertEquals(Double.TYPE, value); value = resolver.getType(bean, "floatProperty"); assertNotNull(value); assertEquals(Float.TYPE, value); value = resolver.getType(bean, "intProperty"); assertNotNull(value); assertEquals(Integer.TYPE, value); value = resolver.getType(bean, "longProperty"); assertNotNull(value); assertEquals(Long.TYPE, value); bean.setNestedProperty(new ElBean()); value = resolver.getType(bean, "nestedProperty"); assertNotNull(value); assertEquals(ElBean.class, value); value = resolver.getType(bean, "shortProperty"); assertNotNull(value); assertEquals(Short.TYPE, value); value = resolver.getType(bean, "stringProperty"); assertNotNull(value); assertEquals(String.class, value); } // Positive getValue() tests on a Map base object public void testStringTypeMap() throws Exception { // PENDING - insert tests here } public void testReadOnlyObject() { ExternalContext ec = getFacesContext().getExternalContext(); // these are mutable Maps assertTrue(!resolver.isReadOnly(ec.getApplicationMap(), "hello")); assertTrue(!resolver.isReadOnly(ec.getSessionMap(), "hello")); assertTrue(!resolver.isReadOnly(ec.getRequestMap(), "hello")); // these are immutable Maps assertTrue(resolver.isReadOnly(ec.getRequestParameterMap(), "hello")); assertTrue(resolver.isReadOnly(ec.getRequestParameterValuesMap(), "hello")); assertTrue(resolver.isReadOnly(ec.getRequestHeaderMap(), "hello")); assertTrue(resolver.isReadOnly(ec.getRequestHeaderValuesMap(), "hello")); assertTrue(resolver.isReadOnly(ec.getRequestCookieMap(), "hello")); assertTrue(resolver.isReadOnly(ec.getInitParameterMap(), "hello")); UIViewRoot root = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null); assertTrue(resolver.isReadOnly(root, "childCount")); com.sun.faces.cactus.TestBean testBean = (com.sun.faces.cactus.TestBean) ec.getSessionMap().get("TestBean"); assertTrue(resolver.isReadOnly(testBean, "readOnly")); assertTrue(!resolver.isReadOnly(testBean, "one")); } public void testReadOnlyIndex() { // PENDING(edburns): implement readonly index tests. } public void testType() { // PENDING(edburns): implement type tests } public void testConversion() throws Exception { ElBean bean = new ElBean(); this.conversionTest(bean, "booleanProperty", null, false); this.conversionTest(bean, "booleanProperty", "5", false); this.conversionTest(bean, "booleanProperty", new Character('c'), false); this.conversionTest(bean, "booleanProperty", Boolean.TRUE, true); this.conversionTest(bean, "booleanProperty", new BigInteger("5"), false); this.conversionTest(bean, "booleanProperty", new BigDecimal("5"), false); this.conversionTest(bean, "booleanProperty", new Byte((byte) 5), false); this.conversionTest(bean, "booleanProperty", new Short((short) 5), false); this.conversionTest(bean, "booleanProperty", new Integer(5), false); this.conversionTest(bean, "booleanProperty", new Long(5), false); this.conversionTest(bean, "booleanProperty", new Float(5), false); this.conversionTest(bean, "booleanProperty", new Double(5), false); this.conversionTest(bean, "byteProperty", null, false); this.conversionTest(bean, "byteProperty", "5", false); this.conversionTest(bean, "byteProperty", new Character('c'), false); this.conversionTest(bean, "byteProperty", Boolean.TRUE, false); this.conversionTest(bean, "byteProperty", new BigInteger("5"), false); this.conversionTest(bean, "byteProperty", new BigDecimal("5"), false); this.conversionTest(bean, "byteProperty", new Byte((byte) 5), true); this.conversionTest(bean, "byteProperty", new Short((short) 5), false); this.conversionTest(bean, "byteProperty", new Integer(5), false); this.conversionTest(bean, "byteProperty", new Long(5), false); this.conversionTest(bean, "byteProperty", new Float(5), false); this.conversionTest(bean, "byteProperty", new Double(5), false); this.conversionTest(bean, "characterProperty", null, false); this.conversionTest(bean, "characterProperty", "5", false); this.conversionTest(bean, "characterProperty", new Character('c'), true); this.conversionTest(bean, "characterProperty", Boolean.TRUE, false); this.conversionTest(bean, "characterProperty", new BigInteger("5"), false); this.conversionTest(bean, "characterProperty", new BigDecimal("5"), false); this.conversionTest(bean, "characterProperty", new Byte((byte) 5), false); this.conversionTest(bean, "characterProperty", new Short((short) 5), false); this.conversionTest(bean, "characterProperty", new Integer(5), false); this.conversionTest(bean, "characterProperty", new Long(5), false); this.conversionTest(bean, "characterProperty", new Float(5), false); this.conversionTest(bean, "characterProperty", new Double(5), false); this.conversionTest(bean, "doubleProperty", null, false); this.conversionTest(bean, "doubleProperty", "5", false); this.conversionTest(bean, "doubleProperty", new Character('c'), true); this.conversionTest(bean, "doubleProperty", Boolean.TRUE, false); this.conversionTest(bean, "doubleProperty", new BigInteger("5"), false); this.conversionTest(bean, "doubleProperty", new BigDecimal("5"), false); this.conversionTest(bean, "doubleProperty", new Byte((byte) 5), true); this.conversionTest(bean, "doubleProperty", new Short((short) 5), true); this.conversionTest(bean, "doubleProperty", new Integer(5), true); this.conversionTest(bean, "doubleProperty", new Long(5), true); this.conversionTest(bean, "doubleProperty", new Float(5), true); this.conversionTest(bean, "doubleProperty", new Double(5), true); this.conversionTest(bean, "floatProperty", null, false); this.conversionTest(bean, "floatProperty", "5", false); this.conversionTest(bean, "floatProperty", new Character('c'), true); this.conversionTest(bean, "floatProperty", Boolean.TRUE, false); this.conversionTest(bean, "floatProperty", new BigInteger("5"), false); this.conversionTest(bean, "floatProperty", new BigDecimal("5"), false); this.conversionTest(bean, "floatProperty", new Byte((byte) 5), true); this.conversionTest(bean, "floatProperty", new Short((short) 5), true); this.conversionTest(bean, "floatProperty", new Integer(5), true); this.conversionTest(bean, "floatProperty", new Long(5), true); this.conversionTest(bean, "floatProperty", new Float(5), true); this.conversionTest(bean, "floatProperty", new Double(5), false); this.conversionTest(bean, "longProperty", null, false); this.conversionTest(bean, "longProperty", "5", false); this.conversionTest(bean, "longProperty", new Character('c'), true); this.conversionTest(bean, "longProperty", Boolean.TRUE, false); this.conversionTest(bean, "longProperty", new BigInteger("5"), false); this.conversionTest(bean, "longProperty", new BigDecimal("5"), false); this.conversionTest(bean, "longProperty", new Byte((byte) 5), true); this.conversionTest(bean, "longProperty", new Short((short) 5), true); this.conversionTest(bean, "longProperty", new Integer(5), true); this.conversionTest(bean, "longProperty", new Long(5), true); this.conversionTest(bean, "longProperty", new Float(5), false); this.conversionTest(bean, "longProperty", new Double(5), false); this.conversionTest(bean, "shortProperty", null, false); this.conversionTest(bean, "shortProperty", "5", false); this.conversionTest(bean, "shortProperty", new Character('c'), false); this.conversionTest(bean, "shortProperty", Boolean.TRUE, false); this.conversionTest(bean, "shortProperty", new BigInteger("5"), false); this.conversionTest(bean, "shortProperty", new BigDecimal("5"), false); this.conversionTest(bean, "shortProperty", new Byte((byte) 5), true); this.conversionTest(bean, "shortProperty", new Short((short) 5), true); this.conversionTest(bean, "shortProperty", new Integer(5), false); this.conversionTest(bean, "shortProperty", new Long(5), false); this.conversionTest(bean, "shortProperty", new Float(5), false); this.conversionTest(bean, "shortProperty", new Double(5), false); this.conversionTest(bean, "stringProperty", null, true); this.conversionTest(bean, "stringProperty", "5", true); this.conversionTest(bean, "stringProperty", new Character('c'), false); this.conversionTest(bean, "stringProperty", Boolean.TRUE, false); this.conversionTest(bean, "stringProperty", new BigInteger("5"), false); this.conversionTest(bean, "stringProperty", new BigDecimal("5"), false); this.conversionTest(bean, "stringProperty", new Byte((byte) 5), false); this.conversionTest(bean, "stringProperty", new Short((short) 5), false); this.conversionTest(bean, "stringProperty", new Integer(5), false); this.conversionTest(bean, "stringProperty", new Long(5), false); this.conversionTest(bean, "stringProperty", new Float(5), false); this.conversionTest(bean, "stringProperty", new Double(5), false); } protected void conversionTest(Object bean, String property, Object value, boolean valid) throws Exception { if (valid) { try { this.resolver.setValue(bean, property, value); } catch (Exception e) { Class type = this.resolver.getType(bean, property); throw e; // throw new Exception("Conversion to "+type+" should not have failed for type "+((value != null) ? value.getClass() : null), e); } } else { try { this.resolver.setValue(bean, property, value); fail("Conversion to "+this.resolver.getType(bean, property)+" should have failed for type "+((value != null) ? value.getClass() : null)); } catch (FacesException e) { // good, should have ended up here } } } } // end of class TestPropertyResolverImpl mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/TestValueExpressionImpl_Model.java 0000644 0000000 0000000 00000033110 11412443352 025007 0 ustar /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can obtain * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. * Sun designates this particular file as subject to the "Classpath" exception * as provided by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the License * Header, with the fields enclosed by brackets [] replaced by your own * identifying information: "Portions Copyrighted [year] * [name of copyright owner]" * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ // TestValueExpressionImpl_Model.java package com.sun.faces.el; import com.sun.faces.cactus.ServletFacesTestCase; import com.sun.faces.TestBean; import com.sun.faces.cactus.TestBean.Inner2Bean; import com.sun.faces.cactus.TestBean.InnerBean; import javax.faces.context.FacesContext; import javax.el.ELException; import javax.el.ValueExpression; import javax.el.ELContext; /** * TestValueExpressionImpl_Model is a class ... *
* Lifetime And Scope* */ public class TestValueExpressionImpl_Model extends ServletFacesTestCase { // // Protected Constants // // // Class Variables // // // Instance Variables // // Attribute Instance Variables // Relationship Instance Variables ValueExpression valueExpression = null; // // Constructors and Initializers // public TestValueExpressionImpl_Model() { super("TestValueExpressionImpl"); } public TestValueExpressionImpl_Model(String name) { super(name); } // // Class methods // // // Methods from TestCase // // // General Methods // public ValueExpression create(String ref) throws Exception { return (getFacesContext().getApplication().getExpressionFactory(). createValueExpression(getFacesContext().getELContext(),("#{" + ref + "}"), Object.class)); } public void setUp() { super.setUp(); valueExpression = null; } public void tearDown() { valueExpression = null; super.tearDown(); } public void testSet() throws Exception { FacesContext facesContext = getFacesContext(); System.out.println("Testing setValue() with model bean in session "); TestBean testBean = new TestBean(); InnerBean inner = new InnerBean(); Inner2Bean innerInner = new Inner2Bean(); Object result = null; getFacesContext().getExternalContext().getSessionMap().put("TestBean", testBean); boolean exceptionThrown = false; System.setProperty(TestBean.PROP, TestBean.FALSE); valueExpression = this.create("TestBean.one"); valueExpression.setValue(getFacesContext().getELContext(), "one"); assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE)); InnerBean newInner = new InnerBean(); valueExpression = this.create("TestBean.inner"); valueExpression.setValue(getFacesContext().getELContext(), newInner); result = valueExpression.getValue(getFacesContext().getELContext()); assertTrue(result == newInner); // Test two levels of nesting System.setProperty(TestBean.PROP, TestBean.FALSE); valueExpression = this.create("sessionScope.TestBean.inner.two"); valueExpression.setValue(getFacesContext().getELContext(), "two"); assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE)); Inner2Bean newInner2 = new Inner2Bean(); valueExpression = this.create("TestBean.inner.inner2"); valueExpression.setValue(getFacesContext().getELContext(), newInner2); result = valueExpression.getValue(getFacesContext().getELContext()); assertTrue(result == newInner2); System.setProperty(TestBean.PROP, TestBean.FALSE); valueExpression = this.create("sessionScope.TestBean.inner.inner2"); valueExpression.setValue(getFacesContext().getELContext(), innerInner); assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE)); // Test three levels of nesting System.setProperty(TestBean.PROP, TestBean.FALSE); valueExpression = this.create("sessionScope.TestBean.inner.inner2.three"); valueExpression.setValue(getFacesContext().getELContext(), "three"); assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE)); } public void testSetNull() throws Exception { FacesContext facesContext = getFacesContext(); System.out.println( "Testing setValue() with model bean in session with null rValues"); TestBean testBean = new TestBean(); InnerBean inner = new InnerBean(); Inner2Bean innerInner = new Inner2Bean(); getFacesContext().getExternalContext().getSessionMap().put("TestBean", testBean); // Test one level of nesting valueExpression = this.create("TestBean.one"); valueExpression.setValue(getFacesContext().getELContext(), null); assertTrue(testBean.getOne() == null); System.setProperty(TestBean.PROP, TestBean.FALSE); valueExpression = this.create("sessionScope.TestBean.inner"); valueExpression.setValue(getFacesContext().getELContext(), inner); assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE)); valueExpression = this.create("sessionScope.TestBean.inner"); valueExpression.setValue(getFacesContext().getELContext(), null); assertTrue(testBean.getInner() == null); // Inner bean does not exist anymore. So this should result in an // exception. Should throw a PropertyNotFoundException according // to page 92 of the EL Spec boolean exceptionThrown = false; valueExpression = this.create("sessionScope.TestBean.inner.two"); try { valueExpression.setValue(getFacesContext().getELContext(), null); } catch (javax.el.PropertyNotFoundException ee) { exceptionThrown = true; } assertTrue(exceptionThrown); } public void testSetWithNoCurlyBraces() throws Exception { FacesContext facesContext = getFacesContext(); System.out.println("Testing setValue() with model bean in request "); TestBean testBean = new TestBean(); InnerBean inner = new InnerBean(); Inner2Bean innerInner = new Inner2Bean(); facesContext.getExternalContext().getSessionMap().remove("TestBean"); facesContext.getExternalContext().getRequestMap().put("TestBean", testBean); // Test implicit scopes direct access to some scope objects should // throw an illegalArgumentException boolean gotException = false; try { valueExpression = this.create("header.header-one"); valueExpression.setValue(getFacesContext().getELContext(), testBean); } catch (javax.el.ELException pnf) { gotException = true; } assertTrue(gotException); // Test one level of nesting System.setProperty(TestBean.PROP, TestBean.FALSE); valueExpression = this.create("TestBean.one"); valueExpression.setValue(getFacesContext().getELContext(), "one"); assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE)); System.setProperty(TestBean.PROP, TestBean.FALSE); valueExpression = this.create("requestScope.TestBean.inner"); valueExpression.setValue(getFacesContext().getELContext(), inner); assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE)); // Test two levels of nesting System.setProperty(TestBean.PROP, TestBean.FALSE); valueExpression = this.create("requestScope.TestBean.inner.two"); valueExpression.setValue(getFacesContext().getELContext(), "two"); assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE)); System.setProperty(TestBean.PROP, TestBean.FALSE); valueExpression = this.create("requestScope.TestBean.inner.inner2"); valueExpression.setValue(getFacesContext().getELContext(), innerInner); assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE)); // Test three levels of nesting System.setProperty(TestBean.PROP, TestBean.FALSE); valueExpression = this.create("requestScope.TestBean.inner.inner2.three"); valueExpression.setValue(getFacesContext().getELContext(), "three"); assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE)); } public void testGet() throws Exception { FacesContext facesContext = getFacesContext(); System.out.println("Testing getValue() with model bean in context"); assertTrue(facesContext != null); TestBean testBeanResult = null, testBean = new TestBean(); InnerBean inner = new InnerBean(); Inner2Bean inner2 = new Inner2Bean(); String result; // Init the beans testBean.setOne("one"); inner.setTwo("two"); inner2.setThree("three"); inner.setInner2(inner2); testBean.setInner(inner); assertTrue(facesContext != null); assertTrue(facesContext.getExternalContext().getSession(false) != null); facesContext.getExternalContext().getRequestMap().remove("TestBean"); facesContext.getExternalContext().getSessionMap().remove("TestBean"); facesContext.getExternalContext().getApplicationMap().put("TestBean", testBean); // Test zero levels of nesting valueExpression = this.create("applicationScope.TestBean"); testBeanResult = (TestBean) valueExpression.getValue(getFacesContext().getELContext()); assertTrue(testBeanResult != null); assertTrue(testBeanResult == testBean); // Test one level of nesting valueExpression = this.create("applicationScope.TestBean.one"); result = (String) valueExpression.getValue(getFacesContext().getELContext()); assertTrue(result.equals("one")); valueExpression = this.create("applicationScope.TestBean.inner"); inner = (InnerBean) valueExpression.getValue(getFacesContext().getELContext()); assertTrue(null != inner); // Test two levels of nesting valueExpression = this.create("applicationScope.TestBean.inner.two"); result = (String) valueExpression.getValue(getFacesContext().getELContext()); assertTrue(result.equals("two")); valueExpression = this.create("applicationScope.TestBean.inner.inner2"); inner2 = (Inner2Bean) valueExpression.getValue(getFacesContext().getELContext()); assertTrue(null != inner2); // Test three levels of nesting valueExpression = this.create("applicationScope.TestBean.inner.inner2.three"); result = (String) valueExpression.getValue(getFacesContext().getELContext()); assertTrue(result.equals("three")); } public void testModelType() { /***************** PENDING(edburns): // Test model type System.out.println("Testing getModelType()"); Class classType = null; String className = null; // Test zero levels of nesting classType = facesContext.getModelType("applicationScope.TestBean"); assertTrue(classType != null); className = classType.getName(); assertTrue(className.equals(testBean.getClass().getName())); classType = facesContext.getModelType("applicationScope.TestBean.inner.pin"); assertTrue(classType != null); className = classType.getName(); assertTrue(className.equals("java.lang.Integer")); classType = facesContext.getModelType("applicationScope.TestBean.inner.result"); assertTrue(classType != null); className = classType.getName(); assertTrue(className.equals("java.lang.Boolean")); classType = facesContext.getModelType("applicationScope.TestBean.one"); assertTrue(classType != null); className = classType.getName(); assertTrue(className.equals("java.lang.String")); *********************/ } } // end of class TestValueExpressionImpl_Model mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/TestFacesResourceBundleELResolver.java 0000644 0000000 0000000 00000017342 11412443352 025550 0 ustar /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can obtain * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. * Sun designates this particular file as subject to the "Classpath" exception * as provided by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the License * Header, with the fields enclosed by brackets [] replaced by your own * identifying information: "Portions Copyrighted [year] * [name of copyright owner]" * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ // TestFacesResourceBundleELResolver.java package com.sun.faces.el; import com.sun.faces.cactus.ServletFacesTestCase; import java.beans.FeatureDescriptor; import java.util.Iterator; import java.util.Locale; import java.util.ResourceBundle; import javax.el.ELResolver; import javax.el.PropertyNotFoundException; import javax.el.PropertyNotWritableException; import javax.faces.component.UIViewRoot; public class TestFacesResourceBundleELResolver extends ServletFacesTestCase { public TestFacesResourceBundleELResolver() { super("TestFacesResourceBundleELResolver"); } public TestFacesResourceBundleELResolver(String name) { super(name); } private FacesResourceBundleELResolver resolver = null; public void setUp() { super.setUp(); UIViewRoot root = new UIViewRoot(); root.setLocale(Locale.ENGLISH); getFacesContext().setViewRoot(root); resolver = new FacesResourceBundleELResolver(); } public void testGetValuePositive() throws Exception { ResourceBundle bundle1 = (ResourceBundle) resolver.getValue(getFacesContext().getELContext(), null, "testResourceBundle"); assertNotNull(bundle1); String value = bundle1.getString("value2"); assertNotNull(value); assertEquals("Bob", value); } public void testGetValueNegative() throws Exception { ResourceBundle bundle1 = (ResourceBundle) resolver.getValue(getFacesContext().getELContext(), "hello", "testResourceBundle"); assertNull(bundle1); boolean exceptionThrown = false; try { bundle1 = (ResourceBundle) resolver.getValue(getFacesContext().getELContext(), null, null); } catch (PropertyNotFoundException e) { exceptionThrown = true; } assertTrue(exceptionThrown); bundle1 = (ResourceBundle) resolver.getValue(getFacesContext().getELContext(), null, "nonExistent"); assertNull(bundle1); } public void testGetTypePositive() throws Exception { getFacesContext().getELContext().setPropertyResolved(false); Class type = resolver.getType(getFacesContext().getELContext(), null, "testResourceBundle"); assertTrue(getFacesContext().getELContext().isPropertyResolved()); assertEquals(ResourceBundle.class, type); } public void testGetTypeNegative() throws Exception { Class result = resolver.getType(getFacesContext().getELContext(), "non-null", "testResourceBundle"); assertTrue(null == result); boolean exceptionThrown = false; try { resolver.getType(getFacesContext().getELContext(), null, null); } catch (PropertyNotFoundException e) { exceptionThrown = true; } assertTrue(exceptionThrown); } public void testSetValeNegative() throws Exception { boolean exceptionThrown = false; try { resolver.setValue(getFacesContext().getELContext(), null, null, null); } catch (PropertyNotFoundException e) { exceptionThrown = true; } assertTrue(exceptionThrown); exceptionThrown = false; try { resolver.setValue(getFacesContext().getELContext(), null, "testResourceBundle", "Value"); } catch (PropertyNotWritableException e) { exceptionThrown = true; } assertTrue(exceptionThrown); } public void testIsReadOnlyPositive() throws Exception { getFacesContext().getELContext().setPropertyResolved(false); boolean result = resolver.isReadOnly(getFacesContext().getELContext(), null, "testResourceBundle"); assertTrue(result); assertTrue(getFacesContext().getELContext().isPropertyResolved()); } public void testIsReadOnlyNegative() throws Exception { boolean result = resolver.isReadOnly(getFacesContext().getELContext(), "non-null Base", null); assertTrue(!result); getFacesContext().getELContext().setPropertyResolved(false); boolean exceptionThrown = false; try { resolver.isReadOnly(getFacesContext().getELContext(), null, null); } catch (PropertyNotFoundException e) { exceptionThrown = true; } assertTrue(exceptionThrown); assertFalse(getFacesContext().getELContext().isPropertyResolved()); } public void testGetFeatureDescriptorsPositive() throws Exception { Iterator iter = resolver.getFeatureDescriptors(getFacesContext().getELContext(), null); assertNotNull(iter); FeatureDescriptor cur = null; String displayName1 = "Testo Pesto", displayName2 = "Second ResourceBundle"; String var1 = "testResourceBundle", var2 = "testResourceBundle2"; boolean test = false; while (iter.hasNext()) { test = false; cur = (FeatureDescriptor) iter.next(); assertEquals(Boolean.TRUE, cur.getValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME)); assertEquals(ResourceBundle.class, cur.getValue(ELResolver.TYPE)); assertTrue(!cur.isExpert()); assertTrue(!cur.isHidden()); assertTrue(cur.isPreferred()); assertNotNull(cur.getDisplayName()); test = cur.getDisplayName().equals(displayName1) || cur.getDisplayName().equals(displayName2); assertTrue(test); test = cur.getName().equals(var1) || cur.getName().equals(var2); assertTrue(test); } } } mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/TestValueBindingImpl.java 0000644 0000000 0000000 00000121326 11412443352 023111 0 ustar /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can obtain * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt. * Sun designates this particular file as subject to the "Classpath" exception * as provided by Sun in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the License * Header, with the fields enclosed by brackets [] replaced by your own * identifying information: "Portions Copyrighted [year] * [name of copyright owner]" * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ // TestValueBindingImpl.java package com.sun.faces.el; import com.sun.faces.cactus.ServletFacesTestCase; import com.sun.faces.TestBean; import com.sun.faces.cactus.TestBean.Inner2Bean; import com.sun.faces.cactus.TestBean.InnerBean; import com.sun.faces.application.ApplicationImpl; import com.sun.faces.util.Util; import org.apache.cactus.WebRequest; import javax.faces.FacesException; import javax.faces.component.StateHolder; import javax.faces.component.UIForm; import javax.faces.component.UIInput; import javax.faces.component.UIViewRoot; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.faces.el.EvaluationException; import javax.faces.el.PropertyNotFoundException; import javax.faces.el.ValueBinding; import javax.servlet.http.HttpServletRequest; import java.io.Serializable; import java.util.HashMap; import java.util.Map; import java.util.Locale; /** * TestValueBindingImpl is a class ...
Lifetime And Scope *
*/
public class TestValueBindingImpl extends ServletFacesTestCase
{
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
protected ValueBinding valueBinding;
// protected ValueBindingFactory factory = new ValueBindingFactory();
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestValueBindingImpl()
{
super("TestValueBindingImpl");
}
public TestValueBindingImpl(String name)
{
super(name);
}
//
// Class methods
//
//
// Methods from TestCase
//
//
// General Methods
//
protected ValueBinding create(String ref) throws Exception
{
return (getFacesContext().getApplication().createValueBinding("#{" + ref + "}"));
}
public void populateRequest(WebRequest theRequest)
{
theRequest.addHeader("ELHeader", "ELHeader");
theRequest.addHeader("multiheader", "1");
theRequest.addHeader("multiheader", "2");
theRequest.addParameter("ELParam", "ELParam");
theRequest.addParameter("multiparam", "one");
theRequest.addParameter("multiparam", "two");
theRequest.addCookie("cookie", "monster");
}
public void beginELGet(WebRequest theRequest)
{
populateRequest(theRequest);
}
public void testELGet() throws Exception
{
TestBean testBean = new TestBean();
InnerBean newInner, oldInner = new InnerBean();
testBean.setInner(oldInner);
Object result = null;
ExternalContext extContext = getFacesContext().getExternalContext();
Map myMap = new HashMap();
TestBean myBean = new TestBean();
myBean.setOne("one");
myMap.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
//
// Get tests
//
valueBinding = this.create("myMap.myBean.one");
result = valueBinding.getValue(getFacesContext());
assertEquals("one", result);
valueBinding = this.create("myMap[\"myBean\"].one");
result = valueBinding.getValue(getFacesContext());
assertTrue("one".equals(result));
valueBinding = this.create("myMap.myBean['one']");
result = valueBinding.getValue(getFacesContext());
assertTrue("one".equals(result));
// Simple tests, verify that bracket and dot operators work
valueBinding = this.create("TestBean.inner");
getFacesContext().getExternalContext().getSessionMap().put("TestBean",
testBean);
result = valueBinding.getValue(getFacesContext());
assertTrue(result == oldInner);
valueBinding = this.create("TestBean[\"inner\"]");
result = valueBinding.getValue(getFacesContext());
assertTrue(result == oldInner);
valueBinding = this.create("TestBean[\"inner\"].customers[1]");
result = valueBinding.getValue(getFacesContext());
assertTrue(result instanceof String);
assertTrue(result.equals("Jerry"));
// try out the implicit objects
valueBinding = this.create("sessionScope.TestBean.inner");
result = valueBinding.getValue(getFacesContext());
assertTrue(result == oldInner);
valueBinding = this.create("header.ELHeader");
result = valueBinding.getValue(getFacesContext());
assertTrue(requestsHaveSameAttributeSet(
(HttpServletRequest) getFacesContext().getExternalContext()
.getRequest(), (HttpServletRequest) request));
assertTrue(request.getHeader("ELHeader").equals("ELHeader"));
assertTrue(result.equals("ELHeader"));
valueBinding = this.create("param.ELParam");
result = valueBinding.getValue(getFacesContext());
assertTrue(result.equals("ELParam"));
String multiparam[] = null;
valueBinding = this.create("paramValues.multiparam");
multiparam = (String[]) valueBinding.getValue(getFacesContext());
assertTrue(null != multiparam);
assertTrue(2 == multiparam.length);
assertTrue(multiparam[0].equals("one"));
assertTrue(multiparam[1].equals("two"));
valueBinding = this.create("headerValues.multiheader");
String[] multiHeader = (String[]) valueBinding
.getValue(getFacesContext());
assertTrue(null != multiHeader);
assertTrue(1 == multiHeader.length);
assertTrue(multiHeader[0].equals("1,2"));
valueBinding = this.create("initParam.testInitParam");
result = valueBinding.getValue(getFacesContext());
assertTrue(null != result);
assertTrue(result.equals("testInitParam"));
// PENDING(craigmcc) - Comment out this test because on my platform
// the getRequestCookies() call returns null
/*
* valueBinding.setRef("cookie.cookie"); result =
* valueBinding.getValue(getFacesContext()); assertTrue(null != result);
* assertTrue(result instanceof Cookie); assertTrue(((Cookie)
* result).getValue().equals("monster"));
*/
}
public void beginELSet(WebRequest theRequest)
{
populateRequest(theRequest);
}
public void testELSet() throws Exception
{
TestBean testBean = new TestBean();
InnerBean newInner, oldInner = new InnerBean();
testBean.setInner(oldInner);
ValueBinding valueBinding = null;
Object result = null;
ExternalContext extContext = getFacesContext().getExternalContext();
Map myMap = new HashMap();
TestBean myBean = new TestBean();
myMap.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
//
// Set tests
//
valueBinding = this.create("myMap.myBean.one");
valueBinding.setValue(getFacesContext(), "one");
Map map = (Map) extContext.getRequestMap().get("myMap");
assertTrue("one".equals(((TestBean) map.get("myBean")).getOne()));
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
// test that we can set null as the value
valueBinding = this.create("myMap.myBean.prop");
valueBinding.setValue(getFacesContext(), null);
map = (Map) extContext.getRequestMap().get("myMap");
assertEquals(null, ((TestBean) map.get("myBean")).getOne());
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
valueBinding = this.create("myMap[\"myBean\"].one");
valueBinding.setValue(getFacesContext(), "one");
map = (Map) extContext.getRequestMap().get("myMap");
assertTrue("one".equals(((TestBean) map.get("myBean")).getOne()));
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
// test that we can set the property to null
valueBinding = this.create("myMap[\"myBean\"].prop");
valueBinding.setValue(getFacesContext(), null);
map = (Map) extContext.getRequestMap().get("myMap");
String msg = "Default Message";
if (((TestBean) map.get("myBean")).getProp() != null)
{
msg = ((TestBean) map.get("myBean")).getProp().getClass().getName();
}
assertEquals(msg, null, ((TestBean) map.get("myBean")).getProp());
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
valueBinding = this.create("myMap.myBean['one']");
valueBinding.setValue(getFacesContext(), "one");
map = (Map) extContext.getRequestMap().get("myMap");
assertTrue("one".equals(((TestBean) map.get("myBean")).getOne()));
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
// set the prop to null
valueBinding = this.create("myMap.myBean['prop']");
valueBinding.setValue(getFacesContext(), null);
map = (Map) extContext.getRequestMap().get("myMap");
assertEquals(null, ((TestBean) map.get("myBean")).getOne());
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
valueBinding = this.create("NonExist");
valueBinding.setValue(getFacesContext(), "value");
result = extContext.getRequestMap().get("NonExist");
assertTrue("value".equals(result));
extContext.getRequestMap().remove("NonExist");
extContext.getSessionMap().put("Key", "oldValue");
valueBinding = this.create("Key");
valueBinding.setValue(getFacesContext(), "newValue");
result = extContext.getSessionMap().get("Key");
assertTrue("newValue".equals(result));
extContext.getSessionMap().remove("Key");
newInner = new InnerBean();
valueBinding = this.create("TestBean.inner");
valueBinding.setValue(getFacesContext(), newInner);
result = valueBinding.getValue(getFacesContext());
assertTrue(result == newInner);
assertTrue(oldInner != newInner);
oldInner = newInner;
newInner = new InnerBean();
valueBinding = this.create("TestBean[\"inner\"]");
valueBinding.setValue(getFacesContext(), newInner);
result = valueBinding.getValue(getFacesContext());
assertTrue(result == newInner);
assertTrue(oldInner != newInner);
String oldCustomer0 = null, oldCustomer1 = null, customer0 = null, customer1 = null;
valueBinding = this.create("TestBean[\"inner\"].customers[0]");
oldCustomer0 = customer0 = (String) valueBinding
.getValue(getFacesContext());
valueBinding = this.create("TestBean[\"inner\"].customers[1]");
oldCustomer1 = customer1 = (String) valueBinding
.getValue(getFacesContext());
valueBinding = this.create("TestBean[\"inner\"].customers[0]");
valueBinding.setValue(getFacesContext(), "Jerry");
valueBinding = this.create("TestBean[\"inner\"].customers[1]");
valueBinding.setValue(getFacesContext(), "Mickey");
valueBinding = this.create("TestBean[\"inner\"].customers[0]");
customer0 = (String) valueBinding.getValue(getFacesContext());
valueBinding = this.create("TestBean[\"inner\"].customers[1]");
customer1 = (String) valueBinding.getValue(getFacesContext());
assertTrue(customer0.equals("Jerry"));
assertTrue(customer1.equals("Mickey"));
valueBinding = this.create("TestBean[\"inner\"].customers[0]");
assertTrue(valueBinding.getValue(getFacesContext()) != oldCustomer0);
valueBinding = this.create("TestBean[\"inner\"].customers[1]");
assertTrue(valueBinding.getValue(getFacesContext()) != oldCustomer1);
// put in a map to the customers Collection
Inner2Bean inner2 = new Inner2Bean();
assertTrue(null == inner2.getNicknames().get("foo"));
valueBinding = this.create("TestBean[\"inner\"].customers[2]");
valueBinding.setValue(getFacesContext(), inner2);
valueBinding = this.create("TestBean[\"inner\"].customers[2]");
assertTrue(valueBinding.getValue(getFacesContext()) == inner2);
valueBinding = this
.create("TestBean[\"inner\"].customers[2].nicknames.foo");
valueBinding.setValue(getFacesContext(), "bar");
assertTrue(((String) inner2.getNicknames().get("foo")).equals("bar"));
}
public void testNullReference() throws Exception
{
try
{
getFacesContext().getApplication().createValueBinding(null);
fail();
}
catch (NullPointerException npe) {}
catch (Exception e) { fail("Should have thrown an NPE"); };
}
public void testLiterals() throws Exception
{
ValueBinding vb = null;
Object result = null;
ExternalContext extContext = getFacesContext().getExternalContext();
vb = getFacesContext().getApplication().createValueBinding("test");
assertEquals("test", vb.getValue(getFacesContext()));
assertEquals(String.class, vb.getType(getFacesContext()));
try
{
vb.setValue(getFacesContext(), "other");
fail("Literal's setValue(..) should have thrown a EvaluationException");
}
catch (javax.faces.el.EvaluationException ee) {}
}
public void testReadOnly_singleCase() throws Exception
{
// these are mutable Maps
/*
* properties on these maps are mutable, but not the object itself....
* see
*/
valueBinding = this.create("applicationScope");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("sessionScope");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("requestScope");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
// these are immutable Maps
valueBinding = this.create("param");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("paramValues");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("header");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("headerValues");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("cookie");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("initParam");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
}
public void testReadOnly_multipleCase() throws Exception
{
// these are mutable Maps
valueBinding = this.create("applicationScope.value");
valueBinding.setValue(getFacesContext(), "value");
String value = (String) valueBinding.getValue(getFacesContext());
assertTrue(!valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("sessionScope.value");
assertTrue(!valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("requestScope.value");
assertTrue(!valueBinding.isReadOnly(getFacesContext()));
// these are immutable Maps
valueBinding = this.create("param.value");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("paramValues.value");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("header.value");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("headerValues.value");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("cookie.value");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("initParam.value");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
// tree
// create a dummy root for the tree.
UIViewRoot page = Util.getViewHandler(getFacesContext()).createView(
getFacesContext(), null);
page.setId("root");
page.setViewId("newTree");
page.setLocale(Locale.US);
getFacesContext().setViewRoot(page);
valueBinding = this.create("view.childCount");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
com.sun.faces.cactus.TestBean testBean = (com.sun.faces.cactus.TestBean) getFacesContext().getExternalContext()
.getSessionMap().get("TestBean");
assertTrue(null != testBean);
valueBinding = this.create("TestBean.readOnly");
assertTrue(valueBinding.isReadOnly(getFacesContext()));
valueBinding = this.create("TestBean.one");
assertTrue(!valueBinding.isReadOnly(getFacesContext()));
InnerBean inner = new InnerBean();
testBean.setInner(inner);
valueBinding = this.create("TestBean[\"inner\"].customers[1]");
assertTrue(!valueBinding.isReadOnly(getFacesContext()));
}
public void testGetType_singleCase() throws Exception
{
// these are mutable Maps
valueBinding = this.create("applicationScope");
assertTrue(valueBinding.getType(getFacesContext()) == null);
valueBinding = this.create("sessionScope");
assertTrue(valueBinding.getType(getFacesContext()) == null);
valueBinding = this.create("requestScope");
assertTrue(valueBinding.getType(getFacesContext()) == null);
// these are immutable Maps
valueBinding = this.create("param");
assertTrue(valueBinding.getType(getFacesContext()) == null);
valueBinding = this.create("paramValues");
assertTrue(valueBinding.getType(getFacesContext()) == null);
valueBinding = this.create("header");
assertTrue(valueBinding.getType(getFacesContext()) == null);
valueBinding = this.create("headerValues");
assertTrue(valueBinding.getType(getFacesContext()) == null);
valueBinding = this.create("cookie");
assertTrue(valueBinding.getType(getFacesContext()) == null);
valueBinding = this.create("initParam");
assertTrue(valueBinding.getType(getFacesContext()) == null);
}
public void beginGetType_multipleCase(WebRequest theRequest)
{
populateRequest(theRequest);
}
public void testGetType_multipleCase() throws Exception
{
String property = "testvalueBindingImpl_property";
getFacesContext().getExternalContext().getApplicationMap().put(
property, property);
getFacesContext().getExternalContext().getSessionMap().put(property,
property);
getFacesContext().getExternalContext().getRequestMap().put(property,
property);
// these are mutable Maps
valueBinding = this.create("applicationScope." + property);
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"java.lang.Object"));
valueBinding = this.create("sessionScope." + property);
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"java.lang.Object"));
valueBinding = this.create("requestScope." + property);
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"java.lang.Object"));
// these are immutable Maps
valueBinding = this.create("param." + "ELParam");
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"java.lang.Object"));
valueBinding = this.create("paramValues.multiparam");
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"java.lang.Object"));
valueBinding = this.create("header.ELHeader");
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"java.lang.Object"));
valueBinding = this.create("headerValues.multiheader");
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"java.lang.Object"));
// assertTrue(java.util.Enumeration.class.isAssignableFrom(valueBinding
// .getType(getFacesContext())));
// PENDING(craigmcc) - Comment out this test because on my platform
// the getRequestCookies() call returns null
/*
* valueBinding = this.create("cookie.cookie");
* assertTrue(valueBinding.getType(getFacesContext()).getName().equals("javax.servlet.http.Cookie"));
*/
valueBinding = this
.create("initParam['javax.faces.STATE_SAVING_METHOD']");
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"java.lang.Object"));
// tree
// create a dummy root for the tree.
UIViewRoot page = Util.getViewHandler(getFacesContext()).createView(
getFacesContext(), null);
page.setId("root");
page.setViewId("newTree");
page.setLocale(Locale.US);
getFacesContext().setViewRoot(page);
valueBinding = this.create("view");
Class c = valueBinding.getType(getFacesContext());
assertTrue(c == null);
com.sun.faces.cactus.TestBean testBean = (com.sun.faces.cactus.TestBean) getFacesContext().getExternalContext()
.getSessionMap().get("TestBean");
assertTrue(null != testBean);
valueBinding = this.create("TestBean.readOnly");
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"java.lang.String"));
valueBinding = this.create("TestBean.one");
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"java.lang.String"));
InnerBean inner = new InnerBean();
testBean.setInner(inner);
valueBinding = this.create("TestBean[\"inner\"].customers[1]");
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"java.lang.Object"));
valueBinding = this.create("TestBean[\"inner\"]");
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"com.sun.faces.cactus.TestBean$InnerBean"));
int[] intArray =
{ 1, 2, 3 };
getFacesContext().getExternalContext().getRequestMap().put("intArray",
intArray);
valueBinding = this.create("requestScope.intArray");
assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
"java.lang.Object"));
// assertTrue(valueBinding.getType(getFacesContext()).getName().equals(
// "[I"));
}
public void testGetScopePositive() throws Exception
{
TestBean testBean = new TestBean();
getFacesContext().getExternalContext().getApplicationMap().put(
"TestApplicationBean", testBean);
valueBinding = this.create("TestApplicationBean");
assertEquals(ELUtils.Scope.APPLICATION, ELUtils.getScope("TestApplicationBean", null));
valueBinding = this.create("TestApplicationBean.one");
assertEquals(ELUtils.Scope.APPLICATION, ELUtils.getScope("TestApplicationBean.one",
null));
valueBinding = this.create("TestApplicationBean.inner.two");
assertEquals(ELUtils.Scope.APPLICATION, ELUtils.getScope(
"TestApplicationBean.inner.two", null));
valueBinding = this.create("applicationScope.TestApplicationBean");
assertEquals(ELUtils.Scope.APPLICATION, ELUtils.getScope(
"applicationScope.TestApplicationBean", null));
valueBinding = this
.create("applicationScope.TestApplicationBean.inner.two");
assertEquals(ELUtils.Scope.APPLICATION, ELUtils.getScope(
"applicationScope.TestApplicationBean.inner.two", null));
getFacesContext().getExternalContext().getSessionMap().put(
"TestSessionBean", testBean);
valueBinding = this.create("TestSessionBean");
assertEquals(ELUtils.Scope.SESSION, ELUtils.getScope("TestSessionBean", null));
valueBinding = this.create("TestSessionBean.one");
assertEquals(ELUtils.Scope.SESSION, ELUtils.getScope("TestSessionBean.one", null));
valueBinding = this.create("TestSessionBean.inner.two");
assertEquals(ELUtils.Scope.SESSION, ELUtils
.getScope("TestSessionBean.inner.two", null));
valueBinding = this.create("sessionScope.TestSessionBean");
assertEquals(ELUtils.Scope.SESSION, ELUtils.getScope("sessionScope.TestSessionBean",
null));
valueBinding = this.create("sessionScope.TestSessionBean.inner.two");
assertEquals(ELUtils.Scope.SESSION, ELUtils.getScope(
"sessionScope.TestSessionBean.inner.two", null));
getFacesContext().getExternalContext().getRequestMap().put(
"TestRequestBean", testBean);
valueBinding = this.create("TestRequestBean");
assertEquals(ELUtils.Scope.REQUEST, ELUtils.getScope("TestRequestBean", null));
valueBinding = this.create("TestRequestBean.one");
assertEquals(ELUtils.Scope.REQUEST, ELUtils.getScope("TestRequestBean.one", null));
valueBinding = this.create("TestRequestBean.inner.two");
assertEquals(ELUtils.Scope.REQUEST, ELUtils
.getScope("TestRequestBean.inner.two", null));
valueBinding = this.create("requestScope.TestRequestBean");
assertEquals(ELUtils.Scope.REQUEST, ELUtils.getScope("requestScope.TestRequestBean",
null));
valueBinding = this.create("requestScope.TestRequestBean.inner.two");
assertEquals(ELUtils.Scope.REQUEST, ELUtils.getScope(
"requestScope.TestRequestBean.inner.two", null));
valueBinding = this.create("TestNoneBean");
assertEquals(null, ELUtils.getScope("TestNoneBean", null));
valueBinding = this.create("TestNoneBean.one");
assertEquals(null, ELUtils.getScope("TestNoneBean.one", null));
valueBinding = this.create("TestNoneBean.inner.two");
assertEquals(null, ELUtils.getScope("TestNoneBean.inner.two", null));
}
public void testGetScopeNegative() throws Exception {
ValueBinding valueBinding = null;
String property = null;
/*
property = "[]";
valueBinding = this.factory.createValueBinding(property);
assertNull(Util.getScope(property, null));
property = "][";
assertNull(Util.getScope(property, null));
property = "";
assertNull(Util.getScope(property, null));
property = null;
assertNull(Util.getScope(property, null));
property = "foo.sessionScope";
assertNull(Util.getScope(property, null));
*/
}
// negative test for case when valueRef is merely
// one of the reserved scope names.
public void testReservedScopeIdentifiers() throws Exception
{
boolean exceptionThrown = false;
try
{
valueBinding = this.create("applicationScope");
valueBinding.setValue(getFacesContext(), "value");
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("sessionScope");
valueBinding.setValue(getFacesContext(), "value");
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("requestScope");
valueBinding.setValue(getFacesContext(), "value");
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("facesContext");
valueBinding.setValue(getFacesContext(), "value");
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("cookie");
valueBinding.setValue(getFacesContext(), "value");
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("header");
valueBinding.setValue(getFacesContext(), "value");
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("headerValues");
valueBinding.setValue(getFacesContext(), "value");
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("initParam");
valueBinding.setValue(getFacesContext(), "value");
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("param");
valueBinding.setValue(getFacesContext(), "value");
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("paramValues");
valueBinding.setValue(getFacesContext(), "value");
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("view");
valueBinding.setValue(getFacesContext(), "value");
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
public void testInvalidExpression() throws Exception
{
boolean exceptionThrown = false;
try
{
valueBinding = this.create("");
valueBinding.getValue(getFacesContext());
}
catch (FacesException e)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("!");
valueBinding.getValue(getFacesContext());
}
catch (PropertyNotFoundException e)
{
exceptionThrown = true;
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("..");
valueBinding.getValue(getFacesContext());
}
catch (PropertyNotFoundException e)
{
exceptionThrown = true;
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create(".foo");
valueBinding.getValue(getFacesContext());
}
catch (PropertyNotFoundException e)
{
exceptionThrown = true;
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("()");
valueBinding.getValue(getFacesContext());
}
catch (PropertyNotFoundException e)
{
exceptionThrown = true;
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("[]");
valueBinding.getValue(getFacesContext());
}
catch (PropertyNotFoundException e)
{
exceptionThrown = true;
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("applicationScope}");
valueBinding.getValue(getFacesContext());
}
catch (PropertyNotFoundException e)
{
exceptionThrown = true;
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(!exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("applicationScope >= sessionScope");
valueBinding.getValue(getFacesContext());
}
catch (PropertyNotFoundException e)
{
exceptionThrown = true;
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try
{
valueBinding = this.create("foo applicationScope");
valueBinding.getValue(getFacesContext());
}
catch (PropertyNotFoundException e)
{
exceptionThrown = true;
}
catch (EvaluationException ee)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
public void testStateHolderSmall() throws Exception
{
StateHolderSaver saver = null;
ValueBinding binding = getFacesContext().getApplication()
.createValueBinding("#{TestBean.indexProperties[0]}");
assertEquals("ValueBinding not expected value", "Justyna",
(String) binding.getValue(getFacesContext()));
saver = new StateHolderSaver(getFacesContext(), binding);
binding = null;
binding = (ValueBinding) saver.restore(getFacesContext());
assertEquals("ValueBinding not expected value", "Justyna",
(String) binding.getValue(getFacesContext()));
}
public void testStateHolderMedium() throws Exception
{
UIViewRoot root = null;
UIForm form = null;
UIInput input = null;
Object state = null;
getFacesContext().setViewRoot(
root = Util.getViewHandler(getFacesContext()).createView(
getFacesContext(), null));
getFacesContext().getViewRoot().setLocale(Locale.US);
root.getChildren().add(form = new UIForm());
form.getChildren().add(input = new UIInput());
input.setValueBinding("buckaroo", getFacesContext().getApplication()
.createValueBinding("#{TestBean.indexProperties[0]}"));
state = root.processSaveState(getFacesContext());
// synthesize the tree structure
getFacesContext().setViewRoot(
root = Util.getViewHandler(getFacesContext()).createView(
getFacesContext(), null));
getFacesContext().getViewRoot().setLocale(Locale.US);
root.getChildren().add(form = new UIForm());
form.getChildren().add(input = new UIInput());
root.processRestoreState(getFacesContext(), state);
assertEquals("ValueBinding not expected value", "Justyna",
(String) input.getValueBinding("buckaroo").getValue(
getFacesContext()));
}
public void testGetExpressionString() throws Exception
{
ApplicationImpl app = (ApplicationImpl) getFacesContext()
.getApplication();
String ref = null;
ValueBinding vb = null;
ref = "#{NewCustomerFormHandler.minimumAge}";
vb = app.createValueBinding(ref);
assertEquals(ref, vb.getExpressionString());
ref = "minimum age is #{NewCustomerFormHandler.minimumAge}";
vb = app.createValueBinding(ref);
assertEquals(ref, vb.getExpressionString());
}
class StateHolderSaver extends Object implements Serializable
{
protected String className = null;
protected Object savedState = null;
public StateHolderSaver(FacesContext context, Object toSave)
{
className = toSave.getClass().getName();
if (toSave instanceof StateHolder)
{
// do not save an attached object that is marked transient.
if (!((StateHolder) toSave).isTransient())
{
savedState = ((StateHolder) toSave).saveState(context);
}
else
{
className = null;
}
}
}
/**
* @return the restored {@link StateHolder}instance.
*/
public Object restore(FacesContext context)
throws IllegalStateException
{
Object result = null;
Class toRestoreClass = null;
if (className == null)
{
return null;
}
try
{
toRestoreClass = loadClass(className, this);
}
catch (ClassNotFoundException e)
{
throw new IllegalStateException(e.getMessage());
}
if (null != toRestoreClass)
{
try
{
result = toRestoreClass.newInstance();
}
catch (InstantiationException e)
{
throw new IllegalStateException(e.getMessage());
}
catch (IllegalAccessException a)
{
throw new IllegalStateException(a.getMessage());
}
}
if (null != result && null != savedState
&& result instanceof StateHolder)
{
// don't need to check transient, since that was done on
// the saving side.
((StateHolder) result).restoreState(context, savedState);
}
return result;
}
private Class loadClass(String name, Object fallbackClass)
throws ClassNotFoundException
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null)
{
loader = fallbackClass.getClass().getClassLoader();
}
return loader.loadClass(name);
}
}
} // end of class TestValueBindingImpl
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/TestNestedELResolver.java 0000644 0000000 0000000 00000020605 11412443352 023103 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.el;
import java.beans.FeatureDescriptor;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Iterator;
import javax.el.ELContext;
import javax.el.ELResolver;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpSession;
import junit.framework.TestCase;
import com.sun.faces.RIConstants;
import com.sun.faces.application.ApplicationAssociate;
import com.sun.faces.application.ApplicationImpl;
import com.sun.faces.mock.MockELContext;
import com.sun.faces.mock.MockExternalContext;
import com.sun.faces.mock.MockFacesContext;
import com.sun.faces.mock.MockHttpServletRequest;
import com.sun.faces.mock.MockHttpServletResponse;
import com.sun.faces.mock.MockHttpSession;
import com.sun.faces.mock.MockServletContext;
/**
* Tests needs to be run with assertions enabled (-ea:com.sun.faces.el.ChainAwareVariableResolver)
*/
public class TestNestedELResolver extends TestCase {
private static final String UNPREFIXED_VALUE = "unprefixedValue";
private static final String UNPREFIXED_KEY = "unprefixedKey";
private static final String PREFIXED_VALUE = "prefixedValue";
private static final String PREFIX = "test:";
private static final String PREFIXED_KEY = PREFIX + "value";
private ELContext elContext;
public void setUp() throws Exception {
FacesContext facesContext = createStubbedFacesContext();
this.elContext = facesContext.getELContext();
facesContext.getExternalContext().getApplicationMap()
.put(PREFIXED_KEY, PREFIXED_VALUE);
facesContext.getExternalContext().getApplicationMap()
.put(UNPREFIXED_KEY, UNPREFIXED_VALUE);
}
public void testShouldResolveVariableWhenNestedELResolverCallCanNotResolve()
throws Exception {
assertEquals(UNPREFIXED_VALUE,
this.elContext.getELResolver().getValue(this.elContext,
null,
UNPREFIXED_KEY));
}
public void testShouldResolveVariableViaNestedELResolverCall()
throws Exception {
assertEquals(PREFIXED_VALUE,
this.elContext.getELResolver().getValue(this.elContext,
null,
PREFIXED_KEY));
}
///wish I could use FacesTester ;-)
private FacesContext createStubbedFacesContext() throws Exception {
ServletContext context = new MockServletContext();
((MockServletContext) context).addInitParameter("javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER", "true");
HttpSession session = new MockHttpSession(context);
ServletRequest request = new MockHttpServletRequest(session);
ServletResponse response = new MockHttpServletResponse();
ExternalContext externalContect = new MockExternalContext(context,
request,
response);
MockFacesContext mockFacesContext = new MockFacesContext(externalContect);
mockFacesContext.setApplication(new ApplicationImpl());
ApplicationAssociate associate = getApplicationAssociate(
mockFacesContext);
associate
.setELResolversFromFacesConfig(Collections.
*/
public class TestValueExpressionImpl extends ServletFacesTestCase
{
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
protected ValueExpression valueExpression;
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestValueExpressionImpl()
{
super("TestValueExpressionImpl");
}
public TestValueExpressionImpl(String name)
{
super(name);
}
//
// Class methods
//
//
// Methods from TestCase
//
//
// General Methods
//
protected ValueExpression create(String ref) throws Exception
{
return (getFacesContext().getApplication().getExpressionFactory().
createValueExpression(getFacesContext().getELContext(),("#{" + ref + "}"), Object.class));
}
public void populateRequest(WebRequest theRequest)
{
theRequest.addHeader("ELHeader", "ELHeader");
theRequest.addHeader("multiheader", "1");
theRequest.addHeader("multiheader", "2");
theRequest.addParameter("ELParam", "ELParam");
theRequest.addParameter("multiparam", "one");
theRequest.addParameter("multiparam", "two");
theRequest.addCookie("cookie", "monster");
}
public void beginELGet(WebRequest theRequest)
{
populateRequest(theRequest);
}
public void testELGet() throws Exception
{
TestBean testBean = new TestBean();
InnerBean newInner, oldInner = new InnerBean();
testBean.setInner(oldInner);
Object result = null;
ExternalContext extContext = getFacesContext().getExternalContext();
Map myMap = new HashMap();
TestBean myBean = new TestBean();
myBean.setOne("one");
myMap.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
//
// Get tests
//
valueExpression = this.create("myMap.myBean.one");
result = valueExpression.getValue(getFacesContext().getELContext());
assertEquals("one", result);
valueExpression = this.create("myMap[\"myBean\"].one");
result = valueExpression.getValue(getFacesContext().getELContext());
assertTrue("one".equals(result));
valueExpression = this.create("myMap.myBean['one']");
result = valueExpression.getValue(getFacesContext().getELContext());
assertTrue("one".equals(result));
// Simple tests, verify that bracket and dot operators work
valueExpression = this.create("TestBean.inner");
getFacesContext().getExternalContext().getSessionMap().put("TestBean",
testBean);
result = valueExpression.getValue(getFacesContext().getELContext());
assertTrue(result == oldInner);
valueExpression = this.create("TestBean[\"inner\"]");
result = valueExpression.getValue(getFacesContext().getELContext());
assertTrue(result == oldInner);
valueExpression = this.create("TestBean[\"inner\"].customers[1]");
result = valueExpression.getValue(getFacesContext().getELContext());
assertTrue(result instanceof String);
assertTrue(result.equals("Jerry"));
// try out the implicit objects
valueExpression = this.create("sessionScope.TestBean.inner");
result = valueExpression.getValue(getFacesContext().getELContext());
assertTrue(result == oldInner);
valueExpression = this.create("header.ELHeader");
result = valueExpression.getValue(getFacesContext().getELContext());
assertTrue(requestsHaveSameAttributeSet(
(HttpServletRequest) getFacesContext().getExternalContext()
.getRequest(), (HttpServletRequest) request));
assertTrue(request.getHeader("ELHeader").equals("ELHeader"));
assertTrue(result.equals("ELHeader"));
valueExpression = this.create("param.ELParam");
result = valueExpression.getValue(getFacesContext().getELContext());
assertTrue(result.equals("ELParam"));
String multiparam[] = null;
valueExpression = this.create("paramValues.multiparam");
multiparam = (String[]) valueExpression.getValue(getFacesContext().getELContext());
assertTrue(null != multiparam);
assertTrue(2 == multiparam.length);
assertTrue(multiparam[0].equals("one"));
assertTrue(multiparam[1].equals("two"));
valueExpression = this.create("headerValues.multiheader");
String[] multiHeader = (String[]) valueExpression
.getValue(getFacesContext().getELContext());
assertTrue(null != multiHeader);
assertTrue(1 == multiHeader.length);
assertTrue(multiHeader[0].equals("1,2"));
valueExpression = this.create("initParam.testInitParam");
result = valueExpression.getValue(getFacesContext().getELContext());
assertTrue(null != result);
assertTrue(result.equals("testInitParam"));
// PENDING(craigmcc) - Comment out this test because on my platform
// the getRequestCookies() call returns null
/*
* valueExpression.setRef("cookie.cookie"); result =
* valueExpression.getValue(getFacesContext().getELContext()); assertTrue(null != result);
* assertTrue(result instanceof Cookie); assertTrue(((Cookie)
* result).getValue().equals("monster"));
*/
}
public void beginELSet(WebRequest theRequest)
{
populateRequest(theRequest);
}
public void testELSet() throws Exception
{
TestBean testBean = new TestBean();
InnerBean newInner, oldInner = new InnerBean();
testBean.setInner(oldInner);
ValueExpression valueExpression = null;
Object result = null;
ExternalContext extContext = getFacesContext().getExternalContext();
Map myMap = new HashMap();
TestBean myBean = new TestBean();
myMap.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
//
// Set tests
//
valueExpression = this.create("myMap.myBean.one");
valueExpression.setValue(getFacesContext().getELContext(), "one");
Map map = (Map) extContext.getRequestMap().get("myMap");
assertTrue("one".equals(((TestBean) map.get("myBean")).getOne()));
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
// test that we can set null as the value
valueExpression = this.create("myMap.myBean.prop");
valueExpression.setValue(getFacesContext().getELContext(), null);
map = (Map) extContext.getRequestMap().get("myMap");
assertEquals(null, ((TestBean) map.get("myBean")).getOne());
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
valueExpression = this.create("myMap[\"myBean\"].one");
valueExpression.setValue(getFacesContext().getELContext(), "one");
map = (Map) extContext.getRequestMap().get("myMap");
assertTrue("one".equals(((TestBean) map.get("myBean")).getOne()));
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
// test that we can set the property to null
valueExpression = this.create("myMap[\"myBean\"].prop");
valueExpression.setValue(getFacesContext().getELContext(), null);
map = (Map) extContext.getRequestMap().get("myMap");
String msg = "Default Message";
if (((TestBean) map.get("myBean")).getProp() != null)
{
msg = ((TestBean) map.get("myBean")).getProp().getClass().getName();
}
assertEquals(msg, null, ((TestBean) map.get("myBean")).getProp());
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
valueExpression = this.create("myMap.myBean['one']");
valueExpression.setValue(getFacesContext().getELContext(), "one");
map = (Map) extContext.getRequestMap().get("myMap");
assertTrue("one".equals(((TestBean) map.get("myBean")).getOne()));
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
// set the prop to null
valueExpression = this.create("myMap.myBean['prop']");
valueExpression.setValue(getFacesContext().getELContext(), null);
map = (Map) extContext.getRequestMap().get("myMap");
assertEquals(null, ((TestBean) map.get("myBean")).getOne());
myBean = new TestBean();
map.put("myBean", myBean);
extContext.getRequestMap().put("myMap", myMap);
valueExpression = this.create("NonExist");
valueExpression.setValue(getFacesContext().getELContext(), "value");
result = extContext.getRequestMap().get("NonExist");
assertTrue("value".equals(result));
extContext.getRequestMap().remove("NonExist");
extContext.getSessionMap().put("Key", "oldValue");
valueExpression = this.create("Key");
valueExpression.setValue(getFacesContext().getELContext(), "newValue");
result = extContext.getSessionMap().get("Key");
assertTrue("newValue".equals(result));
extContext.getSessionMap().remove("Key");
newInner = new InnerBean();
valueExpression = this.create("TestBean.inner");
valueExpression.setValue(getFacesContext().getELContext(), newInner);
result = valueExpression.getValue(getFacesContext().getELContext());
assertTrue(result == newInner);
assertTrue(oldInner != newInner);
oldInner = newInner;
newInner = new InnerBean();
valueExpression = this.create("TestBean[\"inner\"]");
valueExpression.setValue(getFacesContext().getELContext(), newInner);
result = valueExpression.getValue(getFacesContext().getELContext());
assertTrue(result == newInner);
assertTrue(oldInner != newInner);
String oldCustomer0 = null, oldCustomer1 = null, customer0 = null, customer1 = null;
valueExpression = this.create("TestBean[\"inner\"].customers[0]");
oldCustomer0 = customer0 = (String) valueExpression
.getValue(getFacesContext().getELContext());
valueExpression = this.create("TestBean[\"inner\"].customers[1]");
oldCustomer1 = customer1 = (String) valueExpression
.getValue(getFacesContext().getELContext());
valueExpression = this.create("TestBean[\"inner\"].customers[0]");
valueExpression.setValue(getFacesContext().getELContext(), "Jerry");
valueExpression = this.create("TestBean[\"inner\"].customers[1]");
valueExpression.setValue(getFacesContext().getELContext(), "Mickey");
valueExpression = this.create("TestBean[\"inner\"].customers[0]");
customer0 = (String) valueExpression.getValue(getFacesContext().getELContext());
valueExpression = this.create("TestBean[\"inner\"].customers[1]");
customer1 = (String) valueExpression.getValue(getFacesContext().getELContext());
assertTrue(customer0.equals("Jerry"));
assertTrue(customer1.equals("Mickey"));
valueExpression = this.create("TestBean[\"inner\"].customers[0]");
assertTrue(valueExpression.getValue(getFacesContext().getELContext()) != oldCustomer0);
valueExpression = this.create("TestBean[\"inner\"].customers[1]");
assertTrue(valueExpression.getValue(getFacesContext().getELContext()) != oldCustomer1);
// put in a map to the customers Collection
Inner2Bean inner2 = new Inner2Bean();
assertTrue(null == inner2.getNicknames().get("foo"));
valueExpression = this.create("TestBean[\"inner\"].customers[2]");
valueExpression.setValue(getFacesContext().getELContext(), inner2);
valueExpression = this.create("TestBean[\"inner\"].customers[2]");
assertTrue(valueExpression.getValue(getFacesContext().getELContext()) == inner2);
valueExpression = this
.create("TestBean[\"inner\"].customers[2].nicknames.foo");
valueExpression.setValue(getFacesContext().getELContext(), "bar");
assertTrue(((String) inner2.getNicknames().get("foo")).equals("bar"));
// ensure we can call setValue() successfully if the bean isn't already
// in scope at the time of invocation
Map This is a "dummy" implementation of PageContext whose only
* purpose is to serve the attribute getter/setter API's.
*
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: eburns $
**/
public class PageContextImpl
extends PageContext
{
//-------------------------------------
// Properties
//-------------------------------------
//-------------------------------------
// Member variables
//-------------------------------------
Map mPage = Collections.synchronizedMap (new HashMap ());
Map mRequest = Collections.synchronizedMap (new HashMap ());
Map mSession = Collections.synchronizedMap (new HashMap ());
Map mApp = Collections.synchronizedMap (new HashMap ());
//-------------------------------------
/**
*
* Constructor
**/
public PageContextImpl ()
{
}
//-------------------------------------
// PageContext methods
//-------------------------------------
public void initialize (Servlet servlet,
ServletRequest request,
ServletResponse response,
String errorPageURL,
boolean needSession,
int bufferSize,
boolean autoFlush)
{
}
//-------------------------------------
public void release ()
{
}
//-------------------------------------
public void setAttribute (String name,
Object attribute)
{
mPage.put (name, attribute);
}
//-------------------------------------
public void setAttribute (String name,
Object attribute,
int scope)
{
switch (scope) {
case PAGE_SCOPE:
mPage.put (name, attribute);
break;
case REQUEST_SCOPE:
mRequest.put (name, attribute);
break;
case SESSION_SCOPE:
mSession.put (name, attribute);
break;
case APPLICATION_SCOPE:
mApp.put (name, attribute);
break;
default:
throw new IllegalArgumentException ("Bad scope " + scope);
}
}
//-------------------------------------
public Object getAttribute (String name)
{
return mPage.get (name);
}
//-------------------------------------
public Object getAttribute (String name,
int scope)
{
switch (scope) {
case PAGE_SCOPE:
return mPage.get (name);
case REQUEST_SCOPE:
return mRequest.get (name);
case SESSION_SCOPE:
return mSession.get (name);
case APPLICATION_SCOPE:
return mApp.get (name);
default:
throw new IllegalArgumentException ("Bad scope " + scope);
}
}
//-------------------------------------
public Object findAttribute (String name)
{
if (mPage.containsKey (name)) {
return mPage.get (name);
}
else if (mRequest.containsKey (name)) {
return mRequest.get (name);
}
else if (mSession.containsKey (name)) {
return mSession.get (name);
}
else if (mApp.containsKey (name)) {
return mApp.get (name);
}
else {
return null;
}
}
//-------------------------------------
public void removeAttribute (String name)
{
if (mPage.containsKey (name)) {
mPage.remove (name);
}
else if (mRequest.containsKey (name)) {
mRequest.remove (name);
}
else if (mSession.containsKey (name)) {
mSession.remove (name);
}
else if (mApp.containsKey (name)) {
mApp.remove (name);
}
}
//-------------------------------------
public void removeAttribute (String name,
int scope)
{
switch (scope) {
case PAGE_SCOPE:
mPage.remove (name);
break;
case REQUEST_SCOPE:
mRequest.remove (name);
break;
case SESSION_SCOPE:
mSession.remove (name);
break;
case APPLICATION_SCOPE:
mApp.remove (name);
break;
default:
throw new IllegalArgumentException ("Bad scope " + scope);
}
}
//-------------------------------------
public int getAttributesScope (String name)
{
if (mPage.containsKey (name)) {
return PAGE_SCOPE;
}
else if (mRequest.containsKey (name)) {
return REQUEST_SCOPE;
}
else if (mSession.containsKey (name)) {
return SESSION_SCOPE;
}
else if (mApp.containsKey (name)) {
return APPLICATION_SCOPE;
}
else {
return 0;
}
}
//-------------------------------------
public Enumeration getAttributeNamesInScope (int scope)
{
return null;
}
//-------------------------------------
public JspWriter getOut ()
{
return null;
}
//-------------------------------------
public HttpSession getSession ()
{
return null;
}
//-------------------------------------
public Object getPage ()
{
return null;
}
//-------------------------------------
public ServletRequest getRequest ()
{
return null;
}
//-------------------------------------
public ServletResponse getResponse ()
{
return null;
}
//-------------------------------------
public Exception getException ()
{
return null;
}
//-------------------------------------
public ServletConfig getServletConfig ()
{
return null;
}
//-------------------------------------
public ServletContext getServletContext ()
{
return null;
}
//-------------------------------------
public void forward (String path)
{
}
//-------------------------------------
public void include (String path)
{
}
//-------------------------------------
public void handlePageException (Exception exc)
{
}
//-------------------------------------
public void handlePageException (Throwable exc)
{
}
//-------------------------------------
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/PageContextImpl.jsp2 0000644 0000000 0000000 00000021576 11412443350 023025 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.jsp.PageContext;
import java.util.Enumeration;
import javax.servlet.ServletResponse;
import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.el.ExpressionEvaluator;
import javax.servlet.jsp.el.VariableResolver;
import javax.servlet.http.HttpSession;
import java.util.Collections;
import javax.servlet.ServletContext;
import javax.servlet.ServletConfig;
import javax.servlet.Servlet;
/**
*
* This is a "dummy" implementation of PageContext whose only
* purpose is to serve the attribute getter/setter API's.
*
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: eburns $
**/
public class PageContextImpl
extends PageContext
{
//-------------------------------------
// Properties
//-------------------------------------
//-------------------------------------
// Member variables
//-------------------------------------
Map mPage = Collections.synchronizedMap (new HashMap ());
Map mRequest = Collections.synchronizedMap (new HashMap ());
Map mSession = Collections.synchronizedMap (new HashMap ());
Map mApp = Collections.synchronizedMap (new HashMap ());
//-------------------------------------
/**
*
* Constructor
**/
public PageContextImpl ()
{
}
//-------------------------------------
// PageContext methods
//-------------------------------------
public void initialize (Servlet servlet,
ServletRequest request,
ServletResponse response,
String errorPageURL,
boolean needSession,
int bufferSize,
boolean autoFlush)
{
}
//-------------------------------------
public void release ()
{
}
//-------------------------------------
public void setAttribute (String name,
Object attribute)
{
mPage.put (name, attribute);
}
//-------------------------------------
public void setAttribute (String name,
Object attribute,
int scope)
{
switch (scope) {
case PAGE_SCOPE:
mPage.put (name, attribute);
break;
case REQUEST_SCOPE:
mRequest.put (name, attribute);
break;
case SESSION_SCOPE:
mSession.put (name, attribute);
break;
case APPLICATION_SCOPE:
mApp.put (name, attribute);
break;
default:
throw new IllegalArgumentException ("Bad scope " + scope);
}
}
//-------------------------------------
public Object getAttribute (String name)
{
return mPage.get (name);
}
//-------------------------------------
public Object getAttribute (String name,
int scope)
{
switch (scope) {
case PAGE_SCOPE:
return mPage.get (name);
case REQUEST_SCOPE:
return mRequest.get (name);
case SESSION_SCOPE:
return mSession.get (name);
case APPLICATION_SCOPE:
return mApp.get (name);
default:
throw new IllegalArgumentException ("Bad scope " + scope);
}
}
//-------------------------------------
public Object findAttribute (String name)
{
if (mPage.containsKey (name)) {
return mPage.get (name);
}
else if (mRequest.containsKey (name)) {
return mRequest.get (name);
}
else if (mSession.containsKey (name)) {
return mSession.get (name);
}
else if (mApp.containsKey (name)) {
return mApp.get (name);
}
else {
return null;
}
}
//-------------------------------------
public void removeAttribute (String name)
{
if (mPage.containsKey (name)) {
mPage.remove (name);
}
else if (mRequest.containsKey (name)) {
mRequest.remove (name);
}
else if (mSession.containsKey (name)) {
mSession.remove (name);
}
else if (mApp.containsKey (name)) {
mApp.remove (name);
}
}
//-------------------------------------
public void removeAttribute (String name,
int scope)
{
switch (scope) {
case PAGE_SCOPE:
mPage.remove (name);
break;
case REQUEST_SCOPE:
mRequest.remove (name);
break;
case SESSION_SCOPE:
mSession.remove (name);
break;
case APPLICATION_SCOPE:
mApp.remove (name);
break;
default:
throw new IllegalArgumentException ("Bad scope " + scope);
}
}
//-------------------------------------
public int getAttributesScope (String name)
{
if (mPage.containsKey (name)) {
return PAGE_SCOPE;
}
else if (mRequest.containsKey (name)) {
return REQUEST_SCOPE;
}
else if (mSession.containsKey (name)) {
return SESSION_SCOPE;
}
else if (mApp.containsKey (name)) {
return APPLICATION_SCOPE;
}
else {
return 0;
}
}
//-------------------------------------
public Enumeration getAttributeNamesInScope (int scope)
{
return null;
}
//-------------------------------------
public JspWriter getOut ()
{
return null;
}
//-------------------------------------
public HttpSession getSession ()
{
return null;
}
//-------------------------------------
public Object getPage ()
{
return null;
}
//-------------------------------------
public ServletRequest getRequest ()
{
return null;
}
//-------------------------------------
public ServletResponse getResponse ()
{
return null;
}
//-------------------------------------
public Exception getException ()
{
return null;
}
//-------------------------------------
public ServletConfig getServletConfig ()
{
return null;
}
//-------------------------------------
public ServletContext getServletContext ()
{
return null;
}
//-------------------------------------
public void forward (String path)
{
}
//-------------------------------------
public void include (String path)
{
}
//-------------------------------------
public void handlePageException (Exception exc)
{
}
//-------------------------------------
public void handlePageException (Throwable exc)
{
}
//-------------------------------------
// Since JSP 2.0
public void include(java.lang.String relativeUrlPath, boolean flush) {}
public ExpressionEvaluator getExpressionEvaluator() { return null; }
public VariableResolver getVariableResolver() { return null; }
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/Bean2.java 0000644 0000000 0000000 00000007031 11412443350 020742 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl;
/**
* This is a test bean that holds a single String
*
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: ofung $
*/
public class Bean2 {
//-------------------------------------
// Properties
//-------------------------------------
// property value
String mValue;
public String getValue() {
return mValue;
}
public void setValue(String pValue) {
mValue = pValue;
}
//-------------------------------------
// Member variables
//-------------------------------------
//-------------------------------------
/**
* Constructor
*/
public Bean2(String pValue) {
mValue = pValue;
}
//-------------------------------------
public String toString() {
return ("Bean2[" + mValue + "]");
}
//-------------------------------------
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/Bean2Editor.java 0000644 0000000 0000000 00000006244 11412443350 022116 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl;
import java.beans.PropertyEditorSupport;
/**
* PropertyEditor for parsing Bean2
*
* @author Nathan Abramson - Art Technology Group
*/
public class Bean2Editor
extends PropertyEditorSupport {
//-------------------------------------
public void setAsText(String pText)
throws IllegalArgumentException {
if ("badvalue".equals(pText)) {
throw new IllegalArgumentException("Bad value " + pText);
} else {
setValue(new Bean2(pText));
}
}
//-------------------------------------
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/Bean1.java 0000644 0000000 0000000 00000021457 11412443350 020751 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl;
import java.util.List;
import java.util.Map;
/**
* This is a test bean with a set of properties
*
* @author Nathan Abramson - Art Technology Group
*/
public class Bean1 {
//-------------------------------------
// Properties
//-------------------------------------
// property boolean1
boolean mBoolean1;
public boolean getBoolean1() {
return mBoolean1;
}
public void setBoolean1(boolean pBoolean1) {
mBoolean1 = pBoolean1;
}
//-------------------------------------
// property byte1
byte mByte1;
public byte getByte1() {
return mByte1;
}
public void setByte1(byte pByte1) {
mByte1 = pByte1;
}
//-------------------------------------
// property char1
char mChar1;
public char getChar1() {
return mChar1;
}
public void setChar1(char pChar1) {
mChar1 = pChar1;
}
//-------------------------------------
// property short1
short mShort1;
public short getShort1() {
return mShort1;
}
public void setShort1(short pShort1) {
mShort1 = pShort1;
}
//-------------------------------------
// property int1
int mInt1;
public int getInt1() {
return mInt1;
}
public void setInt1(int pInt1) {
mInt1 = pInt1;
}
//-------------------------------------
// property long1
long mLong1;
public long getLong1() {
return mLong1;
}
public void setLong1(long pLong1) {
mLong1 = pLong1;
}
//-------------------------------------
// property float1
float mFloat1;
public float getFloat1() {
return mFloat1;
}
public void setFloat1(float pFloat1) {
mFloat1 = pFloat1;
}
//-------------------------------------
// property double1
double mDouble1;
public double getDouble1() {
return mDouble1;
}
public void setDouble1(double pDouble1) {
mDouble1 = pDouble1;
}
//-------------------------------------
// property boolean2
Boolean mBoolean2;
public Boolean getBoolean2() {
return mBoolean2;
}
public void setBoolean2(Boolean pBoolean2) {
mBoolean2 = pBoolean2;
}
//-------------------------------------
// property byte2
Byte mByte2;
public Byte getByte2() {
return mByte2;
}
public void setByte2(Byte pByte2) {
mByte2 = pByte2;
}
//-------------------------------------
// property char2
Character mChar2;
public Character getChar2() {
return mChar2;
}
public void setChar2(Character pChar2) {
mChar2 = pChar2;
}
//-------------------------------------
// property short2
Short mShort2;
public Short getShort2() {
return mShort2;
}
public void setShort2(Short pShort2) {
mShort2 = pShort2;
}
//-------------------------------------
// property int2
Integer mInt2;
public Integer getInt2() {
return mInt2;
}
public void setInt2(Integer pInt2) {
mInt2 = pInt2;
}
//-------------------------------------
// property long2
Long mLong2;
public Long getLong2() {
return mLong2;
}
public void setLong2(Long pLong2) {
mLong2 = pLong2;
}
//-------------------------------------
// property float2
Float mFloat2;
public Float getFloat2() {
return mFloat2;
}
public void setFloat2(Float pFloat2) {
mFloat2 = pFloat2;
}
//-------------------------------------
// property double2
Double mDouble2;
public Double getDouble2() {
return mDouble2;
}
public void setDouble2(Double pDouble2) {
mDouble2 = pDouble2;
}
//-------------------------------------
// property string1
String mString1;
public String getString1() {
return mString1;
}
public void setString1(String pString1) {
mString1 = pString1;
}
//-------------------------------------
// property string2
String mString2;
public String getString2() {
return mString2;
}
public void setString2(String pString2) {
mString2 = pString2;
}
//-------------------------------------
// property bean1
Bean1 mBean1;
public Bean1 getBean1() {
return mBean1;
}
public void setBean1(Bean1 pBean1) {
mBean1 = pBean1;
}
//-------------------------------------
// property bean2
Bean1 mBean2;
public Bean1 getBean2() {
return mBean2;
}
public void setBean2(Bean1 pBean2) {
mBean2 = pBean2;
}
//-------------------------------------
// property noGetter
String mNoGetter;
public void setNoGetter(String pNoGetter) {
mNoGetter = pNoGetter;
}
//-------------------------------------
// property errorInGetter
String mErrorInGetter;
public String getErrorInGetter() {
throw new NullPointerException("Error!");
}
//-------------------------------------
// property stringArray1
String[] mStringArray1;
public String[] getStringArray1() {
return mStringArray1;
}
public void setStringArray1(String[] pStringArray1) {
mStringArray1 = pStringArray1;
}
//-------------------------------------
// property list1
List mList1;
public List getList1() {
return mList1;
}
public void setList1(List pList1) {
mList1 = pList1;
}
//-------------------------------------
// property map1
Map mMap1;
public Map getMap1() {
return mMap1;
}
public void setMap1(Map pMap1) {
mMap1 = pMap1;
}
//-------------------------------------
// property indexed1
public String getIndexed1(int pIndex) {
return mStringArray1[pIndex];
}
//-------------------------------------
// Member variables
//-------------------------------------
//-------------------------------------
/**
* Constructor
*/
public Bean1() {
}
//-------------------------------------
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/beans/ 0000755 0000000 0000000 00000000000 11412443350 020237 5 ustar mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/beans/PublicBean1.java 0000644 0000000 0000000 00000005476 11412443350 023203 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl.beans;
/**
* A publicly-accessible bean
*
* @author Nathan Abramson - Art Technology Group
*/
public class PublicBean1 {
public Object getValue() {
return "got the value";
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/beans/PrivateBean2b.java 0000644 0000000 0000000 00000005555 11412443350 023540 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl.beans;
/**
* A private implementation of a public interface
*
* @author Nathan Abramson - Art Technology Group
*/
class PrivateBean2b
implements PublicInterface2 {
public Object getValue() {
return "got the value";
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/beans/PublicBean1b.java 0000644 0000000 0000000 00000005615 11412443350 023340 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl.beans;
/**
* A public bean subclassing a private bean subclassing a public
* bean
*
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181181 $$DateTime: 2001/06/26 09:55:09 $$Author: ofung $
*/
public class PublicBean1b
extends PrivateBean1a {
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/beans/PublicBean2a.java 0000644 0000000 0000000 00000005577 11412443350 023347 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl.beans;
/**
* A publicly-accessible implementation of a public interface
*
* @author Nathan Abramson - Art Technology Group
*/
public class PublicBean2a
implements PublicInterface2 {
public Object getValue() {
return "got the value";
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/beans/PrivateBean2c.java 0000644 0000000 0000000 00000005473 11412443350 023540 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl.beans;
/**
* A private subclass of a public class impelementing a public
* interface
*
* @author Nathan Abramson - Art Technology Group
*/
class PrivateBean2c
extends PublicBean2a {
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/beans/PrivateBean1a.java 0000644 0000000 0000000 00000005551 11412443350 023532 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl.beans;
/**
* A private bean subclassing a public bean
*
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181181 $$DateTime: 2001/06/26 09:55:09 $$Author: ofung $
*/
class PrivateBean1a
extends PublicBean1 {
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/beans/PrivateBean2d.java 0000644 0000000 0000000 00000005613 11412443350 023535 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl.beans;
/**
* A private subclass of a private class impelementing a public
* interface
*
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181181 $$DateTime: 2001/06/26 09:55:09 $$Author: ofung $
*/
class PrivateBean2d
extends PrivateBean2b {
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/beans/Factory.java 0000644 0000000 0000000 00000006730 11412443350 022517 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl.beans;
/**
* A factory for generating the various beans
*
* @author Nathan Abramson - Art Technology Group
* @version $Change: 181181 $$DateTime: 2001/06/26 09:55:09 $$Author: ofung $
*/
public class Factory {
public static PublicBean1 createBean1() {
return new PublicBean1();
}
public static PublicBean1 createBean2() {
return new PrivateBean1a();
}
public static PublicBean1 createBean3() {
return new PublicBean1b();
}
public static PublicInterface2 createBean4() {
return new PublicBean2a();
}
public static PublicInterface2 createBean5() {
return new PrivateBean2b();
}
public static PublicInterface2 createBean6() {
return new PrivateBean2c();
}
public static PublicInterface2 createBean7() {
return new PrivateBean2d();
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/beans/PublicInterface2.java 0000644 0000000 0000000 00000005445 11412443350 024233 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl.beans;
/**
* A publicly-accessible interface
*
* @author Nathan Abramson - Art Technology Group
*/
public interface PublicInterface2 {
public Object getValue();
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/impl/TestELImpl.java 0000644 0000000 0000000 00000100401 11412443350 021770 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.sun.faces.el.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.faces.context.ExternalContext;
import javax.faces.el.ValueBinding;
import com.sun.faces.el.impl.beans.Factory;
import com.sun.faces.cactus.ServletFacesTestCase;
/**
* @author jhook
*/
public class TestELImpl extends ServletFacesTestCase
{
/**
*
*/
public TestELImpl()
{
super();
}
/**
* @param name
*/
public TestELImpl(String name)
{
super(name);
}
protected Object evaluate(String ref) throws Exception
{
ValueBinding vb = this.getFacesContext().getApplication().createValueBinding(ref);
return vb.getValue(this.getFacesContext());
}
public void testELEvaluation() throws Exception
{
/* setup our test date */
Bean1 b = this.createBean1();
getExternalContext().getRequestMap().put("bean1a", b);
getExternalContext().getSessionMap().put("val1c", "session-scoped1");
getExternalContext().getRequestMap().put("val1b", "request-scoped1");
getExternalContext().getApplicationMap().put("val1d", "app-scoped1");
Map m = new HashMap();
m.put("emptyArray", new Object[0]);
m.put("nonemptyArray", new Object[]
{ "abc" });
m.put("emptyList", new ArrayList());
{
List l = new ArrayList();
l.add("hello");
m.put("nonemptyList", l);
}
m.put("emptyMap", new HashMap());
{
Map m2 = new HashMap();
m2.put("a", "a");
m.put("nonemptyMap", m2);
}
m.put("emptySet", new HashSet());
{
Set s = new HashSet();
s.add("hello");
m.put("nonemptySet", s);
}
getExternalContext().getRequestMap().put("emptyTests", m);
getExternalContext().getRequestMap().put("pbean1",
Factory.createBean1());
getExternalContext().getRequestMap().put("pbean2",
Factory.createBean2());
getExternalContext().getRequestMap().put("pbean3",
Factory.createBean3());
getExternalContext().getRequestMap().put("pbean4",
Factory.createBean4());
getExternalContext().getRequestMap().put("pbean5",
Factory.createBean5());
getExternalContext().getRequestMap().put("pbean6",
Factory.createBean6());
getExternalContext().getRequestMap().put("pbean7",
Factory.createBean7());
/* testing mixture of strings and expressions */
evaluateTest("abc", "abc");
evaluateTest("#{ 3}", new Long(3));
evaluateTestFailure("a#{");
evaluateTest("a#{ 5 }", "a5");
evaluateTest("#{ 3 }b", "3b");
evaluateTest("#{ 1 }#{ 2 }", "12");
evaluateTest("abc #{ 1} #{ 2} def", "abc 1 2 def");
/* testing values that end with or contain "#" */
evaluateTest("#", "#");
evaluateTest("\\#", "#");
evaluateTest("# ", "# ");
evaluateTest("test#", "test#");
evaluateTest("#test", "#test");
evaluateTest("test#test", "test#test");
evaluateTest("test###", "test###");
evaluateTest("test###{ 34 }", "test##34");
evaluateTest("test###{ 34 }##", "test##34##");
evaluateTest("test##{ 34 }", "test#34");
evaluateTest("##{ 34 }", "#34");
evaluateTest("##", "##");
evaluateTest("test##", "test##");
evaluateTest("test##test", "test##test");
evaluateTest("#{ 34 }##{ 34 }", "34#34");
/* basic literals */
evaluateTest("#{1}", new Long(1));
evaluateTest("#{-12}", new Long(-12));
evaluateTest("#{true}", Boolean.TRUE);
evaluateTest("#{false}", Boolean.FALSE);
evaluateTest("#{null}", null);
evaluateTest("#{4.2}", new Double(4.2));
evaluateTest("#{-21.3}", new Double(-21.3));
evaluateTest("#{4.}", new Double(4.0));
evaluateTest("#{.21}", new Double(0.21));
evaluateTest("#{3e-1}", new Double(0.3));
evaluateTest("#{.2222222222}", new Double(0.2222222222));
/* basic relationals between literals */
evaluateTest("#{1 < 2}", Boolean.TRUE);
evaluateTest("#{1 > 2}", Boolean.FALSE);
evaluateTest("#{1 >= 2}", Boolean.FALSE);
evaluateTest("#{1 <= 2}", Boolean.TRUE);
evaluateTest("#{1 == 2}", Boolean.FALSE);
evaluateTest("#{1 != 2}", Boolean.TRUE);
evaluateTest("#{3 >= 3}", Boolean.TRUE);
evaluateTest("#{3 <= 3}", Boolean.TRUE);
evaluateTest("#{3 == 3}", Boolean.TRUE);
evaluateTest("#{3 < 3}", Boolean.FALSE);
evaluateTest("#{3 > 3}", Boolean.FALSE);
evaluateTest("#{3 != 3}", Boolean.FALSE);
// PENDING (visvan) check with Kinman/Jacob
/* relationals between booleans
evaluateTestFailure("#{false < true}");
evaluateTestFailure("#{false > true}");
evaluateTest("#{true >= true}", Boolean.TRUE);
evaluateTest("#{true <= true}", Boolean.TRUE);
evaluateTest("#{true == true}", Boolean.TRUE);
evaluateTest("#{true != true}", Boolean.FALSE); */
/* looking up objects in scopes */
evaluateTest("#{requestScope.val1b}", "request-scoped1");
evaluateTest("#{sessionScope.val1b}", null);
evaluateTest("#{applicationScope.val1b}", null);
evaluateTest("#{val1b}", "request-scoped1");
evaluateTest("#{requestScope.val1c}", null);
evaluateTest("#{sessionScope.val1c}", "session-scoped1");
evaluateTest("#{applicationScope.val1c}", null);
evaluateTest("#{val1c}", "session-scoped1");
evaluateTest("#{requestScope.val1d}", null);
evaluateTest("#{sessionScope.val1d}", null);
evaluateTest("#{applicationScope.val1d}", "app-scoped1");
evaluateTest("#{val1d}", "app-scoped1");
/* accessing properties */
evaluateTest("#{bean1a.int1}", new Integer(b.getInt1()));
evaluateTest("#{bean1a.boolean1}", Boolean.valueOf(b.getBoolean1()));
evaluateTest("#{bean1a.string1}", b.getString1());
evaluateTest("#{bean1a.bean1.int2}", b.getBean1().getInt2());
evaluateTest("#{bean1a.bean1.bean2.string2}", b.getBean1().getBean2()
.getString2());
evaluateTest("#{bean1a.byte1}", new Byte(b.getByte1()));
evaluateTest("#{bean1a.char1}", new Character(b.getChar1()));
evaluateTest("#{bean1a.short1}", new Short(b.getShort1()));
evaluateTest("#{bean1a.long1}", new Long(b.getLong1()));
evaluateTest("#{bean1a.float1}", new Float(b.getFloat1()));
evaluateTest("#{bean1a.double1}", new Double(b.getDouble1()));
/* test the entire relational comparison type promotion matrix */
evaluateTest("#{bean1a.byte1 < bean1a.byte1}", Boolean.FALSE);
evaluateTest("#{bean1a.byte1 < bean1a.char1}", Boolean.TRUE);
evaluateTest("#{bean1a.byte1 < bean1a.short1}", Boolean.TRUE);
evaluateTest("#{bean1a.byte1 < bean1a.int1}", Boolean.FALSE);
evaluateTest("#{bean1a.byte1 < bean1a.long1}", Boolean.TRUE);
evaluateTest("#{bean1a.byte1 < bean1a.float1}", Boolean.TRUE);
evaluateTest("#{bean1a.byte1 < bean1a.double1}", Boolean.TRUE);
evaluateTest("#{bean1a.char1 < bean1a.byte1}", Boolean.FALSE);
evaluateTest("#{bean1a.char1 < bean1a.char1}", Boolean.FALSE);
evaluateTest("#{bean1a.char1 < bean1a.short1}", Boolean.FALSE);
evaluateTest("#{bean1a.char1 < bean1a.int1}", Boolean.FALSE);
evaluateTest("#{bean1a.char1 < bean1a.long1}", Boolean.FALSE);
evaluateTest("#{bean1a.char1 < bean1a.float1}", Boolean.FALSE);
evaluateTest("#{bean1a.char1 < bean1a.double1}", Boolean.FALSE);
evaluateTest("#{bean1a.short1 < bean1a.byte1}", Boolean.FALSE);
evaluateTest("#{bean1a.short1 < bean1a.char1}", Boolean.FALSE);
evaluateTest("#{bean1a.short1 < bean1a.short1}", Boolean.FALSE);
evaluateTest("#{bean1a.short1 < bean1a.int1}", Boolean.FALSE);
evaluateTest("#{bean1a.short1 < bean1a.float1}", Boolean.FALSE);
evaluateTest("#{bean1a.short1 < bean1a.long1}", Boolean.FALSE);
evaluateTest("#{bean1a.short1 < bean1a.double1}", Boolean.FALSE);
evaluateTest("#{bean1a.int1 < bean1a.byte1}", Boolean.TRUE);
evaluateTest("#{bean1a.int1 < bean1a.char1}", Boolean.TRUE);
evaluateTest("#{bean1a.int1 < bean1a.short1}", Boolean.TRUE);
evaluateTest("#{bean1a.int1 < bean1a.int1}", Boolean.FALSE);
evaluateTest("#{bean1a.int1 < bean1a.long1}", Boolean.TRUE);
evaluateTest("#{bean1a.int1 < bean1a.float1}", Boolean.TRUE);
evaluateTest("#{bean1a.int1 < bean1a.double1}", Boolean.TRUE);
evaluateTest("#{bean1a.long1 < bean1a.byte1}", Boolean.FALSE);
evaluateTest("#{bean1a.long1 < bean1a.char1}", Boolean.FALSE);
evaluateTest("#{bean1a.long1 < bean1a.short1}", Boolean.FALSE);
evaluateTest("#{bean1a.long1 < bean1a.int1}", Boolean.FALSE);
evaluateTest("#{bean1a.long1 < bean1a.long1}", Boolean.FALSE);
evaluateTest("#{bean1a.long1 < bean1a.float1}", Boolean.FALSE);
evaluateTest("#{bean1a.long1 < bean1a.double1}", Boolean.FALSE);
evaluateTest("#{bean1a.float1 < bean1a.byte1}", Boolean.FALSE);
evaluateTest("#{bean1a.float1 < bean1a.char1}", Boolean.TRUE);
evaluateTest("#{bean1a.float1 < bean1a.short1}", Boolean.TRUE);
evaluateTest("#{bean1a.float1 < bean1a.int1}", Boolean.FALSE);
evaluateTest("#{bean1a.float1 < bean1a.long1}", Boolean.TRUE);
evaluateTest("#{bean1a.float1 < bean1a.float1}", Boolean.FALSE);
evaluateTest("#{bean1a.float1 < bean1a.double1}", Boolean.TRUE);
evaluateTest("#{bean1a.double1 < bean1a.byte1}", Boolean.FALSE);
evaluateTest("#{bean1a.double1 < bean1a.char1}", Boolean.TRUE);
evaluateTest("#{bean1a.double1 < bean1a.short1}", Boolean.TRUE);
evaluateTest("#{bean1a.double1 < bean1a.int1}", Boolean.FALSE);
evaluateTest("#{bean1a.double1 < bean1a.long1}", Boolean.TRUE);
evaluateTest("#{bean1a.double1 < bean1a.float1}", Boolean.FALSE);
evaluateTest("#{bean1a.double1 < bean1a.double1}", Boolean.FALSE);
/* test other relational comparison rules */
evaluateTest("#{null == null}", Boolean.TRUE);
evaluateTest("#{noSuchAttribute == noSuchAttribute}", Boolean.TRUE);
evaluateTest("#{noSuchAttribute == null}", Boolean.TRUE);
evaluateTest("#{null == noSuchAttribute}", Boolean.TRUE);
evaluateTest("#{bean1a == null}", Boolean.FALSE);
evaluateTest("#{null == bean1a}", Boolean.FALSE);
evaluateTest("#{bean1a == bean1a}", Boolean.TRUE);
// JSF1.2 BI: This test used to fail with JSF 1.1 EL. With unified EL
// the first portion of the expression is coerced to a string, so
// the expression evaluates to true.
evaluateTest("#{bean1a > \"hello\"}", Boolean.FALSE);
evaluateTestFailure("#{bean1a.bean1 < 14}");
evaluateTest("#{bean1a.bean1 == \"hello\"}", Boolean.FALSE);
/* test String comparisons */
evaluateTest("#{bean1a.string1 == \"hello\"}", Boolean.TRUE);
evaluateTest("#{bean1a.string1 != \"hello\"}", Boolean.FALSE);
evaluateTest("#{bean1a.string1 == \"goodbye\"}", Boolean.FALSE);
evaluateTest("#{bean1a.string1 != \"goodbye\"}", Boolean.TRUE);
evaluateTest("#{bean1a.string1 > \"goodbye\"}", Boolean.TRUE);
evaluateTest("#{\"hello\" == bean1a.string1}", Boolean.TRUE);
evaluateTest("#{\"goodbye\" > bean1a.string1}", Boolean.FALSE);
/* test errors in property traversal */
evaluateTest("#{noSuchAttribute.abc}", null);
evaluateTest("#{bean1a.bean2.byte1}", null);
evaluateTestFailure("#{bean1a.noProperty}");
evaluateTestFailure("#{bean1a.noGetter}");
evaluateTestFailure("#{bean1a.errorInGetter}");
evaluateTest("#{bean1a.bean2.string2}", null);
/* test accessing public properties from private classes */
evaluateTest("#{pbean1.value}", "got the value");
evaluateTest("#{pbean2.value}", "got the value");
evaluateTest("#{pbean3.value}", "got the value");
evaluateTest("#{pbean4.value}", "got the value");
evaluateTest("#{pbean5.value}", "got the value");
evaluateTest("#{pbean6.value}", "got the value");
evaluateTest("#{pbean7.value}", "got the value");
/* test reserved words as identifiers */
evaluateTestFailure("#{and}");
evaluateTestFailure("#{or}");
evaluateTestFailure("#{not}");
evaluateTestFailure("#{eq}");
evaluateTestFailure("#{ne}");
evaluateTestFailure("#{lt}");
evaluateTestFailure("#{gt}");
evaluateTestFailure("#{le}");
evaluateTestFailure("#{ge}");
evaluateTest("#{true}", Boolean.TRUE);
evaluateTest("#{false}", Boolean.FALSE);
evaluateTest("#{null}", null);
/* test reserved words as property names */
evaluateTestFailure("#{bean1a.and}");
evaluateTestFailure("#{bean1a.or}");
evaluateTestFailure("#{bean1a.not}");
evaluateTestFailure("#{bean1a.eq}");
evaluateTestFailure("#{bean1a.ne}");
evaluateTestFailure("#{bean1a.lt}");
evaluateTestFailure("#{bean1a.gt}");
evaluateTestFailure("#{bean1a.le}");
evaluateTestFailure("#{bean1a.ge}");
evaluateTestFailure("#{bean1a.instanceof}");
evaluateTestFailure("#{bean1a.page}");
evaluateTestFailure("#{bean1a.request}");
evaluateTestFailure("#{bean1a.session}");
evaluateTestFailure("#{bean1a.application}");
evaluateTestFailure("#{bean1a.true}");
evaluateTestFailure("#{bean1a.false}");
evaluateTestFailure("#{bean1a.null}");
/* test arithmetic */
evaluateTest("#{3+5}", new Long(8));
evaluateTest("#{3-5}", new Long(-2));
evaluateTest("#{3/5}", new Double(0.6));
evaluateTest("#{3*5}", new Long(15));
evaluateTest("#{3*5.0}", new Double(15.0));
evaluateTest("#{3.0*5}", new Double(15.0));
evaluateTest("#{3.0*5.0}", new Double(15.0));
evaluateTest("#{225 % 17}", new Long(4));
evaluateTest("#{ 1 + 2 + 3 * 5 + 6}", new Long(24));
evaluateTest("#{ 1 + (2 + 3) * 5 + 6}", new Long(32));
/* test logical operators */
evaluateTest("#{ true}", Boolean.TRUE);
evaluateTest("#{ not true}", Boolean.FALSE);
evaluateTest("#{ not false}", Boolean.TRUE);
evaluateTest("#{ not not true}", Boolean.TRUE);
evaluateTest("#{ not not false}", Boolean.FALSE);
evaluateTest("#{ true and false}", Boolean.FALSE);
evaluateTest("#{ true and true}", Boolean.TRUE);
evaluateTest("#{ false and true}", Boolean.FALSE);
evaluateTest("#{ false and false}", Boolean.FALSE);
evaluateTest("#{ true or false}", Boolean.TRUE);
evaluateTest("#{ true or true}", Boolean.TRUE);
evaluateTest("#{ false or true}", Boolean.TRUE);
evaluateTest("#{ false or false}", Boolean.FALSE);
evaluateTest("#{ false or false or false or true and false}",
Boolean.FALSE);
evaluateTest("#{ false or false or false or true and false or true}",
Boolean.TRUE);
/* test indexed access operator */
evaluateTest("#{ bean1a[\"double1\"] }", new Double(b.getDouble1()));
evaluateTest("#{ bean1a[\"double1\"].class }", Double.class);
evaluateTest("#{ bean1a.stringArray1[-1]}", null);
evaluateTest("#{ bean1a.stringArray1[0]}", b.getStringArray1()[0]);
evaluateTest("#{ bean1a.stringArray1[1]}", b.getStringArray1()[1]);
evaluateTest("#{ bean1a.stringArray1[2]}", b.getStringArray1()[2]);
evaluateTest("#{ bean1a.stringArray1[3]}", b.getStringArray1()[3]);
evaluateTest("#{ bean1a.stringArray1[4]}", null);
/* Test as list accessor */
evaluateTest("#{ bean1a.list1 [0] }", b.getList1().get(0));
evaluateTest("#{ bean1a.list1 [1] }", b.getList1().get(1));
evaluateTest("#{ bean1a.list1 [2][2] }", "string3");
/* Test as indexed property accessor */
evaluateTestFailure("#{ bean1a.indexed1[-1]}");
evaluateTestFailure("#{ bean1a.indexed1[0]}");
evaluateTestFailure("#{ bean1a.indexed1[1]}");
evaluateTestFailure("#{ bean1a.indexed1[2]}");
evaluateTestFailure("#{ bean1a.indexed1[3]}");
evaluateTestFailure("#{ bean1a.indexed1[4]}");
/* Test as map accessor */
evaluateTest("#{ bean1a.map1.noKey }", null);
evaluateTest("#{ bean1a.map1.key1 }", b.getMap1().get("key1"));
evaluateTest("#{ bean1a.map1 [\"key1\"] }", b.getMap1().get("key1"));
evaluateTest("#{ bean1a.map1 [14] }", "value3");
evaluateTest("#{ bean1a.map1 [2 * 7] }", "value3");
evaluateTest("#{ bean1a.map1.recurse.list1[0] }", new Integer(14));
/* Test UIComponent as bean
evaluateTest("#{view.rendered}", Boolean.TRUE);
evaluateTest("#{view.attributes.rendered}", Boolean.TRUE);
evaluateTest("#{view.children[0].value}", "inputValue");
evaluateTest("#{view.children[0].rendered}", Boolean.TRUE);
*/
/* test String concatenation */
evaluateTestFailure("#{ \"a\" + \"bcd\" }");
evaluateTestFailure("#{ \"a\" + (4*3) }");
evaluateTestFailure("#{ bean1a.map1 [\"key\" + (5-4)] }");
/* test String comparisons */
evaluateTest("#{ \"30\" < \"4\" }", Boolean.TRUE);
evaluateTest("#{ 30 < \"4\" }", Boolean.FALSE);
evaluateTest("#{ 30 > \"4\" }", Boolean.TRUE);
evaluateTest("#{ \"0004\" == \"4\" }", Boolean.FALSE);
/* test relational comparison with alternate symbols */
evaluateTest("#{ 4 eq 3}", Boolean.FALSE);
evaluateTest("#{ 4 ne 3}", Boolean.TRUE);
evaluateTest("#{ 4 eq 4}", Boolean.TRUE);
evaluateTest("#{ 4 ne 4}", Boolean.FALSE);
evaluateTest("#{ 4 lt 3}", Boolean.FALSE);
evaluateTest("#{ 4 gt 3}", Boolean.TRUE);
evaluateTest("#{ 4 le 3}", Boolean.FALSE);
evaluateTest("#{ 4 ge 3}", Boolean.TRUE);
evaluateTest("#{ 4 le 4}", Boolean.TRUE);
evaluateTest("#{ 4 ge 4}", Boolean.TRUE);
/* test expressions on the left side of a value suffix */
evaluateTest("#{(3).class}", Long.class);
evaluateTest("#{(bean1a.map1)[\"key1\"]}", "value1");
/* test String/boolean logical operators */
evaluateTest("#{'true' and false}", Boolean.FALSE);
evaluateTest("#{'true' or true}", Boolean.TRUE);
evaluateTest("#{false and 'true'}", Boolean.FALSE);
evaluateTest("#{false or 'true'}", Boolean.TRUE);
/* test empty operator */
evaluateTest("#{ empty \"A\"}", Boolean.FALSE);
evaluateTest("#{ empty \"\" }", Boolean.TRUE);
evaluateTest("#{ empty null }", Boolean.TRUE);
evaluateTest("#{ empty false}", Boolean.FALSE);
evaluateTest("#{ empty 0}", Boolean.FALSE);
evaluateTest("#{ not empty 0}", Boolean.TRUE);
evaluateTest("#{ not empty empty 0}", Boolean.TRUE);
evaluateTest("#{ empty emptyTests.emptyArray }", Boolean.TRUE);
evaluateTest("#{ empty emptyTests.nonemptyArray }", Boolean.FALSE);
evaluateTest("#{ empty emptyTests.emptyList }", Boolean.TRUE);
evaluateTest("#{ empty emptyTests.nonemptyList }", Boolean.FALSE);
evaluateTest("#{ empty emptyTests.emptyMap }", Boolean.TRUE);
evaluateTest("#{ empty emptyTests.nonemptyMap }", Boolean.FALSE);
evaluateTest("#{ empty emptyTests.emptySet }", Boolean.TRUE);
evaluateTest("#{ empty emptyTests.nonemptySet }", Boolean.FALSE);
/* test String arithmetic */
evaluateTest("#{ \"6\" / \"3\" }", new Double(2.0));
evaluateTest("#{ 3 + \"4\" }", new Long(7));
evaluateTest("#{ \"4\" + 3 }", new Long(7));
evaluateTest("#{ 3 + \"4.5\" }", new Double(7.5));
evaluateTest("#{ \"4.5\" + 3 }", new Double(7.5));
evaluateTest("#{ 3.0 + 6.0}", new Double(9.0));
evaluateTest("#{ 31121.0 * 61553.0 }", new Double(1.915590913E9));
evaluateTest("#{ 31121 * 61553 }", new Long(1915590913));
evaluateTest("#{ 65536 * 65536 * 65536 * 32759 }", new Long("9220838762064379904"));
evaluateTest("#{ 9220838762064379904.0 - 9220838762064379900.0 }", new Double(0.0));
evaluateTest("#{ 9220838762064379904 - 9220838762064379900 }", new Long(4));
/* test relational operators involving null */
evaluateTest("#{ null == null }", Boolean.TRUE);
evaluateTest("#{ null != null }", Boolean.FALSE);
evaluateTest("#{ null > null }", Boolean.FALSE);
evaluateTest("#{ null < null }", Boolean.FALSE);
evaluateTest("#{ null >= null }", Boolean.TRUE);
evaluateTest("#{ null <= null }", Boolean.TRUE);
evaluateTest("#{ null == 3 }", Boolean.FALSE);
evaluateTest("#{ null != 3 }", Boolean.TRUE);
evaluateTest("#{ null > 3 }", Boolean.FALSE);
evaluateTest("#{ null < 3 }", Boolean.FALSE);
evaluateTest("#{ null >= 3 }", Boolean.FALSE);
evaluateTest("#{ null <= 3 }", Boolean.FALSE);
evaluateTest("#{ 3 == null }", Boolean.FALSE);
evaluateTest("#{ 3 != null }", Boolean.TRUE);
evaluateTest("#{ 3 > null }", Boolean.FALSE);
evaluateTest("#{ 3 < null }", Boolean.FALSE);
evaluateTest("#{ 3 >= null }", Boolean.FALSE);
evaluateTest("#{ 3 <= null }", Boolean.FALSE);
evaluateTest("#{ null == \"\" }", Boolean.FALSE);
evaluateTest("#{ null != \"\" }", Boolean.TRUE);
evaluateTest("#{ \"\" == null }", Boolean.FALSE);
evaluateTest("#{ \"\" != null }", Boolean.TRUE);
/* arithmetic operators involving Strings */
evaluateTest("#{ 4 + 3 }", new Long(7));
evaluateTest("#{ 4.0 + 3 }", new Double(7.0));
evaluateTest("#{ 4 + 3.0 }", new Double(7.0));
evaluateTest("#{ 4.0 + 3.0 }", new Double(7.0));
evaluateTest("#{ \"4\" + 3 }", new Long(7));
evaluateTest("#{ \"4.0\" + 3 }", new Double(7.0));
evaluateTest("#{ \"4\" + 3.0 }", new Double(7.0));
evaluateTest("#{ \"4.0\" + 3.0 }", new Double(7.0));
evaluateTest("#{ 4 + \"3\" }", new Long(7));
evaluateTest("#{ 4.0 + \"3\" }", new Double(7.0));
evaluateTest("#{ 4 + \"3.0\" }", new Double(7.0));
evaluateTest("#{ 4.0 + \"3.0\" }", new Double(7.0));
evaluateTest("#{ \"4\" + \"3\" }", new Long(7));
evaluateTest("#{ \"4.0\" + \"3\" }", new Double(7.0));
evaluateTest("#{ \"4\" + \"3.0\" }", new Double(7.0));
evaluateTest("#{ \"4.0\" + \"3.0\" }", new Double(7.0));
evaluateTest("#{ 4 - 3 }", new Long(1));
evaluateTest("#{ 4.0 - 3 }", new Double(1.0));
evaluateTest("#{ 4 - 3.0 }", new Double(1.0));
evaluateTest("#{ 4.0 - 3.0 }", new Double(1.0));
evaluateTest("#{ \"4\" - 3 }", new Long(1));
evaluateTest("#{ \"4.0\" - 3 }", new Double(1.0));
evaluateTest("#{ \"4\" - 3.0 }", new Double(1.0));
evaluateTest("#{ \"4.0\" - 3.0 }", new Double(1.0));
evaluateTest("#{ 4 - \"3\" }", new Long(1));
evaluateTest("#{ 4.0 - \"3\" }", new Double(1.0));
evaluateTest("#{ 4 - \"3.0\" }", new Double(1.0));
evaluateTest("#{ 4.0 - \"3.0\" }", new Double(1.0));
evaluateTest("#{ \"4\" - \"3\" }", new Long(1));
evaluateTest("#{ \"4.0\" - \"3\" }", new Double(1.0));
evaluateTest("#{ \"4\" - \"3.0\" }", new Double(1.0));
evaluateTest("#{ \"4.0\" - \"3.0\" }", new Double(1.0));
evaluateTest("#{ 4 * 3 }", new Long(12));
evaluateTest("#{ 4.0 * 3 }", new Double(12.0));
evaluateTest("#{ 4 * 3.0 }", new Double(12.0));
evaluateTest("#{ 4.0 * 3.0 }", new Double(12.0));
evaluateTest("#{ \"4\" * 3 }", new Long(12));
evaluateTest("#{ \"4.0\" * 3 }", new Double(12.0));
evaluateTest("#{ \"4\" * 3.0 }", new Double(12.0));
evaluateTest("#{ \"4.0\" * 3.0 }", new Double(12.0));
evaluateTest("#{ 4 * \"3\" }", new Long(12));
evaluateTest("#{ 4.0 * \"3\" }", new Double(12.0));
evaluateTest("#{ 4 * \"3.0\" }", new Double(12.0));
evaluateTest("#{ 4.0 * \"3.0\" }", new Double(12.0));
evaluateTest("#{ \"4\" * \"3\" }", new Long(12));
evaluateTest("#{ \"4.0\" * \"3\" }", new Double(12.0));
evaluateTest("#{ \"4\" * \"3.0\" }", new Double(12.0));
evaluateTest("#{ \"4.0\" * \"3.0\" }", new Double(12.0));
evaluateTest("#{ 4 / 3 }", new Double(4.0 / 3.0));
evaluateTest("#{ 4.0 / 3 }", new Double(4.0 / 3.0));
evaluateTest("#{ 4 / 3.0 }", new Double(4.0 / 3.0));
evaluateTest("#{ 4.0 / 3.0 }", new Double(4.0 / 3.0));
evaluateTest("#{ \"4\" / 3 }", new Double(4.0 / 3.0));
evaluateTest("#{ \"4.0\" / 3 }", new Double(4.0 / 3.0));
evaluateTest("#{ \"4\" / 3.0 }", new Double(4.0 / 3.0));
evaluateTest("#{ \"4.0\" / 3.0 }", new Double(4.0 / 3.0));
evaluateTest("#{ 4 / \"3\" }", new Double(4.0 / 3.0));
evaluateTest("#{ 4.0 / \"3\" }", new Double(4.0 / 3.0));
evaluateTest("#{ 4 / \"3.0\" }", new Double(4.0 / 3.0));
evaluateTest("#{ 4.0 / \"3.0\" }", new Double(4.0 / 3.0));
evaluateTest("#{ \"4\" / \"3\" }", new Double(4.0 / 3.0));
evaluateTest("#{ \"4.0\" / \"3\" }", new Double(4.0 / 3.0));
evaluateTest("#{ \"4\" / \"3.0\" }", new Double(4.0 / 3.0));
evaluateTest("#{ \"4.0\" / \"3.0\" }", new Double(4.0 / 3.0));
evaluateTest("#{ 4 % 3 }", new Long(1));
evaluateTest("#{ 4.0 % 3 }", new Double(1.0));
evaluateTest("#{ 4 % 3.0 }", new Double(1.0));
evaluateTest("#{ 4.0 % 3.0 }", new Double(1.0));
evaluateTest("#{ \"4\" % 3 }", new Long(1));
evaluateTest("#{ \"4.0\" % 3 }", new Double(1.0));
evaluateTest("#{ \"4\" % 3.0 }", new Double(1.0));
evaluateTest("#{ \"4.0\" % 3.0 }", new Double(1.0));
evaluateTest("#{ 4 % \"3\" }", new Long(1));
evaluateTest("#{ 4.0 % \"3\" }", new Double(1.0));
evaluateTest("#{ 4 % \"3.0\" }", new Double(1.0));
evaluateTest("#{ 4.0 % \"3.0\" }", new Double(1.0));
evaluateTest("#{ \"4\" % \"3\" }", new Long(1));
evaluateTest("#{ \"4.0\" % \"3\" }", new Double(1.0));
evaluateTest("#{ \"4\" % \"3.0\" }", new Double(1.0));
evaluateTest("#{ \"4.0\" % \"3.0\" }", new Double(1.0));
evaluateTest("#{ \"8\" / \"2\" }", new Double(4.0));
evaluateTest("#{ \"4e2\" + \"3\" }", new Double(403));
evaluateTest("#{ \"4\" + \"3e2\" }", new Double(304));
evaluateTest("#{ \"4e2\" + \"3e2\" }", new Double(700));
/* unary minus operator involving Strings */
evaluateTest("#{ -3 }", new Long(-3));
evaluateTest("#{ -3.0 }", new Double(-3.0));
evaluateTest("#{ -\"3\" }", new Long(-3));
evaluateTest("#{ -\"3.0\" }", new Double(-3));
evaluateTest("#{ -\"3e2\" }", new Double(-300));
}
protected Bean1 createBean1()
{
Bean1 b1 = new Bean1();
b1.setBoolean1(true);
b1.setByte1((byte) 12);
b1.setShort1((short) 98);
b1.setChar1('b');
b1.setInt1(4);
b1.setLong1(98);
b1.setFloat1((float) 12.4);
b1.setDouble1(89.224);
b1.setString1("hello");
b1.setStringArray1(new String[]
{ "string1", "string2", "string3", "string4" });
{
List l = new ArrayList();
l.add(new Integer(14));
l.add("another value");
l.add(b1.getStringArray1());
b1.setList1(l);
}
{
Map m = new HashMap();
m.put("key1", "value1");
m.put(new Integer(14), "value2");
m.put(new Long(14), "value3");
m.put("recurse", b1);
b1.setMap1(m);
}
Bean1 b2 = new Bean1();
b2.setInt2(new Integer(-224));
b2.setString2("bean2's string");
b1.setBean1(b2);
Bean1 b3 = new Bean1();
b3.setDouble1(1422.332);
b3.setString2("bean3's string");
b2.setBean2(b3);
return b1;
}
public ExternalContext getExternalContext()
{
return getFacesContext().getExternalContext();
}
public void evaluateTestFailure(String ref) throws Exception
{
try
{
this.evaluate(ref);
fail("'" + ref + "' should have thrown an exception");
}
catch (Exception e)
{
// do nothing
}
}
public void evaluateTest(String ref, Object expectedValue) throws Exception
{
Object returnedValue = this.evaluate(ref);
if (returnedValue != null)
{
Class expectedType = expectedValue.getClass();
Class returnedType = returnedValue.getClass();
String msg = "'" + ref + "' expected [" + expectedValue
+ "] of type " + expectedType.getName()
+ ", but returned [" + returnedValue + "] of type "
+ returnedType.getName();
assertTrue(msg, expectedType.isAssignableFrom(returnedType));
assertEquals(msg, expectedValue, returnedValue);
}
else
{
String msg = "'" + ref + "' expected value [" + expectedValue
+ "], but returned [" + returnedValue + "]";
assertEquals(msg, expectedValue, returnedValue);
}
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/TestValueBindingImpl_Model.java 0000644 0000000 0000000 00000031613 11412443352 024230 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestValueBindingImpl_Model.java
package com.sun.faces.el;
import com.sun.faces.cactus.ServletFacesTestCase;
import com.sun.faces.TestBean;
import com.sun.faces.cactus.TestBean.Inner2Bean;
import com.sun.faces.cactus.TestBean.InnerBean;
import javax.faces.context.FacesContext;
import javax.faces.el.PropertyNotFoundException;
import javax.faces.el.ValueBinding;
/**
* TestValueBindingImpl_Model is a class ...
*
*
*/
public class TestValueBindingImpl_Model extends ServletFacesTestCase {
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
ValueBinding valueBinding = null;
//
// Constructors and Initializers
//
public TestValueBindingImpl_Model() {
super("TestValueBindingImpl");
}
public TestValueBindingImpl_Model(String name) {
super(name);
}
//
// Class methods
//
//
// Methods from TestCase
//
//
// General Methods
//
public ValueBinding create(String ref) throws Exception {
return (getFacesContext().getApplication().createValueBinding("#{" + ref + "}"));
}
public void setUp() {
super.setUp();
valueBinding = null;
}
public void tearDown() {
valueBinding = null;
super.tearDown();
}
public void testSet() throws Exception {
FacesContext facesContext = getFacesContext();
System.out.println("Testing setValue() with model bean in session ");
TestBean testBean = new TestBean();
InnerBean inner = new InnerBean();
Inner2Bean innerInner = new Inner2Bean();
Object result = null;
getFacesContext().getExternalContext().getSessionMap().put("TestBean",
testBean);
boolean exceptionThrown = false;
System.setProperty(TestBean.PROP, TestBean.FALSE);
valueBinding = this.create("TestBean.one");
valueBinding.setValue(getFacesContext(), "one");
assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE));
InnerBean newInner = new InnerBean();
valueBinding = this.create("TestBean.inner");
valueBinding.setValue(getFacesContext(), newInner);
result = valueBinding.getValue(getFacesContext());
assertTrue(result == newInner);
// Test two levels of nesting
System.setProperty(TestBean.PROP, TestBean.FALSE);
valueBinding = this.create("sessionScope.TestBean.inner.two");
valueBinding.setValue(getFacesContext(), "two");
assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE));
Inner2Bean newInner2 = new Inner2Bean();
valueBinding = this.create("TestBean.inner.inner2");
valueBinding.setValue(getFacesContext(), newInner2);
result = valueBinding.getValue(getFacesContext());
assertTrue(result == newInner2);
System.setProperty(TestBean.PROP, TestBean.FALSE);
valueBinding = this.create("sessionScope.TestBean.inner.inner2");
valueBinding.setValue(getFacesContext(), innerInner);
assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE));
// Test three levels of nesting
System.setProperty(TestBean.PROP, TestBean.FALSE);
valueBinding = this.create("sessionScope.TestBean.inner.inner2.three");
valueBinding.setValue(getFacesContext(), "three");
assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE));
}
public void testSetNull() throws Exception {
FacesContext facesContext = getFacesContext();
System.out.println(
"Testing setValue() with model bean in session with null rValues");
TestBean testBean = new TestBean();
InnerBean inner = new InnerBean();
Inner2Bean innerInner = new Inner2Bean();
getFacesContext().getExternalContext().getSessionMap().put("TestBean",
testBean);
// Test one level of nesting
valueBinding = this.create("TestBean.one");
valueBinding.setValue(getFacesContext(), null);
assertTrue(testBean.getOne() == null);
System.setProperty(TestBean.PROP, TestBean.FALSE);
valueBinding = this.create("sessionScope.TestBean.inner");
valueBinding.setValue(getFacesContext(), inner);
assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE));
valueBinding = this.create("sessionScope.TestBean.inner");
valueBinding.setValue(getFacesContext(), null);
assertTrue(testBean.getInner() == null);
// Inner bean does not exist anymore. So this should result in an
// exception.
boolean exceptionThrown = false;
valueBinding = this.create("sessionScope.TestBean.inner.two");
try {
valueBinding.setValue(getFacesContext(), null);
} catch (javax.faces.el.EvaluationException ee) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
public void testSetWithNoCurlyBraces() throws Exception {
FacesContext facesContext = getFacesContext();
System.out.println("Testing setValue() with model bean in request ");
TestBean testBean = new TestBean();
InnerBean inner = new InnerBean();
Inner2Bean innerInner = new Inner2Bean();
facesContext.getExternalContext().getSessionMap().remove("TestBean");
facesContext.getExternalContext().getRequestMap().put("TestBean",
testBean);
// Test implicit scopes direct access to some scope objects should
// throw an illegalArgumentException
boolean gotException = false;
try {
valueBinding = this.create("header.header-one");
valueBinding.setValue(getFacesContext(), testBean);
} catch (javax.faces.el.EvaluationException pnf) {
gotException = true;
}
assertTrue(gotException);
// Test one level of nesting
System.setProperty(TestBean.PROP, TestBean.FALSE);
valueBinding = this.create("TestBean.one");
valueBinding.setValue(getFacesContext(), "one");
assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE));
System.setProperty(TestBean.PROP, TestBean.FALSE);
valueBinding = this.create("requestScope.TestBean.inner");
valueBinding.setValue(getFacesContext(), inner);
assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE));
// Test two levels of nesting
System.setProperty(TestBean.PROP, TestBean.FALSE);
valueBinding = this.create("requestScope.TestBean.inner.two");
valueBinding.setValue(getFacesContext(), "two");
assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE));
System.setProperty(TestBean.PROP, TestBean.FALSE);
valueBinding = this.create("requestScope.TestBean.inner.inner2");
valueBinding.setValue(getFacesContext(), innerInner);
assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE));
// Test three levels of nesting
System.setProperty(TestBean.PROP, TestBean.FALSE);
valueBinding = this.create("requestScope.TestBean.inner.inner2.three");
valueBinding.setValue(getFacesContext(), "three");
assertTrue(System.getProperty(TestBean.PROP).equals(TestBean.TRUE));
}
public void testGet() throws Exception {
FacesContext facesContext = getFacesContext();
System.out.println("Testing getValue() with model bean in context");
assertTrue(facesContext != null);
TestBean testBeanResult = null, testBean = new TestBean();
InnerBean inner = new InnerBean();
Inner2Bean inner2 = new Inner2Bean();
String result;
// Init the beans
testBean.setOne("one");
inner.setTwo("two");
inner2.setThree("three");
inner.setInner2(inner2);
testBean.setInner(inner);
assertTrue(facesContext != null);
assertTrue(facesContext.getExternalContext().getSession(false) != null);
facesContext.getExternalContext().getRequestMap().remove("TestBean");
facesContext.getExternalContext().getSessionMap().remove("TestBean");
facesContext.getExternalContext().getApplicationMap().put("TestBean",
testBean);
// Test zero levels of nesting
valueBinding = this.create("applicationScope.TestBean");
testBeanResult = (TestBean) valueBinding.getValue(getFacesContext());
assertTrue(testBeanResult != null);
assertTrue(testBeanResult == testBean);
// Test one level of nesting
valueBinding = this.create("applicationScope.TestBean.one");
result = (String) valueBinding.getValue(getFacesContext());
assertTrue(result.equals("one"));
valueBinding = this.create("applicationScope.TestBean.inner");
inner = (InnerBean) valueBinding.getValue(getFacesContext());
assertTrue(null != inner);
// Test two levels of nesting
valueBinding = this.create("applicationScope.TestBean.inner.two");
result = (String) valueBinding.getValue(getFacesContext());
assertTrue(result.equals("two"));
valueBinding = this.create("applicationScope.TestBean.inner.inner2");
inner2 = (Inner2Bean)
valueBinding.getValue(getFacesContext());
assertTrue(null != inner2);
// Test three levels of nesting
valueBinding = this.create("applicationScope.TestBean.inner.inner2.three");
result = (String) valueBinding.getValue(getFacesContext());
assertTrue(result.equals("three"));
}
public void testModelType() {
/***************** PENDING(edburns):
// Test model type
System.out.println("Testing getModelType()");
Class classType = null;
String className = null;
// Test zero levels of nesting
classType = facesContext.getModelType("applicationScope.TestBean");
assertTrue(classType != null);
className = classType.getName();
assertTrue(className.equals(testBean.getClass().getName()));
classType = facesContext.getModelType("applicationScope.TestBean.inner.pin");
assertTrue(classType != null);
className = classType.getName();
assertTrue(className.equals("java.lang.Integer"));
classType = facesContext.getModelType("applicationScope.TestBean.inner.result");
assertTrue(classType != null);
className = classType.getName();
assertTrue(className.equals("java.lang.Boolean"));
classType = facesContext.getModelType("applicationScope.TestBean.one");
assertTrue(classType != null);
className = classType.getName();
assertTrue(className.equals("java.lang.String"));
*********************/
}
} // end of class TestValueBindingImpl_Model
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/ElBean.java 0000644 0000000 0000000 00000015413 11412443352 020205 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.el;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
// JavaBean for simple expression evaluation tests
public class ElBean {
public ElBean() {
}
public ElBean(String stringProperty) {
this.stringProperty = stringProperty;
}
private boolean booleanProperty = true;
public boolean getBooleanProperty() {
return (this.booleanProperty);
}
public void setBooleanProperty(boolean booleanProperty) {
this.booleanProperty = booleanProperty;
}
private byte byteProperty = 123;
public byte getByteProperty() {
return (this.byteProperty);
}
public void setByteProperty(byte byteProperty) {
this.byteProperty = byteProperty;
}
private char characterProperty = 'c';
public char getCharacterProperty()
{
return this.characterProperty;
}
public void setCharacterProperty(char c)
{
this.characterProperty = c;
}
private double doubleProperty = 654.321;
public double getDoubleProperty() {
return (this.doubleProperty);
}
public void setDoubleProperty(double doubleProperty) {
this.doubleProperty = doubleProperty;
}
private float floatProperty = (float) 123.45;
public float getFloatProperty() {
return (this.floatProperty);
}
public void setFloatProperty(float floatProperty) {
this.floatProperty = floatProperty;
}
private int intArray[] = {1, 2, 3};
public int[] getIntArray() {
return (this.intArray);
}
public void setIntArray(int intArray[]) {
this.intArray = intArray;
}
private List intList = null;
public List getIntList() {
if (intList == null) {
intList = new ArrayList();
intList.add(new Integer(10));
intList.add(new Integer(20));
intList.add(new Integer(30));
intList.add(new Integer(40));
intList.add(new Integer(50));
}
return (intList);
}
public void setIntList(List intList) {
this.intList = intList;
}
private int intProperty = 1234;
public int getIntProperty() {
return (this.intProperty);
}
public void setIntProperty(int intProperty) {
this.intProperty = intProperty;
}
private long longProperty = 54321;
public long getLongProperty() {
return (this.longProperty);
}
public void setLongProperty(long longProperty) {
this.longProperty = longProperty;
}
private ElBean nestedArray[] = null;
public ElBean[] getNestedArray() {
if (nestedArray == null) {
nestedArray = new ElBean[2];
nestedArray[0] = new ElBean("Nested0");
nestedArray[1] = new ElBean("Nested1");
}
return (this.nestedArray);
}
public void setNestedArray(ElBean nestedArray[]) {
this.nestedArray = nestedArray;
}
private List nestedList = null;
public List getNestedList() {
if (nestedList == null) {
nestedList = new ArrayList();
nestedList.add(new ElBean("list0"));
nestedList.add(new ElBean("list1"));
nestedList.add(new ElBean("list2"));
nestedList.add(new ElBean("list3"));
}
return (this.nestedList);
}
public void setNestedList(List nestedList) {
this.nestedList = nestedList;
}
private Map nestedMap = null;
public Map getNestedMap() {
if (nestedMap == null) {
nestedMap = new HashMap();
nestedMap.put("map0", new ElBean("map0"));
nestedMap.put("map1", new ElBean("map1"));
nestedMap.put("map2", new ElBean("map2"));
}
return (this.nestedMap);
}
public void setNestedMap(Map nestedMap) {
this.nestedMap = nestedMap;
}
private ElBean nestedProperty = null;
public ElBean getNestedProperty() {
if (nestedProperty == null) {
nestedProperty = new ElBean();
}
return (this.nestedProperty);
}
public void setNestedProperty(ElBean nestedProperty) {
this.nestedProperty = nestedProperty;
}
private short shortProperty = 321;
public short getShortProperty() {
return (this.shortProperty);
}
public void setShortProperty(short shortProperty) {
this.shortProperty = shortProperty;
}
private String stringProperty = "This is a String";
public String getStringProperty() {
return (this.stringProperty);
}
public void setStringProperty(String stringProperty) {
this.stringProperty = stringProperty;
}
private String nullString = null;
public String getNullStringProperty() {
return ("String length is:" + nullString.length());
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/TestMethodExpressionImpl.java 0000644 0000000 0000000 00000011524 11412443352 024040 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestMethodRef.java
package com.sun.faces.el;
import com.sun.faces.cactus.ServletFacesTestCase;
import javax.el.MethodExpression;
import javax.el.ELException;
import javax.el.MethodNotFoundException;
import javax.faces.el.PropertyNotFoundException;
/**
* TestMethodRef is a class ...
*
*/
public class TestMethodExpressionImpl extends ServletFacesTestCase
{
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestMethodExpressionImpl()
{
super("TestMethodExpression");
}
public TestMethodExpressionImpl(String name)
{
super(name);
}
//
// Class methods
//
//
// General Methods
//
protected MethodExpression create(String ref, Class[] params) throws Exception
{
return (getFacesContext().getApplication().getExpressionFactory().
createMethodExpression(getFacesContext().getELContext(),ref, null, params));
}
public void testNullReference() throws Exception
{
try
{
create(null, null);
fail();
}
catch (NullPointerException npe) {}
catch (Exception e) { fail("Should have thrown an NPE"); };
}
public void testInvalidMethod() throws Exception
{
try
{
create("${foo > 1}", null);
fail();
}
catch (ELException ee) {
fail("Should have thrown a NullPointerException");
}
catch (NullPointerException npe) { }
}
public void testLiteralReference() throws Exception
{
boolean exceptionThrown = false;
try
{
create("some.method", null);
}
catch (NullPointerException ee) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
public void testInvalidTrailing() throws Exception
{
MethodExpression mb = this.create(
"#{NewCustomerFormHandler.redLectroidsMmmm}", new Class[0]);
boolean exceptionThrown = false;
try
{
mb.invoke(getFacesContext().getELContext(), new Object[0]);
}
catch (MethodNotFoundException me)
{
exceptionThrown = true;
}
assertTrue(exceptionThrown);
mb = this.create("#{nonexistentBean.redLectroidsMmmm}", new Class[0]);
exceptionThrown = false;
try
{
mb.invoke(getFacesContext().getELContext(), new Object[0]);
}
catch (PropertyNotFoundException ne)
{
exceptionThrown = true;
}
catch (ELException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
} // end of class TestMethodRef
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/el/TestVariableResolverImpl.java 0000644 0000000 0000000 00000024736 11412443352 024020 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestVariableResolverImpl.java
package com.sun.faces.el;
import com.sun.faces.cactus.ServletFacesTestCase;
import com.sun.faces.TestBean;
import com.sun.faces.mgbean.ManagedBeanInfo;
import com.sun.faces.mgbean.BeanManager;
import com.sun.faces.cactus.TestBean.InnerBean;
import com.sun.faces.application.ApplicationImpl;
import com.sun.faces.application.ApplicationAssociate;
import com.sun.faces.util.Util;
import javax.faces.FactoryFinder;
import javax.faces.application.ApplicationFactory;
import javax.faces.component.UIViewRoot;
import javax.faces.el.VariableResolver;
import java.util.Locale;
/**
* TestVariableResolverImpl is a class ...
*
*
*/
public class TestVariableResolverImpl extends ServletFacesTestCase {
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestVariableResolverImpl() {
super("TestFacesContext");
}
public TestVariableResolverImpl(String name) {
super(name);
}
//
// Class methods
//
//
// Methods from TestCase
//
//
// General Methods
//
public void testScopedLookup() {
TestBean testBean = new TestBean();
InnerBean newInner, oldInner = new InnerBean();
testBean.setInner(oldInner);
VariableResolver variableResolver =
getFacesContext().getApplication().getVariableResolver();
Object result = null;
getFacesContext().getExternalContext().getSessionMap().remove(
"TestBean");
//
// Get tests
//
// application
getFacesContext().getExternalContext().getApplicationMap().put(
"TestBean",
testBean);
result = variableResolver.resolveVariable(getFacesContext(),
"TestBean");
assertTrue(result == testBean);
getFacesContext().getExternalContext().getApplicationMap().remove(
"TestBean");
// session
getFacesContext().getExternalContext().getSessionMap().put("TestBean",
testBean);
result = variableResolver.resolveVariable(getFacesContext(),
"TestBean");
assertTrue(result == testBean);
getFacesContext().getExternalContext().getSessionMap().remove(
"TestBean");
// session
getFacesContext().getExternalContext().getRequestMap().put("TestBean",
testBean);
result = variableResolver.resolveVariable(getFacesContext(),
"TestBean");
assertTrue(result == testBean);
getFacesContext().getExternalContext().getRequestMap().remove(
"TestBean");
}
public void testImplicitObjects() {
VariableResolver variableResolver =
getFacesContext().getApplication().getVariableResolver();
Object result = null;
//
// test scope maps
//
// ApplicationMap
assertTrue(variableResolver.resolveVariable(getFacesContext(),
"applicationScope") ==
getFacesContext().getExternalContext().getApplicationMap());
// SessionMap
assertTrue(variableResolver.resolveVariable(getFacesContext(),
"sessionScope") ==
getFacesContext().getExternalContext().getSessionMap());
// RequestMap
assertTrue(variableResolver.resolveVariable(getFacesContext(),
"requestScope") ==
getFacesContext().getExternalContext().getRequestMap());
//
// test request objects
//
// cookie
assertTrue(variableResolver.resolveVariable(getFacesContext(),
"cookie") ==
getFacesContext().getExternalContext().getRequestCookieMap());
// header
assertTrue(variableResolver.resolveVariable(getFacesContext(),
"header") ==
getFacesContext().getExternalContext().getRequestHeaderMap());
// headerValues
assertTrue(
variableResolver.resolveVariable(getFacesContext(),
"headerValues") ==
getFacesContext().getExternalContext().getRequestHeaderValuesMap());
// parameter
assertTrue(variableResolver.resolveVariable(getFacesContext(),
"param") ==
getFacesContext().getExternalContext()
.getRequestParameterMap());
// parameterValues
assertTrue(
variableResolver.resolveVariable(getFacesContext(),
"paramValues") ==
getFacesContext().getExternalContext()
.getRequestParameterValuesMap());
//
// misc
//
// initParameter
assertTrue(variableResolver.resolveVariable(getFacesContext(),
"initParam") ==
getFacesContext().getExternalContext().getInitParameterMap());
// facesContext
assertTrue(variableResolver.resolveVariable(getFacesContext(),
"facesContext") ==
getFacesContext());
// tree
// create a dummy root for the tree.
UIViewRoot page = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
page.setId("root");
page.setViewId("newTree");
page.setLocale(Locale.US);
getFacesContext().setViewRoot(page);
assertTrue(variableResolver.resolveVariable(getFacesContext(),
"view") ==
getFacesContext().getViewRoot());
}
// Negative tests (should throw exceptions)
public void testNegative() throws Exception {
VariableResolver variableResolver =
getFacesContext().getApplication().getVariableResolver();
Object value = null;
// ---------- NullPointerException Returns ----------
try {
value = variableResolver.resolveVariable(getFacesContext(), null);
fail("Should have thrown NullPointerException");
} catch (NullPointerException e) {
; // Expected result
}
try {
value = variableResolver.resolveVariable(null, "foo");
fail("Should have thrown NullPointerException");
} catch (NullPointerException e) {
; // Expected result
}
try {
value = variableResolver.resolveVariable(null, null);
fail("Should have thrown NullPointerException");
} catch (NullPointerException e) {
; // Expected result
}
}
/**
* This test verifies that if the variable resolver does not find a
* managed bean it tries to instantiate it if it was added to the
* application's managed bean factory list.
*/
public void testManagedBean() throws Exception {
String beanName = "com.sun.faces.TestBean";
ManagedBeanInfo beanInfo = new ManagedBeanInfo(beanName,
beanName,
"session",
null,
null,
null,
null);
ApplicationFactory aFactory = (ApplicationFactory) FactoryFinder.getFactory(
FactoryFinder.APPLICATION_FACTORY);
ApplicationImpl application = (ApplicationImpl) aFactory.getApplication();
ApplicationAssociate associate = ApplicationAssociate.getCurrentInstance();
BeanManager manager = associate.getBeanManager();
manager.register(beanInfo);
VariableResolver variableResolver = application.getVariableResolver();
Object result = variableResolver.resolveVariable(getFacesContext(),
beanName);
assertTrue(result instanceof TestBean);
}
} // end of class TestVariableResolverImpl
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/ext/ 0000755 0000000 0000000 00000000000 11412443346 016413 5 ustar mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/ext/validator/ 0000755 0000000 0000000 00000000000 11412443346 020400 5 ustar mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/TestForm.java 0000644 0000000 0000000 00000004173 11412443352 020223 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces;
import javax.faces.component.html.HtmlForm;
public class TestForm extends HtmlForm {
public static final String COMPONENT_TYPE = "javax.faces.TestForm";
public TestForm() {
super();
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/taglib/ 0000755 0000000 0000000 00000000000 11412443352 017052 5 ustar mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/taglib/TlvTestCase.java 0000644 0000000 0000000 00000006623 11412443352 022125 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.taglib;
import junit.framework.TestCase;
import junit.framework.Test;
import junit.framework.TestSuite;
public class TlvTestCase extends TestCase {
// ------------------------------------------------------ Instance Variables
public TlvTestCase(String name) {
super(name);
}
// ---------------------------------------------------- Overall Test Methods
// Set up instance variables required by this test case.
public void setUp() { }
// Return the tests included in this test case.
public static Test suite() {
return (new TestSuite(TlvTestCase.class));
}
// Tear down instance variables required by this test case.
public void tearDown() {
}
// ------------------------------------------------- Individual Test Methods
public void testDesignTime() {
java.beans.Beans.setDesignTime(true);
TestHtmlBasicValidator hbv = new TestHtmlBasicValidator();
org.xml.sax.helpers.DefaultHandler handler = hbv.getSAXHandler();
assertTrue(null == handler);
java.beans.Beans.setDesignTime(false);
handler = hbv.getSAXHandler();
assertTrue(null != handler);
java.beans.Beans.setDesignTime(true);
TestCoreValidator cv = new TestCoreValidator();
handler = cv.getSAXHandler();
assertTrue(null == handler);
java.beans.Beans.setDesignTime(false);
handler = cv.getSAXHandler();
assertTrue(null != handler);
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/taglib/TestHtmlBasicValidator.java 0000644 0000000 0000000 00000004272 11412443352 024276 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.taglib;
import com.sun.faces.taglib.html_basic.HtmlBasicValidator;
import org.xml.sax.helpers.DefaultHandler;
public class TestHtmlBasicValidator extends HtmlBasicValidator {
public DefaultHandler getSAXHandler() {
return super.getSAXHandler();
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/taglib/html_basic/ 0000755 0000000 0000000 00000000000 11412443352 021157 5 ustar mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/taglib/jsf_core/ 0000755 0000000 0000000 00000000000 11412443352 020644 5 ustar mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/taglib/jsf_core/TestValidatorTags.java 0000644 0000000 0000000 00000023520 11412443352 025115 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestValidatorTags.java
package com.sun.faces.taglib.jsf_core;
import java.util.Iterator;
import java.util.Locale;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import com.sun.faces.cactus.JspFacesTestCase;
import com.sun.faces.lifecycle.ApplyRequestValuesPhase;
import com.sun.faces.lifecycle.Phase;
import com.sun.faces.lifecycle.ProcessValidationsPhase;
import com.sun.faces.lifecycle.RenderResponsePhase;
import com.sun.faces.util.Util;
import org.apache.cactus.WebRequest;
/**
* TestValidatorTags is a class ...
*
*
*/
public class TestValidatorTags extends JspFacesTestCase {
//
// Protected Constants
//
public static final String TEST_URI = "/TestValidatorTags.jsp";
public static final String OUTOFBOUNDS1_ID = "validatorForm" +
NamingContainer.SEPARATOR_CHAR +
"outOfBounds1";
public static final String OUTOFBOUNDS1_VALUE = "3.1415";
public static final String INBOUNDS1_ID = "validatorForm" +
NamingContainer.SEPARATOR_CHAR +
"inBounds1";
public static final String INBOUNDS1_VALUE = "10.25";
public static final String OUTOFBOUNDS2_ID = "validatorForm" +
NamingContainer.SEPARATOR_CHAR +
"outOfBounds2";
public static final String OUTOFBOUNDS2_VALUE = "fox";
public static final String INBOUNDS2_ID = "validatorForm" +
NamingContainer.SEPARATOR_CHAR +
"inBounds2";
public static final String INBOUNDS2_VALUE = "alligator22";
public static final String OUTOFBOUNDS3_ID = "validatorForm" +
NamingContainer.SEPARATOR_CHAR +
"outOfBounds3";
public static final String OUTOFBOUNDS3_VALUE = "30000";
public static final String INBOUNDS3_ID = "validatorForm" +
NamingContainer.SEPARATOR_CHAR +
"inBounds3";
public static final String INBOUNDS3_VALUE = "1100";
public static final String REQUIRED1_ID = "validatorForm" +
NamingContainer.SEPARATOR_CHAR +
"required1";
public static final String REQUIRED1_VALUE = "required";
public static final String REQUIRED2_ID = "validatorForm" +
NamingContainer.SEPARATOR_CHAR +
"required2";
public static final String REQUIRED2_VALUE = "required";
public boolean sendResponseToFile() {
return false;
}
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestValidatorTags() {
super("TestValidatorTags");
}
public TestValidatorTags(String name) {
super(name);
}
//
// Class methods
//
//
// General Methods
//
public void beginValidators(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/faces", TEST_URI, null);
theRequest.addParameter(OUTOFBOUNDS1_ID, OUTOFBOUNDS1_VALUE);
theRequest.addParameter(INBOUNDS1_ID, INBOUNDS1_VALUE);
theRequest.addParameter(OUTOFBOUNDS2_ID, OUTOFBOUNDS2_VALUE);
theRequest.addParameter(INBOUNDS2_ID, INBOUNDS2_VALUE);
theRequest.addParameter(OUTOFBOUNDS3_ID, OUTOFBOUNDS3_VALUE);
theRequest.addParameter(INBOUNDS3_ID, INBOUNDS3_VALUE);
theRequest.addParameter(REQUIRED1_ID, "");
theRequest.addParameter(REQUIRED2_ID, "");
theRequest.addParameter("validatorForm", "validatorForm");
}
public void setUp() {
super.setUp();
}
public void testValidators() {
// Verify the parmeters are as expected
String paramVal = (String) (getFacesContext().getExternalContext()
.getRequestParameterMap()).get(OUTOFBOUNDS1_ID);
assertTrue(OUTOFBOUNDS1_VALUE.equals(paramVal));
// assertTrue(OUTOFBOUNDS1_VALUE.equals(getFacesContext().getServletRequest().getParameter(OUTOFBOUNDS1_ID)));
boolean result = false;
String value = null;
Phase
renderResponse = new RenderResponsePhase(),
processValidations = new ProcessValidationsPhase(),
applyRequestValues = new ApplyRequestValuesPhase();
UIViewRoot page = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), TEST_URI);
page.setLocale(Locale.US);
getFacesContext().setViewRoot(page);
// This builds the tree, and usefaces saves it in the session
renderResponse.execute(getFacesContext());
assertTrue(!(getFacesContext().getRenderResponse()) &&
!(getFacesContext().getResponseComplete()));
// This causes the components to be set to valid
applyRequestValues.execute(getFacesContext());
assertTrue(!(getFacesContext().getRenderResponse()) &&
!(getFacesContext().getResponseComplete()));
// process the validations
processValidations.execute(getFacesContext());
// We know there are validation errors on the page
assertTrue(getFacesContext().getRenderResponse());
// verify the messages have been added correctly.
UIComponent comp = null;
Iterator messages = null;
assertTrue(null != (messages = getFacesContext().getMessages()));
assertTrue(messages.hasNext());
// check the messages for each component in the page
assertTrue(null !=
(comp =
getFacesContext().getViewRoot().findComponent(
OUTOFBOUNDS1_ID)));
assertTrue(
null !=
(messages =
getFacesContext().getMessages(comp.getClientId(getFacesContext()))));
assertTrue(messages.hasNext());
assertTrue(null !=
(comp =
getFacesContext().getViewRoot().findComponent(INBOUNDS1_ID)));
assertTrue(
null !=
(messages =
getFacesContext().getMessages(comp.getClientId(getFacesContext()))));
assertTrue(!messages.hasNext());
assertTrue(null !=
(comp =
getFacesContext().getViewRoot().findComponent(
OUTOFBOUNDS2_ID)));
assertTrue(
null !=
(messages =
getFacesContext().getMessages(comp.getClientId(getFacesContext()))));
assertTrue(messages.hasNext());
assertTrue(null !=
(comp =
getFacesContext().getViewRoot().findComponent(INBOUNDS2_ID)));
assertTrue(
null !=
(messages =
getFacesContext().getMessages(comp.getClientId(getFacesContext()))));
assertTrue(!messages.hasNext());
assertTrue(null !=
(comp =
getFacesContext().getViewRoot().findComponent(
OUTOFBOUNDS3_ID)));
assertTrue(
null !=
(messages =
getFacesContext().getMessages(comp.getClientId(getFacesContext()))));
assertTrue(messages.hasNext());
assertTrue(null !=
(comp =
getFacesContext().getViewRoot().findComponent(INBOUNDS3_ID)));
assertTrue(
null !=
(messages =
getFacesContext().getMessages(comp.getClientId(getFacesContext()))));
assertTrue(!messages.hasNext());
assertTrue(null !=
(comp =
getFacesContext().getViewRoot().findComponent(REQUIRED1_ID)));
assertTrue(
null !=
(messages =
getFacesContext().getMessages(comp.getClientId(getFacesContext()))));
assertTrue(messages.hasNext());
assertTrue(null !=
(comp =
getFacesContext().getViewRoot().findComponent(REQUIRED2_ID)));
assertTrue(
null !=
(messages =
getFacesContext().getMessages(comp.getClientId(getFacesContext()))));
assertTrue(messages.hasNext());
}
} // end of class TestValidatorTags
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/taglib/jsf_core/TestCoreTagsVBEnabled.java 0000644 0000000 0000000 00000021004 11412443352 025556 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.taglib.jsf_core;
import java.util.Iterator;
import java.util.Locale;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import com.sun.faces.cactus.JspFacesTestCase;
import com.sun.faces.lifecycle.ApplyRequestValuesPhase;
import com.sun.faces.lifecycle.Phase;
import com.sun.faces.lifecycle.ProcessValidationsPhase;
import com.sun.faces.lifecycle.RenderResponsePhase;
import com.sun.faces.util.Util;
import org.apache.cactus.WebRequest;
/**
* TestValidatorTags is a class ...
*
*
*/
public class TestCoreTagsVBEnabled extends JspFacesTestCase {
//
// Protected Constants
//
public static final String TEST_URI = "/TestCoreTagVBEnabled.jsp";
public static final String LONGRANGE_ID = "validatorForm" +
NamingContainer.SEPARATOR_CHAR +
"longRange";
public static final String LONGRANGE_VALUE = "115";
public static final String INTRANGE_ID = "validatorForm" +
NamingContainer.SEPARATOR_CHAR +
"intRange";
public static final String INTRANGE_VALUE = "NorthAmerica";
public static final String DOUBLERANGE_ID = "validatorForm" +
NamingContainer.SEPARATOR_CHAR +
"doubleRange";
public static final String DOUBLERANGE_VALUE = "1500";
public boolean sendResponseToFile() {
return false;
}
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestCoreTagsVBEnabled() {
super("TestValidatorTags");
}
public TestCoreTagsVBEnabled(String name) {
super(name);
}
//
// Class methods
//
//
// General Methods
//
public void beginValidators(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/faces", TEST_URI, null);
theRequest.addParameter(LONGRANGE_ID, LONGRANGE_VALUE);
theRequest.addParameter(INTRANGE_ID, INTRANGE_VALUE);
theRequest.addParameter(DOUBLERANGE_ID, DOUBLERANGE_VALUE);
theRequest.addParameter("validatorForm", "validatorForm");
}
public void setUp() {
super.setUp();
(getFacesContext().getExternalContext().getRequestMap()).put("intMin",
new Integer(
1));
(getFacesContext().getExternalContext().getRequestMap()).put("intMax",
new Integer(
10));
(getFacesContext().getExternalContext().getRequestMap()).put("longMin",
new Long(
100));
(getFacesContext().getExternalContext().getRequestMap()).put("longMax",
new Long(
110));
(getFacesContext().getExternalContext().getRequestMap()).put(
"doubleMin", new Double(1.0));
(getFacesContext().getExternalContext().getRequestMap()).put(
"doubleMax", new Double(10.0));
}
public void testValidators() {
System.out.println("Test VBEnabled attributes on core Validator tags");
// Verify the parmeters are as expected
String paramVal = (String) (getFacesContext().getExternalContext()
.getRequestParameterMap()).get(LONGRANGE_ID);
assertTrue(LONGRANGE_VALUE.equals(paramVal));
String paramVal1 = (String) (getFacesContext().getExternalContext()
.getRequestParameterMap()).get(DOUBLERANGE_ID);
assertTrue(DOUBLERANGE_VALUE.equals(paramVal1));
String paramVal2 = (String) (getFacesContext().getExternalContext()
.getRequestParameterMap()).get(INTRANGE_ID);
assertTrue(INTRANGE_VALUE.equals(paramVal2));
boolean result = false;
String value = null;
Phase
renderResponse = new RenderResponsePhase(),
processValidations = new ProcessValidationsPhase(),
applyRequestValues = new ApplyRequestValuesPhase();
UIViewRoot page = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
page.setLocale(Locale.US);
page.setViewId(TEST_URI);
getFacesContext().setViewRoot(page);
// This builds the tree, and usefaces saves it in the session
renderResponse.execute(getFacesContext());
assertTrue(!(getFacesContext().getRenderResponse()) &&
!(getFacesContext().getResponseComplete()));
// This causes the components to be set to valid
applyRequestValues.execute(getFacesContext());
assertTrue(!(getFacesContext().getRenderResponse()) &&
!(getFacesContext().getResponseComplete()));
// process the validations
processValidations.execute(getFacesContext());
// We know there are validation errors on the page
assertTrue(getFacesContext().getRenderResponse());
System.out.println("Verifying results...");
// verify the messages have been added correctly.
UIComponent comp = null;
Iterator messages = null;
assertTrue(null != (messages = getFacesContext().getMessages()));
assertTrue(messages.hasNext());
// check the messages for each component in the page
assertTrue(null !=
(comp =
getFacesContext().getViewRoot().findComponent(LONGRANGE_ID)));
assertTrue(
null !=
(messages =
getFacesContext().getMessages(comp.getClientId(getFacesContext()))));
assertTrue(messages.hasNext());
assertTrue(null !=
(comp =
getFacesContext().getViewRoot().findComponent(INTRANGE_ID)));
assertTrue(
null !=
(messages =
getFacesContext().getMessages(comp.getClientId(getFacesContext()))));
assertTrue(messages.hasNext());
assertTrue(null !=
(comp =
getFacesContext().getViewRoot().findComponent(
DOUBLERANGE_ID)));
assertTrue(
null !=
(messages =
getFacesContext().getMessages(comp.getClientId(getFacesContext()))));
assertTrue(messages.hasNext());
}
} // end of class TestValidatorTags
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/taglib/jsf_core/TestViewTag.java 0000644 0000000 0000000 00000016526 11412443352 023727 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestViewTag.java
package com.sun.faces.taglib.jsf_core;
import com.sun.faces.cactus.JspFacesTestCase;
import com.sun.faces.lifecycle.Phase;
import com.sun.faces.lifecycle.RenderResponsePhase;
import com.sun.faces.util.Util;
import com.sun.faces.cactus.TestingUtil;
import org.apache.cactus.JspTestCase;
import org.apache.cactus.WebRequest;
import javax.faces.FacesException;
import javax.faces.component.UIViewRoot;
import javax.servlet.ServletRequest;
import javax.servlet.jsp.jstl.core.Config;
import java.util.Locale;
/**
* TestViewTag is a class ...
*
*
*/
public class TestViewTag extends JspFacesTestCase {
//
// Protected Constants
//
public static final String TEST_URI = "/TestViewTag.jsp";
public static final String TEST_URI2 = "/TestViewTag2.jsp";
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestViewTag() {
super("TestViewTag");
}
public TestViewTag(String name) {
super(name);
}
//
// Class methods
//
//
// General Methods
//
public void beginViewTag(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/faces", TEST_URI, null);
}
public void testViewTag() {
boolean result = false;
String value = null;
Locale expectedLocale = new Locale("ps", "PS");
Phase renderResponse = new RenderResponsePhase();
UIViewRoot page = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
page.setId("root");
page.setLocale(Locale.US);
page.setViewId(TEST_URI);
page.setLocale(Locale.CANADA_FRENCH);
getFacesContext().setViewRoot(page);
Config.set((ServletRequest)
getFacesContext().getExternalContext().getRequest(),
Config.FMT_LOCALE, Locale.CANADA_FRENCH);
try {
renderResponse.execute(getFacesContext());
} catch (FacesException fe) {
System.out.println(fe.getMessage());
if (null != fe.getCause()) {
fe.getCause().printStackTrace();
} else {
fe.printStackTrace();
}
}
assertEquals("locale not as expected", expectedLocale,
page.getLocale());
assertEquals("locale not as expected", expectedLocale,
Config.get((ServletRequest)
getFacesContext().getExternalContext().
getRequest(),
Config.FMT_LOCALE));
}
public void beginViewTagVB(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/faces", TEST_URI2, null);
}
public void testViewTagVB() {
boolean result = false;
String value = null;
Locale expectedLocale = new Locale("ps", "PS", "Traditional");
request.setAttribute("locale", expectedLocale);
Phase renderResponse = new RenderResponsePhase();
UIViewRoot page = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
page.setId("root");
page.setLocale(Locale.US);
page.setViewId(TEST_URI2);
getFacesContext().setViewRoot(page);
try {
renderResponse.execute(getFacesContext());
} catch (FacesException fe) {
System.out.println(fe.getMessage());
if (null != fe.getCause()) {
fe.getCause().printStackTrace();
} else {
fe.printStackTrace();
}
}
assertEquals("locale not as expected", expectedLocale,
page.getLocale());
}
public void testGetLocaleFromString() {
ViewTag viewTag = new ViewTag();
Locale locale = (Locale)
TestingUtil.invokePrivateMethod("getLocaleFromString",
new Class[] { String.class },
new Object[] { "fr-FR" },
ViewTag.class,
viewTag);
assertTrue(locale.equals(new Locale("fr", "FR")));
locale = (Locale)
TestingUtil.invokePrivateMethod("getLocaleFromString",
new Class[] { String.class },
new Object[] { "fr_FR" },
ViewTag.class,
viewTag);
assertTrue(locale.equals(new Locale("fr", "FR")));
locale = (Locale)
TestingUtil.invokePrivateMethod("getLocaleFromString",
new Class[] {String.class},
new Object[] {"fr"},
ViewTag.class,
viewTag);
assertTrue(locale.equals(new Locale("fr", "")));
locale = (Locale)
TestingUtil.invokePrivateMethod("getLocaleFromString",
new Class[] {String.class},
new Object[] {"testLocale"},
ViewTag.class,
viewTag);
assertTrue(locale.equals(Locale.getDefault()));
}
} // end of class TestViewTag
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/taglib/jsf_core/TestLoadBundleTag.java 0000644 0000000 0000000 00000016476 11412443352 025032 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestLoadBundleTag.java
package com.sun.faces.taglib.jsf_core;
import com.sun.faces.cactus.ServletFacesTestCase;
import com.sun.faces.util.Util;
import javax.faces.component.UIViewRoot;
import javax.faces.application.Application;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import java.util.Map;
import java.util.Locale;
public class TestLoadBundleTag extends ServletFacesTestCase {
//
// Protected Constants
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestLoadBundleTag() {
super("TestLoadBundleTag.java");
}
public TestLoadBundleTag(String name) {
super(name);
}
//
// Class methods
//
//
// General Methods
//
public void testLoadBundle() throws Exception {
getFacesContext().setViewRoot(Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null));
getFacesContext().getViewRoot().setLocale(Locale.US);
LoadBundleTag tag = new LoadBundleTag();
ExpressionFactory factory =
getFacesContext().getApplication().getExpressionFactory();
ValueExpression expr =
factory.createValueExpression(getFacesContext().getELContext(),
"com.sun.faces.TestMessages",String.class);
tag.setBasename(expr);
tag.setVar("messages");
tag.doStartTag();
assertEquals("Didn't get expected value",
((Map) getFacesContext().getExternalContext()
.getRequestMap()
.get("messages")).get("buckaroo"),
"banzai");
assertEquals("Didn't get expected value",
((Map) getFacesContext().getExternalContext()
.getRequestMap()
.get("messages")).get("john"),
"bigboote");
assertEquals("???notpresent???",
((Map) getFacesContext().getExternalContext()
.getRequestMap()
.get("messages")).get("notpresent"));
}
//test out full Map contract implementation of LoadBundleTag
public void testLoadBundleMap() throws Exception {
boolean gotException = false;
Object key = "buckaroo";
Object value = "banzai";
ExpressionFactory factory =
getFacesContext().getApplication().getExpressionFactory();
ValueExpression expr =
factory.createValueExpression(getFacesContext().getELContext(),
"com.sun.faces.TestMessages",String.class);
getFacesContext().setViewRoot(Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null));
getFacesContext().getViewRoot().setLocale(Locale.US);
LoadBundleTag tag = new LoadBundleTag();
tag.setBasename(expr);
tag.setVar("messages");
tag.doStartTag();
Map testMap = (Map) getFacesContext().getExternalContext()
.getRequestMap()
.get("messages");
LoadBundleTag tag2 = new LoadBundleTag();
tag2.setBasename(expr);
tag2.setVar("messages2");
tag2.doStartTag();
Map testMap2 = (Map) getFacesContext().getExternalContext()
.getRequestMap()
.get("messages2");
try {
testMap.clear();
} catch (UnsupportedOperationException ex) {
gotException = true;
}
assertTrue("Map.clear() should not be supported for immutable Map",
gotException);
gotException = false;
assertTrue("key not in Map", testMap.containsKey(key));
assertTrue("value not in Map", testMap.containsValue(value));
assertTrue("entrySet not correct for Map",
testMap.entrySet().equals(testMap2.entrySet()));
assertTrue("Same maps are not equal", testMap.equals(testMap2));
assertEquals("value not in Map", testMap.get(key), value);
//two equal sets should have same hashcode
assertTrue("HashCode not valid",
testMap.hashCode() == testMap2.hashCode());
assertFalse("Map should not be empty", testMap.isEmpty());
assertTrue("keySet not valid", testMap.keySet().contains(key));
try {
testMap.put(key, value);
} catch (UnsupportedOperationException ex) {
gotException = true;
}
assertTrue("Map.put() should not be supported for immutable Map",
gotException);
gotException = false;
try {
testMap.putAll(new java.util.HashMap());
} catch (UnsupportedOperationException ex) {
gotException = true;
}
assertTrue("Map.putAll() should not be supported for immutable Map",
gotException);
gotException = false;
try {
testMap.remove(key);
} catch (UnsupportedOperationException ex) {
gotException = true;
}
assertTrue("Map.remove() should not be supported for immutable Map",
gotException);
gotException = false;
assertTrue("Map size incorrect", testMap.size() == 4);
assertTrue("values from Map incorrect",
testMap.values().contains(value));
}
} // end of class TestLoadBundleTag
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/taglib/TestCoreValidator.java 0000644 0000000 0000000 00000004251 11412443352 023315 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.taglib;
import com.sun.faces.taglib.jsf_core.CoreValidator;
import org.xml.sax.helpers.DefaultHandler;
public class TestCoreValidator extends CoreValidator {
public DefaultHandler getSAXHandler() {
return super.getSAXHandler();
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/ 0000755 0000000 0000000 00000000000 11412443350 020111 5 ustar mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/PropertyResolverTestImpl.java 0000644 0000000 0000000 00000004713 11412443350 026011 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.application;
import com.sun.faces.TestPropertyResolver;
import javax.faces.el.PropertyResolver;
public class PropertyResolverTestImpl extends TestPropertyResolver{
PropertyResolver root = null;
public PropertyResolverTestImpl(PropertyResolver root) {
super(root);
this.root = root;
}
public Object getValue(Object base, Object property) {
if (property.equals("customPRTest2")) {
return "PropertyResolverTestImpl";
}
return root.getValue(base, property);
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/TestAdapters.java 0000644 0000000 0000000 00000056340 11412443350 023367 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.application;
import javax.el.ELContext;
import javax.el.MethodExpression;
import javax.el.MethodInfo;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.el.EvaluationException;
import javax.faces.el.MethodBinding;
import javax.faces.el.MethodNotFoundException;
import javax.faces.el.ValueBinding;
import javax.faces.el.PropertyNotFoundException;
import com.sun.faces.cactus.ServletFacesTestCase;
/**
* This test case will validate the various adapter classes
* found in jsf-api/template-src
*/
@SuppressWarnings("deprecation")
public class TestAdapters extends ServletFacesTestCase {
ExpressionFactory factory;
public TestAdapters() {
super("TestAdapters");
}
public TestAdapters(String name) {
super(name);
}
@Override public void setUp() {
try {
factory = (ExpressionFactory)
Class.forName("com.sun.el.ExpressionFactoryImpl").newInstance();
} catch (Exception e) {
System.out.println(e);
}
super.setUp();
}
@Override public void tearDown() {
super.tearDown();
}
// ------------------------------------------------------------ Test Methods
public void testMEMBAdapterTest() throws Exception {
// Phase 1
// - validate NPEs are thrown as expected
TestMethodBinding binding = new TestMethodBinding("#{simple.invoke}",
Double.class,
new MySimpleBean());
MethodExpressionMethodBindingAdapter meAdapter =
new MethodExpressionMethodBindingAdapter(binding);
FacesContext fContext = getFacesContext();
ExternalContext extContext = fContext.getExternalContext();
TestMethodExpression methodExpr = new TestMethodExpression("invoke",
"#{foo.invoke}",
Double.class,
new Class[] { String.class },
new MySimpleBean());
TestMethodExpression falseExpr = new TestMethodExpression("invoke",
"#{foo.invoke}",
String.class,
new Class[] { String.class },
new MySimpleBean());
extContext.getRequestMap().put("simple", new MySimpleBean());
// Phase 1
// - validate NPEs are thrown as expected
try {
meAdapter.getMethodInfo(null);
assertTrue(false);
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
assertTrue(false);
}
}
try {
meAdapter.invoke(null, new Object[] { "1.4" });
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
assertTrue(false);
}
}
// Phase 2
// - validate methods with correct input
MethodInfo info = meAdapter.getMethodInfo(fContext.getELContext());
assertTrue(Double.class.equals(info.getReturnType()));
Object obj = meAdapter.invoke(fContext.getELContext(), new Object[] { "1.3" });
assertTrue (obj instanceof Double);
assertTrue ("1.3".equals(obj.toString()));
// Phase 3
// - validate the equals() method
assertTrue(!meAdapter.equals(null));
// if the reference is to the same object, it should return true
assertTrue(meAdapter.equals(meAdapter));
// if the argument passed is another MethodExpressionMethodBindingAdapter
// with the same binding, it should return true
MethodExpressionMethodBindingAdapter meTrue =
new MethodExpressionMethodBindingAdapter(binding);
MethodExpressionMethodBindingAdapter meFalse =
new MethodExpressionMethodBindingAdapter(new TestMethodBinding("#{foo.invoke}",
String.class,
new MySimpleBean()));
assertTrue(meAdapter.equals(meTrue));
assertTrue(!meAdapter.equals(meFalse));
// if a MethodBinding is provided, then a little more work will
// be performed - ensure this works
if (factory != null) {
ApplicationAssociate.getInstance(extContext).setExpressionFactory(factory);
assertTrue(meAdapter.equals(methodExpr));
assertTrue(!meAdapter.equals(falseExpr));
}
}
public void testMBMEAdapterTest() throws Exception {
TestMethodExpression expression = new TestMethodExpression("invoke",
"#{simple.invoke}",
Double.class,
new Class[] { String.class },
new MySimpleBean());
MethodBindingMethodExpressionAdapter mbAdapter =
new MethodBindingMethodExpressionAdapter(expression);
FacesContext fContext = getFacesContext();
ExternalContext extContext = fContext.getExternalContext();
TestMethodBinding methodBinding = new TestMethodBinding("#{foo.invoke}",
Double.class,
new MySimpleBean());
TestMethodBinding falseBinding = new TestMethodBinding("#{foo.invoke}",
String.class,
new MySimpleBean());
extContext.getRequestMap().put("foo", new MySimpleBean());
// Phase 1
// - validate NPEs are thrown as expected
try {
mbAdapter.getType(null);
assertTrue(false);
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
assertTrue(false);
}
}
try {
mbAdapter.invoke(null, new Object[]{ "" });
assertTrue(false);
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
assertTrue(false);
}
}
// Phase 2
// - validate methods with correct input
assertTrue(Double.class.equals(mbAdapter.getType(fContext)));
Object obj = mbAdapter.invoke(fContext, new Object[] { "1.3" });
assertTrue (obj instanceof Double);
assertTrue ("1.3".equals(obj.toString()));
// Phase 3
// - validate the equals() method
assertTrue(!mbAdapter.equals(null));
// if the reference is to the same object, it should return true
assertTrue(mbAdapter.equals(mbAdapter));
// if the argument passed is another MethodExpressionMethodBindingAdapter
// with the same binding, it should return true
MethodBindingMethodExpressionAdapter mbTrue =
new MethodBindingMethodExpressionAdapter(expression);
MethodBindingMethodExpressionAdapter mbFalse =
new MethodBindingMethodExpressionAdapter(new TestMethodExpression("invoke",
"#{foo.invoke}",
String.class,
new Class[] { Double.class },
new MySimpleBean()));
assertTrue(mbAdapter.equals(mbTrue));
assertTrue(!mbAdapter.equals(mbFalse));
// if a MethodBinding is provided, then a little more work will
// be performed - ensure this works
if (factory != null) {
ApplicationAssociate.getInstance(extContext).setExpressionFactory(factory);
assertTrue(mbAdapter.equals(methodBinding));
assertTrue(!mbAdapter.equals(falseBinding));
}
}
public void testVEVBAdapterTest() throws Exception {
TestValueBinding binding = new TestValueBinding("#{simple.double}",
new MySimpleBean(),
Double.class);
ValueExpressionValueBindingAdapter veAdapter =
new ValueExpressionValueBindingAdapter(binding);
FacesContext fContext = getFacesContext();
ELContext elContext = fContext.getELContext();
// Phase 1
// - validate NPEs are thrown as expected
try {
veAdapter.getType(null);
assertTrue(false);
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
assertTrue(false);
}
}
try {
veAdapter.getValue(null);
assertTrue(false);
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
assertTrue(false);
}
}
try {
veAdapter.setValue(null, "string");
assertTrue(false);
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
assertTrue(false);
}
}
try {
veAdapter.isReadOnly(null);
assertTrue(false);
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
assertTrue(false);
}
}
// Phase 2
// - validate methods with correct input
assertTrue(Double.class.equals(veAdapter.getType(elContext)));
assertTrue(Double.valueOf("1.5").equals(veAdapter.getValue(elContext)));
assertTrue(veAdapter.isReadOnly(elContext));
// Phase 3
// - validate the equals() method
assertTrue(veAdapter.equals(veAdapter));
ValueExpressionValueBindingAdapter trueAdapter =
new ValueExpressionValueBindingAdapter(binding);
ValueExpressionValueBindingAdapter falseAdapter =
new ValueExpressionValueBindingAdapter(
new TestValueBinding("#{simple.double}",
new MySimpleBean(),
String.class));
assertTrue(veAdapter.equals(trueAdapter));
assertTrue(!veAdapter.equals(falseAdapter));
ValueExpression trueVE = new TestValueExpression("#{ping.double}",
Double.class,
new MySimpleBean());
ValueExpression falseVE = new TestValueExpression("#{foo.double}",
String.class,
new MySimpleBean());
assertTrue(veAdapter.equals(trueVE));
assertTrue(!veAdapter.equals(falseVE));
}
public void testVBVEAdapterTest() throws Exception {
ValueExpression expression = new TestValueExpression("#{simple.double}",
Double.class,
new MySimpleBean());
ValueBindingValueExpressionAdapter vbAdapter =
new ValueBindingValueExpressionAdapter(expression);
FacesContext fContext = getFacesContext();
// Phase 1
// - validate NPEs are thrown as expected
try {
vbAdapter.getType(null);
assertTrue(false);
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
assertTrue(false);
}
}
try {
vbAdapter.getValue(null);
assertTrue(false);
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
assertTrue(false);
}
}
try {
vbAdapter.isReadOnly(null);
assertTrue(false);
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
assertTrue(false);
}
}
try {
vbAdapter.setValue(null, "string");
assertTrue(false);
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
assertTrue(false);
}
}
// Phase 2
// - validate methods with correct input
assertTrue(Double.class.equals(vbAdapter.getType(fContext)));
assertTrue(new Double(1.5).equals(vbAdapter.getValue(fContext)));
assertTrue(vbAdapter.isReadOnly(fContext));
// Phase 3
// - validate the equals() method
assertTrue(vbAdapter.equals(vbAdapter));
ValueBindingValueExpressionAdapter trueAdapter =
new ValueBindingValueExpressionAdapter(expression);
ValueBindingValueExpressionAdapter falseAdapter =
new ValueBindingValueExpressionAdapter(
new TestValueExpression("#{foo.double}",
String.class,
new MySimpleBean()));
assertTrue(vbAdapter.equals(trueAdapter));
assertTrue(!vbAdapter.equals(falseAdapter));
ValueBinding trueVB = new TestValueBinding("#{ping.double}",
new MySimpleBean(),
Double.class);
ValueBinding falseVB = new TestValueBinding("#{foo.double}",
new MySimpleBean(),
String.class);
assertTrue(vbAdapter.equals(trueVB));
assertTrue(!vbAdapter.equals(falseVB));
}
// ----------------------------------------------------------- Inner Classes
private static class MySimpleBean {
Double value = 1.5;
public Double getDouble() {
return value;
}
public Double invoke(String value) {
return Double.valueOf(value);
}
public String invoked(String value) {
return value;
}
}
private static class TestValueExpression extends ValueExpression {
private String expr;
private Class> returnType;
private MySimpleBean bean;
public TestValueExpression(String expr,
Class> returnType,
MySimpleBean bean) {
this.expr = expr;
this.returnType = returnType;
this.bean = bean;
}
public Object getValue(ELContext elContext) {
if (elContext == null) {
throw new NullPointerException();
}
return bean.getDouble();
}
public void setValue(ELContext elContext, Object object) {
if (elContext == null) {
throw new NullPointerException();
}
}
public boolean isReadOnly(ELContext elContext) {
if (elContext == null) {
throw new NullPointerException();
}
return true;
}
public Class> getType(ELContext elContext) {
if (elContext == null) {
throw new NullPointerException();
}
return returnType;
}
public Class> getExpectedType() {
return returnType;
}
public String getExpressionString() {
return expr;
}
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof TestValueExpression) {
TestValueExpression v = (TestValueExpression) object;
return v.getExpressionString().equals(expr)
&& v.getExpectedType().equals(returnType);
}
return false;
}
public int hashCode() {
return (expr.hashCode() ^ returnType.hashCode());
}
public boolean isLiteralText() {
return false;
}
}
private static class TestValueBinding extends ValueBinding {
String expr;
MySimpleBean bean;
Class> returnType;
public TestValueBinding(String expr,
MySimpleBean bean,
Class> returnType) {
this.expr = expr;
this.bean = bean;
this.returnType = returnType;
}
public Object getValue(FacesContext context)
throws EvaluationException, PropertyNotFoundException {
if (context == null) {
throw new NullPointerException();
}
return bean.getDouble();
}
public void setValue(FacesContext context, Object value)
throws EvaluationException, PropertyNotFoundException {
if (context == null) {
throw new NullPointerException();
}
}
public boolean isReadOnly(FacesContext context)
throws EvaluationException, PropertyNotFoundException {
if (context == null) {
throw new NullPointerException();
}
return true;
}
public Class getType(FacesContext context)
throws EvaluationException, PropertyNotFoundException {
if (context == null) {
throw new NullPointerException();
}
return returnType;
}
}
private static class TestMethodBinding extends MethodBinding {
String exprString;
Class> returnType;
MySimpleBean bean;
public TestMethodBinding(String exprString,
Class> returnType,
MySimpleBean bean) {
this.exprString = exprString;
this.returnType = returnType;
this.bean = bean;
}
public Object invoke(FacesContext context, Object[] params)
throws EvaluationException, MethodNotFoundException {
if (context == null) {
throw new NullPointerException();
}
return bean.invoke((String) params[0]);
}
public Class getType(FacesContext context) throws MethodNotFoundException {
if (context == null) {
throw new NullPointerException();
}
return returnType;
}
@Override public String getExpressionString() {
return exprString;
}
}
private static class TestMethodExpression extends MethodExpression {
private String methodName;
private String exprString;
private Class> returnType;
private Class>[] params;
private MySimpleBean bean;
private MethodInfo info;
public TestMethodExpression(String methodName,
String exprString,
Class> returnType,
Class>[] params,
MySimpleBean bean) {
this.methodName = methodName;
this.exprString = exprString;
this.returnType = returnType;
this.params = params;
this.bean = bean;
info = new MethodInfo(methodName, returnType, params);
}
public MethodInfo getMethodInfo(ELContext elContext) {
if (elContext == null) {
throw new NullPointerException();
}
return info;
}
public Object invoke(ELContext elContext, Object[] objects) {
if (elContext == null) {
throw new NullPointerException();
}
return bean.invoke((String) objects[0]);
}
public String getExpressionString() {
return exprString;
}
public boolean equals(Object object) {
return this == object
|| object instanceof TestMethodExpression
&& (exprString.equals(
((TestMethodExpression) object).getExpressionString()));
}
public int hashCode() {
return exprString.hashCode();
}
public boolean isLiteralText() {
return false;
}
}
} // END TestAdapters mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/TestApplicationFactoryImpl.java 0000644 0000000 0000000 00000010610 11412443350 026227 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestApplicationFactoryImpl.java
package com.sun.faces.application;
import com.sun.faces.cactus.JspFacesTestCase;
import com.sun.faces.config.ConfigureListener;
import javax.faces.application.Application;
/**
* TestApplicationFactoryImpl is a class ...
*
*/
public class TestApplicationFactoryImpl extends JspFacesTestCase {
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
private ApplicationFactoryImpl applicationFactory = null;
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestApplicationFactoryImpl() {
super("TestApplicationFactoryImpl");
}
public TestApplicationFactoryImpl(String name) {
super(name);
}
//
// Class methods
//
//
// General Methods
//
public void testFactory() {
applicationFactory = new ApplicationFactoryImpl();
ApplicationAssociate.clearInstance(getFacesContext().getExternalContext());
// 1. Verify "getApplication" returns the same Application instance
// if called multiple times.
//
Application application1 = applicationFactory.getApplication();
Application application2 = applicationFactory.getApplication();
assertTrue(application1 == application2);
// 2. Verify "setApplication" adds instances.. /
// and "getApplication" returns the same instance
//
ApplicationAssociate.clearInstance(getFacesContext().getExternalContext());
Application application3 = new ApplicationImpl();
applicationFactory.setApplication(application3);
Application application4 = applicationFactory.getApplication();
assertTrue(application3 == application4);
}
public void testSpecCompliance() {
applicationFactory = new ApplicationFactoryImpl();
ApplicationAssociate.clearInstance(getFacesContext().getExternalContext());
assertTrue(null != applicationFactory.getApplication());
}
public void testExceptions() {
applicationFactory = new ApplicationFactoryImpl();
// 1. Verify NullPointer exception which occurs when attempting
// to add a null Application
//
boolean thrown = false;
try {
applicationFactory.setApplication(null);
} catch (NullPointerException e) {
thrown = true;
}
assertTrue(thrown);
}
} // end of class TestApplicationFactoryImpl
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/VariableResolverTestImpl.java 0000644 0000000 0000000 00000004261 11412443350 025710 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.application;
import com.sun.faces.TestVariableResolver;
import javax.faces.el.VariableResolver;
public class VariableResolverTestImpl extends TestVariableResolver {
public VariableResolverTestImpl(VariableResolver root) {
super(root);
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/TestHASDeprStateManagerImpl.java 0000644 0000000 0000000 00000013751 11412443350 026167 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.application;
import org.apache.cactus.WebRequest;
import org.apache.cactus.server.ServletConfigWrapper;
import com.sun.faces.RIConstants;
import com.sun.faces.cactus.ServletFacesTestCase;
import com.sun.faces.util.Util;
import javax.faces.FacesException;
import javax.faces.application.StateManager;
import javax.faces.application.ViewHandler;
import javax.faces.application.StateManager.SerializedView;
import javax.faces.component.UIComponent;
import javax.faces.component.UIGraphic;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
import javax.faces.component.UIViewRoot;
import javax.faces.component.UIForm;
import javax.faces.component.UIPanel;
import javax.faces.context.FacesContext;
import javax.faces.render.RenderKitFactory;
import javax.servlet.http.HttpSession;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;
/**
* This class tests the
*/
public class TestApplicationImpl_Config extends ServletFacesTestCase {
//
// Protected Constants
//
public static String standardComponentTypes[] = {
"javax.faces.Column",
"javax.faces.Command",
"javax.faces.Data",
"javax.faces.Form",
"javax.faces.Graphic",
"javax.faces.Input",
"javax.faces.Message",
"javax.faces.Messages",
"javax.faces.NamingContainer",
"javax.faces.Output",
"javax.faces.Panel",
"javax.faces.Parameter",
"javax.faces.SelectBoolean",
"javax.faces.SelectItem",
"javax.faces.SelectItems",
"javax.faces.SelectMany",
"javax.faces.SelectOne",
"javax.faces.ViewRoot",
"javax.faces.HtmlCommandButton",
"javax.faces.HtmlCommandLink",
"javax.faces.HtmlDataTable",
"javax.faces.HtmlForm",
"javax.faces.HtmlGraphicImage",
"javax.faces.HtmlInputHidden",
"javax.faces.HtmlInputSecret",
"javax.faces.HtmlInputText",
"javax.faces.HtmlInputTextarea",
"javax.faces.HtmlMessage",
"javax.faces.HtmlMessages",
"javax.faces.HtmlOutputFormat",
"javax.faces.HtmlOutputLabel",
"javax.faces.HtmlOutputLink",
"javax.faces.HtmlOutputText",
"javax.faces.HtmlPanelGrid",
"javax.faces.HtmlPanelGroup",
"javax.faces.HtmlSelectBooleanCheckbox",
"javax.faces.HtmlSelectManyCheckbox",
"javax.faces.HtmlSelectManyListbox",
"javax.faces.HtmlSelectManyMenu",
"javax.faces.HtmlSelectOneListbox",
"javax.faces.HtmlSelectOneMenu",
"javax.faces.HtmlSelectOneRadio"
};
public static Class standardComponentClasses[] = {
javax.faces.component.UIColumn.class,
javax.faces.component.UICommand.class,
javax.faces.component.UIData.class,
javax.faces.component.UIForm.class,
javax.faces.component.UIGraphic.class,
javax.faces.component.UIInput.class,
javax.faces.component.UIMessage.class,
javax.faces.component.UIMessages.class,
javax.faces.component.UINamingContainer.class,
javax.faces.component.UIOutput.class,
javax.faces.component.UIPanel.class,
javax.faces.component.UIParameter.class,
javax.faces.component.UISelectBoolean.class,
javax.faces.component.UISelectItem.class,
javax.faces.component.UISelectItems.class,
javax.faces.component.UISelectMany.class,
javax.faces.component.UISelectOne.class,
javax.faces.component.UIViewRoot.class,
javax.faces.component.html.HtmlCommandButton.class,
javax.faces.component.html.HtmlCommandLink.class,
javax.faces.component.html.HtmlDataTable.class,
javax.faces.component.html.HtmlForm.class,
javax.faces.component.html.HtmlGraphicImage.class,
javax.faces.component.html.HtmlInputHidden.class,
javax.faces.component.html.HtmlInputSecret.class,
javax.faces.component.html.HtmlInputText.class,
javax.faces.component.html.HtmlInputTextarea.class,
javax.faces.component.html.HtmlMessage.class,
javax.faces.component.html.HtmlMessages.class,
javax.faces.component.html.HtmlOutputFormat.class,
javax.faces.component.html.HtmlOutputLabel.class,
javax.faces.component.html.HtmlOutputLink.class,
javax.faces.component.html.HtmlOutputText.class,
javax.faces.component.html.HtmlPanelGrid.class,
javax.faces.component.html.HtmlPanelGroup.class,
javax.faces.component.html.HtmlSelectBooleanCheckbox.class,
javax.faces.component.html.HtmlSelectManyCheckbox.class,
javax.faces.component.html.HtmlSelectManyListbox.class,
javax.faces.component.html.HtmlSelectManyMenu.class,
javax.faces.component.html.HtmlSelectOneListbox.class,
javax.faces.component.html.HtmlSelectOneMenu.class,
javax.faces.component.html.HtmlSelectOneRadio.class
};
public static String standardConverterIds[] = {
"javax.faces.BigDecimal",
"javax.faces.BigInteger",
"javax.faces.Boolean",
"javax.faces.Byte",
"javax.faces.Character",
"javax.faces.DateTime",
"javax.faces.Double",
"javax.faces.Float",
"javax.faces.Integer",
"javax.faces.Long",
"javax.faces.Number",
"javax.faces.Short"
};
public static Class standardConverterClasses[] = {
javax.faces.convert.BigDecimalConverter.class,
javax.faces.convert.BigIntegerConverter.class,
javax.faces.convert.BooleanConverter.class,
javax.faces.convert.ByteConverter.class,
javax.faces.convert.CharacterConverter.class,
javax.faces.convert.DateTimeConverter.class,
javax.faces.convert.DoubleConverter.class,
javax.faces.convert.FloatConverter.class,
javax.faces.convert.IntegerConverter.class,
javax.faces.convert.LongConverter.class,
javax.faces.convert.NumberConverter.class,
javax.faces.convert.ShortConverter.class
};
public static Class standardConverterByIdClasses[] = {
java.math.BigDecimal.class,
java.math.BigInteger.class,
java.lang.Boolean.class,
java.lang.Byte.class,
java.lang.Character.class,
null,
java.lang.Double.class,
java.lang.Float.class,
java.lang.Integer.class,
java.lang.Long.class,
null,
java.lang.Short.class
};
public static Class standardConverterPrimitiveClasses[] = {
null,
null,
java.lang.Boolean.TYPE,
java.lang.Byte.TYPE,
java.lang.Character.TYPE,
null,
java.lang.Double.TYPE,
java.lang.Float.TYPE,
java.lang.Integer.TYPE,
java.lang.Long.TYPE,
null,
java.lang.Short.TYPE
};
//
// Class Variables
//
//
// Instance Variables
//
private ApplicationImpl application = null;
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestApplicationImpl_Config() {
super("TestApplicationImpl_Config");
}
public TestApplicationImpl_Config(String name) {
super(name);
}
//
// Class methods
//
//
// General Methods
//
public void setUp() {
super.setUp();
ApplicationFactory aFactory =
(ApplicationFactory) FactoryFinder.getFactory(
FactoryFinder.APPLICATION_FACTORY);
application = (ApplicationImpl) aFactory.getApplication();
}
//****
//**** NOTE: We should add a test for finding a faces-config.xml file under
//**** WEB-INF/classes/META-INF.
//****
//
// Test Config related methods
//
public void testComponentPositive() {
TestComponent
newTestComponent = null,
testComponent = new TestComponent();
UIComponent uic = null;
// runtime addition
application.addComponent(testComponent.getComponentType(),
"com.sun.faces.TestComponent");
assertTrue(
null !=
(newTestComponent =
(TestComponent)
application.createComponent(testComponent.getComponentType())));
assertTrue(newTestComponent != testComponent);
// built-in components
for (int i = 0, len = standardComponentTypes.length; i < len; i++) {
assertTrue(null != (uic =
application.createComponent(
standardComponentTypes[i])));
assertTrue(
standardComponentClasses[i].isAssignableFrom(uic.getClass()));
}
}
public void testComponentNegative() {
boolean exceptionThrown = false;
// componentType/componentClass with non-existent class
try {
application.addComponent("William",
"BillyBoy");
application.createComponent("William");
} catch (FacesException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
// non-existent mapping
exceptionThrown = false;
try {
application.createComponent("Joebob");
} catch (FacesException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
public void testGetComponentTypes() {
Iterator iter = application.getComponentTypes();
assertTrue(null != iter);
assertTrue(isSubset(standardComponentTypes, iter));
}
public void testConverterPositive() {
TestConverter
newTestConverter = null,
testConverter = new TestConverter();
Converter conv = null;
// runtime addition
application.addConverter(testConverter.getConverterId(),
"com.sun.faces.TestConverter");
assertTrue(
null !=
(newTestConverter =
(TestConverter)
application.createConverter(testConverter.getConverterId())));
assertTrue(newTestConverter != testConverter);
// built-in components
// by-id
for (int i = 0, len = standardConverterIds.length; i < len; i++) {
assertTrue(null != (conv =
application.createConverter(
standardConverterIds[i])));
assertTrue(
standardConverterClasses[i].isAssignableFrom(conv.getClass()));
}
// by-class
for (int i = 0, len = standardConverterByIdClasses.length; i < len; i++) {
// skip entries for which by-class registation doesn't make sense.
if (null == standardConverterByIdClasses[i]) {
continue;
}
assertTrue("null != " + standardConverterByIdClasses[i].toString(),
null !=
(conv =
application.createConverter(
standardConverterByIdClasses[i])));
assertTrue(
standardConverterClasses[i].isAssignableFrom(conv.getClass()));
}
// primitive classes
for (int i = 0, len = standardConverterPrimitiveClasses.length; i <
len; i++) {
if (null == standardConverterPrimitiveClasses[i]) {
continue;
}
assertTrue(
"null != " + standardConverterPrimitiveClasses[i].toString(),
null !=
(conv =
application.createConverter(
standardConverterPrimitiveClasses[i])));
assertTrue(
standardConverterClasses[i].isAssignableFrom(conv.getClass()));
}
}
public void testConverterNegative() {
boolean exceptionThrown = false;
// componentType/componentClass with non-existent class
try {
application.addConverter("William",
"BillyBoy");
application.createConverter("William");
} catch (FacesException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
// non-existent mapping
exceptionThrown = false;
try {
application.createConverter("Joebob");
} catch (FacesException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
public void testGetConverterIds() {
Iterator iter = application.getConverterIds();
assertTrue(null != iter);
assertTrue(isSubset(standardConverterIds, iter));
}
public void testValidatorPositive() {
Validator
newTestValidator = null,
testValidator = new LengthValidator();
Validator val = null;
// runtime addition
application.addValidator("Billybob",
"javax.faces.validator.LengthValidator");
assertTrue(null != (newTestValidator =
application.createValidator("Billybob")));
assertTrue(newTestValidator != testValidator);
// test standard components
assertTrue(
null !=
(val = application.createValidator("javax.faces.DoubleRange")));
assertTrue(val instanceof Validator);
assertTrue(
null != (val = application.createValidator("javax.faces.Length")));
assertTrue(val instanceof Validator);
assertTrue(
null !=
(val = application.createValidator("javax.faces.LongRange")));
assertTrue(val instanceof Validator);
}
public void testValidatorNegative() {
boolean exceptionThrown = false;
// componentType/componentClass with non-existent class
try {
application.addValidator("William",
"BillyBoy");
application.createValidator("William");
} catch (FacesException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
// non-existent mapping
exceptionThrown = false;
try {
application.createValidator("Joebob");
} catch (FacesException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
public void testGetValidatorIds() {
Iterator iter = application.getValidatorIds();
assertTrue(null != iter);
String standardValidatorIds[] = {
"javax.faces.DoubleRange",
"javax.faces.Length",
"javax.faces.LongRange"
};
assertTrue(isSubset(standardValidatorIds, iter));
}
public void testUpdateRuntimeComponents() {
loadFromInitParam("/runtime-components.xml");
ApplicationFactory aFactory =
(ApplicationFactory) FactoryFinder.getFactory(
FactoryFinder.APPLICATION_FACTORY);
application = (ApplicationImpl) aFactory.getApplication();
ActionListener actionListener = null;
NavigationHandler navHandler = null;
PropertyResolver propResolver = null;
VariableResolver varResolver = null;
ViewHandler viewHandler = null;
StateManager stateManager = null;
assertTrue(null != (actionListener =
application.getActionListener()));
assertTrue(actionListener instanceof com.sun.faces.TestActionListener);
assertTrue(null != (navHandler =
application.getNavigationHandler()));
assertTrue(navHandler instanceof com.sun.faces.TestNavigationHandler);
// JSF1.2 BI: application.getPropertyResolver() no longer returns the
// head of the PropertyResolver. Instead returns the head of the
// ELResolver stack wrapped in a PropertyResolver.This also applies to
// VariableResolver
assertTrue(null != (propResolver =
application.getPropertyResolver()));
assertTrue(
application.getPropertyResolver() instanceof javax.faces.el.PropertyResolver);
assertTrue(null != (varResolver =
application.getVariableResolver()));
assertTrue(varResolver instanceof javax.faces.el.VariableResolver);
assertTrue(null != (viewHandler =
application.getViewHandler()));
assertTrue(viewHandler instanceof javax.faces.application.ViewHandler);
assertTrue(null != (stateManager =
application.getStateManager()));
assertTrue(
stateManager instanceof javax.faces.application.StateManager);
System.out.println("DEFAULT:" + application.getDefaultRenderKitId());
assertEquals("WackyRenderKit", application.getDefaultRenderKitId());
}
public void testLocaleConfigPositive() {
loadFromInitParam("/locale-config.xml");
ApplicationFactory aFactory =
(ApplicationFactory) FactoryFinder.getFactory(
FactoryFinder.APPLICATION_FACTORY);
application = (ApplicationImpl) aFactory.getApplication();
Locale locale;
assertNotNull("Can't get default locale from Application",
locale = application.getDefaultLocale());
assertEquals(Locale.US, locale);
Iterator iter;
int j = 0, len = 0;
boolean found = false;
String[][] expected = {
{"de", "DE"},
{"en", "US"},
{"fr", "FR"},
{"ps", "PS"}
};
len = expected.length;
iter = application.getSupportedLocales();
System.out.println("actual supported locales: ");
while (iter.hasNext()) {
System.out.println(iter.next().toString());
}
// test that the supported locales are a superset of the
// expected locales
for (j = 0; j < len; j++) {
assertNotNull("Can't get supportedLocales from Application",
iter = application.getSupportedLocales());
found = false;
while (iter.hasNext()) {
locale = (Locale) iter.next();
if (expected[j][0].equals(locale.getLanguage()) &&
expected[j][1].equals(locale.getCountry())) {
found = true;
}
}
assertTrue("Can't find expected locale " + expected[j][0] + "_" +
expected[j][1] + " in supported-locales list",
found);
}
}
public void testLocaleConfigNegative2() {
boolean exceptionThrown = false;
try {
loadFromInitParam("/locale-config2.xml");
} catch (FacesException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
} // end of class TestApplicationImpl_Config
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/TestActionListenerImpl.java 0000644 0000000 0000000 00000014543 11412443350 025370 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestActionListenerImpl.java
package com.sun.faces.application;
import com.sun.faces.cactus.ServletFacesTestCase;
import com.sun.faces.util.Util;
import javax.faces.FacesException;
import javax.faces.component.UICommand;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;
import javax.faces.el.MethodNotFoundException;
import javax.faces.event.ActionEvent;
import java.util.Locale;
/**
*
* TestActionListenerImpl is a class ...
*
* Lifetime And Scope
*
*/
/**
* This class tests the
*/
public class TestApplicationImpl extends JspFacesTestCase {
//
// Protected Constants
//
public static final String HANDLED_ACTIONEVENT1 = "handledValueEvent1";
public static final String HANDLED_ACTIONEVENT2 = "handledValueEvent2";
//
// Class Variables
//
//
// Instance Variables
//
private ApplicationImpl application = null;
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestApplicationImpl() {
super("TestApplicationImpl");
}
public TestApplicationImpl(String name) {
super(name);
}
//
// Class methods
//
//
// General Methods
//
public void setUp() {
super.setUp();
ApplicationFactory aFactory =
(ApplicationFactory) FactoryFinder.getFactory(
FactoryFinder.APPLICATION_FACTORY);
application = (ApplicationImpl) aFactory.getApplication();
}
public void testAccessors() {
assertTrue(application.getELResolver() != null);
assertTrue(application.getExpressionFactory() != null);
// 1. Verify "getActionListener" returns the same ActionListener
// instance if called multiple times.
//
ActionListener actionListener1 = new ValidActionListener();
application.setActionListener(actionListener1);
ActionListener actionListener2 = application.getActionListener();
ActionListener actionListener3 = application.getActionListener();
assertTrue((actionListener1 == actionListener2) &&
(actionListener1 == actionListener3));
// 2. Verify "getNavigationHandler" returns the same NavigationHandler
// instance if called multiple times.
//
NavigationHandler navigationHandler1 = new NavigationHandlerImpl();
application.setNavigationHandler(navigationHandler1);
NavigationHandler navigationHandler2 = application.getNavigationHandler();
NavigationHandler navigationHandler3 = application.getNavigationHandler();
assertTrue((navigationHandler1 == navigationHandler2) &&
(navigationHandler1 == navigationHandler3));
// 3. Verify "getPropertyResolver" returns the same PropertyResolver
// instance if called multiple times.
//
PropertyResolver propertyResolver1 = application.getPropertyResolver();
PropertyResolver propertyResolver2 = application.getPropertyResolver();
PropertyResolver propertyResolver3 = application.getPropertyResolver();
assertTrue((propertyResolver1 == propertyResolver2) &&
(propertyResolver1 == propertyResolver3));
// 4. Verify "getVariableResolver" returns the same VariableResolver
// instance if called multiple times.
//
VariableResolver variableResolver1 = application.getVariableResolver();
VariableResolver variableResolver2 = application.getVariableResolver();
VariableResolver variableResolver3 = application.getVariableResolver();
assertTrue((variableResolver1 == variableResolver2) &&
(variableResolver1 == variableResolver3));
// 5. Verify "getStateManager" returns the same StateManager
// instance if called multiple times.
//
StateManager stateManager1 = new StateManagerImpl();
application.setStateManager(stateManager1);
StateManager stateManager2 = application.getStateManager();
StateManager stateManager3 = application.getStateManager();
assertTrue((stateManager1 == stateManager2) &&
(stateManager1 == stateManager3));
}
public void testExceptions() {
boolean thrown;
// 1. Verify NullPointer exception which occurs when attempting
// to set a null ActionListener
//
thrown = false;
try {
application.setActionListener(null);
} catch (NullPointerException e) {
thrown = true;
}
assertTrue(thrown);
// 3. Verify NullPointer exception which occurs when attempting
// to set a null NavigationHandler
//
thrown = false;
try {
application.setNavigationHandler(null);
} catch (NullPointerException e) {
thrown = true;
}
assertTrue(thrown);
// 4. Verify NPE occurs when attempting to set
// a null PropertyResolver
thrown = false;
try {
application.setPropertyResolver(null);
} catch (NullPointerException npe) {
thrown = true;
}
assertTrue(thrown);
// 5. Verify NPE occurs when attempting to set
// a null VariableResolver
thrown = false;
try {
application.setVariableResolver(null);
} catch (NullPointerException npe) {
thrown = true;
}
assertTrue(thrown);
// 5. Verify ISE occurs when attempting to set
// a VariableResolver after a request has been processed
ApplicationAssociate associate =
ApplicationAssociate.getInstance(
getFacesContext().getExternalContext());
associate.setRequestServiced();
thrown = false;
try {
application.setVariableResolver(application.getVariableResolver());
} catch (IllegalStateException e) {
thrown = true;
}
assertTrue(thrown);
// 6. Verify ISE occurs when attempting to set
// a PropertyResolver after a request has been processed
thrown = false;
try {
application.setPropertyResolver(application.getPropertyResolver());
} catch (IllegalStateException e) {
thrown = true;
}
assertTrue(thrown);
// 7. Verify NullPointer exception which occurs when attempting
// to get a ValueBinding with a null ref
//
thrown = false;
try {
application.createValueBinding(null);
} catch (Exception e) {
thrown = true;
}
assertTrue(thrown);
// 8.Verify NullPointerException occurs when attempting to pass a
// null VariableResolver
//
thrown = false;
try {
application.setVariableResolver(null);
} catch (NullPointerException e) {
thrown = true;
}
assertTrue(thrown);
// 9. Verify NullPointer exception which occurs when attempting
// to set a null StateManager
//
thrown = false;
try {
application.setStateManager(null);
} catch (NullPointerException e) {
thrown = true;
}
assertTrue(thrown);
thrown = false;
try {
application.createValueBinding("improperexpression");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
thrown = false;
try {
application.createValueBinding("improper expression");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
thrown = false;
try {
application.createValueBinding("improper\texpression");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
thrown = false;
try {
application.createValueBinding("improper\rexpression");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
thrown = false;
try {
application.createValueBinding("improper\nexpression");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
thrown = false;
try {
application.createValueBinding("#improperexpression");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
thrown = false;
try {
application.createValueBinding("#{improperexpression");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertTrue(thrown);
thrown = false;
try {
application.createValueBinding("improperexpression}");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
thrown = false;
try {
application.createValueBinding("{improperexpression}");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
thrown = false;
try {
application.createValueBinding("improperexpression}#");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
thrown = false;
try {
application.createValueBinding("#{proper[\"a key\"]}");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
try {
application.createValueBinding("#{proper[\"a { } key\"]}");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
try {
application.createValueBinding("bean.a{indentifer");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
thrown = false;
try {
application.createValueBinding("bean['invalid'");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
thrown = false;
try {
application.createValueBinding("bean[[\"invalid\"]].foo");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
thrown = false;
try {
application.createValueBinding("#{bean[\"[a\"]}");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
try {
application.createValueBinding("#{bean[\".a\"]}");
} catch (ReferenceSyntaxException e) {
thrown = true;
}
assertFalse(thrown);
}
public class InvalidActionListener implements ActionListener {
public void processAction(ActionEvent event) {
System.setProperty(HANDLED_ACTIONEVENT1, HANDLED_ACTIONEVENT1);
}
}
public class ValidActionListener implements ActionListener {
public void processAction(ActionEvent event) {
System.setProperty(HANDLED_ACTIONEVENT2, HANDLED_ACTIONEVENT2);
}
}
//
// Test Config related methods
//
public void testAddComponentPositive() {
TestComponent
newTestComponent = null,
testComponent = new TestComponent();
application.addComponent(testComponent.getComponentType(),
"com.sun.faces.TestComponent");
assertTrue(
null !=
(newTestComponent =
(TestComponent)
application.createComponent(testComponent.getComponentType())));
assertTrue(newTestComponent != testComponent);
}
public void testCreateComponentExtension() {
application.addComponent(TestForm.COMPONENT_TYPE,
TestForm.class.getName());
UIComponent c = application.createComponent(TestForm.COMPONENT_TYPE);
assertTrue(c != null);
}
public void testGetComponentWithRefNegative() {
ValueBinding valueBinding = null;
boolean exceptionThrown = false;
UIComponent result = null;
getFacesContext().getExternalContext().getSessionMap().put("TAIBean",
this);
assertTrue(null != (valueBinding =
application.createValueBinding(
"#{sessionScope.TAIBean}")));
try {
result = application.createComponent(valueBinding, getFacesContext(),
"notreached");
assertTrue(false);
} catch (FacesException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
public void testGetComponentExpressionRefNegative() throws ELException{
ValueExpression valueBinding = null;
boolean exceptionThrown = false;
UIComponent result = null;
getFacesContext().getExternalContext().getSessionMap().put("TAIBean",
this);
assertTrue(null != (valueBinding =
application.getExpressionFactory().createValueExpression(
getFacesContext().getELContext(), "#{sessionScope.TAIBean}", Object.class)));
try {
result = application.createComponent(valueBinding, getFacesContext(),
"notreached");
assertTrue(false);
} catch (FacesException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
// make sure FacesException is thrown when a bogus ValueExpression is
// passed to createComponent. JSF RI Issue 162
assertTrue(null != (valueBinding =
application.getExpressionFactory().createValueExpression(
getFacesContext().getELContext(), "#{a.b}", Object.class)));
try {
result = application.createComponent(valueBinding, getFacesContext(),
"notreached");
assertTrue(false);
} catch (FacesException e) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
public void testSetViewHandlerException() throws Exception {
// RELEASE_PENDING - FIX. There seems to be a problem
// with the test framework exposing two different applicationassociate
// instances. As such, the flag denoting that a request has
// been processed is never flagged and thus this test fails.
/*
ViewHandler handler = new ViewHandlerImpl();
UIViewRoot root = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
root.setViewId("/view");
root.setId("id");
root.setLocale(Locale.US);
getFacesContext().setViewRoot(root);
boolean exceptionThrown = false;
try {
application.setViewHandler(handler);
} catch (IllegalStateException ise) {
exceptionThrown = true;
}
assertTrue(!exceptionThrown);
try {
handler.renderView(getFacesContext(),
getFacesContext().getViewRoot());
application.setViewHandler(handler);
} catch (IllegalStateException ise) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
// and test setting the StateManager too.
exceptionThrown = false;
try {
application.setStateManager(new StateManagerImpl());
} catch (IllegalStateException ise) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
*/
}
// Ensure ApplicationImpl.setDefaultLocale(null) throws NPE
public void testSetDefaultLocaleNPE() throws Exception {
try {
application.setDefaultLocale(null);
assertTrue(false);
} catch (NullPointerException npe) {
; // we're ok
}
}
public void testResourceBundle() throws Exception {
ResourceBundle rb = null;
UIViewRoot root = new UIViewRoot();
root.setLocale(Locale.ENGLISH);
getFacesContext().setViewRoot(root);
// negative test, non-existant rb
rb = application.getResourceBundle(getFacesContext(), "bogusName");
assertNull(rb);
// basic test, existing rb
rb = application.getResourceBundle(getFacesContext(), "testResourceBundle");
assertNotNull(rb);
String value = rb.getString("value1");
assertEquals("Jerry", value);
// switch locale to German
getFacesContext().getViewRoot().setLocale(Locale.GERMAN);
rb = application.getResourceBundle(getFacesContext(), "testResourceBundle");
assertNotNull(rb);
value = rb.getString("value1");
assertEquals("Bernhard", value);
// switch to a different rb
rb = application.getResourceBundle(getFacesContext(), "testResourceBundle2");
assertNotNull(rb);
value = rb.getString("label");
assertEquals("Abflug", value);
}
public void testLegacyPropertyResolversWithUnifiedEL() {
ValueExpression ve1 = application.getExpressionFactory().
createValueExpression(getFacesContext().getELContext(),
"#{mixedBean.customPRTest1}", Object.class);
Object result = ve1.getValue(getFacesContext().getELContext());
assertTrue(result.equals("TestPropertyResolver"));
ValueExpression ve2 = application.getExpressionFactory().
createValueExpression(getFacesContext().getELContext(),
"#{mixedBean.customPRTest2}", Object.class);
result = ve2.getValue(getFacesContext().getELContext());
assertTrue(result.equals("PropertyResolverTestImpl"));
}
public void testLegacyVariableResolversWithUnifiedEL() {
ValueExpression ve1 = application.getExpressionFactory().
createValueExpression(getFacesContext().getELContext(),
"#{customVRTest1}", Object.class);
Object result = ve1.getValue(getFacesContext().getELContext());
assertTrue(result.equals("TestVariableResolver"));
ValueExpression ve2 = application.getExpressionFactory().
createValueExpression(getFacesContext().getELContext(),
"#{customVRTest2}", Object.class);
result = ve2.getValue(getFacesContext().getELContext());
assertTrue(result.equals("TestOldVariableResolver"));
}
public void testConverterUpdate() {
FacesContext context = getFacesContext();
Application app = context.getApplication();
Converter intConverter = application.createConverter("javax.faces.Integer");
Converter intConverter2 = application.createConverter(Integer.TYPE);
Converter intConverter3 = application.createConverter(Integer.class);
assertTrue(IntegerConverter.class.equals(intConverter.getClass())
&& IntegerConverter.class.equals(intConverter2.getClass())
&& IntegerConverter.class.equals(intConverter3.getClass()));
app.addConverter("javax.faces.Integer", CustomIntConverter.class.getName());
intConverter = application.createConverter("javax.faces.Integer");
intConverter2 = application.createConverter(Integer.TYPE);
intConverter3 = application.createConverter(Integer.class);
assertTrue(CustomIntConverter.class.equals(intConverter.getClass())
&& CustomIntConverter.class.equals(intConverter2.getClass())
&& CustomIntConverter.class.equals(intConverter3.getClass()));
app.addConverter(Integer.TYPE, IntegerConverter.class.getName());
intConverter = application.createConverter("javax.faces.Integer");
intConverter2 = application.createConverter(Integer.TYPE);
intConverter3 = application.createConverter(Integer.class);
assertTrue(IntegerConverter.class.equals(intConverter.getClass())
&& IntegerConverter.class.equals(intConverter2.getClass())
&& IntegerConverter.class.equals(intConverter3.getClass()));
app.addConverter(Integer.class, CustomIntConverter.class.getName());
intConverter = application.createConverter("javax.faces.Integer");
intConverter2 = application.createConverter(Integer.TYPE);
intConverter3 = application.createConverter(Integer.class);
assertTrue(CustomIntConverter.class.equals(intConverter.getClass())
&& CustomIntConverter.class.equals(intConverter2.getClass())
&& CustomIntConverter.class.equals(intConverter3.getClass()));
// reset to the standard converter
app.addConverter("javax.faces.Integer", IntegerConverter.class.getName());
}
public void testComponentAnnotatations() throws Exception {
Application application = getFacesContext().getApplication();
application.addComponent("CustomInput", CustomOutput.class.getName());
CustomOutput c = (CustomOutput) application.createComponent("CustomInput");
CustomOutput c2 = (CustomOutput) application.createComponent("CustomInput");
UIViewRoot root = getFacesContext().getViewRoot();
root.getChildren().add(c);
root.getChildren().add(c2);
assertTrue(c.getEvent() instanceof PostAddToViewEvent);
assertTrue(c2.getEvent() instanceof PostAddToViewEvent);
List
*
*/
public class TestViewHandlerImpl extends JspFacesTestCase {
//
// Protected Constants
//
public static final String TEST_URI = "/greeting.jsp";
public String getExpectedOutputFilename() {
return "TestViewHandlerImpl_correct";
}
public static final String ignore[] = {
};
public String[] getLinesToIgnore() {
return ignore;
}
public boolean sendResponseToFile() {
return true;
}
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestViewHandlerImpl() {
super("TestViewHandlerImpl");
}
public TestViewHandlerImpl(String name) {
super(name);
}
//
// Class methods
//
//
// General Methods
//
public void beginRender(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/faces", TEST_URI, null);
}
public void beginRender2(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/somepath/greeting.jsf",
null, null);
}
public void beginTransient(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/faces", TEST_URI, null);
theRequest.addParameter("javax.faces.ViewState", "j_id1:j_id2");
}
public void beginCalculateLocaleLang(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/somepath/greeting.jsf",
null, null);
theRequest.addHeader("Accept-Language", "es-ES,tg-AF,tk-IQ,en-US");
}
public void beginCalculateLocaleExact(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/somepath/greeting.jsf",
null, null);
theRequest.addHeader("Accept-Language", "tg-AF,tk-IQ,ps-PS,en-US");
}
public void beginCalculateLocaleLowerCase(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/somepath/greeting.jsf",
null, null);
theRequest.addHeader("Accept-Language", "tg-af,tk-iq,ps-ps");
}
public void beginCalculateLocaleNoMatch(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/somepath/greeting.jsf",
null, null);
theRequest.addHeader("Accept-Language", "es-ES,tg-AF,tk-IQ");
}
public void beginCalculateLocaleFindDefault(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/somepath/greeting.jsf",
null, null);
theRequest.addHeader("Accept-Language", "en,fr");
}
public void beginRestoreViewNegative(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/faces", null, null);
}
public void testGetActionURL() {
LifecycleFactory factory = (LifecycleFactory)
FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle =
factory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
// wrap the request so we can control the return value of getServletPath
TestRequest testRequest = new TestRequest(request);
ExternalContext extContext = new ExternalContextImpl(
config.getServletContext(),
testRequest,
response);
FacesContext facesContext = new FacesContextImpl(extContext, lifecycle);
String contextPath = request.getContextPath();
ViewHandlerImpl handler = new ViewHandlerImpl();
// if getServletPath() returns "" then the viewId path returned should
// be the same as what was passed, prefixed by the context path.
//testRequest.setServletPath("");
//testRequest.setAttribute("com.sun.faces.INVOCATION_PATH", null);
//String path = handler.getActionURL(facesContext, "/test.jsp");
//System.out.println("VIEW ID PATH 1: " + path);
//assertEquals(contextPath + "/test.jsp", path);
// if getServletPath() returns a path prefix, then the viewId path
// returned must have that path prefixed.
testRequest.setServletPath("/faces");
testRequest.setPathInfo("/path/test.jsp");
RequestStateManager.remove(facesContext, RequestStateManager.INVOCATION_PATH);
String path = handler.getActionURL(facesContext, "/path/test.jsp");
System.out.println("VIEW ID PATH 2: " + path);
String expected = contextPath + "/faces/path/test.jsp";
assertEquals("Expected: " + expected + ", recieved: " + path, expected, path);
// if getServletPath() returns a path indicating extension mapping
// and the viewId passed has no extension, append the extension
// to the provided viewId
testRequest.setServletPath("/path/firstRequest.jsf");
testRequest.setPathInfo(null);
RequestStateManager.remove(facesContext, RequestStateManager.INVOCATION_PATH);
path = handler.getActionURL(facesContext, "/path/test");
System.out.println("VIEW ID PATH 3: " + path);
expected = contextPath + "/path/test";
assertEquals("Expected: " + expected + ", recieved: " + path, expected, path);
// if getServletPath() returns a path indicating extension mapping
// and the viewId passed has an extension, replace the extension with
// the extension defined in the deployment descriptor
testRequest.setServletPath("/path/firstRequest.jsf");
testRequest.setPathInfo(null);
RequestStateManager.remove(facesContext, RequestStateManager.INVOCATION_PATH);
path = handler.getActionURL(facesContext, "/path/t.est.jsp");
System.out.println("VIEW ID PATH 4: " + path);
expected = contextPath + "/path/t.est.jsf";
assertEquals("Expected: " + expected + ", recieved: " + path, expected, path);
// if path info is null, the impl must check to see if
// there is an exact match on the servlet path, if so, return
// the servlet path
testRequest.setServletPath("/faces");
testRequest.setPathInfo(null);
RequestStateManager.remove(facesContext, RequestStateManager.INVOCATION_PATH);
path = handler.getActionURL(facesContext, "/path/t.est");
System.out.println("VIEW ID PATH 5: " + path);
expected = contextPath + "/faces/path/t.est";
assertEquals("Expected: " + expected + ", recieved: " + path, expected, path);
}
public void testFullAndPartialStateConfiguration() throws Exception {
WebConfiguration webConfig =
WebConfiguration.getInstance();
webConfig.overrideContextInitParameter(WebConfiguration.BooleanWebContextInitParameter.PartialStateSaving, true);
ApplicationAssociate associate = ApplicationAssociate.getCurrentInstance();
ApplicationStateInfo info = new ApplicationStateInfo();
TestingUtil.setPrivateField("applicationStateInfo",
ApplicationAssociate.class,
associate,
info);
FaceletViewHandlingStrategy strat = new FaceletViewHandlingStrategy();
getFacesContext().getViewRoot().setViewId("/index.xhtml");
assertNotNull(strat.getStateManagementStrategy(getFacesContext(), "/index.xhmtl"));
assertNotNull(getFacesContext().getAttributes().remove("com.sun.faces.context.StateContext_KEY"));
getFacesContext().getViewRoot().setViewId("/index2.xhtml");
assertNotNull(strat.getStateManagementStrategy(getFacesContext(), "/index2.xhtml"));
assertNotNull(getFacesContext().getAttributes().remove("com.sun.faces.context.StateContext_KEY"));
// ---------------------------------------------
webConfig.overrideContextInitParameter(WebConfiguration.BooleanWebContextInitParameter.PartialStateSaving, false);
info = new ApplicationStateInfo();
TestingUtil.setPrivateField("applicationStateInfo",
ApplicationAssociate.class,
associate,
info);
getFacesContext().getViewRoot().setViewId("/index.xhtml");
assertNull(strat.getStateManagementStrategy(getFacesContext(), "/index.xhmtl"));
assertNotNull(getFacesContext().getAttributes().remove("com.sun.faces.context.StateContext_KEY"));
getFacesContext().getViewRoot().setViewId("/index2.xhtml");
assertNull(strat.getStateManagementStrategy(getFacesContext(), "/index2.xhtml"));
assertNotNull(getFacesContext().getAttributes().remove("com.sun.faces.context.StateContext_KEY"));
// ---------------------------------------------
webConfig.overrideContextInitParameter(WebConfiguration.BooleanWebContextInitParameter.PartialStateSaving, true);
webConfig.overrideContextInitParameter(WebConfiguration.WebContextInitParameter.FullStateSavingViewIds, "/index.xhtml");
info = new ApplicationStateInfo();
TestingUtil.setPrivateField("applicationStateInfo",
ApplicationAssociate.class,
associate,
info);
getFacesContext().getViewRoot().setViewId("/index.xhtml");
assertNull(strat.getStateManagementStrategy(getFacesContext(), "/index.xhtml"));
assertNotNull(getFacesContext().getAttributes().remove("com.sun.faces.context.StateContext_KEY"));
getFacesContext().getViewRoot().setViewId("/index2.xhtml");
assertNotNull(strat.getStateManagementStrategy(getFacesContext(), "/index2.xhtml"));
assertNotNull(getFacesContext().getAttributes().remove("com.sun.faces.context.StateContext_KEY"));
// ---------------------------------------------
webConfig.overrideContextInitParameter(WebConfiguration.BooleanWebContextInitParameter.PartialStateSaving, true);
webConfig.overrideContextInitParameter(WebConfiguration.WebContextInitParameter.FullStateSavingViewIds, "/index.xhtml,/index2.xhtml");
info = new ApplicationStateInfo();
TestingUtil.setPrivateField("applicationStateInfo",
ApplicationAssociate.class,
associate,
info);
getFacesContext().getViewRoot().setViewId("/index.xhtml");
assertNull(strat.getStateManagementStrategy(getFacesContext(), "/index.xhtml"));
assertNotNull(getFacesContext().getAttributes().remove("com.sun.faces.context.StateContext_KEY"));
getFacesContext().getViewRoot().setViewId("/index2.xhtml");
assertNull(strat.getStateManagementStrategy(getFacesContext(), "/index2.xhtml"));
assertNotNull(getFacesContext().getAttributes().remove("com.sun.faces.context.StateContext_KEY"));
getFacesContext().getViewRoot().setViewId("/index3.xhtml");
assertNotNull(strat.getStateManagementStrategy(getFacesContext(), "/index3.xhtml"));
assertNotNull(getFacesContext().getAttributes().remove("com.sun.faces.context.StateContext_KEY"));
}
public void testGetActionURLExceptions() throws Exception {
boolean exceptionThrown = false;
ViewHandler handler =
Util.getViewHandler(getFacesContext());
try {
handler.getActionURL(null, "/test.jsp");
} catch (NullPointerException npe) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try {
handler.getActionURL(getFacesContext(), null);
} catch (NullPointerException npe) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
exceptionThrown = false;
try {
handler.getActionURL(getFacesContext(), "test.jsp");
} catch (IllegalArgumentException iae) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
public void testGetResourceURL() throws Exception {
LifecycleFactory factory = (LifecycleFactory)
FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle =
factory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
ExternalContext extContext =
new ExternalContextImpl(config.getServletContext(),
request, response);
FacesContext context =
new FacesContextImpl(extContext, lifecycle);
// Validate correct calculations
assertEquals(request.getContextPath() + "/index.jsp",
Util.getViewHandler(getFacesContext()).
getResourceURL(context, "/index.jsp"));
assertEquals("index.jsp",
Util.getViewHandler(getFacesContext()).
getResourceURL(context, "index.jsp"));
}
public void testRender() {
getFacesContext().setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
UIViewRoot newView = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), TEST_URI);
//newView.setViewId(TEST_URI);
getFacesContext().setViewRoot(newView);
try {
ViewHandler viewHandler =
Util.getViewHandler(getFacesContext());
viewHandler.renderView(getFacesContext(),
getFacesContext().getViewRoot());
} catch (IOException e) {
System.out.println("ViewHandler IOException:" + e);
} catch (FacesException fe) {
System.out.println("ViewHandler FacesException: " + fe);
}
assertTrue(!(getFacesContext().getRenderResponse()) &&
!(getFacesContext().getResponseComplete()));
assertTrue(verifyExpectedOutput());
}
/* public void testRender2() {
// Change the viewID to end with .jsf and make sure that
// the implementation changes .jsf to .jsp and properly dispatches
// the message.
UIViewRoot newView = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
newView.setViewId(TEST_URI);
getFacesContext().setViewRoot(newView);
newView.setViewId("/faces/greeting.jsf");
getFacesContext().setViewRoot(newView);
try {
ViewHandler viewHandler =
Util.getViewHandler(getFacesContext());
viewHandler.renderView(getFacesContext(),
getFacesContext().getViewRoot());
} catch (IOException ioe) {
System.out.println("ViewHandler IOException: " + ioe);
} catch (FacesException fe) {
System.out.println("ViewHandler FacesException: " + fe);
}
assertTrue(!(getFacesContext().getRenderResponse()) &&
!(getFacesContext().getResponseComplete()));
assertTrue(verifyExpectedOutput());
} */
public void testCalculateLocaleLang() {
System.out.println("Testing calculateLocale - Language Match case");
ViewHandler handler = new ViewHandlerImpl();
Locale locale = handler.calculateLocale(getFacesContext());
assertTrue(locale.equals(Locale.ENGLISH));
}
public void testCalculateLocaleExact() {
System.out.println("Testing calculateLocale - Exact Match case ");
ViewHandler handler = new ViewHandlerImpl();
Locale locale = handler.calculateLocale(getFacesContext());
assertTrue(locale.equals(new Locale("ps", "PS")));
}
public void testCalculateLocaleNoMatch() {
System.out.println("Testing calculateLocale - No Match case");
ViewHandler handler = new ViewHandlerImpl();
Locale locale = handler.calculateLocale(getFacesContext());
assertTrue(locale.equals(Locale.US));
}
public void testCalculateLocaleFindDefault() {
System.out.println("Testing calculateLocale - find default");
ViewHandler handler = new ViewHandlerImpl();
Locale locale = handler.calculateLocale(getFacesContext());
assertEquals(Locale.ENGLISH.toString(), locale.toString());
}
public void testCalculateLocaleLowerCase() {
System.out.println("Testing calculateLocale - case sensitivity");
ViewHandler handler = new ViewHandlerImpl();
Locale locale = handler.calculateLocale(getFacesContext());
assertTrue(locale.equals(new Locale("ps", "PS")));
}
public void testTransient() {
// precreate tree and set it in session and make sure the tree is
// restored from session.
UIViewRoot root = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
root.setViewId(TEST_URI);
UIForm basicForm = new UIForm();
basicForm.setId("basicForm");
UIInput userName = new UIInput();
userName.setId("userName");
userName.setTransient(true);
root.getChildren().add(basicForm);
basicForm.getChildren().add(userName);
UIPanel panel1 = new UIPanel();
panel1.setId("panel1");
basicForm.getChildren().add(panel1);
UIInput userName1 = new UIInput();
userName1.setId("userName1");
userName1.setTransient(true);
panel1.getChildren().add(userName1);
UIInput userName2 = new UIInput();
userName2.setId("userName2");
panel1.getChildren().add(userName2);
UIInput userName3 = new UIInput();
userName3.setTransient(true);
panel1.getFacets().put("userName3", userName3);
UIInput userName4 = new UIInput();
panel1.getFacets().put("userName4", userName4);
HttpSession session = (HttpSession)
getFacesContext().getExternalContext().getSession(false);
session.setAttribute(TEST_URI, root);
getFacesContext().setViewRoot(root);
StateManager stateManager =
getFacesContext().getApplication().getStateManager();
SerializedView viewState =
stateManager.saveSerializedView(getFacesContext());
assertTrue(null != viewState);
try {
RenderKit curKit = RenderKitUtils.getCurrentRenderKit(getFacesContext());
StringWriter writer = new StringWriter();
ResponseWriter responseWriter =
curKit.createResponseWriter(writer, "text/html",
"ISO-8859-1");
getFacesContext().setResponseWriter(responseWriter);
stateManager.writeState(getFacesContext(), viewState);
root = stateManager.restoreView(getFacesContext(), TEST_URI,
RenderKitFactory.HTML_BASIC_RENDER_KIT);
getFacesContext().setViewRoot(root);
}
catch (Throwable ioe) {
ioe.printStackTrace();
fail();
}
// make sure that the transient property is not persisted.
basicForm =
(UIForm) (getFacesContext().getViewRoot()).findComponent(
"basicForm");
assertTrue(basicForm != null);
userName = (UIInput) basicForm.findComponent("userName");
assertTrue(userName == null);
panel1 = (UIPanel) basicForm.findComponent("panel1");
assertTrue(panel1 != null);
userName1 = (UIInput) panel1.findComponent("userName1");
assertTrue(userName1 == null);
userName2 = (UIInput) panel1.findComponent("userName2");
assertTrue(userName2 != null);
// make sure facets work correctly when marked transient.
Map facetList = panel1.getFacets();
assertTrue(!(facetList.containsKey("userName3")));
assertTrue(facetList.containsKey("userName4"));
}
public void testRestoreViewNegative() throws Exception {
// make sure the returned view is null if the viewId is the same
// as the servlet mapping.
assertNull(Util.getViewHandler(getFacesContext()).restoreView(getFacesContext(),
"/faces"));
}
private class TestRequest extends HttpServletRequestWrapper {
String servletPath;
String pathInfo;
public TestRequest(HttpServletRequest request) {
super(request);
}
public String getServletPath() {
return servletPath;
}
public void setServletPath(String servletPath) {
this.servletPath = servletPath;
}
public String getPathInfo() {
return pathInfo;
}
public void setPathInfo(String pathInfo) {
this.pathInfo = pathInfo;
}
}
} // end of class TestViewHandlerImpl
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/TestNavigationHandler.java 0000644 0000000 0000000 00000043430 11412443350 025215 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestNavigationHandler.java
package com.sun.faces.application;
import com.sun.faces.cactus.ServletFacesTestCase;
import com.sun.faces.util.Util;
import com.sun.faces.config.DbfFactory;
import javax.faces.FactoryFinder;
import javax.faces.event.SystemEventListener;
import javax.faces.event.SystemEvent;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.PreDestroyViewMapEvent;
import javax.faces.application.*;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.util.*;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.NamedNodeMap;
/**
* This class test the
*
*/
public class TestNavigationHandler extends ServletFacesTestCase {
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
private List testResultList = null;
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestNavigationHandler() {
super("TestNavigationHandler");
}
public TestNavigationHandler(String name) {
super(name);
}
//
// Class methods
//
//
// Methods from TestCase
//
public void setUp() {
super.setUp();
loadConfigFile();
}
//
// General Methods
//
private void loadConfigFile() {
loadFromInitParam("/WEB-INF/faces-navigation.xml");
}
private void loadTestResultList() throws Exception {
DocumentBuilderFactory f = DbfFactory.getFactory();
f.setNamespaceAware(false);
f.setValidating(false);
DocumentBuilder builder = f.newDocumentBuilder();
Document d = builder.parse(config.getServletContext().getResourceAsStream("/WEB-INF/navigation-cases.xml"));
NodeList navigationRules = d.getDocumentElement()
.getElementsByTagName("test");
for (int i = 0; i < navigationRules.getLength(); i++) {
Node test = navigationRules.item(i);
NamedNodeMap attributes = test.getAttributes();
Node fromViewId = attributes.getNamedItem("fromViewId");
Node fromAction = attributes.getNamedItem("fromAction");
Node fromOutput = attributes.getNamedItem("fromOutcome");
Node toViewId = attributes.getNamedItem("toViewId");
createAndAccrueTestResult(((fromViewId != null) ? fromViewId.getTextContent().trim() : null),
((fromAction != null) ? fromAction.getTextContent().trim() : null),
((fromOutput != null) ? fromOutput.getTextContent().trim() : null),
((toViewId != null) ? toViewId.getTextContent().trim() : null));
}
}
public void createAndAccrueTestResult(String fromViewId, String fromAction,
String fromOutcome, String toViewId) {
if (testResultList == null) {
testResultList = new ArrayList();
}
TestResult testResult = new TestResult();
testResult.fromViewId = fromViewId;
testResult.fromAction = fromAction;
testResult.fromOutcome = fromOutcome;
testResult.toViewId = toViewId;
testResultList.add(testResult);
}
public void testNavigationHandler() {
Application application = getFacesContext().getApplication();
ViewMapDestroyedListener listener = new ViewMapDestroyedListener();
application.subscribeToEvent(PreDestroyViewMapEvent.class,
UIViewRoot.class,
listener);
try {
loadTestResultList();
} catch (Exception e) {
throw new RuntimeException(e);
}
NavigationHandlerImpl navHandler = (NavigationHandlerImpl) application.getNavigationHandler();
FacesContext context = getFacesContext();
String newViewId;
UIViewRoot page;
boolean gotException = false;
for (int i = 0; i < testResultList.size(); i++) {
TestResult testResult = (TestResult) testResultList.get(i);
System.out.println("Testing from-view-id=" + testResult.fromViewId +
" from-action=" + testResult.fromAction +
" from-outcome=" + testResult.fromOutcome);
page = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
page.setViewId(testResult.fromViewId);
page.setLocale(Locale.US);
page.getViewMap(); // cause the map to be created
context.setViewRoot(page);
listener.reset();
try {
navHandler.handleNavigation(context, testResult.fromAction,
testResult.fromOutcome);
} catch (Exception e) {
// exception is valid only if context or fromoutcome is null.
assertTrue(testResult.fromOutcome == null);
gotException = true;
}
if (!gotException) {
if (!testResult.fromViewId.equals(testResult.toViewId)
&& testResult.fromOutcome != null) {
assertTrue(listener.getPassedEvent() instanceof PreDestroyViewMapEvent);
} else {
assertTrue(!listener.wasProcessEventInvoked());
assertTrue(listener.getPassedEvent() == null);
}
listener.reset();
newViewId = context.getViewRoot().getViewId();
if (testResult.fromOutcome == null) {
listener.reset();
System.out.println(
"assertTrue(" + newViewId + ".equals(" +
testResult.fromViewId +
"))");
assertTrue(newViewId.equals(testResult.fromViewId));
} else {
listener.reset();
System.out.println(
"assertTrue(" + newViewId + ".equals(" +
testResult.toViewId +
"))");
assertTrue(newViewId.equals(testResult.toViewId));
}
}
}
application.unsubscribeFromEvent(PreDestroyViewMapEvent.class,
UIViewRoot.class,
listener);
}
public void testSimilarFromViewId() {
ApplicationFactory aFactory =
(ApplicationFactory) FactoryFinder.getFactory(
FactoryFinder.APPLICATION_FACTORY);
Application application = aFactory.getApplication();
NavigationHandler navHandler = application.getNavigationHandler();
UIViewRoot root = application.getViewHandler().createView(getFacesContext(), "/dir1/dir2/dir3/test.jsp");
root.setLocale(Locale.US);
getFacesContext().setViewRoot(root);
try {
navHandler.handleNavigation(getFacesContext(), null, "home");
} catch (Exception e) {
e.printStackTrace();
assert(false);
}
String newViewId = getFacesContext().getViewRoot().getViewId();
assertTrue("newViewId is: " + newViewId, "/dir1/dir2/dir3/home.jsp".equals(newViewId));
}
// This tests that the same
*
*/
/**
* This class tests the
*
*/
public class TestJSF2NavigationHandler extends ServletFacesTestCase {
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
private List testResultList = null;
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestJSF2NavigationHandler() {
super("TestJSF2NavigationHandler");
}
public TestJSF2NavigationHandler(String name) {
super(name);
}
//
// Class methods
//
//
// Methods from TestCase
//
public void setUp() {
super.setUp();
loadConfigFile();
}
//
// General Methods
//
private void loadConfigFile() {
loadFromInitParam("/WEB-INF/faces-navigation-2.xml");
}
private void loadTestResultList() throws Exception {
DocumentBuilderFactory f = DbfFactory.getFactory();
f.setNamespaceAware(false);
f.setValidating(false);
DocumentBuilder builder = f.newDocumentBuilder();
Document d = builder.parse(config.getServletContext().getResourceAsStream("/WEB-INF/navigation-cases-2.xml"));
NodeList navigationRules = d.getDocumentElement()
.getElementsByTagName("test");
for (int i = 0; i < navigationRules.getLength(); i++) {
Node test = navigationRules.item(i);
NamedNodeMap attributes = test.getAttributes();
Node fromViewId = attributes.getNamedItem("fromViewId");
Node fromAction = attributes.getNamedItem("fromAction");
Node fromOutput = attributes.getNamedItem("fromOutcome");
Node condition = attributes.getNamedItem("if");
Node toViewId = attributes.getNamedItem("toViewId");
createAndAccrueTestResult(((fromViewId != null) ? fromViewId.getTextContent().trim() : null),
((fromAction != null) ? fromAction.getTextContent().trim() : null),
((fromOutput != null) ? fromOutput.getTextContent().trim() : null),
((condition != null) ? condition.getTextContent().trim() : null),
((toViewId != null) ? toViewId.getTextContent().trim() : null));
}
}
public void createAndAccrueTestResult(String fromViewId, String fromAction,
String fromOutcome, String condition, String toViewId) {
if (testResultList == null) {
testResultList = new ArrayList();
}
TestResult testResult = new TestResult();
testResult.fromViewId = fromViewId;
testResult.fromAction = fromAction;
testResult.fromOutcome = fromOutcome;
testResult.condition = condition;
testResult.toViewId = toViewId;
testResultList.add(testResult);
}
public void testNavigationHandler() {
Application application = getFacesContext().getApplication();
ViewMapDestroyedListener listener = new ViewMapDestroyedListener();
application.subscribeToEvent(PreDestroyViewMapEvent.class,
UIViewRoot.class,
listener);
try {
loadTestResultList();
} catch (Exception e) {
throw new RuntimeException(e);
}
NavigationHandlerImpl navHandler = (NavigationHandlerImpl) application.getNavigationHandler();
FacesContext context = getFacesContext();
String newViewId;
UIViewRoot page;
boolean gotException = false;
for (int i = 0; i < testResultList.size(); i++) {
TestResult testResult = (TestResult) testResultList.get(i);
Boolean conditionResult = null;
if (testResult.condition != null) {
conditionResult = (Boolean) application.getExpressionFactory()
.createValueExpression(context.getELContext(), testResult.condition, Boolean.class).getValue(context.getELContext());
}
System.out.println("Testing from-view-id=" + testResult.fromViewId +
" from-action=" + testResult.fromAction +
" from-outcome=" + testResult.fromOutcome +
" if=" + testResult.condition);
page = Util.getViewHandler(context).createView(context, null);
page.setViewId(testResult.fromViewId);
page.setLocale(Locale.US);
page.getViewMap(); // cause the map to be created
context.setViewRoot(page);
listener.reset();
try {
navHandler.handleNavigation(context, testResult.fromAction,
testResult.fromOutcome);
} catch (Exception e) {
// exception is valid only if context or fromoutcome is null.
assertTrue(testResult.fromOutcome == null);
gotException = true;
}
if (!gotException) {
// test assumption: if the from and to change, it's because the outcome was not-null or a condition was evaluated
if (!testResult.fromViewId.equals(testResult.toViewId)
&& (testResult.fromOutcome != null || testResult.condition != null)
&& (testResult.condition == null || conditionResult != null)) {
assertTrue(listener.getPassedEvent() instanceof PreDestroyViewMapEvent);
} else {
assertTrue(!listener.wasProcessEventInvoked());
assertTrue(listener.getPassedEvent() == null);
}
listener.reset();
newViewId = context.getViewRoot().getViewId();
if (testResult.fromOutcome == null && testResult.condition == null) {
listener.reset();
System.out.println(
"assertTrue(" + newViewId + ".equals(" +
testResult.fromViewId +
"))");
assertTrue(newViewId.equals(testResult.fromViewId));
}
// test assumption: if condition is false, we advance to some other view
else if (testResult.condition != null && conditionResult == false) {
listener.reset();
System.out.println(
"assertTrue(!" + newViewId + ".equals(" +
testResult.toViewId +
"))");
assertTrue(!newViewId.equals(testResult.toViewId));
} else {
listener.reset();
System.out.println(
"assertTrue(" + newViewId + ".equals(" +
testResult.toViewId +
"))");
assertTrue(newViewId.equals(testResult.toViewId));
}
}
}
application.unsubscribeFromEvent(PreDestroyViewMapEvent.class,
UIViewRoot.class,
listener);
}
class TestResult extends Object {
public String fromViewId = null;
public String fromAction = null;
public String fromOutcome = null;
public String condition = null;
public String toViewId = null;
}
private static final class ViewMapDestroyedListener
implements SystemEventListener {
private SystemEvent event;
private boolean processEventInvoked;
public void processEvent(SystemEvent event)
throws AbortProcessingException {
this.processEventInvoked = true;
this.event = event;
}
public boolean isListenerForSource(Object source) {
return (source instanceof UIViewRoot);
}
public SystemEvent getPassedEvent() {
return event;
}
public boolean wasProcessEventInvoked() {
return processEventInvoked;
}
public void reset() {
processEventInvoked = false;
event = null;
}
}
} // end of class TestNavigationHandler
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/ViewHandlerTestImpl.java 0000644 0000000 0000000 00000003770 11412443350 024655 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.application;
public class ViewHandlerTestImpl extends ViewHandlerImpl {
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/TestInjection.java 0000644 0000000 0000000 00000015456 11412443350 023551 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.application;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.faces.FactoryFinder;
import javax.faces.application.ApplicationFactory;
import com.sun.faces.cactus.ServletFacesTestCase;
import com.sun.faces.spi.InjectionProvider;
public class TestInjection extends ServletFacesTestCase {
public TestInjection() {
super("TestInjection");
}
public TestInjection(String name) {
super(name);
}
public void setUp() {
super.setUp();
}
// ------------------------------------------------------------ Test Methods
/**
* Validate PostConstruct/PreDestroy annotations are property
* invoked on protected, package private, and private methods.
* @throws Exception if an error occurs
*/
public void testInjection() throws Exception {
ProtectedBean protectedBean = new ProtectedBean();
PackagePrivateBean packagePrivateBean = new PackagePrivateBean();
PrivateBean privateBean = new PrivateBean();
ConcreteBean concreteBean = new ConcreteBean();
ApplicationFactory aFactory =
(ApplicationFactory) FactoryFinder.getFactory(
FactoryFinder.APPLICATION_FACTORY);
aFactory.getApplication(); // bootstraps the ApplicationAssociate
ApplicationAssociate associate = ApplicationAssociate
.getInstance(getFacesContext().getExternalContext());
assertNotNull(associate);
InjectionProvider injectionProvider = associate.getInjectionProvider();
assertNotNull(injectionProvider);
try {
injectionProvider.inject(protectedBean);
injectionProvider.invokePostConstruct(protectedBean);
injectionProvider.invokePreDestroy(protectedBean);
injectionProvider.inject(packagePrivateBean);
injectionProvider.invokePostConstruct(packagePrivateBean);
injectionProvider.invokePreDestroy(packagePrivateBean);
injectionProvider.inject(privateBean);
injectionProvider.invokePostConstruct(privateBean);
injectionProvider.invokePreDestroy(privateBean);
injectionProvider.inject(concreteBean);
injectionProvider.invokePostConstruct(concreteBean);
injectionProvider.invokePreDestroy(concreteBean);
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
assertTrue(false);
}
assertTrue(protectedBean.getInit());
assertTrue(protectedBean.getDestroy());
assertTrue(packagePrivateBean.getInit());
assertTrue(packagePrivateBean.getDestroy());
assertTrue(privateBean.getInit());
assertTrue(privateBean.getDestroy());
assertTrue(concreteBean.getInit());
assertTrue(concreteBean.getDestroy());
}
// ----------------------------------------------------------- Inner Classes
private static class ProtectedBean {
private boolean initCalled;
private boolean destroyCalled;
@PostConstruct void init() {
initCalled = true;
}
@PreDestroy void destroy() {
destroyCalled = true;
}
public boolean getInit() {
return initCalled;
}
public boolean getDestroy() {
return destroyCalled;
}
} // END ProtectedBean
private static class PackagePrivateBean {
private boolean initCalled;
private boolean destroyCalled;
@PostConstruct void init() {
initCalled = true;
}
@PreDestroy void destroy() {
destroyCalled = true;
}
public boolean getInit() {
return initCalled;
}
public boolean getDestroy() {
return destroyCalled;
}
} // END PackagePrivateBean
private static class PrivateBean {
private boolean initCalled;
private boolean destroyCalled;
@PostConstruct void init() {
initCalled = true;
}
@PreDestroy void destroy() {
destroyCalled = true;
}
public boolean getInit() {
return initCalled;
}
public boolean getDestroy() {
return destroyCalled;
}
} // END PrivateBean
private static abstract class BaseBean {
protected boolean initCalled;
protected boolean destroyCalled;
@PostConstruct void init() {
initCalled = true;
}
}
private static class ConcreteBean extends BaseBean {
@PreDestroy void destroy() {
destroyCalled = true;
}
public boolean getInit() {
return initCalled;
}
public boolean getDestroy() {
return destroyCalled;
}
}
} // END TestInjection mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/ActionListenerTestImpl.java 0000644 0000000 0000000 00000003776 11412443350 025376 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.application;
public class ActionListenerTestImpl extends ActionListenerImpl {
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/TestHAStateManagerImpl.java 0000644 0000000 0000000 00000013010 11412443350 025215 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.application;
import org.apache.cactus.server.ServletConfigWrapper;
import com.sun.faces.RIConstants;
import com.sun.faces.cactus.ServletFacesTestCase;
import com.sun.faces.util.Util;
import javax.faces.application.StateManager;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIComponent;
import javax.faces.component.UIGraphic;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
import javax.faces.component.UIViewRoot;
import javax.faces.component.UIForm;
import javax.faces.component.UIPanel;
import javax.faces.context.FacesContext;
import javax.faces.render.RenderKitFactory;
import javax.servlet.http.HttpSession;
import javax.faces.application.StateManager.SerializedView;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import java.util.ArrayList;
/**
* This class tests the JavaBean represented the data for an individual customer.
*
*/
public class TestUtil_local extends TestCase {
//
// Protected Constants
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestUtil_local() {
super("TestUtil_local.java");
}
public TestUtil_local(String name) {
super(name);
}
//
// Class methods
//
//
// General Methods
//
public void testGetLocaleFromString() {
Locale result = null;
// positive tests
assertNotNull(result = Util.getLocaleFromString("ps"));
assertNotNull(result = Util.getLocaleFromString("tg_AF"));
assertNotNull(result = Util.getLocaleFromString("tk_IQ-Traditional"));
assertNotNull(result = Util.getLocaleFromString("tk-IQ_Traditional"));
}
} // end of class TestUtil_local
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/util/TestUtil.java 0000644 0000000 0000000 00000040047 11412443352 021212 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestUtil.java
package com.sun.faces.util;
import com.sun.faces.cactus.ServletFacesTestCase;
import com.sun.faces.renderkit.Attribute;
import com.sun.faces.renderkit.AttributeManager;
import com.sun.faces.renderkit.RenderKitUtils;
import javax.faces.FactoryFinder;
import javax.faces.component.UIInput;
import javax.faces.component.UISelectItems;
import javax.faces.component.UISelectOne;
import javax.faces.component.UISelectMany;
import javax.faces.component.html.HtmlInputText;
import javax.faces.context.ResponseWriter;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.faces.render.RenderKit;
import javax.faces.render.RenderKitFactory;
import javax.el.ValueExpression;
import javax.el.ExpressionFactory;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeSet;
import java.util.List;
import java.util.Arrays;
/**
* Currently tests RenderKitUtils.
*/
public class TestUtil extends ServletFacesTestCase {
// -------------------------------------------------------------- Test Setup
public TestUtil() {
super("TestUtil");
}
public TestUtil(String name) {
super(name);
}
// ------------------------------------------------------------ Test Methods
public void testRenderPassthruAttributes() {
try {
RenderKitFactory renderKitFactory = (RenderKitFactory)
FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
RenderKit renderKit =
renderKitFactory.getRenderKit(getFacesContext(),
RenderKitFactory.HTML_BASIC_RENDER_KIT);
StringWriter sw = new StringWriter();
ResponseWriter writer = renderKit.createResponseWriter(sw,
"text/html",
"ISO-8859-1");
getFacesContext().setResponseWriter(writer);
Attribute[] attrs = AttributeManager.getAttributes(AttributeManager.Key.INPUTTEXT);
UIInput input = new UIInput();
input.setId("testRenderPassthruAttributes");
input.getAttributes().put("notPresent", "notPresent");
input.getAttributes().put("onblur", "javascript:f.blur()");
writer.startElement("input", input);
RenderKitUtils.renderPassThruAttributes(getFacesContext(),
writer,
input,
attrs);
writer.endElement("input");
String expectedResult = " onblur=\"javascript:f.blur()\"";
assertTrue(sw.toString().contains(expectedResult));
// verify no passthru attributes returns empty string
sw = new StringWriter();
writer =
renderKit.createResponseWriter(sw, "text/html", "ISO-8859-1");
getFacesContext().setResponseWriter(writer);
input.getAttributes().remove("onblur");
writer.startElement("input", input);
RenderKitUtils.renderPassThruAttributes(getFacesContext(),writer, input, attrs);
writer.endElement("input");
assertTrue(sw.toString().equals(""));
} catch (IOException e) {
assertTrue(false);
}
}
public void testRenderPassthruAttributesFromConcreteHtmlComponent() {
try {
RenderKitFactory renderKitFactory = (RenderKitFactory)
FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
RenderKit renderKit =
renderKitFactory.getRenderKit(getFacesContext(),
RenderKitFactory.HTML_BASIC_RENDER_KIT);
StringWriter sw = new StringWriter();
ResponseWriter writer = renderKit.createResponseWriter(sw,
"text/html",
"ISO-8859-1");
getFacesContext().setResponseWriter(writer);
Attribute[] attrs = AttributeManager.getAttributes(AttributeManager.Key.INPUTTEXT);
HtmlInputText input = new HtmlInputText();
input.setId("testRenderPassthruAttributes");
input.setSize(12);
writer.startElement("input", input);
RenderKitUtils.renderPassThruAttributes(getFacesContext(),writer, input, attrs);
writer.endElement("input");
String expectedResult = " size=\"12\"";
assertTrue(sw.toString().contains(expectedResult));
// test that setting the values to the default value causes
// the attributes to not be rendered.
sw = new StringWriter();
writer = renderKit.createResponseWriter(sw, "text/html",
"ISO-8859-1");
input.setSize(Integer.MIN_VALUE);
writer.startElement("input", input);
RenderKitUtils.renderPassThruAttributes(getFacesContext(),writer, input, attrs);
writer.endElement("input");
expectedResult = "";
assertEquals(expectedResult, sw.toString());
sw = new StringWriter();
writer = renderKit.createResponseWriter(sw, "text/html",
"ISO-8859-1");
input.setReadonly(false);
writer.startElement("input", input);
RenderKitUtils.renderPassThruAttributes(getFacesContext(),
writer,
input,
attrs);
writer.endElement("input");
assertEquals(expectedResult, sw.toString());
} catch (IOException e) {
assertTrue(false);
}
}
public void testRenderBooleanPassthruAttributes() {
try {
RenderKitFactory renderKitFactory = (RenderKitFactory)
FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
RenderKit renderKit =
renderKitFactory.getRenderKit(getFacesContext(),
RenderKitFactory.HTML_BASIC_RENDER_KIT);
StringWriter sw = new StringWriter();
ResponseWriter writer = renderKit.createResponseWriter(sw,
"text/html",
"ISO-8859-1");
getFacesContext().setResponseWriter(writer);
UIInput input = new UIInput();
input.setId("testBooleanRenderPassthruAttributes");
input.getAttributes().put("disabled", "true");
input.getAttributes().put("readonly", "false");
writer.startElement("input", input);
RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, input);
writer.endElement("input");
String expectedResult = " disabled=\"disabled\"";
assertTrue(sw.toString().contains(expectedResult));
// verify no passthru attributes returns empty string
sw = new StringWriter();
writer =
renderKit.createResponseWriter(sw, "text/html", "ISO-8859-1");
getFacesContext().setResponseWriter(writer);
input.getAttributes().remove("disabled");
input.getAttributes().remove("readonly");
writer.startElement("input", input);
RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, input);
writer.endElement("input");
assertTrue("".equals(sw.toString()));
} catch (IOException e) {
assertTrue(false);
}
}
public void testGetSelectItems() {
SelectItem item1 = new SelectItem("value", "label");
SelectItem item2 = new SelectItem("value2", "label2");
SelectItem[] itemsArray = {
item1, item2
};
Collection
*
*/
public class MultiThreadTestRunner extends Object {
//
// Protected Constants
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
private Thread [] threads;
private Object [] outcomes;
//
// Constructors and Initializers
//
public MultiThreadTestRunner(Thread [] yourThreads,
Object [] yourOutcomes) {
threads = yourThreads;
outcomes = yourOutcomes;
if (null == threads || null == outcomes) {
throw new IllegalArgumentException();
}
}
/**
* @return true iff one of the threads has failed.
*/
public boolean runThreadsAndOutputResults(PrintStream out) throws Exception {
int i;
if (outcomes.length != threads.length) {
throw new IllegalArgumentException();
}
for (i = 0; i < threads.length; i++) {
outcomes[i] = null;
}
for (i = 0; i < threads.length; i++) {
threads[i].start();
}
BitSet printed = new BitSet(threads.length);
boolean foundFailedThread = false;
// wait for all threads to complete
while (true) {
boolean foundIncompleteThread = false;
for (i = 0; i < threads.length; i++) {
if (null == outcomes[i]) {
foundIncompleteThread = true;
break;
}
else {
// print out the outcome for this thread
if (!printed.get(i)) {
printed.set(i);
out.print(threads[i].getName() + " outcome: ");
if (outcomes[i] instanceof Exception) {
foundFailedThread = true;
out.println("Exception: " +
outcomes[i] + " " +
((Exception)outcomes[i]).getMessage());
}
else {
out.println(outcomes[i].toString());
}
out.flush();
}
}
}
if (!foundIncompleteThread) {
break;
}
Thread.sleep(1000);
}
return foundFailedThread;
}
} // end of class MultiThreadTestRunner
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/util/TestUtil_messages.java 0000644 0000000 0000000 00000033154 11412443352 023102 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestUtil_messages.java
package com.sun.faces.util;
import javax.faces.component.UIViewRoot;
import java.util.Locale;
import com.sun.faces.cactus.ServletFacesTestCase;
/**
* TestUtil_messages.java is a class ...
*
*
*/
public class TestUtil_messages extends ServletFacesTestCase {
//
// Protected Constants
//
// Class Variables
//
//
// Instance Variables
//
// README - Add message info to this array as {message key, "number of params"}
// If message has no parameters entry should be {message key, "0"}
public String[][] messageInfo = {
{MessageUtils.CONVERSION_ERROR_MESSAGE_ID, "2"},
{MessageUtils.MODEL_UPDATE_ERROR_MESSAGE_ID, "2"},
{MessageUtils.FACES_CONTEXT_CONSTRUCTION_ERROR_MESSAGE_ID, "0"},
{MessageUtils.NULL_COMPONENT_ERROR_MESSAGE_ID, "0"},
{MessageUtils.NULL_REQUEST_VIEW_ERROR_MESSAGE_ID, "0"},
{MessageUtils.NULL_RESPONSE_VIEW_ERROR_MESSAGE_ID, "0"},
{MessageUtils.REQUEST_VIEW_ALREADY_SET_ERROR_MESSAGE_ID, "0"},
{MessageUtils.NULL_MESSAGE_ERROR_MESSAGE_ID, "0"},
{MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "1"},
{MessageUtils.NAMED_OBJECT_NOT_FOUND_ERROR_MESSAGE_ID, "1"},
{MessageUtils.NULL_RESPONSE_STREAM_ERROR_MESSAGE_ID, "0"},
{MessageUtils.NULL_RESPONSE_WRITER_ERROR_MESSAGE_ID, "0"},
{MessageUtils.NULL_EVENT_ERROR_MESSAGE_ID, "0"},
{MessageUtils.NULL_HANDLER_ERROR_MESSAGE_ID, "0"},
{MessageUtils.NULL_CONTEXT_ERROR_MESSAGE_ID, "0"},
{MessageUtils.NULL_LOCALE_ERROR_MESSAGE_ID, "0"},
{MessageUtils.SUPPORTS_COMPONENT_ERROR_MESSAGE_ID, "1"},
{MessageUtils.MISSING_RESOURCE_ERROR_MESSAGE_ID, "0"},
{MessageUtils.MISSING_CLASS_ERROR_MESSAGE_ID, "1"},
{MessageUtils.COMPONENT_NOT_FOUND_ERROR_MESSAGE_ID, "1"},
{MessageUtils.LIFECYCLE_ID_ALREADY_ADDED_ID, "1"},
{MessageUtils.LIFECYCLE_ID_NOT_FOUND_ERROR_MESSAGE_ID, "1"},
{MessageUtils.PHASE_ID_OUT_OF_BOUNDS_ERROR_MESSAGE_ID, "1"},
{MessageUtils.CANT_CREATE_LIFECYCLE_ERROR_MESSAGE_ID, "1"},
{MessageUtils.ILLEGAL_MODEL_REFERENCE_ID, "1"},
{MessageUtils.ATTRIBUTE_NOT_SUPORTED_ERROR_MESSAGE_ID, "2"},
{MessageUtils.FILE_NOT_FOUND_ERROR_MESSAGE_ID, "1"},
{MessageUtils.CANT_PARSE_FILE_ERROR_MESSAGE_ID, "1"},
{MessageUtils.CANT_INSTANTIATE_CLASS_ERROR_MESSAGE_ID, "1"},
{MessageUtils.ILLEGAL_CHARACTERS_ERROR_MESSAGE_ID, "0"},
{MessageUtils.NOT_NESTED_IN_FACES_TAG_ERROR_MESSAGE_ID, "1"},
{MessageUtils.NULL_BODY_CONTENT_ERROR_MESSAGE_ID, "1"},
{MessageUtils.SAVING_STATE_ERROR_MESSAGE_ID, "0"},
{MessageUtils.RENDERER_NOT_FOUND_ERROR_MESSAGE_ID, "1"},
{MessageUtils.MAXIMUM_EVENTS_REACHED_ERROR_MESSAGE_ID, "1"},
{MessageUtils.NULL_CONFIGURATION_ERROR_MESSAGE_ID, "0"},
{MessageUtils.ERROR_OPENING_FILE_ERROR_MESSAGE_ID, "1"},
{MessageUtils.ERROR_REGISTERING_DTD_ERROR_MESSAGE_ID, "1"},
{MessageUtils.INVALID_INIT_PARAM_ERROR_MESSAGE_ID, "0"},
{MessageUtils.ERROR_SETTING_BEAN_PROPERTY_ERROR_MESSAGE_ID, "1"},
{MessageUtils.ERROR_GETTING_VALUE_BINDING_ERROR_MESSAGE_ID, "1"},
{MessageUtils.ERROR_GETTING_VALUEREF_VALUE_ERROR_MESSAGE_ID, "1"},
{MessageUtils.CANT_INTROSPECT_CLASS_ERROR_MESSAGE_ID, "1"},
{MessageUtils.CANT_CONVERT_VALUE_ERROR_MESSAGE_ID, "2"},
{MessageUtils.INVALID_SCOPE_LIFESPAN_ERROR_MESSAGE_ID, "4"},
{MessageUtils.NAVIGATION_INVALID_QUERY_STRING_ID, "1"},
{MessageUtils.ENCODING_ERROR_MESSAGE_ID, "0"},
{MessageUtils.ILLEGAL_IDENTIFIER_LVALUE_MODE_ID, "1"},
{MessageUtils.VALIDATION_ID_ERROR_ID, "1"},
{MessageUtils.VALIDATION_EL_ERROR_ID, "1"},
{MessageUtils.VALIDATION_COMMAND_ERROR_ID, "1"},
{MessageUtils.CONTENT_TYPE_ERROR_MESSAGE_ID, "0"},
{MessageUtils.COMPONENT_NOT_FOUND_IN_VIEW_WARNING_ID, "1"},
{MessageUtils.ILLEGAL_ATTEMPT_SETTING_APPLICATION_ARTIFACT_ID, "1"},
{MessageUtils.INVALID_MESSAGE_SEVERITY_IN_CONFIG_ID, "1"},
{MessageUtils.CANT_CLOSE_INPUT_STREAM_ID, "0"},
{MessageUtils.DUPLICATE_COMPONENT_ID_ERROR_ID, "1"},
{MessageUtils.FACES_SERVLET_MAPPING_CANNOT_BE_DETERMINED_ID, "1"},
{MessageUtils.ILLEGAL_VIEW_ID_ID, "1"},
{MessageUtils.INVALID_EXPRESSION_ID, "1"},
{MessageUtils.NULL_FORVALUE_ID, "1"},
{MessageUtils.EMPTY_PARAMETER_ID, "0"},
{MessageUtils.ASSERTION_FAILED_ID, "0"},
{MessageUtils.OBJECT_CREATION_ERROR_ID, "0"},
{MessageUtils.CYCLIC_REFERENCE_ERROR_ID, "2"},
{MessageUtils.NO_DTD_FOUND_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_CANNOT_SET_LIST_ARRAY_PROPERTY_ID, "2"},
{MessageUtils.MANAGED_BEAN_EXISTING_VALUE_NOT_LIST_ID, "2"},
{MessageUtils.MANAGED_BEAN_TYPE_CONVERSION_ERROR_ID, "4"},
{MessageUtils.APPLICATION_ASSOCIATE_CTOR_WRONG_CALLSTACK_ID, "0"},
{MessageUtils.APPLICATION_ASSOCIATE_EXISTS_ID, "0"},
{MessageUtils.OBJECT_IS_READONLY, "1"},
{MessageUtils.INCORRECT_JSP_VERSION_ID, "1"},
{MessageUtils.EL_OUT_OF_BOUNDS_ERROR_ID, "1"},
{MessageUtils.EL_PROPERTY_TYPE_ERROR_ID, "1"},
{MessageUtils.EL_SIZE_OUT_OF_BOUNDS_ERROR_ID,"2"},
{MessageUtils.EVAL_ATTR_UNEXPECTED_TYPE, "3"},
{MessageUtils.RESTORE_VIEW_ERROR_MESSAGE_ID, "1"},
{MessageUtils.VALUE_NOT_SELECT_ITEM_ID, "2"},
{MessageUtils.CHILD_NOT_OF_EXPECTED_TYPE_ID, "4"},
{MessageUtils.COMMAND_LINK_NO_FORM_MESSAGE_ID, "0"},
{MessageUtils.FACES_CONTEXT_NOT_FOUND_ID, "0"},
{MessageUtils.NOT_NESTED_IN_TYPE_TAG_ERROR_MESSAGE_ID, "2"},
{MessageUtils.CANT_WRITE_ID_ATTRIBUTE_ERROR_MESSAGE_ID, "1"},
{MessageUtils.NOT_NESTED_IN_UICOMPONENT_TAG_ERROR_MESSAGE_ID, "0"},
{MessageUtils.NO_COMPONENT_ASSOCIATED_WITH_UICOMPONENT_TAG_MESSAGE_ID, "0"},
{MessageUtils.FACES_SERVLET_MAPPING_INCORRECT_ID, "0"},
{MessageUtils.JS_RESOURCE_WRITING_ERROR_ID, "0"},
{MessageUtils.CANNOT_CONVERT_ID, "2"},
{MessageUtils.CANNOT_VALIDATE_ID, "2"},
{MessageUtils.ERROR_PROCESSING_CONFIG_ID, "0"},
{MessageUtils.MANAGED_BEAN_CLASS_NOT_FOUND_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_CLASS_DEPENDENCY_NOT_FOUND_ERROR_ID, "3"},
{MessageUtils.MANAGED_BEAN_CLASS_IS_NOT_PUBLIC_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_CLASS_IS_ABSTRACT_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_CLASS_NO_PUBLIC_NOARG_CTOR_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_INJECTION_ERROR_ID, "1"},
{MessageUtils.MANAGED_BEAN_LIST_PROPERTY_CONFIG_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_AS_LIST_CONFIG_ERROR_ID, "1"},
{MessageUtils.MANAGED_BEAN_AS_MAP_CONFIG_ERROR_ID, "1"},
{MessageUtils.MANAGED_BEAN_MAP_PROPERTY_CONFIG_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_MAP_PROPERTY_INCORRECT_SETTER_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_MAP_PROPERTY_INCORRECT_GETTER_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_DEFINED_PROPERTY_CLASS_NOT_COMPATIBLE_ERROR_ID, "3"},
{MessageUtils.MANAGED_BEAN_INTROSPECTION_ERROR_ID, "1"},
{MessageUtils.MANAGED_BEAN_PROPERTY_DOES_NOT_EXIST_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_PROPERTY_HAS_NO_SETTER_ID, "2"},
{MessageUtils.MANAGED_BEAN_PROPERTY_INCORRECT_ARGS_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_LIST_SETTER_DOES_NOT_ACCEPT_LIST_OR_ARRAY_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_LIST_GETTER_DOES_NOT_RETURN_LIST_OR_ARRAY_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_LIST_GETTER_ARRAY_NO_SETTER_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_UNABLE_TO_SET_PROPERTY_ERROR_ID, "2"},
{MessageUtils.MANAGED_BEAN_PROBLEMS_ERROR_ID, "1"},
{MessageUtils.MANAGED_BEAN_PROBLEMS_STARTUP_ERROR_ID, "1"},
{MessageUtils.MANAGED_BEAN_UNKNOWN_PROCESSING_ERROR_ID, "1"},
{MessageUtils.MANAGED_BEAN_PROPERTY_UNKNOWN_PROCESSING_ERROR_ID, "1"},
{MessageUtils.VERIFIER_CLASS_MISSING_DEP_ID, "3"},
{MessageUtils.VERIFIER_CLASS_NOT_FOUND_ID, "2"},
{MessageUtils.VERIFIER_CTOR_NOT_PUBLIC_ID, "2"},
{MessageUtils.VERIFIER_NO_DEF_CTOR_ID, "2"},
{MessageUtils.VERIFIER_WRONG_TYPE_ID, "3"},
{MessageUtils.COMMAND_NOT_NESTED_WITHIN_FORM_ID, "0"},
{MessageUtils.NAVIGATION_NO_MATCHING_OUTCOME_ID, "2"},
{MessageUtils.NAVIGATION_NO_MATCHING_OUTCOME_ACTION_ID, "3"},
{MessageUtils.NO_RESOURCE_TARGET_AVAILABLE, "1"},
{MessageUtils.INVALID_RESOURCE_FORMAT_ERROR, "1"},
{MessageUtils.INVALID_RESOURCE_FORMAT_NO_LIBRARY_NAME_ERROR, "1"},
{MessageUtils.INVALID_RESOURCE_FORMAT_COLON_ERROR, "1"},
{MessageUtils.ARGUMENTS_NOT_LEGAL_CC_ATTRS_EXPR, "0"},
{MessageUtils.PARTIAL_STATE_ERROR_RESTORING_ID, "2"},
{MessageUtils.MISSING_COMPONENT_ATTRIBUTE_VALUE, "1"},
{MessageUtils.MISSING_COMPONENT_FACET, "1"},
{MessageUtils.MISSING_COMPONENT_METADATA, "1" }
};
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestUtil_messages() {
super("TestUtil_messages.java");
}
public TestUtil_messages(String name) {
super(name);
}
//
// Methods from TestCase
public void setUp() {
super.setUp();
UIViewRoot viewRoot = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
viewRoot.setViewId("viewId");
viewRoot.setLocale(Locale.US);
getFacesContext().setViewRoot(viewRoot);
}
//
// Class methods
//
//
// General Methods
//
public void testVerifyMessages() {
Locale[] localesToTest = new Locale[] {
new Locale("en", "US"),
new Locale("fr", ""),
new Locale("de", ""),
new Locale("es", ""),
new Locale("ja", ""),
new Locale("ko", ""),
new Locale("pt", "BR"),
new Locale("zh", "CN"),
new Locale("zh", "TW"),
};
for (Locale locale : localesToTest) {
System.out.println("Verifying messages for locale: " + locale.toString());
getFacesContext().getViewRoot().setLocale(locale);
verifyParamsInMessages(messageInfo);
}
}
private void verifyParamsInMessages(String[][] messageInfo) {
int numParams = 0;
for (int i = 0; i < messageInfo.length; i++) {
System.out.println("Testing message: " + messageInfo[i][0]);
try {
numParams = Integer.parseInt(messageInfo[i][1]);
} catch (NumberFormatException e) {
System.out.println("Invalid param number specifier!");
assertTrue(false);
}
if (numParams == 0) {
String message = MessageUtils.getExceptionMessageString(messageInfo[i][0]);
assertTrue(messageInfo[i][0] + " was null", message != null);
} else if (numParams > 0) {
Object[] params = generateParams(numParams);
String message = MessageUtils.getExceptionMessageString(messageInfo[i][0],
params);
assertTrue(message != null);
for (int j = 0; j < params.length; j++) {
assertTrue(messageInfo[i][0] + " unable to finder marker for param " + j,message.indexOf((String) params[j]) != -1);
}
}
}
}
private Object[] generateParams(int numParams) {
Object[] params = new String[numParams];
for (int i = 0; i < numParams; i++) {
params[i] = "param_" + i;
}
return params;
}
} // end of class TestUtil_messages
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/util/TestMessageFactoryImpl.java 0000644 0000000 0000000 00000014067 11412443352 024036 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestMessageFactoryImpl.java
package com.sun.faces.util;
import com.sun.faces.cactus.ServletFacesTestCase;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import java.util.Locale;
/**
* TestMessageFactoryImpl is a class ...
*
*
*/
public class TestMessageFactoryImpl extends ServletFacesTestCase {
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestMessageFactoryImpl() {
super("TestMessageFactoryImpl");
}
public TestMessageFactoryImpl(String name) {
super(name);
}
//
// Class methods
//
//
// Methods from TestCase
//
public void setUp() {
super.setUp();
UIViewRoot viewRoot = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null);
viewRoot.setViewId("viewId");
viewRoot.setLocale(Locale.US);
getFacesContext().setViewRoot(viewRoot);
}
//
// General Methods
//
public void testGetMethods() {
boolean gotException = false;
FacesMessage msg = null;
FacesContext facesContext = getFacesContext();
assert (facesContext != null);
System.out.println("Testing get methods");
try {
msg = MessageFactory.getMessage((FacesContext) null, (String) null);
} catch (NullPointerException fe) {
gotException = true;
}
assertTrue(gotException);
gotException = false;
msg = null;
// if msgId doesn't exist in the resource, null must be returned
try {
msg = MessageFactory.getMessage(facesContext, "MSG01", "param1");
assertTrue(null == msg);
} catch (FacesException fe) {
assertTrue(false);
}
Object[] params1 = {"JavaServerFaces"};
msg = MessageFactory.getMessage(facesContext, "MSG0001", params1);
assertTrue(msg != null);
assertTrue(
(msg.getSummary()).equals(
"'JavaServerFaces' is not a valid number."));
msg = MessageFactory.getMessage(facesContext, "MSG0003", "userId");
assertTrue(msg != null);
assertTrue(
(msg.getSummary()).equals("'userId' field cannot be empty."));
msg =
MessageFactory.getMessage(facesContext, "MSG0004", "userId",
"1000", "10000");
assertTrue(msg != null);
assertTrue(
(msg.getSummary()).equals(
"'userId' out of range. Value should be between '1000' and '10000'."));
}
public void testFindCatalog() {
boolean gotException = false;
FacesMessage msg = null;
// if no locale is set, it should use the fall back,
// JSFMessages.xml
msg = MessageFactory.getMessage(getFacesContext(), "MSG0003", "userId");
assertTrue(msg != null);
assertTrue(
(msg.getSummary()).equals("'userId' field cannot be empty."));
// passing an invalid locale should use fall back.
Locale en_locale = new Locale("eng", "us");
getFacesContext().getViewRoot().setLocale(en_locale);
System.out.println("Testing get methods");
try {
msg =
MessageFactory.getMessage(getFacesContext(), "MSG0003",
"userId");
} catch (Exception fe) {
gotException = true;
}
assertTrue(!gotException);
gotException = false;
msg = null;
en_locale = new Locale("en", "us");
getFacesContext().getViewRoot().setLocale(en_locale);
msg = MessageFactory.getMessage(getFacesContext(), "MSG0003", "userId");
assertTrue(msg != null);
assertTrue(
(msg.getSummary()).equals("'userId' field cannot be empty."));
msg = null;
}
} // end of class TestMessageListImpl
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/util/TestHtmlUtils.java 0000644 0000000 0000000 00000015726 11412443352 022230 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestHtmlUtils.java
package com.sun.faces.util;
import java.io.IOException;
import java.io.StringWriter;
import junit.framework.TestCase;
/**
* TestHtmlUtils is a class ...
*/
public class TestHtmlUtils extends TestCase {
public void testWriteURL() throws IOException {
//Test url with no params
testURLEncoding("http://www.google.com",
"http://www.google.com",
"http://www.google.com");
//Test URL with one param
testURLEncoding("http://www.google.com?joe=10",
"http://www.google.com?joe=10",
"http://www.google.com?joe=10");
//Test URL with two params
testURLEncoding("http://www.google.com?joe=10&fred=20",
"http://www.google.com?joe=10&fred=20",
"http://www.google.com?joe=10&fred=20");
//Test URL with & entity encoded
testURLEncoding("/index.jsf?joe=10&fred=20",
"/index.jsf?joe=10&fred=20",
"/index.jsf?joe=10&fred=20");
//Test URL with two params and second & close to end of string
testURLEncoding("/index.jsf?joe=10&f=20",
"/index.jsf?joe=10&f=20",
"/index.jsf?joe=10&f=20");
//Test URL with misplaced & expected behavior but not necissarily right.
testURLEncoding("/index.jsf?joe=10&f=20&",
"/index.jsf?joe=10&f=20&",
"/index.jsf?joe=10&f=20&");
//Test URL with encoded entity at end of URL expected behavior but not necissarily right.
testURLEncoding("/index.jsf?joe=10&f=20&",
"/index.jsf?joe=10&f=20&",
"/index.jsf?joe=10&f=20&");
}
public void testControlCharacters() throws IOException {
final char[] controlCharacters = new char[32];
for (int i = 0; i < 32; i++) {
controlCharacters[i] = (char) i;
}
String[] stringValues = new String[32];
for (int i = 0; i < 32; i++) {
stringValues[i] = "b" + controlCharacters[i] + "b";
}
final String[] largeStringValues = new String[32];
for (int i = 0; i < 32; i++) {
largeStringValues[i] = (stringValues[i] + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
}
for (int i = 0; i < 32; i++) {
char[] textBuffer = new char[1024];
char[] buffer = new char[1024];
StringWriter writer = new StringWriter();
HtmlUtils.writeAttribute(writer, false, false, buffer, stringValues[i], textBuffer, false);
if (i == 9 || i == 10 || i == 12 || i == 13) {
assertTrue(writer.toString().length() == 3);
} else {
assertTrue(writer.toString().length() == 2);
}
}
for (int i = 0; i < 32; i++) {
char[] textBuffer = new char[1024];
char[] buffer = new char[1024];
StringWriter writer = new StringWriter();
HtmlUtils.writeAttribute(writer, false, false, buffer, largeStringValues[i], textBuffer, false);
if (i == 9 || i == 10 || i == 12 || i == 13) {
assertTrue(writer.toString().length() == 34);
} else {
assertTrue(writer.toString().length() == 33);
}
}
for (int i = 0; i < 32; i++) {
char[] textBuffer = new char[1024];
char[] buffer = new char[1024];
StringWriter writer = new StringWriter();
HtmlUtils.writeText(writer, false, false, buffer, stringValues[i], textBuffer);
if (i == 9 || i == 10 || i == 12 || i == 13) {
assertTrue(writer.toString().length() == 3);
} else {
assertTrue(writer.toString().length() == 2);
}
}
for (int i = 0; i < 32; i++) {
char[] textBuffer = new char[1024];
char[] buffer = new char[1024];
StringWriter writer = new StringWriter();
HtmlUtils.writeText(writer, false, false, buffer, largeStringValues[i], textBuffer);
if (i == 9 || i == 10 || i == 12 || i == 13) {
assertTrue(writer.toString().length() == 34);
} else {
assertTrue(writer.toString().length() == 33);
}
}
}
private void testURLEncoding(String urlToEncode, String expectedHTML, String expectedXML)
throws IOException {
char[] textBuffer = new char[1024];
StringWriter xmlWriter = new StringWriter();
HtmlUtils.writeURL(xmlWriter, urlToEncode, textBuffer, "UTF-8");
System.out.println("XML: " + xmlWriter.toString());
assertEquals(xmlWriter.toString(), expectedXML);
StringWriter htmlWriter = new StringWriter();
HtmlUtils.writeURL(htmlWriter, urlToEncode, textBuffer, "UTF-8");
System.out.println("HTML: " + htmlWriter.toString());
assertEquals(htmlWriter.toString(), expectedHTML);
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/io/ 0000755 0000000 0000000 00000000000 11412443352 016217 5 ustar mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/io/TestIO.java 0000644 0000000 0000000 00000014534 11412443352 020240 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.io;
import com.sun.faces.application.ViewHandlerResponseWrapper;
import com.sun.faces.cactus.ServletFacesTestCase;
import javax.servlet.ServletOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
public class TestIO extends ServletFacesTestCase {
public TestIO() {
super("TestIO");
}
public TestIO(String name) {
super(name);
}
// ------------------------------------------------------------ Test Methods
public void testBase64Streams() throws Exception {
// create a string over 2048 bytes in length
String testString = "This is a test String";
for (int i = testString.length(); i < 6000; i++) {
testString += 'a';
}
StringWriter writer = new StringWriter();
Base64OutputStreamWriter sw = new Base64OutputStreamWriter(2048, writer);
ObjectOutputStream os = new ObjectOutputStream(sw);
os.writeObject(testString);
os.flush();
os.close();
sw.finish();
String encodedString = writer.toString();
// no take the encodedString and reverse the operation
Base64InputStream bin = new Base64InputStream(encodedString);
ObjectInputStream input = new ObjectInputStream(bin);
String result = (String) input.readObject();
input.close();
assertTrue(result != null);
assertTrue(result.length() == testString.length());
assertTrue(testString.equals(result));
}
public void testViewHandlerResponseWrapperStreamIO() throws Exception {
ViewHandlerResponseWrapper w1 =
new ViewHandlerResponseWrapper(getResponse());
ServletOutputStream os = w1.getOutputStream();
os.write('1');
try {
w1.getWriter();
assertTrue(false);
} catch (IllegalStateException ise) {
// expected
}
os.flush();
os.close();
PrintWriter writer = null;
try {
writer = w1.getWriter();
} catch (IllegalStateException ise) {
assertTrue(false);
}
// we've closed the stream - and should have a fake
// writer. Ensure writing to it doesn't impact the result;
writer.print("Some junk");
StringWriter buf = new StringWriter();
w1.flushToWriter(buf, "ISO-8859-1");
assertTrue(!buf.toString().contains("Some junk"));
// ensure that the content that was written to the stream is
// present
assertTrue("1".equals(buf.toString()));
w1 = new ViewHandlerResponseWrapper(getResponse());
os = w1.getOutputStream();
// flushBuffer should commit the response so getWriter()
// should throw no Exception
w1.flushBuffer();
try {
w1.getWriter();
} catch (IllegalStateException ise) {
assertTrue(false);
}
}
public void testViewHandlerResponseWrapperCharIO() throws Exception {
ViewHandlerResponseWrapper w1 =
new ViewHandlerResponseWrapper(getResponse());
PrintWriter pw = w1.getWriter();
pw.write("some stuff");
try {
w1.getOutputStream();
assertTrue(false);
} catch (IllegalStateException ise) {
// expected
}
pw.flush();
pw.close();
ServletOutputStream os = null;
try {
os = w1.getOutputStream();
} catch (IllegalStateException ise) {
assertTrue(false);
}
// we've closed the stream - and should have a fake
// writer. Ensure writing to it doesn't impact the result;
os.write('1');
StringWriter buf = new StringWriter();
w1.flushToWriter(buf, "ISO-8859-1");
assertTrue(!buf.toString().contains("1"));
// ensure that the content that was written to the stream is
// present
assertTrue("some stuff".equals(buf.toString()));
w1 = new ViewHandlerResponseWrapper(getResponse());
pw = w1.getWriter();
// flushBuffer should commit the response so getWriter()
// should throw no Exception
w1.flushBuffer();
try {
w1.getOutputStream();
} catch (IllegalStateException ise) {
assertTrue(false);
}
}
} // END TestIO mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/lifecycle/ 0000755 0000000 0000000 00000000000 11412443346 017552 5 ustar mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/lifecycle/TestRestoreViewFromPage.java 0000644 0000000 0000000 00000015746 11412443346 025171 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestRestoreViewFromPage.java
package com.sun.faces.lifecycle;
import com.sun.faces.cactus.CompareFiles;
import com.sun.faces.cactus.FileOutputResponseWriter;
import com.sun.faces.cactus.ServletFacesTestCase;
import org.apache.cactus.WebRequest;
import javax.faces.render.RenderKitFactory;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* TestRestoreViewFromPage is a class ...
*
*
*/
public class TestRestoreViewFromPage extends ServletFacesTestCase {
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
public static final String TEST_URI = "/greeting.jsp";
public static final String RESTORE_VIEW_OUTPUT_FILE = FileOutputResponseWriter.FACES_RESPONSE_ROOT +
"RestoreView_output";
public static final String RESTORE_VIEW_CORRECT_FILE = FileOutputResponseWriter.FACES_RESPONSE_ROOT +
"RestoreView_correct";
public static final String ignore[] = {
"value=[Ljava.lang.Object;@14a18d"
};
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestRestoreViewFromPage() {
super("TestRestoreViewFromPage");
}
public TestRestoreViewFromPage(String name) {
super(name);
}
//
// Class methods
//
//
// General Methods
//
public void beginRestoreViewFromPage(WebRequest theRequest) {
theRequest.setURL("localhost:8080", null, null, TEST_URI, null);
theRequest.addParameter("javax.faces.ViewState",
"rO0ABXNyACBjb20uc3VuLmZhY2VzLnV0aWwuVHJlZVN0cnVjdHVyZRRmG0QclWAgAgAETAAIY2hpbGRyZW50ABVMamF2YS91dGlsL0FycmF5TGlzdDtMAAljbGFzc05hbWV0ABJMamF2YS9sYW5nL1N0cmluZztMAAZmYWNldHN0ABNMamF2YS91dGlsL0hhc2hNYXA7TAACaWRxAH4AAnhwc3IAE2phdmEudXRpbC5BcnJheUxpc3R4gdIdmcdhnQMAAUkABHNpemV4cAAAAAF3BAAAAApzcQB+AABzcQB+AAUAAAACdwQAAAAKc3EAfgAAcHQAJmphdmF4LmZhY2VzLmNvbXBvbmVudC5iYXNlLlVJSW5wdXRCYXNlcHQABnVzZXJOb3NxAH4AAHB0AChqYXZheC5mYWNlcy5jb21wb25lbnQuYmFzZS5VSUNvbW1hbmRCYXNlcHQABnN1Ym1pdHh0ACVqYXZheC5mYWNlcy5jb21wb25lbnQuYmFzZS5VSUZvcm1CYXNlcHQACWhlbGxvRm9ybXh0AClqYXZheC5mYWNlcy5jb21wb25lbnQuYmFzZS5VSVZpZXdSb290QmFzZXB0AARyb290dXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAAAnVxAH4AEwAAAAJ0ABlERUZBVUxUW3NlcF0vZ3JlZXRpbmcuanNwdXEAfgATAAAABnEAfgAScHEAfgAXcHBwdXEAfgATAAAAAXVxAH4AEwAAAAJ1cQB+ABMAAAAGcQB+ABBwcQB+ABp0AARGb3JtcHNyABFqYXZhLnV0aWwuSGFzaE1hcAUH2sHDFmDRAwACRgAKbG9hZEZhY3RvckkACXRocmVzaG9sZHhwP0AAAAAAABB3CAAAABAAAAACdAAYY29tLnN1bi5mYWNlcy5Gb3JtTnVtYmVyc3IAEWphdmEubGFuZy5JbnRlZ2VyEuKgpPeBhzgCAAFJAAV2YWx1ZXhyABBqYXZhLmxhbmcuTnVtYmVyhqyVHQuU4IsCAAB4cAAAAAB0AARuYW1ldAAJaGVsbG9Gb3JteHVxAH4AEwAAAAJ1cQB+ABMAAAACdXEAfgATAAAAAnVxAH4AEwAAAAR0AA5mYWxzZVtzZXBddHJ1ZXBwcHVxAH4AEwAAAAJ1cQB+ABMAAAADcHQABk5VTUJFUnB1cQB+ABMAAAAGdAAQaGVsbG9Gb3JtX3VzZXJOb3BxAH4ALHQABFRleHRwcHVxAH4AEwAAAAB1cQB+ABMAAAACdXEAfgATAAAAAnVxAH4AEwAAAAJ0AA1udWxsW3NlcF1udWxsdXEAfgATAAAAB3BwcHBwdXIAK1tMamF2YXguZmFjZXMuYXBwbGljYXRpb24uU3RhdGVIb2xkZXJTYXZlcjus7jOyrNsurwIAAHhwAAAAAHB1cQB+ABMAAAACdXEAfgATAAAAA3B0AAZTdWJtaXRwdXEAfgATAAAABnQAEGhlbGxvRm9ybV9zdWJtaXRwcQB+ADp0AAZCdXR0b25wc3EAfgAcP0AAAAAAABB3CAAAABAAAAABdAAEdHlwZXQABnN1Ym1pdHh1cQB+ABMAAAAAc3IAEGphdmEudXRpbC5Mb2NhbGV++BFgnDD57AMABEkACGhhc2hjb2RlTAAHY291bnRyeXEAfgACTAAIbGFuZ3VhZ2VxAH4AAkwAB3ZhcmlhbnRxAH4AAnhw/////3QAAlVTdAACZW50AAB4");
}
public void testRestoreViewFromPage() {
Phase restoreView = new RestoreViewPhase();
try {
restoreView.execute(getFacesContext());
} catch (Throwable e) {
e.printStackTrace();
assertTrue(false);
}
assertTrue(!(getFacesContext().getRenderResponse()) &&
!(getFacesContext().getResponseComplete()));
assertTrue(null != getFacesContext().getViewRoot());
assertTrue(RenderKitFactory.HTML_BASIC_RENDER_KIT.equals(
getFacesContext().getViewRoot().getRenderKitId()));
assertTrue(
getFacesContext().getViewRoot().getLocale().equals(Locale.US));
CompareFiles cf = new CompareFiles();
try {
FileOutputStream os = new FileOutputStream(
RESTORE_VIEW_OUTPUT_FILE);
PrintStream ps = new PrintStream(os);
com.sun.faces.util.DebugUtil.printTree(
getFacesContext().getViewRoot(), ps);
List ignoreList = new ArrayList();
for (int i = 0; i < ignore.length; i++) {
ignoreList.add(ignore[i]);
}
boolean status = cf.filesIdentical(RESTORE_VIEW_OUTPUT_FILE,
RESTORE_VIEW_CORRECT_FILE,
ignoreList);
assertTrue(status);
// PENDING (visvan) test case to verify nothing is persisted if the root
// is marked transient for both client tand server case.
} catch (IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
} // end of class TestRestoreViewFromPage
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/lifecycle/TestSaveStateInPage.java 0000644 0000000 0000000 00000021740 11412443346 024244 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestSaveStateInPage.java
package com.sun.faces.lifecycle;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.component.UIForm;
import javax.faces.component.UIInput;
import javax.faces.component.UIPanel;
import javax.faces.component.UIViewRoot;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Locale;
import org.apache.cactus.WebRequest;
import com.sun.faces.application.StateManagerImpl;
import com.sun.faces.application.ViewHandlerImpl;
import com.sun.faces.cactus.JspFacesTestCase;
import com.sun.faces.cactus.TestingUtil;
import com.sun.faces.util.Util;
/**
* TestSaveStateInPage is a class ...
*
*
*/
public class TestSaveStateInPage extends JspFacesTestCase {
//
// Protected Constants
//
public static final String TEST_URI = "/greeting.jsp";
public String getExpectedOutputFilename() {
return "SaveState_correct";
}
public static final String ignore[] = {
"StateManagerImpl
class with deprecated
* methods only - does not contain any of the replacement methods (such
* as saveView).
*/
public class TestHASDeprStateManagerImpl extends ServletFacesTestCase {
public static final String TEST_URI = "/greeting.jsp";
public String getExpectedOutputFilename() {
return "TestViewHandlerImpl_correct";
}
public static final String ignore[] = {
};
public String[] getLinesToIgnore() {
return ignore;
}
public boolean sendResponseToFile() {
return true;
}
//
// Constructors/Initializers
//
public TestHASDeprStateManagerImpl() {
super("TestHASDeprStateManagerImpl");
}
public TestHASDeprStateManagerImpl(String name) {
super(name);
}
private Application application = null;
public void setUp() {
super.setUp();
ApplicationFactory aFactory =
(ApplicationFactory) FactoryFinder.getFactory(
FactoryFinder.APPLICATION_FACTORY);
application = (ApplicationImpl) aFactory.getApplication();
application.setViewHandler(new ViewHandlerImpl());
application.setStateManager(new DeprStateManagerImpl());
}
//
// Test Methods
//
public void beginRender(WebRequest theRequest) {
theRequest.setURL("localhost:8080", "/test", "/faces", TEST_URI, null);
}
public void testRender() {
UIViewRoot newView = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), TEST_URI);
newView.setLocale(Locale.US);
getFacesContext().setViewRoot(newView);
try {
ViewHandler viewHandler =
Util.getViewHandler(getFacesContext());
viewHandler.renderView(getFacesContext(),
getFacesContext().getViewRoot());
} catch (IOException e) {
System.out.println("ViewHandler IOException:" + e);
} catch (FacesException fe) {
System.out.println("ViewHandler FacesException: " + fe);
}
assertTrue(!(getFacesContext().getRenderResponse()) &&
!(getFacesContext().getResponseComplete()));
assertTrue(verifyExpectedOutput());
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/TestApplicationImpl_Config.java 0000644 0000000 0000000 00000050776 11412443350 026205 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestApplicationImpl_Config.java
package com.sun.faces.application;
import com.sun.faces.cactus.ServletFacesTestCase;
import com.sun.faces.TestComponent;
import com.sun.faces.TestConverter;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
import javax.faces.application.ApplicationFactory;
import javax.faces.application.NavigationHandler;
import javax.faces.application.StateManager;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIComponent;
import javax.faces.convert.Converter;
import javax.faces.el.PropertyResolver;
import javax.faces.el.VariableResolver;
import javax.faces.event.ActionListener;
import javax.faces.validator.LengthValidator;
import javax.faces.validator.Validator;
import java.util.Iterator;
import java.util.Locale;
/**
* TestApplicationImpl_Config is a class ...
* ActionListenerImpl
class
* functionality. It uses the xml configuration file:
* web/test/WEB-INF/faces-navigation.xml
.
*/
public class TestActionListenerImpl extends ServletFacesTestCase {
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestActionListenerImpl() {
super("TestActionListenerImpl");
}
public TestActionListenerImpl(String name) {
super(name);
}
//
// Class methods
//
//
// Methods from TestCase
//
//
// General Methods
//
public void testProcessAction() {
loadFromInitParam("/WEB-INF/faces-navigation.xml");
FacesContext context = getFacesContext();
System.out.println("Testing With Action Literal Set...");
UICommand command = new UICommand();
command.setAction(
context.getApplication().createMethodBinding(
"#{newCustomer.loginRequired}", null));
UIViewRoot page = Util.getViewHandler(context).createView(context, null);
page.setViewId("/login.jsp");
page.setLocale(Locale.US);
context.setViewRoot(page);
ActionListenerImpl actionListener = new ActionListenerImpl();
ActionEvent actionEvent = new ActionEvent(command);
actionListener.processAction(actionEvent);
String newViewId = context.getViewRoot().getViewId();
assertTrue(newViewId.equals("/must-login-first.jsp"));
System.out.println("Testing With Action Set...");
command = new UICommand();
MethodBinding binding =
context.getApplication().createMethodBinding("#{userBean.login}",
null);
command.setAction(binding);
UserBean user = new UserBean();
context.getExternalContext().getSessionMap().put("userBean", user);
assertTrue(
user ==
context.getExternalContext().getSessionMap().get("userBean"));
page = Util.getViewHandler(context).createView(context, null);
page.setViewId("/login.jsp");
page.setLocale(Locale.US);
context.setViewRoot(page);
actionEvent = new ActionEvent(command);
actionListener.processAction(actionEvent);
newViewId = context.getViewRoot().getViewId();
// expected outcome should be view id corresponding to "page/outcome" search..
assertTrue(newViewId.equals("/home.jsp"));
}
public void testIllegalArgException() {
boolean exceptionThrown = false;
FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot page = Util.getViewHandler(getFacesContext()).createView(context, null);
page.setViewId("/login.jsp");
context.setViewRoot(page);
UserBean user = new UserBean();
context.getExternalContext().getApplicationMap().put("UserBean", user);
assertTrue(
user ==
context.getExternalContext().getApplicationMap().get("UserBean"));
UICommand command = new UICommand();
MethodBinding binding =
context.getApplication().createMethodBinding("#{UserBean.noMeth}",
null);
command.setAction(binding);
ActionEvent actionEvent = new ActionEvent(command);
ActionListenerImpl actionListener = new ActionListenerImpl();
try {
actionListener.processAction(actionEvent);
} catch (FacesException e) {
assertTrue(e.getCause() instanceof MethodNotFoundException);
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
public static class UserBean extends Object {
public String login() {
return ("success");
}
}
} // end of class TestActionListenerImpl
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/TestApplicationImpl.java 0000644 0000000 0000000 00000104605 11412443350 024707 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestApplicationImpl.java
package com.sun.faces.application;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.List;
import java.util.Date;
import java.util.ArrayList;
import java.io.IOException;
import java.net.URL;
import javax.el.ELException;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
import javax.faces.view.facelets.ResourceResolver;
import javax.faces.render.RenderKitFactory;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import javax.faces.application.NavigationHandler;
import javax.faces.application.StateManager;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.context.ExternalContext;
import javax.faces.convert.Converter;
import javax.faces.convert.IntegerConverter;
import javax.faces.el.PropertyResolver;
import javax.faces.el.ReferenceSyntaxException;
import javax.faces.el.ValueBinding;
import javax.faces.el.VariableResolver;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import javax.faces.event.ListenerFor;
import javax.faces.event.PostAddToViewEvent;
import javax.faces.event.ComponentSystemEventListener;
import javax.faces.event.ComponentSystemEvent;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ListenersFor;
import javax.faces.event.PreRenderComponentEvent;
import com.sun.faces.RIConstants;
import com.sun.faces.TestComponent;
import com.sun.faces.TestForm;
import com.sun.faces.facelets.FaceletFactory;
import com.sun.faces.facelets.Facelet;
import com.sun.faces.facelets.impl.DefaultFaceletFactory;
import com.sun.faces.config.WebConfiguration;
import static com.sun.faces.config.WebConfiguration.WebContextInitParameter.*;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.DisableFaceletJSFViewHandler;
import com.sun.faces.cactus.JspFacesTestCase;
import com.sun.faces.cactus.TestingUtil;
/**
* TestApplicationImpl is a class ...
* StateManagerImpl
class
* functionality.
*/
public class TestStateManagerImpl extends ServletFacesTestCase {
//
// Constructors/Initializers
//
public TestStateManagerImpl() {
super("TestStateManagerImpl");
}
public TestStateManagerImpl(String name) {
super(name);
}
// ------------------------------------------------------------ Test Methods
// Verify saveSerializedView() throws IllegalStateException
// if duplicate component id's are detected on non-transient
// components.
public void testDuplicateIdDetection() throws Exception {
FacesContext context = getFacesContext();
// construct a view
UIViewRoot root = Util.getViewHandler(getFacesContext()).createView(context, null);
root.setViewId("/test");
root.setId("root");
root.setLocale(Locale.US);
UIComponent comp1 = new UIInput();
comp1.setId("comp1");
UIComponent comp2 = new UIOutput();
comp2.setId("comp2");
UIComponent comp3 = new UIGraphic();
comp3.setId("comp3");
UIComponent facet1 = new UIOutput();
facet1.setId("comp4");
UIComponent facet2 = new UIOutput();
facet2.setId("comp2");
comp2.getFacets().put("facet1", facet1);
comp2.getFacets().put("facet2", facet2);
root.getChildren().add(comp1);
root.getChildren().add(comp2);
root.getChildren().add(comp3);
context.setViewRoot(root);
StateManagerImpl stateManager = (StateManagerImpl) context.getApplication()
.getStateManager();
boolean exceptionThrown = false;
try {
stateManager.saveView(context);
} catch (IllegalStateException ise) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
// multiple componentns with a null ID should not
// trigger an exception
// construct a view
root = Util.getViewHandler(getFacesContext()).createView(context, null);
root.setViewId("/test");
root.setId("root");
root.setLocale(Locale.US);
comp1 = new UIInput();
comp1.setId("comp1");
comp2 = new UIOutput();
comp2.setId(null);
comp3 = new UIGraphic();
comp3.setId(null);
facet1 = new UIOutput();
facet1.setId("comp4");
facet2 = new UIOutput();
facet2.setId("comp2");
comp2.getFacets().put("facet1", facet1);
comp2.getFacets().put("facet2", facet2);
root.getChildren().add(comp1);
root.getChildren().add(comp2);
root.getChildren().add(comp3);
context.setViewRoot(root);
exceptionThrown = false;
try {
stateManager.saveView(context);
} catch (IllegalStateException ise) {
exceptionThrown = true;
}
assertTrue(!exceptionThrown);
// transient components with duplicate ids should
// trigger an error condition
// construct a view
root = Util.getViewHandler(getFacesContext()).createView(context, null);
root.setViewId("/test");
root.setId("root");
root.setLocale(Locale.US);
comp1 = new UIInput();
comp1.setId("comp1");
comp1.setTransient(true);
comp2 = new UIOutput();
comp2.setId("comp1");
comp2.setTransient(true);
comp3 = new UIGraphic();
comp3.setId("comp3");
facet1 = new UIOutput();
facet1.setId("comp4");
facet2 = new UIOutput();
facet2.setId("comp2");
comp2.getFacets().put("facet1", facet1);
comp2.getFacets().put("facet2", facet2);
root.getChildren().add(comp1);
root.getChildren().add(comp2);
root.getChildren().add(comp3);
context.setViewRoot(root);
exceptionThrown = false;
try {
stateManager.saveView(context);
} catch (IllegalStateException ise) {
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
public void beginMultiWindowSaveServer(WebRequest theRequest) {
theRequest.addParameter("javax.faces.ViewState", "j_id1:j_id2");
}
public void testMultiWindowSaveServer() throws Exception {
StateManagerImpl wrapper =
new StateManagerImpl() {
public boolean isSavingStateInClient(FacesContext context) {
return false;
}
};
FacesContext ctx = getFacesContext();
ctx.getApplication().setStateManager(wrapper);
// construct a view
initView(ctx);
UIViewRoot root = ctx.getViewRoot();
root.getAttributes().put("checkThisValue", "checkThisValue");
getFacesContext().setResponseWriter(new HtmlResponseWriter(new StringWriter(), "text/html", "UTF-8"));
Object viewState = wrapper.saveView(getFacesContext());
wrapper.writeState(getFacesContext(), viewState);
// See that the Logical View and Actual View maps are correctly created
Map sessionMap = ctx.getExternalContext().getSessionMap();
assertTrue(sessionMap.containsKey(ServerSideStateHelper.LOGICAL_VIEW_MAP));
assertTrue(((Map)sessionMap.get(ServerSideStateHelper.LOGICAL_VIEW_MAP)).containsKey("j_id1"));
UIViewRoot newRoot = wrapper.restoreView(ctx, "test", "HTML_BASIC");
assertNotNull(newRoot);
assertEquals(root.getAttributes().get("checkThisValue"),
newRoot.getAttributes().get("checkThisValue"));
}
public void testGetViewStateServer() {
// this exercise ResponseStateManager.getViewState() as well
FacesContext ctx = getFacesContext();
initView(ctx);
String control = "j_id1:j_id2";
String result = ctx.getApplication().getStateManager().getViewState(ctx);
assertEquals(control, result);
}
public void testGetViewStateClient() throws Exception {
// this exercise ResponseStateManager.getViewState() as well
FacesContext ctx = getFacesContext();
WebConfiguration webConfig =
WebConfiguration.getInstance(ctx.getExternalContext());
webConfig.overrideContextInitParameter(StateSavingMethod,
StateManager.STATE_SAVING_METHOD_CLIENT);
webConfig.overrideContextInitParameter(AutoCompleteOffOnViewState, false);
// recreate the RenderKit so the change is picked up.
RenderKit rk = new RenderKitImpl();
TestingUtil.setPrivateField("lastRk",
FacesContextImpl.class,
ctx,
rk);
TestingUtil.setPrivateField("lastRkId",
FacesContextImpl.class,
ctx,
RenderKitFactory.HTML_BASIC_RENDER_KIT);
initView(ctx);
StringWriter capture = new StringWriter();
ResponseWriter writer = new HtmlResponseWriter(capture,
"text/html",
"UTF-8");
ctx.setResponseWriter(writer);
StateManager manager = ctx.getApplication().getStateManager();
Object state = ctx.getApplication().getStateManager().saveView(ctx);
manager.writeState(ctx, state);
String rawResult = capture.toString();
Pattern p = Pattern.compile("\\bvalue=\"(.+)\"");
Matcher m = p.matcher(rawResult);
assertTrue(m.find());
String control = m.group(1);
String result = ctx.getApplication().getStateManager().getViewState(ctx);
assertEquals(control, result);
}
// --------------------------------------------------------- Private Methods
private void initView(FacesContext ctx) {
UIViewRoot root = Util.getViewHandler(getFacesContext()).createView(ctx, null);
root.setViewId("/test");
root.setId("root");
root.setLocale(Locale.US);
UIComponent comp1 = new UIInput();
comp1.setId("comp1");
UIComponent comp2 = new UIOutput();
comp2.setId("comp2");
UIComponent comp3 = new UIGraphic();
comp3.setId("comp3");
UIComponent facet1 = new UIOutput();
facet1.setId("comp4");
comp2.getFacets().put("facet1", facet1);
root.getChildren().add(comp1);
root.getChildren().add(comp2);
root.getChildren().add(comp3);
ctx.setViewRoot(root);
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/TestApplicationEvents.java 0000644 0000000 0000000 00000052750 11412443350 025255 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.application;
import java.util.List;
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ComponentSystemEvent;
import javax.faces.event.ComponentSystemEventListener;
import javax.faces.event.FacesListener;
import javax.faces.event.SystemEvent;
import javax.faces.event.SystemEventListener;
import javax.faces.event.SystemEventListenerHolder;
import javax.faces.event.PostConstructApplicationEvent;
import com.sun.faces.CustomSystemEvent;
import com.sun.faces.cactus.ServletFacesTestCase;
/**
* @since 2.0.0
*/
public class TestApplicationEvents extends ServletFacesTestCase {
// ------------------------------------------------------------ Constructors
public TestApplicationEvents() {
super("TestApplicationEvents");
}
public TestApplicationEvents(String name) {
super(name);
}
// ------------------------------------------------------------ Test Methods
////////////////////////////////////////////////////////////////////////////
// ensure NPEs are thrown per the docs
public void testEventsNPEs() {
Application application = getFacesContext().getApplication();
SystemEventListener listener = new TestListener();
// ----------------------------------------------------------- Subscribe
try {
application.subscribeToEvent(null, UIViewRoot.class, listener);
assertTrue(false);
} catch (NullPointerException npe) {
} catch (Exception e) {
assertTrue(false);
}
try {
application.subscribeToEvent(TestApplicationEvents.TestSystemEvent.class, UIViewRoot.class, null);
assert(false);
} catch (NullPointerException ignored) {
} catch (Exception e) {
assertTrue(false);
}
// --------------------------------------------------------- Unsubscribe
try {
application.subscribeToEvent(null, UIViewRoot.class, listener);
assertTrue(false);
} catch (NullPointerException ignored) {
} catch (Exception e) {
assertTrue(false);
}
try {
application.subscribeToEvent(TestApplicationEvents.TestSystemEvent.class, UIViewRoot.class, null);
assertTrue(false);
} catch (NullPointerException ignored) {
} catch (Exception e) {
assertTrue(false);
}
// ------------------------------------------------------------- Publish
try {
application.publishEvent(getFacesContext(), null, new UIViewRoot());
assertTrue(false);
} catch (NullPointerException ignored) {
} catch (Exception e) {
assertTrue(false);
}
try {
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent.class,
null);
assertTrue(false);
} catch (NullPointerException ignored) {
} catch (Exception e) {
assertTrue(false);
}
try {
application.publishEvent(null,
TestApplicationEvents.TestSystemEvent.class,
new UIViewRoot());
assertTrue(false);
} catch (NullPointerException ignored) {
} catch (Exception e) {
assertTrue(false);
}
}
////////////////////////////////////////////////////////////////////////////
// Ensure component level listeners are invoked when
// Application.publishEvent() is called.
public void testEvents1() {
TestComponentListener listener = new TestComponentListener();
Application application = getFacesContext().getApplication();
UIInput input = new UIInput();
input.subscribeToEvent(TestApplicationEvents.TestSystemEvent3.class,
listener);
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent3.class,
input);
assertTrue(listener.getPassedEvent() instanceof TestApplicationEvents.TestSystemEvent3);
// new UIInput without any subs should result in no invocation
listener.reset();
UIInput input2 = new UIInput();
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent3.class,
input2);
assertTrue(!listener.wasProcessEventInvoked());
// unsub'd event should result in no invocations
input.unsubscribeFromEvent(TestApplicationEvents.TestSystemEvent3.class,
listener);
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent3.class,
input);
assertTrue(!listener.wasProcessEventInvoked());
}
////////////////////////////////////////////////////////////////////////////
// Test Application subscribeToEvent() and unsubscribeToEvent() with
// a specific source.
public void testEvents2() {
TestListener listener = new TestListener(UIViewRoot.class);
Application application = getFacesContext().getApplication();
application.subscribeToEvent(TestApplicationEvents.TestSystemEvent.class,
UIViewRoot.class,
listener);
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent.class,
getFacesContext().getViewRoot());
assertTrue(listener.getPassedSource() == getFacesContext().getViewRoot());
assertTrue(listener.getPassedSystemEvent() instanceof TestSystemEvent);
assertTrue(listener.getPassedSystemEvent().getSource() == getFacesContext().getViewRoot());
// event is setup for UIViewRoot sources, so a UIInput source shouldn't
// trigger the listener
UIInput input = new UIInput();
listener.reset();
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent.class,
input);
assertTrue(listener.getPassedSource() == null);
assertTrue(listener.getPassedSystemEvent() == null);
// passing a custom UIViewRoot should result in the listener being
// triggered and the event being created
listener.reset();
CustomViewRoot root = new CustomViewRoot();
application.subscribeToEvent(TestApplicationEvents.TestSystemEvent.class,
CustomViewRoot.class,
listener);
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent.class,
root);
assertTrue(listener.getPassedSource() == root);
assertTrue(listener.getPassedSystemEvent() instanceof TestSystemEvent);
assertTrue(listener.getPassedSystemEvent().getSource() == root);
// unsubscript and verify a publish doesn't trigger the listener
application.unsubscribeFromEvent(TestApplicationEvents.TestSystemEvent.class,
CustomViewRoot.class,
listener);
listener.reset();
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent.class,
root);
assertTrue(!listener.wasIsListenerForSourceInvoked());
assertTrue(!listener.wasProcessEventInvoked());
application.unsubscribeFromEvent(TestApplicationEvents.TestSystemEvent.class,
UIViewRoot.class,
listener);
listener.reset();
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent.class,
root);
assertTrue(!listener.wasIsListenerForSourceInvoked());
assertTrue(!listener.wasProcessEventInvoked());
// verify multiple events for a single source works
listener = new TestListener(UIViewRoot.class);
application.subscribeToEvent(TestApplicationEvents.TestSystemEvent2.class,
UIViewRoot.class,
listener);
application.subscribeToEvent(TestApplicationEvents.TestSystemEvent3.class,
UIViewRoot.class,
listener);
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent2.class,
getFacesContext().getViewRoot());
assertTrue(listener.getPassedSource() == getFacesContext().getViewRoot());
assertTrue(listener.getPassedSystemEvent() instanceof TestSystemEvent2);
assertTrue(listener.getPassedSystemEvent().getSource() == getFacesContext().getViewRoot());
listener.reset();
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent3.class,
getFacesContext().getViewRoot());
assertTrue(listener.getPassedSource() == getFacesContext().getViewRoot());
assertTrue(listener.getPassedSystemEvent() instanceof TestSystemEvent3);
assertTrue(listener.getPassedSystemEvent().getSource() == getFacesContext().getViewRoot());
application.unsubscribeFromEvent(TestApplicationEvents.TestSystemEvent2.class,
UIViewRoot.class,
listener);
application.unsubscribeFromEvent(TestApplicationEvents.TestSystemEvent3.class,
UIViewRoot.class,
listener);
// verify subscription for source that is an Abstract type works or
// doesn't work depending on how the event is published.
TestListener abstractListener = new TestListener(Application.class);
application.subscribeToEvent(PostConstructApplicationEvent.class,
Application.class,
abstractListener);
abstractListener.reset();
application.publishEvent(getFacesContext(),
PostConstructApplicationEvent.class,
Application.class,
application);
assertTrue(abstractListener.getPassedSource() == application);
assertTrue(abstractListener.getPassedSystemEvent() instanceof PostConstructApplicationEvent);
assertTrue(abstractListener.getPassedSystemEvent().getSource() == application);
// verify that the event isn't published when the base type isn't
// provided with publish
abstractListener.reset();
application.publishEvent(getFacesContext(),
PostConstructApplicationEvent.class,
application);
assertTrue(abstractListener.getPassedSource() == null);
assertTrue(abstractListener.getPassedSystemEvent() == null);
// cleanup
application.unsubscribeFromEvent(PostConstructApplicationEvent.class,
Application.class,
abstractListener);
}
////////////////////////////////////////////////////////////////////////////
// Test Application subscribeToEvent() and unsubscribeToEvent() without
// a specific source.
public void testEvents3() {
TestListener listener = new TestListener(UIComponent.class);
Application application = getFacesContext().getApplication();
application.subscribeToEvent(TestApplicationEvents.TestSystemEvent2.class,
listener);
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent2.class,
getFacesContext().getViewRoot());
assertTrue(listener.getPassedSource() == getFacesContext().getViewRoot());
assertTrue(listener.getPassedSystemEvent() instanceof TestSystemEvent2);
assertTrue(listener.getPassedSystemEvent().getSource() == getFacesContext().getViewRoot());
// any UIComponent source should work
listener.reset();
UIInput input = new UIInput();
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent2.class, input);
assertTrue(listener.getPassedSource() == input);
assertTrue(listener.getPassedSystemEvent() instanceof TestSystemEvent2);
assertTrue(listener.getPassedSystemEvent().getSource() == input);
// non UIComponent SystemEventListenerHolder shouldn't result in the
// listener being used
listener.reset();
TestSystemEventListenerHolder holder = new TestSystemEventListenerHolder();
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent2.class,
holder);
assertTrue(listener.getPassedSource() == holder);
assertTrue(!listener.wasProcessEventInvoked());
assertTrue(listener.getPassedSystemEvent() == null);
// unsubscribe
listener.reset();
application.unsubscribeFromEvent(TestApplicationEvents.TestSystemEvent2.class, listener);
application.publishEvent(getFacesContext(),
TestApplicationEvents.TestSystemEvent2.class,
input);
assertTrue(!listener.wasIsListenerForSourceInvoked());
assertTrue(!listener.wasProcessEventInvoked());
}
public void testListenersFromConfig() {
FacesContext ctx = getFacesContext();
Application app = ctx.getApplication();
// SystemEventListener1 is only interested in UIOutput sources, while
// SystemEventListener2 is interested in any events.
app.publishEvent(getFacesContext(),
CustomSystemEvent.class,
new UIInput());
assertNull(ctx.getAttributes().remove("SystemEventListener1"));
assertNotNull(ctx.getAttributes().remove("SystemEventListener2"));
app.publishEvent(getFacesContext(),
CustomSystemEvent.class,
new UIOutput());
assertNotNull(ctx.getAttributes().remove("SystemEventListener1"));
assertNotNull(ctx.getAttributes().remove("SystemEventListener2"));
}
// ----------------------------------------------------------- Inner Classes
private static final class TestComponentListener
implements ComponentSystemEventListener {
private SystemEvent passedEvent;
boolean processEventInvoked;
// -------------------------------------------------------- Constructors
public TestComponentListener() { }
// --------------------------- Methods from ComponentSystemEventListener
public void processEvent(ComponentSystemEvent event)
throws AbortProcessingException {
passedEvent = event;
processEventInvoked = true;
}
// ------------------------------------------------------ Public Methods
public void reset() {
passedEvent = null;
processEventInvoked = false;
}
public boolean wasProcessEventInvoked() {
return processEventInvoked;
}
public SystemEvent getPassedEvent() {
return passedEvent;
}
} // END TestComponentListener
private static final class TestListener implements SystemEventListener {
private Class> sourceFor;
private Object passedSource;
private SystemEvent passedEvent;
boolean processEventInvoked;
private boolean forSourceInvoked;
// -------------------------------------------------------- Constructors
public TestListener() { }
public TestListener(Class> sourceFor) {
this.sourceFor = sourceFor;
}
// ------------------------------------- Methods for SystemEventListener
public void processEvent(SystemEvent event)
throws AbortProcessingException {
processEventInvoked = true;
passedEvent = event;
}
public boolean isListenerForSource(Object source) {
forSourceInvoked = true;
passedSource = source;
if (sourceFor == null) {
return (source != null);
} else {
return sourceFor.isInstance(source);
}
}
// ------------------------------------------------------ Public Methods
public Object getPassedSource() {
return passedSource;
}
public SystemEvent getPassedSystemEvent() {
return passedEvent;
}
public boolean wasProcessEventInvoked() {
return processEventInvoked;
}
public boolean wasIsListenerForSourceInvoked() {
return forSourceInvoked;
}
public void reset() {
passedSource = null;
passedEvent = null;
processEventInvoked = false;
forSourceInvoked = false;
}
public void setSourceFor(Class> sourceFor) {
this.sourceFor = sourceFor;
}
} // END TestListener
public class CustomViewRoot extends UIViewRoot {
} // END CustomViewRoot
public static final class TestSystemEvent extends SystemEvent {
private static final long serialVersionUID = -1623739732540866805L;
// -------------------------------------------------------- Constructors
public TestSystemEvent(UIViewRoot root) {
super(root);
}
// -------------------------------------------- Methods from SystemEvent
@Override
public boolean isAppropriateListener(FacesListener listener) {
return (listener instanceof TestListener);
}
@Override
public void processListener(FacesListener listener) {
super.processListener(listener);
}
} // END TestSystemEvent
public static final class TestSystemEvent2 extends SystemEvent {
private static final long serialVersionUID = -5903799319964180305L;
// -------------------------------------------------------- Constructors
public TestSystemEvent2(UIComponent root) {
super(root);
}
} // END TestSystemEvent2
private static final class TestSystemEventListenerHolder
implements SystemEventListenerHolder {
public ListNavigationHandlerImpl
functionality.
* It uses two xml files:
* 1) faces-navigation.xml --> contains the navigation cases themselves.
* 2) navigation-cases.xml --> contains the test cases including expected
* view identifier outcomes for this test to validate against.
* Both files exist under web/test/WEB-INF
.
* UIViewRoot
corresponding the
* viewId
by restoring the view structure and state.
*/
protected UIViewRoot restoreSerializedView(FacesContext context,
SerializedView sv, String viewId) {
if ( sv == null) {
return null;
}
TreeStructure structRoot = (TreeStructure) sv.getStructure();
if (structRoot == null) {
return null;
}
UIComponent viewRoot = structRoot.createComponent();
if (viewRoot != null) {
restoreComponentTreeStructure(structRoot, viewRoot);
Object state = sv.getState();
viewRoot.processRestoreState(context, state);
}
return ((UIViewRoot)viewRoot);
}
/**
* Returns the value of ServletContextInitParameter that specifies the
* maximum number of logical views to be saved in session. If none is specified
* returns DEFAULT_NUMBER_OF_VIEWS_IN_SESSION
.
*/
protected int getNumberOfViewsParameter(FacesContext context) {
if (noOfViews != 0) {
return noOfViews;
}
noOfViews = DEFAULT_NUMBER_OF_VIEWS_IN_SESSION;
String noOfViewsStr = context.getExternalContext().
getInitParameter(NUMBER_OF_VIEWS_IN_SESSION);
if (noOfViewsStr != null) {
try {
noOfViews = Integer.valueOf(noOfViewsStr).intValue();
} catch (NumberFormatException nfe) {
}
}
return noOfViews;
}
/**
* Returns the value of ServletContextInitParameter that specifies the
* maximum number of views to be saved in this logical view. If none is specified
* returns DEFAULT_NUMBER_OF_VIEWS_IN_LOGICAL_VIEW_IN_SESSION
.
*/
protected int getNumberOfViewsInLogicalViewParameter(FacesContext context) {
if (noOfViewsInLogicalView != 0) {
return noOfViewsInLogicalView;
}
noOfViewsInLogicalView = DEFAULT_NUMBER_OF_VIEWS_IN_LOGICAL_VIEW_IN_SESSION;
String noOfViewsStr = context.getExternalContext().
getInitParameter(NUMBER_OF_VIEWS_IN_LOGICAL_VIEW_IN_SESSION);
if (noOfViewsStr != null) {
try {
noOfViewsInLogicalView = Integer.valueOf(noOfViewsStr).intValue();
} catch (NumberFormatException nfe) {
}
}
return noOfViewsInLogicalView;
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/TestFacesMessage.java 0000644 0000000 0000000 00000012412 11412443350 024142 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestFacesMessage.java
package com.sun.faces.application;
import com.sun.faces.cactus.ServletFacesTestCase;
import com.sun.faces.util.Util;
import java.io.*;
import javax.faces.application.FacesMessage;
/**
*
* TestFacesMessage is a class ...
*
* Lifetime And Scope FacesMessage
class
* functionality. It uses the xml configuration file:
* web/test/WEB-INF/faces-navigation.xml
.
*/
public class TestFacesMessage extends ServletFacesTestCase {
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public TestFacesMessage() {
super("TestFacesMessage");
}
public TestFacesMessage(String name) {
super(name);
}
//
// Class methods
//
//
// Methods from TestCase
//
//
// General Methods
//
public void testSerializeable() {
FacesMessage message = null;
// Case 0 (nothing)
message = new FacesMessage();
persistAndCheck(message);
// Case 1 (summary)
message = new FacesMessage("This is a bad error.");
persistAndCheck(message);
// Case 2 (summary & detail)
message = new FacesMessage("This is a bad error.", "This is a really bad error.");
persistAndCheck(message);
// Case 3 (severity, summary & detail)
message = new FacesMessage(FacesMessage.SEVERITY_FATAL, "This is a bad error.",
"This is a really bad error.");
persistAndCheck(message);
}
private void persistAndCheck(FacesMessage message) {
FacesMessage message1 = null;
String mSummary, mSummary1 = null;
String mDetail, mDetail1 = null;
String severity, severity1 = null;
ByteArrayOutputStream bos = null;
ByteArrayInputStream bis = null;
mSummary = message.getSummary();
mDetail = message.getDetail();
severity = message.getSeverity().toString();
try {
bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(message);
oos.close();
byte[] bytes = bos.toByteArray();
InputStream in = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(in);
message1 = (FacesMessage)ois.readObject();
ois.close();
mSummary1 = message1.getSummary();
mDetail1 = message1.getDetail();
severity1 = message1.getSeverity().toString();
if (null != mSummary1) {
assertTrue(mSummary1.equals(mSummary));
} else {
assertTrue(mSummary == null);
}
if (null != mDetail1) {
assertTrue(mDetail1.equals(mDetail));
} else {
assertTrue(mDetail == null);
}
if (null != severity1) {
assertTrue(severity1.equals(severity));
} else {
assertTrue(severity == null);
}
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
}
} // end of class TestFacesMessage
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/application/TestJSF2NavigationHandler.java 0000644 0000000 0000000 00000026442 11412443350 025646 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// TestNavigationHandler.java
package com.sun.faces.application;
import javax.faces.application.NavigationCase;
import com.sun.faces.cactus.ServletFacesTestCase;
import com.sun.faces.util.Util;
import com.sun.faces.config.DbfFactory;
import javax.faces.FactoryFinder;
import javax.faces.event.SystemEventListener;
import javax.faces.event.SystemEvent;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.PreDestroyViewMapEvent;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import javax.faces.application.NavigationHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.util.*;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.NamedNodeMap;
/**
* This class test the NavigationHandlerImpl
functionality.
* It uses two xml files:
* 1) faces-navigation.xml --> contains the navigation cases themselves.
* 2) navigation-cases.xml --> contains the test cases including expected
* view identifier outcomes for this test to validate against.
* Both files exist under web/test/WEB-INF
.
* StateManagerImpl
class
* functionality.
*/
public class TestHAStateManagerImpl extends ServletFacesTestCase {
public static final String TEST_URI = "/test.jsp";
//
// Constructors/Initializers
//
public TestHAStateManagerImpl() {
super("TestStateManagerImpl");
}
public TestHAStateManagerImpl(String name) {
super(name);
}
private Application application = null;
public void setUp() {
super.setUp();
ApplicationFactory aFactory =
(ApplicationFactory) FactoryFinder.getFactory(
FactoryFinder.APPLICATION_FACTORY);
application = (ApplicationImpl) aFactory.getApplication();
application.setViewHandler(new ViewHandlerImpl());
application.setStateManager(new StateManagerImpl());
}
//
// Test Methods
//
public void testHighAvailabilityStateSaving1() {
// precreate tree and set it in session and make sure the tree is
// restored from session.
UIViewRoot root = application.getViewHandler().createView(getFacesContext(), null);
root.setViewId(TEST_URI);
UIForm basicForm = new UIForm();
basicForm.setId("basicForm");
UIInput userName = new UIInput();
userName.setId("userName");
userName.setTransient(true);
root.getChildren().add(basicForm);
basicForm.getChildren().add(userName);
UIPanel panel1 = new UIPanel();
panel1.setId("panel1");
basicForm.getChildren().add(panel1);
UIInput userName1 = new UIInput();
userName1.setId("userName1");
panel1.getChildren().add(userName1);
getFacesContext().setViewRoot(root);
StateManager stateManager =
getFacesContext().getApplication().getStateManager();
stateManager.saveSerializedView(getFacesContext());
// make sure that the value of viewId attribute in session is an
// instance of SerializedView.
Object result = session.getAttribute(TEST_URI);
assertTrue(result instanceof SerializedView);
root = stateManager.restoreView(getFacesContext(), TEST_URI,
RenderKitFactory.HTML_BASIC_RENDER_KIT);
assertTrue(root != null);
basicForm = (UIForm) root.findComponent("basicForm");
assertTrue(basicForm != null);
userName = (UIInput) basicForm.findComponent("userName");
assertTrue(userName == null);
panel1 = (UIPanel) basicForm.findComponent("panel1");
assertTrue(panel1 != null);
userName1 = (UIInput) panel1.findComponent("userName1");
assertTrue(userName1 != null);
}
}
mojarra-2.0.3.orig/jsf-ri/test/com/sun/faces/CustomerBean.java 0000644 0000000 0000000 00000007072 11412443352 021050 0 ustar /*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces;
/**
*