forked from wakaleo/movie-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
347 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.gradle | ||
build/ | ||
target/ | ||
|
||
# Ignore Gradle GUI config | ||
gradle-app.setting | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 74 additions & 1 deletion
75
src/main/java/com/wakaleo/myflix/movies/MovieServiceApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,90 @@ | ||
package com.wakaleo.myflix.movies; | ||
|
||
import com.fasterxml.classmate.TypeResolver; | ||
import org.joda.time.LocalDate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.context.request.async.DeferredResult; | ||
import springfox.documentation.builders.PathSelectors; | ||
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import springfox.documentation.builders.ResponseMessageBuilder; | ||
import springfox.documentation.schema.ModelRef; | ||
import springfox.documentation.schema.WildcardType; | ||
import springfox.documentation.service.ApiKey; | ||
import springfox.documentation.service.AuthorizationScope; | ||
import springfox.documentation.service.SecurityReference; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spi.service.contexts.SecurityContext; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
import java.util.List; | ||
|
||
import static com.google.common.collect.Lists.newArrayList; | ||
import static springfox.documentation.schema.AlternateTypeRules.newRule; | ||
|
||
//@SpringBootApplication | ||
@Configuration | ||
@ComponentScan | ||
@EnableAutoConfiguration | ||
@EnableSwagger2 | ||
public class MovieServiceApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(MovieServiceApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public Docket petApi() { | ||
return new Docket(DocumentationType.SWAGGER_2) | ||
.select() | ||
.apis(RequestHandlerSelectors.any()) | ||
.paths(PathSelectors.any()) | ||
.build() | ||
.pathMapping("/") | ||
.directModelSubstitute(LocalDate.class, | ||
String.class) | ||
.genericModelSubstitutes(ResponseEntity.class) | ||
.alternateTypeRules( | ||
newRule(typeResolver.resolve(DeferredResult.class, | ||
typeResolver.resolve(ResponseEntity.class, WildcardType.class)), | ||
typeResolver.resolve(WildcardType.class))) | ||
.useDefaultResponseMessages(false) | ||
.globalResponseMessage(RequestMethod.GET, | ||
newArrayList(new ResponseMessageBuilder() | ||
.code(500) | ||
.message("500 message") | ||
.responseModel(new ModelRef("Error")) | ||
.build())) | ||
// .securitySchemes(newArrayList(apiKey())) | ||
// .securityContexts(newArrayList(securityContext())) | ||
; | ||
} | ||
|
||
@Autowired | ||
private TypeResolver typeResolver; | ||
|
||
// private ApiKey apiKey() { | ||
// return new ApiKey("mykey", "api_key", "header"); | ||
// } | ||
// | ||
// private SecurityContext securityContext() { | ||
// return SecurityContext.builder() | ||
// .securityReferences(defaultAuth()) | ||
// .forPaths(PathSelectors.regex("/movies.*")) | ||
// .build(); | ||
// } | ||
// | ||
// List<SecurityReference> defaultAuth() { | ||
// AuthorizationScope authorizationScope | ||
// = new AuthorizationScope("global", "accessEverything"); | ||
// AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; | ||
// authorizationScopes[0] = authorizationScope; | ||
// return newArrayList(new SecurityReference("mykey", authorizationScopes)); | ||
// } | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/groovy/com/wakaleo/myflix/movies/MovieControllerSpecs.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.wakaleo.myflix.movies | ||
|
||
import com.wakaleo.myflix.movies.repository.MovieRepository | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
|
||
class MovieControllerSpecs extends Specification { | ||
|
||
MovieRepository movieRepository = Mock() | ||
|
||
@Unroll | ||
def "should find by director regardless of case (#director -> #filteredDirector)"() { | ||
given: | ||
def controller = new MovieController(repository: movieRepository) | ||
when: | ||
controller.findByDirector(director) | ||
then: | ||
1*movieRepository.findByDirector(filteredDirector) | ||
where: | ||
director | filteredDirector | ||
"Clint Eastwood" | "Clint Eastwood" | ||
"Clint eastwood" | "Clint Eastwood" | ||
"clint eastwood" | "Clint Eastwood" | ||
" clint eastwood " | "Clint Eastwood" | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/test/groovy/com/wakaleo/myflix/movies/integration/WhenFindingMoviesViaTheRestAPI.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.wakaleo.myflix.movies.integration; | ||
|
||
import com.jayway.restassured.RestAssured | ||
import com.wakaleo.myflix.movies.MovieServiceApplication | ||
import com.wakaleo.myflix.movies.model.Movie; | ||
import com.wakaleo.myflix.movies.repository.MovieRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.IntegrationTest; | ||
import org.springframework.boot.test.SpringApplicationContextLoader; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.web.WebAppConfiguration; | ||
import spock.lang.Specification | ||
|
||
import static com.jayway.restassured.RestAssured.when; | ||
|
||
@ContextConfiguration(loader = SpringApplicationContextLoader.class, | ||
classes = MovieServiceApplication.class) | ||
@WebAppConfiguration | ||
@IntegrationTest("server.port:0") | ||
class WhenFindingMoviesViaTheRestAPI extends Specification { | ||
|
||
@Autowired | ||
MovieRepository movieRepository; | ||
|
||
@Value('${local.server.port}') | ||
int port; | ||
|
||
def GLADIATOR = new Movie(title:"Gladiator", director:"Ridley Scott", | ||
description:"Sword and sandles", actors:["Russel Crowe","Joaquin Phoenix"]); | ||
def LETTERS_FROM_IWO_JIMA = new Movie(title:"Letters from Iwo Jima", director:"Clint Eastwood", | ||
description:"The story of the battle of Iwo Jima...", actors:["Ken Watanabe"]); | ||
def GRAN_TORINO = new Movie(title:"Gran Torino", director:"Clint Eastwood", | ||
description:"Disgruntled Korean War veteran", actors:[["Clint Eastwood", "Bee Vang"]]); | ||
|
||
def setup() { | ||
movieRepository.deleteAll(); | ||
RestAssured.port = port; | ||
} | ||
|
||
def "should list all movies"() { | ||
given: | ||
movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA, GRAN_TORINO]) | ||
when: | ||
def movies = when().get("/movies").as(List) | ||
then: | ||
!movies.isEmpty() | ||
} | ||
|
||
def "should return empty list if the catalog is empty"() { | ||
given: | ||
movieCatalogContains([]) | ||
when: | ||
def movies = when().get("/movies").as(List) | ||
then: | ||
movies.isEmpty() | ||
} | ||
|
||
def "should list movies by director"() { | ||
given: | ||
movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA, GRAN_TORINO]) | ||
when: | ||
List<Movie> movies = when().get("/movies/findByDirector/Clint Eastwood").as(List) | ||
then: | ||
movies.collect {movie -> movie.title} == ["Letters from Iwo Jima", "Gran Torino"] | ||
} | ||
|
||
def "should return empty list if no matching films found"() { | ||
given: | ||
movieCatalogContains([GLADIATOR, LETTERS_FROM_IWO_JIMA, GRAN_TORINO]) | ||
when: | ||
List<Movie> movies = when().get("/movies/findByDirector/Peter Jackson").as(List) | ||
then: | ||
movies.isEmpty() | ||
} | ||
|
||
def movieCatalogContains(List<Movie> movies) { | ||
movieRepository.save(movies) | ||
} | ||
|
||
|
||
} |
17 changes: 0 additions & 17 deletions
17
src/test/java/com/wakaleo/myflix/MovieServiceApplicationTests.java
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
src/test/java/com/wakaleo/myflix/movies/features/Catalog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.wakaleo.myflix.movies.features; | ||
|
||
import cucumber.api.CucumberOptions; | ||
import net.serenitybdd.cucumber.CucumberWithSerenity; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(CucumberWithSerenity.class) | ||
@CucumberOptions(features="src/test/resources/features/catalog") | ||
public class Catalog { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.