Testing Movie classes

In the last lesson, you created the access classes (repository and controller) for the Movie entity. Now you will test the application to see the results.

Running and testing the application

To test the application you will need to:

  1. Run the application

    • Open the main application class - AppSpringDataApplication.java.

    • Click the play icon to run the class.

      sd app running annotated
  2. Make a request to the application

    • Open a 2nd terminal. You can use the + or split terminal buttons.

    • Use the command curl 'localhost:8080/movies' to see the results of the findAll method.

      sd run curl
Testing from local environment setup

To run the application, start it from your preferred IDE or use the following command in a terminal window:

shell
./mvnw spring-boot:run

Open a 2nd terminal and make the request to the application:

shell
curl 'localhost:8080/movies'
FindAll Results (example)
{
  "movieId":"1",
  "title":"Toy Story",
  "plot":"A cowboy doll is profoundly threatened and jealous when a new spaceman figure supplants him as top toy in a boy's room.",
  "poster":"https://image.tmdb.org/t/p/w440_and_h660_face/uXDfjJbdP4ijW5hWSBrPrlKpxab.jpg",
  "url":"https://themoviedb.org/movie/862",
  "imdbId":"0114709",
  "tmdbId":"862",
  "released":"1995-11-22",
  "year":1995,
  "runtime":81,
  "budget":30000000,
  "revenue":373554033,
  "imdbVotes":591836,
  "imdbRating":8.3,
  "languages":[
    "English"
  ],
  "countries":[
    "USA"
  ]
},
//additional results

Random results order

Results may not all display (due to the amount of movies in the database), nor be in the same order or formatted exactly as shown above. Formatted results depend on whether the output is pretty-printing.

To test the findById method, execute curl 'localhost:8080/movies/2' and review the results.

FindById Results (example)
{
  "movieId": "2",
  "title": "Jumanji",
  "plot": "When two kids find and play a magical board game, they release a man trapped for decades in it and a host of dangers that can only be stopped by finishing the game.",
  "poster": "https://image.tmdb.org/t/p/w440_and_h660_face/vgpXmVaVyUL7GGiDeiK1mKEKzcX.jpg",
  "url": "https://themoviedb.org/movie/8844",
  "imdbId": "0113497",
  "tmdbId": "8844",
  "released": "1995-12-15",
  "year": 1995,
  "runtime": 104,
  "budget": 65000000,
  "revenue": 262797249,
  "imdbVotes": 198355,
  "imdbRating": 6.9,
  "languages": [
    "English",
    " French"
  ],
  "countries": [
    "USA"
  ]
}

Summary

In this lesson, you tested accessing Movie entities in the database by calling methods in your application.

Next, you will complete a challenge to apply the skills you learned here to create the Person repository and controller classes.