Merge pull request #9889 from eugenp/revert-9843-BAEL-4321-define-a-map-in-yaml-for-pojo
Revert "BAEL-4321 demo app for yaml to pojo"
This commit is contained in:
commit
a098310a5e
@ -56,7 +56,6 @@
|
|||||||
<module>spring-boot-performance</module>
|
<module>spring-boot-performance</module>
|
||||||
<module>spring-boot-properties</module>
|
<module>spring-boot-properties</module>
|
||||||
<module>spring-boot-properties-2</module>
|
<module>spring-boot-properties-2</module>
|
||||||
<module>spring-boot-properties-3</module>
|
|
||||||
<module>spring-boot-property-exp</module>
|
<module>spring-boot-property-exp</module>
|
||||||
<module>spring-boot-runtime</module>
|
<module>spring-boot-runtime</module>
|
||||||
<module>spring-boot-security</module>
|
<module>spring-boot-security</module>
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>com.baeldung.spring-boot-modules</groupId>
|
|
||||||
<artifactId>spring-boot-modules</artifactId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
<relativePath>../</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>spring-boot-properties-3</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<name>spring-boot-properties-3</name>
|
|
||||||
<description>Spring Boot Properties Module</description>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.junit.vintage</groupId>
|
|
||||||
<artifactId>junit-vintage-engine</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
|
||||||
<version>RELEASE</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,16 +0,0 @@
|
|||||||
package com.baeldung.boot.properties;
|
|
||||||
|
|
||||||
import com.baeldung.boot.properties.config.TshirtSizeConfig;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
@EnableConfigurationProperties(TshirtSizeConfig.class)
|
|
||||||
public class DemoApplication {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(DemoApplication.class, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package com.baeldung.boot.properties.config;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@ConfigurationProperties(prefix = "t-shirt-size")
|
|
||||||
public class TshirtSizeConfig {
|
|
||||||
|
|
||||||
private final Map<String, Integer> simpleMapping;
|
|
||||||
|
|
||||||
private final Map<String, Map<String, Integer>> complexMapping;
|
|
||||||
|
|
||||||
|
|
||||||
public TshirtSizeConfig(Map<String, Integer> simpleMapping, Map<String, Map<String, Integer>> complexMapping) {
|
|
||||||
this.simpleMapping = simpleMapping;
|
|
||||||
this.complexMapping = complexMapping;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Integer> getSimpleMapping() {
|
|
||||||
return simpleMapping;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Map<String, Integer>> getComplexMapping() {
|
|
||||||
return complexMapping;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package com.baeldung.boot.properties.controller;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import com.baeldung.boot.properties.service.SizeConverterService;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping(value = "/")
|
|
||||||
public class TshirtSizeController {
|
|
||||||
|
|
||||||
private final SizeConverterService service;
|
|
||||||
|
|
||||||
public TshirtSizeController(SizeConverterService service) {
|
|
||||||
this.service = service;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value ="convertSize", method = RequestMethod.GET)
|
|
||||||
public int convertSize(@RequestParam(value = "label") final String label, @RequestParam(value = "countryCode", required = false) final String countryCode) {
|
|
||||||
return service.convertSize(label, countryCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package com.baeldung.boot.properties.service;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import com.baeldung.boot.properties.config.TshirtSizeConfig;
|
|
||||||
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class SizeConverterImpl implements SizeConverterService {
|
|
||||||
|
|
||||||
private final TshirtSizeConfig tshirtSizeConfig;
|
|
||||||
|
|
||||||
public SizeConverterImpl(TshirtSizeConfig tshirtSizeConfig) {
|
|
||||||
this.tshirtSizeConfig = tshirtSizeConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int convertSize(String label, String countryCode) {
|
|
||||||
if(countryCode == null) {
|
|
||||||
return tshirtSizeConfig.getSimpleMapping().get(label);
|
|
||||||
}
|
|
||||||
return tshirtSizeConfig.getComplexMapping().get(label).get(countryCode.toLowerCase());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package com.baeldung.boot.properties.service;
|
|
||||||
|
|
||||||
|
|
||||||
public interface SizeConverterService {
|
|
||||||
|
|
||||||
int convertSize(String label, String countryCode);
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
t-shirt-size:
|
|
||||||
simple-mapping:
|
|
||||||
XS: 6
|
|
||||||
S: 8
|
|
||||||
M: 10
|
|
||||||
L: 12
|
|
||||||
XL: 14
|
|
||||||
|
|
||||||
|
|
||||||
complex-mapping:
|
|
||||||
XS:
|
|
||||||
uk: 6
|
|
||||||
fr: 34
|
|
||||||
us: 2
|
|
||||||
S:
|
|
||||||
uk: 8
|
|
||||||
fr: 36
|
|
||||||
us: 4
|
|
||||||
M:
|
|
||||||
uk: 10
|
|
||||||
fr: 38
|
|
||||||
us: 6
|
|
||||||
L:
|
|
||||||
uk: 12
|
|
||||||
fr: 40
|
|
||||||
us: 8
|
|
||||||
XL:
|
|
||||||
uk: 14
|
|
||||||
fr: 42
|
|
||||||
us: 10
|
|
@ -1,38 +0,0 @@
|
|||||||
package com.baeldung.boot.properties.controller;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.mockito.InjectMocks;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
|
||||||
import com.baeldung.boot.properties.service.SizeConverterService;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
|
||||||
class TshirtSizeControllerUnitTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private SizeConverterService service;
|
|
||||||
|
|
||||||
@InjectMocks
|
|
||||||
private TshirtSizeController tested;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void whenConvertSize_thenOK() {
|
|
||||||
|
|
||||||
// Given
|
|
||||||
String label = "S";
|
|
||||||
String countryCode = "fr";
|
|
||||||
int result = 36;
|
|
||||||
|
|
||||||
// When
|
|
||||||
when(service.convertSize(label, countryCode)).thenReturn(result);
|
|
||||||
int actual = tested.convertSize(label, countryCode);
|
|
||||||
|
|
||||||
// Then
|
|
||||||
assertEquals(actual, result);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user