1

I want to test a API (Post method). I have to test this API by changing all the available parameters. For EG in Test case one I only change the user Name, in Test case 2 I change only the password and henceforth.

My API looks something like below :

{
          "schemas": [
                         "urn:ietf:params:scim:schemas:core:2.0:User",
                         "urn:ibm:params:scim:schemas:extension:bean:agc:2.0:User"
          ],
          "name": {
          },
          "userName": "GROUPTEST12134",
          "password": "Asdfg12@sdd",
          "emails": [{
                         "value": "steve.hok123@awe.com"
          }],
          "phoneNumbers": [{
                        "value": "70422330098"
          }],

          "urn:ibm:params:scim:schemas:extension:bean:agc:2.0:User": {

          }
          }

I am successfully able to test it by below method :

    String urlParameters = "{\"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\",\"urn:ibm:params:scim:schemas:extension:bean:agc:2.0:User\"],\"name\": {},\"userName\": \"GROUPTEST12138\",\"password\": \"Asdfg12@sdd\",\"emails\": [{\"value\": \"steve.hok1234@awe.com\"}],\"phoneNumbers\": [{\"value\": \"\"}],\"urn:ibm:params:scim:schemas:extension:bean:agc:2.0:User\": {}}";

    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    con.setDoOutput(true);
    con.setRequestMethod("PUT");
    con.setRequestProperty("Content-Type", "application/scim+json");
    con.setRequestProperty("Accept", "application/scim+json");
    con.setRequestProperty("realm", "Ideas");
    con.setRequestProperty("Authorization", "Bearer " + BearerToken);

But I am looking for some way where I don't have to manage this urlParameters.

Can you please some ideas how this can be achieved?

Edward
  • 6,964
  • 2
  • 29
  • 55
Ankit Garg
  • 21
  • 3
  • "But I am looking out at some way where I dont have to manage this urlParameters" what do you mean? Could you clarify where you are "managing" the url parameters in your example that you'd like to avoid? – Alexey R. Jul 12 '18 at 12:12

1 Answers1

0

3 possibilities:

In code- GSON library is quite nice. You might look into it.

In files- I've seen JSON that's commonly used maintained in separate files. Not really my preference, but it has its place for highly re-used JSON, or if you have a lot of boilerplate.

emails- you might want to remove steve's email from your JSON and scrub it from PII in the future.

Zach Folwick
  • 893
  • 10
  • 18