MongoQueryService { public Query getMongoDBQuery() { OpaCompilerResponse opaCompilerApiResponse = opaClientService.getOpaCompilerApiResponse(); AstToMongoDBQuery astToMongoDBQuery = new AstToMongoDBQuery(opaCompilerApiResponse); return astToMongoDBQuery.createQuery(); } MongoQueryService(OpaClientService opaClientService); Query getMongoDBQuery(); Query getMongoDBQuery(PartialRequest partialRequest);  }
@Test void shouldGetMongoDbQueryFromOpaCompilerResponse() { 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(); Query result = target.getMongoDBQuery(partialRequest); assertThat(result, is(notNullValue())); String resultInString = result.getQueryObject().toJson(); assertThat(resultInString, is("{\"$or\": [{\"owner\": \"alice\", \"name\": \"fluffy\"}, {\"veterinarian\": \"alice\", \"clinic\": \"SOMA\", \"name\": \"fluffy\"}]}")); }