Merge branch 'master' of https://github.com/eugenp/tutorials into sanketmeghani-master
This commit is contained in:
+1
-10
@@ -60,12 +60,8 @@
|
||||
<configuration>
|
||||
<source>1.9</source>
|
||||
<target>1.9</target>
|
||||
|
||||
<verbose>true</verbose>
|
||||
<!-- <executable>C:\develop\jdks\jdk-9_ea122\bin\javac</executable>
|
||||
<compilerVersion>1.9</compilerVersion> -->
|
||||
</configuration>
|
||||
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
@@ -85,12 +81,7 @@
|
||||
|
||||
|
||||
<!-- maven plugins -->
|
||||
<!--
|
||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
||||
maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> -->
|
||||
<maven-compiler-plugin.version>3.6-jigsaw-SNAPSHOT</maven-compiler-plugin.version>
|
||||
|
||||
|
||||
<maven-compiler-plugin.version>3.6-jigsaw-SNAPSHOT</maven-compiler-plugin.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
|
||||
<!-- testing -->
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.baeldung.java9;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.java9;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class OptionalToStreamTest {
|
||||
|
||||
@Test
|
||||
public void testOptionalToStream() {
|
||||
Optional<String> op = Optional.ofNullable("String value");
|
||||
Stream<String> strOptionalStream = op.stream();
|
||||
Stream<String> filteredStream = strOptionalStream.filter((str) -> {
|
||||
return str != null && str.startsWith("String");
|
||||
});
|
||||
assertEquals(1, filteredStream.count());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.java9;
|
||||
|
||||
import java.util.Set;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SetExamplesTest {
|
||||
|
||||
@Test
|
||||
public void testUnmutableSet() {
|
||||
Set<String> strKeySet = Set.of("key1", "key2", "key3");
|
||||
try {
|
||||
strKeySet.add("newKey");
|
||||
} catch (UnsupportedOperationException uoe) {
|
||||
}
|
||||
assertEquals(strKeySet.size(), 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayToSet() {
|
||||
Integer[] intArray = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
|
||||
Set<Integer> intSet = Set.of(intArray);
|
||||
assertEquals(intSet.size(), intArray.length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.baeldung.equalshashcode.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ComplexClass {
|
||||
|
||||
private List<?> genericList;
|
||||
private Set<Integer> integerSet;
|
||||
|
||||
public ComplexClass(ArrayList<?> genericArrayList, HashSet<Integer> integerHashSet) {
|
||||
super();
|
||||
this.genericList = genericArrayList;
|
||||
this.integerSet = integerHashSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((genericList == null) ? 0 : genericList.hashCode());
|
||||
result = prime * result + ((integerSet == null) ? 0 : integerSet.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (!(obj instanceof ComplexClass))
|
||||
return false;
|
||||
ComplexClass other = (ComplexClass) obj;
|
||||
if (genericList == null) {
|
||||
if (other.genericList != null)
|
||||
return false;
|
||||
} else if (!genericList.equals(other.genericList))
|
||||
return false;
|
||||
if (integerSet == null) {
|
||||
if (other.integerSet != null)
|
||||
return false;
|
||||
} else if (!integerSet.equals(other.integerSet))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected List<?> getGenericList() {
|
||||
return genericList;
|
||||
}
|
||||
|
||||
protected void setGenericArrayList(List<?> genericList) {
|
||||
this.genericList = genericList;
|
||||
}
|
||||
|
||||
protected Set<Integer> getIntegerSet() {
|
||||
return integerSet;
|
||||
}
|
||||
|
||||
protected void setIntegerSet(Set<Integer> integerSet) {
|
||||
this.integerSet = integerSet;
|
||||
}
|
||||
}
|
||||
-2
@@ -11,13 +11,11 @@ public class Rectangle extends Shape {
|
||||
|
||||
@Override
|
||||
public double area() {
|
||||
// A = w * l
|
||||
return width * length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double perimeter() {
|
||||
// P = 2(w + l)
|
||||
return 2 * (width + length);
|
||||
}
|
||||
|
||||
+2
-3
@@ -22,11 +22,10 @@ public class ComplexClassTest {
|
||||
strArrayListD.add("pqr");
|
||||
ComplexClass dObject = new ComplexClass(strArrayListD, new HashSet<Integer>(45, 67));
|
||||
|
||||
// equals()
|
||||
Assert.assertTrue(aObject.equals(bObject) && bObject.equals(aObject));
|
||||
// hashCode()
|
||||
|
||||
Assert.assertTrue(aObject.hashCode() == bObject.hashCode());
|
||||
// non-equal objects are not equals() and have different hashCode()
|
||||
|
||||
Assert.assertFalse(aObject.equals(dObject));
|
||||
Assert.assertFalse(aObject.hashCode() == dObject.hashCode());
|
||||
}
|
||||
+2
-3
@@ -12,11 +12,10 @@ public class PrimitiveClassTest {
|
||||
PrimitiveClass bObject = new PrimitiveClass(false, 2);
|
||||
PrimitiveClass dObject = new PrimitiveClass(true, 2);
|
||||
|
||||
// equals()
|
||||
Assert.assertTrue(aObject.equals(bObject) && bObject.equals(aObject));
|
||||
// hashCode()
|
||||
|
||||
Assert.assertTrue(aObject.hashCode() == bObject.hashCode());
|
||||
// non-equal objects are not equals() and have different hashCode()
|
||||
|
||||
Assert.assertFalse(aObject.equals(dObject));
|
||||
Assert.assertFalse(aObject.hashCode() == dObject.hashCode());
|
||||
}
|
||||
+2
-3
@@ -15,11 +15,10 @@ public class SquareClassTest {
|
||||
|
||||
Square dObject = new Square(20, Color.BLUE);
|
||||
|
||||
// equals()
|
||||
Assert.assertTrue(aObject.equals(bObject) && bObject.equals(aObject));
|
||||
// hashCode()
|
||||
|
||||
Assert.assertTrue(aObject.hashCode() == bObject.hashCode());
|
||||
// non-equal objects are not equals() and have different hashCode()
|
||||
|
||||
Assert.assertFalse(aObject.equals(dObject));
|
||||
Assert.assertFalse(aObject.hashCode() == dObject.hashCode());
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package org.baeldung.equalshashcode.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ComplexClass {
|
||||
|
||||
private ArrayList<?> genericArrayList;
|
||||
private HashSet<Integer> integerHashSet;
|
||||
|
||||
public ComplexClass(ArrayList<?> genericArrayList, HashSet<Integer> integerHashSet) {
|
||||
super();
|
||||
this.genericArrayList = genericArrayList;
|
||||
this.integerHashSet = integerHashSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((genericArrayList == null) ? 0 : genericArrayList.hashCode());
|
||||
result = prime * result + ((integerHashSet == null) ? 0 : integerHashSet.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (!(obj instanceof ComplexClass))
|
||||
return false;
|
||||
ComplexClass other = (ComplexClass) obj;
|
||||
if (genericArrayList == null) {
|
||||
if (other.genericArrayList != null)
|
||||
return false;
|
||||
} else if (!genericArrayList.equals(other.genericArrayList))
|
||||
return false;
|
||||
if (integerHashSet == null) {
|
||||
if (other.integerHashSet != null)
|
||||
return false;
|
||||
} else if (!integerHashSet.equals(other.integerHashSet))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected ArrayList<?> getGenericArrayList() {
|
||||
return genericArrayList;
|
||||
}
|
||||
|
||||
protected void setGenericArrayList(ArrayList<?> genericArrayList) {
|
||||
this.genericArrayList = genericArrayList;
|
||||
}
|
||||
|
||||
protected HashSet<Integer> getIntegerHashSet() {
|
||||
return integerHashSet;
|
||||
}
|
||||
|
||||
protected void setIntegerHashSet(HashSet<Integer> integerHashSet) {
|
||||
this.integerHashSet = integerHashSet;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
=========
|
||||
|
||||
## ElasticSearch
|
||||
|
||||
### Relevant Articles:
|
||||
- [A Guide to ElasticSearch](http://www.baeldung.com/????????)
|
||||
@@ -1,35 +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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>elasticsearch</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
<version>2.3.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+6
-13
@@ -22,24 +22,17 @@ public class FrontControllerServlet extends HttpServlet {
|
||||
|
||||
private FrontCommand getCommand(HttpServletRequest request) {
|
||||
try {
|
||||
return (FrontCommand) getCommandClass(request)
|
||||
.asSubclass(FrontCommand.class)
|
||||
.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to get command!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Class getCommandClass(HttpServletRequest request) {
|
||||
try {
|
||||
return Class.forName(
|
||||
Class type = Class.forName(
|
||||
String.format(
|
||||
"com.baeldung.enterprise.patterns.front.controller.commands.%sCommand",
|
||||
request.getParameter("command")
|
||||
)
|
||||
);
|
||||
} catch (ClassNotFoundException e) {
|
||||
return UnknownCommand.class;
|
||||
return (FrontCommand) type
|
||||
.asSubclass(FrontCommand.class)
|
||||
.newInstance();
|
||||
} catch (Exception e) {
|
||||
return new UnknownCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-32
@@ -1,40 +1,15 @@
|
||||
package com.baeldung.enterprise.patterns.front.controller.data;
|
||||
|
||||
public class Book {
|
||||
private String author;
|
||||
private String title;
|
||||
private Double price;
|
||||
public interface Book {
|
||||
String getAuthor();
|
||||
|
||||
public Book() {
|
||||
}
|
||||
void setAuthor(String author);
|
||||
|
||||
public Book(String author, String title, Double price) {
|
||||
this.author = author;
|
||||
this.title = title;
|
||||
this.price = price;
|
||||
}
|
||||
String getTitle();
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
void setTitle(String title);
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
Double getPrice();
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(Double price) {
|
||||
this.price = price;
|
||||
}
|
||||
void setPrice(Double price);
|
||||
}
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.baeldung.enterprise.patterns.front.controller.data;
|
||||
|
||||
public class BookImpl implements Book {
|
||||
private String author;
|
||||
private String title;
|
||||
private Double price;
|
||||
|
||||
public BookImpl() {
|
||||
}
|
||||
|
||||
public BookImpl(String author, String title, Double price) {
|
||||
this.author = author;
|
||||
this.title = title;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrice(Double price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,8 +3,8 @@ package com.baeldung.enterprise.patterns.front.controller.data;
|
||||
public interface Bookshelf {
|
||||
|
||||
default void init() {
|
||||
add(new Book("Wilson, Robert Anton & Shea, Robert", "Illuminati", 9.99));
|
||||
add(new Book("Fowler, Martin", "Patterns of Enterprise Application Architecture", 27.88));
|
||||
add(new BookImpl("Wilson, Robert Anton & Shea, Robert", "Illuminati", 9.99));
|
||||
add(new BookImpl("Fowler, Martin", "Patterns of Enterprise Application Architecture", 27.88));
|
||||
}
|
||||
|
||||
Bookshelf getInstance();
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 5.2 KiB |
+1
-1
@@ -1,5 +1,5 @@
|
||||
@startuml
|
||||
|
||||
scale 1.5
|
||||
class Handler {
|
||||
doGet
|
||||
doPost
|
||||
|
||||
+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);
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,6 @@
|
||||
<module>spring-hibernate3</module>
|
||||
<module>spring-hibernate4</module>
|
||||
<module>spring-jpa</module>
|
||||
<module>spring-jpa-jndi</module>
|
||||
<module>spring-katharsis</module>
|
||||
<module>spring-mockito</module>
|
||||
<module>spring-mvc-java</module>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user