details: /erp/devel/pi/rev/775f64262c01
changeset: 6941:775f64262c01
user: Martin Taal <martin.taal <at> openbravo.com>
date: Wed Apr 07 08:45:20 2010 +0200
summary: Added update check on user context cache
details: /erp/devel/pi/rev/3cc3917c2808
changeset: 6942:3cc3917c2808
user: Martin Taal <martin.taal <at> openbravo.com>
date: Wed Apr 07 08:47:08 2010 +0200
summary: fixes issue 12883: Rest Webservice testcases fail because test data
is not what is expected
diffstat:
src-test/org/openbravo/test/webservice/WSReadTest.java | 22 ++++++++++-----
src-test/org/openbravo/test/webservice/WSUpdateTest.java | 7 ++++-
src/org/openbravo/service/web/UserContextCache.java | 13 +++++++++
3 files changed, 34 insertions(+), 8 deletions(-)
diffs (106 lines):
diff -r ceb1a1dc2bc4 -r 3cc3917c2808
src-test/org/openbravo/test/webservice/WSReadTest.java
--- a/src-test/org/openbravo/test/webservice/WSReadTest.java Wed Apr 07
10:23:42 2010 +0530
+++ b/src-test/org/openbravo/test/webservice/WSReadTest.java Wed Apr 07
08:47:08 2010 +0200
@@ -26,6 +26,9 @@
import org.hibernate.mapping.PersistentClass;
import org.openbravo.base.model.Entity;
import org.openbravo.base.session.SessionFactoryController;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBQuery;
+import org.openbravo.model.ad.datamodel.Column;
import org.openbravo.model.ad.datamodel.Table;
/**
@@ -81,16 +84,21 @@
* @throws Exception
*/
public void testPagedWhereClause() throws Exception {
- requestColumnPage(1, 10, 10);
- requestColumnPage(1, 5, 5);
- // note, that there are 32 rows in the query,
- // the test below may fail if the no. of columns changes
- requestColumnPage(30, 5, 2);
+ setBigBazaarAdminContext();
+ requestColumnPage(1, 10);
+ requestColumnPage(1, 5);
+ requestColumnPage(30, 5);
}
- private void requestColumnPage(int firstResult, int maxResult, int
expectedCount)
- throws Exception {
+ private void requestColumnPage(int firstResult, int maxResult) throws
Exception {
+
String whereClause = "(table.id='104' or table.id='105')";
+
+ final OBQuery<Column> columns =
OBDal.getInstance().createQuery(Column.class, whereClause);
+ final int columnCnt = columns.count();
+ final int expectedCount = ((firstResult + maxResult) < columnCnt ?
maxResult
+ : (columnCnt - firstResult));
+
whereClause = URLEncoder.encode(whereClause, "UTF-8");
String content = doTestGetRequest("/ws/dal/ADColumn?where=" + whereClause
+ "&firstResult="
+ firstResult + "&maxResult=" + maxResult, "<ADColumn", 200);
diff -r ceb1a1dc2bc4 -r 3cc3917c2808
src-test/org/openbravo/test/webservice/WSUpdateTest.java
--- a/src-test/org/openbravo/test/webservice/WSUpdateTest.java Wed Apr 07
10:23:42 2010 +0530
+++ b/src-test/org/openbravo/test/webservice/WSUpdateTest.java Wed Apr 07
08:47:08 2010 +0200
@@ -23,6 +23,7 @@
import org.apache.log4j.Logger;
import org.openbravo.base.provider.OBProvider;
+import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.service.OBCriteria;
import org.openbravo.dal.service.OBDal;
import org.openbravo.model.common.geography.City;
@@ -47,7 +48,11 @@
* sets the cityId member in this class.
*/
public void testACreateCity() {
- setBigBazaarAdminContext();
+ // do not replace this with a call to setUserContext,
+ // the city must be stored using the client/org of the 100 user
+ // this ensures that webservice calls will be able to find the city
+ // again
+ OBContext.setOBContext("100");
// first delete the current cities, as we should start fresh
final OBCriteria<City> obc =
OBDal.getInstance().createCriteria(City.class);
diff -r ceb1a1dc2bc4 -r 3cc3917c2808
src/org/openbravo/service/web/UserContextCache.java
--- a/src/org/openbravo/service/web/UserContextCache.java Wed Apr 07
10:23:42 2010 +0530
+++ b/src/org/openbravo/service/web/UserContextCache.java Wed Apr 07
08:47:08 2010 +0200
@@ -27,6 +27,8 @@
import org.openbravo.base.provider.OBProvider;
import org.openbravo.base.provider.OBSingleton;
import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.access.User;
/**
* The main purpose of the user context cache is to support session-less http
requests without a
@@ -103,9 +105,19 @@
class CacheEntry {
private OBContext obContext;
private long lastUsed;
+ private long lastUpdated;
private String userId;
public boolean hasExpired() {
+ try {
+ OBContext.enableAsAdminContext();
+ final User user = OBDal.getInstance().get(User.class, userId);
+ if (user == null || user.getUpdated().getTime() > lastUpdated) {
+ return true;
+ }
+ } finally {
+ OBContext.resetAsAdminContext();
+ }
return getLastUsed() < (System.currentTimeMillis() - EXPIRES_IN);
}
@@ -115,6 +127,7 @@
public void setObContext(OBContext obContext) {
this.obContext = obContext;
+ lastUpdated = obContext.getUser().getUpdated().getTime();
}
public long getLastUsed() {
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits