Skip to content

Commit

Permalink
610: test negative tests for getReceiverAndStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
halprin committed Jan 15, 2024
1 parent 2365f49 commit 2a05973
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,26 +191,33 @@ String[] getReceiverAndStatus(String responseBody) throws FormatterProcessingExc
// ...
// }

String organizationId;
String service;
String overallStatus;
Map<String, Object> responseObject =
formatter.convertJsonToObject(responseBody, new TypeReference<>() {});

String receiver;
try {
Map<String, Object> responseObject =
formatter.convertJsonToObject(responseBody, new TypeReference<>() {});
ArrayList<?> destinations = (ArrayList<?>) responseObject.get("destinations");
Map<?, ?> destination = (Map<?, ?>) destinations.get(0);
organizationId = destination.get("organization_id").toString();
service = destination.get("service").toString();
overallStatus = (String) responseObject.get("overallStatus");
String organizationId = destination.get("organization_id").toString();
String service = destination.get("service").toString();
receiver = organizationId + "." + service;
} catch (IndexOutOfBoundsException e) {
// the destinations have not been determined yet by RS
return null;
receiver = null;
} catch (Exception e) {
throw new FormatterProcessingException(
"Unable to extract receiver name from response due to unexpected format", e);
}

return new String[] {organizationId + "." + service, overallStatus};
String overallStatus;
try {
overallStatus = (String) responseObject.get("overallStatus");
} catch (Exception e) {
throw new FormatterProcessingException(
"Unable to extract overallStatus from response due to unexpected format", e);
}

return new String[] {receiver, overallStatus};
}

PartnerMetadataStatus ourStatusFromReportStreamStatus(String rsStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class PartnerMetadataOrchestratorTest extends Specification {
parsedResponse[1] == status
}

def "getReceiverName throws FormatterProcessingException or returns null for unexpected format response"() {
def "getReceiverAndStatus throws FormatterProcessingException or returns null for unexpected format response"() {
given:
TestApplicationContext.register(Formatter, Jackson.getInstance())
TestApplicationContext.injectRegisteredImplementations()
Expand Down Expand Up @@ -400,10 +400,18 @@ class PartnerMetadataOrchestratorTest extends Specification {
when:

def jsonWithEmptyDestinations = "{\"destinations\": []}"
def receiverName = PartnerMetadataOrchestrator.getInstance().getReceiverAndStatus(jsonWithEmptyDestinations)
def parsedData = PartnerMetadataOrchestrator.getInstance().getReceiverAndStatus(jsonWithEmptyDestinations)

then:
receiverName == null
parsedData[0] == null

when:

def jsonWithNoStatus = "{\"destinations\": []}"
parsedData = PartnerMetadataOrchestrator.getInstance().getReceiverAndStatus(jsonWithNoStatus)

then:
parsedData[1] == null

when:
def jsonWithoutOrgId = "{\"destinations\":[{\"service\":\"service\"}]}"
Expand Down

0 comments on commit 2a05973

Please sign in to comment.