This commit is contained in:
Jonathan Cook 2020-06-30 10:08:18 +02:00
commit a256b723c9
26 changed files with 362 additions and 66 deletions

View File

@ -2,19 +2,16 @@
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.baeldung</groupId>
<artifactId>aws-app-sync</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>aws-app-sync</name>
<description>Spring Boot using AWS App Sync</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
</parent>
<properties>
<java.version>1.8</java.version>

View File

@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
@Disabled
class AwsAppSyncApplicationTests {
class AwsAppSyncApplicationUnitTest {
@Test
void givenGraphQuery_whenListEvents_thenReturnAllEvents() {

View File

@ -16,7 +16,7 @@
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
@ -71,12 +71,12 @@
</build>
<properties>
<org.mapstruct.version>1.3.0.Final</org.mapstruct.version>
<org.mapstruct.version>1.4.0.Beta1</org.mapstruct.version>
<springframework.version>4.3.4.RELEASE</springframework.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<org.projectlombok.version>1.18.4</org.projectlombok.version>
<assertj.version>3.11.1</assertj.version>
<assertj.version>3.16.1</assertj.version>
</properties>
</project>

View File

@ -0,0 +1,25 @@
package com.baeldung.mapstruct.mappingCollections.dto;
import java.util.ArrayList;
import java.util.List;
public class CompanyDTO {
private List<EmployeeDTO> employees;
public List<EmployeeDTO> getEmployees() {
return employees;
}
public void setEmployees(List<EmployeeDTO> employees) {
this.employees = employees;
}
public void addEmployee(EmployeeDTO employeeDTO) {
if (employees == null) {
employees = new ArrayList<>();
}
employees.add(employeeDTO);
}
}

View File

@ -0,0 +1,23 @@
package com.baeldung.mapstruct.mappingCollections.dto;
public class EmployeeDTO {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}

View File

@ -0,0 +1,14 @@
package com.baeldung.mapstruct.mappingCollections.dto;
public class EmployeeFullNameDTO {
private String fullName;
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
}

View File

@ -0,0 +1,11 @@
package com.baeldung.mapstruct.mappingCollections.mapper;
import com.baeldung.mapstruct.mappingCollections.dto.CompanyDTO;
import com.baeldung.mapstruct.mappingCollections.model.Company;
import org.mapstruct.Mapper;
@Mapper(uses = EmployeeMapper.class)
public interface CompanyMapper {
CompanyDTO map(Company company);
}

View File

@ -0,0 +1,12 @@
package com.baeldung.mapstruct.mappingCollections.mapper;
import com.baeldung.mapstruct.mappingCollections.dto.CompanyDTO;
import com.baeldung.mapstruct.mappingCollections.model.Company;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
public interface CompanyMapperAdderPreferred {
CompanyDTO map(Company company);
}

View File

@ -0,0 +1,20 @@
package com.baeldung.mapstruct.mappingCollections.mapper;
import com.baeldung.mapstruct.mappingCollections.dto.EmployeeFullNameDTO;
import com.baeldung.mapstruct.mappingCollections.model.Employee;
import org.mapstruct.Mapper;
import java.util.List;
@Mapper
public interface EmployeeFullNameMapper {
List<EmployeeFullNameDTO> map(List<Employee> employees);
default EmployeeFullNameDTO map(Employee employee) {
EmployeeFullNameDTO employeeInfoDTO = new EmployeeFullNameDTO();
employeeInfoDTO.setFullName(employee.getFirstName() + " " + employee.getLastName());
return employeeInfoDTO;
}
}

View File

@ -0,0 +1,19 @@
package com.baeldung.mapstruct.mappingCollections.mapper;
import com.baeldung.mapstruct.mappingCollections.dto.EmployeeDTO;
import com.baeldung.mapstruct.mappingCollections.model.Employee;
import org.mapstruct.Mapper;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Mapper
public interface EmployeeMapper {
List<EmployeeDTO> map(List<Employee> employees);
Set<EmployeeDTO> map(Set<Employee> employees);
Map<String, EmployeeDTO> map(Map<String, Employee> idEmployeeMap);
}

View File

@ -0,0 +1,16 @@
package com.baeldung.mapstruct.mappingCollections.model;
import java.util.List;
public class Company {
private List<Employee> employees;
public List<Employee> getEmployees() {
return employees;
}
public void setEmployees(List<Employee> employees) {
this.employees = employees;
}
}

View File

@ -0,0 +1,28 @@
package com.baeldung.mapstruct.mappingCollections.model;
public class Employee {
private String firstName;
private String lastName;
public Employee(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}

View File

@ -0,0 +1,32 @@
package com.baeldung.mapstruct.mappingCollections.mapper;
import com.baeldung.mapstruct.mappingCollections.dto.CompanyDTO;
import com.baeldung.mapstruct.mappingCollections.dto.EmployeeDTO;
import com.baeldung.mapstruct.mappingCollections.model.Company;
import com.baeldung.mapstruct.mappingCollections.model.Employee;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class CompanyMapperAdderPreferredUnitTest {
private CompanyMapperAdderPreferred companyMapper = Mappers.getMapper(CompanyMapperAdderPreferred.class);
@Test
void whenMappingToCompanyDTO_thenExpectCorrectMappingResult() {
Employee employee = new Employee("John", "Doe");
Company company = new Company();
company.setEmployees(Collections.singletonList(employee));
CompanyDTO result = companyMapper.map(company);
List<EmployeeDTO> employees = result.getEmployees();
assertThat(employees).hasSize(1);
assertThat(employees.get(0).getFirstName()).isEqualTo("John");
assertThat(employees.get(0).getLastName()).isEqualTo("Doe");
}
}

View File

@ -0,0 +1,32 @@
package com.baeldung.mapstruct.mappingCollections.mapper;
import com.baeldung.mapstruct.mappingCollections.dto.CompanyDTO;
import com.baeldung.mapstruct.mappingCollections.dto.EmployeeDTO;
import com.baeldung.mapstruct.mappingCollections.model.Company;
import com.baeldung.mapstruct.mappingCollections.model.Employee;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class CompanyMapperUnitTest {
private CompanyMapper companyMapper = Mappers.getMapper(CompanyMapper.class);
@Test
void whenMappingToCompanyDTO_thenExpectCorrectMappingResult() {
Employee employee = new Employee("John", "Doe");
Company company = new Company();
company.setEmployees(Collections.singletonList(employee));
CompanyDTO result = companyMapper.map(company);
List<EmployeeDTO> employees = result.getEmployees();
assertThat(employees).hasSize(1);
assertThat(employees.get(0).getFirstName()).isEqualTo("John");
assertThat(employees.get(0).getLastName()).isEqualTo("Doe");
}
}

View File

@ -0,0 +1,26 @@
package com.baeldung.mapstruct.mappingCollections.mapper;
import com.baeldung.mapstruct.mappingCollections.dto.EmployeeFullNameDTO;
import com.baeldung.mapstruct.mappingCollections.model.Employee;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class EmployeeFullNameMapperUnitTest {
private EmployeeFullNameMapper employeeMapper = Mappers.getMapper(EmployeeFullNameMapper.class);
@Test
void whenMappingToEmployeeFullNameDTOList_thenExpectCorrectMappingResult() {
Employee employee = new Employee("John", "Doe");
List<EmployeeFullNameDTO> result = employeeMapper.map(Collections.singletonList(employee));
assertThat(result).hasSize(1);
assertThat(result.get(0).getFullName()).isEqualTo("John Doe");
}
}

View File

@ -0,0 +1,51 @@
package com.baeldung.mapstruct.mappingCollections.mapper;
import com.baeldung.mapstruct.mappingCollections.dto.EmployeeDTO;
import com.baeldung.mapstruct.mappingCollections.model.Employee;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
class EmployeeMapperUnitTest {
private EmployeeMapper employeeMapper = Mappers.getMapper(EmployeeMapper.class);
@Test
void whenMappingToEmployeeDTOList_thenExpectCorrectMappingResult() {
Employee employee = new Employee("John", "Doe");
List<EmployeeDTO> result = employeeMapper.map(Collections.singletonList(employee));
assertThat(result).hasSize(1);
assertThat(result.get(0).getFirstName()).isEqualTo("John");
assertThat(result.get(0).getLastName()).isEqualTo("Doe");
}
@Test
void whenMappingToEmployeeDTOSet_thenExpectCorrectMappingResult() {
Employee employee = new Employee("John", "Doe");
Set<EmployeeDTO> result = employeeMapper.map(Collections.singleton(employee));
assertThat(result).hasSize(1);
assertThat(result.iterator().next().getFirstName()).isEqualTo("John");
assertThat(result.iterator().next().getLastName()).isEqualTo("Doe");
}
@Test
void whenMappingToEmployeeDTOMap_thenExpectCorrectMappingResult() {
Employee employee = new Employee("John", "Doe");
Map<String, EmployeeDTO> result = employeeMapper.map(Collections.singletonMap("1", employee));
assertThat(result).hasSize(1);
assertThat(result.get("1").getFirstName()).isEqualTo("John");
assertThat(result.get("1").getLastName()).isEqualTo("Doe");
}
}

View File

@ -10,11 +10,11 @@
<description>Sample R2DBC Project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
</parent>
<dependencies>
<dependency>

View File

@ -19,7 +19,7 @@ import reactor.core.publisher.Flux;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class R2dbcExampleApplicationTests {
public class R2dbcExampleApplicationIntegrationTest {
@Autowired

View File

@ -1,25 +0,0 @@
package com.baeldung.properties.yamlmap.factory;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertySourceFactory;
import java.io.IOException;
import java.util.Properties;
public class YamlPropertySourceFactory implements PropertySourceFactory {
@Override
public PropertySource<?> createPropertySource(String name, EncodedResource encodedResource) throws IOException {
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
factory.setResources(encodedResource.getResource());
Properties properties = factory.getObject();
return new PropertiesPropertySource(encodedResource.getResource()
.getFilename(), properties);
}
}

View File

@ -4,13 +4,9 @@ import java.util.List;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import com.baeldung.properties.yamlmap.factory.YamlPropertySourceFactory;
@Component
@PropertySource(value = "classpath:server.yml", factory = YamlPropertySourceFactory.class)
@ConfigurationProperties(prefix = "server")
public class ServerProperties {

View File

@ -16,14 +16,14 @@
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot</url>
<id>spring-release</id>
<name>Spring Release</name>
<url>https://repo.spring.io/release</url>
<snapshots>
<enabled>true</enabled>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
<enabled>true</enabled>
</releases>
</repository>
</repositories>

View File

@ -8,9 +8,10 @@
<description>Simple Spring Cloud Stream</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../../parent-boot-2</relativePath>
</parent>
<dependencyManagement>

View File

@ -7,10 +7,10 @@
<name>spring-cloud-stream-kinesis</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../../parent-boot-2</relativePath>
</parent>
<dependencies>

View File

@ -42,7 +42,7 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<structurizr.version>1.0.0-RC5</structurizr.version>
<structurizr.version>1.0.0</structurizr.version>
</properties>
</project>

View File

@ -2,6 +2,8 @@ package com.baeldung.structurizr;
import java.io.File;
import java.io.StringWriter;
import java.util.HashSet;
import java.util.Set;
import com.structurizr.Workspace;
import com.structurizr.analysis.ComponentFinder;
@ -40,15 +42,31 @@ public class StructurizrSimple {
addContainers(workspace);
addComponents(workspace);
addSpringComponents(workspace);
exportToPlantUml(workspace.getViews().getViewWithKey(SOFTWARE_SYSTEM_VIEW));
exportToPlantUml(workspace.getViews().getViewWithKey(CONTAINER_VIEW));
exportToPlantUml(workspace.getViews().getViewWithKey(COMPONENT_VIEW));
exportToPlantUml(findViewWithKey(workspace.getViews(), SOFTWARE_SYSTEM_VIEW));
exportToPlantUml(findViewWithKey(workspace.getViews(), CONTAINER_VIEW));
exportToPlantUml(findViewWithKey(workspace.getViews(), COMPONENT_VIEW));
exportToPlantUml(workspace.getViews().getViewWithKey(JVM2_COMPONENT_VIEW));
exportToPlantUml(findViewWithKey(workspace.getViews(), JVM2_COMPONENT_VIEW));
addStyles(workspace.getViews());
//uploadToExternal(workspace);
}
private static View findViewWithKey(ViewSet viewSet, String key) {
if (key == null) {
throw new IllegalArgumentException("A key must be specified.");
}
Set<View> views = new HashSet<>();
views.addAll(viewSet.getSystemLandscapeViews());
views.addAll(viewSet.getSystemContextViews());
views.addAll(viewSet.getContainerViews());
views.addAll(viewSet.getComponentViews());
views.addAll(viewSet.getDynamicViews());
views.addAll(viewSet.getDeploymentViews());
return views.stream().filter(v -> key.equals(v.getKey())).findFirst().orElse(null);
}
private static void addSpringComponents(Workspace workspace) throws Exception {
Container jvm2 = workspace.getModel().getSoftwareSystemWithName(PAYMENT_TERMINAL).getContainerWithName("JVM-2");