I have to validate two POJOs instance of the same POJO Where one POJO instance is created via Mapping of JSON response Another POJO instance is created by manually mapping with DB

Now few variables are not required to set via DB in one test case but in another test case it is required. Currently those variables are Exclude via Lambok but it will not work for multiple test cases

POJO `

package com.spotify.oauth2.pojo.LeadResponse;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
//@JsonIgnoreProperties(value = {"hasSubscriptions","planId","planName","items","inPersonRate","shippingAddress","keyedInRate"})
public class Order {

    @JsonProperty("uuid")
    private String uuid;

    @JsonProperty("hasSubscriptions")
    @EqualsAndHashCode.Exclude
    private Boolean hasSubscriptions;

    @JsonProperty("planId")
    @EqualsAndHashCode.Exclude
    private String planId;

    @JsonProperty("planName")
    @EqualsAndHashCode.Exclude
    private String planName;

    @JsonProperty("keyedInRate")
    @EqualsAndHashCode.Exclude
    private KeyedInRate keyedInRate;

    @JsonProperty("inPersonRate")
    @EqualsAndHashCode.Exclude
    private InPersonRate inPersonRate;

    @JsonProperty("shippingAddress")
    @EqualsAndHashCode.Exclude
    private ShippingAddress shippingAddress;

    @JsonProperty("items")
    @EqualsAndHashCode.Exclude
    private List<Item> items;

}

` test class

 @Test
public void shouldBeAbleToCreateLead() throws Exception {
    String query = "Select * from growth.merchant_lead where email = '[email protected]' order by created_time desc";
    Lead requestCreateLead = leadBuilder();
    Response response = LeadAPI.put(requestCreateLead);
    assertThat(response.statusCode(), equalTo(StatusCode.CODE_200.getCode()));
    LeadResponse actualResponseLead = response.as(LeadResponse.class);
    JSONArray jsonArray = getDataRows(query);
    LeadResponse expectedResponse = getExpectedResponse(jsonArray);
    boolean result = comparePOJO(actualResponseLead,expectedResponse);
}

@Step
public Lead leadBuilder() {
    Lead lead = new Lead();
    return lead;
}


public static boolean comparePOJO(Object obj1, Object obj2) {
    return obj1.equals(obj2);
}

Can a function is created that will ignore default and null values while validating the objects? Also, in case validation failed, should be able to print the difference.

0

There are 0 best solutions below