BAEL-20552: Migrate spring-4 module to the com.baeldung package

This commit is contained in:
Krzysztof Woyke
2019-12-27 14:35:32 +01:00
parent b63a8c2335
commit 7a827f178f
41 changed files with 48 additions and 48 deletions
@@ -0,0 +1,46 @@
package com.baeldung.spring43.composedmapping;
import java.util.Collections;
import org.easymock.EasyMock;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.beans.factory.InjectionPoint;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Scope;
import static org.easymock.EasyMock.replay;
@Configuration
@ComponentScan
@EnableWebMvc
public class ComposedMappingConfiguration {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/jsp/view/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
@Bean
public AppointmentService appointmentBook() {
AppointmentService book = EasyMock.mock(AppointmentService.class);
EasyMock.expect(book.getAppointmentsForToday()).andReturn(Collections.emptyMap());
replay(book);
return book;
}
@Bean
@Scope("prototype")
public Logger logger(InjectionPoint injectionPoint) {
return LogManager.getLogger(injectionPoint.getField().getDeclaringClass());
}
}
@@ -0,0 +1,41 @@
package com.baeldung.spring43.composedmapping;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.easymock.EasyMock.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ContextConfiguration(classes = ComposedMappingConfiguration.class)
@WebAppConfiguration
public class ComposedMappingIntegrationTest extends AbstractJUnit4SpringContextTests {
@Autowired
private AppointmentService appointmentService;
private MockMvc mockMvc;
@Autowired
private WebApplicationContext wac;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void whenRequestingMethodWithGetMapping_thenReceiving200Answer() throws Exception {
this.mockMvc.perform(get("/appointments").accept(MediaType.ALL)).andExpect(status().isOk());
verify(appointmentService);
}
}