Added movies microservice for Ch 8 EoC Lab
This commit is contained in:
43
movies/src/main/java/com/redhat/movies/Movie.java
Normal file
43
movies/src/main/java/com/redhat/movies/Movie.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.redhat.movies;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Movie implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -3240337073623122124L;
|
||||
|
||||
private Integer movieId;
|
||||
private String name;
|
||||
private String genre;
|
||||
|
||||
public Movie(Integer movieId, String name, String genre) {
|
||||
this.movieId = movieId;
|
||||
this.name = name;
|
||||
this.genre = genre;
|
||||
}
|
||||
|
||||
public Integer getMovieId() {
|
||||
return movieId;
|
||||
}
|
||||
|
||||
public void setMovieId(Integer movieId) {
|
||||
this.movieId = movieId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getGenre() {
|
||||
return genre;
|
||||
}
|
||||
|
||||
public void setGenre(String genre) {
|
||||
this.genre = genre;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.redhat.movies;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MoviesApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MoviesApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
39
movies/src/main/java/com/redhat/movies/MoviesController.java
Normal file
39
movies/src/main/java/com/redhat/movies/MoviesController.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.redhat.movies;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.io.File;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/")
|
||||
public class MoviesController {
|
||||
|
||||
private List<Movie> movies;
|
||||
private String status = "OK";
|
||||
private String flag = "READY";
|
||||
|
||||
@GetMapping("/movies")
|
||||
public List<Movie> getAllMovies() {
|
||||
|
||||
//Generate fake static data
|
||||
movies = new ArrayList<Movie>();
|
||||
movies.add(new Movie(1,"The Godfather","Crime/Thriller"));
|
||||
movies.add(new Movie(2,"Star Wars","Sci-Fi"));
|
||||
movies.add(new Movie(3,"The Mask","Comedy"));
|
||||
movies.add(new Movie(4,"Die Hard","Action"));
|
||||
movies.add(new Movie(5,"The Exorcist","Horror"));
|
||||
movies.add(new Movie(6,"The Silence of the Lambs","Drama"));
|
||||
|
||||
return movies;
|
||||
}
|
||||
|
||||
@GetMapping("/status")
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
}
|
||||
1
movies/src/main/resources/application.properties
Normal file
1
movies/src/main/resources/application.properties
Normal file
@@ -0,0 +1 @@
|
||||
spring.jackson.serialization.indent_output=true
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.redhat.movies;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = MoviesApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class MoviesApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotNullResponse() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
HttpEntity<String> entity = new HttpEntity<String>(null, headers);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange("http://localhost:" + port + "/movies", HttpMethod.GET,
|
||||
entity, String.class);
|
||||
|
||||
Assert.assertNotNull(response.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllMovies() {
|
||||
|
||||
ResponseEntity <List<Movie>> response = restTemplate.exchange("http://localhost:" + port + "/movies",
|
||||
HttpMethod.GET, null, new ParameterizedTypeReference <List<Movie>> () {});
|
||||
|
||||
List <Movie> movies = response.getBody();
|
||||
Assert.assertNotNull(movies);
|
||||
Assert.assertEquals(7, movies.size());
|
||||
Assert.assertEquals("The Godfather", movies.get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStatus() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
HttpEntity<String> entity = new HttpEntity<String>(null, headers);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange("http://localhost:" + port + "/status", HttpMethod.GET,
|
||||
entity, String.class);
|
||||
|
||||
Assert.assertNotNull(response.getBody());
|
||||
Assert.assertEquals("Ready", response.getBody());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user