From 1c9477390d9c05fb6b651883f8c117d04261c66c Mon Sep 17 00:00:00 2001 From: Doha2012 Date: Wed, 25 Oct 2017 19:39:04 +0300 Subject: [PATCH] move query language to new module (#2864) * move security content from spring-security-rest-full * swagger update * move query language to new module * rename spring-security-rest-full to spring-rest-full --- pom.xml | 3 +- .../.gitignore | 0 .../README.md | 10 +- spring-rest-full/pom.xml | 378 ++++++++++++++++++ .../org/baeldung/persistence/IOperations.java | 0 .../org/baeldung/persistence/dao/IFooDao.java | 5 +- .../org/baeldung/persistence/model/Foo.java | 0 .../org/baeldung/persistence/model/User.java | 0 .../persistence/service/IFooService.java | 0 .../service/common/AbstractService.java | 0 .../persistence/service/impl/FooService.java | 0 .../java/org/baeldung/spring/Application.java | 2 +- .../baeldung/spring/PersistenceConfig.java | 0 .../java/org/baeldung/spring/WebConfig.java | 0 .../web/controller/FooController.java | 0 .../web/controller/HomeController.java | 0 .../web/controller/RootController.java | 0 .../RestResponseEntityExceptionHandler.java | 0 .../MyResourceNotFoundException.java | 0 .../event/PaginatedResultsRetrievedEvent.java | 0 .../hateoas/event/ResourceCreatedEvent.java | 0 .../event/SingleResourceRetrievedEvent.java | 0 ...sultsRetrievedDiscoverabilityListener.java | 0 ...esourceCreatedDiscoverabilityListener.java | 0 ...ourceRetrievedDiscoverabilityListener.java | 0 .../web/metric/ActuatorMetricService.java | 0 .../metric/CustomActuatorMetricService.java | 0 .../web/metric/IActuatorMetricService.java | 0 .../metric/ICustomActuatorMetricService.java | 0 .../baeldung/web/metric/IMetricService.java | 0 .../org/baeldung/web/metric/MetricFilter.java | 0 .../baeldung/web/metric/MetricService.java | 0 .../java/org/baeldung/web/util/LinkUtil.java | 0 .../baeldung/web/util/RestPreconditions.java | 0 .../src/main/resources/application.properties | 2 +- .../src/main/resources/logback.xml | 0 .../main/resources/persistence-h2.properties | 0 .../resources/persistence-mysql.properties | 0 .../resources/springDataPersistenceConfig.xml | 0 .../src/main/webapp/WEB-INF/api-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/graph.jsp | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 12 +- .../src/test/java/org/baeldung/Consts.java | 0 .../src/test/java/org/baeldung/TestSuite.java | 0 .../common/web/AbstractBasicLiveTest.java | 46 ++- .../web/AbstractDiscoverabilityLiveTest.java | 20 +- .../baeldung/common/web/AbstractLiveTest.java | 17 +- .../persistence/PersistenceTestSuite.java | 16 + ...ractServicePersistenceIntegrationTest.java | 0 .../FooServicePersistenceIntegrationTest.java | 0 .../java/org/baeldung/spring/ConfigTest.java | 0 .../java/org/baeldung/test/IMarshaller.java | 0 .../org/baeldung/test/JacksonMarshaller.java | 0 .../baeldung/test/TestMarshallerFactory.java | 0 .../org/baeldung/test/XStreamMarshaller.java | 0 .../test/java/org/baeldung/util/IDUtil.java | 0 .../web/FooDiscoverabilityLiveTest.java | 0 .../java/org/baeldung/web/FooLiveTest.java | 0 .../org/baeldung/web/FooPageableLiveTest.java | 32 +- .../java/org/baeldung/web/LiveTestSuite.java | 5 +- .../baeldung/web/util/HTTPLinkHeaderUtil.java | 0 .../src/test/resources/.gitignore | 0 spring-rest-query-language/.gitignore | 13 + spring-rest-query-language/README.md | 35 ++ .../pom.xml | 6 +- .../dao/GenericSpecificationsBuilder.java | 0 .../baeldung/persistence/dao/IUserDAO.java | 0 .../persistence/dao/MyUserPredicate.java | 0 .../dao/MyUserPredicatesBuilder.java | 0 .../persistence/dao/MyUserRepository.java | 0 .../org/baeldung/persistence/dao/UserDAO.java | 0 .../persistence/dao/UserRepository.java | 0 .../persistence/dao/UserSpecification.java | 0 .../dao/UserSpecificationsBuilder.java | 0 .../dao/rsql/CustomRsqlVisitor.java | 0 .../dao/rsql/GenericRsqlSpecBuilder.java | 0 .../dao/rsql/GenericRsqlSpecification.java | 0 .../dao/rsql/RsqlSearchOperation.java | 0 .../baeldung/persistence/model/MyUser.java | 0 .../org/baeldung/persistence/model/User.java | 94 +++++ .../org/baeldung/persistence/model/User_.java | 0 .../java/org/baeldung/spring/Application.java | 40 ++ .../baeldung/spring/PersistenceConfig.java | 85 ++++ .../java/org/baeldung/spring/WebConfig.java | 36 ++ .../web/controller/HomeController.java | 14 + .../web/controller/UserController.java | 0 .../RestResponseEntityExceptionHandler.java | 84 ++++ .../MyResourceNotFoundException.java | 21 + .../org/baeldung/web/util/CriteriaParser.java | 0 .../org/baeldung/web/util/SearchCriteria.java | 0 .../baeldung/web/util/SearchOperation.java | 0 .../baeldung/web/util/SpecSearchCriteria.java | 0 .../src/main/resources/application.properties | 2 + .../src/main/resources/data.sql | 0 .../src/main/resources/logback.xml | 19 + .../main/resources/persistence-h2.properties | 22 + .../resources/persistence-mysql.properties | 10 + .../resources/springDataPersistenceConfig.xml | 12 + .../src/main/webapp/WEB-INF/api-servlet.xml | 6 + .../src/main/webapp/WEB-INF/view/homepage.jsp | 7 + .../src/main/webapp/WEB-INF/web.xml | 42 ++ .../JPACriteriaQueryIntegrationTest.java | 0 .../query/JPAQuerydslIntegrationTest.java | 0 .../JPASpecificationIntegrationTest.java | 0 .../query/JPASpecificationLiveTest.java | 39 +- .../query/RsqlIntegrationTest.java | 0 .../java/org/baeldung/web/MyUserLiveTest.java | 9 +- .../src/test/resources/.gitignore | 13 + spring-security-rest-full/.springBeans | 17 - .../persistence/PersistenceTestSuite.java | 22 - 111 files changed, 1048 insertions(+), 148 deletions(-) rename {spring-security-rest-full => spring-rest-full}/.gitignore (100%) rename {spring-security-rest-full => spring-rest-full}/README.md (65%) create mode 100644 spring-rest-full/pom.xml rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/persistence/IOperations.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/persistence/dao/IFooDao.java (69%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/persistence/model/Foo.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/persistence/model/User.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/persistence/service/IFooService.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/persistence/service/common/AbstractService.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/persistence/service/impl/FooService.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/spring/Application.java (98%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/spring/PersistenceConfig.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/spring/WebConfig.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/controller/FooController.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/controller/HomeController.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/controller/RootController.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/error/RestResponseEntityExceptionHandler.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/hateoas/event/PaginatedResultsRetrievedEvent.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/hateoas/event/ResourceCreatedEvent.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/hateoas/event/SingleResourceRetrievedEvent.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/hateoas/listener/PaginatedResultsRetrievedDiscoverabilityListener.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/hateoas/listener/ResourceCreatedDiscoverabilityListener.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/hateoas/listener/SingleResourceRetrievedDiscoverabilityListener.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/metric/ActuatorMetricService.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/metric/CustomActuatorMetricService.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/metric/IActuatorMetricService.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/metric/ICustomActuatorMetricService.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/metric/IMetricService.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/metric/MetricFilter.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/metric/MetricService.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/util/LinkUtil.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/java/org/baeldung/web/util/RestPreconditions.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/resources/application.properties (50%) rename {spring-security-rest-full => spring-rest-full}/src/main/resources/logback.xml (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/resources/persistence-h2.properties (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/resources/persistence-mysql.properties (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/resources/springDataPersistenceConfig.xml (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/webapp/WEB-INF/api-servlet.xml (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/webapp/WEB-INF/view/graph.jsp (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) rename {spring-security-rest-full => spring-rest-full}/src/main/webapp/WEB-INF/web.xml (82%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/Consts.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/TestSuite.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/common/web/AbstractBasicLiveTest.java (73%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/common/web/AbstractDiscoverabilityLiveTest.java (76%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/common/web/AbstractLiveTest.java (79%) create mode 100644 spring-rest-full/src/test/java/org/baeldung/persistence/PersistenceTestSuite.java rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/persistence/service/AbstractServicePersistenceIntegrationTest.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/persistence/service/FooServicePersistenceIntegrationTest.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/spring/ConfigTest.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/test/IMarshaller.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/test/JacksonMarshaller.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/test/TestMarshallerFactory.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/test/XStreamMarshaller.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/util/IDUtil.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/web/FooDiscoverabilityLiveTest.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/web/FooLiveTest.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/web/FooPageableLiveTest.java (88%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/web/LiveTestSuite.java (60%) rename {spring-security-rest-full => spring-rest-full}/src/test/java/org/baeldung/web/util/HTTPLinkHeaderUtil.java (100%) rename {spring-security-rest-full => spring-rest-full}/src/test/resources/.gitignore (100%) create mode 100644 spring-rest-query-language/.gitignore create mode 100644 spring-rest-query-language/README.md rename {spring-security-rest-full => spring-rest-query-language}/pom.xml (98%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/GenericSpecificationsBuilder.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/IUserDAO.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/MyUserPredicate.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/MyUserPredicatesBuilder.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/MyUserRepository.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/UserDAO.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/UserRepository.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/UserSpecification.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/UserSpecificationsBuilder.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/rsql/CustomRsqlVisitor.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/rsql/GenericRsqlSpecBuilder.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/rsql/GenericRsqlSpecification.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/dao/rsql/RsqlSearchOperation.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/model/MyUser.java (100%) create mode 100644 spring-rest-query-language/src/main/java/org/baeldung/persistence/model/User.java rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/persistence/model/User_.java (100%) create mode 100644 spring-rest-query-language/src/main/java/org/baeldung/spring/Application.java create mode 100644 spring-rest-query-language/src/main/java/org/baeldung/spring/PersistenceConfig.java create mode 100644 spring-rest-query-language/src/main/java/org/baeldung/spring/WebConfig.java create mode 100644 spring-rest-query-language/src/main/java/org/baeldung/web/controller/HomeController.java rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/web/controller/UserController.java (100%) create mode 100644 spring-rest-query-language/src/main/java/org/baeldung/web/error/RestResponseEntityExceptionHandler.java create mode 100644 spring-rest-query-language/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/web/util/CriteriaParser.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/web/util/SearchCriteria.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/web/util/SearchOperation.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/main/java/org/baeldung/web/util/SpecSearchCriteria.java (100%) create mode 100644 spring-rest-query-language/src/main/resources/application.properties rename {spring-security-rest-full => spring-rest-query-language}/src/main/resources/data.sql (100%) create mode 100644 spring-rest-query-language/src/main/resources/logback.xml create mode 100644 spring-rest-query-language/src/main/resources/persistence-h2.properties create mode 100644 spring-rest-query-language/src/main/resources/persistence-mysql.properties create mode 100644 spring-rest-query-language/src/main/resources/springDataPersistenceConfig.xml create mode 100644 spring-rest-query-language/src/main/webapp/WEB-INF/api-servlet.xml create mode 100644 spring-rest-query-language/src/main/webapp/WEB-INF/view/homepage.jsp create mode 100644 spring-rest-query-language/src/main/webapp/WEB-INF/web.xml rename {spring-security-rest-full => spring-rest-query-language}/src/test/java/org/baeldung/persistence/query/JPACriteriaQueryIntegrationTest.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/test/java/org/baeldung/persistence/query/JPAQuerydslIntegrationTest.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/test/java/org/baeldung/persistence/query/JPASpecificationIntegrationTest.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java (78%) rename {spring-security-rest-full => spring-rest-query-language}/src/test/java/org/baeldung/persistence/query/RsqlIntegrationTest.java (100%) rename {spring-security-rest-full => spring-rest-query-language}/src/test/java/org/baeldung/web/MyUserLiveTest.java (94%) create mode 100644 spring-rest-query-language/src/test/resources/.gitignore delete mode 100644 spring-security-rest-full/.springBeans delete mode 100644 spring-security-rest-full/src/test/java/org/baeldung/persistence/PersistenceTestSuite.java 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 { - -}