[view] new test for etags with audited tables
authorAsier Lostalé <asier.lostale@openbravo.com>
Tue, 07 Aug 2018 08:43:26 +0200
changeset 35072 a244cd3d71a7
parent 35071 813f68aaf192
child 35073 6b0da887fc26
[view] new test for etags with audited tables
src-test/src/org/openbravo/test/base/TestConstants.java
src-test/src/org/openbravo/test/views/ETagGeneration.java
--- a/src-test/src/org/openbravo/test/base/TestConstants.java	Mon Aug 06 16:43:06 2018 +0200
+++ b/src-test/src/org/openbravo/test/base/TestConstants.java	Tue Aug 07 08:43:26 2018 +0200
@@ -39,6 +39,10 @@
     public static final String ESP_ADMIN = "F3196A30B53A42778727B2852FF90C24";
   }
 
+  public static class Tables {
+    public static final String C_ORDER = "259";
+  }
+
   private TestConstants() {
   }
 }
--- a/src-test/src/org/openbravo/test/views/ETagGeneration.java	Mon Aug 06 16:43:06 2018 +0200
+++ b/src-test/src/org/openbravo/test/views/ETagGeneration.java	Tue Aug 07 08:43:26 2018 +0200
@@ -32,9 +32,11 @@
 import org.junit.Test;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.businessUtility.Preferences;
+import org.openbravo.model.ad.datamodel.Table;
 import org.openbravo.model.ad.domain.Preference;
 import org.openbravo.model.ad.system.Client;
 import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.test.base.TestConstants.Tables;
 import org.openbravo.test.datasource.BaseDataSourceTestDal;
 import org.openbravo.test.datasource.DatasourceTestUtil;
 
@@ -82,6 +84,33 @@
     }
   }
 
+  @Test
+  public void auditTableShouldChangeETag() throws Exception {
+    assumeThat("Has modules in development", hasModulesInDevelopment(), is(false));
+    setSystemAdministratorContext();
+    boolean wasAudited = false;
+
+    try {
+      String oldEtag = getEtag(SALES_ORDER_WINDOW);
+
+      Table orderTable = OBDal.getInstance().get(Table.class, Tables.C_ORDER);
+      wasAudited = orderTable.isFullyAudited();
+      orderTable.setFullyAudited(!wasAudited);
+      OBDal.getInstance().commitAndClose();
+
+      String newEtag = getEtag(SALES_ORDER_WINDOW);
+      assertThat("ETag should change", newEtag, is(not(oldEtag)));
+
+      assertResponseCode("Response after adding server dl config", SALES_ORDER_WINDOW, oldEtag,
+          HttpServletResponse.SC_OK);
+      assertResponseCode("Response on 2nd request after change audit config", SALES_ORDER_WINDOW,
+          newEtag, HttpServletResponse.SC_NOT_MODIFIED);
+    } finally {
+      Table orderTable = OBDal.getInstance().get(Table.class, Tables.C_ORDER);
+      orderTable.setFullyAudited(wasAudited);
+    }
+  }
+
   private Boolean hasModulesInDevelopment() {
     final Query<Object> indevelMods = OBDal.getInstance().getSession()
         .createQuery("select 1 from ADModule m where m.inDevelopment=true", Object.class);