I want to test method of receiving a list of objects, according to list of given strings. My original method:
@RequestMapping(value = "/fil/", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public ResponseEntity<List<Tag>> findAllByCpe(@RequestBody Fil fil) {
return ResponseEntity.ok(tagRepository.findAllBy(fil));
}
Query (tagRepository):
@Query("SELECT t FROM Tag t WHERE (t.cpe IS NULL OR t.cpe IN (:#{#fil.cpes}))")
List<Tag> findAllBy(@Param("fil") Fil fil);
Fil (Class holding a list of strings I want to search by)
@Getter
@Setter
@AllArgsConstructor
public class Fil {
public Fil() {
}
@NotNull
private List<String> cpes;
}
I wrote an integration test:
@Test
public void FindTagGivenListOfCpes() {
//GIVEN
List<String> cpes = new ArrayList<>();
cpes .add("CPE111");
cpes .add("CPE222");
cpes .add("CPE333");
List<Tag> tagList = (List<Tag>) tagTestBuilder
.saved()
.itemList()
.build();
//WHEN
ResponseEntity<Tag[]> response = restTemplate.postForEntity(TagsResourceConstants.PATH + "/fil/", tagList.get(0).getCpe(), Tag[].class);
//THEN
assertEquals(HttpStatus.OK.value(), response.getStatusCodeValue());
}
I've created an arrayList of strings - Cpes, than I created and save a List of three tags (with exact given Cpes "Cpe111", ...) and I used restTemplate to check if what I search by (cpe) wil give me back the tags with matching cpe (Every tag has one cpe (same as given) already given when I use .itemList method). I have no idea what is missing? I get 415 error :/ I have no idea where to go with that. Basically I just want to test if the objects containg cpes will be found by theirs cpes given under given endpoint.
Aucun commentaire:
Enregistrer un commentaire