src-test/src/org/openbravo/test/views/GCSequenceNumberTests.java
author Stefan Hühner <stefan.huehner@openbravo.com>
Tue, 10 Apr 2018 19:48:23 +0200
changeset 33779 ad665ee3f59e
parent 28222 ec1d815ecbe2
child 33788 d28ede862e61
permissions -rw-r--r--
Fixed 38319. Auto-skip grid config junit test if other grid config present.

That test creates a specially crated grid config entry and verifies expected
behavior. That indirectly requires no other conflicting grid config present
for the same object (i.e. Business Partner tab). So auto-skip this testcase
if any non-core grid config is found similar to what the other 2 grid config
related tests already do.
naroa@28222
     1
/*
naroa@28222
     2
 *************************************************************************
naroa@28222
     3
 * The contents of this file are subject to the Openbravo  Public  License
naroa@28222
     4
 * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
naroa@28222
     5
 * Version 1.1  with a permitted attribution clause; you may not  use this
naroa@28222
     6
 * file except in compliance with the License. You  may  obtain  a copy of
naroa@28222
     7
 * the License at http://www.openbravo.com/legal/license.html 
naroa@28222
     8
 * Software distributed under the License  is  distributed  on  an "AS IS"
naroa@28222
     9
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
naroa@28222
    10
 * License for the specific  language  governing  rights  and  limitations
naroa@28222
    11
 * under the License. 
naroa@28222
    12
 * The Original Code is Openbravo ERP. 
naroa@28222
    13
 * The Initial Developer of the Original Code is Openbravo SLU 
naroa@28222
    14
 * All portions are Copyright (C) 2015 Openbravo SLU 
naroa@28222
    15
 * All Rights Reserved. 
naroa@28222
    16
 * Contributor(s):  ______________________________________.
naroa@28222
    17
 ************************************************************************
naroa@28222
    18
 */
naroa@28222
    19
naroa@28222
    20
package org.openbravo.test.views;
naroa@28222
    21
stefan@33779
    22
import static org.hamcrest.CoreMatchers.is;
naroa@28222
    23
import static org.hamcrest.Matchers.containsString;
stefan@33779
    24
import static org.hibernate.criterion.Restrictions.in;
stefan@33779
    25
import static org.hibernate.criterion.Restrictions.not;
naroa@28222
    26
import static org.junit.Assert.assertThat;
stefan@33779
    27
import static org.junit.Assume.assumeThat;
stefan@33779
    28
stefan@33779
    29
import java.util.Arrays;
stefan@33779
    30
import java.util.List;
naroa@28222
    31
naroa@28222
    32
import org.codehaus.jettison.json.JSONObject;
stefan@33779
    33
import org.junit.Before;
naroa@28222
    34
import org.junit.Test;
naroa@28222
    35
import org.openbravo.base.provider.OBProvider;
stefan@33779
    36
import org.openbravo.client.application.GCSystem;
naroa@28222
    37
import org.openbravo.client.application.GCTab;
naroa@28222
    38
import org.openbravo.client.application.window.OBViewUtil;
naroa@28222
    39
import org.openbravo.dal.core.OBContext;
stefan@33779
    40
import org.openbravo.dal.service.OBCriteria;
naroa@28222
    41
import org.openbravo.dal.service.OBDal;
naroa@28222
    42
import org.openbravo.model.ad.system.Client;
naroa@28222
    43
import org.openbravo.model.ad.ui.Tab;
naroa@28222
    44
import org.openbravo.model.common.enterprise.Organization;
naroa@28222
    45
import org.openbravo.test.base.OBBaseTest;
naroa@28222
    46
naroa@28222
    47
/**
naroa@28222
    48
 * Test cases with different combinations of grid configurations at tab level with different
naroa@28222
    49
 * combinations of sequence numbers.
naroa@28222
    50
 * 
naroa@28222
    51
 * @author NaroaIriarte
naroa@28222
    52
 *
naroa@28222
    53
 */
naroa@28222
    54
public class GCSequenceNumberTests extends OBBaseTest {
naroa@28222
    55
  private static final String CLIENT_FOR_GC_SYSTEM_FIELD_TAB = "0";
naroa@28222
    56
  private static final String ZERO_ORGANIZATION = "0";
naroa@28222
    57
  private static final String BUSINESS_PARTNER_TAB_ID = "220";
naroa@28222
    58
  private static final String PRODUCT_TAB_ID = "180";
naroa@28222
    59
  private static final String CAN_FILTER_FALSE = "\"canFilter\":false";
naroa@28222
    60
  private static final String CAN_FILTER_TRUE = "\"canFilter\":true";
naroa@28222
    61
  private static final String YES = "Y";
naroa@28222
    62
  private static final String NO = "N";
naroa@28222
    63
  private static final long LOW_SEQUENCE_NUMBER = 10;
naroa@28222
    64
  private static final long HIGH_SEQUENCE_NUMBER = 20;
stefan@33779
    65
  private static final List<String> CORE_DEFAULT_GRID_CONFIGS = Arrays.asList(
stefan@33779
    66
      "4701BC23719C41FAA422305FCDBBAF85", "FDA9AFD8D7504E18A220EFC01F5D28D3");
stefan@33779
    67
stefan@33779
    68
  /**
stefan@33779
    69
   * Execute these test cases only if there is no custom grid config as it could make unstable
stefan@33779
    70
   * results
stefan@33779
    71
   */
stefan@33779
    72
  @Before
stefan@33779
    73
  public void shouldExecuteOnlyIfThereIsNoGridConfig() {
stefan@33779
    74
    OBContext.setAdminMode(false);
stefan@33779
    75
    try {
stefan@33779
    76
      OBCriteria<GCSystem> systemGridConfig = OBDal.getInstance().createCriteria(GCSystem.class);
stefan@33779
    77
      OBCriteria<GCTab> tabGridConfig = OBDal.getInstance().createCriteria(GCTab.class);
stefan@33779
    78
      tabGridConfig.add(not(in(GCTab.PROPERTY_ID, CORE_DEFAULT_GRID_CONFIGS)));
stefan@33779
    79
      assumeThat("Number of custom grid configs", systemGridConfig.count() + tabGridConfig.count(),
stefan@33779
    80
          is(0));
stefan@33779
    81
    } finally {
stefan@33779
    82
      OBContext.restorePreviousMode();
stefan@33779
    83
    }
stefan@33779
    84
  }
naroa@28222
    85
naroa@28222
    86
  /**
naroa@28222
    87
   * If different sequence number is set for the same tab, the expected behavior is that the
naroa@28222
    88
   * configuration set in the record with the highest sequence number be applied.
naroa@28222
    89
   */
naroa@28222
    90
  @Test
naroa@28222
    91
  public void sameTabDifferentSequenceNumber() throws Exception {
naroa@28222
    92
    GCTab gctabFirstRecord = null;
naroa@28222
    93
    GCTab gctabSecondRecord = null;
naroa@28222
    94
    OBContext.setAdminMode(false);
naroa@28222
    95
    try {
naroa@28222
    96
      gctabFirstRecord = OBProvider.getInstance().get(GCTab.class);
naroa@28222
    97
      gctabSecondRecord = OBProvider.getInstance().get(GCTab.class);
naroa@28222
    98
      gctabFirstRecord.setClient(OBDal.getInstance().get(Client.class,
naroa@28222
    99
          CLIENT_FOR_GC_SYSTEM_FIELD_TAB));
naroa@28222
   100
      gctabFirstRecord.setOrganization(OBDal.getInstance().get(Organization.class,
naroa@28222
   101
          ZERO_ORGANIZATION));
naroa@28222
   102
      gctabFirstRecord.setFilterable(YES);
naroa@28222
   103
      gctabFirstRecord.setSeqno(HIGH_SEQUENCE_NUMBER);
naroa@28222
   104
      Tab firstTab = OBDal.getInstance().get(Tab.class, BUSINESS_PARTNER_TAB_ID);
naroa@28222
   105
      firstTab.getOBUIAPPGCTabList().add(gctabFirstRecord);
naroa@28222
   106
      OBDal.getInstance().save(gctabFirstRecord);
naroa@28222
   107
naroa@28222
   108
      gctabSecondRecord.setClient(OBDal.getInstance().get(Client.class,
naroa@28222
   109
          CLIENT_FOR_GC_SYSTEM_FIELD_TAB));
naroa@28222
   110
      gctabSecondRecord.setOrganization(OBDal.getInstance().get(Organization.class,
naroa@28222
   111
          ZERO_ORGANIZATION));
naroa@28222
   112
      gctabSecondRecord.setFilterable(NO);
naroa@28222
   113
      gctabSecondRecord.setSeqno(LOW_SEQUENCE_NUMBER);
naroa@28222
   114
      firstTab.getOBUIAPPGCTabList().add(gctabSecondRecord);
naroa@28222
   115
      OBDal.getInstance().save(gctabSecondRecord);
naroa@28222
   116
naroa@28222
   117
      JSONObject tabConfig = OBViewUtil.getGridConfigurationSettings(OBDal.getInstance().get(
naroa@28222
   118
          Tab.class, BUSINESS_PARTNER_TAB_ID));
naroa@28222
   119
naroa@28222
   120
      assertThat("Grid configuration in business partner tab with filtering enabled:",
naroa@28222
   121
          tabConfig.toString(), containsString(CAN_FILTER_TRUE));
naroa@28222
   122
naroa@28222
   123
    } finally {
naroa@28222
   124
      OBDal.getInstance().rollbackAndClose();
naroa@28222
   125
      OBContext.restorePreviousMode();
naroa@28222
   126
    }
naroa@28222
   127
  }
naroa@28222
   128
naroa@28222
   129
  /**
naroa@28222
   130
   * If the same sequence number is set for different tabs, the expected behavior is that set
naroa@28222
   131
   * configurations for these tabs be applied.
naroa@28222
   132
   */
naroa@28222
   133
  @Test
naroa@28222
   134
  public void differentTabSameSequenceNumber() throws Exception {
naroa@28222
   135
    GCTab gctabFirstRecord = null;
naroa@28222
   136
    GCTab gctabSecondRecord = null;
naroa@28222
   137
    OBContext.setAdminMode(false);
naroa@28222
   138
    try {
naroa@28222
   139
      gctabFirstRecord = OBProvider.getInstance().get(GCTab.class);
naroa@28222
   140
      gctabSecondRecord = OBProvider.getInstance().get(GCTab.class);
naroa@28222
   141
      gctabFirstRecord.setClient(OBDal.getInstance().get(Client.class,
naroa@28222
   142
          CLIENT_FOR_GC_SYSTEM_FIELD_TAB));
naroa@28222
   143
      gctabFirstRecord.setOrganization(OBDal.getInstance().get(Organization.class,
naroa@28222
   144
          ZERO_ORGANIZATION));
naroa@28222
   145
      gctabFirstRecord.setFilterable(YES);
naroa@28222
   146
      gctabFirstRecord.setSeqno(LOW_SEQUENCE_NUMBER);
naroa@28222
   147
      Tab firstTab = OBDal.getInstance().get(Tab.class, BUSINESS_PARTNER_TAB_ID);
naroa@28222
   148
      firstTab.getOBUIAPPGCTabList().add(gctabFirstRecord);
naroa@28222
   149
      OBDal.getInstance().save(gctabFirstRecord);
naroa@28222
   150
naroa@28222
   151
      gctabSecondRecord.setClient(OBDal.getInstance().get(Client.class,
naroa@28222
   152
          CLIENT_FOR_GC_SYSTEM_FIELD_TAB));
naroa@28222
   153
      gctabSecondRecord.setOrganization(OBDal.getInstance().get(Organization.class,
naroa@28222
   154
          ZERO_ORGANIZATION));
naroa@28222
   155
      gctabSecondRecord.setFilterable(NO);
naroa@28222
   156
      gctabSecondRecord.setSeqno(LOW_SEQUENCE_NUMBER);
naroa@28222
   157
      Tab secondTab = OBDal.getInstance().get(Tab.class, PRODUCT_TAB_ID);
naroa@28222
   158
      secondTab.getOBUIAPPGCTabList().add(gctabSecondRecord);
naroa@28222
   159
      OBDal.getInstance().save(gctabSecondRecord);
naroa@28222
   160
naroa@28222
   161
      JSONObject bpTabConfig = OBViewUtil.getGridConfigurationSettings(OBDal.getInstance().get(
naroa@28222
   162
          Tab.class, BUSINESS_PARTNER_TAB_ID));
naroa@28222
   163
      JSONObject productTabConfig = OBViewUtil.getGridConfigurationSettings(OBDal.getInstance()
naroa@28222
   164
          .get(Tab.class, PRODUCT_TAB_ID));
naroa@28222
   165
naroa@28222
   166
      assertThat("Grid configuration in business partner tab with filtering enabled:",
naroa@28222
   167
          bpTabConfig.toString(), containsString(CAN_FILTER_TRUE));
naroa@28222
   168
      assertThat("Grid configuration in product tab with filtering disabled:",
naroa@28222
   169
          productTabConfig.toString(), containsString(CAN_FILTER_FALSE));
naroa@28222
   170
naroa@28222
   171
    } finally {
naroa@28222
   172
      OBDal.getInstance().rollbackAndClose();
naroa@28222
   173
      OBContext.restorePreviousMode();
naroa@28222
   174
    }
naroa@28222
   175
  }
naroa@28222
   176
naroa@28222
   177
  /**
naroa@28222
   178
   * If different sequence number is set for different tabs the expected result is that the set
naroa@28222
   179
   * configuration be applied for these tabs.
naroa@28222
   180
   */
naroa@28222
   181
  @Test
naroa@28222
   182
  public void differentTabDifferentSequenceNumber() throws Exception {
naroa@28222
   183
    GCTab gctabFirstRecord = null;
naroa@28222
   184
    GCTab gctabSecondRecord = null;
naroa@28222
   185
    OBContext.setAdminMode(false);
naroa@28222
   186
    try {
naroa@28222
   187
      gctabFirstRecord = OBProvider.getInstance().get(GCTab.class);
naroa@28222
   188
      gctabSecondRecord = OBProvider.getInstance().get(GCTab.class);
naroa@28222
   189
      gctabFirstRecord.setClient(OBDal.getInstance().get(Client.class,
naroa@28222
   190
          CLIENT_FOR_GC_SYSTEM_FIELD_TAB));
naroa@28222
   191
      gctabFirstRecord.setOrganization(OBDal.getInstance().get(Organization.class,
naroa@28222
   192
          ZERO_ORGANIZATION));
naroa@28222
   193
      gctabFirstRecord.setFilterable(YES);
naroa@28222
   194
      gctabFirstRecord.setSeqno(HIGH_SEQUENCE_NUMBER);
naroa@28222
   195
      Tab firstTab = OBDal.getInstance().get(Tab.class, BUSINESS_PARTNER_TAB_ID);
naroa@28222
   196
      firstTab.getOBUIAPPGCTabList().add(gctabFirstRecord);
naroa@28222
   197
      OBDal.getInstance().save(gctabFirstRecord);
naroa@28222
   198
naroa@28222
   199
      gctabSecondRecord.setClient(OBDal.getInstance().get(Client.class,
naroa@28222
   200
          CLIENT_FOR_GC_SYSTEM_FIELD_TAB));
naroa@28222
   201
      gctabSecondRecord.setOrganization(OBDal.getInstance().get(Organization.class,
naroa@28222
   202
          ZERO_ORGANIZATION));
naroa@28222
   203
      gctabSecondRecord.setFilterable(NO);
naroa@28222
   204
      gctabSecondRecord.setSeqno(LOW_SEQUENCE_NUMBER);
naroa@28222
   205
      Tab secondTab = OBDal.getInstance().get(Tab.class, PRODUCT_TAB_ID);
naroa@28222
   206
      secondTab.getOBUIAPPGCTabList().add(gctabSecondRecord);
naroa@28222
   207
      OBDal.getInstance().save(gctabSecondRecord);
naroa@28222
   208
naroa@28222
   209
      JSONObject bpTabConfig = OBViewUtil.getGridConfigurationSettings(OBDal.getInstance().get(
naroa@28222
   210
          Tab.class, BUSINESS_PARTNER_TAB_ID));
naroa@28222
   211
      JSONObject productTabConfig = OBViewUtil.getGridConfigurationSettings(OBDal.getInstance()
naroa@28222
   212
          .get(Tab.class, PRODUCT_TAB_ID));
naroa@28222
   213
naroa@28222
   214
      assertThat("Grid configuration in business partner tab with filtering enabled:",
naroa@28222
   215
          bpTabConfig.toString(), containsString(CAN_FILTER_TRUE));
naroa@28222
   216
      assertThat("Grid configuration in product tab level with filtering disabled:",
naroa@28222
   217
          productTabConfig.toString(), containsString(CAN_FILTER_FALSE));
naroa@28222
   218
naroa@28222
   219
    } finally {
naroa@28222
   220
      OBDal.getInstance().rollbackAndClose();
naroa@28222
   221
      OBContext.restorePreviousMode();
naroa@28222
   222
    }
naroa@28222
   223
  }
naroa@28222
   224
}