[BAEL-7609] - Fixed spring-boot integration tests

This commit is contained in:
amit2103
2018-07-29 18:32:39 +05:30
parent 748c94f231
commit ec4a0a5b94
8 changed files with 66 additions and 20 deletions

View File

@@ -3,6 +3,7 @@ package com.baeldung.displayallbeans.controller;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@@ -14,9 +15,9 @@ public class FooController {
private FooService fooService;
@GetMapping(value = "/displayallbeans")
public String getHeaderAndBody(Map<String, Object> model) {
public ResponseEntity<String> getHeaderAndBody(Map<String, Object> model) {
model.put("header", fooService.getHeader());
model.put("message", fooService.getBody());
return "displayallbeans";
return ResponseEntity.ok("displayallbeans");
}
}

View File

@@ -0,0 +1,15 @@
package org.baeldung.boot.config;
import org.baeldung.boot.converter.StringToEmployeeConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new StringToEmployeeConverter());
}
}

View File

@@ -0,0 +1,16 @@
package org.baeldung.boot.converter;
import org.springframework.core.convert.converter.Converter;
import com.baeldung.toggle.Employee;
public class StringToEmployeeConverter implements Converter<String, Employee> {
@Override
public Employee convert(String from) {
String[] data = from.split(",");
return new Employee(
Long.parseLong(data[0]),
Double.parseDouble(data[1]));
}
}

View File

@@ -0,0 +1,17 @@
package org.baeldung.boot.converter.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baeldung.toggle.Employee;
@RestController
public class StringToEmployeeConverterController {
@GetMapping("/string-to-employee")
public ResponseEntity<Object> getStringToEmployee(@RequestParam("employee") Employee employee) {
return ResponseEntity.ok(employee);
}
}