JBoss Rich Faces SVN: r11290 - in trunk/test-applications/automator/src/main: java/general and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: adubovsky
Date: 2008-11-21 10:01:40 -0500 (Fri, 21 Nov 2008)
New Revision: 11290
Modified:
trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java
trunk/test-applications/automator/src/main/java/general/DrawGrids.java
trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp
trunk/test-applications/automator/src/main/webapp/javascripts/common.js
Log:
+ converterMessageCheck
Modified: trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java
===================================================================
--- trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java 2008-11-21 13:59:26 UTC (rev 11289)
+++ trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java 2008-11-21 15:01:40 UTC (rev 11290)
@@ -31,6 +31,7 @@
private boolean required;
private String align;
private String validatorMessage;
+ private String converterMessage;
private SelectItem value;
private boolean statusValidator = false;
@@ -40,6 +41,12 @@
private boolean statusValueChangeListener = false;
private String phaseValueChangeListener = "UNDEFINED";
+ private boolean statusConverterGetAsObject = false;
+ private boolean statusConverterGetAsString = false;
+ private String phaseConverterGetAsObject = "UNDEFINED";
+ private String phaseConverterGetAsString = "UNDEFINED";
+ private String converterMessageTest = "";
+
private TLDParser tldParser = new TLDParser("comboBox");
private AttributesList attrs = tldParser.getAllAttributes();
private ArrayList<Attribute> generalAttrs = attrs.getCommonAttributes();
@@ -49,6 +56,7 @@
required = true;
align = "right";
validatorMessage = "validator test message!";
+ converterMessage = "converter test message!";
selectItems = new ArrayList<SelectItem>();
for (int i = 0; i < 10; i++) {
@@ -62,6 +70,8 @@
this.validatorMessageCheck();
this.bindingCheck();
this.valueChangeListenerCheck();
+ this.converterCheck();
+ this.converterMessageCheck();
DrawGrids.showResultGrid(panelGrid, generalAttrs);
}
@@ -104,7 +114,7 @@
if (value != null) {
SelectItem st = (SelectItem) value;
- if (st.getLabel().equals("Gosha")) {
+ if (st.getLabel().equals("ValidatorCheck")) {
throw new ValidatorException(new FacesMessage(
FacesMessage.SEVERITY_ERROR, "Validation error",
"Incorrect input"));
@@ -146,7 +156,10 @@
UIComponent component, String newValue)
throws ConverterException {
- if (false)
+ statusConverterGetAsObject = true;
+ phaseConverterGetAsObject = PhaseTracker.currentPhase
+ .toString();
+ if (newValue.equals("ConverterCheck"))
throw new ConverterException(new FacesMessage(
FacesMessage.SEVERITY_ERROR, "Converter error",
"Error while convert to Object"));
@@ -158,6 +171,9 @@
UIComponent component, Object value)
throws ConverterException {
+ statusConverterGetAsString = true;
+ phaseConverterGetAsString = PhaseTracker.currentPhase
+ .toString();
if (false)
throw new ConverterException(new FacesMessage(
FacesMessage.SEVERITY_ERROR, "Converter error",
@@ -165,19 +181,66 @@
String result = "";
if (value != null) {
- if(value instanceof SelectItem) {
+ if (value instanceof SelectItem) {
SelectItem st = (SelectItem) value;
result = st.getLabel();
} else {
result = value.toString();
}
}
-
+
return result;
}
};
}
+ private void converterCheck() {
+ int index = generalAttrs.indexOf(new Attribute("converter"));
+ if (index == -1) {
+ generalAttrs.add(new Attribute("converter", "", "",
+ Status.IMPLEMENTED));
+ } else {
+ Attribute attr = generalAttrs.get(index);
+ if ((statusConverterGetAsObject) && (statusConverterGetAsString)) {
+ if (((phaseConverterGetAsObject.equals("PROCESS_VALIDATIONS 3"))
+ && (!immediate) || (phaseValueChangeListener
+ .equals("APPLY_REQUEST_VALUES 2"))
+ && (immediate))
+ && (phaseConverterGetAsString
+ .equals("RENDER_RESPONSE 6"))) {
+ attr.setStatus(Status.PASSED);
+ } else {
+ attr.setStatus(Status.FAILED);
+ attr
+ .setDescription("Converter was triggered on incorrect phase");
+ }
+ } else {
+ attr.setStatus(Status.FAILED);
+ attr.setDescription("Converter was not triggered");
+ }
+ }
+ }
+
+ private void converterMessageCheck() {
+ int index = generalAttrs.indexOf(new Attribute("converterMessage"));
+ if (index == -1) {
+ generalAttrs.add(new Attribute("converterMessage", "", "",
+ Status.IMPLEMENTED));
+ } else {
+ Attribute attr = generalAttrs.get(index);
+
+ if (converterMessageTest.equals("")) {
+ attr.setStatus(Status.IMPLEMENTED);
+ } else {
+ if (converterMessageTest.indexOf(converterMessage) != -1) {
+ attr.setStatus(Status.PASSED);
+ } else {
+ attr.setStatus(Status.FAILED);
+ }
+ }
+ }
+ }
+
private void alignCheck() {
int index = generalAttrs.indexOf(new Attribute("align"));
if (index == -1) {
@@ -213,10 +276,14 @@
} else {
Attribute attr = generalAttrs.get(index);
- if (validatorMessageTest.indexOf(validatorMessage) != -1) {
- attr.setStatus(Status.PASSED);
+ if (validatorMessageTest.equals("")) {
+ attr.setStatus(Status.IMPLEMENTED);
} else {
- attr.setStatus(Status.FAILED);
+ if (validatorMessageTest.indexOf(validatorMessage) != -1) {
+ attr.setStatus(Status.PASSED);
+ } else {
+ attr.setStatus(Status.FAILED);
+ }
}
}
}
@@ -292,4 +359,20 @@
public void setValue(SelectItem value) {
this.value = value;
}
+
+ public String getConverterMessage() {
+ return converterMessage;
+ }
+
+ public void setConverterMessage(String converterMessage) {
+ this.converterMessage = converterMessage;
+ }
+
+ public String getConverterMessageTest() {
+ return converterMessageTest;
+ }
+
+ public void setConverterMessageTest(String converterMessageTest) {
+ this.converterMessageTest = converterMessageTest;
+ }
}
\ No newline at end of file
Modified: trunk/test-applications/automator/src/main/java/general/DrawGrids.java
===================================================================
--- trunk/test-applications/automator/src/main/java/general/DrawGrids.java 2008-11-21 13:59:26 UTC (rev 11289)
+++ trunk/test-applications/automator/src/main/java/general/DrawGrids.java 2008-11-21 15:01:40 UTC (rev 11290)
@@ -41,6 +41,9 @@
case NOT_READY:
attrStatus.setStyle("color: grey");
break;
+ case IMPLEMENTED:
+ attrStatus.setStyle("color: blue");
+ break;
}
panelGrid.getChildren().add(attrName);
Modified: trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp
===================================================================
--- trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp 2008-11-21 13:59:26 UTC (rev 11289)
+++ trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp 2008-11-21 15:01:40 UTC (rev 11290)
@@ -18,6 +18,7 @@
required="#{comboBoxGeneral.required}"
validatorMessage="#{comboBoxGeneral.validatorMessage}"
converter="#{comboBoxGeneral.convert}"
+ converterMessage="#{comboBoxGeneral.converterMessage}"
onblur="callOnblur('comboBox')"
onmouseover="callOnmouseover('comboBox')"
onclick="callOnclick('comboBox')" onchange="callOnchange('comboBox')"
@@ -35,11 +36,14 @@
valueChangeListener="#{comboBoxGeneral.valueChangeListener}">
<f:selectItems value="#{comboBoxGeneral.selectItems}" />
- <f:selectItem itemValue="Gosha" itemLabel="Gosha" />
+ <f:selectItem itemValue="ValidatorCheck" itemLabel="Gosha" />
+ <f:selectItem itemValue="ConverterCheck" itemLabel="Gosha" />
</rich:comboBox>
- <h:inputHidden id="hiddenInput"
+ <h:inputHidden id="hiddenValidatorInput"
value="#{comboBoxGeneral.validatorMessageTest}" />
+ <h:inputHidden id="hiddenConverterInput"
+ value="#{comboBoxGeneral.converterMessageTest}" />
</h:panelGrid>
<rich:spacer height="30"></rich:spacer>
@@ -47,7 +51,8 @@
<f:facet name="header">
<h:outputText value="Results of testing" />
</f:facet>
- <a4j:commandButton value="testGeneralAttrs" onclick="checkValidatorMessage()"
+ <a4j:commandButton value="testGeneralAttrs" onmousedown="checkValidatorMessage()"
+ onmouseup="checkConverterMessage()"
actionListener="#{comboBoxGeneral.testGeneralAttributes}"
reRender="generalResult, comboBoxGrid"></a4j:commandButton>
<a4j:commandButton value="testHandlers"
Modified: trunk/test-applications/automator/src/main/webapp/javascripts/common.js
===================================================================
--- trunk/test-applications/automator/src/main/webapp/javascripts/common.js 2008-11-21 13:59:26 UTC (rev 11289)
+++ trunk/test-applications/automator/src/main/webapp/javascripts/common.js 2008-11-21 15:01:40 UTC (rev 11290)
@@ -1,7 +1,15 @@
function checkValidatorMessage(){
var mes = document.getElementById('mainForm:comboBoxSubview:mess');
- var inp = document.getElementById('mainForm:comboBoxSubview:hiddenInput');
+ var inp = document.getElementById('mainForm:comboBoxSubview:hiddenValidatorInput');
if ((mes != null)&&(inp != null)) {
- inp.value = mes.textContent;
+ if (mes.textContent.indexOf('converter') == -1) inp.value = mes.textContent;
}
+}
+
+function checkConverterMessage(){
+ var mes = document.getElementById('mainForm:comboBoxSubview:mess');
+ var inp = document.getElementById('mainForm:comboBoxSubview:hiddenConverterInput');
+ if ((mes != null)&&(inp != null)) {
+ if (mes.textContent.indexOf('validator') == -1) inp.value = mes.textContent;
+ }
}
\ No newline at end of file
17 years, 1 month
JBoss Rich Faces SVN: r11289 - trunk/ui/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts.
by richfaces-svn-commits@lists.jboss.org
Author: pyaschenko
Date: 2008-11-21 08:59:26 -0500 (Fri, 21 Nov 2008)
New Revision: 11289
Modified:
trunk/ui/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js
Log:
comments added
Modified: trunk/ui/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js
===================================================================
--- trunk/ui/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js 2008-11-21 13:58:26 UTC (rev 11288)
+++ trunk/ui/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js 2008-11-21 13:59:26 UTC (rev 11289)
@@ -182,6 +182,7 @@
collapse: function(){
if (!this.disabled) {
if (this.expanded){
+ // TODO: PY: don't understand why we are using _getDirectChildrenByTag. We have this.inputs, this.inputState, this.inputAction
if (this._getDirectChildrenByTag(this.content,"INPUT")[0]!=null){
this._getDirectChildrenByTag(this.content,"INPUT")[0].value="closed";}
for (var i = 0; i < this.childObj.length; i++){
@@ -440,7 +441,6 @@
_getDirectChildrenByTag: function(e, tagName) {
var allKids = e.childNodes;
var kids = new Array();
- var ddk;
tagName = tagName.toLowerCase();
for( var i = 0 ; i < allKids.length ; i++ )
if ( allKids[i] && allKids[i].tagName && allKids[i].tagName.toLowerCase() == tagName )
17 years, 1 month
JBoss Rich Faces SVN: r11288 - trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js.
by richfaces-svn-commits@lists.jboss.org
Author: pyaschenko
Date: 2008-11-21 08:58:26 -0500 (Fri, 21 Nov 2008)
New Revision: 11288
Modified:
trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/swfobject.js
Log:
https://jira.jboss.org/jira/browse/RF-4579
Modified: trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/swfobject.js
===================================================================
--- trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/swfobject.js 2008-11-21 13:18:37 UTC (rev 11287)
+++ trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/swfobject.js 2008-11-21 13:58:26 UTC (rev 11288)
@@ -1,33 +1,5 @@
-/* SWFObject v2.0 <http://code.google.com/p/swfobject/>
- Copyright (c) 2007 Geoff Stearns, Michael Williams, and Bobby van der Sluis
+/* SWFObject v2.1 <http://code.google.com/p/swfobject/>
+ Copyright (c) 2007-2008 Geoff Stearns, Michael Williams, and Bobby van der Sluis
This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
-
-/*
-Open Source Initiative OSI - The MIT License:Licensing
-Tue, 2006-10-31 04:56 � nelson
-
-The MIT License
-
-Copyright (c) <year> <copyright holders>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-var swfobject=function(){var Z="undefined",P="object",B="Shockwave Flash",h="ShockwaveFlash.ShockwaveFlash",W="application/x-shockwave-flash",K="SWFObjectExprInst",G=window,g=document,N=navigator,f=[],H=[],Q=null,L=null,T=null,S=false,C=false;var a=function(){var l=typeof g.getElementById!=Z&&typeof g.getElementsByTagName!=Z&&typeof g.createElement!=Z&&typeof g.appendChild!=Z&&typeof g.replaceChild!=Z&&typeof g.removeChild!=Z&&typeof g.cloneNode!=Z,t=[0,0,0],n=null;if(typeof N.plugins!=Z&&typeof N.plugins[B]==P){n=N.plugins[B].description;if(n){n=n.replace(/^.*\s+(\S+\s+\S+$)/,"$1");t[0]=parseInt(n.replace(/^(.*)\..*$/,"$1"),10);t[1]=parseInt(n.replace(/^.*\.(.*)\s.*$/,"$1"),10);t[2]=/r/.test(n)?parseInt(n.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof G.ActiveXObject!=Z){var o=null,s=false;try{o=new ActiveXObject(h+".7")}catch(k){try{o=new ActiveXObject(h+".6");t=[6,0,21];o.AllowScriptAccess="always"}catch(k){if(t[0]==6){s=true}}if(!s){try{o=new ActiveXObject(h)}catch(k){!
}}}if(!s&&o){try{n=o.GetVariable("$version");if(n){n=n.split(" ")[1].split(",");t=[parseInt(n[0],10),parseInt(n[1],10),parseInt(n[2],10)]}}catch(k){}}}}var v=N.userAgent.toLowerCase(),j=N.platform.toLowerCase(),r=/webkit/.test(v)?parseFloat(v.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,i=false,q=j?/win/.test(j):/win/.test(v),m=j?/mac/.test(j):/mac/.test(v);/*@cc_on i=true;@if(@_win32)q=true;@elif(@_mac)m=true;@end@*/return{w3cdom:l,pv:t,webkit:r,ie:i,win:q,mac:m}}();var e=function(){if(!a.w3cdom){return }J(I);if(a.ie&&a.win){try{g.write("<script id=__ie_ondomload defer=true src=//:><\/script>");var i=c("__ie_ondomload");if(i){i.onreadystatechange=function(){if(this.readyState=="complete"){this.parentNode.removeChild(this);V()}}}}catch(j){}}if(a.webkit&&typeof g.readyState!=Z){Q=setInterval(function(){if(/loaded|complete/.test(g.readyState)){V()}},10)}if(typeof g.addEventListener!=Z){g.addEventListener("DOMContentLoaded",V,null)}M(V)}();function V(){if(S){return }if(a!
.ie&&a.win){var m=Y("span");try{var l=g.getElementsByTagName("body")[0
].appendChild(m);l.parentNode.removeChild(l)}catch(n){return }}S=true;if(Q){clearInterval(Q);Q=null}var j=f.length;for(var k=0;k<j;k++){f[k]()}}function J(i){if(S){i()}else{f[f.length]=i}}function M(j){if(typeof G.addEventListener!=Z){G.addEventListener("load",j,false)}else{if(typeof g.addEventListener!=Z){g.addEventListener("load",j,false)}else{if(typeof G.attachEvent!=Z){G.attachEvent("onload",j)}else{if(typeof G.onload=="function"){var i=G.onload;G.onload=function(){i();j()}}else{G.onload=j}}}}}function I(){var l=H.length;for(var j=0;j<l;j++){var m=H[j].id;if(a.pv[0]>0){var k=c(m);if(k){H[j].width=k.getAttribute("width")?k.getAttribute("width"):"0";H[j].height=k.getAttribute("height")?k.getAttribute("height"):"0";if(O(H[j].swfVersion)){if(a.webkit&&a.webkit<312){U(k)}X(m,true)}else{if(H[j].expressInstall&&!C&&O("6.0.65")&&(a.win||a.mac)){D(H[j])}else{d(k)}}}}else{X(m,true)}}}function U(m){var k=m.getElementsByTagName(P)[0];if(k){var p=Y("embed"),r=k.attributes;if(r){var o!
=r.length;for(var n=0;n<o;n++){if(r[n].nodeName.toLowerCase()=="data"){p.setAttribute("src",r[n].nodeValue)}else{p.setAttribute(r[n].nodeName,r[n].nodeValue)}}}var q=k.childNodes;if(q){var s=q.length;for(var l=0;l<s;l++){if(q[l].nodeType==1&&q[l].nodeName.toLowerCase()=="param"){p.setAttribute(q[l].getAttribute("name"),q[l].getAttribute("value"))}}}m.parentNode.replaceChild(p,m)}}function F(i){if(a.ie&&a.win&&O("8.0.0")){G.attachEvent("onunload",function(){var k=c(i);if(k){for(var j in k){if(typeof k[j]=="function"){k[j]=function(){}}}k.parentNode.removeChild(k)}})}}function D(j){C=true;var o=c(j.id);if(o){if(j.altContentId){var l=c(j.altContentId);if(l){L=l;T=j.altContentId}}else{L=b(o)}if(!(/%$/.test(j.width))&&parseInt(j.width,10)<310){j.width="310"}if(!(/%$/.test(j.height))&&parseInt(j.height,10)<137){j.height="137"}g.title=g.title.slice(0,47)+" - Flash Player Installation";var n=a.ie&&a.win?"ActiveX":"PlugIn",k=g.title,m="MMredirectURL="+G.location+"&MMplayerType="+n+"!
&MMdoctitle="+k,p=j.id;if(a.ie&&a.win&&o.readyState!=4){var i=Y("div")
;p+="SWFObjectNew";i.setAttribute("id",p);o.parentNode.insertBefore(i,o);o.style.display="none";G.attachEvent("onload",function(){o.parentNode.removeChild(o)})}R({data:j.expressInstall,id:K,width:j.width,height:j.height},{flashvars:m},p)}}function d(j){if(a.ie&&a.win&&j.readyState!=4){var i=Y("div");j.parentNode.insertBefore(i,j);i.parentNode.replaceChild(b(j),i);j.style.display="none";G.attachEvent("onload",function(){j.parentNode.removeChild(j)})}else{j.parentNode.replaceChild(b(j),j)}}function b(n){var m=Y("div");if(a.win&&a.ie){m.innerHTML=n.innerHTML}else{var k=n.getElementsByTagName(P)[0];if(k){var o=k.childNodes;if(o){var j=o.length;for(var l=0;l<j;l++){if(!(o[l].nodeType==1&&o[l].nodeName.toLowerCase()=="param")&&!(o[l].nodeType==8)){m.appendChild(o[l].cloneNode(true))}}}}}return m}function R(AE,AC,q){var p,t=c(q);if(typeof AE.id==Z){AE.id=q}if(a.ie&&a.win){var AD="";for(var z in AE){if(AE[z]!=Object.prototype[z]){if(z=="data"){AC.movie=AE[z]}else{if(z.toLowerCase()=!
="styleclass"){AD+=' class="'+AE[z]+'"'}else{if(z!="classid"){AD+=" "+z+'="'+AE[z]+'"'}}}}}var AB="";for(var y in AC){if(AC[y]!=Object.prototype[y]){AB+='<param name="'+y+'" value="'+AC[y]+'" />'}}t.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AD+">"+AB+"</object>";F(AE.id);p=c(AE.id)}else{if(a.webkit&&a.webkit<312){var AA=Y("embed");AA.setAttribute("type",W);for(var x in AE){if(AE[x]!=Object.prototype[x]){if(x=="data"){AA.setAttribute("src",AE[x])}else{if(x.toLowerCase()=="styleclass"){AA.setAttribute("class",AE[x])}else{if(x!="classid"){AA.setAttribute(x,AE[x])}}}}}for(var w in AC){if(AC[w]!=Object.prototype[w]){if(w!="movie"){AA.setAttribute(w,AC[w])}}}t.parentNode.replaceChild(AA,t);p=AA}else{var s=Y(P);s.setAttribute("type",W);for(var v in AE){if(AE[v]!=Object.prototype[v]){if(v.toLowerCase()=="styleclass"){s.setAttribute("class",AE[v])}else{if(v!="classid"){s.setAttribute(v,AE[v])}}}}for(var u in AC){if(AC[u]!=Object.prototype[u]&&u!="movie!
"){E(s,u,AC[u])}}t.parentNode.replaceChild(s,t);p=s}}return p}function
E(k,i,j){var l=Y("param");l.setAttribute("name",i);l.setAttribute("value",j);k.appendChild(l)}function c(i){return g.getElementById(i)}function Y(i){return g.createElement(i)}function O(k){var j=a.pv,i=k.split(".");i[0]=parseInt(i[0],10);i[1]=parseInt(i[1],10);i[2]=parseInt(i[2],10);return(j[0]>i[0]||(j[0]==i[0]&&j[1]>i[1])||(j[0]==i[0]&&j[1]==i[1]&&j[2]>=i[2]))?true:false}function A(m,j){if(a.ie&&a.mac){return }var l=g.getElementsByTagName("head")[0],k=Y("style");k.setAttribute("type","text/css");k.setAttribute("media","screen");if(!(a.ie&&a.win)&&typeof g.createTextNode!=Z){k.appendChild(g.createTextNode(m+" {"+j+"}"))}l.appendChild(k);if(a.ie&&a.win&&typeof g.styleSheets!=Z&&g.styleSheets.length>0){var i=g.styleSheets[g.styleSheets.length-1];if(typeof i.addRule==P){i.addRule(m,j)}}}function X(k,i){var j=i?"visible":"hidden";if(S){c(k).style.visibility=j}else{A("#"+k,"visibility:"+j)}}return{registerObject:function(l,i,k){if(!a.w3cdom||!l||!i){return }var j={};j.id=l;j.sw!
fVersion=i;j.expressInstall=k?k:false;H[H.length]=j;X(l,false)},getObjectById:function(l){var i=null;if(a.w3cdom&&S){var j=c(l);if(j){var k=j.getElementsByTagName(P)[0];if(!k||(k&&typeof j.SetVariable!=Z)){i=j}else{if(typeof k.SetVariable!=Z){i=k}}}}return i},embedSWF:function(n,u,r,t,j,m,k,p,s){if(!a.w3cdom||!n||!u||!r||!t||!j){return }r+="";t+="";if(O(j)){X(u,false);var q=(typeof s==P)?s:{};q.data=n;q.width=r;q.height=t;var o=(typeof p==P)?p:{};if(typeof k==P){for(var l in k){if(k[l]!=Object.prototype[l]){if(typeof o.flashvars!=Z){o.flashvars+="&"+l+"="+k[l]}else{o.flashvars=l+"="+k[l]}}}}J(function(){R(q,o,u);if(q.id==u){X(u,true)}})}else{if(m&&!C&&O("6.0.65")&&(a.win||a.mac)){X(u,false);J(function(){var i={};i.id=i.altContentId=u;i.width=r;i.height=t;i.expressInstall=m;D(i)})}}},getFlashPlayerVersion:function(){return{major:a.pv[0],minor:a.pv[1],release:a.pv[2]}},hasFlashPlayerVersion:O,createSWF:function(k,j,i){if(a.w3cdom&&S){return R(k,j,i)}else{return undefined}},cr!
eateCSS:function(j,i){if(a.w3cdom){A(j,i)}},addDomLoadEvent:J,addLoadE
vent:M,getQueryParamValue:function(m){var l=g.location.search||g.location.hash;if(m==null){return l}if(l){var k=l.substring(1).split("&");for(var j=0;j<k.length;j++){if(k[j].substring(0,k[j].indexOf("="))==m){return k[j].substring((k[j].indexOf("=")+1))}}}return""},expressInstallCallback:function(){if(C&&L){var i=c(K);if(i){i.parentNode.replaceChild(L,i);if(T){X(T,true);if(a.ie&&a.win){L.style.display="block"}}L=null;T=null;C=false}}}}}();
\ No newline at end of file
+var swfobject=function(){var b="undefined",Q="object",n="Shockwave Flash",p="ShockwaveFlash.ShockwaveFlash",P="application/x-shockwave-flash",m="SWFObjectExprInst",j=window,K=document,T=navigator,o=[],N=[],i=[],d=[],J,Z=null,M=null,l=null,e=false,A=false;var h=function(){var v=typeof K.getElementById!=b&&typeof K.getElementsByTagName!=b&&typeof K.createElement!=b,AC=[0,0,0],x=null;if(typeof T.plugins!=b&&typeof T.plugins[n]==Q){x=T.plugins[n].description;if(x&&!(typeof T.mimeTypes!=b&&T.mimeTypes[P]&&!T.mimeTypes[P].enabledPlugin)){x=x.replace(/^.*\s+(\S+\s+\S+$)/,"$1");AC[0]=parseInt(x.replace(/^(.*)\..*$/,"$1"),10);AC[1]=parseInt(x.replace(/^.*\.(.*)\s.*$/,"$1"),10);AC[2]=/r/.test(x)?parseInt(x.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof j.ActiveXObject!=b){var y=null,AB=false;try{y=new ActiveXObject(p+".7")}catch(t){try{y=new ActiveXObject(p+".6");AC=[6,0,21];y.AllowScriptAccess="always"}catch(t){if(AC[0]==6){AB=true}}if(!AB){try{y=new ActiveXObject(p)}catch(t){}}}if!
(!AB&&y){try{x=y.GetVariable("$version");if(x){x=x.split(" ")[1].split(",");AC=[parseInt(x[0],10),parseInt(x[1],10),parseInt(x[2],10)]}}catch(t){}}}}var AD=T.userAgent.toLowerCase(),r=T.platform.toLowerCase(),AA=/webkit/.test(AD)?parseFloat(AD.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,q=false,z=r?/win/.test(r):/win/.test(AD),w=r?/mac/.test(r):/mac/.test(AD);/*@cc_on q=true;@if(@_win32)z=true;@elif(@_mac)w=true;@end@*/return{w3cdom:v,pv:AC,webkit:AA,ie:q,win:z,mac:w}}();var L=function(){if(!h.w3cdom){return }f(H);if(h.ie&&h.win){try{K.write("<script id=__ie_ondomload defer=true src=//:><\/script>");J=C("__ie_ondomload");if(J){I(J,"onreadystatechange",S)}}catch(q){}}if(h.webkit&&typeof K.readyState!=b){Z=setInterval(function(){if(/loaded|complete/.test(K.readyState)){E()}},10)}if(typeof K.addEventListener!=b){K.addEventListener("DOMContentLoaded",E,null)}R(E)}();function S(){if(J.readyState=="complete"){J.parentNode.removeChild(J);E()}}function E(){if(e){return }if(h!
.ie&&h.win){var v=a("span");try{var u=K.getElementsByTagName("body")[0
].appendChild(v);u.parentNode.removeChild(u)}catch(w){return }}e=true;if(Z){clearInterval(Z);Z=null}var q=o.length;for(var r=0;r<q;r++){o[r]()}}function f(q){if(e){q()}else{o[o.length]=q}}function R(r){if(typeof j.addEventListener!=b){j.addEventListener("load",r,false)}else{if(typeof K.addEventListener!=b){K.addEventListener("load",r,false)}else{if(typeof j.attachEvent!=b){I(j,"onload",r)}else{if(typeof j.onload=="function"){var q=j.onload;j.onload=function(){q();r()}}else{j.onload=r}}}}}function H(){var t=N.length;for(var q=0;q<t;q++){var u=N[q].id;if(h.pv[0]>0){var r=C(u);if(r){N[q].width=r.getAttribute("width")?r.getAttribute("width"):"0";N[q].height=r.getAttribute("height")?r.getAttribute("height"):"0";if(c(N[q].swfVersion)){if(h.webkit&&h.webkit<312){Y(r)}W(u,true)}else{if(N[q].expressInstall&&!A&&c("6.0.65")&&(h.win||h.mac)){k(N[q])}else{O(r)}}}}else{W(u,true)}}}function Y(t){var q=t.getElementsByTagName(Q)[0];if(q){var w=a("embed"),y=q.attributes;if(y){var v=y.length;!
for(var u=0;u<v;u++){if(y[u].nodeName=="DATA"){w.setAttribute("src",y[u].nodeValue)}else{w.setAttribute(y[u].nodeName,y[u].nodeValue)}}}var x=q.childNodes;if(x){var z=x.length;for(var r=0;r<z;r++){if(x[r].nodeType==1&&x[r].nodeName=="PARAM"){w.setAttribute(x[r].getAttribute("name"),x[r].getAttribute("value"))}}}t.parentNode.replaceChild(w,t)}}function k(w){A=true;var u=C(w.id);if(u){if(w.altContentId){var y=C(w.altContentId);if(y){M=y;l=w.altContentId}}else{M=G(u)}if(!(/%$/.test(w.width))&&parseInt(w.width,10)<310){w.width="310"}if(!(/%$/.test(w.height))&&parseInt(w.height,10)<137){w.height="137"}K.title=K.title.slice(0,47)+" - Flash Player Installation";var z=h.ie&&h.win?"ActiveX":"PlugIn",q=K.title,r="MMredirectURL="+j.location+"&MMplayerType="+z+"&MMdoctitle="+q,x=w.id;if(h.ie&&h.win&&u.readyState!=4){var t=a("div");x+="SWFObjectNew";t.setAttribute("id",x);u.parentNode.insertBefore(t,u);u.style.display="none";var v=function(){u.parentNode.removeChild(u)};I(j,"onload",v)}!
U({data:w.expressInstall,id:m,width:w.width,height:w.height},{flashvar
s:r},x)}}function O(t){if(h.ie&&h.win&&t.readyState!=4){var r=a("div");t.parentNode.insertBefore(r,t);r.parentNode.replaceChild(G(t),r);t.style.display="none";var q=function(){t.parentNode.removeChild(t)};I(j,"onload",q)}else{t.parentNode.replaceChild(G(t),t)}}function G(v){var u=a("div");if(h.win&&h.ie){u.innerHTML=v.innerHTML}else{var r=v.getElementsByTagName(Q)[0];if(r){var w=r.childNodes;if(w){var q=w.length;for(var t=0;t<q;t++){if(!(w[t].nodeType==1&&w[t].nodeName=="PARAM")&&!(w[t].nodeType==8)){u.appendChild(w[t].cloneNode(true))}}}}}return u}function U(AG,AE,t){var q,v=C(t);if(v){if(typeof AG.id==b){AG.id=t}if(h.ie&&h.win){var AF="";for(var AB in AG){if(AG[AB]!=Object.prototype[AB]){if(AB.toLowerCase()=="data"){AE.movie=AG[AB]}else{if(AB.toLowerCase()=="styleclass"){AF+=' class="'+AG[AB]+'"'}else{if(AB.toLowerCase()!="classid"){AF+=" "+AB+'="'+AG[AB]+'"'}}}}}var AD="";for(var AA in AE){if(AE[AA]!=Object.prototype[AA]){AD+='<param name="'+AA+'" value="'+AE[AA]+'" />'}}!
v.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AF+">"+AD+"</object>";i[i.length]=AG.id;q=C(AG.id)}else{if(h.webkit&&h.webkit<312){var AC=a("embed");AC.setAttribute("type",P);for(var z in AG){if(AG[z]!=Object.prototype[z]){if(z.toLowerCase()=="data"){AC.setAttribute("src",AG[z])}else{if(z.toLowerCase()=="styleclass"){AC.setAttribute("class",AG[z])}else{if(z.toLowerCase()!="classid"){AC.setAttribute(z,AG[z])}}}}}for(var y in AE){if(AE[y]!=Object.prototype[y]){if(y.toLowerCase()!="movie"){AC.setAttribute(y,AE[y])}}}v.parentNode.replaceChild(AC,v);q=AC}else{var u=a(Q);u.setAttribute("type",P);for(var x in AG){if(AG[x]!=Object.prototype[x]){if(x.toLowerCase()=="styleclass"){u.setAttribute("class",AG[x])}else{if(x.toLowerCase()!="classid"){u.setAttribute(x,AG[x])}}}}for(var w in AE){if(AE[w]!=Object.prototype[w]&&w.toLowerCase()!="movie"){F(u,w,AE[w])}}v.parentNode.replaceChild(u,v);q=u}}}return q}function F(t,q,r){var u=a("param");u.setAttribute("name!
",q);u.setAttribute("value",r);t.appendChild(u)}function X(r){var q=C(
r);if(q&&(q.nodeName=="OBJECT"||q.nodeName=="EMBED")){if(h.ie&&h.win){if(q.readyState==4){B(r)}else{j.attachEvent("onload",function(){B(r)})}}else{q.parentNode.removeChild(q)}}}function B(t){var r=C(t);if(r){for(var q in r){if(typeof r[q]=="function"){r[q]=null}}r.parentNode.removeChild(r)}}function C(t){var q=null;try{q=K.getElementById(t)}catch(r){}return q}function a(q){return K.createElement(q)}function I(t,q,r){t.attachEvent(q,r);d[d.length]=[t,q,r]}function c(t){var r=h.pv,q=t.split(".");q[0]=parseInt(q[0],10);q[1]=parseInt(q[1],10)||0;q[2]=parseInt(q[2],10)||0;return(r[0]>q[0]||(r[0]==q[0]&&r[1]>q[1])||(r[0]==q[0]&&r[1]==q[1]&&r[2]>=q[2]))?true:false}function V(v,r){if(h.ie&&h.mac){return }var u=K.getElementsByTagName("head")[0],t=a("style");t.setAttribute("type","text/css");t.setAttribute("media","screen");if(!(h.ie&&h.win)&&typeof K.createTextNode!=b){t.appendChild(K.createTextNode(v+" {"+r+"}"))}u.appendChild(t);if(h.ie&&h.win&&typeof K.styleSheets!=b&&K.styleSheet!
s.length>0){var q=K.styleSheets[K.styleSheets.length-1];if(typeof q.addRule==Q){q.addRule(v,r)}}}function W(t,q){var r=q?"visible":"hidden";if(e&&C(t)){C(t).style.visibility=r}else{V("#"+t,"visibility:"+r)}}function g(s){var r=/[\\\"<>\.;]/;var q=r.exec(s)!=null;return q?encodeURIComponent(s):s}var D=function(){if(h.ie&&h.win){window.attachEvent("onunload",function(){var w=d.length;for(var v=0;v<w;v++){d[v][0].detachEvent(d[v][1],d[v][2])}var t=i.length;for(var u=0;u<t;u++){X(i[u])}for(var r in h){h[r]=null}h=null;for(var q in swfobject){swfobject[q]=null}swfobject=null})}}();return{registerObject:function(u,q,t){if(!h.w3cdom||!u||!q){return }var r={};r.id=u;r.swfVersion=q;r.expressInstall=t?t:false;N[N.length]=r;W(u,false)},getObjectById:function(v){var q=null;if(h.w3cdom){var t=C(v);if(t){var u=t.getElementsByTagName(Q)[0];if(!u||(u&&typeof t.SetVariable!=b)){q=t}else{if(typeof u.SetVariable!=b){q=u}}}}return q},embedSWF:function(x,AE,AB,AD,q,w,r,z,AC){if(!h.w3cdom||!x||!!
AE||!AB||!AD||!q){return }AB+="";AD+="";if(c(q)){W(AE,false);var AA={}
;if(AC&&typeof AC===Q){for(var v in AC){if(AC[v]!=Object.prototype[v]){AA[v]=AC[v]}}}AA.data=x;AA.width=AB;AA.height=AD;var y={};if(z&&typeof z===Q){for(var u in z){if(z[u]!=Object.prototype[u]){y[u]=z[u]}}}if(r&&typeof r===Q){for(var t in r){if(r[t]!=Object.prototype[t]){if(typeof y.flashvars!=b){y.flashvars+="&"+t+"="+r[t]}else{y.flashvars=t+"="+r[t]}}}}f(function(){U(AA,y,AE);if(AA.id==AE){W(AE,true)}})}else{if(w&&!A&&c("6.0.65")&&(h.win||h.mac)){A=true;W(AE,false);f(function(){var AF={};AF.id=AF.altContentId=AE;AF.width=AB;AF.height=AD;AF.expressInstall=w;k(AF)})}}},getFlashPlayerVersion:function(){return{major:h.pv[0],minor:h.pv[1],release:h.pv[2]}},hasFlashPlayerVersion:c,createSWF:function(t,r,q){if(h.w3cdom){return U(t,r,q)}else{return undefined}},removeSWF:function(q){if(h.w3cdom){X(q)}},createCSS:function(r,q){if(h.w3cdom){V(r,q)}},addDomLoadEvent:f,addLoadEvent:R,getQueryParamValue:function(v){var u=K.location.search||K.location.hash;if(v==null){return g(u)}if(u){!
var t=u.substring(1).split("&");for(var r=0;r<t.length;r++){if(t[r].substring(0,t[r].indexOf("="))==v){return g(t[r].substring((t[r].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(A&&M){var q=C(m);if(q){q.parentNode.replaceChild(M,q);if(l){W(l,true);if(h.ie&&h.win){M.style.display="block"}}M=null;l=null;A=false}}}}}();
\ No newline at end of file
17 years, 1 month
JBoss Rich Faces SVN: r11287 - in trunk/test-applications/automator/src/main: webapp/component and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: adubovsky
Date: 2008-11-21 08:18:37 -0500 (Fri, 21 Nov 2008)
New Revision: 11287
Modified:
trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java
trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp
Log:
+ converter
Modified: trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java
===================================================================
--- trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java 2008-11-21 09:42:06 UTC (rev 11286)
+++ trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java 2008-11-21 13:18:37 UTC (rev 11287)
@@ -7,6 +7,8 @@
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
@@ -29,11 +31,12 @@
private boolean required;
private String align;
private String validatorMessage;
+ private SelectItem value;
private boolean statusValidator = false;
private String phaseValidator = "UNDEFINED";
private String validatorMessageTest = "";
-
+
private boolean statusValueChangeListener = false;
private String phaseValueChangeListener = "UNDEFINED";
@@ -42,7 +45,7 @@
private ArrayList<Attribute> generalAttrs = attrs.getCommonAttributes();
public ComboBoxGeneral() {
- immediate = false;
+ immediate = true;
required = true;
align = "right";
validatorMessage = "validator test message!";
@@ -62,28 +65,24 @@
DrawGrids.showResultGrid(panelGrid, generalAttrs);
}
-
+
public void valueChangeListener(ValueChangeEvent e) {
- System.out.println("valueChangeListener work!!!!!!!!!!!!!!");
-
statusValueChangeListener = true;
phaseValueChangeListener = PhaseTracker.currentPhase.toString();
}
-
- public void valueChangeListenerCheck() {
+
+ private void valueChangeListenerCheck() {
int index = generalAttrs.indexOf(new Attribute("valueChangeListener"));
if (index == -1) {
- generalAttrs
- .add(new Attribute(
- "valueChangeListener",
- "",
- "", Status.IMPLEMENTED));
+ generalAttrs.add(new Attribute("valueChangeListener", "", "",
+ Status.IMPLEMENTED));
} else {
Attribute attr = generalAttrs.get(index);
if (statusValueChangeListener) {
if ((phaseValueChangeListener.equals("PROCESS_VALIDATIONS 3"))
&& (!immediate)
- || (phaseValueChangeListener.equals("APPLY_REQUEST_VALUES 2"))
+ || (phaseValueChangeListener
+ .equals("APPLY_REQUEST_VALUES 2"))
&& (immediate)) {
attr.setStatus(Status.PASSED);
} else {
@@ -103,13 +102,14 @@
statusValidator = true;
phaseValidator = PhaseTracker.currentPhase.toString();
- String selectedItem = null;
- if (value != null)
- selectedItem = value.toString();
- if (selectedItem.equals("Gosha"))
- throw new ValidatorException(new FacesMessage(
- FacesMessage.SEVERITY_ERROR, "Validation error",
- "Incorrect input"));
+ if (value != null) {
+ SelectItem st = (SelectItem) value;
+ if (st.getLabel().equals("Gosha")) {
+ throw new ValidatorException(new FacesMessage(
+ FacesMessage.SEVERITY_ERROR, "Validation error",
+ "Incorrect input"));
+ }
+ }
}
private void validatorCheck() {
@@ -140,6 +140,44 @@
}
}
+ public Converter getConvert() {
+ return new Converter() {
+ public Object getAsObject(FacesContext context,
+ UIComponent component, String newValue)
+ throws ConverterException {
+
+ if (false)
+ throw new ConverterException(new FacesMessage(
+ FacesMessage.SEVERITY_ERROR, "Converter error",
+ "Error while convert to Object"));
+
+ return new SelectItem(newValue);
+ }
+
+ public String getAsString(FacesContext context,
+ UIComponent component, Object value)
+ throws ConverterException {
+
+ if (false)
+ throw new ConverterException(new FacesMessage(
+ FacesMessage.SEVERITY_ERROR, "Converter error",
+ "Error while convert to String"));
+
+ String result = "";
+ if (value != null) {
+ if(value instanceof SelectItem) {
+ SelectItem st = (SelectItem) value;
+ result = st.getLabel();
+ } else {
+ result = value.toString();
+ }
+ }
+
+ return result;
+ }
+ };
+ }
+
private void alignCheck() {
int index = generalAttrs.indexOf(new Attribute("align"));
if (index == -1) {
@@ -246,4 +284,12 @@
public void setValidatorMessageTest(String validatorMessageTest) {
this.validatorMessageTest = validatorMessageTest;
}
+
+ public SelectItem getValue() {
+ return value;
+ }
+
+ public void setValue(SelectItem value) {
+ this.value = value;
+ }
}
\ No newline at end of file
Modified: trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp
===================================================================
--- trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp 2008-11-21 09:42:06 UTC (rev 11286)
+++ trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp 2008-11-21 13:18:37 UTC (rev 11287)
@@ -12,9 +12,12 @@
<h:messages id="mess" style="color: red" />
<rich:comboBox id="comboBox" binding="#{comboBoxGeneral.comboBox}"
align="#{comboBoxGeneral.align}"
+ immediate="#{comboBoxGeneral.immediate}"
+ value="#{comboBoxGeneral.value}"
validator="#{comboBoxGeneral.validate}"
required="#{comboBoxGeneral.required}"
validatorMessage="#{comboBoxGeneral.validatorMessage}"
+ converter="#{comboBoxGeneral.convert}"
onblur="callOnblur('comboBox')"
onmouseover="callOnmouseover('comboBox')"
onclick="callOnclick('comboBox')" onchange="callOnchange('comboBox')"
17 years, 1 month
JBoss Rich Faces SVN: r11286 - in trunk/test-applications/automator/src/main: webapp/component and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: adubovsky
Date: 2008-11-21 04:42:06 -0500 (Fri, 21 Nov 2008)
New Revision: 11286
Modified:
trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java
trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp
Log:
Modified: trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java
===================================================================
--- trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java 2008-11-21 00:59:48 UTC (rev 11285)
+++ trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java 2008-11-21 09:42:06 UTC (rev 11286)
@@ -8,6 +8,7 @@
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
+import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import javax.faces.validator.ValidatorException;
import org.richfaces.component.html.HtmlComboBox;
@@ -29,9 +30,12 @@
private String align;
private String validatorMessage;
- private String statusValidator = "FAILED";
+ private boolean statusValidator = false;
private String phaseValidator = "UNDEFINED";
private String validatorMessageTest = "";
+
+ private boolean statusValueChangeListener = false;
+ private String phaseValueChangeListener = "UNDEFINED";
private TLDParser tldParser = new TLDParser("comboBox");
private AttributesList attrs = tldParser.getAllAttributes();
@@ -54,13 +58,49 @@
this.alignCheck();
this.validatorMessageCheck();
this.bindingCheck();
+ this.valueChangeListenerCheck();
DrawGrids.showResultGrid(panelGrid, generalAttrs);
}
+
+ public void valueChangeListener(ValueChangeEvent e) {
+ System.out.println("valueChangeListener work!!!!!!!!!!!!!!");
+
+ statusValueChangeListener = true;
+ phaseValueChangeListener = PhaseTracker.currentPhase.toString();
+ }
+
+ public void valueChangeListenerCheck() {
+ int index = generalAttrs.indexOf(new Attribute("valueChangeListener"));
+ if (index == -1) {
+ generalAttrs
+ .add(new Attribute(
+ "valueChangeListener",
+ "",
+ "", Status.IMPLEMENTED));
+ } else {
+ Attribute attr = generalAttrs.get(index);
+ if (statusValueChangeListener) {
+ if ((phaseValueChangeListener.equals("PROCESS_VALIDATIONS 3"))
+ && (!immediate)
+ || (phaseValueChangeListener.equals("APPLY_REQUEST_VALUES 2"))
+ && (immediate)) {
+ attr.setStatus(Status.PASSED);
+ } else {
+ attr.setStatus(Status.FAILED);
+ attr
+ .setDescription("ValueChangeListener was triggered on incorrect phase");
+ }
+ } else {
+ attr.setStatus(Status.FAILED);
+ attr.setDescription("ValueChangeListener was not triggered");
+ }
+ }
+ }
public void validate(FacesContext context, UIComponent component,
Object value) throws ValidatorException {
- statusValidator = "PASSED";
+ statusValidator = true;
phaseValidator = PhaseTracker.currentPhase.toString();
String selectedItem = null;
@@ -82,7 +122,7 @@
"", Status.IMPLEMENTED));
} else {
Attribute attr = generalAttrs.get(index);
- if (statusValidator.equals("PASSED")) {
+ if (statusValidator) {
if ((phaseValidator.equals("PROCESS_VALIDATIONS 3"))
&& (!immediate)
|| (phaseValidator.equals("APPLY_REQUEST_VALUES 2"))
Modified: trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp
===================================================================
--- trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp 2008-11-21 00:59:48 UTC (rev 11285)
+++ trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp 2008-11-21 09:42:06 UTC (rev 11286)
@@ -28,10 +28,13 @@
onmousemove="callOnmousemove('comboBox')"
onmouseout="callOnmouseout('comboBox')"
onmouseup="callOnmouseup('comboBox')"
- onselect="callOnselect('comboBox')">
+ onselect="callOnselect('comboBox')"
+ valueChangeListener="#{comboBoxGeneral.valueChangeListener}">
+
<f:selectItems value="#{comboBoxGeneral.selectItems}" />
<f:selectItem itemValue="Gosha" itemLabel="Gosha" />
</rich:comboBox>
+
<h:inputHidden id="hiddenInput"
value="#{comboBoxGeneral.validatorMessageTest}" />
</h:panelGrid>
17 years, 1 month
JBoss Rich Faces SVN: r11285 - in trunk/ui/core/src: main/java/org/ajax4jsf/renderkit/html and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2008-11-20 19:59:48 -0500 (Thu, 20 Nov 2008)
New Revision: 11285
Modified:
trunk/ui/core/src/main/config/component/queue.xml
trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRenderer.java
trunk/ui/core/src/test/java/org/ajax4jsf/component/AbstractQueueComponentTest.java
trunk/ui/core/src/test/java/org/ajax4jsf/component/ImplicitQueuesTest.java
trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueScriptedTest.java
trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueSizeTest.java
trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-scripted.xhtml
trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-size.xhtml
trunk/ui/core/src/test/resources/org/ajax4jsf/component/simulation.js
Log:
a4j:queue
- latest fixes and updates
- unit tests for client-side code
Modified: trunk/ui/core/src/main/config/component/queue.xml
===================================================================
--- trunk/ui/core/src/main/config/component/queue.xml 2008-11-21 00:57:50 UTC (rev 11284)
+++ trunk/ui/core/src/main/config/component/queue.xml 2008-11-21 00:59:48 UTC (rev 11285)
@@ -80,7 +80,7 @@
<classname>java.lang.String</classname>
</property>
<property>
- <name>onSizeExceeded</name>
+ <name>onsizeexceeded</name>
<classname>java.lang.String</classname>
</property>
</component>
Modified: trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRenderer.java
===================================================================
--- trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRenderer.java 2008-11-21 00:57:50 UTC (rev 11284)
+++ trunk/ui/core/src/main/java/org/ajax4jsf/renderkit/html/QueueRenderer.java 2008-11-21 00:59:48 UTC (rev 11285)
@@ -50,17 +50,10 @@
private static final String QUEUE_ONERROR_ATTRIBUTE = "queueonerror";
private static final String[] QUEUE_ATTRIBUTES = new String[] {
- "enabled",
"size",
"sizeExceededBehavior"
};
- private static final String[] QUEUE_FUNCTION_ATTRIBUTES = new String[] {
- "onSizeExceeded",
- "onError",
- "onExpired"
- };
-
private static final String[] REQUEST_ATTRIBUTES = new String[] {
"requestDelay",
"timeout",
@@ -124,27 +117,24 @@
data.addRequestAttribute(attributeName, value);
}
}
-
- for (String attributeName : QUEUE_FUNCTION_ATTRIBUTES) {
- Object value = attributes.get(attributeName);
- if (isNotEmpty(value)) {
- //TODO nick - apply proper functions signature
- data.addQueueAttribute(attributeName, new JSFunctionDefinition("event").addToBody(value));
- }
+
+ String onsizeexceeded = queue.getOnsizeexceeded();
+ if (isNotEmpty(onsizeexceeded)) {
+ data.addQueueAttribute("onsizeexceeded", new JSFunctionDefinition("query", "options", "event").addToBody(onsizeexceeded));
}
String oncomplete = queue.getOncomplete();
- if (oncomplete != null) {
+ if (isNotEmpty(oncomplete)) {
data.addRequestAttribute(QUEUE_ONCOMPLETE_ATTRIBUTE, AjaxRendererUtils.buildAjaxOncomplete(oncomplete));
}
String onBeforeDomUpdate = queue.getOnbeforedomupdate();
- if (onBeforeDomUpdate != null) {
+ if (isNotEmpty(onBeforeDomUpdate)) {
data.addRequestAttribute(QUEUE_ONBEFOREDOMUPDATE_ATTRIBUTE, AjaxRendererUtils.buildAjaxOnBeforeDomUpdate(onBeforeDomUpdate));
}
String onsubmit = queue.getOnsubmit();
- if (onsubmit != null) {
+ if (isNotEmpty(onsubmit)) {
JSFunctionDefinition onsubmitFunction = new JSFunctionDefinition("request");
onsubmitFunction.addToBody(onsubmit);
@@ -152,7 +142,7 @@
}
String onerror = queue.getOnerror();
- if (onerror != null) {
+ if (isNotEmpty(onerror)) {
JSFunctionDefinition onerrorFunction = new JSFunctionDefinition("request", "status", "message");
onerrorFunction.addToBody(onerror);
Modified: trunk/ui/core/src/test/java/org/ajax4jsf/component/AbstractQueueComponentTest.java
===================================================================
--- trunk/ui/core/src/test/java/org/ajax4jsf/component/AbstractQueueComponentTest.java 2008-11-21 00:57:50 UTC (rev 11284)
+++ trunk/ui/core/src/test/java/org/ajax4jsf/component/AbstractQueueComponentTest.java 2008-11-21 00:59:48 UTC (rev 11285)
@@ -41,14 +41,18 @@
import javax.faces.render.Renderer;
import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.JSLiteral;
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.UserResourceRenderer2;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.mozilla.javascript.FunctionObject;
import org.mozilla.javascript.NativeArray;
import org.mozilla.javascript.NativeObject;
+import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.Undefined;
import com.gargoylesoftware.htmlunit.AlertHandler;
@@ -75,6 +79,8 @@
private static final String AJAX_SUBMIT = "ajaxSubmit";
+ public static final int DEFAULT_REQUEST_TIME = 1000;
+
protected HtmlPage page;
public final static class AjaxSubmitFunctionComponent extends UIComponentBase {
@@ -98,20 +104,21 @@
throws IOException {
JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(component, facesContext);
Map<String, Object> options = AjaxRendererUtils.buildEventOptions(facesContext, component);
- options.put("requestDelay", new JSReference("parameters.requestDelay"));
- options.put("requestId", new JSReference("parameters.requestId || '" + component.getClientId(facesContext) + "'"));
+ options.put("requestDelay", new JSReference("options.requestDelay"));
+ options.put("requestId", new JSReference("options.requestId || '" + component.getClientId(facesContext) + "'"));
options.put("data", new JSReference("data"));
- options.put("requestTime", new JSReference("parameters.requestTime || 1000"));
- options.put("timeout", new JSReference("parameters.timeout"));
- options.put("eventsQueue", new JSReference("parameters.eventsQueue"));
- options.put("implicitEventsQueue", new JSReference("parameters.implicitEventsQueue"));
+ options.put("requestTime", new JSReference("options.requestTime"));
+ options.put("timeout", new JSReference("options.timeout"));
+ options.put("eventsQueue", new JSReference("options.eventsQueue"));
+ options.put("implicitEventsQueue", new JSReference("options.implicitEventsQueue"));
+ options.put("ignoreDupResponses", new JSReference("options.ignoreDupResponses"));
ajaxFunction.addParameter(options);
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.startElement(HTML.SCRIPT_ELEM, component);
responseWriter.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
- responseWriter.writeText("var " + AJAX_SUBMIT + " = function(data, parameters) {" + ajaxFunction.toScript() + "};", null);
+ responseWriter.writeText("var " + AJAX_SUBMIT + " = function(data, options) {" + ajaxFunction.toScript() + "};", null);
responseWriter.endElement(HTML.SCRIPT_ELEM);
}
@@ -139,7 +146,6 @@
resource = (UIResource) application.createComponent("org.ajax4jsf.LoadScript");
resource.setSrc("resource:///org/ajax4jsf/component/simulation.js");
viewRoot.getChildren().add(resource);
-
}
@Override
@@ -164,8 +170,8 @@
return this;
}
- private String getParamatersString() {
- return ScriptUtils.toScript(parameters);
+ protected Map<String, Object> getParameters() {
+ return parameters;
}
public ParametersBuilder requestDelay(double value) {
@@ -186,6 +192,9 @@
public ParametersBuilder implicitEventsQueue(String name) {
return new ParametersBuilder(this.parameters).put("implicitEventsQueue", name);
}
+ public ParametersBuilder ignoreDupResponses(boolean value) {
+ return new ParametersBuilder(this.parameters).put("ignoreDupResponses", value);
+ }
}
protected ParametersBuilder createAjaxParameters() {
@@ -288,7 +297,7 @@
}
};
- protected void assertRequestData(RequestData requestData, String data,
+ protected void checkRequestData(RequestData requestData, String data,
double startTime, double endTime, boolean aborted) {
assertEquals("Data check failed for " + requestData, data, requestData.getData());
@@ -298,22 +307,18 @@
}
- protected void ajax(String data, String parameters) {
- page.executeJavaScript("simulationContext.ajax('" + data + "', " + parameters + ");");
+ protected void ajax(int time, String data, ParametersBuilder builder) {
+ JSFunction function = new JSFunction("simulationContext.ajax", time, data, builder.getParameters());
+ page.executeJavaScript(function.toScript());
}
+
+ protected void executeOnTime(int time, String expression) {
+ JSFunction function = new JSFunction("simulationContext.executeOnTime",
+ time, new JSFunctionDefinition().addToBody(expression));
- protected void ajax(String data, ParametersBuilder builder) {
- ajax(data, builder.getParamatersString());
+ page.executeJavaScript(function.toScript());
}
- protected void executeAfterDelay(String expression) {
- page.executeJavaScript("simulationContext.executeAfterDelay(function(){" + expression + "});");
- }
-
- protected void delay(int delayValue) {
- page.executeJavaScript("simulationContext.wait(" + delayValue + ");");
- }
-
protected String getRootContextPath() {
return this.getClass().getPackage().getName().replace('.', '/');
}
@@ -344,6 +349,7 @@
protected void preRenderView() throws Exception {
StringBuilder builder = new StringBuilder("<script type='text/javascript'>");
+ builder.append("DEFAULT_REQUEST_TIME = " + DEFAULT_REQUEST_TIME + ";");
builder.append("window.simulationContext = new SimulationContext(");
builder.append(AJAX_SUBMIT);
builder.append(");</script>");
@@ -355,12 +361,48 @@
List<UIComponent> childList = facesContext.getViewRoot().getChildren();
childList.add(childList.size(), text);
}
+
+ protected void postRenderView() throws Exception {
+ ScriptableObject scriptableObject = (ScriptableObject) this.page.executeJavaScript("window.LOG").getJavaScriptResult();
+ scriptableObject.defineProperty("out", systemOut, ScriptableObject.READONLY);
+ }
+ private static final ScriptableObject systemOut = new ScriptableObject() {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8574162538513136625L;
+
+ @Override
+ public String getClassName() {
+ return "systemOut";
+ }
+
+ @SuppressWarnings("unused")
+ public void println(String s) {
+ System.out.println(s);
+ }
+ };
+
+ static {
+ try {
+ systemOut.defineProperty("println",
+ new FunctionObject(null, systemOut.getClass().getMethod("println", String.class), systemOut),
+ ScriptableObject.READONLY);
+ } catch (SecurityException e) {
+ throw new IllegalStateException(e.getMessage(), e);
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException(e.getMessage(), e);
+ }
+ }
+
protected HtmlPage renderView(String viewId) throws Exception {
buildView(viewId);
preRenderView();
this.page = super.renderView();
-
+ postRenderView();
+
return this.page;
}
@@ -368,6 +410,7 @@
protected HtmlPage renderView() throws Exception {
preRenderView();
this.page = super.renderView();
+ postRenderView();
return this.page;
}
@@ -423,7 +466,6 @@
public void handleAlert(Page page, String message) {
fail(message);
}
-
});
}
}
@@ -435,6 +477,9 @@
static {
ENTITIES_MAP.put("'", "\"");
ENTITIES_MAP.put(""", "'");
+ ENTITIES_MAP.put("&", "&");
+ ENTITIES_MAP.put("<", "<");
+ ENTITIES_MAP.put(">", ">");
}
private static final Pattern ENTITIES_PATTERN;
Modified: trunk/ui/core/src/test/java/org/ajax4jsf/component/ImplicitQueuesTest.java
===================================================================
--- trunk/ui/core/src/test/java/org/ajax4jsf/component/ImplicitQueuesTest.java 2008-11-21 00:57:50 UTC (rev 11284)
+++ trunk/ui/core/src/test/java/org/ajax4jsf/component/ImplicitQueuesTest.java 2008-11-21 00:59:48 UTC (rev 11285)
@@ -43,8 +43,8 @@
renderView();
- ajax("a", createAjaxParameters().requestTime(1000));
- ajax("b", createAjaxParameters().requestTime(1000));
+ ajax(0, "a", createAjaxParameters().requestTime(1000));
+ ajax(0, "b", createAjaxParameters().requestTime(1000));
TestsResult result = getTestsResult();
assertEquals(2000d, result.getCurrentTime());
@@ -53,8 +53,8 @@
public void testImplicitGlobalQueueDefault() throws Exception {
renderView();
- ajax("a", createAjaxParameters().requestTime(1000));
- ajax("b", createAjaxParameters().requestTime(1000));
+ ajax(0, "a", createAjaxParameters().requestTime(1000));
+ ajax(0, "b", createAjaxParameters().requestTime(1000));
TestsResult result = getTestsResult();
assertEquals(1000d, result.getCurrentTime());
@@ -63,11 +63,9 @@
public void testLegacyQueuesRequestDelay() throws Exception {
renderView("/queue-legacy.xhtml");
- executeAfterDelay("$('form:buttonDelayed').click()");
- delay(500);
- executeAfterDelay("$('form:buttonDelayed').click()");
- delay(250);
- executeAfterDelay("$('form:buttonDelayed').click()");
+ executeOnTime(0, "$('form:buttonDelayed').click()");
+ executeOnTime(500, "$('form:buttonDelayed').click()");
+ executeOnTime(750, "$('form:buttonDelayed').click()");
TestsResult result = getTestsResult();
List<RequestData> dataList = result.getDataList();
@@ -75,7 +73,7 @@
//request time set to 5000 in .xhtml file
RequestData data = dataList.get(0);
- assertRequestData(data, null, 1750, 6750, false);
+ checkRequestData(data, null, 1750, 6750, false);
assertEquals(6750d, result.getCurrentTime());
}
@@ -83,13 +81,9 @@
public void testLegacyQueuesIgnoreDupResponces() throws Exception {
renderView("/queue-legacy.xhtml");
- executeAfterDelay("$('form:buttonIgnoreDupResponces').click()");
- delay(500);
-
- executeAfterDelay("$('form:buttonIgnoreDupResponces').click()");
- delay(250);
-
- executeAfterDelay("$('form:buttonIgnoreDupResponces').click()");
+ executeOnTime(0, "$('form:buttonIgnoreDupResponces').click()");
+ executeOnTime(500, "$('form:buttonIgnoreDupResponces').click()");
+ executeOnTime(750, "$('form:buttonIgnoreDupResponces').click()");
executeTimer();
TestsResult result = getTestsResult();
@@ -97,9 +91,9 @@
assertEquals(3, dataList.size());
//request time set to 5000 in .xhtml file
- assertRequestData(dataList.get(0), null, 0, 5000, false);
- assertRequestData(dataList.get(1), null, 500, 5500, false);
- assertRequestData(dataList.get(2), null, 750, 5750, false);
+ checkRequestData(dataList.get(0), null, 0, 5000, false);
+ checkRequestData(dataList.get(1), null, 500, 5500, false);
+ checkRequestData(dataList.get(2), null, 750, 5750, false);
assertEquals(5750d, result.getCurrentTime());
Modified: trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueScriptedTest.java
===================================================================
--- trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueScriptedTest.java 2008-11-21 00:57:50 UTC (rev 11284)
+++ trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueScriptedTest.java 2008-11-21 00:59:48 UTC (rev 11285)
@@ -24,6 +24,8 @@
import java.util.List;
+import org.mozilla.javascript.NativeArray;
+
/**
* @author Denis Morozov
* @author Nick Belaevski
@@ -38,18 +40,133 @@
super(name);
}
+ public void testRequestDelayDefined() throws Exception {
+ renderView(VIEW_NAME);
+
+ ParametersBuilder parametersBuilder = createAjaxParameters().
+ eventsQueue("queueRequestDelay").requestTime(5);
+
+ ajax(0, "a", parametersBuilder);
+ ajax(25, "b", parametersBuilder);
+ ajax(50, "c", parametersBuilder.requestDelay(30));
+ ajax(90, "d", parametersBuilder.requestDelay(0));
+
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+
+ assertEquals(4, dataList.size());
+
+ checkRequestData(dataList.get(0), "a", 15, 20, false);
+ checkRequestData(dataList.get(1), "b", 40, 45, false);
+ checkRequestData(dataList.get(2), "c", 80, 85, false);
+ checkRequestData(dataList.get(3), "d", 90, 95, false);
+ }
+
+ public void testRequestDelayDefault() throws Exception {
+ renderView(VIEW_NAME);
+
+ ParametersBuilder parametersBuilder = createAjaxParameters().eventsQueue("queueDefaults").
+ requestTime(100);
+
+ ajax(0, "a", parametersBuilder.requestDelay(100));
+ ajax(300, "b", parametersBuilder);
+
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+
+ assertEquals(2, dataList.size());
+
+ checkRequestData(dataList.get(0), "a", 100, 200, false);
+ checkRequestData(dataList.get(1), "b", 300, 400, false);
+ }
+
+ public void testTimeout() throws Exception {
+ renderView(VIEW_NAME);
+
+ ParametersBuilder parametersBuilder = createAjaxParameters().
+ eventsQueue("queueTimeout").requestDelay(0);
+
+ ajax(0, "a", parametersBuilder.requestTime(4999));
+ ajax(10000, "b", parametersBuilder.requestTime(5001).requestId("b"));
+ ajax(10000, "c", parametersBuilder.requestTime(100).requestId("c"));
+ ajax(20000, "d", parametersBuilder.requestTime(10000).timeout(10000));
+ ajax(40000, "e", parametersBuilder.requestTime(10001).timeout(10000));
+
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+
+ assertEquals(5, dataList.size());
+
+ checkRequestData(dataList.get(0), "a", 0, 4999, false);
+ checkRequestData(dataList.get(1), "b", 10000, 15000, true);
+ checkRequestData(dataList.get(2), "c", 15000, 15100, false);
+ checkRequestData(dataList.get(3), "d", 20000, 30000, false);
+ checkRequestData(dataList.get(4), "e", 40000, 50000, true);
+
+ }
+
+ public void testIgnoreDupResponses() throws Exception {
+ renderView(VIEW_NAME);
+
+ ParametersBuilder parametersBuilder = createAjaxParameters().
+ eventsQueue("queueIgnoreDupResponses").requestDelay(0).requestTime(1000);
+
+ ajax(0, "a", parametersBuilder.requestId("a"));
+ ajax(500, "b", parametersBuilder.requestId("a"));
+ ajax(2000, "c", parametersBuilder.requestId("a"));
+ ajax(2500, "d", parametersBuilder.requestId("a").ignoreDupResponses(false));
+
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+
+ assertEquals(4, dataList.size());
+
+ checkRequestData(dataList.get(0), "a", 0, 1000, false);
+ checkRequestData(dataList.get(1), "b", 500, 1500, false);
+
+ checkRequestData(dataList.get(2), "c", 2000, 3000, false);
+ checkRequestData(dataList.get(3), "d", 3000, 4000, false);
+
+ NativeArray array = (NativeArray) executeJavaScript("queueIgnoreDupResponsesTest");
+ long length = array.getLength();
+ assertEquals(3, length);
+
+ assertEquals("b:1500", (String) array.get(0, array));
+ assertEquals("c:3000", (String) array.get(1, array));
+ assertEquals("d:4000", (String) array.get(2, array));
+ }
+
+ public void testIgnoreDupResponsesDefault() throws Exception {
+ renderView(VIEW_NAME);
+
+ ParametersBuilder parametersBuilder = createAjaxParameters().
+ eventsQueue("queueDefaults").requestTime(500);
+
+ ajax(0, "a", parametersBuilder);
+ ajax(250, "b", parametersBuilder);
+ ajax(750, "c", parametersBuilder.ignoreDupResponses(true));
+
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+
+ assertEquals(3, dataList.size());
+
+ checkRequestData(dataList.get(0), "a", 0, 500, false);
+ checkRequestData(dataList.get(1), "b", 500, 1000, false);
+ checkRequestData(dataList.get(2), "c", 750, 1250, false);
+ }
+
public void testSimpleAjax() throws Exception {
renderView(VIEW_NAME);
- delay(50);
- ajax("a", createAjaxParameters().requestTime(100));
- ajax("b", createAjaxParameters().requestTime(150));
+ ajax(50, "a", createAjaxParameters().requestTime(100));
+ ajax(50, "b", createAjaxParameters().requestTime(150));
TestsResult result = getTestsResult();
List<RequestData> dataList = result.getDataList();
assertEquals(2, dataList.size());
- assertRequestData(dataList.get(0), "a", 50, 150, false);
- assertRequestData(dataList.get(1), "b", 50, 200, false);
+ checkRequestData(dataList.get(0), "a", 50, 150, false);
+ checkRequestData(dataList.get(1), "b", 50, 200, false);
assertEquals(200d, result.getCurrentTime());
}
@@ -57,33 +174,19 @@
public void testSimpleQueuedAjax() throws Exception {
renderView(VIEW_NAME);
- delay(50);
ParametersBuilder queueParameters = createAjaxParameters().requestTime(500).eventsQueue(QUEUE_NAME);
- ajax("a", queueParameters.requestId(0));
- delay(200);
- ajax("b", queueParameters.requestId(1));
+ ajax(50, "a", queueParameters.requestId(0));
+ ajax(250, "b", queueParameters.requestId(1));
TestsResult result = getTestsResult();
List<RequestData> dataList = result.getDataList();
assertEquals(2, dataList.size());
- assertRequestData(dataList.get(0), "a", 50, 550, false);
- assertRequestData(dataList.get(1), "b", 550, 1050, false);
+ checkRequestData(dataList.get(0), "a", 50, 550, false);
+ checkRequestData(dataList.get(1), "b", 550, 1050, false);
assertEquals(1050d, result.getCurrentTime());
}
- public void testScript() throws Exception {
- renderView(VIEW_NAME);
-
- delay(500);
- ajax("a", "{requestDelay: 100, requestId: '12', requestTime: 100, eventsQueue: 'q'}");
- delay(4100);
- ajax("b", "{requestDelay: 4400, requestId: '12', requestTime: 101, timeout: 10, eventsQueue: 'q'}");
- ajax("c", "{requestDelay: 0, requestId: '123', requestTime: 1, timeout: 10, eventsQueue: 'q'}");
-
- System.out.println(getTestsResult());
- }
-
public void testImplicitQueue() throws Exception {
renderView(VIEW_NAME);
@@ -92,18 +195,16 @@
implicitEventsQueue("myqueue").
requestTime(10);
- ajax("a", parameters);
- delay(10);
- ajax("b", parameters);
- delay(10);
- ajax("c", parameters.requestDelay(50));
+ ajax(0, "a", parameters);
+ ajax(10, "b", parameters);
+ ajax(20, "c", parameters.requestDelay(50));
TestsResult result = getTestsResult();
List<RequestData> dataList = result.getDataList();
assertEquals(1, dataList.size());
RequestData requestData = dataList.get(0);
- assertRequestData(requestData, "c", 70, 80, false);
+ checkRequestData(requestData, "c", 70, 80, false);
assertEquals(80d, result.getCurrentTime());
Modified: trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueSizeTest.java
===================================================================
--- trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueSizeTest.java 2008-11-21 00:57:50 UTC (rev 11284)
+++ trunk/ui/core/src/test/java/org/ajax4jsf/component/QueueSizeTest.java 2008-11-21 00:59:48 UTC (rev 11285)
@@ -21,10 +21,17 @@
package org.ajax4jsf.component;
+import java.text.NumberFormat;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
import java.util.UUID;
+import org.mozilla.javascript.NativeArray;
+import org.mozilla.javascript.ScriptableObject;
+
/**
* @author Nick Belaevski
* @since 3.3.0
@@ -36,14 +43,348 @@
super(name);
}
- public void testUnlimited() throws Exception {
+ private static final int numberOfEvents = 250;
+
+ private static abstract interface SequenceGenerator<T> {
+ public abstract T next();
+ }
+
+ protected TestsResult simulate(int numberOfEvents,
+ SequenceGenerator<Integer> userDelayGenerator,
+ SequenceGenerator<Integer> processTimeGenerator,
+ SequenceGenerator<String> requestIdGenerator) throws Exception {
+
+ NumberFormat numberFormat = NumberFormat.getInstance();
+ numberFormat.setGroupingUsed(false);
+ numberFormat.setMinimumIntegerDigits(String.valueOf(numberOfEvents).length());
+
renderView("/queue-size.xhtml");
ParametersBuilder parametersBuilder = createAjaxParameters().eventsQueue("defaultSizeQueue");
+
+ int time = 0;
- ajax("a", parametersBuilder.requestId(UUID.randomUUID().toString()));
+ for (int i = 0; i < numberOfEvents; i++) {
+ int userDelay = userDelayGenerator.next();
+ int requestTime = processTimeGenerator.next();
+
+ time += userDelay;
+ ajax(time, numberFormat.format(i), parametersBuilder.requestId(requestIdGenerator.next()).
+ requestTime(requestTime));
+ }
+
TestsResult result = getTestsResult();
+ return result;
}
+ protected void checkQueueOrdering(TestsResult result) throws Exception {
+ double time = 0;
+ String lastRequestId = "";
+
+ List<RequestData> dataList = result.getDataList();
+ Iterator<RequestData> itr = dataList.iterator();
+ while (itr.hasNext()) {
+ RequestData data = itr.next();
+
+ assertTrue(data.getStartTime() >= time);
+ assertTrue(data.getEndTime() >= data.getStartTime());
+ assertTrue(data.getData().compareTo(lastRequestId) > 0);
+
+ lastRequestId = data.getData();
+ time = data.getEndTime();
+ }
+ }
+
+ private static final class UUIDGenerator implements SequenceGenerator<String> {
+
+ public String next() {
+ return UUID.randomUUID().toString();
+ }
+
+ }
+
+ private static final class RandomSequenceGenerator implements SequenceGenerator<Integer> {
+
+ private int offset;
+
+ private int limit;
+
+ public RandomSequenceGenerator(int minimum, int maximum) {
+ super();
+
+ this.limit = maximum - minimum;
+ this.offset = minimum;
+ }
+
+ private Random random = new Random();
+
+ public Integer next() {
+ return random.nextInt(this.limit) + this.offset;
+ }
+
+ }
+
+ public void testUnlimitedOverload() throws Exception {
+ TestsResult result = simulate(numberOfEvents,
+ new RandomSequenceGenerator(5, 100),
+ new RandomSequenceGenerator(50, 300),
+ new UUIDGenerator()
+ );
+
+ checkQueueOrdering(result);
+ assertEquals(numberOfEvents, result.getDataList().size());
+ }
+
+ public void testUnlimitedUnderload() throws Exception {
+ TestsResult result = simulate(numberOfEvents,
+ new RandomSequenceGenerator(50, 300),
+ new RandomSequenceGenerator(5, 100),
+ new UUIDGenerator()
+ );
+
+ checkQueueOrdering(result);
+ assertEquals(numberOfEvents, result.getDataList().size());
+ }
+
+ private static final class TableRequestIdGenerator implements SequenceGenerator<String> {
+ private static final String[] requestIds = new String[] {
+ "aaa", "bbb", "ccc", "ddd", "eee", "fff"
+ };
+
+ private Random random = new Random();
+
+ private String lastValue;
+
+ private int uniqueIdsCounter = 0;
+
+ public String next() {
+ String newValue = requestIds[random.nextInt(requestIds.length)];
+
+ if (!newValue.equals(lastValue)) {
+ lastValue = newValue;
+ uniqueIdsCounter++;
+ }
+
+ return newValue;
+ }
+
+ public int getUniqueIdsCounter() {
+ return uniqueIdsCounter;
+ }
+ };
+
+
+ public void testUnlimitedEmulateUser() throws Exception {
+ TableRequestIdGenerator requestIdGenerator = new TableRequestIdGenerator();
+
+ TestsResult result = simulate(numberOfEvents,
+ new RandomSequenceGenerator(5, 100),
+ new RandomSequenceGenerator(5, 100),
+ requestIdGenerator
+ );
+
+ checkQueueOrdering(result);
+ assertTrue(requestIdGenerator.getUniqueIdsCounter() <= result.getDataList().size());
+ assertTrue(result.getDataList().size() <= numberOfEvents);
+ }
+
+ protected TestsResult checkQueue(String queueName) throws Exception {
+ renderView("/queue-size.xhtml");
+
+ ParametersBuilder parametersBuilder = createAjaxParameters().eventsQueue(queueName).
+ requestDelay(300).requestTime(300);
+
+ ajax(0, "a", parametersBuilder.requestId("a"));
+ ajax(100, "b", parametersBuilder.requestId("b"));
+ ajax(200, "c", parametersBuilder.requestId("c"));
+ ajax(300, "d", parametersBuilder.requestId("d"));
+ ajax(500, "e", parametersBuilder.requestId("e"));
+ ajax(600, "f", parametersBuilder.requestId("f"));
+
+ TestsResult result = getTestsResult();
+ return result;
+ }
+
+ protected TestsResult checkSingleQueue(String queueName) throws Exception {
+ renderView("/queue-size.xhtml");
+
+ ParametersBuilder parametersBuilder = createAjaxParameters().eventsQueue(queueName).
+ requestTime(300).requestDelay(200);
+
+ ajax(0, "a", parametersBuilder.requestId("a"));
+ ajax(100, "b", parametersBuilder.requestId("b"));
+ ajax(400, "c", parametersBuilder.requestId("c"));
+ ajax(500, "d", parametersBuilder.requestId("d"));
+ ajax(700, "e", parametersBuilder.requestId("e"));
+
+ TestsResult result = getTestsResult();
+ return result;
+ }
+
+ public void testDropNext() throws Exception {
+ TestsResult result = checkQueue("dropNextQueue");
+ List<RequestData> dataList = result.getDataList();
+
+ for (RequestData requestData : dataList) {
+ System.out.println(" " + requestData);
+ }
+ System.out.println();
+
+ assertEquals(4, dataList.size());
+
+ checkRequestData(dataList.get(0), "a", 100, 400, false);
+ checkRequestData(dataList.get(1), "c", 400, 700, false);
+ checkRequestData(dataList.get(2), "e", 700, 1000, false);
+ checkRequestData(dataList.get(3), "f", 1000, 1300, false);
+ }
+
+ public void testDropNew() throws Exception {
+ TestsResult result = checkQueue("dropNewQueue");
+ List<RequestData> dataList = result.getDataList();
+
+ for (RequestData requestData : dataList) {
+ System.out.println(" " + requestData);
+ }
+ System.out.println();
+
+ assertEquals(4, dataList.size());
+
+ checkRequestData(dataList.get(0), "a", 100, 400, false);
+ checkRequestData(dataList.get(1), "b", 400, 700, false);
+ checkRequestData(dataList.get(2), "c", 700, 1000, false);
+ checkRequestData(dataList.get(3), "e", 1000, 1300, false);
+ }
+
+ public void testFireNext() throws Exception {
+ TestsResult result = checkQueue("fireNextQueue");
+ List<RequestData> dataList = result.getDataList();
+
+ for (RequestData requestData : dataList) {
+ System.out.println(" " + requestData);
+ }
+ System.out.println();
+
+ assertEquals(6, dataList.size());
+
+ checkRequestData(dataList.get(0), "a", 100, 400, false);
+ checkRequestData(dataList.get(1), "b", 300, 600, false);
+ checkRequestData(dataList.get(2), "c", 400, 700, false);
+ checkRequestData(dataList.get(3), "d", 600, 900, false);
+ checkRequestData(dataList.get(4), "e", 700, 1000, false);
+ checkRequestData(dataList.get(5), "f", 1000, 1300, false);
+ }
+
+ public void testFireNew() throws Exception {
+ TestsResult result = checkQueue("fireNewQueue");
+ List<RequestData> dataList = result.getDataList();
+
+ for (RequestData requestData : dataList) {
+ System.out.println(" " + requestData);
+ }
+ System.out.println();
+
+ assertEquals(6, dataList.size());
+
+ checkRequestData(dataList.get(0), "a", 100, 400, false);
+ checkRequestData(dataList.get(1), "d", 300, 600, false);
+ checkRequestData(dataList.get(2), "b", 400, 700, false);
+ checkRequestData(dataList.get(3), "f", 600, 900, false);
+ checkRequestData(dataList.get(4), "c", 700, 1000, false);
+ checkRequestData(dataList.get(5), "e", 1000, 1300, false);
+ }
+
+ public void testDropNextSingle() throws Exception {
+ TestsResult result = checkSingleQueue("dropNextQueueSingle");
+ List<RequestData> dataList = result.getDataList();
+
+ for (RequestData requestData : dataList) {
+ System.out.println(" " + requestData);
+ }
+ System.out.println();
+
+ assertEquals(2, dataList.size());
+
+ checkRequestData(dataList.get(0), "b", 300, 600, false);
+ checkRequestData(dataList.get(1), "e", 900, 1200, false);
+ }
+
+ public void testDropNewSingle() throws Exception {
+ TestsResult result = checkSingleQueue("dropNewQueueSingle");
+ List<RequestData> dataList = result.getDataList();
+
+ for (RequestData requestData : dataList) {
+ System.out.println(" " + requestData);
+ }
+ System.out.println();
+
+ assertEquals(2, dataList.size());
+
+ checkRequestData(dataList.get(0), "a", 100, 400, false);
+ checkRequestData(dataList.get(1), "d", 700, 1000, false);
+ }
+
+ public void testFireNextSingle() throws Exception {
+ TestsResult result = checkSingleQueue("fireNextQueueSingle");
+ List<RequestData> dataList = result.getDataList();
+
+ for (RequestData requestData : dataList) {
+ System.out.println(" " + requestData);
+ }
+ System.out.println();
+
+ assertEquals(5, dataList.size());
+
+ checkRequestData(dataList.get(0), "a", 100, 400, false);
+ checkRequestData(dataList.get(1), "b", 300, 600, false);
+ checkRequestData(dataList.get(2), "c", 400, 700, false);
+ checkRequestData(dataList.get(3), "d", 500, 800, false);
+ checkRequestData(dataList.get(4), "e", 900, 1200, false);
+ }
+
+ public void testFireNewSingle() throws Exception {
+ TestsResult result = checkSingleQueue("fireNewQueueSingle");
+ List<RequestData> dataList = result.getDataList();
+
+ for (RequestData requestData : dataList) {
+ System.out.println(" " + requestData);
+ }
+ System.out.println();
+
+ assertEquals(5, dataList.size());
+
+ checkRequestData(dataList.get(0), "b", 100, 400, false);
+ checkRequestData(dataList.get(1), "a", 100, 400, false);
+ checkRequestData(dataList.get(2), "c", 400, 700, false);
+ checkRequestData(dataList.get(3), "e", 700, 1000, false);
+ checkRequestData(dataList.get(4), "d", 700, 1000, false);
+ }
+
+ public void testOnSizeExceeded() throws Exception {
+ renderView("/queue-size.xhtml");
+
+ for (int i = 0; i <= 3; i++) {
+ executeOnTime(i, "document.getElementById('form:button" + i + "').click()");
+ }
+
+ TestsResult result = getTestsResult();
+ List<RequestData> dataList = result.getDataList();
+
+ assertEquals(2, dataList.size());
+
+ //dropNext is default
+ checkRequestData(dataList.get(0), null, 0, DEFAULT_REQUEST_TIME, false);
+ checkRequestData(dataList.get(1), null, DEFAULT_REQUEST_TIME, DEFAULT_REQUEST_TIME * 2, false);
+
+ NativeArray handlersData = (NativeArray) executeJavaScript("defaultExceededQueueResults");
+ assertEquals(2, handlersData.getLength());
+
+ ScriptableObject firstHandlerData = (ScriptableObject) handlersData.get(0, handlersData);
+ Double firstEventTime = (Double) firstHandlerData.get("_time", firstHandlerData);
+ assertEquals(2d, firstEventTime);
+
+ ScriptableObject secondHandlerData = (ScriptableObject) handlersData.get(1, handlersData);
+ Double secondEventTime = (Double) secondHandlerData.get("_time", secondHandlerData);
+ assertEquals(3d, secondEventTime);
+ }
}
Modified: trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-scripted.xhtml
===================================================================
--- trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-scripted.xhtml 2008-11-21 00:57:50 UTC (rev 11284)
+++ trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-scripted.xhtml 2008-11-21 00:59:48 UTC (rev 11285)
@@ -11,8 +11,20 @@
<f:view>
<a4j:status startText="...running..." stopText="stopped" startStyle="color: green" />
- <a4j:queue size="2" sizeExceededBehavior="fireNext" name="testQueue" />
+ <a4j:queue name="queueDefaults" />
+ <a4j:queue name="queueRequestDelay" requestDelay="15" />
+
+ <a4j:queue name="queueTimeout" timeout="5000" />
+
+ <script type="text/javascript">
+ window.queueIgnoreDupResponsesTest = new Array();
+ </script>
+
+ <a4j:queue name="queueIgnoreDupResponses" ignoreDupResponses="true" oncomplete="queueIgnoreDupResponsesTest.push(data + ':' + Timer.currentTime)" />
+
+ <a4j:queue name="testQueue" />
+
</f:view>
</body>
</html>
Modified: trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-size.xhtml
===================================================================
--- trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-size.xhtml 2008-11-21 00:57:50 UTC (rev 11284)
+++ trunk/ui/core/src/test/resources/org/ajax4jsf/component/queue-size.xhtml 2008-11-21 00:59:48 UTC (rev 11285)
@@ -6,6 +6,47 @@
<body>
<f:view>
<a4j:queue name="defaultSizeQueue" />
+
+ <a4j:queue name="dropNextQueue" sizeExceededBehavior="dropNext" size="3" />
+ <a4j:queue name="dropNextQueueSingle" sizeExceededBehavior="dropNext" size="1" />
+
+ <a4j:queue name="fireNextQueue" sizeExceededBehavior="fireNext" size="3" />
+ <a4j:queue name="fireNextQueueSingle" sizeExceededBehavior="fireNext" size="1" />
+
+ <a4j:queue name="dropNewQueue" sizeExceededBehavior="dropNew" size="3" />
+ <a4j:queue name="dropNewQueueSingle" sizeExceededBehavior="dropNew" size="1" />
+
+ <a4j:queue name="fireNewQueue" sizeExceededBehavior="fireNew" size="3" />
+ <a4j:queue name="fireNewQueueSingle" sizeExceededBehavior="fireNew" size="1" />
+
+ <script type="text/javascript">
+ defaultExceededQueueResults = new Array();
+
+ function addEventData(queue, query, options, event) {
+ if (!queue) {
+ throw "queue not defined";
+ }
+ if (!query) {
+ throw "query not defined";
+ }
+ if (!options) {
+ throw "options not defined";
+ }
+ if (!event) {
+ throw "event not defined";
+ }
+
+ defaultExceededQueueResults.push({queue: queue, query: query, options: options, event: event, _time: Timer.currentTime});
+ }
+ </script>
+
+ <a4j:queue onsizeexceeded="addEventData(this, query, options, event)" size="2" name="defaultExceededQueue" />
+ <h:form id="form">
+ <a4j:commandButton id="button0" eventsQueue="defaultExceededQueue" value="button" />
+ <a4j:commandButton id="button1" eventsQueue="defaultExceededQueue" value="button" />
+ <a4j:commandButton id="button2" eventsQueue="defaultExceededQueue" value="button" />
+ <a4j:commandButton id="button3" eventsQueue="defaultExceededQueue" value="button" />
+ </h:form>
</f:view>
</body>
</html>
Modified: trunk/ui/core/src/test/resources/org/ajax4jsf/component/simulation.js
===================================================================
--- trunk/ui/core/src/test/resources/org/ajax4jsf/component/simulation.js 2008-11-21 00:57:50 UTC (rev 11284)
+++ trunk/ui/core/src/test/resources/org/ajax4jsf/component/simulation.js 2008-11-21 00:59:48 UTC (rev 11285)
@@ -1,3 +1,11 @@
+LOG.LEVEL = LOG.INFO;
+LOG._logToConsole = function(message, level) {
+ //TODO deal with this nasty message
+ if (message != "No information in response about elements to replace") {
+ LOG.out.println(level.name + ': ' + message)
+ }
+};
+
var Timer = {
_eventCounter: 0,
@@ -4,7 +12,7 @@
currentTime: 0,
- maxTime: 100000,
+ maxTime: 10000000,
events: new Array(),
@@ -67,28 +75,26 @@
var SimulationContext = function(submitFunction) {
this.results = new Array();
- this.time = 0;
this.submitFunction = submitFunction;
};
-SimulationContext.prototype.wait = function(delay) {
- this.time += delay;
-};
-
SimulationContext.prototype.ajax = function() {
- var args = arguments;
+ var args = new Array();
+ for (var i = 1; i < arguments.length; i++) {
+ args.push(arguments[i]);
+ }
var _this = this;
Timer.addEventToTimer(function() {
- _this.submitFunction(args[0], args[1]);
- }, this.time);
+ _this.submitFunction.apply(this, args);
+ }, arguments[0]);
};
-SimulationContext.prototype.executeAfterDelay = function(code) {
+SimulationContext.prototype.executeOnTime = function(time, code) {
Timer.addEventToTimer(function() {
code();
- }, this.time);
+ }, time);
};
window.simulationContext = undefined;
@@ -125,6 +131,7 @@
if ("Ajax-Response" == name) {
return "true";
}
+
return "";
};
XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
@@ -140,10 +147,39 @@
_this.status = 200;
_this.statusText = "Success";
_this.readyState = window.XMLHttpRequest.DONE;
- _this.responseText = "<?xml version='1.0'?><html />";
+ var responseTextArray = new Array();
+ responseTextArray.push("<html><head></head><body>");
+ if (_this.data) {
+
+ responseTextArray.push("<span id='_ajax:data'>");
+ if (typeof _this.data == 'string') {
+ responseTextArray.push("'");
+ responseTextArray.push(_this.data);
+ responseTextArray.push("'");
+ } else {
+ responseTextArray.push(_this.data);
+ }
+ responseTextArray.push("</span>");
+ }
+ responseTextArray.push("</body></html>");
+
+ _this.responseText = responseTextArray.join('');
+
var doc = new ActiveXObject("MSXML.DOMDocument");
doc.loadXML(_this.responseText);
+
+ //hack to make it work with current HTMLUnit
+ delete doc.getElementById;
+ doc.getElementById = function(id){
+ var nodes = this.selectNodes("//*");
+ for (var i = 0; i < nodes.length; i++) {
+ if (nodes[i].getAttribute("id") == id) {
+ return nodes[i];
+ }
+ }
+ };
+
_this.responseXML = doc;
window.simulationContext.results[_this.requestId].endTime = Timer.currentTime;
@@ -157,8 +193,10 @@
var oldSubmitQuery = A4J.AJAX.SubmitQuery;
+var DEFAULT_REQUEST_TIME;
+
A4J.AJAX.SubmitQuery = function(query, options) {
- XMLHttpRequest.requestTime = options.requestTime || XMLHttpRequest.defaultRequestTime;
+ XMLHttpRequest.requestTime = options.requestTime || XMLHttpRequest.defaultRequestTime || DEFAULT_REQUEST_TIME;
XMLHttpRequest.data = options.data;
try {
17 years, 1 month
JBoss Rich Faces SVN: r11284 - in trunk/framework/impl/src/main: javascript/ajaxjsf and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2008-11-20 19:57:50 -0500 (Thu, 20 Nov 2008)
New Revision: 11284
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIQueue.java
trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js
Log:
Latest fixes for a4j:queue
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIQueue.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIQueue.java 2008-11-21 00:26:49 UTC (rev 11283)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIQueue.java 2008-11-21 00:57:50 UTC (rev 11284)
@@ -55,6 +55,9 @@
public abstract String getOnerror();
public abstract void setOnerror(String onerror);
+ public abstract String getOnsizeexceeded();
+ public abstract void setOnsizeexceeded(String onsizeexceeded);
+
public abstract boolean isDisabled();
public abstract void setDisabled(boolean disabled);
Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2008-11-21 00:26:49 UTC (rev 11283)
+++ trunk/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js 2008-11-21 00:57:50 UTC (rev 11284)
@@ -809,7 +809,7 @@
var queue = A4J.AJAX.EventQueue.getOrCreateQueue(options, formId);
if (queue) {
- queue.push(query, options);
+ queue.push(query, options, event);
} else {
A4J.AJAX.SubmitQuery(query, options);
}
Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js
===================================================================
--- trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js 2008-11-21 00:26:49 UTC (rev 11283)
+++ trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js 2008-11-21 00:57:50 UTC (rev 11284)
@@ -60,18 +60,19 @@
addEvent: function(data) {
if (!this.isFull()) {
-
this.items.push(data);
-
- if (!this.request) {
- this.submit();
- }
-
} else {
//log error
}
},
+ //TODO new good name!
+ submitEvent: function() {
+ if (!this.request && !this.isEmpty()) {
+ this.submit();
+ }
+ },
+
submitNext: function() {
this.clearRequest();
@@ -90,7 +91,7 @@
return this.getSize() == 0;
},
- hasNextItem: function() {
+ hasNext: function() {
return this.items.length != 0;
},
@@ -102,8 +103,8 @@
}
},
- abortDupResponces: function(data) {
- if (!this.hasNextItem() && data.getRequestId() == this.requestId) {
+ abortDupResponses: function(data) {
+ if (!this.hasNext() && data.getRequestId() == this.requestId) {
this.abortCurrentRequest();
}
}
@@ -152,12 +153,14 @@
if (this.pipeline.isEmpty()) {
this.pipeline.addEvent(this.pop());
+ this.pipeline.submitEvent();
}
},
transferIfReady: function() {
if (this.delayPassed) {
this.pipeline.addEvent(this.pop());
+ this.pipeline.submitEvent();
}
},
@@ -180,7 +183,7 @@
return function(data) {
if (data.isIgnoreDupResponses()) {
- this.pipeline.abortDupResponces(data);
+ this.pipeline.abortDupResponses(data);
}
var requestId = data.getRequestId();
@@ -196,17 +199,31 @@
this.pipeline.addEvent(this.pop());
}
+ var newDataHandled = false;
+
if (this.pipeline.isFull()) {
var behavior = data.getSizeExceededBehavior();
+
+ var queue = data.queue;
+ var queueOptions = queue.queueOptions;
+
+ if (queueOptions.onsizeexceeded) {
+ var query = data.query;
+ var options = data.options;
+ var event = data.event;
+
+ queueOptions.onsizeexceeded.call(data.queue, query, options, event);
+ }
+
if (behavior == DROP_NEW ||
- (behavior == DROP_NEXT && !this.pipeline.hasNextItem())) {
+ (behavior == DROP_NEXT && !(this.pipeline.hasNext()))) {
- return;
+ newDataHandled = true;
} else if (behavior == FIRE_NEW ||
- (behavior == FIRE_NEXT && !this.pipeline.hasNextItem())) {
+ (behavior == FIRE_NEXT && !(this.pipeline.hasNext()))) {
data.submit();
- return;
+ newDataHandled = true;
} else if (behavior == DROP_NEXT) {
this.pipeline.dropFirst();
} else if (behavior == FIRE_NEXT) {
@@ -215,9 +232,13 @@
}
- this.data = data;
- this.requestId = requestId;
- this.startRequestDelay();
+ this.pipeline.submitEvent();
+
+ if (!newDataHandled) {
+ this.data = data;
+ this.requestId = requestId;
+ this.startRequestDelay();
+ }
}
}
}()
@@ -401,9 +422,11 @@
* }
*/
- var EventQueueData = function(queue, query, options) {
+ var EventQueueData = function(queue, query, options, event) {
this.queue = queue;
this.query = query;
+ this.event = event;
+
this.options = options || {};
this.eventsCount = 1;
@@ -469,7 +492,7 @@
}
for (var name in this.requestOptions) {
- if (!opts[name]) {
+ if (typeof opts[name] == 'undefined') {
opts[name] = this.requestOptions[name];
}
}
@@ -493,9 +516,9 @@
return policy;
},
- push: function(query, opts) {
+ push: function(query, opts, event) {
var options = extendOptions.call(this, opts);
- var queueData = new EventQueueData(this, query, options);
+ var queueData = new EventQueueData(this, query, options, event);
this.gate.push(queueData);
},
17 years, 1 month
JBoss Rich Faces SVN: r11283 - in branches/jsf2.0: framework/jsf-test/src/main/java/org/richfaces/test/staging and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2008-11-20 19:26:49 -0500 (Thu, 20 Nov 2008)
New Revision: 11283
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java
branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java
branches/jsf2.0/tests/ajax/src/test/java/org/richfaces/test/ajax/SimpleAjaxTest.java
Log:
replace all staging server exceptions by the TestException, check init status in the server
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java 2008-11-20 20:25:42 UTC (rev 11282)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java 2008-11-21 00:26:49 UTC (rev 11283)
@@ -59,11 +59,7 @@
if(null != body && FormEncodingType.URL_ENCODED.getName().equals(contentType)){
connection.parseFormParameters(body);
}
- try {
- connection.execute();
- } catch (ServletException e) {
- throw new IOException(e.getMessage());
- }
+ connection.execute();
return new LocalWebResponse(settings,connection);
}
}
\ No newline at end of file
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java 2008-11-20 20:25:42 UTC (rev 11282)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java 2008-11-21 00:26:49 UTC (rev 11283)
@@ -164,17 +164,23 @@
/**
* Execute this connection request on the associated servlet or filter chain.
- * @throws ServletException
- * @throws IOException
+ * @throws TestException if any errors were during execution.
*/
- public void execute() throws ServletException, IOException {
+ public void execute() {
if (isStarted() || isFinished()) {
throw new TestException(
"request have already been executed");
}
start();
- this.servlet.execute(request, response);
- finish();
+ try {
+ this.servlet.execute(request, response);
+ } catch (ServletException e) {
+ throw new TestException("Error execute request ",e);
+ } catch (IOException e) {
+ throw new TestException("IO Error during request execution",e);
+ } finally {
+ finish();
+ }
}
/**
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java 2008-11-20 20:25:42 UTC (rev 11282)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java 2008-11-21 00:26:49 UTC (rev 11283)
@@ -71,28 +71,30 @@
private static final Logger log = ServerLogger.SERVER.getLogger();
- private List<RequestChain> servlets = new ArrayList<RequestChain>();
+ private final List<RequestChain> servlets = new ArrayList<RequestChain>();
- private RequestChain defaultServlet;
+ private RequestChain defaultServlet= new ServletContainer(null, new StaticServlet());
- private List<EventListener> contextListeners = new ArrayList<EventListener>();
+ private final List<EventListener> contextListeners = new ArrayList<EventListener>();
- private Map<String, String> initParameters = new HashMap<String, String>();
+ private final Map<String, String> initParameters = new HashMap<String, String>();
- private ServerResource serverRoot = new ServerResourcesDirectory();
+ private final ServerResource serverRoot = new ServerResourcesDirectory();
private final Map<String, String> mimeTypes = new HashMap<String, String>();
private InvocationListener invocationListener;
- private StagingServletContext context;
+ private final StagingServletContext context = new LocalContext();
private ServletContext contextProxy;
- private ServerHttpSession session;
+ private ServerHttpSession session=null;
- private HttpSession sessionProxy;
+ private HttpSession sessionProxy=null;
+ private boolean initialised=false;
+
/**
* This inner class links ServletContext calls to the server instance.
* @author asmirnov
@@ -286,7 +288,7 @@
result = defaultServlet;
}
} catch (MalformedURLException e) {
- // do nothing, just return no servlet.
+ log.warning("Mailformed request URL "+e.getMessage());
}
}
return result;
@@ -400,7 +402,7 @@
}
} catch (IOException e) {
- throw new TestException(e);
+ throw new TestException("Error read Jar content",e);
} catch (URISyntaxException e) {
throw new TestException(e);
}
@@ -532,6 +534,9 @@
*
*/
public synchronized HttpSession getSession(boolean create) {
+ if(!initialised){
+ throw new TestException("Staging server have not been initialised");
+ }
if (null == this.session && create) {
this.session = new ServerHttpSession();
// Create proxy objects.
@@ -560,8 +565,7 @@
* It should be called from test setUp method to prepare testing environment.
*/
public void init() {
- // Create context.
- this.context = new LocalContext();
+ log.info("Init staging server");
// Create Jsp factory
JspFactory.setDefaultFactory(new StaggingJspFactory(this.context));
// Create init parameters
@@ -576,7 +580,6 @@
new Class[] { ServletContext.class },
getInvocationHandler(context));
// Create default servlet
- defaultServlet = new ServletContainer(null, new StaticServlet());
final ServletContextEvent event = new ServletContextEvent(context);
fireEvent(CONTEXT_LISTENER_CLASS,
new EventInvoker<ServletContextListener>() {
@@ -588,12 +591,13 @@
try {
for (RequestChain servlet : servlets) {
// init servlet
- servlet.init(this.context);
+ servlet.init(context);
}
- defaultServlet.init(getContext());
+ defaultServlet.init(context);
} catch (ServletException e) {
- throw new TestException(e);
+ throw new TestException("Servlet initialisation error ",e);
}
+ this.initialised = true;
}
/**
@@ -602,6 +606,10 @@
*
*/
public void destroy() {
+ if(!initialised){
+ throw new TestException("Staging server have not been initialised");
+ }
+ this.initialised = false;
// Destroy session
if (null != this.session) {
// inform session listeners.
@@ -630,7 +638,8 @@
defaultServlet.destroy();
// Create Jsp factory
JspFactory.setDefaultFactory(null);
-
+ this.contextProxy = null;
+ log.info("Staging server have been destroyed");
}
/**
@@ -641,6 +650,9 @@
* @throws {@link TestException} if no servlet found to process given URL.
*/
public StagingConnection getConnection(URL url) {
+ if(!initialised){
+ throw new TestException("Staging server have not been initialised");
+ }
return new StagingConnection(this, url);
}
@@ -649,6 +661,9 @@
* @return context instance.
*/
public ServletContext getContext() {
+ if(!initialised){
+ throw new TestException("Staging server have not been initialised");
+ }
return contextProxy;
}
Modified: branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java 2008-11-20 20:25:42 UTC (rev 11282)
+++ branches/jsf2.0/framework/jsf-test/src/test/java/org/richfaces/test/FacesServerTest.java 2008-11-21 00:26:49 UTC (rev 11283)
@@ -44,7 +44,7 @@
* @throws java.lang.Exception
*/
@Before
- public void setUp() throws Exception {
+ public void setUpTest() throws Exception {
}
@Override
@@ -58,7 +58,7 @@
* @throws java.lang.Exception
*/
@After
- public void tearDown() throws Exception {
+ public void tearDownTest() throws Exception {
}
/**
Modified: branches/jsf2.0/tests/ajax/src/test/java/org/richfaces/test/ajax/SimpleAjaxTest.java
===================================================================
--- branches/jsf2.0/tests/ajax/src/test/java/org/richfaces/test/ajax/SimpleAjaxTest.java 2008-11-20 20:25:42 UTC (rev 11282)
+++ branches/jsf2.0/tests/ajax/src/test/java/org/richfaces/test/ajax/SimpleAjaxTest.java 2008-11-21 00:26:49 UTC (rev 11283)
@@ -27,7 +27,7 @@
* @throws java.lang.Exception
*/
@Before
- public void setUp() throws Exception {
+ public void setUpTest() throws Exception {
}
@Override
@@ -41,13 +41,13 @@
* @throws java.lang.Exception
*/
@After
- public void tearDown() throws Exception {
+ public void tearDownTest() throws Exception {
}
@Test
public void testRequest() throws Exception {
WebClient webClient = new LocalWebClient(facesServer,BrowserVersion.FIREFOX_3);
- webClient.setThrowExceptionOnScriptError(false);
+ webClient.setThrowExceptionOnScriptError(true);
HtmlPage page = webClient.getPage("http://localhost/home.jsf");
System.out.println(page.asXml());
17 years, 1 month
JBoss Rich Faces SVN: r11282 - in branches/jsf2.0/framework/jsf-test/src/main: java/org/richfaces/test and 6 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2008-11-20 15:25:42 -0500 (Thu, 20 Nov 2008)
New Revision: 11282
Added:
branches/jsf2.0/framework/jsf-test/src/main/javadoc/
branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/
branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/
branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/
branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html
branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging/
branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging/package.html
branches/jsf2.0/framework/jsf-test/src/main/javadoc/overview.html
Removed:
branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/
branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/
branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/
branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html
branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging/
branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging/package.html
branches/jsf2.0/framework/jsf-test/src/main/javadoc/overview.html
Modified:
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/TestException.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/EventInvoker.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/InvocationErrorEvent.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/InvocationEvent.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java
branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StaticServlet.java
Log:
Merge test project changes from the trunk.
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/AbstractFacesTest.java 2008-11-20 20:25:42 UTC (rev 11282)
@@ -22,37 +22,64 @@
import javax.faces.webapp.FacesServlet;
import javax.servlet.Filter;
+import junit.framework.TestCase;
+
import org.junit.After;
import org.junit.Before;
import org.richfaces.test.staging.FilterContainer;
-import org.richfaces.test.staging.RequestChain;
import org.richfaces.test.staging.ServletContainer;
import org.richfaces.test.staging.StagingConnection;
import org.richfaces.test.staging.StagingServer;
/**
+ * Base class for all JSF test cases.
* @author asmirnov
*
*/
-public abstract class AbstractFacesTest {
+public abstract class AbstractFacesTest extends TestCase {
private ClassLoader contextClassLoader;
+ /**
+ * Prepared test server instance. Populated by the default {@link #setUp()} method.
+ */
protected StagingServer facesServer;
+ /**
+ * Current virtual connection. This field populated by the {@link #setupWebContent()} method only.
+ */
protected StagingConnection connection;
+ /**
+ * Current {@link FacesContext} instance. This field populated by the {@link #setupWebContent()} method only.
+ */
protected FacesContext facesContext;
+ /**
+ * JSF {@link Lifecycle} instance. Populated by the default {@link #setUp()} method.
+ */
protected Lifecycle lifecycle;
+ /**
+ * JSF {@link Application} instance. Populated by the default {@link #setUp()} method.
+ */
protected Application application;
/**
+ * Setup staging server instance with JSF implementation. First, this method creates a local test instance
+ * and calls the other template method in the next sequence:
+ * <ol>
+ * <li>{@link #setupFacesServlet()}</li>
+ * <li>{@link #setupFacesListener()}</li>
+ * <li>{@link #setupJsfInitParameters()}</li>
+ * <li>{@link #setupWebContent()}</li>
+ * </ol>
+ * After them, test server is initialized as well as fields {@link #lifecycle} and {@link #application} populated.
+ * Also, if the resource "logging.properties" is exist in the test class package, The Java {@link LogManager} will be configured with its content.
* @throws java.lang.Exception
*/
@Before
- public void setUpServer() throws Exception {
+ public void setUp() throws Exception {
contextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(
this.getClass().getClassLoader());
@@ -74,6 +101,7 @@
facesServer = new StagingServer();
setupFacesServlet();
setupFacesListener();
+ setupJsfInitParameters();
setupWebContent();
facesServer.init();
ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
@@ -86,18 +114,22 @@
}
/**
- *
+ * This hook method called from the {@link #setUp()} should append JSF implementation
+ * listener to the test server. Default version applends "com.sun.faces.config.ConfigureListener"
+ * or "org.apache.myfaces.webapp.StartupServletContextListener" for the existed SUN RI or MyFaces implementation.
+ * This metod also calls appropriate {@link #setupSunFaces()} or {@link #setupMyFaces()} methods.
*/
protected void setupFacesListener() {
EventListener listener = null;
try {
+ // Check Sun RI configuration listener class.
Class<? extends EventListener> listenerClass = contextClassLoader
.loadClass("com.sun.faces.config.ConfigureListener")
.asSubclass(EventListener.class);
listener = listenerClass.newInstance();
setupSunFaces();
} catch (ClassNotFoundException e) {
- // No JSF RI listener
+ // No JSF RI listener, check MyFaces.
Class<? extends EventListener> listenerClass;
try {
listenerClass = contextClassLoader
@@ -119,8 +151,10 @@
}
/**
- * @throws InstantiationException
- * @throws IllegalAccessException
+ * This template method called from {@link #setUp()} to create {@link FacesServlet} instance.
+ * The default implementation also tests presense of the "org.ajax4jsf.Filter" class.
+ * If this class is avalable, these instance appended to the Faces Servlet call chain.
+ * Default mapping to the FacesServlet instance is "*.jsf"
*/
protected void setupFacesServlet() {
ServletContainer facesServletContainer = new ServletContainer("*.jsf",
@@ -145,6 +179,13 @@
} catch (Exception e) {
throw new TestException(e);
}
+ }
+
+ /**
+ * This template method called from {@link #setUp()} to append appropriate init parameters to the test server.
+ * The default implementation sets state saving method to the "server" and default jsf page suffix to the ".xhtml"
+ */
+ protected void setupJsfInitParameters() {
facesServer.addInitParameter(
StateManager.STATE_SAVING_METHOD_PARAM_NAME,
StateManager.STATE_SAVING_METHOD_SERVER);
@@ -152,23 +193,45 @@
".xhtml");
}
+ /**
+ * This template method called from the {@link #setupFacesListener()} if MyFaces implementation presents.
+ * The default implementation does nothing.
+ */
protected void setupMyFaces() {
// Do nothing by default.
}
+ /**
+ * This template method called from the {@link #setupFacesListener()} if Sun JSF reference implementation presents.
+ * The default implementation sets the "com.sun.faces.validateXml" "com.sun.faces.verifyObjects" init parameters to the "true"
+ */
protected void setupSunFaces() {
facesServer.addInitParameter("com.sun.faces.validateXml", "true");
facesServer.addInitParameter("com.sun.faces.verifyObjects", "true");
}
+ /**
+ * This template method called from the {@link #setUp()} to populate virtual server content.
+ * The default implementation do nothing.
+ */
protected void setupWebContent() {
}
+ /**
+ * Setup virtual server connection to run tests inside JSF lifecycle.
+ * The default implementation setups virtual request to the "http://localhost/test.jsf" URL and creates {@link FacesContext} instance.
+ * Two template methods are called :
+ * <ol>
+ * <li>{@link #setupConnection()} to prepare request method, parameters, headers and so</li>
+ * <li>{@link #setupView()} to create default view.</li>
+ * </ol>
+ * @throws Exception
+ */
protected void setupFacesRequest() throws Exception {
connection = facesServer.getConnection(new URL(
"http://localhost/test.jsf"));
- setupConnection(connection);
+ setupConnection();
connection.start();
FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder
.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
@@ -181,21 +244,31 @@
}
}
+ /**
+ * This template method called from the {@link #setupFacesRequest()} to create components view tree in the virtual request.
+ * The default implementation is only creates {@link UIViewRoot} instance for view ID "/test.xhtml".
+ * @return
+ */
protected UIViewRoot setupView() {
UIViewRoot viewRoot = (UIViewRoot) application.createComponent(UIViewRoot.COMPONENT_TYPE);
viewRoot.setViewId("/test.xhtml");
return viewRoot;
}
- protected void setupConnection(StagingConnection connection) {
+ /**
+ * This template method called from the {@link #setupFacesRequest()} to setup additional virtual connection parameters.
+ * The default implementation does nothing.
+ */
+ protected void setupConnection() {
}
/**
+ * Virtual server instance cleanup.
* @throws java.lang.Exception
*/
@After
- public void tearDownServer() throws Exception {
+ public void tearDown() throws Exception {
if (null != facesContext) {
facesContext.release();
facesContext = null;
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebClient.java 2008-11-20 20:25:42 UTC (rev 11282)
@@ -11,6 +11,10 @@
import com.gargoylesoftware.htmlunit.WebConnection;
/**
+ * Modified version of the HtmlUnit {@link WebClient}. This subclass uses {@link LocalWebConnection} by default,
+ * to perform requests to the local saging server {@link StagingServer} instead of real network request.
+ * It is also setup synchonous ajax controller {@link WebClient#setAjaxController(com.gargoylesoftware.htmlunit.AjaxController)},
+ * to avoid thread syncronisation problem.
* @author asmirnov
*
*/
@@ -22,7 +26,8 @@
private transient WebConnection webConnection;
/**
- *
+ * Create WebConnection instance for the given {@link StagingServer}
+ * @param server test server instance.
*/
public LocalWebClient(StagingServer server) {
super();
@@ -31,6 +36,8 @@
}
/**
+ * Create WebConnection instance for the given {@link StagingServer} and browser version.
+ * @param server test server instance.
* @param browserVersion
*/
public LocalWebClient(StagingServer server,BrowserVersion browserVersion) {
@@ -40,8 +47,10 @@
}
/**
+ * Overwride default webConnection.
* @return the webConnection
*/
+ @Override
public WebConnection getWebConnection() {
if (this.webConnection == null) {
this.webConnection = new LocalWebConnection(server);
@@ -53,6 +62,7 @@
/**
* @param webConnection the webConnection to set
*/
+ @Override
public void setWebConnection(WebConnection webConnection) {
this.webConnection = webConnection;
}
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebConnection.java 2008-11-20 20:25:42 UTC (rev 11282)
@@ -17,7 +17,16 @@
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
+/**
+ * This implementation of the HtmlUnit {@link WebConnection} execute http requests on the local
+ * staging server instead of the real network connection.
+ * @author asmirnov
+ *
+ */
public final class LocalWebConnection implements WebConnection {
+ /**
+ * test server instance
+ */
private final StagingServer localServer;
/**
@@ -27,9 +36,13 @@
this.localServer = localServer;
}
+ /* (non-Javadoc)
+ * @see com.gargoylesoftware.htmlunit.WebConnection#getResponse(com.gargoylesoftware.htmlunit.WebRequestSettings)
+ */
public WebResponse getResponse(WebRequestSettings settings)
throws IOException {
StagingConnection connection = localServer.getConnection(settings.getUrl());
+ // Propagate web request settings to the local connection.
for (NameValuePair param : settings.getRequestParameters()) {
connection.addRequestParameter(param.getName(), param.getValue());
}
@@ -41,6 +54,8 @@
connection.setRequestBody(body);
connection.setRequestContentType(contentType);
connection.addRequestHeaders(settings.getAdditionalHeaders());
+ // HtmlUnit uses request parameters map for the form submit, but does not parse
+ // XMLHttpRequest content.
if(null != body && FormEncodingType.URL_ENCODED.getName().equals(contentType)){
connection.parseFormParameters(body);
}
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java 2008-11-20 20:25:42 UTC (rev 11282)
@@ -6,10 +6,8 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
@@ -19,71 +17,169 @@
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
-public final class LocalWebResponse implements WebResponse {
- private final WebRequestSettings settings;
+/**
+ * This implementation realise WebResponse wrapper for a staging server
+ * connection. This class is used by the {@link LocalWebClient}, but also can be used to analise response rendering:
+ * <pre>
+ * ............
+ * @Test
+ * public void testRender() {
+ * setupFacesRequest();
+ * // Prepare view etc
+ * ..................
+ * lifecycle.render(facesContext);
+ * WebClient webClient = new LocalWebClient(facesServer);
+ * HtmlPage page = (HtmlPage) webClient.loadWebResponseInto(new LocalWebResponse(connection), webClient.getCurrentWindow());
+ * // analyse response
+ * assertTrue(....)
+ * }
+ * </pre>
+ *
+ * @author asmirnov
+ *
+ */
+public class LocalWebResponse implements WebResponse {
+ private WebRequestSettings settings;
private final StagingConnection serverConnection;
- public LocalWebResponse(WebRequestSettings settings,StagingConnection serverConnection) {
- this.settings = settings;
+ public LocalWebResponse(StagingConnection serverConnection) {
this.serverConnection = serverConnection;
}
+ public LocalWebResponse(WebRequestSettings settings,
+ StagingConnection connection) {
+ this(connection);
+ this.settings = settings;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.gargoylesoftware.htmlunit.WebResponse#getContentAsStream()
+ */
public InputStream getContentAsStream() throws IOException {
return new ByteArrayInputStream(getResponseBody());
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.gargoylesoftware.htmlunit.WebResponse#getContentAsString()
+ */
public String getContentAsString() {
return serverConnection.getContentAsString();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.gargoylesoftware.htmlunit.WebResponse#getContentCharSet()
+ */
public String getContentCharSet() {
- return serverConnection.getCharacterEncoding();
+ return serverConnection.getResponseCharacterEncoding();
}
public String getContentType() {
- return serverConnection.getContentType();
+ return serverConnection.getResponseContentType();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.gargoylesoftware.htmlunit.WebResponse#getLoadTimeInMilliSeconds()
+ */
public long getLoadTimeInMilliSeconds() {
return 0;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.gargoylesoftware.htmlunit.WebResponse#getRequestMethod()
+ */
public com.gargoylesoftware.htmlunit.HttpMethod getRequestMethod() {
- return com.gargoylesoftware.htmlunit.HttpMethod.valueOf(serverConnection.getMethod().toString());
+ return com.gargoylesoftware.htmlunit.HttpMethod
+ .valueOf(serverConnection.getRequestMethod().toString());
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.gargoylesoftware.htmlunit.WebResponse#getRequestSettings()
+ */
public WebRequestSettings getRequestSettings() {
+ if (settings == null) {
+ settings = new WebRequestSettings(this.getUrl(), getRequestMethod());
+ }
return settings;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.gargoylesoftware.htmlunit.WebResponse#getResponseBody()
+ */
public byte[] getResponseBody() {
return serverConnection.getResponseBody();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.gargoylesoftware.htmlunit.WebResponse#getResponseHeaderValue(java
+ * .lang.String)
+ */
public String getResponseHeaderValue(String headerName) {
- // TODO Auto-generated method stub
+ String[] values = serverConnection.getResponseHeaders().get(headerName);
+ if(null != values && values.length >0){
+ return values[0];
+ }
return null;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.gargoylesoftware.htmlunit.WebResponse#getStatusCode()
+ */
public int getStatusCode() {
- return serverConnection.getStatus();
+ return serverConnection.getResponseStatus();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.gargoylesoftware.htmlunit.WebResponse#getStatusMessage()
+ */
public String getStatusMessage() {
return serverConnection.getErrorMessage();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.gargoylesoftware.htmlunit.WebResponse#getUrl()
+ */
public URL getUrl() {
return serverConnection.getUrl();
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.gargoylesoftware.htmlunit.WebResponse#getResponseHeaders()
+ */
public List<NameValuePair> getResponseHeaders() {
ArrayList<NameValuePair> headers = new ArrayList<NameValuePair>(10);
- for (Entry<String, String[]> entry : serverConnection.getResponseHeaders().entrySet()) {
+ for (Entry<String, String[]> entry : serverConnection
+ .getResponseHeaders().entrySet()) {
for (String value : entry.getValue()) {
- headers.add(new NameValuePair(entry.getKey(),value));
+ headers.add(new NameValuePair(entry.getKey(), value));
}
- };
+ }
+ ;
return headers;
}
}
\ No newline at end of file
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/TestException.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/TestException.java 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/TestException.java 2008-11-20 20:25:42 UTC (rev 11282)
@@ -3,17 +3,21 @@
*/
package org.richfaces.test;
+import org.richfaces.test.staging.StagingServer;
+
/**
+ * Internal runtame exception for the {@link StagingServer} engine.
* @author asmirnov
*
*/
+@SuppressWarnings("serial")
public class TestException extends RuntimeException {
/**
- *
+ * Default constructor.
*/
public TestException() {
- // TODO Auto-generated constructor stub
+ super();
}
/**
@@ -21,7 +25,6 @@
*/
public TestException(String message) {
super(message);
- // TODO Auto-generated constructor stub
}
/**
@@ -29,7 +32,6 @@
*/
public TestException(Throwable cause) {
super(cause);
- // TODO Auto-generated constructor stub
}
/**
@@ -38,7 +40,6 @@
*/
public TestException(String message, Throwable cause) {
super(message, cause);
- // TODO Auto-generated constructor stub
}
}
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/EventInvoker.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/EventInvoker.java 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/EventInvoker.java 2008-11-20 20:25:42 UTC (rev 11282)
@@ -5,6 +5,13 @@
import java.util.EventListener;
+/**
+ * Internal interface, used to invoke listeners of different types.
+
+ * @author asmirnov
+ *
+ * @param <T> listener type.
+ */
interface EventInvoker<T extends EventListener> {
public void invoke(T listener);
}
\ No newline at end of file
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/InvocationErrorEvent.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/InvocationErrorEvent.java 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/InvocationErrorEvent.java 2008-11-20 20:25:42 UTC (rev 11282)
@@ -3,6 +3,18 @@
import java.lang.reflect.Method;
import java.util.EventObject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+/**
+ * This event sent from the virtual server introspection method to the registered
+ * {@link InvocationListener} instance after any exception thrown from calls to {@link HttpServletRequest} , {@link HttpServletResponse}, {@link HttpSession} and {@link ServletContext} objects.
+
+ * @author asmirnov
+ *
+ */
+@SuppressWarnings("serial")
public class InvocationErrorEvent extends EventObject {
private Object target;
private Method method;
@@ -30,6 +42,9 @@
return args;
}
+ /**
+ * @return thrown exception.
+ */
public Throwable getE() {
return e;
}
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/InvocationEvent.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/InvocationEvent.java 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/InvocationEvent.java 2008-11-20 20:25:42 UTC (rev 11282)
@@ -3,6 +3,17 @@
import java.lang.reflect.Method;
import java.util.EventObject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+/**
+ * This event sent from the staging server introspection method to the registered
+ * {@link InvocationListener} instance after all calls to {@link HttpServletRequest} , {@link HttpServletResponse}, {@link HttpSession} and {@link ServletContext} objects.
+ * @author asmirnov
+ *
+ */
+@SuppressWarnings("serial")
public class InvocationEvent extends EventObject {
private Object target;
private Method method;
@@ -18,18 +29,30 @@
this.result = result;
}
+ /**
+ * @return target object instance.
+ */
public Object getTarget() {
return target;
}
+ /**
+ * @return {@link Method} that was called.
+ */
public Method getMethod() {
return method;
}
+ /**
+ * @return method arguments.
+ */
public Object[] getArgs() {
return args;
}
+ /**
+ * @return value returned from the invoked method.
+ */
public Object getResult() {
return result;
}
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingConnection.java 2008-11-20 20:25:42 UTC (rev 11282)
@@ -29,8 +29,9 @@
import org.richfaces.test.TestException;
/**
- * This class represent single connection to the server.
- *
+ * This class represent single connection ( request ) to the virtual server. These instance should not be created directly, but by the {@link StagingServer#getConnection(URL)}.
+ * method only.
+ * Since instance have been created, additional request parameters and headers can be set.
* @author asmirnov
*
*/
@@ -70,9 +71,15 @@
private HttpServletResponse responseProxy;
- public StagingConnection(StagingServer localServer, URL url) {
+ /**
+ * Create connection instance.
+ * @param localServer virtual server instance.
+ * @param url request URL.
+ */
+ StagingConnection(StagingServer localServer, URL url) {
this.server = localServer;
this.url = url;
+ // TODO - context path support.
String path = url.getPath();
servlet = localServer.getServlet(path);
if (null == servlet) {
@@ -100,6 +107,11 @@
responseProxy = (HttpServletResponse) Proxy.newProxyInstance(loader, new Class[]{HttpServletResponse.class}, server.getInvocationHandler(response));
}
+ /**
+ * Parse 'application/x-www-form-urlencoded' string with parameters name/value pairs,
+ * as it expected after a form submit.
+ * @param queryString URL query string or POST content.
+ */
public void parseFormParameters(String queryString) {
String[] queryParams = queryString.split("&");
for (int i = 0; i < queryParams.length; i++) {
@@ -140,19 +152,24 @@
private void checkStarted() {
if (!isFinished()) {
- throw new IllegalStateException("request have not been started");
+ throw new TestException("request have not been started");
}
}
private void checkNotStarted() {
if (isStarted()) {
- throw new IllegalStateException("request was started, no parameters changes allowed");
+ throw new TestException("request was started, no parameters changes allowed");
}
}
+ /**
+ * Execute this connection request on the associated servlet or filter chain.
+ * @throws ServletException
+ * @throws IOException
+ */
public void execute() throws ServletException, IOException {
if (isStarted() || isFinished()) {
- throw new IllegalStateException(
+ throw new TestException(
"request have already been executed");
}
start();
@@ -160,13 +177,20 @@
finish();
}
+ /**
+ * Finish request to the this connection, inform server listeners about request status.
+ */
public void finish() {
server.requestFinished(request);
finished = true;
}
+ /**
+ * Start request to the this connection, inform server listeners about request status.
+ * No request parameters changes allowed after connection start.
+ */
public void start() {
- log.fine("start " + getMethod() + " request processing for file "
+ log.fine("start " + getRequestMethod() + " request processing for file "
+ url.getFile());
log.fine("request parameters: " + requestParameters);
server.requestStarted(request);
@@ -174,15 +198,19 @@
}
/**
+ * Get request HTTP methos ( GET, POST etc ).
* @return the method
*/
- public HttpMethod getMethod() {
+ public HttpMethod getRequestMethod() {
return method;
}
/**
+ * Set request HTTP methos ( GET, POST etc ).
* @param method
* the method to set
+ * @throws TestException
+ * if connection have already been started.
*/
public void setRequestMethod(HttpMethod method) {
checkNotStarted();
@@ -190,12 +218,20 @@
}
/**
+ * Get request url.
* @return the url
*/
public URL getUrl() {
return url;
}
+ /**
+ * Append additional request parameter.
+ * @param name
+ * @param value
+ * @throws TestException
+ * if connection have already been started.
+ */
public void addRequestParameter(String name, String value) {
checkNotStarted();
String[] values = requestParameters.get(name);
@@ -211,7 +247,10 @@
}
/**
- * @return
+ * Get content of the response as String.
+ * @return content of the response writer or String created from the ServletOutputStream with current response encoding.
+ * @throws TestException
+ * if connection have not been started or response has an unsupported encoding.
*/
public String getContentAsString() {
checkStarted();
@@ -234,6 +273,12 @@
return content;
}
+ /**
+ * Get content of the response as byte array.
+ * @return content of the ServletOutputStream or convert String, collected by response writer, with current response encoding.
+ * @throws TestException
+ * if connection have not been started or response has unsupported encoding.
+ */
public byte[] getResponseBody() {
checkStarted();
byte[] content = response.getStreamContent();
@@ -254,6 +299,7 @@
}
/**
+ * List of the {@link Cookie} used by the request or response ( There are same cookies for both request and response ).
* @return the cookies
*/
public List<Cookie> getCookies() {
@@ -261,6 +307,7 @@
}
/**
+ * request object for the this connection.
* @return the request
*/
public HttpServletRequest getRequest() {
@@ -268,18 +315,127 @@
}
/**
+ * response object for the this connection.
* @return the response
*/
public HttpServletResponse getResponse() {
return responseProxy;
}
+ /**
+ * @return encoding used to write response.
+ * @throws TestException
+ * if connection have not been started .
+ */
+ public String getResponseCharacterEncoding() {
+ checkStarted();
+ return response.getCharacterEncoding();
+ }
+
+ /**
+ * @return content type ( eg 'text/html' ) of the response.
+ * @throws TestException
+ * if connection have not been started .
+ */
+ public String getResponseContentType() {
+ checkStarted();
+ return response.getContentType();
+ }
+
+ /**
+ * @return HTTP status code of the response.
+ * @throws TestException
+ * if connection have not been started .
+ */
+ public int getResponseStatus() {
+ checkStarted();
+ return response.getStatus();
+ }
+
+ /**
+ * @return HTTP error message.
+ * @throws TestException
+ * if connection have not been started .
+ */
+ public String getErrorMessage() {
+ checkStarted();
+ return response.getErrorMessage();
+ }
+
+ /**
+ * Set request Query string. This method does not parse query string, {@link #parseFormParameters(String)} should be used.
+ * @param queryString
+ * the queryString to set
+ * @throws TestException
+ * if connection have already been started .
+ */
+ public void setQueryString(String queryString) {
+ checkNotStarted();
+ this.queryString = queryString;
+ }
+
+ /**
+ * @return the queryString
+ */
+ public String getQueryString() {
+ return queryString;
+ }
+
+ /**
+ * Get HTTP response headers.
+ * @return headers name-values map.
+ * @throws TestException
+ * if connection have not been started .
+ */
+ public Map<String, String[]> getResponseHeaders() {
+ checkStarted();
+ return response.getHeaders();
+ }
+
+ /**
+ * Set charset for the request body.
+ * @param charset
+ * @throws UnsupportedEncodingException
+ */
+ public void setRequestCharacterEncoding(String charset) throws UnsupportedEncodingException {
+ checkNotStarted();
+ request.setCharacterEncoding(charset);
+ }
+
+ /**
+ * Set HTTP POST/PUT methods uploading content.
+ * @param body
+ */
+ public void setRequestBody(String body) {
+ checkNotStarted();
+ request.setRequestBody(body);
+ }
+
+ /**
+ * Set HTTP request content type ( eg 'application/x-www-form-urlencoded' or 'text/xml' ).
+ * @param contentType
+ */
+ public void setRequestContentType(String contentType) {
+ checkNotStarted();
+ request.setContentType(contentType);
+
+ }
+
+ /**
+ * Append additional HTTP request headers.
+ * @param headers
+ */
+ public void addRequestHeaders(Map<String, String> headers) {
+ checkNotStarted();
+ request.addHeaders(headers);
+ }
+
private class ConnectionRequest extends StagingHttpRequest {
-
+
public Cookie[] getCookies() {
return cookies.toArray(COOKIE);
}
-
+
/*
* (non-Javadoc)
*
@@ -288,7 +444,7 @@
public String getMethod() {
return method.toString();
}
-
+
/*
* (non-Javadoc)
*
@@ -297,7 +453,7 @@
public String getServletPath() {
return servletPath;
}
-
+
/*
* (non-Javadoc)
*
@@ -306,7 +462,7 @@
public String getPathInfo() {
return pathInfo;
}
-
+
/*
* (non-Javadoc)
*
@@ -315,7 +471,7 @@
public String getQueryString() {
return queryString;
}
-
+
/*
* (non-Javadoc)
*
@@ -324,7 +480,24 @@
public String getRequestURI() {
return url.getPath();
}
-
+
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.StagingHttpRequest#getServerName()
+ */
+ @Override
+ public String getServerName() {
+ return url.getHost();
+ }
+
+
+ @Override
+ public int getLocalPort() {
+ int port = url.getPort();
+ if(port < 0){
+ port = super.getLocalPort();
+ }
+ return port;
+ }
/*
* (non-Javadoc)
*
@@ -337,7 +510,7 @@
}
return null;
}
-
+
/*
* (non-Javadoc)
*
@@ -347,7 +520,7 @@
public Map getParameterMap() {
return Collections.unmodifiableMap(requestParameters);
}
-
+
/*
* (non-Javadoc)
*
@@ -357,7 +530,7 @@
public Enumeration getParameterNames() {
return Collections.enumeration(requestParameters.keySet());
}
-
+
/*
* (non-Javadoc)
*
@@ -367,7 +540,7 @@
public String[] getParameterValues(String name) {
return requestParameters.get(name);
}
-
+
/*
* (non-Javadoc)
*
@@ -376,7 +549,7 @@
public HttpSession getSession() {
return server.getSession();
}
-
+
/*
* (non-Javadoc)
*
@@ -385,7 +558,7 @@
public HttpSession getSession(boolean create) {
return server.getSession(create);
}
-
+
@Override
public RequestDispatcher getRequestDispatcher(String path) {
RequestDispatcher dispatcher = null;
@@ -400,43 +573,43 @@
final RequestChain dispatchedServlet = server.getServlet(path);
if (null != dispatchedServlet) {
dispatcher = new RequestDispatcher() {
-
+
public void forward(ServletRequest request,
ServletResponse response) throws ServletException,
IOException {
response.reset();
dispatchedServlet.execute(request, response);
}
-
+
public void include(ServletRequest request,
ServletResponse response) throws ServletException,
IOException {
dispatchedServlet.execute(request, response);
}
-
+
};
}
return dispatcher;
}
-
+
@Override
protected void attributeAdded(String name, Object o) {
server.requestAttributeAdded(this, name, o);
-
+
}
-
+
@Override
protected void attributeRemoved(String name, Object removed) {
server.requestAttributeRemoved(this, name, removed);
-
+
}
-
+
@Override
protected void attributeReplaced(String name, Object o) {
server.requestAttributeReplaced(this, name, o);
-
+
}
-
+
}
private class ConnectionResponse extends StagingHttpResponse {
@@ -449,73 +622,9 @@
*/
public void addCookie(Cookie cookie) {
cookies.add(cookie);
-
+
}
-
+
}
- public String getCharacterEncoding() {
- checkStarted();
- return response.getCharacterEncoding();
- }
-
- public String getContentType() {
- checkStarted();
- return response.getContentType();
- }
-
- public int getStatus() {
- checkStarted();
- return response.getStatus();
- }
-
- public String getErrorMessage() {
- checkStarted();
- return response.getErrorMessage();
- }
-
- /**
- * @param queryString
- * the queryString to set
- */
- public void setQueryString(String queryString) {
- checkNotStarted();
- this.queryString = queryString;
- }
-
- /**
- * @return the queryString
- */
- public String getQueryString() {
- return queryString;
- }
-
- /**
- * @return
- */
- public Map<String, String[]> getResponseHeaders() {
- checkStarted();
- return response.getHeaders();
- }
-
- public void setRequestCharacterEncoding(String charset) throws UnsupportedEncodingException {
- checkNotStarted();
- request.setCharacterEncoding(charset);
- }
-
- public void setRequestBody(String body) {
- checkNotStarted();
- request.setRequestBody(body);
- }
-
- public void setRequestContentType(String contentType) {
- checkNotStarted();
- request.setContentType(contentType);
-
- }
-
- public void addRequestHeaders(Map<String, String> headers) {
- request.addHeaders(headers);
- }
-
}
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StagingServer.java 2008-11-20 20:25:42 UTC (rev 11282)
@@ -15,6 +15,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -31,6 +32,8 @@
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
@@ -41,9 +44,17 @@
import org.richfaces.test.TestException;
/**
- * This class implements limited Http servlet container 2.5 functionality. It
- * supports only calls only, java code configuration, just one web application
- * etc...
+ * This class implements limited Http servlet container 2.5 functionality. It is designed for a test purposes only ,so that has a limitations:
+ * <ul>
+ * <li>supports local calls only.</li>
+ * <li>java code only configuration ( no xml files processed ).</li>
+ * <li>just one web application, 'deployed' in the root context.</li>
+ * <li>only one client session</li>
+ * <li>communicates by the local java calls only, no network connection</li>
+ * <li>no JSP compilator support ( but it is possible to register pre-compiled pages as servlets)</li>
+ * <li>...</li>
+ * </ul>
+ * It is main part of the test framework.
*
*/
public class StagingServer {
@@ -58,6 +69,8 @@
private static final Class<HttpSessionAttributeListener> SESSION_ATTRIBUTE_LISTENER_CLASS = HttpSessionAttributeListener.class;
+ private static final Logger log = ServerLogger.SERVER.getLogger();
+
private List<RequestChain> servlets = new ArrayList<RequestChain>();
private RequestChain defaultServlet;
@@ -70,20 +83,21 @@
private final Map<String, String> mimeTypes = new HashMap<String, String>();
-
private InvocationListener invocationListener;
-
private StagingServletContext context;
-
+
private ServletContext contextProxy;
-
private ServerHttpSession session;
private HttpSession sessionProxy;
-
+ /**
+ * This inner class links ServletContext calls to the server instance.
+ * @author asmirnov
+ *
+ */
private class LocalContext extends StagingServletContext {
/*
@@ -100,6 +114,9 @@
return mimeTypes.get(file);
}
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.StagingServletContext#valueBound(javax.servlet.ServletContextAttributeEvent)
+ */
@Override
protected void valueBound(ServletContextAttributeEvent event) {
// inform listeners.
@@ -111,6 +128,9 @@
}
}
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.StagingServletContext#valueReplaced(javax.servlet.ServletContextAttributeEvent)
+ */
@Override
protected void valueReplaced(ServletContextAttributeEvent event) {
// inform listeners.
@@ -122,6 +142,9 @@
}
}
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.StagingServletContext#valueUnbound(javax.servlet.ServletContextAttributeEvent)
+ */
@Override
protected void valueUnbound(ServletContextAttributeEvent event) {
// inform listeners.
@@ -133,24 +156,33 @@
}
}
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.StagingServletContext#getServerResource(java.lang.String)
+ */
@Override
- /*
- * @param path
- *
- * @return
- */
protected ServerResource getServerResource(String path) {
return serverRoot.getResource(new ServerResourcePath(path));
}
}
+ /**
+ * This inner class links session object calls to the server instance.
+ * @author asmirnov
+ *
+ */
private class ServerHttpSession extends StagingHttpSession {
+ /* (non-Javadoc)
+ * @see javax.servlet.http.HttpSession#getServletContext()
+ */
public ServletContext getServletContext() {
return context;
}
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.StagingHttpSession#valueBound(javax.servlet.http.HttpSessionBindingEvent)
+ */
@Override
protected void valueBound(
final HttpSessionBindingEvent sessionBindingEvent) {
@@ -163,6 +195,9 @@
});
}
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.StagingHttpSession#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
+ */
@Override
protected void valueUnbound(
final HttpSessionBindingEvent sessionBindingEvent) {
@@ -175,6 +210,9 @@
});
}
+ /* (non-Javadoc)
+ * @see org.richfaces.test.staging.StagingHttpSession#valueReplaced(javax.servlet.http.HttpSessionBindingEvent)
+ */
@Override
protected void valueReplaced(
final HttpSessionBindingEvent sessionBindingEvent) {
@@ -203,7 +241,7 @@
/**
* Append executable server object ( {@link Filter} or {@link Servlet}
- * container.
+ * to the server.
*
* @param servlet
*/
@@ -228,7 +266,8 @@
*
* @param path
* request path relative to web application context.
- * @return
+ * @return Appropriate Filter or Servlet executable object to serve given request. If no servlet was registered for the given path,
+ * try to send requested object directly.
*/
public RequestChain getServlet(String path) {
RequestChain result = null;
@@ -239,9 +278,11 @@
}
}
if (null == result) {
+ // Is requested object exist in the virtual content ?
try {
URL resource = context.getResource(path);
if (null != resource) {
+ // Serve it directly.
result = defaultServlet;
}
} catch (MalformedURLException e) {
@@ -251,29 +292,55 @@
return result;
}
+ /**
+ * Add web application init parameter.
+ * @param name
+ * @param value
+ */
public void addInitParameter(String name, String value) {
initParameters.put(name, value);
}
- void addMimeType(String extension, String mimeType) {
+ /**
+ * Add default mime type for serve files with given extension.
+ * @param extension
+ * @param mimeType
+ */
+ public void addMimeType(String extension, String mimeType) {
mimeTypes.put(extension, mimeType);
}
+ /**
+ * Add java resource to the virtual web application content. This method makes all parent directories as needed.
+ * @param path path to the file in the virtual web server.
+ * @param resource path to the resource in the classpath, as required by the {@link ClassLoader#getResource(String)}.
+ */
public void addResource(String path, String resource) {
ServerResourcePath resourcePath = new ServerResourcePath(path);
serverRoot.addResource(resourcePath, new ClasspathServerResource(
resource));
}
+ /**
+ * Add resource to the virtual veb application content. This method makes all parent directories as needed.
+ * @param path path to the file in the virtual web server.
+ * @param resource {@code URL} to the file content.
+ */
public void addResource(String path, URL resource) {
serverRoot.addResource(new ServerResourcePath(path),
new UrlServerResource(resource));
}
+ /**
+ * Add all resources from the directory to the virtual web application content.
+ * @param path name of the target directory in the virtual web application. If no such directory exists, it will be created, as well as all parent directories as needed.
+ * @param resource {@code URL} to the source directory or any file in the source directory. Only 'file' or 'jar' protocols are supported. If this parameter points to a file, it will be converted to a enclosing directory.
+ */
public void addResourcesFromDirectory(String path, URL resource) {
ServerResourcePath resourcePath = new ServerResourcePath(path);
ServerResource baseDirectory = serverRoot.getResource(resourcePath);
if (null == baseDirectory) {
+ // Create target directory.
baseDirectory = new ServerResourcesDirectory();
serverRoot.addResource(resourcePath, baseDirectory);
}
@@ -287,6 +354,11 @@
}
}
+ /**
+ * Internal method used by the {@link #addResourcesFromDirectory(String, URL)} to process 'file' protocol.
+ * @param resource source directory.
+ * @param baseDirectory target virtual directory.
+ */
protected void addResourcesFromFile(URL resource,
ServerResource baseDirectory) {
File file = new File(resource.getPath());
@@ -300,6 +372,11 @@
}
}
+ /**
+ * Internal method used by the {@link #addResourcesFromDirectory(String, URL)} to process 'jar' protocol.
+ * @param resource URL to the any object in the source directory.
+ * @param baseDirectory target virtual directory.
+ */
protected void addResourcesFromJar(URL resource,
ServerResource baseDirectory) {
try {
@@ -330,6 +407,7 @@
}
/**
+ * Internal reccursive method process directory content and all subdirectories.
* @param baseDirectory
* @param file
* @throws MalformedURLException
@@ -353,11 +431,26 @@
}
}
+ /**
+ * Add web-application wide listenes, same as it is defined by the
+ * <listener> element in the web.xml file for a real server.
+ * Supported listener types:
+ * <ul>
+ * <li>{@link ServletContextListener}</li>
+ * <li>{@link ServletContextAttributeListener}</li>
+ * <li>{@link HttpSessionListener}</li>
+ * <li>{@link HttpSessionAttributeListener}</li>
+ * <li>{@link ServletRequestListener}</li>
+ * <li>{@link ServletRequestAttributeListener}</li>
+ * </ul>
+ * @param listener web listener instance.
+ */
public void addWebListener(EventListener listener) {
contextListeners.add(listener);
}
/**
+ * Getter method for 'interceptor' events listener.
* @return the invocationListener
*/
public InvocationListener getInvocationListener() {
@@ -365,52 +458,90 @@
}
/**
- * @param invocationListener the invocationListener to set
+ * Set listener which gets events on all calls to any methods of the {@link ServletContext}, {@link HttpSession}, {@link HttpServletRequest}, {@link HttpServletResponse} instances
+ * in the virtual server. this interceptor can be used to check internal calls in the tests .
+ * @param invocationListener
+ * the invocationListener to set
*/
public void setInvocationListener(InvocationListener invocationListener) {
this.invocationListener = invocationListener;
}
/**
+ * Create instance of the {@link InvocationHandler} for the proxy objects. This handler fire events to the
+ * registered {@link InvocationListener} ( if present ) after target object method call.
* @return the invocationHandler
*/
- public InvocationHandler getInvocationHandler(final Object target) {
+ InvocationHandler getInvocationHandler(final Object target) {
return new InvocationHandler() {
-
+
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
InvocationListener listener = getInvocationListener();
try {
Object result = method.invoke(target, args);
- if(null != listener){
- listener.afterInvoke(new InvocationEvent(target,method,args,result));
+ if (null != listener) {
+ listener.afterInvoke(new InvocationEvent(target,
+ method, args, result));
}
return result;
} catch (Throwable e) {
- if(null != listener){
- listener.processException(new InvocationErrorEvent(target,method,args,e));
+ if (null != listener) {
+ listener.processException(new InvocationErrorEvent(
+ target, method, args, e));
}
throw e;
}
}
-
+
};
-
+
}
+ /**
+ * Get virtual server session object. Create new one if necessary.
+ * @return instance of the virtual server session.
+ */
public HttpSession getSession() {
return getSession(true);
}
+ /**
+ *
+ * Returns the current <code>HttpSession</code>
+ * associated with this server or, if there is no
+ * current session and <code>create</code> is true, returns
+ * a new session. Staging server supports only one session per instance,
+ * different clients for the same server instance does not supported.
+ *
+ * <p>If <code>create</code> is <code>false</code>
+ * and the request has no valid <code>HttpSession</code>,
+ * this method returns <code>null</code>.
+ *
+ *
+ * @param create <code>true</code> to create
+ * a new session for this request if necessary;
+ * <code>false</code> to return <code>null</code>
+ * if there's no current session
+ *
+ *
+ * @return the <code>HttpSession</code> associated
+ * with this server instance or <code>null</code> if
+ * <code>create</code> is <code>false</code>
+ * and the server has no session
+ *
+ */
public synchronized HttpSession getSession(boolean create) {
if (null == this.session && create) {
this.session = new ServerHttpSession();
// Create proxy objects.
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- if(null == loader){
+ if (null == loader) {
loader = this.getClass().getClassLoader();
}
- this.sessionProxy = (HttpSession) Proxy.newProxyInstance(loader, new Class[]{HttpSession.class}, getInvocationHandler(session));
+ this.sessionProxy = (HttpSession) Proxy.newProxyInstance(loader,
+ new Class[] { HttpSession.class },
+ getInvocationHandler(session));
// inform session listeners.
final HttpSessionEvent event = new HttpSessionEvent(session);
fireEvent(SESSION_LISTENER_CLASS,
@@ -423,6 +554,11 @@
return sessionProxy;
}
+ /**
+ * Virtual server initialization. This method creates instances of the {@link ServletContext}, {@link JspFactory},
+ * informs {@link ServletContextListener} ind inits all {@link Filter} and {@link Servlet} instances.
+ * It should be called from test setUp method to prepare testing environment.
+ */
public void init() {
// Create context.
this.context = new LocalContext();
@@ -433,10 +569,14 @@
// Inform listeners
// Create proxy objects.
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- if(null == loader){
+ if (null == loader) {
loader = this.getClass().getClassLoader();
}
- this.contextProxy = (ServletContext) Proxy.newProxyInstance(loader, new Class[]{ServletContext.class}, getInvocationHandler(context));
+ this.contextProxy = (ServletContext) Proxy.newProxyInstance(loader,
+ new Class[] { ServletContext.class },
+ getInvocationHandler(context));
+ // Create default servlet
+ defaultServlet = new ServletContainer(null, new StaticServlet());
final ServletContextEvent event = new ServletContextEvent(context);
fireEvent(CONTEXT_LISTENER_CLASS,
new EventInvoker<ServletContextListener>() {
@@ -450,13 +590,17 @@
// init servlet
servlet.init(this.context);
}
- defaultServlet = new ServletContainer(null, new StaticServlet());
defaultServlet.init(getContext());
} catch (ServletException e) {
throw new TestException(e);
}
}
+ /**
+ * Stop wirtual server. This method informs {@link ServletContextListener} ind inits all {@link Filter} and {@link Servlet} instances, as well remove all internal objects.
+ * It should be called from the testt thearDown method to clean up testing environment.
+ *
+ */
public void destroy() {
// Destroy session
if (null != this.session) {
@@ -489,15 +633,30 @@
}
+ /**
+ * Get virtual connection to the given URL. Even thought for an http request to the
+ * external servers, only local connection to the virtual server will be created.
+ * @param url request url.
+ * @return local connection to the appropriate servlet in the virtual server.
+ * @throws {@link TestException} if no servlet found to process given URL.
+ */
public StagingConnection getConnection(URL url) {
return new StagingConnection(this, url);
}
+ /**
+ * Get instance of virtual web application context.
+ * @return context instance.
+ */
public ServletContext getContext() {
return contextProxy;
}
- public void requestStarted(ServletRequest request) {
+ /**
+ * Inform {@link ServletRequestListener} instances. For internal use only.
+ * @param request started request.
+ */
+ void requestStarted(ServletRequest request) {
final ServletRequestEvent event = new ServletRequestEvent(context,
request);
fireEvent(REQUEST_LISTENER_CLASS,
@@ -509,7 +668,11 @@
});
}
- public void requestFinished(ServletRequest request) {
+ /**
+ * Inform {@link ServletRequestListener} instances. For internal use only.
+ * @param request finished request.
+ */
+ void requestFinished(ServletRequest request) {
final ServletRequestEvent event = new ServletRequestEvent(context,
request);
fireEvent(REQUEST_LISTENER_CLASS,
@@ -520,7 +683,7 @@
});
}
- public void requestAttributeAdded(ServletRequest request, String name,
+ void requestAttributeAdded(ServletRequest request, String name,
Object o) {
final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(
context, request, name, o);
@@ -532,7 +695,7 @@
});
}
- public void requestAttributeRemoved(ServletRequest request, String name,
+ void requestAttributeRemoved(ServletRequest request, String name,
Object removed) {
final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(
context, request, name, removed);
@@ -544,7 +707,7 @@
});
}
- public void requestAttributeReplaced(ServletRequest request, String name,
+ void requestAttributeReplaced(ServletRequest request, String name,
Object value) {
final ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(
context, request, name, value);
Modified: branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StaticServlet.java
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StaticServlet.java 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/java/org/richfaces/test/staging/StaticServlet.java 2008-11-20 20:25:42 UTC (rev 11282)
@@ -24,6 +24,12 @@
throws ServletException, IOException {
InputStream inputStream = getServletContext().getResourceAsStream(req.getServletPath());
if(null != inputStream){
+ String fileName = req.getServletPath();
+ String mimeType = getServletContext().getMimeType(fileName);
+ if(null == mimeType){
+ mimeType = "text/plain";
+ }
+ resp.setContentType(mimeType);
ServletOutputStream outputStream = resp.getOutputStream();
int c;
while((c = inputStream.read())>0){
Copied: branches/jsf2.0/framework/jsf-test/src/main/javadoc (from rev 11281, trunk/framework/jsf-test/src/main/javadoc)
Copied: branches/jsf2.0/framework/jsf-test/src/main/javadoc/org (from rev 11281, trunk/framework/jsf-test/src/main/javadoc/org)
Copied: branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces (from rev 11281, trunk/framework/jsf-test/src/main/javadoc/org/richfaces)
Copied: branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test (from rev 11281, trunk/framework/jsf-test/src/main/javadoc/org/richfaces/test)
Deleted: branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html
===================================================================
--- trunk/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html 2008-11-20 20:25:42 UTC (rev 11282)
@@ -1,10 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<title>Insert title here</title>
-</head>
-<body>
-
-</body>
-</html>
\ No newline at end of file
Copied: branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html (from rev 11281, trunk/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html)
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html (rev 0)
+++ branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html 2008-11-20 20:25:42 UTC (rev 11282)
@@ -0,0 +1,10 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Insert title here</title>
+</head>
+<body>
+
+</body>
+</html>
\ No newline at end of file
Property changes on: branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/package.html
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging (from rev 11281, trunk/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging)
Deleted: branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging/package.html
===================================================================
--- trunk/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging/package.html 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging/package.html 2008-11-20 20:25:42 UTC (rev 11282)
@@ -1,10 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<title>Insert title here</title>
-</head>
-<body>
-
-</body>
-</html>
\ No newline at end of file
Copied: branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging/package.html (from rev 11281, trunk/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging/package.html)
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging/package.html (rev 0)
+++ branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging/package.html 2008-11-20 20:25:42 UTC (rev 11282)
@@ -0,0 +1,10 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Insert title here</title>
+</head>
+<body>
+
+</body>
+</html>
\ No newline at end of file
Property changes on: branches/jsf2.0/framework/jsf-test/src/main/javadoc/org/richfaces/test/staging/package.html
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: branches/jsf2.0/framework/jsf-test/src/main/javadoc/overview.html
===================================================================
--- trunk/framework/jsf-test/src/main/javadoc/overview.html 2008-11-20 20:04:55 UTC (rev 11281)
+++ branches/jsf2.0/framework/jsf-test/src/main/javadoc/overview.html 2008-11-20 20:25:42 UTC (rev 11282)
@@ -1,10 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<title>Insert title here</title>
-</head>
-<body>
-
-</body>
-</html>
\ No newline at end of file
Copied: branches/jsf2.0/framework/jsf-test/src/main/javadoc/overview.html (from rev 11281, trunk/framework/jsf-test/src/main/javadoc/overview.html)
===================================================================
--- branches/jsf2.0/framework/jsf-test/src/main/javadoc/overview.html (rev 0)
+++ branches/jsf2.0/framework/jsf-test/src/main/javadoc/overview.html 2008-11-20 20:25:42 UTC (rev 11282)
@@ -0,0 +1,10 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Insert title here</title>
+</head>
+<body>
+
+</body>
+</html>
\ No newline at end of file
Property changes on: branches/jsf2.0/framework/jsf-test/src/main/javadoc/overview.html
___________________________________________________________________
Name: svn:mime-type
+ text/plain
17 years, 1 month
JBoss Rich Faces SVN: r11281 - in trunk/framework/jsf-test: src/main/java/org/richfaces/test and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2008-11-20 15:04:55 -0500 (Thu, 20 Nov 2008)
New Revision: 11281
Modified:
trunk/framework/jsf-test/pom.xml
trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java
Log:
make LocalWebResponse usable for an in-response tests
Modified: trunk/framework/jsf-test/pom.xml
===================================================================
--- trunk/framework/jsf-test/pom.xml 2008-11-20 16:06:01 UTC (rev 11280)
+++ trunk/framework/jsf-test/pom.xml 2008-11-20 20:04:55 UTC (rev 11281)
@@ -1,5 +1,6 @@
<?xml version="1.0"?>
-<project>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>framework</artifactId>
<groupId>org.richfaces</groupId>
@@ -25,7 +26,7 @@
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>1.2_10</version>
- <scope>provided</scope>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>el-impl</groupId>
@@ -103,5 +104,16 @@
<artifactId>xalan</artifactId>
<version>2.7.0</version>
</dependency>
+ <dependency>
+ <groupId>de.berlios.jsunit</groupId>
+ <artifactId>jsunit</artifactId>
+ <version>1.3</version>
+ <exclusions>
+ <exclusion>
+ <groupId>rhino</groupId>
+ <artifactId>js</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java
===================================================================
--- trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java 2008-11-20 16:06:01 UTC (rev 11280)
+++ trunk/framework/jsf-test/src/main/java/org/richfaces/test/LocalWebResponse.java 2008-11-20 20:04:55 UTC (rev 11281)
@@ -18,35 +18,61 @@
import com.gargoylesoftware.htmlunit.WebResponse;
/**
- * This implementation realise WebResponse wrapper for a staging server connection.
- * This class for an internal use only.
+ * This implementation realise WebResponse wrapper for a staging server
+ * connection. This class is used by the {@link LocalWebClient}, but also can be used to analise response rendering:
+ * <pre>
+ * ............
+ * @Test
+ * public void testRender() {
+ * setupFacesRequest();
+ * // Prepare view etc
+ * ..................
+ * lifecycle.render(facesContext);
+ * WebClient webClient = new LocalWebClient(facesServer);
+ * HtmlPage page = (HtmlPage) webClient.loadWebResponseInto(new LocalWebResponse(connection), webClient.getCurrentWindow());
+ * // analyse response
+ * assertTrue(....)
+ * }
+ * </pre>
+ *
* @author asmirnov
- *
+ *
*/
-final class LocalWebResponse implements WebResponse {
- private final WebRequestSettings settings;
+public class LocalWebResponse implements WebResponse {
+ private WebRequestSettings settings;
private final StagingConnection serverConnection;
- public LocalWebResponse(WebRequestSettings settings,StagingConnection serverConnection) {
- this.settings = settings;
+ public LocalWebResponse(StagingConnection serverConnection) {
this.serverConnection = serverConnection;
}
- /* (non-Javadoc)
+ public LocalWebResponse(WebRequestSettings settings,
+ StagingConnection connection) {
+ this(connection);
+ this.settings = settings;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getContentAsStream()
*/
public InputStream getContentAsStream() throws IOException {
return new ByteArrayInputStream(getResponseBody());
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getContentAsString()
*/
public String getContentAsString() {
return serverConnection.getContentAsString();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getContentCharSet()
*/
public String getContentCharSet() {
@@ -57,73 +83,103 @@
return serverConnection.getResponseContentType();
}
- /* (non-Javadoc)
- * @see com.gargoylesoftware.htmlunit.WebResponse#getLoadTimeInMilliSeconds()
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.gargoylesoftware.htmlunit.WebResponse#getLoadTimeInMilliSeconds()
*/
public long getLoadTimeInMilliSeconds() {
return 0;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getRequestMethod()
*/
public com.gargoylesoftware.htmlunit.HttpMethod getRequestMethod() {
- return com.gargoylesoftware.htmlunit.HttpMethod.valueOf(serverConnection.getRequestMethod().toString());
+ return com.gargoylesoftware.htmlunit.HttpMethod
+ .valueOf(serverConnection.getRequestMethod().toString());
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getRequestSettings()
*/
public WebRequestSettings getRequestSettings() {
+ if (settings == null) {
+ settings = new WebRequestSettings(this.getUrl(), getRequestMethod());
+ }
return settings;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getResponseBody()
*/
public byte[] getResponseBody() {
return serverConnection.getResponseBody();
}
- /* (non-Javadoc)
- * @see com.gargoylesoftware.htmlunit.WebResponse#getResponseHeaderValue(java.lang.String)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.gargoylesoftware.htmlunit.WebResponse#getResponseHeaderValue(java
+ * .lang.String)
*/
public String getResponseHeaderValue(String headerName) {
- // TODO Auto-generated method stub
+ String[] values = serverConnection.getResponseHeaders().get(headerName);
+ if(null != values && values.length >0){
+ return values[0];
+ }
return null;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getStatusCode()
*/
public int getStatusCode() {
return serverConnection.getResponseStatus();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getStatusMessage()
*/
public String getStatusMessage() {
return serverConnection.getErrorMessage();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getUrl()
*/
public URL getUrl() {
return serverConnection.getUrl();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.gargoylesoftware.htmlunit.WebResponse#getResponseHeaders()
*/
public List<NameValuePair> getResponseHeaders() {
ArrayList<NameValuePair> headers = new ArrayList<NameValuePair>(10);
- for (Entry<String, String[]> entry : serverConnection.getResponseHeaders().entrySet()) {
+ for (Entry<String, String[]> entry : serverConnection
+ .getResponseHeaders().entrySet()) {
for (String value : entry.getValue()) {
- headers.add(new NameValuePair(entry.getKey(),value));
+ headers.add(new NameValuePair(entry.getKey(), value));
}
- };
+ }
+ ;
return headers;
}
}
\ No newline at end of file
17 years, 1 month