Project:
View Issue Details[ Jump to Notes ] | [ Issue History ] [ Print ] | |||||||||||
ID | ||||||||||||
0028945 | ||||||||||||
Type | Category | Severity | Reproducibility | Date Submitted | Last Update | |||||||
feature request | [Openbravo ERP] A. Platform | trivial | have not tried | 2015-02-15 17:34 | 2022-02-01 08:08 | |||||||
Reporter | inigosanchez | View Status | public | |||||||||
Assigned To | Triage Platform Base | |||||||||||
Priority | low | Resolution | open | Fixed in Version | ||||||||
Status | new | Fix in branch | Fixed in SCM revision | |||||||||
Projection | none | ETA | none | Target Version | ||||||||
OS | Any | Database | Any | Java version | ||||||||
OS Version | Database version | Ant version | ||||||||||
Product Version | SCM revision | |||||||||||
Review Assigned To | ||||||||||||
Web browser | ||||||||||||
Modules | Core | |||||||||||
Regression level | ||||||||||||
Regression date | ||||||||||||
Regression introduced in release | ||||||||||||
Regression introduced by commit | ||||||||||||
Triggers an Emergency Pack | No | |||||||||||
Summary | 0028945: Implement matchers for JSON objects | |||||||||||
Description | Implement matchers in JUnit to test and verify JSON objects. | |||||||||||
Steps To Reproduce | - | |||||||||||
Proposed Solution | See an example: JSONObject resp = executeDSRequest(params); assertThat(resp, hasKeyValue("data", hasLength(greaterThan(1)))); assertThat( resp, hasKeyValue( "data", arrayContainsElement(hasKeyValue("property", equalTo("salesOrder._ComputedColumns.invoiceStatus"))))); assertThat(resp, hasKeyValue("data[0].property", equalTo("salesOrder._computedColumns"))); See a first approach in attachment diff file.[1] | |||||||||||
Tags | No tags attached. | |||||||||||
Attached Files | matchers.diff [^] (24,742 bytes) 2015-02-15 17:34 [Show Content] [Hide Content]diff -r 74d15eec44db src-test/src/org/openbravo/test/base/matchers/JSONMatchers.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-test/src/org/openbravo/test/base/matchers/JSONMatchers.java Thu Aug 14 17:18:14 2014 +0200 @@ -0,0 +1,239 @@ +package org.openbravo.test.base.matchers; + +import java.util.Iterator; + +import org.codehaus.jettison.json.JSONArray; +import org.codehaus.jettison.json.JSONException; +import org.codehaus.jettison.json.JSONObject; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +class JSONMatchers { + static class HasJSONPath extends TypeSafeMatcher<JSONObject> { + private Matcher<String> matcher; + private String path; + private String errorMsg = ""; + private String foundPath = ""; + private boolean matchExecuted; + private Object jsonProperty; + + public HasJSONPath(Matcher<String> matcher) { + this.matcher = matcher; + } + + public HasJSONPath(String path) { + this.path = path; + } + + @Override + public void describeTo(Description description) { + if (matcher != null) { + description.appendText("A JSONObject with a key that is "); + matcher.describeTo(description); + } else { + description.appendText("A JSONObject with a path that is <" + this.path + ">"); + } + } + + @Override + protected void describeMismatchSafely(JSONObject item, Description mismatchDescription) { + if (!matchExecuted) { + matchesSafely(item); + } + mismatchDescription.appendText("no path found.\n"); + + if (matcher == null) { + if (!foundPath.isEmpty()) { + mismatchDescription.appendText("\npartial path found <" + foundPath + "> "); + } + + mismatchDescription.appendText("\n" + errorMsg); + } + mismatchDescription.appendText("\n complete JSON "); + super.describeMismatchSafely(item, mismatchDescription); + + } + + @Override + protected boolean matchesSafely(JSONObject jsonObject) { + matchExecuted = true; + return matcher != null ? matchUsingMatcher(jsonObject) : matchUsingPath(jsonObject); + } + + private boolean matchUsingPath(JSONObject jsonObject) { + String elements[] = path.split("\\."); + JSONObject currentObject = jsonObject; + + for (int i = 0; i < elements.length; i++) { + String key = elements[i]; + boolean isArray = key.contains("[") && key.contains("]"); + int arrayPos = 0; + if (isArray) { + arrayPos = Integer.parseInt(key.substring(key.indexOf("[") + 1, key.length() - 1)); + key = key.substring(0, key.indexOf("[")); + } + + if (!currentObject.has(key)) { + return false; + } else { + foundPath += (foundPath.isEmpty() ? "" : ".") + key; + try { + Object nextObj = currentObject.get(key); + if (isArray) { + if (nextObj instanceof JSONArray) { + JSONArray arr = (JSONArray) nextObj; + if (arrayPos < arr.length()) { + nextObj = ((JSONArray) nextObj).get(arrayPos); + } else { + errorMsg = "looking for array position <" + arrayPos + + "> but the array has a length of <" + arr.length() + ">"; + return false; + } + } else { + errorMsg += "<" + key + "> element should be a JSONArray, but it is a " + + nextObj.getClass().getSimpleName(); + return false; + } + } + if (i < elements.length - 1) { + if (nextObj instanceof JSONObject) { + currentObject = (JSONObject) nextObj; + } else { + errorMsg += "<" + key + "> element should be a JSONObject, but it is a " + + nextObj.getClass().getSimpleName(); + return false; + } + } else { + jsonProperty = nextObj; + } + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return false; + } + } + } + + return true; + } + + private boolean matchUsingMatcher(JSONObject jsonObject) { + @SuppressWarnings("unchecked") + Iterator<String> it = jsonObject.keys(); + while (it.hasNext()) { + String key = it.next(); + if (this.matcher.matches(key)) { + return true; + } + } + return false; + } + } + + static class HasKeyValue extends TypeSafeMatcher<JSONObject> { + private Matcher<String> matcherKey; + private Matcher<?> matcherValue; + private String path; + private HasJSONPath pathMatcher; + + public HasKeyValue(Matcher<String> matcherKey, Matcher<? extends Object> matcherValue) { + this.matcherKey = matcherKey; + this.matcherValue = matcherValue; + } + + public HasKeyValue(String path, Matcher<? extends Object> matcherValue) { + this.path = path; + this.matcherValue = matcherValue; + } + + @Override + public void describeTo(Description description) { + if (matcherKey != null) { + description.appendText("a JSONObject with a key that is "); + matcherKey.describeTo(description); + } else { + description.appendText("a JSONObject with a path that is <" + this.path + "> "); + } + + description.appendText(" which value is "); + matcherValue.describeTo(description); + } + + @Override + protected void describeMismatchSafely(JSONObject item, Description mismatchDescription) { + if (!hasCorrectPath(item)) { + pathMatcher.describeMismatch(item, mismatchDescription); + } else { + mismatchDescription.appendText("value was <" + pathMatcher.jsonProperty + ">"); + } + } + + @Override + protected boolean matchesSafely(JSONObject jsonObject) { + if (!hasCorrectPath(jsonObject)) { + return false; + } + + return this.matcherValue.matches(pathMatcher.jsonProperty); + } + + private boolean hasCorrectPath(JSONObject jsonObject) { + if (matcherKey != null) { + pathMatcher = new HasJSONPath(matcherKey); + } else { + pathMatcher = new HasJSONPath(path); + } + return pathMatcher.matches(jsonObject); + } + } + + static class HasLength extends TypeSafeMatcher<JSONArray> { + private Matcher<Integer> matcher; + + @Override + public void describeTo(Description description) { + description.appendText("a JSONArray with a length that is "); + matcher.describeTo(description); + } + + @Override + protected boolean matchesSafely(JSONArray item) { + return matcher.matches(item.length()); + } + + public HasLength(Matcher<Integer> matcher) { + this.matcher = matcher; + } + } + + static class ArrayContains extends TypeSafeMatcher<JSONArray> { + private Matcher<? extends Object> matcher; + + @Override + public void describeTo(Description description) { + description.appendText("a JSONArray with an element that is "); + matcher.describeTo(description); + } + + @Override + protected boolean matchesSafely(JSONArray item) { + for (int i = 0; i < item.length(); i++) { + try { + if (matcher.matches(item.get(i))) { + return true; + } + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return false; + } + } + return false; + } + + public ArrayContains(Matcher<? extends Object> matcher) { + this.matcher = matcher; + } + } +} diff -r 74d15eec44db src-test/src/org/openbravo/test/base/matchers/OBMatchers.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-test/src/org/openbravo/test/base/matchers/OBMatchers.java Thu Aug 14 17:18:14 2014 +0200 @@ -0,0 +1,50 @@ +package org.openbravo.test.base.matchers; + +import static org.hamcrest.Matchers.equalTo; + +import org.codehaus.jettison.json.JSONArray; +import org.codehaus.jettison.json.JSONObject; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; +import org.openbravo.test.base.matchers.JSONMatchers.ArrayContains; +import org.openbravo.test.base.matchers.JSONMatchers.HasJSONPath; +import org.openbravo.test.base.matchers.JSONMatchers.HasKeyValue; +import org.openbravo.test.base.matchers.JSONMatchers.HasLength; + +public class OBMatchers { + // JSON Matchers + @Factory + public static Matcher<JSONObject> hasPath(Matcher<String> matcher) { + return new HasJSONPath(matcher); + } + + @Factory + public static Matcher<JSONObject> hasPath(String path) { + return new HasJSONPath(path); + } + + @Factory + public static Matcher<JSONObject> hasKeyValue(Matcher<String> matcherKey, Matcher<?> matcherValue) { + return new HasKeyValue(matcherKey, matcherValue); + } + + @Factory + public static Matcher<JSONObject> hasKeyValue(String path, Matcher<? extends Object> matcherValue) { + return new HasKeyValue(path, matcherValue); + } + + @Factory + public static Matcher<JSONArray> hasLength(Matcher<Integer> matcher) { + return new HasLength(matcher); + } + + @Factory + public static Matcher<JSONArray> arrayContainsElement(Matcher<? extends Object> matcher) { + return new ArrayContains(matcher); + } + + @Factory + public static Matcher<JSONArray> hasLength(int length) { + return new HasLength(equalTo(length)); + } +} diff -r 74d15eec44db src-test/src/org/openbravo/test/datasource/FICTest.java --- a/src-test/src/org/openbravo/test/datasource/FICTest.java Thu Aug 14 12:09:54 2014 +0200 +++ b/src-test/src/org/openbravo/test/datasource/FICTest.java Thu Aug 14 17:18:14 2014 +0200 @@ -19,12 +19,14 @@ package org.openbravo.test.datasource; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.Matchers.isEmptyOrNullString; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertThat; +import static org.openbravo.test.base.matchers.OBMatchers.hasKeyValue; import java.util.HashMap; import java.util.Map; -import org.apache.commons.lang.StringUtils; import org.codehaus.jettison.json.JSONObject; import org.junit.Test; @@ -49,13 +51,10 @@ params.put("_action", "org.openbravo.client.application.window.FormInitializationComponent"); params.put("TAB_ID", "186"); // Sales Order params.put("PARENT_ID", null); - String response = doRequest("/org.openbravo.client.kernel", params, 200, "POST"); + JSONObject response = new JSONObject(doRequest("/org.openbravo.client.kernel", params, 200, + "POST")); - JSONObject auxiliaryInputs = new JSONObject(response).getJSONObject("auxiliaryInputValues"); - assertTrue("ORDERTYPE should be set", auxiliaryInputs.has("ORDERTYPE")); - - JSONObject orderType = auxiliaryInputs.getJSONObject("ORDERTYPE"); - assertTrue("ORDERTYPE should have value", - orderType.has("value") && StringUtils.isNotEmpty(orderType.getString("value"))); + assertThat(response, + hasKeyValue("auxiliaryInputValues.ORDERTYPE.value", not(isEmptyOrNullString()))); } } diff -r 74d15eec44db src-test/src/org/openbravo/test/datasource/ProductSelectorDataSourceTest.java --- a/src-test/src/org/openbravo/test/datasource/ProductSelectorDataSourceTest.java Thu Aug 14 12:09:54 2014 +0200 +++ b/src-test/src/org/openbravo/test/datasource/ProductSelectorDataSourceTest.java Thu Aug 14 17:18:14 2014 +0200 @@ -19,8 +19,10 @@ package org.openbravo.test.datasource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; +import static org.openbravo.test.base.matchers.OBMatchers.hasLength; +import static org.openbravo.test.base.matchers.OBMatchers.hasPath; import java.util.HashMap; import java.util.Map; @@ -43,8 +45,7 @@ @Test public void testWarehouseFKDropDown() throws Exception { JSONObject resp = performRequest(false); - - assertEquals("Data should have 4 warehouses", 4, resp.getJSONArray("data").length()); + assertThat(resp.getJSONArray("data"), hasLength(equalTo(4))); } /** @@ -53,7 +54,7 @@ @Test public void testWarehouseFKDropDownFilter() throws Exception { JSONObject resp = performRequest(true); - assertEquals("Data should have 2 warehouses", 2, resp.getJSONArray("data").length()); + assertThat(resp.getJSONArray("data"), hasLength(equalTo(2))); } private JSONObject performRequest(boolean addFilter) throws Exception { @@ -85,12 +86,10 @@ params.put("criteria", criteria.toString()); } - String response = doRequest("/org.openbravo.service.datasource/ProductStockView", params, 200, - "POST"); - JSONObject resp = new JSONObject(response).getJSONObject("response"); - - assertTrue("Response should have data", resp.has("data")); - return resp; + JSONObject response = new JSONObject(doRequest( + "/org.openbravo.service.datasource/ProductStockView", params, 200, "POST")); + assertThat(response, hasPath("response.data")); + return response; } } diff -r 74d15eec44db src-test/src/org/openbravo/test/datasource/SelectorFieldPropertySelectorDSTest.java --- a/src-test/src/org/openbravo/test/datasource/SelectorFieldPropertySelectorDSTest.java Thu Aug 14 12:09:54 2014 +0200 +++ b/src-test/src/org/openbravo/test/datasource/SelectorFieldPropertySelectorDSTest.java Thu Aug 14 17:18:14 2014 +0200 @@ -19,9 +19,13 @@ package org.openbravo.test.datasource; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.openbravo.test.base.matchers.OBMatchers.arrayContainsElement; +import static org.openbravo.test.base.matchers.OBMatchers.hasKeyValue; +import static org.openbravo.test.base.matchers.OBMatchers.hasLength; import java.util.HashMap; import java.util.Map; @@ -77,8 +81,8 @@ JSONArray data = resp.getJSONArray("data"); - assertEquals("data length", data.length(), 1); - assertEquals("totalRows", resp.getInt("totalRows"), 1); + assertThat(data, hasLength(1)); + assertThat(resp, hasKeyValue("totalRows", equalTo(1))); } /** @@ -94,11 +98,9 @@ JSONObject resp = executeDSRequest(params); - JSONArray data = resp.getJSONArray("data"); - - assertEquals("data length", 1, data.length()); - assertEquals("totalRows", 1, resp.getInt("totalRows")); - assertEquals("salesOrder._computedColumns", data.getJSONObject(0).getString("property")); + assertThat(resp, hasKeyValue("data", hasLength(equalTo(1)))); + assertThat(resp, hasKeyValue("totalRows", equalTo(1))); + assertThat(resp, hasKeyValue("data[0].property", equalTo("salesOrder._computedColumns"))); } /** @@ -114,20 +116,13 @@ JSONObject resp = executeDSRequest(params); - JSONArray data = resp.getJSONArray("data"); - - assertTrue("data should contain all computed columns", data.length() > 1); - checkJSONcontains(data, "salesOrder._ComputedColumns.invoiceStatus"); - } - - private void checkJSONcontains(JSONArray data, String value) throws JSONException { - for (int i = 0; i < data.length(); i++) { - if (value.equals(data.getJSONObject(i).getString("property"))) { - return; - } - } - fail("Expecting value <" + value + "> in array but found:" + data.toString(1)); - + assertThat(resp, hasKeyValue("data", hasLength(greaterThan(1)))); + assertThat( + resp, + hasKeyValue( + "data", + arrayContainsElement(hasKeyValue("property", + equalTo("salesOrder._ComputedColumns.invoiceStatus"))))); } private Map<? extends String, ? extends String> getFilter(String value) throws JSONException { diff -r 74d15eec44db src-test/src/org/openbravo/test/datasource/TestComboDatasource.java --- a/src-test/src/org/openbravo/test/datasource/TestComboDatasource.java Thu Aug 14 12:09:54 2014 +0200 +++ b/src-test/src/org/openbravo/test/datasource/TestComboDatasource.java Thu Aug 14 17:18:14 2014 +0200 @@ -23,11 +23,13 @@ * * @author Shankar Balachandran */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.openbravo.test.base.matchers.OBMatchers.hasLength; import java.util.HashMap; import java.util.Map; @@ -36,12 +38,11 @@ import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.junit.Test; -import org.openbravo.dal.core.OBContext; import org.openbravo.service.json.JsonConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class TestComboDatasource extends BaseDataSourceTestDal { +public class TestComboDatasource extends BaseDataSourceTestNoDal { private static final Logger log = LoggerFactory.getLogger(TestComboDatasource.class); @@ -55,7 +56,6 @@ */ @Test public void testFetchWithoutLimitParameters() throws Exception { - setOBContext("100"); // Using values of window dropdown in preference window Map<String, String> params = new HashMap<String, String>(); params.put("fieldId", "876"); @@ -64,8 +64,8 @@ String response = doRequest("/org.openbravo.service.datasource/ComboTableDatasourceService", params, 200, "POST"); JSONObject jsonResponse = new JSONObject(response); - assertFalse(getStatus(jsonResponse).equals( - String.valueOf(JsonConstants.RPCREQUEST_STATUS_SUCCESS))); + + assertThat(getStatus(jsonResponse), is(not(JsonConstants.RPCREQUEST_STATUS_SUCCESS))); } /** @@ -78,7 +78,6 @@ */ @Test public void testFetchWithLargeData() throws Exception { - // setContext("100"); // Using values of window dropdown in preference window Map<String, String> params = new HashMap<String, String>(); params.put("fieldId", "876"); @@ -89,8 +88,8 @@ String response = doRequest("/org.openbravo.service.datasource/ComboTableDatasourceService", params, 200, "POST"); JSONObject jsonResponse = new JSONObject(response); - assertFalse(getStatus(jsonResponse).equals( - String.valueOf(JsonConstants.RPCREQUEST_STATUS_SUCCESS))); + + assertThat(getStatus(jsonResponse), is(not(JsonConstants.RPCREQUEST_STATUS_SUCCESS))); } /** @@ -100,7 +99,6 @@ */ @Test public void testPaginatedFetch() throws Exception { - setOBContext("100"); // Using values of window dropdown in preference window Map<String, String> params = new HashMap<String, String>(); params.put("fieldId", "876"); @@ -110,9 +108,9 @@ JSONObject jsonResponse = requestCombo(params); JSONArray data = getData(jsonResponse); - assertTrue(getStatus(jsonResponse).equals( - String.valueOf(JsonConstants.RPCREQUEST_STATUS_SUCCESS))); - assertEquals("paginated combo number of records", 75, data.length()); + + assertThat(getStatus(jsonResponse), is(JsonConstants.RPCREQUEST_STATUS_SUCCESS)); + assertThat("paginated combo number of records", data, hasLength(75)); } /** @@ -120,6 +118,7 @@ * * see issue #27233 */ + @Test public void testDefaultNotInFirstPage() throws Exception { String US_ID = "100"; @@ -132,16 +131,17 @@ JSONObject jsonResponse = requestCombo(params); JSONArray data = getData(jsonResponse); - assertTrue(getStatus(jsonResponse).equals( - String.valueOf(JsonConstants.RPCREQUEST_STATUS_SUCCESS))); + assertThat(getStatus(jsonResponse), is(JsonConstants.RPCREQUEST_STATUS_SUCCESS)); int totalRows = jsonResponse.getJSONObject("response").getInt("totalRows"); // 78 int endRow = jsonResponse.getJSONObject("response").getInt("endRow"); // 76 - assertTrue("more than one page shoudl be detected", totalRows > endRow + 1); + + assertThat("more than one page should be detected", totalRows, greaterThan(endRow + 1)); + String lastRowId = data.getJSONObject(data.length() - 1).getString("id"); - assertFalse( + assertThat( "selected record should not be added at the end of 1st page, because it is in a page after it", - lastRowId.equals(US_ID)); + lastRowId, is(not(US_ID))); } /** @@ -151,7 +151,6 @@ */ @Test public void testFilter() throws Exception { - setOBContext("100"); // Using values of visible at user in preference Map<String, String> params = new HashMap<String, String>(); params.put("fieldId", "927D156048246E92E040A8C0CF071D3D"); @@ -164,9 +163,9 @@ JSONObject jsonResponse = requestCombo(params); JSONArray data = getData(jsonResponse); - assertTrue(getStatus(jsonResponse).equals( - String.valueOf(JsonConstants.RPCREQUEST_STATUS_SUCCESS))); - assertEquals("number of filtered records", 3, data.length()); + + assertThat(getStatus(jsonResponse), is(JsonConstants.RPCREQUEST_STATUS_SUCCESS)); + assertThat("number of filtered records", data, hasLength(3)); } /** @@ -176,7 +175,6 @@ */ @Test public void testFilterWithPagination() throws Exception { - setOBContext("100"); // Using values of visible at user in preference Map<String, String> params = new HashMap<String, String>(); params.put("fieldId", "927D156048246E92E040A8C0CF071D3D"); @@ -189,9 +187,8 @@ JSONObject jsonResponse = requestCombo(params); JSONArray data = getData(jsonResponse); - assertTrue(getStatus(jsonResponse).equals( - String.valueOf(JsonConstants.RPCREQUEST_STATUS_SUCCESS))); - assertEquals("number of filtered records", 2, data.length()); + assertThat(getStatus(jsonResponse), is(JsonConstants.RPCREQUEST_STATUS_SUCCESS)); + assertThat("number of filtered records", data, hasLength(2)); } /** @@ -201,7 +198,6 @@ */ @Test public void testAccess() throws Exception { - setOBContext("100"); // Using values of window dropdown in menu Map<String, String> params = new HashMap<String, String>(); params.put("fieldId", "206"); @@ -211,8 +207,7 @@ params, 200, "POST"); JSONObject jsonResponse = new JSONObject(response); // error should be raised - assertTrue(getStatus(jsonResponse).equals( - String.valueOf(JsonConstants.RPCREQUEST_STATUS_VALIDATION_ERROR))); + assertThat(getStatus(jsonResponse), is(JsonConstants.RPCREQUEST_STATUS_VALIDATION_ERROR)); } /** @@ -222,7 +217,6 @@ */ @Test public void testAccessForFilter() throws Exception { - setOBContext("100"); // Using values of window dropdown in menu Map<String, String> params = new HashMap<String, String>(); params.put("fieldId", "206"); @@ -234,8 +228,7 @@ params, 200, "POST"); JSONObject jsonResponse = new JSONObject(response); // error should be raised - assertTrue(getStatus(jsonResponse).equals( - String.valueOf(JsonConstants.RPCREQUEST_STATUS_VALIDATION_ERROR))); + assertThat(getStatus(jsonResponse), is(JsonConstants.RPCREQUEST_STATUS_VALIDATION_ERROR)); } /** @@ -273,9 +266,8 @@ paramStr = "[" + paramStr + "]"; log.debug("Combo request:\n *params:{}\n *response:{}", paramStr, jsonResponse); } - assertTrue(getStatus(jsonResponse).equals( - String.valueOf(JsonConstants.RPCREQUEST_STATUS_SUCCESS))); - assertNotNull("Combo response shoulnd't be null", jsonResponse.toString()); + assertThat(getStatus(jsonResponse), is(JsonConstants.RPCREQUEST_STATUS_SUCCESS)); + assertThat(jsonResponse.toString(), is(not(nullValue()))); return jsonResponse; } @@ -296,12 +288,7 @@ * @return status of the json response * @throws JSONException */ - private String getStatus(JSONObject jsonResponse) throws JSONException { - return jsonResponse.getJSONObject("response").get("status").toString(); + private int getStatus(JSONObject jsonResponse) throws JSONException { + return jsonResponse.getJSONObject("response").getInt("status"); } - - private void setOBContext(String user) { - OBContext.setOBContext("100"); - } - } \ No newline at end of file | |||||||||||
Relationships [ Relation Graph ] [ Dependency Graph ] | |
Issue History | |||
Date Modified | Username | Field | Change |
2015-02-15 17:34 | inigosanchez | New Issue | |
2015-02-15 17:34 | inigosanchez | Assigned To | => alostale |
2015-02-15 17:34 | inigosanchez | File Added: matchers.diff | |
2015-02-15 17:34 | inigosanchez | Modules | => Core |
2015-02-15 17:34 | inigosanchez | Triggers an Emergency Pack | => No |
2017-04-10 14:35 | alostale | Assigned To | alostale => platform |
2022-02-01 08:08 | alostale | Assigned To | platform => Triage Platform Base |
Copyright © 2000 - 2009 MantisBT Group |