formatting work

This commit is contained in:
eugenp
2016-10-12 08:02:05 +03:00
parent eb7650eead
commit 856be0a08a
128 changed files with 2039 additions and 2275 deletions
@@ -18,17 +18,16 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.ModelAndView;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes={WebConfig.class}, loader=AnnotationConfigWebContextLoader.class )
@ContextConfiguration(classes = { WebConfig.class }, loader = AnnotationConfigWebContextLoader.class)
public class ControllerAnnotationTest {
private MockMvc mockMvc;
private MockMvc mockMvc;
@Autowired
private WebApplicationContext wac;
private Student selectedStudent;
@Before
@@ -43,9 +42,7 @@ public class ControllerAnnotationTest {
@Test
public void testTestController() throws Exception {
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/test/"))
.andReturn()
.getModelAndView();
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/test/")).andReturn().getModelAndView();
// validate modal data
Assert.assertSame(mv.getModelMap().get("data").toString(), "Welcome home man");
@@ -57,9 +54,7 @@ public class ControllerAnnotationTest {
@Test
public void testRestController() throws Exception {
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/{studentId}", 1))
.andReturn().getResponse()
.getContentAsString();
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/{studentId}", 1)).andReturn().getResponse().getContentAsString();
ObjectMapper reader = new ObjectMapper();
@@ -72,9 +67,7 @@ public class ControllerAnnotationTest {
@Test
public void testRestAnnotatedController() throws Exception {
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/annotated/student/{studentId}", 1))
.andReturn().getResponse()
.getContentAsString();
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/annotated/student/{studentId}", 1)).andReturn().getResponse().getContentAsString();
ObjectMapper reader = new ObjectMapper();
@@ -19,7 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration({"classpath:test-mvc.xml"})
@ContextConfiguration({ "classpath:test-mvc.xml" })
public class ControllerTest {
private MockMvc mockMvc;
@@ -41,9 +41,7 @@ public class ControllerTest {
@Test
public void testTestController() throws Exception {
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/test/"))
.andReturn()
.getModelAndView();
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/test/")).andReturn().getModelAndView();
// validate modal data
Assert.assertSame(mv.getModelMap().get("data").toString(), "Welcome home man");
@@ -55,9 +53,7 @@ public class ControllerTest {
@Test
public void testRestController() throws Exception {
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/{studentId}", 1))
.andReturn().getResponse()
.getContentAsString();
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/{studentId}", 1)).andReturn().getResponse().getContentAsString();
ObjectMapper reader = new ObjectMapper();
@@ -70,9 +66,7 @@ public class ControllerTest {
@Test
public void testRestAnnotatedController() throws Exception {
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/annotated/student/{studentId}", 1))
.andReturn().getResponse()
.getContentAsString();
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/annotated/student/{studentId}", 1)).andReturn().getResponse().getContentAsString();
ObjectMapper reader = new ObjectMapper();
@@ -8,36 +8,36 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ScopesTest {
private static final String NAME = "John Smith";
private static final String NAME_OTHER = "Anna Jones";
private static final String NAME = "John Smith";
private static final String NAME_OTHER = "Anna Jones";
@Test
public void testScopeSingleton() {
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("scopes.xml");
@Test
public void testScopeSingleton() {
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("scopes.xml");
final Person personSingletonA = (Person) applicationContext.getBean("personSingleton");
final Person personSingletonB = (Person) applicationContext.getBean("personSingleton");
final Person personSingletonA = (Person) applicationContext.getBean("personSingleton");
final Person personSingletonB = (Person) applicationContext.getBean("personSingleton");
personSingletonA.setName(NAME);
Assert.assertEquals(NAME, personSingletonB.getName());
personSingletonA.setName(NAME);
Assert.assertEquals(NAME, personSingletonB.getName());
((AbstractApplicationContext) applicationContext).close();
}
((AbstractApplicationContext) applicationContext).close();
}
@Test
public void testScopePrototype() {
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("scopes.xml");
@Test
public void testScopePrototype() {
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("scopes.xml");
final Person personPrototypeA = (Person) applicationContext.getBean("personPrototype");
final Person personPrototypeB = (Person) applicationContext.getBean("personPrototype");
final Person personPrototypeA = (Person) applicationContext.getBean("personPrototype");
final Person personPrototypeB = (Person) applicationContext.getBean("personPrototype");
personPrototypeA.setName(NAME);
personPrototypeB.setName(NAME_OTHER);
personPrototypeA.setName(NAME);
personPrototypeB.setName(NAME_OTHER);
Assert.assertEquals(NAME, personPrototypeA.getName());
Assert.assertEquals(NAME_OTHER, personPrototypeB.getName());
Assert.assertEquals(NAME, personPrototypeA.getName());
Assert.assertEquals(NAME_OTHER, personPrototypeB.getName());
((AbstractApplicationContext) applicationContext).close();
}
((AbstractApplicationContext) applicationContext).close();
}
}
@@ -26,18 +26,12 @@ public class AttributeAnnotationTest extends AbstractJUnit4SpringContextTests {
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
.build();
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void whenInterceptorAddsRequestAndSessionParams_thenParamsInjectedWithAttributesAnnotations() throws Exception {
String result = this.mockMvc.perform(get("/test")
.accept(MediaType.ALL))
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
String result = this.mockMvc.perform(get("/test").accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
Assert.assertEquals("login = john, query = invoices", result);
}
@@ -29,15 +29,12 @@ public class ComposedMappingTest extends AbstractJUnit4SpringContextTests {
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
.build();
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void whenRequestingMethodWithGetMapping_thenReceiving200Answer() throws Exception {
this.mockMvc.perform(get("/appointments")
.accept(MediaType.ALL))
.andExpect(status().isOk());
this.mockMvc.perform(get("/appointments").accept(MediaType.ALL)).andExpect(status().isOk());
verify(appointmentService);
}
@@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static org.junit.Assert.assertNotNull;
@ContextConfiguration(classes = {FooRepositoryConfiguration.class, FooServiceConfiguration.class})
@ContextConfiguration(classes = { FooRepositoryConfiguration.class, FooServiceConfiguration.class })
public class ConfigurationConstructorInjectionTest extends AbstractJUnit4SpringContextTests {
@Autowired
@@ -1,6 +1,5 @@
package org.baeldung.spring43.defaultmethods;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
@@ -28,27 +28,16 @@ public class ScopeAnnotationsTest extends AbstractJUnit4SpringContextTests {
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
.build();
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void whenDifferentRequests_thenDifferentInstancesOfRequestScopedBeans() throws Exception {
MockHttpSession session = new MockHttpSession();
String requestScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/request")
.session(session)
.accept(MediaType.ALL)).andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
String requestScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/request").session(session).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
String requestScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/request")
.session(session)
.accept(MediaType.ALL)).andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
String requestScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/request").session(session).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
assertNotEquals(requestScopedServiceInstanceNumber1, requestScopedServiceInstanceNumber2);
}
@@ -59,24 +48,9 @@ public class ScopeAnnotationsTest extends AbstractJUnit4SpringContextTests {
MockHttpSession session1 = new MockHttpSession();
MockHttpSession session2 = new MockHttpSession();
String sessionScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/session")
.session(session1)
.accept(MediaType.ALL)).andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
String sessionScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/session")
.session(session1)
.accept(MediaType.ALL)).andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
String sessionScopedServiceInstanceNumber3 = this.mockMvc.perform(get("/appointments/session")
.session(session2)
.accept(MediaType.ALL)).andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
String sessionScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/session").session(session1).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
String sessionScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/session").session(session1).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
String sessionScopedServiceInstanceNumber3 = this.mockMvc.perform(get("/appointments/session").session(session2).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
assertEquals(sessionScopedServiceInstanceNumber1, sessionScopedServiceInstanceNumber2);
@@ -90,18 +64,8 @@ public class ScopeAnnotationsTest extends AbstractJUnit4SpringContextTests {
MockHttpSession session1 = new MockHttpSession();
MockHttpSession session2 = new MockHttpSession();
String applicationScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/application")
.session(session1)
.accept(MediaType.ALL)).andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
String applicationScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/application")
.session(session2)
.accept(MediaType.ALL)).andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString();
String applicationScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/application").session(session1).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
String applicationScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/application").session(session2).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
assertEquals(applicationScopedServiceInstanceNumber1, applicationScopedServiceInstanceNumber2);