Code Monkey home page Code Monkey logo

spring-events's People

Contributors

nfrankel avatar sbrannen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-events's Issues

EventRepositoryTests does not work when having nested tests

Issue

When having @Nested tests in EventRepositoryTests, it seems that there is an issue with autowired dependencies and transactional context.

For example, if you put delete(), update() and save() tests into a nested WriteTests class, and findAll() with findById() tests into a nested ReadTests class (like this), update() and findById() tests will fail:

└─ JUnit Jupiter ✔
   ├─ ApplicationTests ↷ class com.sambrannen.spring.events.ApplicationTests is @Disabled
   ├─ EventRepositoryTests ✔
   │  ├─ WriteTests ✔
   │  │  ├─ delete() ✔
   │  │  ├─ update() ✘ 
   │  │  │        Expecting actual not to be null
   │  │  └─ save() ✔
   │  └─ ReadTests ✔
   │     ├─ findAll() ✔
   │     └─ findById() ✘ 
   │              Expecting Optional to contain a value but was empty.
   ├─ EventTests ✔
   │  ├─ lombokShouldGetCorrectly() ✔
   │  ├─ eventsShouldHaveSameHashCodeWithDifferentIdsButTheSameName() ✔
   │  ├─ eventsShouldBeEqualWithDifferentIdsButTheSameName() ✔
   │  ├─ lombokShouldSetCorrectly() ✔
   │  ├─ eventsShouldNotBeEqualWithTheSameIdButDifferentNames() ✔
   │  └─ eventsShouldNotHaveSameHashCodeWithTheSameIdButDifferentNames() ✔
   ├─ RestEventsControllerTests ✔
   │  ├─ retrieveNonexistentEvent() ✔
   │  ├─ deleteEvent() ✔
   │  ├─ updateEvent() ✔
   │  ├─ createEvent() ✔
   │  ├─ retrieveAllEvents() ✔
   │  └─ retrieveEvent() ✔
   ├─ EventsControllerWithMockedServiceTests ✔
   │  └─ listEvents(MockMvc) ✔
   └─ EventsControllerTests ✔
      └─ Home page should display more than 10 events ✔

Failures (2):
  JUnit Jupiter:EventRepositoryTests:WriteTests:update()
    MethodSource [className = 'com.sambrannen.spring.events.repository.EventRepositoryTests$WriteTests', methodName = 'update', methodParameterTypes = '']
    => java.lang.AssertionError: 
Expecting actual not to be null
  JUnit Jupiter:EventRepositoryTests:ReadTests:findById()
    MethodSource [className = 'com.sambrannen.spring.events.repository.EventRepositoryTests$ReadTests', methodName = 'findById', methodParameterTypes = '']
    => java.lang.AssertionError: 
Expecting Optional to contain a value but was empty.

Steps to reproduce

Consider moving `EventsControllerTests` into `web` package by changing `TestConfiguration` annotation

I believe EventsControllerTests (which only differs to EventsControllerIT by the mocking of eventService) is outside the web package because the TestConfiguration's @EnableWebMvc annotation causes the Spring Boot Jackson auto-configuration not be used. If this was in the web package as is, it would impact RestEventsControllerIT.retreiveEvent because the eventDate won't be serialized properly.

However, if @EnableWebMvc was changed to @EnableAutoConfiguration, I think things should work fine in the web package as the Jackson JSR-310-based ObjectMapper will continue to be used.

See: Default Jackson HttpMessageConverter does not honor autoconfigured ObjectMapper

Just a suggestion. Would appreciate your feedback.

Static content not found if launching application within Eclipse

Application should extend WebMvcAutoConfiguration; otherwise, static content can not be served when started via 'Run As - Java Application'. (see patch below)

diff --git a/src/main/java/com/sambrannen/spring/events/Application.java b/src/main/java/com/sambrannen/spring/events/Application.java
index 2bc47b0..3cb757f 100644
--- a/src/main/java/com/sambrannen/spring/events/Application.java
+++ b/src/main/java/com/sambrannen/spring/events/Application.java
@@ -19,6 +19,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
 import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
 
@@ -34,7 +35,7 @@
  */
 @SpringBootApplication(scanBasePackageClasses = { EventService.class, EventsController.class })
 @EnableGlobalMethodSecurity(prePostEnabled = true)
-public class Application {
+public class Application extends WebMvcAutoConfiguration {
 
 	public static void main(String[] args) {
 		SpringApplication.run(Application.class, args);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.