From 64b750ab783e83ee248de11cd8ce4bf6153e5d59 Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 28 Jun 2020 00:14:24 +0530 Subject: [PATCH 1/6] updated the snapshot repo to release --- spring-cloud/spring-cloud-circuit-breaker/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud/spring-cloud-circuit-breaker/pom.xml b/spring-cloud/spring-cloud-circuit-breaker/pom.xml index a179f3c831..7db3841bc7 100644 --- a/spring-cloud/spring-cloud-circuit-breaker/pom.xml +++ b/spring-cloud/spring-cloud-circuit-breaker/pom.xml @@ -18,7 +18,7 @@ spring-snapshots Spring Snapshots - https://repo.spring.io/libs-snapshot + https://repo.spring.io/release true From 588ce9c6635bc928b5abb8dd44b105542e5dac62 Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 28 Jun 2020 19:20:41 +0530 Subject: [PATCH 2/6] updated pom repository tag to change the name & id and structurizr version update --- .../spring-cloud-circuit-breaker/pom.xml | 8 +++--- structurizr/pom.xml | 2 +- .../structurizr/StructurizrSimple.java | 26 ++++++++++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/spring-cloud/spring-cloud-circuit-breaker/pom.xml b/spring-cloud/spring-cloud-circuit-breaker/pom.xml index 7db3841bc7..ae44fa8199 100644 --- a/spring-cloud/spring-cloud-circuit-breaker/pom.xml +++ b/spring-cloud/spring-cloud-circuit-breaker/pom.xml @@ -16,14 +16,14 @@ - spring-snapshots - Spring Snapshots + spring-release + Spring Release https://repo.spring.io/release - true + false - false + true diff --git a/structurizr/pom.xml b/structurizr/pom.xml index f1b4355dcf..b8efba0937 100644 --- a/structurizr/pom.xml +++ b/structurizr/pom.xml @@ -42,7 +42,7 @@ 1.8 1.8 - 1.0.0-RC5 + 1.0.0 \ No newline at end of file diff --git a/structurizr/src/main/java/com/baeldung/structurizr/StructurizrSimple.java b/structurizr/src/main/java/com/baeldung/structurizr/StructurizrSimple.java index b33a1d9a77..3f52ea657f 100644 --- a/structurizr/src/main/java/com/baeldung/structurizr/StructurizrSimple.java +++ b/structurizr/src/main/java/com/baeldung/structurizr/StructurizrSimple.java @@ -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 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"); From 0f67a9128f010068f417014c747f5b01839bd0f1 Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 28 Jun 2020 23:13:49 +0530 Subject: [PATCH 3/6] used standard project parent instead of using spring boot parent --- aws-app-sync/pom.xml | 17 +++++++---------- ....java => AwsAppSyncApplicationUnitTest.java} | 2 +- persistence-modules/r2dbc/pom.xml | 10 +++++----- ...R2dbcExampleApplicationIntegrationTest.java} | 2 +- .../spring-cloud-stream-kafka/pom.xml | 7 ++++--- .../spring-cloud-stream-kinesis/pom.xml | 8 ++++---- 6 files changed, 22 insertions(+), 24 deletions(-) rename aws-app-sync/src/test/java/com/baeldung/awsappsync/{AwsAppSyncApplicationTests.java => AwsAppSyncApplicationUnitTest.java} (98%) rename persistence-modules/r2dbc/src/test/java/com/baeldung/examples/r2dbc/{R2dbcExampleApplicationTests.java => R2dbcExampleApplicationIntegrationTest.java} (98%) diff --git a/aws-app-sync/pom.xml b/aws-app-sync/pom.xml index 1f915978ab..4c55d38d77 100644 --- a/aws-app-sync/pom.xml +++ b/aws-app-sync/pom.xml @@ -2,19 +2,16 @@ 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.2.6.RELEASE - - - - com.baeldung aws-app-sync - 0.0.1-SNAPSHOT aws-app-sync - Spring Boot using AWS App Sync + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + 1.8 diff --git a/aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationTests.java b/aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationUnitTest.java similarity index 98% rename from aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationTests.java rename to aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationUnitTest.java index 2338cc29a1..8d83dd5b4b 100644 --- a/aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationTests.java +++ b/aws-app-sync/src/test/java/com/baeldung/awsappsync/AwsAppSyncApplicationUnitTest.java @@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.*; @SpringBootTest @Disabled -class AwsAppSyncApplicationTests { +class AwsAppSyncApplicationUnitTest { @Test void givenGraphQuery_whenListEvents_thenReturnAllEvents() { diff --git a/persistence-modules/r2dbc/pom.xml b/persistence-modules/r2dbc/pom.xml index b1de88e9ea..d0f53ba37c 100644 --- a/persistence-modules/r2dbc/pom.xml +++ b/persistence-modules/r2dbc/pom.xml @@ -10,11 +10,11 @@ Sample R2DBC Project - org.springframework.boot - spring-boot-starter-parent - 2.1.6.RELEASE - - + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + diff --git a/persistence-modules/r2dbc/src/test/java/com/baeldung/examples/r2dbc/R2dbcExampleApplicationTests.java b/persistence-modules/r2dbc/src/test/java/com/baeldung/examples/r2dbc/R2dbcExampleApplicationIntegrationTest.java similarity index 98% rename from persistence-modules/r2dbc/src/test/java/com/baeldung/examples/r2dbc/R2dbcExampleApplicationTests.java rename to persistence-modules/r2dbc/src/test/java/com/baeldung/examples/r2dbc/R2dbcExampleApplicationIntegrationTest.java index 3fb9e24a8e..7c3badc976 100644 --- a/persistence-modules/r2dbc/src/test/java/com/baeldung/examples/r2dbc/R2dbcExampleApplicationTests.java +++ b/persistence-modules/r2dbc/src/test/java/com/baeldung/examples/r2dbc/R2dbcExampleApplicationIntegrationTest.java @@ -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 diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-kafka/pom.xml b/spring-cloud/spring-cloud-stream/spring-cloud-stream-kafka/pom.xml index 3a4cf6c56e..669499efb7 100644 --- a/spring-cloud/spring-cloud-stream/spring-cloud-stream-kafka/pom.xml +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-kafka/pom.xml @@ -8,9 +8,10 @@ Simple Spring Cloud Stream - org.springframework.boot - spring-boot-starter-parent - 2.1.5.RELEASE + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../../parent-boot-2 diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-kinesis/pom.xml b/spring-cloud/spring-cloud-stream/spring-cloud-stream-kinesis/pom.xml index 3817f2747a..bb515fcb36 100644 --- a/spring-cloud/spring-cloud-stream/spring-cloud-stream-kinesis/pom.xml +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-kinesis/pom.xml @@ -7,10 +7,10 @@ spring-cloud-stream-kinesis - org.springframework.boot - spring-boot-starter-parent - 2.1.8.RELEASE - + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../../parent-boot-2 From ae9bc9eef113faec5583d120f34fda8f3f0b7ad6 Mon Sep 17 00:00:00 2001 From: Feraru Bogdan Date: Tue, 30 Jun 2020 00:12:40 +0300 Subject: [PATCH 4/6] [BAEL-4093] Mapping Collections with MapStruct (#9597) Co-authored-by: Bogdan Feraru --- mapstruct/pom.xml | 6 +-- .../mappingCollections/dto/CompanyDTO.java | 25 +++++++++ .../mappingCollections/dto/EmployeeDTO.java | 23 +++++++++ .../dto/EmployeeFullNameDTO.java | 14 +++++ .../mapper/CompanyMapper.java | 11 ++++ .../mapper/CompanyMapperAdderPreferred.java | 12 +++++ .../mapper/EmployeeFullNameMapper.java | 20 ++++++++ .../mapper/EmployeeMapper.java | 19 +++++++ .../mappingCollections/model/Company.java | 16 ++++++ .../mappingCollections/model/Employee.java | 28 ++++++++++ .../CompanyMapperAdderPreferredUnitTest.java | 32 ++++++++++++ .../mapper/CompanyMapperUnitTest.java | 32 ++++++++++++ .../EmployeeFullNameMapperUnitTest.java | 26 ++++++++++ .../mapper/EmployeeMapperUnitTest.java | 51 +++++++++++++++++++ 14 files changed, 312 insertions(+), 3 deletions(-) create mode 100644 mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/dto/CompanyDTO.java create mode 100644 mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/dto/EmployeeDTO.java create mode 100644 mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/dto/EmployeeFullNameDTO.java create mode 100644 mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapper.java create mode 100644 mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapperAdderPreferred.java create mode 100644 mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeFullNameMapper.java create mode 100644 mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeMapper.java create mode 100644 mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/model/Company.java create mode 100644 mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/model/Employee.java create mode 100644 mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapperAdderPreferredUnitTest.java create mode 100644 mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapperUnitTest.java create mode 100644 mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeFullNameMapperUnitTest.java create mode 100644 mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeMapperUnitTest.java diff --git a/mapstruct/pom.xml b/mapstruct/pom.xml index 11c8d9b41e..9fe6ab6485 100644 --- a/mapstruct/pom.xml +++ b/mapstruct/pom.xml @@ -16,7 +16,7 @@ org.mapstruct - mapstruct-jdk8 + mapstruct ${org.mapstruct.version} @@ -71,12 +71,12 @@ - 1.3.0.Final + 1.4.0.Beta1 4.3.4.RELEASE 1.8 1.8 1.18.4 - 3.11.1 + 3.16.1 diff --git a/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/dto/CompanyDTO.java b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/dto/CompanyDTO.java new file mode 100644 index 0000000000..de3571e676 --- /dev/null +++ b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/dto/CompanyDTO.java @@ -0,0 +1,25 @@ +package com.baeldung.mapstruct.mappingCollections.dto; + +import java.util.ArrayList; +import java.util.List; + +public class CompanyDTO { + + private List employees; + + public List getEmployees() { + return employees; + } + + public void setEmployees(List employees) { + this.employees = employees; + } + + public void addEmployee(EmployeeDTO employeeDTO) { + if (employees == null) { + employees = new ArrayList<>(); + } + + employees.add(employeeDTO); + } +} diff --git a/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/dto/EmployeeDTO.java b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/dto/EmployeeDTO.java new file mode 100644 index 0000000000..04e5a1f180 --- /dev/null +++ b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/dto/EmployeeDTO.java @@ -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; + } +} diff --git a/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/dto/EmployeeFullNameDTO.java b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/dto/EmployeeFullNameDTO.java new file mode 100644 index 0000000000..10b97bfce4 --- /dev/null +++ b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/dto/EmployeeFullNameDTO.java @@ -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; + } +} diff --git a/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapper.java b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapper.java new file mode 100644 index 0000000000..5310c0454e --- /dev/null +++ b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapper.java @@ -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); +} diff --git a/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapperAdderPreferred.java b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapperAdderPreferred.java new file mode 100644 index 0000000000..e5cc43074e --- /dev/null +++ b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapperAdderPreferred.java @@ -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); +} diff --git a/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeFullNameMapper.java b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeFullNameMapper.java new file mode 100644 index 0000000000..44d3961f2b --- /dev/null +++ b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeFullNameMapper.java @@ -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 map(List employees); + + default EmployeeFullNameDTO map(Employee employee) { + EmployeeFullNameDTO employeeInfoDTO = new EmployeeFullNameDTO(); + employeeInfoDTO.setFullName(employee.getFirstName() + " " + employee.getLastName()); + + return employeeInfoDTO; + } +} diff --git a/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeMapper.java b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeMapper.java new file mode 100644 index 0000000000..45bf76c5a4 --- /dev/null +++ b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeMapper.java @@ -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 map(List employees); + + Set map(Set employees); + + Map map(Map idEmployeeMap); +} diff --git a/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/model/Company.java b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/model/Company.java new file mode 100644 index 0000000000..f96e0b7aea --- /dev/null +++ b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/model/Company.java @@ -0,0 +1,16 @@ +package com.baeldung.mapstruct.mappingCollections.model; + +import java.util.List; + +public class Company { + + private List employees; + + public List getEmployees() { + return employees; + } + + public void setEmployees(List employees) { + this.employees = employees; + } +} diff --git a/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/model/Employee.java b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/model/Employee.java new file mode 100644 index 0000000000..db6809d53f --- /dev/null +++ b/mapstruct/src/main/java/com/baeldung/mapstruct/mappingCollections/model/Employee.java @@ -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; + } +} diff --git a/mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapperAdderPreferredUnitTest.java b/mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapperAdderPreferredUnitTest.java new file mode 100644 index 0000000000..ad0096f189 --- /dev/null +++ b/mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapperAdderPreferredUnitTest.java @@ -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 employees = result.getEmployees(); + assertThat(employees).hasSize(1); + assertThat(employees.get(0).getFirstName()).isEqualTo("John"); + assertThat(employees.get(0).getLastName()).isEqualTo("Doe"); + } +} \ No newline at end of file diff --git a/mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapperUnitTest.java b/mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapperUnitTest.java new file mode 100644 index 0000000000..a556c88ce5 --- /dev/null +++ b/mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/CompanyMapperUnitTest.java @@ -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 employees = result.getEmployees(); + assertThat(employees).hasSize(1); + assertThat(employees.get(0).getFirstName()).isEqualTo("John"); + assertThat(employees.get(0).getLastName()).isEqualTo("Doe"); + } +} \ No newline at end of file diff --git a/mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeFullNameMapperUnitTest.java b/mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeFullNameMapperUnitTest.java new file mode 100644 index 0000000000..ba010a2bca --- /dev/null +++ b/mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeFullNameMapperUnitTest.java @@ -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 result = employeeMapper.map(Collections.singletonList(employee)); + + assertThat(result).hasSize(1); + assertThat(result.get(0).getFullName()).isEqualTo("John Doe"); + } +} \ No newline at end of file diff --git a/mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeMapperUnitTest.java b/mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeMapperUnitTest.java new file mode 100644 index 0000000000..dfb58252dc --- /dev/null +++ b/mapstruct/src/test/java/com/baeldung/mapstruct/mappingCollections/mapper/EmployeeMapperUnitTest.java @@ -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 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 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 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"); + } +} \ No newline at end of file From eb75cf11fcbb659c2125564875ae881293a87b71 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Mon, 29 Jun 2020 23:13:26 +0200 Subject: [PATCH 5/6] BAEL-4198 - Fix Selenium Testing module (#9611) * BAEL-4198 - Fix Selenium Live Tests * BAEL-4198 Co-authored-by: Jonathan Cook --- testing-modules/selenium-junit-testng/pom.xml | 36 +++++-------- .../baeldung/selenium/SeleniumExample.java | 53 +++++++++++-------- .../selenium/config/SeleniumConfig.java | 22 ++++---- .../selenium/models/BaeldungAbout.java | 6 +-- .../selenium/pages/BaeldungAboutPage.java | 2 +- .../selenium/pages/BaeldungHomePage.java | 6 +-- .../selenium/pages/StartHerePage.java | 4 +- ...a => SeleniumJavaScriptClickLiveTest.java} | 22 ++++---- .../SeleniumCookiesJUnitLiveTest.java | 32 ++++++++--- .../junit/SeleniumWithJUnitLiveTest.java | 25 +++++---- .../SeleniumPageObjectLiveTest.java | 10 ++-- .../testng/SeleniumWithTestNGLiveTest.java | 13 +++-- 12 files changed, 128 insertions(+), 103 deletions(-) rename testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/{SeleniumJavaScriptClickTest.java => SeleniumJavaScriptClickLiveTest.java} (74%) rename testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/{junit => cookies}/SeleniumCookiesJUnitLiveTest.java (80%) rename testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/{junit => pages}/SeleniumPageObjectLiveTest.java (79%) diff --git a/testing-modules/selenium-junit-testng/pom.xml b/testing-modules/selenium-junit-testng/pom.xml index 3734bf72c9..210c2051da 100644 --- a/testing-modules/selenium-junit-testng/pom.xml +++ b/testing-modules/selenium-junit-testng/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 selenium-junit-testng 0.0.1-SNAPSHOT @@ -43,29 +44,18 @@ - src + + + src/main/resources + true + + + src/test/resources + true + + - - - live - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - **/*LiveTest.java - - - - - - - - 6.10 3.4.0 diff --git a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java index c5ad5182ff..b32e51d250 100644 --- a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java +++ b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java @@ -1,14 +1,12 @@ -package main.java.com.baeldung.selenium; - -import main.java.com.baeldung.selenium.config.SeleniumConfig; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.interactions.Actions; +package com.baeldung.selenium; import java.util.List; -import java.util.concurrent.TimeUnit; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.baeldung.selenium.config.SeleniumConfig; public class SeleniumExample { @@ -17,15 +15,18 @@ public class SeleniumExample { public SeleniumExample() { config = new SeleniumConfig(); - config.getDriver().get(url); + config.getDriver() + .get(url); } public void closeWindow() { - this.config.getDriver().close(); + this.config.getDriver() + .close(); } public String getTitle() { - return this.config.getDriver().getTitle(); + return this.config.getDriver() + .getTitle(); } public void getAboutBaeldungPage() { @@ -35,29 +36,35 @@ public class SeleniumExample { } private void closeOverlay() { - List webElementList = this.config.getDriver().findElements(By.tagName("a")); + List webElementList = this.config.getDriver() + .findElements(By.tagName("a")); if (webElementList != null) { webElementList.stream() - .filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))) - .filter(WebElement::isDisplayed) - .findAny() - .ifPresent(WebElement::click); + .filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))) + .filter(WebElement::isDisplayed) + .findAny() + .ifPresent(WebElement::click); } } private void clickAboutLink() { - this.config.getDriver().findElement(By.partialLinkText("About")).click(); + Actions actions = new Actions(config.getDriver()); + WebElement aboutElement = this.config.getDriver() + .findElement(By.id("menu-item-6138")); + + actions.moveToElement(aboutElement).perform(); } private void clickAboutUsLink() { - Actions builder = new Actions(config.getDriver()); - WebElement element = this.config.getDriver().findElement(By.partialLinkText("About Baeldung.")); - builder.moveToElement(element).build().perform(); + WebElement element = this.config.getDriver() + .findElement(By.partialLinkText("About Baeldung.")); + element.click(); } public boolean isAuthorInformationAvailable() { return this.config.getDriver() - .findElement(By.cssSelector("article > .row > div")) - .isDisplayed(); + .getPageSource() + .contains("Hey ! I'm Eugen"); } + } diff --git a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/config/SeleniumConfig.java b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/config/SeleniumConfig.java index c84283b76b..b1b7754648 100644 --- a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/config/SeleniumConfig.java +++ b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/config/SeleniumConfig.java @@ -1,17 +1,14 @@ -package main.java.com.baeldung.selenium.config; +package com.baeldung.selenium.config; + +import java.io.File; +import java.util.concurrent.TimeUnit; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.DesiredCapabilities; -import java.io.File; -import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - public class SeleniumConfig { private WebDriver driver; @@ -19,15 +16,17 @@ public class SeleniumConfig { public SeleniumConfig() { Capabilities capabilities = DesiredCapabilities.firefox(); driver = new FirefoxDriver(capabilities); - driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); + driver.manage() + .timeouts() + .implicitlyWait(5, TimeUnit.SECONDS); } static { System.setProperty("webdriver.gecko.driver", findFile("geckodriver.mac")); } - static private String findFile(String filename) { - String paths[] = {"", "bin/", "target/classes"}; // if you have chromedriver somewhere else on the path, then put it here. + private static String findFile(String filename) { + String[] paths = { "", "bin/", "target/classes" }; // if you have chromedriver somewhere else on the path, then put it here. for (String path : paths) { if (new File(path + filename).exists()) return path + filename; @@ -40,7 +39,8 @@ public class SeleniumConfig { } public void navigateTo(String url) { - driver.navigate().to(url); + driver.navigate() + .to(url); } public void clickElement(WebElement element) { diff --git a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/models/BaeldungAbout.java b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/models/BaeldungAbout.java index 838beb5326..580cbd1f2b 100644 --- a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/models/BaeldungAbout.java +++ b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/models/BaeldungAbout.java @@ -1,7 +1,7 @@ -package main.java.com.baeldung.selenium.models; +package com.baeldung.selenium.models; -import main.java.com.baeldung.selenium.config.SeleniumConfig; -import main.java.com.baeldung.selenium.pages.BaeldungAboutPage; +import com.baeldung.selenium.config.SeleniumConfig; +import com.baeldung.selenium.pages.BaeldungAboutPage; import org.openqa.selenium.support.PageFactory; public class BaeldungAbout { diff --git a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungAboutPage.java b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungAboutPage.java index d33cb76398..064462fc10 100644 --- a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungAboutPage.java +++ b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungAboutPage.java @@ -1,4 +1,4 @@ -package main.java.com.baeldung.selenium.pages; +package com.baeldung.selenium.pages; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; diff --git a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungHomePage.java b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungHomePage.java index 55a8044375..d901bf3c34 100644 --- a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungHomePage.java +++ b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungHomePage.java @@ -1,6 +1,6 @@ -package main.java.com.baeldung.selenium.pages; +package com.baeldung.selenium.pages; -import main.java.com.baeldung.selenium.config.SeleniumConfig; +import com.baeldung.selenium.config.SeleniumConfig; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; @@ -8,7 +8,7 @@ import org.openqa.selenium.support.PageFactory; public class BaeldungHomePage { private SeleniumConfig config; - @FindBy(css=".header--menu > a") + @FindBy(css = ".nav--logo_mobile") private WebElement title; @FindBy(css = ".menu-start-here > a") private WebElement startHere; diff --git a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/StartHerePage.java b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/StartHerePage.java index 4f0ee9edcd..ccc166c351 100644 --- a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/StartHerePage.java +++ b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/StartHerePage.java @@ -1,6 +1,6 @@ -package main.java.com.baeldung.selenium.pages; +package com.baeldung.selenium.pages; -import main.java.com.baeldung.selenium.config.SeleniumConfig; +import com.baeldung.selenium.config.SeleniumConfig; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; diff --git a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/SeleniumJavaScriptClickTest.java b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/SeleniumJavaScriptClickLiveTest.java similarity index 74% rename from testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/SeleniumJavaScriptClickTest.java rename to testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/SeleniumJavaScriptClickLiveTest.java index 6d2ab8ef1f..de519a44fc 100644 --- a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/SeleniumJavaScriptClickTest.java +++ b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/SeleniumJavaScriptClickLiveTest.java @@ -1,4 +1,4 @@ -package java.com.baeldung.selenium.clickusingjavascript; +package com.baeldung.selenium.clickusingjavascript; import org.junit.After; import org.junit.Before; @@ -14,16 +14,18 @@ import org.openqa.selenium.support.ui.WebDriverWait; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -public class SeleniumJavaScriptClickTest { +import java.io.File; + +public class SeleniumJavaScriptClickLiveTest { private WebDriver driver; private WebDriverWait wait; @Before public void setUp() { - System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); + System.setProperty("webdriver.chrome.driver", new File("src/main/resources/chromedriver.mac").getAbsolutePath()); driver = new ChromeDriver(); - wait = new WebDriverWait(driver, 5000); + wait = new WebDriverWait(driver, 20); } @After @@ -37,19 +39,21 @@ public class SeleniumJavaScriptClickTest { String title = driver.getTitle(); assertEquals("Baeldung | Java, Spring and Web Development tutorials", title); - wait.until(ExpectedConditions.elementToBeClickable(By.className("menu-search"))); - WebElement searchButton = driver.findElement(By.className("menu-search")); + wait.until(ExpectedConditions.elementToBeClickable(By.className("nav--menu_item_anchor"))); + WebElement searchButton = driver.findElement(By.className("nav--menu_item_anchor")); clickElement(searchButton); wait.until(ExpectedConditions.elementToBeClickable(By.id("search"))); WebElement searchInput = driver.findElement(By.id("search")); searchInput.sendKeys("Selenium"); - wait.until(ExpectedConditions.elementToBeClickable(By.className("btn-search"))); - WebElement seeSearchResultsButton = driver.findElement(By.className("btn-search")); + wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".btn-search"))); + WebElement seeSearchResultsButton = driver.findElement(By.cssSelector(".btn-search")); clickElement(seeSearchResultsButton); - int seleniumPostsCount = driver.findElements(By.className("post")).size(); + wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("post"))); + int seleniumPostsCount = driver.findElements(By.className("post")) + .size(); assertTrue(seleniumPostsCount > 0); } diff --git a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumCookiesJUnitLiveTest.java b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/cookies/SeleniumCookiesJUnitLiveTest.java similarity index 80% rename from testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumCookiesJUnitLiveTest.java rename to testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/cookies/SeleniumCookiesJUnitLiveTest.java index 0cbbf52454..337e3b85fb 100644 --- a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumCookiesJUnitLiveTest.java +++ b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/cookies/SeleniumCookiesJUnitLiveTest.java @@ -1,4 +1,16 @@ -package test.java.com.baeldung.selenium.junit; +package com.baeldung.selenium.cookies; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; + +import java.io.File; +import java.util.Set; +import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; @@ -9,12 +21,6 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.DesiredCapabilities; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; - public class SeleniumCookiesJUnitLiveTest { private WebDriver driver; @@ -22,11 +28,21 @@ public class SeleniumCookiesJUnitLiveTest { @Before public void setUp() { + System.setProperty("webdriver.gecko.driver", findFile("geckodriver.mac")); + Capabilities capabilities = DesiredCapabilities.firefox(); driver = new FirefoxDriver(capabilities); navUrl = "https://baeldung.com"; driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); - System.setProperty("webdriver.gecko.driver", "geckodriver.exe"); + } + + private static String findFile(String filename) { + String[] paths = { "", "bin/", "target/classes" }; // if you have chromedriver somewhere else on the path, then put it here. + for (String path : paths) { + if (new File(path + filename).exists()) + return path + filename; + } + return ""; } @After diff --git a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java index b1a4149358..1b1035cc6c 100644 --- a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java +++ b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java @@ -1,16 +1,21 @@ -package test.java.com.baeldung.selenium.junit; +package com.baeldung.selenium.junit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; -import main.java.com.baeldung.selenium.SeleniumExample; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import static org.testng.Assert.*; +import com.baeldung.selenium.SeleniumExample; public class SeleniumWithJUnitLiveTest { private static SeleniumExample seleniumExample; - private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials"; + private String expectedTitle = "About Baeldung | Baeldung"; @BeforeClass public static void setUp() { @@ -18,17 +23,17 @@ public class SeleniumWithJUnitLiveTest { } @AfterClass - public static void tearDown() { + public static void tearDown() throws IOException { seleniumExample.closeWindow(); } @Test public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() { - seleniumExample.getAboutBaeldungPage(); - String actualTitle = seleniumExample.getTitle(); - assertNotNull(actualTitle); - assertEquals(expectedTitle, actualTitle); - assertTrue(seleniumExample.isAuthorInformationAvailable()); + seleniumExample.getAboutBaeldungPage(); + String actualTitle = seleniumExample.getTitle(); + assertNotNull(actualTitle); + assertEquals(expectedTitle, actualTitle); + assertTrue(seleniumExample.isAuthorInformationAvailable()); } } diff --git a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumPageObjectLiveTest.java b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/pages/SeleniumPageObjectLiveTest.java similarity index 79% rename from testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumPageObjectLiveTest.java rename to testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/pages/SeleniumPageObjectLiveTest.java index 8493122414..96772821a9 100644 --- a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumPageObjectLiveTest.java +++ b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/pages/SeleniumPageObjectLiveTest.java @@ -1,9 +1,9 @@ -package test.java.com.baeldung.selenium.junit; +package com.baeldung.selenium.pages; -import main.java.com.baeldung.selenium.config.SeleniumConfig; -import main.java.com.baeldung.selenium.models.BaeldungAbout; -import main.java.com.baeldung.selenium.pages.BaeldungHomePage; -import main.java.com.baeldung.selenium.pages.StartHerePage; +import com.baeldung.selenium.config.SeleniumConfig; +import com.baeldung.selenium.models.BaeldungAbout; +import com.baeldung.selenium.pages.BaeldungHomePage; +import com.baeldung.selenium.pages.StartHerePage; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java index 94426edc6d..85fa00c0ab 100644 --- a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java +++ b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java @@ -1,16 +1,19 @@ -package test.java.com.baeldung.selenium.testng; +package com.baeldung.selenium.testng; + +import com.baeldung.selenium.SeleniumExample; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; -import main.java.com.baeldung.selenium.SeleniumExample; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; -import static org.testng.Assert.*; - public class SeleniumWithTestNGLiveTest { private SeleniumExample seleniumExample; - private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials"; + private String expectedTitle = "About Baeldung | Baeldung"; @BeforeSuite public void setUp() { From 750bf1ad37f3ff049eef58c94fe4713a1746f424 Mon Sep 17 00:00:00 2001 From: Azhwani <13301425+azhwani@users.noreply.github.com> Date: Mon, 29 Jun 2020 22:13:53 +0100 Subject: [PATCH 6/6] remove @propertysource (#9612) Co-authored-by: azhwani <> --- .../factory/YamlPropertySourceFactory.java | 25 ------------------- .../yamlmap/pojo/ServerProperties.java | 4 --- .../resources/{server.yml => application.yml} | 0 3 files changed, 29 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/yamlmap/factory/YamlPropertySourceFactory.java rename spring-boot-modules/spring-boot-properties-2/src/main/resources/{server.yml => application.yml} (100%) diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/yamlmap/factory/YamlPropertySourceFactory.java b/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/yamlmap/factory/YamlPropertySourceFactory.java deleted file mode 100644 index e46f7c9cba..0000000000 --- a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/yamlmap/factory/YamlPropertySourceFactory.java +++ /dev/null @@ -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); - } - -} diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/yamlmap/pojo/ServerProperties.java b/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/yamlmap/pojo/ServerProperties.java index 38b44fddc7..9d54daf070 100644 --- a/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/yamlmap/pojo/ServerProperties.java +++ b/spring-boot-modules/spring-boot-properties-2/src/main/java/com/baeldung/properties/yamlmap/pojo/ServerProperties.java @@ -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 { diff --git a/spring-boot-modules/spring-boot-properties-2/src/main/resources/server.yml b/spring-boot-modules/spring-boot-properties-2/src/main/resources/application.yml similarity index 100% rename from spring-boot-modules/spring-boot-properties-2/src/main/resources/server.yml rename to spring-boot-modules/spring-boot-properties-2/src/main/resources/application.yml