TSK-754: PrettyPrint for JSON added

This commit is contained in:
julian.schallenmueller 2018-11-29 12:33:03 +01:00 committed by Holger Hagen
parent 24a700b81d
commit 3be2a01553
4 changed files with 30 additions and 20 deletions

View File

@ -281,7 +281,8 @@ public class ClassificationControllerRestDocumentation {
responseFields(classificationFieldDescriptors))) responseFields(classificationFieldDescriptors)))
.andReturn(); .andReturn();
String newId = result.getResponse().getContentAsString().substring(21, 61); String content = result.getResponse().getContentAsString();
String newId = content.substring(content.indexOf("CLI:"), content.indexOf("CLI:") + 40);
this.mockMvc.perform(RestDocumentationRequestBuilders this.mockMvc.perform(RestDocumentationRequestBuilders
.delete("http://127.0.0.1:" + port + "/v1/classifications/" + newId) .delete("http://127.0.0.1:" + port + "/v1/classifications/" + newId)

View File

@ -356,7 +356,8 @@ public class TaskControllerRestDocumentation {
responseFields(taskFieldDescriptors))) responseFields(taskFieldDescriptors)))
.andReturn(); .andReturn();
String newId = result.getResponse().getContentAsString().substring(11, 51); String content = result.getResponse().getContentAsString();
String newId = content.substring(content.indexOf("TKI:"), content.indexOf("TKI:") + 40);
this.mockMvc.perform(RestDocumentationRequestBuilders this.mockMvc.perform(RestDocumentationRequestBuilders
.delete("http://127.0.0.1:" + port + "/v1/tasks/" + newId) .delete("http://127.0.0.1:" + port + "/v1/tasks/" + newId)
@ -379,13 +380,14 @@ public class TaskControllerRestDocumentation {
.andDo(MockMvcRestDocumentation.document("temp")) .andDo(MockMvcRestDocumentation.document("temp"))
.andReturn(); .andReturn();
String newId = result.getResponse().getContentAsString().substring(11, 51); String content = result.getResponse().getContentAsString();
String newId = content.substring(content.indexOf("TKI:"), content.indexOf("TKI:") + 40);
this.mockMvc.perform(RestDocumentationRequestBuilders this.mockMvc.perform(RestDocumentationRequestBuilders
.post("http://127.0.0.1:" + port + "/v1/tasks/" + newId + "/claim") .post("http://127.0.0.1:" + port + "/v1/tasks/" + newId + "/claim")
.accept("application/hal+json")
.header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x") .header("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x")
.content("{}")) .contentType("application/json")
.content("\"userName\":\"teamlead_1\""))
.andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcRestDocumentation.document("ClaimTaskDocTest", .andDo(MockMvcRestDocumentation.document("ClaimTaskDocTest",
responseFields(taskFieldDescriptors))); responseFields(taskFieldDescriptors)));
@ -410,7 +412,8 @@ public class TaskControllerRestDocumentation {
.andDo(MockMvcRestDocumentation.document("temp")) .andDo(MockMvcRestDocumentation.document("temp"))
.andReturn(); .andReturn();
String newId = result.getResponse().getContentAsString().substring(11, 51); String content = result.getResponse().getContentAsString();
String newId = content.substring(content.indexOf("TKI:"), content.indexOf("TKI:") + 40);
this.mockMvc.perform(RestDocumentationRequestBuilders this.mockMvc.perform(RestDocumentationRequestBuilders
.post("http://127.0.0.1:" + port + "/v1/tasks/" + newId + "/complete") .post("http://127.0.0.1:" + port + "/v1/tasks/" + newId + "/complete")
@ -442,7 +445,8 @@ public class TaskControllerRestDocumentation {
responseFields(taskFieldDescriptors))) responseFields(taskFieldDescriptors)))
.andReturn(); .andReturn();
String newId = result.getResponse().getContentAsString().substring(11, 51); String content = result.getResponse().getContentAsString();
String newId = content.substring(content.indexOf("TKI:"), content.indexOf("TKI:") + 40);
this.mockMvc.perform(RestDocumentationRequestBuilders this.mockMvc.perform(RestDocumentationRequestBuilders
.post("http://127.0.0.1:" + port + "/v1/tasks/" + newId + "/transfer/WBI:100000000000000000000000000000000001") .post("http://127.0.0.1:" + port + "/v1/tasks/" + newId + "/transfer/WBI:100000000000000000000000000000000001")

View File

@ -399,7 +399,8 @@ public class TaskControllerIntTest {
in.close(); in.close();
con.disconnect(); con.disconnect();
String createdTask = responsePayload.toString(); String createdTask = responsePayload.toString();
String taskIdOfCreatedTask = createdTask.substring(11, 51); String taskIdOfCreatedTask = createdTask.substring(createdTask.indexOf("TKI:"), createdTask.indexOf("TKI:") + 40);
assertNotNull(taskIdOfCreatedTask); assertNotNull(taskIdOfCreatedTask);
assertTrue(taskIdOfCreatedTask.startsWith("TKI:")); assertTrue(taskIdOfCreatedTask.startsWith("TKI:"));

View File

@ -1,6 +1,7 @@
package pro.taskana.rest; package pro.taskana.rest;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -11,9 +12,11 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.json.SpringHandlerInstantiator; import org.springframework.http.converter.json.SpringHandlerInstantiator;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
@ -32,7 +35,7 @@ import pro.taskana.ldap.LdapClient;
@Configuration @Configuration
@ComponentScan @ComponentScan
@EnableTransactionManagement @EnableTransactionManagement
public class RestConfiguration { public class RestConfiguration extends WebMvcConfigurationSupport {
@Value("${taskana.schemaName:TASKANA}") @Value("${taskana.schemaName:TASKANA}")
private String schemaName; private String schemaName;
@ -74,18 +77,19 @@ public class RestConfiguration {
return new LdapClient(); return new LdapClient();
} }
// Needed to override JSON De-/Serializer in Jackson.
@Bean
public Jackson2ObjectMapperBuilder jacksonBuilder(HandlerInstantiator handlerInstantiator) {
Jackson2ObjectMapperBuilder b = new Jackson2ObjectMapperBuilder();
b.indentOutput(true);
b.handlerInstantiator(handlerInstantiator);
return b;
}
// Needed for injection into jackson deserializer. // Needed for injection into jackson deserializer.
@Bean @Bean
public HandlerInstantiator handlerInstantiator(ApplicationContext context) { public HandlerInstantiator handlerInstantiator(ApplicationContext context) {
return new SpringHandlerInstantiator(context.getAutowireCapableBeanFactory()); return new SpringHandlerInstantiator(context.getAutowireCapableBeanFactory());
} }
@Override
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
for (HttpMessageConverter<?> converter : converters) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
jacksonConverter.setPrettyPrint(true);
}
}
}
} }