diff --git a/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceBase.java b/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceBase.java index e884c576c1..ec66621928 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceBase.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceBase.java @@ -1,22 +1,15 @@ package com.baeldung.algorithms.editdistance; +import java.util.Arrays; + public class EditDistanceBase { - public static int costOfSubstitution(char a, char b) { - if (a == b) { - return 0; - } - return 1; + static int costOfSubstitution(char a, char b) { + return a == b ? 0 : 1; } - public static int min(int... numbers) { - int min = Integer.MAX_VALUE; - - for (int x : numbers) { - if (x < min) - min = x; - } - - return min; + static int min(int... numbers) { + return Arrays.stream(numbers) + .min().orElse(Integer.MAX_VALUE); } } diff --git a/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceDynamicProgramming.java b/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceDynamicProgramming.java index 163714002b..1f8824c4f4 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceDynamicProgramming.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceDynamicProgramming.java @@ -2,7 +2,7 @@ package com.baeldung.algorithms.editdistance; public class EditDistanceDynamicProgramming extends EditDistanceBase { - public static int calculate(String x, String y) { + static int calculate(String x, String y) { int[][] dp = new int[x.length() + 1][y.length() + 1]; for (int i = 0; i <= x.length(); i++) { @@ -14,12 +14,13 @@ public class EditDistanceDynamicProgramming extends EditDistanceBase { dp[i][j] = i; else { - dp[i][j] = min(dp[i - 1][j - 1] + costOfSubstitution(x.charAt(i - 1), y.charAt(j - 1)), dp[i - 1][j] + 1, dp[i][j - 1] + 1); + dp[i][j] = min(dp[i - 1][j - 1] + + costOfSubstitution(x.charAt(i - 1), y.charAt(j - 1)), + dp[i - 1][j] + 1, dp[i][j - 1] + 1); } } } return dp[x.length()][y.length()]; } - } diff --git a/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceRecursive.java b/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceRecursive.java index 68e470147e..8ed48dc554 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceRecursive.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/editdistance/EditDistanceRecursive.java @@ -2,13 +2,15 @@ package com.baeldung.algorithms.editdistance; public class EditDistanceRecursive extends EditDistanceBase { - public static int calculate(String x, String y) { + static int calculate(String x, String y) { - if (x.isEmpty()) + if (x.isEmpty()) { return y.length(); + } - if (y.isEmpty()) + if (y.isEmpty()) { return x.length(); + } int substitution = calculate(x.substring(1), y.substring(1)) + costOfSubstitution(x.charAt(0), y.charAt(0)); int insertion = calculate(x, y.substring(1)) + 1; @@ -16,5 +18,4 @@ public class EditDistanceRecursive extends EditDistanceBase { return min(substitution, insertion, deletion); } - } diff --git a/algorithms/src/test/java/com/baeldung/algorithms/editdistance/EditDistanceTest.java b/algorithms/src/test/java/com/baeldung/algorithms/editdistance/EditDistanceTest.java index 1594f73a73..bab2f480a5 100644 --- a/algorithms/src/test/java/com/baeldung/algorithms/editdistance/EditDistanceTest.java +++ b/algorithms/src/test/java/com/baeldung/algorithms/editdistance/EditDistanceTest.java @@ -1,16 +1,17 @@ package com.baeldung.algorithms.editdistance; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import static org.junit.Assert.assertEquals; + @RunWith(Parameterized.class) public class EditDistanceTest extends EditDistanceDataProvider { - String x; - String y; - int result; + private String x; + private String y; + private int result; public EditDistanceTest(String a, String b, int res) { super(); @@ -21,11 +22,11 @@ public class EditDistanceTest extends EditDistanceDataProvider { @Test public void testEditDistance_RecursiveImplementation() { - Assert.assertEquals(result, EditDistanceRecursive.calculate(x, y)); + assertEquals(result, EditDistanceRecursive.calculate(x, y)); } @Test public void testEditDistance_givenDynamicProgrammingImplementation() { - Assert.assertEquals(result, EditDistanceDynamicProgramming.calculate(x, y)); + assertEquals(result, EditDistanceDynamicProgramming.calculate(x, y)); } } diff --git a/cas-secured-app/pom.xml b/cas-secured-app/pom.xml index f66d54ae67..0548e0c315 100644 --- a/cas-secured-app/pom.xml +++ b/cas-secured-app/pom.xml @@ -106,5 +106,75 @@ + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + **/AutoconfigurationTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + + autoconfiguration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + **/*IntegrationTest.java + + + **/AutoconfigurationTest.java + + + + + + + json + + + + + + + + + diff --git a/cas-secured-app/src/test/java/com/baeldung/cassecuredapp/CasSecuredAppApplicationTests.java b/cas-secured-app/src/test/java/com/baeldung/cassecuredapp/CasSecuredAppApplicationIntegrationTest.java similarity index 84% rename from cas-secured-app/src/test/java/com/baeldung/cassecuredapp/CasSecuredAppApplicationTests.java rename to cas-secured-app/src/test/java/com/baeldung/cassecuredapp/CasSecuredAppApplicationIntegrationTest.java index 09dbaf0c61..2f2644e2ea 100644 --- a/cas-secured-app/src/test/java/com/baeldung/cassecuredapp/CasSecuredAppApplicationTests.java +++ b/cas-secured-app/src/test/java/com/baeldung/cassecuredapp/CasSecuredAppApplicationIntegrationTest.java @@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest -public class CasSecuredAppApplicationTests { +public class CasSecuredAppApplicationIntegrationTest { @Test public void contextLoads() { diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/runnable/RunnableVsThreadTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/runnable/RunnableVsThreadTest.java new file mode 100644 index 0000000000..d0f4460f51 --- /dev/null +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/runnable/RunnableVsThreadTest.java @@ -0,0 +1,110 @@ +package com.baeldung.concurrent.runnable; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.apache.commons.lang3.RandomUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RunnableVsThreadTest { + + private static Logger log = + LoggerFactory.getLogger(RunnableVsThreadTest.class); + + @Test + public void givenARunnable_whenRunIt_thenResult() throws Exception{ + Thread thread = new Thread(new SimpleRunnable( + "SimpleRunnable executed using Thread")); + thread.start(); + thread.join(); + + ExecutorService executorService = + Executors.newCachedThreadPool(); + + executorService.submit(new SimpleRunnable( + "SimpleRunnable executed using ExecutorService")).get(); + + executorService.submit(()-> + log.info("Lambda runnable executed!!!")).get(); + executorService.shutdown(); + } + + @Test + public void givenAThread_whenRunIt_thenResult() throws Exception{ + Thread thread = new SimpleThread( + "SimpleThread executed using Thread"); + thread.start(); + thread.join(); + + ExecutorService executorService = + Executors.newCachedThreadPool(); + executorService.submit(new SimpleThread( + "SimpleThread executed using ExecutorService")).get(); + } + + @Test + public void givenACallable_whenRunIt_thenResult() throws Exception { + ExecutorService executorService = + Executors.newCachedThreadPool(); + + Future future = executorService.submit(new SimpleCallable()); + log.info("Result from callable: {}", future.get()); + + future = executorService.submit(() -> { + return RandomUtils.nextInt(0, 100); + }); + log.info("Result from callable: {}", future.get()); + + } +} + +class SimpleThread extends Thread{ + + private static final Logger log = + LoggerFactory.getLogger(SimpleThread.class); + + private String message; + + public SimpleThread(String message) { + this.message = message; + } + + @Override + public void run() { + log.info(message); + } +} + +class SimpleRunnable implements Runnable { + + private static final Logger log = + LoggerFactory.getLogger(SimpleRunnable.class); + + private String message; + + public SimpleRunnable(String message) { + this.message = message; + } + + + @Override + public void run() { + log.info(message); + } +} + +class SimpleCallable implements Callable { + + @Override + public Integer call() throws Exception { + return RandomUtils.nextInt(0, 100); + } + +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/CalculatorTest5.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/CalculatorTest5.kt index dd35805044..40cd9adc99 100644 --- a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/CalculatorTest5.kt +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/CalculatorTest5.kt @@ -7,12 +7,12 @@ class CalculatorTest5 { private val calculator = Calculator() @Test - fun testAddition() { + fun whenAdding1and3_thenAnswerIs4() { Assertions.assertEquals(4, calculator.add(1, 3)) } @Test - fun testDivideByZero() { + fun whenDividingBy0_thenErrorOccurs() { val exception = Assertions.assertThrows(DivideByZeroException::class.java) { calculator.divide(5, 0) } @@ -21,7 +21,7 @@ class CalculatorTest5 { } @Test - fun testSquares() { + fun whenSquaringNumbers_thenCorrectAnswerGiven() { Assertions.assertAll( Executable { Assertions.assertEquals(1, calculator.square(1)) }, Executable { Assertions.assertEquals(4, calculator.square(2)) }, @@ -31,9 +31,9 @@ class CalculatorTest5 { @TestFactory fun testSquaresFactory() = listOf( - DynamicTest.dynamicTest("1 squared") { Assertions.assertEquals(1,calculator.square(1))}, - DynamicTest.dynamicTest("2 squared") { Assertions.assertEquals(4,calculator.square(2))}, - DynamicTest.dynamicTest("3 squared") { Assertions.assertEquals(9,calculator.square(3))} + DynamicTest.dynamicTest("when I calculate 1^2 then I get 1") { Assertions.assertEquals(1,calculator.square(1))}, + DynamicTest.dynamicTest("when I calculate 2^2 then I get 4") { Assertions.assertEquals(4,calculator.square(2))}, + DynamicTest.dynamicTest("when I calculate 3^2 then I get 9") { Assertions.assertEquals(9,calculator.square(3))} ) @TestFactory @@ -44,7 +44,7 @@ class CalculatorTest5 { 4 to 16, 5 to 25) .map { (input, expected) -> - DynamicTest.dynamicTest("$input squared") { + DynamicTest.dynamicTest("when I calculate $input^2 then I get $expected") { Assertions.assertEquals(expected, calculator.square(input)) } } @@ -59,14 +59,14 @@ class CalculatorTest5 { @TestFactory fun testSquaresFactory3() = squaresTestData .map { (input, expected) -> - DynamicTest.dynamicTest("$input squared") { + DynamicTest.dynamicTest("when I calculate $input^2 then I get $expected") { Assertions.assertEquals(expected, calculator.square(input)) } } @TestFactory fun testSquareRootsFactory3() = squaresTestData .map { (expected, input) -> - DynamicTest.dynamicTest("Square root of $input") { + DynamicTest.dynamicTest("I calculate the square root of $input then I get $expected") { Assertions.assertEquals(expected.toDouble(), calculator.squareRoot(input)) } } @@ -76,7 +76,7 @@ class CalculatorTest5 { Tag("logarithms") ) @Test - fun testLogarithms() { + fun whenIcalculateLog2Of8_thenIget3() { Assertions.assertEquals(3.0, calculator.log(2, 8)) } } diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/SimpleTest5.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/SimpleTest5.kt index c04ab568f7..70d3fb90bf 100644 --- a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/SimpleTest5.kt +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/junit5/SimpleTest5.kt @@ -6,14 +6,14 @@ import org.junit.jupiter.api.Test class SimpleTest5 { @Test - fun testEmpty() { + fun whenEmptyList_thenListIsEmpty() { val list = listOf() Assertions.assertTrue(list::isEmpty) } @Test @Disabled - fun testMessage() { + fun when3equals4_thenTestFails() { Assertions.assertEquals(3, 4) { "Three does not equal four" } diff --git a/jackson/README.md b/jackson/README.md index a710a1689e..a05c95de94 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -35,3 +35,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array) - [Jackson – Change Name of Field](http://www.baeldung.com/jackson-name-of-property) - [Serialize Only Fields that meet a Custom Criteria with Jackson](http://www.baeldung.com/jackson-serialize-field-custom-criteria) +- [Mapping Nested Values with Jackson](http://www.baeldung.com/jackson-nested-values) diff --git a/libraries-data/src/test/java/com/baeldung/ormlite/ORMLiteTest.java b/libraries-data/src/test/java/com/baeldung/ormlite/ORMLiteIntegrationTest.java similarity index 99% rename from libraries-data/src/test/java/com/baeldung/ormlite/ORMLiteTest.java rename to libraries-data/src/test/java/com/baeldung/ormlite/ORMLiteIntegrationTest.java index 26eb481286..5a713902b4 100644 --- a/libraries-data/src/test/java/com/baeldung/ormlite/ORMLiteTest.java +++ b/libraries-data/src/test/java/com/baeldung/ormlite/ORMLiteIntegrationTest.java @@ -16,7 +16,7 @@ import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.jdbc.JdbcPooledConnectionSource; import com.j256.ormlite.table.TableUtils; -public class ORMLiteTest { +public class ORMLiteIntegrationTest { private static JdbcPooledConnectionSource connectionSource; private static Dao libraryDao; diff --git a/libraries-data/src/test/java/com/baeldung/reladomo/ReladomoTest.java b/libraries-data/src/test/java/com/baeldung/reladomo/ReladomoIntegrationTest.java similarity index 96% rename from libraries-data/src/test/java/com/baeldung/reladomo/ReladomoTest.java rename to libraries-data/src/test/java/com/baeldung/reladomo/ReladomoIntegrationTest.java index 61c29e8aa3..3660d9a8e1 100644 --- a/libraries-data/src/test/java/com/baeldung/reladomo/ReladomoTest.java +++ b/libraries-data/src/test/java/com/baeldung/reladomo/ReladomoIntegrationTest.java @@ -9,7 +9,7 @@ import org.junit.Test; import com.gs.fw.common.mithra.test.ConnectionManagerForTests; import com.gs.fw.common.mithra.test.MithraTestResource; -public class ReladomoTest { +public class ReladomoIntegrationTest { private MithraTestResource mithraTestResource; @Before diff --git a/libraries/src/test/java/com/baeldung/awaitility/AsyncServiceLongRunningUnitTest.java b/libraries/src/test/java/com/baeldung/awaitility/AsyncServiceLongRunningUnitTest.java index d17a7dcf1b..7ca656efbf 100644 --- a/libraries/src/test/java/com/baeldung/awaitility/AsyncServiceLongRunningUnitTest.java +++ b/libraries/src/test/java/com/baeldung/awaitility/AsyncServiceLongRunningUnitTest.java @@ -1,6 +1,5 @@ package com.baeldung.awaitility; -import org.awaitility.Awaitility; import org.awaitility.Duration; import org.junit.Before; import org.junit.Test; diff --git a/pom.xml b/pom.xml index 3d28707b5f..4f10c31ae3 100644 --- a/pom.xml +++ b/pom.xml @@ -192,6 +192,8 @@ spring-quartz spring-rest-angular spring-rest-docs + spring-rest-full + spring-rest-query-language spring-rest spring-rest-simple spring-security-cache-control @@ -213,7 +215,6 @@ spring-security-mvc-socket spring-security-rest-basic-auth spring-security-rest-custom - spring-security-rest-full spring-security-rest spring-security-sso spring-security-x509 diff --git a/spring-security-rest-full/.gitignore b/spring-rest-full/.gitignore similarity index 100% rename from spring-security-rest-full/.gitignore rename to spring-rest-full/.gitignore diff --git a/spring-security-rest-full/README.md b/spring-rest-full/README.md similarity index 65% rename from spring-security-rest-full/README.md rename to spring-rest-full/README.md index 2737bd5465..a1fea806ef 100644 --- a/spring-security-rest-full/README.md +++ b/spring-rest-full/README.md @@ -1,6 +1,6 @@ ========= -## REST Example Project with Spring Security +## REST Example Project with Spring ### Courses The "REST With Spring" Classes: http://bit.ly/restwithspring @@ -15,15 +15,9 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com - [Integration Testing with the Maven Cargo plugin](http://www.baeldung.com/2011/10/16/how-to-set-up-integration-testing-with-the-maven-cargo-plugin/) - [Introduction to Spring Data JPA](http://www.baeldung.com/2011/12/22/the-persistence-layer-with-spring-data-jpa/) - [Project Configuration with Spring](http://www.baeldung.com/2012/03/12/project-configuration-with-spring/) -- [REST Query Language with Spring and JPA Criteria](http://www.baeldung.com/rest-search-language-spring-jpa-criteria) -- [REST Query Language with Spring Data JPA Specifications](http://www.baeldung.com/rest-api-search-language-spring-data-specifications) -- [REST Query Language with Spring Data JPA and QueryDSL](http://www.baeldung.com/rest-api-search-language-spring-data-querydsl) -- [REST Query Language – Advanced Search Operations](http://www.baeldung.com/rest-api-query-search-language-more-operations) - [Metrics for your Spring REST API](http://www.baeldung.com/spring-rest-api-metrics) -- [REST Query Language with RSQL](http://www.baeldung.com/rest-api-search-language-rsql-fiql) - [Spring RestTemplate Tutorial](http://www.baeldung.com/rest-template) - [Bootstrap a Web Application with Spring 4](http://www.baeldung.com/bootstraping-a-web-application-with-spring-and-java-based-configuration) -- [REST Query Language – Implementing OR Operation](http://www.baeldung.com/rest-api-query-search-or-operation) @@ -46,5 +40,5 @@ mysql -u root -p ### Use the REST Service ``` -curl http://localhost:8080/spring-security-rest-full/foos +curl http://localhost:8080/spring-rest-full/foos ``` diff --git a/spring-rest-full/pom.xml b/spring-rest-full/pom.xml new file mode 100644 index 0000000000..c596e79b31 --- /dev/null +++ b/spring-rest-full/pom.xml @@ -0,0 +1,378 @@ + + 4.0.0 + com.baeldung + spring-rest-full + 0.1-SNAPSHOT + + spring-rest-full + war + + + parent-boot-4 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-4 + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.aspectj + aspectjweaver + + + + org.apache.tomcat.embed + tomcat-embed-jasper + provided + + + + + + org.springframework + spring-core + + + commons-logging + commons-logging + + + + + org.springframework + spring-context + + + org.springframework + spring-jdbc + + + org.springframework + spring-beans + + + org.springframework + spring-aop + + + org.springframework + spring-tx + + + org.springframework + spring-expression + + + + org.springframework + spring-web + + + org.springframework + spring-webmvc + + + + org.springframework.data + spring-data-commons + + + + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + + + + org.apache.httpcomponents + httpclient + + + commons-logging + commons-logging + + + + + org.apache.httpcomponents + httpcore + + + + + + org.springframework + spring-orm + + + org.springframework.data + spring-data-jpa + + + org.hibernate + hibernate-entitymanager + + + xml-apis + xml-apis + + + org.javassist + javassist + + + mysql + mysql-connector-java + runtime + + + + com.h2database + h2 + + + + + + javax.servlet + javax.servlet-api + provided + + + + javax.servlet + jstl + runtime + + + + + + com.fasterxml.jackson.core + jackson-databind + + + + com.thoughtworks.xstream + xstream + ${xstream.version} + + + + + + com.google.guava + guava + ${guava.version} + + + + + + org.springframework + spring-test + test + + + + + + + + + + org.hamcrest + hamcrest-library + test + + + + org.mockito + mockito-core + test + + + + + + spring-rest-full + + + src/main/resources + true + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + org.codehaus.cargo + cargo-maven2-plugin + ${cargo-maven2-plugin.version} + + true + + jetty8x + embedded + + + + + + + 8082 + + + + + + + + + com.mysema.maven + apt-maven-plugin + ${apt-maven-plugin.version} + + + + process + + + target/generated-sources/java + com.querydsl.apt.jpa.JPAAnnotationProcessor + + + + + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*IntegrationTest.java + + + **/*LiveTest.java + + + + + + + json + + + + + org.codehaus.cargo + cargo-maven2-plugin + + false + + + + start-server + pre-integration-test + + start + + + + stop-server + post-integration-test + + stop + + + + + + + + + + + + + 1.4.9 + + + 19.0 + 3.5 + + + 1.6.1 + 1.1.3 + + + \ No newline at end of file diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/IOperations.java b/spring-rest-full/src/main/java/org/baeldung/persistence/IOperations.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/IOperations.java rename to spring-rest-full/src/main/java/org/baeldung/persistence/IOperations.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/IFooDao.java b/spring-rest-full/src/main/java/org/baeldung/persistence/dao/IFooDao.java similarity index 69% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/IFooDao.java rename to spring-rest-full/src/main/java/org/baeldung/persistence/dao/IFooDao.java index 824d6ea546..230abd0d5f 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/IFooDao.java +++ b/spring-rest-full/src/main/java/org/baeldung/persistence/dao/IFooDao.java @@ -2,13 +2,10 @@ package org.baeldung.persistence.dao; import org.baeldung.persistence.model.Foo; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; - -public interface IFooDao extends JpaRepository, JpaSpecificationExecutor { +public interface IFooDao extends JpaRepository { @Query("SELECT f FROM Foo f WHERE LOWER(f.name) = LOWER(:name)") Foo retrieveByName(@Param("name") String name); - } diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/model/Foo.java b/spring-rest-full/src/main/java/org/baeldung/persistence/model/Foo.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/model/Foo.java rename to spring-rest-full/src/main/java/org/baeldung/persistence/model/Foo.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/model/User.java b/spring-rest-full/src/main/java/org/baeldung/persistence/model/User.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/model/User.java rename to spring-rest-full/src/main/java/org/baeldung/persistence/model/User.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/service/IFooService.java b/spring-rest-full/src/main/java/org/baeldung/persistence/service/IFooService.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/service/IFooService.java rename to spring-rest-full/src/main/java/org/baeldung/persistence/service/IFooService.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/service/common/AbstractService.java b/spring-rest-full/src/main/java/org/baeldung/persistence/service/common/AbstractService.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/service/common/AbstractService.java rename to spring-rest-full/src/main/java/org/baeldung/persistence/service/common/AbstractService.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/service/impl/FooService.java b/spring-rest-full/src/main/java/org/baeldung/persistence/service/impl/FooService.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/service/impl/FooService.java rename to spring-rest-full/src/main/java/org/baeldung/persistence/service/impl/FooService.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/spring/Application.java b/spring-rest-full/src/main/java/org/baeldung/spring/Application.java similarity index 98% rename from spring-security-rest-full/src/main/java/org/baeldung/spring/Application.java rename to spring-rest-full/src/main/java/org/baeldung/spring/Application.java index a43b21c2b7..9a3f473b8b 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/spring/Application.java +++ b/spring-rest-full/src/main/java/org/baeldung/spring/Application.java @@ -16,7 +16,7 @@ import org.springframework.web.filter.ShallowEtagHeaderFilter; /** * Main Application Class - uses Spring Boot. Just run this as a normal Java - * class to run up a Jetty Server (on http://localhost:8082/spring-security-rest-full) + * class to run up a Jetty Server (on http://localhost:8082/spring-rest-full) * */ @EnableScheduling diff --git a/spring-security-rest-full/src/main/java/org/baeldung/spring/PersistenceConfig.java b/spring-rest-full/src/main/java/org/baeldung/spring/PersistenceConfig.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/spring/PersistenceConfig.java rename to spring-rest-full/src/main/java/org/baeldung/spring/PersistenceConfig.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/spring/WebConfig.java b/spring-rest-full/src/main/java/org/baeldung/spring/WebConfig.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/spring/WebConfig.java rename to spring-rest-full/src/main/java/org/baeldung/spring/WebConfig.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/FooController.java b/spring-rest-full/src/main/java/org/baeldung/web/controller/FooController.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/controller/FooController.java rename to spring-rest-full/src/main/java/org/baeldung/web/controller/FooController.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/HomeController.java b/spring-rest-full/src/main/java/org/baeldung/web/controller/HomeController.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/controller/HomeController.java rename to spring-rest-full/src/main/java/org/baeldung/web/controller/HomeController.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/RootController.java b/spring-rest-full/src/main/java/org/baeldung/web/controller/RootController.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/controller/RootController.java rename to spring-rest-full/src/main/java/org/baeldung/web/controller/RootController.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/error/RestResponseEntityExceptionHandler.java b/spring-rest-full/src/main/java/org/baeldung/web/error/RestResponseEntityExceptionHandler.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/error/RestResponseEntityExceptionHandler.java rename to spring-rest-full/src/main/java/org/baeldung/web/error/RestResponseEntityExceptionHandler.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java b/spring-rest-full/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java rename to spring-rest-full/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/event/PaginatedResultsRetrievedEvent.java b/spring-rest-full/src/main/java/org/baeldung/web/hateoas/event/PaginatedResultsRetrievedEvent.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/event/PaginatedResultsRetrievedEvent.java rename to spring-rest-full/src/main/java/org/baeldung/web/hateoas/event/PaginatedResultsRetrievedEvent.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/event/ResourceCreatedEvent.java b/spring-rest-full/src/main/java/org/baeldung/web/hateoas/event/ResourceCreatedEvent.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/event/ResourceCreatedEvent.java rename to spring-rest-full/src/main/java/org/baeldung/web/hateoas/event/ResourceCreatedEvent.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/event/SingleResourceRetrievedEvent.java b/spring-rest-full/src/main/java/org/baeldung/web/hateoas/event/SingleResourceRetrievedEvent.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/event/SingleResourceRetrievedEvent.java rename to spring-rest-full/src/main/java/org/baeldung/web/hateoas/event/SingleResourceRetrievedEvent.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/listener/PaginatedResultsRetrievedDiscoverabilityListener.java b/spring-rest-full/src/main/java/org/baeldung/web/hateoas/listener/PaginatedResultsRetrievedDiscoverabilityListener.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/listener/PaginatedResultsRetrievedDiscoverabilityListener.java rename to spring-rest-full/src/main/java/org/baeldung/web/hateoas/listener/PaginatedResultsRetrievedDiscoverabilityListener.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/listener/ResourceCreatedDiscoverabilityListener.java b/spring-rest-full/src/main/java/org/baeldung/web/hateoas/listener/ResourceCreatedDiscoverabilityListener.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/listener/ResourceCreatedDiscoverabilityListener.java rename to spring-rest-full/src/main/java/org/baeldung/web/hateoas/listener/ResourceCreatedDiscoverabilityListener.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/listener/SingleResourceRetrievedDiscoverabilityListener.java b/spring-rest-full/src/main/java/org/baeldung/web/hateoas/listener/SingleResourceRetrievedDiscoverabilityListener.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/listener/SingleResourceRetrievedDiscoverabilityListener.java rename to spring-rest-full/src/main/java/org/baeldung/web/hateoas/listener/SingleResourceRetrievedDiscoverabilityListener.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/metric/ActuatorMetricService.java b/spring-rest-full/src/main/java/org/baeldung/web/metric/ActuatorMetricService.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/metric/ActuatorMetricService.java rename to spring-rest-full/src/main/java/org/baeldung/web/metric/ActuatorMetricService.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/metric/CustomActuatorMetricService.java b/spring-rest-full/src/main/java/org/baeldung/web/metric/CustomActuatorMetricService.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/metric/CustomActuatorMetricService.java rename to spring-rest-full/src/main/java/org/baeldung/web/metric/CustomActuatorMetricService.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/metric/IActuatorMetricService.java b/spring-rest-full/src/main/java/org/baeldung/web/metric/IActuatorMetricService.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/metric/IActuatorMetricService.java rename to spring-rest-full/src/main/java/org/baeldung/web/metric/IActuatorMetricService.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/metric/ICustomActuatorMetricService.java b/spring-rest-full/src/main/java/org/baeldung/web/metric/ICustomActuatorMetricService.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/metric/ICustomActuatorMetricService.java rename to spring-rest-full/src/main/java/org/baeldung/web/metric/ICustomActuatorMetricService.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/metric/IMetricService.java b/spring-rest-full/src/main/java/org/baeldung/web/metric/IMetricService.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/metric/IMetricService.java rename to spring-rest-full/src/main/java/org/baeldung/web/metric/IMetricService.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/metric/MetricFilter.java b/spring-rest-full/src/main/java/org/baeldung/web/metric/MetricFilter.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/metric/MetricFilter.java rename to spring-rest-full/src/main/java/org/baeldung/web/metric/MetricFilter.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/metric/MetricService.java b/spring-rest-full/src/main/java/org/baeldung/web/metric/MetricService.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/metric/MetricService.java rename to spring-rest-full/src/main/java/org/baeldung/web/metric/MetricService.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/util/LinkUtil.java b/spring-rest-full/src/main/java/org/baeldung/web/util/LinkUtil.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/util/LinkUtil.java rename to spring-rest-full/src/main/java/org/baeldung/web/util/LinkUtil.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/util/RestPreconditions.java b/spring-rest-full/src/main/java/org/baeldung/web/util/RestPreconditions.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/util/RestPreconditions.java rename to spring-rest-full/src/main/java/org/baeldung/web/util/RestPreconditions.java diff --git a/spring-security-rest-full/src/main/resources/application.properties b/spring-rest-full/src/main/resources/application.properties similarity index 50% rename from spring-security-rest-full/src/main/resources/application.properties rename to spring-rest-full/src/main/resources/application.properties index c3e1f0b4bb..6c7461f12c 100644 --- a/spring-security-rest-full/src/main/resources/application.properties +++ b/spring-rest-full/src/main/resources/application.properties @@ -1,3 +1,3 @@ server.port=8082 -server.context-path=/spring-security-rest-full +server.context-path=/spring-rest-full endpoints.metrics.enabled=true \ No newline at end of file diff --git a/spring-security-rest-full/src/main/resources/logback.xml b/spring-rest-full/src/main/resources/logback.xml similarity index 100% rename from spring-security-rest-full/src/main/resources/logback.xml rename to spring-rest-full/src/main/resources/logback.xml diff --git a/spring-security-rest-full/src/main/resources/persistence-h2.properties b/spring-rest-full/src/main/resources/persistence-h2.properties similarity index 100% rename from spring-security-rest-full/src/main/resources/persistence-h2.properties rename to spring-rest-full/src/main/resources/persistence-h2.properties diff --git a/spring-security-rest-full/src/main/resources/persistence-mysql.properties b/spring-rest-full/src/main/resources/persistence-mysql.properties similarity index 100% rename from spring-security-rest-full/src/main/resources/persistence-mysql.properties rename to spring-rest-full/src/main/resources/persistence-mysql.properties diff --git a/spring-security-rest-full/src/main/resources/springDataPersistenceConfig.xml b/spring-rest-full/src/main/resources/springDataPersistenceConfig.xml similarity index 100% rename from spring-security-rest-full/src/main/resources/springDataPersistenceConfig.xml rename to spring-rest-full/src/main/resources/springDataPersistenceConfig.xml diff --git a/spring-security-rest-full/src/main/webapp/WEB-INF/api-servlet.xml b/spring-rest-full/src/main/webapp/WEB-INF/api-servlet.xml similarity index 100% rename from spring-security-rest-full/src/main/webapp/WEB-INF/api-servlet.xml rename to spring-rest-full/src/main/webapp/WEB-INF/api-servlet.xml diff --git a/spring-security-rest-full/src/main/webapp/WEB-INF/view/graph.jsp b/spring-rest-full/src/main/webapp/WEB-INF/view/graph.jsp similarity index 100% rename from spring-security-rest-full/src/main/webapp/WEB-INF/view/graph.jsp rename to spring-rest-full/src/main/webapp/WEB-INF/view/graph.jsp diff --git a/spring-security-rest-full/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-rest-full/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-security-rest-full/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-rest-full/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-security-rest-full/src/main/webapp/WEB-INF/web.xml b/spring-rest-full/src/main/webapp/WEB-INF/web.xml similarity index 82% rename from spring-security-rest-full/src/main/webapp/WEB-INF/web.xml rename to spring-rest-full/src/main/webapp/WEB-INF/web.xml index 49e4d1afa1..85bc72469e 100644 --- a/spring-security-rest-full/src/main/webapp/WEB-INF/web.xml +++ b/spring-rest-full/src/main/webapp/WEB-INF/web.xml @@ -5,7 +5,7 @@ http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0" > - Spring Security REST Application + Spring REST Application @@ -43,16 +43,6 @@ / - - - springSecurityFilterChain - org.springframework.web.filter.DelegatingFilterProxy - - - springSecurityFilterChain - /* - - metricFilter diff --git a/spring-security-rest-full/src/test/java/org/baeldung/Consts.java b/spring-rest-full/src/test/java/org/baeldung/Consts.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/Consts.java rename to spring-rest-full/src/test/java/org/baeldung/Consts.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/TestSuite.java b/spring-rest-full/src/test/java/org/baeldung/TestSuite.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/TestSuite.java rename to spring-rest-full/src/test/java/org/baeldung/TestSuite.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractBasicLiveTest.java b/spring-rest-full/src/test/java/org/baeldung/common/web/AbstractBasicLiveTest.java similarity index 73% rename from spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractBasicLiveTest.java rename to spring-rest-full/src/test/java/org/baeldung/common/web/AbstractBasicLiveTest.java index 2cc0aa7b28..4e0007d036 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractBasicLiveTest.java +++ b/spring-rest-full/src/test/java/org/baeldung/common/web/AbstractBasicLiveTest.java @@ -10,6 +10,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import io.restassured.RestAssured; +import io.restassured.response.Response; import java.io.Serializable; import java.util.List; @@ -18,7 +20,6 @@ import org.junit.Ignore; import org.junit.Test; import com.google.common.net.HttpHeaders; -import io.restassured.response.Response; public abstract class AbstractBasicLiveTest extends AbstractLiveTest { @@ -34,7 +35,9 @@ public abstract class AbstractBasicLiveTest extends Abst final String uriOfResource = createAsUri(); // When - final Response findOneResponse = givenAuth().header("Accept", "application/json").get(uriOfResource); + final Response findOneResponse = RestAssured.given() + .header("Accept", "application/json") + .get(uriOfResource); // Then assertNotNull(findOneResponse.getHeader(HttpHeaders.ETAG)); @@ -44,11 +47,16 @@ public abstract class AbstractBasicLiveTest extends Abst public void givenResourceWasRetrieved_whenRetrievingAgainWithEtag_thenNotModifiedReturned() { // Given final String uriOfResource = createAsUri(); - final Response findOneResponse = givenAuth().header("Accept", "application/json").get(uriOfResource); + final Response findOneResponse = RestAssured.given() + .header("Accept", "application/json") + .get(uriOfResource); final String etagValue = findOneResponse.getHeader(HttpHeaders.ETAG); // When - final Response secondFindOneResponse = givenAuth().header("Accept", "application/json").headers("If-None-Match", etagValue).get(uriOfResource); + final Response secondFindOneResponse = RestAssured.given() + .header("Accept", "application/json") + .headers("If-None-Match", etagValue) + .get(uriOfResource); // Then assertTrue(secondFindOneResponse.getStatusCode() == 304); @@ -59,14 +67,19 @@ public abstract class AbstractBasicLiveTest extends Abst public void givenResourceWasRetrievedThenModified_whenRetrievingAgainWithEtag_thenResourceIsReturned() { // Given final String uriOfResource = createAsUri(); - final Response findOneResponse = givenAuth().header("Accept", "application/json").get(uriOfResource); + final Response findOneResponse = RestAssured.given() + .header("Accept", "application/json") + .get(uriOfResource); final String etagValue = findOneResponse.getHeader(HttpHeaders.ETAG); // existingResource.setName(randomAlphabetic(6)); // getApi().update(existingResource.setName("randomString")); // When - final Response secondFindOneResponse = givenAuth().header("Accept", "application/json").headers("If-None-Match", etagValue).get(uriOfResource); + final Response secondFindOneResponse = RestAssured.given() + .header("Accept", "application/json") + .headers("If-None-Match", etagValue) + .get(uriOfResource); // Then assertTrue(secondFindOneResponse.getStatusCode() == 200); @@ -79,7 +92,10 @@ public abstract class AbstractBasicLiveTest extends Abst final String uriOfResource = createAsUri(); // When - final Response findOneResponse = givenAuth().header("Accept", "application/json").headers("If-Match", randomAlphabetic(8)).get(uriOfResource); + final Response findOneResponse = RestAssured.given() + .header("Accept", "application/json") + .headers("If-Match", randomAlphabetic(8)) + .get(uriOfResource); // Then assertTrue(findOneResponse.getStatusCode() == 412); @@ -93,7 +109,7 @@ public abstract class AbstractBasicLiveTest extends Abst @Test public void whenResourcesAreRetrievedPaged_then200IsReceived() { - final Response response = givenAuth().get(getURL() + "?page=0&size=10"); + final Response response = RestAssured.get(getURL() + "?page=0&size=10"); assertThat(response.getStatusCode(), is(200)); } @@ -101,7 +117,7 @@ public abstract class AbstractBasicLiveTest extends Abst @Test public void whenPageOfResourcesAreRetrievedOutOfBounds_then404IsReceived() { final String url = getURL() + "?page=" + randomNumeric(5) + "&size=10"; - final Response response = givenAuth().get(url); + final Response response = RestAssured.get(url); assertThat(response.getStatusCode(), is(404)); } @@ -110,14 +126,14 @@ public abstract class AbstractBasicLiveTest extends Abst public void givenResourcesExist_whenFirstPageIsRetrieved_thenPageContainsResources() { create(); - final Response response = givenAuth().get(getURL() + "?page=0&size=10"); + final Response response = RestAssured.get(getURL() + "?page=0&size=10"); assertFalse(response.body().as(List.class).isEmpty()); } @Test public void whenFirstPageOfResourcesAreRetrieved_thenSecondPageIsNext() { - final Response response = givenAuth().get(getURL() + "?page=0&size=2"); + final Response response = RestAssured.get(getURL() + "?page=0&size=2"); final String uriToNextPage = extractURIByRel(response.getHeader(HttpHeaders.LINK), "next"); assertEquals(getURL() + "?page=1&size=2", uriToNextPage); @@ -125,7 +141,7 @@ public abstract class AbstractBasicLiveTest extends Abst @Test public void whenFirstPageOfResourcesAreRetrieved_thenNoPreviousPage() { - final Response response = givenAuth().get(getURL() + "?page=0&size=2"); + final Response response = RestAssured.get(getURL() + "?page=0&size=2"); final String uriToPrevPage = extractURIByRel(response.getHeader(HttpHeaders.LINK), "prev"); assertNull(uriToPrevPage); @@ -136,7 +152,7 @@ public abstract class AbstractBasicLiveTest extends Abst create(); create(); - final Response response = givenAuth().get(getURL() + "?page=1&size=2"); + final Response response = RestAssured.get(getURL() + "?page=1&size=2"); final String uriToPrevPage = extractURIByRel(response.getHeader(HttpHeaders.LINK), "prev"); assertEquals(getURL() + "?page=0&size=2", uriToPrevPage); @@ -144,10 +160,10 @@ public abstract class AbstractBasicLiveTest extends Abst @Test public void whenLastPageOfResourcesIsRetrieved_thenNoNextPageIsDiscoverable() { - final Response first = givenAuth().get(getURL() + "?page=0&size=2"); + final Response first = RestAssured.get(getURL() + "?page=0&size=2"); final String uriToLastPage = extractURIByRel(first.getHeader(HttpHeaders.LINK), "last"); - final Response response = givenAuth().get(uriToLastPage); + final Response response = RestAssured.get(uriToLastPage); final String uriToNextPage = extractURIByRel(response.getHeader(HttpHeaders.LINK), "next"); assertNull(uriToNextPage); diff --git a/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractDiscoverabilityLiveTest.java b/spring-rest-full/src/test/java/org/baeldung/common/web/AbstractDiscoverabilityLiveTest.java similarity index 76% rename from spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractDiscoverabilityLiveTest.java rename to spring-rest-full/src/test/java/org/baeldung/common/web/AbstractDiscoverabilityLiveTest.java index e7456f1667..c2dd3d84c7 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractDiscoverabilityLiveTest.java +++ b/spring-rest-full/src/test/java/org/baeldung/common/web/AbstractDiscoverabilityLiveTest.java @@ -5,6 +5,8 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; +import io.restassured.RestAssured; +import io.restassured.response.Response; import java.io.Serializable; @@ -15,7 +17,6 @@ import org.junit.Test; import org.springframework.http.MediaType; import com.google.common.net.HttpHeaders; -import io.restassured.response.Response; public abstract class AbstractDiscoverabilityLiveTest extends AbstractLiveTest { @@ -33,7 +34,7 @@ public abstract class AbstractDiscoverabilityLiveTest ex final String uriOfExistingResource = createAsUri(); // When - final Response res = givenAuth().post(uriOfExistingResource); + final Response res = RestAssured.post(uriOfExistingResource); // Then final String allowHeader = res.getHeader(HttpHeaders.ALLOW); @@ -44,11 +45,16 @@ public abstract class AbstractDiscoverabilityLiveTest ex public void whenResourceIsCreated_thenUriOfTheNewlyCreatedResourceIsDiscoverable() { // When final Foo newResource = new Foo(randomAlphabetic(6)); - final Response createResp = givenAuth().contentType(MediaType.APPLICATION_JSON_VALUE).body(newResource).post(getURL()); + final Response createResp = RestAssured.given() + .contentType(MediaType.APPLICATION_JSON_VALUE) + .body(newResource) + .post(getURL()); final String uriOfNewResource = createResp.getHeader(HttpHeaders.LOCATION); // Then - final Response response = givenAuth().header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).get(uriOfNewResource); + final Response response = RestAssured.given() + .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE) + .get(uriOfNewResource); final Foo resourceFromServer = response.body().as(Foo.class); assertThat(newResource, equalTo(resourceFromServer)); @@ -60,13 +66,13 @@ public abstract class AbstractDiscoverabilityLiveTest ex final String uriOfExistingResource = createAsUri(); // When - final Response getResponse = givenAuth().get(uriOfExistingResource); + final Response getResponse = RestAssured.get(uriOfExistingResource); // Then final String uriToAllResources = HTTPLinkHeaderUtil.extractURIByRel(getResponse.getHeader("Link"), "collection"); - final Response getAllResponse = givenAuth().get(uriToAllResources); - assertThat(getAllResponse.getStatusCode(), is(403)); + final Response getAllResponse = RestAssured.get(uriToAllResources); + assertThat(getAllResponse.getStatusCode(), is(200)); } // template method diff --git a/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java b/spring-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java similarity index 79% rename from spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java rename to spring-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java index 72dbcedc64..5aa0f5a768 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java +++ b/spring-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java @@ -1,6 +1,8 @@ package org.baeldung.common.web; import static org.baeldung.Consts.APPLICATION_PORT; +import io.restassured.RestAssured; +import io.restassured.response.Response; import java.io.Serializable; @@ -9,9 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired; import com.google.common.base.Preconditions; import com.google.common.net.HttpHeaders; -import io.restassured.RestAssured; -import io.restassured.response.Response; -import io.restassured.specification.RequestSpecification; public abstract class AbstractLiveTest { @@ -48,20 +47,18 @@ public abstract class AbstractLiveTest { final Response createAsResponse(final T resource) { Preconditions.checkNotNull(resource); - final RequestSpecification givenAuthenticated = givenAuth(); final String resourceAsString = marshaller.encode(resource); - return givenAuthenticated.contentType(marshaller.getMime()).body(resourceAsString).post(getURL()); + return RestAssured.given() + .contentType(marshaller.getMime()) + .body(resourceAsString) + .post(getURL()); } // protected String getURL() { - return "http://localhost:" + APPLICATION_PORT + "/spring-security-rest-full/auth/foos"; - } - - protected final RequestSpecification givenAuth() { - return RestAssured.given().auth().preemptive().basic("user1", "user1Pass"); + return "http://localhost:" + APPLICATION_PORT + "/spring-rest-full/auth/foos"; } } diff --git a/spring-rest-full/src/test/java/org/baeldung/persistence/PersistenceTestSuite.java b/spring-rest-full/src/test/java/org/baeldung/persistence/PersistenceTestSuite.java new file mode 100644 index 0000000000..fb0fd00bb5 --- /dev/null +++ b/spring-rest-full/src/test/java/org/baeldung/persistence/PersistenceTestSuite.java @@ -0,0 +1,16 @@ +package org.baeldung.persistence; + +import org.baeldung.persistence.service.FooServicePersistenceIntegrationTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + // @formatter:off + + FooServicePersistenceIntegrationTest.class + +}) // +public class PersistenceTestSuite { + +} diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java b/spring-rest-full/src/test/java/org/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java rename to spring-rest-full/src/test/java/org/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java b/spring-rest-full/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java rename to spring-rest-full/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/spring/ConfigTest.java b/spring-rest-full/src/test/java/org/baeldung/spring/ConfigTest.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/spring/ConfigTest.java rename to spring-rest-full/src/test/java/org/baeldung/spring/ConfigTest.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/test/IMarshaller.java b/spring-rest-full/src/test/java/org/baeldung/test/IMarshaller.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/test/IMarshaller.java rename to spring-rest-full/src/test/java/org/baeldung/test/IMarshaller.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/test/JacksonMarshaller.java b/spring-rest-full/src/test/java/org/baeldung/test/JacksonMarshaller.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/test/JacksonMarshaller.java rename to spring-rest-full/src/test/java/org/baeldung/test/JacksonMarshaller.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/test/TestMarshallerFactory.java b/spring-rest-full/src/test/java/org/baeldung/test/TestMarshallerFactory.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/test/TestMarshallerFactory.java rename to spring-rest-full/src/test/java/org/baeldung/test/TestMarshallerFactory.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/test/XStreamMarshaller.java b/spring-rest-full/src/test/java/org/baeldung/test/XStreamMarshaller.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/test/XStreamMarshaller.java rename to spring-rest-full/src/test/java/org/baeldung/test/XStreamMarshaller.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/util/IDUtil.java b/spring-rest-full/src/test/java/org/baeldung/util/IDUtil.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/util/IDUtil.java rename to spring-rest-full/src/test/java/org/baeldung/util/IDUtil.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/web/FooDiscoverabilityLiveTest.java b/spring-rest-full/src/test/java/org/baeldung/web/FooDiscoverabilityLiveTest.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/web/FooDiscoverabilityLiveTest.java rename to spring-rest-full/src/test/java/org/baeldung/web/FooDiscoverabilityLiveTest.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/web/FooLiveTest.java b/spring-rest-full/src/test/java/org/baeldung/web/FooLiveTest.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/web/FooLiveTest.java rename to spring-rest-full/src/test/java/org/baeldung/web/FooLiveTest.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/web/FooPageableLiveTest.java b/spring-rest-full/src/test/java/org/baeldung/web/FooPageableLiveTest.java similarity index 88% rename from spring-security-rest-full/src/test/java/org/baeldung/web/FooPageableLiveTest.java rename to spring-rest-full/src/test/java/org/baeldung/web/FooPageableLiveTest.java index f43ca34bba..62a8983356 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/web/FooPageableLiveTest.java +++ b/spring-rest-full/src/test/java/org/baeldung/web/FooPageableLiveTest.java @@ -1,29 +1,26 @@ package org.baeldung.web; -import static org.baeldung.Consts.APPLICATION_PORT; -import static org.hamcrest.Matchers.is; - import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.apache.commons.lang3.RandomStringUtils.randomNumeric; +import static org.baeldung.Consts.APPLICATION_PORT; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import io.restassured.RestAssured; +import io.restassured.response.Response; import java.util.List; import org.baeldung.common.web.AbstractBasicLiveTest; import org.baeldung.persistence.model.Foo; +import org.baeldung.spring.ConfigTest; +import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.baeldung.spring.ConfigTest; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import org.junit.runner.RunWith; -import org.junit.Test; -import io.restassured.response.Response; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class) @ActiveProfiles("test") @@ -45,32 +42,35 @@ public class FooPageableLiveTest extends AbstractBasicLiveTest { return createAsUri(new Foo(randomAlphabetic(6))); } + @Override @Test public void whenResourcesAreRetrievedPaged_then200IsReceived() { - final Response response = givenAuth().get(getPageableURL() + "?page=0&size=10"); + final Response response = RestAssured.get(getPageableURL() + "?page=0&size=10"); assertThat(response.getStatusCode(), is(200)); } + @Override @Test public void whenPageOfResourcesAreRetrievedOutOfBounds_then404IsReceived() { final String url = getPageableURL() + "?page=" + randomNumeric(5) + "&size=10"; - final Response response = givenAuth().get(url); + final Response response = RestAssured.get(url); assertThat(response.getStatusCode(), is(404)); } + @Override @Test public void givenResourcesExist_whenFirstPageIsRetrieved_thenPageContainsResources() { create(); - final Response response = givenAuth().get(getPageableURL() + "?page=0&size=10"); + final Response response = RestAssured.get(getPageableURL() + "?page=0&size=10"); assertFalse(response.body().as(List.class).isEmpty()); } protected String getPageableURL() { - return "http://localhost:" + APPLICATION_PORT + "/spring-security-rest-full/auth/foos/pageable"; + return "http://localhost:" + APPLICATION_PORT + "/spring-rest-full/auth/foos/pageable"; } } diff --git a/spring-security-rest-full/src/test/java/org/baeldung/web/LiveTestSuite.java b/spring-rest-full/src/test/java/org/baeldung/web/LiveTestSuite.java similarity index 60% rename from spring-security-rest-full/src/test/java/org/baeldung/web/LiveTestSuite.java rename to spring-rest-full/src/test/java/org/baeldung/web/LiveTestSuite.java index 5d3d7fc518..6d5b94a686 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/web/LiveTestSuite.java +++ b/spring-rest-full/src/test/java/org/baeldung/web/LiveTestSuite.java @@ -1,17 +1,14 @@ package org.baeldung.web; -import org.baeldung.persistence.query.JPASpecificationLiveTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ // @formatter:off - JPASpecificationLiveTest.class - ,FooDiscoverabilityLiveTest.class + FooDiscoverabilityLiveTest.class ,FooLiveTest.class ,FooPageableLiveTest.class - ,MyUserLiveTest.class }) // public class LiveTestSuite { diff --git a/spring-security-rest-full/src/test/java/org/baeldung/web/util/HTTPLinkHeaderUtil.java b/spring-rest-full/src/test/java/org/baeldung/web/util/HTTPLinkHeaderUtil.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/web/util/HTTPLinkHeaderUtil.java rename to spring-rest-full/src/test/java/org/baeldung/web/util/HTTPLinkHeaderUtil.java diff --git a/spring-security-rest-full/src/test/resources/.gitignore b/spring-rest-full/src/test/resources/.gitignore similarity index 100% rename from spring-security-rest-full/src/test/resources/.gitignore rename to spring-rest-full/src/test/resources/.gitignore diff --git a/spring-rest-query-language/.gitignore b/spring-rest-query-language/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/spring-rest-query-language/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/spring-rest-query-language/README.md b/spring-rest-query-language/README.md new file mode 100644 index 0000000000..7677f96379 --- /dev/null +++ b/spring-rest-query-language/README.md @@ -0,0 +1,35 @@ +========= + +## REST Example Project Query Language + +### Courses +The "REST With Spring" Classes: http://bit.ly/restwithspring + +The "Learn Spring Security" Classes: http://github.learnspringsecurity.com + +### Relevant Articles: + +- [REST Query Language with Spring and JPA Criteria](http://www.baeldung.com/rest-search-language-spring-jpa-criteria) +- [REST Query Language with Spring Data JPA Specifications](http://www.baeldung.com/rest-api-search-language-spring-data-specifications) +- [REST Query Language with Spring Data JPA and QueryDSL](http://www.baeldung.com/rest-api-search-language-spring-data-querydsl) +- [REST Query Language – Advanced Search Operations](http://www.baeldung.com/rest-api-query-search-language-more-operations) +- [REST Query Language with RSQL](http://www.baeldung.com/rest-api-search-language-rsql-fiql) +- [REST Query Language – Implementing OR Operation](http://www.baeldung.com/rest-api-query-search-or-operation) + + + + +### Build the Project +``` +mvn clean install +``` + + +### Set up MySQL +``` +mysql -u root -p +> CREATE USER 'tutorialuser'@'localhost' IDENTIFIED BY 'tutorialmy5ql'; +> GRANT ALL PRIVILEGES ON *.* TO 'tutorialuser'@'localhost'; +> FLUSH PRIVILEGES; +``` + diff --git a/spring-security-rest-full/pom.xml b/spring-rest-query-language/pom.xml similarity index 98% rename from spring-security-rest-full/pom.xml rename to spring-rest-query-language/pom.xml index 12a611431e..bf3eb8cb78 100644 --- a/spring-security-rest-full/pom.xml +++ b/spring-rest-query-language/pom.xml @@ -2,10 +2,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.baeldung - spring-security-rest-full + spring-rest-query-language 0.1-SNAPSHOT - spring-security-rest-full + spring-rest-query-language war @@ -230,7 +230,7 @@ - spring-security-rest-full + spring-rest-query-language src/main/resources diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/GenericSpecificationsBuilder.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/GenericSpecificationsBuilder.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/GenericSpecificationsBuilder.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/GenericSpecificationsBuilder.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/IUserDAO.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/IUserDAO.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/IUserDAO.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/IUserDAO.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/MyUserPredicate.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/MyUserPredicate.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/MyUserPredicate.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/MyUserPredicate.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/MyUserPredicatesBuilder.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/MyUserPredicatesBuilder.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/MyUserPredicatesBuilder.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/MyUserPredicatesBuilder.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/MyUserRepository.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/MyUserRepository.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/MyUserRepository.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/MyUserRepository.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/UserDAO.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/UserDAO.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/UserDAO.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/UserDAO.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/UserRepository.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/UserRepository.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/UserRepository.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/UserRepository.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/UserSpecification.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/UserSpecification.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/UserSpecification.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/UserSpecification.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/UserSpecificationsBuilder.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/UserSpecificationsBuilder.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/UserSpecificationsBuilder.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/UserSpecificationsBuilder.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/rsql/RsqlSearchOperation.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/rsql/RsqlSearchOperation.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/dao/rsql/RsqlSearchOperation.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/dao/rsql/RsqlSearchOperation.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/model/MyUser.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/model/MyUser.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/model/MyUser.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/model/MyUser.java diff --git a/spring-rest-query-language/src/main/java/org/baeldung/persistence/model/User.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/model/User.java new file mode 100644 index 0000000000..670d4a2e74 --- /dev/null +++ b/spring-rest-query-language/src/main/java/org/baeldung/persistence/model/User.java @@ -0,0 +1,94 @@ +package org.baeldung.persistence.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String firstName; + + private String lastName; + + private String email; + + private int age; + + public User() { + super(); + } + + public Long getId() { + return id; + } + + public void setId(final Long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(final String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(final String lastName) { + this.lastName = lastName; + } + + public String getEmail() { + return email; + } + + public void setEmail(final String username) { + email = username; + } + + public int getAge() { + return age; + } + + public void setAge(final int age) { + this.age = age; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((email == null) ? 0 : email.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final User user = (User) obj; + return email.equals(user.email); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("User [firstName=").append(firstName).append("]").append("[lastName=").append(lastName).append("]").append("[username").append(email).append("]"); + return builder.toString(); + } + +} \ No newline at end of file diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/model/User_.java b/spring-rest-query-language/src/main/java/org/baeldung/persistence/model/User_.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/persistence/model/User_.java rename to spring-rest-query-language/src/main/java/org/baeldung/persistence/model/User_.java diff --git a/spring-rest-query-language/src/main/java/org/baeldung/spring/Application.java b/spring-rest-query-language/src/main/java/org/baeldung/spring/Application.java new file mode 100644 index 0000000000..7aa9ea5bc3 --- /dev/null +++ b/spring-rest-query-language/src/main/java/org/baeldung/spring/Application.java @@ -0,0 +1,40 @@ +package org.baeldung.spring; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.web.context.request.RequestContextListener; + +/** + * Main Application Class - uses Spring Boot. Just run this as a normal Java + * class to run up a Jetty Server (on http://localhost:8082/spring-rest-query-language) + * + */ +@EnableScheduling +@EnableAutoConfiguration +@ComponentScan("org.baeldung") +@SpringBootApplication +public class Application extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(Application.class); + } + + @Override + public void onStartup(ServletContext sc) throws ServletException { + // Manages the lifecycle of the root application context + sc.addListener(new RequestContextListener()); + } + + public static void main(final String[] args) { + SpringApplication.run(Application.class, args); + } +} \ No newline at end of file diff --git a/spring-rest-query-language/src/main/java/org/baeldung/spring/PersistenceConfig.java b/spring-rest-query-language/src/main/java/org/baeldung/spring/PersistenceConfig.java new file mode 100644 index 0000000000..f3a87b189e --- /dev/null +++ b/spring-rest-query-language/src/main/java/org/baeldung/spring/PersistenceConfig.java @@ -0,0 +1,85 @@ +package org.baeldung.spring; + +import java.util.Properties; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import com.google.common.base.Preconditions; + +@Configuration +@EnableTransactionManagement +@PropertySource({ "classpath:persistence-${envTarget:h2}.properties" }) +@ComponentScan({ "org.baeldung.persistence" }) +// @ImportResource("classpath*:springDataPersistenceConfig.xml") +@EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao") +public class PersistenceConfig { + + @Autowired + private Environment env; + + public PersistenceConfig() { + super(); + } + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(dataSource()); + em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" }); + + final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + // vendorAdapter.set + em.setJpaVendorAdapter(vendorAdapter); + em.setJpaProperties(additionalProperties()); + + return em; + } + + @Bean + public DataSource dataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); + dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); + dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); + dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); + + return dataSource; + } + + @Bean + public PlatformTransactionManager transactionManager() { + final JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(entityManagerFactory().getObject()); + + return transactionManager; + } + + @Bean + public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + final Properties additionalProperties() { + final Properties hibernateProperties = new Properties(); + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + // hibernateProperties.setProperty("hibernate.globally_quoted_identifiers", "true"); + return hibernateProperties; + } + +} \ No newline at end of file diff --git a/spring-rest-query-language/src/main/java/org/baeldung/spring/WebConfig.java b/spring-rest-query-language/src/main/java/org/baeldung/spring/WebConfig.java new file mode 100644 index 0000000000..41711ee1ad --- /dev/null +++ b/spring-rest-query-language/src/main/java/org/baeldung/spring/WebConfig.java @@ -0,0 +1,36 @@ +package org.baeldung.spring; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.view.InternalResourceViewResolver; + +@Configuration +@ComponentScan("org.baeldung.web") +@EnableWebMvc +public class WebConfig extends WebMvcConfigurerAdapter { + + public WebConfig() { + super(); + } + + @Bean + public ViewResolver viewResolver() { + final InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); + viewResolver.setPrefix("/WEB-INF/view/"); + viewResolver.setSuffix(".jsp"); + return viewResolver; + } + + // API + @Override + public void addViewControllers(final ViewControllerRegistry registry) { + super.addViewControllers(registry); + registry.addViewController("/homepage.html"); + } + +} \ No newline at end of file diff --git a/spring-rest-query-language/src/main/java/org/baeldung/web/controller/HomeController.java b/spring-rest-query-language/src/main/java/org/baeldung/web/controller/HomeController.java new file mode 100644 index 0000000000..9c4d14cae3 --- /dev/null +++ b/spring-rest-query-language/src/main/java/org/baeldung/web/controller/HomeController.java @@ -0,0 +1,14 @@ +package org.baeldung.web.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping(value = "/") +public class HomeController { + + public String index() { + return "homepage"; + } + +} diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/UserController.java b/spring-rest-query-language/src/main/java/org/baeldung/web/controller/UserController.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/controller/UserController.java rename to spring-rest-query-language/src/main/java/org/baeldung/web/controller/UserController.java diff --git a/spring-rest-query-language/src/main/java/org/baeldung/web/error/RestResponseEntityExceptionHandler.java b/spring-rest-query-language/src/main/java/org/baeldung/web/error/RestResponseEntityExceptionHandler.java new file mode 100644 index 0000000000..b593116c4a --- /dev/null +++ b/spring-rest-query-language/src/main/java/org/baeldung/web/error/RestResponseEntityExceptionHandler.java @@ -0,0 +1,84 @@ +package org.baeldung.web.error; + +import javax.persistence.EntityNotFoundException; + +import org.baeldung.web.exception.MyResourceNotFoundException; +import org.hibernate.exception.ConstraintViolationException; +import org.springframework.dao.DataAccessException; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.context.request.WebRequest; +import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; + +@ControllerAdvice +public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler { + + public RestResponseEntityExceptionHandler() { + super(); + } + + // API + + // 400 + + @ExceptionHandler({ ConstraintViolationException.class }) + public ResponseEntity handleBadRequest(final ConstraintViolationException ex, final WebRequest request) { + final String bodyOfResponse = "This should be application specific"; + return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.BAD_REQUEST, request); + } + + @ExceptionHandler({ DataIntegrityViolationException.class }) + public ResponseEntity handleBadRequest(final DataIntegrityViolationException ex, final WebRequest request) { + final String bodyOfResponse = "This should be application specific"; + return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.BAD_REQUEST, request); + } + + @Override + protected ResponseEntity handleHttpMessageNotReadable(final HttpMessageNotReadableException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) { + final String bodyOfResponse = "This should be application specific"; + // ex.getCause() instanceof JsonMappingException, JsonParseException // for additional information later on + return handleExceptionInternal(ex, bodyOfResponse, headers, HttpStatus.BAD_REQUEST, request); + } + + @Override + protected ResponseEntity handleMethodArgumentNotValid(final MethodArgumentNotValidException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) { + final String bodyOfResponse = "This should be application specific"; + return handleExceptionInternal(ex, bodyOfResponse, headers, HttpStatus.BAD_REQUEST, request); + } + + + // 404 + + @ExceptionHandler(value = { EntityNotFoundException.class, MyResourceNotFoundException.class }) + protected ResponseEntity handleNotFound(final RuntimeException ex, final WebRequest request) { + final String bodyOfResponse = "This should be application specific"; + return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.NOT_FOUND, request); + } + + // 409 + + @ExceptionHandler({ InvalidDataAccessApiUsageException.class, DataAccessException.class }) + protected ResponseEntity handleConflict(final RuntimeException ex, final WebRequest request) { + final String bodyOfResponse = "This should be application specific"; + return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.CONFLICT, request); + } + + // 412 + + // 500 + + @ExceptionHandler({ NullPointerException.class, IllegalArgumentException.class, IllegalStateException.class }) + /*500*/public ResponseEntity handleInternal(final RuntimeException ex, final WebRequest request) { + logger.error("500 Status Code", ex); + final String bodyOfResponse = "This should be application specific"; + return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request); + } + +} diff --git a/spring-rest-query-language/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java b/spring-rest-query-language/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java new file mode 100644 index 0000000000..14b61f9832 --- /dev/null +++ b/spring-rest-query-language/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java @@ -0,0 +1,21 @@ +package org.baeldung.web.exception; + +public final class MyResourceNotFoundException extends RuntimeException { + + public MyResourceNotFoundException() { + super(); + } + + public MyResourceNotFoundException(final String message, final Throwable cause) { + super(message, cause); + } + + public MyResourceNotFoundException(final String message) { + super(message); + } + + public MyResourceNotFoundException(final Throwable cause) { + super(cause); + } + +} diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/util/CriteriaParser.java b/spring-rest-query-language/src/main/java/org/baeldung/web/util/CriteriaParser.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/util/CriteriaParser.java rename to spring-rest-query-language/src/main/java/org/baeldung/web/util/CriteriaParser.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/util/SearchCriteria.java b/spring-rest-query-language/src/main/java/org/baeldung/web/util/SearchCriteria.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/util/SearchCriteria.java rename to spring-rest-query-language/src/main/java/org/baeldung/web/util/SearchCriteria.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/util/SearchOperation.java b/spring-rest-query-language/src/main/java/org/baeldung/web/util/SearchOperation.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/util/SearchOperation.java rename to spring-rest-query-language/src/main/java/org/baeldung/web/util/SearchOperation.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/util/SpecSearchCriteria.java b/spring-rest-query-language/src/main/java/org/baeldung/web/util/SpecSearchCriteria.java similarity index 100% rename from spring-security-rest-full/src/main/java/org/baeldung/web/util/SpecSearchCriteria.java rename to spring-rest-query-language/src/main/java/org/baeldung/web/util/SpecSearchCriteria.java diff --git a/spring-rest-query-language/src/main/resources/application.properties b/spring-rest-query-language/src/main/resources/application.properties new file mode 100644 index 0000000000..01eaee7040 --- /dev/null +++ b/spring-rest-query-language/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8082 +server.context-path=/spring-rest-query-language \ No newline at end of file diff --git a/spring-security-rest-full/src/main/resources/data.sql b/spring-rest-query-language/src/main/resources/data.sql similarity index 100% rename from spring-security-rest-full/src/main/resources/data.sql rename to spring-rest-query-language/src/main/resources/data.sql diff --git a/spring-rest-query-language/src/main/resources/logback.xml b/spring-rest-query-language/src/main/resources/logback.xml new file mode 100644 index 0000000000..ec0dc2469a --- /dev/null +++ b/spring-rest-query-language/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-rest-query-language/src/main/resources/persistence-h2.properties b/spring-rest-query-language/src/main/resources/persistence-h2.properties new file mode 100644 index 0000000000..839a466533 --- /dev/null +++ b/spring-rest-query-language/src/main/resources/persistence-h2.properties @@ -0,0 +1,22 @@ +## jdbc.X +#jdbc.driverClassName=com.mysql.jdbc.Driver +#jdbc.url=jdbc:mysql://localhost:3306/spring_hibernate4_01?createDatabaseIfNotExist=true +#jdbc.user=tutorialuser +#jdbc.pass=tutorialmy5ql +# +## hibernate.X +#hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +#hibernate.show_sql=false +#hibernate.hbm2ddl.auto=create-drop + + +# jdbc.X +jdbc.driverClassName=org.h2.Driver +jdbc.url=jdbc:h2:mem:security_permission;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE +jdbc.user=sa +jdbc.pass= + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=false +hibernate.hbm2ddl.auto=create-drop diff --git a/spring-rest-query-language/src/main/resources/persistence-mysql.properties b/spring-rest-query-language/src/main/resources/persistence-mysql.properties new file mode 100644 index 0000000000..8263b0d9ac --- /dev/null +++ b/spring-rest-query-language/src/main/resources/persistence-mysql.properties @@ -0,0 +1,10 @@ +# jdbc.X +jdbc.driverClassName=com.mysql.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/spring_hibernate4_01?createDatabaseIfNotExist=true +jdbc.user=tutorialuser +jdbc.pass=tutorialmy5ql + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +hibernate.show_sql=false +hibernate.hbm2ddl.auto=create-drop diff --git a/spring-rest-query-language/src/main/resources/springDataPersistenceConfig.xml b/spring-rest-query-language/src/main/resources/springDataPersistenceConfig.xml new file mode 100644 index 0000000000..d6d0ec6e47 --- /dev/null +++ b/spring-rest-query-language/src/main/resources/springDataPersistenceConfig.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/spring-rest-query-language/src/main/webapp/WEB-INF/api-servlet.xml b/spring-rest-query-language/src/main/webapp/WEB-INF/api-servlet.xml new file mode 100644 index 0000000000..4ba9642448 --- /dev/null +++ b/spring-rest-query-language/src/main/webapp/WEB-INF/api-servlet.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/spring-rest-query-language/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-rest-query-language/src/main/webapp/WEB-INF/view/homepage.jsp new file mode 100644 index 0000000000..7cc14b5dcd --- /dev/null +++ b/spring-rest-query-language/src/main/webapp/WEB-INF/view/homepage.jsp @@ -0,0 +1,7 @@ + + + + +

This is the body of the sample view

+ + \ No newline at end of file diff --git a/spring-rest-query-language/src/main/webapp/WEB-INF/web.xml b/spring-rest-query-language/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..4472afd112 --- /dev/null +++ b/spring-rest-query-language/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,42 @@ + + + + Spring REST Query language Application + + + + contextClass + + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + + contextConfigLocation + org.baeldung.spring + + + + org.springframework.web.context.ContextLoaderListener + + + + + api + org.springframework.web.servlet.DispatcherServlet + 1 + + + api + / + + + + + index.html + + + \ No newline at end of file diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java b/spring-rest-query-language/src/test/java/org/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java rename to spring-rest-query-language/src/test/java/org/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPAQuerydslIntegrationTest.java b/spring-rest-query-language/src/test/java/org/baeldung/persistence/query/JPAQuerydslIntegrationTest.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPAQuerydslIntegrationTest.java rename to spring-rest-query-language/src/test/java/org/baeldung/persistence/query/JPAQuerydslIntegrationTest.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationIntegrationTest.java b/spring-rest-query-language/src/test/java/org/baeldung/persistence/query/JPASpecificationIntegrationTest.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationIntegrationTest.java rename to spring-rest-query-language/src/test/java/org/baeldung/persistence/query/JPASpecificationIntegrationTest.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java b/spring-rest-query-language/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java similarity index 78% rename from spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java rename to spring-rest-query-language/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java index 07b47dd8b6..044029c679 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java +++ b/spring-rest-query-language/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java @@ -1,16 +1,15 @@ package org.baeldung.persistence.query; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import io.restassured.RestAssured; import io.restassured.response.Response; -import io.restassured.specification.RequestSpecification; + import org.baeldung.persistence.model.User; import org.junit.Before; import org.junit.Test; import org.springframework.test.context.ActiveProfiles; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - //@RunWith(SpringJUnit4ClassRunner.class) //@ContextConfiguration(classes = { ConfigTest.class, // PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) @@ -24,7 +23,7 @@ public class JPASpecificationLiveTest { private User userTom; - private final String URL_PREFIX = "http://localhost:8082/spring-security-rest-full/auth/users/spec?search="; + private final String URL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/spec?search="; @Before public void init() { @@ -43,11 +42,11 @@ public class JPASpecificationLiveTest { // repository.save(userTom); } - private final String EURL_PREFIX = "http://localhost:8082/spring-security-rest-full/auth/users/espec?search="; + private final String EURL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/espec?search="; @Test public void givenFirstOrLastName_whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get(EURL_PREFIX + "firstName:john,'lastName:doe"); + final Response response = RestAssured.get(EURL_PREFIX + "firstName:john,'lastName:doe"); final String result = response.body() .asString(); assertTrue(result.contains(userJohn.getEmail())); @@ -56,7 +55,7 @@ public class JPASpecificationLiveTest { @Test public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get(URL_PREFIX + "firstName:john,lastName:doe"); + final Response response = RestAssured.get(URL_PREFIX + "firstName:john,lastName:doe"); final String result = response.body() .asString(); @@ -66,7 +65,7 @@ public class JPASpecificationLiveTest { @Test public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get(URL_PREFIX + "firstName!john"); + final Response response = RestAssured.get(URL_PREFIX + "firstName!john"); final String result = response.body() .asString(); @@ -76,7 +75,7 @@ public class JPASpecificationLiveTest { @Test public void givenMinAge_whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get(URL_PREFIX + "age>25"); + final Response response = RestAssured.get(URL_PREFIX + "age>25"); final String result = response.body() .asString(); @@ -86,7 +85,7 @@ public class JPASpecificationLiveTest { @Test public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get(URL_PREFIX + "firstName:jo*"); + final Response response = RestAssured.get(URL_PREFIX + "firstName:jo*"); final String result = response.body() .asString(); @@ -96,7 +95,7 @@ public class JPASpecificationLiveTest { @Test public void givenFirstNameSuffix_whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get(URL_PREFIX + "firstName:*n"); + final Response response = RestAssured.get(URL_PREFIX + "firstName:*n"); final String result = response.body() .asString(); @@ -106,7 +105,7 @@ public class JPASpecificationLiveTest { @Test public void givenFirstNameSubstring_whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get(URL_PREFIX + "firstName:*oh*"); + final Response response = RestAssured.get(URL_PREFIX + "firstName:*oh*"); final String result = response.body() .asString(); @@ -116,7 +115,7 @@ public class JPASpecificationLiveTest { @Test public void givenAgeRange_whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get(URL_PREFIX + "age>20,age<25"); + final Response response = RestAssured.get(URL_PREFIX + "age>20,age<25"); final String result = response.body() .asString(); @@ -124,11 +123,11 @@ public class JPASpecificationLiveTest { assertFalse(result.contains(userTom.getEmail())); } - private final String ADV_URL_PREFIX = "http://localhost:8082/spring-security-rest-full/auth/users/spec/adv?search="; + private final String ADV_URL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/users/spec/adv?search="; @Test public void givenFirstOrLastName_whenGettingAdvListOfUsers_thenCorrect() { - final Response response = givenAuth().get(ADV_URL_PREFIX + "firstName:john OR lastName:doe"); + final Response response = RestAssured.get(ADV_URL_PREFIX + "firstName:john OR lastName:doe"); final String result = response.body() .asString(); assertTrue(result.contains(userJohn.getEmail())); @@ -137,17 +136,11 @@ public class JPASpecificationLiveTest { @Test public void givenFirstOrFirstNameAndAge_whenGettingAdvListOfUsers_thenCorrect() { - final Response response = givenAuth().get(ADV_URL_PREFIX + "( firstName:john OR firstName:tom ) AND age>22"); + final Response response = RestAssured.get(ADV_URL_PREFIX + "( firstName:john OR firstName:tom ) AND age>22"); final String result = response.body() .asString(); assertFalse(result.contains(userJohn.getEmail())); assertTrue(result.contains(userTom.getEmail())); } - private final RequestSpecification givenAuth() { - return RestAssured.given() - .auth() - .preemptive() - .basic("user1", "user1Pass"); - } } diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/RsqlIntegrationTest.java b/spring-rest-query-language/src/test/java/org/baeldung/persistence/query/RsqlIntegrationTest.java similarity index 100% rename from spring-security-rest-full/src/test/java/org/baeldung/persistence/query/RsqlIntegrationTest.java rename to spring-rest-query-language/src/test/java/org/baeldung/persistence/query/RsqlIntegrationTest.java diff --git a/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java b/spring-rest-query-language/src/test/java/org/baeldung/web/MyUserLiveTest.java similarity index 94% rename from spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java rename to spring-rest-query-language/src/test/java/org/baeldung/web/MyUserLiveTest.java index b598463da0..a478016280 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java +++ b/spring-rest-query-language/src/test/java/org/baeldung/web/MyUserLiveTest.java @@ -1,20 +1,19 @@ package org.baeldung.web; import static org.junit.Assert.assertEquals; +import io.restassured.RestAssured; +import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; import org.baeldung.persistence.model.MyUser; import org.junit.Test; import org.springframework.test.context.ActiveProfiles; -import io.restassured.RestAssured; -import io.restassured.response.Response; -import io.restassured.specification.RequestSpecification; - @ActiveProfiles("test") public class MyUserLiveTest { private final MyUser userJohn = new MyUser("john", "doe", "john@doe.com", 11); - private String URL_PREFIX = "http://localhost:8082/spring-security-rest-full/auth/api/myusers"; + private String URL_PREFIX = "http://localhost:8082/spring-rest-query-language/auth/api/myusers"; @Test public void whenGettingListOfUsers_thenCorrect() { diff --git a/spring-rest-query-language/src/test/resources/.gitignore b/spring-rest-query-language/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/spring-rest-query-language/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/spring-security-rest-full/.springBeans b/spring-security-rest-full/.springBeans deleted file mode 100644 index b01040d91b..0000000000 --- a/spring-security-rest-full/.springBeans +++ /dev/null @@ -1,17 +0,0 @@ - - - 1 - - - - - - - - - src/main/webapp/WEB-INF/api-servlet.xml - java:org.baeldung.spring.Application - - - - diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/PersistenceTestSuite.java b/spring-security-rest-full/src/test/java/org/baeldung/persistence/PersistenceTestSuite.java deleted file mode 100644 index fda7b01c7a..0000000000 --- a/spring-security-rest-full/src/test/java/org/baeldung/persistence/PersistenceTestSuite.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.baeldung.persistence; - -import org.baeldung.persistence.query.JPACriteriaQueryIntegrationTest; -import org.baeldung.persistence.query.JPAQuerydslIntegrationTest; -import org.baeldung.persistence.query.JPASpecificationIntegrationTest; -import org.baeldung.persistence.query.RsqlIntegrationTest; -import org.baeldung.persistence.service.FooServicePersistenceIntegrationTest; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - // @formatter:off - RsqlIntegrationTest.class - ,JPASpecificationIntegrationTest.class - ,FooServicePersistenceIntegrationTest.class - ,JPAQuerydslIntegrationTest.class - ,JPACriteriaQueryIntegrationTest.class -}) // -public class PersistenceTestSuite { - -}