M220J -Paging:Ticket Issue

HI

I am facing an issue in Paging ticket , the test cases in PagingTest.java have passed successfully and changes are implemented in MoviesDao.java

Yet when I navigate to the status tab in mflix application at localhost:5000/status the paging click errors out

“Paging: Did not receive the proper response when paging by genre”

Can you help check and rectify this

Thanks

Hi @Sunil_55501,

What is the error message in console when you click to get the validation code?

Kanika

HI Kanika

Below is the error message
“Paging: Did not receive the proper response when paging by genre”

Hi @Sunil_55501,

No, the console error output. Also, the code for genres will also help to debug.

Kanika

Hi kanika
Which console are u referring to, the IDE console?
I ran pagingtest from command prompt
Then started the application from Eclipse Ide
Then navigated to the localhost:5000/status and clicked on the button to get the code

Will send across the Moviesdao code in sometime

Thanks

code in MovieDao.java getMoviesByGenre
This piece of code allows me to get Pass result for PagingTest

Bson castFilter = Filters.in(“genres”, genres);
int i=0;
// sort key

Bson sort = Sorts.ascending(sortKey);
if (skip==0)
{
 sort = Sorts.descending(sortKey);
}

if (skip>0)
{
 sort = Sorts.ascending("_id");
}

/////////sort = Sorts.descending(sortKey);

List<Document> movies = new ArrayList<>();

System.out.println(sort) ;
System.out.println(limit) ;
System.out.println(skip) ;
// TODO > Ticket: Paging - implement the necessary cursor methods to support simple
// pagination like skip and limit in the code below
moviesCollection.find(castFilter).sort(sort).limit(limit).skip(skip).iterator() 

//sort(sort).limit(limit).skip(skip).iterator()
    .forEachRemaining(movies::add);
return movies;

The IDE console log after clicking on the Validate Paging link in status tab

20
20
{ “tomatoes.viewer.numReviews” : -1 }
20
0
{ “_id” : 1 }
20
100

You might need to think about sort, for this ticket, you do not need to update the code for this.

  sort = Sorts.descending(sortKey);

Above sort code will work for every case.

I am not sure if the forEachRemaining code will work with comment in between. Please do the changes and let me know if it works.

Kanika

Hi! I think there is a mistake in @Test for Paging.

Assert.assertEquals("Expected title field does match: Please check your " + “getMoviesByGenre() movies sort order.”, “Only the Dead”, movieDocs.get(0).getString(“title”));
It should be “Korengal”. So that how you can pass test and validate a ticket.
Cheers!

Hello @kanikasingla! I think also that there is a mistake in testPagingByGenre.

When i try to pass the test for the 2nd case (skip=980) i get this message:

org.junit.ComparisonFailure: Expected title field does match: Please check your getMoviesByGenre() movies sort order. expected:<[Only the Dead]> but was:<[Wolf Hall]>

I tried also to verify using mongoDB shell command

Could you please give a help here?

Thanks,
Christodoulos

Hi,

I am having an issue with 2nd case (skip=980) . Whenever I try, i get this message:

org.junit.ComparisonFailure: Expected title field does match: Please check your getMoviesByGenre() movies sort order. expected:<[Only the Dead]> but was:<[Korengal]>
I tried with MongoDB Compass too and it returned Korengal only.
There is some problem with the expectation.

The query I used is:
moviesCollection.find(castFilter).sort(sort).skip(skip).limit(limit).iterator().forEachRemaining(movies::add);

Please check the query again. We query differently in arrays.

https://docs.mongodb.com/manual/tutorial/query-arrays/index.html

This link might help.

Kanika

Can you share the filter query here?

Kanika

Can you share the query here?

Kanika

Sorry but something goes wrong here. My query was similar to the detailed answer you suggested for this ticket but the unit test is still failing! The only thing that changed is just the error message:

org.junit.ComparisonFailure: Expected title field does match: Please check your getMoviesByGenre() movies sort order. expected:<[Only the Dead]> but was:<[Korengal]>

I wasted so much time for this ticket while i had the correct answer…

Is it working now? I mean are you able to pass the unit test and integration test both?

Kanika

No, nothing changed. The unit test is still failing

Please share the whole code so that we can debug. :slight_smile:

Kanika