formatting cleanup
This commit is contained in:
parent
dec95f5c25
commit
30552c8d0a
|
@ -9,9 +9,7 @@ public class AttrListener implements ServletContextListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
||||||
servletContextEvent
|
servletContextEvent.getServletContext().setAttribute("servlet-context-attr", "test");
|
||||||
.getServletContext()
|
|
||||||
.setAttribute("servlet-context-attr", "test");
|
|
||||||
System.out.println("context init");
|
System.out.println("context init");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,7 @@ public class EchoServlet extends HttpServlet {
|
||||||
@Override
|
@Override
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response) {
|
public void doPost(HttpServletRequest request, HttpServletResponse response) {
|
||||||
try {
|
try {
|
||||||
Path path = File
|
Path path = File.createTempFile("echo", "tmp").toPath();
|
||||||
.createTempFile("echo", "tmp")
|
|
||||||
.toPath();
|
|
||||||
Files.copy(request.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(request.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
|
||||||
Files.copy(path, response.getOutputStream());
|
Files.copy(path, response.getOutputStream());
|
||||||
Files.delete(path);
|
Files.delete(path);
|
||||||
|
|
|
@ -18,9 +18,7 @@ public class HelloFilter implements Filter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||||
servletResponse
|
servletResponse.getOutputStream().print(filterConfig.getInitParameter("msg"));
|
||||||
.getOutputStream()
|
|
||||||
.print(filterConfig.getInitParameter("msg"));
|
|
||||||
filterChain.doFilter(servletRequest, servletResponse);
|
filterChain.doFilter(servletRequest, servletResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,7 @@ public class HelloServlet extends HttpServlet {
|
||||||
@Override
|
@Override
|
||||||
public void doGet(HttpServletRequest request, HttpServletResponse response) {
|
public void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||||
try {
|
try {
|
||||||
response
|
response.getOutputStream().write(servletConfig.getInitParameter("msg").getBytes());
|
||||||
.getOutputStream()
|
|
||||||
.write(servletConfig.getInitParameter("msg").getBytes());
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,8 @@ import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class App
|
public class App {
|
||||||
{
|
public static void main(String[] args) {
|
||||||
public static void main( String[] args )
|
|
||||||
{
|
|
||||||
SpringApplication.run(App.class, args);
|
SpringApplication.run(App.class, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ public class WebMvcConfigure extends WebMvcConfigurerAdapter {
|
||||||
configurer.enable();
|
configurer.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/").setCachePeriod(3600).resourceChain(true).addResolver(new PathResourceResolver());
|
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/").setCachePeriod(3600).resourceChain(true).addResolver(new PathResourceResolver());
|
||||||
|
|
|
@ -10,7 +10,8 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(basePackages = { "com.baeldung.*" })
|
@ComponentScan(basePackages = { "com.baeldung.*" })
|
||||||
@PropertySource("classpath:custom.properties") public class PropertySourcesLoader {
|
@PropertySource("classpath:custom.properties")
|
||||||
|
public class PropertySourcesLoader {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(PropertySourcesLoader.class);
|
private static final Logger log = LoggerFactory.getLogger(PropertySourcesLoader.class);
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@WebServlet(name = "AnnotationServlet",
|
@WebServlet(name = "AnnotationServlet", description = "Example Servlet Using Annotations", urlPatterns = { "/annotationservlet" })
|
||||||
description = "Example Servlet Using Annotations",
|
|
||||||
urlPatterns = { "/annotationservlet" })
|
|
||||||
public class AnnotationServlet extends HttpServlet {
|
public class AnnotationServlet extends HttpServlet {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.ServletRequestBindingException;
|
|
||||||
import org.springframework.web.bind.ServletRequestUtils;
|
import org.springframework.web.bind.ServletRequestUtils;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.baeldung.webjar;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class WebjarsdemoApplication {
|
public class WebjarsdemoApplication {
|
||||||
|
|
|
@ -21,7 +21,6 @@ public class Foo implements Serializable {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Foo(Integer id, String name) {
|
public Foo(Integer id, String name) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
|
@ -22,7 +22,8 @@ import static org.junit.Assert.*;
|
||||||
@TestPropertySource(properties = { "security.basic.enabled=false" })
|
@TestPropertySource(properties = { "security.basic.enabled=false" })
|
||||||
public class SpringBootWithServletComponentIntegrationTest {
|
public class SpringBootWithServletComponentIntegrationTest {
|
||||||
|
|
||||||
@Autowired private ServletContext servletContext;
|
@Autowired
|
||||||
|
private ServletContext servletContext;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenServletContext_whenAccessAttrs_thenFoundAttrsPutInServletListner() {
|
public void givenServletContext_whenAccessAttrs_thenFoundAttrsPutInServletListner() {
|
||||||
|
@ -37,12 +38,11 @@ public class SpringBootWithServletComponentIntegrationTest {
|
||||||
FilterRegistration filterRegistration = servletContext.getFilterRegistration("hello filter");
|
FilterRegistration filterRegistration = servletContext.getFilterRegistration("hello filter");
|
||||||
|
|
||||||
assertNotNull(filterRegistration);
|
assertNotNull(filterRegistration);
|
||||||
assertTrue(filterRegistration
|
assertTrue(filterRegistration.getServletNameMappings().contains("echo servlet"));
|
||||||
.getServletNameMappings()
|
|
||||||
.contains("echo servlet"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired private TestRestTemplate restTemplate;
|
@Autowired
|
||||||
|
private TestRestTemplate restTemplate;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenServletFilter_whenGetHello_thenRequestFiltered() {
|
public void givenServletFilter_whenGetHello_thenRequestFiltered() {
|
||||||
|
@ -58,8 +58,4 @@ public class SpringBootWithServletComponentIntegrationTest {
|
||||||
assertEquals("filtering echo", responseEntity.getBody());
|
assertEquals("filtering echo", responseEntity.getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,11 @@ import static org.junit.Assert.*;
|
||||||
@TestPropertySource(properties = { "security.basic.enabled=false" })
|
@TestPropertySource(properties = { "security.basic.enabled=false" })
|
||||||
public class SpringBootWithoutServletComponentIntegrationTest {
|
public class SpringBootWithoutServletComponentIntegrationTest {
|
||||||
|
|
||||||
@Autowired private ServletContext servletContext;
|
@Autowired
|
||||||
|
private ServletContext servletContext;
|
||||||
|
|
||||||
@Autowired private TestRestTemplate restTemplate;
|
@Autowired
|
||||||
|
private TestRestTemplate restTemplate;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenServletContext_whenAccessAttrs_thenNotFound() {
|
public void givenServletContext_whenAccessAttrs_thenNotFound() {
|
||||||
|
@ -46,5 +48,3 @@ public class SpringBootWithoutServletComponentIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,16 +26,12 @@ public class AppLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getIndex() throws Exception {
|
public void getIndex() throws Exception {
|
||||||
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
|
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(equalTo("Index Page")));
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(content().string(equalTo("Index Page")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getLocal() throws Exception {
|
public void getLocal() throws Exception {
|
||||||
mvc.perform(MockMvcRequestBuilders.get("/local").accept(MediaType.APPLICATION_JSON))
|
mvc.perform(MockMvcRequestBuilders.get("/local").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(equalTo("/local")));
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(content().string(equalTo("/local")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -10,7 +10,6 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
|
||||||
import com.baeldung.utils.controller.UtilsController;
|
import com.baeldung.utils.controller.UtilsController;
|
||||||
|
|
||||||
public class UtilsControllerIntegrationTest {
|
public class UtilsControllerIntegrationTest {
|
||||||
|
@ -23,19 +22,14 @@ public class UtilsControllerIntegrationTest {
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
this.mockMvc = MockMvcBuilders.standaloneSetup(utilsController)
|
this.mockMvc = MockMvcBuilders.standaloneSetup(utilsController).build();
|
||||||
.build();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenParameter_setRequestParam_andSetSessionAttribute() throws Exception {
|
public void givenParameter_setRequestParam_andSetSessionAttribute() throws Exception {
|
||||||
String param = "testparam";
|
String param = "testparam";
|
||||||
this.mockMvc.perform(
|
this.mockMvc.perform(post("/setParam").param("param", param).sessionAttr("parameter", param)).andExpect(status().isOk());
|
||||||
post("/setParam")
|
|
||||||
.param("param", param)
|
|
||||||
.sessionAttr("parameter", param))
|
|
||||||
.andExpect(status().isOk());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.web.WebAppConfiguration;
|
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
import org.subethamail.wiser.Wiser;
|
import org.subethamail.wiser.Wiser;
|
||||||
import org.subethamail.wiser.WiserMessage;
|
import org.subethamail.wiser.WiserMessage;
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,7 @@ import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(
|
@SpringBootTest(classes = DemoApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||||
classes = DemoApplication.class,
|
|
||||||
webEnvironment = WebEnvironment.RANDOM_PORT)
|
|
||||||
public class FooComponentIntegrationTest {
|
public class FooComponentIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
package org.baeldung.boot;
|
package org.baeldung.boot;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -22,7 +23,6 @@ public class FooIntegrationTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
private TestRestTemplate testRestTemplate;
|
private TestRestTemplate testRestTemplate;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenInquiryingFooWithId_whenIdIsValid_thenHttpStatusOK() {
|
public void givenInquiryingFooWithId_whenIdIsValid_thenHttpStatusOK() {
|
||||||
Map<String, String> pathVariables = new HashMap<String, String>();
|
Map<String, String> pathVariables = new HashMap<String, String>();
|
||||||
|
|
|
@ -17,7 +17,6 @@ public class FooJsonIntegrationTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
private JacksonTester<Foo> json;
|
private JacksonTester<Foo> json;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws Exception {
|
public void testSerialize() throws Exception {
|
||||||
Foo foo = new Foo(3, "Foo_Name_3");
|
Foo foo = new Foo(3, "Foo_Name_3");
|
||||||
|
|
Loading…
Reference in New Issue