related to bug 32375: added test case covering preference's client visibility
authorAsier Lostalé <asier.lostale@openbravo.com>
Fri, 04 Mar 2016 08:51:01 +0100
changeset 28828 d7b14fb65c2b
parent 28827 94f9263bb271
child 28829 798b079b6972
related to bug 32375: added test case covering preference's client visibility
src-test/src/org/openbravo/test/preference/PreferenceTest.java
--- a/src-test/src/org/openbravo/test/preference/PreferenceTest.java	Fri Mar 04 08:50:01 2016 +0100
+++ b/src-test/src/org/openbravo/test/preference/PreferenceTest.java	Fri Mar 04 08:51:01 2016 +0100
@@ -11,16 +11,18 @@
  * 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-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2010-2016 Openbravo SLU
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
  */
 package org.openbravo.test.preference;
 
+import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import java.sql.Connection;
@@ -282,6 +284,35 @@
   }
 
   @Test
+  public void testH1ClientVisibility() throws PropertyException {
+    setSystemAdministratorContext();
+    Client testClient = OBDal.getInstance().getProxy(Client.class, TEST_CLIENT_ID);
+    Client systemClient = OBDal.getInstance().getProxy(Client.class, "0");
+
+    final String propAttribute = "clientPropertyTest";
+    Preference p1 = Preferences.setPreferenceValue(propAttribute, "test client", false, testClient,
+        null, null, null, null, null);
+    Preference p2 = Preferences.setPreferenceValue(propAttribute, "system", false, systemClient,
+        null, null, null, null, null);
+
+    OBDal.getInstance().flush();
+
+    String valueClient = Preferences.getPreferenceValue(propAttribute, false, testClient, OBContext
+        .getOBContext().getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext
+        .getOBContext().getRole(), null);
+    assertThat("preference for client", valueClient, is("test client"));
+
+    String valueSystem = Preferences.getPreferenceValue(propAttribute, false, systemClient, OBDal
+        .getInstance().getProxy(Organization.class, "0"), OBContext.getOBContext().getUser(),
+        OBContext.getOBContext().getRole(), null);
+
+    assertThat("preference for system", valueSystem, is("system"));
+
+    OBDal.getInstance().remove(p1);
+    OBDal.getInstance().remove(p2);
+  }
+
+  @Test
   public void testIPLOrgVisibility() throws SQLException {
 
     setSystemAdministratorContext();