I am trying to retrieve a newly added column (xyz) in my response when calling the GET API after creating a category margin setting. Below are the steps I have implemented:
- @Before Method - Setting Up the Test In the @Before method, I create the category margin setting using a POST endpoint and then call the GET API to retrieve the list. The expected response includes the new column xyz:
{
"totalCount": 3418,
"totalPages": 7,
"data": [
{
"field1": 1,
"field2": "ABC",
"field3": 904,
"field4": "aa",
"XYZ": "1"
}
]
}
- Getters and Setters for 'xyz' Column I have added the following getter and setter in the model class:
@JsonProperty("xyz")
public String getXyz() {
return xyz;
}
@JsonProperty("xyz")
public void setXyz(String xyz) {
this.xyz = xyz;
}
- Updated the Test Method with Assertion I have updated my test method to include an assertion for the xyz field:
softAssert.assertEquals(setting.getXyz(), CategorySettingDAOFunctions.getXyz(), "xyz value is not equal");
- Database Query Update in DAO Class In the DAO class, I have updated the method selectCategoryMarginSettingFromId to include the new column:
try {
conn = DatabaseUtil.getConnection();
preparedStatement = conn.prepareStatement(selectQuery);
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
xyz = rs.getString("xyz");
}
}
This method is called inside the test method. The SELECT query has been updated to include XYZ:
SELECT
column_1,
column_2,
column_3,
column_4,
column_5,
column_6,
column_7,
column_8,
column_9,
column_10,
column_11,
column_12,
column_13,
column_14,
column_15,
XYZ,
column_17,
column_18,
column_19
FROM table_A
LEFT JOIN table_B ON table_A.ref_id = table_B.id
LEFT JOIN table_C ON table_C.id = table_A.other_ref_id
LEFT JOIN table_D ON table_D.id = table_C.region_id
LEFT JOIN table_E ON table_E.id = table_C.market_id
WHERE table_A.type = 1
AND table_A.status = 1
AND table_A.id = %s;
Issue: I am getting the following error when executing my test:
How can I resolve this issue? Any insights would be appreciated!`
"error"
"SEVERE: Error
.postgresql.util.PSQLException: The column name application was not found in this ResultSet."