details:   https://code.openbravo.com/erp/devel/pi/rev/cb94187ae5a2
changeset: 28854:cb94187ae5a2
user:      Inigo Sanchez <inigo.sanchez <at> openbravo.com>
date:      Tue Apr 05 16:50:22 2016 +0200
summary:   Related to bug 32584: Added test cases covering this regression

diffstat:

 src-test/src/org/openbravo/test/AllWebserviceTests.java                   |    
9 +-
 src-test/src/org/openbravo/test/datasource/TestFetchDSNoActiveEntity.java |  
108 ++++++++++
 src-test/src/org/openbravo/test/webservice/WSWithNoActiveEntityTest.java  |   
79 +++++++
 3 files changed, 193 insertions(+), 3 deletions(-)

diffs (239 lines):

diff -r 2c4101ab3ad8 -r cb94187ae5a2 
src-test/src/org/openbravo/test/AllWebserviceTests.java
--- a/src-test/src/org/openbravo/test/AllWebserviceTests.java   Tue Apr 05 
16:26:21 2016 +0200
+++ b/src-test/src/org/openbravo/test/AllWebserviceTests.java   Tue Apr 05 
16:50:22 2016 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2010-2015 Openbravo SLU 
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -30,18 +30,19 @@
 import org.openbravo.test.datasource.TestAllowUnpagedDatasourcePreference;
 import org.openbravo.test.datasource.TestCSVEncoding;
 import org.openbravo.test.datasource.TestComboDatasource;
+import org.openbravo.test.datasource.TestFetchDSNoActiveEntity;
 import org.openbravo.test.datasource.TestNoteDatasource;
 import org.openbravo.test.webservice.JSONWebServices;
 import org.openbravo.test.webservice.PerformanceTest;
 import org.openbravo.test.webservice.WSAddRecordWithComputedColumns;
 import org.openbravo.test.webservice.WSReadTest;
 import org.openbravo.test.webservice.WSUpdateTest;
+import org.openbravo.test.webservice.WSWithNoActiveEntityTest;
 import org.openbravo.test.webservice.WebServicesWithNoActiveFilterTest;
 
 /**
  * This test suite should only contain test cases which are to run the 
webservices included in core.
  * 
- * 
  */
 
 @RunWith(Suite.class)
@@ -62,6 +63,8 @@
     TestAllowUnpagedDatasourcePreference.class, //
     TestNoteDatasource.class, //
     WebServicesWithNoActiveFilterTest.class, //
-    ExtendedNavigationModelTest.class })
+    ExtendedNavigationModelTest.class, //
+    WSWithNoActiveEntityTest.class, //
+    TestFetchDSNoActiveEntity.class })
 public class AllWebserviceTests {
 }
diff -r 2c4101ab3ad8 -r cb94187ae5a2 
src-test/src/org/openbravo/test/datasource/TestFetchDSNoActiveEntity.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/datasource/TestFetchDSNoActiveEntity.java 
Tue Apr 05 16:50:22 2016 +0200
@@ -0,0 +1,108 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2016 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.datasource;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.codehaus.jettison.json.JSONObject;
+import org.junit.AfterClass;
+import org.junit.Test;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.service.json.JsonConstants;
+
+/**
+ * Test cases for ensures that fetch works properly with active and non active 
entity.
+ * 
+ * See issue https://issues.openbravo.com/view.php?id=32584
+ * 
+ * @author inigo.sanchez
+ *
+ */
+public class TestFetchDSNoActiveEntity extends BaseDataSourceTestDal {
+
+  @Test
+  public void fetchNoActiveOrganization() throws Exception {
+    OBContext.setAdminMode();
+    try {
+      // Fetching an active organization
+      JSONObject jsonResponse = doFetchOrg();
+      assertThat("Request status", jsonResponse.getInt("status"),
+          is(JsonConstants.RPCREQUEST_STATUS_SUCCESS));
+      assertThat("Request data", jsonResponse.getJSONArray("data").length(), 
is(1));
+
+      // Fetching a non active organization
+      setNoActiveOrganization();
+
+      JSONObject jsonResponseNoActive = doFetchOrg();
+      assertThat("Request status", jsonResponseNoActive.getInt("status"),
+          is(JsonConstants.RPCREQUEST_STATUS_SUCCESS));
+      assertThat("Request data", 
jsonResponseNoActive.getJSONArray("data").length(), is(1));
+
+    } finally {
+      OBDal.getInstance().commitAndClose();
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  /** Fetching organization F&B International Group */
+  private JSONObject doFetchOrg() throws Exception {
+    Map<String, String> params = new HashMap<String, String>();
+    params.put("windowId", "110");
+    params.put("tabId", "143");
+    params.put("moduleId", "0");
+    params.put("_operationType", "fetch");
+    params.put("id", "19404EAD144C49A0AF37D54377CF452D");
+    params.put("_startRow", "0");
+    params.put("_endRow", "1");
+
+    String response = 
doRequest("/org.openbravo.service.datasource/Organization", params, 200,
+        "POST");
+    return new JSONObject(response).getJSONObject("response");
+  }
+
+  /** Setting no active F&B International Group organization */
+  private void setNoActiveOrganization() {
+    // Select organization for testing
+    Organization orgTesting = OBDal.getInstance().get(Organization.class,
+        "19404EAD144C49A0AF37D54377CF452D");
+    orgTesting.setActive(false);
+    OBDal.getInstance().save(orgTesting);
+
+    OBDal.getInstance().commitAndClose();
+  }
+
+  /** Revert change in testing organization */
+  @AfterClass
+  public static void cleanUp() {
+    OBContext.setOBContext("100");
+    Organization orgTesting = OBDal.getInstance().get(Organization.class,
+        "19404EAD144C49A0AF37D54377CF452D");
+    orgTesting.setActive(true);
+    OBDal.getInstance().save(orgTesting);
+
+    OBDal.getInstance().commitAndClose();
+  }
+}
\ No newline at end of file
diff -r 2c4101ab3ad8 -r cb94187ae5a2 
src-test/src/org/openbravo/test/webservice/WSWithNoActiveEntityTest.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/webservice/WSWithNoActiveEntityTest.java  
Tue Apr 05 16:50:22 2016 +0200
@@ -0,0 +1,79 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2016 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.webservice;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.enterprise.Organization;
+
+/**
+ * Test cases for ensures that Dal Web services works properly with active and 
non active entity.
+ * 
+ * See issue https://issues.openbravo.com/view.php?id=32584
+ * 
+ * @author inigo.sanchez
+ *
+ */
+public class WSWithNoActiveEntityTest extends BaseWSTest {
+
+  private static final String ORG_ID_DAL = 
"<id>19404EAD144C49A0AF37D54377CF452D</id>";
+  private static final String ORG_ID = "19404EAD144C49A0AF37D54377CF452D";
+
+  @Test
+  public void dalWebServiceNoActiveOrganization() {
+    OBContext.setAdminMode();
+    try {
+      String dalResp = dalRequest("/ws/dal/Organization/" + ORG_ID);
+      assertThat("Request data", dalResp.contains(ORG_ID_DAL), is(true));
+
+      setNoActiveOrg();
+      String dalRespNoActive = dalRequest("/ws/dal/Organization/" + ORG_ID);
+      assertThat("Request data", dalRespNoActive.contains(ORG_ID_DAL), 
is(true));
+    } finally {
+      Organization orgTesting = OBDal.getInstance().get(Organization.class, 
ORG_ID);
+      orgTesting.setActive(true);
+      OBDal.getInstance().commitAndClose();
+      OBContext.restorePreviousMode();
+    }
+  }
+
+  private void setNoActiveOrg() {
+    Organization organization = OBDal.getInstance().get(Organization.class, 
ORG_ID);
+    organization.setActive(false);
+    OBDal.getInstance().commitAndClose();
+  }
+
+  private String dalRequest(String urlDalRequest) {
+    String organizationDataString;
+    OBContext.setAdminMode();
+    try {
+      organizationDataString = doTestGetRequest(urlDalRequest, null, 200);
+    } catch (Exception e) {
+      organizationDataString = e.getMessage();
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+    return organizationDataString;
+  }
+}

------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to