Chapter 1 - Ticket: Projection

Hello,

I’m trying to run the test case for getMovieByCountry but it fails every time. I’ve written correct code for MovieDoa.java, can some one pls help me what is wrong with code here.

public List getMoviesByCountry(String… country) {

Below is my code from MovieDoa.java class.

Bson queryFilter = new Document("Countries", new Document("$all", Arrays.asList(country)));
Bson projection = new Document("title", 1);
List<Document> movies = new ArrayList<>();
moviesCollection.find(queryFilter).limit(2).projection(projection).into(movies);
//TODO> Ticket: Projection - implement the query and projection required by the unit test
return movies;

}

This is correct but you may want to recheck about array query operator for querying you are using. As $all will match only those arrays containing all mentioned countries.

Also, the error in the console when you run unit test or integration test will help you debug the code.

Kanika

Hi Kanika,

Thanks for your reply. Below is test scenario where expectedSize is 2 and acutalSize is 0, and my test case fails with same error msg.

DAO calling statement and passing country as argument.
String country = “Kosovo”;
Iterable cursor = dao.getMoviesByCountry(country);

Assertion statement:
Assert.assertEquals(
“Unexpected number of returned movie documents. Check your query filter”,
expectedSize,
actualSize);

@pavann24, are you sure the field is named Countries?

1 Like