0

I'm getting an error in my test I've found the end point but I'm getting a null actual response I don't know why. I'm asking my data provider to provide me with the responses I'd like. I get null back. I'm not sure why. My second test the fixture id is not null. Would this be a sufficient enough test in this instance?

Json

    [
  {
    "fixtureId": "1",
    "fixtureStatus": {
      "displayed": false,
      "suspended": true
    },
    "footballFullState": {
      "homeTeam": "Dagenham & Redbridge",
      "awayTeam": "Österreich",
      "finished": false,
      "gameTimeInSeconds": 2656,
      "goals": [
        {
          "clockTime": 640,
          "confirmed": true,
          "id": 678606,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 560617,
          "teamId": "1"
        },
        {
          "clockTime": 864,
          "confirmed": true,
          "id": 164002,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 60817,
          "teamId": "2"
        },
        {
          "clockTime": 1312,
          "confirmed": true,
          "id": 267245,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 136629,
          "teamId": "1"
        },
        {
          "clockTime": 1760,
          "confirmed": true,
          "id": 758030,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 131840,
          "teamId": "2"
        }
      ],
      "period": "SECOND_HALF",
      "possibles": [],
      "corners": [],
      "redCards": [],
      "yellowCards": [],
      "startDateTime": "2018-03-20T10:49:38.655Z",
      "started": true,
      "teams": [
        {
          "association": "HOME",
          "name": "Dagenham-&-Redbridge",
          "teamId": "HOME"
        },
        {
          "association": "AWAY",
          "name": "Österreich",
          "teamId": "AWAY"
        }
      ]
    }
  },
  {
    "fixtureId": "2",
    "fixtureStatus": {
      "displayed": true,
      "suspended": false
    },
    "footballFullState": {
      "homeTeam": "Manchester United",
      "awayTeam": "Leeds United",
      "finished": false,
      "gameTimeInSeconds": 900,
      "goals": [
        {
          "clockTime": 640,
          "confirmed": true,
          "id": 678606,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 560617,
          "teamId": "1"
        },
        {
          "clockTime": 864,
          "confirmed": true,
          "id": 164002,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 60817,
          "teamId": "2"
        }
      ],
      "period": "FIRST_HALF",
      "possibles": [],
      "corners": [],
      "redCards": [],
      "yellowCards": [],
      "startDateTime": "2018-03-20T10:49:38.655Z",
      "started": true,
      "teams": [
        {
          "association": "HOME",
          "name": "Manchester-United",
          "teamId": "HOME"
        },
        {
          "association": "AWAY",
          "name": "Leeds-United",
          "teamId": "AWAY"
        }
      ]
    }
  },
  {
    "fixtureId": "3",
    "fixtureStatus": {
      "displayed": false,
      "suspended": true
    },
    "footballFullState": {
      "homeTeam": "Garforth FC",
      "awayTeam": "York FC",
      "finished": false,
      "gameTimeInSeconds": 950,
      "goals": [
        {
          "clockTime": 640,
          "confirmed": true,
          "id": 678606,
          "ownGoal": false,
          "penalty": false,
          "period": "FIRST_HALF",
          "playerId": 560617,
          "teamId": "1"
        }
      ],
      "period": "FIRST_HALF",
      "possibles": [],
      "corners": [],
      "redCards": [],
      "yellowCards": [],
      "startDateTime": "2018-03-20T10:49:38.655Z",
      "started": true,
      "teams": [
        {
          "association": "HOME",
          "name": "Garforth-FC",
          "teamId": "HOME"
        },
        {
          "association": "AWAY",
          "name": "York-FC",
          "teamId": "AWAY"
        }
      ]
    }
  }
]

Endpoint:

String endpointfixtureId = "http://localhost:3000/fixtures/{fixtureId}";

Tests:

public class test extends enablers{

@DataProvider(name = "getData")
public Object[][] getData() {
    return new Object[][]{
            {"1"},
            {"2"},
            {"3"}
    };
}

@Test(dataProvider = "getData")
public void GetUserId(String fixtureId) {
    given().log().all().and().
            pathParam("fixtureId", fixtureId).
            when().
            get(endpointfixtureId).
            then().
            assertThat().
            body(("fixtureId"), equalTo(fixtureId));

}


@Test
public void GetId() {

    given().log().all().
            when().
            get(endpoint).
            then().
            assertThat().
            statusCode(200).
            and().
            body("body", hasSize(numberOfId)).
            and().
            body("fixtureId", notNullValue());


}

}

Error:

    java.lang.AssertionError: 1 expectation failed.
XML path fixtureId doesn't match.
Expected: 2
  Actual: nullErrorCannot GET /fixtures/2
  • What if you get `http://localhost:3000/fixtures/2` manually? Does the response seem okay? – Alexey R. Aug 22 '20 at 20:23
  • Cannot GET /fixtures/2 nope, thats the bizzare thing it's like it's not an endpoint when you search for an ID. – Peter Kirby Aug 23 '20 at 08:09
  • So this is the answer to your question. It has nothing to do with Java, TestNG or RestAssured. You need to sort out the things with your service. – Alexey R. Aug 23 '20 at 08:28

0 Answers0