Moved Content Negotiation article code from spring-mvc-java to spring-mvc-basics
This commit is contained in:
@@ -13,7 +13,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
- [A Quick Guide to Spring MVC Matrix Variables](http://www.baeldung.com/spring-mvc-matrix-variables)
|
||||
- [Intro to WebSockets with Spring](http://www.baeldung.com/websockets-spring)
|
||||
- [File Upload with Spring MVC](http://www.baeldung.com/spring-file-upload)
|
||||
- [Spring MVC Content Negotiation](http://www.baeldung.com/spring-mvc-content-negotiation-json-xml)
|
||||
- [Circular Dependencies in Spring](http://www.baeldung.com/circular-dependencies-in-spring)
|
||||
- [Introduction to HtmlUnit](http://www.baeldung.com/htmlunit)
|
||||
- [Spring @RequestMapping New Shortcut Annotations](http://www.baeldung.com/spring-new-requestmapping-shortcuts)
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
@@ -94,11 +93,6 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
|
||||
configurer.favorPathExtension(false).favorParameter(true).parameterName("mediaType").ignoreAcceptHeader(true).useRegisteredExtensionsOnly(false).defaultContentType(MediaType.APPLICATION_JSON).mediaType("xml", MediaType.APPLICATION_XML).mediaType("json",
|
||||
MediaType.APPLICATION_JSON);
|
||||
}
|
||||
@Bean(name = "multipartResolver")
|
||||
public CommonsMultipartResolver multipartResolver() {
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.baeldung.web.controller;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import com.baeldung.model.Employee;
|
||||
import com.baeldung.spring.web.config.WebConfig;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes = WebConfig.class)
|
||||
public class EmployeeIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private EmployeeController employeeController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
employeeController.initEmployees();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInitEmployees_thenVerifyValuesInitiation() {
|
||||
|
||||
Employee employee1 = employeeController.employeeMap.get(1L);
|
||||
Employee employee2 = employeeController.employeeMap.get(2L);
|
||||
Employee employee3 = employeeController.employeeMap.get(3L);
|
||||
|
||||
Assert.assertTrue(employee1.getId() == 1L);
|
||||
Assert.assertTrue(employee1.getName().equals("John"));
|
||||
Assert.assertTrue(employee1.getContactNumber().equals("223334411"));
|
||||
Assert.assertTrue(employee1.getWorkingArea().equals("rh"));
|
||||
|
||||
Assert.assertTrue(employee2.getId() == 2L);
|
||||
Assert.assertTrue(employee2.getName().equals("Peter"));
|
||||
Assert.assertTrue(employee2.getContactNumber().equals("22001543"));
|
||||
Assert.assertTrue(employee2.getWorkingArea().equals("informatics"));
|
||||
|
||||
Assert.assertTrue(employee3.getId() == 3L);
|
||||
Assert.assertTrue(employee3.getName().equals("Mike"));
|
||||
Assert.assertTrue(employee3.getContactNumber().equals("223334411"));
|
||||
Assert.assertTrue(employee3.getWorkingArea().equals("admin"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user