diff --git a/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/BasicConnectionPool.java b/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/BasicConnectionPool.java deleted file mode 100644 index 243ec88eb5..0000000000 --- a/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/BasicConnectionPool.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.baeldung.connectionpool.connectionpools; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -public class BasicConnectionPool implements ConnectionPool { - - private final String url; - private final String user; - private final String password; - private final List connectionPool; - private final List usedConnections = new ArrayList<>(); - private static final int INITIAL_POOL_SIZE = 10; - private final int MAX_POOL_SIZE = 20; - - public static BasicConnectionPool create(String url, String user, String password) throws SQLException { - List pool = new ArrayList<>(INITIAL_POOL_SIZE); - for (int i = 0; i < INITIAL_POOL_SIZE; i++) { - pool.add(createConnection(url, user, password)); - } - return new BasicConnectionPool(url, user, password, pool); - } - - private BasicConnectionPool(String url, String user, String password, List connectionPool) { - this.url = url; - this.user = user; - this.password = password; - this.connectionPool = connectionPool; - } - - @Override - public Connection getConnection() throws SQLException { - if (connectionPool.size() == 0) { - if (usedConnections.size() < MAX_POOL_SIZE) { - connectionPool.add(createConnection(url, user, password)); - } else { - throw new RuntimeException("Maximum pool size reached, no available connections!"); - } - } - - Connection connection = connectionPool.remove(connectionPool.size() - 1); - usedConnections.add(connection); - return connection; - } - - @Override - public boolean releaseConnection(Connection connection) { - connectionPool.add(connection); - return usedConnections.remove(connection); - } - - private static Connection createConnection(String url, String user, String password) throws SQLException { - return DriverManager.getConnection(url, user, password); - } - - public int getSize() { - return connectionPool.size() + usedConnections.size(); - } - - @Override - public String getUrl() { - return url; - } - - @Override - public String getUser() { - return user; - } - - @Override - public String getPassword() { - return password; - } - - public void shutdown() throws SQLException { - for (Connection c : usedConnections) { - this.releaseConnection(c); - } - for (Connection c : connectionPool) { - c.close(); - } - connectionPool.clear(); - } -} diff --git a/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/C3poDataSource.java b/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/C3poDataSource.java deleted file mode 100644 index 5b91f707a9..0000000000 --- a/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/C3poDataSource.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.connectionpool.connectionpools; - -import com.mchange.v2.c3p0.ComboPooledDataSource; -import java.beans.PropertyVetoException; -import java.sql.Connection; -import java.sql.SQLException; - -public class C3poDataSource { - - private static final ComboPooledDataSource cpds = new ComboPooledDataSource(); - - static { - try { - cpds.setDriverClass("org.h2.Driver"); - cpds.setJdbcUrl("jdbc:h2:mem:test"); - cpds.setUser("user"); - cpds.setPassword("password"); - } catch (PropertyVetoException e) { - e.printStackTrace(); - } - } - - public static Connection getConnection() throws SQLException { - return cpds.getConnection(); - } - - private C3poDataSource(){} -} \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/ConnectionPool.java b/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/ConnectionPool.java deleted file mode 100644 index 3d5ad06c3d..0000000000 --- a/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/ConnectionPool.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.connectionpool.connectionpools; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.List; - -public interface ConnectionPool { - - Connection getConnection() throws SQLException; - - boolean releaseConnection(Connection connection); - - String getUrl(); - - String getUser(); - - String getPassword(); -} \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/DBCPDataSource.java b/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/DBCPDataSource.java deleted file mode 100644 index 2f33cde883..0000000000 --- a/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/DBCPDataSource.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.connectionpool.connectionpools; - -import java.sql.Connection; -import java.sql.SQLException; -import org.apache.commons.dbcp2.BasicDataSource; - -public class DBCPDataSource { - - private static final BasicDataSource ds = new BasicDataSource(); - - static { - ds.setUrl("jdbc:h2:mem:test"); - ds.setUsername("user"); - ds.setPassword("password"); - ds.setMinIdle(5); - ds.setMaxIdle(10); - ds.setMaxOpenPreparedStatements(100); - } - - public static Connection getConnection() throws SQLException { - return ds.getConnection(); - } - - private DBCPDataSource(){} -} diff --git a/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/HikariCPDataSource.java b/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/HikariCPDataSource.java deleted file mode 100644 index 5ed2de181d..0000000000 --- a/core-java/src/main/java/com/baeldung/connectionpool/connectionpools/HikariCPDataSource.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.connectionpool.connectionpools; - -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.HikariDataSource; -import java.sql.Connection; -import java.sql.SQLException; - -public class HikariCPDataSource { - - private static final HikariConfig config = new HikariConfig(); - private static final HikariDataSource ds; - - static { - config.setJdbcUrl("jdbc:h2:mem:test"); - config.setUsername("user"); - config.setPassword("password"); - config.addDataSourceProperty("cachePrepStmts", "true"); - config.addDataSourceProperty("prepStmtCacheSize", "250"); - config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); - ds = new HikariDataSource(config); - } - - public static Connection getConnection() throws SQLException { - return ds.getConnection(); - } - - private HikariCPDataSource(){} -} diff --git a/core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF b/core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF deleted file mode 100644 index a363171952..0000000000 --- a/core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF +++ /dev/null @@ -1 +0,0 @@ -Main-Class: com.baeldung.manifest.AppExample diff --git a/core-java/src/test/java/com/baeldung/connectionpool/BasicConnectionPoolUnitTest.java b/core-java/src/test/java/com/baeldung/connectionpool/BasicConnectionPoolUnitTest.java deleted file mode 100644 index 5edc6bba94..0000000000 --- a/core-java/src/test/java/com/baeldung/connectionpool/BasicConnectionPoolUnitTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.baeldung.connectionpool; - -import com.baeldung.connectionpool.connectionpools.BasicConnectionPool; -import com.baeldung.connectionpool.connectionpools.ConnectionPool; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.List; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.junit.BeforeClass; -import org.junit.Test; - -public class BasicConnectionPoolUnitTest { - - private static ConnectionPool connectionPool; - - @BeforeClass - public static void setUpBasicConnectionPoolInstance() throws SQLException { - connectionPool = BasicConnectionPool.create("jdbc:h2:mem:test", "user", "password"); - } - - @Test - public void givenBasicConnectionPoolInstance_whenCalledgetConnection_thenCorrect() throws Exception { - assertTrue(connectionPool.getConnection().isValid(1)); - } - - @Test - public void givenBasicConnectionPoolInstance_whenCalledreleaseConnection_thenCorrect() throws Exception { - Connection connection = connectionPool.getConnection(); - assertThat(connectionPool.releaseConnection(connection)).isTrue(); - } - - @Test - public void givenBasicConnectionPoolInstance_whenCalledgetUrl_thenCorrect() { - assertThat(connectionPool.getUrl()).isEqualTo("jdbc:h2:mem:test"); - } - - @Test - public void givenBasicConnectionPoolInstance_whenCalledgetUser_thenCorrect() { - assertThat(connectionPool.getUser()).isEqualTo("user"); - } - - @Test - public void givenBasicConnectionPoolInstance_whenCalledgetPassword_thenCorrect() { - assertThat(connectionPool.getPassword()).isEqualTo("password"); - } - - @Test(expected = RuntimeException.class) - public void givenBasicConnectionPoolInstance_whenAskedForMoreThanMax_thenError() throws Exception { - // this test needs to be independent so it doesn't share the same connection pool as other tests - ConnectionPool cp = BasicConnectionPool.create("jdbc:h2:mem:test", "user", "password"); - final int MAX_POOL_SIZE = 20; - for (int i = 0; i < MAX_POOL_SIZE + 1; i++) { - cp.getConnection(); - } - fail(); - } - - @Test - public void givenBasicConnectionPoolInstance_whenSutdown_thenEmpty() throws Exception { - ConnectionPool cp = BasicConnectionPool.create("jdbc:h2:mem:test", "user", "password"); - assertThat(((BasicConnectionPool)cp).getSize()).isEqualTo(10); - - ((BasicConnectionPool) cp).shutdown(); - assertThat(((BasicConnectionPool)cp).getSize()).isEqualTo(0); - } -} diff --git a/core-java/src/test/java/com/baeldung/connectionpool/C3poDataSourceUnitTest.java b/core-java/src/test/java/com/baeldung/connectionpool/C3poDataSourceUnitTest.java deleted file mode 100644 index a02daa40f6..0000000000 --- a/core-java/src/test/java/com/baeldung/connectionpool/C3poDataSourceUnitTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.connectionpool; - -import com.baeldung.connectionpool.connectionpools.C3poDataSource; -import java.sql.SQLException; -import static org.junit.Assert.assertTrue; -import org.junit.Test; - -public class C3poDataSourceUnitTest { - - @Test - public void givenC3poDataSourceClass_whenCalledgetConnection_thenCorrect() throws SQLException { - assertTrue(C3poDataSource.getConnection().isValid(1)); - } -} \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/connectionpool/DBCPDataSourceUnitTest.java b/core-java/src/test/java/com/baeldung/connectionpool/DBCPDataSourceUnitTest.java deleted file mode 100644 index 9583eedf4b..0000000000 --- a/core-java/src/test/java/com/baeldung/connectionpool/DBCPDataSourceUnitTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.connectionpool; - -import com.baeldung.connectionpool.connectionpools.DBCPDataSource; -import java.sql.SQLException; -import static org.junit.Assert.assertTrue; -import org.junit.Test; - -public class DBCPDataSourceUnitTest { - - @Test - public void givenDBCPDataSourceClass_whenCalledgetConnection_thenCorrect() throws SQLException { - assertTrue(DBCPDataSource.getConnection().isValid(1)); - } -} \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/connectionpool/HikariCPDataSourceUnitTest.java b/core-java/src/test/java/com/baeldung/connectionpool/HikariCPDataSourceUnitTest.java deleted file mode 100644 index 6b78815797..0000000000 --- a/core-java/src/test/java/com/baeldung/connectionpool/HikariCPDataSourceUnitTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.connectionpool; - -import com.baeldung.connectionpool.connectionpools.HikariCPDataSource; -import java.sql.SQLException; -import static org.junit.Assert.assertTrue; -import org.junit.Test; - -public class HikariCPDataSourceUnitTest { - - @Test - public void givenHikariDataSourceClass_whenCalledgetConnection_thenCorrect() throws SQLException { - assertTrue(HikariCPDataSource.getConnection().isValid(1)); - } -} \ No newline at end of file diff --git a/libraries/src/main/java/com/baeldung/jmapper/User.java b/libraries/src/main/java/com/baeldung/jmapper/User.java deleted file mode 100644 index 9f99157183..0000000000 --- a/libraries/src/main/java/com/baeldung/jmapper/User.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.baeldung.jmapper; - -import java.time.LocalDate; - - -public class User { - - private long id; - private String email; - private LocalDate birthDate; - - // constructors - - public User() { - super(); - } - - public User(long id, String email, LocalDate birthDate) { - super(); - this.id = id; - this.email = email; - this.birthDate = birthDate; - } - - // getters and setters - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public LocalDate getBirthDate() { - return birthDate; - } - - public void setBirthDate(LocalDate birthDate) { - this.birthDate = birthDate; - } - - @Override - public String toString() { - return "User [id=" + id + ", email=" + email + ", birthDate=" + birthDate + "]"; - } - -} diff --git a/libraries/src/main/java/com/baeldung/jmapper/UserDto.java b/libraries/src/main/java/com/baeldung/jmapper/UserDto.java deleted file mode 100644 index 326e8f3cd5..0000000000 --- a/libraries/src/main/java/com/baeldung/jmapper/UserDto.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.baeldung.jmapper; - -import java.time.LocalDate; -import java.time.Period; - -import com.googlecode.jmapper.annotations.JMap; -import com.googlecode.jmapper.annotations.JMapConversion; - -public class UserDto { - - @JMap - private long id; - - @JMap("email") - private String username; - - @JMap("birthDate") - private int age; - - @JMapConversion(from={"birthDate"}, to={"age"}) - public int conversion(LocalDate birthDate){ - return Period.between(birthDate, LocalDate.now()).getYears(); - } - - // constructors - - public UserDto() { - super(); - } - - public UserDto(long id, String username, int age) { - super(); - this.id = id; - this.username = username; - this.age = age; - } - - // getters and setters - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - @Override - public String toString() { - return "UserDto [id=" + id + ", username=" + username + ", age=" + age + "]"; - } - -} diff --git a/libraries/src/main/java/com/baeldung/jmapper/UserDto1.java b/libraries/src/main/java/com/baeldung/jmapper/UserDto1.java deleted file mode 100644 index 99247c56f6..0000000000 --- a/libraries/src/main/java/com/baeldung/jmapper/UserDto1.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.jmapper; - -import com.googlecode.jmapper.annotations.JGlobalMap; - -@JGlobalMap -public class UserDto1 { - - private long id; - private String email; - - - // constructors - - public UserDto1() { - super(); - } - - public UserDto1(long id, String email) { - super(); - this.id = id; - this.email = email; - } - - // getters and setters - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - @Override - public String toString() { - return "UserDto [id=" + id + ", email=" + email + "]"; - } - -} diff --git a/libraries/src/main/java/com/baeldung/jmapper/relational/User.java b/libraries/src/main/java/com/baeldung/jmapper/relational/User.java deleted file mode 100644 index 1238a82684..0000000000 --- a/libraries/src/main/java/com/baeldung/jmapper/relational/User.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.jmapper.relational; - -import com.googlecode.jmapper.annotations.JMap; - - -public class User { - - @JMap(classes = {UserDto1.class, UserDto2.class}) - private long id; - - @JMap(attributes = {"username", "email"}, classes = {UserDto1.class, UserDto2.class}) - private String email; - - // constructors - - public User() { - super(); - } - - public User(long id, String email) { - super(); - this.id = id; - this.email = email; - } - - // getters and setters - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - @Override - public String toString() { - return "User [id=" + id + ", email=" + email + "]"; - } - -} diff --git a/libraries/src/main/java/com/baeldung/jmapper/relational/UserDto1.java b/libraries/src/main/java/com/baeldung/jmapper/relational/UserDto1.java deleted file mode 100644 index 375fd267a0..0000000000 --- a/libraries/src/main/java/com/baeldung/jmapper/relational/UserDto1.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.jmapper.relational; - - -public class UserDto1 { - - private long id; - private String username; - - // constructors - - public UserDto1() { - super(); - } - - public UserDto1(long id, String username) { - super(); - this.id = id; - this.username = username; - } - - // getters and setters - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - @Override - public String toString() { - return "UserDto [id=" + id + ", username=" + username + "]"; - } - -} diff --git a/libraries/src/main/java/com/baeldung/jmapper/relational/UserDto2.java b/libraries/src/main/java/com/baeldung/jmapper/relational/UserDto2.java deleted file mode 100644 index d0858c7d8e..0000000000 --- a/libraries/src/main/java/com/baeldung/jmapper/relational/UserDto2.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.jmapper.relational; - - -public class UserDto2 { - - private long id; - private String email; - - // constructors - - public UserDto2() { - super(); - } - - public UserDto2(long id, String email) { - super(); - this.id = id; - this.email = email; - } - - // getters and setters - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - @Override - public String toString() { - return "UserDto2 [id=" + id + ", email=" + email + "]"; - } - -} diff --git a/libraries/src/main/resources/user_jmapper.xml b/libraries/src/main/resources/user_jmapper.xml deleted file mode 100644 index f007de9f0a..0000000000 --- a/libraries/src/main/resources/user_jmapper.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/libraries/src/main/resources/user_jmapper1.xml b/libraries/src/main/resources/user_jmapper1.xml deleted file mode 100644 index abcfd77e1c..0000000000 --- a/libraries/src/main/resources/user_jmapper1.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/libraries/src/main/resources/user_jmapper2.xml b/libraries/src/main/resources/user_jmapper2.xml deleted file mode 100644 index 1e708e14bf..0000000000 --- a/libraries/src/main/resources/user_jmapper2.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/libraries/src/test/java/com/baeldung/jmapper/JMapperIntegrationTest.java b/libraries/src/test/java/com/baeldung/jmapper/JMapperIntegrationTest.java deleted file mode 100644 index 96ed090482..0000000000 --- a/libraries/src/test/java/com/baeldung/jmapper/JMapperIntegrationTest.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.baeldung.jmapper; - -import static com.googlecode.jmapper.api.JMapperAPI.attribute; -import static com.googlecode.jmapper.api.JMapperAPI.global; -import static com.googlecode.jmapper.api.JMapperAPI.mappedClass; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.time.LocalDate; - -import org.junit.Test; - -import com.googlecode.jmapper.JMapper; -import com.googlecode.jmapper.api.JMapperAPI; - -public class JMapperIntegrationTest { - - - @Test - public void givenUser_whenUseAnnotation_thenConverted(){ - JMapper userMapper = new JMapper<>(UserDto.class, User.class); - - User user = new User(1L,"john@test.com", LocalDate.of(1980,8,20)); - UserDto result = userMapper.getDestination(user); - - System.out.println(result); - assertEquals(user.getId(), result.getId()); - assertEquals(user.getEmail(), result.getUsername()); - } - - @Test - public void givenUser_whenUseGlobalMapAnnotation_thenConverted(){ - JMapper userMapper= new JMapper<>(UserDto1.class, User.class); - - User user = new User(1L,"john@test.com", LocalDate.of(1980,8,20)); - UserDto1 result = userMapper.getDestination(user); - - System.out.println(result); - assertEquals(user.getId(), result.getId()); - assertEquals(user.getEmail(), result.getEmail()); - } - - @Test - public void givenUser_whenUseAnnotationExplicitConversion_thenConverted(){ - JMapper userMapper = new JMapper<>(UserDto.class, User.class); - - User user = new User(1L,"john@test.com", LocalDate.of(1980,8,20)); - UserDto result = userMapper.getDestination(user); - - System.out.println(result); - assertEquals(user.getId(), result.getId()); - assertEquals(user.getEmail(), result.getUsername()); - assertTrue(result.getAge() > 0); - } - - //======================= XML - - @Test - public void givenUser_whenUseXml_thenConverted(){ - JMapper userMapper = new JMapper<>(UserDto.class, User.class,"user_jmapper.xml"); - - User user = new User(1L,"john@test.com", LocalDate.of(1980,8,20)); - UserDto result = userMapper.getDestination(user); - - System.out.println(result); - assertEquals(user.getId(), result.getId()); - assertEquals(user.getEmail(), result.getUsername()); - } - - @Test - public void givenUser_whenUseXmlGlobal_thenConverted(){ - JMapper userMapper = new JMapper<>(UserDto1.class, User.class,"user_jmapper1.xml"); - - User user = new User(1L,"john@test.com", LocalDate.of(1980,8,20)); - UserDto1 result = userMapper.getDestination(user); - - System.out.println(result); - assertEquals(user.getId(), result.getId()); - assertEquals(user.getEmail(), result.getEmail()); - } - - // ===== API - - @Test - public void givenUser_whenUseApi_thenConverted(){ - JMapperAPI jmapperApi = new JMapperAPI() .add(mappedClass(UserDto.class) - .add(attribute("id").value("id")) - .add(attribute("username").value("email")) - ) ; - JMapper userMapper = new JMapper<>(UserDto.class, User.class, jmapperApi); - - User user = new User(1L,"john@test.com", LocalDate.of(1980,8,20)); - UserDto result = userMapper.getDestination(user); - - System.out.println(result); - assertEquals(user.getId(), result.getId()); - assertEquals(user.getEmail(), result.getUsername()); - } - - @Test - public void givenUser_whenUseApiGlobal_thenConverted(){ - JMapperAPI jmapperApi = new JMapperAPI() .add(mappedClass(UserDto.class) - .add(global()) - ) ; - JMapper userMapper1 = new JMapper<>(UserDto1.class, User.class,jmapperApi); - - User user = new User(1L,"john@test.com", LocalDate.of(1980,8,20)); - UserDto1 result = userMapper1.getDestination(user); - - System.out.println(result); - assertEquals(user.getId(), result.getId()); - assertEquals(user.getEmail(), result.getEmail()); - } -} diff --git a/libraries/src/test/java/com/baeldung/jmapper/JMapperRelationalIntegrationTest.java b/libraries/src/test/java/com/baeldung/jmapper/JMapperRelationalIntegrationTest.java deleted file mode 100644 index 6af2865159..0000000000 --- a/libraries/src/test/java/com/baeldung/jmapper/JMapperRelationalIntegrationTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.baeldung.jmapper; - -import static com.googlecode.jmapper.api.JMapperAPI.attribute; -import static com.googlecode.jmapper.api.JMapperAPI.mappedClass; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.baeldung.jmapper.relational.User; -import com.baeldung.jmapper.relational.UserDto1; -import com.baeldung.jmapper.relational.UserDto2; -import com.googlecode.jmapper.RelationalJMapper; -import com.googlecode.jmapper.api.JMapperAPI; - -public class JMapperRelationalIntegrationTest { - - - @Test - public void givenUser_whenUseAnnotation_thenConverted(){ - RelationalJMapper relationalMapper = new RelationalJMapper<>(User.class); - - User user = new User(1L,"john@test.com"); - UserDto1 result1 = relationalMapper.oneToMany(UserDto1.class, user); - UserDto2 result2= relationalMapper.oneToMany(UserDto2.class, user); - - System.out.println(result1); - System.out.println(result2); - assertEquals(user.getId(), result1.getId()); - assertEquals(user.getEmail(), result1.getUsername()); - assertEquals(user.getId(), result2.getId()); - assertEquals(user.getEmail(), result2.getEmail()); - } - - //======================= XML - - @Test - public void givenUser_whenUseXml_thenConverted(){ - RelationalJMapper relationalMapper = new RelationalJMapper<>(User.class,"user_jmapper2.xml"); - - User user = new User(1L,"john@test.com"); - UserDto1 result1 = relationalMapper.oneToMany(UserDto1.class, user); - UserDto2 result2 = relationalMapper.oneToMany(UserDto2.class, user); - - System.out.println(result1); - System.out.println(result2); - assertEquals(user.getId(), result1.getId()); - assertEquals(user.getEmail(), result1.getUsername()); - assertEquals(user.getId(), result2.getId()); - assertEquals(user.getEmail(), result2.getEmail()); - } - - - // ===== API - - @Test - public void givenUser_whenUseApi_thenConverted(){ - JMapperAPI jmapperApi = new JMapperAPI() - .add(mappedClass(User.class) - .add(attribute("id").value("id").targetClasses(UserDto1.class,UserDto2.class)) - .add(attribute("email").targetAttributes("username","email").targetClasses(UserDto1.class,UserDto2.class)) ) - ; - RelationalJMapper relationalMapper = new RelationalJMapper<>(User.class,jmapperApi); - - User user = new User(1L,"john@test.com"); - UserDto1 result1 = relationalMapper.oneToMany(UserDto1.class, user); - UserDto2 result2 = relationalMapper.oneToMany(UserDto2.class, user); - - System.out.println(result1); - System.out.println(result2); - assertEquals(user.getId(), result1.getId()); - assertEquals(user.getEmail(), result1.getUsername()); - assertEquals(user.getId(), result2.getId()); - assertEquals(user.getEmail(), result2.getEmail()); - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/.gitignore b/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/.gitignore deleted file mode 100644 index 90b27cf4da..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/FooReactiveController.java diff --git a/spring-boot-persistence/src/main/java/com/baeldung/domain/Article.java b/spring-boot-persistence/src/main/java/com/baeldung/domain/Article.java deleted file mode 100644 index 3b5a8be088..0000000000 --- a/spring-boot-persistence/src/main/java/com/baeldung/domain/Article.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.domain; - -import javax.persistence.*; -import java.util.Date; - -@Entity -public class Article { - - @Id - @GeneratedValue - private Integer id; - @Temporal(TemporalType.DATE) - private Date publicationDate; - @Temporal(TemporalType.TIME) - private Date publicationTime; - @Temporal(TemporalType.TIMESTAMP) - private Date creationDateTime; - - public Integer getId() { - return id; - } - -} diff --git a/spring-boot-persistence/src/main/java/com/baeldung/repository/ArticleRepository.java b/spring-boot-persistence/src/main/java/com/baeldung/repository/ArticleRepository.java deleted file mode 100644 index 4e1b109430..0000000000 --- a/spring-boot-persistence/src/main/java/com/baeldung/repository/ArticleRepository.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.repository; - -import com.baeldung.domain.Article; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.Date; -import java.util.List; - -public interface ArticleRepository extends JpaRepository { - - List
findAllByPublicationDate(Date publicationDate); - - List
findAllByPublicationTimeBetween(Date publicationTimeStart, - Date publicationTimeEnd); - - @Query("select a from Article a where a.creationDateTime <= :creationDateTime") - List
findAllWithCreationDateTimeBefore( - @Param("creationDateTime") Date creationDateTime); - -} diff --git a/spring-boot-persistence/src/test/java/com/baeldung/repository/ArticleRepositoryIntegrationTest.java b/spring-boot-persistence/src/test/java/com/baeldung/repository/ArticleRepositoryIntegrationTest.java deleted file mode 100644 index 7d531d1461..0000000000 --- a/spring-boot-persistence/src/test/java/com/baeldung/repository/ArticleRepositoryIntegrationTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.baeldung.repository; - -import com.baeldung.domain.Article; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -@RunWith(SpringRunner.class) -@DataJpaTest -public class ArticleRepositoryIntegrationTest { - - @Autowired - private ArticleRepository repository; - - @Test - public void givenImportedArticlesWhenFindAllByPublicationDateThenArticles1And2Returned() - throws Exception { - List
result = repository.findAllByPublicationDate( - new SimpleDateFormat("yyyy-MM-dd").parse("2018-01-01") - ); - - assertEquals(2, result.size()); - assertTrue(result.stream() - .map(Article::getId) - .allMatch(id -> Arrays.asList(1, 2).contains(id)) - ); - } - - @Test - public void givenImportedArticlesWhenFindAllByPublicationTimeBetweenThenArticles2And3Returned() - throws Exception { - List
result = repository.findAllByPublicationTimeBetween( - new SimpleDateFormat("HH:mm").parse("15:15"), - new SimpleDateFormat("HH:mm").parse("16:30") - ); - - assertEquals(2, result.size()); - assertTrue(result.stream() - .map(Article::getId) - .allMatch(id -> Arrays.asList(2, 3).contains(id)) - ); - } - - @Test - public void givenImportedArticlesWhenFindAllWithCreationDateTimeBeforeThenArticles2And3Returned() throws Exception { - List
result = repository.findAllWithCreationDateTimeBefore( - new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2017-12-15 10:00") - ); - - assertEquals(2, result.size()); - assertTrue(result.stream() - .map(Article::getId) - .allMatch(id -> Arrays.asList(2, 3).contains(id)) - ); - } - -} diff --git a/spring-boot-persistence/src/test/resources/application.properties b/spring-boot-persistence/src/test/resources/application.properties index a5d09db840..a5c1d983cf 100644 --- a/spring-boot-persistence/src/test/resources/application.properties +++ b/spring-boot-persistence/src/test/resources/application.properties @@ -13,4 +13,4 @@ hibernate.cache.use_query_cache=true hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory spring.jpa.properties.hibernate.hbm2ddl.import_files=migrated_users.sql -spring.datasource.data=import_*_users.sql,import_articles.sql \ No newline at end of file +spring.datasource.data=import_*_users.sql \ No newline at end of file diff --git a/spring-boot-persistence/src/test/resources/import_articles.sql b/spring-boot-persistence/src/test/resources/import_articles.sql deleted file mode 100644 index 4fe18bf4aa..0000000000 --- a/spring-boot-persistence/src/test/resources/import_articles.sql +++ /dev/null @@ -1,3 +0,0 @@ -insert into Article(id, publication_date, publication_time, creation_date_time) values(1, TO_DATE('01/01/2018', 'DD/MM/YYYY'), TO_DATE('15:00', 'HH24:MI'), TO_DATE('31/12/2017 07:30', 'DD/MM/YYYY HH24:MI')); -insert into Article(id, publication_date, publication_time, creation_date_time) values(2, TO_DATE('01/01/2018', 'DD/MM/YYYY'), TO_DATE('15:30', 'HH24:MI'), TO_DATE('15/12/2017 08:00', 'DD/MM/YYYY HH24:MI')); -insert into Article(id, publication_date, publication_time, creation_date_time) values(3, TO_DATE('15/12/2017', 'DD/MM/YYYY'), TO_DATE('16:00', 'HH24:MI'), TO_DATE('01/12/2017 13:45', 'DD/MM/YYYY HH24:MI')); \ No newline at end of file