details:   https://code.openbravo.com/erp/devel/pi/rev/1cb95f1f4e4d
changeset: 33343:1cb95f1f4e4d
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Fri Feb 02 11:38:24 2018 +0100
summary:   related to issue 37700: code review improvements in test case

 - Use admin mode to create/remove data with the CostAdjustmentTestDataHelper
 - Use getProxy() to set the document type

diffstat:

 src-test/src/org/openbravo/test/datasource/LinkToParentTreeDataSourceTest.java 
|  52 ++++++---
 1 files changed, 33 insertions(+), 19 deletions(-)

diffs (96 lines):

diff -r 31ed5cfcd285 -r 1cb95f1f4e4d 
src-test/src/org/openbravo/test/datasource/LinkToParentTreeDataSourceTest.java
--- 
a/src-test/src/org/openbravo/test/datasource/LinkToParentTreeDataSourceTest.java
    Fri Jan 26 12:32:24 2018 +0100
+++ 
b/src-test/src/org/openbravo/test/datasource/LinkToParentTreeDataSourceTest.java
    Fri Feb 02 11:38:24 2018 +0100
@@ -58,6 +58,7 @@
    */
   @Test
   public void fetchIncludeNonActiveRecords() {
+    OBContext.setOBContext(TEST_USER_ID);
     this.costAdjustmentId = 
this.dataHelper.createCostAdjustmentWithActiveAndNonActiveLines();
 
     assertThat("Fetched the expected number of records", 
this.getNumberOfCostAdjustmentLines(),
@@ -70,6 +71,7 @@
    */
   @Test
   public void fetchIncludeHasChildrenHavingNonActiveChildren() {
+    OBContext.setOBContext(TEST_USER_ID);
     this.costAdjustmentId = 
this.dataHelper.createCostAdjustmentWithANonActiveChildLine();
 
     assertThat("First node has children", 
this.doesFirstCostAdjustmentLineHasChildren(),
@@ -160,45 +162,57 @@
     private static final String DOCUMENT_NO = "::DOCUMENT-NO::";
 
     public String createCostAdjustmentWithActiveAndNonActiveLines() {
-      OBContext.setOBContext(TEST_USER_ID);
+      try {
+        OBContext.setAdminMode(false);
 
-      CostAdjustment costAdjustment = this.createCostAdjustment();
-      this.createActiveCostAdjustmentLine(costAdjustment);
-      this.createNonActiveCostAdjustmentLine(costAdjustment);
+        CostAdjustment costAdjustment = this.createCostAdjustment();
+        this.createActiveCostAdjustmentLine(costAdjustment);
+        this.createNonActiveCostAdjustmentLine(costAdjustment);
 
-      OBDal.getInstance().commitAndClose();
+        OBDal.getInstance().commitAndClose();
 
-      return costAdjustment.getId();
+        return costAdjustment.getId();
+      } finally {
+        OBContext.restorePreviousMode();
+      }
     }
 
     public String createCostAdjustmentWithANonActiveChildLine() {
-      OBContext.setOBContext(TEST_USER_ID);
+      try {
+        OBContext.setAdminMode(false);
 
-      CostAdjustment costAdjustment = this.createCostAdjustment();
-      CostAdjustmentLine parentAdjustmentLine = 
this.createActiveCostAdjustmentLine(costAdjustment);
-      this.createNonActiveChildAdjustmentLine(costAdjustment, 
parentAdjustmentLine);
-      OBDal.getInstance().commitAndClose();
+        CostAdjustment costAdjustment = this.createCostAdjustment();
+        CostAdjustmentLine parentAdjustmentLine = this
+            .createActiveCostAdjustmentLine(costAdjustment);
+        this.createNonActiveChildAdjustmentLine(costAdjustment, 
parentAdjustmentLine);
+        OBDal.getInstance().commitAndClose();
 
-      return costAdjustment.getId();
+        return costAdjustment.getId();
+      } finally {
+        OBContext.restorePreviousMode();
+      }
     }
 
     public void removeCostAdjustment(String id) {
-      OBContext.setOBContext(TEST_USER_ID);
-
-      OBDal obdal = OBDal.getInstance();
-      obdal.remove(obdal.getProxy(CostAdjustment.class, id));
-      obdal.commitAndClose();
+      try {
+        OBContext.setAdminMode(false);
+        OBDal obdal = OBDal.getInstance();
+        obdal.remove(obdal.getProxy(CostAdjustment.class, id));
+        obdal.commitAndClose();
+      } finally {
+        OBContext.restorePreviousMode();
+      }
     }
 
     private CostAdjustment createCostAdjustment() {
       OBDal obdal = OBDal.getInstance();
 
       CostAdjustment costAdjustment = 
OBProvider.getInstance().get(CostAdjustment.class);
-      costAdjustment.setDocumentType(obdal.get(DocumentType.class, 
DOCUMENT_TYPE_ID));
+      costAdjustment.setDocumentType(obdal.getProxy(DocumentType.class, 
DOCUMENT_TYPE_ID));
       costAdjustment.setDocumentNo(DOCUMENT_NO);
       costAdjustment.setSourceProcess(SOURCE_PROCESS);
 
-      OBDal.getInstance().save(costAdjustment);
+      obdal.save(costAdjustment);
 
       return costAdjustment;
     }

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to