details: https://code.openbravo.com/erp/devel/pi/rev/88f469f4c231 changeset: 32522:88f469f4c231 user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Fri Jul 28 12:10:42 2017 +0200 summary: fixed 35117: unstable DataSourceWhereParameter tests
* Added more log information in case it fails * Be more precise when checking for row id (asserting on "id" property instead of on the full response details: https://code.openbravo.com/erp/devel/pi/rev/ab7a25173408 changeset: 32523:ab7a25173408 user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Mon Jul 31 08:52:55 2017 +0200 summary: related to bug 35117: fixed assertions with implicit filters diffstat: src-test/src/org/openbravo/test/datasource/DataSourceWhereParameter.java | 62 ++++----- 1 files changed, 29 insertions(+), 33 deletions(-) diffs (91 lines): diff -r 3ec690db55fe -r ab7a25173408 src-test/src/org/openbravo/test/datasource/DataSourceWhereParameter.java --- a/src-test/src/org/openbravo/test/datasource/DataSourceWhereParameter.java Mon Jul 31 09:00:49 2017 +0200 +++ b/src-test/src/org/openbravo/test/datasource/DataSourceWhereParameter.java Mon Jul 31 08:52:55 2017 +0200 @@ -175,29 +175,33 @@ @Test public void datasourceWithNoManualWhereParameter() throws Exception { - boolean isRecordPresent; - if (!datasource.onlySuccessAssert) { - if (datasource.hasImplicitFilter) { - datasource.params.put("isImplicitFilterApplied", "true"); - isRecordPresent = isRecordPresentInTheResponse(datasource.expected); - assertThat("Record present.", isRecordPresent, is(true)); - isRecordPresent = isRecordPresentInTheResponse(datasource.unexpected); - assertThat("Record not present.", isRecordPresent, is(false)); - datasource.params.put("isImplicitFilterApplied", "false"); - isRecordPresent = isRecordPresentInTheResponse(datasource.expected); - assertThat("Record present.", isRecordPresent, is(true)); - isRecordPresent = isRecordPresentInTheResponse(datasource.unexpected); - assertThat("Record present.", isRecordPresent, is(true)); + if (datasource.onlySuccessAssert) { + return; + } + String datasourceResponse; + if (datasource.hasImplicitFilter) { + datasource.params.put("isImplicitFilterApplied", "true"); + } + datasourceResponse = getDataSourceResponse(); + assertRecordInResponse(datasourceResponse, datasource.expected, true); + assertRecordInResponse(datasourceResponse, datasource.unexpected, false); - } else { - isRecordPresent = isRecordPresentInTheResponse(datasource.expected); - assertThat("Record present.", isRecordPresent, is(true)); - isRecordPresent = isRecordPresentInTheResponse(datasource.unexpected); - assertThat("Record not present", isRecordPresent, is(false)); - } + if (datasource.hasImplicitFilter) { + datasource.params.put("isImplicitFilterApplied", "false"); + + datasourceResponse = getDataSourceResponse(); + assertRecordInResponse(datasourceResponse, datasource.expected, true); + assertRecordInResponse(datasourceResponse, datasource.unexpected, true); } } + private void assertRecordInResponse(String datasourceResponse, String recordId, + boolean shouldBePresent) throws Exception { + boolean isRecordPresent = isValueInTheResponseData(recordId, datasourceResponse); + assertThat("Record [" + recordId + "] - params:" + datasource.params + + " - present in response: " + datasourceResponse, isRecordPresent, is(shouldBePresent)); + } + @Test public void datasourceWithManualWhereParameter() throws Exception { if (!datasource.onlySuccessAssert && !"DB9F062472294F12A0291A7BD203F922".equals(datasource.ds)) { @@ -223,28 +227,20 @@ is(String.valueOf(JsonConstants.RPCREQUEST_STATUS_SUCCESS))); } - private boolean isRecordPresentInTheResponse(String expectedRecord) throws Exception { - boolean isExpectedRecordPresent; - String datasourceResponse = getDataSourceResponse(); - isExpectedRecordPresent = isValueInTheResponseData(expectedRecord, datasourceResponse); - return isExpectedRecordPresent; - } - private boolean isValueInTheResponseData(String valueId, String dataSourceResponse) throws Exception { JSONObject dataSourceResponseMid = new JSONObject(); JSONArray dataSourceData = new JSONArray(); - boolean existsValue = false; JSONObject jsonResponse = new JSONObject(dataSourceResponse); dataSourceResponseMid = jsonResponse.getJSONObject("response"); dataSourceData = dataSourceResponseMid.getJSONArray("data"); - String dataSourceDataString = dataSourceData.toString(); - if (dataSourceDataString.contains(valueId)) { - existsValue = true; - } else { - existsValue = false; + for (int i = 0; i < dataSourceData.length(); i++) { + JSONObject row = dataSourceData.getJSONObject(i); + if (valueId.equals(row.getString("id"))) { + return true; + } } - return existsValue; + return false; } private String getDataSourceResponse() throws Exception { ------------------------------------------------------------------------------ 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