Skip to content

NPE in FieldDeserializer.deserialize when loading list of case fields #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexeyOnGitHub opened this issue Jul 17, 2015 · 4 comments

Comments

@alexeyOnGitHub
Copy link

using testrail-api-java-client 1.0.0 from Maven Central.

TestRail v4.1.0.3294

code:

    final List<CaseField> customCaseFields = client.caseFields().list().execute();

exception:

java.lang.NullPointerException
at com.codepine.api.testrail.internal.FieldModule$FieldDeserializer.deserialize(FieldModule.java:65)
at com.codepine.api.testrail.internal.FieldModule$FieldDeserializer.deserialize(FieldModule.java:51)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:227)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:204)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:23)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2993)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2151)
at com.codepine.api.testrail.Request.execute(Request.java:164)
at org.jenkinsci.plugin.trp.TestRailClient.getCases(TestRailClient.java:156)


I see field.getConfigs() returns NULL in FieldModule.FieldDeserializer
field processed is:

Field(id=1, label=Preconditions, name=preconds, description=The preconditions of this test case. Reference other test cases with [C#] (e.g. [C17])., systemName=custom_preconds, typeId=3, type=TEXT, displayOrder=1, configs=null)

maybe field.getConfigs() can be modified to return an empty collection rather than Null when no configs are found?

@alexeyOnGitHub
Copy link
Author

workaround until this is fixed: loading fields directly from REST API:

public Collection<Case> getCases(int projectId, int suiteId) throws IOException {
    final String body = get("index.php?/api/v2/get_cases/" + projectId + "&suite_id=" + suiteId).getBody();
    final JSONArray array = new JSONArray(body);
    final Collection<Case> cases = new ArrayList<>(array.length());
    for (int i = 0; i < array.length(); i++) {
        final JSONObject json = array.getJSONObject(i);
        cases.add(createCaseFromJson(json));
    }
    return cases;
}
private static final String CUSTOM_FIELD_FOR_FULL_TEST_NAME = "custom_automated_test_name";

private static Case createCaseFromJson(JSONObject json) {
    final String title = json.getString("title");
    final int id = json.getInt("id");
    final String fullTestName = json.getString(CUSTOM_FIELD_FOR_FULL_TEST_NAME);
    final Map<String, Object> fields = new HashMap<>(1);
    fields.put(CUSTOM_FIELD_FOR_FULL_TEST_NAME, fullTestName);
    return new Case().setId(id).setTitle(title).setCustomFields(fields);
}

@kunal546
Copy link
Contributor

I tested this on my end and it does not seem to be an issue even when I remove all custom fields from TestRail. TestRail server also returns an empty JSON array for the same which gets correctly deserialized.

In your case, it seems like the server response is 200 OK but the body is something else (may not even be reaching TestRail server). Did you get any other APIs working with the same TestRail configuration (end point and credentials)?

@alexeyOnGitHub
Copy link
Author

do you have same version of TestRail?
our networking configuration is screwed up indeed , but I use my laptop as a "baseline": all integration tests work when I run them on my laptop - except for this request to get case fields.
maybe it's some weird custom field created in our TestRail instance that does not get those "configs" - can they be ignored if not found in response?
maybe that field is optional in our version of TestRail?..

here is the field that is loaded from the server (copied from debugger) -

Field(id=1, label=Preconditions, name=preconds, description=The preconditions of this test case. Reference other test cases with [C#] (e.g. [C17])., systemName=custom_preconds, typeId=3, type=TEXT, displayOrder=1, configs=null)

@kunal546
Copy link
Contributor

Closing since it is related to #3.

davidbrazilparker pushed a commit to chapeco/testrail-api-java-client that referenced this issue Aug 15, 2018
# This is the 1st commit message:

# This is a combination of 8 commits.
# This is the 1st commit message:

Added new fields to Milestone available since TestRail 5.3; Fixed configuration of Lombok; Added Template model

# This is the commit message codepine#2:

Added Nexus distributionManagement to pom

# This is the commit message codepine#3:

Changed groupID

# This is the commit message codepine#4:

Fixed configuration of Lombok; Added Template model

# This is the commit message codepine#5:

Added deserialization of test Templates json file, updated Template class to deserialize is_default correctly

# This is the commit message codepine#6:

Added new fields to Milestone available since TestRail 5.3

# This is the commit message codepine#7:

Updated pom with release information for forked version of project

# This is the commit message codepine#8:

Update issue templates
# This is the commit message codepine#2:

Removed log4j dependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants