OpaClientService { public String getExecutableSqlStatements() { return getExecutableSqlStatements(defaultPartialRequest.getDefaultPartialRequest()); } OpaClientService(OpaConfig opaConfig);  OpaClientService(OpaConfig opaConfig, RestTemplate restTemplate); String getExecutableSqlStatements(); String getExecutableSqlStatements(PartialRequest partialRequest); OpaCompilerResponse getOpaCompilerApiResponse(); OpaCompilerResponse getOpaCompilerApiResponse(PartialRequest partialRequest);  }
@Test void shouldGetTheSqlStatementsFromPartialRequest() { when(restTemplate.postForEntity(anyString(), any(HttpEntity.class), eq(OpaCompilerResponse.class))) .thenReturn(new ResponseEntity<>(opaCompilerResponse, HttpStatus.OK)); PartialRequest partialRequest = PartialRequest.builder() .query("data.petclinic.authz.allow = true") .unknowns(Set.of("data.pets")).build(); String result = target.getExecutableSqlStatements(partialRequest); assertThat(result, is(notNullValue())); assertThat(result, is("SELECT * FROM pets WHERE (pets.owner = 'alice' AND pets.name = 'fluffy') OR (pets.veterinarian = 'alice' AND pets.clinic = 'SOMA' AND pets.name = 'fluffy');")); }
@Test void shouldThrowOpaClientException() { when(restTemplate.postForEntity(anyString(), any(HttpEntity.class), eq(OpaCompilerResponse.class))) .thenReturn(new ResponseEntity<>(opaCompilerResponse, HttpStatus.BAD_REQUEST)); PartialRequest partialRequest = PartialRequest.builder() .query("data.petclinic.authz.allow = true") .unknowns(Set.of("data.pets")).build(); assertThrows(OpaClientException.class, () -> { target.getExecutableSqlStatements(partialRequest); }); }