Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package com.baeldung.java8;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Java9OptionalsStreamTest {
|
||||
|
||||
private static List<Optional<String>> listOfOptionals = Arrays.asList(Optional.empty(), Optional.of("foo"), Optional.empty(), Optional.of("bar"));
|
||||
|
||||
@Test
|
||||
public void filterOutPresentOptionalsWithFilter() {
|
||||
assertEquals(4, listOfOptionals.size());
|
||||
|
||||
List<String> filteredList = listOfOptionals.stream()
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(2, filteredList.size());
|
||||
assertEquals("foo", filteredList.get(0));
|
||||
assertEquals("bar", filteredList.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterOutPresentOptionalsWithFlatMap() {
|
||||
assertEquals(4, listOfOptionals.size());
|
||||
|
||||
List<String> filteredList = listOfOptionals.stream()
|
||||
.flatMap(o -> o.isPresent() ? Stream.of(o.get()) : Stream.empty())
|
||||
.collect(Collectors.toList());
|
||||
assertEquals(2, filteredList.size());
|
||||
|
||||
assertEquals("foo", filteredList.get(0));
|
||||
assertEquals("bar", filteredList.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterOutPresentOptionalsWithJava9() {
|
||||
assertEquals(4, listOfOptionals.size());
|
||||
|
||||
List<String> filteredList = listOfOptionals.stream()
|
||||
.flatMap(Optional::stream)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(2, filteredList.size());
|
||||
assertEquals("foo", filteredList.get(0));
|
||||
assertEquals("bar", filteredList.get(1));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,18 +18,18 @@ public class ArrayListTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
List<String> xs = LongStream.range(0, 16)
|
||||
List<String> list = LongStream.range(0, 16)
|
||||
.boxed()
|
||||
.map(Long::toHexString)
|
||||
.collect(toCollection(ArrayList::new));
|
||||
stringsToSearch = new ArrayList<>(xs);
|
||||
stringsToSearch.addAll(xs);
|
||||
stringsToSearch = new ArrayList<>(list);
|
||||
stringsToSearch.addAll(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNewArrayList_whenCheckCapacity_thenDefaultValue() {
|
||||
List<String> xs = new ArrayList<>();
|
||||
assertTrue(xs.isEmpty());
|
||||
List<String> list = new ArrayList<>();
|
||||
assertTrue(list.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -37,29 +37,29 @@ public class ArrayListTest {
|
||||
Collection<Integer> numbers =
|
||||
IntStream.range(0, 10).boxed().collect(toSet());
|
||||
|
||||
List<Integer> xs = new ArrayList<>(numbers);
|
||||
assertEquals(10, xs.size());
|
||||
assertTrue(numbers.containsAll(xs));
|
||||
List<Integer> list = new ArrayList<>(numbers);
|
||||
assertEquals(10, list.size());
|
||||
assertTrue(numbers.containsAll(list));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenElement_whenAddToArrayList_thenIsAdded() {
|
||||
List<Long> xs = new ArrayList<>();
|
||||
List<Long> list = new ArrayList<>();
|
||||
|
||||
xs.add(1L);
|
||||
xs.add(2L);
|
||||
xs.add(1, 3L);
|
||||
list.add(1L);
|
||||
list.add(2L);
|
||||
list.add(1, 3L);
|
||||
|
||||
assertThat(Arrays.asList(1L, 3L, 2L), equalTo(xs));
|
||||
assertThat(Arrays.asList(1L, 3L, 2L), equalTo(list));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCollection_whenAddToArrayList_thenIsAdded() {
|
||||
List<Long> xs = new ArrayList<>(Arrays.asList(1L, 2L, 3L));
|
||||
List<Long> list = new ArrayList<>(Arrays.asList(1L, 2L, 3L));
|
||||
LongStream.range(4, 10).boxed()
|
||||
.collect(collectingAndThen(toCollection(ArrayList::new), ys -> xs.addAll(0, ys)));
|
||||
.collect(collectingAndThen(toCollection(ArrayList::new), ys -> list.addAll(0, ys)));
|
||||
|
||||
assertThat(Arrays.asList(4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L), equalTo(xs));
|
||||
assertThat(Arrays.asList(4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L), equalTo(list));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,27 +106,27 @@ public class ArrayListTest {
|
||||
|
||||
@Test
|
||||
public void givenIndex_whenRemove_thenCorrectElementRemoved() {
|
||||
List<Integer> xs = IntStream.range(0, 10).boxed().collect(toCollection(ArrayList::new));
|
||||
Collections.reverse(xs);
|
||||
List<Integer> list = IntStream.range(0, 10).boxed().collect(toCollection(ArrayList::new));
|
||||
Collections.reverse(list);
|
||||
|
||||
xs.remove(0);
|
||||
assertThat(xs.get(0), equalTo(8));
|
||||
list.remove(0);
|
||||
assertThat(list.get(0), equalTo(8));
|
||||
|
||||
xs.remove(Integer.valueOf(0));
|
||||
assertFalse(xs.contains(0));
|
||||
list.remove(Integer.valueOf(0));
|
||||
assertFalse(list.contains(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenListIterator_whenReverseTraversal_thenRetrieveElementsInOppositeOrder() {
|
||||
List<Integer> xs = IntStream.range(0, 10).boxed().collect(toCollection(ArrayList::new));
|
||||
ListIterator<Integer> it = xs.listIterator(xs.size());
|
||||
List<Integer> result = new ArrayList<>(xs.size());
|
||||
List<Integer> list = IntStream.range(0, 10).boxed().collect(toCollection(ArrayList::new));
|
||||
ListIterator<Integer> it = list.listIterator(list.size());
|
||||
List<Integer> result = new ArrayList<>(list.size());
|
||||
while (it.hasPrevious()) {
|
||||
result.add(it.previous());
|
||||
}
|
||||
|
||||
Collections.reverse(xs);
|
||||
assertThat(result, equalTo(xs));
|
||||
Collections.reverse(list);
|
||||
assertThat(result, equalTo(list));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
## Feign Hypermedia Client ##
|
||||
|
||||
This is the implementation of a [spring-hypermedia-api][1] client using Feign.
|
||||
|
||||
[1]: https://github.com/eugenp/spring-hypermedia-api
|
||||
@@ -0,0 +1,99 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>
|
||||
|
||||
<groupId>com.baeldung.feign</groupId>
|
||||
<artifactId>feign-client</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-core</artifactId>
|
||||
<version>9.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-okhttp</artifactId>
|
||||
<version>9.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-gson</artifactId>
|
||||
<version>9.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-slf4j</artifactId>
|
||||
<version>9.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.10</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>1.4.0.RELEASE</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.feign;
|
||||
|
||||
import com.baeldung.feign.clients.BookClient;
|
||||
import feign.Feign;
|
||||
import feign.Logger;
|
||||
import feign.gson.GsonDecoder;
|
||||
import feign.gson.GsonEncoder;
|
||||
import feign.okhttp.OkHttpClient;
|
||||
import feign.slf4j.Slf4jLogger;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class BookControllerFeignClientBuilder {
|
||||
private BookClient bookClient = createClient(BookClient.class,
|
||||
"http://localhost:8081/api/books");
|
||||
|
||||
private static <T> T createClient(Class<T> type, String uri) {
|
||||
return Feign.builder()
|
||||
.client(new OkHttpClient())
|
||||
.encoder(new GsonEncoder())
|
||||
.decoder(new GsonDecoder())
|
||||
.logger(new Slf4jLogger(type))
|
||||
.logLevel(Logger.Level.FULL)
|
||||
.target(type, uri);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.feign.clients;
|
||||
|
||||
import com.baeldung.feign.models.Book;
|
||||
import com.baeldung.feign.models.BookResource;
|
||||
import feign.Headers;
|
||||
import feign.Param;
|
||||
import feign.RequestLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BookClient {
|
||||
@RequestLine("GET /{isbn}")
|
||||
BookResource findByIsbn(@Param("isbn") String isbn);
|
||||
|
||||
@RequestLine("GET")
|
||||
List<BookResource> findAll();
|
||||
|
||||
@RequestLine("POST")
|
||||
@Headers("Content-Type: application/json")
|
||||
void create(Book book);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.feign.models;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Book {
|
||||
private String isbn;
|
||||
private String author;
|
||||
private String title;
|
||||
private String synopsis;
|
||||
private String language;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.feign.models;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BookResource {
|
||||
private Book book;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36}:%n[+] %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.baeldung.feign.clients;
|
||||
|
||||
import com.baeldung.feign.BookControllerFeignClientBuilder;
|
||||
import com.baeldung.feign.models.Book;
|
||||
import com.baeldung.feign.models.BookResource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@Slf4j
|
||||
@RunWith(JUnit4.class)
|
||||
public class BookClientTest {
|
||||
private BookClient bookClient;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
BookControllerFeignClientBuilder feignClientBuilder = new BookControllerFeignClientBuilder();
|
||||
bookClient = feignClientBuilder.getBookClient();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBookClient_shouldRunSuccessfully() throws Exception {
|
||||
List<Book> books = bookClient.findAll().stream()
|
||||
.map(BookResource::getBook)
|
||||
.collect(Collectors.toList());
|
||||
assertTrue(books.size() > 2);
|
||||
log.info("{}", books);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBookClient_shouldFindOneBook() throws Exception {
|
||||
Book book = bookClient.findByIsbn("0151072558").getBook();
|
||||
assertThat(book.getAuthor(), containsString("Orwell"));
|
||||
log.info("{}", book);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBookClient_shouldPostBook() throws Exception {
|
||||
String isbn = UUID.randomUUID().toString();
|
||||
Book book = new Book(isbn, "Me", "It's me!", null, null);
|
||||
bookClient.create(book);
|
||||
|
||||
book = bookClient.findByIsbn(isbn).getBook();
|
||||
assertThat(book.getAuthor(), is("Me"));
|
||||
log.info("{}", book);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE IF NOT EXISTS `department` (
|
||||
|
||||
`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` varchar(20)
|
||||
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=UTF8;
|
||||
|
||||
ALTER TABLE `employee` ADD `dept_id` int AFTER `email`;
|
||||
@@ -23,6 +23,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
|
||||
+23
-5
@@ -15,7 +15,13 @@
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SLF4J - Log4J dependency
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<!--log4j2 dependencies-->
|
||||
<dependency>
|
||||
@@ -28,22 +34,34 @@
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
|
||||
<!--disruptor for log4j2 async logging-->
|
||||
<!--disruptor for log4j2 async logging-->
|
||||
<dependency>
|
||||
<groupId>com.lmax</groupId>
|
||||
<artifactId>disruptor</artifactId>
|
||||
<version>3.3.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SLF4J - Log4J2 dependency
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.6.2</version>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<!--logback dependencies-->
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.1.7</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SLF4J - JCL dependency
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jcl</artifactId>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
-->
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.slf4j;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* To switch between logging frameworks you need only to uncomment needed framework dependencies in pom.xml
|
||||
*/
|
||||
public class Slf4jExample {
|
||||
private static Logger logger = LoggerFactory.getLogger(Slf4jExample.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
logger.debug("Debug log message");
|
||||
logger.info("Info log message");
|
||||
logger.error("Error log message");
|
||||
|
||||
String variable = "Hello John";
|
||||
logger.debug("Printing variable value {} ", variable);
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@
|
||||
<module>deltaspike</module>
|
||||
|
||||
<module>enterprise-patterns</module>
|
||||
<module>feign-client</module>
|
||||
<!-- <module>gatling</module> --> <!-- not meant to run as part of the standard build -->
|
||||
|
||||
<module>gson</module>
|
||||
@@ -129,6 +130,7 @@
|
||||
<module>lombok</module>
|
||||
<module>redis</module>
|
||||
|
||||
<module>wicket</module>
|
||||
<module>xstream</module>
|
||||
<module>java-cassandra</module>
|
||||
</modules>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<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>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>selenium-junit-testng</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>2.53.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.9.10</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,29 @@
|
||||
package main.java.com.baeldung.selenium;
|
||||
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
|
||||
public class SeleniumExample {
|
||||
|
||||
private WebDriver webDriver;
|
||||
private final String url = "http://www.baeldung.com/";
|
||||
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
||||
|
||||
public SeleniumExample() {
|
||||
webDriver = new FirefoxDriver();
|
||||
webDriver.get(url);
|
||||
}
|
||||
|
||||
public void closeWindow() {
|
||||
webDriver.close();
|
||||
}
|
||||
|
||||
public String getActualTitle() {
|
||||
return webDriver.getTitle();
|
||||
}
|
||||
|
||||
public String getExpectedTitle() {
|
||||
return expectedTitle;
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package test.java.com.baeldung.selenium.junit;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import main.java.com.baeldung.selenium.SeleniumExample;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestSeleniumWithJUnit {
|
||||
|
||||
private SeleniumExample seleniumExample;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
seleniumExample = new SeleniumExample();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
seleniumExample.closeWindow();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
||||
String expectedTitle = seleniumExample.getExpectedTitle();
|
||||
String actualTitle = seleniumExample.getActualTitle();
|
||||
assertEquals(actualTitle, expectedTitle);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package test.java.com.baeldung.selenium.testng;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import main.java.com.baeldung.selenium.SeleniumExample;
|
||||
|
||||
import org.testng.annotations.AfterSuite;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class TestSeleniumWithTestNG {
|
||||
|
||||
private SeleniumExample seleniumExample;
|
||||
|
||||
@BeforeSuite
|
||||
public void setUp() {
|
||||
seleniumExample = new SeleniumExample();
|
||||
}
|
||||
|
||||
@AfterSuite
|
||||
public void tearDown() {
|
||||
seleniumExample.closeWindow();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
||||
String expectedTitle = seleniumExample.getExpectedTitle();
|
||||
String actualTitle = seleniumExample.getActualTitle();
|
||||
assertEquals(actualTitle, expectedTitle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.baeldun.selenium.testng;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.testng.annotations.AfterSuite;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class TestSeleniumWithTestNG {
|
||||
|
||||
private WebDriver webDriver;
|
||||
private final String url = "http://www.baeldung.com/";
|
||||
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
||||
|
||||
@BeforeSuite
|
||||
public void setUp() {
|
||||
webDriver = new FirefoxDriver();
|
||||
webDriver.get(url);
|
||||
}
|
||||
|
||||
@AfterSuite
|
||||
public void tearDown() {
|
||||
webDriver.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
||||
String actualTitleReturned = webDriver.getTitle();
|
||||
assertNotNull(actualTitleReturned);
|
||||
assertEquals(expectedTitle, actualTitleReturned);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.selenium.junit;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
|
||||
public class TestSeleniumWithJUnit {
|
||||
|
||||
private WebDriver webDriver;
|
||||
private final String url = "http://www.baeldung.com/";
|
||||
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
webDriver = new FirefoxDriver();
|
||||
webDriver.get(url);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
webDriver.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
||||
String actualTitleReturned = webDriver.getTitle();
|
||||
assertNotNull(actualTitleReturned);
|
||||
assertEquals(expectedTitle, actualTitleReturned);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
user.role=Developer
|
||||
user.password=pass
|
||||
@@ -1 +0,0 @@
|
||||
user.role=User
|
||||
@@ -1,4 +0,0 @@
|
||||
FROM alpine:edge
|
||||
MAINTAINER baeldung.com
|
||||
RUN apk add --no-cache openjdk8
|
||||
COPY files/UnlimitedJCEPolicyJDK8/* /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/
|
||||
@@ -1,41 +0,0 @@
|
||||
version: '2'
|
||||
services:
|
||||
config-server:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.server
|
||||
image: config-server:latest
|
||||
expose:
|
||||
- 8888
|
||||
networks:
|
||||
- spring-cloud-network
|
||||
volumes:
|
||||
- spring-cloud-config-repo:/var/lib/spring-cloud/config-repo
|
||||
logging:
|
||||
driver: json-file
|
||||
config-client:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.client
|
||||
image: config-client:latest
|
||||
entrypoint: /opt/spring-cloud/bin/config-client-entrypoint.sh
|
||||
environment:
|
||||
SPRING_APPLICATION_JSON: '{"spring": {"cloud": {"config": {"uri": "http://config-server:8888"}}}}'
|
||||
expose:
|
||||
- 8080
|
||||
ports:
|
||||
- 8080
|
||||
networks:
|
||||
- spring-cloud-network
|
||||
links:
|
||||
- config-server:config-server
|
||||
depends_on:
|
||||
- config-server
|
||||
logging:
|
||||
driver: json-file
|
||||
networks:
|
||||
spring-cloud-network:
|
||||
driver: bridge
|
||||
volumes:
|
||||
spring-cloud-config-repo:
|
||||
external: true
|
||||
@@ -1,43 +0,0 @@
|
||||
version: '2'
|
||||
services:
|
||||
config-server:
|
||||
container_name: config-server
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.server
|
||||
image: config-server:latest
|
||||
expose:
|
||||
- 8888
|
||||
networks:
|
||||
- spring-cloud-network
|
||||
volumes:
|
||||
- spring-cloud-config-repo:/var/lib/spring-cloud/config-repo
|
||||
logging:
|
||||
driver: json-file
|
||||
config-client:
|
||||
container_name: config-client
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.client
|
||||
image: config-client:latest
|
||||
entrypoint: /opt/spring-cloud/bin/config-client-entrypoint.sh
|
||||
environment:
|
||||
SPRING_APPLICATION_JSON: '{"spring": {"cloud": {"config": {"uri": "http://config-server:8888"}}}}'
|
||||
expose:
|
||||
- 8080
|
||||
ports:
|
||||
- 8080:8080
|
||||
networks:
|
||||
- spring-cloud-network
|
||||
links:
|
||||
- config-server:config-server
|
||||
depends_on:
|
||||
- config-server
|
||||
logging:
|
||||
driver: json-file
|
||||
networks:
|
||||
spring-cloud-network:
|
||||
driver: bridge
|
||||
volumes:
|
||||
spring-cloud-config-repo:
|
||||
external: true
|
||||
@@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring.cloud</groupId>
|
||||
<artifactId>spring-cloud-config</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-config-client</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>spring-cloud-config-client</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
<version>1.1.3.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>1.4.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<outputDirectory>../docker/files</outputDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.baeldung.spring.cloud.config.client;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
public class ConfigClient {
|
||||
@Value("${user.role}")
|
||||
private String role;
|
||||
|
||||
@Value("${user.password}")
|
||||
private String password;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ConfigClient.class, args);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/whoami/{username}", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
public String whoami(@PathVariable("username") String username) {
|
||||
return String.format("Hello %s! You are a(n) %s and your password is '%s'.\n", username, role, password);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
spring.application.name=config-client
|
||||
spring.profiles.active=development
|
||||
spring.cloud.config.uri=http://localhost:${PORT:8888}
|
||||
spring.cloud.config.username=root
|
||||
spring.cloud.config.password=s3cr3t
|
||||
@@ -1,44 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring.cloud</groupId>
|
||||
<artifactId>spring-cloud-config</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-config-server</artifactId>
|
||||
|
||||
<name>spring-cloud-config-server</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-config-server</artifactId>
|
||||
<version>1.1.3.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
<version>1.4.0.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>1.4.0.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<outputDirectory>../docker/files</outputDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user