commit
8af8f88787
4
.gitignore
vendored
4
.gitignore
vendored
@ -85,7 +85,3 @@ transaction.log
|
||||
*-shell.log
|
||||
|
||||
apache-cxf/cxf-aegis/baeldung.xml
|
||||
apache-fop/src/test/resources/input.xml
|
||||
apache-fop/src/test/resources/output_herold.pdf
|
||||
apache-fop/src/test/resources/output_html2fo.pdf
|
||||
apache-fop/src/test/resources/output_jtidy.pdf
|
@ -2,20 +2,17 @@
|
||||
<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>
|
||||
</properties>
|
||||
|
@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
@Disabled
|
||||
class AwsAppSyncApplicationTests {
|
||||
class AwsAppSyncApplicationUnitTest {
|
||||
|
||||
@Test
|
||||
void givenGraphQuery_whenListEvents_thenReturnAllEvents() {
|
@ -1,44 +0,0 @@
|
||||
<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>
|
||||
<groupId>com.baeldung.groovy</groupId>
|
||||
<artifactId>determine-datatype</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmaven</groupId>
|
||||
<artifactId>groovy-maven-plugin</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
<version>2.0.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/org.junit/junit5-engine -->
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit5-engine</artifactId>
|
||||
<version>${junit5.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<junit5.version>5.0.0-ALPHA</junit5.version>
|
||||
</properties>
|
||||
</project>
|
@ -1,14 +0,0 @@
|
||||
package com.baeldung.groovy.determine.datatype
|
||||
|
||||
class Person {
|
||||
|
||||
private int ageAsInt
|
||||
private Double ageAsDouble
|
||||
private String ageAsString
|
||||
|
||||
Person() {}
|
||||
Person(int ageAsInt) { this.ageAsInt = ageAsInt}
|
||||
Person(Double ageAsDouble) { this.ageAsDouble = ageAsDouble}
|
||||
Person(String ageAsString) { this.ageAsString = ageAsString}
|
||||
}
|
||||
class Student extends Person {}
|
@ -1,55 +0,0 @@
|
||||
package com.baeldung.groovy.determine.datatype;
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test;
|
||||
|
||||
public class PersonTest {
|
||||
|
||||
@Test
|
||||
public void givenWhenParameterTypeIsInteger_thenReturnTrue() {
|
||||
Person personObj = new Person(10)
|
||||
Assert.assertTrue(personObj.ageAsInt instanceof Integer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWhenParameterTypeIsDouble_thenReturnTrue() {
|
||||
Person personObj = new Person(10.0)
|
||||
Assert.assertTrue((personObj.ageAsDouble).getClass() == Double)
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWhenParameterTypeIsString_thenReturnTrue() {
|
||||
Person personObj = new Person("10 years")
|
||||
Assert.assertTrue(personObj.ageAsString.class == String)
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenClassName_WhenParameterIsInteger_thenReturnTrue() {
|
||||
Assert.assertTrue(Person.class.getDeclaredField('ageAsInt').type == int.class)
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWhenObjectIsInstanceOfType_thenReturnTrue() {
|
||||
Person personObj = new Person()
|
||||
Assert.assertTrue(personObj instanceof Person)
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWhenInstanceIsOfSubtype_thenReturnTrue() {
|
||||
Student studentObj = new Student()
|
||||
Assert.assertTrue(studentObj in Person)
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenGroovyList_WhenFindClassName_thenReturnTrue() {
|
||||
def ageList = ['ageAsString','ageAsDouble', 10]
|
||||
Assert.assertTrue(ageList.class == ArrayList)
|
||||
Assert.assertTrue(ageList.getClass() == ArrayList)
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenGrooyMap_WhenFindClassName_thenReturnTrue() {
|
||||
def ageMap = [ageAsString: '10 years', ageAsDouble: 10.0]
|
||||
Assert.assertFalse(ageMap.class == LinkedHashMap)
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.baeldung.macaddress;
|
||||
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class GetAllMacAddressesDemo {
|
||||
|
||||
public static void main(String[] args) throws SocketException {
|
||||
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||
while (networkInterfaces.hasMoreElements()) {
|
||||
NetworkInterface ni = networkInterfaces.nextElement();
|
||||
byte[] hardwareAddress = ni.getHardwareAddress();
|
||||
if (hardwareAddress != null) {
|
||||
String[] hexadecimalFormat = new String[hardwareAddress.length];
|
||||
for (int i = 0; i < hardwareAddress.length; i++) {
|
||||
hexadecimalFormat[i] = String.format("%02X", hardwareAddress[i]);
|
||||
}
|
||||
System.out.println(String.join("-", hexadecimalFormat));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.baeldung.macaddress;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class MacAddressUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenNetworkInterface_whenUsingLocalHost_thenGetMacAddress() throws UnknownHostException, SocketException {
|
||||
InetAddress localHost = InetAddress.getLocalHost();
|
||||
NetworkInterface ni = NetworkInterface.getByInetAddress(localHost);
|
||||
byte[] macAddress = ni.getHardwareAddress();
|
||||
assertEquals(6, macAddress.length);
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.baeldung.observer
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
interface IObservable {
|
||||
val observers: ArrayList<IObserver>
|
||||
fun add(observer: IObserver) {
|
||||
observers.add(observer)
|
||||
}
|
||||
|
||||
fun remove(observer: IObserver) {
|
||||
observers.remove(observer)
|
||||
}
|
||||
|
||||
fun sendUpdateEvent() {
|
||||
observers.forEach { it.update() }
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.baeldung.observer
|
||||
|
||||
interface IObserver {
|
||||
fun update()
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.baeldung.observer.delegates
|
||||
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class BaeldungNewsletter {
|
||||
val newestArticleObservers = mutableListOf<(String) -> Unit>()
|
||||
var newestArticleUrl: String by Delegates.observable("") { _, _, newValue ->
|
||||
newestArticleObservers.forEach { it(newValue) }
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package com.baeldung.observer.delegates
|
||||
|
||||
fun main() {
|
||||
val newsletter = BaeldungNewsletter()
|
||||
newsletter.newestArticleObservers.add { newestArticleUrl ->
|
||||
println("New Baeldung article: ${newestArticleUrl}")
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.baeldung.observer.standard
|
||||
|
||||
import com.baeldung.observer.IObservable
|
||||
import com.baeldung.observer.IObserver
|
||||
import java.util.ArrayList
|
||||
|
||||
class BaeldungNewsletter : IObservable {
|
||||
override val observers: ArrayList<IObserver> = ArrayList()
|
||||
var newestArticleUrl = ""
|
||||
set(value) {
|
||||
field = value
|
||||
sendUpdateEvent()
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.baeldung.observer.standard
|
||||
|
||||
import com.baeldung.observer.IObserver
|
||||
|
||||
class BaeldungReader(private var newsletter: BaeldungNewsletter) : IObserver {
|
||||
override fun update() {
|
||||
println("New Baeldung article: ${newsletter.newestArticleUrl}")
|
||||
}
|
||||
}
|
@ -10,10 +10,10 @@
|
||||
<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 -->
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@ -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
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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 {
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
@ -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,16 +42,32 @@ 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");
|
||||
findComponents(jvm2);
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?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"
|
||||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>selenium-junit-testng</artifactId>
|
||||
@ -40,35 +41,30 @@
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>${hamcrest-all.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.yandex.qatools.ashot</groupId>
|
||||
<artifactId>ashot</artifactId>
|
||||
<version>${ashot.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/test/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>live</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*LiveTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
<testng.version>6.10</testng.version>
|
||||
<selenium-java.version>3.4.0</selenium-java.version>
|
||||
<ashot.version>1.5.4</ashot.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -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,7 +36,8 @@ public class SeleniumExample {
|
||||
}
|
||||
|
||||
private void closeOverlay() {
|
||||
List<WebElement> webElementList = this.config.getDriver().findElements(By.tagName("a"));
|
||||
List<WebElement> webElementList = this.config.getDriver()
|
||||
.findElements(By.tagName("a"));
|
||||
if (webElementList != null) {
|
||||
webElementList.stream()
|
||||
.filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title")))
|
||||
@ -46,18 +48,23 @@ public class SeleniumExample {
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
@ -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,7 +23,7 @@ public class SeleniumWithJUnitLiveTest {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
public static void tearDown() throws IOException {
|
||||
seleniumExample.closeWindow();
|
||||
}
|
||||
|
||||
|
@ -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;
|
@ -0,0 +1,85 @@
|
||||
package com.baeldung.selenium.screenshot;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.Capabilities;
|
||||
import org.openqa.selenium.OutputType;
|
||||
import org.openqa.selenium.TakesScreenshot;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||
|
||||
import ru.yandex.qatools.ashot.AShot;
|
||||
import ru.yandex.qatools.ashot.Screenshot;
|
||||
import ru.yandex.qatools.ashot.coordinates.WebDriverCoordsProvider;
|
||||
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;
|
||||
|
||||
public class TakeScreenShotSeleniumLiveTest {
|
||||
|
||||
private static ChromeDriver driver;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
System.setProperty("webdriver.chrome.driver", resolveResourcePath("chromedriver.mac"));
|
||||
|
||||
Capabilities capabilities = DesiredCapabilities.chrome();
|
||||
driver = new ChromeDriver(capabilities);
|
||||
driver.manage()
|
||||
.timeouts()
|
||||
.implicitlyWait(5, TimeUnit.SECONDS);
|
||||
|
||||
driver.get("http://www.google.com/");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws IOException {
|
||||
driver.close();
|
||||
|
||||
System.clearProperty("webdriver.chrome.driver");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGoogleIsLoaded_thenCaptureScreenshot() throws IOException {
|
||||
takeScreenshot(resolveTestResourcePath("google-home.png"));
|
||||
|
||||
assertTrue(new File(resolveTestResourcePath("google-home.png")).exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGoogleIsLoaded_thenCaptureLogo() throws IOException {
|
||||
WebElement logo = driver.findElement(By.id("hplogo"));
|
||||
|
||||
Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000))
|
||||
.coordsProvider(new WebDriverCoordsProvider())
|
||||
.takeScreenshot(driver, logo);
|
||||
|
||||
ImageIO.write(screenshot.getImage(), "jpg", new File(resolveTestResourcePath("google-logo.png")));
|
||||
assertTrue(new File(resolveTestResourcePath("google-logo.png")).exists());
|
||||
}
|
||||
|
||||
public void takeScreenshot(String pathname) throws IOException {
|
||||
File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
|
||||
FileUtils.copyFile(src, new File(pathname));
|
||||
}
|
||||
|
||||
private static String resolveResourcePath(String filename) {
|
||||
File file = new File("src/main/resources/" + filename);
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
private static String resolveTestResourcePath(String filename) {
|
||||
File file = new File("src/test/resources/" + filename);
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
}
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user