From f5c4e3af74da4a636e558615a20ba0d366698ad5 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Sun, 20 Jan 2019 00:08:52 -0500 Subject: [PATCH 001/134] BAEL-2339 || ResultSet Demo BAEL-2339 || ResultSet Demo --- .../main/java/com/baeldung/jdbc/Employee.java | 6 +- .../com/baeldung/jdbc/ResultSetLiveTest.java | 325 ++++++++++++++++++ 2 files changed, 330 insertions(+), 1 deletion(-) create mode 100644 persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java diff --git a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java index 749855ca3b..8f3fce0378 100644 --- a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java +++ b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java @@ -47,5 +47,9 @@ public class Employee { public void setPosition(String position) { this.position = position; } - + + @Override + public boolean equals(Object obj) { + return this.getId() == ((Employee) obj).getId(); + } } diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java new file mode 100644 index 0000000000..369d5e9222 --- /dev/null +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -0,0 +1,325 @@ +package com.baeldung.jdbc; + +import static org.junit.Assert.assertEquals; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ResultSetLiveTest { + + private static final Logger logger = Logger.getLogger(ResultSetLiveTest.class); + + private final Employee expectedEmployee1 = new Employee(1, "John", 1000.0, "Developer"); + + private final Employee updatedEmployee1 = new Employee(1, "John", 1100.0, "Developer"); + + private final Employee expectedEmployee2 = new Employee(2, "Chris", 925.0, "DBA"); + + private final int rowCount = 2; + + private static Connection dbConnection; + + @BeforeClass + public static void setup() throws ClassNotFoundException, SQLException { + Class.forName("com.mysql.cj.jdbc.Driver"); + dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB?noAccessToProcedureBodies=true", "user1", "pass"); + String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)"; + try (Statement stmt = dbConnection.createStatement()) { + stmt.execute(tableSql); + try (PreparedStatement pstmt = dbConnection.prepareStatement("INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) { + pstmt.executeUpdate(); + } + } + } + + @Test + public void givenDbConnectionA_whenARetreiveByColumnNames_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } + + assertEquals("Employee information retreived by column names.", expectedEmployee1, employee); + } + + @Test + public void givenDbConnectionB_whenBRetreiveByColumnIds_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + Integer empId = rs.getInt(1); + String name = rs.getString(2); + String position = rs.getString(3); + Double salary = rs.getDouble(4); + employee = new Employee(empId, name, salary, position); + } + } + + assertEquals("Employee information retreived by column ids.", employee, expectedEmployee1); + } + + @Test + public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException { + int rowCount = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.moveToInsertRow(); + rs.updateString("name", "Venkat"); + rs.updateString("position", "DBA"); + rs.updateDouble("salary", 925.0); + rs.insertRow(); + rs.moveToCurrentRow(); + rs.last(); + rowCount = rs.getRow(); + } + + assertEquals("Row Count after inserting a row", rowCount, 2); + } + + private Employee populateResultSet(ResultSet rs) throws SQLException { + Employee employee; + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + return employee; + } + + @Test + public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { + int numOfRows = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.last(); + numOfRows = rs.getRow(); + } + + assertEquals("Num of rows", numOfRows, rowCount); + } + + @Test + public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { + Employee secondEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.absolute(2); + secondEmployee = populateResultSet(rs); + } + + assertEquals("Absolute navigation", secondEmployee, expectedEmployee2); + } + + @Test + public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException { + Employee secondEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.last(); + secondEmployee = populateResultSet(rs); + } + + assertEquals("Using Last", secondEmployee, expectedEmployee2); + } + + @Test + public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { + Employee firstEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.beforeFirst(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.first(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + while (rs.previous()) { + Employee employee = populateResultSet(rs); + } + rs.afterLast(); + while (rs.previous()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + while (rs.previous()) { + firstEmployee = populateResultSet(rs); + } + } + + assertEquals("Several Navigation Options", firstEmployee, updatedEmployee1); + } + + @Test + public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { + int numOfRows = 0; + dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT)) { + dbConnection.setAutoCommit(false); + pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); + ResultSet rs = pstmt.executeQuery("select * from employees"); + dbConnection.commit(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + numOfRows = rs.getRow(); + } + + assertEquals("Inserted using close cursor after commit", numOfRows, 3); + } + + @Test + public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { + int numOfRows = 0; + try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT)) { + dbConnection.setAutoCommit(false); + pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); + ResultSet rs = pstmt.executeQuery("select * from employees"); + dbConnection.commit(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + numOfRows = rs.getRow(); + } + + assertEquals("Inserted using hold cursor after commit", numOfRows, 4); + } + + @Test + public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { + int numOfRows = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.absolute(3); + rs.deleteRow(); + rs.last(); + numOfRows = rs.getRow(); + } + + assertEquals("Deleted row", numOfRows, 3); + } + + @Test + public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + rs.updateDouble("salary", 1100.0); + rs.updateRow(); + rs.refreshRow(); + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } + + assertEquals("Employee information updated successfully.", employee, updatedEmployee1); + } + + @Test + public void givenDbConnectionE_whenDBMetaInfo_thenCorrect() throws SQLException { + DatabaseMetaData dbmd = dbConnection.getMetaData(); + boolean supportsTypeForward = dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY); + boolean supportsTypeScrollSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); + boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); + boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); + boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollInSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + boolean concurrency4TypeScrollSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); + int rsHoldability = dbmd.getResultSetHoldability(); + + assertEquals("checking scroll sensitivity and concur updates : ", concurrency4TypeScrollInSensitiveNConcurUpdatable, true); + } + + @Test + public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException { + int columnCount = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + ResultSetMetaData metaData = rs.getMetaData(); + columnCount = metaData.getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + String catalogName = metaData.getCatalogName(i); + String className = metaData.getColumnClassName(i); + String label = metaData.getColumnLabel(i); + String name = metaData.getColumnName(i); + String typeName = metaData.getColumnTypeName(i); + Integer type = metaData.getColumnType(i); + String tableName = metaData.getTableName(i); + String schemaName = metaData.getSchemaName(i); + boolean isAutoIncrement = metaData.isAutoIncrement(i); + boolean isCaseSensitive = metaData.isCaseSensitive(i); + boolean isCurrency = metaData.isCurrency(i); + boolean isDefiniteWritable = metaData.isDefinitelyWritable(i); + boolean isReadOnly = metaData.isReadOnly(i); + boolean isSearchable = metaData.isSearchable(i); + boolean isReadable = metaData.isReadOnly(i); + boolean isSigned = metaData.isSigned(i); + boolean isWritable = metaData.isWritable(i); + int nullable = metaData.isNullable(i); + } + } + + assertEquals("column count", columnCount, 4); + } + + @Test + public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { + PreparedStatement pstmt = null; + ResultSet rs = null; + List listOfEmployees = new ArrayList(); + try { + pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + pstmt.setFetchSize(2); + rs = pstmt.executeQuery(); + rs.setFetchSize(1); + while (rs.next()) { + Employee employee = populateResultSet(rs); + listOfEmployees.add(employee); + } + } catch (Exception e) { + throw e; + } finally { + if (rs != null) + rs.close(); + if (pstmt != null) + pstmt.close(); + } + + assertEquals(listOfEmployees.size(), 3); + } + + @AfterClass + public static void closeConnection() throws SQLException { + PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + deleteStmt.execute(); + dbConnection.close(); + } +} From eb8f0cf66c5464eb6664731477305d9ea16ffd81 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Tue, 22 Jan 2019 02:20:08 -0500 Subject: [PATCH 002/134] Fixed unit tests and equals method for ResultSetLiveTest --- .../main/java/com/baeldung/jdbc/Employee.java | 98 ++-- .../com/baeldung/jdbc/ResultSetLiveTest.java | 551 +++++++++--------- 2 files changed, 344 insertions(+), 305 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java index 8f3fce0378..88af4902b5 100644 --- a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java +++ b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java @@ -1,55 +1,71 @@ package com.baeldung.jdbc; +import java.util.Objects; + public class Employee { - private int id; - private String name; - private String position; - private double salary; + private int id; + private String name; + private String position; + private double salary; - public Employee() { - } + public Employee() { + } - public Employee(int id, String name, double salary, String position) { - this.id = id; - this.name = name; - this.salary = salary; - this.position = position; - } + public Employee(int id, String name, double salary, String position) { + this.id = id; + this.name = name; + this.salary = salary; + this.position = position; + } - public int getId() { - return id; - } + public int getId() { + return id; + } - public void setId(int id) { - this.id = id; - } + public void setId(int id) { + this.id = id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public double getSalary() { - return salary; - } + public double getSalary() { + return salary; + } - public void setSalary(double salary) { - this.salary = salary; - } + public void setSalary(double salary) { + this.salary = salary; + } - public String getPosition() { - return position; - } + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + @Override + public int hashCode() { + return Objects.hash(id, name, position, salary); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Employee other = (Employee) obj; + return id == other.id && Objects.equals(name, other.name) && Objects.equals(position, other.position) + && Double.doubleToLongBits(salary) == Double.doubleToLongBits(other.salary); + } - public void setPosition(String position) { - this.position = position; - } - - @Override - public boolean equals(Object obj) { - return this.getId() == ((Employee) obj).getId(); - } } diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java index 369d5e9222..553c7f9919 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -23,303 +23,326 @@ import org.junit.runners.MethodSorters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ResultSetLiveTest { - private static final Logger logger = Logger.getLogger(ResultSetLiveTest.class); + private static final Logger logger = Logger.getLogger(ResultSetLiveTest.class); - private final Employee expectedEmployee1 = new Employee(1, "John", 1000.0, "Developer"); + private final Employee expectedEmployee1 = new Employee(1, "John", 1000.0, "Developer"); - private final Employee updatedEmployee1 = new Employee(1, "John", 1100.0, "Developer"); + private final Employee updatedEmployee1 = new Employee(1, "John", 1100.0, "Developer"); - private final Employee expectedEmployee2 = new Employee(2, "Chris", 925.0, "DBA"); + private final Employee expectedEmployee2 = new Employee(2, "Chris", 925.0, "DBA"); - private final int rowCount = 2; + private final int rowCount = 2; - private static Connection dbConnection; + private static Connection dbConnection; - @BeforeClass - public static void setup() throws ClassNotFoundException, SQLException { - Class.forName("com.mysql.cj.jdbc.Driver"); - dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB?noAccessToProcedureBodies=true", "user1", "pass"); - String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)"; - try (Statement stmt = dbConnection.createStatement()) { - stmt.execute(tableSql); - try (PreparedStatement pstmt = dbConnection.prepareStatement("INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) { - pstmt.executeUpdate(); - } - } - } + @BeforeClass + public static void setup() throws ClassNotFoundException, SQLException { + Class.forName("com.mysql.cj.jdbc.Driver"); + dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB?noAccessToProcedureBodies=true", + "user1", "pass"); + String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)"; + try (Statement stmt = dbConnection.createStatement()) { + stmt.execute(tableSql); + try (PreparedStatement pstmt = dbConnection.prepareStatement( + "INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) { + pstmt.executeUpdate(); + } + } + } - @Test - public void givenDbConnectionA_whenARetreiveByColumnNames_thenCorrect() throws SQLException { - Employee employee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - String name = rs.getString("name"); - Integer empId = rs.getInt("emp_id"); - Double salary = rs.getDouble("salary"); - String position = rs.getString("position"); - employee = new Employee(empId, name, salary, position); - } - } + @Test + public void givenDbConnectionA_whenARetreiveByColumnNames_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); + ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } - assertEquals("Employee information retreived by column names.", expectedEmployee1, employee); - } + assertEquals("Employee information retreived by column names.", expectedEmployee1, employee); + } - @Test - public void givenDbConnectionB_whenBRetreiveByColumnIds_thenCorrect() throws SQLException { - Employee employee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - Integer empId = rs.getInt(1); - String name = rs.getString(2); - String position = rs.getString(3); - Double salary = rs.getDouble(4); - employee = new Employee(empId, name, salary, position); - } - } + @Test + public void givenDbConnectionB_whenBRetreiveByColumnIds_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); + ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + Integer empId = rs.getInt(1); + String name = rs.getString(2); + String position = rs.getString(3); + Double salary = rs.getDouble(4); + employee = new Employee(empId, name, salary, position); + } + } - assertEquals("Employee information retreived by column ids.", employee, expectedEmployee1); - } + assertEquals("Employee information retreived by column ids.", expectedEmployee1, employee); + } - @Test - public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException { - int rowCount = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.moveToInsertRow(); - rs.updateString("name", "Venkat"); - rs.updateString("position", "DBA"); - rs.updateDouble("salary", 925.0); - rs.insertRow(); - rs.moveToCurrentRow(); - rs.last(); - rowCount = rs.getRow(); - } + @Test + public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException { + int rowCount = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.moveToInsertRow(); + rs.updateString("name", "Venkat"); + rs.updateString("position", "DBA"); + rs.updateDouble("salary", 925.0); + rs.insertRow(); + rs.moveToCurrentRow(); + rs.last(); + rowCount = rs.getRow(); + } - assertEquals("Row Count after inserting a row", rowCount, 2); - } + assertEquals("Row Count after inserting a row", 2, rowCount); + } - private Employee populateResultSet(ResultSet rs) throws SQLException { - Employee employee; - String name = rs.getString("name"); - Integer empId = rs.getInt("emp_id"); - Double salary = rs.getDouble("salary"); - String position = rs.getString("position"); - employee = new Employee(empId, name, salary, position); - return employee; - } + private Employee populateResultSet(ResultSet rs) throws SQLException { + Employee employee; + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + return employee; + } - @Test - public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { - int numOfRows = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { + int numOfRows = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Num of rows", numOfRows, rowCount); - } + assertEquals("Num of rows", rowCount, numOfRows); + } - @Test - public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { - Employee secondEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.absolute(2); - secondEmployee = populateResultSet(rs); - } + @Test + public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { + Employee secondEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.absolute(2); + secondEmployee = populateResultSet(rs); + } - assertEquals("Absolute navigation", secondEmployee, expectedEmployee2); - } + assertEquals("Absolute navigation", expectedEmployee2, secondEmployee); + } - @Test - public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException { - Employee secondEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.last(); - secondEmployee = populateResultSet(rs); - } + @Test + public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException { + Employee secondEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.last(); + secondEmployee = populateResultSet(rs); + } - assertEquals("Using Last", secondEmployee, expectedEmployee2); - } + assertEquals("Using Last", expectedEmployee2, secondEmployee); + } - @Test - public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { - Employee firstEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.beforeFirst(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.first(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - while (rs.previous()) { - Employee employee = populateResultSet(rs); - } - rs.afterLast(); - while (rs.previous()) { - Employee employee = populateResultSet(rs); - } - rs.last(); - while (rs.previous()) { - firstEmployee = populateResultSet(rs); - } - } + @Test + public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { + Employee firstEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.beforeFirst(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.first(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + while (rs.previous()) { + Employee employee = populateResultSet(rs); + } + rs.afterLast(); + while (rs.previous()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + while (rs.previous()) { + firstEmployee = populateResultSet(rs); + } + } - assertEquals("Several Navigation Options", firstEmployee, updatedEmployee1); - } + assertEquals("Several Navigation Options", updatedEmployee1, firstEmployee); + } - @Test - public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { - int numOfRows = 0; - dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); - try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT)) { - dbConnection.setAutoCommit(false); - pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); - ResultSet rs = pstmt.executeQuery("select * from employees"); - dbConnection.commit(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { + int numOfRows = 0; + dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, + ResultSet.CLOSE_CURSORS_AT_COMMIT)) { + dbConnection.setAutoCommit(false); + pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); + ResultSet rs = pstmt.executeQuery("select * from employees"); + dbConnection.commit(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Inserted using close cursor after commit", numOfRows, 3); - } + assertEquals("Inserted using close cursor after commit", 3, numOfRows); + } - @Test - public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { - int numOfRows = 0; - try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT)) { - dbConnection.setAutoCommit(false); - pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); - ResultSet rs = pstmt.executeQuery("select * from employees"); - dbConnection.commit(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { + int numOfRows = 0; + try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, + ResultSet.HOLD_CURSORS_OVER_COMMIT)) { + dbConnection.setAutoCommit(false); + pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); + ResultSet rs = pstmt.executeQuery("select * from employees"); + dbConnection.commit(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Inserted using hold cursor after commit", numOfRows, 4); - } + assertEquals("Inserted using hold cursor after commit", 4, numOfRows); + } - @Test - public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { - int numOfRows = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.absolute(3); - rs.deleteRow(); - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { + int numOfRows = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.absolute(3); + rs.deleteRow(); + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Deleted row", numOfRows, 3); - } + assertEquals("Deleted row", 3, numOfRows); + } - @Test - public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException { - Employee employee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - rs.updateDouble("salary", 1100.0); - rs.updateRow(); - rs.refreshRow(); - String name = rs.getString("name"); - Integer empId = rs.getInt("emp_id"); - Double salary = rs.getDouble("salary"); - String position = rs.getString("position"); - employee = new Employee(empId, name, salary, position); - } - } + @Test + public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + rs.updateDouble("salary", 1100.0); + rs.updateRow(); + rs.refreshRow(); + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } - assertEquals("Employee information updated successfully.", employee, updatedEmployee1); - } + assertEquals("Employee information updated successfully.", updatedEmployee1, employee); + } - @Test - public void givenDbConnectionE_whenDBMetaInfo_thenCorrect() throws SQLException { - DatabaseMetaData dbmd = dbConnection.getMetaData(); - boolean supportsTypeForward = dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY); - boolean supportsTypeScrollSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); - boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); - boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); - boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); - boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); - boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); - boolean concurrency4TypeScrollInSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); - boolean concurrency4TypeScrollSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); - boolean concurrency4TypeScrollSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); - int rsHoldability = dbmd.getResultSetHoldability(); + @Test + public void givenDbConnectionE_whenDBMetaInfo_thenCorrect() throws SQLException { + DatabaseMetaData dbmd = dbConnection.getMetaData(); + boolean supportsTypeForward = dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY); + boolean supportsTypeScrollSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); + boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); + boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); + boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_READ_ONLY); + boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd + .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollInSensitiveNConcurReadOnly = dbmd + .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + boolean concurrency4TypeScrollSensitiveNConcurUpdatable = dbmd + .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollSensitiveNConcurReadOnly = dbmd + .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); + int rsHoldability = dbmd.getResultSetHoldability(); - assertEquals("checking scroll sensitivity and concur updates : ", concurrency4TypeScrollInSensitiveNConcurUpdatable, true); - } + assertEquals("checking scroll sensitivity and concur updates : ", true, + concurrency4TypeScrollInSensitiveNConcurUpdatable); + } - @Test - public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException { - int columnCount = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - ResultSetMetaData metaData = rs.getMetaData(); - columnCount = metaData.getColumnCount(); - for (int i = 1; i <= columnCount; i++) { - String catalogName = metaData.getCatalogName(i); - String className = metaData.getColumnClassName(i); - String label = metaData.getColumnLabel(i); - String name = metaData.getColumnName(i); - String typeName = metaData.getColumnTypeName(i); - Integer type = metaData.getColumnType(i); - String tableName = metaData.getTableName(i); - String schemaName = metaData.getSchemaName(i); - boolean isAutoIncrement = metaData.isAutoIncrement(i); - boolean isCaseSensitive = metaData.isCaseSensitive(i); - boolean isCurrency = metaData.isCurrency(i); - boolean isDefiniteWritable = metaData.isDefinitelyWritable(i); - boolean isReadOnly = metaData.isReadOnly(i); - boolean isSearchable = metaData.isSearchable(i); - boolean isReadable = metaData.isReadOnly(i); - boolean isSigned = metaData.isSigned(i); - boolean isWritable = metaData.isWritable(i); - int nullable = metaData.isNullable(i); - } - } + @Test + public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException { + int columnCount = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + ResultSetMetaData metaData = rs.getMetaData(); + columnCount = metaData.getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + String catalogName = metaData.getCatalogName(i); + String className = metaData.getColumnClassName(i); + String label = metaData.getColumnLabel(i); + String name = metaData.getColumnName(i); + String typeName = metaData.getColumnTypeName(i); + Integer type = metaData.getColumnType(i); + String tableName = metaData.getTableName(i); + String schemaName = metaData.getSchemaName(i); + boolean isAutoIncrement = metaData.isAutoIncrement(i); + boolean isCaseSensitive = metaData.isCaseSensitive(i); + boolean isCurrency = metaData.isCurrency(i); + boolean isDefiniteWritable = metaData.isDefinitelyWritable(i); + boolean isReadOnly = metaData.isReadOnly(i); + boolean isSearchable = metaData.isSearchable(i); + boolean isReadable = metaData.isReadOnly(i); + boolean isSigned = metaData.isSigned(i); + boolean isWritable = metaData.isWritable(i); + int nullable = metaData.isNullable(i); + } + } - assertEquals("column count", columnCount, 4); - } + assertEquals("column count", 4, columnCount); + } - @Test - public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { - PreparedStatement pstmt = null; - ResultSet rs = null; - List listOfEmployees = new ArrayList(); - try { - pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - pstmt.setFetchSize(2); - rs = pstmt.executeQuery(); - rs.setFetchSize(1); - while (rs.next()) { - Employee employee = populateResultSet(rs); - listOfEmployees.add(employee); - } - } catch (Exception e) { - throw e; - } finally { - if (rs != null) - rs.close(); - if (pstmt != null) - pstmt.close(); - } - - assertEquals(listOfEmployees.size(), 3); - } + @Test + public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { + PreparedStatement pstmt = null; + ResultSet rs = null; + List listOfEmployees = new ArrayList(); + try { + pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_READ_ONLY); + pstmt.setFetchSize(2); + rs = pstmt.executeQuery(); + rs.setFetchSize(1); + while (rs.next()) { + Employee employee = populateResultSet(rs); + listOfEmployees.add(employee); + } + } catch (Exception e) { + throw e; + } finally { + if (rs != null) + rs.close(); + if (pstmt != null) + pstmt.close(); + } - @AfterClass - public static void closeConnection() throws SQLException { - PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); - deleteStmt.execute(); - dbConnection.close(); - } + assertEquals(3, listOfEmployees.size()); + } + + @AfterClass + public static void closeConnection() throws SQLException { + PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", + ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + deleteStmt.execute(); + dbConnection.close(); + } } From 48bad8243930c53eb936e1bc37b2126a10302ea2 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Thu, 24 Jan 2019 13:16:56 -0500 Subject: [PATCH 003/134] Fixed issues with adding the 2nd record --- .../com/baeldung/jdbc/ResultSetLiveTest.java | 554 +++++++++--------- 1 file changed, 268 insertions(+), 286 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java index 553c7f9919..64d64e76f2 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -20,329 +20,311 @@ import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; +import junit.framework.Assert; + @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ResultSetLiveTest { - private static final Logger logger = Logger.getLogger(ResultSetLiveTest.class); + private static final Logger logger = Logger.getLogger(ResultSetLiveTest.class); - private final Employee expectedEmployee1 = new Employee(1, "John", 1000.0, "Developer"); + private final Employee expectedEmployee1 = new Employee(1, "John", 1000.0, "Developer"); - private final Employee updatedEmployee1 = new Employee(1, "John", 1100.0, "Developer"); + private final Employee updatedEmployee1 = new Employee(1, "John", 1100.0, "Developer"); - private final Employee expectedEmployee2 = new Employee(2, "Chris", 925.0, "DBA"); + private final Employee expectedEmployee2 = new Employee(2, "Chris", 925.0, "DBA"); - private final int rowCount = 2; + private final int rowCount = 2; - private static Connection dbConnection; + private static Connection dbConnection; - @BeforeClass - public static void setup() throws ClassNotFoundException, SQLException { - Class.forName("com.mysql.cj.jdbc.Driver"); - dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB?noAccessToProcedureBodies=true", - "user1", "pass"); - String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)"; - try (Statement stmt = dbConnection.createStatement()) { - stmt.execute(tableSql); - try (PreparedStatement pstmt = dbConnection.prepareStatement( - "INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) { - pstmt.executeUpdate(); - } - } - } + @BeforeClass + public static void setup() throws ClassNotFoundException, SQLException { + Class.forName("com.mysql.cj.jdbc.Driver"); + dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB?noAccessToProcedureBodies=true", "user1", "pass"); + String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)"; + try (Statement stmt = dbConnection.createStatement()) { + stmt.execute(tableSql); + try (PreparedStatement pstmt = dbConnection.prepareStatement("INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) { + pstmt.executeUpdate(); + } + } + } - @Test - public void givenDbConnectionA_whenARetreiveByColumnNames_thenCorrect() throws SQLException { - Employee employee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); - ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - String name = rs.getString("name"); - Integer empId = rs.getInt("emp_id"); - Double salary = rs.getDouble("salary"); - String position = rs.getString("position"); - employee = new Employee(empId, name, salary, position); - } - } + @Test + public void givenDbConnectionA_whenRetreiveByColumnNames_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } - assertEquals("Employee information retreived by column names.", expectedEmployee1, employee); - } + assertEquals("Employee information retreived by column names.", expectedEmployee1, employee); + } - @Test - public void givenDbConnectionB_whenBRetreiveByColumnIds_thenCorrect() throws SQLException { - Employee employee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); - ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - Integer empId = rs.getInt(1); - String name = rs.getString(2); - String position = rs.getString(3); - Double salary = rs.getDouble(4); - employee = new Employee(empId, name, salary, position); - } - } + @Test + public void givenDbConnectionB_whenRetreiveByColumnIds_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + Integer empId = rs.getInt(1); + String name = rs.getString(2); + String position = rs.getString(3); + Double salary = rs.getDouble(4); + employee = new Employee(empId, name, salary, position); + } + } - assertEquals("Employee information retreived by column ids.", expectedEmployee1, employee); - } + assertEquals("Employee information retreived by column ids.", expectedEmployee1, employee); + } - @Test - public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException { - int rowCount = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.moveToInsertRow(); - rs.updateString("name", "Venkat"); - rs.updateString("position", "DBA"); - rs.updateDouble("salary", 925.0); - rs.insertRow(); - rs.moveToCurrentRow(); - rs.last(); - rowCount = rs.getRow(); - } + @Test + public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException { + int rowCount = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.moveToInsertRow(); + rs.updateString("name", "Chris"); + rs.updateString("position", "DBA"); + rs.updateDouble("salary", 925.0); + rs.insertRow(); + rs.moveToCurrentRow(); + rs.last(); + rowCount = rs.getRow(); + } - assertEquals("Row Count after inserting a row", 2, rowCount); - } + assertEquals("Row Count after inserting a row", 2, rowCount); + } - private Employee populateResultSet(ResultSet rs) throws SQLException { - Employee employee; - String name = rs.getString("name"); - Integer empId = rs.getInt("emp_id"); - Double salary = rs.getDouble("salary"); - String position = rs.getString("position"); - employee = new Employee(empId, name, salary, position); - return employee; - } + private Employee populateResultSet(ResultSet rs) throws SQLException { + Employee employee; + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + return employee; + } - @Test - public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { - int numOfRows = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { + int numOfRows = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Num of rows", rowCount, numOfRows); - } + assertEquals("Num of rows", rowCount, numOfRows); + } - @Test - public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { - Employee secondEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.absolute(2); - secondEmployee = populateResultSet(rs); - } + @Test + public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { + Employee secondEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.absolute(2); + secondEmployee = populateResultSet(rs); + } - assertEquals("Absolute navigation", expectedEmployee2, secondEmployee); - } + assertEquals("Absolute navigation", expectedEmployee2, secondEmployee); + } - @Test - public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException { - Employee secondEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.last(); - secondEmployee = populateResultSet(rs); - } + @Test + public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException { + Employee secondEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.last(); + secondEmployee = populateResultSet(rs); + } - assertEquals("Using Last", expectedEmployee2, secondEmployee); - } + assertEquals("Using Last", expectedEmployee2, secondEmployee); + } - @Test - public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { - Employee firstEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.beforeFirst(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.first(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - while (rs.previous()) { - Employee employee = populateResultSet(rs); - } - rs.afterLast(); - while (rs.previous()) { - Employee employee = populateResultSet(rs); - } - rs.last(); - while (rs.previous()) { - firstEmployee = populateResultSet(rs); - } - } + @Test + public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { + Employee firstEmployee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.beforeFirst(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.first(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + while (rs.previous()) { + Employee employee = populateResultSet(rs); + } + rs.afterLast(); + while (rs.previous()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + while (rs.previous()) { + firstEmployee = populateResultSet(rs); + } + } - assertEquals("Several Navigation Options", updatedEmployee1, firstEmployee); - } + assertEquals("Several Navigation Options", updatedEmployee1, firstEmployee); + } - @Test - public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { - int numOfRows = 0; - dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); - try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, - ResultSet.CLOSE_CURSORS_AT_COMMIT)) { - dbConnection.setAutoCommit(false); - pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); - ResultSet rs = pstmt.executeQuery("select * from employees"); - dbConnection.commit(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { + int numOfRows = 0; + dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT)) { + dbConnection.setAutoCommit(false); + pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); + ResultSet rs = pstmt.executeQuery("select * from employees"); + dbConnection.commit(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Inserted using close cursor after commit", 3, numOfRows); - } + assertEquals("Inserted using close cursor after commit", 3, numOfRows); + } - @Test - public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { - int numOfRows = 0; - try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, - ResultSet.HOLD_CURSORS_OVER_COMMIT)) { - dbConnection.setAutoCommit(false); - pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); - ResultSet rs = pstmt.executeQuery("select * from employees"); - dbConnection.commit(); - while (rs.next()) { - Employee employee = populateResultSet(rs); - } - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { + int numOfRows = 0; + try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT)) { + dbConnection.setAutoCommit(false); + pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); + ResultSet rs = pstmt.executeQuery("select * from employees"); + dbConnection.commit(); + while (rs.next()) { + Employee employee = populateResultSet(rs); + } + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Inserted using hold cursor after commit", 4, numOfRows); - } + assertEquals("Inserted using hold cursor after commit", 4, numOfRows); + } - @Test - public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { - int numOfRows = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.absolute(3); - rs.deleteRow(); - rs.last(); - numOfRows = rs.getRow(); - } + @Test + public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { + int numOfRows = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + rs.absolute(3); + rs.deleteRow(); + rs.last(); + numOfRows = rs.getRow(); + } - assertEquals("Deleted row", 3, numOfRows); - } + assertEquals("Deleted row", 3, numOfRows); + } - @Test - public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException { - Employee employee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - while (rs.next()) { - rs.updateDouble("salary", 1100.0); - rs.updateRow(); - rs.refreshRow(); - String name = rs.getString("name"); - Integer empId = rs.getInt("emp_id"); - Double salary = rs.getDouble("salary"); - String position = rs.getString("position"); - employee = new Employee(empId, name, salary, position); - } - } + @Test + public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { - assertEquals("Employee information updated successfully.", updatedEmployee1, employee); - } + Assert.assertEquals(1000.0, rs.getDouble("salary")); - @Test - public void givenDbConnectionE_whenDBMetaInfo_thenCorrect() throws SQLException { - DatabaseMetaData dbmd = dbConnection.getMetaData(); - boolean supportsTypeForward = dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY); - boolean supportsTypeScrollSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); - boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); - boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); - boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); - boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_READ_ONLY); - boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_UPDATABLE); - boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd - .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); - boolean concurrency4TypeScrollInSensitiveNConcurReadOnly = dbmd - .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); - boolean concurrency4TypeScrollSensitiveNConcurUpdatable = dbmd - .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); - boolean concurrency4TypeScrollSensitiveNConcurReadOnly = dbmd - .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); - int rsHoldability = dbmd.getResultSetHoldability(); + rs.updateDouble("salary", 1100.0); + rs.updateRow(); - assertEquals("checking scroll sensitivity and concur updates : ", true, - concurrency4TypeScrollInSensitiveNConcurUpdatable); - } + Assert.assertEquals(1100.0, rs.getDouble("salary")); - @Test - public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException { - int columnCount = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - ResultSetMetaData metaData = rs.getMetaData(); - columnCount = metaData.getColumnCount(); - for (int i = 1; i <= columnCount; i++) { - String catalogName = metaData.getCatalogName(i); - String className = metaData.getColumnClassName(i); - String label = metaData.getColumnLabel(i); - String name = metaData.getColumnName(i); - String typeName = metaData.getColumnTypeName(i); - Integer type = metaData.getColumnType(i); - String tableName = metaData.getTableName(i); - String schemaName = metaData.getSchemaName(i); - boolean isAutoIncrement = metaData.isAutoIncrement(i); - boolean isCaseSensitive = metaData.isCaseSensitive(i); - boolean isCurrency = metaData.isCurrency(i); - boolean isDefiniteWritable = metaData.isDefinitelyWritable(i); - boolean isReadOnly = metaData.isReadOnly(i); - boolean isSearchable = metaData.isSearchable(i); - boolean isReadable = metaData.isReadOnly(i); - boolean isSigned = metaData.isSigned(i); - boolean isWritable = metaData.isWritable(i); - int nullable = metaData.isNullable(i); - } - } + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } + } - assertEquals("column count", 4, columnCount); - } + @Test + public void givenDbConnectionE_whenDBMetaInfo_thenCorrect() throws SQLException { + DatabaseMetaData dbmd = dbConnection.getMetaData(); + boolean supportsTypeForward = dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY); + boolean supportsTypeScrollSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE); + boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE); + boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); + boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); + boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollInSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + boolean concurrency4TypeScrollSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); + boolean concurrency4TypeScrollSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); + int rsHoldability = dbmd.getResultSetHoldability(); - @Test - public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { - PreparedStatement pstmt = null; - ResultSet rs = null; - List listOfEmployees = new ArrayList(); - try { - pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_READ_ONLY); - pstmt.setFetchSize(2); - rs = pstmt.executeQuery(); - rs.setFetchSize(1); - while (rs.next()) { - Employee employee = populateResultSet(rs); - listOfEmployees.add(employee); - } - } catch (Exception e) { - throw e; - } finally { - if (rs != null) - rs.close(); - if (pstmt != null) - pstmt.close(); - } + assertEquals("checking scroll sensitivity and concur updates : ", true, concurrency4TypeScrollInSensitiveNConcurUpdatable); + } - assertEquals(3, listOfEmployees.size()); - } + @Test + public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException { + int columnCount = 0; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + ResultSetMetaData metaData = rs.getMetaData(); + columnCount = metaData.getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + String catalogName = metaData.getCatalogName(i); + String className = metaData.getColumnClassName(i); + String label = metaData.getColumnLabel(i); + String name = metaData.getColumnName(i); + String typeName = metaData.getColumnTypeName(i); + Integer type = metaData.getColumnType(i); + String tableName = metaData.getTableName(i); + String schemaName = metaData.getSchemaName(i); + boolean isAutoIncrement = metaData.isAutoIncrement(i); + boolean isCaseSensitive = metaData.isCaseSensitive(i); + boolean isCurrency = metaData.isCurrency(i); + boolean isDefiniteWritable = metaData.isDefinitelyWritable(i); + boolean isReadOnly = metaData.isReadOnly(i); + boolean isSearchable = metaData.isSearchable(i); + boolean isReadable = metaData.isReadOnly(i); + boolean isSigned = metaData.isSigned(i); + boolean isWritable = metaData.isWritable(i); + int nullable = metaData.isNullable(i); + } + } - @AfterClass - public static void closeConnection() throws SQLException { - PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", - ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); - deleteStmt.execute(); - dbConnection.close(); - } + assertEquals("column count", 4, columnCount); + } + + @Test + public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { + PreparedStatement pstmt = null; + ResultSet rs = null; + List listOfEmployees = new ArrayList(); + try { + pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + pstmt.setFetchSize(2); + rs = pstmt.executeQuery(); + rs.setFetchSize(1); + while (rs.next()) { + Employee employee = populateResultSet(rs); + listOfEmployees.add(employee); + } + } catch (Exception e) { + throw e; + } finally { + if (rs != null) + rs.close(); + if (pstmt != null) + pstmt.close(); + } + + assertEquals(3, listOfEmployees.size()); + } + + @AfterClass + public static void closeConnection() throws SQLException { + PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); + deleteStmt.execute(); + dbConnection.close(); + } } From d9b88ed303d95a2d2ed72c34c445f7a9f88181a4 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Thu, 24 Jan 2019 15:03:42 -0500 Subject: [PATCH 004/134] Fixed some resultset creation --- .../src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java index 64d64e76f2..ef01382e2c 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -112,7 +112,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { int numOfRows = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet rs = pstmt.executeQuery()) { rs.last(); numOfRows = rs.getRow(); } @@ -123,7 +123,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { Employee secondEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet rs = pstmt.executeQuery()) { rs.absolute(2); secondEmployee = populateResultSet(rs); } @@ -145,7 +145,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { Employee firstEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet rs = pstmt.executeQuery()) { while (rs.next()) { Employee employee = populateResultSet(rs); } From 2fadf8b5a0cda9dedf9f9e40e430a825257d9832 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Thu, 24 Jan 2019 15:09:02 -0500 Subject: [PATCH 005/134] d --- .../src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java index ef01382e2c..7f714a9b32 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -79,7 +79,7 @@ public class ResultSetLiveTest { } } - assertEquals("Employee information retreived by column ids.", expectedEmployee1, employee); + assertEquals("Employee information retreived by column ids:", expectedEmployee1, employee); } @Test From 474a3675f1575b244f15d1a812a94aa4d4ae52f3 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Fri, 25 Jan 2019 03:06:50 -0500 Subject: [PATCH 006/134] Fixed the name of the fetch example --- .../com/baeldung/jdbc/ResultSetLiveTest.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java index 7f714a9b32..2762aeda5e 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -79,7 +79,7 @@ public class ResultSetLiveTest { } } - assertEquals("Employee information retreived by column ids:", expectedEmployee1, employee); + assertEquals("Employee information retreived by column ids.", expectedEmployee1, employee); } @Test @@ -112,7 +112,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException { int numOfRows = 0; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { rs.last(); numOfRows = rs.getRow(); } @@ -123,7 +123,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException { Employee secondEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { rs.absolute(2); secondEmployee = populateResultSet(rs); } @@ -145,7 +145,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException { Employee firstEmployee = null; - try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE); ResultSet rs = pstmt.executeQuery()) { + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { while (rs.next()) { Employee employee = populateResultSet(rs); } @@ -195,6 +195,7 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { int numOfRows = 0; + dbConnection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT)) { dbConnection.setAutoCommit(false); pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); @@ -211,15 +212,16 @@ public class ResultSetLiveTest { } @Test - public void givenDbConnectionL_whenDelete_thenCorrect() throws SQLException { + public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { int numOfRows = 0; try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { rs.absolute(3); rs.deleteRow(); + } + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { rs.last(); numOfRows = rs.getRow(); } - assertEquals("Deleted row", 3, numOfRows); } @@ -296,13 +298,13 @@ public class ResultSetLiveTest { } @Test - public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { + public void givenDbConnectionL_whenFetch_thenCorrect() throws SQLException { PreparedStatement pstmt = null; ResultSet rs = null; List listOfEmployees = new ArrayList(); try { - pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - pstmt.setFetchSize(2); + pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); + pstmt.setFetchSize(1); rs = pstmt.executeQuery(); rs.setFetchSize(1); while (rs.next()) { @@ -318,7 +320,7 @@ public class ResultSetLiveTest { pstmt.close(); } - assertEquals(3, listOfEmployees.size()); + assertEquals(4, listOfEmployees.size()); } @AfterClass From 435f1982985b316d7f2653997ea7d3ec3a8b2175 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Mon, 28 Jan 2019 01:55:39 -0500 Subject: [PATCH 007/134] applied formatter --- .../main/java/com/baeldung/jdbc/Employee.java | 103 +++++++++--------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java index 88af4902b5..27aef8b82f 100644 --- a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java +++ b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbc/Employee.java @@ -3,69 +3,68 @@ package com.baeldung.jdbc; import java.util.Objects; public class Employee { - private int id; - private String name; - private String position; - private double salary; + private int id; + private String name; + private String position; + private double salary; - public Employee() { - } + public Employee() { + } - public Employee(int id, String name, double salary, String position) { - this.id = id; - this.name = name; - this.salary = salary; - this.position = position; - } + public Employee(int id, String name, double salary, String position) { + this.id = id; + this.name = name; + this.salary = salary; + this.position = position; + } - public int getId() { - return id; - } + public int getId() { + return id; + } - public void setId(int id) { - this.id = id; - } + public void setId(int id) { + this.id = id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public double getSalary() { - return salary; - } + public double getSalary() { + return salary; + } - public void setSalary(double salary) { - this.salary = salary; - } + public void setSalary(double salary) { + this.salary = salary; + } - public String getPosition() { - return position; - } + public String getPosition() { + return position; + } - public void setPosition(String position) { - this.position = position; - } + public void setPosition(String position) { + this.position = position; + } - @Override - public int hashCode() { - return Objects.hash(id, name, position, salary); - } + @Override + public int hashCode() { + return Objects.hash(id, name, position, salary); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Employee other = (Employee) obj; - return id == other.id && Objects.equals(name, other.name) && Objects.equals(position, other.position) - && Double.doubleToLongBits(salary) == Double.doubleToLongBits(other.salary); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Employee other = (Employee) obj; + return id == other.id && Objects.equals(name, other.name) && Objects.equals(position, other.position) && Double.doubleToLongBits(salary) == Double.doubleToLongBits(other.salary); + } } From 648e66d9e3c799cc44e87d22d4199cb9e0debd55 Mon Sep 17 00:00:00 2001 From: Yatendra Goel Date: Sun, 10 Feb 2019 02:54:20 +0530 Subject: [PATCH 008/134] BAEL-1915: Upgraded from Boot1 to Boot2 --- spring-boot-security/pom.xml | 10 ++++++++-- .../basic_auth/SpringBootSecurityApplication.java | 2 +- .../basic_auth/config/BasicAuthConfiguration.java | 9 ++++++--- .../BasicAuthConfigurationIntegrationTest.java | 4 +--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/spring-boot-security/pom.xml b/spring-boot-security/pom.xml index b87189757a..ec442f8dd1 100644 --- a/spring-boot-security/pom.xml +++ b/spring-boot-security/pom.xml @@ -8,10 +8,10 @@ Spring Boot Security Auto-Configuration - parent-boot-1 + parent-boot-2 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-1 + ../parent-boot-2 @@ -22,6 +22,12 @@ org.springframework.security.oauth spring-security-oauth2 + 2.3.3.RELEASE + + + org.springframework.security.oauth.boot + spring-security-oauth2-autoconfigure + 2.1.2.RELEASE org.springframework.boot diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/SpringBootSecurityApplication.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/SpringBootSecurityApplication.java index 2ecad4ae35..4666ca4fbd 100644 --- a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/SpringBootSecurityApplication.java +++ b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/SpringBootSecurityApplication.java @@ -2,7 +2,7 @@ package com.baeldung.springbootsecurity.basic_auth; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; @SpringBootApplication(exclude = { SecurityAutoConfiguration.class diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/config/BasicAuthConfiguration.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/config/BasicAuthConfiguration.java index 993c573fb0..592ef5354d 100644 --- a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/config/BasicAuthConfiguration.java +++ b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/config/BasicAuthConfiguration.java @@ -5,6 +5,8 @@ import org.springframework.security.config.annotation.authentication.builders.Au import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.factory.PasswordEncoderFactories; +import org.springframework.security.crypto.password.PasswordEncoder; @Configuration @EnableWebSecurity @@ -12,14 +14,15 @@ public class BasicAuthConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth + PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder(); + auth .inMemoryAuthentication() .withUser("user") - .password("password") + .password(encoder.encode("password")) .roles("USER") .and() .withUser("admin") - .password("admin") + .password(encoder.encode("admin")) .roles("USER", "ADMIN"); } diff --git a/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/basic_auth/BasicAuthConfigurationIntegrationTest.java b/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/basic_auth/BasicAuthConfigurationIntegrationTest.java index 32c3fbdef4..94cf9f4148 100644 --- a/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/basic_auth/BasicAuthConfigurationIntegrationTest.java +++ b/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/basic_auth/BasicAuthConfigurationIntegrationTest.java @@ -1,12 +1,11 @@ package com.baeldung.springbootsecurity.basic_auth; -import com.baeldung.springbootsecurity.basic_auth.SpringBootSecurityApplication; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; @@ -18,7 +17,6 @@ import java.net.URL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT, classes = SpringBootSecurityApplication.class) public class BasicAuthConfigurationIntegrationTest { From b4041f577d9a42f7656f664ac42b010e76f470a8 Mon Sep 17 00:00:00 2001 From: Venkata Kiran Surapaneni Date: Mon, 11 Feb 2019 08:28:20 -0500 Subject: [PATCH 009/134] Made holdability example much clear. --- .../com/baeldung/jdbc/ResultSetLiveTest.java | 65 +++++++++++++------ 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java index 2762aeda5e..4e10f8bd43 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/ResultSetLiveTest.java @@ -175,54 +175,60 @@ public class ResultSetLiveTest { @Test public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException { - int numOfRows = 0; + Employee employee = null; dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT)) { dbConnection.setAutoCommit(false); - pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Chris',2100.0,'Manager')"); ResultSet rs = pstmt.executeQuery("select * from employees"); - dbConnection.commit(); while (rs.next()) { - Employee employee = populateResultSet(rs); + if (rs.getString("name") + .equalsIgnoreCase("john")) { + rs.updateString("position", "Senior Engineer"); + rs.updateRow(); + dbConnection.commit(); + employee = populateResultSet(rs); + } } rs.last(); - numOfRows = rs.getRow(); } - assertEquals("Inserted using close cursor after commit", 3, numOfRows); + assertEquals("Update using closed cursor", "Senior Engineer", employee.getPosition()); } @Test public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException { - int numOfRows = 0; + Employee employee = null; dbConnection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT)) { dbConnection.setAutoCommit(false); - pstmt.executeUpdate("INSERT INTO employees (name, salary,position) VALUES ('Michael',1200.0,'Consultant')"); ResultSet rs = pstmt.executeQuery("select * from employees"); - dbConnection.commit(); while (rs.next()) { - Employee employee = populateResultSet(rs); + if (rs.getString("name") + .equalsIgnoreCase("john")) { + rs.updateString("name", "John Doe"); + rs.updateRow(); + dbConnection.commit(); + employee = populateResultSet(rs); + } } rs.last(); - numOfRows = rs.getRow(); } - assertEquals("Inserted using hold cursor after commit", 4, numOfRows); + assertEquals("Update using open cursor", "John Doe", employee.getName()); } @Test public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException { int numOfRows = 0; try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { - rs.absolute(3); + rs.absolute(2); rs.deleteRow(); } try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { rs.last(); numOfRows = rs.getRow(); } - assertEquals("Deleted row", 3, numOfRows); + assertEquals("Deleted row", 1, numOfRows); } @Test @@ -231,12 +237,33 @@ public class ResultSetLiveTest { try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { while (rs.next()) { - Assert.assertEquals(1000.0, rs.getDouble("salary")); + Assert.assertEquals(1100.0, rs.getDouble("salary")); - rs.updateDouble("salary", 1100.0); + rs.updateDouble("salary", 1200.0); rs.updateRow(); - Assert.assertEquals(1100.0, rs.getDouble("salary")); + Assert.assertEquals(1200.0, rs.getDouble("salary")); + + String name = rs.getString("name"); + Integer empId = rs.getInt("emp_id"); + Double salary = rs.getDouble("salary"); + String position = rs.getString("position"); + employee = new Employee(empId, name, salary, position); + } + } + } + + @Test + public void givenDbConnectionC_whenUpdateByIndex_thenCorrect() throws SQLException { + Employee employee = null; + try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) { + while (rs.next()) { + + Assert.assertEquals(1000.0, rs.getDouble(4)); + + rs.updateDouble(4, 1100.0); + rs.updateRow(); + Assert.assertEquals(1100.0, rs.getDouble(4)); String name = rs.getString("name"); Integer empId = rs.getInt("emp_id"); @@ -320,7 +347,7 @@ public class ResultSetLiveTest { pstmt.close(); } - assertEquals(4, listOfEmployees.size()); + assertEquals(2, listOfEmployees.size()); } @AfterClass @@ -329,4 +356,4 @@ public class ResultSetLiveTest { deleteStmt.execute(); dbConnection.close(); } -} +} \ No newline at end of file From 062b959d5a4d127a168d56045d589f0e45d8d5da Mon Sep 17 00:00:00 2001 From: vsurapaneni Date: Tue, 19 Feb 2019 15:33:40 -0500 Subject: [PATCH 010/134] BAEL-2575 --- spring-boot-datasource-issue/pom.xml | 21 +++++++++ .../pom.xml | 36 +++++++++++++++ .../DataSourceIssueSolutionApplication.java | 15 +++++++ .../pom.xml | 36 +++++++++++++++ .../DataSourceIssueSolutionApplication.java | 13 ++++++ .../src/main/resources/application.properties | 2 + .../pom.xml | 45 +++++++++++++++++++ .../DataSourceIssueSolutionApplication.java | 13 ++++++ .../src/main/resources/application.yml | 4 ++ .../spring-boot-datasource-program/pom.xml | 36 +++++++++++++++ .../DataSourceIssueSolutionApplication.java | 13 ++++++ .../datasourcedemo/DatasourceConfig.java | 18 ++++++++ .../spring-boot-datasource-properties/pom.xml | 36 +++++++++++++++ .../DataSourceIssueSolutionApplication.java | 13 ++++++ .../src/main/resources/application.properties | 4 ++ .../spring-boot-datasource-yml/pom.xml | 45 +++++++++++++++++++ .../DataSourceIssueSolutionApplication.java | 13 ++++++ .../src/main/resources/application.yml | 6 +++ 18 files changed, 369 insertions(+) create mode 100644 spring-boot-datasource-issue/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java create mode 100644 spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml diff --git a/spring-boot-datasource-issue/pom.xml b/spring-boot-datasource-issue/pom.xml new file mode 100644 index 0000000000..2316d86e70 --- /dev/null +++ b/spring-boot-datasource-issue/pom.xml @@ -0,0 +1,21 @@ + + 4.0.0 + spring-boot-datasource-issue + pom + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + spring-boot-datasource-properties + spring-boot-datasource-exclude-program + spring-boot-datasource-exclude-properties + spring-boot-datasource-exclude-yml + spring-boot-datasource-program + spring-boot-datasource-yml + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml new file mode 100644 index 0000000000..8025cc8959 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + com.baeldung + spring-boot-datasource-issue + 0.0.1-SNAPSHOT + + spring-boot-datasource-exclude-program + spring-boot-datasource-exclude-program + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java new file mode 100644 index 0000000000..b6c81471c4 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.datasourcedemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +@SpringBootApplication(exclude={DataSourceAutoConfiguration.class}) +public class DataSourceIssueSolutionApplication { + + public static void main(String[] args) { + SpringApplication.run(DataSourceIssueSolutionApplication.class, args); + } + +} + diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml new file mode 100644 index 0000000000..78d253c4f7 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + com.baeldung + spring-boot-datasource-issue + 0.0.1-SNAPSHOT + + spring-boot-datasource-exclude-properties + spring-boot-datasource-exclude-properties + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java new file mode 100644 index 0000000000..377a245b38 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.datasourcedemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DataSourceIssueSolutionApplication { + + public static void main(String[] args) { + SpringApplication.run(DataSourceIssueSolutionApplication.class, args); + } + +} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties new file mode 100644 index 0000000000..ae2b359cd0 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration + diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml new file mode 100644 index 0000000000..1d60ea3dbf --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + + com.baeldung + spring-boot-datasource-issue + 0.0.1-SNAPSHOT + + spring-boot-datasource-exclude-yml + spring-boot-datasource-exclude-yml + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + + + org.yaml + snakeyaml + + + + + Sonatype-public + SnakeYAML repository + http://oss.sonatype.org/content/groups/public/ + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java new file mode 100644 index 0000000000..377a245b38 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.datasourcedemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DataSourceIssueSolutionApplication { + + public static void main(String[] args) { + SpringApplication.run(DataSourceIssueSolutionApplication.class, args); + } + +} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml new file mode 100644 index 0000000000..c574bf01a7 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml @@ -0,0 +1,4 @@ +spring: + autoconfigure: + exclude: + - org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration diff --git a/spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml new file mode 100644 index 0000000000..279fcc063b --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + com.baeldung + spring-boot-datasource-issue + 0.0.1-SNAPSHOT + + spring-boot-datasource-program + spring-boot-datasource-program + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java new file mode 100644 index 0000000000..377a245b38 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.datasourcedemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DataSourceIssueSolutionApplication { + + public static void main(String[] args) { + SpringApplication.run(DataSourceIssueSolutionApplication.class, args); + } + +} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java b/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java new file mode 100644 index 0000000000..0eca032d42 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java @@ -0,0 +1,18 @@ +package com.baeldung.datasourcedemo; + + +import javax.sql.DataSource; + +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class DatasourceConfig { + @Bean + public DataSource datasource() { + return DataSourceBuilder.create().driverClassName("com.mysql.cj.jdbc.Driver"). + url("jdbc:mysql://localhost:3306/lonar").username("root").password("Chinna@1988").build(); + } + +} \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml new file mode 100644 index 0000000000..8a7ca75bdd --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + com.baeldung + spring-boot-datasource-issue + 0.0.1-SNAPSHOT + + spring-boot-datasource-properties + spring-boot-datasource-properties + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java new file mode 100644 index 0000000000..377a245b38 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.datasourcedemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DataSourceIssueSolutionApplication { + + public static void main(String[] args) { + SpringApplication.run(DataSourceIssueSolutionApplication.class, args); + } + +} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties b/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties new file mode 100644 index 0000000000..90605e9258 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties @@ -0,0 +1,4 @@ +spring.datasource.url=jdbc:mysql://localhost:3306/lonar +spring.datasource.username=root +spring.datasource.password=Chinna@1988 +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver diff --git a/spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml new file mode 100644 index 0000000000..6f474f76db --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + + com.baeldung + spring-boot-datasource-issue + 0.0.1-SNAPSHOT + + spring-boot-datasource-yml + spring-boot-datasource-yml + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + runtime + + + org.yaml + snakeyaml + + + + + Sonatype-public + SnakeYAML repository + http://oss.sonatype.org/content/groups/public/ + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java new file mode 100644 index 0000000000..377a245b38 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.datasourcedemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DataSourceIssueSolutionApplication { + + public static void main(String[] args) { + SpringApplication.run(DataSourceIssueSolutionApplication.class, args); + } + +} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml b/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml new file mode 100644 index 0000000000..98d7c843e8 --- /dev/null +++ b/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml @@ -0,0 +1,6 @@ +spring: + datasource: + driverClassName: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/lonar + username: root + password: Chinna@1988 From c5d9aceb86b450b2a022c39acc73ddc128b5fb11 Mon Sep 17 00:00:00 2001 From: vsurapaneni Date: Tue, 19 Feb 2019 16:09:52 -0500 Subject: [PATCH 011/134] fixed the mix up with another pr. --- spring-boot-datasource-issue/pom.xml | 21 --------- .../pom.xml | 36 --------------- .../DataSourceIssueSolutionApplication.java | 15 ------- .../pom.xml | 36 --------------- .../DataSourceIssueSolutionApplication.java | 13 ------ .../src/main/resources/application.properties | 2 - .../pom.xml | 45 ------------------- .../DataSourceIssueSolutionApplication.java | 13 ------ .../src/main/resources/application.yml | 4 -- .../spring-boot-datasource-program/pom.xml | 36 --------------- .../DataSourceIssueSolutionApplication.java | 13 ------ .../datasourcedemo/DatasourceConfig.java | 18 -------- .../spring-boot-datasource-properties/pom.xml | 36 --------------- .../DataSourceIssueSolutionApplication.java | 13 ------ .../src/main/resources/application.properties | 4 -- .../spring-boot-datasource-yml/pom.xml | 45 ------------------- .../DataSourceIssueSolutionApplication.java | 13 ------ .../src/main/resources/application.yml | 6 --- 18 files changed, 369 deletions(-) delete mode 100644 spring-boot-datasource-issue/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java delete mode 100644 spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml diff --git a/spring-boot-datasource-issue/pom.xml b/spring-boot-datasource-issue/pom.xml deleted file mode 100644 index 2316d86e70..0000000000 --- a/spring-boot-datasource-issue/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - 4.0.0 - spring-boot-datasource-issue - pom - - - parent-boot-2 - com.baeldung - 0.0.1-SNAPSHOT - ../parent-boot-2 - - - - spring-boot-datasource-properties - spring-boot-datasource-exclude-program - spring-boot-datasource-exclude-properties - spring-boot-datasource-exclude-yml - spring-boot-datasource-program - spring-boot-datasource-yml - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml deleted file mode 100644 index 8025cc8959..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - com.baeldung - spring-boot-datasource-issue - 0.0.1-SNAPSHOT - - spring-boot-datasource-exclude-program - spring-boot-datasource-exclude-program - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java deleted file mode 100644 index b6c81471c4..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.datasourcedemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; - -@SpringBootApplication(exclude={DataSourceAutoConfiguration.class}) -public class DataSourceIssueSolutionApplication { - - public static void main(String[] args) { - SpringApplication.run(DataSourceIssueSolutionApplication.class, args); - } - -} - diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml deleted file mode 100644 index 78d253c4f7..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - com.baeldung - spring-boot-datasource-issue - 0.0.1-SNAPSHOT - - spring-boot-datasource-exclude-properties - spring-boot-datasource-exclude-properties - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java deleted file mode 100644 index 377a245b38..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.datasourcedemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DataSourceIssueSolutionApplication { - - public static void main(String[] args) { - SpringApplication.run(DataSourceIssueSolutionApplication.class, args); - } - -} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties b/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties deleted file mode 100644 index ae2b359cd0..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-properties/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration - diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml deleted file mode 100644 index 1d60ea3dbf..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - 4.0.0 - - com.baeldung - spring-boot-datasource-issue - 0.0.1-SNAPSHOT - - spring-boot-datasource-exclude-yml - spring-boot-datasource-exclude-yml - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - - - org.yaml - snakeyaml - - - - - Sonatype-public - SnakeYAML repository - http://oss.sonatype.org/content/groups/public/ - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java deleted file mode 100644 index 377a245b38..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.datasourcedemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DataSourceIssueSolutionApplication { - - public static void main(String[] args) { - SpringApplication.run(DataSourceIssueSolutionApplication.class, args); - } - -} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml b/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml deleted file mode 100644 index c574bf01a7..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-exclude-yml/src/main/resources/application.yml +++ /dev/null @@ -1,4 +0,0 @@ -spring: - autoconfigure: - exclude: - - org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration diff --git a/spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml deleted file mode 100644 index 279fcc063b..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-program/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - com.baeldung - spring-boot-datasource-issue - 0.0.1-SNAPSHOT - - spring-boot-datasource-program - spring-boot-datasource-program - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java deleted file mode 100644 index 377a245b38..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.datasourcedemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DataSourceIssueSolutionApplication { - - public static void main(String[] args) { - SpringApplication.run(DataSourceIssueSolutionApplication.class, args); - } - -} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java b/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java deleted file mode 100644 index 0eca032d42..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-program/src/main/java/com/baeldung/datasourcedemo/DatasourceConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.datasourcedemo; - - -import javax.sql.DataSource; - -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class DatasourceConfig { - @Bean - public DataSource datasource() { - return DataSourceBuilder.create().driverClassName("com.mysql.cj.jdbc.Driver"). - url("jdbc:mysql://localhost:3306/lonar").username("root").password("Chinna@1988").build(); - } - -} \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml deleted file mode 100644 index 8a7ca75bdd..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-properties/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - 4.0.0 - - com.baeldung - spring-boot-datasource-issue - 0.0.1-SNAPSHOT - - spring-boot-datasource-properties - spring-boot-datasource-properties - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java deleted file mode 100644 index 377a245b38..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.datasourcedemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DataSourceIssueSolutionApplication { - - public static void main(String[] args) { - SpringApplication.run(DataSourceIssueSolutionApplication.class, args); - } - -} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties b/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties deleted file mode 100644 index 90605e9258..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-properties/src/main/resources/application.properties +++ /dev/null @@ -1,4 +0,0 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/lonar -spring.datasource.username=root -spring.datasource.password=Chinna@1988 -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver diff --git a/spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml b/spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml deleted file mode 100644 index 6f474f76db..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-yml/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - 4.0.0 - - com.baeldung - spring-boot-datasource-issue - 0.0.1-SNAPSHOT - - spring-boot-datasource-yml - spring-boot-datasource-yml - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - mysql - mysql-connector-java - runtime - - - org.yaml - snakeyaml - - - - - Sonatype-public - SnakeYAML repository - http://oss.sonatype.org/content/groups/public/ - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - \ No newline at end of file diff --git a/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java b/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java deleted file mode 100644 index 377a245b38..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/java/com/baeldung/datasourcedemo/DataSourceIssueSolutionApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.datasourcedemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DataSourceIssueSolutionApplication { - - public static void main(String[] args) { - SpringApplication.run(DataSourceIssueSolutionApplication.class, args); - } - -} diff --git a/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml b/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml deleted file mode 100644 index 98d7c843e8..0000000000 --- a/spring-boot-datasource-issue/spring-boot-datasource-yml/src/main/resources/application.yml +++ /dev/null @@ -1,6 +0,0 @@ -spring: - datasource: - driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/lonar - username: root - password: Chinna@1988 From 249f2f0ed06a343e81ef101eea500af585c8e70b Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Wed, 20 Feb 2019 20:47:13 +0200 Subject: [PATCH 012/134] Update SpringBootSecurityApplication.java --- .../basic_auth/SpringBootSecurityApplication.java | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/SpringBootSecurityApplication.java b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/SpringBootSecurityApplication.java index 4666ca4fbd..7007c15596 100644 --- a/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/SpringBootSecurityApplication.java +++ b/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/basic_auth/SpringBootSecurityApplication.java @@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfi // ,ManagementWebSecurityAutoConfiguration.class }, scanBasePackages = "com.baeldung.springbootsecurity.basic_auth") public class SpringBootSecurityApplication { - public static void main(String[] args) { SpringApplication.run(SpringBootSecurityApplication.class, args); } From f14c3fbab33ce21cb99978e1813366338059745a Mon Sep 17 00:00:00 2001 From: Jon Cook Date: Wed, 20 Feb 2019 20:55:15 +0100 Subject: [PATCH 013/134] BAEL-2541 - Guide to ProcessBuilder API --- .../ProcessBuilderUnitTest.java | 159 ++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java b/core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java new file mode 100644 index 0000000000..89a42b5d5c --- /dev/null +++ b/core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java @@ -0,0 +1,159 @@ +package com.baeldung.processbuilder; + +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.ProcessBuilder.Redirect; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +public class ProcessBuilderUnitTest { + + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); + + @Test + public void givenProcessBuilder_whenInvokeStart_thenSuccess() throws IOException, InterruptedException, ExecutionException { + ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); + processBuilder.redirectErrorStream(true); + + Process process = processBuilder.start(); + + List results = readOutput(process.getInputStream()); + assertThat("Results should not be empty", results, is(not(empty()))); + assertThat("Results should contain java version: ", results, hasItem(containsString("java version"))); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + } + + @Test + public void givenProcessBuilder_whenModifyEnvironment_thenSuccess() throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder(); + Map environment = processBuilder.environment(); + environment.forEach((key, value) -> System.out.println(key + value)); + + environment.put("GREETING", "Hola Mundo"); + + processBuilder.command("/bin/bash", "-c", "echo $GREETING"); + Process process = processBuilder.start(); + + List results = readOutput(process.getInputStream()); + assertThat("Results should not be empty", results, is(not(empty()))); + assertThat("Results should contain a greeting ", results, hasItem(containsString("Hola Mundo"))); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + } + + @Test + public void givenProcessBuilder_whenModifyWorkingDir_thenSuccess() throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder("/bin/sh", "-c", "ls"); + + processBuilder.directory(new File("src")); + Process process = processBuilder.start(); + + List results = readOutput(process.getInputStream()); + assertThat("Results should not be empty", results, is(not(empty()))); + assertThat("Results should contain directory listing: ", results, contains("main", "test")); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + } + + @Test + public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessWriting() throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); + + processBuilder.redirectErrorStream(true); + File log = tempFolder.newFile("java-version.log"); + processBuilder.redirectOutput(log); + + Process process = processBuilder.start(); + + assertEquals("If redirected, should be -1 ", -1, process.getInputStream() + .read()); + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + + List lines = Files.lines(log.toPath()) + .collect(Collectors.toList()); + + assertThat("Results should not be empty", lines, is(not(empty()))); + assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); + } + + @Test + public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessAppending() throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); + + File log = tempFolder.newFile("java-version-append.log"); + processBuilder.redirectErrorStream(true); + processBuilder.redirectOutput(Redirect.appendTo(log)); + + Process process = processBuilder.start(); + + assertEquals("If redirected output, should be -1 ", -1, process.getInputStream() + .read()); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + + List lines = Files.lines(log.toPath()) + .collect(Collectors.toList()); + + assertThat("Results should not be empty", lines, is(not(empty()))); + assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); + } + + @Test + public void givenProcessBuilder_whenStartingPipeline_thenSuccess() throws IOException, InterruptedException { + List builders = Arrays.asList( + new ProcessBuilder("find", "src", "-name", "*.java", "-type", "f"), + new ProcessBuilder("wc", "-l")); + + List processes = ProcessBuilder.startPipeline(builders); + Process last = processes.get(processes.size() - 1); + + List output = readOutput(last.getInputStream()); + assertThat("Results should not be empty", output, is(not(empty()))); + } + + @Test + public void givenProcessBuilder_whenInheritIO_thenSuccess() throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder("/bin/sh", "-c", "echo hello"); + + processBuilder.inheritIO(); + Process process = processBuilder.start(); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + } + + private List readOutput(InputStream inputStream) throws IOException { + try (BufferedReader output = new BufferedReader(new InputStreamReader(inputStream))) { + return output.lines() + .collect(Collectors.toList()); + } + } + +} From 1dac10b24782ab46aff992cebc75c705df962d1e Mon Sep 17 00:00:00 2001 From: Jonathan Paul Cook Date: Wed, 20 Feb 2019 22:58:18 +0100 Subject: [PATCH 014/134] BAEL-2541 - Guide to ProcessBuilder API - Update test commands to work on windows --- .../ProcessBuilderUnitTest.java | 340 ++++++++++-------- 1 file changed, 181 insertions(+), 159 deletions(-) diff --git a/core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java b/core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java index 89a42b5d5c..a18cc3e368 100644 --- a/core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java +++ b/core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java @@ -1,159 +1,181 @@ -package com.baeldung.processbuilder; - -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.lang.ProcessBuilder.Redirect; -import java.nio.file.Files; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -public class ProcessBuilderUnitTest { - - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); - - @Test - public void givenProcessBuilder_whenInvokeStart_thenSuccess() throws IOException, InterruptedException, ExecutionException { - ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); - processBuilder.redirectErrorStream(true); - - Process process = processBuilder.start(); - - List results = readOutput(process.getInputStream()); - assertThat("Results should not be empty", results, is(not(empty()))); - assertThat("Results should contain java version: ", results, hasItem(containsString("java version"))); - - int exitCode = process.waitFor(); - assertEquals("No errors should be detected", 0, exitCode); - } - - @Test - public void givenProcessBuilder_whenModifyEnvironment_thenSuccess() throws IOException, InterruptedException { - ProcessBuilder processBuilder = new ProcessBuilder(); - Map environment = processBuilder.environment(); - environment.forEach((key, value) -> System.out.println(key + value)); - - environment.put("GREETING", "Hola Mundo"); - - processBuilder.command("/bin/bash", "-c", "echo $GREETING"); - Process process = processBuilder.start(); - - List results = readOutput(process.getInputStream()); - assertThat("Results should not be empty", results, is(not(empty()))); - assertThat("Results should contain a greeting ", results, hasItem(containsString("Hola Mundo"))); - - int exitCode = process.waitFor(); - assertEquals("No errors should be detected", 0, exitCode); - } - - @Test - public void givenProcessBuilder_whenModifyWorkingDir_thenSuccess() throws IOException, InterruptedException { - ProcessBuilder processBuilder = new ProcessBuilder("/bin/sh", "-c", "ls"); - - processBuilder.directory(new File("src")); - Process process = processBuilder.start(); - - List results = readOutput(process.getInputStream()); - assertThat("Results should not be empty", results, is(not(empty()))); - assertThat("Results should contain directory listing: ", results, contains("main", "test")); - - int exitCode = process.waitFor(); - assertEquals("No errors should be detected", 0, exitCode); - } - - @Test - public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessWriting() throws IOException, InterruptedException { - ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); - - processBuilder.redirectErrorStream(true); - File log = tempFolder.newFile("java-version.log"); - processBuilder.redirectOutput(log); - - Process process = processBuilder.start(); - - assertEquals("If redirected, should be -1 ", -1, process.getInputStream() - .read()); - int exitCode = process.waitFor(); - assertEquals("No errors should be detected", 0, exitCode); - - List lines = Files.lines(log.toPath()) - .collect(Collectors.toList()); - - assertThat("Results should not be empty", lines, is(not(empty()))); - assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); - } - - @Test - public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessAppending() throws IOException, InterruptedException { - ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); - - File log = tempFolder.newFile("java-version-append.log"); - processBuilder.redirectErrorStream(true); - processBuilder.redirectOutput(Redirect.appendTo(log)); - - Process process = processBuilder.start(); - - assertEquals("If redirected output, should be -1 ", -1, process.getInputStream() - .read()); - - int exitCode = process.waitFor(); - assertEquals("No errors should be detected", 0, exitCode); - - List lines = Files.lines(log.toPath()) - .collect(Collectors.toList()); - - assertThat("Results should not be empty", lines, is(not(empty()))); - assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); - } - - @Test - public void givenProcessBuilder_whenStartingPipeline_thenSuccess() throws IOException, InterruptedException { - List builders = Arrays.asList( - new ProcessBuilder("find", "src", "-name", "*.java", "-type", "f"), - new ProcessBuilder("wc", "-l")); - - List processes = ProcessBuilder.startPipeline(builders); - Process last = processes.get(processes.size() - 1); - - List output = readOutput(last.getInputStream()); - assertThat("Results should not be empty", output, is(not(empty()))); - } - - @Test - public void givenProcessBuilder_whenInheritIO_thenSuccess() throws IOException, InterruptedException { - ProcessBuilder processBuilder = new ProcessBuilder("/bin/sh", "-c", "echo hello"); - - processBuilder.inheritIO(); - Process process = processBuilder.start(); - - int exitCode = process.waitFor(); - assertEquals("No errors should be detected", 0, exitCode); - } - - private List readOutput(InputStream inputStream) throws IOException { - try (BufferedReader output = new BufferedReader(new InputStreamReader(inputStream))) { - return output.lines() - .collect(Collectors.toList()); - } - } - -} +package com.baeldung.processbuilder; + +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.ProcessBuilder.Redirect; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +public class ProcessBuilderUnitTest { + + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); + + @Test + public void givenProcessBuilder_whenInvokeStart_thenSuccess() throws IOException, InterruptedException, ExecutionException { + ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); + processBuilder.redirectErrorStream(true); + + Process process = processBuilder.start(); + + List results = readOutput(process.getInputStream()); + assertThat("Results should not be empty", results, is(not(empty()))); + assertThat("Results should contain java version: ", results, hasItem(containsString("java version"))); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + } + + @Test + public void givenProcessBuilder_whenModifyEnvironment_thenSuccess() throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder(); + Map environment = processBuilder.environment(); + environment.forEach((key, value) -> System.out.println(key + value)); + + environment.put("GREETING", "Hola Mundo"); + + List command = getGreetingCommand(); + processBuilder.command(command); + Process process = processBuilder.start(); + + List results = readOutput(process.getInputStream()); + assertThat("Results should not be empty", results, is(not(empty()))); + assertThat("Results should contain a greeting ", results, hasItem(containsString("Hola Mundo"))); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + } + + @Test + public void givenProcessBuilder_whenModifyWorkingDir_thenSuccess() throws IOException, InterruptedException { + List command = getDirectoryListingCommand(); + ProcessBuilder processBuilder = new ProcessBuilder(command); + + processBuilder.directory(new File("src")); + Process process = processBuilder.start(); + + List results = readOutput(process.getInputStream()); + assertThat("Results should not be empty", results, is(not(empty()))); + assertThat("Results should contain directory listing: ", results, hasItems(containsString("main"), containsString("test"))); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + } + + private List getDirectoryListingCommand() { + return isWindows() ? Arrays.asList("cmd.exe", "/c", "dir") : Arrays.asList("/bin/sh", "-c", "ls"); + } + + private List getGreetingCommand() { + return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo %GREETING%") : Arrays.asList("/bin/bash", "-c", "echo $GREETING"); + } + + private List getEchoCommand() { + return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo hello") : Arrays.asList("/bin/sh", "-c", "echo hello"); + } + + private boolean isWindows() { + return System.getProperty("os.name") + .toLowerCase() + .startsWith("windows"); + } + + @Test + public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessWriting() throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); + + processBuilder.redirectErrorStream(true); + File log = tempFolder.newFile("java-version.log"); + processBuilder.redirectOutput(log); + + Process process = processBuilder.start(); + + assertEquals("If redirected, should be -1 ", -1, process.getInputStream() + .read()); + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + + List lines = Files.lines(log.toPath()) + .collect(Collectors.toList()); + + assertThat("Results should not be empty", lines, is(not(empty()))); + assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); + } + + @Test + public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessAppending() throws IOException, InterruptedException { + ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); + + File log = tempFolder.newFile("java-version-append.log"); + processBuilder.redirectErrorStream(true); + processBuilder.redirectOutput(Redirect.appendTo(log)); + + Process process = processBuilder.start(); + + assertEquals("If redirected output, should be -1 ", -1, process.getInputStream() + .read()); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + + List lines = Files.lines(log.toPath()) + .collect(Collectors.toList()); + + assertThat("Results should not be empty", lines, is(not(empty()))); + assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); + } + +/* @Test + public void givenProcessBuilder_whenStartingPipeline_thenSuccess() throws IOException, InterruptedException { + List builders = Arrays.asList( + new ProcessBuilder("find", "src", "-name", "*.java", "-type", "f"), + new ProcessBuilder("wc", "-l")); + + List processes = ProcessBuilder.startPipeline(builders); + Process last = processes.get(processes.size() - 1); + + List output = readOutput(last.getInputStream()); + assertThat("Results should not be empty", output, is(not(empty()))); + }*/ + + @Test + public void givenProcessBuilder_whenInheritIO_thenSuccess() throws IOException, InterruptedException { + List command = getEchoCommand(); + ProcessBuilder processBuilder = new ProcessBuilder(command); + + processBuilder.inheritIO(); + Process process = processBuilder.start(); + + int exitCode = process.waitFor(); + assertEquals("No errors should be detected", 0, exitCode); + } + + private List readOutput(InputStream inputStream) throws IOException { + try (BufferedReader output = new BufferedReader(new InputStreamReader(inputStream))) { + return output.lines() + .collect(Collectors.toList()); + } + } + +} From 95c0513cfcea05a9a79f3ea03b46ef8f941c391a Mon Sep 17 00:00:00 2001 From: Jon Cook Date: Wed, 20 Feb 2019 23:17:09 +0100 Subject: [PATCH 015/134] BAEL-2541 - Guide to ProcessBuilder API - Move ProcessBuilderUnitTest to core-java-9 --- .../ProcessBuilderUnitTest.java | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) rename {core-java => core-java-9}/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java (90%) diff --git a/core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java b/core-java-9/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java similarity index 90% rename from core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java rename to core-java-9/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java index a18cc3e368..0458383e99 100644 --- a/core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java +++ b/core-java-9/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java @@ -1,6 +1,5 @@ package com.baeldung.processbuilder; -import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasItem; @@ -83,24 +82,6 @@ public class ProcessBuilderUnitTest { assertEquals("No errors should be detected", 0, exitCode); } - private List getDirectoryListingCommand() { - return isWindows() ? Arrays.asList("cmd.exe", "/c", "dir") : Arrays.asList("/bin/sh", "-c", "ls"); - } - - private List getGreetingCommand() { - return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo %GREETING%") : Arrays.asList("/bin/bash", "-c", "echo $GREETING"); - } - - private List getEchoCommand() { - return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo hello") : Arrays.asList("/bin/sh", "-c", "echo hello"); - } - - private boolean isWindows() { - return System.getProperty("os.name") - .toLowerCase() - .startsWith("windows"); - } - @Test public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessWriting() throws IOException, InterruptedException { ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); @@ -146,18 +127,20 @@ public class ProcessBuilderUnitTest { assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); } -/* @Test + @Test public void givenProcessBuilder_whenStartingPipeline_thenSuccess() throws IOException, InterruptedException { - List builders = Arrays.asList( - new ProcessBuilder("find", "src", "-name", "*.java", "-type", "f"), - new ProcessBuilder("wc", "-l")); + if (!isWindows()) { + List builders = Arrays.asList( + new ProcessBuilder("find", "src", "-name", "*.java", "-type", "f"), + new ProcessBuilder("wc", "-l")); - List processes = ProcessBuilder.startPipeline(builders); - Process last = processes.get(processes.size() - 1); + List processes = ProcessBuilder.startPipeline(builders); + Process last = processes.get(processes.size() - 1); - List output = readOutput(last.getInputStream()); - assertThat("Results should not be empty", output, is(not(empty()))); - }*/ + List output = readOutput(last.getInputStream()); + assertThat("Results should not be empty", output, is(not(empty()))); + } + } @Test public void givenProcessBuilder_whenInheritIO_thenSuccess() throws IOException, InterruptedException { @@ -178,4 +161,22 @@ public class ProcessBuilderUnitTest { } } + private List getDirectoryListingCommand() { + return isWindows() ? Arrays.asList("cmd.exe", "/c", "dir") : Arrays.asList("/bin/sh", "-c", "ls"); + } + + private List getGreetingCommand() { + return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo %GREETING%") : Arrays.asList("/bin/bash", "-c", "echo $GREETING"); + } + + private List getEchoCommand() { + return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo hello") : Arrays.asList("/bin/sh", "-c", "echo hello"); + } + + private boolean isWindows() { + return System.getProperty("os.name") + .toLowerCase() + .startsWith("windows"); + } + } From b8411e44a3ca93797eaf2d15a4a8c3884a6f7939 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Wed, 27 Feb 2019 15:33:20 +0800 Subject: [PATCH 016/134] Update README.md --- spring-rest-full/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-rest-full/README.md b/spring-rest-full/README.md index 32b65ccc6a..ed6df1675f 100644 --- a/spring-rest-full/README.md +++ b/spring-rest-full/README.md @@ -12,7 +12,7 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com - [Introduction to Spring Data JPA](http://www.baeldung.com/the-persistence-layer-with-spring-data-jpa) - [Project Configuration with Spring](http://www.baeldung.com/project-configuration-with-spring) - [Metrics for your Spring REST API](http://www.baeldung.com/spring-rest-api-metrics) -- [Bootstrap a Web Application with Spring 4](http://www.baeldung.com/bootstraping-a-web-application-with-spring-and-java-based-configuration) +- [Bootstrap a Web Application with Spring 5](http://www.baeldung.com/bootstraping-a-web-application-with-spring-and-java-based-configuration) - [Spring Security Expressions - hasRole Example](https://www.baeldung.com/spring-security-expressions-basic) From dbb7b45460e7e1f60b909e37a6b28561ede9d523 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Wed, 27 Feb 2019 16:17:25 +0800 Subject: [PATCH 017/134] Update README.md --- aws/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/aws/README.md b/aws/README.md index 2c61928095..d14ea8a75e 100644 --- a/aws/README.md +++ b/aws/README.md @@ -4,7 +4,6 @@ - [AWS S3 with Java](http://www.baeldung.com/aws-s3-java) - [AWS Lambda With Java](http://www.baeldung.com/java-aws-lambda) - [Managing EC2 Instances in Java](http://www.baeldung.com/ec2-java) -- [http://www.baeldung.com/aws-s3-multipart-upload](https://github.com/eugenp/tutorials/tree/master/aws) - [Multipart Uploads in Amazon S3 with Java](http://www.baeldung.com/aws-s3-multipart-upload) - [Integration Testing with a Local DynamoDB Instance](http://www.baeldung.com/dynamodb-local-integration-tests) - [Using the JetS3t Java Client With Amazon S3](http://www.baeldung.com/jets3t-amazon-s3) From e60c69198eb27ca097894ac5cb3b2d143e139480 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Wed, 27 Feb 2019 16:46:15 +0800 Subject: [PATCH 018/134] Update README.md --- core-java-9/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-9/README.md b/core-java-9/README.md index d9586ba684..904782819c 100644 --- a/core-java-9/README.md +++ b/core-java-9/README.md @@ -16,7 +16,7 @@ - [Java 9 Reactive Streams](http://www.baeldung.com/java-9-reactive-streams) - [Java 9 java.util.Objects Additions](http://www.baeldung.com/java-9-objects-new) - [Java 9 Variable Handles Demistyfied](http://www.baeldung.com/java-variable-handles) -- [Exploring the New HTTP Client in Java 9](http://www.baeldung.com/java-9-http-client) +- [Exploring the New HTTP Client in Java 9 and 11](http://www.baeldung.com/java-9-http-client) - [Method Handles in Java](http://www.baeldung.com/java-method-handles) - [Introduction to Chronicle Queue](http://www.baeldung.com/java-chronicle-queue) - [A Guide to Java 9 Modularity](http://www.baeldung.com/java-9-modularity) From 072e2232b08aaf27c194be5e86f527decd386b1e Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 17:00:45 +0800 Subject: [PATCH 019/134] Update README.MD --- persistence-modules/spring-boot-persistence/README.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-boot-persistence/README.MD b/persistence-modules/spring-boot-persistence/README.MD index 6fe5e6f05f..f62ca57a19 100644 --- a/persistence-modules/spring-boot-persistence/README.MD +++ b/persistence-modules/spring-boot-persistence/README.MD @@ -2,7 +2,7 @@ - [Spring Boot with Multiple SQL Import Files](http://www.baeldung.com/spring-boot-sql-import-files) - [Configuring Separate Spring DataSource for Tests](http://www.baeldung.com/spring-testing-separate-data-source) -- [Quick Guide on data.sql and schema.sql Files in Spring Boot](http://www.baeldung.com/spring-boot-data-sql-and-schema-sql) +- [Quick Guide on Loading Initial Data with Spring Boot](http://www.baeldung.com/spring-boot-data-sql-and-schema-sql) - [Configuring a Tomcat Connection Pool in Spring Boot](https://www.baeldung.com/spring-boot-tomcat-connection-pool) - [Hibernate Field Naming with Spring Boot](https://www.baeldung.com/hibernate-field-naming-spring-boot) - [Integrating Spring Boot with HSQLDB](https://www.baeldung.com/spring-boot-hsqldb) From 397ca5b59f946312255e7c0f289554c2614a2cce Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 17:18:43 +0800 Subject: [PATCH 020/134] Update README.MD --- spring-cloud/spring-cloud-gateway/README.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud/spring-cloud-gateway/README.MD b/spring-cloud/spring-cloud-gateway/README.MD index 48fbf41b8e..d945ae949c 100644 --- a/spring-cloud/spring-cloud-gateway/README.MD +++ b/spring-cloud/spring-cloud-gateway/README.MD @@ -1,2 +1,2 @@ ### Relevant Articles: -- [Explore the new Spring Cloud Gateway](http://www.baeldung.com/spring-cloud-gateway) +- [Exploring the new Spring Cloud Gateway](http://www.baeldung.com/spring-cloud-gateway) From 0661a109c7226a97b052599ae74ced53eb8b58a1 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 17:23:21 +0800 Subject: [PATCH 021/134] Update README.md --- jooby/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jooby/README.md b/jooby/README.md index 032e595354..aa867b2c56 100644 --- a/jooby/README.md +++ b/jooby/README.md @@ -1,3 +1,3 @@ ## Relevant articles: -- [Introduction to Jooby Project](http://www.baeldung.com/jooby) +- [Introduction to Jooby](http://www.baeldung.com/jooby) From b41efaaf6b851d7147185616f17a3548f3bb203e Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 17:30:09 +0800 Subject: [PATCH 022/134] Update README.md --- vavr/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vavr/README.md b/vavr/README.md index 0857765ec6..266cae91bb 100644 --- a/vavr/README.md +++ b/vavr/README.md @@ -4,7 +4,7 @@ - [Guide to Pattern Matching in Vavr](http://www.baeldung.com/vavr-pattern-matching) - [Property Testing Example With Vavr](http://www.baeldung.com/vavr-property-testing) - [Exceptions in Lambda Expression Using Vavr](http://www.baeldung.com/exceptions-using-vavr) -- [Vavr (ex-Javaslang) Support in Spring Data](http://www.baeldung.com/spring-vavr) +- [Vavr Support in Spring Data](http://www.baeldung.com/spring-vavr) - [Introduction to Vavr’s Validation API](http://www.baeldung.com/vavr-validation-api) - [Guide to Collections API in Vavr](http://www.baeldung.com/vavr-collections) - [Collection Factory Methods for Vavr](http://www.baeldung.com/vavr-collection-factory-methods) From dad532bb537432a225f39b9814f326eefeafc324 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 17:32:45 +0800 Subject: [PATCH 023/134] Update README.md --- testing-modules/junit-5/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing-modules/junit-5/README.md b/testing-modules/junit-5/README.md index 4ed01e7fa9..e68d72efe3 100644 --- a/testing-modules/junit-5/README.md +++ b/testing-modules/junit-5/README.md @@ -3,7 +3,7 @@ - [A Guide to JUnit 5](http://www.baeldung.com/junit-5) - [A Guide to @RepeatedTest in Junit 5](http://www.baeldung.com/junit-5-repeated-test) - [Guide to Dynamic Tests in Junit 5](http://www.baeldung.com/junit5-dynamic-tests) -- [A Guied to JUnit 5 Extensions](http://www.baeldung.com/junit-5-extensions) +- [A Guide to JUnit 5 Extensions](http://www.baeldung.com/junit-5-extensions) - [Inject Parameters into JUnit Jupiter Unit Tests](http://www.baeldung.com/junit-5-parameters) - [Mockito and JUnit 5 – Using ExtendWith](http://www.baeldung.com/mockito-junit-5-extension) - [JUnit 5 – @RunWith](http://www.baeldung.com/junit-5-runwith) From f7e2c8062304e551e9fa0bb62fd92a90ead9b17b Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 17:35:28 +0800 Subject: [PATCH 024/134] Update README.md --- spring-5-reactive/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-reactive/README.md b/spring-5-reactive/README.md index c39bb616f8..119e57f256 100644 --- a/spring-5-reactive/README.md +++ b/spring-5-reactive/README.md @@ -7,7 +7,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Introduction to the Functional Web Framework in Spring 5](http://www.baeldung.com/spring-5-functional-web) - [Spring 5 WebClient](http://www.baeldung.com/spring-5-webclient) -- [Exploring the Spring 5 MVC URL Matching Improvements](http://www.baeldung.com/spring-5-mvc-url-matching) +- [Exploring the Spring 5 MVC URL Matching](http://www.baeldung.com/spring-5-mvc-url-matching) - [Reactive WebSockets with Spring 5](http://www.baeldung.com/spring-5-reactive-websockets) - [Spring Webflux Filters](http://www.baeldung.com/spring-webflux-filters) - [How to Set a Header on a Response with Spring 5](http://www.baeldung.com/spring-response-header) From af1f80f1469730055ea81a94652cd564f0d94084 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 17:46:06 +0800 Subject: [PATCH 025/134] Update README.md --- core-kotlin/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-kotlin/README.md b/core-kotlin/README.md index 6ee79b2a2e..45163b3f99 100644 --- a/core-kotlin/README.md +++ b/core-kotlin/README.md @@ -4,7 +4,7 @@ - [A guide to the “when{}” block in Kotlin](http://www.baeldung.com/kotlin-when) - [Comprehensive Guide to Null Safety in Kotlin](http://www.baeldung.com/kotlin-null-safety) - [Kotlin Java Interoperability](http://www.baeldung.com/kotlin-java-interoperability) -- [Difference Between “==” and “===” in Kotlin](http://www.baeldung.com/kotlin-equality-operators) +- [Difference Between “==” and “===” operators in Kotlin](http://www.baeldung.com/kotlin-equality-operators) - [Generics in Kotlin](http://www.baeldung.com/kotlin-generics) - [Introduction to Kotlin Coroutines](http://www.baeldung.com/kotlin-coroutines) - [Destructuring Declarations in Kotlin](http://www.baeldung.com/kotlin-destructuring-declarations) From df5e2493c1c05f1016283fd36058d02791734973 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 17:53:09 +0800 Subject: [PATCH 026/134] Update README.md --- core-java-networking/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-networking/README.md b/core-java-networking/README.md index b2367782b6..dd4ee1e151 100644 --- a/core-java-networking/README.md +++ b/core-java-networking/README.md @@ -13,4 +13,4 @@ - [Working with Network Interfaces in Java](http://www.baeldung.com/java-network-interfaces) - [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets) - [URL Encoding and Decoding in Java](http://www.baeldung.com/java-url-encoding-decoding) -- [How to Perform a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request) \ No newline at end of file +- [Do a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request) From 9ac6c2c8de8bf5fd27da13e9d8ba0bbe187e4791 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 19:23:55 +0800 Subject: [PATCH 027/134] Update README.md --- spring-rest/src/main/java/com/baeldung/produceimage/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-rest/src/main/java/com/baeldung/produceimage/README.md b/spring-rest/src/main/java/com/baeldung/produceimage/README.md index acd546598d..4aeadea546 100644 --- a/spring-rest/src/main/java/com/baeldung/produceimage/README.md +++ b/spring-rest/src/main/java/com/baeldung/produceimage/README.md @@ -1,3 +1,3 @@ ### Relevant articles -- [Returning an Image or a File with Spring](http://www.baeldung.com/spring-controller-return-image-file) +- [Download an Image or a File with Spring MVC](http://www.baeldung.com/spring-controller-return-image-file) From c9c6f879d08a72e0ce89d9e03ef98acdf9cd4048 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 19:45:23 +0800 Subject: [PATCH 028/134] Update README.md --- spark-java/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spark-java/README.md b/spark-java/README.md index 711607bd4e..5abe78263c 100644 --- a/spark-java/README.md +++ b/spark-java/README.md @@ -3,4 +3,4 @@ ## Spark Java Framework Tutorial Sample Project ### Relevant Articles -- [Intro to Spark Java Framework](http://www.baeldung.com/spark-framework-rest-api) +- [Building an API With the Spark Java Framework](http://www.baeldung.com/spark-framework-rest-api) From ffe5768eef005a83b8429620e78f961042c999e2 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 19:50:20 +0800 Subject: [PATCH 029/134] Update README.md --- spring-security-core/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-core/README.md b/spring-security-core/README.md index f7b3f6dffe..b38dc061b4 100644 --- a/spring-security-core/README.md +++ b/spring-security-core/README.md @@ -7,6 +7,6 @@ mvn clean install ``` ### Relevant Articles: -- [Intro to @PreFilter and @PostFilter in Spring Security](http://www.baeldung.com/spring-security-prefilter-postfilter) +- [Spring Security – @PreFilter and @PostFilter](http://www.baeldung.com/spring-security-prefilter-postfilter) - [Spring Boot Authentication Auditing Support](http://www.baeldung.com/spring-boot-authentication-audit) - [Introduction to Spring Method Security](http://www.baeldung.com/spring-security-method-security) From 0f5d447fac99e8506461ff11b6332a9e688cfd3e Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 19:53:36 +0800 Subject: [PATCH 030/134] Update README.md --- core-java-networking/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-networking/README.md b/core-java-networking/README.md index dd4ee1e151..f6ce44d72f 100644 --- a/core-java-networking/README.md +++ b/core-java-networking/README.md @@ -12,5 +12,5 @@ - [A Guide to the Java URL](http://www.baeldung.com/java-url) - [Working with Network Interfaces in Java](http://www.baeldung.com/java-network-interfaces) - [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets) -- [URL Encoding and Decoding in Java](http://www.baeldung.com/java-url-encoding-decoding) +- [Guide to Java URL Encoding/Decoding](http://www.baeldung.com/java-url-encoding-decoding) - [Do a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request) From 433af3993b093cd9a1bab12fc7fd629bcb118016 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 19:55:45 +0800 Subject: [PATCH 031/134] Update README.md --- core-java-io/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-io/README.md b/core-java-io/README.md index 9a25009849..ac6d5c4eee 100644 --- a/core-java-io/README.md +++ b/core-java-io/README.md @@ -11,7 +11,7 @@ - [Java – Byte Array to Writer](http://www.baeldung.com/java-convert-byte-array-to-writer) - [Java – Directory Size](http://www.baeldung.com/java-folder-size) - [Differences Between the Java WatchService API and the Apache Commons IO Monitor Library](http://www.baeldung.com/java-watchservice-vs-apache-commons-io-monitor-library) -- [Calculate the Size of a File in Java](http://www.baeldung.com/java-file-size) +- [File Size in Java](http://www.baeldung.com/java-file-size) - [Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java](http://www.baeldung.com/java-path) - [Using Java MappedByteBuffer](http://www.baeldung.com/java-mapped-byte-buffer) - [Copy a File with Java](http://www.baeldung.com/java-copy-file) From dea68e021be5601723e094967ed76429083b9afa Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 19:57:32 +0800 Subject: [PATCH 032/134] Update README.md --- core-java-lang-syntax/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-lang-syntax/README.md b/core-java-lang-syntax/README.md index 99c8613929..e77a8a58cb 100644 --- a/core-java-lang-syntax/README.md +++ b/core-java-lang-syntax/README.md @@ -3,7 +3,7 @@ ## Core Java Lang Syntax Cookbooks and Examples ### Relevant Articles: -- [Introduction to Java Generics](http://www.baeldung.com/java-generics) +- [The Basics of Java Generics](http://www.baeldung.com/java-generics) - [Java Primitive Conversions](http://www.baeldung.com/java-primitive-conversions) - [Java Double Brace Initialization](http://www.baeldung.com/java-double-brace-initialization) - [Guide to the Diamond Operator in Java](http://www.baeldung.com/java-diamond-operator) From 296f70dde9c1f9632a0c9b625d2ffc973358119d Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 19:58:41 +0800 Subject: [PATCH 033/134] Update README.md --- core-java-security/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-security/README.md b/core-java-security/README.md index d3343f79ca..9526b15be5 100644 --- a/core-java-security/README.md +++ b/core-java-security/README.md @@ -8,5 +8,5 @@ - [Encrypting and Decrypting Files in Java](http://www.baeldung.com/java-cipher-input-output-stream) - [Hashing a Password in Java](https://www.baeldung.com/java-password-hashing) - [SSL Handshake Failures](https://www.baeldung.com/java-ssl-handshake-failures) -- [SHA-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java) +- [SHA-256 and SHA3-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java) - [Enabling TLS v1.2 in Java 7](https://www.baeldung.com/java-7-tls-v12) From 76ecabe9614050691e4bbda9e83d5f7eb901ab34 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:04:22 +0800 Subject: [PATCH 034/134] Update README.md --- spring-security-rest-basic-auth/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-rest-basic-auth/README.md b/spring-security-rest-basic-auth/README.md index f92fcfe36b..0c97b9b592 100644 --- a/spring-security-rest-basic-auth/README.md +++ b/spring-security-rest-basic-auth/README.md @@ -9,5 +9,5 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com - [RestTemplate with Basic Authentication in Spring](http://www.baeldung.com/how-to-use-resttemplate-with-basic-authentication-in-spring) - [HttpClient Timeout](http://www.baeldung.com/httpclient-timeout) - [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) -- [Writing a Custom Filter in Spring Security](http://www.baeldung.com/spring-security-custom-filter) +- [A Custom Filter in the Spring Security Filter Chain](http://www.baeldung.com/spring-security-custom-filter) - [Spring Security Basic Authentication](http://www.baeldung.com/spring-security-basic-authentication) From 44c22f4fe77e283edad111dab826616d6712d9df Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:05:37 +0800 Subject: [PATCH 035/134] Update README.md --- spring-jms/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-jms/README.md b/spring-jms/README.md index b942cc72a0..55e74f18ff 100644 --- a/spring-jms/README.md +++ b/spring-jms/README.md @@ -1,2 +1,2 @@ ### Relevant Articles: -- [An Introduction To Spring JMS](http://www.baeldung.com/spring-jms) +- [Getting Started with Spring JMS](http://www.baeldung.com/spring-jms) From 2480c458b9d05e6bc9218b2419ce583941b4f5f1 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:09:34 +0800 Subject: [PATCH 036/134] Update README.md --- core-java-collections-list/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-collections-list/README.md b/core-java-collections-list/README.md index 3a4a7c69e8..5fe84480db 100644 --- a/core-java-collections-list/README.md +++ b/core-java-collections-list/README.md @@ -5,7 +5,7 @@ ### Relevant Articles: - [Immutable ArrayList in Java](http://www.baeldung.com/java-immutable-list) - [Guide to the Java ArrayList](http://www.baeldung.com/java-arraylist) -- [Random List Element](http://www.baeldung.com/java-random-list-element) +- [Java – Get Random Item/Element From a List](http://www.baeldung.com/java-random-list-element) - [Removing all nulls from a List in Java](http://www.baeldung.com/java-remove-nulls-from-list) - [Removing all duplicates from a List in Java](http://www.baeldung.com/java-remove-duplicates-from-list) - [How to TDD a List Implementation in Java](http://www.baeldung.com/java-test-driven-list) From 98325175c57c78cbd246c7d3978d2e463ead77ec Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:16:14 +0800 Subject: [PATCH 037/134] Update README.md --- core-java-8/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-8/README.md b/core-java-8/README.md index 892dc71f76..fb4f54222d 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -4,7 +4,7 @@ ### Relevant Articles: - [Java 8 Collectors](http://www.baeldung.com/java-8-collectors) -- [Guide to Java 8’s Functional Interfaces](http://www.baeldung.com/java-8-functional-interfaces) +- [Functional Interfaces in Java 8](http://www.baeldung.com/java-8-functional-interfaces) - [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda) - [Java 8 New Features](http://www.baeldung.com/java-8-new-features) - [Lambda Expressions and Functional Interfaces: Tips and Best Practices](http://www.baeldung.com/java-8-lambda-expressions-tips) From 1a020467280fd9d3f465b84fcf4c9cd98e83a21d Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:18:10 +0800 Subject: [PATCH 038/134] Update README.md --- spring-all/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-all/README.md b/spring-all/README.md index 0d78efdcf2..791af2cb58 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -15,7 +15,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring Profiles](http://www.baeldung.com/spring-profiles) - [A Spring Custom Annotation for a Better DAO](http://www.baeldung.com/spring-annotation-bean-pre-processor) - [What's New in Spring 4.3?](http://www.baeldung.com/whats-new-in-spring-4-3) -- [Guide To Running Logic on Startup in Spring](http://www.baeldung.com/running-setup-logic-on-startup-in-spring) +- [Running Setup Data on Startup in Spring](http://www.baeldung.com/running-setup-logic-on-startup-in-spring) - [Quick Guide to Spring Controllers](http://www.baeldung.com/spring-controllers) - [Quick Guide to Spring Bean Scopes](http://www.baeldung.com/spring-bean-scopes) - [Introduction To Ehcache](http://www.baeldung.com/ehcache) From 295bc9d070a1f9a9a8ec674acd89cb975543fbf3 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:19:16 +0800 Subject: [PATCH 039/134] Update README.md --- jsf/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsf/README.md b/jsf/README.md index 6e0891182d..d96c1eb8e3 100644 --- a/jsf/README.md +++ b/jsf/README.md @@ -1,5 +1,5 @@ ### Relevant Articles: -- [Introduction to JSF Expression Language 3.0](http://www.baeldung.com/jsf-expression-language-el-3) +- [Guide to JSF Expression Language 3.0](http://www.baeldung.com/jsf-expression-language-el-3) - [Introduction to JSF EL 2](http://www.baeldung.com/intro-to-jsf-expression-language) - [JavaServer Faces (JSF) with Spring](http://www.baeldung.com/spring-jsf) - [Introduction to Primefaces](http://www.baeldung.com/jsf-primefaces) From 53d1331ea8eafd8f3ee4bfb7ea834c43b7f547d1 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:20:47 +0800 Subject: [PATCH 040/134] Update README.md --- persistence-modules/spring-hibernate-5/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-hibernate-5/README.md b/persistence-modules/spring-hibernate-5/README.md index 5e287919f1..c48e58fcca 100644 --- a/persistence-modules/spring-hibernate-5/README.md +++ b/persistence-modules/spring-hibernate-5/README.md @@ -2,4 +2,4 @@ - [Hibernate Many to Many Annotation Tutorial](http://www.baeldung.com/hibernate-many-to-many) - [Programmatic Transactions in the Spring TestContext Framework](http://www.baeldung.com/spring-test-programmatic-transactions) -- [Hibernate Criteria Queries](http://www.baeldung.com/hibernate-criteria-queries) +- [JPA Criteria Queries](http://www.baeldung.com/hibernate-criteria-queries) From 44f84c548510f93ba7b5705ebea78d0d3d7763e8 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:23:44 +0800 Subject: [PATCH 041/134] Update README.md --- testing-modules/testing/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing-modules/testing/README.md b/testing-modules/testing/README.md index 849b578a55..e96b26ab41 100644 --- a/testing-modules/testing/README.md +++ b/testing-modules/testing/README.md @@ -3,7 +3,7 @@ ## Mutation Testing ### Relevant Articles: -- [Introduction to Mutation Testing Using the PITest Library](http://www.baeldung.com/java-mutation-testing-with-pitest) +- [Mutation Testing with PITest](http://www.baeldung.com/java-mutation-testing-with-pitest) - [Intro to JaCoCo](http://www.baeldung.com/jacoco) - [AssertJ’s Java 8 Features](http://www.baeldung.com/assertJ-java-8-features) - [AssertJ for Guava](http://www.baeldung.com/assertJ-for-guava) From cc5a956133d0b7b6bb426a15c2fce43d52a43ea7 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:25:32 +0800 Subject: [PATCH 042/134] Update README.md --- java-streams/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-streams/README.md b/java-streams/README.md index 15ea1c742a..b931c0d7d9 100644 --- a/java-streams/README.md +++ b/java-streams/README.md @@ -3,7 +3,7 @@ ## Java Streams Cookbooks and Examples ### Relevant Articles: -- [Java 8 Streams Advanced](http://www.baeldung.com/java-8-streams) +- [The Java 8 Stream API Tutorial](http://www.baeldung.com/java-8-streams) - [Introduction to Java 8 Streams](http://www.baeldung.com/java-8-streams-introduction) - [Java 8 and Infinite Streams](http://www.baeldung.com/java-inifinite-streams) - [Java 8 Stream findFirst() vs. findAny()](http://www.baeldung.com/java-stream-findfirst-vs-findany) From 850c0096662ae04b6db9a02026db9b5c6a909825 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:29:55 +0800 Subject: [PATCH 043/134] Update README.md --- core-java-8/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-8/README.md b/core-java-8/README.md index fb4f54222d..f601ea9d37 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -6,7 +6,7 @@ - [Java 8 Collectors](http://www.baeldung.com/java-8-collectors) - [Functional Interfaces in Java 8](http://www.baeldung.com/java-8-functional-interfaces) - [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda) -- [Java 8 New Features](http://www.baeldung.com/java-8-new-features) +- [New Features in Java 8](http://www.baeldung.com/java-8-new-features) - [Lambda Expressions and Functional Interfaces: Tips and Best Practices](http://www.baeldung.com/java-8-lambda-expressions-tips) - [The Double Colon Operator in Java 8](http://www.baeldung.com/java-8-double-colon-operator) - [Guide to Java 8 groupingBy Collector](http://www.baeldung.com/java-groupingby-collector) From b0eac9be89ede158fc9b139797ef2d1545641781 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:33:41 +0800 Subject: [PATCH 044/134] Update README.md --- persistence-modules/spring-data-couchbase-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-data-couchbase-2/README.md b/persistence-modules/spring-data-couchbase-2/README.md index 2e56b25fef..2b6a1faddf 100644 --- a/persistence-modules/spring-data-couchbase-2/README.md +++ b/persistence-modules/spring-data-couchbase-2/README.md @@ -1,7 +1,7 @@ ## Spring Data Couchbase Tutorial Project ### Relevant Articles: -- [Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase) +- [Intro to Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase) - [Entity Validation, Query Consistency, and Optimistic Locking in Spring Data Couchbase](http://www.baeldung.com/entity-validation-locking-and-query-consistency-in-spring-data-couchbase) - [Multiple Buckets and Spatial View Queries in Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase-buckets-and-spatial-view-queries) From 5ebfdee1501256f1c403ecfcb3132cf8bc0cb97f Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:35:00 +0800 Subject: [PATCH 045/134] Update README.md --- spring-katharsis/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-katharsis/README.md b/spring-katharsis/README.md index cf2a001760..2082de2dda 100644 --- a/spring-katharsis/README.md +++ b/spring-katharsis/README.md @@ -6,4 +6,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: -- [JSON API in a Java Web Application](http://www.baeldung.com/json-api-java-spring-web-app) +- [JSON API in a Spring Application](http://www.baeldung.com/json-api-java-spring-web-app) From 847d694adfef47554d37f3cc8c4474b3e272d6a0 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:36:16 +0800 Subject: [PATCH 046/134] Update README.md --- spring-resttemplate/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-resttemplate/README.md b/spring-resttemplate/README.md index 1c8ddf73f9..353e9f955e 100644 --- a/spring-resttemplate/README.md +++ b/spring-resttemplate/README.md @@ -4,7 +4,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: -- [Spring RestTemplate Tutorial](http://www.baeldung.com/rest-template) +- [The Guide to RestTemplate](http://www.baeldung.com/rest-template) - [Exploring the Spring Boot TestRestTemplate](http://www.baeldung.com/spring-boot-testresttemplate) - [Spring RestTemplate Error Handling](http://www.baeldung.com/spring-rest-template-error-handling) - [Configure a RestTemplate with RestTemplateBuilder](http://www.baeldung.com/spring-rest-template-builder) From fd4104c8fd668f3c89b9eb2bb8458f867ab397b7 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:39:35 +0800 Subject: [PATCH 047/134] Update README.md --- jackson/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jackson/README.md b/jackson/README.md index e201a06727..0806575367 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -17,7 +17,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Jackson JSON Tutorial](http://www.baeldung.com/jackson) - [Jackson – Working with Maps and nulls](http://www.baeldung.com/jackson-map-null-values-or-null-key) - [Jackson – Decide What Fields Get Serialized/Deserializaed](http://www.baeldung.com/jackson-field-serializable-deserializable-or-not) -- [A Guide to Jackson Annotations](http://www.baeldung.com/jackson-annotations) +- [Jackson Annotation Examples](http://www.baeldung.com/jackson-annotations) - [Working with Tree Model Nodes in Jackson](http://www.baeldung.com/jackson-json-node-tree-model) - [Jackson vs Gson](http://www.baeldung.com/jackson-vs-gson) - [Intro to the Jackson ObjectMapper](http://www.baeldung.com/jackson-object-mapper-tutorial) From d9debd5daf484dc9e15a78da3401952f1888e88e Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:42:40 +0800 Subject: [PATCH 048/134] Update README.md --- testing-modules/mockito/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing-modules/mockito/README.md b/testing-modules/mockito/README.md index 158a1918e7..59954784f9 100644 --- a/testing-modules/mockito/README.md +++ b/testing-modules/mockito/README.md @@ -7,7 +7,7 @@ - [Mockito Verify Cookbook](http://www.baeldung.com/mockito-verify) - [Mockito When/Then Cookbook](http://www.baeldung.com/mockito-behavior) - [Mockito – Using Spies](http://www.baeldung.com/mockito-spy) -- [Mockito – @Mock, @Spy, @Captor and @InjectMocks](http://www.baeldung.com/mockito-annotations) +- [Getting Started with Mockito @Mock, @Spy, @Captor and @InjectMocks](http://www.baeldung.com/mockito-annotations) - [Mockito’s Mock Methods](http://www.baeldung.com/mockito-mock-methods) - [Introduction to PowerMock](http://www.baeldung.com/intro-to-powermock) - [Mocking Exception Throwing using Mockito](http://www.baeldung.com/mockito-exceptions) From 3728f2e2618000ba40a6186aba3ef78655aee0e1 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:47:08 +0800 Subject: [PATCH 049/134] Update README.md --- spring-security-rest-basic-auth/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-rest-basic-auth/README.md b/spring-security-rest-basic-auth/README.md index 0c97b9b592..30da3afbcf 100644 --- a/spring-security-rest-basic-auth/README.md +++ b/spring-security-rest-basic-auth/README.md @@ -6,7 +6,7 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com ### Relevant Articles: -- [RestTemplate with Basic Authentication in Spring](http://www.baeldung.com/how-to-use-resttemplate-with-basic-authentication-in-spring) +- [Basic Authentication with the RestTemplate](http://www.baeldung.com/how-to-use-resttemplate-with-basic-authentication-in-spring) - [HttpClient Timeout](http://www.baeldung.com/httpclient-timeout) - [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) - [A Custom Filter in the Spring Security Filter Chain](http://www.baeldung.com/spring-security-custom-filter) From f463cc341e48444cd0ae32ce1cde7fb2c8c6abfa Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:48:31 +0800 Subject: [PATCH 050/134] Update README.md --- httpclient/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpclient/README.md b/httpclient/README.md index 93e0f3c9e1..19886be750 100644 --- a/httpclient/README.md +++ b/httpclient/README.md @@ -14,7 +14,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient) - [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) - [HttpClient 4 – Follow Redirects for POST](http://www.baeldung.com/httpclient-redirect-on-http-post) -- [HttpClient – Set Custom Header](http://www.baeldung.com/httpclient-custom-http-header) +- [Custom HTTP Header with the HttpClient](http://www.baeldung.com/httpclient-custom-http-header) - [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication) - [Multipart Upload with HttpClient 4](http://www.baeldung.com/httpclient-multipart-upload) - [HttpAsyncClient Tutorial](http://www.baeldung.com/httpasyncclient-tutorial) From ffc4ab61b4421e4c4f72bcf5f5a5e47e8ea3d81c Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:49:57 +0800 Subject: [PATCH 051/134] Update README.md --- jackson/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jackson/README.md b/jackson/README.md index 0806575367..519673738f 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -10,7 +10,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array) - [Jackson Unmarshalling json with Unknown Properties](http://www.baeldung.com/jackson-deserialize-json-unknown-properties) - [Jackson – Custom Serializer](http://www.baeldung.com/jackson-custom-serialization) -- [Jackson – Custom Deserializer](http://www.baeldung.com/jackson-deserialization) +- [Getting Started with Custom Deserialization in Jackson](http://www.baeldung.com/jackson-deserialization) - [Jackson Exceptions – Problems and Solutions](http://www.baeldung.com/jackson-exception) - [Jackson Date](http://www.baeldung.com/jackson-serialize-dates) - [Jackson – Bidirectional Relationships](http://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion) From 5b65fc65dc0a37465c414b7840fd5907dccb747a Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:51:04 +0800 Subject: [PATCH 052/134] Update README.md --- core-java-io/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-io/README.md b/core-java-io/README.md index ac6d5c4eee..5e0f7bfbd1 100644 --- a/core-java-io/README.md +++ b/core-java-io/README.md @@ -3,7 +3,7 @@ ## Core Java IO Cookbooks and Examples ### Relevant Articles: -- [Java - Reading a Large File Efficiently](http://www.baeldung.com/java-read-lines-large-file) +- [How to Read a Large File Efficiently with Java](http://www.baeldung.com/java-read-lines-large-file) - [Java InputStream to String](http://www.baeldung.com/convert-input-stream-to-string) - [Java – Write to File](http://www.baeldung.com/java-write-to-file) - [Java - Convert File to InputStream](http://www.baeldung.com/convert-file-to-input-stream) From 1b8f5e1837834c1506ebe269b8993150eed29336 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:54:45 +0800 Subject: [PATCH 053/134] Update README.md --- httpclient/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpclient/README.md b/httpclient/README.md index 19886be750..7c5122c5b8 100644 --- a/httpclient/README.md +++ b/httpclient/README.md @@ -21,4 +21,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [HttpClient 4 Tutorial](http://www.baeldung.com/httpclient-guide) - [Advanced HttpClient Configuration](http://www.baeldung.com/httpclient-advanced-config) - [HttpClient 4 – Do Not Follow Redirects](http://www.baeldung.com/httpclient-stop-follow-redirect) -- [HttpClient 4 – Setting a Custom User-Agent](http://www.baeldung.com/httpclient-user-agent-header) +- [Custom User-Agent in HttpClient 4](http://www.baeldung.com/httpclient-user-agent-header) From 4ddb3c8c6f936fcea37541d1d1287c79f84cbd69 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:56:39 +0800 Subject: [PATCH 054/134] Update README.md --- spring-all/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-all/README.md b/spring-all/README.md index 791af2cb58..6e392088d9 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -11,7 +11,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant articles: - [Guide to Spring @Autowired](http://www.baeldung.com/spring-autowire) -- [Properties with Spring](http://www.baeldung.com/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage +- [Properties with Spring and Spring Boot](http://www.baeldung.com/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage - [Spring Profiles](http://www.baeldung.com/spring-profiles) - [A Spring Custom Annotation for a Better DAO](http://www.baeldung.com/spring-annotation-bean-pre-processor) - [What's New in Spring 4.3?](http://www.baeldung.com/whats-new-in-spring-4-3) From db2454c10f6ebbca45a678e54b8a677174bb8157 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:57:35 +0800 Subject: [PATCH 055/134] Update README.md --- spring-mvc-xml/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-mvc-xml/README.md b/spring-mvc-xml/README.md index 3199118281..dbc6125424 100644 --- a/spring-mvc-xml/README.md +++ b/spring-mvc-xml/README.md @@ -8,7 +8,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: -- [Servlet Session Timeout](http://www.baeldung.com/servlet-session-timeout) +- [Java Session Timeout](http://www.baeldung.com/servlet-session-timeout) - [Returning Image/Media Data with Spring MVC](http://www.baeldung.com/spring-mvc-image-media-data) - [Geolocation by IP in Java](http://www.baeldung.com/geolocation-by-ip-with-maxmind) - [Guide to JavaServer Pages (JSP)](http://www.baeldung.com/jsp) From 10fe310a930aae4bef7bf7954cd10e3017006931 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 20:59:23 +0800 Subject: [PATCH 056/134] Update README.md --- spring-security-mvc-session/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-mvc-session/README.md b/spring-security-mvc-session/README.md index fc44209640..ce40ed5f5f 100644 --- a/spring-security-mvc-session/README.md +++ b/spring-security-mvc-session/README.md @@ -7,7 +7,7 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com ### Relevant Articles: - [HttpSessionListener Example – Monitoring](http://www.baeldung.com/httpsessionlistener_with_metrics) -- [Spring Security Session Management](http://www.baeldung.com/spring-security-session) +- [Control the Session with Spring Security](http://www.baeldung.com/spring-security-session) ### Build the Project From 4df758c4e217ad57842ce0a61fbeb28b1b233510 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 21:00:50 +0800 Subject: [PATCH 057/134] Update README.md --- persistence-modules/spring-hibernate4/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-hibernate4/README.md b/persistence-modules/spring-hibernate4/README.md index 57a341ed45..c6d846a18d 100644 --- a/persistence-modules/spring-hibernate4/README.md +++ b/persistence-modules/spring-hibernate4/README.md @@ -3,7 +3,7 @@ ## Spring with Hibernate 4 Example Project ### Relevant Articles: -- [Hibernate 4 with Spring](http://www.baeldung.com/hibernate-4-spring) +- [Guide to Hibernate 4 with Spring](http://www.baeldung.com/hibernate-4-spring) - [The DAO with Spring 3 and Hibernate](http://www.baeldung.com/persistence-layer-with-spring-and-hibernate) - [Hibernate Pagination](http://www.baeldung.com/hibernate-pagination) - [Sorting with Hibernate](http://www.baeldung.com/hibernate-sort) From e3ba00d4fdd6fdfada6b38dae2c17fdc26b11c8f Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 21:01:26 +0800 Subject: [PATCH 058/134] Update README.md --- persistence-modules/spring-hibernate4/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-hibernate4/README.md b/persistence-modules/spring-hibernate4/README.md index c6d846a18d..f2553ad229 100644 --- a/persistence-modules/spring-hibernate4/README.md +++ b/persistence-modules/spring-hibernate4/README.md @@ -4,7 +4,7 @@ ### Relevant Articles: - [Guide to Hibernate 4 with Spring](http://www.baeldung.com/hibernate-4-spring) -- [The DAO with Spring 3 and Hibernate](http://www.baeldung.com/persistence-layer-with-spring-and-hibernate) +- [The DAO with Spring and Hibernate](http://www.baeldung.com/persistence-layer-with-spring-and-hibernate) - [Hibernate Pagination](http://www.baeldung.com/hibernate-pagination) - [Sorting with Hibernate](http://www.baeldung.com/hibernate-sort) - [Stored Procedures with Hibernate](http://www.baeldung.com/stored-procedures-with-hibernate-tutorial) From 60d198882476d3579693929fad8e4755c94d4cfd Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 21:05:52 +0800 Subject: [PATCH 059/134] Update README.md --- core-java-lang-syntax/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-lang-syntax/README.md b/core-java-lang-syntax/README.md index e77a8a58cb..81c3d6c354 100644 --- a/core-java-lang-syntax/README.md +++ b/core-java-lang-syntax/README.md @@ -8,7 +8,7 @@ - [Java Double Brace Initialization](http://www.baeldung.com/java-double-brace-initialization) - [Guide to the Diamond Operator in Java](http://www.baeldung.com/java-diamond-operator) - [The Java continue and break Keywords](http://www.baeldung.com/java-continue-and-break) -- [A Guide to Java Initialization](http://www.baeldung.com/java-initialization) +- [A Guide to Creating Objects in Java](http://www.baeldung.com/java-initialization) - [A Guide to Java Loops](http://www.baeldung.com/java-loops) - [Varargs in Java](http://www.baeldung.com/java-varargs) - [A Guide to Java Enums](http://www.baeldung.com/a-guide-to-java-enums) From d7c44430102f40540414b1941c43f3af69e4d688 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 21:15:55 +0800 Subject: [PATCH 060/134] Update README.md --- testing-modules/junit-5/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing-modules/junit-5/README.md b/testing-modules/junit-5/README.md index e68d72efe3..abd50261e7 100644 --- a/testing-modules/junit-5/README.md +++ b/testing-modules/junit-5/README.md @@ -8,7 +8,7 @@ - [Mockito and JUnit 5 – Using ExtendWith](http://www.baeldung.com/mockito-junit-5-extension) - [JUnit 5 – @RunWith](http://www.baeldung.com/junit-5-runwith) - [JUnit 5 @Test Annotation](http://www.baeldung.com/junit-5-test-annotation) -- [JUnit Assert an Exception is Thrown](http://www.baeldung.com/junit-assert-exception) +- [Assert an Exception is Thrown in JUnit 4 and 5](http://www.baeldung.com/junit-assert-exception) - [@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll](http://www.baeldung.com/junit-before-beforeclass-beforeeach-beforeall) - [Migrating from JUnit 4 to JUnit 5](http://www.baeldung.com/junit-5-migration) - [JUnit5 Programmatic Extension Registration with @RegisterExtension](http://www.baeldung.com/junit-5-registerextension-annotation) From ffc06440554a22eae0e94634695168831c9ec979 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 21:17:44 +0800 Subject: [PATCH 061/134] Update README.md --- spring-all/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-all/README.md b/spring-all/README.md index 6e392088d9..81dd435007 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -28,7 +28,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Model, ModelMap, and ModelView in Spring MVC](http://www.baeldung.com/spring-mvc-model-model-map-model-view) - [A Guide To Caching in Spring](http://www.baeldung.com/spring-cache-tutorial) - [How To Do @Async in Spring](http://www.baeldung.com/spring-async) -- [Quick Guide to the Spring @Order Annotation](http://www.baeldung.com/spring-order) +- [@Order in Spring](http://www.baeldung.com/spring-order) - [Spring Web Contexts](http://www.baeldung.com/spring-web-contexts) - [Spring Cache – Creating a Custom KeyGenerator](http://www.baeldung.com/spring-cache-custom-keygenerator) - [Spring @Primary Annotation](http://www.baeldung.com/spring-primary) From 1e8cc42e2072f0a39e77e4b8d7031120ff4f26b6 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 21:20:04 +0800 Subject: [PATCH 062/134] Update README.md --- java-strings/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-strings/README.md b/java-strings/README.md index 1ab5e098f6..fc9748cd2c 100644 --- a/java-strings/README.md +++ b/java-strings/README.md @@ -22,7 +22,7 @@ - [Check if a String is a Palindrome](http://www.baeldung.com/java-palindrome) - [Comparing Strings in Java](http://www.baeldung.com/java-compare-strings) - [Check If a String Is Numeric in Java](http://www.baeldung.com/java-check-string-number) -- [Why Use char[] Array Over a String for Storing Passwords in Java?](http://www.baeldung.com/java-storing-passwords) +- [Use char[] Array Over a String for Manipulating Passwords in Java?](http://www.baeldung.com/java-storing-passwords) - [Convert a String to Title Case](http://www.baeldung.com/java-string-title-case) - [Compact Strings in Java 9](http://www.baeldung.com/java-9-compact-string) - [Java Check a String for Lowercase/Uppercase Letter, Special Character and Digit](https://www.baeldung.com/java-lowercase-uppercase-special-character-digit-regex) From df9935ce979d952bf2c5e8be4de5a95853698f82 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 21:22:25 +0800 Subject: [PATCH 063/134] Update README.md --- persistence-modules/hibernate5/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/hibernate5/README.md b/persistence-modules/hibernate5/README.md index a4e95a9062..b7f2cd8387 100644 --- a/persistence-modules/hibernate5/README.md +++ b/persistence-modules/hibernate5/README.md @@ -18,7 +18,7 @@ - [@JoinColumn Annotation Explained](https://www.baeldung.com/jpa-join-column) - [Hibernate 5 Naming Strategy Configuration](https://www.baeldung.com/hibernate-naming-strategy) - [Proxy in Hibernate load() Method](https://www.baeldung.com/hibernate-proxy-load-method) -- [Custom Types in Hibernate](https://www.baeldung.com/hibernate-custom-types) +- [Custom Types in Hibernate and the @Type Annotation](https://www.baeldung.com/hibernate-custom-types) - [Criteria API – An Example of IN Expressions](https://www.baeldung.com/jpa-criteria-api-in-expressions) - [Difference Between @JoinColumn and mappedBy](https://www.baeldung.com/jpa-joincolumn-vs-mappedby) - [Hibernate 5 Bootstrapping API](https://www.baeldung.com/hibernate-5-bootstrapping-api) From ee475e09d703591f8262941de6ebd6ef4540f7d0 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Thu, 28 Feb 2019 21:54:27 +0800 Subject: [PATCH 064/134] Update README.md --- spring-boot-bootstrap/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-bootstrap/README.md b/spring-boot-bootstrap/README.md index 2186aa8fec..70fcd90118 100644 --- a/spring-boot-bootstrap/README.md +++ b/spring-boot-bootstrap/README.md @@ -1,5 +1,5 @@ ### Relevant Articles: -- [Bootstrap a Simple Application using Spring Boot](http://www.baeldung.com/spring-boot-start) +- [Spring Boot Tutorial – Bootstrap a Simple Application](http://www.baeldung.com/spring-boot-start) - [Spring Boot Dependency Management with a Custom Parent](http://www.baeldung.com/spring-boot-dependency-management-custom-parent) - [Thin JARs with Spring Boot](http://www.baeldung.com/spring-boot-thin-jar) - [Deploying a Spring Boot Application to Cloud Foundry](https://www.baeldung.com/spring-boot-app-deploy-to-cloud-foundry) From d62fd333b0b8f6a0eb953d6b7720093f3b58b977 Mon Sep 17 00:00:00 2001 From: Jonathan Paul Cook Date: Thu, 28 Feb 2019 17:09:00 +0100 Subject: [PATCH 065/134] BAEL-2512 - Add a new section in Mockito Spy article --- .../misusing/MockitoMisusingUnitTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java diff --git a/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java b/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java new file mode 100644 index 0000000000..e2de23aa14 --- /dev/null +++ b/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java @@ -0,0 +1,30 @@ +package org.baeldung.mockito.misusing; + +import static org.hamcrest.core.StringContains.containsString; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.exceptions.misusing.NotAMockException; + +public class MockitoMisusingUnitTest { + + @Test + public void givenNotASpy_whenDoReturn_thenThrowNotAMock() { + try { + List list = new ArrayList(); + Mockito.doReturn(100) + .when(list) + .size(); + + fail("Should have thrown a NotAMockException because 'list' is not a mock!"); + } catch (NotAMockException e) { + assertThat(e.getMessage(), containsString("Argument passed to when() is not a mock!")); + } + } + +} From f067f5a0f5f254ec919c09b6d0a851abc0ebffaa Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Thu, 28 Feb 2019 22:15:51 +0530 Subject: [PATCH 066/134] BAEL-10890 Added aggregator poms in several projects, cleaned up main pom.xml --- cas/pom.xml | 21 ++++ guava-modules/pom.xml | 22 ++++ logging-modules/pom.xml | 23 ++++ persistence-modules/pom.xml | 58 ++++++++++ pom.xml | 198 ++++----------------------------- rule-engines/pom.xml | 22 ++++ spring-security-client/pom.xml | 25 +++++ testing-modules/pom.xml | 36 ++++++ 8 files changed, 230 insertions(+), 175 deletions(-) create mode 100644 cas/pom.xml create mode 100644 guava-modules/pom.xml create mode 100644 logging-modules/pom.xml create mode 100644 persistence-modules/pom.xml create mode 100644 rule-engines/pom.xml create mode 100644 spring-security-client/pom.xml create mode 100644 testing-modules/pom.xml diff --git a/cas/pom.xml b/cas/pom.xml new file mode 100644 index 0000000000..ac766ae5bf --- /dev/null +++ b/cas/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + cas + cas + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + .. + + + + cas-secured-app + cas-server + + + diff --git a/guava-modules/pom.xml b/guava-modules/pom.xml new file mode 100644 index 0000000000..7a5f217c15 --- /dev/null +++ b/guava-modules/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + guava-modules + guava-modules + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + .. + + + + guava-18 + guava-19 + guava-21 + + + diff --git a/logging-modules/pom.xml b/logging-modules/pom.xml new file mode 100644 index 0000000000..d48955b1b8 --- /dev/null +++ b/logging-modules/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + logging-modules + logging-modules + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + .. + + + + log4j + log4j2 + logback + log-mdc + + + diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml new file mode 100644 index 0000000000..beba135d7f --- /dev/null +++ b/persistence-modules/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + persistence-modules + persistence-modules + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + .. + + + + activejdbc + apache-cayenne + core-java-persistence + deltaspike + flyway + hbase + hibernate5 + hibernate-ogm + influxdb + java-cassandra + java-cockroachdb + java-jdbi + java-jpa + java-mongodb + jnosql + liquibase + orientdb + querydsl + redis + solr + spring-boot-h2/spring-boot-h2-database + spring-boot-persistence + spring-boot-persistence-mongodb + spring-data-cassandra + spring-data-cassandra-reactive + spring-data-couchbase-2 + spring-data-dynamodb + spring-data-eclipselink + spring-data-elasticsearch + spring-data-gemfire + spring-data-jpa + spring-data-keyvalue + spring-data-mongodb + spring-data-neo4j + spring-data-redis + spring-data-solr + spring-hibernate-3 + spring-hibernate-5 + spring-hibernate4 + spring-jpa + + diff --git a/pom.xml b/pom.xml index 0a401299ba..d26b96ea8e 100644 --- a/pom.xml +++ b/pom.xml @@ -371,8 +371,7 @@ bootique - cas/cas-secured-app - cas/cas-server + cas cdi checker-plugin core-groovy @@ -422,9 +421,7 @@ gson guava guava-collections - guava-modules/guava-18 - guava-modules/guava-19 - guava-modules/guava-21 + guava-modules guice @@ -475,16 +472,13 @@ kotlin-libraries - libraries + libraries libraries-data libraries-apache-commons libraries-security libraries-server linkrest - logging-modules/log4j - logging-modules/log4j2 - logging-modules/logback - logging-modules/log-mdc + logging-modules lombok lucene @@ -515,45 +509,7 @@ protobuffer - persistence-modules/activejdbc - persistence-modules/apache-cayenne - persistence-modules/core-java-persistence - persistence-modules/deltaspike - persistence-modules/flyway - persistence-modules/hbase - persistence-modules/hibernate5 - persistence-modules/hibernate-ogm - persistence-modules/influxdb - persistence-modules/java-cassandra - persistence-modules/java-cockroachdb - persistence-modules/java-jdbi - persistence-modules/java-jpa - persistence-modules/jnosql - persistence-modules/liquibase - persistence-modules/orientdb - persistence-modules/querydsl - persistence-modules/redis - persistence-modules/solr - persistence-modules/spring-boot-h2/spring-boot-h2-database - persistence-modules/spring-boot-persistence - persistence-modules/spring-boot-persistence-mongodb - persistence-modules/spring-data-cassandra - persistence-modules/spring-data-cassandra-reactive - persistence-modules/spring-data-couchbase-2 - persistence-modules/spring-data-dynamodb - persistence-modules/spring-data-eclipselink - persistence-modules/spring-data-elasticsearch - persistence-modules/spring-data-gemfire - persistence-modules/spring-data-jpa - persistence-modules/spring-data-keyvalue - persistence-modules/spring-data-mongodb - persistence-modules/spring-data-neo4j - persistence-modules/spring-data-redis - persistence-modules/spring-data-solr - persistence-modules/spring-hibernate-3 - persistence-modules/spring-hibernate-5 - persistence-modules/spring-hibernate4 - persistence-modules/spring-jpa + persistence-modules rabbitmq @@ -563,9 +519,7 @@ resteasy restx - rule-engines/easy-rules - rule-engines/openl-tablets - rule-engines/rulebook + rule-engines rsocket rxjava rxjava-2 @@ -721,13 +675,7 @@ spring-security-angular/server spring-security-cache-control - spring-security-client/spring-security-jsp-authentication - spring-security-client/spring-security-jsp-authorize - spring-security-client/spring-security-jsp-config - spring-security-client/spring-security-mvc - spring-security-client/spring-security-thymeleaf-authentication - spring-security-client/spring-security-thymeleaf-authorize - spring-security-client/spring-security-thymeleaf-config + spring-security-client spring-security-core spring-security-mvc-boot @@ -773,24 +721,7 @@ structurizr struts-2 - testing-modules/gatling - testing-modules/groovy-spock - testing-modules/junit-5 - testing-modules/junit5-migration - testing-modules/load-testing-comparison - testing-modules/mockito - testing-modules/mockito-2 - testing-modules/mocks - testing-modules/mockserver - testing-modules/parallel-tests-junit - testing-modules/rest-assured - testing-modules/rest-testing - - testing-modules/selenium-junit-testng - testing-modules/spring-testing - testing-modules/test-containers - testing-modules/testing - testing-modules/testng + testing-modules twilio Twitter4J @@ -849,8 +780,7 @@ spring-apache-camel spring-batch spring-bom - spring-boot-admin/spring-boot-admin-client - spring-boot-admin/spring-boot-admin-server + spring-boot-admin spring-boot-bootstrap spring-boot-bootstrap spring-boot-camel @@ -862,22 +792,18 @@ spring-boot-jasypt spring-boot-keycloak spring-boot-mvc - spring-boot-property-exp/property-exp-custom-config - spring-boot-property-exp/property-exp-default-config + spring-boot-property-exp spring-boot-vue spring-cloud spring-cloud/spring-cloud-archaius/basic-config spring-cloud/spring-cloud-archaius/extra-configs spring-cloud/spring-cloud-bootstrap/config - spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer - spring-cloud/spring-cloud-contract/spring-cloud-contract-producer + spring-cloud/spring-cloud-contract spring-cloud/spring-cloud-gateway spring-cloud/spring-cloud-kubernetes/demo-backend spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server spring-cloud/spring-cloud-ribbon-client - spring-cloud/spring-cloud-security/auth-client - spring-cloud/spring-cloud-security/auth-resource - spring-cloud/spring-cloud-security/auth-server + spring-cloud/spring-cloud-security spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit spring-cloud/spring-cloud-task/springcloudtasksink spring-cloud/spring-cloud-zookeeper @@ -925,13 +851,7 @@ spring-security-acl spring-security-angular spring-security-cache-control - spring-security-client/spring-security-jsp-authentication - spring-security-client/spring-security-jsp-authorize - spring-security-client/spring-security-jsp-config - spring-security-client/spring-security-mvc - spring-security-client/spring-security-thymeleaf-authentication - spring-security-client/spring-security-thymeleaf-authorize - spring-security-client/spring-security-thymeleaf-config + spring-security-client spring-security-core spring-security-mvc-boot spring-security-mvc-custom @@ -941,14 +861,11 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-rest - spring-security-sso/spring-security-sso-auth-server - spring-security-sso/spring-security-sso-ui - spring-security-sso/spring-security-sso-ui-2 + spring-security-sso spring-security-thymeleaf/spring-security-thymeleaf-authentication spring-security-thymeleaf/spring-security-thymeleaf-authorize spring-security-thymeleaf/spring-security-thymeleaf-config - spring-security-x509/spring-security-x509-basic-auth - spring-security-x509/spring-security-x509-client-auth + spring-security-x509 spring-session/spring-session-jdbc spring-sleuth spring-social-login @@ -1090,8 +1007,7 @@ bootique - cas/cas-secured-app - cas/cas-server + cas cdi checker-plugin core-groovy @@ -1140,9 +1056,7 @@ gson guava guava-collections - guava-modules/guava-18 - guava-modules/guava-19 - guava-modules/guava-21 + guava-modules guice @@ -1199,10 +1113,7 @@ libraries-security libraries-server linkrest - logging-modules/log4j - logging-modules/log4j2 - logging-modules/logback - logging-modules/log-mdc + logging-modules lombok lucene @@ -1233,46 +1144,8 @@ protobuffer - persistence-modules/activejdbc - persistence-modules/apache-cayenne - persistence-modules/core-java-persistence - persistence-modules/deltaspike - persistence-modules/flyway - persistence-modules/hbase - persistence-modules/hibernate5 - persistence-modules/hibernate-ogm - persistence-modules/influxdb - persistence-modules/java-cassandra - persistence-modules/java-cockroachdb - persistence-modules/java-jdbi - persistence-modules/java-jpa - persistence-modules/jnosql - persistence-modules/liquibase - persistence-modules/orientdb - persistence-modules/querydsl - persistence-modules/redis - persistence-modules/solr - persistence-modules/spring-boot-h2/spring-boot-h2-database - persistence-modules/spring-boot-persistence - persistence-modules/spring-boot-persistence-mongodb - persistence-modules/spring-data-cassandra - persistence-modules/spring-data-cassandra-reactive - persistence-modules/spring-data-couchbase-2 - persistence-modules/spring-data-dynamodb - persistence-modules/spring-data-eclipselink - persistence-modules/spring-data-elasticsearch - persistence-modules/spring-data-gemfire - persistence-modules/spring-data-jpa - persistence-modules/spring-data-keyvalue - persistence-modules/spring-data-mongodb - persistence-modules/spring-data-neo4j - persistence-modules/spring-data-redis - persistence-modules/spring-data-solr - persistence-modules/spring-hibernate-3 - persistence-modules/spring-hibernate-5 - persistence-modules/spring-hibernate4 - persistence-modules/spring-jpa - + persistence-modules + rabbitmq ratpack @@ -1281,9 +1154,7 @@ resteasy restx - rule-engines/easy-rules - rule-engines/openl-tablets - rule-engines/rulebook + rule-engines rsocket rxjava rxjava-2 @@ -1434,13 +1305,7 @@ spring-security-angular/server spring-security-cache-control - spring-security-client/spring-security-jsp-authentication - spring-security-client/spring-security-jsp-authorize - spring-security-client/spring-security-jsp-config - spring-security-client/spring-security-mvc - spring-security-client/spring-security-thymeleaf-authentication - spring-security-client/spring-security-thymeleaf-authorize - spring-security-client/spring-security-thymeleaf-config + spring-security-client spring-security-core spring-security-mvc-boot @@ -1485,24 +1350,7 @@ structurizr struts-2 - testing-modules/gatling - testing-modules/groovy-spock - testing-modules/junit-5 - testing-modules/junit5-migration - testing-modules/load-testing-comparison - testing-modules/mockito - testing-modules/mockito-2 - testing-modules/mocks - testing-modules/mockserver - testing-modules/parallel-tests-junit - testing-modules/rest-assured - testing-modules/rest-testing - - testing-modules/selenium-junit-testng - testing-modules/spring-testing - testing-modules/test-containers - testing-modules/testing - testing-modules/testng + testing-modules twilio Twitter4J diff --git a/rule-engines/pom.xml b/rule-engines/pom.xml new file mode 100644 index 0000000000..2b3f2f530b --- /dev/null +++ b/rule-engines/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + rule-engines + rule-engines + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + .. + + + + easy-rules + openl-tablets + rulebook + + + diff --git a/spring-security-client/pom.xml b/spring-security-client/pom.xml new file mode 100644 index 0000000000..aa424ca759 --- /dev/null +++ b/spring-security-client/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + spring-security-client + spring-security-client + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + .. + + + + spring-security-jsp-authentication + spring-security-jsp-authorize + spring-security-jsp-config + spring-security-mvc + spring-security-thymeleaf-authentication + spring-security-thymeleaf-authorize + spring-security-thymeleaf-config + + diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml new file mode 100644 index 0000000000..6a3c2399f8 --- /dev/null +++ b/testing-modules/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + testing-modules + testing-modules + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + .. + + + + gatling + groovy-spock + junit-5 + junit5-migration + load-testing-comparison + mockito + mockito-2 + mocks + mockserver + parallel-tests-junit + rest-assured + rest-testing + + selenium-junit-testng + spring-testing + test-containers + testing + testng + + From a2f1f59e1f3cae524892ed515dcfee58bc543bab Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Thu, 28 Feb 2019 22:21:29 +0530 Subject: [PATCH 067/134] BAEL-10890 Fixed minor formatting --- cas/pom.xml | 2 +- guava-modules/pom.xml | 4 ++-- logging-modules/pom.xml | 6 +++--- persistence-modules/pom.xml | 2 +- rule-engines/pom.xml | 4 ++-- spring-security-client/pom.xml | 2 +- testing-modules/pom.xml | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cas/pom.xml b/cas/pom.xml index ac766ae5bf..6d141277c5 100644 --- a/cas/pom.xml +++ b/cas/pom.xml @@ -15,7 +15,7 @@ cas-secured-app - cas-server + cas-server diff --git a/guava-modules/pom.xml b/guava-modules/pom.xml index 7a5f217c15..fed9e446f7 100644 --- a/guava-modules/pom.xml +++ b/guava-modules/pom.xml @@ -15,8 +15,8 @@ guava-18 - guava-19 - guava-21 + guava-19 + guava-21 diff --git a/logging-modules/pom.xml b/logging-modules/pom.xml index d48955b1b8..a303e50ff1 100644 --- a/logging-modules/pom.xml +++ b/logging-modules/pom.xml @@ -15,9 +15,9 @@ log4j - log4j2 - logback - log-mdc + log4j2 + logback + log-mdc diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index beba135d7f..47c733d8a7 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -54,5 +54,5 @@ spring-hibernate-5 spring-hibernate4 spring-jpa - + diff --git a/rule-engines/pom.xml b/rule-engines/pom.xml index 2b3f2f530b..2ce82ed22b 100644 --- a/rule-engines/pom.xml +++ b/rule-engines/pom.xml @@ -15,8 +15,8 @@ easy-rules - openl-tablets - rulebook + openl-tablets + rulebook diff --git a/spring-security-client/pom.xml b/spring-security-client/pom.xml index aa424ca759..96ac837a09 100644 --- a/spring-security-client/pom.xml +++ b/spring-security-client/pom.xml @@ -21,5 +21,5 @@ spring-security-thymeleaf-authentication spring-security-thymeleaf-authorize spring-security-thymeleaf-config - + diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml index 6a3c2399f8..39047fb756 100644 --- a/testing-modules/pom.xml +++ b/testing-modules/pom.xml @@ -32,5 +32,5 @@ test-containers testing testng - + From d753bd3bd39a4256362d8ce4fdca7fecb895fa19 Mon Sep 17 00:00:00 2001 From: Josephine Barboza Date: Thu, 28 Feb 2019 22:57:01 +0530 Subject: [PATCH 068/134] BAEL-2725 Lists in Groovy --- .../groovy/com/baeldung/lists/ListTest.groovy | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 core-groovy/src/test/groovy/com/baeldung/lists/ListTest.groovy diff --git a/core-groovy/src/test/groovy/com/baeldung/lists/ListTest.groovy b/core-groovy/src/test/groovy/com/baeldung/lists/ListTest.groovy new file mode 100644 index 0000000000..89a0194742 --- /dev/null +++ b/core-groovy/src/test/groovy/com/baeldung/lists/ListTest.groovy @@ -0,0 +1,170 @@ +package com.baeldung.groovy.lists + +import static groovy.test.GroovyAssert.* +import org.junit.Test + +class ListTest{ + + @Test + void testCreateList() { + + def list = [1, 2, 3] + assertNotNull(list) + + def listMix = ['A', "b", 1, true] + assertTrue(listMix == ['A', "b", 1, true]) + + def linkedList = [1, 2, 3] as LinkedList + assertTrue(linkedList instanceof LinkedList) + + ArrayList arrList = [1, 2, 3] + assertTrue(arrList.class == ArrayList) + + def list2 = new ArrayList(arrList) + assertTrue(list2 == arrList) + + def list3 = arrList.clone() + assertTrue(list3 == arrList) + } + + @Test + void testCreateEmptyList() { + + def emptyList = [] + assertTrue(emptyList.size() == 0) + } + + @Test + void testCompareTwoLists() { + + def list1 = [5, 6.0, 'p'] + def list2 = [5, 6.0, 'p'] + assertTrue(list1 == list2) + } + + @Test + void testGetItemsFromList(){ + + def list = ["Hello", "World"] + + assertTrue(list.get(1) == "World") + assertTrue(list[1] == "World") + assertTrue(list[-1] == "World") + assertTrue(list.getAt(1) == "World") + assertTrue(list.getAt(-2) == "Hello") + } + + @Test + void testAddItemsToList() { + + def list = [] + + list << 1 + list.add("Apple") + assertTrue(list == [1, "Apple"]) + + list[2] = "Box" + list[4] = true + assertTrue(list == [1, "Apple", "Box", null, true]) + + list.add(1, 6.0) + assertTrue(list == [1, 6.0, "Apple", "Box", null, true]) + + def list2 = [1, 2] + list += list2 + list += 12 + assertTrue(list == [1, 6.0, "Apple", "Box", null, true, 1, 2, 12]) + } + + @Test + void testUpdateItemsInList() { + + def list =[1, "Apple", 80, "App"] + list[1] = "Box" + list.set(2,90) + assertTrue(list == [1, "Box", 90, "App"]) + } + + @Test + void testRemoveItemsFromList(){ + + def list = [1, 2, 3, 4, 5, 5, 6, 6, 7] + + list.remove(3) + assertTrue(list == [1, 2, 3, 5, 5, 6, 6, 7]) + + list.removeElement(5) + assertTrue(list == [1, 2, 3, 5, 6, 6, 7]) + + assertTrue(list - 6 == [1, 2, 3, 5, 7]) + } + + @Test + void testIteratingOnAList(){ + + def list = [1, "App", 3, 4] + list.each{ println it * 2} + + list.eachWithIndex{ it, i -> println "$i : $it" } + } + + @Test + void testCollectingToAnotherList(){ + + def list = ["Kay", "Henry", "Justin", "Tom"] + assertTrue(list.collect{"Hi " + it} == ["Hi Kay", "Hi Henry", "Hi Justin", "Hi Tom"]) + } + + @Test + void testJoinItemsInAList(){ + assertTrue(["One", "Two", "Three"].join(",") == "One,Two,Three") + } + + @Test + void testFilteringOnLists(){ + def list = [2, 1, 3, 4, 5, 6, 76] + + assertTrue(list.find{it > 3} == 4) + + assertTrue(list.findAll{it > 3} == [4, 5, 6, 76]) + + assertTrue(list.findAll{ it instanceof Number} == [2, 1, 3, 4, 5, 6, 76]) + + assertFalse(list.every{ it < 6}) + + assertTrue(list.any{ it%2 == 0}) + + assertTrue(list.grep( Number )== [2, 1, 3, 4, 5, 6, 76]) + + assertTrue(list.grep{ it> 6 }== [76]) + } + + @Test + void testGetUniqueItemsInAList(){ + assertTrue([1, 3, 3, 4].toUnique() == [1, 3, 4]) + + def list = [1, 3, 3, 4] + list.unique() + assertTrue(list == [1, 3, 4]) + + assertTrue(["A", "B", "Ba", "Bat", "Cat"].toUnique{ it.size()} == ["A", "Ba", "Bat"]) + } + + @Test + void testSorting(){ + + assertTrue([1, 2, 1, 0].sort() == [0, 1, 1, 2]) + Comparator mc = {a,b -> a == b? 0: a < b? 1 : -1} + + def list = [1, 2, 1, 0] + list.sort(mc) + assertTrue(list == [2, 1, 1, 0]) + + def list1 = ["na", "ppp", "as"] + assertTrue(list1.max() == "ppp") + + Comparator minc = {a,b -> a == b? 0: a < b? -1 : 1} + def list2 = [3, 2, 0, 7] + assertTrue(list2.min(minc) == 0) + } +} \ No newline at end of file From 23010dd32a5e88c095bcb2048dd113b7aced7a42 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Fri, 1 Mar 2019 18:40:44 +0800 Subject: [PATCH 069/134] Update README.md --- core-java-networking/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-networking/README.md b/core-java-networking/README.md index f6ce44d72f..faeeadab24 100644 --- a/core-java-networking/README.md +++ b/core-java-networking/README.md @@ -9,7 +9,7 @@ - [A Guide To UDP In Java](http://www.baeldung.com/udp-in-java) - [Sending Emails with Java](http://www.baeldung.com/java-email) - [A Guide To HTTP Cookies In Java](http://www.baeldung.com/cookies-java) -- [A Guide to the Java URL](http://www.baeldung.com/java-url) +- [A Simple Guide to the Java URL](http://www.baeldung.com/java-url) - [Working with Network Interfaces in Java](http://www.baeldung.com/java-network-interfaces) - [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets) - [Guide to Java URL Encoding/Decoding](http://www.baeldung.com/java-url-encoding-decoding) From 6189d4645e8d0ee3799080c7d8e06c2c1a08b3f0 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Fri, 1 Mar 2019 18:43:45 +0800 Subject: [PATCH 070/134] Update README.md --- spring-remoting/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-remoting/README.md b/spring-remoting/README.md index 7d344a3f27..0898b9b002 100644 --- a/spring-remoting/README.md +++ b/spring-remoting/README.md @@ -4,7 +4,7 @@ - [Intro to Spring Remoting with HTTP Invokers](http://www.baeldung.com/spring-remoting-http-invoker) - [Spring Remoting with Hessian and Burlap](http://www.baeldung.com/spring-remoting-hessian-burlap) - [Spring Remoting with AMQP](http://www.baeldung.com/spring-remoting-amqp) -- [Spring Remoting with JMS](http://www.baeldung.com/spring-remoting-jms) +- [Spring Remoting with JMS and ActiveMQ](http://www.baeldung.com/spring-remoting-jms) - [Spring Remoting with RMI](http://www.baeldung.com/spring-remoting-rmi) ### Overview From bb4258a0daa94633795987d73d2cfac4c1135a44 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Fri, 1 Mar 2019 18:44:51 +0800 Subject: [PATCH 071/134] Update README.md --- jackson/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jackson/README.md b/jackson/README.md index 519673738f..25194c7255 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -25,7 +25,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [More Jackson Annotations](http://www.baeldung.com/jackson-advanced-annotations) - [Inheritance with Jackson](http://www.baeldung.com/jackson-inheritance) - [Guide to @JsonFormat in Jackson](http://www.baeldung.com/jackson-jsonformat) -- [A Guide to Optional with Jackson](http://www.baeldung.com/jackson-optional) +- [Using Optional with Jackson](http://www.baeldung.com/jackson-optional) - [Map Serialization and Deserialization with Jackson](http://www.baeldung.com/jackson-map) - [Jackson Streaming API](http://www.baeldung.com/jackson-streaming-api) - [Jackson – JsonMappingException (No serializer found for class)](http://www.baeldung.com/jackson-jsonmappingexception) From 7b3da0202ec8574f741cb12699f65b4c31bd46ce Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Sat, 2 Mar 2019 07:52:09 -0500 Subject: [PATCH 072/134] BAEL-2504 Combinations Initial Combinations code. --- algorithms-miscellaneous-1/pom.xml | 5 +++ .../ApacheCommonsCombinationGenerator.java | 17 +++++++ .../CombinatoricsLibCombinationGenerator.java | 13 ++++++ .../GuavaCombinationsGenerator.java | 17 +++++++ .../IterativeCombinationGenerator.java | 45 +++++++++++++++++++ ...electionRecursiveCombinationGenerator.java | 39 ++++++++++++++++ .../SetRecursiveCombinationGenerator.java | 38 ++++++++++++++++ .../combination/CombinationUnitTest.java | 35 +++++++++++++++ 8 files changed, 209 insertions(+) create mode 100644 algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java create mode 100644 algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java create mode 100644 algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java create mode 100644 algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java create mode 100644 algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java create mode 100644 algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java create mode 100644 algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java diff --git a/algorithms-miscellaneous-1/pom.xml b/algorithms-miscellaneous-1/pom.xml index fe670963c0..0d528023d6 100644 --- a/algorithms-miscellaneous-1/pom.xml +++ b/algorithms-miscellaneous-1/pom.xml @@ -39,6 +39,11 @@ ${org.assertj.core.version} test + + com.github.dpaukov + combinatoricslib3 + 3.3.0 + diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java new file mode 100644 index 0000000000..4ec36927fa --- /dev/null +++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java @@ -0,0 +1,17 @@ +package com.baeldung.algorithms.combination; + +import java.util.Arrays; +import java.util.Iterator; + +import org.apache.commons.math3.util.CombinatoricsUtils; + +public class ApacheCommonsCombinationGenerator { + + public static void main(String[] args) { + Iterator iterator = CombinatoricsUtils.combinationsIterator(5, 3); + while (iterator.hasNext()) { + final int[] combination = iterator.next(); + System.out.println(Arrays.toString(combination)); + } + } +} \ No newline at end of file diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java new file mode 100644 index 0000000000..0afdeefb8b --- /dev/null +++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java @@ -0,0 +1,13 @@ +package com.baeldung.algorithms.combination; + +import org.paukov.combinatorics3.Generator; + +public class CombinatoricsLibCombinationGenerator { + + public static void main(String[] args) { + Generator.combination(0, 1, 2, 3, 4, 5) + .simple(3) + .stream() + .forEach(System.out::println); + } +} diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java new file mode 100644 index 0000000000..d2783881ba --- /dev/null +++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java @@ -0,0 +1,17 @@ +package com.baeldung.algorithms.combination; + +import java.util.Arrays; +import java.util.Set; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + +public class GuavaCombinationsGenerator { + + public static void main(String[] args) { + + Set> combinations = Sets.combinations(ImmutableSet.of(0, 1, 2, 3, 4, 5), 3); + System.out.println(combinations.size()); + System.out.println(Arrays.toString(combinations.toArray())); + } +} diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java new file mode 100644 index 0000000000..a0c7222717 --- /dev/null +++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java @@ -0,0 +1,45 @@ +package com.baeldung.algorithms.combination; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class IterativeCombinationGenerator { + + private static final int N = 5; + private static final int R = 2; + + public List generate(int n, int r) { + List combinations = new ArrayList<>(); + int[] combination = new int[r]; + + for (int i = 0; i < r; i++) { + combination[i] = i; + } + + while (combination[r - 1] < n) { + combinations.add(combination.clone()); + + int t = r - 1; + while (t != 0 && combination[t] == n - r + t) { + t--; + } + combination[t]++; + for (int i = t + 1; i < r; i++) { + combination[i] = combination[i - 1] + 1; + } + } + + return combinations; + } + + public static void main(String[] args) { + IterativeCombinationGenerator generator = new IterativeCombinationGenerator(); + List combinations = generator.generate(N, R); + System.out.println(combinations.size()); + for (int[] combination : combinations) { + System.out.println(Arrays.toString(combination)); + } + } + +} diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java new file mode 100644 index 0000000000..400042b137 --- /dev/null +++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java @@ -0,0 +1,39 @@ +package com.baeldung.algorithms.combination; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SelectionRecursiveCombinationGenerator { + + private static final int N = 6; + private static final int R = 3; + + public List generate(int n, int r) { + List combinations = new ArrayList<>(); + helper(combinations, new int[r], 0, n - 1, 0); + return combinations; + } + + private void helper(List combinations, int data[], int start, int end, int index) { + if (index == data.length) { + int[] combination = data.clone(); + combinations.add(combination); + } else { + int max = Math.min(end, end + 1 - data.length + index); + for (int i = start; i <= max; i++) { + data[index] = i; + helper(combinations, data, i + 1, end, index + 1); + } + } + } + + public static void main(String[] args) { + SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator(); + List combinations = generator.generate(N, R); + System.out.println(combinations.size()); + for (int[] combination : combinations) { + System.out.println(Arrays.toString(combination)); + } + } +} diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java new file mode 100644 index 0000000000..60c1c229b9 --- /dev/null +++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java @@ -0,0 +1,38 @@ +package com.baeldung.algorithms.combination; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SetRecursiveCombinationGenerator { + + private static final int N = 6; + private static final int R = 3; + + public List generate(int n, int r) { + List combinations = new ArrayList<>(); + helper(combinations, new int[r], 0, n - 1, 0, r); + return combinations; + } + + private void helper(List combinations, int data[], int start, int end, int index, int r) { + if (index == data.length) { + int[] combination = data.clone(); + combinations.add(combination); + + } else if (start <= end) { + data[index] = start; + helper(combinations, data, start + 1, end, index + 1, r); + helper(combinations, data, start + 1, end, index, r); + } + } + + public static void main(String[] args) { + SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator(); + List combinations = generator.generate(N, R); + System.out.println(combinations.size()); + for (int[] combination : combinations) { + System.out.println(Arrays.toString(combination)); + } + } +} diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java new file mode 100644 index 0000000000..987b6ddae6 --- /dev/null +++ b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java @@ -0,0 +1,35 @@ +package com.baeldung.algorithms.combination; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; + +import org.junit.Test; + +public class CombinationUnitTest { + + private static final int N = 5; + private static final int R = 3; + private static final int nCr = 10; + + @Test + public void givenSetAndSelectionSize_whenCalculatedUsingSetRecursiveAlgorithm_thenExpectedCount() { + SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator(); + List selection = generator.generate(N, R); + assertEquals(nCr, selection.size()); + } + + @Test + public void givenSetAndSelectionSize_whenCalculatedUsingSelectionRecursiveAlgorithm_thenExpectedCount() { + SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator(); + List selection = generator.generate(N, R); + assertEquals(nCr, selection.size()); + } + + @Test + public void givenSetAndSelectionSize_whenCalculatedUsingIterativeAlgorithm_thenExpectedCount() { + IterativeCombinationGenerator generator = new IterativeCombinationGenerator(); + List selection = generator.generate(N, R); + assertEquals(nCr, selection.size()); + } +} From 3deeefe9107d1ff8936057b3dd35dc3a1a7d966b Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sat, 2 Mar 2019 19:58:07 +0100 Subject: [PATCH 073/134] BAEL-2755 - Introduction to the Null Object Pattern --- .../com/baeldung/nullobject/JmsRouter.java | 10 +++++++ .../java/com/baeldung/nullobject/Message.java | 24 +++++++++++++++ .../com/baeldung/nullobject/NullRouter.java | 10 +++++++ .../java/com/baeldung/nullobject/Router.java | 7 +++++ .../baeldung/nullobject/RouterFactory.java | 23 ++++++++++++++ .../baeldung/nullobject/RoutingHandler.java | 30 +++++++++++++++++++ .../com/baeldung/nullobject/SmsRouter.java | 10 +++++++ 7 files changed, 114 insertions(+) create mode 100644 patterns/design-patterns/src/main/java/com/baeldung/nullobject/JmsRouter.java create mode 100644 patterns/design-patterns/src/main/java/com/baeldung/nullobject/Message.java create mode 100644 patterns/design-patterns/src/main/java/com/baeldung/nullobject/NullRouter.java create mode 100644 patterns/design-patterns/src/main/java/com/baeldung/nullobject/Router.java create mode 100644 patterns/design-patterns/src/main/java/com/baeldung/nullobject/RouterFactory.java create mode 100644 patterns/design-patterns/src/main/java/com/baeldung/nullobject/RoutingHandler.java create mode 100644 patterns/design-patterns/src/main/java/com/baeldung/nullobject/SmsRouter.java diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/JmsRouter.java b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/JmsRouter.java new file mode 100644 index 0000000000..7d8215fead --- /dev/null +++ b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/JmsRouter.java @@ -0,0 +1,10 @@ +package com.baeldung.nullobject; + +public class JmsRouter implements Router { + + @Override + public void route(Message msg) { + System.out.println("Routing to a JMS queue. Msg: " + msg); + } + +} diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/Message.java b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/Message.java new file mode 100644 index 0000000000..9086b6d92d --- /dev/null +++ b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/Message.java @@ -0,0 +1,24 @@ +package com.baeldung.nullobject; + +public class Message { + + private String body; + + private String priority; + + public Message(String body, String priority) { + this.body = body; + this.priority = priority; + } + + public String getPriority() { + return priority; + } + + @Override + public String toString() { + return "{body='" + body + '\'' + + ", priority='" + priority + '\'' + + '}'; + } +} diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/NullRouter.java b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/NullRouter.java new file mode 100644 index 0000000000..7da3856c93 --- /dev/null +++ b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/NullRouter.java @@ -0,0 +1,10 @@ +package com.baeldung.nullobject; + +public class NullRouter implements Router { + + @Override + public void route(Message msg) { + // routing to /dev/null + } + +} diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/Router.java b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/Router.java new file mode 100644 index 0000000000..3e67de9558 --- /dev/null +++ b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/Router.java @@ -0,0 +1,7 @@ +package com.baeldung.nullobject; + +public interface Router { + + void route(Message msg); + +} diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/RouterFactory.java b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/RouterFactory.java new file mode 100644 index 0000000000..ba80834865 --- /dev/null +++ b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/RouterFactory.java @@ -0,0 +1,23 @@ +package com.baeldung.nullobject; + +public class RouterFactory { + + public static Router getRouterForMessage(Message msg) { + + if (msg.getPriority() == null) { + return new NullRouter(); + } + + switch (msg.getPriority()) { + case "high": + return new SmsRouter(); + + case "medium": + return new JmsRouter(); + + default: + return new NullRouter(); + } + + } +} diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/RoutingHandler.java b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/RoutingHandler.java new file mode 100644 index 0000000000..282b066085 --- /dev/null +++ b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/RoutingHandler.java @@ -0,0 +1,30 @@ +package com.baeldung.nullobject; + +import java.util.Arrays; +import java.util.List; + +public class RoutingHandler { + + public void handle(Iterable messages){ + for (Message msg : messages) { + Router router = RouterFactory.getRouterForMessage(msg); + router.route(msg); + } + } + + public static void main(String[] args) { + Message highPriorityMsg = new Message("Alert!", "high"); + Message mediumPriorityMsg = new Message("Warning!", "medium"); + Message lowPriorityMsg = new Message("Take a look!", "low"); + Message nullPriorityMsg = new Message("Take a look!", null); + + List messages = Arrays.asList(highPriorityMsg, + mediumPriorityMsg, + lowPriorityMsg, + nullPriorityMsg); + + RoutingHandler routingHandler = new RoutingHandler(); + routingHandler.handle(messages); + + } +} diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/SmsRouter.java b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/SmsRouter.java new file mode 100644 index 0000000000..3d4a684f94 --- /dev/null +++ b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/SmsRouter.java @@ -0,0 +1,10 @@ +package com.baeldung.nullobject; + +public class SmsRouter implements Router { + + @Override + public void route(Message msg) { + System.out.println("Routing to a SMS gate. Msg: " + msg); + } + +} From 4826f19d00ed78c7efcafae0f6bfea79a3b9679d Mon Sep 17 00:00:00 2001 From: Jon Cook Date: Sat, 2 Mar 2019 22:50:04 +0100 Subject: [PATCH 074/134] BAEL-2512 - Add a new section in Mockito Spy article --- .../org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java b/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java index e2de23aa14..e39b8c0023 100644 --- a/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java +++ b/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java @@ -17,6 +17,7 @@ public class MockitoMisusingUnitTest { public void givenNotASpy_whenDoReturn_thenThrowNotAMock() { try { List list = new ArrayList(); + Mockito.doReturn(100) .when(list) .size(); From 47eee45301d4bb7bfa4f8f5cb390a4ad7a3c1491 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Sun, 3 Mar 2019 07:24:02 +0800 Subject: [PATCH 075/134] BAEL-2581 Delegation Pattern in Kotlin --- .../kotlin/delegates/InterfaceDelegation.kt | 64 +++++++++++++++++++ .../delegates/InterfaceDelegationTest.kt | 28 ++++++++ 2 files changed, 92 insertions(+) create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegation.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegationTest.kt diff --git a/core-kotlin/src/main/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegation.kt b/core-kotlin/src/main/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegation.kt new file mode 100644 index 0000000000..8e261aacf2 --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegation.kt @@ -0,0 +1,64 @@ +package com.baeldung.kotlin.delegates + +import java.util.concurrent.locks.ReentrantLock +import kotlin.concurrent.withLock + +interface Producer { + + fun produce(): String +} + +class ProducerImpl : Producer { + + override fun produce() = "ProducerImpl" +} + +class EnhancedProducer(private val delegate: Producer) : Producer by delegate { + + override fun produce() = "${delegate.produce()} and EnhancedProducer" +} + +interface MessageService { + + fun processMessage(message: String): String +} + +class MessageServiceImpl : MessageService { + override fun processMessage(message: String): String { + return "MessageServiceImpl: $message" + } +} + +interface UserService { + + fun processUser(userId: String): String +} + +class UserServiceImpl : UserService { + + override fun processUser(userId: String): String { + return "UserServiceImpl: $userId" + } +} + +class CompositeService : UserService by UserServiceImpl(), MessageService by MessageServiceImpl() + +interface Service { + + val seed: Int + + fun serve(action: (Int) -> Unit) +} + +class ServiceImpl : Service { + + override val seed = 1 + + override fun serve(action: (Int) -> Unit) { + action(seed) + } +} + +class ServiceDecorator : Service by ServiceImpl() { + override val seed = 2 +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegationTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegationTest.kt new file mode 100644 index 0000000000..e65032acd4 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegationTest.kt @@ -0,0 +1,28 @@ +package com.baeldung.kotlin.delegates + +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test + +class InterfaceDelegationTest { + + @Test + fun `when delegated implementation is used then it works as expected`() { + val producer = EnhancedProducer(ProducerImpl()) + assertThat(producer.produce()).isEqualTo("ProducerImpl and EnhancedProducer") + } + + @Test + fun `when composite delegation is used then it works as expected`() { + val service = CompositeService() + assertThat(service.processMessage("message")).isEqualTo("MessageServiceImpl: message") + assertThat(service.processUser("user")).isEqualTo("UserServiceImpl: user") + } + + @Test + fun `when decoration is used then delegate knows nothing about it`() { + val service = ServiceDecorator() + service.serve { + assertThat(it).isEqualTo(1) + } + } +} \ No newline at end of file From 6ecbe4b20adbe69bfb762b8a3bb4b0db280c8a10 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 3 Mar 2019 08:27:57 +0200 Subject: [PATCH 076/134] Update MockitoMisusingUnitTest.java --- .../org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java b/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java index e2de23aa14..2935f7ea8a 100644 --- a/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java +++ b/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java @@ -26,5 +26,4 @@ public class MockitoMisusingUnitTest { assertThat(e.getMessage(), containsString("Argument passed to when() is not a mock!")); } } - } From 86b51e41571082a4cbd732bb386aac9c4a5ed881 Mon Sep 17 00:00:00 2001 From: Jon Cook Date: Sun, 3 Mar 2019 08:45:45 +0100 Subject: [PATCH 077/134] BAEL-2512 - Add a new section in Mockito Spy article --- .../misusing/MockitoMisusingUnitTest.java | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java diff --git a/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java b/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java deleted file mode 100644 index e39b8c0023..0000000000 --- a/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.baeldung.mockito.misusing; - -import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; -import org.mockito.Mockito; -import org.mockito.exceptions.misusing.NotAMockException; - -public class MockitoMisusingUnitTest { - - @Test - public void givenNotASpy_whenDoReturn_thenThrowNotAMock() { - try { - List list = new ArrayList(); - - Mockito.doReturn(100) - .when(list) - .size(); - - fail("Should have thrown a NotAMockException because 'list' is not a mock!"); - } catch (NotAMockException e) { - assertThat(e.getMessage(), containsString("Argument passed to when() is not a mock!")); - } - } - -} From 23e3e6c7088077b030c6a6cdad40c9dc39699b31 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 3 Mar 2019 10:33:31 +0100 Subject: [PATCH 078/134] BAEL-2755 - minor improvements --- .../src/main/java/com/baeldung/nullobject/NullRouter.java | 2 +- .../src/main/java/com/baeldung/nullobject/SmsRouter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/NullRouter.java b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/NullRouter.java index 7da3856c93..a0065a321d 100644 --- a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/NullRouter.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/NullRouter.java @@ -4,7 +4,7 @@ public class NullRouter implements Router { @Override public void route(Message msg) { - // routing to /dev/null + // do nothing } } diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/SmsRouter.java b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/SmsRouter.java index 3d4a684f94..3e8e2f15f3 100644 --- a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/SmsRouter.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/nullobject/SmsRouter.java @@ -4,7 +4,7 @@ public class SmsRouter implements Router { @Override public void route(Message msg) { - System.out.println("Routing to a SMS gate. Msg: " + msg); + System.out.println("Routing to a SMS gateway. Msg: " + msg); } } From 9838dca33acaf295e5d5c4f511deb6f8d78bb5b6 Mon Sep 17 00:00:00 2001 From: Jon Cook Date: Sun, 3 Mar 2019 15:18:14 +0100 Subject: [PATCH 079/134] BAEL-2512 - Add a new section in Mockito Spy article --- .../misusing/MockitoMisusingUnitTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java diff --git a/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java b/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java new file mode 100644 index 0000000000..306f53297a --- /dev/null +++ b/testing-modules/mockito/src/test/java/org/baeldung/mockito/misusing/MockitoMisusingUnitTest.java @@ -0,0 +1,38 @@ +package org.baeldung.mockito.misusing; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.After; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.exceptions.misusing.NotAMockException; +import org.mockito.internal.progress.ThreadSafeMockingProgress; + +public class MockitoMisusingUnitTest { + + @After + public void tearDown() { + ThreadSafeMockingProgress.mockingProgress().reset(); + } + + @Test + public void givenNotASpy_whenDoReturn_thenThrowNotAMock() { + try { + List list = new ArrayList(); + + Mockito.doReturn(100, Mockito.withSettings().lenient()) + .when(list) + .size(); + + fail("Should have thrown a NotAMockException because 'list' is not a mock!"); + } catch (NotAMockException e) { + assertThat(e.getMessage(), containsString("Argument passed to when() is not a mock!")); + } + } + +} From 19cf211ddfa2a0cca1a0eaa3b7230ab9302f9e8e Mon Sep 17 00:00:00 2001 From: eric-martin Date: Sun, 3 Mar 2019 10:36:36 -0600 Subject: [PATCH 080/134] BAEL-2496: Updated ArraySortBenchmark --- .../performance/ArraySortBenchmark.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/core-java-collections/src/main/java/com/baeldung/performance/ArraySortBenchmark.java b/core-java-collections/src/main/java/com/baeldung/performance/ArraySortBenchmark.java index a1d40657d3..b93f8e9cc2 100644 --- a/core-java-collections/src/main/java/com/baeldung/performance/ArraySortBenchmark.java +++ b/core-java-collections/src/main/java/com/baeldung/performance/ArraySortBenchmark.java @@ -1,17 +1,21 @@ package com.baeldung.performance; -import org.openjdk.jmh.annotations.*; +import java.util.Arrays; +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeUnit; - -@BenchmarkMode(Mode.SingleShotTime) +@BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MILLISECONDS) @Measurement(batchSize = 100000, iterations = 10) @Warmup(batchSize = 100000, iterations = 10) @@ -19,8 +23,8 @@ public class ArraySortBenchmark { @State(Scope.Thread) public static class Initialize { - Integer[] numbers = {5, 22, 10, 0}; - int[] primitives = {5, 22, 10, 0}; + Integer[] numbers = { -769214442, -1283881723, 1504158300, -1260321086, -1800976432, 1278262737, 1863224321, 1895424914, 2062768552, -1051922993, 751605209, -1500919212, 2094856518, -1014488489, -931226326, -1677121986, -2080561705, 562424208, -1233745158, 41308167 }; + int[] primitives = { -769214442, -1283881723, 1504158300, -1260321086, -1800976432, 1278262737, 1863224321, 1895424914, 2062768552, -1051922993, 751605209, -1500919212, 2094856518, -1014488489, -931226326, -1677121986, -2080561705, 562424208, -1233745158, 41308167 }; } @Benchmark From b796bb014639a30245f336c1761d5e88438a5651 Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Sun, 3 Mar 2019 18:14:03 -0500 Subject: [PATCH 081/134] guava library updated to 27.0.1 upgraded guava library to 27.0.1 added javadoc --- algorithms-miscellaneous-1/pom.xml | 2 +- .../ApacheCommonsCombinationGenerator.java | 16 +++++++++-- .../IterativeCombinationGenerator.java | 11 ++++++-- ...electionRecursiveCombinationGenerator.java | 16 ++++++++++- .../SetRecursiveCombinationGenerator.java | 28 +++++++++++++------ 5 files changed, 59 insertions(+), 14 deletions(-) diff --git a/algorithms-miscellaneous-1/pom.xml b/algorithms-miscellaneous-1/pom.xml index 0d528023d6..30130208f8 100644 --- a/algorithms-miscellaneous-1/pom.xml +++ b/algorithms-miscellaneous-1/pom.xml @@ -82,7 +82,7 @@ 3.6.1 3.9.0 1.11 - 25.1-jre + 27.0.1-jre \ No newline at end of file diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java index 4ec36927fa..40142ce940 100644 --- a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java +++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java @@ -7,11 +7,23 @@ import org.apache.commons.math3.util.CombinatoricsUtils; public class ApacheCommonsCombinationGenerator { - public static void main(String[] args) { - Iterator iterator = CombinatoricsUtils.combinationsIterator(5, 3); + private static final int N = 6; + private static final int R = 3; + + /** + * Print all combinations of r elements from a set + * @param n - number of elements in set + * @param r - number of elements in selection + */ + public static void generate(int n, int r) { + Iterator iterator = CombinatoricsUtils.combinationsIterator(n, r); while (iterator.hasNext()) { final int[] combination = iterator.next(); System.out.println(Arrays.toString(combination)); } } + + public static void main(String[] args) { + generate(N, R); + } } \ No newline at end of file diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java index a0c7222717..676d2f41e3 100644 --- a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java +++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java @@ -5,14 +5,21 @@ import java.util.Arrays; import java.util.List; public class IterativeCombinationGenerator { - + private static final int N = 5; private static final int R = 2; + /** + * Generate all combinations of r elements from a set + * @param n the number of elements in input set + * @param r the number of elements in a combination + * @return the list containing all combinations + */ public List generate(int n, int r) { List combinations = new ArrayList<>(); int[] combination = new int[r]; + // initialize with lowest lexicographic combination for (int i = 0; i < r; i++) { combination[i] = i; } @@ -20,6 +27,7 @@ public class IterativeCombinationGenerator { while (combination[r - 1] < n) { combinations.add(combination.clone()); + // generate next combination in lexicographic order int t = r - 1; while (t != 0 && combination[t] == n - r + t) { t--; @@ -41,5 +49,4 @@ public class IterativeCombinationGenerator { System.out.println(Arrays.toString(combination)); } } - } diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java index 400042b137..52305b8c2f 100644 --- a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java +++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java @@ -9,12 +9,26 @@ public class SelectionRecursiveCombinationGenerator { private static final int N = 6; private static final int R = 3; + /** + * Generate all combinations of r elements from a set + * @param n - number of elements in input set + * @param r - number of elements to be chosen + * @return the list containing all combinations + */ public List generate(int n, int r) { List combinations = new ArrayList<>(); helper(combinations, new int[r], 0, n - 1, 0); return combinations; } + /** + * Choose elements from set by recursing over elements selected + * @param combinations - List to store generated combinations + * @param data - current combination + * @param start - starting element of remaining set + * @param end - last element of remaining set + * @param index - number of elements chosen so far. + */ private void helper(List combinations, int data[], int start, int end, int index) { if (index == data.length) { int[] combination = data.clone(); @@ -31,9 +45,9 @@ public class SelectionRecursiveCombinationGenerator { public static void main(String[] args) { SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator(); List combinations = generator.generate(N, R); - System.out.println(combinations.size()); for (int[] combination : combinations) { System.out.println(Arrays.toString(combination)); } + System.out.printf("generated %d combinations of %d items from %d ", combinations.size(), R, N); } } diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java index 60c1c229b9..a73447b31d 100644 --- a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java +++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java @@ -6,33 +6,45 @@ import java.util.List; public class SetRecursiveCombinationGenerator { - private static final int N = 6; - private static final int R = 3; + private static final int N = 5; + private static final int R = 2; + /** + * Generate all combinations of r elements from a set + * @param n - number of elements in set + * @param r - number of elements in selection + * @return the list containing all combinations + */ public List generate(int n, int r) { List combinations = new ArrayList<>(); - helper(combinations, new int[r], 0, n - 1, 0, r); + helper(combinations, new int[r], 0, n-1, 0); return combinations; } - private void helper(List combinations, int data[], int start, int end, int index, int r) { + /** + * @param combinations - List to contain the generated combinations + * @param data - List of elements in the selection + * @param start - index of the starting element in the remaining set + * @param end - index of the last element in the set + * @param index - number of elements selected so far + */ + private void helper(List combinations, int data[], int start, int end, int index) { if (index == data.length) { int[] combination = data.clone(); combinations.add(combination); - } else if (start <= end) { data[index] = start; - helper(combinations, data, start + 1, end, index + 1, r); - helper(combinations, data, start + 1, end, index, r); + helper(combinations, data, start + 1, end, index + 1); + helper(combinations, data, start + 1, end, index); } } public static void main(String[] args) { SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator(); List combinations = generator.generate(N, R); - System.out.println(combinations.size()); for (int[] combination : combinations) { System.out.println(Arrays.toString(combination)); } + System.out.printf("generated %d combinations of %d items from %d ", combinations.size(), R, N); } } From 00c115229bed0b072afd1e4170cb3c6bd4f7cda0 Mon Sep 17 00:00:00 2001 From: Shubhra Srivastava Date: Mon, 4 Mar 2019 08:06:11 +0530 Subject: [PATCH 082/134] Bael 2560 spring jms error handler (#6447) * Spring jms error handler * BAEL-2560 Reverting a change --- .../spring/jms/SampleJmsErrorHandler.java | 17 +++++ .../spring/jms/SampleJmsMessageSender.java | 4 + .../baeldung/spring/jms/SampleListener.java | 4 + .../src/main/resources/applicationContext.xml | 75 +++++++++---------- ...faultTextMessageSenderIntegrationTest.java | 7 ++ 5 files changed, 68 insertions(+), 39 deletions(-) create mode 100644 spring-jms/src/main/java/com/baeldung/spring/jms/SampleJmsErrorHandler.java diff --git a/spring-jms/src/main/java/com/baeldung/spring/jms/SampleJmsErrorHandler.java b/spring-jms/src/main/java/com/baeldung/spring/jms/SampleJmsErrorHandler.java new file mode 100644 index 0000000000..220b2744f3 --- /dev/null +++ b/spring-jms/src/main/java/com/baeldung/spring/jms/SampleJmsErrorHandler.java @@ -0,0 +1,17 @@ +package com.baeldung.spring.jms; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.ErrorHandler; + +public class SampleJmsErrorHandler implements ErrorHandler { + + private static final Logger LOG = LoggerFactory.getLogger(SampleJmsErrorHandler.class); + + @Override + public void handleError(Throwable t) { + LOG.warn("In default jms error handler..."); + LOG.error("Error Message : {}", t.getMessage()); + } + +} diff --git a/spring-jms/src/main/java/com/baeldung/spring/jms/SampleJmsMessageSender.java b/spring-jms/src/main/java/com/baeldung/spring/jms/SampleJmsMessageSender.java index 927762f05b..d3f09618fb 100644 --- a/spring-jms/src/main/java/com/baeldung/spring/jms/SampleJmsMessageSender.java +++ b/spring-jms/src/main/java/com/baeldung/spring/jms/SampleJmsMessageSender.java @@ -26,4 +26,8 @@ public class SampleJmsMessageSender { public void sendMessage(final Employee employee) { this.jmsTemplate.convertAndSend(employee); } + + public void sendTextMessage(String msg) { + this.jmsTemplate.send(queue, s -> s.createTextMessage(msg)); + } } diff --git a/spring-jms/src/main/java/com/baeldung/spring/jms/SampleListener.java b/spring-jms/src/main/java/com/baeldung/spring/jms/SampleListener.java index f35c22e144..87627c47e7 100644 --- a/spring-jms/src/main/java/com/baeldung/spring/jms/SampleListener.java +++ b/spring-jms/src/main/java/com/baeldung/spring/jms/SampleListener.java @@ -27,6 +27,9 @@ public class SampleListener implements MessageListener { try { String msg = ((TextMessage) message).getText(); System.out.println("Received message: " + msg); + if (msg == null) { + throw new IllegalArgumentException("Null value received..."); + } } catch (JMSException ex) { throw new RuntimeException(ex); } @@ -37,4 +40,5 @@ public class SampleListener implements MessageListener { Map map = (Map) this.jmsTemplate.receiveAndConvert(); return new Employee((String) map.get("name"), (Integer) map.get("age")); } + } diff --git a/spring-jms/src/main/resources/applicationContext.xml b/spring-jms/src/main/resources/applicationContext.xml index 28bf848e59..97a90e0bf2 100644 --- a/spring-jms/src/main/resources/applicationContext.xml +++ b/spring-jms/src/main/resources/applicationContext.xml @@ -1,51 +1,48 @@ - - - - - - - - - - + + + + + + - - - + + + - + + + + + + + - - - + + + + + - - - - + + + + + - + - - - - - - - - - - - - - + + + + + + + diff --git a/spring-jms/src/test/java/com/baeldung/spring/jms/DefaultTextMessageSenderIntegrationTest.java b/spring-jms/src/test/java/com/baeldung/spring/jms/DefaultTextMessageSenderIntegrationTest.java index f87d26b144..f23ead4d69 100644 --- a/spring-jms/src/test/java/com/baeldung/spring/jms/DefaultTextMessageSenderIntegrationTest.java +++ b/spring-jms/src/test/java/com/baeldung/spring/jms/DefaultTextMessageSenderIntegrationTest.java @@ -8,12 +8,14 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; public class DefaultTextMessageSenderIntegrationTest { private static SampleJmsMessageSender messageProducer; + private static SampleListener messageListener; @SuppressWarnings("resource") @BeforeClass public static void setUp() { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:EmbeddedActiveMQ.xml", "classpath:applicationContext.xml"); messageProducer = (SampleJmsMessageSender) applicationContext.getBean("SampleJmsMessageSender"); + messageListener = (SampleListener) applicationContext.getBean("messageListener"); } @Test @@ -21,4 +23,9 @@ public class DefaultTextMessageSenderIntegrationTest { messageProducer.simpleSend(); } + @Test + public void testSendTextMessage() { + messageProducer.sendTextMessage(null); + } + } From 7e2de11a5afaee971e4e54cf05540217263c1ff5 Mon Sep 17 00:00:00 2001 From: Rodolfo Felipe Date: Mon, 4 Mar 2019 00:36:23 -0400 Subject: [PATCH 083/134] BAEL-2448 Code examples for article. --- .../CollectionFilteringExamples.java | 51 +++++++++++++++++++ .../collection/filtering/Employee.java | 44 ++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 core-java-collections-list/src/main/java/com/baeldung/collection/filtering/CollectionFilteringExamples.java create mode 100644 core-java-collections-list/src/main/java/com/baeldung/collection/filtering/Employee.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/collection/filtering/CollectionFilteringExamples.java b/core-java-collections-list/src/main/java/com/baeldung/collection/filtering/CollectionFilteringExamples.java new file mode 100644 index 0000000000..a7ab5840f7 --- /dev/null +++ b/core-java-collections-list/src/main/java/com/baeldung/collection/filtering/CollectionFilteringExamples.java @@ -0,0 +1,51 @@ +package com.baeldung.collection.filtering; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Various filtering examples. + * + * @author Rodolfo Felipe + */ +public class CollectionFilteringExamples { + + private List buildEmployeeList() { + return Arrays.asList(new Employee(1, "Mike", 1), new Employee(2, "John", 1), new Employee(3, "Mary", 1), new Employee(4, "Joe", 2), new Employee(5, "Nicole", 2), new Employee(6, "Alice", 2), new Employee(7, "Bob", 3), new Employee(8, "Scarlett", 3)); + } + + private List employeeNameFilter() { + return Arrays.asList("Alice", "Mike", "Bob"); + } + + private List getFilteredEmployeeList() { + List filteredList = new ArrayList<>(); + for (Employee employee : buildEmployeeList()) { + for (String name : employeeNameFilter()) { + if (employee.getName() + .equalsIgnoreCase(name)) { + filteredList.add(employee); + } + } + } + return filteredList; + } + + private List getFilteredEmployeeListLambdaExample() { + return buildEmployeeList().stream() + .filter(employee -> employeeNameFilter().contains(employee.getName())) + .collect(Collectors.toList()); + } + + private List getFilteredEmployeeListLambdaExampleWithHashSetContains() { + Set nameFilterSet = employeeNameFilter().stream() + .collect(Collectors.toSet()); + return buildEmployeeList().stream() + .filter(employee -> nameFilterSet.contains(employee.getName())) + .collect(Collectors.toList()); + } + +} diff --git a/core-java-collections-list/src/main/java/com/baeldung/collection/filtering/Employee.java b/core-java-collections-list/src/main/java/com/baeldung/collection/filtering/Employee.java new file mode 100644 index 0000000000..2aa267b4dc --- /dev/null +++ b/core-java-collections-list/src/main/java/com/baeldung/collection/filtering/Employee.java @@ -0,0 +1,44 @@ +package com.baeldung.collection.filtering; + +/** + * Java 8 Collection Filtering by List of Values base class. + * + * @author Rodolfo Felipe + */ +public class Employee { + + private Integer employeeNumber; + private String name; + private Integer departmentId; + + public Employee(Integer employeeNumber, String name, Integer departmentId) { + this.employeeNumber = employeeNumber; + this.name = name; + this.departmentId = departmentId; + } + + public Integer getEmployeeNumber() { + return employeeNumber; + } + + public void setEmployeeNumber(Integer employeeNumber) { + this.employeeNumber = employeeNumber; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getDepartmentId() { + return departmentId; + } + + public void setDepartmentId(Integer departmentId) { + this.departmentId = departmentId; + } + +} From 834df022ec8b70993653978e9c7a17124e9e82c7 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Mon, 4 Mar 2019 18:16:42 +0800 Subject: [PATCH 084/134] Update README.md --- spring-5-reactive/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-reactive/README.md b/spring-5-reactive/README.md index 119e57f256..ef2f7d07eb 100644 --- a/spring-5-reactive/README.md +++ b/spring-5-reactive/README.md @@ -7,7 +7,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Introduction to the Functional Web Framework in Spring 5](http://www.baeldung.com/spring-5-functional-web) - [Spring 5 WebClient](http://www.baeldung.com/spring-5-webclient) -- [Exploring the Spring 5 MVC URL Matching](http://www.baeldung.com/spring-5-mvc-url-matching) +- [Exploring the Spring 5 WebFlux URL Matching](http://www.baeldung.com/spring-5-mvc-url-matching) - [Reactive WebSockets with Spring 5](http://www.baeldung.com/spring-5-reactive-websockets) - [Spring Webflux Filters](http://www.baeldung.com/spring-webflux-filters) - [How to Set a Header on a Response with Spring 5](http://www.baeldung.com/spring-response-header) From 8cb3b8d8dcc9ee2f09152cc836af78212f25e388 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:28:17 +0530 Subject: [PATCH 085/134] Back-link added --- core-java-collections-list/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-collections-list/README.md b/core-java-collections-list/README.md index 3a4a7c69e8..b4e5a31f20 100644 --- a/core-java-collections-list/README.md +++ b/core-java-collections-list/README.md @@ -28,3 +28,4 @@ - [Intersection of Two Lists in Java](https://www.baeldung.com/java-lists-intersection) - [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist) - [Determine If All Elements Are the Same in a Java List](https://www.baeldung.com/java-list-all-equal) +- [List of Primitive Integer Values in Java](https://www.baeldung.com/java-list-primitive-int) From e7503db1e798cc876d0eb09263dcf0b61c1fcc51 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:31:22 +0530 Subject: [PATCH 086/134] Back-link added --- java-strings/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-strings/README.md b/java-strings/README.md index 1ab5e098f6..3c401b4102 100644 --- a/java-strings/README.md +++ b/java-strings/README.md @@ -53,3 +53,4 @@ - [Java String Interview Questions and Answers](https://www.baeldung.com/java-string-interview-questions) - [Check if a String is a Pangram in Java](https://www.baeldung.com/java-string-pangram) - [Check If a String Contains Multiple Keywords](https://www.baeldung.com/string-contains-multiple-words) +- [Common String Operations in Java](https://www.baeldung.com/java-string-operations) From d3090e250855681cf68aa2a639137203a918b9d1 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:35:03 +0530 Subject: [PATCH 087/134] Back-link added --- core-java-lang/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-lang/README.md b/core-java-lang/README.md index c1c22caf6c..eaedc93eed 100644 --- a/core-java-lang/README.md +++ b/core-java-lang/README.md @@ -41,3 +41,4 @@ - [Java Interfaces](https://www.baeldung.com/java-interfaces) - [Attaching Values to Java Enum](https://www.baeldung.com/java-enum-values) - [Variable Scope in Java](https://www.baeldung.com/java-variable-scope) +- [Java Classes and Objects](https://www.baeldung.com/java-classes-objects) From aa80b07e8071713d01eec0aa9cfd31d49e72bc9a Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:36:45 +0530 Subject: [PATCH 088/134] Back-link added --- core-java-8/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-8/README.md b/core-java-8/README.md index 892dc71f76..540a5f677f 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -38,3 +38,4 @@ - [Java @SafeVarargs Annotation](https://www.baeldung.com/java-safevarargs) - [Java @Deprecated Annotation](https://www.baeldung.com/java-deprecated) - [Java 8 Predicate Chain](https://www.baeldung.com/java-predicate-chain) +- [Method References in Java](https://www.baeldung.com/java-method-references) From a8fb9250bf2e7e06ef0e39fb0cdb862d46cd0b1f Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:38:13 +0530 Subject: [PATCH 089/134] Back-link added --- spring-boot-mvc/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-mvc/README.md b/spring-boot-mvc/README.md index 0e1ac5a8ce..d5a39cdc9f 100644 --- a/spring-boot-mvc/README.md +++ b/spring-boot-mvc/README.md @@ -11,3 +11,4 @@ - [Cache Eviction in Spring Boot](https://www.baeldung.com/spring-boot-evict-cache) - [Setting Up Swagger 2 with a Spring REST API](http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api) - [Conditionally Enable Scheduled Jobs in Spring](https://www.baeldung.com/spring-scheduled-enabled-conditionally) +- [Accessing Spring MVC Model Objects in JavaScript](https://www.baeldung.com/spring-mvc-model-objects-js) From ab33ec149ea2dc72c585be797291d5d47747cdc0 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:41:20 +0530 Subject: [PATCH 090/134] Back-link added --- guice/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guice/README.md b/guice/README.md index d1bd1ff883..77c788c363 100644 --- a/guice/README.md +++ b/guice/README.md @@ -2,3 +2,4 @@ ### Relevant Articles - [Guide to Google Guice](http://www.baeldung.com/guice) +- [Guice vs Spring – Dependency Injection](https://www.baeldung.com/guice-spring-dependency-injection) From 17fad4c738237d86092779dc7cc4674b3344e44e Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:44:10 +0530 Subject: [PATCH 091/134] Back-link added --- core-java-lang-oop/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-lang-oop/README.md b/core-java-lang-oop/README.md index bbc3d26c99..200415fe21 100644 --- a/core-java-lang-oop/README.md +++ b/core-java-lang-oop/README.md @@ -22,3 +22,4 @@ - [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition) - [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors) - [Java equals() and hashCode() Contracts](https://www.baeldung.com/java-equals-hashcode-contracts) +- [Marker Interfaces in Java](https://www.baeldung.com/java-marker-interfaces) From 1df138e5099eb80a14b217508b922c1d612ea7d8 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:47:01 +0530 Subject: [PATCH 092/134] Back-link added --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 1143604eac..67538a3895 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -50,3 +50,4 @@ - [Using Curl in Java](https://www.baeldung.com/java-curl) - [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year) - [Java Bitwise Operators](https://www.baeldung.com/java-bitwise-operators) +- [Guide to Creating and Running a Jar File in Java](https://www.baeldung.com/java-create-jar) From b5a73e7252845a3685986526feec8a4ab1f1b8a3 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:49:02 +0530 Subject: [PATCH 093/134] Back-link added --- core-groovy/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-groovy/README.md b/core-groovy/README.md index 71788acdb7..f1a1161875 100644 --- a/core-groovy/README.md +++ b/core-groovy/README.md @@ -4,3 +4,4 @@ - [JDBC with Groovy](http://www.baeldung.com/jdbc-groovy) - [Working with JSON in Groovy](http://www.baeldung.com/groovy-json) +- [Reading a File in Groovy](https://www.baeldung.com/groovy-file-read) From 5bc15c387d0989ddb9bb1adb8078faf86f511fc4 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:52:30 +0530 Subject: [PATCH 094/134] Back-link added --- spring-security-mvc-jsonview/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-security-mvc-jsonview/README.md diff --git a/spring-security-mvc-jsonview/README.md b/spring-security-mvc-jsonview/README.md new file mode 100644 index 0000000000..35c806e856 --- /dev/null +++ b/spring-security-mvc-jsonview/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Filtering Jackson JSON Output Based on Spring Security Role](https://www.baeldung.com/spring-security-role-filter-json) From 178e3aa0f26cee2c68e97cc63ec4ff6ec40cbd2d Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:54:04 +0530 Subject: [PATCH 095/134] Back-link added --- core-java-collections/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-collections/README.md b/core-java-collections/README.md index 710be31a08..80d4385c45 100644 --- a/core-java-collections/README.md +++ b/core-java-collections/README.md @@ -32,3 +32,4 @@ - [A Guide to Iterator in Java](http://www.baeldung.com/java-iterator) - [Differences Between HashMap and Hashtable](https://www.baeldung.com/hashmap-hashtable-differences) - [Java ArrayList vs Vector](https://www.baeldung.com/java-arraylist-vs-vector) +- [Defining a Char Stack in Java](https://www.baeldung.com/java-char-stack) From e299681c32a956ed5d4e4e67e9e788a3e78363e5 Mon Sep 17 00:00:00 2001 From: sheryllresulta <48046330+sheryllresulta@users.noreply.github.com> Date: Mon, 4 Mar 2019 19:24:11 +0800 Subject: [PATCH 096/134] Update README.md --- core-java-networking/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-networking/README.md b/core-java-networking/README.md index faeeadab24..f6ce44d72f 100644 --- a/core-java-networking/README.md +++ b/core-java-networking/README.md @@ -9,7 +9,7 @@ - [A Guide To UDP In Java](http://www.baeldung.com/udp-in-java) - [Sending Emails with Java](http://www.baeldung.com/java-email) - [A Guide To HTTP Cookies In Java](http://www.baeldung.com/cookies-java) -- [A Simple Guide to the Java URL](http://www.baeldung.com/java-url) +- [A Guide to the Java URL](http://www.baeldung.com/java-url) - [Working with Network Interfaces in Java](http://www.baeldung.com/java-network-interfaces) - [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets) - [Guide to Java URL Encoding/Decoding](http://www.baeldung.com/java-url-encoding-decoding) From 1e2032b96cbdee9fcecb4a1856c7b2fe7d983c3f Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 16:55:58 +0530 Subject: [PATCH 097/134] Back-link added --- core-kotlin/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-kotlin/README.md b/core-kotlin/README.md index 6ee79b2a2e..1a7ecd34e1 100644 --- a/core-kotlin/README.md +++ b/core-kotlin/README.md @@ -52,3 +52,4 @@ - [Inline Classes in Kotlin](https://www.baeldung.com/kotlin-inline-classes) - [Creating Java static final Equivalents in Kotlin](https://www.baeldung.com/kotlin-java-static-final) - [Nested forEach in Kotlin](https://www.baeldung.com/kotlin-nested-foreach) +- [Building DSLs in Kotlin](https://www.baeldung.com/kotlin-dsl) From b9914774480135413159479385af48611b9b194f Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:00:18 +0530 Subject: [PATCH 098/134] Back-Link added --- spring-boot-libraries/README.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-libraries/README.MD b/spring-boot-libraries/README.MD index cc32ce8355..f3706e0fa4 100644 --- a/spring-boot-libraries/README.MD +++ b/spring-boot-libraries/README.MD @@ -4,3 +4,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [Guide to ShedLock with Spring](https://www.baeldung.com/shedlock-spring) +- [A Guide to the Problem Spring Web Library](https://www.baeldung.com/problem-spring-web) From f8ca54321733bc26e76d3bc649e7835afa29fe53 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:04:53 +0530 Subject: [PATCH 099/134] Back-link added --- spring-soap/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-soap/README.md diff --git a/spring-soap/README.md b/spring-soap/README.md new file mode 100644 index 0000000000..8d96350e1e --- /dev/null +++ b/spring-soap/README.md @@ -0,0 +1,3 @@ +## Relevant articles: + +- [Creating a SOAP Web Service with Spring](https://www.baeldung.com/spring-boot-soap-web-service) From f956a00fdd5cb59fa7e126f031456a2e11b39fec Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:05:55 +0530 Subject: [PATCH 100/134] Back-link added --- persistence-modules/hibernate5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/hibernate5/README.md b/persistence-modules/hibernate5/README.md index a4e95a9062..8fc8a433e8 100644 --- a/persistence-modules/hibernate5/README.md +++ b/persistence-modules/hibernate5/README.md @@ -30,3 +30,4 @@ - [Using c3p0 with Hibernate](https://www.baeldung.com/hibernate-c3p0) - [Persist a JSON Object Using Hibernate](https://www.baeldung.com/hibernate-persist-json-object) - [Common Hibernate Exceptions](https://www.baeldung.com/hibernate-exceptions) +- [Hibernate Aggregate Functions](https://www.baeldung.com/hibernate-aggregate-functions) From aa4a20b4a899843055c1876964d2d2300257b315 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:07:30 +0530 Subject: [PATCH 101/134] Back-link added --- persistence-modules/hibernate5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/hibernate5/README.md b/persistence-modules/hibernate5/README.md index 8fc8a433e8..026a5feb86 100644 --- a/persistence-modules/hibernate5/README.md +++ b/persistence-modules/hibernate5/README.md @@ -31,3 +31,4 @@ - [Persist a JSON Object Using Hibernate](https://www.baeldung.com/hibernate-persist-json-object) - [Common Hibernate Exceptions](https://www.baeldung.com/hibernate-exceptions) - [Hibernate Aggregate Functions](https://www.baeldung.com/hibernate-aggregate-functions) +- [Hibernate Query Plan Cache](https://www.baeldung.com/hibernate-query-plan-cache) From 5e30bafb53e1ee1bf4318900ffe6ed1bbedc20f9 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:14:03 +0530 Subject: [PATCH 102/134] Back-link added --- core-java-9/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-9/README.md b/core-java-9/README.md index d9586ba684..d24106cc8f 100644 --- a/core-java-9/README.md +++ b/core-java-9/README.md @@ -27,3 +27,4 @@ - [Java 9 Platform Logging API](https://www.baeldung.com/java-9-logging-api) - [Guide to java.lang.Process API](https://www.baeldung.com/java-process-api) - [Immutable Set in Java](https://www.baeldung.com/java-immutable-set) +- [Multi-Release Jar Files](https://www.baeldung.com/java-multi-release-jar) From 70d2bb2c91c4168d0f6c91a6dc1f284cfc0b716e Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:15:06 +0530 Subject: [PATCH 103/134] Back-link added --- core-kotlin/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-kotlin/README.md b/core-kotlin/README.md index 1a7ecd34e1..64ecd73b1c 100644 --- a/core-kotlin/README.md +++ b/core-kotlin/README.md @@ -53,3 +53,4 @@ - [Creating Java static final Equivalents in Kotlin](https://www.baeldung.com/kotlin-java-static-final) - [Nested forEach in Kotlin](https://www.baeldung.com/kotlin-nested-foreach) - [Building DSLs in Kotlin](https://www.baeldung.com/kotlin-dsl) +- [Static Methods Behavior in Kotlin](https://www.baeldung.com/kotlin-static-methods) From 00b9b9e9b95adc11130c90f98f20f0b74b60b247 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:17:19 +0530 Subject: [PATCH 104/134] Back-link added --- persistence-modules/spring-data-jpa/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/spring-data-jpa/README.md b/persistence-modules/spring-data-jpa/README.md index 739031ff5e..e629a464df 100644 --- a/persistence-modules/spring-data-jpa/README.md +++ b/persistence-modules/spring-data-jpa/README.md @@ -20,6 +20,7 @@ - [INSERT Statement in JPA](https://www.baeldung.com/jpa-insert) - [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting) - [Spring Data JPA Query by Example](https://www.baeldung.com/spring-data-query-by-example) +- [DB Integration Tests with Spring Boot and Testcontainers](https://www.baeldung.com/spring-boot-testcontainers-integration-test) ### Eclipse Config After importing the project into Eclipse, you may see the following error: From 140850225e44001cb096ec6bbbe2e1f3b22d6661 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:18:18 +0530 Subject: [PATCH 105/134] Back-link added --- core-groovy/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-groovy/README.md b/core-groovy/README.md index f1a1161875..fde7f33f86 100644 --- a/core-groovy/README.md +++ b/core-groovy/README.md @@ -5,3 +5,4 @@ - [JDBC with Groovy](http://www.baeldung.com/jdbc-groovy) - [Working with JSON in Groovy](http://www.baeldung.com/groovy-json) - [Reading a File in Groovy](https://www.baeldung.com/groovy-file-read) +- [Types of Strings in Groovy](https://www.baeldung.com/groovy-strings) From 8fbe21c0eb1b37aed4aa33be90c8a30ef104b721 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:19:13 +0530 Subject: [PATCH 106/134] Back-link added --- core-java-9/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-9/README.md b/core-java-9/README.md index d24106cc8f..7e256d5c7e 100644 --- a/core-java-9/README.md +++ b/core-java-9/README.md @@ -28,3 +28,4 @@ - [Guide to java.lang.Process API](https://www.baeldung.com/java-process-api) - [Immutable Set in Java](https://www.baeldung.com/java-immutable-set) - [Multi-Release Jar Files](https://www.baeldung.com/java-multi-release-jar) +- [Ahead of Time Compilation (AoT)](https://www.baeldung.com/ahead-of-time-compilation) From 55b93c5c52587a53795b5568b76c02b5cf36230f Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:20:11 +0530 Subject: [PATCH 107/134] Back-link added --- core-groovy/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-groovy/README.md b/core-groovy/README.md index fde7f33f86..6e385d528f 100644 --- a/core-groovy/README.md +++ b/core-groovy/README.md @@ -6,3 +6,4 @@ - [Working with JSON in Groovy](http://www.baeldung.com/groovy-json) - [Reading a File in Groovy](https://www.baeldung.com/groovy-file-read) - [Types of Strings in Groovy](https://www.baeldung.com/groovy-strings) +- [A Quick Guide to Iterating a Map in Groovy](https://www.baeldung.com/groovy-map-iterating) From b4a1434ad6eaefcf04a8942d8df4e55b75823b4a Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:21:01 +0530 Subject: [PATCH 108/134] Back-link added --- core-java-collections-list/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-collections-list/README.md b/core-java-collections-list/README.md index b4e5a31f20..598d8331d0 100644 --- a/core-java-collections-list/README.md +++ b/core-java-collections-list/README.md @@ -29,3 +29,4 @@ - [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist) - [Determine If All Elements Are the Same in a Java List](https://www.baeldung.com/java-list-all-equal) - [List of Primitive Integer Values in Java](https://www.baeldung.com/java-list-primitive-int) +- [Performance Comparison of Primitive Lists in Java](https://www.baeldung.com/java-list-primitive-performance) From bb2003ca8ef2226e62d7bc3b8de0c30cc3278c4c Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:21:57 +0530 Subject: [PATCH 109/134] Back-link added --- core-groovy/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-groovy/README.md b/core-groovy/README.md index 6e385d528f..ec2fcfa574 100644 --- a/core-groovy/README.md +++ b/core-groovy/README.md @@ -7,3 +7,4 @@ - [Reading a File in Groovy](https://www.baeldung.com/groovy-file-read) - [Types of Strings in Groovy](https://www.baeldung.com/groovy-strings) - [A Quick Guide to Iterating a Map in Groovy](https://www.baeldung.com/groovy-map-iterating) +- [An Introduction to Traits in Groovy](https://www.baeldung.com/groovy-traits) From 5f9665ab6ecb43da5ef64b58348f6b5021a23ed1 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:22:50 +0530 Subject: [PATCH 110/134] Back-link added --- spring-mvc-simple/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-simple/README.md b/spring-mvc-simple/README.md index 755e0932fc..cd4ad5aba2 100644 --- a/spring-mvc-simple/README.md +++ b/spring-mvc-simple/README.md @@ -8,3 +8,4 @@ - [Guide to Spring Email](http://www.baeldung.com/spring-email) - [Request Method Not Supported (405) in Spring](https://www.baeldung.com/spring-request-method-not-supported-405) - [Spring @RequestParam Annotation](https://www.baeldung.com/spring-request-param) +- [Validating RequestParams and PathVariables in Spring](https://www.baeldung.com/spring-validate-requestparam-pathvariable) From f6d4d8c4602e0e84cc577f3ce750c256e4f49ad9 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:23:41 +0530 Subject: [PATCH 111/134] Back-link added --- json/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/json/README.md b/json/README.md index 2e253a4ae9..24b25a5b12 100644 --- a/json/README.md +++ b/json/README.md @@ -11,3 +11,4 @@ - [Overview of JSON Pointer](https://www.baeldung.com/json-pointer) - [Introduction to the JSON Binding API (JSR 367) in Java](http://www.baeldung.com/java-json-binding-api) - [Get a Value by Key in a JSONArray](https://www.baeldung.com/java-jsonarray-get-value-by-key) +- [Iterating Over an Instance of org.json.JSONObject](https://www.baeldung.com/jsonobject-iteration) From 58389b2a86b5c87abeaa540290aafa4303b21a11 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:24:40 +0530 Subject: [PATCH 112/134] Back-link added --- json/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/json/README.md b/json/README.md index 24b25a5b12..c0ca4b00ef 100644 --- a/json/README.md +++ b/json/README.md @@ -12,3 +12,4 @@ - [Introduction to the JSON Binding API (JSR 367) in Java](http://www.baeldung.com/java-json-binding-api) - [Get a Value by Key in a JSONArray](https://www.baeldung.com/java-jsonarray-get-value-by-key) - [Iterating Over an Instance of org.json.JSONObject](https://www.baeldung.com/jsonobject-iteration) +- [Testing Web APIs with Postman Collections](https://www.baeldung.com/postman-testing-collections) From 6afbc3086f2e7403e6a935842e2c3d52d01a134d Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:27:04 +0530 Subject: [PATCH 113/134] Back-link added --- software-security/sql-injection-samples/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 software-security/sql-injection-samples/README.md diff --git a/software-security/sql-injection-samples/README.md b/software-security/sql-injection-samples/README.md new file mode 100644 index 0000000000..7a077074ac --- /dev/null +++ b/software-security/sql-injection-samples/README.md @@ -0,0 +1,3 @@ +## Relevant articles: + +- [SQL Injection and How to Prevent It?](https://www.baeldung.com/sql-injection) From 0f2e3da7d465fd457c7f94c849644cc3a4ebe114 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:27:39 +0530 Subject: [PATCH 114/134] Back-link added --- core-kotlin-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-kotlin-2/README.md b/core-kotlin-2/README.md index 6aabd71a6c..8d22c4f1a8 100644 --- a/core-kotlin-2/README.md +++ b/core-kotlin-2/README.md @@ -1,3 +1,4 @@ ## Relevant articles: - [Void Type in Kotlin](https://www.baeldung.com/kotlin-void-type) +- [How to use Kotlin Range Expressions](https://www.baeldung.com/kotlin-ranges) From 3ede9262f6fa6e1a8f49e3e24c24f9d34cd9979e Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:28:52 +0530 Subject: [PATCH 115/134] Back-link added --- jhipster/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/jhipster/README.md b/jhipster/README.md index 91ba54bf60..289bfac754 100644 --- a/jhipster/README.md +++ b/jhipster/README.md @@ -3,3 +3,4 @@ - [JHipster with a Microservice Architecture](http://www.baeldung.com/jhipster-microservices) - [Intro to JHipster](http://www.baeldung.com/jhipster) - [Building a Basic UAA-Secured JHipster Microservice](https://www.baeldung.com/jhipster-uaa-secured-micro-service) +- [Creating New Roles and Authorities in JHipster](https://www.baeldung.com/jhipster-new-roles) From 04638627a7c15f23edfea156a531f751e6a6e8e1 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:29:42 +0530 Subject: [PATCH 116/134] Back-link added --- persistence-modules/spring-data-jpa/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/spring-data-jpa/README.md b/persistence-modules/spring-data-jpa/README.md index e629a464df..9512ad336d 100644 --- a/persistence-modules/spring-data-jpa/README.md +++ b/persistence-modules/spring-data-jpa/README.md @@ -21,6 +21,7 @@ - [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting) - [Spring Data JPA Query by Example](https://www.baeldung.com/spring-data-query-by-example) - [DB Integration Tests with Spring Boot and Testcontainers](https://www.baeldung.com/spring-boot-testcontainers-integration-test) +- [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation) ### Eclipse Config After importing the project into Eclipse, you may see the following error: From be2d3ce59a317cd4dfeeeed459c49383ba79357b Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:30:56 +0530 Subject: [PATCH 117/134] Back-link added --- ratpack/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ratpack/README.md b/ratpack/README.md index dded42fab6..14bc3f6c74 100644 --- a/ratpack/README.md +++ b/ratpack/README.md @@ -5,3 +5,4 @@ - [Ratpack Integration with Spring Boot](http://www.baeldung.com/ratpack-spring-boot) - [Ratpack with Hystrix](http://www.baeldung.com/ratpack-hystrix) - [Ratpack HTTP Client](https://www.baeldung.com/ratpack-http-client) +- [Ratpack with RxJava](https://www.baeldung.com/ratpack-rxjava) From 10a395f64e1cb6d9649fc17ae02d422ca374e89c Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:31:49 +0530 Subject: [PATCH 118/134] Back-link added --- maven/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/maven/README.md b/maven/README.md index 1c0e50f95a..1352a2a10f 100644 --- a/maven/README.md +++ b/maven/README.md @@ -14,3 +14,4 @@ - [Apache Maven Tutorial](https://www.baeldung.com/maven) - [Use the Latest Version of a Dependency in Maven](https://www.baeldung.com/maven-dependency-latest-version) - [Multi-Module Project with Maven](https://www.baeldung.com/maven-multi-module) +- [Maven Enforcer Plugin](https://www.baeldung.com/maven-enforcer-plugin) From 3f6b909ab8d6083fa1bdb35af05aa53505fa2c69 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Mon, 4 Mar 2019 17:33:17 +0530 Subject: [PATCH 119/134] Back-link added --- libraries/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/README.md b/libraries/README.md index 378317778e..57f22631f1 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -66,6 +66,7 @@ - [Implementing a FTP-Client in Java](http://www.baeldung.com/java-ftp-client) - [Introduction to Functional Java](https://www.baeldung.com/java-functional-library) - [Intro to Derive4J](https://www.baeldung.com/derive4j) +- [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library) The libraries module contains examples related to small libraries that are relatively easy to use and does not require any separate module of its own. From 904046b0671898beb5504b66b68dc18dad3d2083 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Mon, 4 Mar 2019 21:39:47 +0200 Subject: [PATCH 120/134] Update README.md --- core-java-8/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-8/README.md b/core-java-8/README.md index 540a5f677f..eca07883e0 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -39,3 +39,4 @@ - [Java @Deprecated Annotation](https://www.baeldung.com/java-deprecated) - [Java 8 Predicate Chain](https://www.baeldung.com/java-predicate-chain) - [Method References in Java](https://www.baeldung.com/java-method-references) +- [Creating a Custom Annotation in Java](https://www.baeldung.com/java-custom-annotation) From 3186e484037e39ce9fa61874ce911f8a9dd90156 Mon Sep 17 00:00:00 2001 From: Rodolfo Felipe Date: Mon, 4 Mar 2019 20:43:14 -0400 Subject: [PATCH 121/134] BAEL-2448-Rev1 Changing examples to unit tests instead of plain methods after advice from editor. --- .../CollectionFilteringExamples.java | 51 ------------- .../filtering/CollectionFilteringTest.java | 73 +++++++++++++++++++ 2 files changed, 73 insertions(+), 51 deletions(-) delete mode 100644 core-java-collections-list/src/main/java/com/baeldung/collection/filtering/CollectionFilteringExamples.java create mode 100644 core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringTest.java diff --git a/core-java-collections-list/src/main/java/com/baeldung/collection/filtering/CollectionFilteringExamples.java b/core-java-collections-list/src/main/java/com/baeldung/collection/filtering/CollectionFilteringExamples.java deleted file mode 100644 index a7ab5840f7..0000000000 --- a/core-java-collections-list/src/main/java/com/baeldung/collection/filtering/CollectionFilteringExamples.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.baeldung.collection.filtering; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * Various filtering examples. - * - * @author Rodolfo Felipe - */ -public class CollectionFilteringExamples { - - private List buildEmployeeList() { - return Arrays.asList(new Employee(1, "Mike", 1), new Employee(2, "John", 1), new Employee(3, "Mary", 1), new Employee(4, "Joe", 2), new Employee(5, "Nicole", 2), new Employee(6, "Alice", 2), new Employee(7, "Bob", 3), new Employee(8, "Scarlett", 3)); - } - - private List employeeNameFilter() { - return Arrays.asList("Alice", "Mike", "Bob"); - } - - private List getFilteredEmployeeList() { - List filteredList = new ArrayList<>(); - for (Employee employee : buildEmployeeList()) { - for (String name : employeeNameFilter()) { - if (employee.getName() - .equalsIgnoreCase(name)) { - filteredList.add(employee); - } - } - } - return filteredList; - } - - private List getFilteredEmployeeListLambdaExample() { - return buildEmployeeList().stream() - .filter(employee -> employeeNameFilter().contains(employee.getName())) - .collect(Collectors.toList()); - } - - private List getFilteredEmployeeListLambdaExampleWithHashSetContains() { - Set nameFilterSet = employeeNameFilter().stream() - .collect(Collectors.toSet()); - return buildEmployeeList().stream() - .filter(employee -> nameFilterSet.contains(employee.getName())) - .collect(Collectors.toList()); - } - -} diff --git a/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringTest.java b/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringTest.java new file mode 100644 index 0000000000..bf3ec53abb --- /dev/null +++ b/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringTest.java @@ -0,0 +1,73 @@ +package com.baeldung.collection.filtering; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.Test; + +/** + * Various filtering examples. + * + * @author Rodolfo Felipe + */ +public class CollectionFilteringTest { + + private List buildEmployeeList() { + return Arrays.asList(new Employee(1, "Mike", 1), new Employee(2, "John", 1), new Employee(3, "Mary", 1), new Employee(4, "Joe", 2), new Employee(5, "Nicole", 2), new Employee(6, "Alice", 2), new Employee(7, "Bob", 3), new Employee(8, "Scarlett", 3)); + } + + private List employeeNameFilter() { + return Arrays.asList("Alice", "Mike", "Bob"); + } + + @Test + public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingForEachLoop() { + List filteredList = new ArrayList<>(); + List originalList = buildEmployeeList(); + List nameFilter = employeeNameFilter(); + + for (Employee employee : originalList) { + for (String name : nameFilter) { + if (employee.getName() + .equalsIgnoreCase(name)) { + filteredList.add(employee); + } + } + } + + Assert.assertThat(filteredList.size(), Matchers.is(nameFilter.size())); + } + + @Test + public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingLambda() { + List filteredList; + List originalList = buildEmployeeList(); + List nameFilter = employeeNameFilter(); + + filteredList = originalList.stream() + .filter(employee -> nameFilter.contains(employee.getName())) + .collect(Collectors.toList()); + + Assert.assertThat(filteredList.size(), Matchers.is(nameFilter.size())); + } + + @Test + public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingLambdaAndHashSet() { + List filteredList; + List originalList = buildEmployeeList(); + Set nameFilterSet = employeeNameFilter().stream() + .collect(Collectors.toSet()); + + filteredList = originalList.stream() + .filter(employee -> nameFilterSet.contains(employee.getName())) + .collect(Collectors.toList()); + + Assert.assertThat(filteredList.size(), Matchers.is(nameFilterSet.size())); + } + +} From bf31484ee367db29fc23a190698da2207ce6d0de Mon Sep 17 00:00:00 2001 From: Rodolfo Felipe Date: Mon, 4 Mar 2019 20:49:30 -0400 Subject: [PATCH 122/134] BAEL-2448-Rev2 Changing method names to comply with Jenkins PMD method naming rules. --- .../collection/filtering/CollectionFilteringTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringTest.java b/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringTest.java index bf3ec53abb..3b4a087ecd 100644 --- a/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringTest.java +++ b/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringTest.java @@ -26,7 +26,7 @@ public class CollectionFilteringTest { } @Test - public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingForEachLoop() { + public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingForEachLoopUnitTest() { List filteredList = new ArrayList<>(); List originalList = buildEmployeeList(); List nameFilter = employeeNameFilter(); @@ -44,7 +44,7 @@ public class CollectionFilteringTest { } @Test - public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingLambda() { + public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingLambdaUnitTest() { List filteredList; List originalList = buildEmployeeList(); List nameFilter = employeeNameFilter(); @@ -57,7 +57,7 @@ public class CollectionFilteringTest { } @Test - public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingLambdaAndHashSet() { + public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingLambdaAndHashSetUnitTest() { List filteredList; List originalList = buildEmployeeList(); Set nameFilterSet = employeeNameFilter().stream() From 245e0f32b33ed5c3465bead17bbf87a8cb49d8a2 Mon Sep 17 00:00:00 2001 From: Rodolfo Felipe Date: Mon, 4 Mar 2019 20:54:50 -0400 Subject: [PATCH 123/134] BAEL-2448-Rev3 Renaming test class so it passes PMD checks. Reverting method names to previous commit. --- ...ilteringTest.java => CollectionFilteringUnitTest.java} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename core-java-collections-list/src/test/java/com/baeldung/collection/filtering/{CollectionFilteringTest.java => CollectionFilteringUnitTest.java} (92%) diff --git a/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringTest.java b/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringUnitTest.java similarity index 92% rename from core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringTest.java rename to core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringUnitTest.java index 3b4a087ecd..cbc7136192 100644 --- a/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringTest.java +++ b/core-java-collections-list/src/test/java/com/baeldung/collection/filtering/CollectionFilteringUnitTest.java @@ -15,7 +15,7 @@ import org.junit.Test; * * @author Rodolfo Felipe */ -public class CollectionFilteringTest { +public class CollectionFilteringUnitTest { private List buildEmployeeList() { return Arrays.asList(new Employee(1, "Mike", 1), new Employee(2, "John", 1), new Employee(3, "Mary", 1), new Employee(4, "Joe", 2), new Employee(5, "Nicole", 2), new Employee(6, "Alice", 2), new Employee(7, "Bob", 3), new Employee(8, "Scarlett", 3)); @@ -26,7 +26,7 @@ public class CollectionFilteringTest { } @Test - public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingForEachLoopUnitTest() { + public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingForEachLoop() { List filteredList = new ArrayList<>(); List originalList = buildEmployeeList(); List nameFilter = employeeNameFilter(); @@ -44,7 +44,7 @@ public class CollectionFilteringTest { } @Test - public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingLambdaUnitTest() { + public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingLambda() { List filteredList; List originalList = buildEmployeeList(); List nameFilter = employeeNameFilter(); @@ -57,7 +57,7 @@ public class CollectionFilteringTest { } @Test - public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingLambdaAndHashSetUnitTest() { + public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingLambdaAndHashSet() { List filteredList; List originalList = buildEmployeeList(); Set nameFilterSet = employeeNameFilter().stream() From b095add969b84a4f72d6b4864ec938407ac8f07f Mon Sep 17 00:00:00 2001 From: Josephine Barboza Date: Tue, 5 Mar 2019 22:00:33 +0530 Subject: [PATCH 124/134] BAEL-2725 --- .../groovy/com/baeldung/lists/ListTest.groovy | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/core-groovy/src/test/groovy/com/baeldung/lists/ListTest.groovy b/core-groovy/src/test/groovy/com/baeldung/lists/ListTest.groovy index 89a0194742..f682503ed4 100644 --- a/core-groovy/src/test/groovy/com/baeldung/lists/ListTest.groovy +++ b/core-groovy/src/test/groovy/com/baeldung/lists/ListTest.groovy @@ -20,11 +20,11 @@ class ListTest{ ArrayList arrList = [1, 2, 3] assertTrue(arrList.class == ArrayList) - def list2 = new ArrayList(arrList) - assertTrue(list2 == arrList) + def copyList = new ArrayList(arrList) + assertTrue(copyList == arrList) - def list3 = arrList.clone() - assertTrue(list3 == arrList) + def cloneList = arrList.clone() + assertTrue(cloneList == arrList) } @Test @@ -122,30 +122,33 @@ class ListTest{ @Test void testFilteringOnLists(){ - def list = [2, 1, 3, 4, 5, 6, 76] + def filterList = [2, 1, 3, 4, 5, 6, 76] - assertTrue(list.find{it > 3} == 4) + assertTrue(filterList.find{it > 3} == 4) - assertTrue(list.findAll{it > 3} == [4, 5, 6, 76]) + assertTrue(filterList.findAll{it > 3} == [4, 5, 6, 76]) - assertTrue(list.findAll{ it instanceof Number} == [2, 1, 3, 4, 5, 6, 76]) + assertTrue(filterList.findAll{ it instanceof Number} == [2, 1, 3, 4, 5, 6, 76]) + + assertTrue(filterList.grep( Number )== [2, 1, 3, 4, 5, 6, 76]) + + assertTrue(filterList.grep{ it> 6 }== [76]) - assertFalse(list.every{ it < 6}) + def conditionList = [2, 1, 3, 4, 5, 6, 76] + + assertFalse(conditionList.every{ it < 6}) - assertTrue(list.any{ it%2 == 0}) + assertTrue(conditionList.any{ it%2 == 0}) - assertTrue(list.grep( Number )== [2, 1, 3, 4, 5, 6, 76]) - - assertTrue(list.grep{ it> 6 }== [76]) } @Test void testGetUniqueItemsInAList(){ assertTrue([1, 3, 3, 4].toUnique() == [1, 3, 4]) - def list = [1, 3, 3, 4] - list.unique() - assertTrue(list == [1, 3, 4]) + def uniqueList = [1, 3, 3, 4] + uniqueList.unique() + assertTrue(uniqueList == [1, 3, 4]) assertTrue(["A", "B", "Ba", "Bat", "Cat"].toUnique{ it.size()} == ["A", "Ba", "Bat"]) } @@ -160,11 +163,11 @@ class ListTest{ list.sort(mc) assertTrue(list == [2, 1, 1, 0]) - def list1 = ["na", "ppp", "as"] - assertTrue(list1.max() == "ppp") + def strList = ["na", "ppp", "as"] + assertTrue(strList.max() == "ppp") Comparator minc = {a,b -> a == b? 0: a < b? -1 : 1} - def list2 = [3, 2, 0, 7] - assertTrue(list2.min(minc) == 0) + def numberList = [3, 2, 0, 7] + assertTrue(numberList.min(minc) == 0) } } \ No newline at end of file From 0983aa916328e8097908b0fc6eb2f462bbef7e85 Mon Sep 17 00:00:00 2001 From: eelhazati Date: Tue, 5 Mar 2019 21:14:51 +0100 Subject: [PATCH 125/134] CF UAA config && demo. --- cloud-foundry-uaa/cf-uaa-config/uaa.yml | 73 +++++++++++++++++ .../cf-uaa-oauth2-client/pom.xml | 43 ++++++++++ .../client/CFUAAOAuth2ClientApplication.java | 13 +++ .../client/CFUAAOAuth2ClientController.java | 80 +++++++++++++++++++ .../src/main/resources/application.properties | 23 ++++++ .../src/main/resources/templates/index.html | 1 + .../cf-uaa-oauth2-resource-server/pom.xml | 43 ++++++++++ .../CFUAAOAuth2ResourceServerApplication.java | 13 +++ ...UAAOAuth2ResourceServerRestController.java | 28 +++++++ ...h2ResourceServerSecurityConfiguration.java | 21 +++++ .../src/main/resources/application.properties | 16 ++++ 11 files changed, 354 insertions(+) create mode 100644 cloud-foundry-uaa/cf-uaa-config/uaa.yml create mode 100644 cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml create mode 100644 cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientApplication.java create mode 100644 cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientController.java create mode 100644 cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/application.properties create mode 100644 cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/templates/index.html create mode 100644 cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml create mode 100644 cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerApplication.java create mode 100644 cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerRestController.java create mode 100644 cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerSecurityConfiguration.java create mode 100644 cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/resources/application.properties diff --git a/cloud-foundry-uaa/cf-uaa-config/uaa.yml b/cloud-foundry-uaa/cf-uaa-config/uaa.yml new file mode 100644 index 0000000000..b782c2b681 --- /dev/null +++ b/cloud-foundry-uaa/cf-uaa-config/uaa.yml @@ -0,0 +1,73 @@ +issuer: + uri: http://localhost:8080/uaa + +spring_profiles: postgresql,default + +database.driverClassName: org.postgresql.Driver +database.url: jdbc:postgresql:uaadb2 +database.username: postgres +database.password: postgres + +encryption: + active_key_label: CHANGE-THIS-KEY + encryption_keys: + - label: CHANGE-THIS-KEY + passphrase: CHANGEME + +login: + serviceProviderKey: | + -----BEGIN RSA PRIVATE KEY----- + MIICXQIBAAKBgQDHtC5gUXxBKpEqZTLkNvFwNGnNIkggNOwOQVNbpO0WVHIivig5 + L39WqS9u0hnA+O7MCA/KlrAR4bXaeVVhwfUPYBKIpaaTWFQR5cTR1UFZJL/OF9vA + fpOwznoD66DDCnQVpbCjtDYWX+x6imxn8HCYxhMol6ZnTbSsFW6VZjFMjQIDAQAB + AoGAVOj2Yvuigi6wJD99AO2fgF64sYCm/BKkX3dFEw0vxTPIh58kiRP554Xt5ges + 7ZCqL9QpqrChUikO4kJ+nB8Uq2AvaZHbpCEUmbip06IlgdA440o0r0CPo1mgNxGu + lhiWRN43Lruzfh9qKPhleg2dvyFGQxy5Gk6KW/t8IS4x4r0CQQD/dceBA+Ndj3Xp + ubHfxqNz4GTOxndc/AXAowPGpge2zpgIc7f50t8OHhG6XhsfJ0wyQEEvodDhZPYX + kKBnXNHzAkEAyCA76vAwuxqAd3MObhiebniAU3SnPf2u4fdL1EOm92dyFs1JxyyL + gu/DsjPjx6tRtn4YAalxCzmAMXFSb1qHfwJBAM3qx3z0gGKbUEWtPHcP7BNsrnWK + vw6By7VC8bk/ffpaP2yYspS66Le9fzbFwoDzMVVUO/dELVZyBnhqSRHoXQcCQQCe + A2WL8S5o7Vn19rC0GVgu3ZJlUrwiZEVLQdlrticFPXaFrn3Md82ICww3jmURaKHS + N+l4lnMda79eSp3OMmq9AkA0p79BvYsLshUJJnvbk76pCjR28PK4dV1gSDUEqQMB + qy45ptdwJLqLJCeNoR0JUcDNIRhOCuOPND7pcMtX6hI/ + -----END RSA PRIVATE KEY----- + serviceProviderKeyPassword: password + serviceProviderCertificate: | + -----BEGIN CERTIFICATE----- + MIIDSTCCArKgAwIBAgIBADANBgkqhkiG9w0BAQQFADB8MQswCQYDVQQGEwJhdzEO + MAwGA1UECBMFYXJ1YmExDjAMBgNVBAoTBWFydWJhMQ4wDAYDVQQHEwVhcnViYTEO + MAwGA1UECxMFYXJ1YmExDjAMBgNVBAMTBWFydWJhMR0wGwYJKoZIhvcNAQkBFg5h + cnViYUBhcnViYS5hcjAeFw0xNTExMjAyMjI2MjdaFw0xNjExMTkyMjI2MjdaMHwx + CzAJBgNVBAYTAmF3MQ4wDAYDVQQIEwVhcnViYTEOMAwGA1UEChMFYXJ1YmExDjAM + BgNVBAcTBWFydWJhMQ4wDAYDVQQLEwVhcnViYTEOMAwGA1UEAxMFYXJ1YmExHTAb + BgkqhkiG9w0BCQEWDmFydWJhQGFydWJhLmFyMIGfMA0GCSqGSIb3DQEBAQUAA4GN + ADCBiQKBgQDHtC5gUXxBKpEqZTLkNvFwNGnNIkggNOwOQVNbpO0WVHIivig5L39W + qS9u0hnA+O7MCA/KlrAR4bXaeVVhwfUPYBKIpaaTWFQR5cTR1UFZJL/OF9vAfpOw + znoD66DDCnQVpbCjtDYWX+x6imxn8HCYxhMol6ZnTbSsFW6VZjFMjQIDAQABo4Ha + MIHXMB0GA1UdDgQWBBTx0lDzjH/iOBnOSQaSEWQLx1syGDCBpwYDVR0jBIGfMIGc + gBTx0lDzjH/iOBnOSQaSEWQLx1syGKGBgKR+MHwxCzAJBgNVBAYTAmF3MQ4wDAYD + VQQIEwVhcnViYTEOMAwGA1UEChMFYXJ1YmExDjAMBgNVBAcTBWFydWJhMQ4wDAYD + VQQLEwVhcnViYTEOMAwGA1UEAxMFYXJ1YmExHTAbBgkqhkiG9w0BCQEWDmFydWJh + QGFydWJhLmFyggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAYvBJ + 0HOZbbHClXmGUjGs+GS+xC1FO/am2suCSYqNB9dyMXfOWiJ1+TLJk+o/YZt8vuxC + KdcZYgl4l/L6PxJ982SRhc83ZW2dkAZI4M0/Ud3oePe84k8jm3A7EvH5wi5hvCkK + RpuRBwn3Ei+jCRouxTbzKPsuCVB+1sNyxMTXzf0= + -----END CERTIFICATE----- + +#The secret that an external login server will use to authenticate to the uaa using the id `login` +LOGIN_SECRET: loginsecret + +jwt: + token: + signing-key: | + -----BEGIN RSA PRIVATE KEY----- + MIIEpAIBAAKCAQEAqUeygEfDGxI6c1VDQ6xIyUSLrP6iz1y97iHFbtXSxXaArL4a + ... + v6Mtt5LcRAAVP7pemunTdju4h8Q/noKYlVDVL30uLYUfKBL4UKfOBw== + -----END RSA PRIVATE KEY----- + verification-key: | + -----BEGIN PUBLIC KEY----- + MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqUeygEfDGxI6c1VDQ6xI + ... + AwIDAQAB + -----END PUBLIC KEY----- diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml b/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml new file mode 100644 index 0000000000..8e31cc41fb --- /dev/null +++ b/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.3.RELEASE + + + com.example + cf-uaa-oauth2-client + 0.0.1-SNAPSHOT + uaa-client-webapp + Demo project for Spring Boot + + + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-oauth2-client + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientApplication.java b/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientApplication.java new file mode 100644 index 0000000000..c9e81fcd5d --- /dev/null +++ b/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.cfuaa.oauth2.client; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class CFUAAOAuth2ClientApplication { + + public static void main(String[] args) { + SpringApplication.run(CFUAAOAuth2ClientApplication.class, args); + } + +} diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientController.java b/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientController.java new file mode 100644 index 0000000000..b1631ed327 --- /dev/null +++ b/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientController.java @@ -0,0 +1,80 @@ +package com.baeldung.cfuaa.oauth2.client; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; +import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService; +import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; +import org.springframework.security.oauth2.core.OAuth2AccessToken; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; + +@RestController +public class CFUAAOAuth2ClientController { + + @Value("${resource.server.url}") + private String remoteResourceServer; + + private RestTemplate restTemplate; + + private OAuth2AuthorizedClientService authorizedClientService; + + public CFUAAOAuth2ClientController(OAuth2AuthorizedClientService authorizedClientService) { + this.authorizedClientService = authorizedClientService; + this.restTemplate = new RestTemplate(); + } + + @RequestMapping("/") + public String index(OAuth2AuthenticationToken authenticationToken) { + OAuth2AuthorizedClient oAuth2AuthorizedClient = this.authorizedClientService.loadAuthorizedClient(authenticationToken.getAuthorizedClientRegistrationId(), authenticationToken.getName()); + OAuth2AccessToken oAuth2AccessToken = oAuth2AuthorizedClient.getAccessToken(); + + String response = "Hello, " + authenticationToken.getPrincipal().getName(); + response += "

"; + response += "Here is your accees token :
" + oAuth2AccessToken.getTokenValue(); + response += "
"; + response += "
You can use it to call these Resource Server APIs:"; + response += "

"; + response += "Call Resource Server Read API"; + response += "
"; + response += "Call Resource Server Write API"; + return response; + } + + @RequestMapping("/read") + public String read(OAuth2AuthenticationToken authenticationToken) { + String url = remoteResourceServer + "/read"; + return callResourceServer(authenticationToken, url); + } + + @RequestMapping("/write") + public String write(OAuth2AuthenticationToken authenticationToken) { + String url = remoteResourceServer + "/write"; + return callResourceServer(authenticationToken, url); + } + + private String callResourceServer(OAuth2AuthenticationToken authenticationToken, String url) { + OAuth2AuthorizedClient oAuth2AuthorizedClient = this.authorizedClientService.loadAuthorizedClient(authenticationToken.getAuthorizedClientRegistrationId(), authenticationToken.getName()); + OAuth2AccessToken oAuth2AccessToken = oAuth2AuthorizedClient.getAccessToken(); + + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + oAuth2AccessToken.getTokenValue()); + + HttpEntity entity = new HttpEntity<>("parameters", headers); + ResponseEntity responseEntity = null; + + String response = null; + try { + responseEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class); + response = responseEntity.getBody(); + } catch (HttpClientErrorException e) { + response = e.getMessage(); + } + return response; + } +} \ No newline at end of file diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/application.properties b/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/application.properties new file mode 100644 index 0000000000..de8e1a7b9f --- /dev/null +++ b/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/application.properties @@ -0,0 +1,23 @@ +# SECURITY OAUTH2 CLIENT (OAuth2ClientProperties) +#spring.security.oauth2.client.provider.*= # OAuth provider details. +#spring.security.oauth2.client.registration.*= # OAuth client registrations. + +server.port=8081 +#server.servlet.context-path=/uaa-client-webapp + +uaa.url=http://localhost:8080/uaa +resource.server.url=http://localhost:8082 + +spring.security.oauth2.client.registration.uaa.client-name=UAA OAuth2 Client +spring.security.oauth2.client.registration.uaa.client-id=client1 +spring.security.oauth2.client.registration.uaa.client-secret=client1 +spring.security.oauth2.client.registration.uaa.authorization-grant-type=authorization_code +spring.security.oauth2.client.registration.uaa.scope=resource.read,resource.write,openid,profile +spring.security.oauth2.client.registration.uaa.redirect-uri=http://localhost:8081/login/oauth2/code/uaa +#spring.security.oauth2.client.registration.uaa.redirect-uri=http://localhost:8081/** + +spring.security.oauth2.client.provider.uaa.token-uri=${uaa.url}/oauth/token +spring.security.oauth2.client.provider.uaa.authorization-uri=${uaa.url}/oauth/authorize +spring.security.oauth2.client.provider.uaa.jwk-set-uri=${uaa.url}/token_keys +spring.security.oauth2.client.provider.uaa.user-info-uri=${uaa.url}/userinfo +spring.security.oauth2.client.provider.uaa.user-name-attribute=user_name diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/templates/index.html b/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/templates/index.html new file mode 100644 index 0000000000..eb6e267b94 --- /dev/null +++ b/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/templates/index.html @@ -0,0 +1 @@ +tintin \ No newline at end of file diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml new file mode 100644 index 0000000000..9cf8993cd2 --- /dev/null +++ b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.3.RELEASE + + + com.baeldung.cfuaa + cf-uaa-oauth2-resource-server + 0.0.1-SNAPSHOT + cf-uaa-oauth2-resource-server + Demo project for Spring Boot + + + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-oauth2-resource-server + + + org.springframework.boot + spring-boot-starter-web + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerApplication.java b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerApplication.java new file mode 100644 index 0000000000..51ad6e938d --- /dev/null +++ b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.cfuaa.oauth2.resourceserver; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class CFUAAOAuth2ResourceServerApplication { + + public static void main(String[] args) { + SpringApplication.run(CFUAAOAuth2ResourceServerApplication.class, args); + } + +} diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerRestController.java b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerRestController.java new file mode 100644 index 0000000000..c08f17d8d8 --- /dev/null +++ b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerRestController.java @@ -0,0 +1,28 @@ +package com.baeldung.cfuaa.oauth2.resourceserver; + +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.oauth2.jwt.Jwt; +import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.security.Principal; + +@RestController +public class CFUAAOAuth2ResourceServerRestController { + + @GetMapping("/") + public String index(@AuthenticationPrincipal Jwt jwt) { + return String.format("Hello, %s!", jwt.getSubject()); + } + + @GetMapping("/read") + public String read(JwtAuthenticationToken jwtAuthenticationToken) { + return "Hello write: " + jwtAuthenticationToken.getTokenAttributes(); + } + + @GetMapping("/write") + public String write(Principal principal) { + return "Hello write: " + principal.getName(); + } +} diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerSecurityConfiguration.java b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerSecurityConfiguration.java new file mode 100644 index 0000000000..d04d51cda3 --- /dev/null +++ b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerSecurityConfiguration.java @@ -0,0 +1,21 @@ +package com.baeldung.cfuaa.oauth2.resourceserver; + +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@EnableWebSecurity +public class CFUAAOAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .authorizeRequests() + .antMatchers("/read/**").hasAuthority("SCOPE_resource.read") + .antMatchers("/write/**").hasAuthority("SCOPE_resource.write") + .anyRequest().authenticated() + .and() + .oauth2ResourceServer() + .jwt(); + } +} \ No newline at end of file diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/resources/application.properties b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/resources/application.properties new file mode 100644 index 0000000000..ba9b95e0d4 --- /dev/null +++ b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/resources/application.properties @@ -0,0 +1,16 @@ +server.port=8082 + +uaa.url=http://localhost:8080/uaa + +#approch1 +spring.security.oauth2.resourceserver.jwt.issuer-uri=${uaa.url}/oauth/token + +#approch2 +#spring.security.oauth2.resourceserver.jwt.jwk-set-uri=${uaa.url}/token_key + +# SECURITY OAUTH2 CLIENT (OAuth2ClientProperties) +#security.oauth2.client.client-id=client1 +#security.oauth2.client.client-secret=client1 + +#security.oauth2.resource.jwt.key-uri=${uaa.url}/token_key +#security.oauth2.resource.token-info-uri=${uaa.url}/oauth/check_token From 9f22567d4f0935ac1c4da08c8f745847a3f477a4 Mon Sep 17 00:00:00 2001 From: amdegregorio Date: Sat, 2 Mar 2019 11:06:35 -0500 Subject: [PATCH 126/134] BAEL-2727 Example Code --- .../main/groovy/com/baeldung/io/Task.groovy | 8 ++ .../src/main/resources/binaryExample.jpg | Bin 0 -> 1139 bytes core-groovy/src/main/resources/ioData.txt | Bin 0 -> 34 bytes core-groovy/src/main/resources/ioInput.txt | 4 + core-groovy/src/main/resources/ioOutput.txt | 3 + .../src/main/resources/ioSerializedObject.txt | Bin 0 -> 199 bytes .../baeldung/io/DataAndObjectsUnitTest.groovy | 51 +++++++ .../baeldung/io/ReadExampleUnitTest.groovy | 134 ++++++++++++++++++ .../io/TraverseFileTreeUnitTest.groovy | 61 ++++++++ .../baeldung/io/WriteExampleUnitTest.groovy | 96 +++++++++++++ 10 files changed, 357 insertions(+) create mode 100644 core-groovy/src/main/groovy/com/baeldung/io/Task.groovy create mode 100644 core-groovy/src/main/resources/binaryExample.jpg create mode 100644 core-groovy/src/main/resources/ioData.txt create mode 100644 core-groovy/src/main/resources/ioInput.txt create mode 100644 core-groovy/src/main/resources/ioOutput.txt create mode 100644 core-groovy/src/main/resources/ioSerializedObject.txt create mode 100644 core-groovy/src/test/groovy/com/baeldung/io/DataAndObjectsUnitTest.groovy create mode 100644 core-groovy/src/test/groovy/com/baeldung/io/ReadExampleUnitTest.groovy create mode 100644 core-groovy/src/test/groovy/com/baeldung/io/TraverseFileTreeUnitTest.groovy create mode 100644 core-groovy/src/test/groovy/com/baeldung/io/WriteExampleUnitTest.groovy diff --git a/core-groovy/src/main/groovy/com/baeldung/io/Task.groovy b/core-groovy/src/main/groovy/com/baeldung/io/Task.groovy new file mode 100644 index 0000000000..8a3bedc048 --- /dev/null +++ b/core-groovy/src/main/groovy/com/baeldung/io/Task.groovy @@ -0,0 +1,8 @@ +package com.baeldung.io + +class Task implements Serializable { + String description + Date startDate + Date dueDate + int status +} diff --git a/core-groovy/src/main/resources/binaryExample.jpg b/core-groovy/src/main/resources/binaryExample.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4b32645ac9b8030b3ed570263cd4f5c477a13d0f GIT binary patch literal 1139 zcmex=``2_j6xdp@o1cgOJMMZh|#U;coyG6VInuyV4pa*FVB^NNrR z{vTivwh= zDOELf4NWZ*Q!{f5ODks=S2uSLPp{yR(6I1`$f)F$)U@=B%&g*)(z5c3%Btp;*0%PJ z&aO$5r%atTea6gLixw|gx@`H1m8&*w-m-Pu_8mKS9XfpE=&|D`PM*4S`O4L6*Kgds z_3+W-Cr_U}fAR9w$4{TXeEs(Q$Io9Ne=#yJL%ap|8JfQYf&OA*VPR%r2lxYE z#}NLy#lXYN2#h>tK?Zwsdx80d=DeqoLp33BN>@lV5)W0p*xBF6khQ3U6 zd|u@KEmAIb41aHDTx{>#nkC<~Jx*3U>Uf9g?-TCdWVB0j6ID+27Ax=^&QO1*obaGL zF@Af(VsHJEk9BnJsHWWR@(aq%*y``S^~J;|=RU8_)Ly*5{gHTgeOkOMcddR{_HHJz zvQ1OwD?L;4=b8C4y2+f+eZ9r{3-#^)Y%cv%t}yrfs5Vpmm)v58sevc%N~g5DeGlVV zen;w0{g3vKPVbM$DeSnqzRcwulRHm+nTf1O)!$mr^-KOSRoFk$+xua*)BcNgS4?)c zJmZ~x;J`eG!p2v;m3tgpmiHXGxVCFba%`lR*R7Y=?$$r(Ynh{RrL^;1{5J77O?5WM z**o@_7PHNN%&k!~X*$aq^NUPgiw)$pd*-g~k$LbSVf`^V{tx~~);Hxo;?{AXX;%T4=@?p*vK{+sQO z^N*QpZr%B@-hbzZ^0v^!G2S)%V(+Z7S`#pThVb9#419YYi~gGYu%0(_AMb~Ea~Hn& swmNlL<_F!qdpIu&y0KsRHShT>jde1|Wuqm7uEupQ40*6 + out.writeUTF(message) + out.writeInt(length) + out.writeBoolean(valid) + } + + String loadedMessage = "" + int loadedLength + boolean loadedValid + + new File('src/main/resources/ioData.txt').withDataInputStream { is -> + loadedMessage = is.readUTF() + loadedLength = is.readInt() + loadedValid = is.readBoolean() + } + + assertEquals(message, loadedMessage) + assertEquals(length, loadedLength) + assertEquals(valid, loadedValid) + } + + @Test + void whenUsingWithObjectOutputStream_thenObjectIsSerializedToFile() { + Task task = new Task(description:'Take out the trash', startDate:new Date(), status:0) + new File('src/main/resources/ioSerializedObject.txt').withObjectOutputStream { out -> + out.writeObject(task) + } + + Task taskRead + + new File('src/main/resources/ioSerializedObject.txt').withObjectInputStream { is -> + taskRead = is.readObject() + } + + assertEquals(task.description, taskRead.description) + assertEquals(task.startDate, taskRead.startDate) + assertEquals(task.status, taskRead.status) + } +} diff --git a/core-groovy/src/test/groovy/com/baeldung/io/ReadExampleUnitTest.groovy b/core-groovy/src/test/groovy/com/baeldung/io/ReadExampleUnitTest.groovy new file mode 100644 index 0000000000..bed77b4d81 --- /dev/null +++ b/core-groovy/src/test/groovy/com/baeldung/io/ReadExampleUnitTest.groovy @@ -0,0 +1,134 @@ +package com.baeldung.io + +import static org.junit.Assert.* +import org.junit.Test + +class ReadExampleUnitTest { + + @Test + void whenUsingEachLine_thenCorrectLinesReturned() { + def expectedList = [ + 'First line of text', + 'Second line of text', + 'Third line of text', + 'Fourth line of text'] + + def lines = [] + + new File('src/main/resources/ioInput.txt').eachLine { line -> + lines.add(line) + } + assertEquals(expectedList, lines) + } + + @Test + void whenUsingReadEachLineWithLineNumber_thenCorrectLinesReturned() { + def expectedList = [ + 'Second line of text', + 'Third line of text', + 'Fourth line of text'] + + def lineNoRange = 2..4 + def lines = [] + + new File('src/main/resources/ioInput.txt').eachLine { line, lineNo -> + if (lineNoRange.contains(lineNo)) { + lines.add(line) + } + } + assertEquals(expectedList, lines) + } + + @Test + void whenUsingReadEachLineWithLineNumberStartAtZero_thenCorrectLinesReturned() { + def expectedList = [ + 'Second line of text', + 'Third line of text', + 'Fourth line of text'] + + def lineNoRange = 1..3 + def lines = [] + + new File('src/main/resources/ioInput.txt').eachLine(0, { line, lineNo -> + if (lineNoRange.contains(lineNo)) { + lines.add(line) + } + }) + assertEquals(expectedList, lines) + } + + @Test + void whenUsingWithReader_thenLineCountReturned() { + def expectedCount = 4 + def actualCount = 0 + new File('src/main/resources/ioInput.txt').withReader { reader -> + while(reader.readLine()) { + actualCount++ + } + } + assertEquals(expectedCount, actualCount) + } + + @Test + void whenUsingNewReader_thenOutputFileCreated() { + def outputPath = 'src/main/resources/ioOut.txt' + def reader = new File('src/main/resources/ioInput.txt').newReader() + new File(outputPath).append(reader) + reader.close() + def ioOut = new File(outputPath) + assertTrue(ioOut.exists()) + ioOut.delete() + } + + @Test + void whenUsingWithInputStream_thenCorrectBytesAreReturned() { + def expectedLength = 1139 + byte[] data = [] + new File("src/main/resources/binaryExample.jpg").withInputStream { stream -> + data = stream.getBytes() + } + assertEquals(expectedLength, data.length) + } + + @Test + void whenUsingNewInputStream_thenOutputFileCreated() { + def outputPath = 'src/main/resources/binaryOut.jpg' + def is = new File('src/main/resources/binaryExample.jpg').newInputStream() + new File(outputPath).append(is) + is.close() + def ioOut = new File(outputPath) + assertTrue(ioOut.exists()) + ioOut.delete() + } + + @Test + void whenUsingCollect_thenCorrectListIsReturned() { + def expectedList = ['First line of text', 'Second line of text', 'Third line of text', 'Fourth line of text'] + + def actualList = new File('src/main/resources/ioInput.txt').collect {it} + assertEquals(expectedList, actualList) + } + + @Test + void whenUsingAsStringArray_thenCorrectArrayIsReturned() { + String[] expectedArray = ['First line of text', 'Second line of text', 'Third line of text', 'Fourth line of text'] + + def actualArray = new File('src/main/resources/ioInput.txt') as String[] + assertArrayEquals(expectedArray, actualArray) + } + + @Test + void whenUsingText_thenCorrectStringIsReturned() { + def ln = System.getProperty('line.separator') + def expectedString = "First line of text${ln}Second line of text${ln}Third line of text${ln}Fourth line of text" + def actualString = new File('src/main/resources/ioInput.txt').text + assertEquals(expectedString.toString(), actualString) + } + + @Test + void whenUsingBytes_thenByteArrayIsReturned() { + def expectedLength = 1139 + def contents = new File('src/main/resources/binaryExample.jpg').bytes + assertEquals(expectedLength, contents.length) + } +} diff --git a/core-groovy/src/test/groovy/com/baeldung/io/TraverseFileTreeUnitTest.groovy b/core-groovy/src/test/groovy/com/baeldung/io/TraverseFileTreeUnitTest.groovy new file mode 100644 index 0000000000..dac0189fb9 --- /dev/null +++ b/core-groovy/src/test/groovy/com/baeldung/io/TraverseFileTreeUnitTest.groovy @@ -0,0 +1,61 @@ +package com.baeldung.io + +import org.junit.Test + +import groovy.io.FileType +import groovy.io.FileVisitResult + +class TraverseFileTreeUnitTest { + @Test + void whenUsingEachFile_filesAreListed() { + new File('src/main/resources').eachFile { file -> + println file.name + } + } + + @Test(expected = IllegalArgumentException) + void whenUsingEachFileOnAFile_anErrorOccurs() { + new File('src/main/resources/ioInput.txt').eachFile { file -> + println file.name + } + } + + @Test + void whenUsingEachFileMatch_filesAreListed() { + new File('src/main/resources').eachFileMatch(~/io.*\.txt/) { file -> + println file.name + } + } + + @Test + void whenUsingEachFileRecurse_thenFilesInSubfoldersAreListed() { + new File('src/main').eachFileRecurse(FileType.FILES) { file -> + println "$file.parent $file.name" + } + } + + @Test + void whenUsingEachFileRecurse_thenDirsInSubfoldersAreListed() { + new File('src/main').eachFileRecurse(FileType.DIRECTORIES) { file -> + println "$file.parent $file.name" + } + } + + @Test + void whenUsingEachDirRecurse_thenDirsAndSubDirsAreListed() { + new File('src/main').eachDirRecurse { dir -> + println "$dir.parent $dir.name" + } + } + + @Test + void whenUsingTraverse_thenDirectoryIsTraversed() { + new File('src/main').traverse { file -> + if (file.directory && file.name == 'groovy') { + FileVisitResult.SKIP_SUBTREE + } else { + println "$file.parent - $file.name" + } + } + } +} diff --git a/core-groovy/src/test/groovy/com/baeldung/io/WriteExampleUnitTest.groovy b/core-groovy/src/test/groovy/com/baeldung/io/WriteExampleUnitTest.groovy new file mode 100644 index 0000000000..81758b430a --- /dev/null +++ b/core-groovy/src/test/groovy/com/baeldung/io/WriteExampleUnitTest.groovy @@ -0,0 +1,96 @@ +package com.baeldung.io + +import static org.junit.Assert.* + +import org.junit.Before +import org.junit.Test + +class WriteExampleUnitTest { + @Before + void clearOutputFile() { + new File('src/main/resources/ioOutput.txt').text = '' + new File('src/main/resources/ioBinaryOutput.bin').delete() + } + + @Test + void whenUsingWithWriter_thenFileCreated() { + def outputLines = [ + 'Line one of output example', + 'Line two of output example', + 'Line three of output example' + ] + + def outputFileName = 'src/main/resources/ioOutput.txt' + new File(outputFileName).withWriter { writer -> + outputLines.each { line -> + writer.writeLine line + } + } + def writtenLines = new File(outputFileName).collect {it} + assertEquals(outputLines, writtenLines) + } + + @Test + void whenUsingNewWriter_thenFileCreated() { + def outputLines = [ + 'Line one of output example', + 'Line two of output example', + 'Line three of output example' + ] + + def outputFileName = 'src/main/resources/ioOutput.txt' + def writer = new File(outputFileName).newWriter() + outputLines.forEach {line -> + writer.writeLine line + } + writer.flush() + writer.close() + + def writtenLines = new File(outputFileName).collect {it} + assertEquals(outputLines, writtenLines) + } + + @Test + void whenUsingDoubleLessThanOperator_thenFileCreated() { + def outputLines = [ + 'Line one of output example', + 'Line two of output example', + 'Line three of output example' + ] + + def ln = System.getProperty('line.separator') + def outputFileName = 'src/main/resources/ioOutput.txt' + new File(outputFileName) << "Line one of output example${ln}Line two of output example${ln}Line three of output example" + def writtenLines = new File(outputFileName).collect {it} + assertEquals(outputLines.size(), writtenLines.size()) + } + + @Test + void whenUsingBytes_thenBinaryFileCreated() { + def outputFileName = 'src/main/resources/ioBinaryOutput.bin' + def outputFile = new File(outputFileName) + byte[] outBytes = [44, 88, 22] + outputFile.bytes = outBytes + assertEquals(3, new File(outputFileName).size()) + } + + @Test + void whenUsingWithOutputStream_thenBinaryFileCreated() { + def outputFileName = 'src/main/resources/ioBinaryOutput.bin' + byte[] outBytes = [44, 88, 22] + new File(outputFileName).withOutputStream { stream -> + stream.write(outBytes) + } + assertEquals(3, new File(outputFileName).size()) + } + + @Test + void whenUsingNewOutputStream_thenBinaryFileCreated() { + def outputFileName = 'src/main/resources/ioBinaryOutput.bin' + byte[] outBytes = [44, 88, 22] + def os = new File(outputFileName).newOutputStream() + os.write(outBytes) + os.close() + assertEquals(3, new File(outputFileName).size()) + } +} From 7a029078e6860742f08fb13e6f5da75fcb81788a Mon Sep 17 00:00:00 2001 From: Urvy Agrawal Date: Thu, 7 Mar 2019 22:49:44 +0530 Subject: [PATCH 127/134] Adding files for BAEL-2196 (#6477) * Adding files for BAEL-2196 * modified Package structure --- maven/compiler-plugin-java-9/pom.xml | 22 +++++++++++++++++++ .../maven/java9/MavenCompilerPlugin.java | 9 ++++++++ .../src/main/java/module-info.java | 3 +++ 3 files changed, 34 insertions(+) create mode 100644 maven/compiler-plugin-java-9/pom.xml create mode 100644 maven/compiler-plugin-java-9/src/main/java/com/baeldung/maven/java9/MavenCompilerPlugin.java create mode 100644 maven/compiler-plugin-java-9/src/main/java/module-info.java diff --git a/maven/compiler-plugin-java-9/pom.xml b/maven/compiler-plugin-java-9/pom.xml new file mode 100644 index 0000000000..5303cee82e --- /dev/null +++ b/maven/compiler-plugin-java-9/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + com.baeldung + compiler-plugin-java-9 + 0.0.1-SNAPSHOT + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 9 + 9 + + + + + \ No newline at end of file diff --git a/maven/compiler-plugin-java-9/src/main/java/com/baeldung/maven/java9/MavenCompilerPlugin.java b/maven/compiler-plugin-java-9/src/main/java/com/baeldung/maven/java9/MavenCompilerPlugin.java new file mode 100644 index 0000000000..b460d6e38c --- /dev/null +++ b/maven/compiler-plugin-java-9/src/main/java/com/baeldung/maven/java9/MavenCompilerPlugin.java @@ -0,0 +1,9 @@ +package com.baeldung.maven.java9; + +import static javax.xml.XMLConstants.XML_NS_PREFIX; + +public class MavenCompilerPlugin { + public static void main(String[] args) { + System.out.println("The XML namespace prefix is: " + XML_NS_PREFIX); + } +} diff --git a/maven/compiler-plugin-java-9/src/main/java/module-info.java b/maven/compiler-plugin-java-9/src/main/java/module-info.java new file mode 100644 index 0000000000..afc1d45e71 --- /dev/null +++ b/maven/compiler-plugin-java-9/src/main/java/module-info.java @@ -0,0 +1,3 @@ +module com.baeldung.maven.java9 { + requires java.xml; +} \ No newline at end of file From 67ed044498250f2b62a55866d63efd45dd5c4119 Mon Sep 17 00:00:00 2001 From: eric-martin Date: Thu, 7 Mar 2019 21:52:47 -0600 Subject: [PATCH 128/134] BAEL-2755: Added design-patterns-2 module --- patterns/design-patterns-2/pom.xml | 25 +++++++++++++++++++ .../com/baeldung/nullobject/JmsRouter.java | 0 .../java/com/baeldung/nullobject/Message.java | 0 .../com/baeldung/nullobject/NullRouter.java | 0 .../java/com/baeldung/nullobject/Router.java | 0 .../baeldung/nullobject/RouterFactory.java | 0 .../baeldung/nullobject/RoutingHandler.java | 0 .../com/baeldung/nullobject/SmsRouter.java | 0 patterns/pom.xml | 1 + 9 files changed, 26 insertions(+) create mode 100644 patterns/design-patterns-2/pom.xml rename patterns/{design-patterns => design-patterns-2}/src/main/java/com/baeldung/nullobject/JmsRouter.java (100%) rename patterns/{design-patterns => design-patterns-2}/src/main/java/com/baeldung/nullobject/Message.java (100%) rename patterns/{design-patterns => design-patterns-2}/src/main/java/com/baeldung/nullobject/NullRouter.java (100%) rename patterns/{design-patterns => design-patterns-2}/src/main/java/com/baeldung/nullobject/Router.java (100%) rename patterns/{design-patterns => design-patterns-2}/src/main/java/com/baeldung/nullobject/RouterFactory.java (100%) rename patterns/{design-patterns => design-patterns-2}/src/main/java/com/baeldung/nullobject/RoutingHandler.java (100%) rename patterns/{design-patterns => design-patterns-2}/src/main/java/com/baeldung/nullobject/SmsRouter.java (100%) diff --git a/patterns/design-patterns-2/pom.xml b/patterns/design-patterns-2/pom.xml new file mode 100644 index 0000000000..2a0213065b --- /dev/null +++ b/patterns/design-patterns-2/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + design-patterns-2 + 1.0 + design-patterns-2 + jar + + + com.baeldung + patterns + 1.0.0-SNAPSHOT + .. + + + + + + + UTF-8 + 1.8 + 1.8 + + diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/JmsRouter.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/JmsRouter.java similarity index 100% rename from patterns/design-patterns/src/main/java/com/baeldung/nullobject/JmsRouter.java rename to patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/JmsRouter.java diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/Message.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/Message.java similarity index 100% rename from patterns/design-patterns/src/main/java/com/baeldung/nullobject/Message.java rename to patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/Message.java diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/NullRouter.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/NullRouter.java similarity index 100% rename from patterns/design-patterns/src/main/java/com/baeldung/nullobject/NullRouter.java rename to patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/NullRouter.java diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/Router.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/Router.java similarity index 100% rename from patterns/design-patterns/src/main/java/com/baeldung/nullobject/Router.java rename to patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/Router.java diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/RouterFactory.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/RouterFactory.java similarity index 100% rename from patterns/design-patterns/src/main/java/com/baeldung/nullobject/RouterFactory.java rename to patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/RouterFactory.java diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/RoutingHandler.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/RoutingHandler.java similarity index 100% rename from patterns/design-patterns/src/main/java/com/baeldung/nullobject/RoutingHandler.java rename to patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/RoutingHandler.java diff --git a/patterns/design-patterns/src/main/java/com/baeldung/nullobject/SmsRouter.java b/patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/SmsRouter.java similarity index 100% rename from patterns/design-patterns/src/main/java/com/baeldung/nullobject/SmsRouter.java rename to patterns/design-patterns-2/src/main/java/com/baeldung/nullobject/SmsRouter.java diff --git a/patterns/pom.xml b/patterns/pom.xml index 3c3bb6d5ea..111e72b9ca 100644 --- a/patterns/pom.xml +++ b/patterns/pom.xml @@ -17,6 +17,7 @@ front-controller intercepting-filter design-patterns + design-patterns-2 solid From 786888f7c33d5bd147654565a5a810dfba8ad0b6 Mon Sep 17 00:00:00 2001 From: Ger Roza Date: Fri, 8 Mar 2019 08:39:44 -0300 Subject: [PATCH 129/134] BAEL-12777 Upgrade parent-spring-5 version: * Migrated parent-spring-5 version (spring-core and spring-security) * Cleaned spring-security version being used in some modules. Now using the parent version --- parent-spring-5/pom.xml | 4 ++-- spring-mvc-simple/pom.xml | 3 +-- spring-security-mvc-custom/pom.xml | 11 ++++------- spring-security-mvc-jsonview/pom.xml | 11 ++++------- spring-security-mvc-login/pom.xml | 9 ++++----- spring-security-rest/pom.xml | 7 +++---- spring-static-resources/pom.xml | 9 +++------ 7 files changed, 21 insertions(+), 33 deletions(-) diff --git a/parent-spring-5/pom.xml b/parent-spring-5/pom.xml index 5d7a3b66b3..3178682d34 100644 --- a/parent-spring-5/pom.xml +++ b/parent-spring-5/pom.xml @@ -29,10 +29,10 @@ - 5.1.2.RELEASE + 5.1.4.RELEASE 5.0.2 2.9.6 - 5.1.2.RELEASE + 5.1.4.RELEASE \ No newline at end of file diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml index 8c2661cc27..b9ed3a3e81 100644 --- a/spring-mvc-simple/pom.xml +++ b/spring-mvc-simple/pom.xml @@ -17,7 +17,7 @@ org.springframework spring-oxm - ${spring-oxm.version} + ${spring.version} com.sun.mail @@ -181,7 +181,6 @@ 1.4.9 5.1.0 20180130 - 5.0.2.RELEASE 3.0.8 diff --git a/spring-security-mvc-custom/pom.xml b/spring-security-mvc-custom/pom.xml index b4239fb2b8..7c60a8e18a 100644 --- a/spring-security-mvc-custom/pom.xml +++ b/spring-security-mvc-custom/pom.xml @@ -21,17 +21,17 @@ org.springframework.security spring-security-web - ${org.springframework.security.version} + ${spring-security.version} org.springframework.security spring-security-config - ${org.springframework.security.version} + ${spring-security.version} org.springframework.security spring-security-taglibs - ${org.springframework.security.version} + ${spring-security.version} @@ -144,7 +144,7 @@ org.springframework.security spring-security-test - ${org.springframework.security.version} + ${spring-security.version} test @@ -192,9 +192,6 @@
- - 5.0.6.RELEASE - 3.1.0 1.2 diff --git a/spring-security-mvc-jsonview/pom.xml b/spring-security-mvc-jsonview/pom.xml index 7f1129128f..b6d3e7e399 100644 --- a/spring-security-mvc-jsonview/pom.xml +++ b/spring-security-mvc-jsonview/pom.xml @@ -38,17 +38,17 @@ org.springframework.security spring-security-web - ${org.springframework.security.version} + ${spring-security.version} org.springframework.security spring-security-config - ${org.springframework.security.version} + ${spring-security.version} org.springframework.security spring-security-taglibs - ${org.springframework.security.version} + ${spring-security.version} @@ -133,7 +133,7 @@ org.springframework.security spring-security-test - ${org.springframework.security.version} + ${spring-security.version} test @@ -206,9 +206,6 @@ - - 5.0.5.RELEASE - 3.1.0 1.2 diff --git a/spring-security-mvc-login/pom.xml b/spring-security-mvc-login/pom.xml index bbdff6fc2f..048297bbd4 100644 --- a/spring-security-mvc-login/pom.xml +++ b/spring-security-mvc-login/pom.xml @@ -21,17 +21,17 @@ org.springframework.security spring-security-web - ${org.springframework.security.version} + ${spring-security.version} org.springframework.security spring-security-config - ${org.springframework.security.version} + ${spring-security.version} org.springframework.security spring-security-taglibs - ${org.springframework.security.version} + ${spring-security.version} @@ -116,7 +116,7 @@ org.springframework.security spring-security-test - ${org.springframework.security.version} + ${spring-security.version} test @@ -175,7 +175,6 @@ - 5.0.5.RELEASE 3.1.0 diff --git a/spring-security-rest/pom.xml b/spring-security-rest/pom.xml index 37c743e896..24f1c5807a 100644 --- a/spring-security-rest/pom.xml +++ b/spring-security-rest/pom.xml @@ -21,12 +21,12 @@ org.springframework.security spring-security-web - ${org.springframework.security.version} + ${spring-security.version} org.springframework.security spring-security-config - ${org.springframework.security.version} + ${spring-security.version} @@ -144,7 +144,7 @@ org.springframework.security spring-security-test - ${org.springframework.security.version} + ${spring-security.version} test @@ -274,7 +274,6 @@ - 5.1.0.RELEASE 0.25.0.RELEASE diff --git a/spring-static-resources/pom.xml b/spring-static-resources/pom.xml index aedf88e384..fc2b3336bc 100644 --- a/spring-static-resources/pom.xml +++ b/spring-static-resources/pom.xml @@ -20,17 +20,17 @@ org.springframework.security spring-security-web - ${org.springframework.security.version} + ${spring-security.version} org.springframework.security spring-security-config - ${org.springframework.security.version} + ${spring-security.version} org.springframework.security spring-security-taglibs - ${org.springframework.security.version} + ${spring-security.version} @@ -196,9 +196,6 @@ - - 5.0.6.RELEASE - 1.8.9 2.3.2-b02 From ae6c29dd19fcb5edf0182096f3f3b7b0f8a5c6e8 Mon Sep 17 00:00:00 2001 From: Alejandro Gervasio Date: Fri, 8 Mar 2019 11:20:52 -0300 Subject: [PATCH 130/134] Guide to Stream.reduce() (#6480) * Initial Commit * Update Application.java * Update Application.java --- java-streams-2/pom.xml | 39 +++++++++ .../reduce/application/Application.java | 39 +++++++++ .../benchmarks/JMHStreamReduceBenchMark.java | 52 ++++++++++++ .../com/baeldung/reduce/entities/User.java | 25 ++++++ .../reduce/utilities/NumberUtils.java | 52 ++++++++++++ .../reduce/tests/StreamReduceUnitTest.java | 79 +++++++++++++++++++ 6 files changed, 286 insertions(+) create mode 100644 java-streams-2/pom.xml create mode 100644 java-streams-2/src/main/java/com/baeldung/reduce/application/Application.java create mode 100644 java-streams-2/src/main/java/com/baeldung/reduce/benchmarks/JMHStreamReduceBenchMark.java create mode 100644 java-streams-2/src/main/java/com/baeldung/reduce/entities/User.java create mode 100644 java-streams-2/src/main/java/com/baeldung/reduce/utilities/NumberUtils.java create mode 100644 java-streams-2/src/test/java/com/baeldung/reduce/tests/StreamReduceUnitTest.java diff --git a/java-streams-2/pom.xml b/java-streams-2/pom.xml new file mode 100644 index 0000000000..cd89a1a80f --- /dev/null +++ b/java-streams-2/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + com.baeldung.javastreams2 + javastreams2 + 1.0 + jar + + + org.openjdk.jmh + jmh-core + 1.21 + + + org.openjdk.jmh + jmh-generator-annprocess + 1.21 + + + junit + junit + 4.12 + test + jar + + + org.assertj + assertj-core + 3.11.1 + test + + + Stream Reduce + + UTF-8 + 1.8 + 1.8 + + \ No newline at end of file diff --git a/java-streams-2/src/main/java/com/baeldung/reduce/application/Application.java b/java-streams-2/src/main/java/com/baeldung/reduce/application/Application.java new file mode 100644 index 0000000000..79c557524d --- /dev/null +++ b/java-streams-2/src/main/java/com/baeldung/reduce/application/Application.java @@ -0,0 +1,39 @@ +package com.baeldung.reduce.application; + +import com.baeldung.reduce.entities.User; +import com.baeldung.reduce.utilities.NumberUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Application { + + public static void main(String[] args) { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + int result1 = numbers.stream().reduce(0, (subtotal, element) -> subtotal + element); + System.out.println(result1); + + int result2 = numbers.stream().reduce(0, Integer::sum); + System.out.println(result2); + + List letters = Arrays.asList("a", "b", "c", "d", "e"); + String result3 = letters.stream().reduce("", (partialString, element) -> partialString + element); + System.out.println(result3); + + String result4 = letters.stream().reduce("", String::concat); + System.out.println(result4); + + String result5 = letters.stream().reduce("", (partialString, element) -> partialString.toUpperCase() + element.toUpperCase()); + System.out.println(result5); + + List users = Arrays.asList(new User("John", 30), new User("Julie", 35)); + int result6 = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); + System.out.println(result6); + + String result7 = letters.parallelStream().reduce("", String::concat); + System.out.println(result7); + + int result8 = users.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); + System.out.println(result8); + } +} diff --git a/java-streams-2/src/main/java/com/baeldung/reduce/benchmarks/JMHStreamReduceBenchMark.java b/java-streams-2/src/main/java/com/baeldung/reduce/benchmarks/JMHStreamReduceBenchMark.java new file mode 100644 index 0000000000..af4a9276a9 --- /dev/null +++ b/java-streams-2/src/main/java/com/baeldung/reduce/benchmarks/JMHStreamReduceBenchMark.java @@ -0,0 +1,52 @@ +package com.baeldung.reduce.benchmarks; + +import com.baeldung.reduce.entities.User; +import java.util.ArrayList; +import java.util.List; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +@State(Scope.Thread) +@BenchmarkMode(Mode.AverageTime) +public class JMHStreamReduceBenchMark { + + private final List userList = createUsers(); + + public static void main(String[] args) throws RunnerException { + + Options options = new OptionsBuilder() + .include(JMHStreamReduceBenchMark.class.getSimpleName()).threads(1) + .forks(1).shouldFailOnError(true).shouldDoGC(true) + .jvmArgs("-server").build(); + new Runner(options).run(); + } + + private List createUsers() { + List users = new ArrayList<>(); + for (int i = 0; i <= 1000000; i++) { + users.add(new User("John" + i, i)); + } + return users; + } + + @Benchmark + public Integer executeReduceOnParallelizedStream() { + return this.userList + .parallelStream() + .reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); + } + + @Benchmark + public Integer executeReduceOnSequentialStream() { + return this.userList + .stream() + .reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); + } +} diff --git a/java-streams-2/src/main/java/com/baeldung/reduce/entities/User.java b/java-streams-2/src/main/java/com/baeldung/reduce/entities/User.java new file mode 100644 index 0000000000..a17c6a02b6 --- /dev/null +++ b/java-streams-2/src/main/java/com/baeldung/reduce/entities/User.java @@ -0,0 +1,25 @@ +package com.baeldung.reduce.entities; + +public class User { + + private final String name; + private final int age; + + public User(String name, int age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } + + @Override + public String toString() { + return "User{" + "name=" + name + ", age=" + age + '}'; + } +} diff --git a/java-streams-2/src/main/java/com/baeldung/reduce/utilities/NumberUtils.java b/java-streams-2/src/main/java/com/baeldung/reduce/utilities/NumberUtils.java new file mode 100644 index 0000000000..a7a4b8df29 --- /dev/null +++ b/java-streams-2/src/main/java/com/baeldung/reduce/utilities/NumberUtils.java @@ -0,0 +1,52 @@ +package com.baeldung.reduce.utilities; + +import java.util.List; +import java.util.function.BiFunction; +import java.util.logging.Level; +import java.util.logging.Logger; + +public abstract class NumberUtils { + + private static final Logger LOGGER = Logger.getLogger(NumberUtils.class.getName()); + + public static int divideListElements(List values, Integer divider) { + return values.stream() + .reduce(0, (a, b) -> { + try { + return a / divider + b / divider; + } catch (ArithmeticException e) { + LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero"); + } + return 0; + }); + } + + public static int divideListElementsWithExtractedTryCatchBlock(List values, int divider) { + return values.stream().reduce(0, (a, b) -> divide(a, divider) + divide(b, divider)); + } + + public static int divideListElementsWithApplyFunctionMethod(List values, int divider) { + BiFunction division = (a, b) -> a / b; + return values.stream().reduce(0, (a, b) -> applyFunction(division, a, divider) + applyFunction(division, b, divider)); + } + + private static int divide(int value, int factor) { + int result = 0; + try { + result = value / factor; + } catch (ArithmeticException e) { + LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero"); + } + return result; + } + + private static int applyFunction(BiFunction function, int a, int b) { + try { + return function.apply(a, b); + } + catch(Exception e) { + LOGGER.log(Level.INFO, "Exception thrown!"); + } + return 0; + } +} diff --git a/java-streams-2/src/test/java/com/baeldung/reduce/tests/StreamReduceUnitTest.java b/java-streams-2/src/test/java/com/baeldung/reduce/tests/StreamReduceUnitTest.java new file mode 100644 index 0000000000..564d614017 --- /dev/null +++ b/java-streams-2/src/test/java/com/baeldung/reduce/tests/StreamReduceUnitTest.java @@ -0,0 +1,79 @@ +package com.baeldung.reduce.tests; + +import com.baeldung.reduce.entities.User; +import com.baeldung.reduce.utilities.NumberUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; + +public class StreamReduceUnitTest { + + @Test + public void givenIntegerList_whenReduceWithSumAccumulatorLambda_thenCorrect() { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + int result = numbers.stream().reduce(0, (subtotal, element) -> subtotal + element); + assertThat(result).isEqualTo(21); + } + + @Test + public void givenIntegerList_whenReduceWithSumAccumulatorMethodReference_thenCorrect() { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + int result = numbers.stream().reduce(0, Integer::sum); + assertThat(result).isEqualTo(21); + } + + @Test + public void givenStringList_whenReduceWithConcatenatorAccumulatorLambda_thenCorrect() { + List letters = Arrays.asList("a", "b", "c", "d", "e"); + String result = letters.stream().reduce("", (partialString, element) -> partialString + element); + assertThat(result).isEqualTo("abcde"); + } + + @Test + public void givenStringList_whenReduceWithConcatenatorAccumulatorMethodReference_thenCorrect() { + List letters = Arrays.asList("a", "b", "c", "d", "e"); + String result = letters.stream().reduce("", String::concat); + assertThat(result).isEqualTo("abcde"); + } + + @Test + public void givenStringList_whenReduceWithUppercaseConcatenatorAccumulator_thenCorrect() { + List letters = Arrays.asList("a", "b", "c", "d", "e"); + String result = letters.stream().reduce("", (partialString, element) -> partialString.toUpperCase() + element.toUpperCase()); + assertThat(result).isEqualTo("ABCDE"); + } + + @Test + public void givenUserList_whenReduceWithAgeAccumulatorAndSumCombiner_thenCorrect() { + List users = Arrays.asList(new User("John", 30), new User("Julie", 35)); + int result = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum); + assertThat(result).isEqualTo(65); + } + + @Test + public void givenStringList_whenReduceWithParallelStream_thenCorrect() { + List letters = Arrays.asList("a", "b", "c", "d", "e"); + String result = letters.parallelStream().reduce("", String::concat); + assertThat(result).isEqualTo("abcde"); + } + + @Test + public void givenNumberUtilsClass_whenCalledDivideListElements_thenCorrect() { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + assertThat(NumberUtils.divideListElements(numbers, 1)).isEqualTo(21); + } + + @Test + public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlock_thenCorrect() { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21); + } + + @Test + public void givenStream_whneCalleddivideListElementsWithApplyFunctionMethod_thenCorrect() { + List numbers = Arrays.asList(1, 2, 3, 4, 5, 6); + assertThat(NumberUtils.divideListElementsWithApplyFunctionMethod(numbers, 1)).isEqualTo(21); + } +} From 3fd4fb1cdaa7336358a259134ed5547a6fb57b2c Mon Sep 17 00:00:00 2001 From: Johan Janssen Date: Fri, 8 Mar 2019 15:30:10 +0100 Subject: [PATCH 131/134] Kotlin split list in pairs examples. (#6368) * Kotlin split list in pairs examples. * Renamed some items. --- .../com/baeldung/splitting/SplittingTest.kt | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/splitting/SplittingTest.kt diff --git a/core-kotlin/src/test/kotlin/com/baeldung/splitting/SplittingTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/splitting/SplittingTest.kt new file mode 100644 index 0000000000..a9ddc99992 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/splitting/SplittingTest.kt @@ -0,0 +1,99 @@ +package com.baeldung.lambda + +import org.junit.jupiter.api.Test +import kotlin.test.assertEquals + +class SplittingTest { + private val evenList = listOf(0, "a", 1, "b", 2, "c"); + + private val unevenList = listOf(0, "a", 1, "b", 2, "c", 3); + + private fun verifyList(resultList: List>) { + assertEquals("[[0, a], [1, b], [2, c]]", resultList.toString()) + } + + private fun verifyPartialList(resultList: List>) { + assertEquals("[[0, a], [1, b], [2, c], [3]]", resultList.toString()) + } + + @Test + fun whenChunked_thenListIsSplit() { + val resultList = evenList.chunked(2) + verifyList(resultList) + } + + @Test + fun whenUnevenChunked_thenListIsSplit() { + val resultList = unevenList.chunked(2) + verifyPartialList(resultList) + } + + @Test + fun whenWindowed_thenListIsSplit() { + val resultList = evenList.windowed(2, 2) + verifyList(resultList) + } + + @Test + fun whenUnevenPartialWindowed_thenListIsSplit() { + val resultList = unevenList.windowed(2, 2, partialWindows = true) + verifyPartialList(resultList) + } + + @Test + fun whenUnevenWindowed_thenListIsSplit() { + val resultList = unevenList.windowed(2, 2, partialWindows = false) + verifyList(resultList) + } + + @Test + fun whenGroupByWithAscendingNumbers_thenListIsSplit() { + val numberList = listOf(1, 2, 3, 4, 5, 6); + val resultList = numberList.groupBy { (it + 1) / 2 } + assertEquals("[[1, 2], [3, 4], [5, 6]]", resultList.values.toString()) + assertEquals("[1, 2, 3]", resultList.keys.toString()) + } + + @Test + fun whenGroupByWithAscendingNumbersUneven_thenListIsSplit() { + val numberList = listOf(1, 2, 3, 4, 5, 6, 7); + val resultList = numberList.groupBy { (it + 1) / 2 }.values + assertEquals("[[1, 2], [3, 4], [5, 6], [7]]", resultList.toString()) + } + + @Test + fun whenGroupByWithRandomNumbers_thenListIsSplitInWrongWay() { + val numberList = listOf(1, 3, 8, 20, 23, 30); + val resultList = numberList.groupBy { (it + 1) / 2 } + assertEquals("[[1], [3], [8], [20], [23], [30]]", resultList.values.toString()) + assertEquals("[1, 2, 4, 10, 12, 15]", resultList.keys.toString()) + } + + @Test + fun whenWithIndexGroupBy_thenListIsSplit() { + val resultList = evenList.withIndex() + .groupBy { it.index / 2 } + .map { it.value.map { it.value } } + verifyList(resultList) + } + + @Test + fun whenWithIndexGroupByUneven_thenListIsSplit() { + val resultList = unevenList.withIndex() + .groupBy { it.index / 2 } + .map { it.value.map { it.value } } + verifyPartialList(resultList) + } + + @Test + fun whenFoldIndexed_thenListIsSplit() { + val resultList = evenList.foldIndexed(ArrayList>(evenList.size / 2)) { index, acc, item -> + if (index % 2 == 0) { + acc.add(ArrayList(2)) + } + acc.last().add(item) + acc + } + verifyList(resultList) + } +} \ No newline at end of file From 4ec4fdb72bfc402fe1c3c1ea9dde8c59eced9f92 Mon Sep 17 00:00:00 2001 From: Wosin Date: Fri, 8 Mar 2019 23:20:37 +0100 Subject: [PATCH 132/134] Bael 43 (#6423) * BAEL-43: Apache Spark with Spring Cloud Data Flow * Replaced functions with lambdas + removed unnecessary type casting. --- .../apache-spark-job/pom.xml | 36 +++++++++++++++++ .../spring/cloud/PiApproximation.java | 39 +++++++++++++++++++ spring-cloud-data-flow/pom.xml | 1 + 3 files changed, 76 insertions(+) create mode 100644 spring-cloud-data-flow/apache-spark-job/pom.xml create mode 100644 spring-cloud-data-flow/apache-spark-job/src/main/java/com/baeldung/spring/cloud/PiApproximation.java diff --git a/spring-cloud-data-flow/apache-spark-job/pom.xml b/spring-cloud-data-flow/apache-spark-job/pom.xml new file mode 100644 index 0000000000..390b7ebdc6 --- /dev/null +++ b/spring-cloud-data-flow/apache-spark-job/pom.xml @@ -0,0 +1,36 @@ + + + + spring-cloud-data-flow + com.baeldung + 0.0.1-SNAPSHOT + + 4.0.0 + + apache-spark-job + + + org.springframework.cloud + spring-cloud-task-core + 2.0.0.RELEASE + + + org.apache.spark + spark-core_2.10 + 1.6.2 + + + log4j + log4j + + + org.slf4j + slf4j-log4j12 + + + + + + \ No newline at end of file diff --git a/spring-cloud-data-flow/apache-spark-job/src/main/java/com/baeldung/spring/cloud/PiApproximation.java b/spring-cloud-data-flow/apache-spark-job/src/main/java/com/baeldung/spring/cloud/PiApproximation.java new file mode 100644 index 0000000000..dfead21728 --- /dev/null +++ b/spring-cloud-data-flow/apache-spark-job/src/main/java/com/baeldung/spring/cloud/PiApproximation.java @@ -0,0 +1,39 @@ +package com.baeldung.spring.cloud; + +import org.apache.spark.SparkConf; +import org.apache.spark.api.java.JavaRDD; +import org.apache.spark.api.java.JavaSparkContext; +import org.apache.spark.api.java.function.Function; +import org.apache.spark.api.java.function.Function2; +import org.apache.spark.rdd.RDD; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class PiApproximation { + public static void main(String[] args) { + SparkConf conf = new SparkConf().setAppName("BaeldungPIApproximation"); + JavaSparkContext context = new JavaSparkContext(conf); + int slices = args.length >= 1 ? Integer.valueOf(args[0]) : 2; + int n = (100000L * slices) > Integer.MAX_VALUE ? Integer.MAX_VALUE : 100000 * slices; + + List xs = IntStream.rangeClosed(0, n) + .mapToObj(element -> Integer.valueOf(element)) + .collect(Collectors.toList()); + + JavaRDD dataSet = context.parallelize(xs, slices); + + JavaRDD pointsInsideTheCircle = dataSet.map(integer -> { + double x = Math.random() * 2 - 1; + double y = Math.random() * 2 - 1; + return (x*x + y*y ) < 1 ? 1: 0; + }); + + int count = pointsInsideTheCircle.reduce((integer, integer2) -> integer + integer2); + + System.out.println("The pi was estimated as:" + count / n); + + context.stop(); + } +} diff --git a/spring-cloud-data-flow/pom.xml b/spring-cloud-data-flow/pom.xml index daf8ebd2c8..36a780c28d 100644 --- a/spring-cloud-data-flow/pom.xml +++ b/spring-cloud-data-flow/pom.xml @@ -20,6 +20,7 @@ log-sink batch-job etl + apache-spark-job From 2c4d334dc3f11781393d354773fbb681d7c98794 Mon Sep 17 00:00:00 2001 From: soufiane-cheouati <46105138+soufiane-cheouati@users.noreply.github.com> Date: Fri, 8 Mar 2019 22:30:42 +0000 Subject: [PATCH 133/134] Reversing binary tree classes (#6467) * Add files via upload * Add files via upload * Add files via upload --- .../algorithms/reversingtree/TreeNode.java | 42 ++++++++++++ .../reversingtree/TreeReverser.java | 68 +++++++++++++++++++ .../reversingtree/TreeReverserUnitTest.java | 33 +++++++++ 3 files changed, 143 insertions(+) create mode 100644 algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeNode.java create mode 100644 algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeReverser.java create mode 100644 algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/reversingtree/TreeReverserUnitTest.java diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeNode.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeNode.java new file mode 100644 index 0000000000..7905b752a9 --- /dev/null +++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeNode.java @@ -0,0 +1,42 @@ +package com.baeldung.algorithms.reversingtree; + +public class TreeNode { + + private int value; + private TreeNode rightChild; + private TreeNode leftChild; + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public TreeNode getRightChild() { + return rightChild; + } + + public void setRightChild(TreeNode rightChild) { + this.rightChild = rightChild; + } + + public TreeNode getLeftChild() { + return leftChild; + } + + public void setLeftChild(TreeNode leftChild) { + this.leftChild = leftChild; + } + + public TreeNode(int value, TreeNode rightChild, TreeNode leftChild) { + this.value = value; + this.rightChild = rightChild; + this.leftChild = leftChild; + } + + public TreeNode(int value) { + this.value = value; + } +} diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeReverser.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeReverser.java new file mode 100644 index 0000000000..6d3a9ddd31 --- /dev/null +++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/reversingtree/TreeReverser.java @@ -0,0 +1,68 @@ +package com.baeldung.algorithms.reversingtree; + +import java.util.LinkedList; + +public class TreeReverser { + + public TreeNode createBinaryTree() { + + TreeNode leaf1 = new TreeNode(3); + TreeNode leaf2 = new TreeNode(1); + TreeNode leaf3 = new TreeNode(9); + TreeNode leaf4 = new TreeNode(6); + + TreeNode nodeLeft = new TreeNode(2, leaf1, leaf2); + TreeNode nodeRight = new TreeNode(7, leaf3, leaf4); + + TreeNode root = new TreeNode(4, nodeRight, nodeLeft); + + return root; + } + + public void reverseRecursive(TreeNode treeNode) { + if (treeNode == null) { + return; + } + + TreeNode temp = treeNode.getLeftChild(); + treeNode.setLeftChild(treeNode.getRightChild()); + treeNode.setRightChild(temp); + + reverseRecursive(treeNode.getLeftChild()); + reverseRecursive(treeNode.getRightChild()); + } + + public void reverseIterative(TreeNode treeNode) { + LinkedList queue = new LinkedList(); + + if (treeNode != null) { + queue.add(treeNode); + } + + while (!queue.isEmpty()) { + + TreeNode node = queue.poll(); + if (node.getLeftChild() != null) + queue.add(node.getLeftChild()); + if (node.getRightChild() != null) + queue.add(node.getRightChild()); + + TreeNode temp = node.getLeftChild(); + node.setLeftChild(node.getRightChild()); + node.setRightChild(temp); + } + } + + public String toString(TreeNode root) { + if (root == null) { + return ""; + } + + StringBuffer buffer = new StringBuffer(String.valueOf(root.getValue())).append(" "); + + buffer.append(toString(root.getLeftChild())); + buffer.append(toString(root.getRightChild())); + + return buffer.toString(); + } +} diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/reversingtree/TreeReverserUnitTest.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/reversingtree/TreeReverserUnitTest.java new file mode 100644 index 0000000000..cbc265fae1 --- /dev/null +++ b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/reversingtree/TreeReverserUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.algorithms.reversingtree; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class TreeReverserUnitTest { + + @Test + public void givenTreeWhenReversingRecursivelyThenReversed() { + TreeReverser reverser = new TreeReverser(); + + TreeNode treeNode = reverser.createBinaryTree(); + + reverser.reverseRecursive(treeNode); + + assertEquals("4 7 9 6 2 3 1", reverser.toString(treeNode) + .trim()); + } + + @Test + public void givenTreeWhenReversingIterativelyThenReversed() { + TreeReverser reverser = new TreeReverser(); + + TreeNode treeNode = reverser.createBinaryTree(); + + reverser.reverseIterative(treeNode); + + assertEquals("4 7 9 6 2 3 1", reverser.toString(treeNode) + .trim()); + } + +} From 8f54420e95d5012319dae1a27193234722e126b2 Mon Sep 17 00:00:00 2001 From: Juan Moreno Date: Sat, 9 Mar 2019 00:50:03 -0300 Subject: [PATCH 134/134] Added sample code for BAEL-1122 (#6468) --- spring-all/pom.xml | 18 +++++++------ .../spring/PropertiesWithJavaConfig.java | 1 + .../main/resources/configForProperties.xml | 2 +- ...lePropertiesJavaConfigIntegrationTest.java | 25 +++++++++++++++++++ ...plePropertiesXmlConfigIntegrationTest.java | 21 ++++++++++++++++ 5 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 spring-all/src/test/java/org/baeldung/properties/multiple/MultiplePropertiesJavaConfigIntegrationTest.java create mode 100644 spring-all/src/test/java/org/baeldung/properties/multiple/MultiplePropertiesXmlConfigIntegrationTest.java diff --git a/spring-all/pom.xml b/spring-all/pom.xml index 5872fbdac5..8c88efb970 100644 --- a/spring-all/pom.xml +++ b/spring-all/pom.xml @@ -1,5 +1,5 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-all 0.1-SNAPSHOT @@ -47,12 +47,16 @@ org.springframework spring-websocket - - + + org.springframework spring-messaging - - + + + javax.annotation + javax.annotation-api + ${annotation-api.version} + org.springframework @@ -227,13 +231,13 @@ - + org.baeldung.sample.App 5.0.6.RELEASE 1.2.0.RELEASE - + 1.3.2 5.2.5.Final diff --git a/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfig.java b/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfig.java index 08626bb4d2..6589143a94 100644 --- a/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfig.java +++ b/spring-all/src/main/java/org/baeldung/properties/spring/PropertiesWithJavaConfig.java @@ -7,6 +7,7 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; @Configuration @PropertySource("classpath:foo.properties") +@PropertySource("classpath:bar.properties") public class PropertiesWithJavaConfig { public PropertiesWithJavaConfig() { diff --git a/spring-all/src/main/resources/configForProperties.xml b/spring-all/src/main/resources/configForProperties.xml index 0f766665eb..459aea3ec6 100644 --- a/spring-all/src/main/resources/configForProperties.xml +++ b/spring-all/src/main/resources/configForProperties.xml @@ -7,7 +7,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd" > - + diff --git a/spring-all/src/test/java/org/baeldung/properties/multiple/MultiplePropertiesJavaConfigIntegrationTest.java b/spring-all/src/test/java/org/baeldung/properties/multiple/MultiplePropertiesJavaConfigIntegrationTest.java new file mode 100644 index 0000000000..9cb41c20f7 --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/properties/multiple/MultiplePropertiesJavaConfigIntegrationTest.java @@ -0,0 +1,25 @@ +package org.baeldung.properties.multiple; + +import org.baeldung.properties.spring.PropertiesWithJavaConfig; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringJUnitConfig(PropertiesWithJavaConfig.class) +public class MultiplePropertiesJavaConfigIntegrationTest { + + @Value("${key.something}") + private String something; + + @Value("${key.something2}") + private String something2; + + + @Test + public void whenReadInjectedValues_thenGetCorrectValues() { + assertThat(something).isEqualTo("val"); + assertThat(something2).isEqualTo("val2"); + } +} diff --git a/spring-all/src/test/java/org/baeldung/properties/multiple/MultiplePropertiesXmlConfigIntegrationTest.java b/spring-all/src/test/java/org/baeldung/properties/multiple/MultiplePropertiesXmlConfigIntegrationTest.java new file mode 100644 index 0000000000..b4f81f3541 --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/properties/multiple/MultiplePropertiesXmlConfigIntegrationTest.java @@ -0,0 +1,21 @@ +package org.baeldung.properties.multiple; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringJUnitConfig(locations = "classpath:configForProperties.xml") +public class MultiplePropertiesXmlConfigIntegrationTest { + + @Value("${key.something}") private String something; + + @Value("${key.something2}") private String something2; + + @Test + public void whenReadInjectedValues_thenGetCorrectValues() { + assertThat(something).isEqualTo("val"); + assertThat(something2).isEqualTo("val2"); + } +}