From d5c0009c6eb0e77e4e1013d149d33de7dccdbd4d Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Tue, 25 Jun 2019 10:11:56 -0700 Subject: [PATCH] Rename samples to smoke tests Closes gh-17197 --- CONTRIBUTING.adoc | 10 +- README.adoc | 3 - ci/scripts/build-samples.sh | 2 +- ci/scripts/stage.sh | 2 +- eclipse/spring-boot-project.setup | 4 +- pom.xml | 6 +- .../src/main/asciidoc/getting-started.adoc | 7 +- .../src/main/asciidoc/howto.adoc | 38 +-- .../main/asciidoc/spring-boot-features.adoc | 12 +- spring-boot-samples-invoker/pom.xml | 81 ------ spring-boot-samples/README.adoc | 244 ----------------- spring-boot-samples/pom.xml | 250 ------------------ .../spring-boot-sample-activemq/pom.xml | 38 --- .../main/java/sample/activemq/Consumer.java | 30 --- .../main/java/sample/activemq/Producer.java | 45 ---- .../activemq/SampleActiveMQApplication.java | 41 --- .../sample/activemq/SampleActiveMqTests.java | 48 ---- .../pom.xml | 60 ----- .../customsecurity/ExampleController.java | 42 --- .../ExampleRestControllerEndpoint.java | 34 --- ...mpleActuatorCustomSecurityApplication.java | 29 -- .../customsecurity/SecurityConfiguration.java | 60 ----- .../CorsSampleActuatorApplicationTests.java | 83 ------ ...AndPathSampleActuatorApplicationTests.java | 85 ------ ...ctuatorCustomSecurityApplicationTests.java | 162 ------------ .../pom.xml | 60 ----- .../SampleActuatorLog4J2Application.java | 29 -- .../SampleActuatorLog4J2ApplicationTests.java | 72 ----- .../spring-boot-sample-actuator-noweb/pom.xml | 44 --- .../actuator/noweb/HelloWorldService.java | 34 --- .../noweb/SampleActuatorNoWebApplication.java | 29 -- .../actuator/noweb/ServiceProperties.java | 37 --- .../SampleActuatorNoWebApplicationTests.java | 36 --- .../spring-boot-sample-actuator-ui/pom.xml | 54 ---- .../ui/SampleActuatorUiApplication.java | 49 ---- .../SampleActuatorUiApplicationPortTests.java | 74 ------ .../ui/SampleActuatorUiApplicationTests.java | 87 ------ .../spring-boot-sample-actuator/pom.xml | 86 ------ .../actuator/ExampleHealthIndicator.java | 31 --- .../actuator/ExampleInfoContributor.java | 33 --- .../sample/actuator/HelloWorldService.java | 34 --- .../actuator/SampleActuatorApplication.java | 37 --- .../sample/actuator/SampleController.java | 82 ------ .../sample/actuator/ServiceProperties.java | 37 --- ...pertiesSampleActuatorApplicationTests.java | 70 ----- ...gementAddressActuatorApplicationTests.java | 67 ----- ...entPathSampleActuatorApplicationTests.java | 67 ----- ...AndPathSampleActuatorApplicationTests.java | 124 --------- ...entPortSampleActuatorApplicationTests.java | 93 ------- ...gementPortWithLazyInitializationTests.java | 50 ---- ...agementSampleActuatorApplicationTests.java | 67 ----- .../SampleActuatorApplicationTests.java | 195 -------------- ...letPathSampleActuatorApplicationTests.java | 78 ------ ...hutdownSampleActuatorApplicationTests.java | 85 ------ .../spring-boot-sample-amqp/pom.xml | 39 --- .../amqp/SampleAmqpSimpleApplication.java | 54 ---- .../src/main/java/sample/amqp/Sender.java | 33 --- .../pom.xml | 38 --- .../SampleAnimatedBannerApplication.java | 29 -- .../spring-boot-sample-ant/build.xml | 69 ----- .../spring-boot-sample-ant/ivy.xml | 12 - .../spring-boot-sample-ant/pom.xml | 107 -------- .../java/sample/ant/SampleAntApplication.java | 35 --- .../sample/ant/SampleAntApplicationIT.java | 58 ---- .../spring-boot-sample-aop/pom.xml | 38 --- .../java/sample/aop/SampleAopApplication.java | 43 --- .../sample/aop/monitor/ServiceMonitor.java | 34 --- .../sample/aop/service/HelloWorldService.java | 32 --- .../sample/aop/SampleAopApplicationTests.java | 67 ----- .../spring-boot-sample-atmosphere/pom.xml | 58 ---- .../java/sample/atmosphere/ChatService.java | 81 ------ .../main/java/sample/atmosphere/Message.java | 53 ---- .../SampleAtmosphereApplication.java | 88 ------ .../SampleAtmosphereApplicationTests.java | 120 --------- .../spring-boot-sample-batch/pom.xml | 44 --- .../sample/batch/SampleBatchApplication.java | 71 ----- .../batch/SampleBatchApplicationTests.java | 37 --- .../spring-boot-sample-cache/README.adoc | 126 --------- .../spring-boot-sample-cache/pom.xml | 128 --------- .../java/sample/cache/CacheManagerCheck.java | 44 --- .../src/main/java/sample/cache/Country.java | 53 ---- .../java/sample/cache/CountryRepository.java | 33 --- .../sample/cache/SampleCacheApplication.java | 33 --- .../main/java/sample/cache/SampleClient.java | 63 ----- .../cache/SampleCacheApplicationTests.java | 47 ---- .../spring-boot-sample-custom-layout/pom.xml | 114 -------- .../src/it/custom/pom.xml | 43 --- .../src/it/custom/verify.groovy | 6 - .../src/it/default/verify.groovy | 6 - .../src/it/settings.xml | 35 --- .../main/java/sample/layout/SampleLayout.java | 44 --- .../sample/layout/SampleLayoutFactory.java | 48 ---- .../main/resources/META-INF/spring.factories | 2 - .../src/test/java/sample/layout/Verify.java | 41 --- .../README.adoc | 12 - .../spring-boot-sample-data-cassandra/pom.xml | 131 --------- .../java/sample/data/cassandra/Customer.java | 48 ---- .../data/cassandra/CustomerRepository.java | 32 --- .../cassandra/SampleCassandraApplication.java | 64 ----- ...OrderedCassandraTestExecutionListener.java | 44 --- .../SampleCassandraApplicationTests.java | 56 ---- .../README.adoc | 27 -- .../spring-boot-sample-data-couchbase/pom.xml | 37 --- .../couchbase/SampleCouchbaseApplication.java | 51 ---- .../main/java/sample/data/couchbase/User.java | 66 ----- .../sample/data/couchbase/UserRepository.java | 25 -- .../SampleCouchbaseApplicationTests.java | 59 ----- .../pom.xml | 42 --- .../sample/data/elasticsearch/Customer.java | 69 ----- .../elasticsearch/CustomerRepository.java | 29 -- .../SampleElasticsearchApplication.java | 68 ----- .../SampleElasticsearchApplicationTests.java | 63 ----- .../spring-boot-sample-data-jdbc/pom.xml | 48 ---- .../main/java/sample/data/jdbc/Customer.java | 56 ---- .../sample/data/jdbc/CustomerRepository.java | 30 --- .../sample/data/jdbc/SampleController.java | 43 --- .../data/jdbc/SampleDataJdbcApplication.java | 29 -- .../CustomerRepositoryIntegrationTests.java | 53 ---- .../jdbc/SampleDataJdbcApplicationTests.java | 57 ---- .../spring-boot-sample-data-jpa/pom.xml | 48 ---- .../data/jpa/SampleDataJpaApplication.java | 29 -- .../java/sample/data/jpa/domain/City.java | 78 ------ .../java/sample/data/jpa/domain/Hotel.java | 84 ------ .../sample/data/jpa/domain/HotelSummary.java | 31 --- .../java/sample/data/jpa/domain/Rating.java | 23 -- .../sample/data/jpa/domain/RatingCount.java | 25 -- .../java/sample/data/jpa/domain/Review.java | 132 --------- .../sample/data/jpa/domain/ReviewDetails.java | 79 ------ .../java/sample/data/jpa/domain/TripType.java | 23 -- .../data/jpa/service/CityRepository.java | 33 --- .../data/jpa/service/CitySearchCriteria.java | 45 ---- .../sample/data/jpa/service/CityService.java | 33 --- .../data/jpa/service/CityServiceImpl.java | 77 ------ .../data/jpa/service/HotelRepository.java | 43 --- .../sample/data/jpa/service/HotelService.java | 39 --- .../data/jpa/service/HotelServiceImpl.java | 99 ------- .../data/jpa/service/ReviewRepository.java | 34 --- .../data/jpa/service/ReviewsSummary.java | 25 -- .../sample/data/jpa/web/SampleController.java | 40 --- .../jpa/SampleDataJpaApplicationTests.java | 72 ----- .../CityRepositoryIntegrationTests.java | 45 ---- .../HotelRepositoryIntegrationTests.java | 62 ----- .../spring-boot-sample-data-ldap/pom.xml | 46 ---- .../main/java/sample/data/ldap/Person.java | 39 --- .../sample/data/ldap/PersonRepository.java | 25 -- .../data/ldap/SampleLdapApplication.java | 53 ---- .../data/ldap/SampleLdapApplicationTests.java | 42 --- .../spring-boot-sample-data-mongodb/pom.xml | 46 ---- .../main/java/sample/data/mongo/Customer.java | 43 --- .../sample/data/mongo/CustomerRepository.java | 29 -- .../data/mongo/SampleMongoApplication.java | 72 ----- .../mongo/SampleMongoApplicationTests.java | 43 --- .../spring-boot-sample-data-neo4j/README.adoc | 16 -- .../spring-boot-sample-data-neo4j/pom.xml | 38 --- .../main/java/sample/data/neo4j/Customer.java | 47 ---- .../sample/data/neo4j/CustomerRepository.java | 29 -- .../data/neo4j/SampleNeo4jApplication.java | 62 ----- .../neo4j/SampleNeo4jApplicationTests.java | 56 ---- .../spring-boot-sample-data-redis/pom.xml | 52 ---- .../data/redis/SampleRedisApplication.java | 47 ---- .../redis/SampleRedisApplicationTests.java | 57 ---- .../spring-boot-sample-data-rest/pom.xml | 81 ------ .../data/rest/SampleDataRestApplication.java | 29 -- .../java/sample/data/rest/domain/City.java | 78 ------ .../java/sample/data/rest/domain/Hotel.java | 78 ------ .../data/rest/service/CityRepository.java | 35 --- .../data/rest/service/CitySearchCriteria.java | 45 ---- .../data/rest/service/HotelRepository.java | 30 --- .../rest/SampleDataRestApplicationTests.java | 75 ------ .../CityRepositoryIntegrationTests.java | 61 ----- .../spring-boot-sample-data-solr/pom.xml | 38 --- .../main/java/sample/data/solr/Product.java | 100 ------- .../sample/data/solr/ProductRepository.java | 27 -- .../data/solr/SampleSolrApplication.java | 61 ----- .../data/solr/SampleSolrApplicationTests.java | 55 ---- .../spring-boot-sample-devtools/pom.xml | 46 ---- .../main/java/sample/devtools/Message.java | 29 -- .../java/sample/devtools/MyController.java | 48 ---- .../devtools/SampleDevToolsApplication.java | 29 -- ...leDevToolsApplicationIntegrationTests.java | 62 ----- .../spring-boot-sample-flyway/README.adoc | 9 - .../spring-boot-sample-flyway/pom.xml | 70 ----- .../src/main/java/sample/flyway/Person.java | 57 ---- .../java/sample/flyway/PersonRepository.java | 25 -- .../flyway/SampleFlywayApplication.java | 43 --- .../flyway/SampleFlywayApplicationTests.java | 38 --- .../spring-boot-sample-hateoas/pom.xml | 38 --- .../hateoas/SampleHateoasApplication.java | 29 -- .../java/sample/hateoas/domain/Customer.java | 45 ---- .../hateoas/domain/CustomerRepository.java | 27 -- .../domain/InMemoryCustomerRepository.java | 51 ---- .../hateoas/web/CustomerController.java | 63 ----- .../SampleHateoasApplicationTests.java | 59 ----- .../spring-boot-sample-integration/pom.xml | 48 ---- .../sample/integration/HelloWorldService.java | 34 --- .../integration/SampleApplicationRunner.java | 39 --- .../sample/integration/SampleEndpoint.java | 43 --- .../SampleIntegrationApplication.java | 84 ------ .../integration/SampleMessageGateway.java | 26 -- .../sample/integration/ServiceProperties.java | 60 ----- .../SampleIntegrationApplicationTests.java | 116 -------- .../producer/ProducerApplication.java | 58 ---- .../spring-boot-sample-jersey/pom.xml | 71 ----- .../src/main/java/sample/jersey/Endpoint.java | 39 --- .../main/java/sample/jersey/JerseyConfig.java | 31 --- .../java/sample/jersey/ReverseEndpoint.java | 35 --- .../jersey/SampleJerseyApplication.java | 30 --- .../src/main/java/sample/jersey/Service.java | 32 --- ...ApplicationPathAndManagementPortTests.java | 57 ---- .../jersey/SampleJerseyApplicationTests.java | 62 ----- .../spring-boot-sample-jetty-jsp/pom.xml | 126 --------- .../java/sample/jetty/jsp/MyException.java | 25 -- .../java/sample/jetty/jsp/MyRestResponse.java | 31 --- .../jetty/jsp/SampleJettyJspApplication.java | 36 --- .../sample/jetty/jsp/WelcomeController.java | 59 ----- .../jsp/SampleWebJspApplicationTests.java | 48 ---- .../spring-boot-sample-jetty-ssl/pom.xml | 54 ---- .../jetty/ssl/SampleJettySslApplication.java | 29 -- .../jetty/ssl/web/SampleController.java | 30 --- .../ssl/SampleJettySslApplicationTests.java | 57 ---- .../spring-boot-sample-jetty/pom.xml | 49 ---- .../jetty/ExampleServletContextListener.java | 40 --- .../sample/jetty/SampleJettyApplication.java | 29 -- .../jetty/service/HelloWorldService.java | 32 --- .../sample/jetty/web/SampleController.java | 38 --- .../jetty/SampleJettyApplicationTests.java | 69 ----- .../spring-boot-sample-jooq/README.adoc | 9 - .../main/java/sample/jooq/domain/Author.java | 141 ---------- .../main/java/sample/jooq/domain/Book.java | 144 ---------- .../java/sample/jooq/domain/BookStore.java | 102 ------- .../sample/jooq/domain/BookToBookStore.java | 132 --------- .../sample/jooq/domain/DefaultCatalog.java | 53 ---- .../main/java/sample/jooq/domain/Keys.java | 97 ------- .../java/sample/jooq/domain/Language.java | 122 --------- .../main/java/sample/jooq/domain/Public.java | 83 ------ .../main/java/sample/jooq/domain/Tables.java | 41 --- .../spring-boot-sample-jooq/pom.xml | 199 -------------- .../main/java/sample/jooq/JooqExamples.java | 77 ------ .../sample/jooq/SampleJooqApplication.java | 29 -- .../util/TangleFreeGeneratorStrategy.java | 33 --- .../jooq/SampleJooqApplicationTests.java | 43 --- .../spring-boot-sample-jpa/pom.xml | 88 ------ .../java/sample/jpa/SampleJpaApplication.java | 29 -- .../src/main/java/sample/jpa/domain/Note.java | 74 ------ .../src/main/java/sample/jpa/domain/Tag.java | 64 ----- .../jpa/repository/JpaNoteRepository.java | 39 --- .../jpa/repository/JpaTagRepository.java | 39 --- .../sample/jpa/repository/NoteRepository.java | 27 -- .../sample/jpa/repository/TagRepository.java | 27 -- .../java/sample/jpa/web/IndexController.java | 45 ---- .../sample/jpa/SampleJpaApplicationTests.java | 58 ---- .../JpaNoteRepositoryIntegrationTests.java | 50 ---- .../JpaTagRepositoryIntegrationTests.java | 50 ---- .../spring-boot-sample-jta-atomikos/pom.xml | 78 ------ .../main/java/sample/atomikos/Account.java | 43 --- .../sample/atomikos/AccountRepository.java | 23 -- .../java/sample/atomikos/AccountService.java | 45 ---- .../main/java/sample/atomikos/Messages.java | 30 --- .../atomikos/SampleAtomikosApplication.java | 45 ---- .../SampleAtomikosApplicationTests.java | 60 ----- .../spring-boot-sample-jta-bitronix/pom.xml | 78 ------ .../main/java/sample/bitronix/Account.java | 43 --- .../sample/bitronix/AccountRepository.java | 23 -- .../java/sample/bitronix/AccountService.java | 45 ---- .../main/java/sample/bitronix/Messages.java | 30 --- .../bitronix/SampleBitronixApplication.java | 45 ---- .../SampleBitronixApplicationTests.java | 74 ------ .../spring-boot-sample-jta-jndi/README.adoc | 148 ----------- .../spring-boot-sample-jta-jndi/pom.xml | 59 ----- .../src/main/java/sample/jndi/Account.java | 43 --- .../java/sample/jndi/AccountRepository.java | 23 -- .../main/java/sample/jndi/AccountService.java | 45 ---- .../src/main/java/sample/jndi/Messages.java | 30 --- .../sample/jndi/SampleJndiApplication.java | 24 -- .../sample/jndi/SampleJndiInitializer.java | 29 -- .../main/java/sample/jndi/WebController.java | 49 ---- .../spring-boot-sample-junit-jupiter/pom.xml | 46 ---- .../main/java/sample/MessageController.java | 30 --- .../sample/SampleJUnitJupiterApplication.java | 29 -- .../SampleJUnitJupiterApplicationTests.java | 40 --- .../spring-boot-sample-junit-vintage/pom.xml | 28 -- .../main/java/sample/MessageController.java | 30 --- .../sample/SampleJUnitVintageApplication.java | 29 -- .../SampleJUnitVintageApplicationTests.java | 42 --- .../spring-boot-sample-kafka/pom.xml | 47 ---- .../src/main/java/sample/kafka/Consumer.java | 40 --- .../src/main/java/sample/kafka/Producer.java | 36 --- .../sample/kafka/SampleKafkaApplication.java | 43 --- .../main/java/sample/kafka/SampleMessage.java | 46 ---- .../src/main/resources/application.properties | 6 - .../kafka/SampleKafkaApplicationTests.java | 49 ---- .../spring-boot-sample-liquibase/README.adoc | 10 - .../spring-boot-sample-liquibase/pom.xml | 56 ---- .../liquibase/SampleLiquibaseApplication.java | 29 -- .../SampleLiquibaseApplicationTests.java | 66 ----- .../spring-boot-sample-logback/pom.xml | 38 --- .../logback/SampleLogbackApplication.java | 42 --- .../src/main/resources/logback-spring.xml | 8 - .../SampleLogbackApplicationTests.java | 42 --- .../README.adoc | 12 - .../spring-boot-sample-oauth2-client/pom.xml | 47 ---- .../oauth2/client/ExampleController.java | 32 --- .../client/SampleOAuth2ClientApplication.java | 29 -- .../SampleOAuth2ClientApplicationTests.java | 60 ----- .../pom.xml | 48 ---- .../oauth2/resource/ExampleController.java | 31 --- ...SampleOauth2ResourceServerApplication.java | 28 -- ...eOauth2ResourceServerApplicationTests.java | 105 -------- .../spring-boot-sample-parent-context/pom.xml | 47 ---- .../java/sample/parent/HelloWorldService.java | 34 --- .../java/sample/parent/SampleEndpoint.java | 43 --- .../SampleParentContextApplication.java | 92 ------- .../java/sample/parent/ServiceProperties.java | 60 ----- ...mpleIntegrationParentApplicationTests.java | 105 -------- .../parent/producer/ProducerApplication.java | 58 ---- .../spring-boot-sample-profile/pom.xml | 38 --- .../profile/SampleProfileApplication.java | 45 ---- .../profile/service/GenericService.java | 38 --- .../profile/service/GoodbyeWorldService.java | 35 --- .../profile/service/HelloWorldService.java | 35 --- .../profile/service/MessageService.java | 23 -- .../SampleProfileApplicationTests.java | 81 ------ .../pom.xml | 44 --- .../propertyvalidation/SampleProperties.java | 52 ---- .../SamplePropertiesValidator.java | 44 --- .../SamplePropertyValidationApplication.java | 51 ---- ...plePropertyValidationApplicationTests.java | 81 ------ .../spring-boot-sample-quartz/README.adoc | 11 - .../spring-boot-sample-quartz/pom.xml | 37 --- .../main/java/sample/quartz/SampleJob.java | 38 --- .../quartz/SampleQuartzApplication.java | 51 ---- .../quartz/SampleQuartzApplicationTests.java | 48 ---- .../README.adoc | 12 - .../pom.xml | 47 ---- .../oauth2/client/ExampleController.java | 32 --- ...SampleReactiveOAuth2ClientApplication.java | 29 -- ...eReactiveOAuth2ClientApplicationTests.java | 51 ---- .../pom.xml | 48 ---- .../oauth2/resource/ExampleController.java | 32 --- ...activeOAuth2ResourceServerApplication.java | 29 -- ...eOAuth2ResourceServerApplicationTests.java | 93 ------- .../spring-boot-sample-secure-webflux/pom.xml | 60 ----- .../sample/secure/webflux/EchoHandler.java | 32 --- .../SampleSecureWebFluxApplication.java | 40 --- .../secure/webflux/WelcomeController.java | 32 --- ...anagementPortSampleSecureWebFluxTests.java | 103 -------- .../SampleSecureWebFluxApplicationTests.java | 82 ------ ...ampleSecureWebFluxCustomSecurityTests.java | 126 --------- .../spring-boot-sample-secure/pom.xml | 38 --- .../secure/SampleSecureApplication.java | 53 ---- .../java/sample/secure/SampleService.java | 41 --- .../secure/SampleSecureApplicationTests.java | 82 ------ .../spring-boot-sample-servlet/pom.xml | 50 ---- .../servlet/SampleServletApplication.java | 59 ----- .../SampleServletApplicationTests.java | 68 ----- .../README.adoc | 37 --- .../pom.xml | 76 ------ .../sample/session/HelloRestController.java | 31 --- .../SampleSessionWebFluxApplication.java | 48 ---- .../SampleSessionWebFluxApplicationTests.java | 69 ----- .../spring-boot-sample-session/README.adoc | 60 ----- .../spring-boot-sample-session/pom.xml | 106 -------- .../sample/session/HelloRestController.java | 32 --- .../session/SampleSessionApplication.java | 29 -- .../SampleSessionApplicationTests.java | 80 ------ .../spring-boot-sample-simple/pom.xml | 52 ---- .../java/sample/simple/ExitException.java | 28 -- .../simple/SampleConfigurationProperties.java | 39 --- .../simple/SampleSimpleApplication.java | 48 ---- .../simple/service/HelloWorldService.java | 37 --- .../simple/SampleSimpleApplicationTests.java | 67 ----- ...pringTestSampleSimpleApplicationTests.java | 45 ---- .../spring-boot-sample-test-nomockito/pom.xml | 53 ---- .../SampleTestNoMockitoApplication.java | 29 -- .../SampleTestNoMockitoApplicationTests.java | 48 ---- .../spring-boot-sample-test/pom.xml | 78 ------ .../sample/test/SampleTestApplication.java | 37 --- .../sample/test/WelcomeCommandLineRunner.java | 36 --- .../main/java/sample/test/domain/User.java | 65 ----- .../sample/test/domain/UserRepository.java | 30 --- .../domain/VehicleIdentificationNumber.java | 57 ---- ...dentificationNumberAttributeConverter.java | 41 --- .../service/RemoteVehicleDetailsService.java | 62 ----- .../test/service/ServiceProperties.java | 39 --- .../sample/test/service/VehicleDetails.java | 68 ----- .../test/service/VehicleDetailsService.java | 37 --- ...IdentificationNumberNotFoundException.java | 43 --- .../test/web/UserNameNotFoundException.java | 35 --- .../test/web/UserVehicleController.java | 68 ----- .../sample/test/web/UserVehicleService.java | 55 ---- ...pleTestApplicationWebIntegrationTests.java | 61 ----- .../sample/test/domain/UserEntityTests.java | 66 ----- .../test/domain/UserRepositoryTests.java | 58 ---- .../VehicleIdentificationNumberTests.java | 69 ----- .../RemoteVehicleDetailsServiceTests.java | 87 ------ .../test/service/VehicleDetailsJsonTests.java | 54 ---- ...UserVehicleControllerApplicationTests.java | 70 ----- .../UserVehicleControllerHtmlUnitTests.java | 52 ---- .../UserVehicleControllerSeleniumTests.java | 54 ---- .../test/web/UserVehicleControllerTests.java | 100 ------- .../test/web/UserVehicleServiceTests.java | 80 ------ .../spring-boot-sample-testng/pom.xml | 62 ----- .../testng/SampleTestNGApplication.java | 55 ---- .../testng/service/HelloWorldService.java | 32 --- .../sample/testng/web/SampleController.java | 38 --- .../testng/SampleTestNGApplicationTests.java | 49 ---- .../spring-boot-sample-tomcat-jsp/pom.xml | 57 ---- .../java/sample/tomcat/jsp/MyException.java | 25 -- .../sample/tomcat/jsp/MyRestResponse.java | 31 --- .../jsp/SampleTomcatJspApplication.java | 36 --- .../sample/tomcat/jsp/WelcomeController.java | 60 ----- .../jsp/SampleWebJspApplicationTests.java | 48 ---- .../pom.xml | 43 --- .../SampleTomcatTwoConnectorsApplication.java | 53 ---- .../multiconnector/web/SampleController.java | 30 --- ...leTomcatTwoConnectorsApplicationTests.java | 111 -------- .../spring-boot-sample-tomcat-ssl/pom.xml | 43 --- .../ssl/SampleTomcatSslApplication.java | 29 -- .../tomcat/ssl/web/SampleController.java | 30 --- .../ssl/SampleTomcatSslApplicationTests.java | 52 ---- .../spring-boot-sample-tomcat/pom.xml | 46 ---- .../tomcat/SampleTomcatApplication.java | 55 ---- .../tomcat/service/HelloWorldService.java | 32 --- .../sample/tomcat/web/SampleController.java | 38 --- ...igurationSampleTomcatApplicationTests.java | 72 ----- .../tomcat/SampleTomcatApplicationTests.java | 86 ------ .../spring-boot-sample-traditional/pom.xml | 55 ---- .../SampleTraditionalApplication.java | 29 -- .../sample/traditional/config/WebConfig.java | 58 ---- .../SampleTraditionalApplicationTests.java | 57 ---- .../spring-boot-sample-undertow-ssl/pom.xml | 52 ---- .../ssl/SampleUndertowSslApplication.java | 29 -- .../undertow/ssl/web/SampleController.java | 30 --- .../SampleUndertowSslApplicationTests.java | 57 ---- .../spring-boot-sample-undertow/pom.xml | 48 ---- .../undertow/SampleUndertowApplication.java | 29 -- .../sample/undertow/web/SampleController.java | 37 --- .../SampleUndertowApplicationTests.java | 79 ------ .../spring-boot-sample-war/pom.xml | 94 ------- .../main/java/sample/war/MyController.java | 30 --- .../java/sample/war/SampleWarApplication.java | 32 --- .../war/WarApplicationResourceTests.java | 39 --- .../spring-boot-sample-web-freemarker/pom.xml | 53 ---- .../SampleWebFreeMarkerApplication.java | 29 -- .../sample/freemarker/WelcomeController.java | 39 --- .../SampleWebFreeMarkerApplicationTests.java | 68 ----- .../README.adoc | 6 - .../pom.xml | 52 ---- .../InMemoryMessageRepository.java | 50 ---- .../java/sample/groovytemplates/Message.java | 67 ----- .../groovytemplates/MessageRepository.java | 27 -- .../SampleGroovyTemplateApplication.java | 46 ---- .../mvc/MessageController.java | 91 ------- .../MessageControllerWebTests.java | 105 -------- .../SampleGroovyTemplateApplicationTests.java | 73 ----- .../spring-boot-sample-web-jsp/pom.xml | 62 ----- .../sample/jsp/SampleWebJspApplication.java | 36 --- .../java/sample/jsp/WelcomeController.java | 45 ---- .../jsp/SampleWebJspApplicationTests.java | 65 ----- .../pom.xml | 50 ---- .../SampleMethodSecurityApplication.java | 120 --------- .../SampleMethodSecurityApplicationTests.java | 131 --------- .../spring-boot-sample-web-mustache/pom.xml | 50 ---- .../SampleWebMustacheApplication.java | 29 -- .../sample/mustache/WelcomeController.java | 67 ----- .../SampleWebMustacheApplicationTests.java | 99 ------- .../pom.xml | 51 ---- .../SampleWebSecureCustomApplication.java | 70 ----- ...SampleWebSecureCustomApplicationTests.java | 110 -------- .../pom.xml | 59 ----- .../jdbc/SampleWebSecureJdbcApplication.java | 81 ------ .../SampleWebSecureJdbcApplicationTests.java | 110 -------- .../spring-boot-sample-web-secure/pom.xml | 55 ---- .../secure/SampleWebSecureApplication.java | 78 ------ .../secure/SampleSecureApplicationTests.java | 110 -------- .../spring-boot-sample-web-static/pom.xml | 55 ---- .../SampleWebStaticApplication.java | 36 --- .../SampleWebStaticApplicationTests.java | 58 ---- .../spring-boot-sample-web-ui/pom.xml | 46 ---- .../web/ui/InMemoryMessageRepository.java | 55 ---- .../src/main/java/sample/web/ui/Message.java | 67 ----- .../java/sample/web/ui/MessageRepository.java | 29 -- .../sample/web/ui/SampleWebUiApplication.java | 46 ---- .../sample/web/ui/mvc/MessageController.java | 87 ------ .../web/ui/MessageControllerWebTests.java | 105 -------- .../web/ui/SampleWebUiApplicationTests.java | 74 ------ .../spring-boot-sample-webflux/pom.xml | 56 ---- .../main/java/sample/webflux/EchoHandler.java | 32 --- .../sample/webflux/ExampleController.java | 32 --- .../webflux/SampleWebFluxApplication.java | 40 --- .../sample/webflux/WelcomeController.java | 30 --- .../SampleWebFluxApplicationTests.java | 58 ---- .../README.adoc | 14 - .../spring-boot-sample-webservices/pom.xml | 68 ----- .../SampleWebServicesApplication.java | 29 -- .../sample/webservices/WebServiceConfig.java | 38 --- .../webservices/endpoint/HolidayEndpoint.java | 70 ----- .../service/HumanResourceService.java | 25 -- .../service/StubHumanResourceService.java | 36 --- .../webservices/SampleWsApplicationTests.java | 64 ----- .../pom.xml | 48 ---- .../SampleJettyWebSocketsApplication.java | 90 ------- .../jetty/client/GreetingService.java | 23 -- .../client/SimpleClientWebSocketHandler.java | 60 ----- .../jetty/client/SimpleGreetingService.java | 26 -- .../jetty/echo/DefaultEchoService.java | 32 --- .../websocket/jetty/echo/EchoService.java | 23 -- .../jetty/echo/EchoWebSocketHandler.java | 58 ---- .../reverse/ReverseWebSocketEndpoint.java | 33 --- .../websocket/jetty/snake/Direction.java | 23 -- .../websocket/jetty/snake/Location.java | 78 ------ .../samples/websocket/jetty/snake/Snake.java | 156 ----------- .../websocket/jetty/snake/SnakeTimer.java | 117 -------- .../websocket/jetty/snake/SnakeUtils.java | 66 ----- .../jetty/snake/SnakeWebSocketHandler.java | 103 -------- .../SampleWebSocketsApplicationTests.java | 126 --------- ...omContainerWebSocketsApplicationTests.java | 141 ---------- .../jetty/snake/SnakeTimerTests.java | 40 --- .../pom.xml | 38 --- .../SampleTomcatWebSocketApplication.java | 90 ------- .../tomcat/client/GreetingService.java | 23 -- .../client/SimpleClientWebSocketHandler.java | 60 ----- .../tomcat/client/SimpleGreetingService.java | 26 -- .../tomcat/echo/DefaultEchoService.java | 32 --- .../websocket/tomcat/echo/EchoService.java | 23 -- .../tomcat/echo/EchoWebSocketHandler.java | 58 ---- .../reverse/ReverseWebSocketEndpoint.java | 33 --- .../websocket/tomcat/snake/Direction.java | 23 -- .../websocket/tomcat/snake/Location.java | 78 ------ .../samples/websocket/tomcat/snake/Snake.java | 156 ----------- .../websocket/tomcat/snake/SnakeTimer.java | 117 -------- .../websocket/tomcat/snake/SnakeUtils.java | 66 ----- .../tomcat/snake/SnakeWebSocketHandler.java | 103 -------- .../SampleWebSocketsApplicationTests.java | 126 --------- ...omContainerWebSocketsApplicationTests.java | 141 ---------- .../tomcat/snake/SnakeTimerTests.java | 39 --- .../pom.xml | 48 ---- .../SampleUndertowWebSocketsApplication.java | 90 ------- .../undertow/client/GreetingService.java | 23 -- .../client/SimpleClientWebSocketHandler.java | 60 ----- .../client/SimpleGreetingService.java | 26 -- .../undertow/echo/DefaultEchoService.java | 32 --- .../websocket/undertow/echo/EchoService.java | 23 -- .../undertow/echo/EchoWebSocketHandler.java | 58 ---- .../reverse/ReverseWebSocketEndpoint.java | 33 --- .../websocket/undertow/snake/Direction.java | 23 -- .../websocket/undertow/snake/Location.java | 78 ------ .../websocket/undertow/snake/Snake.java | 156 ----------- .../websocket/undertow/snake/SnakeTimer.java | 117 -------- .../websocket/undertow/snake/SnakeUtils.java | 66 ----- .../undertow/snake/SnakeWebSocketHandler.java | 103 -------- .../SampleWebSocketsApplicationTests.java | 126 --------- ...omContainerWebSocketsApplicationTests.java | 141 ---------- .../undertow/snake/SnakeTimerTests.java | 39 --- .../spring-boot-sample-xml/pom.xml | 38 --- .../xml/SampleSpringXmlApplication.java | 45 ---- .../sample/xml/service/HelloWorldService.java | 32 --- .../META-INF/application-context.xml | 14 - .../xml/SampleSpringXmlApplicationTests.java | 36 --- spring-boot-smoke-tests-invoker/pom.xml | 81 ++++++ spring-boot-smoke-tests/pom.xml | 250 ++++++++++++++++++ .../spring-boot-smoke-test-activemq/pom.xml | 38 +++ .../java/smoketest/activemq/Consumer.java | 30 +++ .../java/smoketest/activemq/Producer.java | 45 ++++ .../activemq/SampleActiveMQApplication.java | 41 +++ .../src/main/resources/application.properties | 0 .../activemq/SampleActiveMqTests.java | 48 ++++ .../pom.xml | 60 +++++ .../customsecurity/ExampleController.java | 42 +++ .../ExampleRestControllerEndpoint.java | 34 +++ ...mpleActuatorCustomSecurityApplication.java | 29 ++ .../customsecurity/SecurityConfiguration.java | 60 +++++ .../src/main/resources/application.properties | 0 .../resources/static/css/bootstrap.min.css | 0 .../src/main/resources/templates/error.ftlh | 0 .../src/main/resources/templates/home.ftlh | 0 .../CorsSampleActuatorApplicationTests.java | 83 ++++++ ...AndPathSampleActuatorApplicationTests.java | 85 ++++++ ...ctuatorCustomSecurityApplicationTests.java | 162 ++++++++++++ .../resources/application-cors.properties | 0 .../pom.xml | 60 +++++ .../SampleActuatorLog4J2Application.java | 29 ++ .../src/main/resources/application.properties | 0 .../src/main/resources/log4j2.xml | 0 .../SampleActuatorLog4J2ApplicationTests.java | 72 +++++ .../pom.xml | 44 +++ .../actuator/noweb/HelloWorldService.java | 34 +++ .../noweb/SampleActuatorNoWebApplication.java | 29 ++ .../actuator/noweb/ServiceProperties.java | 37 +++ .../src/main/resources/application.properties | 0 .../src/main/resources/banner.txt | 0 .../SampleActuatorNoWebApplicationTests.java | 36 +++ .../pom.xml | 54 ++++ .../ui/SampleActuatorUiApplication.java | 49 ++++ .../src/main/resources/application.properties | 0 .../resources/static/css/bootstrap.min.css | 0 .../src/main/resources/templates/error.ftlh | 0 .../src/main/resources/templates/home.ftlh | 0 .../SampleActuatorUiApplicationPortTests.java | 74 ++++++ .../ui/SampleActuatorUiApplicationTests.java | 87 ++++++ .../spring-boot-smoke-test-actuator/pom.xml | 86 ++++++ .../actuator/ExampleHealthIndicator.java | 31 +++ .../actuator/ExampleInfoContributor.java | 33 +++ .../smoketest/actuator/HelloWorldService.java | 34 +++ .../actuator/SampleActuatorApplication.java | 37 +++ .../smoketest/actuator/SampleController.java | 82 ++++++ .../smoketest/actuator/ServiceProperties.java | 37 +++ .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 ...pertiesSampleActuatorApplicationTests.java | 70 +++++ ...gementAddressActuatorApplicationTests.java | 67 +++++ ...entPathSampleActuatorApplicationTests.java | 67 +++++ ...AndPathSampleActuatorApplicationTests.java | 124 +++++++++ ...entPortSampleActuatorApplicationTests.java | 93 +++++++ ...gementPortWithLazyInitializationTests.java | 50 ++++ ...agementSampleActuatorApplicationTests.java | 67 +++++ .../SampleActuatorApplicationTests.java | 195 ++++++++++++++ ...letPathSampleActuatorApplicationTests.java | 78 ++++++ ...hutdownSampleActuatorApplicationTests.java | 85 ++++++ .../application-endpoints.properties | 0 .../docker-compose.yml | 0 .../spring-boot-smoke-test-amqp/pom.xml | 39 +++ .../amqp/SampleAmqpSimpleApplication.java | 54 ++++ .../src/main/java/smoketest/amqp/Sender.java | 33 +++ .../pom.xml | 38 +++ .../SampleAnimatedBannerApplication.java | 29 ++ .../src/main/resources/banner.gif | Bin .../spring-boot-smoke-test-ant/build.xml | 69 +++++ .../spring-boot-smoke-test-ant/ivy.xml | 12 + .../ivysettings.xml | 0 .../spring-boot-smoke-test-ant/pom.xml | 107 ++++++++ .../smoketest/ant/SampleAntApplication.java | 35 +++ .../smoketest/ant/SampleAntApplicationIT.java | 58 ++++ .../src/test/resources/application.properties | 0 .../spring-boot-smoke-test-aop/pom.xml | 38 +++ .../smoketest/aop/SampleAopApplication.java | 43 +++ .../smoketest/aop/monitor/ServiceMonitor.java | 34 +++ .../aop/service/HelloWorldService.java | 32 +++ .../src/main/resources/application.properties | 0 .../aop/SampleAopApplicationTests.java | 67 +++++ .../spring-boot-smoke-test-atmosphere/pom.xml | 58 ++++ .../smoketest/atmosphere/ChatService.java | 81 ++++++ .../java/smoketest/atmosphere/Message.java | 53 ++++ .../SampleAtmosphereApplication.java | 88 ++++++ .../src/main/resources/application.properties | 0 .../src/main/resources/static/home.html | 0 .../static/javascript/application.js | 0 .../static/javascript/jquery-1.9.0.js | 0 .../SampleAtmosphereApplicationTests.java | 120 +++++++++ .../spring-boot-smoke-test-batch/pom.xml | 44 +++ .../batch/SampleBatchApplication.java | 71 +++++ .../batch/SampleBatchApplicationTests.java | 37 +++ .../spring-boot-smoke-test-cache/pom.xml | 128 +++++++++ .../smoketest/cache/CacheManagerCheck.java | 44 +++ .../main/java/smoketest/cache/Country.java | 53 ++++ .../smoketest/cache/CountryRepository.java | 33 +++ .../cache/SampleCacheApplication.java | 33 +++ .../java/smoketest/cache/SampleClient.java | 63 +++++ .../src/main/resources/application.properties | 0 .../src/main/resources/ehcache.xml | 0 .../src/main/resources/ehcache3.xml | 0 .../src/main/resources/hazelcast.xml | 0 .../src/main/resources/infinispan.xml | 0 .../cache/SampleCacheApplicationTests.java | 47 ++++ .../pom.xml | 114 ++++++++ .../src/it/custom/pom.xml | 43 +++ .../main/java/org/test/SampleApplication.java | 0 .../src/it/custom/verify.groovy | 6 + .../src/it/default/pom.xml | 0 .../main/java/org/test/SampleApplication.java | 0 .../src/it/default/verify.groovy | 6 + .../java/smoketest/layout/SampleLayout.java | 44 +++ .../smoketest/layout/SampleLayoutFactory.java | 48 ++++ .../main/resources/META-INF/spring.factories | 2 + .../test/java/smoketest/layout/Verify.java | 41 +++ .../pom.xml | 131 +++++++++ .../smoketest/data/cassandra/Customer.java | 48 ++++ .../data/cassandra/CustomerRepository.java | 32 +++ .../cassandra/SampleCassandraApplication.java | 64 +++++ .../src/main/resources/application.properties | 0 ...OrderedCassandraTestExecutionListener.java | 44 +++ .../SampleCassandraApplicationTests.java | 56 ++++ .../src/test/resources/setup.cql | 0 .../pom.xml | 37 +++ .../couchbase/SampleCouchbaseApplication.java | 51 ++++ .../java/smoketest/data/couchbase/User.java | 66 +++++ .../data/couchbase/UserRepository.java | 25 ++ .../src/main/resources/application.properties | 0 .../SampleCouchbaseApplicationTests.java | 59 +++++ .../pom.xml | 42 +++ .../data/elasticsearch/Customer.java | 69 +++++ .../elasticsearch/CustomerRepository.java | 29 ++ .../SampleElasticsearchApplication.java | 68 +++++ .../src/main/resources/application.properties | 0 .../SampleElasticsearchApplicationTests.java | 63 +++++ .../spring-boot-smoke-test-data-jdbc/pom.xml | 48 ++++ .../java/smoketest/data/jdbc/Customer.java | 56 ++++ .../data/jdbc/CustomerRepository.java | 30 +++ .../smoketest/data/jdbc/SampleController.java | 43 +++ .../data/jdbc/SampleDataJdbcApplication.java | 29 ++ .../src/main/resources/data.sql | 0 .../src/main/resources/schema.sql | 0 .../CustomerRepositoryIntegrationTests.java | 53 ++++ .../jdbc/SampleDataJdbcApplicationTests.java | 57 ++++ .../spring-boot-smoke-test-data-jpa/pom.xml | 48 ++++ .../data/jpa/SampleDataJpaApplication.java | 29 ++ .../java/smoketest/data/jpa/domain/City.java | 78 ++++++ .../java/smoketest/data/jpa/domain/Hotel.java | 84 ++++++ .../data/jpa/domain/HotelSummary.java | 31 +++ .../smoketest/data/jpa/domain/Rating.java | 23 ++ .../data/jpa/domain/RatingCount.java | 25 ++ .../smoketest/data/jpa/domain/Review.java | 132 +++++++++ .../data/jpa/domain/ReviewDetails.java | 79 ++++++ .../smoketest/data/jpa/domain/TripType.java | 23 ++ .../data/jpa/service/CityRepository.java | 33 +++ .../data/jpa/service/CitySearchCriteria.java | 45 ++++ .../data/jpa/service/CityService.java | 33 +++ .../data/jpa/service/CityServiceImpl.java | 77 ++++++ .../data/jpa/service/HotelRepository.java | 43 +++ .../data/jpa/service/HotelService.java | 39 +++ .../data/jpa/service/HotelServiceImpl.java | 99 +++++++ .../data/jpa/service/ReviewRepository.java | 34 +++ .../data/jpa/service/ReviewsSummary.java | 25 ++ .../data/jpa/web/SampleController.java | 40 +++ .../src/main/resources/application.properties | 0 .../src/main/resources/import.sql | 0 .../jpa/SampleDataJpaApplicationTests.java | 72 +++++ .../CityRepositoryIntegrationTests.java | 45 ++++ .../HotelRepositoryIntegrationTests.java | 62 +++++ .../resources/application-scratch.properties | 0 .../spring-boot-smoke-test-data-ldap/pom.xml | 46 ++++ .../main/java/smoketest/data/ldap/Person.java | 39 +++ .../smoketest/data/ldap/PersonRepository.java | 25 ++ .../data/ldap/SampleLdapApplication.java | 53 ++++ .../src/main/resources/application.properties | 0 .../src/main/resources/schema.ldif | 0 .../data/ldap/SampleLdapApplicationTests.java | 42 +++ .../pom.xml | 46 ++++ .../java/smoketest/data/mongo/Customer.java | 43 +++ .../data/mongo/CustomerRepository.java | 29 ++ .../data/mongo/SampleMongoApplication.java | 72 +++++ .../mongo/SampleMongoApplicationTests.java | 43 +++ .../spring-boot-smoke-test-data-neo4j/pom.xml | 38 +++ .../java/smoketest/data/neo4j/Customer.java | 47 ++++ .../data/neo4j/CustomerRepository.java | 29 ++ .../data/neo4j/SampleNeo4jApplication.java | 62 +++++ .../src/main/resources/application.properties | 0 .../neo4j/SampleNeo4jApplicationTests.java | 56 ++++ .../spring-boot-smoke-test-data-redis/pom.xml | 52 ++++ .../data/redis/SampleRedisApplication.java | 47 ++++ .../redis/SampleRedisApplicationTests.java | 57 ++++ .../spring-boot-smoke-test-data-rest/pom.xml | 81 ++++++ .../data/rest/SampleDataRestApplication.java | 29 ++ .../java/smoketest/data/rest/domain/City.java | 78 ++++++ .../smoketest/data/rest/domain/Hotel.java | 78 ++++++ .../data/rest/service/CityRepository.java | 35 +++ .../data/rest/service/CitySearchCriteria.java | 45 ++++ .../data/rest/service/HotelRepository.java | 30 +++ .../src/main/resources/application.properties | 0 .../src/main/resources/import.sql | 0 .../rest/SampleDataRestApplicationTests.java | 75 ++++++ .../CityRepositoryIntegrationTests.java | 61 +++++ .../resources/application-scratch.properties | 0 .../spring-boot-smoke-test-data-solr/pom.xml | 38 +++ .../java/smoketest/data/solr/Product.java | 100 +++++++ .../data/solr/ProductRepository.java | 27 ++ .../data/solr/SampleSolrApplication.java | 61 +++++ .../data/solr/SampleSolrApplicationTests.java | 55 ++++ .../spring-boot-smoke-test-devtools/pom.xml | 46 ++++ .../main/java/smoketest/devtools/Message.java | 29 ++ .../java/smoketest/devtools/MyController.java | 48 ++++ .../devtools/SampleDevToolsApplication.java | 29 ++ .../src/main/resources/application.properties | 0 .../src/main/resources/public/public.txt | 0 .../main/resources/static/css/application.css | 0 .../src/main/resources/templates/hello.html | 0 ...leDevToolsApplicationIntegrationTests.java | 62 +++++ .../spring-boot-smoke-test-flyway/pom.xml | 70 +++++ .../main/java/smoketest/flyway/Person.java | 57 ++++ .../smoketest/flyway/PersonRepository.java | 25 ++ .../flyway/SampleFlywayApplication.java | 43 +++ .../src/main/resources/application.properties | 0 .../main/resources/db/migration/V1__init.sql | 0 .../flyway/SampleFlywayApplicationTests.java | 38 +++ .../spring-boot-smoke-test-hateoas/pom.xml | 38 +++ .../hateoas/SampleHateoasApplication.java | 29 ++ .../smoketest/hateoas/domain/Customer.java | 45 ++++ .../hateoas/domain/CustomerRepository.java | 27 ++ .../domain/InMemoryCustomerRepository.java | 51 ++++ .../hateoas/web/CustomerController.java | 63 +++++ .../SampleHateoasApplicationTests.java | 59 +++++ .../pom.xml | 48 ++++ .../integration/HelloWorldService.java | 34 +++ .../integration/SampleApplicationRunner.java | 39 +++ .../smoketest/integration/SampleEndpoint.java | 43 +++ .../SampleIntegrationApplication.java | 84 ++++++ .../integration/SampleMessageGateway.java | 26 ++ .../integration/ServiceProperties.java | 60 +++++ .../src/main/resources/application.properties | 0 .../SampleIntegrationApplicationTests.java | 116 ++++++++ .../producer/ProducerApplication.java | 58 ++++ .../spring-boot-smoke-test-jersey/pom.xml | 71 +++++ .../main/java/smoketest/jersey/Endpoint.java | 39 +++ .../java/smoketest/jersey/JerseyConfig.java | 31 +++ .../smoketest/jersey/ReverseEndpoint.java | 35 +++ .../jersey/SampleJerseyApplication.java | 30 +++ .../main/java/smoketest/jersey/Service.java | 32 +++ ...ApplicationPathAndManagementPortTests.java | 57 ++++ .../jersey/SampleJerseyApplicationTests.java | 62 +++++ .../spring-boot-smoke-test-jetty-jsp/pom.xml | 126 +++++++++ .../java/smoketest/jetty/jsp/MyException.java | 25 ++ .../smoketest/jetty/jsp/MyRestResponse.java | 31 +++ .../jetty/jsp/SampleJettyJspApplication.java | 36 +++ .../jetty/jsp/WelcomeController.java | 59 +++++ .../src/main/resources/application.properties | 0 .../src/main/webapp/WEB-INF/jsp/welcome.jsp | 0 .../jsp/SampleWebJspApplicationTests.java | 48 ++++ .../spring-boot-smoke-test-jetty-ssl/pom.xml | 54 ++++ .../jetty/ssl/SampleJettySslApplication.java | 29 ++ .../jetty/ssl/web/SampleController.java | 30 +++ .../src/main/resources/application.properties | 0 .../src/main/resources/sample.jks | Bin .../ssl/SampleJettySslApplicationTests.java | 57 ++++ .../spring-boot-smoke-test-jetty/pom.xml | 49 ++++ .../jetty/ExampleServletContextListener.java | 40 +++ .../jetty/SampleJettyApplication.java | 29 ++ .../jetty/service/HelloWorldService.java | 32 +++ .../smoketest/jetty/web/SampleController.java | 38 +++ .../src/main/resources/application.properties | 0 .../jetty/SampleJettyApplicationTests.java | 69 +++++ .../java/smoketest/jooq/domain/Author.java | 157 +++++++++++ .../main/java/smoketest/jooq/domain/Book.java | 160 +++++++++++ .../java/smoketest/jooq/domain/BookStore.java | 118 +++++++++ .../jooq/domain/BookToBookStore.java | 148 +++++++++++ .../smoketest/jooq/domain/DefaultCatalog.java | 69 +++++ .../main/java/smoketest/jooq/domain/Keys.java | 113 ++++++++ .../java/smoketest/jooq/domain/Language.java | 138 ++++++++++ .../java/smoketest/jooq/domain/Public.java | 99 +++++++ .../java/smoketest/jooq/domain/Tables.java | 57 ++++ .../spring-boot-smoke-test-jooq/pom.xml | 199 ++++++++++++++ .../java/smoketest/jooq/JooqExamples.java | 77 ++++++ .../smoketest/jooq/SampleJooqApplication.java | 29 ++ .../util/TangleFreeGeneratorStrategy.java | 33 +++ .../src/main/resources/data.sql | 0 .../src/main/resources/reset.sql | 0 .../src/main/resources/schema.sql | 0 .../jooq/SampleJooqApplicationTests.java | 43 +++ .../spring-boot-smoke-test-jpa/pom.xml | 88 ++++++ .../smoketest/jpa/SampleJpaApplication.java | 29 ++ .../main/java/smoketest/jpa/domain/Note.java | 74 ++++++ .../main/java/smoketest/jpa/domain/Tag.java | 64 +++++ .../jpa/repository/JpaNoteRepository.java | 39 +++ .../jpa/repository/JpaTagRepository.java | 39 +++ .../jpa/repository/NoteRepository.java | 27 ++ .../jpa/repository/TagRepository.java | 27 ++ .../smoketest/jpa/web/IndexController.java | 45 ++++ .../src/main/resources/application.properties | 0 .../src/main/resources/import.sql | 0 .../src/main/resources/templates/index.ftlh | 0 .../jpa/SampleJpaApplicationTests.java | 58 ++++ .../JpaNoteRepositoryIntegrationTests.java | 50 ++++ .../JpaTagRepositoryIntegrationTests.java | 50 ++++ .../pom.xml | 78 ++++++ .../main/java/smoketest/atomikos/Account.java | 43 +++ .../smoketest/atomikos/AccountRepository.java | 23 ++ .../smoketest/atomikos/AccountService.java | 45 ++++ .../java/smoketest/atomikos/Messages.java | 30 +++ .../atomikos/SampleAtomikosApplication.java | 45 ++++ .../src/main/resources/application.properties | 0 .../SampleAtomikosApplicationTests.java | 60 +++++ .../pom.xml | 78 ++++++ .../main/java/smoketest/bitronix/Account.java | 43 +++ .../smoketest/bitronix/AccountRepository.java | 23 ++ .../smoketest/bitronix/AccountService.java | 45 ++++ .../java/smoketest/bitronix/Messages.java | 30 +++ .../bitronix/SampleBitronixApplication.java | 45 ++++ .../src/main/resources/application.properties | 0 .../SampleBitronixApplicationTests.java | 74 ++++++ .../spring-boot-smoke-test-jta-jndi/pom.xml | 59 +++++ .../src/main/java/smoketest/jndi/Account.java | 43 +++ .../smoketest/jndi/AccountRepository.java | 23 ++ .../java/smoketest/jndi/AccountService.java | 45 ++++ .../main/java/smoketest/jndi/Messages.java | 30 +++ .../smoketest/jndi/SampleJndiApplication.java | 24 ++ .../smoketest/jndi/SampleJndiInitializer.java | 29 ++ .../java/smoketest/jndi/WebController.java | 49 ++++ .../src/main/resources/application.properties | 0 .../pom.xml | 46 ++++ .../java/smoketest/MessageController.java | 30 +++ .../SampleJUnitJupiterApplication.java | 29 ++ .../SampleJUnitJupiterApplicationTests.java | 40 +++ .../pom.xml | 28 ++ .../java/smoketest/MessageController.java | 30 +++ .../SampleJUnitVintageApplication.java | 29 ++ .../SampleJUnitVintageApplicationTests.java | 42 +++ .../spring-boot-smoke-test-kafka/pom.xml | 47 ++++ .../main/java/smoketest/kafka/Consumer.java | 40 +++ .../main/java/smoketest/kafka/Producer.java | 36 +++ .../kafka/SampleKafkaApplication.java | 43 +++ .../java/smoketest/kafka/SampleMessage.java | 46 ++++ .../src/main/resources/application.properties | 6 + .../kafka/SampleKafkaApplicationTests.java | 49 ++++ .../spring-boot-smoke-test-liquibase/pom.xml | 56 ++++ .../liquibase/SampleLiquibaseApplication.java | 29 ++ .../src/main/resources/application.properties | 0 .../db/changelog/db.changelog-master.yaml | 0 .../SampleLiquibaseApplicationTests.java | 66 +++++ .../spring-boot-smoke-test-logback/pom.xml | 38 +++ .../logback/SampleLogbackApplication.java | 42 +++ .../src/main/resources/logback-spring.xml | 8 + .../SampleLogbackApplicationTests.java | 42 +++ .../pom.xml | 47 ++++ .../oauth2/client/ExampleController.java | 32 +++ .../client/SampleOAuth2ClientApplication.java | 29 ++ .../src/main/resources/application.yml | 0 .../SampleOAuth2ClientApplicationTests.java | 60 +++++ .../pom.xml | 48 ++++ .../oauth2/resource/ExampleController.java | 31 +++ ...SampleOauth2ResourceServerApplication.java | 28 ++ .../src/main/resources/application.yml | 0 ...eOauth2ResourceServerApplicationTests.java | 105 ++++++++ .../pom.xml | 47 ++++ .../smoketest/parent/HelloWorldService.java | 34 +++ .../java/smoketest/parent/SampleEndpoint.java | 43 +++ .../SampleParentContextApplication.java | 92 +++++++ .../smoketest/parent/ServiceProperties.java | 60 +++++ .../src/main/resources/application.properties | 0 ...mpleIntegrationParentApplicationTests.java | 105 ++++++++ .../parent/producer/ProducerApplication.java | 58 ++++ .../application.yml | 0 .../spring-boot-smoke-test-profile/pom.xml | 38 +++ .../profile/SampleProfileApplication.java | 45 ++++ .../profile/service/GenericService.java | 38 +++ .../profile/service/GoodbyeWorldService.java | 35 +++ .../profile/service/HelloWorldService.java | 35 +++ .../profile/service/MessageService.java | 23 ++ .../src/main/resources/application.yml | 0 .../SampleProfileApplicationTests.java | 81 ++++++ .../pom.xml | 44 +++ .../propertyvalidation/SampleProperties.java | 52 ++++ .../SamplePropertiesValidator.java | 44 +++ .../SamplePropertyValidationApplication.java | 51 ++++ .../src/main/resources/application.properties | 0 ...plePropertyValidationApplicationTests.java | 81 ++++++ .../spring-boot-smoke-test-quartz/pom.xml | 37 +++ .../main/java/smoketest/quartz/SampleJob.java | 38 +++ .../quartz/SampleQuartzApplication.java | 51 ++++ .../quartz/SampleQuartzApplicationTests.java | 48 ++++ .../pom.xml | 47 ++++ .../oauth2/client/ExampleController.java | 32 +++ ...SampleReactiveOAuth2ClientApplication.java | 29 ++ .../src/main/resources/application.yml | 0 ...eReactiveOAuth2ClientApplicationTests.java | 51 ++++ .../pom.xml | 48 ++++ .../oauth2/resource/ExampleController.java | 32 +++ ...activeOAuth2ResourceServerApplication.java | 29 ++ .../src/main/resources/application.yml | 0 ...eOAuth2ResourceServerApplicationTests.java | 93 +++++++ .../pom.xml | 60 +++++ .../smoketest/secure/webflux/EchoHandler.java | 32 +++ .../SampleSecureWebFluxApplication.java | 40 +++ .../secure/webflux/WelcomeController.java | 32 +++ .../src/main/resources/application.properties | 0 .../resources/static/css/bootstrap.min.css | 0 ...anagementPortSampleSecureWebFluxTests.java | 103 ++++++++ .../SampleSecureWebFluxApplicationTests.java | 82 ++++++ ...ampleSecureWebFluxCustomSecurityTests.java | 126 +++++++++ .../spring-boot-smoke-test-secure/pom.xml | 38 +++ .../secure/SampleSecureApplication.java | 53 ++++ .../java/smoketest/secure/SampleService.java | 41 +++ .../src/main/resources/application.properties | 0 .../secure/SampleSecureApplicationTests.java | 82 ++++++ .../spring-boot-smoke-test-servlet/pom.xml | 50 ++++ .../servlet/SampleServletApplication.java | 59 +++++ .../src/main/resources/application.properties | 0 .../SampleServletApplicationTests.java | 68 +++++ .../pom.xml | 76 ++++++ .../session/HelloRestController.java | 31 +++ .../SampleSessionWebFluxApplication.java | 48 ++++ .../src/main/resources/application.properties | 0 .../SampleSessionWebFluxApplicationTests.java | 69 +++++ .../spring-boot-smoke-test-session/pom.xml | 106 ++++++++ .../session/HelloRestController.java | 32 +++ .../session/SampleSessionApplication.java | 29 ++ .../src/main/resources/application.properties | 0 .../src/main/resources/hazelcast.xml | 0 .../SampleSessionApplicationTests.java | 80 ++++++ .../spring-boot-smoke-test-simple/pom.xml | 52 ++++ .../java/smoketest/simple/ExitException.java | 28 ++ .../simple/SampleConfigurationProperties.java | 39 +++ .../simple/SampleSimpleApplication.java | 48 ++++ .../simple/service/HelloWorldService.java | 37 +++ .../src/main/resources/application.properties | 0 .../src/main/resources/banner.jpg | Bin .../src/main/resources/banner.txt | 0 .../simple/SampleSimpleApplicationTests.java | 67 +++++ ...pringTestSampleSimpleApplicationTests.java | 45 ++++ .../pom.xml | 53 ++++ .../SampleTestNoMockitoApplication.java | 29 ++ .../SampleTestNoMockitoApplicationTests.java | 48 ++++ .../spring-boot-smoke-test-test/pom.xml | 78 ++++++ .../smoketest/test/SampleTestApplication.java | 37 +++ .../test/WelcomeCommandLineRunner.java | 36 +++ .../main/java/smoketest/test/domain/User.java | 65 +++++ .../smoketest/test/domain/UserRepository.java | 30 +++ .../domain/VehicleIdentificationNumber.java | 57 ++++ ...dentificationNumberAttributeConverter.java | 41 +++ .../service/RemoteVehicleDetailsService.java | 62 +++++ .../test/service/ServiceProperties.java | 39 +++ .../test/service/VehicleDetails.java | 68 +++++ .../test/service/VehicleDetailsService.java | 37 +++ ...IdentificationNumberNotFoundException.java | 43 +++ .../test/web/UserNameNotFoundException.java | 35 +++ .../test/web/UserVehicleController.java | 68 +++++ .../test/web/UserVehicleService.java | 55 ++++ .../src/main/resources/application.properties | 0 ...pleTestApplicationWebIntegrationTests.java | 61 +++++ .../test/domain/UserEntityTests.java | 66 +++++ .../test/domain/UserRepositoryTests.java | 58 ++++ .../VehicleIdentificationNumberTests.java | 69 +++++ .../RemoteVehicleDetailsServiceTests.java | 87 ++++++ .../test/service/VehicleDetailsJsonTests.java | 54 ++++ ...UserVehicleControllerApplicationTests.java | 70 +++++ .../UserVehicleControllerHtmlUnitTests.java | 52 ++++ .../UserVehicleControllerSeleniumTests.java | 54 ++++ .../test/web/UserVehicleControllerTests.java | 100 +++++++ .../test/web/UserVehicleServiceTests.java | 80 ++++++ .../src/test/resources/application.properties | 0 .../src/test/resources/data.sql | 0 .../test/service/vehicledetails.json | 0 .../spring-boot-smoke-test-testng/pom.xml | 62 +++++ .../testng/SampleTestNGApplication.java | 55 ++++ .../testng/service/HelloWorldService.java | 32 +++ .../testng/web/SampleController.java | 38 +++ .../src/main/resources/public/test.css | 0 .../testng/SampleTestNGApplicationTests.java | 49 ++++ .../spring-boot-smoke-test-tomcat-jsp/pom.xml | 57 ++++ .../smoketest/tomcat/jsp/MyException.java | 25 ++ .../smoketest/tomcat/jsp/MyRestResponse.java | 31 +++ .../jsp/SampleTomcatJspApplication.java | 36 +++ .../tomcat/jsp/WelcomeController.java | 60 +++++ .../resources/META-INF/resources/favicon.ico | Bin .../src/main/resources/application.properties | 0 .../src/main/webapp/WEB-INF/jsp/welcome.jsp | 0 .../jsp/SampleWebJspApplicationTests.java | 48 ++++ .../pom.xml | 43 +++ .../SampleTomcatTwoConnectorsApplication.java | 53 ++++ .../multiconnector/web/SampleController.java | 30 +++ .../src/main/resources/application.properties | 0 .../src/main/resources/sample.jks | Bin ...leTomcatTwoConnectorsApplicationTests.java | 111 ++++++++ .../spring-boot-smoke-test-tomcat-ssl/pom.xml | 43 +++ .../ssl/SampleTomcatSslApplication.java | 29 ++ .../tomcat/ssl/web/SampleController.java | 30 +++ .../src/main/resources/application.properties | 0 .../src/main/resources/sample.jks | Bin .../ssl/SampleTomcatSslApplicationTests.java | 52 ++++ .../spring-boot-smoke-test-tomcat/pom.xml | 46 ++++ .../tomcat/SampleTomcatApplication.java | 55 ++++ .../tomcat/service/HelloWorldService.java | 32 +++ .../tomcat/web/SampleController.java | 38 +++ .../src/main/resources/application.properties | 0 ...igurationSampleTomcatApplicationTests.java | 72 +++++ .../tomcat/SampleTomcatApplicationTests.java | 86 ++++++ .../pom.xml | 55 ++++ .../SampleTraditionalApplication.java | 29 ++ .../traditional/config/WebConfig.java | 58 ++++ .../src/main/webapp/WEB-INF/views/home.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/main/webapp/index.html | 0 .../SampleTraditionalApplicationTests.java | 57 ++++ .../src/test/resources/log4j.properties | 0 .../pom.xml | 52 ++++ .../ssl/SampleUndertowSslApplication.java | 29 ++ .../undertow/ssl/web/SampleController.java | 30 +++ .../src/main/resources/application.properties | 0 .../src/main/resources/sample.jks | Bin .../SampleUndertowSslApplicationTests.java | 57 ++++ .../spring-boot-smoke-test-undertow/pom.xml | 48 ++++ .../undertow/SampleUndertowApplication.java | 29 ++ .../undertow/web/SampleController.java | 37 +++ .../src/main/resources/application.properties | 0 .../SampleUndertowApplicationTests.java | 79 ++++++ .../spring-boot-smoke-test-war/pom.xml | 94 +++++++ .../main/java/smoketest/war/MyController.java | 30 +++ .../smoketest/war/SampleWarApplication.java | 32 +++ .../src/main/webapp/WEB-INF/custom.properties | 0 .../src/main/webapp/webapp.txt | 0 .../war/WarApplicationResourceTests.java | 39 +++ .../pom.xml | 53 ++++ .../SampleWebFreeMarkerApplication.java | 29 ++ .../freemarker/WelcomeController.java | 39 +++ .../src/main/resources/application.properties | 0 .../src/main/resources/templates/error.ftlh | 0 .../src/main/resources/templates/welcome.ftlh | 0 .../SampleWebFreeMarkerApplicationTests.java | 68 +++++ .../pom.xml | 52 ++++ .../InMemoryMessageRepository.java | 50 ++++ .../smoketest/groovytemplates/Message.java | 67 +++++ .../groovytemplates/MessageRepository.java | 27 ++ .../SampleGroovyTemplateApplication.java | 46 ++++ .../mvc/MessageController.java | 91 +++++++ .../src/main/resources/application.properties | 0 .../resources/static/css/bootstrap.min.css | 0 .../main/resources/static/js/jquery-1.7.2.js | 0 .../resources/static/js/jquery.validate.js | 0 .../src/main/resources/templates/layout.tpl | 0 .../resources/templates/messages/form.tpl | 0 .../resources/templates/messages/list.tpl | 0 .../resources/templates/messages/view.tpl | 0 .../MessageControllerWebTests.java | 105 ++++++++ .../SampleGroovyTemplateApplicationTests.java | 73 +++++ .../spring-boot-smoke-test-web-jsp/pom.xml | 62 +++++ .../jsp/SampleWebJspApplication.java | 36 +++ .../java/smoketest/jsp/WelcomeController.java | 45 ++++ .../src/main/resources/application.properties | 0 .../src/main/webapp/WEB-INF/jsp/error.jsp | 0 .../src/main/webapp/WEB-INF/jsp/welcome.jsp | 0 .../jsp/SampleWebJspApplicationTests.java | 65 +++++ .../pom.xml | 50 ++++ .../SampleMethodSecurityApplication.java | 120 +++++++++ .../src/main/resources/application.properties | 0 .../resources/static/css/bootstrap.min.css | 0 .../src/main/resources/templates/access.html | 0 .../src/main/resources/templates/error.html | 0 .../src/main/resources/templates/home.html | 0 .../src/main/resources/templates/login.html | 0 .../SampleMethodSecurityApplicationTests.java | 131 +++++++++ .../pom.xml | 50 ++++ .../SampleWebMustacheApplication.java | 29 ++ .../smoketest/mustache/WelcomeController.java | 67 +++++ .../src/main/resources/application.properties | 0 .../src/main/resources/public/error/503.html | 0 .../src/main/resources/public/error/5xx.html | 0 .../main/resources/templates/error.mustache | 0 .../resources/templates/error/507.mustache | 0 .../main/resources/templates/welcome.mustache | 0 .../SampleWebMustacheApplicationTests.java | 99 +++++++ .../pom.xml | 51 ++++ .../SampleWebSecureCustomApplication.java | 70 +++++ .../src/main/resources/application.properties | 0 .../resources/static/css/bootstrap.min.css | 0 .../src/main/resources/templates/error.html | 0 .../src/main/resources/templates/home.html | 0 .../src/main/resources/templates/login.html | 0 ...SampleWebSecureCustomApplicationTests.java | 110 ++++++++ .../pom.xml | 59 +++++ .../jdbc/SampleWebSecureJdbcApplication.java | 81 ++++++ .../src/main/resources/application.properties | 0 .../src/main/resources/data.sql | 0 .../src/main/resources/schema.sql | 0 .../resources/static/css/bootstrap.min.css | 0 .../src/main/resources/templates/error.html | 0 .../src/main/resources/templates/home.html | 0 .../src/main/resources/templates/login.html | 0 .../SampleWebSecureJdbcApplicationTests.java | 110 ++++++++ .../spring-boot-smoke-test-web-secure/pom.xml | 55 ++++ .../secure/SampleWebSecureApplication.java | 78 ++++++ .../src/main/resources/application.properties | 0 .../src/main/resources/schema.sql | 0 .../resources/static/css/bootstrap.min.css | 0 .../src/main/resources/templates/error.html | 0 .../src/main/resources/templates/home.html | 0 .../src/main/resources/templates/login.html | 0 .../secure/SampleSecureApplicationTests.java | 110 ++++++++ .../spring-boot-smoke-test-web-static/pom.xml | 55 ++++ .../SampleWebStaticApplication.java | 36 +++ .../src/main/resources/static/index.html | 0 .../SampleWebStaticApplicationTests.java | 58 ++++ .../spring-boot-smoke-test-web-ui/pom.xml | 46 ++++ .../web/ui/InMemoryMessageRepository.java | 55 ++++ .../main/java/smoketest/web/ui/Message.java | 67 +++++ .../smoketest/web/ui/MessageRepository.java | 29 ++ .../web/ui/SampleWebUiApplication.java | 46 ++++ .../web/ui/mvc/MessageController.java | 87 ++++++ .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/messages.properties | 0 .../resources/static/css/bootstrap.min.css | 0 .../src/main/resources/static/favicon.ico | Bin .../main/resources/templates/fragments.html | 0 .../resources/templates/messages/form.html | 0 .../resources/templates/messages/list.html | 0 .../resources/templates/messages/view.html | 0 .../web/ui/MessageControllerWebTests.java | 105 ++++++++ .../web/ui/SampleWebUiApplicationTests.java | 74 ++++++ .../spring-boot-smoke-test-webflux/pom.xml | 56 ++++ .../java/smoketest/webflux/EchoHandler.java | 32 +++ .../smoketest/webflux/ExampleController.java | 32 +++ .../webflux/SampleWebFluxApplication.java | 40 +++ .../smoketest/webflux/WelcomeController.java | 30 +++ .../SampleWebFluxApplicationTests.java | 58 ++++ .../pom.xml | 68 +++++ .../SampleWebServicesApplication.java | 29 ++ .../webservices/WebServiceConfig.java | 38 +++ .../webservices/endpoint/HolidayEndpoint.java | 70 +++++ .../service/HumanResourceService.java | 25 ++ .../service/StubHumanResourceService.java | 36 +++ .../main/resources/META-INF/schemas/hr.xsd | 0 .../src/main/resources/application.properties | 0 .../webservices/SampleWsApplicationTests.java | 64 +++++ .../pom.xml | 48 ++++ .../SampleJettyWebSocketsApplication.java | 90 +++++++ .../jetty/client/GreetingService.java | 23 ++ .../client/SimpleClientWebSocketHandler.java | 60 +++++ .../jetty/client/SimpleGreetingService.java | 26 ++ .../jetty/echo/DefaultEchoService.java | 32 +++ .../websocket/jetty/echo/EchoService.java | 23 ++ .../jetty/echo/EchoWebSocketHandler.java | 58 ++++ .../reverse/ReverseWebSocketEndpoint.java | 33 +++ .../websocket/jetty/snake/Direction.java | 23 ++ .../websocket/jetty/snake/Location.java | 78 ++++++ .../websocket/jetty/snake/Snake.java | 156 +++++++++++ .../websocket/jetty/snake/SnakeTimer.java | 117 ++++++++ .../websocket/jetty/snake/SnakeUtils.java | 66 +++++ .../jetty/snake/SnakeWebSocketHandler.java | 103 ++++++++ .../src/main/resources/static/echo.html | 0 .../src/main/resources/static/index.html | 0 .../src/main/resources/static/reverse.html | 0 .../src/main/resources/static/snake.html | 0 .../SampleWebSocketsApplicationTests.java | 126 +++++++++ ...omContainerWebSocketsApplicationTests.java | 141 ++++++++++ .../jetty/snake/SnakeTimerTests.java | 40 +++ .../pom.xml | 38 +++ .../SampleTomcatWebSocketApplication.java | 90 +++++++ .../tomcat/client/GreetingService.java | 23 ++ .../client/SimpleClientWebSocketHandler.java | 60 +++++ .../tomcat/client/SimpleGreetingService.java | 26 ++ .../tomcat/echo/DefaultEchoService.java | 32 +++ .../websocket/tomcat/echo/EchoService.java | 23 ++ .../tomcat/echo/EchoWebSocketHandler.java | 58 ++++ .../reverse/ReverseWebSocketEndpoint.java | 33 +++ .../websocket/tomcat/snake/Direction.java | 23 ++ .../websocket/tomcat/snake/Location.java | 78 ++++++ .../websocket/tomcat/snake/Snake.java | 156 +++++++++++ .../websocket/tomcat/snake/SnakeTimer.java | 117 ++++++++ .../websocket/tomcat/snake/SnakeUtils.java | 66 +++++ .../tomcat/snake/SnakeWebSocketHandler.java | 103 ++++++++ .../src/main/resources/static/echo.html | 0 .../src/main/resources/static/index.html | 0 .../src/main/resources/static/reverse.html | 0 .../src/main/resources/static/snake.html | 0 .../SampleWebSocketsApplicationTests.java | 126 +++++++++ ...omContainerWebSocketsApplicationTests.java | 141 ++++++++++ .../tomcat/snake/SnakeTimerTests.java | 39 +++ .../pom.xml | 48 ++++ .../SampleUndertowWebSocketsApplication.java | 90 +++++++ .../undertow/client/GreetingService.java | 23 ++ .../client/SimpleClientWebSocketHandler.java | 60 +++++ .../client/SimpleGreetingService.java | 26 ++ .../undertow/echo/DefaultEchoService.java | 32 +++ .../websocket/undertow/echo/EchoService.java | 23 ++ .../undertow/echo/EchoWebSocketHandler.java | 58 ++++ .../reverse/ReverseWebSocketEndpoint.java | 33 +++ .../websocket/undertow/snake/Direction.java | 23 ++ .../websocket/undertow/snake/Location.java | 78 ++++++ .../websocket/undertow/snake/Snake.java | 156 +++++++++++ .../websocket/undertow/snake/SnakeTimer.java | 117 ++++++++ .../websocket/undertow/snake/SnakeUtils.java | 66 +++++ .../undertow/snake/SnakeWebSocketHandler.java | 103 ++++++++ .../src/main/resources/static/echo.html | 0 .../src/main/resources/static/index.html | 0 .../src/main/resources/static/reverse.html | 0 .../src/main/resources/static/snake.html | 0 .../SampleWebSocketsApplicationTests.java | 126 +++++++++ ...omContainerWebSocketsApplicationTests.java | 141 ++++++++++ .../undertow/snake/SnakeTimerTests.java | 39 +++ .../spring-boot-smoke-test-xml/pom.xml | 38 +++ .../xml/SampleSpringXmlApplication.java | 45 ++++ .../xml/service/HelloWorldService.java | 32 +++ .../META-INF/application-context.xml | 14 + .../xml/SampleSpringXmlApplicationTests.java | 36 +++ src/checkstyle/checkstyle-suppressions.xml | 4 +- 1273 files changed, 29573 insertions(+), 30267 deletions(-) delete mode 100644 spring-boot-samples-invoker/pom.xml delete mode 100644 spring-boot-samples/README.adoc delete mode 100644 spring-boot-samples/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-activemq/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-activemq/src/main/java/sample/activemq/Consumer.java delete mode 100644 spring-boot-samples/spring-boot-sample-activemq/src/main/java/sample/activemq/Producer.java delete mode 100644 spring-boot-samples/spring-boot-sample-activemq/src/main/java/sample/activemq/SampleActiveMQApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-activemq/src/test/java/sample/activemq/SampleActiveMqTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-custom-security/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/ExampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/ExampleRestControllerEndpoint.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-log4j2/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleActuatorLog4J2Application.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/HelloWorldService.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/SampleActuatorNoWebApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/ServiceProperties.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/noweb/SampleActuatorNoWebApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-ui/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-ui/src/main/java/sample/actuator/ui/SampleActuatorUiApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ExampleHealthIndicator.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ExampleInfoContributor.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/HelloWorldService.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleActuatorApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ServiceProperties.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortWithLazyInitializationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-amqp/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-amqp/src/main/java/sample/amqp/SampleAmqpSimpleApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-amqp/src/main/java/sample/amqp/Sender.java delete mode 100644 spring-boot-samples/spring-boot-sample-animated-banner/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-animated-banner/src/main/java/sample/animated/SampleAnimatedBannerApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-ant/build.xml delete mode 100644 spring-boot-samples/spring-boot-sample-ant/ivy.xml delete mode 100644 spring-boot-samples/spring-boot-sample-ant/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-ant/src/main/java/sample/ant/SampleAntApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java delete mode 100644 spring-boot-samples/spring-boot-sample-aop/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-aop/src/main/java/sample/aop/SampleAopApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-aop/src/main/java/sample/aop/monitor/ServiceMonitor.java delete mode 100644 spring-boot-samples/spring-boot-sample-aop/src/main/java/sample/aop/service/HelloWorldService.java delete mode 100644 spring-boot-samples/spring-boot-sample-aop/src/test/java/sample/aop/SampleAopApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-atmosphere/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/ChatService.java delete mode 100644 spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/Message.java delete mode 100644 spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/SampleAtmosphereApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-batch/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-batch/src/main/java/sample/batch/SampleBatchApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-cache/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-cache/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/CacheManagerCheck.java delete mode 100644 spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/Country.java delete mode 100644 spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/CountryRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleCacheApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleClient.java delete mode 100644 spring-boot-samples/spring-boot-sample-cache/src/test/java/sample/cache/SampleCacheApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-custom-layout/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-custom-layout/src/it/custom/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-custom-layout/src/it/custom/verify.groovy delete mode 100644 spring-boot-samples/spring-boot-sample-custom-layout/src/it/default/verify.groovy delete mode 100644 spring-boot-samples/spring-boot-sample-custom-layout/src/it/settings.xml delete mode 100644 spring-boot-samples/spring-boot-sample-custom-layout/src/main/java/sample/layout/SampleLayout.java delete mode 100644 spring-boot-samples/spring-boot-sample-custom-layout/src/main/java/sample/layout/SampleLayoutFactory.java delete mode 100644 spring-boot-samples/spring-boot-sample-custom-layout/src/main/resources/META-INF/spring.factories delete mode 100644 spring-boot-samples/spring-boot-sample-custom-layout/src/test/java/sample/layout/Verify.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-cassandra/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-data-cassandra/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/Customer.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/CustomerRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/SampleCassandraApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/OrderedCassandraTestExecutionListener.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-couchbase/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-data-couchbase/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/SampleCouchbaseApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/User.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/UserRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-couchbase/src/test/java/sample/data/couchbase/SampleCouchbaseApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/CustomerRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/SampleElasticsearchApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java delete mode 100755 spring-boot-samples/spring-boot-sample-data-jdbc/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/Customer.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/CustomerRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleDataJdbcApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/CustomerRepositoryIntegrationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/SampleDataJdbcApplicationTests.java delete mode 100755 spring-boot-samples/spring-boot-sample-data-jpa/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/SampleDataJpaApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/City.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Hotel.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/HotelSummary.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Rating.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/RatingCount.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Review.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/ReviewDetails.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/TripType.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CitySearchCriteria.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityService.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityServiceImpl.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelService.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelServiceImpl.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/ReviewRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/ReviewsSummary.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/web/SampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-ldap/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-data-ldap/src/main/java/sample/data/ldap/Person.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-ldap/src/main/java/sample/data/ldap/PersonRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-ldap/src/main/java/sample/data/ldap/SampleLdapApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-ldap/src/test/java/sample/data/ldap/SampleLdapApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-mongodb/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/Customer.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/CustomerRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/SampleMongoApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-neo4j/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-data-neo4j/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/Customer.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/CustomerRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/SampleNeo4jApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-neo4j/src/test/java/sample/data/neo4j/SampleNeo4jApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-redis/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-data-redis/src/main/java/sample/data/redis/SampleRedisApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-redis/src/test/java/sample/data/redis/SampleRedisApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-rest/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/SampleDataRestApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/City.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/Hotel.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/CityRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/CitySearchCriteria.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/HotelRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/SampleDataRestApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-solr/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/ProductRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/SampleSolrApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-devtools/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/Message.java delete mode 100644 spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java delete mode 100644 spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/SampleDevToolsApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-flyway/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-flyway/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/Person.java delete mode 100644 spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/PersonRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/SampleFlywayApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-hateoas/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/SampleHateoasApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/domain/Customer.java delete mode 100644 spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/domain/CustomerRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/domain/InMemoryCustomerRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/web/CustomerController.java delete mode 100644 spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-integration/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/HelloWorldService.java delete mode 100644 spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleApplicationRunner.java delete mode 100644 spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleEndpoint.java delete mode 100644 spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleIntegrationApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleMessageGateway.java delete mode 100644 spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/ServiceProperties.java delete mode 100644 spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/producer/ProducerApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-jersey/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/Endpoint.java delete mode 100644 spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/JerseyConfig.java delete mode 100644 spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/ReverseEndpoint.java delete mode 100644 spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/SampleJerseyApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/Service.java delete mode 100644 spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/JerseyApplicationPathAndManagementPortTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty-jsp/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/MyException.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/MyRestResponse.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/SampleJettyJspApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/WelcomeController.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty-jsp/src/test/java/sample/jetty/jsp/SampleWebJspApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/ssl/SampleJettySslApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/ssl/web/SampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/ExampleServletContextListener.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/SampleJettyApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/service/HelloWorldService.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/web/SampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Author.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Book.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/BookStore.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/BookToBookStore.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/DefaultCatalog.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Keys.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Language.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Public.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Tables.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/JooqExamples.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/SampleJooqApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/util/TangleFreeGeneratorStrategy.java delete mode 100644 spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-jpa/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/SampleJpaApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.java delete mode 100644 spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Tag.java delete mode 100644 spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaNoteRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaTagRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/NoteRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/TagRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/web/IndexController.java delete mode 100644 spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/SampleJpaApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-atomikos/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/Account.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/AccountRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/AccountService.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/Messages.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/SampleAtomikosApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-bitronix/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/Account.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/AccountRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/AccountService.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/Messages.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/SampleBitronixApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-jndi/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-jta-jndi/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/Account.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/AccountRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/AccountService.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/Messages.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/SampleJndiApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/SampleJndiInitializer.java delete mode 100644 spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/WebController.java delete mode 100644 spring-boot-samples/spring-boot-sample-junit-jupiter/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/MessageController.java delete mode 100644 spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/SampleJUnitJupiterApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-junit-jupiter/src/test/java/sample/SampleJUnitJupiterApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-junit-vintage/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/MessageController.java delete mode 100644 spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/SampleJUnitVintageApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-junit-vintage/src/test/java/sample/SampleJUnitVintageApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-kafka/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/Consumer.java delete mode 100644 spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/Producer.java delete mode 100644 spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleKafkaApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleMessage.java delete mode 100644 spring-boot-samples/spring-boot-sample-kafka/src/main/resources/application.properties delete mode 100644 spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-liquibase/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-liquibase/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-liquibase/src/main/java/sample/liquibase/SampleLiquibaseApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-logback/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-logback/src/main/java/sample/logback/SampleLogbackApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-logback/src/main/resources/logback-spring.xml delete mode 100644 spring-boot-samples/spring-boot-sample-logback/src/test/java/sample/logback/SampleLogbackApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-oauth2-client/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-oauth2-client/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-oauth2-client/src/main/java/sample/oauth2/client/ExampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-oauth2-client/src/main/java/sample/oauth2/client/SampleOAuth2ClientApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-oauth2-resource-server/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/main/java/sample/oauth2/resource/ExampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/main/java/sample/oauth2/resource/SampleOauth2ResourceServerApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/test/java/sample/oauth2/resource/SampleOauth2ResourceServerApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-parent-context/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/HelloWorldService.java delete mode 100644 spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleEndpoint.java delete mode 100644 spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleParentContextApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/ServiceProperties.java delete mode 100644 spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/consumer/SampleIntegrationParentApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/producer/ProducerApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-profile/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/SampleProfileApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/GenericService.java delete mode 100644 spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/GoodbyeWorldService.java delete mode 100644 spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/HelloWorldService.java delete mode 100644 spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/MessageService.java delete mode 100644 spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-property-validation/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SampleProperties.java delete mode 100644 spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertiesValidator.java delete mode 100644 spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertyValidationApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-quartz/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-quartz/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleJob.java delete mode 100644 spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleQuartzApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-reactive-oauth2-client/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-reactive-oauth2-client/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/main/java/sample/oauth2/client/ExampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/main/java/sample/oauth2/client/SampleReactiveOAuth2ClientApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/test/java/sample/oauth2/client/SampleReactiveOAuth2ClientApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/main/java/sample/oauth2/resource/ExampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/main/java/sample/oauth2/resource/SampleReactiveOAuth2ResourceServerApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/test/java/sample/oauth2/resource/SampleReactiveOAuth2ResourceServerApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-secure-webflux/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/EchoHandler.java delete mode 100644 spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/SampleSecureWebFluxApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/WelcomeController.java delete mode 100644 spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/ManagementPortSampleSecureWebFluxTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-secure/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleService.java delete mode 100644 spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-servlet/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-session-webflux/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-session-webflux/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-session-webflux/src/main/java/sample/session/HelloRestController.java delete mode 100644 spring-boot-samples/spring-boot-sample-session-webflux/src/main/java/sample/session/SampleSessionWebFluxApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-session-webflux/src/test/java/sample/session/SampleSessionWebFluxApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-session/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-session/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-session/src/main/java/sample/session/HelloRestController.java delete mode 100644 spring-boot-samples/spring-boot-sample-session/src/main/java/sample/session/SampleSessionApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-session/src/test/java/sample/session/SampleSessionApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-simple/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/ExitException.java delete mode 100644 spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/SampleConfigurationProperties.java delete mode 100644 spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/SampleSimpleApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/service/HelloWorldService.java delete mode 100644 spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-test-nomockito/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-test-nomockito/src/main/java/sample/testnomockito/SampleTestNoMockitoApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-test-nomockito/src/test/java/sample/testnomockito/SampleTestNoMockitoApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/SampleTestApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/WelcomeCommandLineRunner.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/User.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/UserRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/VehicleIdentificationNumber.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/VehicleIdentificationNumberAttributeConverter.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/RemoteVehicleDetailsService.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/ServiceProperties.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleDetails.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleDetailsService.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleIdentificationNumberNotFoundException.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserNameNotFoundException.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserVehicleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserVehicleService.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserEntityTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserRepositoryTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/VehicleIdentificationNumberTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/RemoteVehicleDetailsServiceTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/VehicleDetailsJsonTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerHtmlUnitTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerSeleniumTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleServiceTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-testng/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/SampleTestNGApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/service/HelloWorldService.java delete mode 100644 spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/web/SampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-jsp/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/MyException.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/MyRestResponse.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/SampleTomcatJspApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/WelcomeController.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/web/SampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-ssl/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/java/sample/tomcat/ssl/SampleTomcatSslApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/java/sample/tomcat/ssl/web/SampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/ssl/SampleTomcatSslApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat/src/main/java/sample/tomcat/SampleTomcatApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat/src/main/java/sample/tomcat/service/HelloWorldService.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat/src/main/java/sample/tomcat/web/SampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-traditional/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-traditional/src/main/java/sample/traditional/SampleTraditionalApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-traditional/src/main/java/sample/traditional/config/WebConfig.java delete mode 100644 spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-undertow-ssl/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/java/sample/undertow/ssl/SampleUndertowSslApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/java/sample/undertow/ssl/web/SampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-undertow/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-undertow/src/main/java/sample/undertow/SampleUndertowApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-undertow/src/main/java/sample/undertow/web/SampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-war/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/MyController.java delete mode 100644 spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/SampleWarApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-war/src/test/java/sample/war/WarApplicationResourceTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-freemarker/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-web-freemarker/src/main/java/sample/freemarker/SampleWebFreeMarkerApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-freemarker/src/main/java/sample/freemarker/WelcomeController.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-groovy-templates/README.adoc delete mode 100755 spring-boot-samples/spring-boot-sample-web-groovy-templates/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/InMemoryMessageRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/Message.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/MessageRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/SampleGroovyTemplateApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/mvc/MessageController.java delete mode 100755 spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/MessageControllerWebTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-jsp/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/SampleWebJspApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/WelcomeController.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-method-security/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-mustache/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-web-mustache/src/main/java/sample/mustache/SampleWebMustacheApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-mustache/src/main/java/sample/mustache/WelcomeController.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-secure-custom/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/java/sample/web/secure/custom/SampleWebSecureCustomApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-secure-jdbc/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-secure/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-web-secure/src/main/java/sample/web/secure/SampleWebSecureApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-static/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-web-static/src/main/java/sample/web/staticcontent/SampleWebStaticApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java delete mode 100755 spring-boot-samples/spring-boot-sample-web-ui/pom.xml delete mode 100755 spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/InMemoryMessageRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/Message.java delete mode 100755 spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/MessageRepository.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/SampleWebUiApplication.java delete mode 100755 spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/MessageControllerWebTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-webflux/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/EchoHandler.java delete mode 100644 spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/ExampleController.java delete mode 100644 spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/WelcomeController.java delete mode 100644 spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-webservices/README.adoc delete mode 100644 spring-boot-samples/spring-boot-sample-webservices/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/SampleWebServicesApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/WebServiceConfig.java delete mode 100644 spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/endpoint/HolidayEndpoint.java delete mode 100644 spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/service/HumanResourceService.java delete mode 100644 spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/service/StubHumanResourceService.java delete mode 100644 spring-boot-samples/spring-boot-sample-webservices/src/test/java/sample/webservices/SampleWsApplicationTests.java delete mode 100755 spring-boot-samples/spring-boot-sample-websocket-jetty/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/SampleJettyWebSocketsApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/GreetingService.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/SimpleClientWebSocketHandler.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/SimpleGreetingService.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/DefaultEchoService.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/EchoService.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/EchoWebSocketHandler.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/reverse/ReverseWebSocketEndpoint.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Direction.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Location.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Snake.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeTimer.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeUtils.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeWebSocketHandler.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/snake/SnakeTimerTests.java delete mode 100755 spring-boot-samples/spring-boot-sample-websocket-tomcat/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/SampleTomcatWebSocketApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/GreetingService.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/SimpleClientWebSocketHandler.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/SimpleGreetingService.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/DefaultEchoService.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/EchoService.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/EchoWebSocketHandler.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/reverse/ReverseWebSocketEndpoint.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Direction.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Location.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Snake.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeTimer.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeUtils.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeWebSocketHandler.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/snake/SnakeTimerTests.java delete mode 100755 spring-boot-samples/spring-boot-sample-websocket-undertow/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/SampleUndertowWebSocketsApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/GreetingService.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/SimpleClientWebSocketHandler.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/SimpleGreetingService.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/DefaultEchoService.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/EchoService.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/EchoWebSocketHandler.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/reverse/ReverseWebSocketEndpoint.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Direction.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Location.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Snake.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeTimer.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeUtils.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeWebSocketHandler.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/snake/SnakeTimerTests.java delete mode 100644 spring-boot-samples/spring-boot-sample-xml/pom.xml delete mode 100644 spring-boot-samples/spring-boot-sample-xml/src/main/java/sample/xml/SampleSpringXmlApplication.java delete mode 100644 spring-boot-samples/spring-boot-sample-xml/src/main/java/sample/xml/service/HelloWorldService.java delete mode 100644 spring-boot-samples/spring-boot-sample-xml/src/main/resources/META-INF/application-context.xml delete mode 100644 spring-boot-samples/spring-boot-sample-xml/src/test/java/sample/xml/SampleSpringXmlApplicationTests.java create mode 100644 spring-boot-smoke-tests-invoker/pom.xml create mode 100644 spring-boot-smoke-tests/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-activemq/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/java/smoketest/activemq/Consumer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/java/smoketest/activemq/Producer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/java/smoketest/activemq/SampleActiveMQApplication.java rename {spring-boot-samples/spring-boot-sample-activemq => spring-boot-smoke-tests/spring-boot-smoke-test-activemq}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/test/java/smoketest/activemq/SampleActiveMqTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/ExampleController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/ExampleRestControllerEndpoint.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/SampleActuatorCustomSecurityApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/SecurityConfiguration.java rename {spring-boot-samples/spring-boot-sample-actuator-custom-security => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-actuator-custom-security => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security}/src/main/resources/static/css/bootstrap.min.css (100%) rename {spring-boot-samples/spring-boot-sample-actuator-custom-security => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security}/src/main/resources/templates/error.ftlh (100%) rename {spring-boot-samples/spring-boot-sample-actuator-custom-security => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security}/src/main/resources/templates/home.ftlh (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/CorsSampleActuatorApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java rename {spring-boot-samples/spring-boot-sample-actuator-custom-security => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security}/src/test/resources/application-cors.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/src/main/java/smoketest/actuator/log4j2/SampleActuatorLog4J2Application.java rename {spring-boot-samples/spring-boot-sample-actuator-log4j2 => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-actuator-log4j2 => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2}/src/main/resources/log4j2.xml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/src/test/java/smoketest/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/java/smoketest/actuator/noweb/HelloWorldService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/java/smoketest/actuator/noweb/SampleActuatorNoWebApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/java/smoketest/actuator/noweb/ServiceProperties.java rename {spring-boot-samples/spring-boot-sample-actuator-noweb => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-actuator-noweb => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb}/src/main/resources/banner.txt (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/test/java/smoketest/actuator/noweb/SampleActuatorNoWebApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/main/java/smoketest/actuator/ui/SampleActuatorUiApplication.java rename {spring-boot-samples/spring-boot-sample-actuator-ui => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-actuator-ui => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui}/src/main/resources/static/css/bootstrap.min.css (100%) rename {spring-boot-samples/spring-boot-sample-actuator-ui => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui}/src/main/resources/templates/error.ftlh (100%) rename {spring-boot-samples/spring-boot-sample-actuator-ui => spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui}/src/main/resources/templates/home.ftlh (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/test/java/smoketest/actuator/ui/SampleActuatorUiApplicationPortTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/test/java/smoketest/actuator/ui/SampleActuatorUiApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/ExampleHealthIndicator.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/ExampleInfoContributor.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/HelloWorldService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/SampleActuatorApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/SampleController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/ServiceProperties.java rename {spring-boot-samples/spring-boot-sample-actuator => spring-boot-smoke-tests/spring-boot-smoke-test-actuator}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-actuator => spring-boot-smoke-tests/spring-boot-smoke-test-actuator}/src/main/resources/logback.xml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementAddressActuatorApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortSampleActuatorApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortWithLazyInitializationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/NoManagementSampleActuatorApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ShutdownSampleActuatorApplicationTests.java rename {spring-boot-samples/spring-boot-sample-actuator => spring-boot-smoke-tests/spring-boot-smoke-test-actuator}/src/test/resources/application-endpoints.properties (100%) rename {spring-boot-samples/spring-boot-sample-amqp => spring-boot-smoke-tests/spring-boot-smoke-test-amqp}/docker-compose.yml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-amqp/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-amqp/src/main/java/smoketest/amqp/SampleAmqpSimpleApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-amqp/src/main/java/smoketest/amqp/Sender.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/src/main/java/smoketest/animated/SampleAnimatedBannerApplication.java rename {spring-boot-samples/spring-boot-sample-animated-banner => spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner}/src/main/resources/banner.gif (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-ant/ivy.xml rename {spring-boot-samples/spring-boot-sample-ant => spring-boot-smoke-tests/spring-boot-smoke-test-ant}/ivysettings.xml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-ant/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-ant/src/main/java/smoketest/ant/SampleAntApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-ant/src/test/java/smoketest/ant/SampleAntApplicationIT.java rename {spring-boot-samples/spring-boot-sample-ant => spring-boot-smoke-tests/spring-boot-smoke-test-ant}/src/test/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-aop/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/java/smoketest/aop/SampleAopApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/java/smoketest/aop/monitor/ServiceMonitor.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/java/smoketest/aop/service/HelloWorldService.java rename {spring-boot-samples/spring-boot-sample-aop => spring-boot-smoke-tests/spring-boot-smoke-test-aop}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/test/java/smoketest/aop/SampleAopApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/java/smoketest/atmosphere/ChatService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/java/smoketest/atmosphere/Message.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/java/smoketest/atmosphere/SampleAtmosphereApplication.java rename {spring-boot-samples/spring-boot-sample-atmosphere => spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-atmosphere => spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere}/src/main/resources/static/home.html (100%) rename {spring-boot-samples/spring-boot-sample-atmosphere => spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere}/src/main/resources/static/javascript/application.js (100%) rename {spring-boot-samples/spring-boot-sample-atmosphere => spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere}/src/main/resources/static/javascript/jquery-1.9.0.js (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/test/java/smoketest/atmosphere/SampleAtmosphereApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-batch/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-batch/src/test/java/smoketest/batch/SampleBatchApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-cache/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/CacheManagerCheck.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/Country.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/CountryRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/SampleCacheApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/SampleClient.java rename {spring-boot-samples/spring-boot-sample-cache => spring-boot-smoke-tests/spring-boot-smoke-test-cache}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-cache => spring-boot-smoke-tests/spring-boot-smoke-test-cache}/src/main/resources/ehcache.xml (100%) rename {spring-boot-samples/spring-boot-sample-cache => spring-boot-smoke-tests/spring-boot-smoke-test-cache}/src/main/resources/ehcache3.xml (100%) rename {spring-boot-samples/spring-boot-sample-cache => spring-boot-smoke-tests/spring-boot-smoke-test-cache}/src/main/resources/hazelcast.xml (100%) rename {spring-boot-samples/spring-boot-sample-cache => spring-boot-smoke-tests/spring-boot-smoke-test-cache}/src/main/resources/infinispan.xml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/test/java/smoketest/cache/SampleCacheApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/custom/pom.xml rename {spring-boot-samples/spring-boot-sample-custom-layout => spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout}/src/it/custom/src/main/java/org/test/SampleApplication.java (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/custom/verify.groovy rename {spring-boot-samples/spring-boot-sample-custom-layout => spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout}/src/it/default/pom.xml (100%) rename {spring-boot-samples/spring-boot-sample-custom-layout => spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout}/src/it/default/src/main/java/org/test/SampleApplication.java (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/default/verify.groovy create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/main/java/smoketest/layout/SampleLayout.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/main/java/smoketest/layout/SampleLayoutFactory.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/main/resources/META-INF/spring.factories create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/test/java/smoketest/layout/Verify.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/Customer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/CustomerRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/SampleCassandraApplication.java rename {spring-boot-samples/spring-boot-sample-data-cassandra => spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/OrderedCassandraTestExecutionListener.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationTests.java rename {spring-boot-samples/spring-boot-sample-data-cassandra => spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra}/src/test/resources/setup.cql (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/java/smoketest/data/couchbase/SampleCouchbaseApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/java/smoketest/data/couchbase/User.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/java/smoketest/data/couchbase/UserRepository.java rename {spring-boot-samples/spring-boot-sample-data-couchbase => spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/test/java/smoketest/data/couchbase/SampleCouchbaseApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/java/smoketest/data/elasticsearch/Customer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/java/smoketest/data/elasticsearch/CustomerRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/java/smoketest/data/elasticsearch/SampleElasticsearchApplication.java rename {spring-boot-samples/spring-boot-sample-data-elasticsearch => spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/test/java/smoketest/data/elasticsearch/SampleElasticsearchApplicationTests.java create mode 100755 spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/Customer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/CustomerRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/SampleController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/SampleDataJdbcApplication.java rename {spring-boot-samples/spring-boot-sample-data-jdbc => spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc}/src/main/resources/data.sql (100%) rename {spring-boot-samples/spring-boot-sample-data-jdbc => spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc}/src/main/resources/schema.sql (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/test/java/smoketest/data/jdbc/CustomerRepositoryIntegrationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/test/java/smoketest/data/jdbc/SampleDataJdbcApplicationTests.java create mode 100755 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/SampleDataJpaApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/City.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/Hotel.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/HotelSummary.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/Rating.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/RatingCount.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/Review.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/ReviewDetails.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/TripType.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CitySearchCriteria.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityServiceImpl.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/HotelRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/HotelService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/HotelServiceImpl.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/ReviewRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/ReviewsSummary.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/web/SampleController.java rename {spring-boot-samples/spring-boot-sample-data-jpa => spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-data-jpa => spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa}/src/main/resources/import.sql (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/SampleDataJpaApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/service/CityRepositoryIntegrationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/service/HotelRepositoryIntegrationTests.java rename {spring-boot-samples/spring-boot-sample-data-jpa => spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa}/src/test/resources/application-scratch.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/java/smoketest/data/ldap/Person.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/java/smoketest/data/ldap/PersonRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/java/smoketest/data/ldap/SampleLdapApplication.java rename {spring-boot-samples/spring-boot-sample-data-ldap => spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-data-ldap => spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap}/src/main/resources/schema.ldif (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/test/java/smoketest/data/ldap/SampleLdapApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/Customer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/CustomerRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/SampleMongoApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/test/java/smoketest/data/mongo/SampleMongoApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/java/smoketest/data/neo4j/Customer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/java/smoketest/data/neo4j/CustomerRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/java/smoketest/data/neo4j/SampleNeo4jApplication.java rename {spring-boot-samples/spring-boot-sample-data-neo4j => spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/test/java/smoketest/data/neo4j/SampleNeo4jApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/src/main/java/smoketest/data/redis/SampleRedisApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/src/test/java/smoketest/data/redis/SampleRedisApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/SampleDataRestApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/domain/City.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/domain/Hotel.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/service/CityRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/service/CitySearchCriteria.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/service/HotelRepository.java rename {spring-boot-samples/spring-boot-sample-data-rest => spring-boot-smoke-tests/spring-boot-smoke-test-data-rest}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-data-rest => spring-boot-smoke-tests/spring-boot-smoke-test-data-rest}/src/main/resources/import.sql (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/test/java/smoketest/data/rest/SampleDataRestApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/test/java/smoketest/data/rest/service/CityRepositoryIntegrationTests.java rename {spring-boot-samples/spring-boot-sample-data-rest => spring-boot-smoke-tests/spring-boot-smoke-test-data-rest}/src/test/resources/application-scratch.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/main/java/smoketest/data/solr/Product.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/main/java/smoketest/data/solr/ProductRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/main/java/smoketest/data/solr/SampleSolrApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/test/java/smoketest/data/solr/SampleSolrApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-devtools/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/java/smoketest/devtools/Message.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/java/smoketest/devtools/MyController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/java/smoketest/devtools/SampleDevToolsApplication.java rename {spring-boot-samples/spring-boot-sample-devtools => spring-boot-smoke-tests/spring-boot-smoke-test-devtools}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-devtools => spring-boot-smoke-tests/spring-boot-smoke-test-devtools}/src/main/resources/public/public.txt (100%) rename {spring-boot-samples/spring-boot-sample-devtools => spring-boot-smoke-tests/spring-boot-smoke-test-devtools}/src/main/resources/static/css/application.css (100%) rename {spring-boot-samples/spring-boot-sample-devtools => spring-boot-smoke-tests/spring-boot-smoke-test-devtools}/src/main/resources/templates/hello.html (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/test/java/smoketest/devtools/SampleDevToolsApplicationIntegrationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-flyway/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/java/smoketest/flyway/Person.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/java/smoketest/flyway/PersonRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/java/smoketest/flyway/SampleFlywayApplication.java rename {spring-boot-samples/spring-boot-sample-flyway => spring-boot-smoke-tests/spring-boot-smoke-test-flyway}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-flyway => spring-boot-smoke-tests/spring-boot-smoke-test-flyway}/src/main/resources/db/migration/V1__init.sql (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/test/java/smoketest/flyway/SampleFlywayApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/SampleHateoasApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/Customer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/CustomerRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/InMemoryCustomerRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/CustomerController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/test/java/smoketest/hateoas/SampleHateoasApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-integration/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/HelloWorldService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleApplicationRunner.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleEndpoint.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleIntegrationApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleMessageGateway.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/ServiceProperties.java rename {spring-boot-samples/spring-boot-sample-integration => spring-boot-smoke-tests/spring-boot-smoke-test-integration}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/consumer/SampleIntegrationApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/producer/ProducerApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jersey/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/Endpoint.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/JerseyConfig.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/ReverseEndpoint.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/SampleJerseyApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/Service.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/JerseyApplicationPathAndManagementPortTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/SampleJerseyApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/MyException.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/MyRestResponse.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/SampleJettyJspApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/WelcomeController.java rename {spring-boot-samples/spring-boot-sample-jetty-jsp => spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-jetty-jsp => spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp}/src/main/webapp/WEB-INF/jsp/welcome.jsp (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/test/java/smoketest/jetty/jsp/SampleWebJspApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/main/java/smoketest/jetty/ssl/SampleJettySslApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/main/java/smoketest/jetty/ssl/web/SampleController.java rename {spring-boot-samples/spring-boot-sample-jetty-ssl => spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-jetty-ssl => spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl}/src/main/resources/sample.jks (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/test/java/smoketest/jetty/ssl/SampleJettySslApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/ExampleServletContextListener.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/SampleJettyApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/service/HelloWorldService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/web/SampleController.java rename {spring-boot-samples/spring-boot-sample-jetty => spring-boot-smoke-tests/spring-boot-smoke-test-jetty}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/test/java/smoketest/jetty/SampleJettyApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Author.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Book.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/BookStore.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/BookToBookStore.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/DefaultCatalog.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Keys.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Language.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Public.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Tables.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/java/smoketest/jooq/JooqExamples.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/java/smoketest/jooq/SampleJooqApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/java/smoketest/jooq/util/TangleFreeGeneratorStrategy.java rename {spring-boot-samples/spring-boot-sample-jooq => spring-boot-smoke-tests/spring-boot-smoke-test-jooq}/src/main/resources/data.sql (100%) rename {spring-boot-samples/spring-boot-sample-jooq => spring-boot-smoke-tests/spring-boot-smoke-test-jooq}/src/main/resources/reset.sql (100%) rename {spring-boot-samples/spring-boot-sample-jooq => spring-boot-smoke-tests/spring-boot-smoke-test-jooq}/src/main/resources/schema.sql (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/test/java/smoketest/jooq/SampleJooqApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jpa/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/SampleJpaApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/domain/Note.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/domain/Tag.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/JpaNoteRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/JpaTagRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/NoteRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/TagRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/web/IndexController.java rename {spring-boot-samples/spring-boot-sample-jpa => spring-boot-smoke-tests/spring-boot-smoke-test-jpa}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-jpa => spring-boot-smoke-tests/spring-boot-smoke-test-jpa}/src/main/resources/import.sql (100%) rename {spring-boot-samples/spring-boot-sample-jpa => spring-boot-smoke-tests/spring-boot-smoke-test-jpa}/src/main/resources/templates/index.ftlh (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/test/java/smoketest/jpa/SampleJpaApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/test/java/smoketest/jpa/repository/JpaNoteRepositoryIntegrationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/test/java/smoketest/jpa/repository/JpaTagRepositoryIntegrationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/Account.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/AccountRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/AccountService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/Messages.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/SampleAtomikosApplication.java rename {spring-boot-samples/spring-boot-sample-jta-atomikos => spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/test/java/smoketest/atomikos/SampleAtomikosApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/Account.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/AccountRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/AccountService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/Messages.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/SampleBitronixApplication.java rename {spring-boot-samples/spring-boot-sample-jta-bitronix => spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/test/java/smoketest/bitronix/SampleBitronixApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/Account.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/AccountRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/AccountService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/Messages.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/SampleJndiApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/SampleJndiInitializer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/WebController.java rename {spring-boot-samples/spring-boot-sample-jta-jndi => spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/MessageController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/SampleJUnitJupiterApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/test/java/smoketest/SampleJUnitJupiterApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/src/main/java/smoketest/MessageController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/src/main/java/smoketest/SampleJUnitVintageApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/src/test/java/smoketest/SampleJUnitVintageApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-kafka/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/Consumer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/Producer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/SampleKafkaApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/SampleMessage.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/resources/application.properties create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/test/java/smoketest/kafka/SampleKafkaApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/main/java/smoketest/liquibase/SampleLiquibaseApplication.java rename {spring-boot-samples/spring-boot-sample-liquibase => spring-boot-smoke-tests/spring-boot-smoke-test-liquibase}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-liquibase => spring-boot-smoke-tests/spring-boot-smoke-test-liquibase}/src/main/resources/db/changelog/db.changelog-master.yaml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/test/java/smoketest/liquibase/SampleLiquibaseApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-logback/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-logback/src/main/java/smoketest/logback/SampleLogbackApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-logback/src/main/resources/logback-spring.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-logback/src/test/java/smoketest/logback/SampleLogbackApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/main/java/smoketest/oauth2/client/ExampleController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/main/java/smoketest/oauth2/client/SampleOAuth2ClientApplication.java rename {spring-boot-samples/spring-boot-sample-oauth2-client => spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client}/src/main/resources/application.yml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/test/java/smoketest/oauth2/client/SampleOAuth2ClientApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/ExampleController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/SampleOauth2ResourceServerApplication.java rename {spring-boot-samples/spring-boot-sample-oauth2-resource-server => spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server}/src/main/resources/application.yml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/test/java/smoketest/oauth2/resource/SampleOauth2ResourceServerApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/HelloWorldService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/SampleEndpoint.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/SampleParentContextApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/ServiceProperties.java rename {spring-boot-samples/spring-boot-sample-parent-context => spring-boot-smoke-tests/spring-boot-smoke-test-parent-context}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/consumer/SampleIntegrationParentApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/producer/ProducerApplication.java rename {spring-boot-samples/spring-boot-sample-profile => spring-boot-smoke-tests/spring-boot-smoke-test-profile}/application.yml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-profile/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/SampleProfileApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/GenericService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/GoodbyeWorldService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/HelloWorldService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/MessageService.java rename {spring-boot-samples/spring-boot-sample-profile => spring-boot-smoke-tests/spring-boot-smoke-test-profile}/src/main/resources/application.yml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/test/java/smoketest/profile/SampleProfileApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/java/smoketest/propertyvalidation/SampleProperties.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/java/smoketest/propertyvalidation/SamplePropertiesValidator.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/java/smoketest/propertyvalidation/SamplePropertyValidationApplication.java rename {spring-boot-samples/spring-boot-sample-property-validation => spring-boot-smoke-tests/spring-boot-smoke-test-property-validation}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/test/java/smoketest/propertyvalidation/SamplePropertyValidationApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-quartz/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-quartz/src/main/java/smoketest/quartz/SampleJob.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-quartz/src/main/java/smoketest/quartz/SampleQuartzApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-quartz/src/test/java/smoketest/quartz/SampleQuartzApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/main/java/smoketest/oauth2/client/ExampleController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/main/java/smoketest/oauth2/client/SampleReactiveOAuth2ClientApplication.java rename {spring-boot-samples/spring-boot-sample-reactive-oauth2-client => spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client}/src/main/resources/application.yml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/test/java/smoketest/oauth2/client/SampleReactiveOAuth2ClientApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/ExampleController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/SampleReactiveOAuth2ResourceServerApplication.java rename {spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server => spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server}/src/main/resources/application.yml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/test/java/smoketest/oauth2/resource/SampleReactiveOAuth2ResourceServerApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/java/smoketest/secure/webflux/EchoHandler.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/java/smoketest/secure/webflux/SampleSecureWebFluxApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/java/smoketest/secure/webflux/WelcomeController.java rename {spring-boot-samples/spring-boot-sample-secure-webflux => spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-secure-webflux => spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux}/src/main/resources/static/css/bootstrap.min.css (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/ManagementPortSampleSecureWebFluxTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/SampleSecureWebFluxApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-secure/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/main/java/smoketest/secure/SampleSecureApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/main/java/smoketest/secure/SampleService.java rename {spring-boot-samples/spring-boot-sample-secure => spring-boot-smoke-tests/spring-boot-smoke-test-secure}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/test/java/smoketest/secure/SampleSecureApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-servlet/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-servlet/src/main/java/smoketest/servlet/SampleServletApplication.java rename {spring-boot-samples/spring-boot-sample-servlet => spring-boot-smoke-tests/spring-boot-smoke-test-servlet}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-servlet/src/test/java/smoketest/servlet/SampleServletApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/main/java/smoketest/session/HelloRestController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/main/java/smoketest/session/SampleSessionWebFluxApplication.java rename {spring-boot-samples/spring-boot-sample-session-webflux => spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/test/java/smoketest/session/SampleSessionWebFluxApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-session/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/HelloRestController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/SampleSessionApplication.java rename {spring-boot-samples/spring-boot-sample-session => spring-boot-smoke-tests/spring-boot-smoke-test-session}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-session => spring-boot-smoke-tests/spring-boot-smoke-test-session}/src/main/resources/hazelcast.xml (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-session/src/test/java/smoketest/session/SampleSessionApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-simple/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/ExitException.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/SampleConfigurationProperties.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/SampleSimpleApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/service/HelloWorldService.java rename {spring-boot-samples/spring-boot-sample-simple => spring-boot-smoke-tests/spring-boot-smoke-test-simple}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-simple => spring-boot-smoke-tests/spring-boot-smoke-test-simple}/src/main/resources/banner.jpg (100%) rename {spring-boot-samples/spring-boot-sample-simple => spring-boot-smoke-tests/spring-boot-smoke-test-simple}/src/main/resources/banner.txt (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/test/java/smoketest/simple/SampleSimpleApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/test/java/smoketest/simple/SpringTestSampleSimpleApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/src/main/java/smoketest/testnomockito/SampleTestNoMockitoApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/src/test/java/smoketest/testnomockito/SampleTestNoMockitoApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/SampleTestApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/WelcomeCommandLineRunner.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/User.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/UserRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/VehicleIdentificationNumber.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/VehicleIdentificationNumberAttributeConverter.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/RemoteVehicleDetailsService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/ServiceProperties.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleDetails.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleDetailsService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleIdentificationNumberNotFoundException.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/web/UserNameNotFoundException.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/web/UserVehicleController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/web/UserVehicleService.java rename {spring-boot-samples/spring-boot-sample-test => spring-boot-smoke-tests/spring-boot-smoke-test-test}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/SampleTestApplicationWebIntegrationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/domain/UserEntityTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/domain/UserRepositoryTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/domain/VehicleIdentificationNumberTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/service/RemoteVehicleDetailsServiceTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/service/VehicleDetailsJsonTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerHtmlUnitTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerSeleniumTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleServiceTests.java rename {spring-boot-samples/spring-boot-sample-test => spring-boot-smoke-tests/spring-boot-smoke-test-test}/src/test/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-test => spring-boot-smoke-tests/spring-boot-smoke-test-test}/src/test/resources/data.sql (100%) rename {spring-boot-samples/spring-boot-sample-test/src/test/resources/sample => spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/resources/smoketest}/test/service/vehicledetails.json (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-testng/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/java/smoketest/testng/SampleTestNGApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/java/smoketest/testng/service/HelloWorldService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/java/smoketest/testng/web/SampleController.java rename {spring-boot-samples/spring-boot-sample-testng => spring-boot-smoke-tests/spring-boot-smoke-test-testng}/src/main/resources/public/test.css (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/test/java/smoketest/testng/SampleTestNGApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/MyException.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/MyRestResponse.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/SampleTomcatJspApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/WelcomeController.java rename {spring-boot-samples/spring-boot-sample-tomcat-jsp => spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp}/src/main/resources/META-INF/resources/favicon.ico (100%) rename {spring-boot-samples/spring-boot-sample-tomcat-jsp => spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-tomcat-jsp => spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp}/src/main/webapp/WEB-INF/jsp/welcome.jsp (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/test/java/smoketest/tomcat/jsp/SampleWebJspApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/main/java/smoketest/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/main/java/smoketest/tomcat/multiconnector/web/SampleController.java rename {spring-boot-samples/spring-boot-sample-tomcat-multi-connectors => spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-tomcat-multi-connectors => spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors}/src/main/resources/sample.jks (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/test/java/smoketest/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/main/java/smoketest/tomcat/ssl/SampleTomcatSslApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/main/java/smoketest/tomcat/ssl/web/SampleController.java rename {spring-boot-samples/spring-boot-sample-tomcat-ssl => spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-tomcat-ssl => spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl}/src/main/resources/sample.jks (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/test/java/smoketest/tomcat/ssl/SampleTomcatSslApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/java/smoketest/tomcat/SampleTomcatApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/java/smoketest/tomcat/service/HelloWorldService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/java/smoketest/tomcat/web/SampleController.java rename {spring-boot-samples/spring-boot-sample-tomcat => spring-boot-smoke-tests/spring-boot-smoke-test-tomcat}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/test/java/smoketest/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/test/java/smoketest/tomcat/SampleTomcatApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-traditional/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/java/smoketest/traditional/SampleTraditionalApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/java/smoketest/traditional/config/WebConfig.java rename {spring-boot-samples/spring-boot-sample-traditional => spring-boot-smoke-tests/spring-boot-smoke-test-traditional}/src/main/webapp/WEB-INF/views/home.jsp (100%) rename {spring-boot-samples/spring-boot-sample-traditional => spring-boot-smoke-tests/spring-boot-smoke-test-traditional}/src/main/webapp/WEB-INF/web.xml (100%) rename {spring-boot-samples/spring-boot-sample-traditional => spring-boot-smoke-tests/spring-boot-smoke-test-traditional}/src/main/webapp/index.html (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/test/java/smoketest/traditional/SampleTraditionalApplicationTests.java rename {spring-boot-samples/spring-boot-sample-traditional => spring-boot-smoke-tests/spring-boot-smoke-test-traditional}/src/test/resources/log4j.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/main/java/smoketest/undertow/ssl/SampleUndertowSslApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/main/java/smoketest/undertow/ssl/web/SampleController.java rename {spring-boot-samples/spring-boot-sample-undertow-ssl => spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-undertow-ssl => spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl}/src/main/resources/sample.jks (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/test/java/smoketest/undertow/ssl/SampleUndertowSslApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-undertow/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/main/java/smoketest/undertow/SampleUndertowApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/main/java/smoketest/undertow/web/SampleController.java rename {spring-boot-samples/spring-boot-sample-undertow => spring-boot-smoke-tests/spring-boot-smoke-test-undertow}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/test/java/smoketest/undertow/SampleUndertowApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-war/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-war/src/main/java/smoketest/war/MyController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-war/src/main/java/smoketest/war/SampleWarApplication.java rename {spring-boot-samples/spring-boot-sample-war => spring-boot-smoke-tests/spring-boot-smoke-test-war}/src/main/webapp/WEB-INF/custom.properties (100%) rename {spring-boot-samples/spring-boot-sample-war => spring-boot-smoke-tests/spring-boot-smoke-test-war}/src/main/webapp/webapp.txt (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-war/src/test/java/smoketest/war/WarApplicationResourceTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/java/smoketest/freemarker/SampleWebFreeMarkerApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/java/smoketest/freemarker/WelcomeController.java rename {spring-boot-samples/spring-boot-sample-web-freemarker => spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-web-freemarker => spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker}/src/main/resources/templates/error.ftlh (100%) rename {spring-boot-samples/spring-boot-sample-web-freemarker => spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker}/src/main/resources/templates/welcome.ftlh (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/test/java/smoketest/freemarker/SampleWebFreeMarkerApplicationTests.java create mode 100755 spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/InMemoryMessageRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/Message.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/MessageRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/SampleGroovyTemplateApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/mvc/MessageController.java rename {spring-boot-samples/spring-boot-sample-web-groovy-templates => spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-web-groovy-templates => spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates}/src/main/resources/static/css/bootstrap.min.css (100%) rename {spring-boot-samples/spring-boot-sample-web-groovy-templates => spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates}/src/main/resources/static/js/jquery-1.7.2.js (100%) rename {spring-boot-samples/spring-boot-sample-web-groovy-templates => spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates}/src/main/resources/static/js/jquery.validate.js (100%) rename {spring-boot-samples/spring-boot-sample-web-groovy-templates => spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates}/src/main/resources/templates/layout.tpl (100%) rename {spring-boot-samples/spring-boot-sample-web-groovy-templates => spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates}/src/main/resources/templates/messages/form.tpl (100%) rename {spring-boot-samples/spring-boot-sample-web-groovy-templates => spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates}/src/main/resources/templates/messages/list.tpl (100%) rename {spring-boot-samples/spring-boot-sample-web-groovy-templates => spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates}/src/main/resources/templates/messages/view.tpl (100%) create mode 100755 spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/test/java/smoketest/groovytemplates/MessageControllerWebTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/test/java/smoketest/groovytemplates/SampleGroovyTemplateApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/java/smoketest/jsp/SampleWebJspApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/java/smoketest/jsp/WelcomeController.java rename {spring-boot-samples/spring-boot-sample-web-jsp => spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-web-jsp => spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp}/src/main/webapp/WEB-INF/jsp/error.jsp (100%) rename {spring-boot-samples/spring-boot-sample-web-jsp => spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp}/src/main/webapp/WEB-INF/jsp/welcome.jsp (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/test/java/smoketest/jsp/SampleWebJspApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/java/smoketest/security/method/SampleMethodSecurityApplication.java rename {spring-boot-samples/spring-boot-sample-web-method-security => spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-web-method-security => spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security}/src/main/resources/static/css/bootstrap.min.css (100%) rename {spring-boot-samples/spring-boot-sample-web-method-security => spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security}/src/main/resources/templates/access.html (100%) rename {spring-boot-samples/spring-boot-sample-web-method-security => spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security}/src/main/resources/templates/error.html (100%) rename {spring-boot-samples/spring-boot-sample-web-method-security => spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security}/src/main/resources/templates/home.html (100%) rename {spring-boot-samples/spring-boot-sample-web-method-security => spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security}/src/main/resources/templates/login.html (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/test/java/smoketest/security/method/SampleMethodSecurityApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/java/smoketest/mustache/SampleWebMustacheApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/java/smoketest/mustache/WelcomeController.java rename {spring-boot-samples/spring-boot-sample-web-mustache => spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-web-mustache => spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache}/src/main/resources/public/error/503.html (100%) rename {spring-boot-samples/spring-boot-sample-web-mustache => spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache}/src/main/resources/public/error/5xx.html (100%) rename {spring-boot-samples/spring-boot-sample-web-mustache => spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache}/src/main/resources/templates/error.mustache (100%) rename {spring-boot-samples/spring-boot-sample-web-mustache => spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache}/src/main/resources/templates/error/507.mustache (100%) rename {spring-boot-samples/spring-boot-sample-web-mustache => spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache}/src/main/resources/templates/welcome.mustache (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/test/java/smoketest/mustache/SampleWebMustacheApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/java/smoketest/web/secure/custom/SampleWebSecureCustomApplication.java rename {spring-boot-samples/spring-boot-sample-web-secure-custom => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-web-secure-custom => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom}/src/main/resources/static/css/bootstrap.min.css (100%) rename {spring-boot-samples/spring-boot-sample-web-secure-custom => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom}/src/main/resources/templates/error.html (100%) rename {spring-boot-samples/spring-boot-sample-web-secure-custom => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom}/src/main/resources/templates/home.html (100%) rename {spring-boot-samples/spring-boot-sample-web-secure-custom => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom}/src/main/resources/templates/login.html (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/test/java/smoketest/web/secure/custom/SampleWebSecureCustomApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/java/smoketest/web/secure/jdbc/SampleWebSecureJdbcApplication.java rename {spring-boot-samples/spring-boot-sample-web-secure-jdbc => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-web-secure-jdbc => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc}/src/main/resources/data.sql (100%) rename {spring-boot-samples/spring-boot-sample-web-secure-jdbc => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc}/src/main/resources/schema.sql (100%) rename {spring-boot-samples/spring-boot-sample-web-secure-jdbc => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc}/src/main/resources/static/css/bootstrap.min.css (100%) rename {spring-boot-samples/spring-boot-sample-web-secure-jdbc => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc}/src/main/resources/templates/error.html (100%) rename {spring-boot-samples/spring-boot-sample-web-secure-jdbc => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc}/src/main/resources/templates/home.html (100%) rename {spring-boot-samples/spring-boot-sample-web-secure-jdbc => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc}/src/main/resources/templates/login.html (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/test/java/smoketest/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/java/smoketest/web/secure/SampleWebSecureApplication.java rename {spring-boot-samples/spring-boot-sample-web-secure => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-web-secure => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure}/src/main/resources/schema.sql (100%) rename {spring-boot-samples/spring-boot-sample-web-secure => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure}/src/main/resources/static/css/bootstrap.min.css (100%) rename {spring-boot-samples/spring-boot-sample-web-secure => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure}/src/main/resources/templates/error.html (100%) rename {spring-boot-samples/spring-boot-sample-web-secure => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure}/src/main/resources/templates/home.html (100%) rename {spring-boot-samples/spring-boot-sample-web-secure => spring-boot-smoke-tests/spring-boot-smoke-test-web-secure}/src/main/resources/templates/login.html (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/SampleSecureApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-static/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-static/src/main/java/smoketest/web/staticcontent/SampleWebStaticApplication.java rename {spring-boot-samples/spring-boot-sample-web-static => spring-boot-smoke-tests/spring-boot-smoke-test-web-static}/src/main/resources/static/index.html (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-static/src/test/java/smoketest/web/staticcontent/SampleWebStaticApplicationTests.java create mode 100755 spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/pom.xml create mode 100755 spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/InMemoryMessageRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/Message.java create mode 100755 spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/MessageRepository.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/SampleWebUiApplication.java create mode 100755 spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/mvc/MessageController.java rename {spring-boot-samples/spring-boot-sample-web-ui => spring-boot-smoke-tests/spring-boot-smoke-test-web-ui}/src/main/resources/application.properties (100%) rename {spring-boot-samples/spring-boot-sample-web-ui => spring-boot-smoke-tests/spring-boot-smoke-test-web-ui}/src/main/resources/logback.xml (100%) rename {spring-boot-samples/spring-boot-sample-web-ui => spring-boot-smoke-tests/spring-boot-smoke-test-web-ui}/src/main/resources/messages.properties (100%) rename {spring-boot-samples/spring-boot-sample-web-ui => spring-boot-smoke-tests/spring-boot-smoke-test-web-ui}/src/main/resources/static/css/bootstrap.min.css (100%) rename {spring-boot-samples/spring-boot-sample-web-ui => spring-boot-smoke-tests/spring-boot-smoke-test-web-ui}/src/main/resources/static/favicon.ico (100%) rename {spring-boot-samples/spring-boot-sample-web-ui => spring-boot-smoke-tests/spring-boot-smoke-test-web-ui}/src/main/resources/templates/fragments.html (100%) rename {spring-boot-samples/spring-boot-sample-web-ui => spring-boot-smoke-tests/spring-boot-smoke-test-web-ui}/src/main/resources/templates/messages/form.html (100%) rename {spring-boot-samples/spring-boot-sample-web-ui => spring-boot-smoke-tests/spring-boot-smoke-test-web-ui}/src/main/resources/templates/messages/list.html (100%) rename {spring-boot-samples/spring-boot-sample-web-ui => spring-boot-smoke-tests/spring-boot-smoke-test-web-ui}/src/main/resources/templates/messages/view.html (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/test/java/smoketest/web/ui/MessageControllerWebTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/test/java/smoketest/web/ui/SampleWebUiApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webflux/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/EchoHandler.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/ExampleController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/SampleWebFluxApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/WelcomeController.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/test/java/smoketest/webflux/SampleWebFluxApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webservices/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/SampleWebServicesApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/WebServiceConfig.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/endpoint/HolidayEndpoint.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/service/HumanResourceService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/service/StubHumanResourceService.java rename {spring-boot-samples/spring-boot-sample-webservices => spring-boot-smoke-tests/spring-boot-smoke-test-webservices}/src/main/resources/META-INF/schemas/hr.xsd (100%) rename {spring-boot-samples/spring-boot-sample-webservices => spring-boot-smoke-tests/spring-boot-smoke-test-webservices}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/test/java/smoketest/webservices/SampleWsApplicationTests.java create mode 100755 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/SampleJettyWebSocketsApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/client/GreetingService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/client/SimpleClientWebSocketHandler.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/client/SimpleGreetingService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/echo/DefaultEchoService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/echo/EchoService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/echo/EchoWebSocketHandler.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/reverse/ReverseWebSocketEndpoint.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Direction.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Location.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Snake.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/SnakeTimer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/SnakeUtils.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/SnakeWebSocketHandler.java rename {spring-boot-samples/spring-boot-sample-websocket-jetty => spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty}/src/main/resources/static/echo.html (100%) rename {spring-boot-samples/spring-boot-sample-websocket-jetty => spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty}/src/main/resources/static/index.html (100%) rename {spring-boot-samples/spring-boot-sample-websocket-jetty => spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty}/src/main/resources/static/reverse.html (100%) rename {spring-boot-samples/spring-boot-sample-websocket-jetty => spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty}/src/main/resources/static/snake.html (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/test/java/smoketest/websocket/jetty/SampleWebSocketsApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/test/java/smoketest/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/test/java/smoketest/websocket/jetty/snake/SnakeTimerTests.java create mode 100755 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/SampleTomcatWebSocketApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/client/GreetingService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/client/SimpleClientWebSocketHandler.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/client/SimpleGreetingService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/echo/DefaultEchoService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/echo/EchoService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/echo/EchoWebSocketHandler.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/reverse/ReverseWebSocketEndpoint.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Direction.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Location.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Snake.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/SnakeTimer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/SnakeUtils.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/SnakeWebSocketHandler.java rename {spring-boot-samples/spring-boot-sample-websocket-tomcat => spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat}/src/main/resources/static/echo.html (100%) rename {spring-boot-samples/spring-boot-sample-websocket-tomcat => spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat}/src/main/resources/static/index.html (100%) rename {spring-boot-samples/spring-boot-sample-websocket-tomcat => spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat}/src/main/resources/static/reverse.html (100%) rename {spring-boot-samples/spring-boot-sample-websocket-tomcat => spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat}/src/main/resources/static/snake.html (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/test/java/smoketest/websocket/tomcat/SampleWebSocketsApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/test/java/smoketest/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/test/java/smoketest/websocket/tomcat/snake/SnakeTimerTests.java create mode 100755 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/SampleUndertowWebSocketsApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/client/GreetingService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/client/SimpleClientWebSocketHandler.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/client/SimpleGreetingService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/echo/DefaultEchoService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/echo/EchoService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/echo/EchoWebSocketHandler.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/reverse/ReverseWebSocketEndpoint.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Direction.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Location.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Snake.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/SnakeTimer.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/SnakeUtils.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/SnakeWebSocketHandler.java rename {spring-boot-samples/spring-boot-sample-websocket-undertow => spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow}/src/main/resources/static/echo.html (100%) rename {spring-boot-samples/spring-boot-sample-websocket-undertow => spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow}/src/main/resources/static/index.html (100%) rename {spring-boot-samples/spring-boot-sample-websocket-undertow => spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow}/src/main/resources/static/reverse.html (100%) rename {spring-boot-samples/spring-boot-sample-websocket-undertow => spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow}/src/main/resources/static/snake.html (100%) create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/test/java/smoketest/websocket/undertow/SampleWebSocketsApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/test/java/smoketest/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/test/java/smoketest/websocket/undertow/snake/SnakeTimerTests.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-xml/pom.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/main/java/smoketest/xml/SampleSpringXmlApplication.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/main/java/smoketest/xml/service/HelloWorldService.java create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/main/resources/META-INF/application-context.xml create mode 100644 spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/test/java/smoketest/xml/SampleSpringXmlApplicationTests.java diff --git a/CONTRIBUTING.adoc b/CONTRIBUTING.adoc index ad44e78fe8..b5308db262 100755 --- a/CONTRIBUTING.adoc +++ b/CONTRIBUTING.adoc @@ -125,7 +125,7 @@ find the process a little slower than the standard build. [TIP] ==== -If you want to run a build without the samples and integration tests, building the +If you want to run a build without the smoke tests and integration tests, building the `spring-boot-project` module is enough. You can cd there and run the same command, or you can run this from the top-level directory: @@ -196,7 +196,7 @@ changes just won't be automatically formatted. With the requisite eclipse plugins installed you can select `import existing maven projects` from the `file` menu to import the code. You will -need to import the root `spring-boot` pom and the `spring-boot-samples` pom separately. +need to import the root `spring-boot` pom and the `spring-boot-smoke-tests` pom separately. @@ -241,11 +241,11 @@ Maven is well supported by most Java IDEs. Refer to your vendor documentation. == Integration Tests -The sample applications are used as integration tests during the build (when you -`./mvnw install`). Due to the fact that they make use of the `spring-boot-maven-plugin` +The smoke tests run as part of the build when you `./mvnw install`. +Due to the fact that they make use of the `spring-boot-maven-plugin` they cannot be called directly, and so instead are launched via the `maven-invoker-plugin`. If you encounter build failures running the integration tests, -check the `build.log` file in the appropriate sample directory. +check the `build.log` file in the appropriate smoke test directory. == Cloning the git repository on Windows diff --git a/README.adoc b/README.adoc index 9cd6d7dc3c..089eba4976 100755 --- a/README.adoc +++ b/README.adoc @@ -251,9 +251,6 @@ Groovy samples for use with the command line application are available in link:spring-boot-project/spring-boot-cli/samples[spring-boot-cli/samples]. To run the CLI samples type `spring run .groovy` from samples directory. -Java samples are available in link:spring-boot-samples[spring-boot-samples] and should -be built with maven and run by invoking `java -jar target/.jar`. - == Guides diff --git a/ci/scripts/build-samples.sh b/ci/scripts/build-samples.sh index bf27164251..9781ecf228 100755 --- a/ci/scripts/build-samples.sh +++ b/ci/scripts/build-samples.sh @@ -5,5 +5,5 @@ source $(dirname $0)/common.sh repository=$(pwd)/distribution-repository pushd git-repo > /dev/null -run_maven -f spring-boot-samples/pom.xml clean install -U -Dfull -Drepository=file://${repository} +run_maven -f spring-boot-smoke-tests/pom.xml clean install -U -Dfull -Drepository=file://${repository} popd > /dev/null diff --git a/ci/scripts/stage.sh b/ci/scripts/stage.sh index b8ecc4f625..f791917a16 100755 --- a/ci/scripts/stage.sh +++ b/ci/scripts/stage.sh @@ -36,7 +36,7 @@ git commit -m"Release v$stageVersion" > /dev/null git tag -a "v$stageVersion" -m"Release v$stageVersion" > /dev/null run_maven -f spring-boot-project/pom.xml clean deploy -U -Dfull -DaltDeploymentRepository=distribution::default::file://${repository} -run_maven -f spring-boot-samples/pom.xml clean install -U -Dfull -Drepository=file://${repository} +run_maven -f spring-boot-smoke-tests/pom.xml clean install -U -Dfull -Drepository=file://${repository} run_maven -f spring-boot-tests/spring-boot-integration-tests/pom.xml clean install -U -Dfull -Drepository=file://${repository} run_maven -f spring-boot-tests/spring-boot-deployment-tests/pom.xml clean install -U -Dfull -Drepository=file://${repository} diff --git a/eclipse/spring-boot-project.setup b/eclipse/spring-boot-project.setup index acb81c65f0..72985e11ac 100644 --- a/eclipse/spring-boot-project.setup +++ b/eclipse/spring-boot-project.setup @@ -127,10 +127,10 @@ pattern="spring-boot-starter(s|-.*)"/> + name="spring-boot-smoke-tests"> + pattern="spring-boot-smoke-test(s|-.*)"/> diff --git a/pom.xml b/pom.xml index f37b72e8df..28d97909af 100644 --- a/pom.xml +++ b/pom.xml @@ -106,8 +106,8 @@ spring-boot-project - - spring-boot-samples-invoker + + spring-boot-smoke-tests-invoker spring-boot-tests @@ -121,7 +121,7 @@ spring-boot-project - spring-boot-samples + spring-boot-smoke-tests spring-boot-tests diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc index 33fc8ed912..de4aeb50d4 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc @@ -557,7 +557,7 @@ editor for this example. [[getting-started-first-application-dependencies]] === Adding Classpath Dependencies Spring Boot provides a number of "`Starters`" that let you add jars to your classpath. -Our sample application has already used `spring-boot-starter-parent` in the `parent` +Our applications for smoke tests use the `spring-boot-starter-parent` in the `parent` section of the POM. The `spring-boot-starter-parent` is a special starter that provides useful Maven defaults. It also provides a <> @@ -819,11 +819,6 @@ https://spring.io/guides/[getting started] guides that solve specific "`How do I with Spring?`" problems. We also have Spring Boot-specific "`<>`" reference documentation. -The https://github.com/{github-repo}[Spring Boot repository] also has a -{github-code}/spring-boot-samples[bunch of samples] you can run. The samples are -independent of the rest of the code (that is, you do not need to build the rest to run or -use the samples). - Otherwise, the next logical step is to read _<>_. If you are really impatient, you could also jump ahead and read about _<>_. diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc index addc901e54..835adb7163 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -699,9 +699,7 @@ a plain HTTP connector at port 8080. Spring Boot does not support the configurat both an HTTP connector and an HTTPS connector through `application.properties`. If you want to have both, you need to configure one of them programmatically. We recommend using `application.properties` to configure HTTPS, as the HTTP connector is the easier of the -two to configure programmatically. See the -{github-code}/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors[`spring-boot-sample-tomcat-multi-connectors`] -sample project for an example. +two to configure programmatically. @@ -1668,9 +1666,7 @@ And the following example shows one way to set up the starters in Gradle: NOTE: The Log4j starters gather together the dependencies for common logging requirements (such as having Tomcat use `java.util.logging` but configuring the -output using Log4j 2). See the -{github-code}/spring-boot-samples/spring-boot-sample-actuator-log4j2[Actuator Log4j 2] -samples for more detail and to see it in action. +output using Log4j 2). NOTE: To ensure that debug logging performed using `java.util.logging` is routed into Log4j 2, configure its https://logging.apache.org/log4j/2.0/log4j-jul/index.html[JDK @@ -1895,9 +1891,7 @@ the same package (or a sub-package) of your `@EnableAutoConfiguration` class. For many applications, all you need is to put the right Spring Data dependencies on your classpath (there is a `spring-boot-starter-data-jpa` for JPA and a `spring-boot-starter-data-mongodb` for Mongodb) and create some repository interfaces to -handle your `@Entity` objects. Examples are in the -{github-code}/spring-boot-samples/spring-boot-sample-data-jpa[JPA sample] and the -{github-code}/spring-boot-samples/spring-boot-sample-data-mongodb[Mongodb sample]. +handle your `@Entity` objects. Spring Boot tries to guess the location of your `@Repository` definitions, based on the `@EnableAutoConfiguration` it finds. To get more control, use the `@EnableJpaRepositories` @@ -2356,8 +2350,6 @@ is sufficient to cause Flyway to use its own `DataSource`. If any of the three properties has not be set, the value of its equivalent `spring.datasource` property will be used. -There is a {github-code}/spring-boot-samples/spring-boot-sample-flyway[Flyway sample] so -that you can see how to set things up. You can also use Flyway to provide data for specific scenarios. For example, you can place test-specific migrations in `src/test/resources` and they are run only when your @@ -2399,9 +2391,6 @@ See {sc-spring-boot-autoconfigure}/liquibase/LiquibaseProperties.{sc-ext}[`LiquibaseProperties`] for details about available settings such as contexts, the default schema, and others. -There is a {github-code}/spring-boot-samples/spring-boot-sample-liquibase[Liquibase -sample] so that you can see how to set things up. - [[howto-messaging]] @@ -3049,22 +3038,6 @@ The following example shows how to build an executable archive with Ant: ---- -The {github-code}/spring-boot-samples/spring-boot-sample-ant[Ant Sample] has a -`build.xml` file with a `manual` task that should work if you run it with the following -command: - -[indent=0,subs="verbatim,quotes,attributes"] ----- - $ ant -lib clean manual ----- - -Then you can run the application with the following command: - -[indent=0,subs="verbatim,quotes,attributes"] ----- - $ java -jar target/*.jar ----- - [[howto-traditional-deployment]] @@ -3166,11 +3139,6 @@ file with the provided dependencies packaged in a `lib-provided` directory. This that, in addition to being deployable to a servlet container, you can also run your application by using `java -jar` on the command line. -TIP: Take a look at Spring Boot's sample applications for a -{github-code}/spring-boot-samples/spring-boot-sample-traditional/pom.xml[Maven-based -example] of the previously described configuration. - - [[howto-convert-an-existing-application-to-spring-boot]] diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index cae153fb80..296d786acc 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -1586,9 +1586,7 @@ You can also add a custom Spring `Validator` by creating a bean definition calle configuration properties validator is created very early in the application's lifecycle, and declaring the `@Bean` method as static lets the bean be created without having to instantiate the `@Configuration` class. Doing so avoids any problems that may be caused -by early instantiation. There is a -{github-code}/spring-boot-samples/spring-boot-sample-property-validation[property -validation sample] that shows how to set things up. +by early instantiation. TIP: The `spring-boot-actuator` module includes an endpoint that exposes all `@ConfigurationProperties` beans. Point your web browser to @@ -3212,9 +3210,6 @@ an `@Order`, which you can set with `spring.jersey.filter.order`. Both the servl the filter registrations can be given init parameters by using `spring.jersey.init.*` to specify a map of properties. -There is a {github-code}/spring-boot-samples/spring-boot-sample-jersey[Jersey sample] so -that you can see how to set things up. - [[boot-features-embedded-container]] @@ -3422,9 +3417,6 @@ packaged as an executable archive), there are some limitations in the JSP suppor <> should be used instead. -There is a {github-code}/spring-boot-samples/spring-boot-sample-web-jsp[JSP sample] so -that you can see how to set things up. - [[boot-features-reactive-server]] @@ -3646,8 +3638,6 @@ so does not disable the `UserDetailsService` configuration or Actuator's securit To also switch off the `UserDetailsService` configuration, you can add a bean of type `UserDetailsService`, `AuthenticationProvider`, or `AuthenticationManager`. -There are several secure applications in the {github-code}/spring-boot-samples/[Spring -Boot samples] to get you started with common use cases. Access rules can be overridden by adding a custom `WebSecurityConfigurerAdapter`. Spring Boot provides convenience methods that can be used to override access rules for actuator diff --git a/spring-boot-samples-invoker/pom.xml b/spring-boot-samples-invoker/pom.xml deleted file mode 100644 index 1b6538aaf9..0000000000 --- a/spring-boot-samples-invoker/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-parent - ${revision} - ../spring-boot-project/spring-boot-parent - - spring-boot-samples-invoker - pom - Spring Boot Samples Invoker - Spring Boot Samples Invoker - - ${basedir}/.. - - - - - - org.apache.maven.plugins - maven-invoker-plugin - false - - ${main.basedir}/spring-boot-samples - ${skipTests} - true - - pom.xml - - - - - integration-test - install - - run - - - - - - org.apache.maven.plugins - maven-antrun-plugin - false - - - clean-samples - clean - - run - - - - - - - - - - - - - org.apache.maven.plugins - maven-clean-plugin - false - - - clean-samples - clean - - clean - - - - - - - diff --git a/spring-boot-samples/README.adoc b/spring-boot-samples/README.adoc deleted file mode 100644 index a4d77923dc..0000000000 --- a/spring-boot-samples/README.adoc +++ /dev/null @@ -1,244 +0,0 @@ -= Spring Boot Samples - -The following sample applications are provided: - -|=== -| Sample | Description - -| link:spring-boot-sample-activemq[spring-boot-sample-activemq] -| JMS consumer and producer using Apache ActiveMQ - -| link:spring-boot-sample-actuator[spring-boot-sample-actuator] -| REST service with production-ready features - -| link:spring-boot-sample-actuator-log4j2[spring-boot-sample-actuator-log4j2] -| Production-ready features using log4j 2 for logging (instead of logback) - -| link:spring-boot-sample-actuator-noweb[spring-boot-sample-actuator-noweb] -| Non-web application with production-ready features - -| link:spring-boot-sample-actuator-ui[spring-boot-sample-actuator-ui] -| Web UI example with production-ready features - -| link:spring-boot-sample-amqp[spring-boot-sample-amqp] -| Message-oriented application using AMQP and RabbitMQ - -| link:spring-boot-sample-ant[spring-boot-sample-ant] -| Executable JAR build using Ant - -| link:spring-boot-sample-aop[spring-boot-sample-aop] -| Demonstrates explicit usage of Spring AOP - -| link:spring-boot-sample-atmosphere[spring-boot-sample-atmosphere] -| Chat service built using Atmosphere - -| link:spring-boot-sample-batch[spring-boot-sample-batch] -| Define and run a Batch job in a few lines of code - -| link:spring-boot-sample-cache[spring-boot-sample-cache] -| Web application that uses Spring's cache abstraction - -| link:spring-boot-sample-custom-layout[spring-boot-sample-custom-layout] -| Creates custom Jar Layout - -| link:spring-boot-sample-data-cassandra[spring-boot-sample-data-cassandra] -| Stores data using Spring Data Cassandra - -| link:spring-boot-sample-data-couchbase[spring-boot-sample-data-couchbase] -| Stores data using Spring Data Couchbase - -| link:spring-boot-sample-data-elasticsearch[spring-boot-sample-data-elasticsearch] -| Stores data using Spring Data Elasticsearch - -| link:spring-boot-sample-data-jdbc[spring-boot-sample-data-jdbc] -| Stores data using Spring Data JDBC - -| link:spring-boot-sample-data-jpa[spring-boot-sample-data-jpa] -| Stores data using Spring Data JPA with Hibernate - -| link:spring-boot-sample-data-ldap[spring-boot-sample-data-ldap] -| Stores data using Spring Data LDAP - -| link:spring-boot-sample-data-mongodb[spring-boot-sample-data-mongodb] -| Stores data using Spring Data MongoDB - -| link:spring-boot-sample-data-neo4j[spring-boot-sample-data-neo4j] -| Stores data using Spring Data Neo4j - -| link:spring-boot-sample-data-redis[spring-boot-sample-data-redis] -| Stores data using Spring Data Redis - -| link:spring-boot-sample-data-rest[spring-boot-sample-data-rest] -| RESTful service built using Spring Data REST - -| link:spring-boot-sample-data-solr[spring-boot-sample-data-solr] -| Stores data using Spring Data Solr - -| link:spring-boot-sample-devtools[spring-boot-sample-devtools] -| Using DevTools for rapid application development - -| link:spring-boot-sample-flyway[spring-boot-sample-flyway] -| Database migrations with Flyway - -| link:spring-boot-sample-hateoas[spring-boot-sample-hateoas] -| RESTful API built using Spring Hateoas - -| link:spring-boot-sample-integration[spring-boot-sample-integration] -| Integration application built using Spring Integration and its Java DSL - -| link:spring-boot-sample-jersey[spring-boot-sample-jersey] -| RESTful service built using Jersey - -| link:spring-boot-sample-jetty[spring-boot-sample-jetty] -| Embedded Jetty - -| link:spring-boot-sample-jetty-ssl[spring-boot-sample-jetty-ssl] -| Embedded Jetty configured to use SSL - -| link:spring-boot-sample-jetty-jsp[spring-boot-sample-jetty-jsp] -| Web application that uses JSP templates with Jetty - -| link:spring-boot-sample-jooq[spring-boot-sample-jooq] -| Stores data using jOOQ - -| link:spring-boot-sample-jpa[spring-boot-sample-jpa] -| Uses plain JPA (Hibernate) - -| link:spring-boot-sample-jta-atomikos[spring-boot-sample-jta-atomikos] -| JTA transactions with Atomikos - -| link:spring-boot-sample-jta-bitronix[spring-boot-sample-jta-bitronix] -| JTA transactions with Bitronix - -| link:spring-boot-sample-jta-jndi[spring-boot-sample-jta-jndi] -| JTA transactions using a `TransactionManager` and `DataSource` from JNDI - -| link:spring-boot-sample-junit-jupiter[spring-boot-sample-junit-jupiter] -| Demonstrates JUnit Jupiter-based testing - -| link:spring-boot-sample-kafka[spring-boot-sample-kafka] -| Consumer and producer using Apache Kafka - -| link:spring-boot-sample-liquibase[spring-boot-sample-liquibase] -| Database migrations with Liquibase - -| link:spring-boot-sample-logback[spring-boot-sample-logback] -| Demonstrates Spring Boot's custom Logback functionality configured in logback-spring.xml - -| link:spring-boot-sample-metrics-dropwizard[spring-boot-sample-metrics-dropwizard] -| Demonstrates support for Dropwizard metrics - -| link:spring-boot-sample-metrics-opentsdb[spring-boot-sample-metrics-opentsdb] -| Exports metrics to OpenTSDB - -| link:spring-boot-sample-metrics-redis[spring-boot-sample-metrics-redis] -| Exports metrics to Redis - -| link:spring-boot-sample-oauth2-client[spring-boot-sample-oauth2-client] -| Configure an OAuth2 login client - -| link:spring-boot-sample-reactive-oauth2-client[spring-boot-sample-reactive-oauth2-client] -| Configure a Reactive OAuth2 login client - -| link:spring-boot-sample-oauth2-resource-server[spring-boot-sample-oauth2-resource-server] -| Configure an OAuth2 resource server - -| link:spring-boot-sample-reactive-oauth2-resource-server[spring-boot-sample-reactive-oauth2-resource-server] -| Configure a Reactive OAuth2 resource server - -| link:spring-boot-sample-parent-context[spring-boot-sample-parent-context] -| Application that uses an `ApplicationContext` with a parent - -| link:spring-boot-sample-profile[spring-boot-sample-profile] -| Demonstrates some of Spring Framework's `@Profile` capabilities - -| link:spring-boot-sample-property-validation[spring-boot-sample-property-validation] -| Demonstrates the usage of `@ConfigurationProperties` with a Spring `Validator` - -| link:spring-boot-sample-secure[spring-boot-sample-secure] -| Non-web application that uses Spring Security - -| link:spring-boot-sample-servlet[spring-boot-sample-servlet] -| Web application with a "raw" `Servlet` returning plain text content - -| link:spring-boot-sample-session[spring-boot-sample-session] -| Web Application that uses Spring Session to manage session data - -| link:spring-boot-sample-simple[spring-boot-sample-simple] -| Simple command line application - -| link:spring-boot-sample-test[spring-boot-sample-test] -| Demonstrates Spring Boot's testing capabilities - -| link:spring-boot-sample-testng[spring-boot-sample-testng] -| Demonstrates TestNG-based testing - -| link:spring-boot-sample-tomcat[spring-boot-sample-tomcat] -| Embedded Tomcat - -| link:spring-boot-sample-tomcat-jsp[spring-boot-sample-tomcat-jsp] -| Web application that uses JSP templates with Tomcat - -| link:spring-boot-sample-tomcat-multi-connectors[spring-boot-sample-tomcat-multi-connectors] -| Web application that uses Tomcat configured with multiple connectors - -| link:spring-boot-sample-tomcat-ssl[spring-boot-sample-tomcat-ssl] -| Web application that uses Tomcat configured with SSL - -| link:spring-boot-sample-traditional[spring-boot-sample-traditional] -| Traditional WAR packaging (but also executable using `java -jar`) - -| link:spring-boot-sample-undertow[spring-boot-sample-undertow] -| Embedded Undertow - -| link:spring-boot-sample-undertow-ssl[spring-boot-sample-undertow-ssl] -| Embedded Undertow configured to use SSL - -| link:spring-boot-sample-war[spring-boot-sample-war] -| Web application packaged as a war file - -| link:spring-boot-sample-web-freemarker[spring-boot-sample-web-freemarker] -| Web application that uses FreeMarker templates - -| link:spring-boot-sample-web-groovy-templates[spring-boot-sample-web-groovy-templates] -| Web application that uses Groovy templates - -| link:spring-boot-sample-web-jsp[spring-boot-sample-web-jsp] -| Web application that uses JSP templates - -| link:spring-boot-sample-web-method-security[spring-boot-sample-web-method-security] -| Web application with Security configuration enabling global method security - -| link:spring-boot-sample-web-mustache[spring-boot-sample-web-mustache] -| Web application that uses Mustache views - -| link:spring-boot-sample-web-secure[spring-boot-sample-web-secure] -| Web application with typical Security configuration enabling a login form - -| link:spring-boot-sample-web-secure-custom[spring-boot-sample-web-secure-custom] -| Web application with custom Spring Security configuration - -| link:spring-boot-sample-web-secure-jdbc[spring-boot-sample-web-secure-jdbc] -| Web application with Spring Security configured to use JDBC authentication - -| link:spring-boot-sample-web-static[spring-boot-sample-web-static] -| Web application that serves static files - -| link:spring-boot-sample-web-ui[spring-boot-sample-web-ui] -| Web application with a basic UI built using Bootstrap and JQuery - -| link:spring-boot-sample-webservices[spring-boot-sample-webservices] -| Simple contract-first SOAP web service with Spring Web Services - -| link:spring-boot-sample-websocket-jetty[spring-boot-sample-websocket-jetty] -| WebSocket application that uses Jetty - -| link:spring-boot-sample-websocket-tomcat[spring-boot-sample-websocket-tomcat] -| WebSocket application that uses Tomcat - -| link:spring-boot-sample-websocket-undertow[spring-boot-sample-websocket-undertow] -| WebSocket application that uses Undertow - -| link:spring-boot-sample-xml[spring-boot-sample-xml] -| Example show how Spring Boot can be mixed with traditional XML configuration (we - generally recommend using Java `@Configuration` whenever possible diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml deleted file mode 100644 index b555b92df0..0000000000 --- a/spring-boot-samples/pom.xml +++ /dev/null @@ -1,250 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - ${revision} - ../spring-boot-project/spring-boot-starters/spring-boot-starter-parent - - spring-boot-samples - pom - Spring Boot Samples - Spring Boot Samples - - ${basedir}/.. - 1.8 - false - - - spring-boot-sample-ant - spring-boot-sample-activemq - spring-boot-sample-actuator - spring-boot-sample-actuator-log4j2 - spring-boot-sample-actuator-noweb - spring-boot-sample-actuator-ui - spring-boot-sample-actuator-custom-security - spring-boot-sample-amqp - spring-boot-sample-animated-banner - spring-boot-sample-aop - spring-boot-sample-atmosphere - spring-boot-sample-batch - spring-boot-sample-cache - spring-boot-sample-custom-layout - spring-boot-sample-data-cassandra - spring-boot-sample-data-couchbase - spring-boot-sample-data-elasticsearch - spring-boot-sample-data-jdbc - spring-boot-sample-data-jpa - spring-boot-sample-data-ldap - spring-boot-sample-data-mongodb - spring-boot-sample-data-neo4j - spring-boot-sample-data-redis - spring-boot-sample-data-rest - spring-boot-sample-data-solr - spring-boot-sample-devtools - spring-boot-sample-flyway - spring-boot-sample-hateoas - spring-boot-sample-integration - spring-boot-sample-jersey - spring-boot-sample-jetty - spring-boot-sample-jetty-jsp - spring-boot-sample-jetty-ssl - spring-boot-sample-jooq - spring-boot-sample-jpa - spring-boot-sample-jta-atomikos - spring-boot-sample-jta-bitronix - spring-boot-sample-jta-jndi - spring-boot-sample-junit-jupiter - spring-boot-sample-junit-vintage - spring-boot-sample-kafka - spring-boot-sample-liquibase - spring-boot-sample-logback - spring-boot-sample-oauth2-client - spring-boot-sample-oauth2-resource-server - spring-boot-sample-parent-context - spring-boot-sample-profile - spring-boot-sample-property-validation - spring-boot-sample-quartz - spring-boot-sample-reactive-oauth2-client - spring-boot-sample-reactive-oauth2-resource-server - spring-boot-sample-secure - spring-boot-sample-secure-webflux - spring-boot-sample-servlet - spring-boot-sample-session - spring-boot-sample-session-webflux - spring-boot-sample-simple - spring-boot-sample-test - spring-boot-sample-test-nomockito - spring-boot-sample-testng - spring-boot-sample-tomcat - spring-boot-sample-tomcat-jsp - spring-boot-sample-tomcat-ssl - spring-boot-sample-tomcat-multi-connectors - spring-boot-sample-traditional - spring-boot-sample-undertow - spring-boot-sample-undertow-ssl - spring-boot-sample-war - spring-boot-sample-web-freemarker - spring-boot-sample-web-groovy-templates - spring-boot-sample-web-jsp - spring-boot-sample-web-method-security - spring-boot-sample-web-mustache - spring-boot-sample-web-secure - spring-boot-sample-web-secure-custom - spring-boot-sample-web-secure-jdbc - spring-boot-sample-web-static - spring-boot-sample-web-ui - spring-boot-sample-webflux - spring-boot-sample-websocket-jetty - spring-boot-sample-websocket-tomcat - spring-boot-sample-websocket-undertow - spring-boot-sample-webservices - spring-boot-sample-xml - - - - - - - org.codehaus.mojo - flatten-maven-plugin - true - - - flatten - process-resources - - flatten - - - true - oss - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.apache.maven.plugins - - - maven-enforcer-plugin - - - [1.3.1,) - - - enforce - - - - - - - - - - org.springframework.boot - - - spring-boot-maven-plugin - - - [1.4.0.BUILD-SNAPSHOT,) - - - build-info - - - - - - - - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*Tests.java - - - **/Abstract*.java - - - file:/dev/./urandom - true - - - - - org.apache.maven.plugins - maven-enforcer-plugin - - - enforce-rules - - enforce - - - - - - commons-logging:*:* - - true - - - true - - - - - - org.apache.maven.plugins - maven-install-plugin - - true - - - - org.apache.maven.plugins - maven-javadoc-plugin - - true - - true - - - - - - fast - - - fast - - - - true - - - - diff --git a/spring-boot-samples/spring-boot-sample-activemq/pom.xml b/spring-boot-samples/spring-boot-sample-activemq/pom.xml deleted file mode 100644 index 5a865f7680..0000000000 --- a/spring-boot-samples/spring-boot-sample-activemq/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - 4.0.0 - - - spring-boot-samples - org.springframework.boot - ${revision} - - spring-boot-sample-activemq - Spring Boot ActiveMQ Sample - Spring Boot ActiveMQ Sample - - ${basedir}/../.. - - - - - org.springframework.boot - spring-boot-starter-activemq - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/spring-boot-samples/spring-boot-sample-activemq/src/main/java/sample/activemq/Consumer.java b/spring-boot-samples/spring-boot-sample-activemq/src/main/java/sample/activemq/Consumer.java deleted file mode 100644 index c3baf20193..0000000000 --- a/spring-boot-samples/spring-boot-sample-activemq/src/main/java/sample/activemq/Consumer.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.activemq; - -import org.springframework.jms.annotation.JmsListener; -import org.springframework.stereotype.Component; - -@Component -public class Consumer { - - @JmsListener(destination = "sample.queue") - public void receiveQueue(String text) { - System.out.println(text); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-activemq/src/main/java/sample/activemq/Producer.java b/spring-boot-samples/spring-boot-sample-activemq/src/main/java/sample/activemq/Producer.java deleted file mode 100644 index ae000863f7..0000000000 --- a/spring-boot-samples/spring-boot-sample-activemq/src/main/java/sample/activemq/Producer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.activemq; - -import javax.jms.Queue; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.jms.core.JmsMessagingTemplate; -import org.springframework.stereotype.Component; - -@Component -public class Producer implements CommandLineRunner { - - @Autowired - private JmsMessagingTemplate jmsMessagingTemplate; - - @Autowired - private Queue queue; - - @Override - public void run(String... args) throws Exception { - send("Sample message"); - System.out.println("Message was sent to the Queue"); - } - - public void send(String msg) { - this.jmsMessagingTemplate.convertAndSend(this.queue, msg); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-activemq/src/main/java/sample/activemq/SampleActiveMQApplication.java b/spring-boot-samples/spring-boot-sample-activemq/src/main/java/sample/activemq/SampleActiveMQApplication.java deleted file mode 100644 index fb48a93163..0000000000 --- a/spring-boot-samples/spring-boot-sample-activemq/src/main/java/sample/activemq/SampleActiveMQApplication.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.activemq; - -import javax.jms.Queue; - -import org.apache.activemq.command.ActiveMQQueue; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.jms.annotation.EnableJms; - -@SpringBootApplication -@EnableJms -public class SampleActiveMQApplication { - - @Bean - public Queue queue() { - return new ActiveMQQueue("sample.queue"); - } - - public static void main(String[] args) { - SpringApplication.run(SampleActiveMQApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-activemq/src/test/java/sample/activemq/SampleActiveMqTests.java b/spring-boot-samples/spring-boot-sample-activemq/src/test/java/sample/activemq/SampleActiveMqTests.java deleted file mode 100644 index 41f0d4cf15..0000000000 --- a/spring-boot-samples/spring-boot-sample-activemq/src/test/java/sample/activemq/SampleActiveMqTests.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.activemq; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for demo application. - * - * @author Eddú Meléndez - */ -@SpringBootTest -@ExtendWith(OutputCaptureExtension.class) -class SampleActiveMqTests { - - @Autowired - private Producer producer; - - @Test - void sendSimpleMessage(CapturedOutput capturedOutput) throws InterruptedException { - this.producer.send("Test message"); - Thread.sleep(1000L); - assertThat(capturedOutput).contains("Test message"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/pom.xml b/spring-boot-samples/spring-boot-sample-actuator-custom-security/pom.xml deleted file mode 100644 index 4f94511e49..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-samples - ${revision} - - spring-boot-sample-actuator-custom-security - Spring Boot Actuator Custom Security Sample - Spring Boot Actuator Custom Security Sample - - ${basedir}/../.. - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-freemarker - - - org.springframework.boot - spring-boot-starter-security - - - org.jolokia - jolokia-core - - - - org.apache.httpcomponents - httpclient - runtime - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/ExampleController.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/ExampleController.java deleted file mode 100644 index 382629276a..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/ExampleController.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.customsecurity; - -import java.util.Date; -import java.util.Map; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; - -@Controller -public class ExampleController { - - @GetMapping("/") - public String home(Map model) { - model.put("message", "Hello World"); - model.put("title", "Hello Home"); - model.put("date", new Date()); - return "home"; - } - - @RequestMapping("/foo") - public String foo() { - throw new RuntimeException("Expected exception in controller"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/ExampleRestControllerEndpoint.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/ExampleRestControllerEndpoint.java deleted file mode 100644 index 52fc2d4c5e..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/ExampleRestControllerEndpoint.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.customsecurity; - -import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Component; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -@Component -@RestControllerEndpoint(id = "example") -public class ExampleRestControllerEndpoint { - - @GetMapping("/echo") - public ResponseEntity echo(@RequestParam("text") String text) { - return ResponseEntity.ok().header("echo", text).body(text); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplication.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplication.java deleted file mode 100644 index ec13c48665..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.customsecurity; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleActuatorCustomSecurityApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleActuatorCustomSecurityApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java deleted file mode 100644 index 0f45475c4e..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.customsecurity; - -import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; -import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; -import org.springframework.boot.autoconfigure.security.servlet.PathRequest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.provisioning.InMemoryUserDetailsManager; - -@Configuration(proxyBeanMethods = false) -public class SecurityConfiguration extends WebSecurityConfigurerAdapter { - - @SuppressWarnings("deprecation") - @Bean - public InMemoryUserDetailsManager inMemoryUserDetailsManager() { - return new InMemoryUserDetailsManager( - User.withDefaultPasswordEncoder().username("user").password("password").authorities("ROLE_USER") - .build(), - User.withDefaultPasswordEncoder().username("beans").password("beans").authorities("ROLE_BEANS").build(), - User.withDefaultPasswordEncoder().username("admin").password("admin") - .authorities("ROLE_ACTUATOR", "ROLE_USER").build()); - } - - @Override - protected void configure(HttpSecurity http) throws Exception { - // @formatter:off - http.authorizeRequests() - .mvcMatchers("/actuator/beans").hasRole("BEANS") - .requestMatchers(EndpointRequest.to("health", "info")).permitAll() - .requestMatchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class)).hasRole("ACTUATOR") - .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() - .antMatchers("/foo").permitAll() - .antMatchers("/**").hasRole("USER") - .and() - .cors() - .and() - .httpBasic(); - // @formatter:on - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java deleted file mode 100644 index 741e33a1f6..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.customsecurity; - -import java.net.URI; -import java.util.Map; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.ApplicationContext; -import org.springframework.http.HttpStatus; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ActiveProfiles; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration test for cors preflight requests to management endpoints. - * - * @author Madhura Bhave - */ -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ActiveProfiles("cors") -class CorsSampleActuatorApplicationTests { - - private TestRestTemplate testRestTemplate; - - @Autowired - private ApplicationContext applicationContext; - - @BeforeEach - void setUp() { - RestTemplateBuilder builder = new RestTemplateBuilder(); - LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(this.applicationContext.getEnvironment(), - "http"); - builder = builder.uriTemplateHandler(handler); - this.testRestTemplate = new TestRestTemplate(builder); - } - - @Test - void endpointShouldReturnUnauthorized() { - ResponseEntity entity = this.testRestTemplate.getForEntity("/actuator/env", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void preflightRequestToEndpointShouldReturnOk() throws Exception { - RequestEntity healthRequest = RequestEntity.options(new URI("/actuator/env")) - .header("Origin", "http://localhost:8080").header("Access-Control-Request-Method", "GET").build(); - ResponseEntity exchange = this.testRestTemplate.exchange(healthRequest, Map.class); - assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.OK); - } - - @Test - void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() throws Exception { - RequestEntity entity = RequestEntity.options(new URI("/actuator/env")) - .header("Origin", "http://localhost:9095").header("Access-Control-Request-Method", "GET").build(); - ResponseEntity exchange = this.testRestTemplate.exchange(entity, byte[].class); - assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java deleted file mode 100644 index 5c04d4ca69..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.customsecurity; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for separate management and main service ports. - * - * @author Dave Syer - * @author Madhura Bhave - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, - properties = { "management.server.port=0", "management.server.servlet.context-path=/management" }) -class ManagementPortAndPathSampleActuatorApplicationTests { - - @LocalServerPort - private int port; - - @LocalManagementPort - private int managementPort; - - @Test - void testHome() { - ResponseEntity entity = new TestRestTemplate("user", "password") - .getForEntity("http://localhost:" + this.port, String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("Hello World"); - } - - @Test - void actuatorPathOnMainPortShouldNotMatch() { - ResponseEntity entity = new TestRestTemplate() - .getForEntity("http://localhost:" + this.port + "/actuator/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void testSecureActuator() { - ResponseEntity entity = new TestRestTemplate() - .getForEntity("http://localhost:" + this.managementPort + "/management/actuator/env", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void testInsecureActuator() { - ResponseEntity entity = new TestRestTemplate() - .getForEntity("http://localhost:" + this.managementPort + "/management/actuator/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"status\":\"UP\""); - } - - @Test - void testMissing() { - ResponseEntity entity = new TestRestTemplate("admin", "admin") - .getForEntity("http://localhost:" + this.managementPort + "/management/actuator/missing", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); - assertThat(entity.getBody()).contains("\"status\":404"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java deleted file mode 100644 index 59e3809100..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.customsecurity; - -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Madhura Bhave - * @author Stephane Nicoll - */ -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class SampleActuatorCustomSecurityApplicationTests { - - @Autowired - private Environment environment; - - @Test - void homeIsSecure() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = restTemplate().getForEntity("/", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat(body.get("error")).isEqualTo("Unauthorized"); - assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); - } - - @Test - void testInsecureApplicationPath() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = restTemplate().getForEntity("/foo", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - @SuppressWarnings("unchecked") - Map body = entity.getBody(); - assertThat((String) body.get("message")).contains("Expected exception in controller"); - } - - @Test - void testInsecureStaticResources() { - ResponseEntity entity = restTemplate().getForEntity("/css/bootstrap.min.css", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("body"); - } - - @Test - void actuatorInsecureEndpoint() { - ResponseEntity entity = restTemplate().getForEntity("/actuator/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"status\":\"UP\""); - } - - @Test - void actuatorLinksIsSecure() { - ResponseEntity entity = restTemplate().getForEntity("/actuator", Object.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - entity = adminRestTemplate().getForEntity("/actuator", Object.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - } - - @Test - void actuatorSecureEndpointWithAnonymous() { - ResponseEntity entity = restTemplate().getForEntity("/actuator/env", Object.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void actuatorSecureEndpointWithUnauthorizedUser() { - ResponseEntity entity = userRestTemplate().getForEntity("/actuator/env", Object.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); - } - - @Test - void actuatorSecureEndpointWithAuthorizedUser() { - ResponseEntity entity = adminRestTemplate().getForEntity("/actuator/env", Object.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - } - - @Test - void actuatorCustomMvcSecureEndpointWithAnonymous() { - ResponseEntity entity = restTemplate().getForEntity("/actuator/example/echo?text={t}", String.class, - "test"); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void actuatorCustomMvcSecureEndpointWithUnauthorizedUser() { - ResponseEntity entity = userRestTemplate().getForEntity("/actuator/example/echo?text={t}", String.class, - "test"); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); - } - - @Test - void actuatorCustomMvcSecureEndpointWithAuthorizedUser() { - ResponseEntity entity = adminRestTemplate().getForEntity("/actuator/example/echo?text={t}", - String.class, "test"); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("test"); - assertThat(entity.getHeaders().getFirst("echo")).isEqualTo("test"); - } - - @Test - void actuatorExcludedFromEndpointRequestMatcher() { - ResponseEntity entity = userRestTemplate().getForEntity("/actuator/mappings", Object.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - } - - @Test - void mvcMatchersCanBeUsedToSecureActuators() { - ResponseEntity entity = beansRestTemplate().getForEntity("/actuator/beans", Object.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - entity = beansRestTemplate().getForEntity("/actuator/beans/", Object.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - } - - private TestRestTemplate restTemplate() { - return configure(new TestRestTemplate()); - } - - private TestRestTemplate adminRestTemplate() { - return configure(new TestRestTemplate("admin", "admin")); - } - - private TestRestTemplate userRestTemplate() { - return configure(new TestRestTemplate("user", "password")); - } - - private TestRestTemplate beansRestTemplate() { - return configure(new TestRestTemplate("beans", "beans")); - } - - private TestRestTemplate configure(TestRestTemplate restTemplate) { - restTemplate.setUriTemplateHandler(new LocalHostUriTemplateHandler(this.environment)); - return restTemplate; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/pom.xml b/spring-boot-samples/spring-boot-sample-actuator-log4j2/pom.xml deleted file mode 100644 index 759e4926ea..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-log4j2/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-samples - ${revision} - - spring-boot-sample-actuator-log4j2 - Spring Boot Actuator Log4j 2 Sample - Spring Boot Actuator Log4j 2 Sample - - ${basedir}/../.. - - - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-logging - - - - - org.springframework.boot - spring-boot-starter-log4j2 - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-security - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleActuatorLog4J2Application.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleActuatorLog4J2Application.java deleted file mode 100644 index 8eea7f66a3..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleActuatorLog4J2Application.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.log4j2; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleActuatorLog4J2Application { - - public static void main(String[] args) { - SpringApplication.run(SampleActuatorLog4J2Application.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java deleted file mode 100644 index 91437ee87d..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.log4j2; - -import java.util.Base64; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; -import org.springframework.test.web.servlet.MockMvc; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * Tests for {@link SampleActuatorLog4J2Application}. - * - * @author Dave Syer - * @author Stephane Nicoll - */ -@SpringBootTest -@AutoConfigureMockMvc -@ExtendWith(OutputCaptureExtension.class) -class SampleActuatorLog4J2ApplicationTests { - - private static final Logger logger = LogManager.getLogger(SampleActuatorLog4J2ApplicationTests.class); - - @Autowired - private MockMvc mvc; - - @Test - void testLogger(CapturedOutput capturedOutput) { - logger.info("Hello World"); - assertThat(capturedOutput).contains("Hello World"); - } - - @Test - void validateLoggersEndpoint() throws Exception { - this.mvc.perform(get("/actuator/loggers/org.apache.coyote.http11.Http11NioProtocol").header("Authorization", - "Basic " + getBasicAuth())).andExpect(status().isOk()).andExpect( - content().string(equalTo("{\"configuredLevel\":\"WARN\"," + "\"effectiveLevel\":\"WARN\"}"))); - } - - private String getBasicAuth() { - return new String(Base64.getEncoder().encode(("user:password").getBytes())); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml b/spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml deleted file mode 100644 index add5fe534d..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-samples - ${revision} - - spring-boot-sample-actuator-noweb - Spring Boot Actuator Non-Web Sample - Spring Boot Actuator Non-Web Sample - - ${basedir}/../.. - - - - - org.springframework.boot - spring-boot-starter-actuator - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/HelloWorldService.java deleted file mode 100644 index c08b14f8c8..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/HelloWorldService.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.noweb; - -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - private final ServiceProperties configuration; - - public HelloWorldService(ServiceProperties configuration) { - this.configuration = configuration; - } - - public String getHelloMessage() { - return "Hello " + this.configuration.getName(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/SampleActuatorNoWebApplication.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/SampleActuatorNoWebApplication.java deleted file mode 100644 index 8ecb9d1f28..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/SampleActuatorNoWebApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.noweb; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleActuatorNoWebApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleActuatorNoWebApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/ServiceProperties.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/ServiceProperties.java deleted file mode 100644 index 0d02f58eec..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/sample/actuator/noweb/ServiceProperties.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.noweb; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) -public class ServiceProperties { - - /** - * Name of the service. - */ - private String name = "World"; - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/noweb/SampleActuatorNoWebApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/noweb/SampleActuatorNoWebApplicationTests.java deleted file mode 100644 index 03378f1966..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/noweb/SampleActuatorNoWebApplicationTests.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.noweb; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.test.context.SpringBootTest; - -/** - * Basic integration tests for service demo application. - * - * @author Dave Syer - */ -@SpringBootTest -class SampleActuatorNoWebApplicationTests { - - @Test - void contextLoads() { - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/pom.xml b/spring-boot-samples/spring-boot-sample-actuator-ui/pom.xml deleted file mode 100644 index 04cec5b143..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-samples - ${revision} - - spring-boot-sample-actuator-ui - Spring Boot Actuator UI Sample - Spring Boot Actuator UI Sample - - ${basedir}/../.. - - - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-freemarker - - - org.springframework.boot - spring-boot-starter-security - - - org.jolokia - jolokia-core - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/java/sample/actuator/ui/SampleActuatorUiApplication.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/java/sample/actuator/ui/SampleActuatorUiApplication.java deleted file mode 100644 index 5114f9bce1..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/java/sample/actuator/ui/SampleActuatorUiApplication.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.ui; - -import java.util.Date; -import java.util.Map; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; - -@SpringBootApplication -@Controller -public class SampleActuatorUiApplication { - - @GetMapping("/") - public String home(Map model) { - model.put("message", "Hello World"); - model.put("title", "Hello Home"); - model.put("date", new Date()); - return "home"; - } - - @RequestMapping("/foo") - public String foo() { - throw new RuntimeException("Expected exception in controller"); - } - - public static void main(String[] args) { - SpringApplication.run(SampleActuatorUiApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java deleted file mode 100644 index f4f1187a1a..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.ui; - -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for separate management and main service ports. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port:0" }) -class SampleActuatorUiApplicationPortTests { - - @LocalServerPort - private int port; - - @LocalManagementPort - private int managementPort; - - @Test - void testHome() { - ResponseEntity entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - } - - @Test - void testMetrics() { - @SuppressWarnings("rawtypes") - ResponseEntity entity = new TestRestTemplate() - .getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void testHealth() { - ResponseEntity entity = new TestRestTemplate().withBasicAuth("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"status\":\"UP\""); - } - - private String getPassword() { - return "password"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java deleted file mode 100644 index 13e585d4b7..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator.ui; - -import java.util.Arrays; -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleActuatorUiApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHome() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/", - HttpMethod.GET, new HttpEntity(headers), String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("Hello"); - } - - @Test - void testCss() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("body"); - } - - @Test - void testMetrics() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void testError() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/error", - HttpMethod.GET, new HttpEntity<Void>(headers), String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - assertThat(entity.getBody()).contains("<html>").contains("<body>") - .contains("Please contact the operator with the above information"); - } - - private String getPassword() { - return "password"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/pom.xml b/spring-boot-samples/spring-boot-sample-actuator/pom.xml deleted file mode 100644 index 7c345c7f85..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/pom.xml +++ /dev/null @@ -1,86 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-actuator</artifactId> - <name>Spring Boot Actuator Sample</name> - <description>Spring Boot Actuator Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jdbc</artifactId> - </dependency> - <!-- Runtime --> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <scope>runtime</scope> - </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>runtime</scope> - </dependency> - <!-- Optional --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-configuration-processor</artifactId> - <optional>true</optional> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <configuration> - <executable>true</executable> - </configuration> - <executions> - <execution> - <id>generate build info</id> - <goals> - <goal>build-info</goal> - </goals> - <configuration> - <additionalProperties> - <encoding.source>${project.build.sourceEncoding}</encoding.source> - <encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting> - <java.source>${maven.compiler.source}</java.source> - <java.target>${maven.compiler.target}</java.target> - </additionalProperties> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ExampleHealthIndicator.java b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ExampleHealthIndicator.java deleted file mode 100644 index 1d034ee9be..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ExampleHealthIndicator.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import org.springframework.boot.actuate.health.Health; -import org.springframework.boot.actuate.health.HealthIndicator; -import org.springframework.stereotype.Component; - -@Component -public class ExampleHealthIndicator implements HealthIndicator { - - @Override - public Health health() { - return Health.up().withDetail("counter", 42).build(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ExampleInfoContributor.java b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ExampleInfoContributor.java deleted file mode 100644 index 9b22173692..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ExampleInfoContributor.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import java.util.Collections; - -import org.springframework.boot.actuate.info.Info; -import org.springframework.boot.actuate.info.InfoContributor; -import org.springframework.stereotype.Component; - -@Component -public class ExampleInfoContributor implements InfoContributor { - - @Override - public void contribute(Info.Builder builder) { - builder.withDetail("example", Collections.singletonMap("someKey", "someValue")); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/HelloWorldService.java deleted file mode 100644 index e565cfedd4..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/HelloWorldService.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - private final ServiceProperties configuration; - - public HelloWorldService(ServiceProperties configuration) { - this.configuration = configuration; - } - - public String getHelloMessage() { - return "Hello " + this.configuration.getName(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleActuatorApplication.java b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleActuatorApplication.java deleted file mode 100644 index f114d86ac3..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleActuatorApplication.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.actuate.health.Health; -import org.springframework.boot.actuate.health.HealthIndicator; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -public class SampleActuatorApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleActuatorApplication.class, args); - } - - @Bean - public HealthIndicator helloHealthIndicator() { - return () -> Health.up().withDetail("hello", "world").build(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java deleted file mode 100644 index 6c136ee68f..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import java.util.Collections; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.Map; - -import javax.validation.constraints.NotBlank; - -import org.springframework.context.annotation.Description; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Controller; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -@Description("A controller for handling requests for hello messages") -public class SampleController { - - private final HelloWorldService helloWorldService; - - public SampleController(HelloWorldService helloWorldService) { - this.helloWorldService = helloWorldService; - } - - @GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - public Map<String, String> hello() { - return Collections.singletonMap("message", this.helloWorldService.getHelloMessage()); - } - - @PostMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - public Map<String, Object> olleh(@Validated Message message) { - Map<String, Object> model = new LinkedHashMap<>(); - model.put("message", message.getValue()); - model.put("title", "Hello Home"); - model.put("date", new Date()); - return model; - } - - @RequestMapping("/foo") - @ResponseBody - public String foo() { - throw new IllegalArgumentException("Server error"); - } - - protected static class Message { - - @NotBlank(message = "Message value cannot be empty") - private String value; - - public String getValue() { - return this.value; - } - - public void setValue(String value) { - this.value = value; - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ServiceProperties.java b/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ServiceProperties.java deleted file mode 100644 index 8cd33b49d0..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/ServiceProperties.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) -public class ServiceProperties { - - /** - * Name of the service. - */ - private String name = "World"; - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java deleted file mode 100644 index f53be03c1c..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ActiveProfiles; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for endpoints configuration. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ActiveProfiles("endpoints") -class EndpointsPropertiesSampleActuatorApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testCustomErrorPath() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/oops", - Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("error")).isEqualTo("None"); - assertThat(body.get("status")).isEqualTo(999); - } - - @Test - void testCustomContextPath() { - ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/admin/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"status\":\"UP\""); - assertThat(entity.getBody()).contains("\"hello\":\"world\""); - } - - private String getPassword() { - return "password"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java deleted file mode 100644 index 98f86bc4c5..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for separate management and main service ports. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=0", - "management.server.address=127.0.0.1", "management.server.servlet.context-path:/admin" }) -class ManagementAddressActuatorApplicationTests { - - @LocalServerPort - private int port; - - @LocalManagementPort - private int managementPort; - - @Test - void testHome() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void testHealth() { - ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/admin/actuator/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"status\":\"UP\""); - } - - private String getPassword() { - return "password"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java deleted file mode 100644 index 075013f7ea..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for endpoints configuration. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, - properties = { "management.endpoints.web.base-path=/admin" }) -class ManagementPathSampleActuatorApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHealth() { - ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/admin/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"status\":\"UP\""); - } - - @Test - void testHomeIsSecure() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.getForEntity("/", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("error")).isEqualTo("Unauthorized"); - assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); - } - - private String getPassword() { - return "password"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java deleted file mode 100644 index 9788a6e2e1..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for separate management and main service ports. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=0", - "management.endpoints.web.base-path=/admin", "management.endpoint.health.show-details=never" }) -class ManagementPortAndPathSampleActuatorApplicationTests { - - @LocalServerPort - private int port; - - @LocalManagementPort - private int managementPort; - - @Autowired - private Environment environment; - - @Test - void testHome() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.port, Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("message")).isEqualTo("Hello Phil"); - } - - @Test - void testMetrics() { - testHome(); // makes sure some requests have been made - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate() - .getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void testHealth() { - ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}"); - } - - @Test - void testEnvNotFound() { - String unknownProperty = "test-does-not-exist"; - assertThat(this.environment.containsProperty(unknownProperty)).isFalse(); - ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()).getForEntity( - "http://localhost:" + this.managementPort + "/admin/env/" + unknownProperty, String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); - } - - @Test - void testMissing() { - ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/admin/missing", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); - assertThat(entity.getBody()).contains("\"status\":404"); - } - - @Test - void testErrorPage() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.port + "/error", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("status")).isEqualTo(999); - } - - @Test - void testManagementErrorPage() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("status")).isEqualTo(999); - } - - private String getPassword() { - return "password"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java deleted file mode 100644 index 9e768efb58..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for separate management and main service ports. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, - properties = { "management.server.port=0", "management.endpoint.health.show-details=always" }) -class ManagementPortSampleActuatorApplicationTests { - - @LocalServerPort - private int port; - - @LocalManagementPort - private int managementPort; - - @Test - void testHome() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.port, Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("message")).isEqualTo("Hello Phil"); - } - - @Test - void testMetrics() { - testHome(); // makes sure some requests have been made - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate() - .getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void testHealth() { - ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"status\":\"UP\""); - assertThat(entity.getBody()).contains("\"example\""); - assertThat(entity.getBody()).contains("\"counter\":42"); - } - - @Test - void testErrorPage() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("status")).isEqualTo(999); - } - - private String getPassword() { - return "password"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortWithLazyInitializationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortWithLazyInitializationTests.java deleted file mode 100644 index 5bbf340e3b..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortWithLazyInitializationTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for separate management and main service ports when - * lazy-initialization is enabled. - * - * @author Madhura Bhave - */ -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = { "management.server.port=0", "spring.main.lazy-initialization=true" }) -class ManagementPortWithLazyInitializationTests { - - @LocalManagementPort - private int managementPort; - - @Test - void testHealth() { - ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password") - .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"status\":\"UP\""); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java deleted file mode 100644 index 2a62dfc694..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for switching off management endpoints. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=-1" }) -class NoManagementSampleActuatorApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHome() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", - Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("message")).isEqualTo("Hello Phil"); - } - - @Test - void testMetricsNotAvailable() { - testHome(); // makes sure some requests have been made - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/metrics", - Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); - } - - private String getPassword() { - return "password"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java deleted file mode 100644 index ef1ea60e61..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.context.ApplicationContext; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for service demo application. - * - * @author Dave Syer - * @author Stephane Nicoll - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleActuatorApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Autowired - private ApplicationContext applicationContext; - - @Test - void testHomeIsSecure() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.getForEntity("/", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("error")).isEqualTo("Unauthorized"); - assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); - } - - @Test - void testMetricsIsSecure() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - entity = this.restTemplate.getForEntity("/actuator/metrics/", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - entity = this.restTemplate.getForEntity("/actuator/metrics/foo", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - entity = this.restTemplate.getForEntity("/actuator/metrics.json", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void testHome() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", - Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("message")).isEqualTo("Hello Phil"); - } - - @SuppressWarnings("unchecked") - @Test - void testMetrics() { - testHome(); // makes sure some requests have been made - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/actuator/metrics", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - Map<String, Object> body = entity.getBody(); - assertThat(body).containsKey("names"); - assertThat((List<String>) body.get("names")).contains("jvm.buffer.count"); - - } - - @Test - void testEnv() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/actuator/env", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body).containsKey("propertySources"); - } - - @Test - void healthInsecureByDefault() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"status\":\"UP\""); - assertThat(entity.getBody()).doesNotContain("\"hello\":\"1\""); - } - - @Test - void infoInsecureByDefault() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/info", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"artifact\":\"spring-boot-sample-actuator\""); - assertThat(entity.getBody()).contains("\"someKey\":\"someValue\""); - assertThat(entity.getBody()).contains("\"java\":{", "\"source\":\"1.8\"", "\"target\":\"1.8\""); - assertThat(entity.getBody()).contains("\"encoding\":{", "\"source\":\"UTF-8\"", "\"reporting\":\"UTF-8\""); - } - - @Test - void testErrorPage() { - ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/foo", - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - String body = entity.getBody(); - assertThat(body).contains("\"error\":"); - } - - @Test - void testHtmlErrorPage() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - HttpEntity<?> request = new HttpEntity<Void>(headers); - ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/foo", - HttpMethod.GET, request, String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - String body = entity.getBody(); - assertThat(body).as("Body was null").isNotNull(); - assertThat(body).contains("This application has no explicit mapping for /error"); - } - - @Test - void testErrorPageDirectAccess() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/error", - Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("error")).isEqualTo("None"); - assertThat(body.get("status")).isEqualTo(999); - } - - @Test - @SuppressWarnings("unchecked") - void testBeans() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/actuator/beans", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).containsOnlyKeys("contexts"); - } - - @SuppressWarnings("unchecked") - @Test - void testConfigProps() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/actuator/configprops", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - Map<String, Object> body = entity.getBody(); - Map<String, Object> contexts = (Map<String, Object>) body.get("contexts"); - Map<String, Object> context = (Map<String, Object>) contexts.get(this.applicationContext.getId()); - Map<String, Object> beans = (Map<String, Object>) context.get("beans"); - assertThat(beans).containsKey("spring.datasource-" + DataSourceProperties.class.getName()); - } - - private String getPassword() { - return "password"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java deleted file mode 100644 index 5b56c96168..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for endpoints configuration. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.mvc.servlet.path=/spring" }) -class ServletPathSampleActuatorApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testErrorPath() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/spring/error", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("error")).isEqualTo("None"); - assertThat(body.get("status")).isEqualTo(999); - } - - @Test - void testHealth() { - ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/spring/actuator/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"status\":\"UP\""); - } - - @Test - void testHomeIsSecure() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/", Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("error")).isEqualTo("Unauthorized"); - assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); - } - - private String getPassword() { - return "password"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java deleted file mode 100644 index 4bb7f69748..0000000000 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.actuator; - -import java.util.Map; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.test.annotation.DirtiesContext; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for separate management and main service ports. - * - * @author Dave Syer - */ -@SpringBootTest(classes = { ShutdownSampleActuatorApplicationTests.SecurityConfiguration.class, - SampleActuatorApplication.class }, webEnvironment = WebEnvironment.RANDOM_PORT) -class ShutdownSampleActuatorApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHome() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", - Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(body.get("message")).isEqualTo("Hello Phil"); - } - - @Test - @DirtiesContext - void testShutdown() { - @SuppressWarnings("rawtypes") - ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) - .postForEntity("/actuator/shutdown", null, Map.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - @SuppressWarnings("unchecked") - Map<String, Object> body = entity.getBody(); - assertThat(((String) body.get("message"))).contains("Shutting down"); - } - - private String getPassword() { - return "password"; - } - - @Configuration(proxyBeanMethods = false) - static class SecurityConfiguration extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable(); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-amqp/pom.xml b/spring-boot-samples/spring-boot-sample-amqp/pom.xml deleted file mode 100644 index 2a9de00d25..0000000000 --- a/spring-boot-samples/spring-boot-sample-amqp/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-amqp</artifactId> - <name>Spring Boot AMQP Sample</name> - <description>Spring Boot AMQP Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-amqp</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-amqp/src/main/java/sample/amqp/SampleAmqpSimpleApplication.java b/spring-boot-samples/spring-boot-sample-amqp/src/main/java/sample/amqp/SampleAmqpSimpleApplication.java deleted file mode 100644 index ead4364488..0000000000 --- a/spring-boot-samples/spring-boot-sample-amqp/src/main/java/sample/amqp/SampleAmqpSimpleApplication.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.amqp; - -import java.util.Date; - -import org.springframework.amqp.core.Queue; -import org.springframework.amqp.rabbit.annotation.RabbitHandler; -import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.messaging.handler.annotation.Payload; -import org.springframework.scheduling.annotation.EnableScheduling; - -@SpringBootApplication -@RabbitListener(queues = "foo") -@EnableScheduling -public class SampleAmqpSimpleApplication { - - @Bean - public Sender mySender() { - return new Sender(); - } - - @Bean - public Queue fooQueue() { - return new Queue("foo"); - } - - @RabbitHandler - public void process(@Payload String foo) { - System.out.println(new Date() + ": " + foo); - } - - public static void main(String[] args) { - SpringApplication.run(SampleAmqpSimpleApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-amqp/src/main/java/sample/amqp/Sender.java b/spring-boot-samples/spring-boot-sample-amqp/src/main/java/sample/amqp/Sender.java deleted file mode 100644 index 7e6f893652..0000000000 --- a/spring-boot-samples/spring-boot-sample-amqp/src/main/java/sample/amqp/Sender.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.amqp; - -import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; - -public class Sender { - - @Autowired - private RabbitTemplate rabbitTemplate; - - @Scheduled(fixedDelay = 1000L) - public void send() { - this.rabbitTemplate.convertAndSend("foo", "hello"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-animated-banner/pom.xml b/spring-boot-samples/spring-boot-sample-animated-banner/pom.xml deleted file mode 100644 index 69621abbb2..0000000000 --- a/spring-boot-samples/spring-boot-sample-animated-banner/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-animated-banner</artifactId> - <name>Spring Boot Simple Animated Banner</name> - <description>Spring Boot Simple Animated Banner</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-animated-banner/src/main/java/sample/animated/SampleAnimatedBannerApplication.java b/spring-boot-samples/spring-boot-sample-animated-banner/src/main/java/sample/animated/SampleAnimatedBannerApplication.java deleted file mode 100644 index c777c19d74..0000000000 --- a/spring-boot-samples/spring-boot-sample-animated-banner/src/main/java/sample/animated/SampleAnimatedBannerApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.animated; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleAnimatedBannerApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleAnimatedBannerApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-ant/build.xml b/spring-boot-samples/spring-boot-sample-ant/build.xml deleted file mode 100644 index 68c7b752dc..0000000000 --- a/spring-boot-samples/spring-boot-sample-ant/build.xml +++ /dev/null @@ -1,69 +0,0 @@ -<project - xmlns:ivy="antlib:org.apache.ivy.ant" - xmlns:spring-boot="antlib:org.springframework.boot.ant" - name="spring-boot-sample-ant" - default="build"> - - <description> - Sample ANT build script for a Spring Boot executable JAR project. Uses ivy for - dependency management and spring-boot-antlib for additional tasks. Run with - '$ ant -lib ivy-2.2.jar spring-boot-antlib.jar' (substitute the location of your - actual jars). Run with '$ java -jar target/*.jar'. - </description> - - <property name="ant-spring-boot.version" value="${revision}" /> - <property name="lib.dir" location="${basedir}/target/lib" /> - <property name="start-class" value="sample.ant.SampleAntApplication" /> - - <target name="resolve" description="--> retrieve dependencies with ivy"> - <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact]-[type]-[revision].[ext]" /> - </target> - - <target name="classpaths" depends="resolve"> - <path id="compile.classpath"> - <fileset dir="${lib.dir}/compile" includes="*.jar" /> - </path> - </target> - - <target name="init" depends="classpaths"> - <mkdir dir="target/classes" /> - </target> - - <target name="compile" depends="init" description="compile"> - <javac srcdir="src/main/java" destdir="target/classes" classpathref="compile.classpath" /> - </target> - - <target name="clean" description="cleans all created files/dirs"> - <delete dir="target" /> - </target> - - <target name="build" depends="compile"> - <spring-boot:exejar destfile="target/${ant.project.name}-${ant-spring-boot.version}.jar" classes="target/classes"> - <spring-boot:lib> - <fileset dir="${lib.dir}/runtime" /> - </spring-boot:lib> - </spring-boot:exejar> - </target> - <!-- Manual equivalent of the build target --> - <target name="manual" depends="compile"> - <jar destfile="target/${ant.project.name}-${ant-spring-boot.version}.jar" compress="false"> - <mappedresources> - <fileset dir="target/classes" /> - <globmapper from="*" to="BOOT-INF/classes/*"/> - </mappedresources> - <mappedresources> - <fileset dir="src/main/resources" erroronmissingdir="false"/> - <globmapper from="*" to="BOOT-INF/classes/*"/> - </mappedresources> - <mappedresources> - <fileset dir="${lib.dir}/runtime" /> - <globmapper from="*" to="BOOT-INF/lib/*"/> - </mappedresources> - <zipfileset src="${lib.dir}/loader/spring-boot-loader-jar-${ant-spring-boot.version}.jar" /> - <manifest> - <attribute name="Main-Class" value="org.springframework.boot.loader.JarLauncher" /> - <attribute name="Start-Class" value="${start-class}" /> - </manifest> - </jar> - </target> -</project> diff --git a/spring-boot-samples/spring-boot-sample-ant/ivy.xml b/spring-boot-samples/spring-boot-sample-ant/ivy.xml deleted file mode 100644 index a09621d5ba..0000000000 --- a/spring-boot-samples/spring-boot-sample-ant/ivy.xml +++ /dev/null @@ -1,12 +0,0 @@ -<ivy-module version="2.0"> - <info organisation="org.springframework.boot" module="spring-boot-sample-ant" /> - <configurations> - <conf name="compile" description="everything needed to compile this module" /> - <conf name="runtime" extends="compile" description="everything needed to run this module" /> - <conf name="loader" description="Spring Boot loader used when manually building an executable archive" /> - </configurations> - <dependencies> - <dependency org="org.springframework.boot" name="spring-boot-starter" rev="${ant-spring-boot.version}" conf="compile" /> - <dependency org="org.springframework.boot" name="spring-boot-loader" rev="${ant-spring-boot.version}" conf="loader->default" /> - </dependencies> -</ivy-module> diff --git a/spring-boot-samples/spring-boot-sample-ant/pom.xml b/spring-boot-samples/spring-boot-sample-ant/pom.xml deleted file mode 100644 index 7b42650ce5..0000000000 --- a/spring-boot-samples/spring-boot-sample-ant/pom.xml +++ /dev/null @@ -1,107 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <!-- This POM is just to trigger the Ant/Ivy sample from Maven and to test --> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-ant</artifactId> - <name>Spring Boot Ant Sample</name> - <description>Spring Boot Ant Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <ant.version>1.9.3</ant.version> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-loader</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-antlib</artifactId> - <version>${project.version}</version> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-loader-tools</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <executions> - <execution> - <id>default-compile</id> - <phase>none</phase> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-antrun-plugin</artifactId> - <executions> - <execution> - <id>antbuild</id> - <phase>package</phase> - <configuration> - <target> - <property name="build.compiler" value="extJavac" /> - <ant dir="${basedir}" /> - </target> - </configuration> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.apache.ant</groupId> - <artifactId>ant</artifactId> - <version>${ant.version}</version> - </dependency> - <dependency> - <groupId>org.apache.ivy</groupId> - <artifactId>ivy</artifactId> - <version>2.4.0</version> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-antlib</artifactId> - <version>${revision}</version> - </dependency> - </dependencies> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>integration-test</goal> - <goal>verify</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-ant/src/main/java/sample/ant/SampleAntApplication.java b/spring-boot-samples/spring-boot-sample-ant/src/main/java/sample/ant/SampleAntApplication.java deleted file mode 100644 index 464342f4c0..0000000000 --- a/spring-boot-samples/spring-boot-sample-ant/src/main/java/sample/ant/SampleAntApplication.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.ant; - -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleAntApplication implements CommandLineRunner { - - @Override - public void run(String... args) { - System.out.println("Spring Boot Ant Example"); - } - - public static void main(String[] args) { - SpringApplication.run(SampleAntApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java b/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java deleted file mode 100644 index 75c0f35a38..0000000000 --- a/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.ant; - -import java.io.File; -import java.io.FileFilter; -import java.io.InputStreamReader; -import java.util.concurrent.TimeUnit; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.loader.tools.JavaExecutable; -import org.springframework.util.FileCopyUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration Tests for {@code SampleAntApplication}. - * - * @author Dave Syer - * @author Phillip Webb - */ -public class SampleAntApplicationIT { - - @Test - void runJar() throws Exception { - File target = new File("target"); - File[] jarFiles = target.listFiles(new FileFilter() { - - @Override - public boolean accept(File file) { - return file.getName().endsWith(".jar"); - } - - }); - assertThat(jarFiles).hasSize(1); - Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start(); - process.waitFor(5, TimeUnit.MINUTES); - assertThat(process.exitValue()).isEqualTo(0); - String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream())); - assertThat(output).contains("Spring Boot Ant Example"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-aop/pom.xml b/spring-boot-samples/spring-boot-sample-aop/pom.xml deleted file mode 100644 index d09cae360e..0000000000 --- a/spring-boot-samples/spring-boot-sample-aop/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-aop</artifactId> - <name>Spring Boot AOP Sample</name> - <description>Spring Boot AOP Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-aop</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-aop/src/main/java/sample/aop/SampleAopApplication.java b/spring-boot-samples/spring-boot-sample-aop/src/main/java/sample/aop/SampleAopApplication.java deleted file mode 100644 index 4fa7e379c0..0000000000 --- a/spring-boot-samples/spring-boot-sample-aop/src/main/java/sample/aop/SampleAopApplication.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.aop; - -import sample.aop.service.HelloWorldService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleAopApplication implements CommandLineRunner { - - // Simple example shows how an application can spy on itself with AOP - - @Autowired - private HelloWorldService helloWorldService; - - @Override - public void run(String... args) { - System.out.println(this.helloWorldService.getHelloMessage()); - } - - public static void main(String[] args) { - SpringApplication.run(SampleAopApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-aop/src/main/java/sample/aop/monitor/ServiceMonitor.java b/spring-boot-samples/spring-boot-sample-aop/src/main/java/sample/aop/monitor/ServiceMonitor.java deleted file mode 100644 index d2f06a7fa4..0000000000 --- a/spring-boot-samples/spring-boot-sample-aop/src/main/java/sample/aop/monitor/ServiceMonitor.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.aop.monitor; - -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.AfterReturning; -import org.aspectj.lang.annotation.Aspect; - -import org.springframework.stereotype.Component; - -@Aspect -@Component -public class ServiceMonitor { - - @AfterReturning("execution(* sample..*Service.*(..))") - public void logServiceAccess(JoinPoint joinPoint) { - System.out.println("Completed: " + joinPoint); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-aop/src/main/java/sample/aop/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-aop/src/main/java/sample/aop/service/HelloWorldService.java deleted file mode 100644 index ab8b1c85ef..0000000000 --- a/spring-boot-samples/spring-boot-sample-aop/src/main/java/sample/aop/service/HelloWorldService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.aop.service; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - @Value("${name:World}") - private String name; - - public String getHelloMessage() { - return "Hello " + this.name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-aop/src/test/java/sample/aop/SampleAopApplicationTests.java b/spring-boot-samples/spring-boot-sample-aop/src/test/java/sample/aop/SampleAopApplicationTests.java deleted file mode 100644 index 17a96ef670..0000000000 --- a/spring-boot-samples/spring-boot-sample-aop/src/test/java/sample/aop/SampleAopApplicationTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.aop; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SampleAopApplication}. - * - * @author Dave Syer - * @author Phillip Webb - */ -@ExtendWith(OutputCaptureExtension.class) -class SampleAopApplicationTests { - - private String profiles; - - @BeforeEach - void init() { - this.profiles = System.getProperty("spring.profiles.active"); - } - - @AfterEach - void after() { - if (this.profiles != null) { - System.setProperty("spring.profiles.active", this.profiles); - } - else { - System.clearProperty("spring.profiles.active"); - } - } - - @Test - void testDefaultSettings(CapturedOutput capturedOutput) throws Exception { - SampleAopApplication.main(new String[0]); - assertThat(capturedOutput).contains("Hello Phil"); - } - - @Test - void testCommandLineOverrides(CapturedOutput capturedOutput) throws Exception { - SampleAopApplication.main(new String[] { "--name=Gordon" }); - assertThat(capturedOutput).contains("Hello Gordon"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/pom.xml b/spring-boot-samples/spring-boot-sample-atmosphere/pom.xml deleted file mode 100644 index 64b73a0cd6..0000000000 --- a/spring-boot-samples/spring-boot-sample-atmosphere/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-atmosphere</artifactId> - <name>Spring Boot Atmosphere Sample</name> - <description>Spring Boot Atmosphere Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>javax.inject</groupId> - <artifactId>javax.inject</artifactId> - <version>1</version> - </dependency> - <dependency> - <groupId>org.atmosphere</groupId> - <artifactId>atmosphere-runtime</artifactId> - <version>2.4.14</version> - </dependency> - <dependency> - <groupId>org.webjars</groupId> - <artifactId>atmosphere-javascript</artifactId> - <version>2.3.4</version> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-websocket</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/ChatService.java b/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/ChatService.java deleted file mode 100644 index 1dd151dbfa..0000000000 --- a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/ChatService.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.atmosphere; - -import java.io.IOException; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.atmosphere.config.managed.Decoder; -import org.atmosphere.config.managed.Encoder; -import org.atmosphere.config.service.Disconnect; -import org.atmosphere.config.service.ManagedService; -import org.atmosphere.config.service.Ready; -import org.atmosphere.cpr.AtmosphereResource; -import org.atmosphere.cpr.AtmosphereResourceEvent; - -@ManagedService(path = "/chat") -public class ChatService { - - private final Log logger = LogFactory.getLog(ChatService.class); - - @Ready - public void onReady(AtmosphereResource resource) { - this.logger.info("Connected " + resource.uuid()); - } - - @Disconnect - public void onDisconnect(AtmosphereResourceEvent event) { - this.logger.info("Client " + event.getResource().uuid() + " disconnected [" - + (event.isCancelled() ? "cancelled" : "closed") + "]"); - } - - @org.atmosphere.config.service.Message(encoders = JacksonEncoderDecoder.class, - decoders = JacksonEncoderDecoder.class) - public Message onMessage(Message message) throws IOException { - this.logger.info("Author " + message.getAuthor() + " sent message " + message.getMessage()); - return message; - } - - public static class JacksonEncoderDecoder implements Encoder<Message, String>, Decoder<String, Message> { - - private final ObjectMapper mapper = new ObjectMapper(); - - @Override - public String encode(Message m) { - try { - return this.mapper.writeValueAsString(m); - } - catch (IOException ex) { - throw new IllegalStateException(ex); - } - } - - @Override - public Message decode(String s) { - try { - return this.mapper.readValue(s, Message.class); - } - catch (IOException ex) { - throw new IllegalStateException(ex); - } - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/Message.java b/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/Message.java deleted file mode 100644 index 3ceb718279..0000000000 --- a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/Message.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.atmosphere; - -import java.util.Date; - -public class Message { - - private String message; - - private String author; - - private long time = new Date().getTime(); - - public String getMessage() { - return this.message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getAuthor() { - return this.author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public long getTime() { - return this.time; - } - - public void setTime(long time) { - this.time = time; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/SampleAtmosphereApplication.java b/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/SampleAtmosphereApplication.java deleted file mode 100644 index 0c075b2e4c..0000000000 --- a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/java/sample/atmosphere/SampleAtmosphereApplication.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.atmosphere; - -import java.util.Collections; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; - -import org.atmosphere.cpr.AtmosphereServlet; -import org.atmosphere.cpr.ContainerInitializer; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.web.servlet.ServletContextInitializer; -import org.springframework.boot.web.servlet.ServletRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.Ordered; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@SpringBootConfiguration -@EnableAutoConfiguration -public class SampleAtmosphereApplication { - - @Bean - public EmbeddedAtmosphereInitializer atmosphereInitializer() { - return new EmbeddedAtmosphereInitializer(); - } - - @Bean - public ServletRegistrationBean<AtmosphereServlet> atmosphereServlet() { - // Dispatcher servlet is mapped to '/home' to allow the AtmosphereServlet - // to be mapped to '/chat' - AtmosphereServlet atmosphereServlet = new AtmosphereServlet(); - atmosphereServlet.framework().setHandlersPath("/"); - ServletRegistrationBean<AtmosphereServlet> registration = new ServletRegistrationBean<>(atmosphereServlet, - "/chat/*"); - registration.addInitParameter("org.atmosphere.cpr.packages", "sample"); - registration.addInitParameter( - "org.atmosphere.interceptor.HeartbeatInterceptor" + ".clientHeartbeatFrequencyInSeconds", "10"); - registration.setLoadOnStartup(0); - // Need to occur before the EmbeddedAtmosphereInitializer - registration.setOrder(Ordered.HIGHEST_PRECEDENCE); - return registration; - } - - public static void main(String[] args) throws Exception { - SpringApplication.run(SampleAtmosphereApplication.class, args); - } - - @Configuration(proxyBeanMethods = false) - static class MvcConfiguration implements WebMvcConfigurer { - - @Override - public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/").setViewName("forward:/home/home.html"); - } - - } - - private static class EmbeddedAtmosphereInitializer extends ContainerInitializer - implements ServletContextInitializer { - - @Override - public void onStartup(ServletContext servletContext) throws ServletException { - onStartup(Collections.emptySet(), servletContext); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java deleted file mode 100644 index a500372d65..0000000000 --- a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.atmosphere; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(classes = SampleAtmosphereApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleAtmosphereApplicationTests { - - private static Log logger = LogFactory.getLog(SampleAtmosphereApplicationTests.class); - - @LocalServerPort - private int port = 1234; - - @Test - void chatEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/chat/websocket") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0L); - assertThat(messagePayloadReference.get()).contains("{\"message\":\"test\",\"author\":\"test\",\"time\":"); - } - - @Configuration(proxyBeanMethods = false) - static class ClientConfiguration implements CommandLineRunner { - - @Value("${websocket.uri}") - private String webSocketUri; - - private final CountDownLatch latch = new CountDownLatch(1); - - private final AtomicReference<String> messagePayload = new AtomicReference<>(); - - @Override - public void run(String... args) throws Exception { - logger.info("Waiting for response: latch=" + this.latch.getCount()); - if (this.latch.await(10, TimeUnit.SECONDS)) { - logger.info("Got response: " + this.messagePayload.get()); - } - else { - logger.info("Response not received: latch=" + this.latch.getCount()); - } - } - - @Bean - public WebSocketConnectionManager wsConnectionManager() { - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); - manager.setAutoStartup(true); - return manager; - } - - @Bean - public StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } - - @Bean - public TextWebSocketHandler handler() { - return new TextWebSocketHandler() { - - @Override - public void afterConnectionEstablished(WebSocketSession session) throws Exception { - session.sendMessage(new TextMessage("{\"author\":\"test\",\"message\":\"test\"}")); - } - - @Override - protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - logger.info("Received: " + message + " (" + ClientConfiguration.this.latch.getCount() + ")"); - session.close(); - ClientConfiguration.this.messagePayload.set(message.getPayload()); - ClientConfiguration.this.latch.countDown(); - } - }; - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-batch/pom.xml b/spring-boot-samples/spring-boot-sample-batch/pom.xml deleted file mode 100644 index a08bf27fef..0000000000 --- a/spring-boot-samples/spring-boot-sample-batch/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-batch</artifactId> - <name>Spring Boot Batch Sample</name> - <description>Spring Boot Batch Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-batch</artifactId> - </dependency> - <!-- Runtime --> - <dependency> - <groupId>org.hsqldb</groupId> - <artifactId>hsqldb</artifactId> - <scope>runtime</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-batch/src/main/java/sample/batch/SampleBatchApplication.java b/spring-boot-samples/spring-boot-sample-batch/src/main/java/sample/batch/SampleBatchApplication.java deleted file mode 100644 index 0c737c4a55..0000000000 --- a/spring-boot-samples/spring-boot-sample-batch/src/main/java/sample/batch/SampleBatchApplication.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.batch; - -import org.springframework.batch.core.Job; -import org.springframework.batch.core.Step; -import org.springframework.batch.core.StepContribution; -import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; -import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; -import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; -import org.springframework.batch.core.scope.context.ChunkContext; -import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.repeat.RepeatStatus; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -@EnableBatchProcessing -public class SampleBatchApplication { - - @Autowired - private JobBuilderFactory jobs; - - @Autowired - private StepBuilderFactory steps; - - @Bean - protected Tasklet tasklet() { - - return new Tasklet() { - @Override - public RepeatStatus execute(StepContribution contribution, ChunkContext context) { - return RepeatStatus.FINISHED; - } - }; - - } - - @Bean - public Job job() throws Exception { - return this.jobs.get("job").start(step1()).build(); - } - - @Bean - protected Step step1() throws Exception { - return this.steps.get("step1").tasklet(tasklet()).build(); - } - - public static void main(String[] args) { - // System.exit is common for Batch applications since the exit code can be used to - // drive a workflow - System.exit(SpringApplication.exit(SpringApplication.run(SampleBatchApplication.class, args))); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java b/spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java deleted file mode 100644 index e120a3f888..0000000000 --- a/spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.batch; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -@ExtendWith(OutputCaptureExtension.class) -class SampleBatchApplicationTests { - - @Test - void testDefaultSettings(CapturedOutput capturedOutput) { - assertThat(SpringApplication.exit(SpringApplication.run(SampleBatchApplication.class))).isEqualTo(0); - assertThat(capturedOutput).contains("completed with the following parameters"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-cache/README.adoc b/spring-boot-samples/spring-boot-sample-cache/README.adoc deleted file mode 100644 index ee332a9799..0000000000 --- a/spring-boot-samples/spring-boot-sample-cache/README.adoc +++ /dev/null @@ -1,126 +0,0 @@ -= Spring Boot Cache Sample - -This sample demonstrates the caching auto-configuration support. Spring's caching -abstraction is supported by many caching libraries, including: - -* Any compliant `JSR-107` (JCache) provider -* `EhCache` -* `Hazelcast` -* `Infinispan` -* `Couchbase` -* `Redis` -* `Caffeine` -* Simple provider based on `ConcurrentHashMap` -* Generic provider based on `org.springframework.Cache` bean definition(s) - -The sample defines a simple `CountryService` that caches countries by ISO code. When -the application starts a client invokes the service with a random code every 500ms. -You can look at the `/metrics` endpoint to review the cache statistics if your chosen -caching provider is supported. - - - -== Using the JSR-107 annotations -The sample uses Spring's cache annotation. If you want to use the JSR-107 annotations -instead, simply add the `javax.cache:cache-api` dependency to the project. No further -configuration is necessary. - -NOTE: You can use the JSR-107 annotations with _any_ cache provider; a JSR-107 -compliant cache provider is not necessary. - - - -== Using a different cache provider -Initially, the project does not define any caching library so the abstraction works -on simple `ConcurrentHashMap`-based caches. You can try out your favorite caching -library as explained below. - - - -=== JCache (JSR-107) -If you want to configure your cache infrastructure via the standard, you need a -compliant implementation and the JSR-107 api. You first need to add -`javax.cache:cache-api` to your project. Then you could try the following: - -* `EhCache 3`: add `org.ehcache:ehcache` -* `Hazelcast`: add `com.hazelcast:hazelcast` -* `Infinispan`: add `org.infinispan:infinispan-jcache` - -TIP: Run sample cache application using JCache and EhCache3 by uncommenting the -`spring.cache.jcache.config` property and `$mvn spring-boot:run -Pehcache`. - -TIP: Refer to the documentation of the JSR-107 implementation you want to use: certain -cache providers do not create a default cache on-the-fly if it does not exist so you might -need to update the sample to create the caches on startup or specify the location to the -provider-specific file via the `spring.cache.jcache.config` property. - -NOTE: Any other JSR-107 compliant provider is also supported but Spring Boot may not -offer a dependency management entry for it. You will have to add it with the version -of the library that you want to use. - - - -=== EhCache 2.x -Simply add the `net.sf.ehcache:ehcache` dependency to the project. Since there is a -default `ehcache.xml` configuration file at the root of the classpath, -it is automatically used to configure the underlying `CacheManager`. -Note that EhCache 3 uses a different format and doesn't default to `ehcache.xml` -anymore. Check https://www.ehcache.org/documentation/3.0/xml.html[the documentation] -for more details. - -TIP: Run sample cache application using EhCache with -`$mvn spring-boot:run -Pehcache2`. - - - -=== Hazelcast -Both `com.hazelcast:hazelcast` and `com.hazelcast:hazelcast-spring` should be added -to the project to enable support for Hazelcast. Since there is a default -`hazelcast.xml` configuration file at the root of the classpath, it is used to -automatically configure the underlying `HazelcastInstance`. - -TIP: Run sample cache application using Hazelcast with -`$mvn spring-boot:run -Phazelcast`. - - - -=== Infinispan -Add the `org.infinispan:infinispan-spring4-embedded` dependency to enable support for -Infinispan. There is no default location that Infinispan uses to look for a config -file so this sample is configured to use the provider `infinispan.xml` configuration -file specified via the `spring.cache.infinispan.config` property. - -TIP: Run sample cache application using Infinispan with -`$mvn spring-boot:run -Pinfinispan`. - -NOTE: If you want to use the client/server mode or if you need more options, Infinispan -provides an official Spring Boot starter, check -https://github.com/infinispan/infinispan-spring-boot[the documentation] for more details. - - - -=== Couchbase -Add the `java-client` and `couchbase-spring-cache` dependencies and make sure that -you have setup at least a `spring.couchbase.bootstrap-hosts` property. - -TIP: Run sample cache application using Couchbase with -`$mvn spring-boot:run -Pcouchbase`. - - - -=== Redis -Add the `spring-boot-starter-data-redis` and make sure it is configured properly (by -default, a redis instance with the default settings is expected on your local box). - -TIP: Run sample cache application using Redis with -`$mvn spring-boot:run -Predis`. - - - -=== Caffeine -Simply add the `com.github.ben-manes.caffeine:caffeine` dependency to enable support -for Caffeine. You can customize how caches are created in different ways, see -`application.properties` for an example and the documentation for more details. - -TIP: Run sample cache application using Caffeine with -`$mvn spring-boot:run -Pcaffeine`. diff --git a/spring-boot-samples/spring-boot-sample-cache/pom.xml b/spring-boot-samples/spring-boot-sample-cache/pom.xml deleted file mode 100644 index 349bdb8bae..0000000000 --- a/spring-boot-samples/spring-boot-sample-cache/pom.xml +++ /dev/null @@ -1,128 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-cache</artifactId> - <name>Spring Boot Cache Sample</name> - <description>Spring Boot Cache Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-cache</artifactId> - </dependency> - <!-- Only used to expose cache metrics --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>caffeine</id> - <dependencies> - <dependency> - <groupId>com.github.ben-manes.caffeine</groupId> - <artifactId>caffeine</artifactId> - </dependency> - </dependencies> - </profile> - <profile> - <id>couchbase</id> - <dependencies> - <dependency> - <groupId>com.couchbase.client</groupId> - <artifactId>java-client</artifactId> - </dependency> - <dependency> - <groupId>com.couchbase.client</groupId> - <artifactId>couchbase-spring-cache</artifactId> - </dependency> - </dependencies> - </profile> - <profile> - <id>ehcache2</id> - <dependencies> - <dependency> - <groupId>net.sf.ehcache</groupId> - <artifactId>ehcache</artifactId> - </dependency> - </dependencies> - </profile> - <profile> - <id>ehcache</id> - <dependencies> - <dependency> - <groupId>javax.cache</groupId> - <artifactId>cache-api</artifactId> - </dependency> - <dependency> - <groupId>org.ehcache</groupId> - <artifactId>ehcache</artifactId> - </dependency> - </dependencies> - </profile> - <profile> - <id>hazelcast</id> - <dependencies> - <dependency> - <groupId>com.hazelcast</groupId> - <artifactId>hazelcast</artifactId> - </dependency> - <dependency> - <groupId>com.hazelcast</groupId> - <artifactId>hazelcast-spring</artifactId> - </dependency> - </dependencies> - </profile> - <profile> - <id>infinispan</id> - <dependencies> - <dependency> - <groupId>org.infinispan</groupId> - <artifactId>infinispan-spring4-embedded</artifactId> - </dependency> - <dependency> - <groupId>org.infinispan</groupId> - <artifactId>infinispan-jcache</artifactId> - </dependency> - </dependencies> - </profile> - <profile> - <id>redis</id> - <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-redis</artifactId> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/CacheManagerCheck.java b/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/CacheManagerCheck.java deleted file mode 100644 index e6c28f9f38..0000000000 --- a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/CacheManagerCheck.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.cache; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.boot.CommandLineRunner; -import org.springframework.cache.CacheManager; -import org.springframework.stereotype.Component; - -@Component -public class CacheManagerCheck implements CommandLineRunner { - - private static final Log logger = LogFactory.getLog(CacheManagerCheck.class); - - private final CacheManager cacheManager; - - public CacheManagerCheck(CacheManager cacheManager) { - this.cacheManager = cacheManager; - } - - @Override - public void run(String... strings) throws Exception { - logger.info("\n\n" + "=========================================================\n" + "Using cache manager: " - + this.cacheManager.getClass().getName() + "\n" - + "=========================================================\n\n"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/Country.java b/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/Country.java deleted file mode 100644 index 8a8eea0cca..0000000000 --- a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/Country.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.cache; - -import java.io.Serializable; - -@SuppressWarnings("serial") -public class Country implements Serializable { - - private final String code; - - public Country(String code) { - this.code = code; - } - - public String getCode() { - return this.code; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - Country country = (Country) o; - - return this.code.equals(country.code); - } - - @Override - public int hashCode() { - return this.code.hashCode(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/CountryRepository.java b/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/CountryRepository.java deleted file mode 100644 index 6aab3d607d..0000000000 --- a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/CountryRepository.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.cache; - -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Component; - -@Component -@CacheConfig(cacheNames = "countries") -public class CountryRepository { - - @Cacheable - public Country findByCode(String code) { - System.out.println("---> Loading country with code '" + code + "'"); - return new Country(code); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleCacheApplication.java b/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleCacheApplication.java deleted file mode 100644 index 2d4d5fb657..0000000000 --- a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleCacheApplication.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.cache; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.cache.annotation.EnableCaching; -import org.springframework.scheduling.annotation.EnableScheduling; - -@EnableCaching -@EnableScheduling -@SpringBootApplication -public class SampleCacheApplication { - - public static void main(String[] args) { - new SpringApplicationBuilder().sources(SampleCacheApplication.class).profiles("app").run(args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleClient.java b/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleClient.java deleted file mode 100644 index 27823e8f4b..0000000000 --- a/spring-boot-samples/spring-boot-sample-cache/src/main/java/sample/cache/SampleClient.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.cache; - -import java.util.Arrays; -import java.util.List; -import java.util.Random; - -import org.springframework.context.annotation.Profile; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -@Component -@Profile("app") -class SampleClient { - - private static final List<String> SAMPLE_COUNTRY_CODES = Arrays.asList("AF", "AX", "AL", "DZ", "AS", "AD", "AO", - "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", - "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", - "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", - "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", - "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", - "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", - "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", - "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", - "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", - "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", "KN", - "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", - "ZA", "GS", "SS", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", - "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", - "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW"); - - private final CountryRepository countryService; - - private final Random random; - - SampleClient(CountryRepository countryService) { - this.countryService = countryService; - this.random = new Random(); - } - - @Scheduled(fixedDelay = 500) - public void retrieveCountry() { - String randomCode = SAMPLE_COUNTRY_CODES.get(this.random.nextInt(SAMPLE_COUNTRY_CODES.size())); - System.out.println("Looking for country with code '" + randomCode + "'"); - this.countryService.findByCode(randomCode); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-cache/src/test/java/sample/cache/SampleCacheApplicationTests.java b/spring-boot-samples/spring-boot-sample-cache/src/test/java/sample/cache/SampleCacheApplicationTests.java deleted file mode 100644 index e5625dda0a..0000000000 --- a/spring-boot-samples/spring-boot-sample-cache/src/test/java/sample/cache/SampleCacheApplicationTests.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.cache; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -class SampleCacheApplicationTests { - - @Autowired - private CacheManager cacheManager; - - @Autowired - private CountryRepository countryRepository; - - @Test - void validateCache() { - Cache countries = this.cacheManager.getCache("countries"); - assertThat(countries).isNotNull(); - countries.clear(); // Simple test assuming the cache is empty - assertThat(countries.get("BE")).isNull(); - Country be = this.countryRepository.findByCode("BE"); - assertThat((Country) countries.get("BE").get()).isEqualTo(be); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-custom-layout/pom.xml b/spring-boot-samples/spring-boot-sample-custom-layout/pom.xml deleted file mode 100644 index c681e9df34..0000000000 --- a/spring-boot-samples/spring-boot-sample-custom-layout/pom.xml +++ /dev/null @@ -1,114 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-custom-layout</artifactId> - <name>Spring Boot Custom Layout Sample</name> - <description>Spring Boot Custom Layout Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-loader-tools</artifactId> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-invoker-plugin</artifactId> - <configuration> - <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> - </configuration> - <executions> - <execution> - <id>prepare-integration-test</id> - <phase>pre-integration-test</phase> - <goals> - <goal>install</goal> - </goals> - </execution> - <execution> - <id>integration-test</id> - <phase>integration-test</phase> - <goals> - <goal>run</goal> - </goals> - <configuration> - <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> - <settingsFile>src/it/settings.xml</settingsFile> - <postBuildHookScript>verify</postBuildHookScript> - <addTestClassPath>true</addTestClassPath> - <skipInvocation>${skipTests}</skipInvocation> - <streamLogs>true</streamLogs> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-antrun-plugin</artifactId> - <executions> - <execution> - <id>cleanup-local-integration-repo</id> - <phase>pre-integration-test</phase> - <goals> - <goal>run</goal> - </goals> - <configuration> - <target> - <replaceregexp match="\$\{revision\}" replace="${project.version}" - flags="g" byline="true"> - <fileset - dir="${project.build.directory}/local-repo/org/springframework/boot/" - includes="**/*.pom" /> - </replaceregexp> - </target> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - </plugin> - </plugins> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.eclipse.m2e</groupId> - <artifactId>lifecycle-mapping</artifactId> - <version>1.0.0</version> - <configuration> - <lifecycleMappingMetadata> - <pluginExecutions> - <pluginExecution> - <pluginExecutionFilter> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <versionRange>[2.10,)</versionRange> - <goals> - <goal>copy</goal> - </goals> - </pluginExecutionFilter> - <action> - <ignore></ignore> - </action> - </pluginExecution> - </pluginExecutions> - </lifecycleMappingMetadata> - </configuration> - </plugin> - </plugins> - </pluginManagement> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-custom-layout/src/it/custom/pom.xml b/spring-boot-samples/spring-boot-sample-custom-layout/src/it/custom/pom.xml deleted file mode 100644 index 9ee510b000..0000000000 --- a/spring-boot-samples/spring-boot-sample-custom-layout/src/it/custom/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>org.springframework.boot.maven.it</groupId> - <artifactId>custom</artifactId> - <version>0.0.1.BUILD-SNAPSHOT</version> - <properties> - <maven.compiler.source>1.8</maven.compiler.source> - <maven.compiler.target>1.8</maven.compiler.target> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <version>@project.version@</version> - <executions> - <execution> - <goals> - <goal>repackage</goal> - </goals> - <configuration> - <layoutFactory implementation="sample.layout.SampleLayoutFactory"> - <name>custom</name> - </layoutFactory> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>@project.groupId@</groupId> - <artifactId>@project.artifactId@</artifactId> - <version>@project.version@</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> - <dependencies> - </dependencies> -</project> diff --git a/spring-boot-samples/spring-boot-sample-custom-layout/src/it/custom/verify.groovy b/spring-boot-samples/spring-boot-sample-custom-layout/src/it/custom/verify.groovy deleted file mode 100644 index 2b5aeae0a2..0000000000 --- a/spring-boot-samples/spring-boot-sample-custom-layout/src/it/custom/verify.groovy +++ /dev/null @@ -1,6 +0,0 @@ -import java.io.*; -import sample.layout.*; - -Verify.verify( - new File(basedir, "target/custom-0.0.1.BUILD-SNAPSHOT.jar"), "custom" -) diff --git a/spring-boot-samples/spring-boot-sample-custom-layout/src/it/default/verify.groovy b/spring-boot-samples/spring-boot-sample-custom-layout/src/it/default/verify.groovy deleted file mode 100644 index 6c956d1478..0000000000 --- a/spring-boot-samples/spring-boot-sample-custom-layout/src/it/default/verify.groovy +++ /dev/null @@ -1,6 +0,0 @@ -import java.io.*; -import sample.layout.*; - -Verify.verify( - new File(basedir, "target/default-0.0.1.BUILD-SNAPSHOT.jar"), "sample" -) diff --git a/spring-boot-samples/spring-boot-sample-custom-layout/src/it/settings.xml b/spring-boot-samples/spring-boot-sample-custom-layout/src/it/settings.xml deleted file mode 100644 index e1e0ace341..0000000000 --- a/spring-boot-samples/spring-boot-sample-custom-layout/src/it/settings.xml +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<settings> - <profiles> - <profile> - <id>it-repo</id> - <activation> - <activeByDefault>true</activeByDefault> - </activation> - <repositories> - <repository> - <id>local.central</id> - <url>@localRepositoryUrl@</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>true</enabled> - </snapshots> - </repository> - </repositories> - <pluginRepositories> - <pluginRepository> - <id>local.central</id> - <url>@localRepositoryUrl@</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>true</enabled> - </snapshots> - </pluginRepository> - </pluginRepositories> - </profile> - </profiles> -</settings> diff --git a/spring-boot-samples/spring-boot-sample-custom-layout/src/main/java/sample/layout/SampleLayout.java b/spring-boot-samples/spring-boot-sample-custom-layout/src/main/java/sample/layout/SampleLayout.java deleted file mode 100644 index e75d6178a1..0000000000 --- a/spring-boot-samples/spring-boot-sample-custom-layout/src/main/java/sample/layout/SampleLayout.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.layout; - -import java.io.ByteArrayInputStream; -import java.io.IOException; - -import org.springframework.boot.loader.tools.CustomLoaderLayout; -import org.springframework.boot.loader.tools.Layouts; -import org.springframework.boot.loader.tools.LoaderClassesWriter; - -/** - * An example layout. - * - * @author Phillip Webb - */ -public class SampleLayout extends Layouts.Jar implements CustomLoaderLayout { - - private String name; - - public SampleLayout(String name) { - this.name = name; - } - - @Override - public void writeLoadedClasses(LoaderClassesWriter writer) throws IOException { - writer.writeEntry(this.name, new ByteArrayInputStream("test".getBytes())); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-custom-layout/src/main/java/sample/layout/SampleLayoutFactory.java b/spring-boot-samples/spring-boot-sample-custom-layout/src/main/java/sample/layout/SampleLayoutFactory.java deleted file mode 100644 index 6d35da5116..0000000000 --- a/spring-boot-samples/spring-boot-sample-custom-layout/src/main/java/sample/layout/SampleLayoutFactory.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.layout; - -import java.io.File; - -import org.springframework.boot.loader.tools.Layout; -import org.springframework.boot.loader.tools.LayoutFactory; - -public class SampleLayoutFactory implements LayoutFactory { - - private String name = "sample"; - - public SampleLayoutFactory() { - } - - public SampleLayoutFactory(String name) { - this.name = name; - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return this.name; - } - - @Override - public Layout getLayout(File source) { - return new SampleLayout(this.name); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-custom-layout/src/main/resources/META-INF/spring.factories b/spring-boot-samples/spring-boot-sample-custom-layout/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 3f2ec6985e..0000000000 --- a/spring-boot-samples/spring-boot-sample-custom-layout/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.loader.tools.LayoutFactory=\ -sample.layout.SampleLayoutFactory diff --git a/spring-boot-samples/spring-boot-sample-custom-layout/src/test/java/sample/layout/Verify.java b/spring-boot-samples/spring-boot-sample-custom-layout/src/test/java/sample/layout/Verify.java deleted file mode 100644 index 71dc12be9e..0000000000 --- a/spring-boot-samples/spring-boot-sample-custom-layout/src/test/java/sample/layout/Verify.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.layout; - -import java.io.File; -import java.util.Enumeration; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -public final class Verify { - - private Verify() { - } - - public static void verify(File file, String entry) throws Exception { - try (ZipFile zipFile = new ZipFile(file)) { - Enumeration<? extends ZipEntry> entries = zipFile.entries(); - while (entries.hasMoreElements()) { - if (entries.nextElement().getName().equals(entry)) { - return; - } - } - throw new AssertionError("No entry " + entry); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/README.adoc b/spring-boot-samples/spring-boot-sample-data-cassandra/README.adoc deleted file mode 100644 index 6712ec1a85..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-cassandra/README.adoc +++ /dev/null @@ -1,12 +0,0 @@ -= Spring Boot Sample Data Cassandra - -To run the project, need to run below `cql` commands on Cassandra. - -== Keyspace Creation in Cassandra -[source,indent=0] ----- - CREATE KEYSPACE mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }; ----- - -== Table Creation in Cassandra -Run `cql` using the link:src/test/resources/setup.cql[setup script] located in resources folder. diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/pom.xml b/spring-boot-samples/spring-boot-sample-data-cassandra/pom.xml deleted file mode 100644 index c1b27036a3..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-cassandra/pom.xml +++ /dev/null @@ -1,131 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-data-cassandra</artifactId> - <name>Spring Boot Data Cassandra Sample</name> - <description>Spring Boot Data Cassandra Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-cassandra</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.cassandraunit</groupId> - <artifactId>cassandra-unit-spring</artifactId> - <version>3.5.0.1</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <executions> - <execution> - <id>reserve-cassandra-port</id> - <goals> - <goal>reserve-network-port</goal> - </goals> - <phase>process-resources</phase> - <configuration> - <portNames> - <portName>cassandra.port.native-transport</portName> - <portName>cassandra.port.storage</portName> - </portNames> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <systemPropertyVariables> - <spring.data.cassandra.port>${cassandra.port.native-transport}</spring.data.cassandra.port> - <cassandra.native_transport_port>${cassandra.port.native-transport}</cassandra.native_transport_port> - <cassandra.storage_port>${cassandra.port.storage}</cassandra.storage_port> - </systemPropertyVariables> - </configuration> - </plugin> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.eclipse.m2e</groupId> - <artifactId>lifecycle-mapping</artifactId> - <version>1.0.0</version> - <configuration> - <lifecycleMappingMetadata> - <pluginExecutions> - <pluginExecution> - <pluginExecutionFilter> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <versionRange>[1.9.1,)</versionRange> - <goals> - <goal>reserve-network-port</goal> - </goals> - </pluginExecutionFilter> - <action> - <ignore /> - </action> - </pluginExecution> - </pluginExecutions> - </lifecycleMappingMetadata> - </configuration> - </plugin> - </plugins> - </pluginManagement> - </build> - <profiles> - <profile> - <id>java9+</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <skipTests>true</skipTests> - </configuration> - </plugin> - </plugins> - </build> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/Customer.java b/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/Customer.java deleted file mode 100644 index f6544d802e..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/Customer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.cassandra; - -import java.util.UUID; - -import org.springframework.data.cassandra.core.mapping.PrimaryKey; -import org.springframework.data.cassandra.core.mapping.Table; - -@Table -public class Customer { - - @PrimaryKey - private UUID id; - - private String firstName; - - private String lastName; - - public Customer() { - } - - public Customer(UUID id, String firstName, String lastName) { - this.id = id; - this.firstName = firstName; - this.lastName = lastName; - } - - @Override - public String toString() { - return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, this.firstName, this.lastName); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/CustomerRepository.java b/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/CustomerRepository.java deleted file mode 100644 index 4da80e1a25..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/CustomerRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.cassandra; - -import java.util.List; - -import org.springframework.data.cassandra.repository.Query; -import org.springframework.data.repository.CrudRepository; - -public interface CustomerRepository extends CrudRepository<Customer, String> { - - @Query("Select * from customer where firstname=?0") - Customer findByFirstName(String firstName); - - @Query("Select * from customer where lastname=?0") - List<Customer> findByLastName(String lastName); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/SampleCassandraApplication.java b/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/SampleCassandraApplication.java deleted file mode 100644 index acb6c13f67..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/java/sample/data/cassandra/SampleCassandraApplication.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.cassandra; - -import com.datastax.driver.core.utils.UUIDs; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleCassandraApplication implements CommandLineRunner { - - @Autowired - private CustomerRepository repository; - - @Override - public void run(String... args) throws Exception { - this.repository.deleteAll(); - - // save a couple of customers - this.repository.save(new Customer(UUIDs.timeBased(), "Alice", "Smith")); - this.repository.save(new Customer(UUIDs.timeBased(), "Bob", "Smith")); - - // fetch all customers - System.out.println("Customers found with findAll():"); - System.out.println("-------------------------------"); - for (Customer customer : this.repository.findAll()) { - System.out.println(customer); - } - System.out.println(); - - // fetch an individual customer - System.out.println("Customer found with findByFirstName('Alice'):"); - System.out.println("--------------------------------"); - System.out.println(this.repository.findByFirstName("Alice")); - - System.out.println("Customers found with findByLastName('Smith'):"); - System.out.println("--------------------------------"); - for (Customer customer : this.repository.findByLastName("Smith")) { - System.out.println(customer); - } - } - - public static void main(String[] args) { - SpringApplication.run(SampleCassandraApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/OrderedCassandraTestExecutionListener.java b/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/OrderedCassandraTestExecutionListener.java deleted file mode 100644 index 1ab82e29ae..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/OrderedCassandraTestExecutionListener.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.cassandra; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.cassandraunit.spring.CassandraUnitDependencyInjectionTestExecutionListener; - -import org.springframework.core.Ordered; - -public class OrderedCassandraTestExecutionListener extends CassandraUnitDependencyInjectionTestExecutionListener { - - private static final Log logger = LogFactory.getLog(OrderedCassandraTestExecutionListener.class); - - @Override - public int getOrder() { - return Ordered.HIGHEST_PRECEDENCE; - } - - @Override - protected void cleanServer() { - try { - super.cleanServer(); - } - catch (Exception ex) { - logger.warn("Failure during server cleanup", ex); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java deleted file mode 100644 index 7b61ac1ea2..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.cassandra; - -import java.io.File; - -import org.cassandraunit.spring.CassandraDataSet; -import org.cassandraunit.spring.EmbeddedCassandra; -import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; -import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.TestExecutionListeners.MergeMode; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SampleCassandraApplication}. - */ -@TestExecutionListeners(mergeMode = MergeMode.MERGE_WITH_DEFAULTS, - listeners = { OrderedCassandraTestExecutionListener.class }) -@ExtendWith(OutputCaptureExtension.class) -@SpringBootTest -@CassandraDataSet(keyspace = "mykeyspace", value = "setup.cql") -@EmbeddedCassandra(timeout = 60000) -class SampleCassandraApplicationTests { - - @Test - void testDefaultSettings(CapturedOutput output) { - Assumptions.assumeFalse(this::runningOnWindows); - assertThat(output).contains("firstName='Alice', lastName='Smith'"); - } - - private boolean runningOnWindows() { - return File.separatorChar == '\\'; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-couchbase/README.adoc b/spring-boot-samples/spring-boot-sample-data-couchbase/README.adoc deleted file mode 100644 index 926b7b2d95..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-couchbase/README.adoc +++ /dev/null @@ -1,27 +0,0 @@ -= Spring Boot Couchbase Sample - -This sample demonstrates how you can store a simple document using Spring Data Couchbase. - -The sample expects couchbase to run on your machine with a bucket named `default` and -no password. You can customize these settings in `application.properties`. - -This sample also configures the `auto-index` property and the `UserRepository` defines -the `all` view so you should be able to invoke `findAll` for this sample. - -== Creating the view manually - -If you don't want to rely on `auto-index` and better understand how this works behind the -scenes, you need to create an `all` view for the `User`. Go to the Couchbase server’s -admin console and visit the Views screen, then click `Create Development View` and name -it `all` with `user` as document name. On that view, you need to change the code to: - -```java -function (doc, meta) { - if (doc._class == "sample.data.couchbase.User") { - emit(meta.id, null); - } -} -``` - -and the _reduce_ function to `_count`. After you've saved your changes go back to `Views` -and click on `Publish` so that the `all` view move to the `Production Views` tab. \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-data-couchbase/pom.xml b/spring-boot-samples/spring-boot-sample-data-couchbase/pom.xml deleted file mode 100644 index 4e99416f79..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-couchbase/pom.xml +++ /dev/null @@ -1,37 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <artifactId>spring-boot-samples</artifactId> - <groupId>org.springframework.boot</groupId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-data-couchbase</artifactId> - <name>Spring Boot Data Couchbase Sample</name> - <description>Spring Boot Data Couchbase Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-couchbase</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/SampleCouchbaseApplication.java b/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/SampleCouchbaseApplication.java deleted file mode 100644 index 6abcc46c89..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/SampleCouchbaseApplication.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.couchbase; - -import java.util.UUID; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleCouchbaseApplication implements CommandLineRunner { - - @Autowired - private UserRepository userRepository; - - public static void main(String[] args) { - SpringApplication.run(SampleCouchbaseApplication.class); - } - - @Override - public void run(String... args) throws Exception { - this.userRepository.deleteAll(); - User user = saveUser(); - System.out.println(this.userRepository.findById(user.getId())); - } - - private User saveUser() { - User user = new User(); - user.setId(UUID.randomUUID().toString()); - user.setFirstName("Alice"); - user.setLastName("Smith"); - return this.userRepository.save(user); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/User.java b/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/User.java deleted file mode 100644 index c8253536fe..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/User.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.couchbase; - -import com.couchbase.client.java.repository.annotation.Field; -import com.couchbase.client.java.repository.annotation.Id; - -import org.springframework.data.couchbase.core.mapping.Document; - -@Document -public class User { - - @Id - private String id; - - @Field - private String firstName; - - @Field - private String lastName; - - public String getId() { - return this.id; - } - - public void setId(String id) { - this.id = id; - } - - public String getFirstName() { - return this.firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return this.lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - @Override - public String toString() { - return "User{" + "id='" + this.id + '\'' + ", firstName='" + this.firstName + '\'' + ", lastName='" - + this.lastName + '\'' + '}'; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/UserRepository.java b/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/UserRepository.java deleted file mode 100644 index f31c7c24ba..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/java/sample/data/couchbase/UserRepository.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.couchbase; - -import org.springframework.data.couchbase.core.query.ViewIndexed; -import org.springframework.data.couchbase.repository.CouchbaseRepository; - -@ViewIndexed(designDoc = "user", viewName = "all") -public interface UserRepository extends CouchbaseRepository<User, String> { - -} diff --git a/spring-boot-samples/spring-boot-sample-data-couchbase/src/test/java/sample/data/couchbase/SampleCouchbaseApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-couchbase/src/test/java/sample/data/couchbase/SampleCouchbaseApplicationTests.java deleted file mode 100644 index 2d6c220ac2..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-couchbase/src/test/java/sample/data/couchbase/SampleCouchbaseApplicationTests.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.data.couchbase; - -import java.net.ConnectException; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; -import org.springframework.core.NestedCheckedException; - -import static org.assertj.core.api.Assertions.assertThat; - -@ExtendWith(OutputCaptureExtension.class) -class SampleCouchbaseApplicationTests { - - @Test - void testDefaultSettings(CapturedOutput capturedOutput) { - try { - new SpringApplicationBuilder(SampleCouchbaseApplication.class).run("--server.port=0"); - } - catch (RuntimeException ex) { - if (serverNotRunning(ex)) { - return; - } - } - assertThat(capturedOutput).contains("firstName='Alice', lastName='Smith'"); - } - - private boolean serverNotRunning(RuntimeException ex) { - @SuppressWarnings("serial") - NestedCheckedException nested = new NestedCheckedException("failed", ex) { - }; - if (nested.contains(ConnectException.class)) { - Throwable root = nested.getRootCause(); - if (root.getMessage().contains("Connection refused")) { - return true; - } - } - return false; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml b/spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml deleted file mode 100644 index bb4272b855..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-elasticsearch/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-data-elasticsearch</artifactId> - <name>Spring Boot Data Elasticsearch Sample</name> - <description>Spring Boot Data Elasticsearch Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-elasticsearch</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java deleted file mode 100644 index 8002e9ddd3..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/Customer.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.elasticsearch; - -import org.springframework.data.annotation.Id; -import org.springframework.data.elasticsearch.annotations.Document; - -@Document(indexName = "customer", type = "customer", shards = 1, replicas = 0, refreshInterval = "-1") -public class Customer { - - @Id - private String id; - - private String firstName; - - private String lastName; - - public Customer() { - } - - public Customer(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } - - public String getId() { - return this.id; - } - - public void setId(String id) { - this.id = id; - } - - public String getFirstName() { - return this.firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return this.lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - @Override - public String toString() { - return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, this.firstName, this.lastName); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/CustomerRepository.java b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/CustomerRepository.java deleted file mode 100644 index d2eda1cffd..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/CustomerRepository.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.elasticsearch; - -import java.util.List; - -import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; - -public interface CustomerRepository extends ElasticsearchRepository<Customer, String> { - - Customer findByFirstName(String firstName); - - List<Customer> findByLastName(String lastName); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/SampleElasticsearchApplication.java b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/SampleElasticsearchApplication.java deleted file mode 100644 index a48cb0a352..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/java/sample/data/elasticsearch/SampleElasticsearchApplication.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.elasticsearch; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleElasticsearchApplication implements CommandLineRunner { - - @Autowired - private CustomerRepository repository; - - @Override - public void run(String... args) throws Exception { - this.repository.deleteAll(); - saveCustomers(); - fetchAllCustomers(); - fetchIndividualCustomers(); - } - - private void saveCustomers() { - this.repository.save(new Customer("Alice", "Smith")); - this.repository.save(new Customer("Bob", "Smith")); - } - - private void fetchAllCustomers() { - System.out.println("Customers found with findAll():"); - System.out.println("-------------------------------"); - for (Customer customer : this.repository.findAll()) { - System.out.println(customer); - } - System.out.println(); - } - - private void fetchIndividualCustomers() { - System.out.println("Customer found with findByFirstName('Alice'):"); - System.out.println("--------------------------------"); - System.out.println(this.repository.findByFirstName("Alice")); - - System.out.println("Customers found with findByLastName('Smith'):"); - System.out.println("--------------------------------"); - for (Customer customer : this.repository.findByLastName("Smith")) { - System.out.println(customer); - } - } - - public static void main(String[] args) { - SpringApplication.run(SampleElasticsearchApplication.class, "--debug").close(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java deleted file mode 100644 index 500ce6184e..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.elasticsearch; - -import java.net.ConnectException; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SampleElasticsearchApplication}. - * - * @author Artur Konczak - */ -@ExtendWith(OutputCaptureExtension.class) -class SampleElasticsearchApplicationTests { - - @Test - void testDefaultSettings(CapturedOutput capturedOutput) { - try { - new SpringApplicationBuilder(SampleElasticsearchApplication.class).run(); - } - catch (Exception ex) { - if (!elasticsearchRunning(ex)) { - return; - } - throw ex; - } - assertThat(capturedOutput).contains("firstName='Alice', lastName='Smith'"); - } - - private boolean elasticsearchRunning(Exception ex) { - Throwable candidate = ex; - while (candidate != null) { - if (candidate instanceof ConnectException) { - return false; - } - candidate = candidate.getCause(); - } - return true; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/pom.xml b/spring-boot-samples/spring-boot-sample-data-jdbc/pom.xml deleted file mode 100755 index 12eb7a8109..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jdbc/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-data-jdbc</artifactId> - <name>Spring Boot Data JDBC Sample</name> - <description>Spring Boot Data JDBC Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jdbc</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <!-- Runtime --> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>runtime</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/Customer.java b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/Customer.java deleted file mode 100644 index ccb410fa5a..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/Customer.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jdbc; - -import java.time.LocalDate; - -import org.springframework.data.annotation.Id; - -class Customer { - - @Id - private Long id; - - private String firstName; - - private LocalDate dateOfBirth; - - public Long getId() { - return this.id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getFirstName() { - return this.firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public LocalDate getDateOfBirth() { - return this.dateOfBirth; - } - - public void setDateOfBirth(LocalDate dateOfBirth) { - this.dateOfBirth = dateOfBirth; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/CustomerRepository.java b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/CustomerRepository.java deleted file mode 100644 index cd4decfb99..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/CustomerRepository.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jdbc; - -import java.util.List; - -import org.springframework.data.jdbc.repository.query.Query; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.query.Param; - -interface CustomerRepository extends CrudRepository<Customer, Long> { - - @Query("select id, first_name, date_of_birth from customer where upper(first_name) like '%' || upper(:name) || '%' ") - List<Customer> findByName(@Param("name") String name); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleController.java b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleController.java deleted file mode 100644 index 97dc209cad..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleController.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jdbc; - -import java.util.List; - -import org.springframework.stereotype.Controller; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class SampleController { - - private final CustomerRepository customerRepository; - - public SampleController(CustomerRepository customerRepository) { - this.customerRepository = customerRepository; - } - - @GetMapping("/") - @ResponseBody - @Transactional(readOnly = true) - public List<Customer> customers(@RequestParam String name) { - return this.customerRepository.findByName(name); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleDataJdbcApplication.java b/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleDataJdbcApplication.java deleted file mode 100644 index 94e4c18455..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/java/sample/data/jdbc/SampleDataJdbcApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jdbc; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleDataJdbcApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleDataJdbcApplication.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/CustomerRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/CustomerRepositoryIntegrationTests.java deleted file mode 100644 index 59c1336e82..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/CustomerRepositoryIntegrationTests.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.data.jdbc; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.context.SpringBootTest; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for {@link CustomerRepository}. - * - * @author Andy Wilkinson - */ -@SpringBootTest -@AutoConfigureTestDatabase -class CustomerRepositoryIntegrationTests { - - @Autowired - private CustomerRepository repository; - - @Test - void findAllCustomers() { - assertThat(this.repository.findAll()).hasSize(2); - } - - @Test - void findByNameWithMatch() { - assertThat(this.repository.findByName("joan")).hasSize(1); - } - - @Test - void findByNameWithNoMatch() { - assertThat(this.repository.findByName("hugh")).isEmpty(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/SampleDataJdbcApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/SampleDataJdbcApplicationTests.java deleted file mode 100644 index 76e2a104d9..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jdbc/src/test/java/sample/data/jdbc/SampleDataJdbcApplicationTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jdbc; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import static org.hamcrest.Matchers.containsString; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * Integration tests for {@link SampleDataJdbcApplication}. - * - * @author Andy Wilkinson - */ -@SpringBootTest -class SampleDataJdbcApplicationTests { - - @Autowired - private WebApplicationContext context; - - private MockMvc mvc; - - @BeforeEach - void setUp() { - this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); - } - - @Test - void testCustomers() throws Exception { - this.mvc.perform(get("/").param("name", "merEDith")).andExpect(status().isOk()) - .andExpect(content().string(containsString("Meredith"))); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/pom.xml b/spring-boot-samples/spring-boot-sample-data-jpa/pom.xml deleted file mode 100755 index 0f1c6ba52b..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-data-jpa</artifactId> - <name>Spring Boot Data JPA Sample</name> - <description>Spring Boot Data JPA Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <!-- Runtime --> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>runtime</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/SampleDataJpaApplication.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/SampleDataJpaApplication.java deleted file mode 100644 index 98b4db5c1b..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/SampleDataJpaApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleDataJpaApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleDataJpaApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/City.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/City.java deleted file mode 100644 index 69b2a72247..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/City.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.domain; - -import java.io.Serializable; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.SequenceGenerator; - -@Entity -public class City implements Serializable { - - private static final long serialVersionUID = 1L; - - @Id - @SequenceGenerator(name = "city_generator", sequenceName = "city_sequence", initialValue = 23) - @GeneratedValue(generator = "city_generator") - private Long id; - - @Column(nullable = false) - private String name; - - @Column(nullable = false) - private String state; - - @Column(nullable = false) - private String country; - - @Column(nullable = false) - private String map; - - protected City() { - } - - public City(String name, String country) { - this.name = name; - this.country = country; - } - - public String getName() { - return this.name; - } - - public String getState() { - return this.state; - } - - public String getCountry() { - return this.country; - } - - public String getMap() { - return this.map; - } - - @Override - public String toString() { - return getName() + "," + getState() + "," + getCountry(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Hotel.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Hotel.java deleted file mode 100644 index a2d7804710..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Hotel.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.domain; - -import java.io.Serializable; -import java.util.Set; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.SequenceGenerator; - -import org.hibernate.annotations.NaturalId; - -@Entity -public class Hotel implements Serializable { - - private static final long serialVersionUID = 1L; - - @Id - @SequenceGenerator(name = "hotel_generator", sequenceName = "hotel_sequence", initialValue = 28) - @GeneratedValue(generator = "hotel_generator") - private Long id; - - @ManyToOne(optional = false) - @NaturalId - private City city; - - @Column(nullable = false) - @NaturalId - private String name; - - @Column(nullable = false) - private String address; - - @Column(nullable = false) - private String zip; - - @OneToMany(fetch = FetchType.LAZY, mappedBy = "hotel") - private Set<Review> reviews; - - protected Hotel() { - } - - public Hotel(City city, String name) { - this.city = city; - this.name = name; - } - - public City getCity() { - return this.city; - } - - public String getName() { - return this.name; - } - - public String getAddress() { - return this.address; - } - - public String getZip() { - return this.zip; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/HotelSummary.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/HotelSummary.java deleted file mode 100644 index 63c60fab3f..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/HotelSummary.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.domain; - -public interface HotelSummary { - - City getCity(); - - String getName(); - - Double getAverageRating(); - - default Integer getAverageRatingRounded() { - return (getAverageRating() != null) ? (int) Math.round(getAverageRating()) : null; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Rating.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Rating.java deleted file mode 100644 index d6a9021ad5..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Rating.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.domain; - -public enum Rating { - - TERRIBLE, POOR, AVERAGE, GOOD, EXCELLENT - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/RatingCount.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/RatingCount.java deleted file mode 100644 index 03f8d8a501..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/RatingCount.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.domain; - -public interface RatingCount { - - Rating getRating(); - - long getCount(); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Review.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Review.java deleted file mode 100644 index 608943423b..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Review.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.domain; - -import java.io.Serializable; -import java.util.Date; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.persistence.SequenceGenerator; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; - -import org.springframework.util.Assert; - -@Entity -public class Review implements Serializable { - - private static final long serialVersionUID = 1L; - - @Id - @SequenceGenerator(name = "review_generator", sequenceName = "review_sequence", initialValue = 64) - @GeneratedValue(generator = "review_generator") - private Long id; - - @ManyToOne(optional = false) - private Hotel hotel; - - @Column(nullable = false, name = "idx") - private int index; - - @Column(nullable = false) - @Enumerated(EnumType.ORDINAL) - private Rating rating; - - @Column(nullable = false) - @Temporal(TemporalType.DATE) - private Date checkInDate; - - @Column(nullable = false) - @Enumerated(EnumType.ORDINAL) - private TripType tripType; - - @Column(nullable = false) - private String title; - - @Column(nullable = false, length = 5000) - private String details; - - protected Review() { - } - - public Review(Hotel hotel, int index, ReviewDetails details) { - Assert.notNull(hotel, "Hotel must not be null"); - Assert.notNull(details, "Details must not be null"); - this.hotel = hotel; - this.index = index; - this.rating = details.getRating(); - this.checkInDate = details.getCheckInDate(); - this.tripType = details.getTripType(); - this.title = details.getTitle(); - this.details = details.getDetails(); - } - - public Hotel getHotel() { - return this.hotel; - } - - public int getIndex() { - return this.index; - } - - public Rating getRating() { - return this.rating; - } - - public void setRating(Rating rating) { - this.rating = rating; - } - - public Date getCheckInDate() { - return this.checkInDate; - } - - public void setCheckInDate(Date checkInDate) { - this.checkInDate = checkInDate; - } - - public TripType getTripType() { - return this.tripType; - } - - public void setTripType(TripType tripType) { - this.tripType = tripType; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDetails() { - return this.details; - } - - public void setDetails(String details) { - this.details = details; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/ReviewDetails.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/ReviewDetails.java deleted file mode 100644 index 7379701f51..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/ReviewDetails.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.domain; - -import java.io.Serializable; -import java.util.Date; - -public class ReviewDetails implements Serializable { - - private static final long serialVersionUID = 1L; - - private Rating rating; - - private Date checkInDate; - - private TripType tripType; - - private String title; - - private String details; - - public ReviewDetails() { - } - - public Rating getRating() { - return this.rating; - } - - public void setRating(Rating rating) { - this.rating = rating; - } - - public Date getCheckInDate() { - return this.checkInDate; - } - - public void setCheckInDate(Date checkInDate) { - this.checkInDate = checkInDate; - } - - public TripType getTripType() { - return this.tripType; - } - - public void setTripType(TripType tripType) { - this.tripType = tripType; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDetails() { - return this.details; - } - - public void setDetails(String details) { - this.details = details; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/TripType.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/TripType.java deleted file mode 100644 index 89b084df5b..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/TripType.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.domain; - -public enum TripType { - - BUSINESS, COUPLES, FAMILY, FRIENDS, SOLO - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityRepository.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityRepository.java deleted file mode 100644 index c16ec30dfb..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityRepository.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.service; - -import sample.data.jpa.domain.City; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.repository.Repository; - -interface CityRepository extends Repository<City, Long> { - - Page<City> findAll(Pageable pageable); - - Page<City> findByNameContainingAndCountryContainingAllIgnoringCase(String name, String country, Pageable pageable); - - City findByNameAndCountryAllIgnoringCase(String name, String country); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CitySearchCriteria.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CitySearchCriteria.java deleted file mode 100644 index 31ad7506a2..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CitySearchCriteria.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.service; - -import java.io.Serializable; - -import org.springframework.util.Assert; - -public class CitySearchCriteria implements Serializable { - - private static final long serialVersionUID = 1L; - - private String name; - - public CitySearchCriteria() { - } - - public CitySearchCriteria(String name) { - Assert.notNull(name, "Name must not be null"); - this.name = name; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityService.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityService.java deleted file mode 100644 index a3744d86e1..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityService.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.service; - -import sample.data.jpa.domain.City; -import sample.data.jpa.domain.HotelSummary; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -public interface CityService { - - Page<City> findCities(CitySearchCriteria criteria, Pageable pageable); - - City getCity(String name, String country); - - Page<HotelSummary> getHotels(City city, Pageable pageable); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityServiceImpl.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityServiceImpl.java deleted file mode 100644 index 6ba53659c3..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/CityServiceImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.service; - -import sample.data.jpa.domain.City; -import sample.data.jpa.domain.HotelSummary; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -@Component("cityService") -@Transactional -class CityServiceImpl implements CityService { - - private final CityRepository cityRepository; - - private final HotelRepository hotelRepository; - - CityServiceImpl(CityRepository cityRepository, HotelRepository hotelRepository) { - this.cityRepository = cityRepository; - this.hotelRepository = hotelRepository; - } - - @Override - public Page<City> findCities(CitySearchCriteria criteria, Pageable pageable) { - - Assert.notNull(criteria, "Criteria must not be null"); - String name = criteria.getName(); - - if (!StringUtils.hasLength(name)) { - return this.cityRepository.findAll(null); - } - - String country = ""; - int splitPos = name.lastIndexOf(","); - - if (splitPos >= 0) { - country = name.substring(splitPos + 1); - name = name.substring(0, splitPos); - } - - return this.cityRepository.findByNameContainingAndCountryContainingAllIgnoringCase(name.trim(), country.trim(), - pageable); - } - - @Override - public City getCity(String name, String country) { - Assert.notNull(name, "Name must not be null"); - Assert.notNull(country, "Country must not be null"); - return this.cityRepository.findByNameAndCountryAllIgnoringCase(name, country); - } - - @Override - public Page<HotelSummary> getHotels(City city, Pageable pageable) { - Assert.notNull(city, "City must not be null"); - return this.hotelRepository.findByCity(city, pageable); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelRepository.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelRepository.java deleted file mode 100644 index 7a787d98db..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelRepository.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.service; - -import java.util.List; - -import sample.data.jpa.domain.City; -import sample.data.jpa.domain.Hotel; -import sample.data.jpa.domain.HotelSummary; -import sample.data.jpa.domain.RatingCount; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.Repository; - -interface HotelRepository extends Repository<Hotel, Long> { - - Hotel findByCityAndName(City city, String name); - - @Query("select h.city as city, h.name as name, avg(r.rating) as averageRating " - + "from Hotel h left outer join h.reviews r where h.city = ?1 group by h") - Page<HotelSummary> findByCity(City city, Pageable pageable); - - @Query("select r.rating as rating, count(r) as count " - + "from Review r where r.hotel = ?1 group by r.rating order by r.rating DESC") - List<RatingCount> findRatingCounts(Hotel hotel); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelService.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelService.java deleted file mode 100644 index d276c3a5ae..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelService.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.service; - -import sample.data.jpa.domain.City; -import sample.data.jpa.domain.Hotel; -import sample.data.jpa.domain.Review; -import sample.data.jpa.domain.ReviewDetails; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -public interface HotelService { - - Hotel getHotel(City city, String name); - - Page<Review> getReviews(Hotel hotel, Pageable pageable); - - Review getReview(Hotel hotel, int index); - - Review addReview(Hotel hotel, ReviewDetails details); - - ReviewsSummary getReviewSummary(Hotel hotel); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelServiceImpl.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelServiceImpl.java deleted file mode 100644 index 30a7ea082c..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/HotelServiceImpl.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.service; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import sample.data.jpa.domain.City; -import sample.data.jpa.domain.Hotel; -import sample.data.jpa.domain.Rating; -import sample.data.jpa.domain.RatingCount; -import sample.data.jpa.domain.Review; -import sample.data.jpa.domain.ReviewDetails; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.Assert; - -@Component("hotelService") -@Transactional -class HotelServiceImpl implements HotelService { - - private final HotelRepository hotelRepository; - - private final ReviewRepository reviewRepository; - - HotelServiceImpl(HotelRepository hotelRepository, ReviewRepository reviewRepository) { - this.hotelRepository = hotelRepository; - this.reviewRepository = reviewRepository; - } - - @Override - public Hotel getHotel(City city, String name) { - Assert.notNull(city, "City must not be null"); - Assert.hasLength(name, "Name must not be empty"); - return this.hotelRepository.findByCityAndName(city, name); - } - - @Override - public Page<Review> getReviews(Hotel hotel, Pageable pageable) { - Assert.notNull(hotel, "Hotel must not be null"); - return this.reviewRepository.findByHotel(hotel, pageable); - } - - @Override - public Review getReview(Hotel hotel, int reviewNumber) { - Assert.notNull(hotel, "Hotel must not be null"); - return this.reviewRepository.findByHotelAndIndex(hotel, reviewNumber); - } - - @Override - public Review addReview(Hotel hotel, ReviewDetails details) { - Review review = new Review(hotel, 1, details); - return this.reviewRepository.save(review); - } - - @Override - public ReviewsSummary getReviewSummary(Hotel hotel) { - List<RatingCount> ratingCounts = this.hotelRepository.findRatingCounts(hotel); - return new ReviewsSummaryImpl(ratingCounts); - } - - private static class ReviewsSummaryImpl implements ReviewsSummary { - - private final Map<Rating, Long> ratingCount; - - ReviewsSummaryImpl(List<RatingCount> ratingCounts) { - this.ratingCount = new HashMap<>(); - for (RatingCount ratingCount : ratingCounts) { - this.ratingCount.put(ratingCount.getRating(), ratingCount.getCount()); - } - } - - @Override - public long getNumberOfReviewsWithRating(Rating rating) { - Long count = this.ratingCount.get(rating); - return (count != null) ? count : 0; - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/ReviewRepository.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/ReviewRepository.java deleted file mode 100644 index 98823560cc..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/ReviewRepository.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.service; - -import sample.data.jpa.domain.Hotel; -import sample.data.jpa.domain.Review; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.repository.Repository; - -interface ReviewRepository extends Repository<Review, Long> { - - Page<Review> findByHotel(Hotel hotel, Pageable pageable); - - Review findByHotelAndIndex(Hotel hotel, int index); - - Review save(Review review); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/ReviewsSummary.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/ReviewsSummary.java deleted file mode 100644 index fd3cd5b971..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/service/ReviewsSummary.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.service; - -import sample.data.jpa.domain.Rating; - -public interface ReviewsSummary { - - long getNumberOfReviewsWithRating(Rating rating); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/web/SampleController.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/web/SampleController.java deleted file mode 100644 index 3161fda83a..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/web/SampleController.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa.web; - -import sample.data.jpa.service.CityService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class SampleController { - - @Autowired - private CityService cityService; - - @GetMapping("/") - @ResponseBody - @Transactional(readOnly = true) - public String helloWorld() { - return this.cityService.getCity("Bath", "UK").getName(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java deleted file mode 100644 index 0a22960a50..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.jpa; - -import java.lang.management.ManagementFactory; - -import javax.management.ObjectName; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * Integration test to run the application. - * - * @author Oliver Gierke - * @author Dave Syer - */ -// Enable JMX so we can test the MBeans (you can't do this in a properties file) -@SpringBootTest(properties = "spring.jmx.enabled:true") -@ActiveProfiles("scratch") -// Separate profile for web tests to avoid clashing databases -class SampleDataJpaApplicationTests { - - @Autowired - private WebApplicationContext context; - - private MockMvc mvc; - - @BeforeEach - void setUp() { - this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); - } - - @Test - void testHome() throws Exception { - - this.mvc.perform(get("/")).andExpect(status().isOk()).andExpect(content().string("Bath")); - } - - @Test - void testJmx() throws Exception { - assertThat(ManagementFactory.getPlatformMBeanServer() - .queryMBeans(new ObjectName("jpa.sample:type=HikariDataSource,*"), null)).hasSize(1); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java deleted file mode 100644 index c4ab194e05..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.data.jpa.service; - -import org.junit.jupiter.api.Test; -import sample.data.jpa.domain.City; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for {@link CityRepository}. - * - * @author Oliver Gierke - */ -@SpringBootTest -class CityRepositoryIntegrationTests { - - @Autowired - CityRepository repository; - - @Test - void findsFirstPageOfCities() { - Page<City> cities = this.repository.findAll(PageRequest.of(0, 10)); - assertThat(cities.getTotalElements()).isGreaterThan(20L); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java deleted file mode 100644 index 4001b8bba2..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.data.jpa.service; - -import java.util.List; - -import org.junit.jupiter.api.Test; -import sample.data.jpa.domain.City; -import sample.data.jpa.domain.Hotel; -import sample.data.jpa.domain.HotelSummary; -import sample.data.jpa.domain.Rating; -import sample.data.jpa.domain.RatingCount; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort.Direction; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for {@link HotelRepository}. - * - * @author Oliver Gierke - */ -@SpringBootTest -class HotelRepositoryIntegrationTests { - - @Autowired - CityRepository cityRepository; - - @Autowired - HotelRepository repository; - - @Test - void executesQueryMethodsCorrectly() { - City city = this.cityRepository.findAll(PageRequest.of(0, 1, Direction.ASC, "name")).getContent().get(0); - assertThat(city.getName()).isEqualTo("Atlanta"); - Page<HotelSummary> hotels = this.repository.findByCity(city, PageRequest.of(0, 10, Direction.ASC, "name")); - Hotel hotel = this.repository.findByCityAndName(city, hotels.getContent().get(0).getName()); - assertThat(hotel.getName()).isEqualTo("Doubletree"); - List<RatingCount> counts = this.repository.findRatingCounts(hotel); - assertThat(counts).hasSize(1); - assertThat(counts.get(0).getRating()).isEqualTo(Rating.AVERAGE); - assertThat(counts.get(0).getCount()).isGreaterThan(1L); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-ldap/pom.xml b/spring-boot-samples/spring-boot-sample-data-ldap/pom.xml deleted file mode 100644 index 69d10ad63b..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-ldap/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-data-ldap</artifactId> - <name>Spring Boot Data LDAP Sample</name> - <description>Spring Boot Data LDAP Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>com.unboundid</groupId> - <artifactId>unboundid-ldapsdk</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-ldap</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-data-ldap/src/main/java/sample/data/ldap/Person.java b/spring-boot-samples/spring-boot-sample-data-ldap/src/main/java/sample/data/ldap/Person.java deleted file mode 100644 index 79dbccdf62..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-ldap/src/main/java/sample/data/ldap/Person.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.ldap; - -import javax.naming.Name; - -import org.springframework.ldap.odm.annotations.Attribute; -import org.springframework.ldap.odm.annotations.Entry; -import org.springframework.ldap.odm.annotations.Id; - -@Entry(objectClasses = { "person", "top" }) -public class Person { - - @Id - private Name dn; - - @Attribute(name = "telephoneNumber") - private String phone; - - @Override - public String toString() { - return String.format("Customer[dn=%s, phone='%s']", this.dn, this.phone); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-ldap/src/main/java/sample/data/ldap/PersonRepository.java b/spring-boot-samples/spring-boot-sample-data-ldap/src/main/java/sample/data/ldap/PersonRepository.java deleted file mode 100644 index ed0fec2cc0..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-ldap/src/main/java/sample/data/ldap/PersonRepository.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.ldap; - -import org.springframework.data.ldap.repository.LdapRepository; - -public interface PersonRepository extends LdapRepository<Person> { - - Person findByPhone(String phone); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-ldap/src/main/java/sample/data/ldap/SampleLdapApplication.java b/spring-boot-samples/spring-boot-sample-data-ldap/src/main/java/sample/data/ldap/SampleLdapApplication.java deleted file mode 100644 index 8094cb9c87..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-ldap/src/main/java/sample/data/ldap/SampleLdapApplication.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.ldap; - -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleLdapApplication implements CommandLineRunner { - - private final PersonRepository repository; - - public SampleLdapApplication(PersonRepository repository) { - this.repository = repository; - } - - @Override - public void run(String... args) throws Exception { - - // fetch all people - System.out.println("People found with findAll():"); - System.out.println("-------------------------------"); - for (Person person : this.repository.findAll()) { - System.out.println(person); - } - System.out.println(); - - // fetch an individual person - System.out.println("Person found with findByPhone('+46 555-123456'):"); - System.out.println("--------------------------------"); - System.out.println(this.repository.findByPhone("+46 555-123456")); - } - - public static void main(String[] args) { - SpringApplication.run(SampleLdapApplication.class, args).close(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-ldap/src/test/java/sample/data/ldap/SampleLdapApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-ldap/src/test/java/sample/data/ldap/SampleLdapApplicationTests.java deleted file mode 100644 index 90d26a60ef..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-ldap/src/test/java/sample/data/ldap/SampleLdapApplicationTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.ldap; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SampleLdapApplication}. - * - * @author Phillip Webb - */ -@ExtendWith(OutputCaptureExtension.class) -@SpringBootTest -class SampleLdapApplicationTests { - - @Test - void testDefaultSettings(CapturedOutput output) { - assertThat(output).contains("cn=Alice Smith"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-mongodb/pom.xml b/spring-boot-samples/spring-boot-sample-data-mongodb/pom.xml deleted file mode 100644 index e661d7c702..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-mongodb/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-data-mongodb</artifactId> - <name>Spring Boot Data MongoDB Sample</name> - <description>Spring Boot Data MongoDB Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-mongodb</artifactId> - </dependency> - <dependency> - <groupId>de.flapdoodle.embed</groupId> - <artifactId>de.flapdoodle.embed.mongo</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/Customer.java b/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/Customer.java deleted file mode 100644 index 80860e0bf9..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/Customer.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.mongo; - -import org.springframework.data.annotation.Id; - -public class Customer { - - @Id - private String id; - - private String firstName; - - private String lastName; - - public Customer() { - } - - public Customer(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } - - @Override - public String toString() { - return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, this.firstName, this.lastName); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/CustomerRepository.java b/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/CustomerRepository.java deleted file mode 100644 index 83fa9d4403..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/CustomerRepository.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.mongo; - -import java.util.List; - -import org.springframework.data.mongodb.repository.MongoRepository; - -public interface CustomerRepository extends MongoRepository<Customer, String> { - - Customer findByFirstName(String firstName); - - List<Customer> findByLastName(String lastName); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/SampleMongoApplication.java b/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/SampleMongoApplication.java deleted file mode 100644 index afc261cb06..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-mongodb/src/main/java/sample/data/mongo/SampleMongoApplication.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.mongo; - -import java.util.concurrent.TimeUnit; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCustomizer; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -public class SampleMongoApplication implements CommandLineRunner { - - @Autowired - private CustomerRepository repository; - - @Override - public void run(String... args) throws Exception { - this.repository.deleteAll(); - - // save a couple of customers - this.repository.save(new Customer("Alice", "Smith")); - this.repository.save(new Customer("Bob", "Smith")); - - // fetch all customers - System.out.println("Customers found with findAll():"); - System.out.println("-------------------------------"); - for (Customer customer : this.repository.findAll()) { - System.out.println(customer); - } - System.out.println(); - - // fetch an individual customer - System.out.println("Customer found with findByFirstName('Alice'):"); - System.out.println("--------------------------------"); - System.out.println(this.repository.findByFirstName("Alice")); - - System.out.println("Customers found with findByLastName('Smith'):"); - System.out.println("--------------------------------"); - for (Customer customer : this.repository.findByLastName("Smith")) { - System.out.println(customer); - } - } - - @Bean - public MongoClientSettingsBuilderCustomizer customizer() { - return (builder) -> builder.applyToConnectionPoolSettings( - (connectionPool) -> connectionPool.maxConnectionIdleTime(5, TimeUnit.MINUTES)); - } - - public static void main(String[] args) { - SpringApplication.run(SampleMongoApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java deleted file mode 100644 index 3ff624cc48..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.mongo; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SampleMongoApplication}. - * - * @author Dave Syer - * @author Andy Wilkinson - */ -@ExtendWith(OutputCaptureExtension.class) -@SpringBootTest -class SampleMongoApplicationTests { - - @Test - void testDefaultSettings(CapturedOutput output) { - assertThat(output).contains("firstName='Alice', lastName='Smith'"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-neo4j/README.adoc b/spring-boot-samples/spring-boot-sample-data-neo4j/README.adoc deleted file mode 100644 index 9e7d37cb24..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-neo4j/README.adoc +++ /dev/null @@ -1,16 +0,0 @@ -= Spring Boot Neo4j Sample - -This sample demonstrates the integration of Neo4j with a simple entity. It -expects a Neo4j instance running on `localhost`. If your neo4j instance -requires authentication, update `application.properties` with your credentials: - -``` -spring.data.neo4j.username=neo4j -spring.data.neo4j.password=secret -``` - -You can also locally add the embedded driver to embed Neo4j instead. Note -that Spring Boot does not provide dependency management for that GPL-licensed -library, see -https://docs.spring.io/spring-data/neo4j/docs/4.2.x/reference/html/#reference.getting_started.driver[the official documentation] -for more details. diff --git a/spring-boot-samples/spring-boot-sample-data-neo4j/pom.xml b/spring-boot-samples/spring-boot-sample-data-neo4j/pom.xml deleted file mode 100644 index 999257bc3c..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-neo4j/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-data-neo4j</artifactId> - <name>Spring Boot Data Neo4j Sample</name> - <description>Spring Boot Data Neo4j Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-neo4j</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/Customer.java b/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/Customer.java deleted file mode 100644 index 1568eca45d..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/Customer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.neo4j; - -import org.neo4j.ogm.annotation.GeneratedValue; -import org.neo4j.ogm.annotation.Id; -import org.neo4j.ogm.annotation.NodeEntity; - -@NodeEntity -public class Customer { - - @Id - @GeneratedValue - private Long id; - - private String firstName; - - private String lastName; - - public Customer() { - } - - public Customer(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } - - @Override - public String toString() { - return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, this.firstName, this.lastName); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/CustomerRepository.java b/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/CustomerRepository.java deleted file mode 100644 index 2334e851ae..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/CustomerRepository.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.neo4j; - -import java.util.List; - -import org.springframework.data.neo4j.repository.Neo4jRepository; - -public interface CustomerRepository extends Neo4jRepository<Customer, Long> { - - Customer findByFirstName(String firstName); - - List<Customer> findByLastName(String lastName); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/SampleNeo4jApplication.java b/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/SampleNeo4jApplication.java deleted file mode 100644 index bf4c19088b..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/java/sample/data/neo4j/SampleNeo4jApplication.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.neo4j; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleNeo4jApplication implements CommandLineRunner { - - @Autowired - private CustomerRepository repository; - - @Override - public void run(String... args) throws Exception { - this.repository.deleteAll(); - - // save a couple of customers - this.repository.save(new Customer("Alice", "Smith")); - this.repository.save(new Customer("Bob", "Smith")); - - // fetch all customers - System.out.println("Customers found with findAll():"); - System.out.println("-------------------------------"); - for (Customer customer : this.repository.findAll()) { - System.out.println(customer); - } - System.out.println(); - - // fetch an individual customer - System.out.println("Customer found with findByFirstName('Alice'):"); - System.out.println("--------------------------------"); - System.out.println(this.repository.findByFirstName("Alice")); - - System.out.println("Customers found with findByLastName('Smith'):"); - System.out.println("--------------------------------"); - for (Customer customer : this.repository.findByLastName("Smith")) { - System.out.println(customer); - } - } - - public static void main(String[] args) { - SpringApplication.run(SampleNeo4jApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-neo4j/src/test/java/sample/data/neo4j/SampleNeo4jApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-neo4j/src/test/java/sample/data/neo4j/SampleNeo4jApplicationTests.java deleted file mode 100644 index 513b76af27..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-neo4j/src/test/java/sample/data/neo4j/SampleNeo4jApplicationTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.neo4j; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.neo4j.driver.v1.exceptions.ServiceUnavailableException; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SampleNeo4jApplication}. - * - * @author Stephane Nicoll - */ -@ExtendWith(OutputCaptureExtension.class) -class SampleNeo4jApplicationTests { - - @Test - void testDefaultSettings(CapturedOutput capturedOutput) { - try { - SampleNeo4jApplication.main(new String[0]); - } - catch (Exception ex) { - if (!neo4jServerRunning(ex)) { - return; - } - } - assertThat(capturedOutput).contains("firstName='Alice', lastName='Smith'"); - } - - private boolean neo4jServerRunning(Throwable ex) { - if (ex instanceof ServiceUnavailableException) { - return false; - } - return (ex.getCause() == null || neo4jServerRunning(ex.getCause())); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-redis/pom.xml b/spring-boot-samples/spring-boot-sample-data-redis/pom.xml deleted file mode 100644 index 0b0c847980..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-redis/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-data-redis</artifactId> - <name>Spring Boot Data Redis Sample</name> - <description>Spring Boot Data Redis Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-redis</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <profiles> - <profile> - <id>production</id> - <dependencies> - <!-- This sample is a test for the autoconfig when commons-pool is *absent*. - In production it would be useful to enable pooling by using this dependency. --> - <dependency> - <groupId>commons-pool</groupId> - <artifactId>commons-pool</artifactId> - <type>pom.lastUpdated</type> - </dependency> - </dependencies> - </profile> - </profiles> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-data-redis/src/main/java/sample/data/redis/SampleRedisApplication.java b/spring-boot-samples/spring-boot-sample-data-redis/src/main/java/sample/data/redis/SampleRedisApplication.java deleted file mode 100644 index 27f09c0e99..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-redis/src/main/java/sample/data/redis/SampleRedisApplication.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.redis; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.data.redis.core.ValueOperations; - -@SpringBootApplication -public class SampleRedisApplication implements CommandLineRunner { - - @Autowired - private StringRedisTemplate template; - - @Override - public void run(String... args) throws Exception { - ValueOperations<String, String> ops = this.template.opsForValue(); - String key = "spring.boot.redis.test"; - if (!this.template.hasKey(key)) { - ops.set(key, "foo"); - } - System.out.println("Found key " + key + ", value=" + ops.get(key)); - } - - public static void main(String[] args) { - // Close the context so it doesn't stay awake listening for redis - SpringApplication.run(SampleRedisApplication.class, args).close(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-redis/src/test/java/sample/data/redis/SampleRedisApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-redis/src/test/java/sample/data/redis/SampleRedisApplicationTests.java deleted file mode 100644 index 2b852d7cf5..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-redis/src/test/java/sample/data/redis/SampleRedisApplicationTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.redis; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; -import org.springframework.data.redis.RedisConnectionFailureException; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SampleRedisApplication}. - * - * @author Dave Syer - */ -@ExtendWith(OutputCaptureExtension.class) -class SampleRedisApplicationTests { - - @Test - void testDefaultSettings(CapturedOutput capturedOutput) { - try { - SampleRedisApplication.main(new String[0]); - } - catch (Exception ex) { - if (!redisServerRunning(ex)) { - return; - } - } - assertThat(capturedOutput).contains("Found key spring.boot.redis.test"); - } - - private boolean redisServerRunning(Throwable ex) { - System.out.println(ex.getMessage()); - if (ex instanceof RedisConnectionFailureException) { - return false; - } - return (ex.getCause() == null || redisServerRunning(ex.getCause())); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/pom.xml b/spring-boot-samples/spring-boot-sample-data-rest/pom.xml deleted file mode 100644 index 2cea664552..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-rest/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-data-rest</artifactId> - <name>Spring Boot Data REST Sample</name> - <description>Spring Boot Data REST Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jetty</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-rest</artifactId> - </dependency> - <!-- Runtime --> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>runtime</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.jayway.jsonpath</groupId> - <artifactId>json-path</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>java9+</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <dependencies> - <dependency> - <groupId>jakarta.xml.bind</groupId> - <artifactId>jakarta.xml.bind-api</artifactId> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/SampleDataRestApplication.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/SampleDataRestApplication.java deleted file mode 100644 index 5a85ef4c1d..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/SampleDataRestApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.rest; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleDataRestApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleDataRestApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/City.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/City.java deleted file mode 100644 index 2359abc991..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/City.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.rest.domain; - -import java.io.Serializable; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.SequenceGenerator; - -@Entity -public class City implements Serializable { - - private static final long serialVersionUID = 1L; - - @Id - @SequenceGenerator(name = "city_generator", sequenceName = "city_sequence", initialValue = 23) - @GeneratedValue(generator = "city_generator") - private Long id; - - @Column(nullable = false) - private String name; - - @Column(nullable = false) - private String state; - - @Column(nullable = false) - private String country; - - @Column(nullable = false) - private String map; - - protected City() { - } - - public City(String name, String country) { - this.name = name; - this.country = country; - } - - public String getName() { - return this.name; - } - - public String getState() { - return this.state; - } - - public String getCountry() { - return this.country; - } - - public String getMap() { - return this.map; - } - - @Override - public String toString() { - return getName() + "," + getState() + "," + getCountry(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/Hotel.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/Hotel.java deleted file mode 100644 index 91e249e93b..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/Hotel.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.rest.domain; - -import java.io.Serializable; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.persistence.SequenceGenerator; - -import org.hibernate.annotations.NaturalId; - -@Entity -public class Hotel implements Serializable { - - private static final long serialVersionUID = 1L; - - @Id - @SequenceGenerator(name = "hotel_generator", sequenceName = "hotel_sequence", initialValue = 28) - @GeneratedValue(generator = "hotel_generator") - private Long id; - - @ManyToOne(optional = false) - @NaturalId - private City city; - - @Column(nullable = false) - @NaturalId - private String name; - - @Column(nullable = false) - private String address; - - @Column(nullable = false) - private String zip; - - protected Hotel() { - } - - public Hotel(City city, String name) { - this.city = city; - this.name = name; - } - - public City getCity() { - return this.city; - } - - public String getName() { - return this.name; - } - - public String getAddress() { - return this.address; - } - - public String getZip() { - return this.zip; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/CityRepository.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/CityRepository.java deleted file mode 100644 index 566d54db8a..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/CityRepository.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.rest.service; - -import sample.data.rest.domain.City; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.repository.PagingAndSortingRepository; -import org.springframework.data.repository.query.Param; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource(collectionResourceRel = "cities", path = "cities") -interface CityRepository extends PagingAndSortingRepository<City, Long> { - - Page<City> findByNameContainingAndCountryContainingAllIgnoringCase(@Param("name") String name, - @Param("country") String country, Pageable pageable); - - City findByNameAndCountryAllIgnoringCase(@Param("name") String name, @Param("country") String country); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/CitySearchCriteria.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/CitySearchCriteria.java deleted file mode 100644 index 25443a6524..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/CitySearchCriteria.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.rest.service; - -import java.io.Serializable; - -import org.springframework.util.Assert; - -public class CitySearchCriteria implements Serializable { - - private static final long serialVersionUID = 1L; - - private String name; - - public CitySearchCriteria() { - } - - public CitySearchCriteria(String name) { - Assert.notNull(name, "Name must not be null"); - this.name = name; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/HotelRepository.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/HotelRepository.java deleted file mode 100644 index 488247ba24..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/service/HotelRepository.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.rest.service; - -import sample.data.rest.domain.City; -import sample.data.rest.domain.Hotel; - -import org.springframework.data.repository.PagingAndSortingRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource(collectionResourceRel = "hotels", path = "hotels") -interface HotelRepository extends PagingAndSortingRepository<Hotel, Long> { - - Hotel findByCityAndName(City city, String name); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/SampleDataRestApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/SampleDataRestApplicationTests.java deleted file mode 100644 index 5723473ab0..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/SampleDataRestApplicationTests.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.rest; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * Integration test to run the application. - * - * @author Oliver Gierke - * @author Andy Wilkinson - */ -@SpringBootTest -// Separate profile for web tests to avoid clashing databases -class SampleDataRestApplicationTests { - - @Autowired - private WebApplicationContext context; - - private MockMvc mvc; - - @BeforeEach - void setUp() { - this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); - } - - @Test - void testHome() throws Exception { - this.mvc.perform(get("/api")).andExpect(status().isOk()).andExpect(content().string(containsString("hotels"))); - } - - @Test - void findByNameAndCountry() throws Exception { - this.mvc.perform(get("/api/cities/search/findByNameAndCountryAllIgnoringCase?name=Melbourne&country=Australia")) - .andExpect(status().isOk()).andExpect(jsonPath("state", equalTo("Victoria"))) - .andExpect(jsonPath("name", equalTo("Melbourne"))); - } - - @Test - void findByContaining() throws Exception { - this.mvc.perform( - get("/api/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK")) - .andExpect(status().isOk()).andExpect(jsonPath("_embedded.cities", hasSize(3))); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java deleted file mode 100644 index 7e33f64dca..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.rest.service; - -import org.junit.jupiter.api.Test; -import sample.data.rest.domain.City; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for {@link CityRepository}. - * - * @author Oliver Gierke - * @author Andy Wilkinson - */ -@SpringBootTest -class CityRepositoryIntegrationTests { - - @Autowired - CityRepository repository; - - @Test - void findsFirstPageOfCities() { - Page<City> cities = this.repository.findAll(PageRequest.of(0, 10)); - assertThat(cities.getTotalElements()).isGreaterThan(20L); - } - - @Test - void findByNameAndCountry() { - City city = this.repository.findByNameAndCountryAllIgnoringCase("Melbourne", "Australia"); - assertThat(city).isNotNull(); - assertThat(city.getName()).isEqualTo("Melbourne"); - } - - @Test - void findContaining() { - Page<City> cities = this.repository.findByNameContainingAndCountryContainingAllIgnoringCase("", "UK", - PageRequest.of(0, 10)); - assertThat(cities.getTotalElements()).isEqualTo(3L); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-solr/pom.xml b/spring-boot-samples/spring-boot-sample-data-solr/pom.xml deleted file mode 100644 index f6a72b5258..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-solr/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-data-solr</artifactId> - <name>Spring Boot Data Solr Sample</name> - <description>Spring Boot Data Solr Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-solr</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java b/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java deleted file mode 100644 index f569740eb4..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/Product.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.solr; - -import java.util.List; - -import org.apache.solr.client.solrj.beans.Field; - -import org.springframework.data.annotation.Id; -import org.springframework.data.solr.core.geo.Point; -import org.springframework.data.solr.core.mapping.SolrDocument; - -@SolrDocument(solrCoreName = "collection1") -public class Product { - - @Id - @Field - private String id; - - @Field - private String name; - - @Field - private Double price; - - @Field("cat") - private List<String> category; - - @Field("store") - private Point location; - - public Product() { - } - - public Product(String id, String name) { - this.id = id; - this.name = name; - } - - public String getId() { - return this.id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public Double getPrice() { - return this.price; - } - - public void setPrice(Double price) { - this.price = price; - } - - public List<String> getCategory() { - return this.category; - } - - public void setCategory(List<String> category) { - this.category = category; - } - - public Point getLocation() { - return this.location; - } - - public void setLocation(Point location) { - this.location = location; - } - - @Override - public String toString() { - return "Product [id=" + this.id + ", name=" + this.name + ", price=" + this.price + ", category=" - + this.category + ", location=" + this.location + "]"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/ProductRepository.java b/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/ProductRepository.java deleted file mode 100644 index 5064fe1a9d..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/ProductRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.solr; - -import java.util.List; - -import org.springframework.data.solr.repository.SolrCrudRepository; - -public interface ProductRepository extends SolrCrudRepository<Product, String> { - - List<Product> findByNameStartingWith(String name); - -} diff --git a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/SampleSolrApplication.java b/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/SampleSolrApplication.java deleted file mode 100644 index 4e876bea46..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-solr/src/main/java/sample/data/solr/SampleSolrApplication.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.solr; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleSolrApplication implements CommandLineRunner { - - @Autowired - private ProductRepository repository; - - @Override - public void run(String... args) throws Exception { - - this.repository.deleteAll(); - - // insert some products - this.repository.save(new Product("1", "Nintendo Entertainment System")); - this.repository.save(new Product("2", "Sega Megadrive")); - this.repository.save(new Product("3", "Sony Playstation")); - - // fetch all - System.out.println("Products found by findAll():"); - System.out.println("----------------------------"); - for (Product product : this.repository.findAll()) { - System.out.println(product); - } - System.out.println(); - - // fetch a single product - System.out.println("Products found with findByNameStartingWith('So'):"); - System.out.println("--------------------------------"); - for (Product product : this.repository.findByNameStartingWith("So")) { - System.out.println(product); - } - System.out.println(); - } - - public static void main(String[] args) { - SpringApplication.run(SampleSolrApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java deleted file mode 100644 index 78afa4183b..0000000000 --- a/spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.data.solr; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; -import org.springframework.core.NestedCheckedException; - -import static org.assertj.core.api.Assertions.assertThat; - -@ExtendWith(OutputCaptureExtension.class) -class SampleSolrApplicationTests { - - @Test - void testDefaultSettings(CapturedOutput capturedOutput) throws Exception { - try { - SampleSolrApplication.main(new String[0]); - } - catch (IllegalStateException ex) { - if (serverNotRunning(ex)) { - return; - } - } - assertThat(capturedOutput).contains("name=Sony Playstation"); - } - - @SuppressWarnings("serial") - private boolean serverNotRunning(IllegalStateException ex) { - NestedCheckedException nested = new NestedCheckedException("failed", ex) { - }; - Throwable root = nested.getRootCause(); - if (root.getMessage().contains("Connection refused")) { - return true; - } - return false; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-devtools/pom.xml b/spring-boot-samples/spring-boot-sample-devtools/pom.xml deleted file mode 100644 index e692c813b0..0000000000 --- a/spring-boot-samples/spring-boot-sample-devtools/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-devtools</artifactId> - <name>Spring Boot Developer Tools Sample</name> - <description>Spring Boot Developer Tools Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-thymeleaf</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-devtools</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/Message.java b/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/Message.java deleted file mode 100644 index 43daa80656..0000000000 --- a/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/Message.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.devtools; - -public final class Message { - - /** - * Sample message. - */ - public static String MESSAGE = "Message"; - - private Message() { - } - -} diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java b/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java deleted file mode 100644 index d0778e9dd0..0000000000 --- a/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.devtools; - -import java.util.Date; - -import javax.annotation.PostConstruct; -import javax.servlet.http.HttpSession; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.servlet.ModelAndView; - -@Controller -public class MyController { - - @PostConstruct - public void slowRestart() throws InterruptedException { - Thread.sleep(5000); - } - - @GetMapping("/") - public ModelAndView get(HttpSession session) { - Object sessionVar = session.getAttribute("var"); - if (sessionVar == null) { - sessionVar = new Date(); - session.setAttribute("var", sessionVar); - } - ModelMap model = new ModelMap("message", Message.MESSAGE).addAttribute("sessionVar", sessionVar); - return new ModelAndView("hello", model); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/SampleDevToolsApplication.java b/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/SampleDevToolsApplication.java deleted file mode 100644 index fa2066453c..0000000000 --- a/spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/SampleDevToolsApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.devtools; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleDevToolsApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleDevToolsApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java b/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java deleted file mode 100644 index 5ae76704a7..0000000000 --- a/spring-boot-samples/spring-boot-sample-devtools/src/test/java/sample/devtools/SampleDevToolsApplicationIntegrationTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.devtools; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for {@link SampleDevToolsApplication}. - * - * @author Andy Wilkinson - * @author Phillip Webb - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleDevToolsApplicationIntegrationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testStaticResource() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/application.css", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("color: green;"); - } - - @Test - void testPublicResource() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/public.txt", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("public file"); - } - - @Test - void testClassResource() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/application.properties", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-flyway/README.adoc b/spring-boot-samples/spring-boot-sample-flyway/README.adoc deleted file mode 100644 index 1c3559a3f1..0000000000 --- a/spring-boot-samples/spring-boot-sample-flyway/README.adoc +++ /dev/null @@ -1,9 +0,0 @@ -== Spring Boot Flyway Sample - -This sample demonstrates the flyway auto-configuration support. - -You can look at `http://localhost:8080/actuator/flyway` to review the list of scripts. - -This sample also enables the H2 console (at `http://localhost:8080/h2-console`) -so that you can review the state of the database (the default jdbc url is -`jdbc:h2:mem:testdb`). diff --git a/spring-boot-samples/spring-boot-sample-flyway/pom.xml b/spring-boot-samples/spring-boot-sample-flyway/pom.xml deleted file mode 100644 index ea14ac4d64..0000000000 --- a/spring-boot-samples/spring-boot-sample-flyway/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-flyway</artifactId> - <name>Spring Boot Flyway Sample</name> - <description>Spring Boot Flyway Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> - <dependency> - <groupId>org.flywaydb</groupId> - <artifactId>flyway-core</artifactId> - </dependency> - <!-- Runtime --> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>runtime</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>java9+</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <dependencies> - <dependency> - <groupId>jakarta.xml.bind</groupId> - <artifactId>jakarta.xml.bind-api</artifactId> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/Person.java b/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/Person.java deleted file mode 100644 index fdf9cc55d4..0000000000 --- a/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/Person.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.flyway; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.SequenceGenerator; - -@Entity -public class Person { - - @Id - @SequenceGenerator(name = "person_generator", sequenceName = "person_sequence", allocationSize = 1) - @GeneratedValue(generator = "person_generator") - private Long id; - - private String firstName; - - private String lastName; - - public String getFirstName() { - return this.firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return this.lastName; - } - - public void setLastName(String lastname) { - this.lastName = lastname; - } - - @Override - public String toString() { - return "Person [firstName=" + this.firstName + ", lastName=" + this.lastName + "]"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/PersonRepository.java b/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/PersonRepository.java deleted file mode 100644 index 3995b378cd..0000000000 --- a/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/PersonRepository.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.flyway; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface PersonRepository extends CrudRepository<Person, Long> { - -} diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/SampleFlywayApplication.java b/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/SampleFlywayApplication.java deleted file mode 100644 index eca314f029..0000000000 --- a/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/SampleFlywayApplication.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.flyway; - -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -public class SampleFlywayApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleFlywayApplication.class, args); - } - - @Bean - public CommandLineRunner runner(PersonRepository repository) { - return new CommandLineRunner() { - - @Override - public void run(String... args) throws Exception { - System.err.println(repository.findAll()); - } - - }; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java b/spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java deleted file mode 100644 index 1eb458869c..0000000000 --- a/spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.flyway; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.jdbc.core.JdbcTemplate; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -class SampleFlywayApplicationTests { - - @Autowired - private JdbcTemplate template; - - @Test - void testDefaultSettings() { - assertThat(this.template.queryForObject("SELECT COUNT(*) from PERSON", Integer.class)).isEqualTo(1); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-hateoas/pom.xml b/spring-boot-samples/spring-boot-sample-hateoas/pom.xml deleted file mode 100644 index cc64688ecb..0000000000 --- a/spring-boot-samples/spring-boot-sample-hateoas/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-hateoas</artifactId> - <name>Spring Boot Hateoas Sample</name> - <description>Spring Boot Hateoas Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-hateoas</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/SampleHateoasApplication.java b/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/SampleHateoasApplication.java deleted file mode 100644 index b1e9b814be..0000000000 --- a/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/SampleHateoasApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.hateoas; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleHateoasApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleHateoasApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/domain/Customer.java b/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/domain/Customer.java deleted file mode 100644 index ad8ca3acea..0000000000 --- a/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/domain/Customer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.hateoas.domain; - -public class Customer { - - private final Long id; - - private final String firstName; - - private final String lastName; - - public Customer(Long id, String firstName, String lastName) { - this.id = id; - this.firstName = firstName; - this.lastName = lastName; - } - - public Long getId() { - return this.id; - } - - public String getFirstName() { - return this.firstName; - } - - public String getLastName() { - return this.lastName; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/domain/CustomerRepository.java b/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/domain/CustomerRepository.java deleted file mode 100644 index 4744b01504..0000000000 --- a/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/domain/CustomerRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.hateoas.domain; - -import java.util.List; - -public interface CustomerRepository { - - List<Customer> findAll(); - - Customer findOne(Long id); - -} diff --git a/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/domain/InMemoryCustomerRepository.java b/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/domain/InMemoryCustomerRepository.java deleted file mode 100644 index e002ff5597..0000000000 --- a/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/domain/InMemoryCustomerRepository.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.hateoas.domain; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.stereotype.Repository; -import org.springframework.util.ObjectUtils; - -@Repository -public class InMemoryCustomerRepository implements CustomerRepository { - - private final List<Customer> customers = new ArrayList<>(); - - public InMemoryCustomerRepository() { - this.customers.add(new Customer(1L, "Oliver", "Gierke")); - this.customers.add(new Customer(2L, "Andy", "Wilkinson")); - this.customers.add(new Customer(2L, "Dave", "Syer")); - } - - @Override - public List<Customer> findAll() { - return this.customers; - } - - @Override - public Customer findOne(Long id) { - for (Customer customer : this.customers) { - if (ObjectUtils.nullSafeEquals(customer.getId(), id)) { - return customer; - } - } - return null; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/web/CustomerController.java b/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/web/CustomerController.java deleted file mode 100644 index 336f3db774..0000000000 --- a/spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/web/CustomerController.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.hateoas.web; - -import sample.hateoas.domain.Customer; -import sample.hateoas.domain.CustomerRepository; - -import org.springframework.hateoas.CollectionModel; -import org.springframework.hateoas.EntityModel; -import org.springframework.hateoas.server.EntityLinks; -import org.springframework.hateoas.server.ExposesResourceFor; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; - -@Controller -@RequestMapping("/customers") -@ExposesResourceFor(Customer.class) -public class CustomerController { - - private final CustomerRepository repository; - - private final EntityLinks entityLinks; - - public CustomerController(CustomerRepository repository, EntityLinks entityLinks) { - this.repository = repository; - this.entityLinks = entityLinks; - } - - @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) - HttpEntity<CollectionModel<Customer>> showCustomers() { - CollectionModel<Customer> resources = new CollectionModel<>(this.repository.findAll()); - resources.add(this.entityLinks.linkToCollectionResource(Customer.class)); - return new ResponseEntity<>(resources, HttpStatus.OK); - } - - @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - HttpEntity<EntityModel<Customer>> showCustomer(@PathVariable Long id) { - EntityModel<Customer> resource = new EntityModel<>(this.repository.findOne(id)); - resource.add(this.entityLinks.linkToItemResource(Customer.class, id)); - return new ResponseEntity<>(resource, HttpStatus.OK); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java b/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java deleted file mode 100644 index dc6ee3fe5d..0000000000 --- a/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.hateoas; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleHateoasApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void hasHalLinks() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/customers/1", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).startsWith("{\"id\":1,\"firstName\":\"Oliver\"" + ",\"lastName\":\"Gierke\""); - assertThat(entity.getBody()).contains("_links\":{\"self\":{\"href\""); - } - - @Test - void producesJsonWhenXmlIsPreferred() { - HttpHeaders headers = new HttpHeaders(); - headers.set(HttpHeaders.ACCEPT, "application/xml;q=0.9,application/json;q=0.8"); - HttpEntity<?> request = new HttpEntity<>(headers); - ResponseEntity<String> response = this.restTemplate.exchange("/customers/1", HttpMethod.GET, request, - String.class); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.getHeaders().getContentType()).isEqualTo(MediaType.parseMediaType("application/json")); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-integration/pom.xml b/spring-boot-samples/spring-boot-sample-integration/pom.xml deleted file mode 100644 index 09fd96017c..0000000000 --- a/spring-boot-samples/spring-boot-sample-integration/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-integration</artifactId> - <name>Spring Boot Integration Sample</name> - <description>Spring Boot Integration Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-integration</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.integration</groupId> - <artifactId>spring-integration-file</artifactId> - </dependency> - <!-- Optional --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-configuration-processor</artifactId> - <optional>true</optional> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/HelloWorldService.java deleted file mode 100644 index 2936af3abe..0000000000 --- a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/HelloWorldService.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.integration; - -import org.springframework.stereotype.Service; - -@Service -public class HelloWorldService { - - private final ServiceProperties configuration; - - public HelloWorldService(ServiceProperties configuration) { - this.configuration = configuration; - } - - public String getHelloMessage(String name) { - return this.configuration.getGreeting() + " " + name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleApplicationRunner.java b/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleApplicationRunner.java deleted file mode 100644 index eacabf5346..0000000000 --- a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleApplicationRunner.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.integration; - -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.stereotype.Component; - -@Component -public class SampleApplicationRunner implements ApplicationRunner { - - private final SampleMessageGateway gateway; - - public SampleApplicationRunner(SampleMessageGateway gateway) { - this.gateway = gateway; - } - - @Override - public void run(ApplicationArguments args) throws Exception { - for (String arg : args.getNonOptionArgs()) { - this.gateway.echo(arg); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleEndpoint.java b/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleEndpoint.java deleted file mode 100644 index 2c52411e9b..0000000000 --- a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleEndpoint.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.integration; - -import java.io.File; -import java.io.FileInputStream; - -import org.springframework.integration.annotation.MessageEndpoint; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.util.StreamUtils; - -@MessageEndpoint -public class SampleEndpoint { - - private final HelloWorldService helloWorldService; - - public SampleEndpoint(HelloWorldService helloWorldService) { - this.helloWorldService = helloWorldService; - } - - @ServiceActivator - public String hello(File input) throws Exception { - FileInputStream in = new FileInputStream(input); - String name = new String(StreamUtils.copyToByteArray(in)); - in.close(); - return this.helloWorldService.getHelloMessage(name); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleIntegrationApplication.java b/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleIntegrationApplication.java deleted file mode 100644 index 8e5ded4b68..0000000000 --- a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleIntegrationApplication.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.integration; - -import java.util.function.Consumer; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.integration.channel.DirectChannel; -import org.springframework.integration.dsl.IntegrationFlow; -import org.springframework.integration.dsl.IntegrationFlows; -import org.springframework.integration.dsl.Pollers; -import org.springframework.integration.dsl.SourcePollingChannelAdapterSpec; -import org.springframework.integration.file.FileReadingMessageSource; -import org.springframework.integration.file.FileWritingMessageHandler; - -@SpringBootApplication -public class SampleIntegrationApplication { - - private final ServiceProperties serviceProperties; - - public SampleIntegrationApplication(ServiceProperties serviceProperties) { - this.serviceProperties = serviceProperties; - } - - @Bean - public FileReadingMessageSource fileReader() { - FileReadingMessageSource reader = new FileReadingMessageSource(); - reader.setDirectory(this.serviceProperties.getInputDir()); - return reader; - } - - @Bean - public DirectChannel inputChannel() { - return new DirectChannel(); - } - - @Bean - public DirectChannel outputChannel() { - return new DirectChannel(); - } - - @Bean - public FileWritingMessageHandler fileWriter() { - FileWritingMessageHandler writer = new FileWritingMessageHandler(this.serviceProperties.getOutputDir()); - writer.setExpectReply(false); - return writer; - } - - @Bean - public IntegrationFlow integrationFlow(SampleEndpoint endpoint) { - return IntegrationFlows.from(fileReader(), new FixedRatePoller()).channel(inputChannel()).handle(endpoint) - .channel(outputChannel()).handle(fileWriter()).get(); - } - - public static void main(String[] args) { - SpringApplication.run(SampleIntegrationApplication.class, args); - } - - private static class FixedRatePoller implements Consumer<SourcePollingChannelAdapterSpec> { - - @Override - public void accept(SourcePollingChannelAdapterSpec spec) { - spec.poller(Pollers.fixedRate(500)); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleMessageGateway.java b/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleMessageGateway.java deleted file mode 100644 index 734e9925cf..0000000000 --- a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/SampleMessageGateway.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.integration; - -import org.springframework.integration.annotation.MessagingGateway; - -@MessagingGateway(defaultRequestChannel = "outputChannel") -public interface SampleMessageGateway { - - void echo(String message); - -} diff --git a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/ServiceProperties.java b/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/ServiceProperties.java deleted file mode 100644 index d43819b18f..0000000000 --- a/spring-boot-samples/spring-boot-sample-integration/src/main/java/sample/integration/ServiceProperties.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.integration; - -import java.io.File; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.jmx.export.annotation.ManagedAttribute; -import org.springframework.jmx.export.annotation.ManagedResource; - -@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) -@ManagedResource -public class ServiceProperties { - - private String greeting = "Hello"; - - private File inputDir; - - private File outputDir; - - @ManagedAttribute - public String getGreeting() { - return this.greeting; - } - - public void setGreeting(String greeting) { - this.greeting = greeting; - } - - public File getInputDir() { - return this.inputDir; - } - - public void setInputDir(File inputDir) { - this.inputDir = inputDir; - } - - public File getOutputDir() { - return this.outputDir; - } - - public void setOutputDir(File outputDir) { - this.outputDir = outputDir; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java b/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java deleted file mode 100644 index 44a0c363da..0000000000 --- a/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.integration.consumer; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.util.concurrent.Callable; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; -import sample.integration.SampleIntegrationApplication; -import sample.integration.ServiceProperties; -import sample.integration.producer.ProducerApplication; - -import org.springframework.boot.SpringApplication; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.io.DefaultResourceLoader; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.ResourcePatternUtils; -import org.springframework.util.StreamUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for service demo application. - * - * @author Dave Syer - * @author Andy Wilkinson - */ -class SampleIntegrationApplicationTests { - - private ConfigurableApplicationContext context; - - @AfterEach - void stop() { - if (this.context != null) { - this.context.close(); - } - } - - @Test - void testVanillaExchange(@TempDir Path temp) throws Exception { - File inputDir = new File(temp.toFile(), "input"); - File outputDir = new File(temp.toFile(), "output"); - this.context = SpringApplication.run(SampleIntegrationApplication.class, "--service.input-dir=" + inputDir, - "--service.output-dir=" + outputDir); - SpringApplication.run(ProducerApplication.class, "World", "--service.input-dir=" + inputDir, - "--service.output-dir=" + outputDir); - String output = getOutput(outputDir); - assertThat(output).contains("Hello World"); - } - - @Test - void testMessageGateway(@TempDir Path temp) throws Exception { - File inputDir = new File(temp.toFile(), "input"); - File outputDir = new File(temp.toFile(), "output"); - this.context = SpringApplication.run(SampleIntegrationApplication.class, "testviamg", - "--service.input-dir=" + inputDir, "--service.output-dir=" + outputDir); - String output = getOutput(this.context.getBean(ServiceProperties.class).getOutputDir()); - assertThat(output).contains("testviamg"); - } - - private String getOutput(File outputDir) throws Exception { - Future<String> future = Executors.newSingleThreadExecutor().submit(new Callable<String>() { - @Override - public String call() throws Exception { - Resource[] resources = getResourcesWithContent(outputDir); - while (resources.length == 0) { - Thread.sleep(200); - resources = getResourcesWithContent(outputDir); - } - StringBuilder builder = new StringBuilder(); - for (Resource resource : resources) { - try (InputStream inputStream = resource.getInputStream()) { - builder.append(new String(StreamUtils.copyToByteArray(inputStream))); - } - } - return builder.toString(); - } - }); - return future.get(30, TimeUnit.SECONDS); - } - - private Resource[] getResourcesWithContent(File outputDir) throws IOException { - Resource[] candidates = ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader()) - .getResources("file:" + outputDir.getAbsolutePath() + "/**"); - for (Resource candidate : candidates) { - if ((candidate.getFilename() != null && candidate.getFilename().endsWith(".writing")) - || candidate.contentLength() == 0) { - return new Resource[0]; - } - } - return candidates; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/producer/ProducerApplication.java b/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/producer/ProducerApplication.java deleted file mode 100644 index 1ba46554d5..0000000000 --- a/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/producer/ProducerApplication.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.integration.producer; - -import java.io.File; -import java.io.FileOutputStream; - -import sample.integration.ServiceProperties; - -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties(ServiceProperties.class) -public class ProducerApplication implements ApplicationRunner { - - private final ServiceProperties serviceProperties; - - public ProducerApplication(ServiceProperties serviceProperties) { - this.serviceProperties = serviceProperties; - } - - @Override - public void run(ApplicationArguments args) throws Exception { - this.serviceProperties.getInputDir().mkdirs(); - if (args.getNonOptionArgs().size() > 0) { - FileOutputStream stream = new FileOutputStream( - new File(this.serviceProperties.getInputDir(), "data" + System.currentTimeMillis() + ".txt")); - for (String arg : args.getNonOptionArgs()) { - stream.write(arg.getBytes()); - } - stream.flush(); - stream.close(); - } - } - - public static void main(String[] args) { - SpringApplication.run(ProducerApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jersey/pom.xml b/spring-boot-samples/spring-boot-sample-jersey/pom.xml deleted file mode 100644 index 92c0977212..0000000000 --- a/spring-boot-samples/spring-boot-sample-jersey/pom.xml +++ /dev/null @@ -1,71 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-jersey</artifactId> - <packaging>war</packaging> - <name>Spring Boot Jersey Sample</name> - <description>Spring Boot Jersey Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jersey</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> - <!-- Provided --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - <scope>provided</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <executions> - <execution> - <id>generate build info</id> - <goals> - <goal>build-info</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>java9+</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <dependencies> - <dependency> - <groupId>jakarta.xml.bind</groupId> - <artifactId>jakarta.xml.bind-api</artifactId> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/Endpoint.java b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/Endpoint.java deleted file mode 100644 index 7c74ac9a9e..0000000000 --- a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/Endpoint.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jersey; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.springframework.stereotype.Component; - -@Component -@Path("/hello") -public class Endpoint { - - private final Service service; - - public Endpoint(Service service) { - this.service = service; - } - - @GET - public String message() { - return "Hello " + this.service.message(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/JerseyConfig.java b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/JerseyConfig.java deleted file mode 100644 index 93d0b115b9..0000000000 --- a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/JerseyConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jersey; - -import org.glassfish.jersey.server.ResourceConfig; - -import org.springframework.stereotype.Component; - -@Component -public class JerseyConfig extends ResourceConfig { - - public JerseyConfig() { - register(Endpoint.class); - register(ReverseEndpoint.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/ReverseEndpoint.java b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/ReverseEndpoint.java deleted file mode 100644 index abf7c5407b..0000000000 --- a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/ReverseEndpoint.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jersey; - -import javax.validation.constraints.NotNull; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.QueryParam; - -import org.springframework.stereotype.Component; - -@Component -@Path("/reverse") -public class ReverseEndpoint { - - @GET - public String reverse(@QueryParam("input") @NotNull String input) { - return new StringBuilder(input).reverse().toString(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/SampleJerseyApplication.java b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/SampleJerseyApplication.java deleted file mode 100644 index 20362e4a59..0000000000 --- a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/SampleJerseyApplication.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jersey; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; - -@SpringBootApplication -public class SampleJerseyApplication extends SpringBootServletInitializer { - - public static void main(String[] args) { - new SampleJerseyApplication().configure(new SpringApplicationBuilder(SampleJerseyApplication.class)).run(args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/Service.java b/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/Service.java deleted file mode 100644 index 84c6c0caed..0000000000 --- a/spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/Service.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jersey; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class Service { - - @Value("${message:World}") - private String msg; - - public String message() { - return this.msg; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/JerseyApplicationPathAndManagementPortTests.java b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/JerseyApplicationPathAndManagementPortTests.java deleted file mode 100644 index 3cfbc090e8..0000000000 --- a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/JerseyApplicationPathAndManagementPortTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.jersey; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for separate management and main service ports with custom - * application path. - * - * @author Madhura Bhave - */ -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = { "management.server.port=0", "spring.jersey.application-path=/app" }) -class JerseyApplicationPathAndManagementPortTests { - - @LocalServerPort - private int port; - - @LocalManagementPort - private int managementPort; - - @Autowired - private TestRestTemplate testRestTemplate; - - @Test - void applicationPathShouldNotAffectActuators() { - ResponseEntity<String> entity = this.testRestTemplate - .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"status\":\"UP\""); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java deleted file mode 100644 index 3c12e5c427..0000000000 --- a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jersey; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleJerseyApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void contextLoads() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/hello", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - } - - @Test - void reverse() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/reverse?input=olleh", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("hello"); - } - - @Test - void validation() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/reverse", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); - } - - @Test - void actuatorStatus() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/health", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty-jsp/pom.xml b/spring-boot-samples/spring-boot-sample-jetty-jsp/pom.xml deleted file mode 100644 index 2060386111..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty-jsp/pom.xml +++ /dev/null @@ -1,126 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-jetty-jsp</artifactId> - <packaging>war</packaging> - <name>Spring Boot Jetty JSP Sample</name> - <description>Spring Boot Jetty JSP Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> - <servlet-api.version>3.1.0</servlet-api.version> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>jstl</artifactId> - </dependency> - <!-- Provided --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jetty</artifactId> - <scope>provided</scope> - <exclusions> - <exclusion> - <groupId>jakarta.servlet</groupId> - <artifactId>jakarta.servlet-api</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>apache-jsp</artifactId> - <scope>provided</scope> - <exclusions> - <exclusion> - <groupId>javax.annotation</groupId> - <artifactId>javax.annotation-api</artifactId> - </exclusion> - </exclusions> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <configuration> - <executable>true</executable> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-enforcer-plugin</artifactId> - <executions> - <execution> - <id>enforce-rules</id> - <goals> - <goal>enforce</goal> - </goals> - <configuration> - <rules> - <bannedDependencies> - <includes> - <include>javax.servlet:javax.servlet-api:*</include> - </includes> - <searchTransitive>true</searchTransitive> - </bannedDependencies> - </rules> - <fail>true</fail> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <useSystemClassLoader>false</useSystemClassLoader> - </configuration> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>java9+</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <skipTests>true</skipTests> - </configuration> - </plugin> - </plugins> - </build> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/MyException.java b/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/MyException.java deleted file mode 100644 index f19a6fa4e4..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/MyException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty.jsp; - -public class MyException extends RuntimeException { - - public MyException(String message) { - super(message); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/MyRestResponse.java b/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/MyRestResponse.java deleted file mode 100644 index aade1c8d22..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/MyRestResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty.jsp; - -public class MyRestResponse { - - private String message; - - public MyRestResponse(String message) { - this.message = message; - } - - public String getMessage() { - return this.message; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/SampleJettyJspApplication.java b/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/SampleJettyJspApplication.java deleted file mode 100644 index 01ecec3833..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/SampleJettyJspApplication.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty.jsp; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; - -@SpringBootApplication -public class SampleJettyJspApplication extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleJettyJspApplication.class); - } - - public static void main(String[] args) { - SpringApplication.run(SampleJettyJspApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/WelcomeController.java b/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/WelcomeController.java deleted file mode 100644 index eea31ee5d0..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/java/sample/jetty/jsp/WelcomeController.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty.jsp; - -import java.util.Date; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; - -@Controller -public class WelcomeController { - - @Value("${application.message:Hello World}") - private String message = "Hello World"; - - @RequestMapping("/") - public String welcome(Map<String, Object> model) { - model.put("time", new Date()); - model.put("message", this.message); - return "welcome"; - } - - @RequestMapping("/fail") - public String fail() { - throw new MyException("Oh dear!"); - } - - @RequestMapping("/fail2") - public String fail2() { - throw new IllegalStateException(); - } - - @ExceptionHandler(MyException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - public @ResponseBody MyRestResponse handleMyRuntimeException(MyException exception) { - return new MyRestResponse("Some data I want to send back to the client."); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty-jsp/src/test/java/sample/jetty/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty-jsp/src/test/java/sample/jetty/jsp/SampleWebJspApplicationTests.java deleted file mode 100644 index 13a3e0e20f..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty-jsp/src/test/java/sample/jetty/jsp/SampleWebJspApplicationTests.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty.jsp; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for JSP application. - * - * @author Phillip Webb - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebJspApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testJspWithEl() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("/resources/text.txt"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml b/spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml deleted file mode 100644 index 7f69978edb..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-jetty-ssl</artifactId> - <name>Spring Boot Jetty SSL Sample</name> - <description>Spring Boot Jetty SSL Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <servlet-api.version>3.1.0</servlet-api.version> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jetty</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/ssl/SampleJettySslApplication.java b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/ssl/SampleJettySslApplication.java deleted file mode 100644 index 0bfb0841ae..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/ssl/SampleJettySslApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty.ssl; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleJettySslApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleJettySslApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/ssl/web/SampleController.java b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/ssl/web/SampleController.java deleted file mode 100644 index d7baf36a95..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/java/sample/jetty/ssl/web/SampleController.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty.ssl.web; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class SampleController { - - @GetMapping("/") - public String helloWorld() { - return "Hello World"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java deleted file mode 100644 index 8350bd2ec3..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty.ssl; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleJettySslApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Autowired - private AbstractConfigurableWebServerFactory webServerFactory; - - @Test - void testSsl() { - assertThat(this.webServerFactory.getSsl().isEnabled()).isTrue(); - } - - @Test - void testHome() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("Hello World"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty/pom.xml b/spring-boot-samples/spring-boot-sample-jetty/pom.xml deleted file mode 100644 index 77d5aaf1ce..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-jetty</artifactId> - <name>Spring Boot Jetty Sample</name> - <description>Spring Boot Jetty Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <servlet-api.version>3.1.0</servlet-api.version> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jetty</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/ExampleServletContextListener.java b/spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/ExampleServletContextListener.java deleted file mode 100644 index e99130ea75..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/ExampleServletContextListener.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.springframework.stereotype.Component; - -/** - * Simple {@link ServletContextListener} to test gh-2058. - */ -@Component -public class ExampleServletContextListener implements ServletContextListener { - - @Override - public void contextInitialized(ServletContextEvent sce) { - System.out.println("*** contextInitialized"); - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - System.out.println("*** contextDestroyed"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/SampleJettyApplication.java b/spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/SampleJettyApplication.java deleted file mode 100644 index 94a9a6bbcc..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/SampleJettyApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleJettyApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleJettyApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/service/HelloWorldService.java deleted file mode 100644 index 5cd88cb3d6..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/service/HelloWorldService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty.service; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - @Value("${name:World}") - private String name; - - public String getHelloMessage() { - return "Hello " + this.name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/web/SampleController.java b/spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/web/SampleController.java deleted file mode 100644 index 7ef6b5bdba..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty/src/main/java/sample/jetty/web/SampleController.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty.web; - -import sample.jetty.service.HelloWorldService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class SampleController { - - @Autowired - private HelloWorldService helloWorldService; - - @GetMapping("/") - @ResponseBody - public String helloWorld() { - return this.helloWorldService.getHelloMessage(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java deleted file mode 100644 index b237a978d7..0000000000 --- a/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jetty; - -import java.io.ByteArrayInputStream; -import java.nio.charset.StandardCharsets; -import java.util.zip.GZIPInputStream; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.util.StreamUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - * @author Andy Wilkinson - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleJettyApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHome() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("Hello World"); - } - - @Test - void testCompression() throws Exception { - HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.set("Accept-Encoding", "gzip"); - HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders); - ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - try (GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()))) { - assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)).isEqualTo("Hello World"); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/README.adoc b/spring-boot-samples/spring-boot-sample-jooq/README.adoc deleted file mode 100644 index 17e6be3742..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/README.adoc +++ /dev/null @@ -1,9 +0,0 @@ -== jOOQ Sample - -To rerun the code generator: - -[indent=0] ----- - $ rm -fr gensrc - $ mvn clean generate-sources -Pgenerate ----- diff --git a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Author.java b/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Author.java deleted file mode 100644 index 75ca335cd0..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Author.java +++ /dev/null @@ -1,141 +0,0 @@ -/** - * This class is generated by jOOQ - */ -package sample.jooq.domain; - -import java.sql.Date; -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Generated; - -import org.jooq.Field; -import org.jooq.Record; -import org.jooq.Schema; -import org.jooq.Table; -import org.jooq.TableField; -import org.jooq.UniqueKey; -import org.jooq.impl.TableImpl; - -/** - * This class is generated by jOOQ. - */ -@Generated(value = { "https://www.jooq.org", - "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class Author extends TableImpl<Record> { - - private static final long serialVersionUID = 1187406915; - - /** - * The reference instance of <code>PUBLIC.AUTHOR</code> - */ - public static final Author AUTHOR = new Author(); - - /** - * The class holding records for this type - */ - @Override - public Class<Record> getRecordType() { - return Record.class; - } - - /** - * The column <code>PUBLIC.AUTHOR.ID</code>. - */ - public final TableField<Record, Integer> ID = createField("ID", - org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); - - /** - * The column <code>PUBLIC.AUTHOR.FIRST_NAME</code>. - */ - public final TableField<Record, String> FIRST_NAME = createField("FIRST_NAME", - org.jooq.impl.SQLDataType.VARCHAR.length(50), this, ""); - - /** - * The column <code>PUBLIC.AUTHOR.LAST_NAME</code>. - */ - public final TableField<Record, String> LAST_NAME = createField("LAST_NAME", - org.jooq.impl.SQLDataType.VARCHAR.length(50).nullable(false), this, ""); - - /** - * The column <code>PUBLIC.AUTHOR.DATE_OF_BIRTH</code>. - */ - public final TableField<Record, Date> DATE_OF_BIRTH = createField("DATE_OF_BIRTH", - org.jooq.impl.SQLDataType.DATE, this, ""); - - /** - * The column <code>PUBLIC.AUTHOR.YEAR_OF_BIRTH</code>. - */ - public final TableField<Record, Integer> YEAR_OF_BIRTH = createField("YEAR_OF_BIRTH", - org.jooq.impl.SQLDataType.INTEGER, this, ""); - - /** - * The column <code>PUBLIC.AUTHOR.DISTINGUISHED</code>. - */ - public final TableField<Record, Byte> DISTINGUISHED = createField("DISTINGUISHED", - org.jooq.impl.SQLDataType.TINYINT, this, ""); - - /** - * Create a <code>PUBLIC.AUTHOR</code> table reference - */ - public Author() { - this("AUTHOR", null); - } - - /** - * Create an aliased <code>PUBLIC.AUTHOR</code> table reference - */ - public Author(String alias) { - this(alias, AUTHOR); - } - - private Author(String alias, Table<Record> aliased) { - this(alias, aliased, null); - } - - private Author(String alias, Table<Record> aliased, Field<?>[] parameters) { - super(alias, null, aliased, parameters, ""); - } - - /** - * {@inheritDoc} - */ - @Override - public Schema getSchema() { - return Public.PUBLIC; - } - - /** - * {@inheritDoc} - */ - @Override - public UniqueKey<Record> getPrimaryKey() { - return Keys.CONSTRAINT_7; - } - - /** - * {@inheritDoc} - */ - @Override - public List<UniqueKey<Record>> getKeys() { - return Arrays.<UniqueKey<Record>>asList(Keys.CONSTRAINT_7); - } - - /** - * {@inheritDoc} - */ - @Override - public Author as(String alias) { - return new Author(alias, this); - } - - /** - * Rename this table - */ - @Override - public Author rename(String name) { - return new Author(name, null); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Book.java b/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Book.java deleted file mode 100644 index ae21234fd1..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Book.java +++ /dev/null @@ -1,144 +0,0 @@ -/** - * This class is generated by jOOQ - */ -package sample.jooq.domain; - -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Generated; - -import org.jooq.Field; -import org.jooq.ForeignKey; -import org.jooq.Record; -import org.jooq.Schema; -import org.jooq.Table; -import org.jooq.TableField; -import org.jooq.UniqueKey; -import org.jooq.impl.TableImpl; - -/** - * This class is generated by jOOQ. - */ -@Generated(value = { "https://www.jooq.org", - "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class Book extends TableImpl<Record> { - - private static final long serialVersionUID = 1176189796; - - /** - * The reference instance of <code>PUBLIC.BOOK</code> - */ - public static final Book BOOK = new Book(); - - /** - * The class holding records for this type - */ - @Override - public Class<Record> getRecordType() { - return Record.class; - } - - /** - * The column <code>PUBLIC.BOOK.ID</code>. - */ - public final TableField<Record, Integer> ID = createField("ID", - org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); - - /** - * The column <code>PUBLIC.BOOK.AUTHOR_ID</code>. - */ - public final TableField<Record, Integer> AUTHOR_ID = createField("AUTHOR_ID", - org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); - - /** - * The column <code>PUBLIC.BOOK.TITLE</code>. - */ - public final TableField<Record, String> TITLE = createField("TITLE", - org.jooq.impl.SQLDataType.VARCHAR.length(400).nullable(false), this, ""); - - /** - * The column <code>PUBLIC.BOOK.PUBLISHED_IN</code>. - */ - public final TableField<Record, Integer> PUBLISHED_IN = createField("PUBLISHED_IN", - org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); - - /** - * The column <code>PUBLIC.BOOK.LANGUAGE_ID</code>. - */ - public final TableField<Record, Integer> LANGUAGE_ID = createField("LANGUAGE_ID", - org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); - - /** - * Create a <code>PUBLIC.BOOK</code> table reference - */ - public Book() { - this("BOOK", null); - } - - /** - * Create an aliased <code>PUBLIC.BOOK</code> table reference - */ - public Book(String alias) { - this(alias, BOOK); - } - - private Book(String alias, Table<Record> aliased) { - this(alias, aliased, null); - } - - private Book(String alias, Table<Record> aliased, Field<?>[] parameters) { - super(alias, null, aliased, parameters, ""); - } - - /** - * {@inheritDoc} - */ - @Override - public Schema getSchema() { - return Public.PUBLIC; - } - - /** - * {@inheritDoc} - */ - @Override - public UniqueKey<Record> getPrimaryKey() { - return Keys.CONSTRAINT_1; - } - - /** - * {@inheritDoc} - */ - @Override - public List<UniqueKey<Record>> getKeys() { - return Arrays.<UniqueKey<Record>>asList(Keys.CONSTRAINT_1); - } - - /** - * {@inheritDoc} - */ - @Override - public List<ForeignKey<Record, ?>> getReferences() { - return Arrays.<ForeignKey<Record, ?>>asList(Keys.FK_BOOK_AUTHOR, - Keys.FK_BOOK_LANGUAGE); - } - - /** - * {@inheritDoc} - */ - @Override - public Book as(String alias) { - return new Book(alias, this); - } - - /** - * Rename this table - */ - @Override - public Book rename(String name) { - return new Book(name, null); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/BookStore.java b/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/BookStore.java deleted file mode 100644 index 3142dd6258..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/BookStore.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * This class is generated by jOOQ - */ -package sample.jooq.domain; - -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Generated; - -import org.jooq.Field; -import org.jooq.Record; -import org.jooq.Schema; -import org.jooq.Table; -import org.jooq.TableField; -import org.jooq.UniqueKey; -import org.jooq.impl.TableImpl; - -/** - * This class is generated by jOOQ. - */ -@Generated(value = { "https://www.jooq.org", - "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class BookStore extends TableImpl<Record> { - - private static final long serialVersionUID = -2132596210; - - /** - * The reference instance of <code>PUBLIC.BOOK_STORE</code> - */ - public static final BookStore BOOK_STORE = new BookStore(); - - /** - * The class holding records for this type - */ - @Override - public Class<Record> getRecordType() { - return Record.class; - } - - /** - * The column <code>PUBLIC.BOOK_STORE.NAME</code>. - */ - public final TableField<Record, String> NAME = createField("NAME", - org.jooq.impl.SQLDataType.VARCHAR.length(400).nullable(false), this, ""); - - /** - * Create a <code>PUBLIC.BOOK_STORE</code> table reference - */ - public BookStore() { - this("BOOK_STORE", null); - } - - /** - * Create an aliased <code>PUBLIC.BOOK_STORE</code> table reference - */ - public BookStore(String alias) { - this(alias, BOOK_STORE); - } - - private BookStore(String alias, Table<Record> aliased) { - this(alias, aliased, null); - } - - private BookStore(String alias, Table<Record> aliased, Field<?>[] parameters) { - super(alias, null, aliased, parameters, ""); - } - - /** - * {@inheritDoc} - */ - @Override - public Schema getSchema() { - return Public.PUBLIC; - } - - /** - * {@inheritDoc} - */ - @Override - public List<UniqueKey<Record>> getKeys() { - return Arrays.<UniqueKey<Record>>asList(Keys.CONSTRAINT_F); - } - - /** - * {@inheritDoc} - */ - @Override - public BookStore as(String alias) { - return new BookStore(alias, this); - } - - /** - * Rename this table - */ - @Override - public BookStore rename(String name) { - return new BookStore(name, null); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/BookToBookStore.java b/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/BookToBookStore.java deleted file mode 100644 index 4a06446441..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/BookToBookStore.java +++ /dev/null @@ -1,132 +0,0 @@ -/** - * This class is generated by jOOQ - */ -package sample.jooq.domain; - -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Generated; - -import org.jooq.Field; -import org.jooq.ForeignKey; -import org.jooq.Record; -import org.jooq.Schema; -import org.jooq.Table; -import org.jooq.TableField; -import org.jooq.UniqueKey; -import org.jooq.impl.TableImpl; - -/** - * This class is generated by jOOQ. - */ -@Generated(value = { "https://www.jooq.org", - "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class BookToBookStore extends TableImpl<Record> { - - private static final long serialVersionUID = -1360744633; - - /** - * The reference instance of <code>PUBLIC.BOOK_TO_BOOK_STORE</code> - */ - public static final BookToBookStore BOOK_TO_BOOK_STORE = new BookToBookStore(); - - /** - * The class holding records for this type - */ - @Override - public Class<Record> getRecordType() { - return Record.class; - } - - /** - * The column <code>PUBLIC.BOOK_TO_BOOK_STORE.NAME</code>. - */ - public final TableField<Record, String> NAME = createField("NAME", - org.jooq.impl.SQLDataType.VARCHAR.length(400).nullable(false), this, ""); - - /** - * The column <code>PUBLIC.BOOK_TO_BOOK_STORE.BOOK_ID</code>. - */ - public final TableField<Record, Integer> BOOK_ID = createField("BOOK_ID", - org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); - - /** - * The column <code>PUBLIC.BOOK_TO_BOOK_STORE.STOCK</code>. - */ - public final TableField<Record, Integer> STOCK = createField("STOCK", - org.jooq.impl.SQLDataType.INTEGER, this, ""); - - /** - * Create a <code>PUBLIC.BOOK_TO_BOOK_STORE</code> table reference - */ - public BookToBookStore() { - this("BOOK_TO_BOOK_STORE", null); - } - - /** - * Create an aliased <code>PUBLIC.BOOK_TO_BOOK_STORE</code> table reference - */ - public BookToBookStore(String alias) { - this(alias, BOOK_TO_BOOK_STORE); - } - - private BookToBookStore(String alias, Table<Record> aliased) { - this(alias, aliased, null); - } - - private BookToBookStore(String alias, Table<Record> aliased, Field<?>[] parameters) { - super(alias, null, aliased, parameters, ""); - } - - /** - * {@inheritDoc} - */ - @Override - public Schema getSchema() { - return Public.PUBLIC; - } - - /** - * {@inheritDoc} - */ - @Override - public UniqueKey<Record> getPrimaryKey() { - return Keys.CONSTRAINT_2; - } - - /** - * {@inheritDoc} - */ - @Override - public List<UniqueKey<Record>> getKeys() { - return Arrays.<UniqueKey<Record>>asList(Keys.CONSTRAINT_2); - } - - /** - * {@inheritDoc} - */ - @Override - public List<ForeignKey<Record, ?>> getReferences() { - return Arrays.<ForeignKey<Record, ?>>asList(Keys.FK_B2BS_BOOK_STORE, - Keys.FK_B2BS_BOOK); - } - - /** - * {@inheritDoc} - */ - @Override - public BookToBookStore as(String alias) { - return new BookToBookStore(alias, this); - } - - /** - * Rename this table - */ - @Override - public BookToBookStore rename(String name) { - return new BookToBookStore(name, null); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/DefaultCatalog.java b/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/DefaultCatalog.java deleted file mode 100644 index daac4d0c13..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/DefaultCatalog.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * This class is generated by jOOQ - */ -package sample.jooq.domain; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Generated; - -import org.jooq.Schema; -import org.jooq.impl.CatalogImpl; - -/** - * This class is generated by jOOQ. - */ -@Generated(value = { "https://www.jooq.org", - "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class DefaultCatalog extends CatalogImpl { - - private static final long serialVersionUID = -1557925562; - - /** - * The reference instance of <code></code> - */ - public static final DefaultCatalog DEFAULT_CATALOG = new DefaultCatalog(); - - /** - * The schema <code>PUBLIC</code>. - */ - public final Public PUBLIC = sample.jooq.domain.Public.PUBLIC; - - /** - * No further instances allowed - */ - private DefaultCatalog() { - super(""); - } - - @Override - public final List<Schema> getSchemas() { - List result = new ArrayList(); - result.addAll(getSchemas0()); - return result; - } - - private final List<Schema> getSchemas0() { - return Arrays.<Schema>asList(Public.PUBLIC); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Keys.java b/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Keys.java deleted file mode 100644 index 7bbdfdef91..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Keys.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * This class is generated by jOOQ - */ -package sample.jooq.domain; - -import javax.annotation.Generated; - -import org.jooq.ForeignKey; -import org.jooq.Record; -import org.jooq.UniqueKey; -import org.jooq.impl.AbstractKeys; - -/** - * A class modelling foreign key relationships between tables of the <code>PUBLIC</code> - * schema - */ -@Generated(value = { "https://www.jooq.org", - "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class Keys { - - // ------------------------------------------------------------------------- - // IDENTITY definitions - // ------------------------------------------------------------------------- - - // ------------------------------------------------------------------------- - // UNIQUE and PRIMARY KEY definitions - // ------------------------------------------------------------------------- - - public static final UniqueKey<Record> CONSTRAINT_C = UniqueKeys0.CONSTRAINT_C; - - public static final UniqueKey<Record> CONSTRAINT_7 = UniqueKeys0.CONSTRAINT_7; - - public static final UniqueKey<Record> CONSTRAINT_1 = UniqueKeys0.CONSTRAINT_1; - - public static final UniqueKey<Record> CONSTRAINT_F = UniqueKeys0.CONSTRAINT_F; - - public static final UniqueKey<Record> CONSTRAINT_2 = UniqueKeys0.CONSTRAINT_2; - - // ------------------------------------------------------------------------- - // FOREIGN KEY definitions - // ------------------------------------------------------------------------- - - public static final ForeignKey<Record, Record> FK_BOOK_AUTHOR = ForeignKeys0.FK_BOOK_AUTHOR; - - public static final ForeignKey<Record, Record> FK_BOOK_LANGUAGE = ForeignKeys0.FK_BOOK_LANGUAGE; - - public static final ForeignKey<Record, Record> FK_B2BS_BOOK_STORE = ForeignKeys0.FK_B2BS_BOOK_STORE; - - public static final ForeignKey<Record, Record> FK_B2BS_BOOK = ForeignKeys0.FK_B2BS_BOOK; - - // ------------------------------------------------------------------------- - // [#1459] distribute members to avoid static initialisers > 64kb - // ------------------------------------------------------------------------- - - private static class UniqueKeys0 extends AbstractKeys { - - public static final UniqueKey<Record> CONSTRAINT_C = createUniqueKey( - Language.LANGUAGE, "CONSTRAINT_C", Language.LANGUAGE.ID); - - public static final UniqueKey<Record> CONSTRAINT_7 = createUniqueKey( - Author.AUTHOR, "CONSTRAINT_7", Author.AUTHOR.ID); - - public static final UniqueKey<Record> CONSTRAINT_1 = createUniqueKey(Book.BOOK, - "CONSTRAINT_1", Book.BOOK.ID); - - public static final UniqueKey<Record> CONSTRAINT_F = createUniqueKey( - BookStore.BOOK_STORE, "CONSTRAINT_F", BookStore.BOOK_STORE.NAME); - - public static final UniqueKey<Record> CONSTRAINT_2 = createUniqueKey( - BookToBookStore.BOOK_TO_BOOK_STORE, "CONSTRAINT_2", - BookToBookStore.BOOK_TO_BOOK_STORE.NAME, - BookToBookStore.BOOK_TO_BOOK_STORE.BOOK_ID); - - } - - private static class ForeignKeys0 extends AbstractKeys { - - public static final ForeignKey<Record, Record> FK_BOOK_AUTHOR = createForeignKey( - sample.jooq.domain.Keys.CONSTRAINT_7, Book.BOOK, "FK_BOOK_AUTHOR", - Book.BOOK.AUTHOR_ID); - - public static final ForeignKey<Record, Record> FK_BOOK_LANGUAGE = createForeignKey( - sample.jooq.domain.Keys.CONSTRAINT_C, Book.BOOK, "FK_BOOK_LANGUAGE", - Book.BOOK.LANGUAGE_ID); - - public static final ForeignKey<Record, Record> FK_B2BS_BOOK_STORE = createForeignKey( - sample.jooq.domain.Keys.CONSTRAINT_F, BookToBookStore.BOOK_TO_BOOK_STORE, - "FK_B2BS_BOOK_STORE", BookToBookStore.BOOK_TO_BOOK_STORE.NAME); - - public static final ForeignKey<Record, Record> FK_B2BS_BOOK = createForeignKey( - sample.jooq.domain.Keys.CONSTRAINT_1, BookToBookStore.BOOK_TO_BOOK_STORE, - "FK_B2BS_BOOK", BookToBookStore.BOOK_TO_BOOK_STORE.BOOK_ID); - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Language.java b/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Language.java deleted file mode 100644 index ea1aad175d..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Language.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * This class is generated by jOOQ - */ -package sample.jooq.domain; - -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Generated; - -import org.jooq.Field; -import org.jooq.Record; -import org.jooq.Schema; -import org.jooq.Table; -import org.jooq.TableField; -import org.jooq.UniqueKey; -import org.jooq.impl.TableImpl; - -/** - * This class is generated by jOOQ. - */ -@Generated(value = { "https://www.jooq.org", - "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class Language extends TableImpl<Record> { - - private static final long serialVersionUID = -1890716744; - - /** - * The reference instance of <code>PUBLIC.LANGUAGE</code> - */ - public static final Language LANGUAGE = new Language(); - - /** - * The class holding records for this type - */ - @Override - public Class<Record> getRecordType() { - return Record.class; - } - - /** - * The column <code>PUBLIC.LANGUAGE.ID</code>. - */ - public final TableField<Record, Integer> ID = createField("ID", - org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); - - /** - * The column <code>PUBLIC.LANGUAGE.CD</code>. - */ - public final TableField<Record, String> CD = createField("CD", - org.jooq.impl.SQLDataType.CHAR.length(2).nullable(false), this, ""); - - /** - * The column <code>PUBLIC.LANGUAGE.DESCRIPTION</code>. - */ - public final TableField<Record, String> DESCRIPTION = createField("DESCRIPTION", - org.jooq.impl.SQLDataType.VARCHAR.length(50), this, ""); - - /** - * Create a <code>PUBLIC.LANGUAGE</code> table reference - */ - public Language() { - this("LANGUAGE", null); - } - - /** - * Create an aliased <code>PUBLIC.LANGUAGE</code> table reference - */ - public Language(String alias) { - this(alias, LANGUAGE); - } - - private Language(String alias, Table<Record> aliased) { - this(alias, aliased, null); - } - - private Language(String alias, Table<Record> aliased, Field<?>[] parameters) { - super(alias, null, aliased, parameters, ""); - } - - /** - * {@inheritDoc} - */ - @Override - public Schema getSchema() { - return Public.PUBLIC; - } - - /** - * {@inheritDoc} - */ - @Override - public UniqueKey<Record> getPrimaryKey() { - return Keys.CONSTRAINT_C; - } - - /** - * {@inheritDoc} - */ - @Override - public List<UniqueKey<Record>> getKeys() { - return Arrays.<UniqueKey<Record>>asList(Keys.CONSTRAINT_C); - } - - /** - * {@inheritDoc} - */ - @Override - public Language as(String alias) { - return new Language(alias, this); - } - - /** - * Rename this table - */ - @Override - public Language rename(String name) { - return new Language(name, null); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Public.java b/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Public.java deleted file mode 100644 index 16cfbe951c..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Public.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * This class is generated by jOOQ - */ -package sample.jooq.domain; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Generated; - -import org.jooq.Catalog; -import org.jooq.Table; -import org.jooq.impl.SchemaImpl; - -/** - * This class is generated by jOOQ. - */ -@Generated(value = { "https://www.jooq.org", - "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class Public extends SchemaImpl { - - private static final long serialVersionUID = 217498103; - - /** - * The reference instance of <code>PUBLIC</code> - */ - public static final Public PUBLIC = new Public(); - - /** - * The table <code>PUBLIC.LANGUAGE</code>. - */ - public final Language LANGUAGE = sample.jooq.domain.Language.LANGUAGE; - - /** - * The table <code>PUBLIC.AUTHOR</code>. - */ - public final Author AUTHOR = sample.jooq.domain.Author.AUTHOR; - - /** - * The table <code>PUBLIC.BOOK</code>. - */ - public final Book BOOK = sample.jooq.domain.Book.BOOK; - - /** - * The table <code>PUBLIC.BOOK_STORE</code>. - */ - public final BookStore BOOK_STORE = sample.jooq.domain.BookStore.BOOK_STORE; - - /** - * The table <code>PUBLIC.BOOK_TO_BOOK_STORE</code>. - */ - public final BookToBookStore BOOK_TO_BOOK_STORE = sample.jooq.domain.BookToBookStore.BOOK_TO_BOOK_STORE; - - /** - * No further instances allowed - */ - private Public() { - super("PUBLIC", null); - } - - /** - * {@inheritDoc} - */ - @Override - public Catalog getCatalog() { - return DefaultCatalog.DEFAULT_CATALOG; - } - - @Override - public final List<Table<?>> getTables() { - List result = new ArrayList(); - result.addAll(getTables0()); - return result; - } - - private final List<Table<?>> getTables0() { - return Arrays.<Table<?>>asList(Language.LANGUAGE, Author.AUTHOR, Book.BOOK, - BookStore.BOOK_STORE, BookToBookStore.BOOK_TO_BOOK_STORE); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Tables.java b/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Tables.java deleted file mode 100644 index e40f288ce8..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/gensrc/main/java/sample/jooq/domain/Tables.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * This class is generated by jOOQ - */ -package sample.jooq.domain; - -import javax.annotation.Generated; - -/** - * Convenience access to all tables in PUBLIC - */ -@Generated(value = { "https://www.jooq.org", - "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") -@SuppressWarnings({ "all", "unchecked", "rawtypes" }) -public class Tables { - - /** - * The table <code>PUBLIC.LANGUAGE</code>. - */ - public static final Language LANGUAGE = sample.jooq.domain.Language.LANGUAGE; - - /** - * The table <code>PUBLIC.AUTHOR</code>. - */ - public static final Author AUTHOR = sample.jooq.domain.Author.AUTHOR; - - /** - * The table <code>PUBLIC.BOOK</code>. - */ - public static final Book BOOK = sample.jooq.domain.Book.BOOK; - - /** - * The table <code>PUBLIC.BOOK_STORE</code>. - */ - public static final BookStore BOOK_STORE = sample.jooq.domain.BookStore.BOOK_STORE; - - /** - * The table <code>PUBLIC.BOOK_TO_BOOK_STORE</code>. - */ - public static final BookToBookStore BOOK_TO_BOOK_STORE = sample.jooq.domain.BookToBookStore.BOOK_TO_BOOK_STORE; - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/pom.xml b/spring-boot-samples/spring-boot-sample-jooq/pom.xml deleted file mode 100644 index 2f60fb8efb..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/pom.xml +++ /dev/null @@ -1,199 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-jooq</artifactId> - <name>Spring Boot jOOQ Sample</name> - <description>Spring Boot jOOQ Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jooq</artifactId> - </dependency> - <!-- Runtime --> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>runtime</scope> - </dependency> - <!-- Provided --> - <dependency> - <groupId>org.jooq</groupId> - <artifactId>jooq-codegen</artifactId> - <scope>provided</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <executions> - <execution> - <phase>generate-sources</phase> - <goals> - <goal>add-source</goal> - </goals> - <configuration> - <sources> - <source>gensrc/main/java</source> - </sources> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - <pluginManagement> - <plugins> - <!--This plugin's configuration is used to store Eclipse m2e settings - only. It has no influence on the Maven build itself. --> - <plugin> - <groupId>org.eclipse.m2e</groupId> - <artifactId>lifecycle-mapping</artifactId> - <version>1.0.0</version> - <configuration> - <lifecycleMappingMetadata> - <pluginExecutions> - <pluginExecution> - <pluginExecutionFilter> - <groupId>org.jooq</groupId> - <artifactId> - jooq-codegen-maven - </artifactId> - <versionRange> - [3.6.2,) - </versionRange> - <goals> - <goal>generate</goal> - </goals> - </pluginExecutionFilter> - <action> - <ignore /> - </action> - </pluginExecution> - </pluginExecutions> - </lifecycleMappingMetadata> - </configuration> - </plugin> - </plugins> - </pluginManagement> - </build> - <profiles> - <profile> - <id>generate</id> - <build> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <executions> - <execution> - <id>generate-jooq-utils</id> - <phase>generate-sources</phase> - <goals> - <goal>compile</goal> - </goals> - <inherited>false</inherited> - <configuration> - <includes> - <include>sample/jooq/util/**</include> - </includes> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>sql-maven-plugin</artifactId> - <version>1.5</version> - <executions> - <execution> - <phase>generate-sources</phase> - <goals> - <goal>execute</goal> - </goals> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <version>${h2.version}</version> - </dependency> - </dependencies> - <configuration> - <driver>org.h2.Driver</driver> - <url>jdbc:h2:~/springbootjooq</url> - <srcFiles> - <srcFile>${basedir}/src/main/resources/reset.sql</srcFile> - <srcFile>${basedir}/src/main/resources/schema.sql</srcFile> - </srcFiles> - </configuration> - </plugin> - <plugin> - <groupId>org.jooq</groupId> - <artifactId>jooq-codegen-maven</artifactId> - <executions> - <execution> - <goals> - <goal>generate</goal> - </goals> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <version>${h2.version}</version> - </dependency> - </dependencies> - <configuration> - <jdbc> - <driver>org.h2.Driver</driver> - <url>jdbc:h2:~/springbootjooq</url> - </jdbc> - <generator> - <name>org.jooq.util.DefaultGenerator</name> - <database> - <name>org.jooq.util.h2.H2Database</name> - <includes>.*</includes> - <excludes /> - <inputSchema>PUBLIC</inputSchema> - </database> - <strategy> - <name>sample.jooq.util.TangleFreeGeneratorStrategy</name> - </strategy> - <target> - <packageName>sample.jooq.domain</packageName> - <directory>${basedir}/gensrc/main/java</directory> - </target> - <generate> - <records>false</records> - </generate> - </generator> - </configuration> - </plugin> - </plugins> - </build> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/JooqExamples.java b/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/JooqExamples.java deleted file mode 100644 index 68f5819820..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/JooqExamples.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jooq; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; - -import org.jooq.DSLContext; -import org.jooq.Query; -import org.jooq.Record; -import org.jooq.Result; - -import org.springframework.boot.CommandLineRunner; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.stereotype.Component; - -import static sample.jooq.domain.Author.AUTHOR; -import static sample.jooq.domain.Book.BOOK; - -@Component -public class JooqExamples implements CommandLineRunner { - - private final DSLContext dsl; - - private final JdbcTemplate jdbc; - - public JooqExamples(DSLContext dsl, JdbcTemplate jdbc) { - this.dsl = dsl; - this.jdbc = jdbc; - } - - @Override - public void run(String... args) throws Exception { - jooqFetch(); - jooqSql(); - } - - private void jooqFetch() { - Result<Record> results = this.dsl.select().from(AUTHOR).fetch(); - for (Record result : results) { - Integer id = result.getValue(AUTHOR.ID); - String firstName = result.getValue(AUTHOR.FIRST_NAME); - String lastName = result.getValue(AUTHOR.LAST_NAME); - System.out.println("jOOQ Fetch " + id + " " + firstName + " " + lastName); - } - } - - private void jooqSql() { - Query query = this.dsl.select(BOOK.TITLE, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME).from(BOOK).join(AUTHOR) - .on(BOOK.AUTHOR_ID.equal(AUTHOR.ID)).where(BOOK.PUBLISHED_IN.equal(2015)); - Object[] bind = query.getBindValues().toArray(new Object[0]); - List<String> list = this.jdbc.query(query.getSQL(), bind, new RowMapper<String>() { - @Override - public String mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getString(1) + " : " + rs.getString(2) + " " + rs.getString(3); - } - }); - System.out.println("jOOQ SQL " + list); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/SampleJooqApplication.java b/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/SampleJooqApplication.java deleted file mode 100644 index aaa64f6a8c..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/SampleJooqApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jooq; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleJooqApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleJooqApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/util/TangleFreeGeneratorStrategy.java b/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/util/TangleFreeGeneratorStrategy.java deleted file mode 100644 index 93692cd341..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/util/TangleFreeGeneratorStrategy.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jooq.util; - -import org.jooq.codegen.DefaultGeneratorStrategy; -import org.jooq.meta.Definition; - -/** - * Custom {@link DefaultGeneratorStrategy} that doesn't produce tangled packages. Too - * simple for general use but solves false flags for our build. - */ -public class TangleFreeGeneratorStrategy extends DefaultGeneratorStrategy { - - @Override - public String getJavaPackageName(Definition definition, Mode mode) { - return getTargetPackage(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java b/spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java deleted file mode 100644 index a01e65d156..0000000000 --- a/spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jooq; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for {@link SampleJooqApplication}. - */ -@ExtendWith(OutputCaptureExtension.class) -class SampleJooqApplicationTests { - - private static final String[] NO_ARGS = {}; - - @Test - void outputResults(CapturedOutput capturedOutput) { - SampleJooqApplication.main(NO_ARGS); - assertThat(capturedOutput).contains("jOOQ Fetch 1 Greg Turnquest").contains("jOOQ Fetch 2 Craig Walls") - .contains("jOOQ SQL " + "[Learning Spring Boot : Greg Turnquest, " - + "Spring Boot in Action : Craig Walls]"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jpa/pom.xml b/spring-boot-samples/spring-boot-sample-jpa/pom.xml deleted file mode 100644 index 52a80207a1..0000000000 --- a/spring-boot-samples/spring-boot-sample-jpa/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-jpa</artifactId> - <name>Spring Boot JPA Sample</name> - <description>Spring Boot JPA Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>jakarta.persistence</groupId> - <artifactId>jakarta.persistence-api</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-freemarker</artifactId> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-orm</artifactId> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-core</artifactId> - <exclusions> - <exclusion> - <groupId>javax.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - </exclusion> - <exclusion> - <groupId>javax.persistence</groupId> - <artifactId>javax.persistence-api</artifactId> - </exclusion> - <exclusion> - <groupId>javax.activation</groupId> - <artifactId>javax.activation-api</artifactId> - </exclusion> - </exclusions> - </dependency> - <!-- Runtime --> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>runtime</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>java9+</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <dependencies> - <dependency> - <groupId>jakarta.xml.bind</groupId> - <artifactId>jakarta.xml.bind-api</artifactId> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/SampleJpaApplication.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/SampleJpaApplication.java deleted file mode 100644 index e397ffade5..0000000000 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/SampleJpaApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jpa; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleJpaApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleJpaApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.java deleted file mode 100644 index f9c1a8e147..0000000000 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jpa.domain; - -import java.util.List; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToMany; -import javax.persistence.SequenceGenerator; - -@Entity -public class Note { - - @Id - @SequenceGenerator(name = "note_generator", sequenceName = "note_sequence", initialValue = 5) - @GeneratedValue(generator = "note_generator") - private long id; - - private String title; - - private String body; - - @ManyToMany - private List<Tag> tags; - - public long getId() { - return this.id; - } - - public void setId(long id) { - this.id = id; - } - - public String getTitle() { - return this.title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getBody() { - return this.body; - } - - public void setBody(String body) { - this.body = body; - } - - public List<Tag> getTags() { - return this.tags; - } - - public void setTags(List<Tag> tags) { - this.tags = tags; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Tag.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Tag.java deleted file mode 100644 index 09c5673408..0000000000 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Tag.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jpa.domain; - -import java.util.List; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToMany; -import javax.persistence.SequenceGenerator; - -@Entity -public class Tag { - - @Id - @SequenceGenerator(name = "tag_generator", sequenceName = "tag_sequence", initialValue = 4) - @GeneratedValue(generator = "tag_generator") - private long id; - - private String name; - - @ManyToMany(mappedBy = "tags") - private List<Note> notes; - - public long getId() { - return this.id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public List<Note> getNotes() { - return this.notes; - } - - public void setNotes(List<Note> notes) { - this.notes = notes; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaNoteRepository.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaNoteRepository.java deleted file mode 100644 index f530dd0997..0000000000 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaNoteRepository.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jpa.repository; - -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; - -import sample.jpa.domain.Note; - -import org.springframework.stereotype.Repository; - -@Repository -class JpaNoteRepository implements NoteRepository { - - @PersistenceContext - private EntityManager entityManager; - - @Override - public List<Note> findAll() { - return this.entityManager.createQuery("SELECT n FROM Note n", Note.class).getResultList(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaTagRepository.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaTagRepository.java deleted file mode 100644 index 4fbcd3d43c..0000000000 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/JpaTagRepository.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jpa.repository; - -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; - -import sample.jpa.domain.Tag; - -import org.springframework.stereotype.Repository; - -@Repository -class JpaTagRepository implements TagRepository { - - @PersistenceContext - private EntityManager entityManager; - - @Override - public List<Tag> findAll() { - return this.entityManager.createQuery("SELECT t FROM Tag t", Tag.class).getResultList(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/NoteRepository.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/NoteRepository.java deleted file mode 100644 index a161bb90be..0000000000 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/NoteRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jpa.repository; - -import java.util.List; - -import sample.jpa.domain.Note; - -public interface NoteRepository { - - List<Note> findAll(); - -} diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/TagRepository.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/TagRepository.java deleted file mode 100644 index d2dd652a7d..0000000000 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/repository/TagRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jpa.repository; - -import java.util.List; - -import sample.jpa.domain.Tag; - -public interface TagRepository { - - List<Tag> findAll(); - -} diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/web/IndexController.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/web/IndexController.java deleted file mode 100644 index bf3162eef8..0000000000 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/web/IndexController.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jpa.web; - -import java.util.List; - -import sample.jpa.domain.Note; -import sample.jpa.repository.NoteRepository; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.servlet.ModelAndView; - -@Controller -public class IndexController { - - @Autowired - private NoteRepository noteRepository; - - @GetMapping("/") - @Transactional(readOnly = true) - public ModelAndView index() { - List<Note> notes = this.noteRepository.findAll(); - ModelAndView modelAndView = new ModelAndView("index"); - modelAndView.addObject("notes", notes); - return modelAndView; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/SampleJpaApplicationTests.java b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/SampleJpaApplicationTests.java deleted file mode 100644 index 585b615a79..0000000000 --- a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/SampleJpaApplicationTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jpa; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.xpath; - -/** - * Integration test to run the application. - * - * @author Oliver Gierke - * @author Dave Syer - */ -@SpringBootTest -@WebAppConfiguration -class SampleJpaApplicationTests { - - @Autowired - private WebApplicationContext context; - - private MockMvc mvc; - - @BeforeEach - void setUp() { - this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); - } - - @Test - void testHome() throws Exception { - this.mvc.perform(get("/")).andExpect(status().isOk()).andExpect(xpath("//tbody/tr").nodeCount(4)); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java deleted file mode 100644 index cf2f7ae33c..0000000000 --- a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.jpa.repository; - -import java.util.List; - -import org.junit.jupiter.api.Test; -import sample.jpa.domain.Note; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for {@link JpaNoteRepository}. - * - * @author Andy Wilkinson - */ -@SpringBootTest -@Transactional -class JpaNoteRepositoryIntegrationTests { - - @Autowired - JpaNoteRepository repository; - - @Test - void findsAllNotes() { - List<Note> notes = this.repository.findAll(); - assertThat(notes).hasSize(4); - for (Note note : notes) { - assertThat(note.getTags().size()).isGreaterThan(0); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java deleted file mode 100644 index 79075112b4..0000000000 --- a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.jpa.repository; - -import java.util.List; - -import org.junit.jupiter.api.Test; -import sample.jpa.domain.Tag; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for {@link JpaTagRepository}. - * - * @author Andy Wilkinson - */ -@SpringBootTest -@Transactional -class JpaTagRepositoryIntegrationTests { - - @Autowired - JpaTagRepository repository; - - @Test - void findsAllTags() { - List<Tag> tags = this.repository.findAll(); - assertThat(tags).hasSize(3); - for (Tag tag : tags) { - assertThat(tag.getNotes().size()).isGreaterThan(0); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-atomikos/pom.xml b/spring-boot-samples/spring-boot-sample-jta-atomikos/pom.xml deleted file mode 100644 index 29083a2865..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-atomikos/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-jta-atomikos</artifactId> - <name>Spring Boot Atomikos JTA Sample</name> - <description>Spring Boot Atomikos JTA Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jms</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jta-atomikos</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-artemis</artifactId> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-jms-server</artifactId> - <exclusions> - <exclusion> - <artifactId>geronimo-jms_2.0_spec</artifactId> - <groupId>org.apache.geronimo.specs</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>java9+</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <dependencies> - <dependency> - <groupId>jakarta.xml.bind</groupId> - <artifactId>jakarta.xml.bind-api</artifactId> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/Account.java b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/Account.java deleted file mode 100644 index 4221ebc44c..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/Account.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.atomikos; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity -public class Account { - - @Id - @GeneratedValue - private Long id; - - private String username; - - Account() { - } - - public Account(String username) { - this.username = username; - } - - public String getUsername() { - return this.username; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/AccountRepository.java b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/AccountRepository.java deleted file mode 100644 index bbd8734424..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/AccountRepository.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.atomikos; - -import org.springframework.data.jpa.repository.JpaRepository; - -public interface AccountRepository extends JpaRepository<Account, Long> { - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/AccountService.java b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/AccountService.java deleted file mode 100644 index 6cb4fc7202..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/AccountService.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.atomikos; - -import javax.transaction.Transactional; - -import org.springframework.jms.core.JmsTemplate; -import org.springframework.stereotype.Service; - -@Service -@Transactional -public class AccountService { - - private final JmsTemplate jmsTemplate; - - private final AccountRepository accountRepository; - - public AccountService(JmsTemplate jmsTemplate, AccountRepository accountRepository) { - this.jmsTemplate = jmsTemplate; - this.accountRepository = accountRepository; - } - - public void createAccountAndNotify(String username) { - this.jmsTemplate.convertAndSend("accounts", username); - this.accountRepository.save(new Account(username)); - if ("error".equals(username)) { - throw new RuntimeException("Simulated error"); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/Messages.java b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/Messages.java deleted file mode 100644 index 1b461c720d..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/Messages.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.atomikos; - -import org.springframework.jms.annotation.JmsListener; -import org.springframework.stereotype.Component; - -@Component -public class Messages { - - @JmsListener(destination = "accounts") - public void onMessage(String content) { - System.out.println("----> " + content); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/SampleAtomikosApplication.java b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/SampleAtomikosApplication.java deleted file mode 100644 index 29518952d8..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/java/sample/atomikos/SampleAtomikosApplication.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.atomikos; - -import java.io.Closeable; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.ApplicationContext; - -@SpringBootApplication -public class SampleAtomikosApplication { - - public static void main(String[] args) throws Exception { - ApplicationContext context = SpringApplication.run(SampleAtomikosApplication.class, args); - AccountService service = context.getBean(AccountService.class); - AccountRepository repository = context.getBean(AccountRepository.class); - service.createAccountAndNotify("josh"); - System.out.println("Count is " + repository.count()); - try { - service.createAccountAndNotify("error"); - } - catch (Exception ex) { - System.out.println(ex.getMessage()); - } - System.out.println("Count is " + repository.count()); - Thread.sleep(100); - ((Closeable) context).close(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java deleted file mode 100644 index 5cf3d2517b..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.atomikos; - -import org.assertj.core.api.Condition; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Phillip Webb - */ -@ExtendWith(OutputCaptureExtension.class) -class SampleAtomikosApplicationTests { - - @Test - void testTransactionRollback(CapturedOutput capturedOutput) throws Exception { - SampleAtomikosApplication.main(new String[] {}); - assertThat(capturedOutput.toString()).has(substring(1, "---->")).has(substring(1, "----> josh")) - .has(substring(2, "Count is 1")).has(substring(1, "Simulated error")); - } - - private Condition<String> substring(int times, String substring) { - return new Condition<String>("containing '" + substring + "' " + times + " times") { - - @Override - public boolean matches(String value) { - int i = 0; - while (value.contains(substring)) { - int beginIndex = value.indexOf(substring) + substring.length(); - value = value.substring(beginIndex); - i++; - } - return i == times; - } - - }; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-bitronix/pom.xml b/spring-boot-samples/spring-boot-sample-jta-bitronix/pom.xml deleted file mode 100644 index 40749be5de..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-bitronix/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-jta-bitronix</artifactId> - <name>Spring Boot Bitronix JTA Sample</name> - <description>Spring Boot Bitronix JTA Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jms</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jta-bitronix</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-artemis</artifactId> - </dependency> - <dependency> - <groupId>org.apache.activemq</groupId> - <artifactId>artemis-jms-server</artifactId> - <exclusions> - <exclusion> - <artifactId>geronimo-jms_2.0_spec</artifactId> - <groupId>org.apache.geronimo.specs</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>java9+</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <dependencies> - <dependency> - <groupId>jakarta.xml.bind</groupId> - <artifactId>jakarta.xml.bind-api</artifactId> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/Account.java b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/Account.java deleted file mode 100644 index 407f3b836b..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/Account.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.bitronix; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity -public class Account { - - @Id - @GeneratedValue - private Long id; - - private String username; - - Account() { - } - - public Account(String username) { - this.username = username; - } - - public String getUsername() { - return this.username; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/AccountRepository.java b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/AccountRepository.java deleted file mode 100644 index c8d899712f..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/AccountRepository.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.bitronix; - -import org.springframework.data.jpa.repository.JpaRepository; - -public interface AccountRepository extends JpaRepository<Account, Long> { - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/AccountService.java b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/AccountService.java deleted file mode 100644 index d56814d18c..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/AccountService.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.bitronix; - -import javax.transaction.Transactional; - -import org.springframework.jms.core.JmsTemplate; -import org.springframework.stereotype.Service; - -@Service -@Transactional -public class AccountService { - - private final JmsTemplate jmsTemplate; - - private final AccountRepository accountRepository; - - public AccountService(JmsTemplate jmsTemplate, AccountRepository accountRepository) { - this.jmsTemplate = jmsTemplate; - this.accountRepository = accountRepository; - } - - public void createAccountAndNotify(String username) { - this.jmsTemplate.convertAndSend("accounts", username); - this.accountRepository.save(new Account(username)); - if ("error".equals(username)) { - throw new RuntimeException("Simulated error"); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/Messages.java b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/Messages.java deleted file mode 100644 index 21d82c908d..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/Messages.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.bitronix; - -import org.springframework.jms.annotation.JmsListener; -import org.springframework.stereotype.Component; - -@Component -public class Messages { - - @JmsListener(destination = "accounts") - public void onMessage(String content) { - System.out.println("----> " + content); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/SampleBitronixApplication.java b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/SampleBitronixApplication.java deleted file mode 100644 index dfa42e8064..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/java/sample/bitronix/SampleBitronixApplication.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.bitronix; - -import java.io.Closeable; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.ApplicationContext; - -@SpringBootApplication -public class SampleBitronixApplication { - - public static void main(String[] args) throws Exception { - ApplicationContext context = SpringApplication.run(SampleBitronixApplication.class, args); - AccountService service = context.getBean(AccountService.class); - AccountRepository repository = context.getBean(AccountRepository.class); - service.createAccountAndNotify("josh"); - System.out.println("Count is " + repository.count()); - try { - service.createAccountAndNotify("error"); - } - catch (Exception ex) { - System.out.println(ex.getMessage()); - } - System.out.println("Count is " + repository.count()); - Thread.sleep(100); - ((Closeable) context).close(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java deleted file mode 100644 index fd77e2a278..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.bitronix; - -import bitronix.tm.resource.jms.PoolingConnectionFactory; -import org.assertj.core.api.Condition; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; -import org.springframework.context.ApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Phillip Webb - */ -@ExtendWith(OutputCaptureExtension.class) -class SampleBitronixApplicationTests { - - @Test - void testTransactionRollback(CapturedOutput capturedOutput) throws Exception { - SampleBitronixApplication.main(new String[] {}); - assertThat(capturedOutput.toString()).has(substring(1, "---->")).has(substring(1, "----> josh")) - .has(substring(2, "Count is 1")).has(substring(1, "Simulated error")); - } - - @Test - void testExposesXaAndNonXa() { - ApplicationContext context = SpringApplication.run(SampleBitronixApplication.class); - Object jmsConnectionFactory = context.getBean("jmsConnectionFactory"); - Object xaJmsConnectionFactory = context.getBean("xaJmsConnectionFactory"); - Object nonXaJmsConnectionFactory = context.getBean("nonXaJmsConnectionFactory"); - assertThat(jmsConnectionFactory).isSameAs(xaJmsConnectionFactory); - assertThat(jmsConnectionFactory).isInstanceOf(PoolingConnectionFactory.class); - assertThat(nonXaJmsConnectionFactory).isNotInstanceOf(PoolingConnectionFactory.class); - } - - private Condition<String> substring(int times, String substring) { - return new Condition<String>("containing '" + substring + "' " + times + " times") { - - @Override - public boolean matches(String value) { - int i = 0; - while (value.contains(substring)) { - int beginIndex = value.indexOf(substring) + substring.length(); - value = value.substring(beginIndex); - i++; - } - return i == times; - } - - }; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-jndi/README.adoc b/spring-boot-samples/spring-boot-sample-jta-jndi/README.adoc deleted file mode 100644 index f415a5540f..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-jndi/README.adoc +++ /dev/null @@ -1,148 +0,0 @@ -## Introduction - -This application is intended to run inside of a Java EE application server such as -JBoss Wildfly. It demonstrates Spring Boot's auto-configuration defaulting for a -container-managed `TransactionManager` and `DataSource`. This example unfortunately -requires a fully configured Wildfly installation. You'll need to configure a PostgreSQL -XA `DataSource` and an XA `ConnectionFactory` in the Java EE application server's -JNDI machinery. - -## Setup - -### Postgres -We will use postgres as the underlying database, v9.3.5 or above is recommend. Follow -the installation instructions from https://www.postgresql.org/[postgresql.org] or use -a package manager to install the appropriate binaries. - -Once installed you will need to initialize and start the server. - -[source,indent=0] ----- - $ initdb /usr/local/var/postgres -E utf8 - $ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start ----- - -With the server running you can create a user and a database: - -[source,indent=0] ----- - $ createuser springboot - $ createdb bootdemo ----- - -Finally you can type `psql bootdemo` to configure a password: - -[source,indent=0] ----- - ALTER USER springboot WITH PASSWORD 'springboot'; - \q ----- - - -### WildFly 8.1 -Download an install WildFly 8.1 from https://wildfly.org/downloads/[wildfly.org]. Once -installed you will need to add a management user by running `$JBOSS_HOME/bin/add-user.sh` -(see the WildFly documentation for details). - -You will also need to add a postgresql module. The following commands setup the basic -structure: - -[source,indent=0] ----- - $ cd $JBOSS_HOME - mkdir -p modules/org/postgresql/main - wget https://jdbc.postgresql.org/download/postgresql-9.3-1102.jdbc41.jar - mv postgresql-9.3-1102.jdbc41.jar modules/org/postgresql/main ----- - -You can then add the following to `$JBOSS_HOME/modules/org/postgresql/main/module.xml`: - -[source,indent=0] ----- - <?xml version="1.0" encoding="UTF-8"?> - <module xmlns="urn:jboss:module:1.0" name="org.postgresql"> - <resources> - <resource-root path="postgresql-9.3-1102.jdbc41.jar"/> - </resources> - <dependencies> - <module name="javax.api"/> - <module name="javax.transaction.api"/> - </dependencies> - </module> ----- - -## Configuration -A custom WildFly configuration is required for the XA `DataSource` and `ConnectionFactory` -elements. The `$JBOSS_HOME/standalone/configuration/standalone-full.xml` is a good -starting point, copy this file to -`$JBOSS_HOME/standalone/configuration/standalone-boot-demo.xml` then make the following -changes. - -### DataSource -You need to register a PostgreSQL XA `Driver` and then configure an `xa-datasource`. - -Here's a complete listing of the `xa-datasource` contribution to the `datasources` -element, and the `driver` contribution to the `drivers` element to configure a PostgreSQL -DB connection to localhost. -https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6/html-single/Administration_and_Configuration_Guide/index.html#Install_a_JDBC_Driver_with_the_Management_Console[You can learn more from the documentation]. - -[source,xml,indent=0,subs="verbatim,attributes"] ----- - <datasources> - ... - <xa-datasource - jndi-name="java:jboss/datasources/bootdemo" - pool-name="CrmXADS" - enabled="true"> - <xa-datasource-property name="url">jdbc:postgresql://localhost:5432/crm</xa-datasource-property> - <driver>postgres</driver> - <xa-pool> - <min-pool-size>10</min-pool-size> - <max-pool-size>20</max-pool-size> - <prefill>true</prefill> - </xa-pool> - <security> - <user-name>springboot</user-name> - <password>springboot</password> - </security> - </xa-datasource> - <drivers> - ... - <driver name="postgres" module="org.postgresql"> - <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class> - </driver> - </drivers> - </datasources> ----- - -### JMS Destination -You will also need to configure a `javax.jms.Destination` by contributing the following to -the `hornetq-server` element: - -[source,xml,indent=0,subs="verbatim,attributes"] ----- - <jms-destinations> - <jms-queue name="accounts"> - <entry name="java:/jms/queue/bootdemo"/> - </jms-queue> - ... - </jms-destinations> ----- - - -## Running and deploying the sample -Run Wildfly with the following command: - -[source,indent=0] ----- - $JBOSS_HOME/bin/standalone.sh -c standalone-boot-demo.xml ----- - -Once running you can deploy the application by copying -`target/spring-boot-sample-jta-jndi.war` to `$JBOSS_HOME/standalone/deployments`. - -Open a browser to http://localhost:8080/spring-boot-sample-jta-jndi to trigger the -sample. You should see the current count (it will increment by one on each refresh). If -you check the logs you should see a `----> Josh` message and some counts. Notice how the -`error` message triggers an exception with causes both the database insert and the JMS -message to be rolled back. diff --git a/spring-boot-samples/spring-boot-sample-jta-jndi/pom.xml b/spring-boot-samples/spring-boot-sample-jta-jndi/pom.xml deleted file mode 100644 index 20659984f2..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-jndi/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-jta-jndi</artifactId> - <name>Spring Boot JNDI JTA Sample</name> - <packaging>war</packaging> - <description>Spring Boot JNDI JTA Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jms</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </exclusion> - </exclusions> - </dependency> - <!-- Provided --> - <dependency> - <groupId>jakarta.servlet</groupId> - <artifactId>jakarta.servlet-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>jakarta.jms</groupId> - <artifactId>jakarta.jms-api</artifactId> - <scope>provided</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <finalName>spring-boot-sample-jta-jndi</finalName> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/Account.java b/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/Account.java deleted file mode 100644 index 8b9a42d448..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/Account.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jndi; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity -public class Account { - - @Id - @GeneratedValue - private Long id; - - private String username; - - Account() { - } - - public Account(String username) { - this.username = username; - } - - public String getUsername() { - return this.username; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/AccountRepository.java b/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/AccountRepository.java deleted file mode 100644 index 08b458a80d..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/AccountRepository.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jndi; - -import org.springframework.data.repository.CrudRepository; - -public interface AccountRepository extends CrudRepository<Account, Long> { - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/AccountService.java b/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/AccountService.java deleted file mode 100644 index f2ad414982..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/AccountService.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jndi; - -import org.springframework.jms.core.JmsTemplate; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@Transactional -public class AccountService { - - private final JmsTemplate jmsTemplate; - - private final AccountRepository accountRepository; - - public AccountService(JmsTemplate jmsTemplate, AccountRepository accountRepository) { - this.jmsTemplate = jmsTemplate; - this.accountRepository = accountRepository; - } - - public void createAccountAndNotify(String username) { - this.jmsTemplate.convertAndSend("java:/jms/queue/bootdemo", username); - Account entity = new Account(username); - this.accountRepository.save(entity); - if ("error".equals(username)) { - throw new RuntimeException("Simulated error"); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/Messages.java b/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/Messages.java deleted file mode 100644 index 640f667d5d..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/Messages.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jndi; - -import org.springframework.jms.annotation.JmsListener; -import org.springframework.stereotype.Component; - -@Component -public class Messages { - - @JmsListener(destination = "java:/jms/queue/bootdemo") - public void onMessage(String content) { - System.out.println("----> " + content); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/SampleJndiApplication.java b/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/SampleJndiApplication.java deleted file mode 100644 index 4583094085..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/SampleJndiApplication.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jndi; - -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleJndiApplication { - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/SampleJndiInitializer.java b/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/SampleJndiInitializer.java deleted file mode 100644 index c43faa31c1..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/SampleJndiInitializer.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jndi; - -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; - -public class SampleJndiInitializer extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleJndiApplication.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/WebController.java b/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/WebController.java deleted file mode 100644 index f83d9aee5e..0000000000 --- a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/java/sample/jndi/WebController.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jndi; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class WebController { - - private final AccountService service; - - private final AccountRepository repository; - - public WebController(AccountService service, AccountRepository repository) { - this.service = service; - this.repository = repository; - } - - @GetMapping("/") - public String hello() { - System.out.println("Count is " + this.repository.count()); - this.service.createAccountAndNotify("josh"); - try { - this.service.createAccountAndNotify("error"); - } - catch (Exception ex) { - System.out.println(ex.getMessage()); - } - long count = this.repository.count(); - System.out.println("Count is " + count); - return "Count is " + count; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-junit-jupiter/pom.xml b/spring-boot-samples/spring-boot-sample-junit-jupiter/pom.xml deleted file mode 100644 index 15eb042064..0000000000 --- a/spring-boot-samples/spring-boot-sample-junit-jupiter/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-junit-jupiter</artifactId> - <name>Spring Boot JUnit Jupiter Sample</name> - <description>Spring Boot JUnit Jupiter Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>org.junit.vintage</groupId> - <artifactId>junit-vintage-engine</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/MessageController.java b/spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/MessageController.java deleted file mode 100644 index 6e24d3d3ae..0000000000 --- a/spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/MessageController.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class MessageController { - - @GetMapping("/hi") - public String hello() { - return "Hello World"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/SampleJUnitJupiterApplication.java b/spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/SampleJUnitJupiterApplication.java deleted file mode 100644 index 725ce5dc07..0000000000 --- a/spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/SampleJUnitJupiterApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleJUnitJupiterApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleJUnitJupiterApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-junit-jupiter/src/test/java/sample/SampleJUnitJupiterApplicationTests.java b/spring-boot-samples/spring-boot-sample-junit-jupiter/src/test/java/sample/SampleJUnitJupiterApplicationTests.java deleted file mode 100644 index d115e5275b..0000000000 --- a/spring-boot-samples/spring-boot-sample-junit-jupiter/src/test/java/sample/SampleJUnitJupiterApplicationTests.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleJUnitJupiterApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testMessage() { - String message = this.restTemplate.getForObject("/hi", String.class); - assertThat(message).isEqualTo("Hello World"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-junit-vintage/pom.xml b/spring-boot-samples/spring-boot-sample-junit-vintage/pom.xml deleted file mode 100644 index d245eb7bfa..0000000000 --- a/spring-boot-samples/spring-boot-sample-junit-vintage/pom.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-junit-vintage</artifactId> - <name>Spring Boot JUnit Vintage Sample</name> - <description>Spring Boot JUnit Vintage Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> -</project> diff --git a/spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/MessageController.java b/spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/MessageController.java deleted file mode 100644 index f46482e8e4..0000000000 --- a/spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/MessageController.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -class MessageController { - - @GetMapping("/hi") - public String hello() { - return "Hello World"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/SampleJUnitVintageApplication.java b/spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/SampleJUnitVintageApplication.java deleted file mode 100644 index 2257815c58..0000000000 --- a/spring-boot-samples/spring-boot-sample-junit-vintage/src/main/java/sample/SampleJUnitVintageApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleJUnitVintageApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleJUnitVintageApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-junit-vintage/src/test/java/sample/SampleJUnitVintageApplicationTests.java b/spring-boot-samples/spring-boot-sample-junit-vintage/src/test/java/sample/SampleJUnitVintageApplicationTests.java deleted file mode 100644 index dec352a463..0000000000 --- a/spring-boot-samples/spring-boot-sample-junit-vintage/src/test/java/sample/SampleJUnitVintageApplicationTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; - -@RunWith(SpringRunner.class) -@WebMvcTest -public class SampleJUnitVintageApplicationTests { - - @Autowired - private MockMvc mockMvc; - - @Test - public void testMessage() throws Exception { - this.mockMvc.perform(get("/hi")).andExpect(content().string("Hello World")); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-kafka/pom.xml b/spring-boot-samples/spring-boot-sample-kafka/pom.xml deleted file mode 100644 index e10ff6a2d6..0000000000 --- a/spring-boot-samples/spring-boot-sample-kafka/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <artifactId>spring-boot-samples</artifactId> - <groupId>org.springframework.boot</groupId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-kafka</artifactId> - <name>Spring Boot Kafka Sample</name> - <description>Spring Boot Kafka Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-json</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.kafka</groupId> - <artifactId>spring-kafka</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework.kafka</groupId> - <artifactId>spring-kafka-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/Consumer.java b/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/Consumer.java deleted file mode 100644 index ee45b10da1..0000000000 --- a/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/Consumer.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.kafka; - -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.springframework.kafka.annotation.KafkaListener; -import org.springframework.stereotype.Component; - -@Component -class Consumer { - - private final List<SampleMessage> messages = new CopyOnWriteArrayList<>(); - - @KafkaListener(topics = "testTopic") - public void processMessage(SampleMessage message) { - this.messages.add(message); - System.out.println("Received sample message [" + message + "]"); - } - - List<SampleMessage> getMessages() { - return this.messages; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/Producer.java b/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/Producer.java deleted file mode 100644 index aa127544cb..0000000000 --- a/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/Producer.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.kafka; - -import org.springframework.kafka.core.KafkaTemplate; -import org.springframework.stereotype.Component; - -@Component -public class Producer { - - private final KafkaTemplate<Object, SampleMessage> kafkaTemplate; - - Producer(KafkaTemplate<Object, SampleMessage> kafkaTemplate) { - this.kafkaTemplate = kafkaTemplate; - } - - public void send(SampleMessage message) { - this.kafkaTemplate.send("testTopic", message); - System.out.println("Sent sample message [" + message + "]"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleKafkaApplication.java b/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleKafkaApplication.java deleted file mode 100644 index 6cce2bb4ea..0000000000 --- a/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleKafkaApplication.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.kafka; - -import org.apache.kafka.clients.admin.NewTopic; - -import org.springframework.boot.ApplicationRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -public class SampleKafkaApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleKafkaApplication.class, args); - } - - @Bean - public NewTopic kafkaTestTopic() { - return new NewTopic("testTopic", 10, (short) 2); - } - - @Bean - public ApplicationRunner runner(Producer producer) { - return (args) -> producer.send(new SampleMessage(1, "A simple test message")); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleMessage.java b/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleMessage.java deleted file mode 100644 index bd6cf687e8..0000000000 --- a/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleMessage.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.kafka; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class SampleMessage { - - private final Integer id; - - private final String message; - - @JsonCreator - public SampleMessage(@JsonProperty("id") Integer id, @JsonProperty("message") String message) { - this.id = id; - this.message = message; - } - - public Integer getId() { - return this.id; - } - - public String getMessage() { - return this.message; - } - - @Override - public String toString() { - return "SampleMessage{id=" + this.id + ", message='" + this.message + "'}"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-kafka/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-kafka/src/main/resources/application.properties deleted file mode 100644 index 60839de6f4..0000000000 --- a/spring-boot-samples/spring-boot-sample-kafka/src/main/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.kafka.bootstrap-servers=localhost:9092 -spring.kafka.consumer.group-id=testGroup -spring.kafka.consumer.auto-offset-reset=earliest -spring.kafka.consumer.value-deserializer=org.springframework.kafka.support.serializer.JsonDeserializer -spring.kafka.consumer.properties.spring.json.trusted.packages=sample.kafka -spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer diff --git a/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java b/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java deleted file mode 100644 index a55d8aedf4..0000000000 --- a/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.kafka; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.kafka.test.context.EmbeddedKafka; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for demo application. - * - * @author hcxin - * @author Gary Russell - * @author Stephane Nicoll - */ -@SpringBootTest(properties = "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}") -@EmbeddedKafka(topics = "testTopic") -class SampleKafkaApplicationTests { - - @Autowired - private Consumer consumer; - - @Test - void testVanillaExchange() throws Exception { - long end = System.currentTimeMillis() + 10000; - while (this.consumer.getMessages().isEmpty() && System.currentTimeMillis() < end) { - Thread.sleep(250); - } - assertThat(this.consumer.getMessages()).extracting("message").containsOnly("A simple test message"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-liquibase/README.adoc b/spring-boot-samples/spring-boot-sample-liquibase/README.adoc deleted file mode 100644 index 23b5fbc074..0000000000 --- a/spring-boot-samples/spring-boot-sample-liquibase/README.adoc +++ /dev/null @@ -1,10 +0,0 @@ -== Spring Boot Liquibase Sample - -This sample demonstrates the liquibase auto-configuration support. - -You can look at `http://localhost:8080/actuator/liquibase` to review the list of -scripts. - -This sample also enables the H2 console (at `http://localhost:8080/h2-console`) -so that you can review the state of the database (the default jdbc url is -`jdbc:h2:mem:testdb`). diff --git a/spring-boot-samples/spring-boot-sample-liquibase/pom.xml b/spring-boot-samples/spring-boot-sample-liquibase/pom.xml deleted file mode 100644 index 0344d13556..0000000000 --- a/spring-boot-samples/spring-boot-sample-liquibase/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-liquibase</artifactId> - <name>Spring Boot Liquibase Sample</name> - <description>Spring Boot Liquibase Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jdbc</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> - <dependency> - <groupId>org.liquibase</groupId> - <artifactId>liquibase-core</artifactId> - </dependency> - <!-- Runtime --> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>runtime</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-liquibase/src/main/java/sample/liquibase/SampleLiquibaseApplication.java b/spring-boot-samples/spring-boot-sample-liquibase/src/main/java/sample/liquibase/SampleLiquibaseApplication.java deleted file mode 100644 index 60bb8061e9..0000000000 --- a/spring-boot-samples/spring-boot-sample-liquibase/src/main/java/sample/liquibase/SampleLiquibaseApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.liquibase; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleLiquibaseApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleLiquibaseApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java b/spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java deleted file mode 100644 index 1198fe10fc..0000000000 --- a/spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.liquibase; - -import java.net.ConnectException; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; -import org.springframework.core.NestedCheckedException; - -import static org.assertj.core.api.Assertions.assertThat; - -@ExtendWith(OutputCaptureExtension.class) -class SampleLiquibaseApplicationTests { - - @Test - void testDefaultSettings(CapturedOutput capturedOutput) throws Exception { - try { - SampleLiquibaseApplication.main(new String[] { "--server.port=0" }); - } - catch (IllegalStateException ex) { - if (serverNotRunning(ex)) { - return; - } - } - assertThat(capturedOutput).contains("Successfully acquired change log lock") - .contains("Creating database history " + "table with name: PUBLIC.DATABASECHANGELOG") - .contains("Table person created") - .contains("ChangeSet classpath:/db/" + "changelog/db.changelog-master.yaml::1::" - + "marceloverdijk ran successfully") - .contains("New row inserted into person").contains("ChangeSet classpath:/db/changelog/" - + "db.changelog-master.yaml::2::" + "marceloverdijk ran successfully") - .contains("Successfully released change log lock"); - } - - @SuppressWarnings("serial") - private boolean serverNotRunning(IllegalStateException ex) { - NestedCheckedException nested = new NestedCheckedException("failed", ex) { - }; - if (nested.contains(ConnectException.class)) { - Throwable root = nested.getRootCause(); - if (root.getMessage().contains("Connection refused")) { - return true; - } - } - return false; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-logback/pom.xml b/spring-boot-samples/spring-boot-sample-logback/pom.xml deleted file mode 100644 index aa04723265..0000000000 --- a/spring-boot-samples/spring-boot-sample-logback/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-logback</artifactId> - <name>Spring Boot Logback Sample</name> - <description>Spring Boot Logback Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-logback/src/main/java/sample/logback/SampleLogbackApplication.java b/spring-boot-samples/spring-boot-sample-logback/src/main/java/sample/logback/SampleLogbackApplication.java deleted file mode 100644 index bc24bc3ca1..0000000000 --- a/spring-boot-samples/spring-boot-sample-logback/src/main/java/sample/logback/SampleLogbackApplication.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.logback; - -import javax.annotation.PostConstruct; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleLogbackApplication { - - private static final Logger logger = LoggerFactory.getLogger(SampleLogbackApplication.class); - - @PostConstruct - public void logSomething() { - logger.debug("Sample Debug Message"); - logger.trace("Sample Trace Message"); - } - - public static void main(String[] args) { - SpringApplication.run(SampleLogbackApplication.class, args).close(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-logback/src/main/resources/logback-spring.xml b/spring-boot-samples/spring-boot-sample-logback/src/main/resources/logback-spring.xml deleted file mode 100644 index e279b82276..0000000000 --- a/spring-boot-samples/spring-boot-sample-logback/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<configuration> - <include resource="org/springframework/boot/logging/logback/base.xml" /> - <logger name="sample.logback" level="DEBUG" /> - <springProfile name="staging"> - <logger name="sample.logback" level="TRACE" /> - </springProfile> -</configuration> diff --git a/spring-boot-samples/spring-boot-sample-logback/src/test/java/sample/logback/SampleLogbackApplicationTests.java b/spring-boot-samples/spring-boot-sample-logback/src/test/java/sample/logback/SampleLogbackApplicationTests.java deleted file mode 100644 index 1682d2d4ff..0000000000 --- a/spring-boot-samples/spring-boot-sample-logback/src/test/java/sample/logback/SampleLogbackApplicationTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.logback; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -@ExtendWith(OutputCaptureExtension.class) -class SampleLogbackApplicationTests { - - @Test - void testLoadedCustomLogbackConfig(CapturedOutput capturedOutput) throws Exception { - SampleLogbackApplication.main(new String[0]); - assertThat(capturedOutput).contains("Sample Debug Message").doesNotContain("Sample Trace Message"); - } - - @Test - void testProfile(CapturedOutput capturedOutput) throws Exception { - SampleLogbackApplication.main(new String[] { "--spring.profiles.active=staging" }); - assertThat(capturedOutput).contains("Sample Debug Message").contains("Sample Trace Message"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-oauth2-client/README.adoc b/spring-boot-samples/spring-boot-sample-oauth2-client/README.adoc deleted file mode 100644 index 8da6508883..0000000000 --- a/spring-boot-samples/spring-boot-sample-oauth2-client/README.adoc +++ /dev/null @@ -1,12 +0,0 @@ -= Spring Boot Sample OAuth2 Client - -== Register Github OAuth2 application -To run the sample, you need to link:https://github.com/settings/applications/new[register an OAuth application on Github]. -While registering your application, ensure the Authorization callback URL is set to http://localhost:8080/login/oauth2/code/github. -After completing the registration, you will have a new OAuth Application with a Client ID and Client Secret. - -== Configuring application.yml -Once the OAuth application is registered with GitHub, you need to configure the sample application to use this OAuth application (client). -Edit the link:src/main/resources/application.yml[application.yml] and replace ${APP-CLIENT-ID} and ${APP-CLIENT-SECRET} with the OAuth client credentials created in the previous section. - -The sample can now be run and you can login with your Github user credentials. diff --git a/spring-boot-samples/spring-boot-sample-oauth2-client/pom.xml b/spring-boot-samples/spring-boot-sample-oauth2-client/pom.xml deleted file mode 100644 index 1ba73519d1..0000000000 --- a/spring-boot-samples/spring-boot-sample-oauth2-client/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-oauth2-client</artifactId> - <name>Spring Boot Sample OAuth2 Client</name> - <description>Spring Boot Sample OAuth2 Client</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-oauth2-client</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-oauth2-client/src/main/java/sample/oauth2/client/ExampleController.java b/spring-boot-samples/spring-boot-sample-oauth2-client/src/main/java/sample/oauth2/client/ExampleController.java deleted file mode 100644 index c6976e191f..0000000000 --- a/spring-boot-samples/spring-boot-sample-oauth2-client/src/main/java/sample/oauth2/client/ExampleController.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.oauth2.client; - -import java.security.Principal; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class ExampleController { - - @RequestMapping("/") - public String email(Principal principal) { - return "Hello " + principal.getName(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-oauth2-client/src/main/java/sample/oauth2/client/SampleOAuth2ClientApplication.java b/spring-boot-samples/spring-boot-sample-oauth2-client/src/main/java/sample/oauth2/client/SampleOAuth2ClientApplication.java deleted file mode 100644 index 7aea0299d3..0000000000 --- a/spring-boot-samples/spring-boot-sample-oauth2-client/src/main/java/sample/oauth2/client/SampleOAuth2ClientApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.oauth2.client; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleOAuth2ClientApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleOAuth2ClientApplication.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java b/spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java deleted file mode 100644 index ff0bc01989..0000000000 --- a/spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.oauth2.client; - -import java.net.URI; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = { "APP-CLIENT-ID=my-client-id", "APP-CLIENT-SECRET=my-client-secret", - "YAHOO-CLIENT-ID=my-yahoo-client-id", "YAHOO-CLIENT-SECRET=my-yahoo-client-secret" }) -class SampleOAuth2ClientApplicationTests { - - @LocalServerPort - private int port; - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void everythingShouldRedirectToLogin() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation()).isEqualTo(URI.create("http://localhost:" + this.port + "/login")); - } - - @Test - void loginShouldHaveAllOAuth2ClientsToChooseFrom() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/login", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("/oauth2/authorization/yahoo"); - assertThat(entity.getBody()).contains("/oauth2/authorization/github-client-1"); - assertThat(entity.getBody()).contains("/oauth2/authorization/github-client-2"); - assertThat(entity.getBody()).contains("/oauth2/authorization/github-repos"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-oauth2-resource-server/pom.xml b/spring-boot-samples/spring-boot-sample-oauth2-resource-server/pom.xml deleted file mode 100644 index 4a21741555..0000000000 --- a/spring-boot-samples/spring-boot-sample-oauth2-resource-server/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-oauth2-resource-server</artifactId> - <name>Spring Boot Sample OAuth2 Resource Server</name> - <description>Spring Boot Sample Resource Server</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-oauth2-resource-server</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>com.squareup.okhttp3</groupId> - <artifactId>mockwebserver</artifactId> - <version>3.9.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/main/java/sample/oauth2/resource/ExampleController.java b/spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/main/java/sample/oauth2/resource/ExampleController.java deleted file mode 100644 index 7c197f60cb..0000000000 --- a/spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/main/java/sample/oauth2/resource/ExampleController.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.oauth2.resource; - -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.security.oauth2.jwt.Jwt; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class ExampleController { - - @GetMapping("/") - public String index(@AuthenticationPrincipal Jwt jwt) { - return String.format("Hello, %s!", jwt.getSubject()); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/main/java/sample/oauth2/resource/SampleOauth2ResourceServerApplication.java b/spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/main/java/sample/oauth2/resource/SampleOauth2ResourceServerApplication.java deleted file mode 100644 index c7a9ea1e6d..0000000000 --- a/spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/main/java/sample/oauth2/resource/SampleOauth2ResourceServerApplication.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.oauth2.resource; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleOauth2ResourceServerApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleOauth2ResourceServerApplication.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/test/java/sample/oauth2/resource/SampleOauth2ResourceServerApplicationTests.java b/spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/test/java/sample/oauth2/resource/SampleOauth2ResourceServerApplicationTests.java deleted file mode 100644 index 68a22a463c..0000000000 --- a/spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/test/java/sample/oauth2/resource/SampleOauth2ResourceServerApplicationTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.oauth2.resource; - -import java.io.IOException; - -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class SampleOauth2ResourceServerApplicationTests { - - private static MockWebServer server = new MockWebServer(); - - private static final String VALID_TOKEN = "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0Iiwic2NvcGUiOiJtZXNzYWdlOnJlYWQi" - + "LCJleHAiOjQ2ODM4MDUxNDF9.h-j6FKRFdnTdmAueTZCdep45e6DPwqM68ZQ8doIJ1exi9YxAlbWzOwId6Bd0L5YmCmp63gGQgsBUBLzwnZQ8kLUgU" - + "OBEC3UzSWGRqMskCY9_k9pX0iomX6IfF3N0PaYs0WPC4hO1s8wfZQ-6hKQ4KigFi13G9LMLdH58PRMK0pKEvs3gCbHJuEPw-K5ORlpdnleUTQIwIN" - + "afU57cmK3KocTeknPAM_L716sCuSYGvDl6xUTXO7oPdrXhS_EhxLP6KxrpI1uD4Ea_5OWTh7S0Wx5LLDfU6wBG1DowN20d374zepOIEkR-Jnmr_Ql" - + "R44vmRqS5ncrF-1R0EGcPX49U6A"; - - @Autowired - private TestRestTemplate restTemplate; - - @BeforeAll - public static void setup() throws Exception { - server.start(); - String url = server.url("/.well-known/jwks.json").toString(); - server.enqueue(mockResponse()); - System.setProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri", url); - } - - @AfterAll - public static void shutdown() throws IOException { - server.shutdown(); - System.clearProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri"); - } - - @Test - void withValidBearerTokenShouldAllowAccess() { - HttpHeaders headers = new HttpHeaders(); - headers.setBearerAuth(VALID_TOKEN); - HttpEntity<?> request = new HttpEntity<Void>(headers); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, request, String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - } - - @Test - void withNoBearerTokenShouldNotAllowAccess() { - HttpHeaders headers = new HttpHeaders(); - HttpEntity<?> request = new HttpEntity<Void>(headers); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, request, String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - private static MockResponse mockResponse() { - String body = "{\"keys\":[{\"p\":\"2p-ViY7DE9ZrdWQb544m0Jp7Cv03YCSljqfim9pD4ALhObX0OrAznOiowTjwBky9JGffMw" - + "DBVSfJSD9TSU7aH2sbbfi0bZLMdekKAuimudXwUqPDxrrg0BCyvCYgLmKjbVT3zcdylWSog93CNTxGDPzauu-oc0XPNKCXnaDpNvE\"" - + ",\"kty\":\"RSA\",\"q\":\"sP_QYavrpBvSJ86uoKVGj2AGl78CSsAtpf1ybSY5TwUlorXSdqapRbY69Y271b0aMLzlleUn9ZTBO" - + "1dlKV2_dw_lPADHVia8z3pxL-8sUhIXLsgj4acchMk4c9YX-sFh07xENnyZ-_TXm3llPLuL67HUfBC2eKe800TmCYVWc9U\",\"d\"" - + ":\"bn1nFxCQT4KLTHqo8mo9HvHD0cRNRNdWcKNnnEQkCF6tKbt-ILRyQGP8O40axLd7CoNVG9c9p_-g4-2kwCtLJNv_STLtwfpCY7" - + "VN5o6-ZIpfTjiW6duoPrLWq64Hm_4LOBQTiZfUPcLhsuJRHbWqakj-kV_YbUyC2Ocf_dd8IAQcSrAU2SCcDebhDCWwRUFvaa9V5eq0" - + "851S9goaA-AJz-JXyePH6ZFr8JxmWkWxYZ5kdcMD-sm9ZbxE0CaEk32l4fE4hR-L8x2dDtjWA-ahKCZ091z-gV3HWtR2JOjvxoNRjxUo" - + "3UxaGiFJHWNIl0EYUJZu1Cb-5wIlEI7wPx5mwQ\",\"e\":\"AQAB\",\"use\":\"sig\",\"kid\":\"one\",\"qi\":\"qS0OK4" - + "8M2CIAA6_4Wdw4EbCaAfcTLf5Oy9t5BOF_PFUKqoSpZ6JsT5H0a_4zkjt-oI969v78OTlvBKbmEyKO-KeytzHBAA5CsLmVcz0THrMSg6o" - + "XZqu66MPnvWoZN9FEN5TklPOvBFm8Bg1QZ3k-YMVaM--DLvhaYR95_mqaz50\",\"dp\":\"Too2NozLGD1XrXyhabZvy1E0EuaVFj0UHQ" - + "PDLSpkZ_2g3BK6Art6T0xmE8RYtmqrKIEIdlI3IliAvyvAx_1D7zWTTRaj-xlZyqJFrnXWL7zj8UxT8PkB-r2E-ILZ3NAi1gxIWezlBTZ8" - + "M6NfObDFmbTc_3tJkN_raISo8z_ziIE\",\"dq\":\"U0yhSkY5yOsa9YcMoigGVBWSJLpNHtbg5NypjHrPv8OhWbkOSq7WvSstBkF" - + "k5AtyFvvfZLMLIkWWxxGzV0t6f1MoxBtttLrYYyCxwihiiGFhLbAdSuZ1wnxcqA9bC7UVECvrQmVTpsMs8UupfHKbQBpZ8OWAqrn" - + "uYNNtG4_4Bt0\",\"n\":\"lygtuZj0lJjqOqIWocF8Bb583QDdq-aaFg8PesOp2-EDda6GqCpL-_NZVOflNGX7XIgjsWHcPsQHs" - + "V9gWuOzSJ0iEuWvtQ6eGBP5M6m7pccLNZfwUse8Cb4Ngx3XiTlyuqM7pv0LPyppZusfEHVEdeelou7Dy9k0OQ_nJTI3b2E1WBoHC5" - + "8CJ453lo4gcBm1efURN3LIVc1V9NQY_ESBKVdwqYyoJPEanURLVGRd6cQKn6YrCbbIRHjqAyqOE-z3KmgDJnPriljfR5XhSGyM9eq" - + "D9Xpy6zu_MAeMJJfSArp857zLPk-Wf5VP9STAcjyfdBIybMKnwBYr2qHMT675hQ\"}]}"; - return new MockResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) - .setResponseCode(200).setBody(body); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-parent-context/pom.xml b/spring-boot-samples/spring-boot-sample-parent-context/pom.xml deleted file mode 100644 index 843b4082cb..0000000000 --- a/spring-boot-samples/spring-boot-sample-parent-context/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-parent-context</artifactId> - <name>Spring Boot Parent Context Sample</name> - <description>Spring Boot Parent Context Sample</description> - <properties> - <start-class>sample.parent.SampleParentContextApplication</start-class> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-integration</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.integration</groupId> - <artifactId>spring-integration-file</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/HelloWorldService.java deleted file mode 100644 index a8469b61dd..0000000000 --- a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/HelloWorldService.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.parent; - -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - private final ServiceProperties configuration; - - public HelloWorldService(ServiceProperties configuration) { - this.configuration = configuration; - } - - public String getHelloMessage(String name) { - return this.configuration.getGreeting() + " " + name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleEndpoint.java b/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleEndpoint.java deleted file mode 100644 index 19c7029141..0000000000 --- a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleEndpoint.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.parent; - -import java.io.File; -import java.io.FileInputStream; - -import org.springframework.integration.annotation.MessageEndpoint; -import org.springframework.integration.annotation.ServiceActivator; -import org.springframework.util.StreamUtils; - -@MessageEndpoint -public class SampleEndpoint { - - private final HelloWorldService helloWorldService; - - public SampleEndpoint(HelloWorldService helloWorldService) { - this.helloWorldService = helloWorldService; - } - - @ServiceActivator - public String hello(File input) throws Exception { - FileInputStream in = new FileInputStream(input); - String name = new String(StreamUtils.copyToByteArray(in)); - in.close(); - return this.helloWorldService.getHelloMessage(name); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleParentContextApplication.java b/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleParentContextApplication.java deleted file mode 100644 index 0036b584d5..0000000000 --- a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/SampleParentContextApplication.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.parent; - -import java.util.function.Consumer; - -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.integration.channel.DirectChannel; -import org.springframework.integration.dsl.IntegrationFlow; -import org.springframework.integration.dsl.IntegrationFlows; -import org.springframework.integration.dsl.Pollers; -import org.springframework.integration.dsl.SourcePollingChannelAdapterSpec; -import org.springframework.integration.file.FileReadingMessageSource; -import org.springframework.integration.file.FileWritingMessageHandler; - -@SpringBootApplication -public class SampleParentContextApplication { - - public static void main(String[] args) throws Exception { - new SpringApplicationBuilder(Parent.class).child(SampleParentContextApplication.class).run(args); - } - - @Configuration(proxyBeanMethods = false) - @EnableAutoConfiguration - protected static class Parent { - - private final ServiceProperties serviceProperties; - - public Parent(ServiceProperties serviceProperties) { - this.serviceProperties = serviceProperties; - } - - @Bean - public FileReadingMessageSource fileReader() { - FileReadingMessageSource reader = new FileReadingMessageSource(); - reader.setDirectory(this.serviceProperties.getInputDir()); - return reader; - } - - @Bean - public DirectChannel inputChannel() { - return new DirectChannel(); - } - - @Bean - public DirectChannel outputChannel() { - return new DirectChannel(); - } - - @Bean - public FileWritingMessageHandler fileWriter() { - FileWritingMessageHandler writer = new FileWritingMessageHandler(this.serviceProperties.getOutputDir()); - writer.setExpectReply(false); - return writer; - } - - @Bean - public IntegrationFlow integrationFlow(SampleEndpoint endpoint) { - return IntegrationFlows.from(fileReader(), new FixedRatePoller()).channel(inputChannel()).handle(endpoint) - .channel(outputChannel()).handle(fileWriter()).get(); - } - - private static class FixedRatePoller implements Consumer<SourcePollingChannelAdapterSpec> { - - @Override - public void accept(SourcePollingChannelAdapterSpec spec) { - spec.poller(Pollers.fixedRate(500)); - } - - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/ServiceProperties.java b/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/ServiceProperties.java deleted file mode 100644 index 9e907f2911..0000000000 --- a/spring-boot-samples/spring-boot-sample-parent-context/src/main/java/sample/parent/ServiceProperties.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.parent; - -import java.io.File; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.jmx.export.annotation.ManagedAttribute; -import org.springframework.jmx.export.annotation.ManagedResource; - -@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) -@ManagedResource -public class ServiceProperties { - - private String greeting = "Hello"; - - private File inputDir; - - private File outputDir; - - @ManagedAttribute - public String getGreeting() { - return this.greeting; - } - - public void setGreeting(String greeting) { - this.greeting = greeting; - } - - public File getInputDir() { - return this.inputDir; - } - - public void setInputDir(File inputDir) { - this.inputDir = inputDir; - } - - public File getOutputDir() { - return this.outputDir; - } - - public void setOutputDir(File outputDir) { - this.outputDir = outputDir; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/consumer/SampleIntegrationParentApplicationTests.java b/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/consumer/SampleIntegrationParentApplicationTests.java deleted file mode 100644 index ab80bf749d..0000000000 --- a/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/consumer/SampleIntegrationParentApplicationTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.parent.consumer; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; -import sample.parent.SampleParentContextApplication; -import sample.parent.producer.ProducerApplication; - -import org.springframework.boot.SpringApplication; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.io.DefaultResourceLoader; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.ResourcePatternUtils; -import org.springframework.util.StreamUtils; - -import static org.junit.jupiter.api.Assertions.fail; - -/** - * Basic integration tests for service demo application. - * - * @author Dave Syer - * @author Andy Wilkinson - */ -class SampleIntegrationParentApplicationTests { - - @Test - void testVanillaExchange(@TempDir Path temp) throws Exception { - File inputDir = new File(temp.toFile(), "input"); - File outputDir = new File(temp.toFile(), "output"); - ConfigurableApplicationContext app = SpringApplication.run(SampleParentContextApplication.class, - "--service.input-dir=" + inputDir, "--service.output-dir=" + outputDir); - try { - ConfigurableApplicationContext producer = SpringApplication.run(ProducerApplication.class, - "--service.input-dir=" + inputDir, "--service.output-dir=" + outputDir, "World"); - try { - awaitOutputContaining(outputDir, "Hello World"); - } - finally { - producer.close(); - } - } - finally { - app.close(); - } - } - - private void awaitOutputContaining(File outputDir, String requiredContents) throws Exception { - long endTime = System.currentTimeMillis() + 30000; - String output = null; - while (System.currentTimeMillis() < endTime) { - Resource[] resources = findResources(outputDir); - if (resources.length == 0) { - Thread.sleep(200); - resources = findResources(outputDir); - } - else { - output = readResources(resources); - if (output != null && output.contains(requiredContents)) { - return; - } - else { - Thread.sleep(200); - output = readResources(resources); - } - } - } - fail("Timed out awaiting output containing '" + requiredContents + "'. Output was '" + output + "'"); - } - - private Resource[] findResources(File outputDir) throws IOException { - return ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader()) - .getResources("file:" + outputDir.getAbsolutePath() + "/*.txt"); - } - - private String readResources(Resource[] resources) throws IOException { - StringBuilder builder = new StringBuilder(); - for (Resource resource : resources) { - try (InputStream input = resource.getInputStream()) { - builder.append(new String(StreamUtils.copyToByteArray(input))); - } - } - return builder.toString(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/producer/ProducerApplication.java b/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/producer/ProducerApplication.java deleted file mode 100644 index 245e9b03b8..0000000000 --- a/spring-boot-samples/spring-boot-sample-parent-context/src/test/java/sample/parent/producer/ProducerApplication.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.parent.producer; - -import java.io.File; -import java.io.FileOutputStream; - -import sample.parent.ServiceProperties; - -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration(proxyBeanMethods = false) -@EnableConfigurationProperties(ServiceProperties.class) -public class ProducerApplication implements ApplicationRunner { - - private final ServiceProperties serviceProperties; - - public ProducerApplication(ServiceProperties serviceProperties) { - this.serviceProperties = serviceProperties; - } - - @Override - public void run(ApplicationArguments args) throws Exception { - this.serviceProperties.getInputDir().mkdirs(); - if (args.getNonOptionArgs().size() > 0) { - FileOutputStream stream = new FileOutputStream( - new File(this.serviceProperties.getInputDir(), "data" + System.currentTimeMillis() + ".txt")); - for (String arg : args.getNonOptionArgs()) { - stream.write(arg.getBytes()); - } - stream.flush(); - stream.close(); - } - } - - public static void main(String[] args) { - SpringApplication.run(ProducerApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-profile/pom.xml b/spring-boot-samples/spring-boot-sample-profile/pom.xml deleted file mode 100644 index 0f85b31c29..0000000000 --- a/spring-boot-samples/spring-boot-sample-profile/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-profile</artifactId> - <name>Spring Boot Profile Sample</name> - <description>Spring Boot Profile Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/SampleProfileApplication.java b/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/SampleProfileApplication.java deleted file mode 100644 index 758c532078..0000000000 --- a/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/SampleProfileApplication.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.profile; - -import sample.profile.service.MessageService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleProfileApplication implements CommandLineRunner { - - // Simple example shows how a command line spring application can execute an - // injected bean service. Also demonstrates how you can use @Value to inject - // command line args ('--name=whatever') or application properties - - @Autowired - private MessageService helloWorldService; - - @Override - public void run(String... args) { - System.out.println(this.helloWorldService.getMessage()); - } - - public static void main(String[] args) { - SpringApplication.run(SampleProfileApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/GenericService.java b/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/GenericService.java deleted file mode 100644 index c5bae54e84..0000000000 --- a/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/GenericService.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.profile.service; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; - -@Component -@Profile({ "generic" }) -public class GenericService implements MessageService { - - @Value("${hello:Hello}") - private String hello; - - @Value("${name:World}") - private String name; - - @Override - public String getMessage() { - return this.hello + " " + this.name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/GoodbyeWorldService.java b/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/GoodbyeWorldService.java deleted file mode 100644 index 7af8d8f36b..0000000000 --- a/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/GoodbyeWorldService.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.profile.service; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; - -@Component -@Profile("goodbye") -public class GoodbyeWorldService implements MessageService { - - @Value("${name:World}") - private String name; - - @Override - public String getMessage() { - return "Goodbye " + this.name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/HelloWorldService.java deleted file mode 100644 index a60fecd67f..0000000000 --- a/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/HelloWorldService.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.profile.service; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; - -@Component -@Profile({ "hello", "default" }) -public class HelloWorldService implements MessageService { - - @Value("${name:World}") - private String name; - - @Override - public String getMessage() { - return "Hello " + this.name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/MessageService.java b/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/MessageService.java deleted file mode 100644 index 884202d04a..0000000000 --- a/spring-boot-samples/spring-boot-sample-profile/src/main/java/sample/profile/service/MessageService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.profile.service; - -public interface MessageService { - - String getMessage(); - -} diff --git a/spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java b/spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java deleted file mode 100644 index aafb89bff6..0000000000 --- a/spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.profile; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -@ExtendWith(OutputCaptureExtension.class) -class SampleProfileApplicationTests { - - private String profiles; - - @BeforeEach - void before() { - this.profiles = System.getProperty("spring.profiles.active"); - } - - @AfterEach - void after() { - if (this.profiles != null) { - System.setProperty("spring.profiles.active", this.profiles); - } - else { - System.clearProperty("spring.profiles.active"); - } - } - - @Test - void testDefaultProfile(CapturedOutput capturedOutput) { - SampleProfileApplication.main(new String[0]); - assertThat(capturedOutput).contains("Hello Phil"); - } - - @Test - void testGoodbyeProfile(CapturedOutput capturedOutput) { - System.setProperty("spring.profiles.active", "goodbye"); - SampleProfileApplication.main(new String[0]); - assertThat(capturedOutput).contains("Goodbye Everyone"); - } - - @Test - void testGenericProfile(CapturedOutput capturedOutput) { - /* - * This is a profile that requires a new environment property, and one which is - * only overridden in the current working directory. That file also only contains - * partial overrides, and the default application.yml should still supply the - * "name" property. - */ - System.setProperty("spring.profiles.active", "generic"); - SampleProfileApplication.main(new String[0]); - assertThat(capturedOutput).contains("Bonjour Phil"); - } - - @Test - void testGoodbyeProfileFromCommandline(CapturedOutput capturedOutput) { - SampleProfileApplication.main(new String[] { "--spring.profiles.active=goodbye" }); - assertThat(capturedOutput).contains("Goodbye Everyone"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-property-validation/pom.xml b/spring-boot-samples/spring-boot-sample-property-validation/pom.xml deleted file mode 100644 index 8f1db1b326..0000000000 --- a/spring-boot-samples/spring-boot-sample-property-validation/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-property-validation</artifactId> - <name>Spring Boot Property Validation Sample</name> - <description>Spring Boot Property Validation Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <!-- Optional --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-configuration-processor</artifactId> - <optional>true</optional> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SampleProperties.java b/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SampleProperties.java deleted file mode 100644 index a8f1c31c24..0000000000 --- a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SampleProperties.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.propertyvalidation; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; - -@ConfigurationProperties(prefix = "sample") -@Validated -public class SampleProperties { - - /** - * Sample host. - */ - private String host; - - /** - * Sample port. - */ - private Integer port = 8080; - - public String getHost() { - return this.host; - } - - public void setHost(String host) { - this.host = host; - } - - public Integer getPort() { - return this.port; - } - - public void setPort(Integer port) { - this.port = port; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertiesValidator.java b/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertiesValidator.java deleted file mode 100644 index 277b1a9f13..0000000000 --- a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertiesValidator.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.propertyvalidation; - -import java.util.regex.Pattern; - -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -public class SamplePropertiesValidator implements Validator { - - final Pattern pattern = Pattern.compile("^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$"); - - @Override - public boolean supports(Class<?> type) { - return type == SampleProperties.class; - } - - @Override - public void validate(Object o, Errors errors) { - ValidationUtils.rejectIfEmpty(errors, "host", "host.empty"); - ValidationUtils.rejectIfEmpty(errors, "port", "port.empty"); - SampleProperties properties = (SampleProperties) o; - if (properties.getHost() != null && !this.pattern.matcher(properties.getHost()).matches()) { - errors.rejectValue("host", "Invalid host"); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertyValidationApplication.java b/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertyValidationApplication.java deleted file mode 100644 index 0b45a135a2..0000000000 --- a/spring-boot-samples/spring-boot-sample-property-validation/src/main/java/sample/propertyvalidation/SamplePropertyValidationApplication.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.propertyvalidation; - -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.validation.Validator; - -@SpringBootApplication -public class SamplePropertyValidationApplication implements CommandLineRunner { - - private final SampleProperties properties; - - public SamplePropertyValidationApplication(SampleProperties properties) { - this.properties = properties; - } - - @Bean - public static Validator configurationPropertiesValidator() { - return new SamplePropertiesValidator(); - } - - @Override - public void run(String... args) { - System.out.println("========================================="); - System.out.println("Sample host: " + this.properties.getHost()); - System.out.println("Sample port: " + this.properties.getPort()); - System.out.println("========================================="); - } - - public static void main(String[] args) { - new SpringApplicationBuilder(SamplePropertyValidationApplication.class).run(args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java b/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java deleted file mode 100644 index 400f655e2c..0000000000 --- a/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.propertyvalidation; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.BeanCreationException; -import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.test.util.TestPropertyValues; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - -/** - * Tests for {@link SamplePropertyValidationApplication}. - * - * @author Lucas Saldanha - * @author Stephane Nicoll - */ -class SamplePropertyValidationApplicationTests { - - private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - @AfterEach - void closeContext() { - this.context.close(); - } - - @Test - void bindValidProperties() { - this.context.register(SamplePropertyValidationApplication.class); - TestPropertyValues.of("sample.host:192.168.0.1", "sample.port:9090").applyTo(this.context); - this.context.refresh(); - SampleProperties properties = this.context.getBean(SampleProperties.class); - assertThat(properties.getHost()).isEqualTo("192.168.0.1"); - assertThat(properties.getPort()).isEqualTo(Integer.valueOf(9090)); - } - - @Test - void bindInvalidHost() { - this.context.register(SamplePropertyValidationApplication.class); - TestPropertyValues.of("sample.host:xxxxxx", "sample.port:9090").applyTo(this.context); - assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> this.context.refresh()) - .withMessageContaining("Failed to bind properties under 'sample'"); - } - - @Test - void bindNullHost() { - this.context.register(SamplePropertyValidationApplication.class); - assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> this.context.refresh()) - .withMessageContaining("Failed to bind properties under 'sample'"); - } - - @Test - void validatorOnlyCalledOnSupportedClass() { - this.context.register(SamplePropertyValidationApplication.class); - this.context.register(ServerProperties.class); // our validator will not apply - TestPropertyValues.of("sample.host:192.168.0.1", "sample.port:9090").applyTo(this.context); - this.context.refresh(); - SampleProperties properties = this.context.getBean(SampleProperties.class); - assertThat(properties.getHost()).isEqualTo("192.168.0.1"); - assertThat(properties.getPort()).isEqualTo(Integer.valueOf(9090)); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-quartz/README.adoc b/spring-boot-samples/spring-boot-sample-quartz/README.adoc deleted file mode 100644 index e90a709db9..0000000000 --- a/spring-boot-samples/spring-boot-sample-quartz/README.adoc +++ /dev/null @@ -1,11 +0,0 @@ -== Spring Boot Quartz Sample - -This sample demonstrates the Quartz auto-configuration support. - -The sample uses Maven. It can be built and run from the command line: - ----- -$ mvn spring-boot:run ----- - -Console log will now show "Hello World!" from `SampleJob` every 2 seconds. diff --git a/spring-boot-samples/spring-boot-sample-quartz/pom.xml b/spring-boot-samples/spring-boot-sample-quartz/pom.xml deleted file mode 100644 index 95428ba8e5..0000000000 --- a/spring-boot-samples/spring-boot-sample-quartz/pom.xml +++ /dev/null @@ -1,37 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-quartz</artifactId> - <name>Spring Boot Quartz Sample</name> - <description>Spring Boot Quartz Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-quartz</artifactId> - </dependency> - - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleJob.java b/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleJob.java deleted file mode 100644 index a0449fe9bf..0000000000 --- a/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleJob.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.quartz; - -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; - -import org.springframework.scheduling.quartz.QuartzJobBean; - -public class SampleJob extends QuartzJobBean { - - private String name; - - // Invoked if a Job data map entry with that name - public void setName(String name) { - this.name = name; - } - - @Override - protected void executeInternal(JobExecutionContext context) throws JobExecutionException { - System.out.println(String.format("Hello %s!", this.name)); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleQuartzApplication.java b/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleQuartzApplication.java deleted file mode 100644 index c6300b64f7..0000000000 --- a/spring-boot-samples/spring-boot-sample-quartz/src/main/java/sample/quartz/SampleQuartzApplication.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.quartz; - -import org.quartz.JobBuilder; -import org.quartz.JobDetail; -import org.quartz.SimpleScheduleBuilder; -import org.quartz.Trigger; -import org.quartz.TriggerBuilder; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -public class SampleQuartzApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleQuartzApplication.class, args); - } - - @Bean - public JobDetail sampleJobDetail() { - return JobBuilder.newJob(SampleJob.class).withIdentity("sampleJob").usingJobData("name", "World").storeDurably() - .build(); - } - - @Bean - public Trigger sampleJobTrigger() { - SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(2) - .repeatForever(); - - return TriggerBuilder.newTrigger().forJob(sampleJobDetail()).withIdentity("sampleTrigger") - .withSchedule(scheduleBuilder).build(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java b/spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java deleted file mode 100644 index 9ca0a44681..0000000000 --- a/spring-boot-samples/spring-boot-sample-quartz/src/test/java/sample/quartz/SampleQuartzApplicationTests.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.quartz; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; -import org.springframework.context.ConfigurableApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SampleQuartzApplication}. - * - * @author Eddú Meléndez - */ -@ExtendWith(OutputCaptureExtension.class) -class SampleQuartzApplicationTests { - - @Test - void quartzJobIsTriggered(CapturedOutput capturedOutput) throws InterruptedException { - try (ConfigurableApplicationContext context = SpringApplication.run(SampleQuartzApplication.class)) { - long end = System.currentTimeMillis() + 5000; - while ((!capturedOutput.toString().contains("Hello World!")) && System.currentTimeMillis() < end) { - Thread.sleep(100); - } - assertThat(capturedOutput).contains("Hello World!"); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/README.adoc b/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/README.adoc deleted file mode 100644 index ba8ce9869f..0000000000 --- a/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/README.adoc +++ /dev/null @@ -1,12 +0,0 @@ -= Spring Boot Sample Reactive OAuth2 Client - -== Register Github OAuth2 application -To run the sample, you need to link:https://github.com/settings/applications/new[register an OAuth application on Github]. -While registering your application, ensure the Authorization callback URL is set to http://localhost:8080/login/oauth2/code/github. -After completing the registration, you will have a new OAuth Application with a Client ID and Client Secret. - -== Configuring application.yml -Once the OAuth application is registered with GitHub, you need to configure the sample application to use this OAuth application (client). -Edit the link:src/main/resources/application.yml[application.yml] and replace ${APP-CLIENT-ID} and ${APP-CLIENT-SECRET} with the OAuth client credentials created in the previous section. - -The sample can now be run and you can login with your Github user credentials. diff --git a/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/pom.xml b/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/pom.xml deleted file mode 100644 index b4fc0a173c..0000000000 --- a/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-reactive-oauth2-client</artifactId> - <name>Spring Boot Sample Reactive OAuth2 Client</name> - <description>Spring Boot Sample Reactive OAuth2 Client</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-oauth2-client</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-webflux</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/main/java/sample/oauth2/client/ExampleController.java b/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/main/java/sample/oauth2/client/ExampleController.java deleted file mode 100644 index 3e6046f6fb..0000000000 --- a/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/main/java/sample/oauth2/client/ExampleController.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.oauth2.client; - -import java.security.Principal; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class ExampleController { - - @RequestMapping("/") - public String email(Principal principal) { - return "Hello " + principal.getName(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/main/java/sample/oauth2/client/SampleReactiveOAuth2ClientApplication.java b/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/main/java/sample/oauth2/client/SampleReactiveOAuth2ClientApplication.java deleted file mode 100644 index cfdcb97035..0000000000 --- a/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/main/java/sample/oauth2/client/SampleReactiveOAuth2ClientApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.oauth2.client; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleReactiveOAuth2ClientApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleReactiveOAuth2ClientApplication.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/test/java/sample/oauth2/client/SampleReactiveOAuth2ClientApplicationTests.java b/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/test/java/sample/oauth2/client/SampleReactiveOAuth2ClientApplicationTests.java deleted file mode 100644 index 3cc8c54e23..0000000000 --- a/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/test/java/sample/oauth2/client/SampleReactiveOAuth2ClientApplicationTests.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.oauth2.client; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.web.reactive.server.WebTestClient; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = { "APP-CLIENT-ID=my-client-id", "APP-CLIENT-SECRET=my-client-secret", - "YAHOO-CLIENT-ID=my-google-client-id", "YAHOO-CLIENT-SECRET=my-google-client-secret" }) -class SampleReactiveOAuth2ClientApplicationTests { - - @Autowired - private WebTestClient webTestClient; - - @Test - void everythingShouldRedirectToLogin() { - this.webTestClient.get().uri("/").exchange().expectStatus().isFound().expectHeader().valueEquals("Location", - "/login"); - } - - @Test - void loginShouldHaveBothOAuthClientsToChooseFrom() { - byte[] body = this.webTestClient.get().uri("/login").exchange().expectStatus().isOk().returnResult(String.class) - .getResponseBodyContent(); - String bodyString = new String(body); - assertThat(bodyString).contains("/oauth2/authorization/yahoo"); - assertThat(bodyString).contains("/oauth2/authorization/github-client-1"); - assertThat(bodyString).contains("/oauth2/authorization/github-client-2"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/pom.xml b/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/pom.xml deleted file mode 100644 index 81387943f2..0000000000 --- a/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-reactive-oauth2-resource-server</artifactId> - <name>Spring Boot Sample Reactive OAuth2 Resource Server</name> - <description>Spring Boot Sample Reactive Resource Server</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-oauth2-resource-server</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-webflux</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>com.squareup.okhttp3</groupId> - <artifactId>mockwebserver</artifactId> - <version>3.9.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/main/java/sample/oauth2/resource/ExampleController.java b/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/main/java/sample/oauth2/resource/ExampleController.java deleted file mode 100644 index 570222b59b..0000000000 --- a/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/main/java/sample/oauth2/resource/ExampleController.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.oauth2.resource; - -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.security.oauth2.jwt.Jwt; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class ExampleController { - - @GetMapping("/") - public String index(@AuthenticationPrincipal Jwt jwt) { - return String.format("Hello, %s!", jwt.getSubject()); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/main/java/sample/oauth2/resource/SampleReactiveOAuth2ResourceServerApplication.java b/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/main/java/sample/oauth2/resource/SampleReactiveOAuth2ResourceServerApplication.java deleted file mode 100644 index 259b18c366..0000000000 --- a/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/main/java/sample/oauth2/resource/SampleReactiveOAuth2ResourceServerApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.oauth2.resource; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleReactiveOAuth2ResourceServerApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleReactiveOAuth2ResourceServerApplication.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/test/java/sample/oauth2/resource/SampleReactiveOAuth2ResourceServerApplicationTests.java b/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/test/java/sample/oauth2/resource/SampleReactiveOAuth2ResourceServerApplicationTests.java deleted file mode 100644 index 3a01eef95b..0000000000 --- a/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/test/java/sample/oauth2/resource/SampleReactiveOAuth2ResourceServerApplicationTests.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.oauth2.resource; - -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.test.web.reactive.server.WebTestClient; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class SampleReactiveOAuth2ResourceServerApplicationTests { - - @Autowired - private WebTestClient webTestClient; - - private static MockWebServer server = new MockWebServer(); - - private static final String VALID_TOKEN = "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0Iiwic2NvcGUiOiJtZXNzYWdlOnJlYWQi" - + "LCJleHAiOjQ2ODM4MDUxNDF9.h-j6FKRFdnTdmAueTZCdep45e6DPwqM68ZQ8doIJ1exi9YxAlbWzOwId6Bd0L5YmCmp63gGQgsBUBLzwnZQ8kLUgU" - + "OBEC3UzSWGRqMskCY9_k9pX0iomX6IfF3N0PaYs0WPC4hO1s8wfZQ-6hKQ4KigFi13G9LMLdH58PRMK0pKEvs3gCbHJuEPw-K5ORlpdnleUTQIwIN" - + "afU57cmK3KocTeknPAM_L716sCuSYGvDl6xUTXO7oPdrXhS_EhxLP6KxrpI1uD4Ea_5OWTh7S0Wx5LLDfU6wBG1DowN20d374zepOIEkR-Jnmr_Ql" - + "R44vmRqS5ncrF-1R0EGcPX49U6A"; - - @BeforeAll - public static void setup() throws Exception { - server.start(); - String url = server.url("/.well-known/jwks.json").toString(); - server.enqueue(mockResponse()); - System.setProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri", url); - } - - @AfterAll - public static void shutdown() throws Exception { - server.shutdown(); - System.clearProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri"); - } - - @Test - void getWhenValidTokenShouldBeOk() { - this.webTestClient.get().uri("/").headers((headers) -> headers.setBearerAuth(VALID_TOKEN)).exchange() - .expectStatus().isOk().expectBody(String.class).isEqualTo("Hello, subject!"); - } - - @Test - void getWhenNoTokenShouldBeUnauthorized() { - this.webTestClient.get().uri("/").exchange().expectStatus().isUnauthorized().expectHeader() - .valueEquals(HttpHeaders.WWW_AUTHENTICATE, "Bearer"); - } - - private static MockResponse mockResponse() { - String body = "{\"keys\":[{\"p\":\"2p-ViY7DE9ZrdWQb544m0Jp7Cv03YCSljqfim9pD4ALhObX0OrAznOiowTjwBky9JGffMw" - + "DBVSfJSD9TSU7aH2sbbfi0bZLMdekKAuimudXwUqPDxrrg0BCyvCYgLmKjbVT3zcdylWSog93CNTxGDPzauu-oc0XPNKCXnaDpNvE\"" - + ",\"kty\":\"RSA\",\"q\":\"sP_QYavrpBvSJ86uoKVGj2AGl78CSsAtpf1ybSY5TwUlorXSdqapRbY69Y271b0aMLzlleUn9ZTBO" - + "1dlKV2_dw_lPADHVia8z3pxL-8sUhIXLsgj4acchMk4c9YX-sFh07xENnyZ-_TXm3llPLuL67HUfBC2eKe800TmCYVWc9U\",\"d\"" - + ":\"bn1nFxCQT4KLTHqo8mo9HvHD0cRNRNdWcKNnnEQkCF6tKbt-ILRyQGP8O40axLd7CoNVG9c9p_-g4-2kwCtLJNv_STLtwfpCY7" - + "VN5o6-ZIpfTjiW6duoPrLWq64Hm_4LOBQTiZfUPcLhsuJRHbWqakj-kV_YbUyC2Ocf_dd8IAQcSrAU2SCcDebhDCWwRUFvaa9V5eq0" - + "851S9goaA-AJz-JXyePH6ZFr8JxmWkWxYZ5kdcMD-sm9ZbxE0CaEk32l4fE4hR-L8x2dDtjWA-ahKCZ091z-gV3HWtR2JOjvxoNRjxUo" - + "3UxaGiFJHWNIl0EYUJZu1Cb-5wIlEI7wPx5mwQ\",\"e\":\"AQAB\",\"use\":\"sig\",\"kid\":\"one\",\"qi\":\"qS0OK4" - + "8M2CIAA6_4Wdw4EbCaAfcTLf5Oy9t5BOF_PFUKqoSpZ6JsT5H0a_4zkjt-oI969v78OTlvBKbmEyKO-KeytzHBAA5CsLmVcz0THrMSg6o" - + "XZqu66MPnvWoZN9FEN5TklPOvBFm8Bg1QZ3k-YMVaM--DLvhaYR95_mqaz50\",\"dp\":\"Too2NozLGD1XrXyhabZvy1E0EuaVFj0UHQ" - + "PDLSpkZ_2g3BK6Art6T0xmE8RYtmqrKIEIdlI3IliAvyvAx_1D7zWTTRaj-xlZyqJFrnXWL7zj8UxT8PkB-r2E-ILZ3NAi1gxIWezlBTZ8" - + "M6NfObDFmbTc_3tJkN_raISo8z_ziIE\",\"dq\":\"U0yhSkY5yOsa9YcMoigGVBWSJLpNHtbg5NypjHrPv8OhWbkOSq7WvSstBkF" - + "k5AtyFvvfZLMLIkWWxxGzV0t6f1MoxBtttLrYYyCxwihiiGFhLbAdSuZ1wnxcqA9bC7UVECvrQmVTpsMs8UupfHKbQBpZ8OWAqrn" - + "uYNNtG4_4Bt0\",\"n\":\"lygtuZj0lJjqOqIWocF8Bb583QDdq-aaFg8PesOp2-EDda6GqCpL-_NZVOflNGX7XIgjsWHcPsQHs" - + "V9gWuOzSJ0iEuWvtQ6eGBP5M6m7pccLNZfwUse8Cb4Ngx3XiTlyuqM7pv0LPyppZusfEHVEdeelou7Dy9k0OQ_nJTI3b2E1WBoHC5" - + "8CJ453lo4gcBm1efURN3LIVc1V9NQY_ESBKVdwqYyoJPEanURLVGRd6cQKn6YrCbbIRHjqAyqOE-z3KmgDJnPriljfR5XhSGyM9eq" - + "D9Xpy6zu_MAeMJJfSArp857zLPk-Wf5VP9STAcjyfdBIybMKnwBYr2qHMT675hQ\"}]}"; - return new MockResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) - .setResponseCode(200).setBody(body); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/pom.xml b/spring-boot-samples/spring-boot-sample-secure-webflux/pom.xml deleted file mode 100644 index f5da9b2f91..0000000000 --- a/spring-boot-samples/spring-boot-sample-secure-webflux/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-secure-webflux</artifactId> - <name>Spring Boot Secure WebFlux Sample</name> - <description>Spring Boot Secure WebFlux Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-webflux</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>io.projectreactor</groupId> - <artifactId>reactor-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <executions> - <execution> - <id>generate build info</id> - <goals> - <goal>build-info</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/EchoHandler.java b/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/EchoHandler.java deleted file mode 100644 index 8eb6afea99..0000000000 --- a/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/EchoHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.secure.webflux; - -import reactor.core.publisher.Mono; - -import org.springframework.stereotype.Component; -import org.springframework.web.reactive.function.server.ServerRequest; -import org.springframework.web.reactive.function.server.ServerResponse; - -@Component -public class EchoHandler { - - public Mono<ServerResponse> echo(ServerRequest request) { - return ServerResponse.ok().body(request.bodyToMono(String.class), String.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/SampleSecureWebFluxApplication.java b/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/SampleSecureWebFluxApplication.java deleted file mode 100644 index 290aa44fe7..0000000000 --- a/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/SampleSecureWebFluxApplication.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.secure.webflux; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.ServerResponse; - -import static org.springframework.web.reactive.function.server.RequestPredicates.POST; -import static org.springframework.web.reactive.function.server.RouterFunctions.route; - -@SpringBootApplication -public class SampleSecureWebFluxApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleSecureWebFluxApplication.class); - } - - @Bean - public RouterFunction<ServerResponse> monoRouterFunction(EchoHandler echoHandler) { - return route(POST("/echo"), echoHandler::echo); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/WelcomeController.java b/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/WelcomeController.java deleted file mode 100644 index 0a9a0b995d..0000000000 --- a/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/java/sample/secure/webflux/WelcomeController.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.secure.webflux; - -import java.security.Principal; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class WelcomeController { - - @GetMapping("/") - public String welcome(Principal principal) { - return "Hello " + principal.getName(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/ManagementPortSampleSecureWebFluxTests.java b/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/ManagementPortSampleSecureWebFluxTests.java deleted file mode 100644 index 255b1333fa..0000000000 --- a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/ManagementPortSampleSecureWebFluxTests.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.secure.webflux; - -import java.util.Base64; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest; -import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; -import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; -import org.springframework.boot.autoconfigure.security.reactive.PathRequest; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.web.server.ServerHttpSecurity; -import org.springframework.security.web.server.SecurityWebFilterChain; -import org.springframework.test.web.reactive.server.WebTestClient; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for separate management and main service ports. - * - * @author Madhura Bhave - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=0" }, classes = { - ManagementPortSampleSecureWebFluxTests.SecurityConfiguration.class, SampleSecureWebFluxApplication.class }) -class ManagementPortSampleSecureWebFluxTests { - - @LocalServerPort - private int port; - - @LocalManagementPort - private int managementPort; - - @Autowired - private WebTestClient webClient; - - @Test - void testHome() { - this.webClient.get().uri("http://localhost:" + this.port, String.class) - .header("Authorization", "basic " + getBasicAuth()).exchange().expectStatus().isOk() - .expectBody(String.class).isEqualTo("Hello user"); - } - - @Test - void actuatorPathOnMainPortShouldNotMatch() { - this.webClient.get().uri("http://localhost:" + this.port + "/actuator", String.class).exchange().expectStatus() - .isUnauthorized(); - this.webClient.get().uri("http://localhost:" + this.port + "/actuator/health", String.class).exchange() - .expectStatus().isUnauthorized(); - } - - @Test - void testSecureActuator() { - this.webClient.get().uri("http://localhost:" + this.managementPort + "/actuator/env", String.class).exchange() - .expectStatus().isUnauthorized(); - } - - @Test - void testInsecureActuator() { - String responseBody = this.webClient.get() - .uri("http://localhost:" + this.managementPort + "/actuator/health", String.class).exchange() - .expectStatus().isOk().expectBody(String.class).returnResult().getResponseBody(); - assertThat(responseBody).contains("\"status\":\"UP\""); - } - - private String getBasicAuth() { - return new String(Base64.getEncoder().encode(("user:password").getBytes())); - } - - @Configuration(proxyBeanMethods = false) - static class SecurityConfiguration { - - @Bean - public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { - return http.authorizeExchange().matchers(EndpointRequest.to("health", "info")).permitAll() - .matchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class)).hasRole("ACTUATOR") - .matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll().pathMatchers("/login") - .permitAll().anyExchange().authenticated().and().httpBasic().and().build(); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxApplicationTests.java b/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxApplicationTests.java deleted file mode 100644 index 5c61fad0a9..0000000000 --- a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxApplicationTests.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.secure.webflux; - -import java.util.Base64; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.test.web.reactive.server.WebTestClient; - -/** - * Integration tests for a secure reactive application. - * - * @author Madhura Bhave - */ -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = "management.endpoint.health.show-details=never") -class SampleSecureWebFluxApplicationTests { - - @Autowired - private WebTestClient webClient; - - @Test - void userDefinedMappingsSecureByDefault() { - this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() - .isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void healthInsecureByDefault() { - this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() - .isOk(); - } - - @Test - void infoInsecureByDefault() { - this.webClient.get().uri("/actuator/info").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk(); - } - - @Test - void otherActuatorsSecureByDefault() { - this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() - .isUnauthorized(); - } - - @Test - void userDefinedMappingsAccessibleOnLogin() { - this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "basic " + getBasicAuth()).exchange().expectBody(String.class) - .isEqualTo("Hello user"); - } - - @Test - void actuatorsAccessibleOnLogin() { - this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "basic " + getBasicAuth()).exchange().expectBody(String.class) - .isEqualTo("{\"status\":\"UP\"}"); - } - - private String getBasicAuth() { - return new String(Base64.getEncoder().encode(("user:password").getBytes())); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java b/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java deleted file mode 100644 index 8d490c3703..0000000000 --- a/spring-boot-samples/spring-boot-sample-secure-webflux/src/test/java/sample/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.secure.webflux; - -import java.util.Base64; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest; -import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; -import org.springframework.boot.autoconfigure.security.reactive.PathRequest; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.security.config.web.server.ServerHttpSecurity; -import org.springframework.security.core.userdetails.MapReactiveUserDetailsService; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.web.server.SecurityWebFilterChain; -import org.springframework.test.web.reactive.server.WebTestClient; - -/** - * Integration tests for a secure reactive application with custom security. - * - * @author Madhura Bhave - */ -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { - SampleSecureWebFluxCustomSecurityTests.SecurityConfiguration.class, SampleSecureWebFluxApplication.class }) -class SampleSecureWebFluxCustomSecurityTests { - - @Autowired - private WebTestClient webClient; - - @Test - void userDefinedMappingsSecure() { - this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() - .isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void healthAndInfoDoNotRequireAuthentication() { - this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() - .isOk(); - this.webClient.get().uri("/actuator/info").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk(); - } - - @Test - void actuatorsSecuredByRole() { - this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "basic " + getBasicAuth()).exchange().expectStatus().isForbidden(); - } - - @Test - void actuatorsAccessibleOnCorrectLogin() { - this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "basic " + getBasicAuthForAdmin()).exchange().expectStatus().isOk(); - } - - @Test - void actuatorExcludedFromEndpointRequestMatcher() { - this.webClient.get().uri("/actuator/mappings").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "basic " + getBasicAuth()).exchange().expectStatus().isOk(); - } - - @Test - void staticResourceShouldBeAccessible() { - this.webClient.get().uri("/css/bootstrap.min.css").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() - .isOk(); - } - - @Test - void actuatorLinksIsSecure() { - this.webClient.get().uri("/actuator").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() - .isUnauthorized(); - this.webClient.get().uri("/actuator").accept(MediaType.APPLICATION_JSON) - .header("Authorization", "basic " + getBasicAuthForAdmin()).exchange().expectStatus().isOk(); - } - - private String getBasicAuth() { - return new String(Base64.getEncoder().encode(("user:password").getBytes())); - } - - private String getBasicAuthForAdmin() { - return new String(Base64.getEncoder().encode(("admin:admin").getBytes())); - } - - @Configuration(proxyBeanMethods = false) - static class SecurityConfiguration { - - @SuppressWarnings("deprecation") - @Bean - public MapReactiveUserDetailsService userDetailsService() { - return new MapReactiveUserDetailsService( - User.withDefaultPasswordEncoder().username("user").password("password").authorities("ROLE_USER") - .build(), - User.withDefaultPasswordEncoder().username("admin").password("admin") - .authorities("ROLE_ACTUATOR", "ROLE_USER").build()); - } - - @Bean - public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { - return http.authorizeExchange().matchers(EndpointRequest.to("health", "info")).permitAll() - .matchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class)).hasRole("ACTUATOR") - .matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll().pathMatchers("/login") - .permitAll().anyExchange().authenticated().and().httpBasic().and().build(); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-secure/pom.xml b/spring-boot-samples/spring-boot-sample-secure/pom.xml deleted file mode 100644 index cbe546632a..0000000000 --- a/spring-boot-samples/spring-boot-sample-secure/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-secure</artifactId> - <name>Spring Boot Security Sample</name> - <description>Spring Boot Security Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java b/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java deleted file mode 100644 index ec0afa4be3..0000000000 --- a/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleSecureApplication.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.secure; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.core.authority.AuthorityUtils; -import org.springframework.security.core.context.SecurityContextHolder; - -@EnableAutoConfiguration -@ComponentScan -@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) -public class SampleSecureApplication implements CommandLineRunner { - - @Autowired - private SampleService service; - - @Override - public void run(String... args) throws Exception { - SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("user", "N/A", - AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"))); - try { - System.out.println(this.service.secure()); - } - finally { - SecurityContextHolder.clearContext(); - } - } - - public static void main(String[] args) { - SpringApplication.run(SampleSecureApplication.class, "--debug"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleService.java b/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleService.java deleted file mode 100644 index f8e584e10a..0000000000 --- a/spring-boot-samples/spring-boot-sample-secure/src/main/java/sample/secure/SampleService.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.secure; - -import org.springframework.security.access.annotation.Secured; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Service; - -@Service -public class SampleService { - - @Secured("ROLE_USER") - public String secure() { - return "Hello Security"; - } - - @PreAuthorize("true") - public String authorized() { - return "Hello World"; - } - - @PreAuthorize("false") - public String denied() { - return "Goodbye World"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java b/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java deleted file mode 100644 index cb1c2ec378..0000000000 --- a/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.secure; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.security.access.AccessDeniedException; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.AuthenticationException; -import org.springframework.security.core.context.SecurityContextHolder; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(classes = { SampleSecureApplication.class }) -class SampleSecureApplicationTests { - - @Autowired - private SampleService service; - - private Authentication authentication; - - @BeforeEach - void init() { - this.authentication = new UsernamePasswordAuthenticationToken("user", "password"); - } - - @AfterEach - void close() { - SecurityContextHolder.clearContext(); - } - - @Test - void secure() { - assertThatExceptionOfType(AuthenticationException.class) - .isThrownBy(() -> SampleSecureApplicationTests.this.service.secure()); - } - - @Test - void authenticated() { - SecurityContextHolder.getContext().setAuthentication(this.authentication); - assertThat("Hello Security").isEqualTo(this.service.secure()); - } - - @Test - void preauth() { - SecurityContextHolder.getContext().setAuthentication(this.authentication); - assertThat("Hello World").isEqualTo(this.service.authorized()); - } - - @Test - void denied() { - SecurityContextHolder.getContext().setAuthentication(this.authentication); - assertThatExceptionOfType(AccessDeniedException.class) - .isThrownBy(() -> SampleSecureApplicationTests.this.service.denied()); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-servlet/pom.xml b/spring-boot-samples/spring-boot-sample-servlet/pom.xml deleted file mode 100644 index caf93b3a2b..0000000000 --- a/spring-boot-samples/spring-boot-sample-servlet/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-servlet</artifactId> - <packaging>war</packaging> - <name>Spring Boot Servlet Sample</name> - <description>Spring Boot Servlet Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> - <!-- Provided --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - <scope>provided</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java b/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java deleted file mode 100644 index e27a5914f5..0000000000 --- a/spring-boot-samples/spring-boot-sample-servlet/src/main/java/sample/servlet/SampleServletApplication.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.servlet; - -import java.io.IOException; - -import javax.servlet.GenericServlet; -import javax.servlet.Servlet; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.Bean; - -@SpringBootConfiguration -@EnableAutoConfiguration -public class SampleServletApplication extends SpringBootServletInitializer { - - @SuppressWarnings("serial") - @Bean - public Servlet dispatcherServlet() { - return new GenericServlet() { - @Override - public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { - res.setContentType("text/plain"); - res.getWriter().append("Hello World"); - } - }; - } - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleServletApplication.class); - } - - public static void main(String[] args) { - SpringApplication.run(SampleServletApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java deleted file mode 100644 index c8af28e4a4..0000000000 --- a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.servlet; - -import java.util.Collections; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleServletApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHomeIsSecure() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void testHome() { - ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("Hello World"); - } - - private String getPassword() { - return "password"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-session-webflux/README.adoc b/spring-boot-samples/spring-boot-sample-session-webflux/README.adoc deleted file mode 100644 index a537f4af9b..0000000000 --- a/spring-boot-samples/spring-boot-sample-session-webflux/README.adoc +++ /dev/null @@ -1,37 +0,0 @@ -= Spring Boot Spring Session Sample - -This sample demonstrates the Spring Session WebFlux auto-configuration support. Spring -Session supports multiple reactive session store types, including: - -* `Redis` -* `MongoDB` - - - -== Using a different session store -Initially, the project uses MongoDB session store backed by an embedded MongoDB. You can -try out your favorite session store as explained below. - - - -=== Redis -Add `org.springframework.session:spring-session-data-redis` and -`spring-boot-starter-data-redis-reactive` dependencies to the project and make sure it is -configured properly (by default, a Redis instance with the default settings is expected -on your local box). - -TIP: Run sample application using Redis session store using -`$mvn spring-boot:run -Predis`. - - - -=== MongoDB -Add `org.springframework.session:spring-session-data-mongodb` and -`spring-boot-starter-data-mongodb-reactive` and -`de.flapdoodle.embed:de.flapdoodle.embed.mongo` dependencies to the project. An embedded -MongoDB is automatically configured. - -TIP: Run sample application using MongoDB session store using -`$mvn spring-boot:run -Pmongodb`. - -Note that this profile is active by default. diff --git a/spring-boot-samples/spring-boot-sample-session-webflux/pom.xml b/spring-boot-samples/spring-boot-sample-session-webflux/pom.xml deleted file mode 100644 index 70deda9256..0000000000 --- a/spring-boot-samples/spring-boot-sample-session-webflux/pom.xml +++ /dev/null @@ -1,76 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-session-webflux</artifactId> - <name>Spring Boot Session WebFlux Sample</name> - <description>Spring Boot Session WebFlux Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-webflux</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>redis</id> - <dependencies> - <dependency> - <groupId>org.springframework.session</groupId> - <artifactId>spring-session-data-redis</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-redis-reactive</artifactId> - </dependency> - </dependencies> - </profile> - <profile> - <id>mongodb</id> - <activation> - <activeByDefault>true</activeByDefault> - </activation> - <dependencies> - <dependency> - <groupId>org.springframework.session</groupId> - <artifactId>spring-session-data-mongodb</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-mongodb-reactive</artifactId> - </dependency> - <dependency> - <groupId>de.flapdoodle.embed</groupId> - <artifactId>de.flapdoodle.embed.mongo</artifactId> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-session-webflux/src/main/java/sample/session/HelloRestController.java b/spring-boot-samples/spring-boot-sample-session-webflux/src/main/java/sample/session/HelloRestController.java deleted file mode 100644 index 60c49e48a6..0000000000 --- a/spring-boot-samples/spring-boot-sample-session-webflux/src/main/java/sample/session/HelloRestController.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.session; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.server.WebSession; - -@RestController -public class HelloRestController { - - @GetMapping("/") - String sessionId(WebSession session) { - return session.getId(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-session-webflux/src/main/java/sample/session/SampleSessionWebFluxApplication.java b/spring-boot-samples/spring-boot-sample-session-webflux/src/main/java/sample/session/SampleSessionWebFluxApplication.java deleted file mode 100644 index 3fae99d4b8..0000000000 --- a/spring-boot-samples/spring-boot-sample-session-webflux/src/main/java/sample/session/SampleSessionWebFluxApplication.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.session; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.security.config.web.server.ServerHttpSecurity; -import org.springframework.security.web.server.SecurityWebFilterChain; -import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository; - -@SpringBootApplication -public class SampleSessionWebFluxApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleSessionWebFluxApplication.class); - } - - @Bean - public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { - // @formatter:off - return http - .authorizeExchange() - .anyExchange().authenticated() - .and() - .httpBasic().securityContextRepository(new WebSessionServerSecurityContextRepository()) - .and() - .formLogin() - .and() - .build(); - // @formatter:on - } - -} diff --git a/spring-boot-samples/spring-boot-sample-session-webflux/src/test/java/sample/session/SampleSessionWebFluxApplicationTests.java b/spring-boot-samples/spring-boot-sample-session-webflux/src/test/java/sample/session/SampleSessionWebFluxApplicationTests.java deleted file mode 100644 index 6eb2df4422..0000000000 --- a/spring-boot-samples/spring-boot-sample-session-webflux/src/test/java/sample/session/SampleSessionWebFluxApplicationTests.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.session; - -import java.time.Duration; -import java.util.Base64; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseCookie; -import org.springframework.web.reactive.function.client.ClientResponse; -import org.springframework.web.reactive.function.client.WebClient; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests for {@link SampleSessionWebFluxApplication}. - * - * @author Vedran Pavic - */ -@SpringBootTest(properties = "server.servlet.session.timeout:2", - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class SampleSessionWebFluxApplicationTests { - - @LocalServerPort - private int port; - - @Autowired - private WebClient.Builder webClientBuilder; - - @Test - void userDefinedMappingsSecureByDefault() throws Exception { - WebClient webClient = this.webClientBuilder.baseUrl("http://localhost:" + this.port + "/").build(); - ClientResponse response = webClient.get().header("Authorization", getBasicAuth()).exchange() - .block(Duration.ofSeconds(30)); - assertThat(response.statusCode()).isEqualTo(HttpStatus.OK); - ResponseCookie sessionCookie = response.cookies().getFirst("SESSION"); - String sessionId = response.bodyToMono(String.class).block(Duration.ofSeconds(30)); - response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30)); - assertThat(response.statusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.bodyToMono(String.class).block(Duration.ofSeconds(30))).isEqualTo(sessionId); - Thread.sleep(2000); - response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30)); - assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - private String getBasicAuth() { - return "Basic " + Base64.getEncoder().encodeToString("user:password".getBytes()); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-session/README.adoc b/spring-boot-samples/spring-boot-sample-session/README.adoc deleted file mode 100644 index 6349857325..0000000000 --- a/spring-boot-samples/spring-boot-sample-session/README.adoc +++ /dev/null @@ -1,60 +0,0 @@ -= Spring Boot Spring Session Sample - -This sample demonstrates the Spring Session auto-configuration support. Spring Session -supports multiple session store types, including: - -* `Redis` -* `JDBC` -* `Hazelcast` -* `MongoDB` - - - -== Using a different session store -Initially, the project uses JDBC session store backed by an in-memory embedded H2 -database. You can try out your favorite session store as explained below. - - - -=== Redis -Add `org.springframework.session:spring-session-data-redis` and -`spring-boot-starter-data-redis` dependencies to the project and make sure it is -configured properly (by default, a Redis instance with the default settings is expected -on your local box). - -TIP: Run sample application using Redis session store using -`$mvn spring-boot:run -Predis`. - - - -=== JDBC -Add `org.springframework.session:spring-session-jdbc`, -`org.springframework.boot:spring-boot-starter-jdbc` and `com.h2database:h2` dependencies -to the project. An in-memory embedded H2 database is automatically configured. - -TIP: Run sample application using JDBC session store with -`$mvn spring-boot:run -Pjdbc`. - -Note that this profile is active by default. - - - -=== Hazelcast -Add `org.springframework.session:spring-session-hazelcast` and `com.hazelcast:hazelcast` -dependencies to the project to enable support for Hazelcast. Since there is a default -`hazelcast.xml` configuration file at the root of the classpath, it is used to -automatically configure the underlying `HazelcastInstance`. - -TIP: Run sample application using Hazelcast session store with -`$mvn spring-boot:run -Phazelcast`. - - - -=== MongoDB -Add `org.springframework.session:spring-session-data-mongodb` and -`spring-boot-starter-data-mongodb` dependencies to the project and make sure it is -configured properly (by default, a MongoDB instance with the default settings is expected -on your local box). - -TIP: Run sample application using MongoDB session store using -`$mvn spring-boot:run -Pmongodb`. diff --git a/spring-boot-samples/spring-boot-sample-session/pom.xml b/spring-boot-samples/spring-boot-sample-session/pom.xml deleted file mode 100644 index 8d1469c321..0000000000 --- a/spring-boot-samples/spring-boot-sample-session/pom.xml +++ /dev/null @@ -1,106 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-session</artifactId> - <name>Spring Boot Session Sample</name> - <description>Spring Boot Session Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>redis</id> - <dependencies> - <dependency> - <groupId>org.springframework.session</groupId> - <artifactId>spring-session-data-redis</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-redis</artifactId> - </dependency> - </dependencies> - </profile> - <profile> - <id>jdbc</id> - <activation> - <activeByDefault>true</activeByDefault> - </activation> - <dependencies> - <dependency> - <groupId>org.springframework.session</groupId> - <artifactId>spring-session-jdbc</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jdbc</artifactId> - </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - </dependency> - </dependencies> - </profile> - <profile> - <id>hazelcast</id> - <dependencies> - <dependency> - <groupId>org.springframework.session</groupId> - <artifactId>spring-session-hazelcast</artifactId> - </dependency> - <dependency> - <groupId>com.hazelcast</groupId> - <artifactId>hazelcast</artifactId> - </dependency> - </dependencies> - </profile> - <profile> - <id>mongodb</id> - <dependencies> - <dependency> - <groupId>org.springframework.session</groupId> - <artifactId>spring-session-data-mongodb</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-mongodb</artifactId> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-session/src/main/java/sample/session/HelloRestController.java b/spring-boot-samples/spring-boot-sample-session/src/main/java/sample/session/HelloRestController.java deleted file mode 100644 index 0d70fee400..0000000000 --- a/spring-boot-samples/spring-boot-sample-session/src/main/java/sample/session/HelloRestController.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.session; - -import javax.servlet.http.HttpSession; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class HelloRestController { - - @GetMapping("/") - String uid(HttpSession session) { - return session.getId(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-session/src/main/java/sample/session/SampleSessionApplication.java b/spring-boot-samples/spring-boot-sample-session/src/main/java/sample/session/SampleSessionApplication.java deleted file mode 100644 index 71152509b6..0000000000 --- a/spring-boot-samples/spring-boot-sample-session/src/main/java/sample/session/SampleSessionApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.session; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleSessionApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleSessionApplication.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-session/src/test/java/sample/session/SampleSessionApplicationTests.java b/spring-boot-samples/spring-boot-sample-session/src/test/java/sample/session/SampleSessionApplicationTests.java deleted file mode 100644 index c7b973555a..0000000000 --- a/spring-boot-samples/spring-boot-sample-session/src/test/java/sample/session/SampleSessionApplicationTests.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.session; - -import java.net.URI; -import java.util.Base64; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SampleSessionApplication}. - * - * @author Andy Wilkinson - * @author Vedran Pavic - */ -class SampleSessionApplicationTests { - - @Test - void sessionExpiry() throws Exception { - ConfigurableApplicationContext context = createContext(); - String port = context.getEnvironment().getProperty("local.server.port"); - URI uri = URI.create("http://localhost:" + port + "/"); - RestTemplate restTemplate = new RestTemplate(); - ResponseEntity<String> firstResponse = firstRequest(restTemplate, uri); - String sessionId1 = firstResponse.getBody(); - String cookie = firstResponse.getHeaders().getFirst("Set-Cookie"); - String sessionId2 = nextRequest(restTemplate, uri, cookie).getBody(); - assertThat(sessionId1).isEqualTo(sessionId2); - Thread.sleep(1000); - String loginPage = nextRequest(restTemplate, uri, cookie).getBody(); - assertThat(loginPage).containsIgnoringCase("login"); - } - - private ConfigurableApplicationContext createContext() { - ConfigurableApplicationContext context = new SpringApplicationBuilder().sources(SampleSessionApplication.class) - .properties("server.port:0", "server.servlet.session.timeout:1") - .initializers(new ServerPortInfoApplicationContextInitializer()).run(); - return context; - } - - private ResponseEntity<String> firstRequest(RestTemplate restTemplate, URI uri) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", "Basic " + Base64.getEncoder().encodeToString("user:password".getBytes())); - RequestEntity<Object> request = new RequestEntity<>(headers, HttpMethod.GET, uri); - return restTemplate.exchange(request, String.class); - } - - private ResponseEntity<String> nextRequest(RestTemplate restTemplate, URI uri, String cookie) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Cookie", cookie); - RequestEntity<Object> request = new RequestEntity<>(headers, HttpMethod.GET, uri); - return restTemplate.exchange(request, String.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-simple/pom.xml b/spring-boot-samples/spring-boot-sample-simple/pom.xml deleted file mode 100644 index 0d37b216a9..0000000000 --- a/spring-boot-samples/spring-boot-sample-simple/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-simple</artifactId> - <name>Spring Boot Simple Sample</name> - <description>Spring Boot Simple Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>jakarta.validation</groupId> - <artifactId>jakarta.validation-api</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <dependency> - <groupId>org.hibernate.validator</groupId> - <artifactId>hibernate-validator</artifactId> - <exclusions> - <exclusion> - <groupId>javax.validation</groupId> - <artifactId>validation-api</artifactId> - </exclusion> - </exclusions> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/ExitException.java b/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/ExitException.java deleted file mode 100644 index 2352a2058e..0000000000 --- a/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/ExitException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.simple; - -import org.springframework.boot.ExitCodeGenerator; - -public class ExitException extends RuntimeException implements ExitCodeGenerator { - - @Override - public int getExitCode() { - return 10; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/SampleConfigurationProperties.java b/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/SampleConfigurationProperties.java deleted file mode 100644 index f45f54a4d3..0000000000 --- a/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/SampleConfigurationProperties.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.simple; - -import javax.validation.constraints.NotNull; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; - -@Validated -@ConfigurationProperties(prefix = "sample") -public class SampleConfigurationProperties { - - @NotNull - private String name; - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/SampleSimpleApplication.java b/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/SampleSimpleApplication.java deleted file mode 100644 index 38ec17cc79..0000000000 --- a/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/SampleSimpleApplication.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.simple; - -import sample.simple.service.HelloWorldService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleSimpleApplication implements CommandLineRunner { - - // Simple example shows how a command line spring application can execute an - // injected bean service. Also demonstrates how you can use @Value to inject - // command line args ('--name=whatever') or application properties - - @Autowired - private HelloWorldService helloWorldService; - - @Override - public void run(String... args) { - System.out.println(this.helloWorldService.getHelloMessage()); - if (args.length > 0 && args[0].equals("exitcode")) { - throw new ExitException(); - } - } - - public static void main(String[] args) { - SpringApplication.run(SampleSimpleApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/service/HelloWorldService.java deleted file mode 100644 index 2e2ad8a53e..0000000000 --- a/spring-boot-samples/spring-boot-sample-simple/src/main/java/sample/simple/service/HelloWorldService.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.simple.service; - -import java.time.Duration; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - @Value("${name:World}") - private String name; - - @Value("${duration:10s}") - private Duration duration; - - public String getHelloMessage() { - return "Hello " + this.name + " for " + this.duration.getSeconds() + " seconds"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java b/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java deleted file mode 100644 index 411b12f326..0000000000 --- a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.simple; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SampleSimpleApplication}. - * - * @author Dave Syer - * @author Phillip Webb - */ -@ExtendWith(OutputCaptureExtension.class) -class SampleSimpleApplicationTests { - - private String profiles; - - @BeforeEach - void init() { - this.profiles = System.getProperty("spring.profiles.active"); - } - - @AfterEach - void after() { - if (this.profiles != null) { - System.setProperty("spring.profiles.active", this.profiles); - } - else { - System.clearProperty("spring.profiles.active"); - } - } - - @Test - void testDefaultSettings(CapturedOutput capturedOutput) { - SampleSimpleApplication.main(new String[0]); - assertThat(capturedOutput).contains("Hello Phil"); - } - - @Test - void testCommandLineOverrides(CapturedOutput capturedOutput) { - SampleSimpleApplication.main(new String[] { "--name=Gordon", "--duration=1m" }); - assertThat(capturedOutput).contains("Hello Gordon for 60 seconds"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java b/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java deleted file mode 100644 index 81029fcafe..0000000000 --- a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.simple; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.ApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SampleSimpleApplication}. - * - * @author Dave Syer - */ -@SpringBootTest -class SpringTestSampleSimpleApplicationTests { - - @Autowired - ApplicationContext ctx; - - @Test - void testContextLoads() { - assertThat(this.ctx).isNotNull(); - assertThat(this.ctx.containsBean("helloWorldService")).isTrue(); - assertThat(this.ctx.containsBean("sampleSimpleApplication")).isTrue(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test-nomockito/pom.xml b/spring-boot-samples/spring-boot-sample-test-nomockito/pom.xml deleted file mode 100644 index 92f900c5df..0000000000 --- a/spring-boot-samples/spring-boot-sample-test-nomockito/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-test-nomockito</artifactId> - <name>Spring Boot Test Sample No Mockito</name> - <description>Spring Boot Test Sample No Mockito</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-engine</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-test-nomockito/src/main/java/sample/testnomockito/SampleTestNoMockitoApplication.java b/spring-boot-samples/spring-boot-sample-test-nomockito/src/main/java/sample/testnomockito/SampleTestNoMockitoApplication.java deleted file mode 100644 index 637a869c40..0000000000 --- a/spring-boot-samples/spring-boot-sample-test-nomockito/src/main/java/sample/testnomockito/SampleTestNoMockitoApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.testnomockito; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleTestNoMockitoApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleTestNoMockitoApplication.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test-nomockito/src/test/java/sample/testnomockito/SampleTestNoMockitoApplicationTests.java b/spring-boot-samples/spring-boot-sample-test-nomockito/src/test/java/sample/testnomockito/SampleTestNoMockitoApplicationTests.java deleted file mode 100644 index 9af1a5fdf3..0000000000 --- a/spring-boot-samples/spring-boot-sample-test-nomockito/src/test/java/sample/testnomockito/SampleTestNoMockitoApplicationTests.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.testnomockito; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests that {@code ResetMocksTestExecutionListener} and - * {@code MockitoTestExecutionListener} gracefully degrade when Mockito is not on the - * classpath. - * - * @author Madhura Bhave - */ -@ExtendWith(SpringExtension.class) -class SampleTestNoMockitoApplicationTests { - - // gh-7065 - - @Autowired - private ApplicationContext context; - - @Test - void contextLoads() throws Exception { - assertThat(this.context).isNotNull(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/pom.xml b/spring-boot-samples/spring-boot-sample-test/pom.xml deleted file mode 100644 index 01289d1895..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-test</artifactId> - <name>Spring Boot Test Sample</name> - <description>Spring Boot Test Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> - </dependency> - <dependency> - <groupId>org.seleniumhq.selenium</groupId> - <artifactId>selenium-api</artifactId> - </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - </dependency> - <dependency> - <groupId>mysql</groupId> - <artifactId>mysql-connector-java</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.seleniumhq.selenium</groupId> - <artifactId>htmlunit-driver</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>net.sourceforge.htmlunit</groupId> - <artifactId>htmlunit</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>java9+</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <dependencies> - <dependency> - <groupId>jakarta.xml.bind</groupId> - <artifactId>jakarta.xml.bind-api</artifactId> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/SampleTestApplication.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/SampleTestApplication.java deleted file mode 100644 index e8beaf54f2..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/SampleTestApplication.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * Sample application to demonstrate testing. - * - * @author Phillip Webb - */ -@SpringBootApplication -public class SampleTestApplication { - - // NOTE: this application will intentionally not start without MySQL, the test will - // still run. - - public static void main(String[] args) { - SpringApplication.run(SampleTestApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/WelcomeCommandLineRunner.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/WelcomeCommandLineRunner.java deleted file mode 100644 index f32bdc0969..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/WelcomeCommandLineRunner.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test; - -import org.springframework.boot.CommandLineRunner; -import org.springframework.stereotype.Component; - -/** - * Simple component that just prints a message. Used to show how different types of - * integration tests work. - * - * @author Phillip Webb - */ -@Component -public class WelcomeCommandLineRunner implements CommandLineRunner { - - @Override - public void run(String... args) throws Exception { - System.out.println("***** WELCOME TO THE DEMO *****"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/User.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/User.java deleted file mode 100644 index d0dd2b4bfc..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/User.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.domain; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -import org.springframework.util.Assert; - -/** - * A user of the system. - * - * @author Phillip Webb - */ -@Entity -public class User { - - @Id - @GeneratedValue - private Long id; - - @Column(unique = true) - private String username; - - private VehicleIdentificationNumber vin; - - protected User() { - } - - public User(String username, VehicleIdentificationNumber vin) { - Assert.hasLength(username, "Username must not be empty"); - Assert.notNull(vin, "VIN must not be null"); - this.username = username; - this.vin = vin; - } - - public Long getId() { - return this.id; - } - - public String getUsername() { - return this.username; - } - - public VehicleIdentificationNumber getVin() { - return this.vin; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/UserRepository.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/UserRepository.java deleted file mode 100644 index dac1eb8103..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/UserRepository.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.domain; - -import org.springframework.data.repository.Repository; - -/** - * Domain repository for {@link User}. - * - * @author Phillip Webb - */ -public interface UserRepository extends Repository<User, Long> { - - User findByUsername(String username); - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/VehicleIdentificationNumber.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/VehicleIdentificationNumber.java deleted file mode 100644 index c99edad0e7..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/VehicleIdentificationNumber.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.domain; - -import org.springframework.util.Assert; - -/** - * A Vehicle Identification Number. - * - * @author Phillip Webb - */ -public final class VehicleIdentificationNumber { - - private String vin; - - public VehicleIdentificationNumber(String vin) { - Assert.notNull(vin, "VIN must not be null"); - Assert.isTrue(vin.length() == 17, "VIN must be exactly 17 characters"); - this.vin = vin; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj == null || obj.getClass() != getClass()) { - return false; - } - return this.vin.equals(((VehicleIdentificationNumber) obj).vin); - } - - @Override - public int hashCode() { - return this.vin.hashCode(); - } - - @Override - public String toString() { - return this.vin; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/VehicleIdentificationNumberAttributeConverter.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/VehicleIdentificationNumberAttributeConverter.java deleted file mode 100644 index 61a8692b29..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/domain/VehicleIdentificationNumberAttributeConverter.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.domain; - -import javax.persistence.AttributeConverter; -import javax.persistence.Converter; - -/** - * JPA {@link AttributeConverter} for {@link VehicleIdentificationNumber}. - * - * @author Phillip Webb - */ -@Converter(autoApply = true) -public class VehicleIdentificationNumberAttributeConverter - implements AttributeConverter<VehicleIdentificationNumber, String> { - - @Override - public String convertToDatabaseColumn(VehicleIdentificationNumber attribute) { - return attribute.toString(); - } - - @Override - public VehicleIdentificationNumber convertToEntityAttribute(String dbData) { - return new VehicleIdentificationNumber(dbData); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/RemoteVehicleDetailsService.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/RemoteVehicleDetailsService.java deleted file mode 100644 index 3865cb3b17..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/RemoteVehicleDetailsService.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.service; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import sample.test.domain.VehicleIdentificationNumber; - -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; -import org.springframework.web.client.HttpStatusCodeException; -import org.springframework.web.client.RestTemplate; - -/** - * {@link VehicleDetailsService} backed by a remote REST service. - * - * @author Phillip Webb - */ -@Service -public class RemoteVehicleDetailsService implements VehicleDetailsService { - - private static final Log logger = LogFactory.getLog(RemoteVehicleDetailsService.class); - - private final RestTemplate restTemplate; - - public RemoteVehicleDetailsService(ServiceProperties properties, RestTemplateBuilder restTemplateBuilder) { - this.restTemplate = restTemplateBuilder.rootUri(properties.getVehicleServiceRootUrl()).build(); - } - - @Override - public VehicleDetails getVehicleDetails(VehicleIdentificationNumber vin) - throws VehicleIdentificationNumberNotFoundException { - Assert.notNull(vin, "VIN must not be null"); - logger.debug("Retrieving vehicle data for: " + vin); - try { - return this.restTemplate.getForObject("/vehicle/{vin}/details", VehicleDetails.class, vin); - } - catch (HttpStatusCodeException ex) { - if (HttpStatus.NOT_FOUND.equals(ex.getStatusCode())) { - throw new VehicleIdentificationNumberNotFoundException(vin, ex); - } - throw ex; - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/ServiceProperties.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/ServiceProperties.java deleted file mode 100644 index 88af8a972d..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/ServiceProperties.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.service; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * Properties for the service. - * - * @author Phillip Webb - */ -@ConfigurationProperties -public class ServiceProperties { - - private String vehicleServiceRootUrl = "http://localhost:8080/vs"; - - public String getVehicleServiceRootUrl() { - return this.vehicleServiceRootUrl; - } - - public void setVehicleServiceRootUrl(String vehicleServiceRootUrl) { - this.vehicleServiceRootUrl = vehicleServiceRootUrl; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleDetails.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleDetails.java deleted file mode 100644 index 2dad1455f1..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleDetails.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.service; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -import org.springframework.util.Assert; - -/** - * Details of a single vehicle. - * - * @author Phillip Webb - */ -public class VehicleDetails { - - private final String make; - - private final String model; - - @JsonCreator - public VehicleDetails(@JsonProperty("make") String make, @JsonProperty("model") String model) { - Assert.notNull(make, "Make must not be null"); - Assert.notNull(model, "Model must not be null"); - this.make = make; - this.model = model; - } - - public String getMake() { - return this.make; - } - - public String getModel() { - return this.model; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj == null || obj.getClass() != getClass()) { - return false; - } - VehicleDetails other = (VehicleDetails) obj; - return this.make.equals(other.make) && this.model.equals(other.model); - } - - @Override - public int hashCode() { - return this.make.hashCode() * 31 + this.model.hashCode(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleDetailsService.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleDetailsService.java deleted file mode 100644 index bc8fec5f7d..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleDetailsService.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.service; - -import sample.test.domain.VehicleIdentificationNumber; - -/** - * A service to obtain {@link VehicleDetails} given a {@link VehicleIdentificationNumber}. - * - * @author Phillip Webb - */ -public interface VehicleDetailsService { - - /** - * Get vehicle details for a given {@link VehicleIdentificationNumber}. - * @param vin the vehicle identification number - * @return vehicle details - * @throws VehicleIdentificationNumberNotFoundException if the VIN is not known - */ - VehicleDetails getVehicleDetails(VehicleIdentificationNumber vin) - throws VehicleIdentificationNumberNotFoundException; - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleIdentificationNumberNotFoundException.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleIdentificationNumberNotFoundException.java deleted file mode 100644 index a7ee16f762..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/service/VehicleIdentificationNumberNotFoundException.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.service; - -import sample.test.domain.VehicleIdentificationNumber; - -/** - * Exception thrown when a {@link VehicleIdentificationNumber} is not found. - * - * @author Phillip Webb - */ -public class VehicleIdentificationNumberNotFoundException extends RuntimeException { - - private final VehicleIdentificationNumber vehicleIdentificationNumber; - - public VehicleIdentificationNumberNotFoundException(VehicleIdentificationNumber vin) { - this(vin, null); - } - - public VehicleIdentificationNumberNotFoundException(VehicleIdentificationNumber vin, Throwable cause) { - super("Unable to find VehicleIdentificationNumber " + vin, cause); - this.vehicleIdentificationNumber = vin; - } - - public VehicleIdentificationNumber getVehicleIdentificationNumber() { - return this.vehicleIdentificationNumber; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserNameNotFoundException.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserNameNotFoundException.java deleted file mode 100644 index 1de29bc0f3..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserNameNotFoundException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.web; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(HttpStatus.NOT_FOUND) -public class UserNameNotFoundException extends RuntimeException { - - private final String username; - - public UserNameNotFoundException(String username) { - this.username = username; - } - - public String getUsername() { - return this.username; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserVehicleController.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserVehicleController.java deleted file mode 100644 index 9fc6f41e57..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserVehicleController.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.web; - -import sample.test.domain.User; -import sample.test.service.VehicleDetails; -import sample.test.service.VehicleIdentificationNumberNotFoundException; - -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; - -/** - * Controller to return vehicle information for a given {@link User}. - * - * @author Phillip Webb - */ -@RestController -public class UserVehicleController { - - private UserVehicleService userVehicleService; - - public UserVehicleController(UserVehicleService userVehicleService) { - this.userVehicleService = userVehicleService; - } - - @GetMapping(path = "/{username}/vehicle", produces = MediaType.TEXT_PLAIN_VALUE) - public String getVehicleDetailsText(@PathVariable String username) { - VehicleDetails details = this.userVehicleService.getVehicleDetails(username); - return details.getMake() + " " + details.getModel(); - } - - @GetMapping(path = "/{username}/vehicle", produces = MediaType.APPLICATION_JSON_VALUE) - public VehicleDetails VehicleDetailsJson(@PathVariable String username) { - return this.userVehicleService.getVehicleDetails(username); - } - - @GetMapping(path = "/{username}/vehicle.html", produces = MediaType.TEXT_HTML_VALUE) - public String VehicleDetailsHtml(@PathVariable String username) { - VehicleDetails details = this.userVehicleService.getVehicleDetails(username); - String makeAndModel = details.getMake() + " " + details.getModel(); - return "<html><body><h1>" + makeAndModel + "</h1></body></html>"; - } - - @ExceptionHandler - @ResponseStatus(HttpStatus.NOT_FOUND) - private void handleVinNotFound(VehicleIdentificationNumberNotFoundException ex) { - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserVehicleService.java b/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserVehicleService.java deleted file mode 100644 index 8b22f4dd8d..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/main/java/sample/test/web/UserVehicleService.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.web; - -import sample.test.domain.User; -import sample.test.domain.UserRepository; -import sample.test.service.VehicleDetails; -import sample.test.service.VehicleDetailsService; -import sample.test.service.VehicleIdentificationNumberNotFoundException; - -import org.springframework.stereotype.Component; -import org.springframework.util.Assert; - -/** - * Controller service used to provide vehicle information for a given user. - * - * @author Phillip Webb - */ -@Component -public class UserVehicleService { - - private final UserRepository userRepository; - - private final VehicleDetailsService vehicleDetailsService; - - public UserVehicleService(UserRepository userRepository, VehicleDetailsService vehicleDetailsService) { - this.userRepository = userRepository; - this.vehicleDetailsService = vehicleDetailsService; - } - - public VehicleDetails getVehicleDetails(String username) - throws UserNameNotFoundException, VehicleIdentificationNumberNotFoundException { - Assert.notNull(username, "Username must not be null"); - User user = this.userRepository.findByUsername(username); - if (user == null) { - throw new UserNameNotFoundException(username); - } - return this.vehicleDetailsService.getVehicleDetails(user.getVin()); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java deleted file mode 100644 index bd60574170..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import sample.test.domain.VehicleIdentificationNumber; -import sample.test.service.VehicleDetails; -import sample.test.service.VehicleDetailsService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.web.client.TestRestTemplate; - -import static org.mockito.BDDMockito.given; - -/** - * {@code @SpringBootTest} with a random port for {@link SampleTestApplication}. - * - * @author Phillip Webb - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@AutoConfigureTestDatabase -class SampleTestApplicationWebIntegrationTests { - - private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("01234567890123456"); - - @Autowired - private TestRestTemplate restTemplate; - - @MockBean - private VehicleDetailsService vehicleDetailsService; - - @BeforeEach - void setup() { - given(this.vehicleDetailsService.getVehicleDetails(VIN)).willReturn(new VehicleDetails("Honda", "Civic")); - } - - @Test - void test() { - this.restTemplate.getForEntity("/{username}/vehicle", String.class, "sframework"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserEntityTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserEntityTests.java deleted file mode 100644 index 16dfc7ea7b..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserEntityTests.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.domain; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; - -/** - * Data JPA tests for {@link User}. - * - * @author Phillip Webb - */ -@DataJpaTest -class UserEntityTests { - - private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("00000000000000000"); - - @Autowired - private TestEntityManager entityManager; - - @Test - void createWhenUsernameIsNullShouldThrowException() { - assertThatIllegalArgumentException().isThrownBy(() -> new User(null, VIN)) - .withMessage("Username must not be empty"); - } - - @Test - void createWhenUsernameIsEmptyShouldThrowException() { - assertThatIllegalArgumentException().isThrownBy(() -> new User("", VIN)) - .withMessage("Username must not be empty"); - } - - @Test - void createWhenVinIsNullShouldThrowException() { - assertThatIllegalArgumentException().isThrownBy(() -> new User("sboot", null)) - .withMessage("VIN must not be null"); - } - - @Test - void saveShouldPersistData() { - User user = this.entityManager.persistFlushFind(new User("sboot", VIN)); - assertThat(user.getUsername()).isEqualTo("sboot"); - assertThat(user.getVin()).isEqualTo(VIN); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserRepositoryTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserRepositoryTests.java deleted file mode 100644 index 9479c8205c..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/UserRepositoryTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.domain; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link UserRepository}. - * - * @author Phillip Webb - */ -@DataJpaTest -class UserRepositoryTests { - - private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("00000000000000000"); - - @Autowired - private TestEntityManager entityManager; - - @Autowired - private UserRepository repository; - - @Test - void findByUsernameShouldReturnUser() { - this.entityManager.persist(new User("sboot", VIN)); - User user = this.repository.findByUsername("sboot"); - assertThat(user.getUsername()).isEqualTo("sboot"); - assertThat(user.getVin()).isEqualTo(VIN); - } - - @Test - void findByUsernameWhenNoUserShouldReturnNull() { - this.entityManager.persist(new User("sboot", VIN)); - User user = this.repository.findByUsername("mmouse"); - assertThat(user).isNull(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/VehicleIdentificationNumberTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/VehicleIdentificationNumberTests.java deleted file mode 100644 index 4dc8e04582..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/domain/VehicleIdentificationNumberTests.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.domain; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; - -/** - * Tests for {@link VehicleIdentificationNumber}. - * - * @author Phillip Webb - * @see <a href="https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html"> - * Naming standards for unit tests</a> - * @see <a href="https://joel-costigliola.github.io/assertj/">AssertJ</a> - */ -class VehicleIdentificationNumberTests { - - private static final String SAMPLE_VIN = "41549485710496749"; - - @Test - void createWhenVinIsNullShouldThrowException() { - assertThatIllegalArgumentException().isThrownBy(() -> new VehicleIdentificationNumber(null)) - .withMessage("VIN must not be null"); - } - - @Test - void createWhenVinIsMoreThan17CharsShouldThrowException() { - assertThatIllegalArgumentException().isThrownBy(() -> new VehicleIdentificationNumber("012345678901234567")) - .withMessage("VIN must be exactly 17 characters"); - } - - @Test - void createWhenVinIsLessThan17CharsShouldThrowException() { - assertThatIllegalArgumentException().isThrownBy(() -> new VehicleIdentificationNumber("0123456789012345")) - .withMessage("VIN must be exactly 17 characters"); - } - - @Test - void toStringShouldReturnVin() { - VehicleIdentificationNumber vin = new VehicleIdentificationNumber(SAMPLE_VIN); - assertThat(vin.toString()).isEqualTo(SAMPLE_VIN); - } - - @Test - void equalsAndHashCodeShouldBeBasedOnVin() { - VehicleIdentificationNumber vin1 = new VehicleIdentificationNumber(SAMPLE_VIN); - VehicleIdentificationNumber vin2 = new VehicleIdentificationNumber(SAMPLE_VIN); - VehicleIdentificationNumber vin3 = new VehicleIdentificationNumber("00000000000000000"); - assertThat(vin1.hashCode()).isEqualTo(vin2.hashCode()); - assertThat(vin1).isEqualTo(vin1).isEqualTo(vin2).isNotEqualTo(vin3); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/RemoteVehicleDetailsServiceTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/RemoteVehicleDetailsServiceTests.java deleted file mode 100644 index 8e84495383..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/RemoteVehicleDetailsServiceTests.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.service; - -import org.junit.jupiter.api.Test; -import sample.test.domain.VehicleIdentificationNumber; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; -import org.springframework.core.io.ClassPathResource; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.test.web.client.MockRestServiceServer; -import org.springframework.web.client.HttpServerErrorException; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withServerError; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; - -/** - * Tests for {@link RemoteVehicleDetailsService}. - * - * @author Phillip Webb - */ -@RestClientTest({ RemoteVehicleDetailsService.class, ServiceProperties.class }) -class RemoteVehicleDetailsServiceTests { - - private static final String VIN = "00000000000000000"; - - @Autowired - private RemoteVehicleDetailsService service; - - @Autowired - private MockRestServiceServer server; - - @Test - void getVehicleDetailsWhenVinIsNullShouldThrowException() { - assertThatIllegalArgumentException().isThrownBy(() -> this.service.getVehicleDetails(null)) - .withMessage("VIN must not be null"); - } - - @Test - void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails() { - this.server.expect(requestTo("/vehicle/" + VIN + "/details")) - .andRespond(withSuccess(getClassPathResource("vehicledetails.json"), MediaType.APPLICATION_JSON)); - VehicleDetails details = this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN)); - assertThat(details.getMake()).isEqualTo("Honda"); - assertThat(details.getModel()).isEqualTo("Civic"); - } - - @Test - void getVehicleDetailsWhenResultIsNotFoundShouldThrowException() { - this.server.expect(requestTo("/vehicle/" + VIN + "/details")).andRespond(withStatus(HttpStatus.NOT_FOUND)); - assertThatExceptionOfType(VehicleIdentificationNumberNotFoundException.class) - .isThrownBy(() -> this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN))); - } - - @Test - void getVehicleDetailsWhenResultIServerErrorShouldThrowException() { - this.server.expect(requestTo("/vehicle/" + VIN + "/details")).andRespond(withServerError()); - assertThatExceptionOfType(HttpServerErrorException.class) - .isThrownBy(() -> this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN))); - } - - private ClassPathResource getClassPathResource(String path) { - return new ClassPathResource(path, getClass()); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/VehicleDetailsJsonTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/VehicleDetailsJsonTests.java deleted file mode 100644 index f0ad51d709..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/service/VehicleDetailsJsonTests.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.service; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.json.JsonTest; -import org.springframework.boot.test.json.JacksonTester; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * JSON tests for {@link VehicleDetails}. - * - * @author Phillip Webb - */ -@JsonTest -class VehicleDetailsJsonTests { - - @Autowired - private JacksonTester<VehicleDetails> json; - - @Test - void serializeJson() throws Exception { - VehicleDetails details = new VehicleDetails("Honda", "Civic"); - assertThat(this.json.write(details)).isEqualTo("vehicledetails.json"); - assertThat(this.json.write(details)).isEqualToJson("vehicledetails.json"); - assertThat(this.json.write(details)).hasJsonPathStringValue("@.make"); - assertThat(this.json.write(details)).extractingJsonPathStringValue("@.make").isEqualTo("Honda"); - } - - @Test - void deserializeJson() throws Exception { - String content = "{\"make\":\"Ford\",\"model\":\"Focus\"}"; - assertThat(this.json.parse(content)).isEqualTo(new VehicleDetails("Ford", "Focus")); - assertThat(this.json.parseObject(content).getMake()).isEqualTo("Ford"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerApplicationTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerApplicationTests.java deleted file mode 100644 index e2339cc116..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerApplicationTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.web; - -import org.junit.jupiter.api.Test; -import sample.test.WelcomeCommandLineRunner; -import sample.test.service.VehicleDetails; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.ApplicationContext; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * {@code @SpringBootTest} based tests for {@link UserVehicleController}. - * - * @author Phillip Webb - */ -@SpringBootTest -@AutoConfigureMockMvc -@AutoConfigureTestDatabase -class UserVehicleControllerApplicationTests { - - @Autowired - private MockMvc mvc; - - @Autowired - private ApplicationContext applicationContext; - - @MockBean - private UserVehicleService userVehicleService; - - @Test - void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); - this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk()) - .andExpect(content().string("Honda Civic")); - } - - @Test - void welcomeCommandLineRunnerShouldBeAvailable() { - // Since we're a @SpringBootTest all beans should be available. - assertThat(this.applicationContext.getBean(WelcomeCommandLineRunner.class)).isNotNull(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerHtmlUnitTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerHtmlUnitTests.java deleted file mode 100644 index 5e9f5d7965..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerHtmlUnitTests.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.web; - -import com.gargoylesoftware.htmlunit.WebClient; -import com.gargoylesoftware.htmlunit.html.HtmlPage; -import org.junit.jupiter.api.Test; -import sample.test.service.VehicleDetails; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; - -/** - * HtmlUnit based tests for {@link UserVehicleController}. - * - * @author Phillip Webb - */ -@WebMvcTest(UserVehicleController.class) -class UserVehicleControllerHtmlUnitTests { - - @Autowired - private WebClient webClient; - - @MockBean - private UserVehicleService userVehicleService; - - @Test - void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); - HtmlPage page = this.webClient.getPage("/sboot/vehicle.html"); - assertThat(page.getBody().getTextContent()).isEqualTo("Honda Civic"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerSeleniumTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerSeleniumTests.java deleted file mode 100644 index 4d3214427b..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerSeleniumTests.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.web; - -import org.junit.jupiter.api.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import sample.test.service.VehicleDetails; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; - -/** - * Selenium based tests for {@link UserVehicleController}. - * - * @author Phillip Webb - */ -@WebMvcTest(UserVehicleController.class) -class UserVehicleControllerSeleniumTests { - - @Autowired - private WebDriver webDriver; - - @MockBean - private UserVehicleService userVehicleService; - - @Test - void getVehicleWhenRequestingTextShouldReturnMakeAndModel() { - given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); - this.webDriver.get("/sboot/vehicle.html"); - WebElement element = this.webDriver.findElement(By.tagName("h1")); - assertThat(element.getText()).isEqualTo("Honda Civic"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerTests.java deleted file mode 100644 index f82c2224b6..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerTests.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.web; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; -import sample.test.WelcomeCommandLineRunner; -import sample.test.domain.VehicleIdentificationNumber; -import sample.test.service.VehicleDetails; -import sample.test.service.VehicleIdentificationNumberNotFoundException; - -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.ApplicationContext; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; - -import static org.hamcrest.Matchers.containsString; -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * {@code @WebMvcTest} based tests for {@link UserVehicleController}. - * - * @author Phillip Webb - */ -@WebMvcTest(UserVehicleController.class) -class UserVehicleControllerTests { - - private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("00000000000000000"); - - @Autowired - private MockMvc mvc; - - @Autowired - private ApplicationContext applicationContext; - - @MockBean - private UserVehicleService userVehicleService; - - @Test - void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); - this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk()) - .andExpect(content().string("Honda Civic")); - } - - @Test - void getVehicleWhenRequestingJsonShouldReturnMakeAndModel() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); - this.mvc.perform(get("/sboot/vehicle").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) - .andExpect(content().json("{'make':'Honda','model':'Civic'}")); - } - - @Test - void getVehicleWhenRequestingHtmlShouldReturnMakeAndModel() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); - this.mvc.perform(get("/sboot/vehicle.html").accept(MediaType.TEXT_HTML)).andExpect(status().isOk()) - .andExpect(content().string(containsString("<h1>Honda Civic</h1>"))); - } - - @Test - void getVehicleWhenUserNotFoundShouldReturnNotFound() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")).willThrow(new UserNameNotFoundException("sboot")); - this.mvc.perform(get("/sboot/vehicle")).andExpect(status().isNotFound()); - } - - @Test - void getVehicleWhenVinNotFoundShouldReturnNotFound() throws Exception { - given(this.userVehicleService.getVehicleDetails("sboot")) - .willThrow(new VehicleIdentificationNumberNotFoundException(VIN)); - this.mvc.perform(get("/sboot/vehicle")).andExpect(status().isNotFound()); - } - - @Test - void welcomeCommandLineRunnerShouldBeAvailable() { - // Since we're a @WebMvcTest WelcomeCommandLineRunner should not be available. - Assertions.assertThatThrownBy(() -> this.applicationContext.getBean(WelcomeCommandLineRunner.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleServiceTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleServiceTests.java deleted file mode 100644 index a847b33812..0000000000 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleServiceTests.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.test.web; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import sample.test.domain.User; -import sample.test.domain.UserRepository; -import sample.test.domain.VehicleIdentificationNumber; -import sample.test.service.VehicleDetails; -import sample.test.service.VehicleDetailsService; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.BDDMockito.given; - -/** - * Tests for {@link UserVehicleService}. - * - * @author Phillip Webb - */ -class UserVehicleServiceTests { - - private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("00000000000000000"); - - @Mock - private VehicleDetailsService vehicleDetailsService; - - @Mock - private UserRepository userRepository; - - private UserVehicleService service; - - @BeforeEach - void setup() { - MockitoAnnotations.initMocks(this); - this.service = new UserVehicleService(this.userRepository, this.vehicleDetailsService); - } - - @Test - void getVehicleDetailsWhenUsernameIsNullShouldThrowException() { - assertThatIllegalArgumentException().isThrownBy(() -> this.service.getVehicleDetails(null)) - .withMessage("Username must not be null"); - } - - @Test - void getVehicleDetailsWhenUsernameNotFoundShouldThrowException() { - given(this.userRepository.findByUsername(anyString())).willReturn(null); - assertThatExceptionOfType(UserNameNotFoundException.class) - .isThrownBy(() -> this.service.getVehicleDetails("sboot")); - } - - @Test - void getVehicleDetailsShouldReturnMakeAndModel() { - given(this.userRepository.findByUsername(anyString())).willReturn(new User("sboot", VIN)); - VehicleDetails details = new VehicleDetails("Honda", "Civic"); - given(this.vehicleDetailsService.getVehicleDetails(VIN)).willReturn(details); - VehicleDetails actual = this.service.getVehicleDetails("sboot"); - assertThat(actual).isEqualTo(details); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-testng/pom.xml b/spring-boot-samples/spring-boot-sample-testng/pom.xml deleted file mode 100644 index 6507f0ac76..0000000000 --- a/spring-boot-samples/spring-boot-sample-testng/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-testng</artifactId> - <name>Spring Boot TestNG Sample</name> - <description>Spring Boot TestNG Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-webmvc</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <version>6.8.13</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-core</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/SampleTestNGApplication.java b/spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/SampleTestNGApplication.java deleted file mode 100644 index 926597e693..0000000000 --- a/spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/SampleTestNGApplication.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.testng; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -public class SampleTestNGApplication { - - private static Log logger = LogFactory.getLog(SampleTestNGApplication.class); - - @Bean - protected ServletContextListener listener() { - return new ServletContextListener() { - - @Override - public void contextInitialized(ServletContextEvent sce) { - logger.info("ServletContext initialized"); - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - logger.info("ServletContext destroyed"); - } - - }; - } - - public static void main(String[] args) { - SpringApplication.run(SampleTestNGApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/service/HelloWorldService.java deleted file mode 100644 index e851ddf778..0000000000 --- a/spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/service/HelloWorldService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.testng.service; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - @Value("${name:World}") - private String name; - - public String getHelloMessage() { - return "Hello " + this.name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/web/SampleController.java b/spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/web/SampleController.java deleted file mode 100644 index 571fadd82b..0000000000 --- a/spring-boot-samples/spring-boot-sample-testng/src/main/java/sample/testng/web/SampleController.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.testng.web; - -import sample.testng.service.HelloWorldService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class SampleController { - - @Autowired - private HelloWorldService helloWorldService; - - @GetMapping("/") - @ResponseBody - public String helloWorld() { - return this.helloWorldService.getHelloMessage(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java b/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java deleted file mode 100644 index 6571378ef8..0000000000 --- a/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.testng; - -import org.testng.annotations.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Phillip Webb - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleTestNGApplicationTests extends AbstractTestNGSpringContextTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHome() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("Hello World"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/pom.xml b/spring-boot-samples/spring-boot-sample-tomcat-jsp/pom.xml deleted file mode 100644 index 57f0b1d5be..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-jsp/pom.xml +++ /dev/null @@ -1,57 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-tomcat-jsp</artifactId> - <packaging>war</packaging> - <name>Spring Boot Tomcat JSP Sample</name> - <description>Spring Boot Tomcat JSP Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>jstl</artifactId> - </dependency> - <!-- Provided --> - <dependency> - <groupId>org.apache.tomcat.embed</groupId> - <artifactId>tomcat-embed-jasper</artifactId> - <scope>provided</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <useSystemClassLoader>false</useSystemClassLoader> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/MyException.java b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/MyException.java deleted file mode 100644 index c2a1048401..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/MyException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.jsp; - -public class MyException extends RuntimeException { - - public MyException(String message) { - super(message); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/MyRestResponse.java b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/MyRestResponse.java deleted file mode 100644 index 8be2d3f936..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/MyRestResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.jsp; - -public class MyRestResponse { - - private String message; - - public MyRestResponse(String message) { - this.message = message; - } - - public String getMessage() { - return this.message; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/SampleTomcatJspApplication.java b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/SampleTomcatJspApplication.java deleted file mode 100644 index fee593d637..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/SampleTomcatJspApplication.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.jsp; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; - -@SpringBootApplication -public class SampleTomcatJspApplication extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleTomcatJspApplication.class); - } - - public static void main(String[] args) { - SpringApplication.run(SampleTomcatJspApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/WelcomeController.java b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/WelcomeController.java deleted file mode 100644 index 89e437171e..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/java/sample/tomcat/jsp/WelcomeController.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.jsp; - -import java.util.Date; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; - -@Controller -public class WelcomeController { - - @Value("${application.message:Hello World}") - private String message = "Hello World"; - - @GetMapping("/") - public String welcome(Map<String, Object> model) { - model.put("time", new Date()); - model.put("message", this.message); - return "welcome"; - } - - @RequestMapping("/fail") - public String fail() { - throw new MyException("Oh dear!"); - } - - @RequestMapping("/fail2") - public String fail2() { - throw new IllegalStateException(); - } - - @ExceptionHandler(MyException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - public @ResponseBody MyRestResponse handleMyRuntimeException(MyException exception) { - return new MyRestResponse("Some data I want to send back to the client."); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java deleted file mode 100644 index 20deeb1a19..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.jsp; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for JSP application. - * - * @author Phillip Webb - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebJspApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testJspWithEl() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("/resources/text.txt"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/pom.xml b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/pom.xml deleted file mode 100644 index 4b51173be7..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-tomcat-multi-connectors</artifactId> - <name>Spring Boot Multi-Connector Tomcat Sample</name> - <description>Spring Boot Multi-Connector Tomcat Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java deleted file mode 100644 index 734e0f34b5..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.multiconnector; - -import org.apache.catalina.connector.Connector; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; -import org.springframework.boot.web.servlet.server.ServletWebServerFactory; -import org.springframework.context.annotation.Bean; - -/** - * Sample Application to show Tomcat running two connectors. - * - * @author Brock Mills - * @author Andy Wilkinson - */ -@SpringBootApplication -public class SampleTomcatTwoConnectorsApplication { - - @Bean - public ServletWebServerFactory servletContainer() { - TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); - tomcat.addAdditionalTomcatConnectors(createStandardConnector()); - return tomcat; - } - - private Connector createStandardConnector() { - Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); - connector.setPort(0); - return connector; - } - - public static void main(String[] args) { - SpringApplication.run(SampleTomcatTwoConnectorsApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/web/SampleController.java b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/web/SampleController.java deleted file mode 100644 index 02fef2fbe8..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/web/SampleController.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.multiconnector.web; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class SampleController { - - @GetMapping("/hello") - public String helloWorld() { - return "hello"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java deleted file mode 100644 index 726046a603..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.multiconnector; - -import org.apache.catalina.Service; -import org.apache.catalina.connector.Connector; -import org.junit.jupiter.api.Test; -import sample.tomcat.multiconnector.SampleTomcatTwoConnectorsApplicationTests.Ports; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.context.WebServerInitializedEvent; -import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; -import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.context.ApplicationListener; -import org.springframework.context.annotation.Import; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for {@link SampleTomcatTwoConnectorsApplication}. - * - * @author Brock Mills - * @author Andy Wilkinson - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@Import(Ports.class) -class SampleTomcatTwoConnectorsApplicationTests { - - @LocalServerPort - private int port; - - @Autowired - private Ports ports; - - @Autowired - private TestRestTemplate restTemplate; - - @Autowired - private AbstractConfigurableWebServerFactory webServerFactory; - - @Test - void testSsl() { - assertThat(this.webServerFactory.getSsl().isEnabled()).isTrue(); - } - - @Test - void testHello() { - assertThat(this.ports.getHttpsPort()).isEqualTo(this.port); - assertThat(this.ports.getHttpPort()).isNotEqualTo(this.port); - ResponseEntity<String> entity = this.restTemplate - .getForEntity("http://localhost:" + this.ports.getHttpPort() + "/hello", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("hello"); - ResponseEntity<String> httpsEntity = this.restTemplate.getForEntity("https://localhost:" + this.port + "/hello", - String.class); - assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(httpsEntity.getBody()).isEqualTo("hello"); - } - - @TestConfiguration - static class Ports implements ApplicationListener<WebServerInitializedEvent> { - - private int httpPort; - - private int httpsPort; - - @Override - public void onApplicationEvent(WebServerInitializedEvent event) { - Service service = ((TomcatWebServer) event.getWebServer()).getTomcat().getService(); - for (Connector connector : service.findConnectors()) { - if (connector.getSecure()) { - this.httpsPort = connector.getLocalPort(); - } - else { - this.httpPort = connector.getLocalPort(); - } - } - } - - int getHttpPort() { - return this.httpPort; - } - - int getHttpsPort() { - return this.httpsPort; - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-ssl/pom.xml b/spring-boot-samples/spring-boot-sample-tomcat-ssl/pom.xml deleted file mode 100644 index 4992e1c16d..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-ssl/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-tomcat-ssl</artifactId> - <name>Spring Boot Tomcat SSL Sample</name> - <description>Spring Boot Tomcat SSL Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/java/sample/tomcat/ssl/SampleTomcatSslApplication.java b/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/java/sample/tomcat/ssl/SampleTomcatSslApplication.java deleted file mode 100644 index 1fbcee25dc..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/java/sample/tomcat/ssl/SampleTomcatSslApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.ssl; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleTomcatSslApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleTomcatSslApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/java/sample/tomcat/ssl/web/SampleController.java b/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/java/sample/tomcat/ssl/web/SampleController.java deleted file mode 100644 index ff00b315c5..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/java/sample/tomcat/ssl/web/SampleController.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.ssl.web; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class SampleController { - - @GetMapping("/") - public String helloWorld() { - return "Hello, world"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/ssl/SampleTomcatSslApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/ssl/SampleTomcatSslApplicationTests.java deleted file mode 100644 index 0aaaa5fbd0..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/ssl/SampleTomcatSslApplicationTests.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.ssl; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleTomcatSslApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Autowired - private AbstractConfigurableWebServerFactory webServerFactory; - - @Test - void testSsl() { - assertThat(this.webServerFactory.getSsl().isEnabled()).isTrue(); - } - - @Test - void testHome() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("Hello, world"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat/pom.xml b/spring-boot-samples/spring-boot-sample-tomcat/pom.xml deleted file mode 100644 index 0af0428885..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-tomcat</artifactId> - <name>Spring Boot Tomcat Sample</name> - <description>Spring Boot Tomcat Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-webmvc</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/main/java/sample/tomcat/SampleTomcatApplication.java b/spring-boot-samples/spring-boot-sample-tomcat/src/main/java/sample/tomcat/SampleTomcatApplication.java deleted file mode 100644 index a16ccac913..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/main/java/sample/tomcat/SampleTomcatApplication.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -public class SampleTomcatApplication { - - private static Log logger = LogFactory.getLog(SampleTomcatApplication.class); - - @Bean - protected ServletContextListener listener() { - return new ServletContextListener() { - - @Override - public void contextInitialized(ServletContextEvent sce) { - logger.info("ServletContext initialized"); - } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - logger.info("ServletContext destroyed"); - } - - }; - } - - public static void main(String[] args) { - SpringApplication.run(SampleTomcatApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/main/java/sample/tomcat/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-tomcat/src/main/java/sample/tomcat/service/HelloWorldService.java deleted file mode 100644 index 095a009d03..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/main/java/sample/tomcat/service/HelloWorldService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.service; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - @Value("${name:World}") - private String name; - - public String getHelloMessage() { - return "Hello " + this.name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/main/java/sample/tomcat/web/SampleController.java b/spring-boot-samples/spring-boot-sample-tomcat/src/main/java/sample/tomcat/web/SampleController.java deleted file mode 100644 index d608fff1b8..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/main/java/sample/tomcat/web/SampleController.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat.web; - -import sample.tomcat.service.HelloWorldService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class SampleController { - - @Autowired - private HelloWorldService helloWorldService; - - @GetMapping("/") - @ResponseBody - public String helloWorld() { - return this.helloWorldService.getHelloMessage(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java deleted file mode 100644 index c672685675..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat; - -import org.junit.jupiter.api.Test; -import sample.tomcat.service.HelloWorldService; -import sample.tomcat.web.SampleController; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration; -import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; -import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class NonAutoConfigurationSampleTomcatApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHome() throws Exception { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("Hello World"); - } - - @Configuration(proxyBeanMethods = false) - @Import({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, - WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, - PropertyPlaceholderAutoConfiguration.class }) - @ComponentScan(basePackageClasses = { SampleController.class, HelloWorldService.class }) - public static class NonAutoConfigurationSampleTomcatApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleTomcatApplication.class, args); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java deleted file mode 100644 index e51663520d..0000000000 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.tomcat; - -import java.io.ByteArrayInputStream; -import java.nio.charset.StandardCharsets; -import java.util.zip.GZIPInputStream; - -import org.apache.coyote.AbstractProtocol; -import org.apache.coyote.ProtocolHandler; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; -import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; -import org.springframework.context.ApplicationContext; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.util.StreamUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - * @author Andy Wilkinson - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleTomcatApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Autowired - private ApplicationContext applicationContext; - - @Test - void testHome() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("Hello World"); - } - - @Test - void testCompression() throws Exception { - HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.set("Accept-Encoding", "gzip"); - HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders); - ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - try (GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()))) { - assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)).isEqualTo("Hello World"); - } - } - - @Test - void testTimeout() { - ServletWebServerApplicationContext context = (ServletWebServerApplicationContext) this.applicationContext; - TomcatWebServer embeddedServletContainer = (TomcatWebServer) context.getWebServer(); - ProtocolHandler protocolHandler = embeddedServletContainer.getTomcat().getConnector().getProtocolHandler(); - int timeout = ((AbstractProtocol<?>) protocolHandler).getConnectionTimeout(); - assertThat(timeout).isEqualTo(5000); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-traditional/pom.xml b/spring-boot-samples/spring-boot-sample-traditional/pom.xml deleted file mode 100644 index b285d11709..0000000000 --- a/spring-boot-samples/spring-boot-sample-traditional/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-traditional</artifactId> - <packaging>war</packaging> - <name>Spring Boot Traditional Sample</name> - <description>Spring Boot Traditional Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-webmvc</artifactId> - </dependency> - <!-- Provided (for embedded war support) --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.tomcat.embed</groupId> - <artifactId>tomcat-embed-jasper</artifactId> - <scope>provided</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/main/java/sample/traditional/SampleTraditionalApplication.java b/spring-boot-samples/spring-boot-sample-traditional/src/main/java/sample/traditional/SampleTraditionalApplication.java deleted file mode 100644 index fca2258b19..0000000000 --- a/spring-boot-samples/spring-boot-sample-traditional/src/main/java/sample/traditional/SampleTraditionalApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.traditional; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleTraditionalApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleTraditionalApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/main/java/sample/traditional/config/WebConfig.java b/spring-boot-samples/spring-boot-sample-traditional/src/main/java/sample/traditional/config/WebConfig.java deleted file mode 100644 index f297f30e02..0000000000 --- a/spring-boot-samples/spring-boot-sample-traditional/src/main/java/sample/traditional/config/WebConfig.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.traditional.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.DispatcherServlet; -import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.web.servlet.view.InternalResourceViewResolver; - -@EnableWebMvc -@ComponentScan -@Configuration(proxyBeanMethods = false) -public class WebConfig implements WebMvcConfigurer { - - @Override - public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/").setViewName("home"); - } - - @Bean - public InternalResourceViewResolver viewResolver() { - InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); - viewResolver.setPrefix("/WEB-INF/views/"); - viewResolver.setSuffix(".jsp"); - return viewResolver; - } - - @Bean - // Only used when running in embedded servlet - public DispatcherServlet dispatcherServlet() { - return new DispatcherServlet(); - } - - @Override - public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { - configurer.enable(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java b/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java deleted file mode 100644 index a96db51f5d..0000000000 --- a/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.traditional; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleTraditionalApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHomeJsp() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - String body = entity.getBody(); - assertThat(body).contains("<html>").contains("<h1>Home</h1>"); - } - - @Test - void testStaticPage() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/index.html", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - String body = entity.getBody(); - assertThat(body).contains("<html>").contains("<h1>Hello</h1>"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-undertow-ssl/pom.xml b/spring-boot-samples/spring-boot-sample-undertow-ssl/pom.xml deleted file mode 100644 index e92d770b72..0000000000 --- a/spring-boot-samples/spring-boot-sample-undertow-ssl/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-undertow-ssl</artifactId> - <name>Spring Boot Undertow SSL Sample</name> - <description>Spring Boot Undertow SSL Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-undertow</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/java/sample/undertow/ssl/SampleUndertowSslApplication.java b/spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/java/sample/undertow/ssl/SampleUndertowSslApplication.java deleted file mode 100644 index 4c3c4150a5..0000000000 --- a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/java/sample/undertow/ssl/SampleUndertowSslApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.undertow.ssl; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleUndertowSslApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleUndertowSslApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/java/sample/undertow/ssl/web/SampleController.java b/spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/java/sample/undertow/ssl/web/SampleController.java deleted file mode 100644 index d7f5366357..0000000000 --- a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/java/sample/undertow/ssl/web/SampleController.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.undertow.ssl.web; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class SampleController { - - @GetMapping("/") - public String helloWorld() { - return "Hello World"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java b/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java deleted file mode 100644 index 1f7a28d62f..0000000000 --- a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.undertow.ssl; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Ivan Sopov - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleUndertowSslApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Autowired - private AbstractConfigurableWebServerFactory webServerFactory; - - @Test - void testSsl() { - assertThat(this.webServerFactory.getSsl().isEnabled()).isTrue(); - } - - @Test - void testHome() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo("Hello World"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-undertow/pom.xml b/spring-boot-samples/spring-boot-sample-undertow/pom.xml deleted file mode 100644 index a8aa5e498c..0000000000 --- a/spring-boot-samples/spring-boot-sample-undertow/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-undertow</artifactId> - <name>Spring Boot Undertow Sample</name> - <description>Spring Boot Undertow Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-undertow</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-undertow/src/main/java/sample/undertow/SampleUndertowApplication.java b/spring-boot-samples/spring-boot-sample-undertow/src/main/java/sample/undertow/SampleUndertowApplication.java deleted file mode 100644 index 9e5f04218d..0000000000 --- a/spring-boot-samples/spring-boot-sample-undertow/src/main/java/sample/undertow/SampleUndertowApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.undertow; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleUndertowApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleUndertowApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-undertow/src/main/java/sample/undertow/web/SampleController.java b/spring-boot-samples/spring-boot-sample-undertow/src/main/java/sample/undertow/web/SampleController.java deleted file mode 100644 index 29cdeeb180..0000000000 --- a/spring-boot-samples/spring-boot-sample-undertow/src/main/java/sample/undertow/web/SampleController.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.undertow.web; - -import java.util.concurrent.Callable; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class SampleController { - - @GetMapping("/") - public String helloWorld() { - return "Hello World"; - } - - @GetMapping("/async") - public Callable<String> helloWorldAsync() { - return () -> "async: Hello World"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java b/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java deleted file mode 100644 index 973431aa75..0000000000 --- a/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.undertow; - -import java.io.ByteArrayInputStream; -import java.nio.charset.StandardCharsets; -import java.util.zip.GZIPInputStream; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.util.StreamUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Ivan Sopov - * @author Andy Wilkinson - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleUndertowApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHome() { - assertOkResponse("/", "Hello World"); - } - - @Test - void testAsync() { - assertOkResponse("/async", "async: Hello World"); - } - - @Test - void testCompression() throws Exception { - HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.set("Accept-Encoding", "gzip"); - HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders); - ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - - try (GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()))) { - assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)).isEqualTo("Hello World"); - } - } - - private void assertOkResponse(String path, String body) { - ResponseEntity<String> entity = this.restTemplate.getForEntity(path, String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).isEqualTo(body); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-war/pom.xml b/spring-boot-samples/spring-boot-sample-war/pom.xml deleted file mode 100644 index ab81f16ef6..0000000000 --- a/spring-boot-samples/spring-boot-sample-war/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-war</artifactId> - <packaging>war</packaging> - <name>Spring Boot War Sample</name> - <description>Spring Boot War Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <dependency> - <!-- To build an executable war use one of the profiles below --> - <groupId>jakarta.servlet</groupId> - <artifactId>jakarta.servlet-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </exclusion> - </exclusions> - </dependency> - <!-- Provided --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-devtools</artifactId> - <scope>provided</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>tomcat</id> - <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - <scope>provided</scope> - </dependency> - </dependencies> - </profile> - <profile> - <id>jetty</id> - <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jetty</artifactId> - <scope>provided</scope> - </dependency> - </dependencies> - </profile> - <profile> - <id>undertow</id> - <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-undertow</artifactId> - <scope>provided</scope> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/MyController.java b/spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/MyController.java deleted file mode 100644 index 21d9995b1e..0000000000 --- a/spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/MyController.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.war; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class MyController { - - @GetMapping("/") - public String hello() { - return "Hello World!"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/SampleWarApplication.java b/spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/SampleWarApplication.java deleted file mode 100644 index c459e61bcb..0000000000 --- a/spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/SampleWarApplication.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.war; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.PropertySource; - -@SpringBootApplication -@PropertySource("WEB-INF/custom.properties") -public class SampleWarApplication extends SpringBootServletInitializer { - - public static void main(String[] args) { - SpringApplication.run(SampleWarApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-war/src/test/java/sample/war/WarApplicationResourceTests.java b/spring-boot-samples/spring-boot-sample-war/src/test/java/sample/war/WarApplicationResourceTests.java deleted file mode 100644 index 14d565f776..0000000000 --- a/spring-boot-samples/spring-boot-sample-war/src/test/java/sample/war/WarApplicationResourceTests.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.war; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest -class WarApplicationResourceTests { - - // gh-6371 - - @Value("${demo.string.value}") - private String demoStringValue; - - @Test - void contextLoads() { - assertThat(this.demoStringValue).isEqualTo("demo"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-freemarker/pom.xml b/spring-boot-samples/spring-boot-sample-web-freemarker/pom.xml deleted file mode 100644 index 60d3544405..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-freemarker/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-web-freemarker</artifactId> - <name>Spring Boot Web FreeMarker Sample</name> - <description>Spring Boot Web FreeMarker Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-freemarker</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <configuration> - <executable>true</executable> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <useSystemClassLoader>false</useSystemClassLoader> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-web-freemarker/src/main/java/sample/freemarker/SampleWebFreeMarkerApplication.java b/spring-boot-samples/spring-boot-sample-web-freemarker/src/main/java/sample/freemarker/SampleWebFreeMarkerApplication.java deleted file mode 100644 index 130e643693..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-freemarker/src/main/java/sample/freemarker/SampleWebFreeMarkerApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.freemarker; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleWebFreeMarkerApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleWebFreeMarkerApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-freemarker/src/main/java/sample/freemarker/WelcomeController.java b/spring-boot-samples/spring-boot-sample-web-freemarker/src/main/java/sample/freemarker/WelcomeController.java deleted file mode 100644 index 29947a743d..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-freemarker/src/main/java/sample/freemarker/WelcomeController.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.freemarker; - -import java.util.Date; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; - -@Controller -public class WelcomeController { - - @Value("${application.message:Hello World}") - private String message = "Hello World"; - - @GetMapping("/") - public String welcome(Map<String, Object> model) { - model.put("time", new Date()); - model.put("message", this.message); - return "welcome"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java deleted file mode 100644 index 21e9c1e3d7..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.freemarker; - -import java.util.Arrays; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for FreeMarker application. - * - * @author Phillip Webb - * @author Andy Wilkinson - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebFreeMarkerApplicationTests { - - @Autowired - private TestRestTemplate testRestTemplate; - - @Test - void testFreeMarkerTemplate() { - ResponseEntity<String> entity = this.testRestTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("Hello, Andy"); - } - - @Test - void testFreeMarkerErrorTemplate() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - HttpEntity<String> requestEntity = new HttpEntity<>(headers); - - ResponseEntity<String> responseEntity = this.testRestTemplate.exchange("/does-not-exist", HttpMethod.GET, - requestEntity, String.class); - - assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); - assertThat(responseEntity.getBody()).contains("Something went wrong: 404 Not Found"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/README.adoc b/spring-boot-samples/spring-boot-sample-web-groovy-templates/README.adoc deleted file mode 100644 index da52f5c29b..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/README.adoc +++ /dev/null @@ -1,6 +0,0 @@ -This sample application uses Spring Boot and -http://docs.groovy-lang.org/latest/html/documentation/#_the_markuptemplateengine[Groovy templates] -in the View layer. The templates for this app live in `classpath:/templates/`, which is -the conventional location for Spring Boot. External configuration is available via -``spring.groovy.template.*''. - diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/pom.xml b/spring-boot-samples/spring-boot-sample-web-groovy-templates/pom.xml deleted file mode 100755 index f5dde306bf..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-web-groovy-templates</artifactId> - <name>Spring Boot Web Groovy Templates Sample</name> - <description>Spring Boot Web Groovy Templates Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-groovy-templates</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>java9+</id> - <activation> - <jdk>[9,)</jdk> - </activation> - <dependencies> - <dependency> - <groupId>jakarta.xml.bind</groupId> - <artifactId>jakarta.xml.bind-api</artifactId> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/InMemoryMessageRepository.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/InMemoryMessageRepository.java deleted file mode 100644 index 0bf08a9590..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/InMemoryMessageRepository.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.groovytemplates; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.atomic.AtomicLong; - -public class InMemoryMessageRepository implements MessageRepository { - - private static AtomicLong counter = new AtomicLong(); - - private final ConcurrentMap<Long, Message> messages = new ConcurrentHashMap<>(); - - @Override - public Iterable<Message> findAll() { - return this.messages.values(); - } - - @Override - public Message save(Message message) { - Long id = message.getId(); - if (id == null) { - id = counter.incrementAndGet(); - message.setId(id); - } - this.messages.put(id, message); - return message; - } - - @Override - public Message findMessage(Long id) { - return this.messages.get(id); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/Message.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/Message.java deleted file mode 100644 index 2e4b97a2df..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/Message.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.groovytemplates; - -import java.util.Date; - -import javax.validation.constraints.NotEmpty; - -public class Message { - - private Long id; - - @NotEmpty(message = "Text is required.") - private String text; - - @NotEmpty(message = "Summary is required.") - private String summary; - - private Date created = new Date(); - - public Long getId() { - return this.id; - } - - public void setId(Long id) { - this.id = id; - } - - public Date getCreated() { - return this.created; - } - - public void setCreated(Date created) { - this.created = created; - } - - public String getText() { - return this.text; - } - - public void setText(String text) { - this.text = text; - } - - public String getSummary() { - return this.summary; - } - - public void setSummary(String summary) { - this.summary = summary; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/MessageRepository.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/MessageRepository.java deleted file mode 100644 index 0e35ced6e3..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/MessageRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.groovytemplates; - -public interface MessageRepository { - - Iterable<Message> findAll(); - - Message save(Message message); - - Message findMessage(Long id); - -} diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/SampleGroovyTemplateApplication.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/SampleGroovyTemplateApplication.java deleted file mode 100644 index 98f9dcfe5e..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/SampleGroovyTemplateApplication.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.groovytemplates; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.core.convert.converter.Converter; - -@SpringBootApplication -public class SampleGroovyTemplateApplication { - - @Bean - public MessageRepository messageRepository() { - return new InMemoryMessageRepository(); - } - - @Bean - public Converter<String, Message> messageConverter() { - return new Converter<String, Message>() { - @Override - public Message convert(String id) { - return messageRepository().findMessage(Long.valueOf(id)); - } - }; - } - - public static void main(String[] args) { - SpringApplication.run(SampleGroovyTemplateApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/mvc/MessageController.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/mvc/MessageController.java deleted file mode 100644 index c7a57071f9..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/java/sample/groovytemplates/mvc/MessageController.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.groovytemplates.mvc; - -import java.util.HashMap; -import java.util.Map; - -import javax.validation.Valid; - -import sample.groovytemplates.Message; -import sample.groovytemplates.MessageRepository; - -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.validation.FieldError; -import org.springframework.validation.ObjectError; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.support.RedirectAttributes; - -@Controller -@RequestMapping("/") -public class MessageController { - - private final MessageRepository messageRepository; - - public MessageController(MessageRepository messageRepository) { - this.messageRepository = messageRepository; - } - - @GetMapping - public ModelAndView list() { - Iterable<Message> messages = this.messageRepository.findAll(); - return new ModelAndView("messages/list", "messages", messages); - } - - @GetMapping("{id}") - public ModelAndView view(@PathVariable("id") Message message) { - return new ModelAndView("messages/view", "message", message); - } - - @GetMapping(params = "form") - public String createForm(@ModelAttribute Message message) { - return "messages/form"; - } - - @PostMapping - public ModelAndView create(@Valid Message message, BindingResult result, RedirectAttributes redirect) { - if (result.hasErrors()) { - ModelAndView mav = new ModelAndView("messages/form"); - mav.addObject("formErrors", result.getAllErrors()); - mav.addObject("fieldErrors", getFieldErrors(result)); - return mav; - } - message = this.messageRepository.save(message); - redirect.addFlashAttribute("globalMessage", "Successfully created a new message"); - return new ModelAndView("redirect:/{message.id}", "message.id", message.getId()); - } - - private Map<String, ObjectError> getFieldErrors(BindingResult result) { - Map<String, ObjectError> map = new HashMap<>(); - for (FieldError error : result.getFieldErrors()) { - map.put(error.getField(), error); - } - return map; - } - - @RequestMapping("foo") - public String foo() { - throw new RuntimeException("Expected exception in controller"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/MessageControllerWebTests.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/MessageControllerWebTests.java deleted file mode 100755 index e8c5a7be82..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/MessageControllerWebTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.groovytemplates; - -import java.util.regex.Pattern; - -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import static org.hamcrest.Matchers.containsString; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * A Basic Spring MVC Test for the Sample Controller" - * - * @author Biju Kunjummen - * @author Doo-Hwan, Kwak - */ -@SpringBootTest -class MessageControllerWebTests { - - @Autowired - private WebApplicationContext wac; - - private MockMvc mockMvc; - - @BeforeEach - void setup() { - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); - } - - @Test - void testHome() throws Exception { - this.mockMvc.perform(get("/")).andExpect(status().isOk()) - .andExpect(content().string(containsString("<title>Messages"))); - } - - @Test - void testCreate() throws Exception { - this.mockMvc.perform(post("/").param("text", "FOO text").param("summary", "FOO")).andExpect(status().isFound()) - .andExpect(header().string("location", RegexMatcher.matches("/[0-9]+"))); - } - - @Test - void testCreateValidation() throws Exception { - this.mockMvc.perform(post("/").param("text", "").param("summary", "")).andExpect(status().isOk()) - .andExpect(content().string(containsString("is required"))); - } - - private static class RegexMatcher extends TypeSafeMatcher<String> { - - private final String regex; - - RegexMatcher(String regex) { - this.regex = regex; - } - - @Override - public boolean matchesSafely(String item) { - return Pattern.compile(this.regex).matcher(item).find(); - } - - @Override - public void describeMismatchSafely(String item, Description mismatchDescription) { - mismatchDescription.appendText("was \"").appendText(item).appendText("\""); - } - - @Override - public void describeTo(Description description) { - description.appendText("a string that matches regex: ").appendText(this.regex); - } - - public static org.hamcrest.Matcher<java.lang.String> matches(String regex) { - return new RegexMatcher(regex); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java deleted file mode 100644 index da7deaad95..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.groovytemplates; - -import java.net.URI; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleGroovyTemplateApplicationTests { - - @LocalServerPort - private int port; - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHome() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("<title>Messages"); - assertThat(entity.getBody()).doesNotContain("layout:fragment"); - } - - @Test - void testCreate() { - MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); - map.set("text", "FOO text"); - map.set("summary", "FOO"); - URI location = this.restTemplate.postForLocation("/", map); - assertThat(location.toString()).contains("localhost:" + this.port); - } - - @Test - void testCss() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("body"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/pom.xml b/spring-boot-samples/spring-boot-sample-web-jsp/pom.xml deleted file mode 100644 index 003e640267..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-jsp/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-web-jsp</artifactId> - <packaging>war</packaging> - <name>Spring Boot Web JSP Sample</name> - <description>Spring Boot Web JSP Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>jstl</artifactId> - </dependency> - <!-- Provided --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.tomcat.embed</groupId> - <artifactId>tomcat-embed-jasper</artifactId> - <scope>provided</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <useSystemClassLoader>false</useSystemClassLoader> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/SampleWebJspApplication.java b/spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/SampleWebJspApplication.java deleted file mode 100644 index 52a282e31a..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/SampleWebJspApplication.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jsp; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; - -@SpringBootApplication -public class SampleWebJspApplication extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleWebJspApplication.class); - } - - public static void main(String[] args) { - SpringApplication.run(SampleWebJspApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/WelcomeController.java b/spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/WelcomeController.java deleted file mode 100644 index 5be4f3900f..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-jsp/src/main/java/sample/jsp/WelcomeController.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jsp; - -import java.util.Date; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; - -@Controller -public class WelcomeController { - - @Value("${application.message:Hello World}") - private String message = "Hello World"; - - @GetMapping("/") - public String welcome(Map<String, Object> model) { - model.put("time", new Date()); - model.put("message", this.message); - return "welcome"; - } - - @RequestMapping("/foo") - public String foo(Map<String, Object> model) { - throw new RuntimeException("Foo"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java deleted file mode 100644 index 4d7e6dc8d0..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.jsp; - -import java.net.URI; -import java.util.Arrays; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for JSP application. - * - * @author Phillip Webb - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebJspApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testJspWithEl() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("/resources/text.txt"); - } - - @Test - void customErrorPage() throws Exception { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - RequestEntity<Void> request = new RequestEntity<>(headers, HttpMethod.GET, URI.create("/foo")); - ResponseEntity<String> entity = this.restTemplate.exchange(request, String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - assertThat(entity.getBody()).contains("Something went wrong: 500 Internal Server Error"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/pom.xml b/spring-boot-samples/spring-boot-sample-web-method-security/pom.xml deleted file mode 100644 index 1426a20d61..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-method-security/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-web-method-security</artifactId> - <name>Spring Boot Web Method Security Sample</name> - <description>Spring Boot Web Method Security Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-thymeleaf</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java deleted file mode 100644 index 504d9b1ab5..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/java/sample/security/method/SampleMethodSecurityApplication.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.security.method; - -import java.util.Date; -import java.util.Map; - -import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.Ordered; -import org.springframework.core.annotation.Order; -import org.springframework.security.access.annotation.Secured; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.provisioning.InMemoryUserDetailsManager; -import org.springframework.security.web.util.matcher.AntPathRequestMatcher; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@SpringBootApplication -@EnableGlobalMethodSecurity(securedEnabled = true) -public class SampleMethodSecurityApplication implements WebMvcConfigurer { - - @Override - public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/login").setViewName("login"); - registry.addViewController("/access").setViewName("access"); - } - - public static void main(String[] args) { - new SpringApplicationBuilder(SampleMethodSecurityApplication.class).run(args); - } - - @Order(Ordered.HIGHEST_PRECEDENCE) - @Configuration(proxyBeanMethods = false) - protected static class AuthenticationSecurity { - - @SuppressWarnings("deprecation") - @Bean - public InMemoryUserDetailsManager inMemoryUserDetailsManager() throws Exception { - return new InMemoryUserDetailsManager( - User.withDefaultPasswordEncoder().username("admin").password("admin") - .roles("ADMIN", "USER", "ACTUATOR").build(), - User.withDefaultPasswordEncoder().username("user").password("user").roles("USER").build()); - } - - } - - @Configuration(proxyBeanMethods = false) - protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - // @formatter:off - http.authorizeRequests() - .antMatchers("/login").permitAll() - .anyRequest().fullyAuthenticated() - .and() - .formLogin().loginPage("/login").failureUrl("/login?error") - .and() - .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")) - .and() - .exceptionHandling().accessDeniedPage("/access?error"); - // @formatter:on - } - - } - - @Configuration(proxyBeanMethods = false) - @Order(1) - protected static class ActuatorSecurity extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - // @formatter:off - http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests() - .anyRequest().authenticated() - .and() - .httpBasic(); - // @formatter:on - } - - } - - @Controller - protected static class HomeController { - - @GetMapping("/") - @Secured("ROLE_ADMIN") - public String home(Map<String, Object> model) { - model.put("message", "Hello World"); - model.put("title", "Hello Home"); - model.put("date", new Date()); - return "home"; - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java deleted file mode 100644 index c45a3d97ce..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.security.method; - -import java.util.Arrays; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.http.client.support.BasicAuthenticationInterceptor; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleMethodSecurityApplicationTests { - - @LocalServerPort - private int port; - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHome() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("<title>Login"); - } - - @Test - void testLogin() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); - form.set("username", "admin"); - form.set("password", "admin"); - getCsrf(form, headers); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, - new HttpEntity<>(form, headers), String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()).isEqualTo("http://localhost:" + this.port + "/"); - } - - @Test - void testDenied() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); - form.set("username", "user"); - form.set("password", "user"); - getCsrf(form, headers); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, - new HttpEntity<>(form, headers), String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - String cookie = entity.getHeaders().getFirst("Set-Cookie"); - headers.set("Cookie", cookie); - ResponseEntity<String> page = this.restTemplate.exchange(entity.getHeaders().getLocation(), HttpMethod.GET, - new HttpEntity<Void>(headers), String.class); - assertThat(page.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); - assertThat(page.getBody()).contains("Access denied"); - } - - @Test - void testManagementProtected() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); - ResponseEntity<String> entity = this.restTemplate.exchange("/actuator/beans", HttpMethod.GET, - new HttpEntity<Void>(headers), String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); - } - - @Test - void testManagementAuthorizedAccess() { - BasicAuthenticationInterceptor basicAuthInterceptor = new BasicAuthenticationInterceptor("admin", "admin"); - this.restTemplate.getRestTemplate().getInterceptors().add(basicAuthInterceptor); - try { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/beans", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - } - finally { - this.restTemplate.getRestTemplate().getInterceptors().remove(basicAuthInterceptor); - } - } - - private void getCsrf(MultiValueMap<String, String> form, HttpHeaders headers) { - ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class); - String cookie = page.getHeaders().getFirst("Set-Cookie"); - headers.set("Cookie", cookie); - String body = page.getBody(); - Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*").matcher(body); - matcher.find(); - form.set("_csrf", matcher.group(1)); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/pom.xml b/spring-boot-samples/spring-boot-sample-web-mustache/pom.xml deleted file mode 100644 index 40b50bce15..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-mustache/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-web-mustache</artifactId> - <name>Spring Boot Web Mustache Sample</name> - <description>Spring Boot Web Mustache Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-mustache</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <useSystemClassLoader>false</useSystemClassLoader> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/java/sample/mustache/SampleWebMustacheApplication.java b/spring-boot-samples/spring-boot-sample-web-mustache/src/main/java/sample/mustache/SampleWebMustacheApplication.java deleted file mode 100644 index 701dbad063..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/java/sample/mustache/SampleWebMustacheApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.mustache; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleWebMustacheApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleWebMustacheApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/java/sample/mustache/WelcomeController.java b/spring-boot-samples/spring-boot-sample-web-mustache/src/main/java/sample/mustache/WelcomeController.java deleted file mode 100644 index 2a0dd0580b..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/java/sample/mustache/WelcomeController.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.mustache; - -import java.util.Date; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseStatus; - -@Controller -public class WelcomeController { - - @Value("${application.message:Hello World}") - private String message = "Hello World"; - - @GetMapping("/") - public String welcome(Map<String, Object> model) { - model.put("time", new Date()); - model.put("message", this.message); - return "welcome"; - } - - @RequestMapping("/serviceUnavailable") - public String ServiceUnavailable() { - throw new ServiceUnavailableException(); - } - - @RequestMapping("/bang") - public String bang() { - throw new RuntimeException("Boom"); - } - - @RequestMapping("/insufficientStorage") - public String insufficientStorage() { - throw new InsufficientStorageException(); - } - - @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE) - private static class ServiceUnavailableException extends RuntimeException { - - } - - @ResponseStatus(HttpStatus.INSUFFICIENT_STORAGE) - private static class InsufficientStorageException extends RuntimeException { - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java deleted file mode 100644 index 0d237be942..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.mustache; - -import java.util.Arrays; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for Mustache application. - * - * @author Phillip Webb - * @author Andy Wilkinson - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebMustacheApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testMustacheTemplate() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("Hello, Andy"); - } - - @Test - void testMustacheErrorTemplate() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - HttpEntity<String> requestEntity = new HttpEntity<>(headers); - ResponseEntity<String> responseEntity = this.restTemplate.exchange("/does-not-exist", HttpMethod.GET, - requestEntity, String.class); - assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); - assertThat(responseEntity.getBody()).contains("Something went wrong: 404 Not Found"); - } - - @Test - void test503HtmlResource() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - HttpEntity<String> requestEntity = new HttpEntity<>(headers); - ResponseEntity<String> entity = this.restTemplate.exchange("/serviceUnavailable", HttpMethod.GET, requestEntity, - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE); - assertThat(entity.getBody()).contains("I'm a 503"); - } - - @Test - void test5xxHtmlResource() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - HttpEntity<String> requestEntity = new HttpEntity<>(headers); - ResponseEntity<String> entity = this.restTemplate.exchange("/bang", HttpMethod.GET, requestEntity, - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - assertThat(entity.getBody()).contains("I'm a 5xx"); - } - - @Test - void test507Template() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - HttpEntity<String> requestEntity = new HttpEntity<>(headers); - ResponseEntity<String> entity = this.restTemplate.exchange("/insufficientStorage", HttpMethod.GET, - requestEntity, String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INSUFFICIENT_STORAGE); - assertThat(entity.getBody()).contains("I'm a 507"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/pom.xml b/spring-boot-samples/spring-boot-sample-web-secure-custom/pom.xml deleted file mode 100644 index 49df77db04..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-secure-custom/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-web-secure-custom</artifactId> - <name>Spring Boot Web Secure Custom Sample</name> - <description>Spring Boot Web Secure Custom Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-thymeleaf</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/java/sample/web/secure/custom/SampleWebSecureCustomApplication.java b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/java/sample/web/secure/custom/SampleWebSecureCustomApplication.java deleted file mode 100644 index 938789ae86..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/java/sample/web/secure/custom/SampleWebSecureCustomApplication.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.secure.custom; - -import java.util.Date; -import java.util.Map; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@SpringBootApplication -@Controller -public class SampleWebSecureCustomApplication implements WebMvcConfigurer { - - @GetMapping("/") - public String home(Map<String, Object> model) { - model.put("message", "Hello World"); - model.put("title", "Hello Home"); - model.put("date", new Date()); - return "home"; - } - - @RequestMapping("/foo") - public String foo() { - throw new RuntimeException("Expected exception in controller"); - } - - @Override - public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/login").setViewName("login"); - } - - public static void main(String[] args) { - new SpringApplicationBuilder(SampleWebSecureCustomApplication.class).run(args); - } - - @Configuration(proxyBeanMethods = false) - protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests().antMatchers("/css/**").permitAll().anyRequest().fullyAuthenticated().and() - .formLogin().loginPage("/login").failureUrl("/login?error").permitAll().and().logout().permitAll(); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java deleted file mode 100644 index ea45ad6db9..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.secure.custom; - -import java.util.Arrays; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebSecureCustomApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @LocalServerPort - private int port; - - @Test - void testHome() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/login"); - } - - @Test - void testLoginPage() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, - new HttpEntity<Void>(headers), String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("_csrf"); - } - - @Test - void testLogin() { - HttpHeaders headers = getHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); - form.set("username", "user"); - form.set("password", "password"); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, - new HttpEntity<>(form, headers), String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/"); - assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); - } - - private HttpHeaders getHeaders() { - HttpHeaders headers = new HttpHeaders(); - ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class); - assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK); - String cookie = page.getHeaders().getFirst("Set-Cookie"); - headers.set("Cookie", cookie); - Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"); - Matcher matcher = pattern.matcher(page.getBody()); - assertThat(matcher.matches()).as(page.getBody()).isTrue(); - headers.set("X-CSRF-TOKEN", matcher.group(1)); - return headers; - } - - @Test - void testCss() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("body"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/pom.xml b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/pom.xml deleted file mode 100644 index ddc52511da..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-web-secure-jdbc</artifactId> - <name>Spring Boot Web Secure JDBC Sample</name> - <description>Spring Boot Web Secure JDBC Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-thymeleaf</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jdbc</artifactId> - </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplication.java b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplication.java deleted file mode 100644 index 882362f5fd..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplication.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.secure.jdbc; - -import java.util.Date; -import java.util.Map; - -import javax.sql.DataSource; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.provisioning.JdbcUserDetailsManager; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@SpringBootApplication -@Controller -public class SampleWebSecureJdbcApplication implements WebMvcConfigurer { - - @GetMapping("/") - public String home(Map<String, Object> model) { - model.put("message", "Hello World"); - model.put("title", "Hello Home"); - model.put("date", new Date()); - return "home"; - } - - @RequestMapping("/foo") - public String foo() { - throw new RuntimeException("Expected exception in controller"); - } - - @Override - public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/login").setViewName("login"); - } - - public static void main(String[] args) { - new SpringApplicationBuilder(SampleWebSecureJdbcApplication.class).run(args); - } - - @Configuration(proxyBeanMethods = false) - protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests().antMatchers("/css/**").permitAll().anyRequest().fullyAuthenticated().and() - .formLogin().loginPage("/login").failureUrl("/login?error").permitAll().and().logout().permitAll(); - } - - @Bean - public JdbcUserDetailsManager jdbcUserDetailsManager(DataSource dataSource) { - JdbcUserDetailsManager jdbcUserDetailsManager = new JdbcUserDetailsManager(); - jdbcUserDetailsManager.setDataSource(dataSource); - return jdbcUserDetailsManager; - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java deleted file mode 100644 index 136783c96b..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.secure.jdbc; - -import java.util.Arrays; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebSecureJdbcApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @LocalServerPort - private int port; - - @Test - void testHome() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/login"); - } - - @Test - void testLoginPage() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, - new HttpEntity<Void>(headers), String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("_csrf"); - } - - @Test - void testLogin() { - HttpHeaders headers = getHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); - form.set("username", "user"); - form.set("password", "user"); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, - new HttpEntity<>(form, headers), String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/"); - assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); - } - - private HttpHeaders getHeaders() { - HttpHeaders headers = new HttpHeaders(); - ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class); - assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK); - String cookie = page.getHeaders().getFirst("Set-Cookie"); - headers.set("Cookie", cookie); - Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"); - Matcher matcher = pattern.matcher(page.getBody()); - assertThat(matcher.matches()).as(page.getBody()).isTrue(); - headers.set("X-CSRF-TOKEN", matcher.group(1)); - return headers; - } - - @Test - void testCss() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("body"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-secure/pom.xml b/spring-boot-samples/spring-boot-sample-web-secure/pom.xml deleted file mode 100644 index e211862496..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-secure/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-web-secure</artifactId> - <name>Spring Boot Web Secure Sample</name> - <description>Spring Boot Web Secure Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-thymeleaf</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/main/java/sample/web/secure/SampleWebSecureApplication.java b/spring-boot-samples/spring-boot-sample-web-secure/src/main/java/sample/web/secure/SampleWebSecureApplication.java deleted file mode 100644 index 7a5e4ab193..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-secure/src/main/java/sample/web/secure/SampleWebSecureApplication.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.secure; - -import java.util.Date; -import java.util.Map; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.security.servlet.PathRequest; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@SpringBootApplication -@Controller -public class SampleWebSecureApplication implements WebMvcConfigurer { - - @GetMapping("/") - public String home(Map<String, Object> model) { - model.put("message", "Hello World"); - model.put("title", "Hello Home"); - model.put("date", new Date()); - return "home"; - } - - @RequestMapping("/foo") - public String foo() { - throw new RuntimeException("Expected exception in controller"); - } - - @Override - public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/login").setViewName("login"); - } - - public static void main(String[] args) { - new SpringApplicationBuilder(SampleWebSecureApplication.class).run(args); - } - - @Configuration(proxyBeanMethods = false) - protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - // @formatter:off - http.authorizeRequests() - .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() - .anyRequest().fullyAuthenticated() - .and() - .formLogin().loginPage("/login").failureUrl("/login?error").permitAll() - .and() - .logout().permitAll(); - // @formatter:on - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java deleted file mode 100644 index 9b1a9f03a5..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.secure; - -import java.util.Arrays; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleSecureApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @LocalServerPort - private int port; - - @Test - void testHome() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/login"); - } - - @Test - void testLoginPage() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, - new HttpEntity<Void>(headers), String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("_csrf"); - } - - @Test - void testLogin() { - HttpHeaders headers = getHeaders(); - headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); - headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); - form.set("username", "user"); - form.set("password", "password"); - ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, - new HttpEntity<>(form, headers), String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); - assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/"); - assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); - } - - private HttpHeaders getHeaders() { - HttpHeaders headers = new HttpHeaders(); - ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class); - assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK); - String cookie = page.getHeaders().getFirst("Set-Cookie"); - headers.set("Cookie", cookie); - Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"); - Matcher matcher = pattern.matcher(page.getBody()); - assertThat(matcher.matches()).as(page.getBody()).isTrue(); - headers.set("X-CSRF-TOKEN", matcher.group(1)); - return headers; - } - - @Test - void testCss() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("body"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-static/pom.xml b/spring-boot-samples/spring-boot-sample-web-static/pom.xml deleted file mode 100644 index df792911ac..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-static/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-web-static</artifactId> - <packaging>war</packaging> - <name>Spring Boot Web Static Sample</name> - <description>Spring Boot Web Static Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.webjars</groupId> - <artifactId>bootstrap</artifactId> - <version>3.0.3</version> - </dependency> - <dependency> - <groupId>org.webjars</groupId> - <artifactId>jquery</artifactId> - <version>2.0.3-1</version> - </dependency> - <!-- Provided --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - <scope>provided</scope> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-web-static/src/main/java/sample/web/staticcontent/SampleWebStaticApplication.java b/spring-boot-samples/spring-boot-sample-web-static/src/main/java/sample/web/staticcontent/SampleWebStaticApplication.java deleted file mode 100644 index 85b4c86dd2..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-static/src/main/java/sample/web/staticcontent/SampleWebStaticApplication.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.staticcontent; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; - -@SpringBootApplication -public class SampleWebStaticApplication extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleWebStaticApplication.class); - } - - public static void main(String[] args) { - SpringApplication.run(SampleWebStaticApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java deleted file mode 100644 index efcc4f3160..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.staticcontent; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebStaticApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Test - void testHome() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("<title>Static"); - } - - @Test - void testCss() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/webjars/bootstrap/3.0.3/css/bootstrap.min.css", - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("body"); - assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.valueOf("text/css")); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-ui/pom.xml b/spring-boot-samples/spring-boot-sample-web-ui/pom.xml deleted file mode 100755 index fec5cef220..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-ui/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-web-ui</artifactId> - <name>Spring Boot Web UI Sample</name> - <description>Spring Boot Web UI Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-thymeleaf</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-devtools</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/InMemoryMessageRepository.java b/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/InMemoryMessageRepository.java deleted file mode 100755 index 732dd1cbf3..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/InMemoryMessageRepository.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.ui; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.atomic.AtomicLong; - -public class InMemoryMessageRepository implements MessageRepository { - - private static AtomicLong counter = new AtomicLong(); - - private final ConcurrentMap<Long, Message> messages = new ConcurrentHashMap<>(); - - @Override - public Iterable<Message> findAll() { - return this.messages.values(); - } - - @Override - public Message save(Message message) { - Long id = message.getId(); - if (id == null) { - id = counter.incrementAndGet(); - message.setId(id); - } - this.messages.put(id, message); - return message; - } - - @Override - public Message findMessage(Long id) { - return this.messages.get(id); - } - - @Override - public void deleteMessage(Long id) { - this.messages.remove(id); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/Message.java b/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/Message.java deleted file mode 100644 index 32fa0cad21..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/Message.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.ui; - -import java.util.Calendar; - -import javax.validation.constraints.NotEmpty; - -public class Message { - - private Long id; - - @NotEmpty(message = "Text is required.") - private String text; - - @NotEmpty(message = "Summary is required.") - private String summary; - - private Calendar created = Calendar.getInstance(); - - public Long getId() { - return this.id; - } - - public void setId(Long id) { - this.id = id; - } - - public Calendar getCreated() { - return this.created; - } - - public void setCreated(Calendar created) { - this.created = created; - } - - public String getText() { - return this.text; - } - - public void setText(String text) { - this.text = text; - } - - public String getSummary() { - return this.summary; - } - - public void setSummary(String summary) { - this.summary = summary; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/MessageRepository.java b/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/MessageRepository.java deleted file mode 100755 index 3b84e9d7ec..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/MessageRepository.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.ui; - -public interface MessageRepository { - - Iterable<Message> findAll(); - - Message save(Message message); - - Message findMessage(Long id); - - void deleteMessage(Long id); - -} diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/SampleWebUiApplication.java b/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/SampleWebUiApplication.java deleted file mode 100644 index ea456a9044..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/SampleWebUiApplication.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.ui; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.core.convert.converter.Converter; - -@SpringBootApplication -public class SampleWebUiApplication { - - @Bean - public MessageRepository messageRepository() { - return new InMemoryMessageRepository(); - } - - @Bean - public Converter<String, Message> messageConverter() { - return new Converter<String, Message>() { - @Override - public Message convert(String id) { - return messageRepository().findMessage(Long.valueOf(id)); - } - }; - } - - public static void main(String[] args) { - SpringApplication.run(SampleWebUiApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java b/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java deleted file mode 100755 index 55df4f71a8..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.ui.mvc; - -import javax.validation.Valid; - -import sample.web.ui.Message; -import sample.web.ui.MessageRepository; - -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.support.RedirectAttributes; - -@Controller -@RequestMapping("/") -public class MessageController { - - private final MessageRepository messageRepository; - - public MessageController(MessageRepository messageRepository) { - this.messageRepository = messageRepository; - } - - @GetMapping - public ModelAndView list() { - Iterable<Message> messages = this.messageRepository.findAll(); - return new ModelAndView("messages/list", "messages", messages); - } - - @GetMapping("{id}") - public ModelAndView view(@PathVariable("id") Message message) { - return new ModelAndView("messages/view", "message", message); - } - - @GetMapping(params = "form") - public String createForm(@ModelAttribute Message message) { - return "messages/form"; - } - - @PostMapping - public ModelAndView create(@Valid Message message, BindingResult result, RedirectAttributes redirect) { - if (result.hasErrors()) { - return new ModelAndView("messages/form", "formErrors", result.getAllErrors()); - } - message = this.messageRepository.save(message); - redirect.addFlashAttribute("globalMessage", "view.success"); - return new ModelAndView("redirect:/{message.id}", "message.id", message.getId()); - } - - @RequestMapping("foo") - public String foo() { - throw new RuntimeException("Expected exception in controller"); - } - - @GetMapping("delete/{id}") - public ModelAndView delete(@PathVariable("id") Long id) { - this.messageRepository.deleteMessage(id); - Iterable<Message> messages = this.messageRepository.findAll(); - return new ModelAndView("messages/list", "messages", messages); - } - - @GetMapping("modify/{id}") - public ModelAndView modifyForm(@PathVariable("id") Message message) { - return new ModelAndView("messages/form", "message", message); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/MessageControllerWebTests.java b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/MessageControllerWebTests.java deleted file mode 100644 index 66b02253a6..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/MessageControllerWebTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.ui; - -import java.util.regex.Pattern; - -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import static org.hamcrest.Matchers.containsString; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * A Basic Spring MVC Test for the Sample Controller" - * - * @author Biju Kunjummen - * @author Doo-Hwan, Kwak - */ -@SpringBootTest -class MessageControllerWebTests { - - @Autowired - private WebApplicationContext wac; - - private MockMvc mockMvc; - - @BeforeEach - void setup() { - this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); - } - - @Test - void testHome() throws Exception { - this.mockMvc.perform(get("/")).andExpect(status().isOk()) - .andExpect(content().string(containsString("<title>Messages"))); - } - - @Test - void testCreate() throws Exception { - this.mockMvc.perform(post("/").param("text", "FOO text").param("summary", "FOO")).andExpect(status().isFound()) - .andExpect(header().string("location", RegexMatcher.matches("/[0-9]+"))); - } - - @Test - void testCreateValidation() throws Exception { - this.mockMvc.perform(post("/").param("text", "").param("summary", "")).andExpect(status().isOk()) - .andExpect(content().string(containsString("is required"))); - } - - private static class RegexMatcher extends TypeSafeMatcher<String> { - - private final String regex; - - RegexMatcher(String regex) { - this.regex = regex; - } - - @Override - public boolean matchesSafely(String item) { - return Pattern.compile(this.regex).matcher(item).find(); - } - - @Override - public void describeMismatchSafely(String item, Description mismatchDescription) { - mismatchDescription.appendText("was \"").appendText(item).appendText("\""); - } - - @Override - public void describeTo(Description description) { - description.appendText("a string that matches regex: ").appendText(this.regex); - } - - public static org.hamcrest.Matcher<java.lang.String> matches(String regex) { - return new RegexMatcher(regex); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java deleted file mode 100644 index 1df6c0529b..0000000000 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.web.ui; - -import java.net.URI; - -import org.junit.jupiter.api.Test; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Basic integration tests for demo application. - * - * @author Dave Syer - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebUiApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @LocalServerPort - private int port; - - @Test - void testHome() { - ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("<title>Messages"); - assertThat(entity.getBody()).doesNotContain("layout:fragment"); - } - - @Test - void testCreate() { - MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); - map.set("text", "FOO text"); - map.set("summary", "FOO"); - URI location = this.restTemplate.postForLocation("/", map); - assertThat(location.toString()).contains("localhost:" + this.port); - } - - @Test - void testCss() { - ResponseEntity<String> entity = this.restTemplate - .getForEntity("http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("body"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-webflux/pom.xml b/spring-boot-samples/spring-boot-sample-webflux/pom.xml deleted file mode 100644 index 3b1e7a3abf..0000000000 --- a/spring-boot-samples/spring-boot-sample-webflux/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-webflux</artifactId> - <name>Spring Boot WebFlux Sample</name> - <description>Spring Boot WebFlux Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-webflux</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>io.projectreactor</groupId> - <artifactId>reactor-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <executions> - <execution> - <id>generate build info</id> - <goals> - <goal>build-info</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/EchoHandler.java b/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/EchoHandler.java deleted file mode 100644 index 392d6e8054..0000000000 --- a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/EchoHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.webflux; - -import reactor.core.publisher.Mono; - -import org.springframework.stereotype.Component; -import org.springframework.web.reactive.function.server.ServerRequest; -import org.springframework.web.reactive.function.server.ServerResponse; - -@Component -public class EchoHandler { - - public Mono<ServerResponse> echo(ServerRequest request) { - return ServerResponse.ok().body(request.bodyToMono(String.class), String.class); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/ExampleController.java b/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/ExampleController.java deleted file mode 100644 index 1b5062d6f6..0000000000 --- a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/ExampleController.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.webflux; - -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class ExampleController { - - @PostMapping(path = "/", consumes = { MediaType.APPLICATION_JSON_VALUE, "!application/xml" }, - produces = MediaType.TEXT_PLAIN_VALUE, headers = "X-Custom=Foo", params = "a!=alpha") - public String example() { - return "Hello World"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java b/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java deleted file mode 100644 index 25d838717f..0000000000 --- a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.webflux; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.web.reactive.function.server.RouterFunction; -import org.springframework.web.reactive.function.server.ServerResponse; - -import static org.springframework.web.reactive.function.server.RequestPredicates.POST; -import static org.springframework.web.reactive.function.server.RouterFunctions.route; - -@SpringBootApplication -public class SampleWebFluxApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleWebFluxApplication.class, args); - } - - @Bean - public RouterFunction<ServerResponse> monoRouterFunction(EchoHandler echoHandler) { - return route(POST("/echo"), echoHandler::echo); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/WelcomeController.java b/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/WelcomeController.java deleted file mode 100644 index b0299472d7..0000000000 --- a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/WelcomeController.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.webflux; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class WelcomeController { - - @GetMapping("/") - public String welcome() { - return "Hello World"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java b/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java deleted file mode 100644 index 2177fdc67e..0000000000 --- a/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.webflux; - -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.http.MediaType; -import org.springframework.test.web.reactive.server.WebTestClient; - -/** - * Basic integration tests for WebFlux application. - * - * @author Brian Clozel - */ -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebFluxApplicationTests { - - @Autowired - private WebTestClient webClient; - - @Test - void testWelcome() { - this.webClient.get().uri("/").accept(MediaType.TEXT_PLAIN).exchange().expectBody(String.class) - .isEqualTo("Hello World"); - } - - @Test - void testEcho() { - this.webClient.post().uri("/echo").contentType(MediaType.TEXT_PLAIN).accept(MediaType.TEXT_PLAIN) - .body(Mono.just("Hello WebFlux!"), String.class).exchange().expectBody(String.class) - .isEqualTo("Hello WebFlux!"); - } - - @Test - void testActuatorStatus() { - this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk() - .expectBody().json("{\"status\":\"UP\"}"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-webservices/README.adoc b/spring-boot-samples/spring-boot-sample-webservices/README.adoc deleted file mode 100644 index 9acfd45e2d..0000000000 --- a/spring-boot-samples/spring-boot-sample-webservices/README.adoc +++ /dev/null @@ -1,14 +0,0 @@ -== Spring Boot - Samples - Web Services - -This sample project demonstrates how to use https://projects.spring.io/spring-ws/[Spring Web Services] -with Spring Boot. It is an implementation of the -https://docs.spring.io/spring-ws/site/reference/html/tutorial.html#tutorial.implementing.endpoint[Holiday Request sample] -in the Spring Web Services reference guide. - -The sample uses Maven. It can be built and run from the command line: - ----- -$ mvn spring-boot:run ----- - -http://localhost:8080/services/holidayService/holiday.wsdl will now display the generated WSDL. diff --git a/spring-boot-samples/spring-boot-sample-webservices/pom.xml b/spring-boot-samples/spring-boot-sample-webservices/pom.xml deleted file mode 100644 index 0686af6dc0..0000000000 --- a/spring-boot-samples/spring-boot-sample-webservices/pom.xml +++ /dev/null @@ -1,68 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <artifactId>spring-boot-samples</artifactId> - <groupId>org.springframework.boot</groupId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-webservices</artifactId> - <name>Spring Boot Web Services Sample</name> - <description>Spring Boot Web Services Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web-services</artifactId> - </dependency> - <dependency> - <groupId>jaxen</groupId> - <artifactId>jaxen</artifactId> - </dependency> - <dependency> - <groupId>org.jdom</groupId> - <artifactId>jdom2</artifactId> - </dependency> - <dependency> - <groupId>wsdl4j</groupId> - <artifactId>wsdl4j</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>java11+</id> - <activation> - <jdk>[11,)</jdk> - </activation> - <dependencies> - <dependency> - <groupId>jakarta.activation</groupId> - <artifactId>jakarta.activation-api</artifactId> - </dependency> - <dependency> - <groupId>org.glassfish.jaxb</groupId> - <artifactId>jaxb-runtime</artifactId> - </dependency> - </dependencies> - </profile> - </profiles> -</project> diff --git a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/SampleWebServicesApplication.java b/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/SampleWebServicesApplication.java deleted file mode 100644 index 4c3dd9d17e..0000000000 --- a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/SampleWebServicesApplication.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.webservices; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SampleWebServicesApplication { - - public static void main(String[] args) { - SpringApplication.run(SampleWebServicesApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/WebServiceConfig.java b/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/WebServiceConfig.java deleted file mode 100644 index 00f209fc02..0000000000 --- a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/WebServiceConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.webservices; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.ws.config.annotation.WsConfigurerAdapter; -import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition; -import org.springframework.xml.xsd.XsdSchema; - -@Configuration(proxyBeanMethods = false) -public class WebServiceConfig extends WsConfigurerAdapter { - - @Bean(name = "holiday") - public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) { - DefaultWsdl11Definition wsdl = new DefaultWsdl11Definition(); - wsdl.setPortTypeName("HumanResource"); - wsdl.setLocationUri("/holidayService/"); - wsdl.setTargetNamespace("https://company.example.com/hr/definitions"); - wsdl.setSchema(countriesSchema); - return wsdl; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/endpoint/HolidayEndpoint.java b/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/endpoint/HolidayEndpoint.java deleted file mode 100644 index e5be9211e4..0000000000 --- a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/endpoint/HolidayEndpoint.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.webservices.endpoint; - -import java.text.SimpleDateFormat; -import java.util.Date; - -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactoryConfigurationException; - -import org.jdom2.Element; -import org.jdom2.JDOMException; -import org.jdom2.Namespace; -import org.jdom2.filter.Filters; -import org.jdom2.xpath.XPathExpression; -import org.jdom2.xpath.XPathFactory; -import sample.webservices.service.HumanResourceService; - -import org.springframework.ws.server.endpoint.annotation.Endpoint; -import org.springframework.ws.server.endpoint.annotation.PayloadRoot; -import org.springframework.ws.server.endpoint.annotation.RequestPayload; - -@Endpoint -public class HolidayEndpoint { - - private static final String NAMESPACE_URI = "https://company.example.com/hr/schemas"; - - private XPathExpression<Element> startDateExpression; - - private XPathExpression<Element> endDateExpression; - - private XPathExpression<String> nameExpression; - - private HumanResourceService humanResourceService; - - public HolidayEndpoint(HumanResourceService humanResourceService) - throws JDOMException, XPathFactoryConfigurationException, XPathExpressionException { - this.humanResourceService = humanResourceService; - Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI); - XPathFactory xPathFactory = XPathFactory.instance(); - this.startDateExpression = xPathFactory.compile("//hr:StartDate", Filters.element(), null, namespace); - this.endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(), null, namespace); - this.nameExpression = xPathFactory.compile("concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(), null, - namespace); - } - - @PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest") - public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception { - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - Date startDate = dateFormat.parse(this.startDateExpression.evaluateFirst(holidayRequest).getText()); - Date endDate = dateFormat.parse(this.endDateExpression.evaluateFirst(holidayRequest).getText()); - String name = this.nameExpression.evaluateFirst(holidayRequest); - this.humanResourceService.bookHoliday(startDate, endDate, name); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/service/HumanResourceService.java b/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/service/HumanResourceService.java deleted file mode 100644 index f4281d4339..0000000000 --- a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/service/HumanResourceService.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.webservices.service; - -import java.util.Date; - -public interface HumanResourceService { - - void bookHoliday(Date startDate, Date endDate, String name); - -} diff --git a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/service/StubHumanResourceService.java b/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/service/StubHumanResourceService.java deleted file mode 100644 index 6ae3ff2954..0000000000 --- a/spring-boot-samples/spring-boot-sample-webservices/src/main/java/sample/webservices/service/StubHumanResourceService.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.webservices.service; - -import java.util.Date; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.stereotype.Service; - -@Service -public class StubHumanResourceService implements HumanResourceService { - - private final Log logger = LogFactory.getLog(StubHumanResourceService.class); - - @Override - public void bookHoliday(Date startDate, Date endDate, String name) { - this.logger.info("Booking holiday for [" + startDate + " - " + endDate + "] for [" + name + "]"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-webservices/src/test/java/sample/webservices/SampleWsApplicationTests.java b/spring-boot-samples/spring-boot-sample-webservices/src/test/java/sample/webservices/SampleWsApplicationTests.java deleted file mode 100644 index 02a18aa6ab..0000000000 --- a/spring-boot-samples/spring-boot-sample-webservices/src/test/java/sample/webservices/SampleWsApplicationTests.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.webservices; - -import java.io.StringReader; - -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.stream.StreamSource; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.ws.client.core.WebServiceTemplate; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ExtendWith(OutputCaptureExtension.class) -class SampleWsApplicationTests { - - private WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); - - @LocalServerPort - private int serverPort; - - @BeforeEach - void setUp() { - this.webServiceTemplate.setDefaultUri("http://localhost:" + this.serverPort + "/services/"); - } - - @Test - void testSendingHolidayRequest(CapturedOutput capturedOutput) { - final String request = "<hr:HolidayRequest xmlns:hr=\"https://company.example.com/hr/schemas\">" - + " <hr:Holiday>" + " <hr:StartDate>2013-10-20</hr:StartDate>" - + " <hr:EndDate>2013-11-22</hr:EndDate>" + " </hr:Holiday>" + " <hr:Employee>" - + " <hr:Number>1</hr:Number>" + " <hr:FirstName>John</hr:FirstName>" - + " <hr:LastName>Doe</hr:LastName>" + " </hr:Employee>" + "</hr:HolidayRequest>"; - StreamSource source = new StreamSource(new StringReader(request)); - StreamResult result = new StreamResult(System.out); - this.webServiceTemplate.sendSourceAndReceiveToResult(source, result); - assertThat(capturedOutput).contains("Booking holiday for"); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/pom.xml b/spring-boot-samples/spring-boot-sample-websocket-jetty/pom.xml deleted file mode 100755 index 9b0de569fa..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-websocket-jetty</artifactId> - <name>Spring Boot WebSocket Jetty Sample</name> - <description>Spring Boot WebSocket Jetty Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-websocket</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jetty</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/SampleJettyWebSocketsApplication.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/SampleJettyWebSocketsApplication.java deleted file mode 100644 index c2e18cd7e5..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/SampleJettyWebSocketsApplication.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty; - -import samples.websocket.jetty.client.GreetingService; -import samples.websocket.jetty.client.SimpleGreetingService; -import samples.websocket.jetty.echo.DefaultEchoService; -import samples.websocket.jetty.echo.EchoService; -import samples.websocket.jetty.echo.EchoWebSocketHandler; -import samples.websocket.jetty.reverse.ReverseWebSocketEndpoint; -import samples.websocket.jetty.snake.SnakeWebSocketHandler; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.WebSocketHandler; -import org.springframework.web.socket.config.annotation.EnableWebSocket; -import org.springframework.web.socket.config.annotation.WebSocketConfigurer; -import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; -import org.springframework.web.socket.handler.PerConnectionWebSocketHandler; -import org.springframework.web.socket.server.standard.ServerEndpointExporter; - -@Configuration(proxyBeanMethods = false) -@EnableAutoConfiguration -@EnableWebSocket -public class SampleJettyWebSocketsApplication extends SpringBootServletInitializer implements WebSocketConfigurer { - - @Override - public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(echoWebSocketHandler(), "/echo").withSockJS(); - registry.addHandler(snakeWebSocketHandler(), "/snake").withSockJS(); - } - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleJettyWebSocketsApplication.class); - } - - @Bean - public EchoService echoService() { - return new DefaultEchoService("Did you say \"%s\"?"); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - - @Bean - public WebSocketHandler echoWebSocketHandler() { - return new EchoWebSocketHandler(echoService()); - } - - @Bean - public WebSocketHandler snakeWebSocketHandler() { - return new PerConnectionWebSocketHandler(SnakeWebSocketHandler.class); - } - - @Bean - public ReverseWebSocketEndpoint reverseWebSocketEndpoint() { - return new ReverseWebSocketEndpoint(); - } - - @Bean - public ServerEndpointExporter serverEndpointExporter() { - return new ServerEndpointExporter(); - } - - public static void main(String[] args) { - SpringApplication.run(SampleJettyWebSocketsApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/GreetingService.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/GreetingService.java deleted file mode 100644 index 684b16d91b..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/GreetingService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.client; - -public interface GreetingService { - - String getGreeting(); - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/SimpleClientWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/SimpleClientWebSocketHandler.java deleted file mode 100644 index 5f8be527b3..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/SimpleClientWebSocketHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.client; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -public class SimpleClientWebSocketHandler extends TextWebSocketHandler { - - protected Log logger = LogFactory.getLog(SimpleClientWebSocketHandler.class); - - private final GreetingService greetingService; - - private final CountDownLatch latch; - - private final AtomicReference<String> messagePayload; - - public SimpleClientWebSocketHandler(GreetingService greetingService, CountDownLatch latch, - AtomicReference<String> message) { - this.greetingService = greetingService; - this.latch = latch; - this.messagePayload = message; - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) throws Exception { - TextMessage message = new TextMessage(this.greetingService.getGreeting()); - session.sendMessage(message); - } - - @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - this.logger.info("Received: " + message + " (" + this.latch.getCount() + ")"); - session.close(); - this.messagePayload.set(message.getPayload()); - this.latch.countDown(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/SimpleGreetingService.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/SimpleGreetingService.java deleted file mode 100644 index 9dead7832d..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/client/SimpleGreetingService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.client; - -public class SimpleGreetingService implements GreetingService { - - @Override - public String getGreeting() { - return "Hello world!"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/DefaultEchoService.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/DefaultEchoService.java deleted file mode 100644 index 57a5879b0b..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/DefaultEchoService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.echo; - -public class DefaultEchoService implements EchoService { - - private final String echoFormat; - - public DefaultEchoService(String echoFormat) { - this.echoFormat = (echoFormat != null) ? echoFormat : "%s"; - } - - @Override - public String getMessage(String message) { - return String.format(this.echoFormat, message); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/EchoService.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/EchoService.java deleted file mode 100644 index 006c0fbc42..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/EchoService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.echo; - -public interface EchoService { - - String getMessage(String message); - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/EchoWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/EchoWebSocketHandler.java deleted file mode 100644 index 22c2e0ce8f..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo/EchoWebSocketHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.echo; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.web.socket.CloseStatus; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketHandler; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -/** - * Echo messages by implementing a Spring {@link WebSocketHandler} abstraction. - */ -public class EchoWebSocketHandler extends TextWebSocketHandler { - - private static Log logger = LogFactory.getLog(EchoWebSocketHandler.class); - - private final EchoService echoService; - - public EchoWebSocketHandler(EchoService echoService) { - this.echoService = echoService; - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) { - logger.debug("Opened new session in instance " + this); - } - - @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - String echoMessage = this.echoService.getMessage(message.getPayload()); - logger.debug(echoMessage); - session.sendMessage(new TextMessage(echoMessage)); - } - - @Override - public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { - session.close(CloseStatus.SERVER_ERROR); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/reverse/ReverseWebSocketEndpoint.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/reverse/ReverseWebSocketEndpoint.java deleted file mode 100644 index 857b3a5b14..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/reverse/ReverseWebSocketEndpoint.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.reverse; - -import java.io.IOException; - -import javax.websocket.OnMessage; -import javax.websocket.Session; -import javax.websocket.server.ServerEndpoint; - -@ServerEndpoint("/reverse") -public class ReverseWebSocketEndpoint { - - @OnMessage - public void handleMessage(Session session, String message) throws IOException { - session.getBasicRemote().sendText("Reversed: " + new StringBuilder(message).reverse()); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Direction.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Direction.java deleted file mode 100644 index 47fbba8ac8..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Direction.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.snake; - -public enum Direction { - - NONE, NORTH, SOUTH, EAST, WEST - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Location.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Location.java deleted file mode 100644 index 11072d857e..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Location.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.snake; - -public class Location { - - /** - * The X location. - */ - public int x; - - /** - * The Y location. - */ - public int y; - - public Location(int x, int y) { - this.x = x; - this.y = y; - } - - public Location getAdjacentLocation(Direction direction) { - switch (direction) { - case NORTH: - return new Location(this.x, this.y - SnakeUtils.GRID_SIZE); - case SOUTH: - return new Location(this.x, this.y + SnakeUtils.GRID_SIZE); - case EAST: - return new Location(this.x + SnakeUtils.GRID_SIZE, this.y); - case WEST: - return new Location(this.x - SnakeUtils.GRID_SIZE, this.y); - case NONE: - // fall through - default: - return this; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Location location = (Location) o; - if (this.x != location.x) { - return false; - } - if (this.y != location.y) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int result = this.x; - result = 31 * result + this.y; - return result; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Snake.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Snake.java deleted file mode 100644 index 2d2bba68c2..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/Snake.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.snake; - -import java.util.ArrayDeque; -import java.util.Collection; -import java.util.Deque; - -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; - -public class Snake { - - private static final int DEFAULT_LENGTH = 5; - - private final Deque<Location> tail = new ArrayDeque<>(); - - private final Object monitor = new Object(); - - private final int id; - - private final WebSocketSession session; - - private final String hexColor; - - private Direction direction; - - private int length = DEFAULT_LENGTH; - - private Location head; - - public Snake(int id, WebSocketSession session) { - this.id = id; - this.session = session; - this.hexColor = SnakeUtils.getRandomHexColor(); - resetState(); - } - - private void resetState() { - this.direction = Direction.NONE; - this.head = SnakeUtils.getRandomLocation(); - this.tail.clear(); - this.length = DEFAULT_LENGTH; - } - - private void kill() throws Exception { - synchronized (this.monitor) { - resetState(); - sendMessage("{'type': 'dead'}"); - } - } - - private void reward() throws Exception { - synchronized (this.monitor) { - this.length++; - sendMessage("{'type': 'kill'}"); - } - } - - protected void sendMessage(String msg) throws Exception { - this.session.sendMessage(new TextMessage(msg)); - } - - public void update(Collection<Snake> snakes) throws Exception { - synchronized (this.monitor) { - Location nextLocation = this.head.getAdjacentLocation(this.direction); - if (nextLocation.x >= SnakeUtils.PLAYFIELD_WIDTH) { - nextLocation.x = 0; - } - if (nextLocation.y >= SnakeUtils.PLAYFIELD_HEIGHT) { - nextLocation.y = 0; - } - if (nextLocation.x < 0) { - nextLocation.x = SnakeUtils.PLAYFIELD_WIDTH; - } - if (nextLocation.y < 0) { - nextLocation.y = SnakeUtils.PLAYFIELD_HEIGHT; - } - if (this.direction != Direction.NONE) { - this.tail.addFirst(this.head); - if (this.tail.size() > this.length) { - this.tail.removeLast(); - } - this.head = nextLocation; - } - - handleCollisions(snakes); - } - } - - private void handleCollisions(Collection<Snake> snakes) throws Exception { - for (Snake snake : snakes) { - boolean headCollision = this.id != snake.id && snake.getHead().equals(this.head); - boolean tailCollision = snake.getTail().contains(this.head); - if (headCollision || tailCollision) { - kill(); - if (this.id != snake.id) { - snake.reward(); - } - } - } - } - - public Location getHead() { - synchronized (this.monitor) { - return this.head; - } - } - - public Collection<Location> getTail() { - synchronized (this.monitor) { - return this.tail; - } - } - - public void setDirection(Direction direction) { - synchronized (this.monitor) { - this.direction = direction; - } - } - - public String getLocationsJson() { - synchronized (this.monitor) { - StringBuilder sb = new StringBuilder(); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y))); - for (Location location : this.tail) { - sb.append(','); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y))); - } - return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb.toString()); - } - } - - public int getId() { - return this.id; - } - - public String getHexColor() { - return this.hexColor; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeTimer.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeTimer.java deleted file mode 100644 index 8bf1a1fc05..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeTimer.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.snake; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Sets up the timer for the multi-player snake game WebSocket example. - */ -public final class SnakeTimer { - - private static final long TICK_DELAY = 100; - - private static final Object MONITOR = new Object(); - - private static final Log logger = LogFactory.getLog(SnakeTimer.class); - - private static final ConcurrentHashMap<Integer, Snake> snakes = new ConcurrentHashMap<>(); - - private static Timer gameTimer = null; - - private SnakeTimer() { - } - - public static void addSnake(Snake snake) { - synchronized (MONITOR) { - if (snakes.isEmpty()) { - startTimer(); - } - snakes.put(Integer.valueOf(snake.getId()), snake); - } - } - - public static Collection<Snake> getSnakes() { - return Collections.unmodifiableCollection(snakes.values()); - } - - public static void removeSnake(Snake snake) { - synchronized (MONITOR) { - snakes.remove(Integer.valueOf(snake.getId())); - if (snakes.isEmpty()) { - stopTimer(); - } - } - } - - public static void tick() throws Exception { - StringBuilder sb = new StringBuilder(); - for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { - Snake snake = iterator.next(); - snake.update(SnakeTimer.getSnakes()); - sb.append(snake.getLocationsJson()); - if (iterator.hasNext()) { - sb.append(','); - } - } - broadcast(String.format("{'type': 'update', 'data' : [%s]}", sb.toString())); - } - - public static void broadcast(String message) throws Exception { - Collection<Snake> snakes = new CopyOnWriteArrayList<>(SnakeTimer.getSnakes()); - for (Snake snake : snakes) { - try { - snake.sendMessage(message); - } - catch (Throwable ex) { - // if Snake#sendMessage fails the client is removed - removeSnake(snake); - } - } - } - - public static void startTimer() { - gameTimer = new Timer(SnakeTimer.class.getSimpleName() + " Timer"); - gameTimer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - try { - tick(); - } - catch (Throwable ex) { - logger.error("Caught to prevent timer from shutting down", ex); - } - } - }, TICK_DELAY, TICK_DELAY); - } - - public static void stopTimer() { - if (gameTimer != null) { - gameTimer.cancel(); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeUtils.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeUtils.java deleted file mode 100644 index 054a252d8a..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeUtils.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.snake; - -import java.awt.Color; -import java.util.Random; - -public final class SnakeUtils { - - /** - * The width of the playfield. - */ - public static final int PLAYFIELD_WIDTH = 640; - - /** - * The height of the playfield. - */ - public static final int PLAYFIELD_HEIGHT = 480; - - /** - * The grid size. - */ - public static final int GRID_SIZE = 10; - - private static final Random random = new Random(); - - private SnakeUtils() { - } - - public static String getRandomHexColor() { - float hue = random.nextFloat(); - // sat between 0.1 and 0.3 - float saturation = (random.nextInt(2000) + 1000) / 10000f; - float luminance = 0.9f; - Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); - } - - public static Location getRandomLocation() { - int x = roundByGridSize(random.nextInt(PLAYFIELD_WIDTH)); - int y = roundByGridSize(random.nextInt(PLAYFIELD_HEIGHT)); - return new Location(x, y); - } - - private static int roundByGridSize(int value) { - value = value + (GRID_SIZE / 2); - value = value / GRID_SIZE; - value = value * GRID_SIZE; - return value; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeWebSocketHandler.java deleted file mode 100644 index 4023957bd4..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/snake/SnakeWebSocketHandler.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.snake; - -import java.awt.Color; -import java.util.Iterator; -import java.util.Random; -import java.util.concurrent.atomic.AtomicInteger; - -import org.springframework.web.socket.CloseStatus; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -public class SnakeWebSocketHandler extends TextWebSocketHandler { - - private static final AtomicInteger snakeIds = new AtomicInteger(0); - - private static final Random random = new Random(); - - private final int id; - - private Snake snake; - - public static String getRandomHexColor() { - float hue = random.nextFloat(); - // sat between 0.1 and 0.3 - float saturation = (random.nextInt(2000) + 1000) / 10000f; - float luminance = 0.9f; - Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); - } - - public static Location getRandomLocation() { - int x = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_WIDTH)); - int y = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_HEIGHT)); - return new Location(x, y); - } - - private static int roundByGridSize(int value) { - value = value + (SnakeUtils.GRID_SIZE / 2); - value = value / SnakeUtils.GRID_SIZE; - value = value * SnakeUtils.GRID_SIZE; - return value; - } - - public SnakeWebSocketHandler() { - this.id = snakeIds.getAndIncrement(); - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) throws Exception { - this.snake = new Snake(this.id, session); - SnakeTimer.addSnake(this.snake); - StringBuilder sb = new StringBuilder(); - for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { - Snake snake = iterator.next(); - sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor())); - if (iterator.hasNext()) { - sb.append(','); - } - } - SnakeTimer.broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); - } - - @Override - protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - String payload = message.getPayload(); - if ("west".equals(payload)) { - this.snake.setDirection(Direction.WEST); - } - else if ("north".equals(payload)) { - this.snake.setDirection(Direction.NORTH); - } - else if ("east".equals(payload)) { - this.snake.setDirection(Direction.EAST); - } - else if ("south".equals(payload)) { - this.snake.setDirection(Direction.SOUTH); - } - } - - @Override - public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { - SnakeTimer.removeSnake(this.snake); - SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java deleted file mode 100644 index 5aad8587f5..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.jupiter.api.Test; -import samples.websocket.jetty.client.GreetingService; -import samples.websocket.jetty.client.SimpleClientWebSocketHandler; -import samples.websocket.jetty.client.SimpleGreetingService; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(classes = SampleJettyWebSocketsApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebSocketsApplicationTests { - - private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); - - @LocalServerPort - private int port = 1234; - - @Test - void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); - } - - @Test - void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/reverse") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); - } - - @Configuration(proxyBeanMethods = false) - static class ClientConfiguration implements CommandLineRunner { - - @Value("${websocket.uri}") - private String webSocketUri; - - private final CountDownLatch latch = new CountDownLatch(1); - - private final AtomicReference<String> messagePayload = new AtomicReference<>(); - - @Override - public void run(String... args) throws Exception { - logger.info("Waiting for response: latch=" + this.latch.getCount()); - if (this.latch.await(10, TimeUnit.SECONDS)) { - logger.info("Got response: " + this.messagePayload.get()); - } - else { - logger.info("Response not received: latch=" + this.latch.getCount()); - } - } - - @Bean - public WebSocketConnectionManager wsConnectionManager() { - - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); - manager.setAutoStartup(true); - - return manager; - } - - @Bean - public StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } - - @Bean - public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java deleted file mode 100644 index a6e414c6df..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.echo; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.jupiter.api.Test; -import samples.websocket.jetty.SampleJettyWebSocketsApplication; -import samples.websocket.jetty.client.GreetingService; -import samples.websocket.jetty.client.SimpleClientWebSocketHandler; -import samples.websocket.jetty.client.SimpleGreetingService; -import samples.websocket.jetty.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.boot.web.servlet.server.ServletWebServerFactory; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(classes = { SampleJettyWebSocketsApplication.class, CustomContainerConfiguration.class }, - webEnvironment = WebEnvironment.RANDOM_PORT) -class CustomContainerWebSocketsApplicationTests { - - private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class); - - @LocalServerPort - private int port; - - @Test - void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); - } - - @Test - void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); - } - - @Configuration(proxyBeanMethods = false) - protected static class CustomContainerConfiguration { - - @Bean - public ServletWebServerFactory webServerFactory() { - return new JettyServletWebServerFactory("/ws", 0); - } - - } - - @Configuration(proxyBeanMethods = false) - static class ClientConfiguration implements CommandLineRunner { - - @Value("${websocket.uri}") - private String webSocketUri; - - private final CountDownLatch latch = new CountDownLatch(1); - - private final AtomicReference<String> messagePayload = new AtomicReference<>(); - - @Override - public void run(String... args) throws Exception { - logger.info("Waiting for response: latch=" + this.latch.getCount()); - if (this.latch.await(10, TimeUnit.SECONDS)) { - logger.info("Got response: " + this.messagePayload.get()); - } - else { - logger.info("Response not received: latch=" + this.latch.getCount()); - } - } - - @Bean - public WebSocketConnectionManager wsConnectionManager() { - - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); - manager.setAutoStartup(true); - - return manager; - } - - @Bean - public StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } - - @Bean - public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/snake/SnakeTimerTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/snake/SnakeTimerTests.java deleted file mode 100644 index e6830d5f29..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/snake/SnakeTimerTests.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.jetty.snake; - -import java.io.IOException; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Mockito.mock; - -class SnakeTimerTests { - - @Test - void removeDysfunctionalSnakes() throws Exception { - Snake snake = mock(Snake.class); - willThrow(new IOException()).given(snake).sendMessage(anyString()); - SnakeTimer.addSnake(snake); - - SnakeTimer.broadcast(""); - assertThat(SnakeTimer.getSnakes()).hasSize(0); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/pom.xml b/spring-boot-samples/spring-boot-sample-websocket-tomcat/pom.xml deleted file mode 100755 index ccbc0cdf2a..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-websocket-tomcat</artifactId> - <name>Spring Boot WebSocket Tomcat Sample</name> - <description>Spring Boot WebSocket Tomcat Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-websocket</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/SampleTomcatWebSocketApplication.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/SampleTomcatWebSocketApplication.java deleted file mode 100644 index 25efa6bb10..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/SampleTomcatWebSocketApplication.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat; - -import samples.websocket.tomcat.client.GreetingService; -import samples.websocket.tomcat.client.SimpleGreetingService; -import samples.websocket.tomcat.echo.DefaultEchoService; -import samples.websocket.tomcat.echo.EchoService; -import samples.websocket.tomcat.echo.EchoWebSocketHandler; -import samples.websocket.tomcat.reverse.ReverseWebSocketEndpoint; -import samples.websocket.tomcat.snake.SnakeWebSocketHandler; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.WebSocketHandler; -import org.springframework.web.socket.config.annotation.EnableWebSocket; -import org.springframework.web.socket.config.annotation.WebSocketConfigurer; -import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; -import org.springframework.web.socket.handler.PerConnectionWebSocketHandler; -import org.springframework.web.socket.server.standard.ServerEndpointExporter; - -@Configuration(proxyBeanMethods = false) -@EnableAutoConfiguration -@EnableWebSocket -public class SampleTomcatWebSocketApplication extends SpringBootServletInitializer implements WebSocketConfigurer { - - @Override - public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(echoWebSocketHandler(), "/echo").withSockJS(); - registry.addHandler(snakeWebSocketHandler(), "/snake").withSockJS(); - } - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleTomcatWebSocketApplication.class); - } - - @Bean - public EchoService echoService() { - return new DefaultEchoService("Did you say \"%s\"?"); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - - @Bean - public WebSocketHandler echoWebSocketHandler() { - return new EchoWebSocketHandler(echoService()); - } - - @Bean - public WebSocketHandler snakeWebSocketHandler() { - return new PerConnectionWebSocketHandler(SnakeWebSocketHandler.class); - } - - @Bean - public ReverseWebSocketEndpoint reverseWebSocketEndpoint() { - return new ReverseWebSocketEndpoint(); - } - - @Bean - public ServerEndpointExporter serverEndpointExporter() { - return new ServerEndpointExporter(); - } - - public static void main(String[] args) { - SpringApplication.run(SampleTomcatWebSocketApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/GreetingService.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/GreetingService.java deleted file mode 100644 index 29f8b88816..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/GreetingService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.client; - -public interface GreetingService { - - String getGreeting(); - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/SimpleClientWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/SimpleClientWebSocketHandler.java deleted file mode 100644 index 685c70924a..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/SimpleClientWebSocketHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.client; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -public class SimpleClientWebSocketHandler extends TextWebSocketHandler { - - protected Log logger = LogFactory.getLog(SimpleClientWebSocketHandler.class); - - private final GreetingService greetingService; - - private final CountDownLatch latch; - - private final AtomicReference<String> messagePayload; - - public SimpleClientWebSocketHandler(GreetingService greetingService, CountDownLatch latch, - AtomicReference<String> message) { - this.greetingService = greetingService; - this.latch = latch; - this.messagePayload = message; - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) throws Exception { - TextMessage message = new TextMessage(this.greetingService.getGreeting()); - session.sendMessage(message); - } - - @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - this.logger.info("Received: " + message + " (" + this.latch.getCount() + ")"); - session.close(); - this.messagePayload.set(message.getPayload()); - this.latch.countDown(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/SimpleGreetingService.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/SimpleGreetingService.java deleted file mode 100644 index 6a93f6c2ce..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/client/SimpleGreetingService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.client; - -public class SimpleGreetingService implements GreetingService { - - @Override - public String getGreeting() { - return "Hello world!"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/DefaultEchoService.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/DefaultEchoService.java deleted file mode 100644 index 9e1212c312..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/DefaultEchoService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.echo; - -public class DefaultEchoService implements EchoService { - - private final String echoFormat; - - public DefaultEchoService(String echoFormat) { - this.echoFormat = (echoFormat != null) ? echoFormat : "%s"; - } - - @Override - public String getMessage(String message) { - return String.format(this.echoFormat, message); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/EchoService.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/EchoService.java deleted file mode 100644 index a188a47a01..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/EchoService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.echo; - -public interface EchoService { - - String getMessage(String message); - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/EchoWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/EchoWebSocketHandler.java deleted file mode 100644 index 7b7312d3a8..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/echo/EchoWebSocketHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.echo; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.web.socket.CloseStatus; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketHandler; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -/** - * Echo messages by implementing a Spring {@link WebSocketHandler} abstraction. - */ -public class EchoWebSocketHandler extends TextWebSocketHandler { - - private static Log logger = LogFactory.getLog(EchoWebSocketHandler.class); - - private final EchoService echoService; - - public EchoWebSocketHandler(EchoService echoService) { - this.echoService = echoService; - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) { - logger.debug("Opened new session in instance " + this); - } - - @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - String echoMessage = this.echoService.getMessage(message.getPayload()); - logger.debug(echoMessage); - session.sendMessage(new TextMessage(echoMessage)); - } - - @Override - public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { - session.close(CloseStatus.SERVER_ERROR); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/reverse/ReverseWebSocketEndpoint.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/reverse/ReverseWebSocketEndpoint.java deleted file mode 100644 index 0d3e2245cc..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/reverse/ReverseWebSocketEndpoint.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.reverse; - -import java.io.IOException; - -import javax.websocket.OnMessage; -import javax.websocket.Session; -import javax.websocket.server.ServerEndpoint; - -@ServerEndpoint("/reverse") -public class ReverseWebSocketEndpoint { - - @OnMessage - public void handleMessage(Session session, String message) throws IOException { - session.getBasicRemote().sendText("Reversed: " + new StringBuilder(message).reverse()); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Direction.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Direction.java deleted file mode 100644 index 9ffe6f776d..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Direction.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.snake; - -public enum Direction { - - NONE, NORTH, SOUTH, EAST, WEST - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Location.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Location.java deleted file mode 100644 index 0137f19965..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Location.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.snake; - -public class Location { - - /** - * The X location. - */ - public int x; - - /** - * The Y location. - */ - public int y; - - public Location(int x, int y) { - this.x = x; - this.y = y; - } - - public Location getAdjacentLocation(Direction direction) { - switch (direction) { - case NORTH: - return new Location(this.x, this.y - SnakeUtils.GRID_SIZE); - case SOUTH: - return new Location(this.x, this.y + SnakeUtils.GRID_SIZE); - case EAST: - return new Location(this.x + SnakeUtils.GRID_SIZE, this.y); - case WEST: - return new Location(this.x - SnakeUtils.GRID_SIZE, this.y); - case NONE: - // fall through - default: - return this; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Location location = (Location) o; - if (this.x != location.x) { - return false; - } - if (this.y != location.y) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int result = this.x; - result = 31 * result + this.y; - return result; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Snake.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Snake.java deleted file mode 100644 index b576047e1e..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/Snake.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.snake; - -import java.util.ArrayDeque; -import java.util.Collection; -import java.util.Deque; - -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; - -public class Snake { - - private static final int DEFAULT_LENGTH = 5; - - private final Deque<Location> tail = new ArrayDeque<>(); - - private final Object monitor = new Object(); - - private final int id; - - private final WebSocketSession session; - - private final String hexColor; - - private Direction direction; - - private int length = DEFAULT_LENGTH; - - private Location head; - - public Snake(int id, WebSocketSession session) { - this.id = id; - this.session = session; - this.hexColor = SnakeUtils.getRandomHexColor(); - resetState(); - } - - private void resetState() { - this.direction = Direction.NONE; - this.head = SnakeUtils.getRandomLocation(); - this.tail.clear(); - this.length = DEFAULT_LENGTH; - } - - private void kill() throws Exception { - synchronized (this.monitor) { - resetState(); - sendMessage("{'type': 'dead'}"); - } - } - - private void reward() throws Exception { - synchronized (this.monitor) { - this.length++; - sendMessage("{'type': 'kill'}"); - } - } - - protected void sendMessage(String msg) throws Exception { - this.session.sendMessage(new TextMessage(msg)); - } - - public void update(Collection<Snake> snakes) throws Exception { - synchronized (this.monitor) { - Location nextLocation = this.head.getAdjacentLocation(this.direction); - if (nextLocation.x >= SnakeUtils.PLAYFIELD_WIDTH) { - nextLocation.x = 0; - } - if (nextLocation.y >= SnakeUtils.PLAYFIELD_HEIGHT) { - nextLocation.y = 0; - } - if (nextLocation.x < 0) { - nextLocation.x = SnakeUtils.PLAYFIELD_WIDTH; - } - if (nextLocation.y < 0) { - nextLocation.y = SnakeUtils.PLAYFIELD_HEIGHT; - } - if (this.direction != Direction.NONE) { - this.tail.addFirst(this.head); - if (this.tail.size() > this.length) { - this.tail.removeLast(); - } - this.head = nextLocation; - } - - handleCollisions(snakes); - } - } - - private void handleCollisions(Collection<Snake> snakes) throws Exception { - for (Snake snake : snakes) { - boolean headCollision = this.id != snake.id && snake.getHead().equals(this.head); - boolean tailCollision = snake.getTail().contains(this.head); - if (headCollision || tailCollision) { - kill(); - if (this.id != snake.id) { - snake.reward(); - } - } - } - } - - public Location getHead() { - synchronized (this.monitor) { - return this.head; - } - } - - public Collection<Location> getTail() { - synchronized (this.monitor) { - return this.tail; - } - } - - public void setDirection(Direction direction) { - synchronized (this.monitor) { - this.direction = direction; - } - } - - public String getLocationsJson() { - synchronized (this.monitor) { - StringBuilder sb = new StringBuilder(); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y))); - for (Location location : this.tail) { - sb.append(','); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y))); - } - return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb.toString()); - } - } - - public int getId() { - return this.id; - } - - public String getHexColor() { - return this.hexColor; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeTimer.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeTimer.java deleted file mode 100644 index 69595d0862..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeTimer.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.snake; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Sets up the timer for the multi-player snake game WebSocket example. - */ -public final class SnakeTimer { - - private static final long TICK_DELAY = 100; - - private static final Object MONITOR = new Object(); - - private static final Log logger = LogFactory.getLog(SnakeTimer.class); - - private static final ConcurrentHashMap<Integer, Snake> snakes = new ConcurrentHashMap<>(); - - private static Timer gameTimer = null; - - private SnakeTimer() { - } - - public static void addSnake(Snake snake) { - synchronized (MONITOR) { - if (snakes.isEmpty()) { - startTimer(); - } - snakes.put(Integer.valueOf(snake.getId()), snake); - } - } - - public static Collection<Snake> getSnakes() { - return Collections.unmodifiableCollection(snakes.values()); - } - - public static void removeSnake(Snake snake) { - synchronized (MONITOR) { - snakes.remove(Integer.valueOf(snake.getId())); - if (snakes.isEmpty()) { - stopTimer(); - } - } - } - - public static void tick() throws Exception { - StringBuilder sb = new StringBuilder(); - for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { - Snake snake = iterator.next(); - snake.update(SnakeTimer.getSnakes()); - sb.append(snake.getLocationsJson()); - if (iterator.hasNext()) { - sb.append(','); - } - } - broadcast(String.format("{'type': 'update', 'data' : [%s]}", sb.toString())); - } - - public static void broadcast(String message) throws Exception { - Collection<Snake> snakes = new CopyOnWriteArrayList<>(SnakeTimer.getSnakes()); - for (Snake snake : snakes) { - try { - snake.sendMessage(message); - } - catch (Throwable ex) { - // if Snake#sendMessage fails the client is removed - removeSnake(snake); - } - } - } - - public static void startTimer() { - gameTimer = new Timer(SnakeTimer.class.getSimpleName() + " Timer"); - gameTimer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - try { - tick(); - } - catch (Throwable ex) { - logger.error("Caught to prevent timer from shutting down", ex); - } - } - }, TICK_DELAY, TICK_DELAY); - } - - public static void stopTimer() { - if (gameTimer != null) { - gameTimer.cancel(); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeUtils.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeUtils.java deleted file mode 100644 index ff0e3764ef..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeUtils.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.snake; - -import java.awt.Color; -import java.util.Random; - -public final class SnakeUtils { - - /** - * The width of the playfield. - */ - public static final int PLAYFIELD_WIDTH = 640; - - /** - * The height of the playfield. - */ - public static final int PLAYFIELD_HEIGHT = 480; - - /** - * The grid size. - */ - public static final int GRID_SIZE = 10; - - private static final Random random = new Random(); - - private SnakeUtils() { - } - - public static String getRandomHexColor() { - float hue = random.nextFloat(); - // sat between 0.1 and 0.3 - float saturation = (random.nextInt(2000) + 1000) / 10000f; - float luminance = 0.9f; - Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); - } - - public static Location getRandomLocation() { - int x = roundByGridSize(random.nextInt(PLAYFIELD_WIDTH)); - int y = roundByGridSize(random.nextInt(PLAYFIELD_HEIGHT)); - return new Location(x, y); - } - - private static int roundByGridSize(int value) { - value = value + (GRID_SIZE / 2); - value = value / GRID_SIZE; - value = value * GRID_SIZE; - return value; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeWebSocketHandler.java deleted file mode 100644 index c35a633eb6..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/tomcat/snake/SnakeWebSocketHandler.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.snake; - -import java.awt.Color; -import java.util.Iterator; -import java.util.Random; -import java.util.concurrent.atomic.AtomicInteger; - -import org.springframework.web.socket.CloseStatus; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -public class SnakeWebSocketHandler extends TextWebSocketHandler { - - private static final AtomicInteger snakeIds = new AtomicInteger(0); - - private static final Random random = new Random(); - - private final int id; - - private Snake snake; - - public static String getRandomHexColor() { - float hue = random.nextFloat(); - // sat between 0.1 and 0.3 - float saturation = (random.nextInt(2000) + 1000) / 10000f; - float luminance = 0.9f; - Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); - } - - public static Location getRandomLocation() { - int x = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_WIDTH)); - int y = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_HEIGHT)); - return new Location(x, y); - } - - private static int roundByGridSize(int value) { - value = value + (SnakeUtils.GRID_SIZE / 2); - value = value / SnakeUtils.GRID_SIZE; - value = value * SnakeUtils.GRID_SIZE; - return value; - } - - public SnakeWebSocketHandler() { - this.id = snakeIds.getAndIncrement(); - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) throws Exception { - this.snake = new Snake(this.id, session); - SnakeTimer.addSnake(this.snake); - StringBuilder sb = new StringBuilder(); - for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { - Snake snake = iterator.next(); - sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor())); - if (iterator.hasNext()) { - sb.append(','); - } - } - SnakeTimer.broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); - } - - @Override - protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - String payload = message.getPayload(); - if ("west".equals(payload)) { - this.snake.setDirection(Direction.WEST); - } - else if ("north".equals(payload)) { - this.snake.setDirection(Direction.NORTH); - } - else if ("east".equals(payload)) { - this.snake.setDirection(Direction.EAST); - } - else if ("south".equals(payload)) { - this.snake.setDirection(Direction.SOUTH); - } - } - - @Override - public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { - SnakeTimer.removeSnake(this.snake); - SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java deleted file mode 100644 index 47023e4547..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.jupiter.api.Test; -import samples.websocket.tomcat.client.GreetingService; -import samples.websocket.tomcat.client.SimpleClientWebSocketHandler; -import samples.websocket.tomcat.client.SimpleGreetingService; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(classes = SampleTomcatWebSocketApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebSocketsApplicationTests { - - private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); - - @LocalServerPort - private int port = 1234; - - @Test - void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); - } - - @Test - void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/reverse") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); - } - - @Configuration(proxyBeanMethods = false) - static class ClientConfiguration implements CommandLineRunner { - - @Value("${websocket.uri}") - private String webSocketUri; - - private final CountDownLatch latch = new CountDownLatch(1); - - private final AtomicReference<String> messagePayload = new AtomicReference<>(); - - @Override - public void run(String... args) throws Exception { - logger.info("Waiting for response: latch=" + this.latch.getCount()); - if (this.latch.await(10, TimeUnit.SECONDS)) { - logger.info("Got response: " + this.messagePayload.get()); - } - else { - logger.info("Response not received: latch=" + this.latch.getCount()); - } - } - - @Bean - public WebSocketConnectionManager wsConnectionManager() { - - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); - manager.setAutoStartup(true); - - return manager; - } - - @Bean - public StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } - - @Bean - public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java deleted file mode 100644 index 7ca76c7148..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.echo; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.jupiter.api.Test; -import samples.websocket.tomcat.SampleTomcatWebSocketApplication; -import samples.websocket.tomcat.client.GreetingService; -import samples.websocket.tomcat.client.SimpleClientWebSocketHandler; -import samples.websocket.tomcat.client.SimpleGreetingService; -import samples.websocket.tomcat.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.boot.web.servlet.server.ServletWebServerFactory; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(classes = { SampleTomcatWebSocketApplication.class, CustomContainerConfiguration.class }, - webEnvironment = WebEnvironment.RANDOM_PORT) -class CustomContainerWebSocketsApplicationTests { - - private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class); - - @LocalServerPort - private int port; - - @Test - void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); - } - - @Test - void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); - } - - @Configuration(proxyBeanMethods = false) - protected static class CustomContainerConfiguration { - - @Bean - public ServletWebServerFactory webServerFactory() { - return new TomcatServletWebServerFactory("/ws", 0); - } - - } - - @Configuration(proxyBeanMethods = false) - static class ClientConfiguration implements CommandLineRunner { - - @Value("${websocket.uri}") - private String webSocketUri; - - private final CountDownLatch latch = new CountDownLatch(1); - - private final AtomicReference<String> messagePayload = new AtomicReference<>(); - - @Override - public void run(String... args) throws Exception { - logger.info("Waiting for response: latch=" + this.latch.getCount()); - if (this.latch.await(10, TimeUnit.SECONDS)) { - logger.info("Got response: " + this.messagePayload.get()); - } - else { - logger.info("Response not received: latch=" + this.latch.getCount()); - } - } - - @Bean - public WebSocketConnectionManager wsConnectionManager() { - - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); - manager.setAutoStartup(true); - - return manager; - } - - @Bean - public StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } - - @Bean - public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/snake/SnakeTimerTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/snake/SnakeTimerTests.java deleted file mode 100644 index 4e5c642474..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/snake/SnakeTimerTests.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.tomcat.snake; - -import java.io.IOException; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Mockito.mock; - -class SnakeTimerTests { - - @Test - void removeDysfunctionalSnakes() throws Exception { - Snake snake = mock(Snake.class); - willThrow(new IOException()).given(snake).sendMessage(anyString()); - SnakeTimer.addSnake(snake); - SnakeTimer.broadcast(""); - assertThat(SnakeTimer.getSnakes()).hasSize(0); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/pom.xml b/spring-boot-samples/spring-boot-sample-websocket-undertow/pom.xml deleted file mode 100755 index 5d0a263888..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-websocket-undertow</artifactId> - <name>Spring Boot WebSocket Undertow Sample</name> - <description>Spring Boot WebSocket Undertow Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-websocket</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-undertow</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/SampleUndertowWebSocketsApplication.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/SampleUndertowWebSocketsApplication.java deleted file mode 100644 index ebd0d7d5e7..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/SampleUndertowWebSocketsApplication.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow; - -import samples.websocket.undertow.client.GreetingService; -import samples.websocket.undertow.client.SimpleGreetingService; -import samples.websocket.undertow.echo.DefaultEchoService; -import samples.websocket.undertow.echo.EchoService; -import samples.websocket.undertow.echo.EchoWebSocketHandler; -import samples.websocket.undertow.reverse.ReverseWebSocketEndpoint; -import samples.websocket.undertow.snake.SnakeWebSocketHandler; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.WebSocketHandler; -import org.springframework.web.socket.config.annotation.EnableWebSocket; -import org.springframework.web.socket.config.annotation.WebSocketConfigurer; -import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; -import org.springframework.web.socket.handler.PerConnectionWebSocketHandler; -import org.springframework.web.socket.server.standard.ServerEndpointExporter; - -@Configuration(proxyBeanMethods = false) -@EnableAutoConfiguration -@EnableWebSocket -public class SampleUndertowWebSocketsApplication extends SpringBootServletInitializer implements WebSocketConfigurer { - - @Override - public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(echoWebSocketHandler(), "/echo").setAllowedOrigins("*").withSockJS(); - registry.addHandler(snakeWebSocketHandler(), "/snake").setAllowedOrigins("*").withSockJS(); - } - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleUndertowWebSocketsApplication.class); - } - - @Bean - public EchoService echoService() { - return new DefaultEchoService("Did you say \"%s\"?"); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - - @Bean - public WebSocketHandler echoWebSocketHandler() { - return new EchoWebSocketHandler(echoService()); - } - - @Bean - public WebSocketHandler snakeWebSocketHandler() { - return new PerConnectionWebSocketHandler(SnakeWebSocketHandler.class); - } - - @Bean - public ReverseWebSocketEndpoint reverseWebSocketEndpoint() { - return new ReverseWebSocketEndpoint(); - } - - @Bean - public ServerEndpointExporter serverEndpointExporter() { - return new ServerEndpointExporter(); - } - - public static void main(String[] args) { - SpringApplication.run(SampleUndertowWebSocketsApplication.class, args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/GreetingService.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/GreetingService.java deleted file mode 100644 index 9e80f3fd9a..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/GreetingService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.client; - -public interface GreetingService { - - String getGreeting(); - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/SimpleClientWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/SimpleClientWebSocketHandler.java deleted file mode 100644 index 4ada967e84..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/SimpleClientWebSocketHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.client; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -public class SimpleClientWebSocketHandler extends TextWebSocketHandler { - - protected Log logger = LogFactory.getLog(SimpleClientWebSocketHandler.class); - - private final GreetingService greetingService; - - private final CountDownLatch latch; - - private final AtomicReference<String> messagePayload; - - public SimpleClientWebSocketHandler(GreetingService greetingService, CountDownLatch latch, - AtomicReference<String> message) { - this.greetingService = greetingService; - this.latch = latch; - this.messagePayload = message; - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) throws Exception { - TextMessage message = new TextMessage(this.greetingService.getGreeting()); - session.sendMessage(message); - } - - @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - this.logger.info("Received: " + message + " (" + this.latch.getCount() + ")"); - session.close(); - this.messagePayload.set(message.getPayload()); - this.latch.countDown(); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/SimpleGreetingService.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/SimpleGreetingService.java deleted file mode 100644 index ebb99bd826..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/client/SimpleGreetingService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.client; - -public class SimpleGreetingService implements GreetingService { - - @Override - public String getGreeting() { - return "Hello world!"; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/DefaultEchoService.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/DefaultEchoService.java deleted file mode 100644 index 530b30551d..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/DefaultEchoService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.echo; - -public class DefaultEchoService implements EchoService { - - private final String echoFormat; - - public DefaultEchoService(String echoFormat) { - this.echoFormat = (echoFormat != null) ? echoFormat : "%s"; - } - - @Override - public String getMessage(String message) { - return String.format(this.echoFormat, message); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/EchoService.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/EchoService.java deleted file mode 100644 index bd1ece52a1..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/EchoService.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.echo; - -public interface EchoService { - - String getMessage(String message); - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/EchoWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/EchoWebSocketHandler.java deleted file mode 100644 index ca51c57824..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/echo/EchoWebSocketHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.echo; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.web.socket.CloseStatus; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketHandler; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -/** - * Echo messages by implementing a Spring {@link WebSocketHandler} abstraction. - */ -public class EchoWebSocketHandler extends TextWebSocketHandler { - - private static Log logger = LogFactory.getLog(EchoWebSocketHandler.class); - - private final EchoService echoService; - - public EchoWebSocketHandler(EchoService echoService) { - this.echoService = echoService; - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) { - logger.debug("Opened new session in instance " + this); - } - - @Override - public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - String echoMessage = this.echoService.getMessage(message.getPayload()); - logger.debug(echoMessage); - session.sendMessage(new TextMessage(echoMessage)); - } - - @Override - public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { - session.close(CloseStatus.SERVER_ERROR); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/reverse/ReverseWebSocketEndpoint.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/reverse/ReverseWebSocketEndpoint.java deleted file mode 100644 index a5a9de3f07..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/reverse/ReverseWebSocketEndpoint.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.reverse; - -import java.io.IOException; - -import javax.websocket.OnMessage; -import javax.websocket.Session; -import javax.websocket.server.ServerEndpoint; - -@ServerEndpoint("/reverse") -public class ReverseWebSocketEndpoint { - - @OnMessage - public void handleMessage(Session session, String message) throws IOException { - session.getBasicRemote().sendText("Reversed: " + new StringBuilder(message).reverse()); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Direction.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Direction.java deleted file mode 100644 index ee1296271c..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Direction.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.snake; - -public enum Direction { - - NONE, NORTH, SOUTH, EAST, WEST - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Location.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Location.java deleted file mode 100644 index 9c094aff02..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Location.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.snake; - -public class Location { - - /** - * The X location. - */ - public int x; - - /** - * The Y location. - */ - public int y; - - public Location(int x, int y) { - this.x = x; - this.y = y; - } - - public Location getAdjacentLocation(Direction direction) { - switch (direction) { - case NORTH: - return new Location(this.x, this.y - SnakeUtils.GRID_SIZE); - case SOUTH: - return new Location(this.x, this.y + SnakeUtils.GRID_SIZE); - case EAST: - return new Location(this.x + SnakeUtils.GRID_SIZE, this.y); - case WEST: - return new Location(this.x - SnakeUtils.GRID_SIZE, this.y); - case NONE: - // fall through - default: - return this; - } - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Location location = (Location) o; - if (this.x != location.x) { - return false; - } - if (this.y != location.y) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int result = this.x; - result = 31 * result + this.y; - return result; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Snake.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Snake.java deleted file mode 100644 index 8b7ea21b3e..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/Snake.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.snake; - -import java.util.ArrayDeque; -import java.util.Collection; -import java.util.Deque; - -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; - -public class Snake { - - private static final int DEFAULT_LENGTH = 5; - - private final Deque<Location> tail = new ArrayDeque<>(); - - private final Object monitor = new Object(); - - private final int id; - - private final WebSocketSession session; - - private final String hexColor; - - private Direction direction; - - private int length = DEFAULT_LENGTH; - - private Location head; - - public Snake(int id, WebSocketSession session) { - this.id = id; - this.session = session; - this.hexColor = SnakeUtils.getRandomHexColor(); - resetState(); - } - - private void resetState() { - this.direction = Direction.NONE; - this.head = SnakeUtils.getRandomLocation(); - this.tail.clear(); - this.length = DEFAULT_LENGTH; - } - - private void kill() throws Exception { - synchronized (this.monitor) { - resetState(); - sendMessage("{'type': 'dead'}"); - } - } - - private void reward() throws Exception { - synchronized (this.monitor) { - this.length++; - sendMessage("{'type': 'kill'}"); - } - } - - protected void sendMessage(String msg) throws Exception { - this.session.sendMessage(new TextMessage(msg)); - } - - public void update(Collection<Snake> snakes) throws Exception { - synchronized (this.monitor) { - Location nextLocation = this.head.getAdjacentLocation(this.direction); - if (nextLocation.x >= SnakeUtils.PLAYFIELD_WIDTH) { - nextLocation.x = 0; - } - if (nextLocation.y >= SnakeUtils.PLAYFIELD_HEIGHT) { - nextLocation.y = 0; - } - if (nextLocation.x < 0) { - nextLocation.x = SnakeUtils.PLAYFIELD_WIDTH; - } - if (nextLocation.y < 0) { - nextLocation.y = SnakeUtils.PLAYFIELD_HEIGHT; - } - if (this.direction != Direction.NONE) { - this.tail.addFirst(this.head); - if (this.tail.size() > this.length) { - this.tail.removeLast(); - } - this.head = nextLocation; - } - - handleCollisions(snakes); - } - } - - private void handleCollisions(Collection<Snake> snakes) throws Exception { - for (Snake snake : snakes) { - boolean headCollision = this.id != snake.id && snake.getHead().equals(this.head); - boolean tailCollision = snake.getTail().contains(this.head); - if (headCollision || tailCollision) { - kill(); - if (this.id != snake.id) { - snake.reward(); - } - } - } - } - - public Location getHead() { - synchronized (this.monitor) { - return this.head; - } - } - - public Collection<Location> getTail() { - synchronized (this.monitor) { - return this.tail; - } - } - - public void setDirection(Direction direction) { - synchronized (this.monitor) { - this.direction = direction; - } - } - - public String getLocationsJson() { - synchronized (this.monitor) { - StringBuilder sb = new StringBuilder(); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y))); - for (Location location : this.tail) { - sb.append(','); - sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y))); - } - return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb.toString()); - } - } - - public int getId() { - return this.id; - } - - public String getHexColor() { - return this.hexColor; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeTimer.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeTimer.java deleted file mode 100644 index 9cab39ad37..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeTimer.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.snake; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Sets up the timer for the multi-player snake game WebSocket example. - */ -public final class SnakeTimer { - - private static final long TICK_DELAY = 100; - - private static final Object MONITOR = new Object(); - - private static final Log logger = LogFactory.getLog(SnakeTimer.class); - - private static final ConcurrentHashMap<Integer, Snake> snakes = new ConcurrentHashMap<>(); - - private static Timer gameTimer = null; - - private SnakeTimer() { - } - - public static void addSnake(Snake snake) { - synchronized (MONITOR) { - if (snakes.isEmpty()) { - startTimer(); - } - snakes.put(Integer.valueOf(snake.getId()), snake); - } - } - - public static Collection<Snake> getSnakes() { - return Collections.unmodifiableCollection(snakes.values()); - } - - public static void removeSnake(Snake snake) { - synchronized (MONITOR) { - snakes.remove(Integer.valueOf(snake.getId())); - if (snakes.isEmpty()) { - stopTimer(); - } - } - } - - public static void tick() throws Exception { - StringBuilder sb = new StringBuilder(); - for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { - Snake snake = iterator.next(); - snake.update(SnakeTimer.getSnakes()); - sb.append(snake.getLocationsJson()); - if (iterator.hasNext()) { - sb.append(','); - } - } - broadcast(String.format("{'type': 'update', 'data' : [%s]}", sb.toString())); - } - - public static void broadcast(String message) throws Exception { - Collection<Snake> snakes = new CopyOnWriteArrayList<>(SnakeTimer.getSnakes()); - for (Snake snake : snakes) { - try { - snake.sendMessage(message); - } - catch (Throwable ex) { - // if Snake#sendMessage fails the client is removed - removeSnake(snake); - } - } - } - - public static void startTimer() { - gameTimer = new Timer(SnakeTimer.class.getSimpleName() + " Timer"); - gameTimer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - try { - tick(); - } - catch (Throwable ex) { - logger.error("Caught to prevent timer from shutting down", ex); - } - } - }, TICK_DELAY, TICK_DELAY); - } - - public static void stopTimer() { - if (gameTimer != null) { - gameTimer.cancel(); - } - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeUtils.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeUtils.java deleted file mode 100644 index a41587c76c..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeUtils.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.snake; - -import java.awt.Color; -import java.util.Random; - -public final class SnakeUtils { - - /** - * The width of the playfield. - */ - public static final int PLAYFIELD_WIDTH = 640; - - /** - * The height of the playfield. - */ - public static final int PLAYFIELD_HEIGHT = 480; - - /** - * The grid size. - */ - public static final int GRID_SIZE = 10; - - private static final Random random = new Random(); - - private SnakeUtils() { - } - - public static String getRandomHexColor() { - float hue = random.nextFloat(); - // sat between 0.1 and 0.3 - float saturation = (random.nextInt(2000) + 1000) / 10000f; - float luminance = 0.9f; - Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); - } - - public static Location getRandomLocation() { - int x = roundByGridSize(random.nextInt(PLAYFIELD_WIDTH)); - int y = roundByGridSize(random.nextInt(PLAYFIELD_HEIGHT)); - return new Location(x, y); - } - - private static int roundByGridSize(int value) { - value = value + (GRID_SIZE / 2); - value = value / GRID_SIZE; - value = value * GRID_SIZE; - return value; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeWebSocketHandler.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeWebSocketHandler.java deleted file mode 100644 index aefc5f2eab..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/undertow/snake/SnakeWebSocketHandler.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.snake; - -import java.awt.Color; -import java.util.Iterator; -import java.util.Random; -import java.util.concurrent.atomic.AtomicInteger; - -import org.springframework.web.socket.CloseStatus; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; -import org.springframework.web.socket.handler.TextWebSocketHandler; - -public class SnakeWebSocketHandler extends TextWebSocketHandler { - - private static final AtomicInteger snakeIds = new AtomicInteger(0); - - private static final Random random = new Random(); - - private final int id; - - private Snake snake; - - public static String getRandomHexColor() { - float hue = random.nextFloat(); - // sat between 0.1 and 0.3 - float saturation = (random.nextInt(2000) + 1000) / 10000f; - float luminance = 0.9f; - Color color = Color.getHSBColor(hue, saturation, luminance); - return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); - } - - public static Location getRandomLocation() { - int x = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_WIDTH)); - int y = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_HEIGHT)); - return new Location(x, y); - } - - private static int roundByGridSize(int value) { - value = value + (SnakeUtils.GRID_SIZE / 2); - value = value / SnakeUtils.GRID_SIZE; - value = value * SnakeUtils.GRID_SIZE; - return value; - } - - public SnakeWebSocketHandler() { - this.id = snakeIds.getAndIncrement(); - } - - @Override - public void afterConnectionEstablished(WebSocketSession session) throws Exception { - this.snake = new Snake(this.id, session); - SnakeTimer.addSnake(this.snake); - StringBuilder sb = new StringBuilder(); - for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { - Snake snake = iterator.next(); - sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor())); - if (iterator.hasNext()) { - sb.append(','); - } - } - SnakeTimer.broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); - } - - @Override - protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { - String payload = message.getPayload(); - if ("west".equals(payload)) { - this.snake.setDirection(Direction.WEST); - } - else if ("north".equals(payload)) { - this.snake.setDirection(Direction.NORTH); - } - else if ("east".equals(payload)) { - this.snake.setDirection(Direction.EAST); - } - else if ("south".equals(payload)) { - this.snake.setDirection(Direction.SOUTH); - } - } - - @Override - public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { - SnakeTimer.removeSnake(this.snake); - SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java deleted file mode 100644 index 2d48780b35..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.jupiter.api.Test; -import samples.websocket.undertow.client.GreetingService; -import samples.websocket.undertow.client.SimpleClientWebSocketHandler; -import samples.websocket.undertow.client.SimpleGreetingService; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(classes = SampleUndertowWebSocketsApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) -class SampleWebSocketsApplicationTests { - - private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); - - @LocalServerPort - private int port = 1234; - - @Test - void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); - } - - @Test - void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/reverse") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); - } - - @Configuration(proxyBeanMethods = false) - static class ClientConfiguration implements CommandLineRunner { - - @Value("${websocket.uri}") - private String webSocketUri; - - private final CountDownLatch latch = new CountDownLatch(1); - - private final AtomicReference<String> messagePayload = new AtomicReference<>(); - - @Override - public void run(String... args) throws Exception { - logger.info("Waiting for response: latch=" + this.latch.getCount()); - if (this.latch.await(10, TimeUnit.SECONDS)) { - logger.info("Got response: " + this.messagePayload.get()); - } - else { - logger.info("Response not received: latch=" + this.latch.getCount()); - } - } - - @Bean - public WebSocketConnectionManager wsConnectionManager() { - - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); - manager.setAutoStartup(true); - - return manager; - } - - @Bean - public StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } - - @Bean - public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java deleted file mode 100644 index 8485c0c965..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.echo; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.jupiter.api.Test; -import samples.websocket.undertow.SampleUndertowWebSocketsApplication; -import samples.websocket.undertow.client.GreetingService; -import samples.websocket.undertow.client.SimpleClientWebSocketHandler; -import samples.websocket.undertow.client.SimpleGreetingService; -import samples.websocket.undertow.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.boot.web.servlet.server.ServletWebServerFactory; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.client.WebSocketConnectionManager; -import org.springframework.web.socket.client.standard.StandardWebSocketClient; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(classes = { SampleUndertowWebSocketsApplication.class, CustomContainerConfiguration.class }, - webEnvironment = WebEnvironment.RANDOM_PORT) -class CustomContainerWebSocketsApplicationTests { - - private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class); - - @LocalServerPort - private int port; - - @Test - void echoEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); - } - - @Test - void reverseEndpoint() { - ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, - PropertyPlaceholderAutoConfiguration.class) - .properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse") - .run("--spring.main.web-application-type=none"); - long count = context.getBean(ClientConfiguration.class).latch.getCount(); - AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; - context.close(); - assertThat(count).isEqualTo(0); - assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); - } - - @Configuration(proxyBeanMethods = false) - protected static class CustomContainerConfiguration { - - @Bean - public ServletWebServerFactory webServerFactory() { - return new UndertowServletWebServerFactory("/ws", 0); - } - - } - - @Configuration(proxyBeanMethods = false) - static class ClientConfiguration implements CommandLineRunner { - - @Value("${websocket.uri}") - private String webSocketUri; - - private final CountDownLatch latch = new CountDownLatch(1); - - private final AtomicReference<String> messagePayload = new AtomicReference<>(); - - @Override - public void run(String... args) throws Exception { - logger.info("Waiting for response: latch=" + this.latch.getCount()); - if (this.latch.await(10, TimeUnit.SECONDS)) { - logger.info("Got response: " + this.messagePayload.get()); - } - else { - logger.info("Response not received: latch=" + this.latch.getCount()); - } - } - - @Bean - public WebSocketConnectionManager wsConnectionManager() { - - WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); - manager.setAutoStartup(true); - - return manager; - } - - @Bean - public StandardWebSocketClient client() { - return new StandardWebSocketClient(); - } - - @Bean - public SimpleClientWebSocketHandler handler() { - return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); - } - - @Bean - public GreetingService greetingService() { - return new SimpleGreetingService(); - } - - } - -} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/snake/SnakeTimerTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/snake/SnakeTimerTests.java deleted file mode 100644 index e9b9a11bb3..0000000000 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/snake/SnakeTimerTests.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package samples.websocket.undertow.snake; - -import java.io.IOException; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Mockito.mock; - -class SnakeTimerTests { - - @Test - void removeDysfunctionalSnakes() throws Exception { - Snake snake = mock(Snake.class); - willThrow(new IOException()).given(snake).sendMessage(anyString()); - SnakeTimer.addSnake(snake); - SnakeTimer.broadcast(""); - assertThat(SnakeTimer.getSnakes()).hasSize(0); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-xml/pom.xml b/spring-boot-samples/spring-boot-sample-xml/pom.xml deleted file mode 100644 index a50fc95b97..0000000000 --- a/spring-boot-samples/spring-boot-sample-xml/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <!-- Your own application should inherit from spring-boot-starter-parent --> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-samples</artifactId> - <version>${revision}</version> - </parent> - <artifactId>spring-boot-sample-xml</artifactId> - <name>Spring Boot XML Sample</name> - <description>Spring Boot XML Sample</description> - <properties> - <main.basedir>${basedir}/../..</main.basedir> - </properties> - <dependencies> - <!-- Compile --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter</artifactId> - </dependency> - <!-- Test --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> diff --git a/spring-boot-samples/spring-boot-sample-xml/src/main/java/sample/xml/SampleSpringXmlApplication.java b/spring-boot-samples/spring-boot-sample-xml/src/main/java/sample/xml/SampleSpringXmlApplication.java deleted file mode 100644 index 2806b38a12..0000000000 --- a/spring-boot-samples/spring-boot-sample-xml/src/main/java/sample/xml/SampleSpringXmlApplication.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.xml; - -import java.util.Collections; - -import sample.xml.service.HelloWorldService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; - -public class SampleSpringXmlApplication implements CommandLineRunner { - - private static final String CONTEXT_XML = "classpath:/META-INF/application-context.xml"; - - @Autowired - private HelloWorldService helloWorldService; - - @Override - public void run(String... args) { - System.out.println(this.helloWorldService.getHelloMessage()); - } - - public static void main(String[] args) { - SpringApplication application = new SpringApplication(); - application.setSources(Collections.singleton(CONTEXT_XML)); - application.run(args); - } - -} diff --git a/spring-boot-samples/spring-boot-sample-xml/src/main/java/sample/xml/service/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-xml/src/main/java/sample/xml/service/HelloWorldService.java deleted file mode 100644 index 36415b5431..0000000000 --- a/spring-boot-samples/spring-boot-sample-xml/src/main/java/sample/xml/service/HelloWorldService.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.xml.service; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class HelloWorldService { - - @Value("${name:World}") - private String name; - - public String getHelloMessage() { - return "Hello " + this.name; - } - -} diff --git a/spring-boot-samples/spring-boot-sample-xml/src/main/resources/META-INF/application-context.xml b/spring-boot-samples/spring-boot-sample-xml/src/main/resources/META-INF/application-context.xml deleted file mode 100644 index f080646aa1..0000000000 --- a/spring-boot-samples/spring-boot-sample-xml/src/main/resources/META-INF/application-context.xml +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:context="http://www.springframework.org/schema/context" - xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"> - - <context:annotation-config/> - <context:property-placeholder/> - - <bean id="helloService" class="sample.xml.service.HelloWorldService"/> - <bean id="application" class="sample.xml.SampleSpringXmlApplication"/> - -</beans> diff --git a/spring-boot-samples/spring-boot-sample-xml/src/test/java/sample/xml/SampleSpringXmlApplicationTests.java b/spring-boot-samples/spring-boot-sample-xml/src/test/java/sample/xml/SampleSpringXmlApplicationTests.java deleted file mode 100644 index c3f27c40d2..0000000000 --- a/spring-boot-samples/spring-boot-sample-xml/src/test/java/sample/xml/SampleSpringXmlApplicationTests.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.xml; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; - -import static org.assertj.core.api.Assertions.assertThat; - -@ExtendWith(OutputCaptureExtension.class) -class SampleSpringXmlApplicationTests { - - @Test - void testDefaultSettings(CapturedOutput capturedOutput) throws Exception { - SampleSpringXmlApplication.main(new String[0]); - assertThat(capturedOutput).contains("Hello World"); - } - -} diff --git a/spring-boot-smoke-tests-invoker/pom.xml b/spring-boot-smoke-tests-invoker/pom.xml new file mode 100644 index 0000000000..7b5000a38b --- /dev/null +++ b/spring-boot-smoke-tests-invoker/pom.xml @@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-parent</artifactId> + <version>${revision}</version> + <relativePath>../spring-boot-project/spring-boot-parent</relativePath> + </parent> + <artifactId>spring-boot-smoke-tests-invoker</artifactId> + <packaging>pom</packaging> + <name>Spring Boot Smoke Tests Invoker</name> + <description>Spring Boot Smoke Tests Invoker</description> + <properties> + <main.basedir>${basedir}/..</main.basedir> + </properties> + <build> + <plugins> + <plugin> + <!-- We use invoker so that the spring-boot-maven-plugin can be used --> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-invoker-plugin</artifactId> + <inherited>false</inherited> + <configuration> + <projectsDirectory>${main.basedir}/spring-boot-smoke-tests</projectsDirectory> + <skipInvocation>${skipTests}</skipInvocation> + <streamLogs>true</streamLogs> + <pomIncludes> + <pomInclude>pom.xml</pomInclude> + </pomIncludes> + </configuration> + <executions> + <execution> + <id>integration-test</id> + <phase>install</phase> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <inherited>false</inherited> + <executions> + <execution> + <id>clean-smoke-tests</id> + <phase>clean</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <target> + <delete includeemptydirs="true"> + <fileset dir="${main.basedir}/spring-boot-smoke-tests" + includes="**/target/" /> + </delete> + </target> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-clean-plugin</artifactId> + <inherited>false</inherited> + <executions> + <execution> + <id>clean-smoke-tests</id> + <phase>clean</phase> + <goals> + <goal>clean</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/pom.xml b/spring-boot-smoke-tests/pom.xml new file mode 100644 index 0000000000..8ee30bd110 --- /dev/null +++ b/spring-boot-smoke-tests/pom.xml @@ -0,0 +1,250 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-parent</artifactId> + <version>${revision}</version> + <relativePath>../spring-boot-project/spring-boot-starters/spring-boot-starter-parent</relativePath> + </parent> + <artifactId>spring-boot-smoke-tests</artifactId> + <packaging>pom</packaging> + <name>Spring Boot Smoke Tests</name> + <description>Spring Boot Smoke Tests</description> + <properties> + <main.basedir>${basedir}/..</main.basedir> + <java.version>1.8</java.version> + <disable.checks>false</disable.checks> + </properties> + <modules> + <module>spring-boot-smoke-test-ant</module> + <module>spring-boot-smoke-test-activemq</module> + <module>spring-boot-smoke-test-actuator</module> + <module>spring-boot-smoke-test-actuator-log4j2</module> + <module>spring-boot-smoke-test-actuator-noweb</module> + <module>spring-boot-smoke-test-actuator-ui</module> + <module>spring-boot-smoke-test-actuator-custom-security</module> + <module>spring-boot-smoke-test-amqp</module> + <module>spring-boot-smoke-test-animated-banner</module> + <module>spring-boot-smoke-test-aop</module> + <module>spring-boot-smoke-test-atmosphere</module> + <module>spring-boot-smoke-test-batch</module> + <module>spring-boot-smoke-test-cache</module> + <module>spring-boot-smoke-test-custom-layout</module> + <module>spring-boot-smoke-test-data-cassandra</module> + <module>spring-boot-smoke-test-data-couchbase</module> + <module>spring-boot-smoke-test-data-elasticsearch</module> + <module>spring-boot-smoke-test-data-jdbc</module> + <module>spring-boot-smoke-test-data-jpa</module> + <module>spring-boot-smoke-test-data-ldap</module> + <module>spring-boot-smoke-test-data-mongodb</module> + <module>spring-boot-smoke-test-data-neo4j</module> + <module>spring-boot-smoke-test-data-redis</module> + <module>spring-boot-smoke-test-data-rest</module> + <module>spring-boot-smoke-test-data-solr</module> + <module>spring-boot-smoke-test-devtools</module> + <module>spring-boot-smoke-test-flyway</module> + <module>spring-boot-smoke-test-hateoas</module> + <module>spring-boot-smoke-test-integration</module> + <module>spring-boot-smoke-test-jersey</module> + <module>spring-boot-smoke-test-jetty</module> + <module>spring-boot-smoke-test-jetty-jsp</module> + <module>spring-boot-smoke-test-jetty-ssl</module> + <module>spring-boot-smoke-test-jooq</module> + <module>spring-boot-smoke-test-jpa</module> + <module>spring-boot-smoke-test-jta-atomikos</module> + <module>spring-boot-smoke-test-jta-bitronix</module> + <module>spring-boot-smoke-test-jta-jndi</module> + <module>spring-boot-smoke-test-junit-jupiter</module> + <module>spring-boot-smoke-test-junit-vintage</module> + <module>spring-boot-smoke-test-kafka</module> + <module>spring-boot-smoke-test-liquibase</module> + <module>spring-boot-smoke-test-logback</module> + <module>spring-boot-smoke-test-oauth2-client</module> + <module>spring-boot-smoke-test-oauth2-resource-server</module> + <module>spring-boot-smoke-test-parent-context</module> + <module>spring-boot-smoke-test-profile</module> + <module>spring-boot-smoke-test-property-validation</module> + <module>spring-boot-smoke-test-quartz</module> + <module>spring-boot-smoke-test-reactive-oauth2-client</module> + <module>spring-boot-smoke-test-reactive-oauth2-resource-server</module> + <module>spring-boot-smoke-test-secure</module> + <module>spring-boot-smoke-test-secure-webflux</module> + <module>spring-boot-smoke-test-servlet</module> + <module>spring-boot-smoke-test-session</module> + <module>spring-boot-smoke-test-session-webflux</module> + <module>spring-boot-smoke-test-simple</module> + <module>spring-boot-smoke-test-test</module> + <module>spring-boot-smoke-test-test-nomockito</module> + <module>spring-boot-smoke-test-testng</module> + <module>spring-boot-smoke-test-tomcat</module> + <module>spring-boot-smoke-test-tomcat-jsp</module> + <module>spring-boot-smoke-test-tomcat-ssl</module> + <module>spring-boot-smoke-test-tomcat-multi-connectors</module> + <module>spring-boot-smoke-test-traditional</module> + <module>spring-boot-smoke-test-undertow</module> + <module>spring-boot-smoke-test-undertow-ssl</module> + <module>spring-boot-smoke-test-war</module> + <module>spring-boot-smoke-test-web-freemarker</module> + <module>spring-boot-smoke-test-web-groovy-templates</module> + <module>spring-boot-smoke-test-web-jsp</module> + <module>spring-boot-smoke-test-web-method-security</module> + <module>spring-boot-smoke-test-web-mustache</module> + <module>spring-boot-smoke-test-web-secure</module> + <module>spring-boot-smoke-test-web-secure-custom</module> + <module>spring-boot-smoke-test-web-secure-jdbc</module> + <module>spring-boot-smoke-test-web-static</module> + <module>spring-boot-smoke-test-web-ui</module> + <module>spring-boot-smoke-test-webflux</module> + <module>spring-boot-smoke-test-websocket-jetty</module> + <module>spring-boot-smoke-test-websocket-tomcat</module> + <module>spring-boot-smoke-test-websocket-undertow</module> + <module>spring-boot-smoke-test-webservices</module> + <module>spring-boot-smoke-test-xml</module> + </modules> + <!-- No dependencies - otherwise the smoke tests won't work if you change the + parent --> + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>flatten-maven-plugin</artifactId> + <inherited>true</inherited> + <executions> + <execution> + <id>flatten</id> + <phase>process-resources</phase> + <goals> + <goal>flatten</goal> + </goals> + <configuration> + <updatePomFile>true</updatePomFile> + <flattenMode>oss</flattenMode> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.eclipse.m2e</groupId> + <artifactId>lifecycle-mapping</artifactId> + <version>1.0.0</version> + <configuration> + <lifecycleMappingMetadata> + <pluginExecutions> + <pluginExecution> + <pluginExecutionFilter> + <groupId> + org.apache.maven.plugins + </groupId> + <artifactId> + maven-enforcer-plugin + </artifactId> + <versionRange> + [1.3.1,) + </versionRange> + <goals> + <goal>enforce</goal> + </goals> + </pluginExecutionFilter> + <action> + <ignore /> + </action> + </pluginExecution> + <pluginExecution> + <pluginExecutionFilter> + <groupId> + org.springframework.boot + </groupId> + <artifactId> + spring-boot-maven-plugin + </artifactId> + <versionRange> + [1.4.0.BUILD-SNAPSHOT,) + </versionRange> + <goals> + <goal>build-info</goal> + </goals> + </pluginExecutionFilter> + <action> + <ignore /> + </action> + </pluginExecution> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + </plugins> + </pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <includes> + <include>**/*Tests.java</include> + </includes> + <excludes> + <exclude>**/Abstract*.java</exclude> + </excludes> + <systemPropertyVariables> + <java.security.egd>file:/dev/./urandom</java.security.egd> + <java.awt.headless>true</java.awt.headless> + </systemPropertyVariables> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <executions> + <execution> + <id>enforce-rules</id> + <goals> + <goal>enforce</goal> + </goals> + <configuration> + <rules> + <bannedDependencies> + <excludes> + <exclude>commons-logging:*:*</exclude> + </excludes> + <searchTransitive>true</searchTransitive> + </bannedDependencies> + </rules> + <fail>true</fail> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-install-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + <inherited>true</inherited> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>fast</id> + <activation> + <property> + <name>fast</name> + </property> + </activation> + <properties> + <disable.checks>true</disable.checks> + </properties> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/pom.xml new file mode 100644 index 0000000000..b5bc123aeb --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <artifactId>spring-boot-smoke-tests</artifactId> + <groupId>org.springframework.boot</groupId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-activemq</artifactId> + <name>Spring Boot ActiveMQ Smoke Test</name> + <description>Spring Boot ActiveMQ Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-activemq</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/java/smoketest/activemq/Consumer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/java/smoketest/activemq/Consumer.java new file mode 100644 index 0000000000..9be8c0b322 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/java/smoketest/activemq/Consumer.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.activemq; + +import org.springframework.jms.annotation.JmsListener; +import org.springframework.stereotype.Component; + +@Component +public class Consumer { + + @JmsListener(destination = "sample.queue") + public void receiveQueue(String text) { + System.out.println(text); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/java/smoketest/activemq/Producer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/java/smoketest/activemq/Producer.java new file mode 100644 index 0000000000..a6bfcb2b52 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/java/smoketest/activemq/Producer.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.activemq; + +import javax.jms.Queue; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.jms.core.JmsMessagingTemplate; +import org.springframework.stereotype.Component; + +@Component +public class Producer implements CommandLineRunner { + + @Autowired + private JmsMessagingTemplate jmsMessagingTemplate; + + @Autowired + private Queue queue; + + @Override + public void run(String... args) throws Exception { + send("Sample message"); + System.out.println("Message was sent to the Queue"); + } + + public void send(String msg) { + this.jmsMessagingTemplate.convertAndSend(this.queue, msg); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/java/smoketest/activemq/SampleActiveMQApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/java/smoketest/activemq/SampleActiveMQApplication.java new file mode 100644 index 0000000000..a1cb3301bb --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/java/smoketest/activemq/SampleActiveMQApplication.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.activemq; + +import javax.jms.Queue; + +import org.apache.activemq.command.ActiveMQQueue; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.jms.annotation.EnableJms; + +@SpringBootApplication +@EnableJms +public class SampleActiveMQApplication { + + @Bean + public Queue queue() { + return new ActiveMQQueue("sample.queue"); + } + + public static void main(String[] args) { + SpringApplication.run(SampleActiveMQApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-activemq/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-activemq/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/test/java/smoketest/activemq/SampleActiveMqTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/test/java/smoketest/activemq/SampleActiveMqTests.java new file mode 100644 index 0000000000..8912287133 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-activemq/src/test/java/smoketest/activemq/SampleActiveMqTests.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.activemq; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for demo application. + * + * @author Eddú Meléndez + */ +@SpringBootTest +@ExtendWith(OutputCaptureExtension.class) +class SampleActiveMqTests { + + @Autowired + private Producer producer; + + @Test + void sendSimpleMessage(CapturedOutput capturedOutput) throws InterruptedException { + this.producer.send("Test message"); + Thread.sleep(1000L); + assertThat(capturedOutput).contains("Test message"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/pom.xml new file mode 100644 index 0000000000..57cc81ade8 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/pom.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-actuator-custom-security</artifactId> + <name>Spring Boot Actuator Custom Security Smoke Test</name> + <description>Spring Boot Actuator Custom Security Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-freemarker</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <dependency> + <groupId>org.jolokia</groupId> + <artifactId>jolokia-core</artifactId> + </dependency> + <!-- Runtime --> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>runtime</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/ExampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/ExampleController.java new file mode 100644 index 0000000000..65933a96f2 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/ExampleController.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.customsecurity; + +import java.util.Date; +import java.util.Map; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class ExampleController { + + @GetMapping("/") + public String home(Map<String, Object> model) { + model.put("message", "Hello World"); + model.put("title", "Hello Home"); + model.put("date", new Date()); + return "home"; + } + + @RequestMapping("/foo") + public String foo() { + throw new RuntimeException("Expected exception in controller"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/ExampleRestControllerEndpoint.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/ExampleRestControllerEndpoint.java new file mode 100644 index 0000000000..12566a20dc --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/ExampleRestControllerEndpoint.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.customsecurity; + +import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Component +@RestControllerEndpoint(id = "example") +public class ExampleRestControllerEndpoint { + + @GetMapping("/echo") + public ResponseEntity<String> echo(@RequestParam("text") String text) { + return ResponseEntity.ok().header("echo", text).body(text); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/SampleActuatorCustomSecurityApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/SampleActuatorCustomSecurityApplication.java new file mode 100644 index 0000000000..1b98fbfee4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/SampleActuatorCustomSecurityApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.customsecurity; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleActuatorCustomSecurityApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleActuatorCustomSecurityApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/SecurityConfiguration.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/SecurityConfiguration.java new file mode 100644 index 0000000000..011927e17f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/java/smoketest/actuator/customsecurity/SecurityConfiguration.java @@ -0,0 +1,60 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.customsecurity; + +import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; +import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; + +@Configuration(proxyBeanMethods = false) +public class SecurityConfiguration extends WebSecurityConfigurerAdapter { + + @SuppressWarnings("deprecation") + @Bean + public InMemoryUserDetailsManager inMemoryUserDetailsManager() { + return new InMemoryUserDetailsManager( + User.withDefaultPasswordEncoder().username("user").password("password").authorities("ROLE_USER") + .build(), + User.withDefaultPasswordEncoder().username("beans").password("beans").authorities("ROLE_BEANS").build(), + User.withDefaultPasswordEncoder().username("admin").password("admin") + .authorities("ROLE_ACTUATOR", "ROLE_USER").build()); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + // @formatter:off + http.authorizeRequests() + .mvcMatchers("/actuator/beans").hasRole("BEANS") + .requestMatchers(EndpointRequest.to("health", "info")).permitAll() + .requestMatchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class)).hasRole("ACTUATOR") + .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() + .antMatchers("/foo").permitAll() + .antMatchers("/**").hasRole("USER") + .and() + .cors() + .and() + .httpBasic(); + // @formatter:on + } + +} diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/resources/static/css/bootstrap.min.css b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/resources/static/css/bootstrap.min.css similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/resources/static/css/bootstrap.min.css rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/resources/static/css/bootstrap.min.css diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/resources/templates/error.ftlh b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/resources/templates/error.ftlh similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/resources/templates/error.ftlh rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/resources/templates/error.ftlh diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/resources/templates/home.ftlh b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/resources/templates/home.ftlh similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/resources/templates/home.ftlh rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/main/resources/templates/home.ftlh diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/CorsSampleActuatorApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/CorsSampleActuatorApplicationTests.java new file mode 100644 index 0000000000..e077b45d17 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/CorsSampleActuatorApplicationTests.java @@ -0,0 +1,83 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.customsecurity; + +import java.net.URI; +import java.util.Map; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.ApplicationContext; +import org.springframework.http.HttpStatus; +import org.springframework.http.RequestEntity; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration test for cors preflight requests to management endpoints. + * + * @author Madhura Bhave + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("cors") +class CorsSampleActuatorApplicationTests { + + private TestRestTemplate testRestTemplate; + + @Autowired + private ApplicationContext applicationContext; + + @BeforeEach + void setUp() { + RestTemplateBuilder builder = new RestTemplateBuilder(); + LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(this.applicationContext.getEnvironment(), + "http"); + builder = builder.uriTemplateHandler(handler); + this.testRestTemplate = new TestRestTemplate(builder); + } + + @Test + void endpointShouldReturnUnauthorized() { + ResponseEntity<?> entity = this.testRestTemplate.getForEntity("/actuator/env", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void preflightRequestToEndpointShouldReturnOk() throws Exception { + RequestEntity<?> healthRequest = RequestEntity.options(new URI("/actuator/env")) + .header("Origin", "http://localhost:8080").header("Access-Control-Request-Method", "GET").build(); + ResponseEntity<?> exchange = this.testRestTemplate.exchange(healthRequest, Map.class); + assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.OK); + } + + @Test + void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() throws Exception { + RequestEntity<?> entity = RequestEntity.options(new URI("/actuator/env")) + .header("Origin", "http://localhost:9095").header("Access-Control-Request-Method", "GET").build(); + ResponseEntity<byte[]> exchange = this.testRestTemplate.exchange(entity, byte[].class); + assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java new file mode 100644 index 0000000000..412c8a82b2 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java @@ -0,0 +1,85 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.customsecurity; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for separate management and main service ports. + * + * @author Dave Syer + * @author Madhura Bhave + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, + properties = { "management.server.port=0", "management.server.servlet.context-path=/management" }) +class ManagementPortAndPathSampleActuatorApplicationTests { + + @LocalServerPort + private int port; + + @LocalManagementPort + private int managementPort; + + @Test + void testHome() { + ResponseEntity<String> entity = new TestRestTemplate("user", "password") + .getForEntity("http://localhost:" + this.port, String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("Hello World"); + } + + @Test + void actuatorPathOnMainPortShouldNotMatch() { + ResponseEntity<String> entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.port + "/actuator/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void testSecureActuator() { + ResponseEntity<String> entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + "/management/actuator/env", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void testInsecureActuator() { + ResponseEntity<String> entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + "/management/actuator/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + } + + @Test + void testMissing() { + ResponseEntity<String> entity = new TestRestTemplate("admin", "admin") + .getForEntity("http://localhost:" + this.managementPort + "/management/actuator/missing", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + assertThat(entity.getBody()).contains("\"status\":404"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java new file mode 100644 index 0000000000..a27eda943d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/java/smoketest/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java @@ -0,0 +1,162 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.customsecurity; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Madhura Bhave + * @author Stephane Nicoll + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class SampleActuatorCustomSecurityApplicationTests { + + @Autowired + private Environment environment; + + @Test + void homeIsSecure() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = restTemplate().getForEntity("/", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("error")).isEqualTo("Unauthorized"); + assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); + } + + @Test + void testInsecureApplicationPath() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = restTemplate().getForEntity("/foo", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat((String) body.get("message")).contains("Expected exception in controller"); + } + + @Test + void testInsecureStaticResources() { + ResponseEntity<String> entity = restTemplate().getForEntity("/css/bootstrap.min.css", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); + } + + @Test + void actuatorInsecureEndpoint() { + ResponseEntity<String> entity = restTemplate().getForEntity("/actuator/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + } + + @Test + void actuatorLinksIsSecure() { + ResponseEntity<Object> entity = restTemplate().getForEntity("/actuator", Object.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + entity = adminRestTemplate().getForEntity("/actuator", Object.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + } + + @Test + void actuatorSecureEndpointWithAnonymous() { + ResponseEntity<Object> entity = restTemplate().getForEntity("/actuator/env", Object.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void actuatorSecureEndpointWithUnauthorizedUser() { + ResponseEntity<Object> entity = userRestTemplate().getForEntity("/actuator/env", Object.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); + } + + @Test + void actuatorSecureEndpointWithAuthorizedUser() { + ResponseEntity<Object> entity = adminRestTemplate().getForEntity("/actuator/env", Object.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + } + + @Test + void actuatorCustomMvcSecureEndpointWithAnonymous() { + ResponseEntity<String> entity = restTemplate().getForEntity("/actuator/example/echo?text={t}", String.class, + "test"); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void actuatorCustomMvcSecureEndpointWithUnauthorizedUser() { + ResponseEntity<String> entity = userRestTemplate().getForEntity("/actuator/example/echo?text={t}", String.class, + "test"); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); + } + + @Test + void actuatorCustomMvcSecureEndpointWithAuthorizedUser() { + ResponseEntity<String> entity = adminRestTemplate().getForEntity("/actuator/example/echo?text={t}", + String.class, "test"); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("test"); + assertThat(entity.getHeaders().getFirst("echo")).isEqualTo("test"); + } + + @Test + void actuatorExcludedFromEndpointRequestMatcher() { + ResponseEntity<Object> entity = userRestTemplate().getForEntity("/actuator/mappings", Object.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + } + + @Test + void mvcMatchersCanBeUsedToSecureActuators() { + ResponseEntity<Object> entity = beansRestTemplate().getForEntity("/actuator/beans", Object.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + entity = beansRestTemplate().getForEntity("/actuator/beans/", Object.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + } + + private TestRestTemplate restTemplate() { + return configure(new TestRestTemplate()); + } + + private TestRestTemplate adminRestTemplate() { + return configure(new TestRestTemplate("admin", "admin")); + } + + private TestRestTemplate userRestTemplate() { + return configure(new TestRestTemplate("user", "password")); + } + + private TestRestTemplate beansRestTemplate() { + return configure(new TestRestTemplate("beans", "beans")); + } + + private TestRestTemplate configure(TestRestTemplate restTemplate) { + restTemplate.setUriTemplateHandler(new LocalHostUriTemplateHandler(this.environment)); + return restTemplate; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/resources/application-cors.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/resources/application-cors.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/resources/application-cors.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-custom-security/src/test/resources/application-cors.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/pom.xml new file mode 100644 index 0000000000..8f0779761e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/pom.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-actuator-log4j2</artifactId> + <name>Spring Boot Actuator Log4j 2 Smoke Test</name> + <description>Spring Boot Actuator Log4j 2 Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-log4j2</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/src/main/java/smoketest/actuator/log4j2/SampleActuatorLog4J2Application.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/src/main/java/smoketest/actuator/log4j2/SampleActuatorLog4J2Application.java new file mode 100644 index 0000000000..a6d7126a77 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/src/main/java/smoketest/actuator/log4j2/SampleActuatorLog4J2Application.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.log4j2; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleActuatorLog4J2Application { + + public static void main(String[] args) { + SpringApplication.run(SampleActuatorLog4J2Application.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/log4j2.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/src/main/resources/log4j2.xml similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/resources/log4j2.xml rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/src/main/resources/log4j2.xml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/src/test/java/smoketest/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/src/test/java/smoketest/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java new file mode 100644 index 0000000000..1ee0a2ffd2 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-log4j2/src/test/java/smoketest/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java @@ -0,0 +1,72 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.log4j2; + +import java.util.Base64; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.test.web.servlet.MockMvc; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * Tests for {@link SampleActuatorLog4J2Application}. + * + * @author Dave Syer + * @author Stephane Nicoll + */ +@SpringBootTest +@AutoConfigureMockMvc +@ExtendWith(OutputCaptureExtension.class) +class SampleActuatorLog4J2ApplicationTests { + + private static final Logger logger = LogManager.getLogger(SampleActuatorLog4J2ApplicationTests.class); + + @Autowired + private MockMvc mvc; + + @Test + void testLogger(CapturedOutput capturedOutput) { + logger.info("Hello World"); + assertThat(capturedOutput).contains("Hello World"); + } + + @Test + void validateLoggersEndpoint() throws Exception { + this.mvc.perform(get("/actuator/loggers/org.apache.coyote.http11.Http11NioProtocol").header("Authorization", + "Basic " + getBasicAuth())).andExpect(status().isOk()).andExpect( + content().string(equalTo("{\"configuredLevel\":\"WARN\"," + "\"effectiveLevel\":\"WARN\"}"))); + } + + private String getBasicAuth() { + return new String(Base64.getEncoder().encode(("user:password").getBytes())); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/pom.xml new file mode 100644 index 0000000000..c270cb1b44 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/pom.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-actuator-noweb</artifactId> + <name>Spring Boot Actuator Non-Web Smoke Test</name> + <description>Spring Boot Actuator Non-Web Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <!-- Optional --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <optional>true</optional> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/java/smoketest/actuator/noweb/HelloWorldService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/java/smoketest/actuator/noweb/HelloWorldService.java new file mode 100644 index 0000000000..553fa54db9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/java/smoketest/actuator/noweb/HelloWorldService.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.noweb; + +import org.springframework.stereotype.Component; + +@Component +public class HelloWorldService { + + private final ServiceProperties configuration; + + public HelloWorldService(ServiceProperties configuration) { + this.configuration = configuration; + } + + public String getHelloMessage() { + return "Hello " + this.configuration.getName(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/java/smoketest/actuator/noweb/SampleActuatorNoWebApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/java/smoketest/actuator/noweb/SampleActuatorNoWebApplication.java new file mode 100644 index 0000000000..ed53132776 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/java/smoketest/actuator/noweb/SampleActuatorNoWebApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.noweb; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleActuatorNoWebApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleActuatorNoWebApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/java/smoketest/actuator/noweb/ServiceProperties.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/java/smoketest/actuator/noweb/ServiceProperties.java new file mode 100644 index 0000000000..035593601b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/java/smoketest/actuator/noweb/ServiceProperties.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.noweb; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) +public class ServiceProperties { + + /** + * Name of the service. + */ + private String name = "World"; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/resources/banner.txt b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/resources/banner.txt similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/resources/banner.txt rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/main/resources/banner.txt diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/test/java/smoketest/actuator/noweb/SampleActuatorNoWebApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/test/java/smoketest/actuator/noweb/SampleActuatorNoWebApplicationTests.java new file mode 100644 index 0000000000..4abc5070a6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-noweb/src/test/java/smoketest/actuator/noweb/SampleActuatorNoWebApplicationTests.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.noweb; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.test.context.SpringBootTest; + +/** + * Basic integration tests for service demo application. + * + * @author Dave Syer + */ +@SpringBootTest +class SampleActuatorNoWebApplicationTests { + + @Test + void contextLoads() { + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/pom.xml new file mode 100644 index 0000000000..a698ff768b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/pom.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-actuator-ui</artifactId> + <name>Spring Boot Actuator UI Smoke Test</name> + <description>Spring Boot Actuator UI Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-freemarker</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <dependency> + <groupId>org.jolokia</groupId> + <artifactId>jolokia-core</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/main/java/smoketest/actuator/ui/SampleActuatorUiApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/main/java/smoketest/actuator/ui/SampleActuatorUiApplication.java new file mode 100644 index 0000000000..44a2742570 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/main/java/smoketest/actuator/ui/SampleActuatorUiApplication.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.ui; + +import java.util.Date; +import java.util.Map; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@SpringBootApplication +@Controller +public class SampleActuatorUiApplication { + + @GetMapping("/") + public String home(Map<String, Object> model) { + model.put("message", "Hello World"); + model.put("title", "Hello Home"); + model.put("date", new Date()); + return "home"; + } + + @RequestMapping("/foo") + public String foo() { + throw new RuntimeException("Expected exception in controller"); + } + + public static void main(String[] args) { + SpringApplication.run(SampleActuatorUiApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/static/css/bootstrap.min.css b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/main/resources/static/css/bootstrap.min.css similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/static/css/bootstrap.min.css rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/main/resources/static/css/bootstrap.min.css diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/templates/error.ftlh b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/main/resources/templates/error.ftlh similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/templates/error.ftlh rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/main/resources/templates/error.ftlh diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/templates/home.ftlh b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/main/resources/templates/home.ftlh similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator-ui/src/main/resources/templates/home.ftlh rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/main/resources/templates/home.ftlh diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/test/java/smoketest/actuator/ui/SampleActuatorUiApplicationPortTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/test/java/smoketest/actuator/ui/SampleActuatorUiApplicationPortTests.java new file mode 100644 index 0000000000..c8009a6a5c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/test/java/smoketest/actuator/ui/SampleActuatorUiApplicationPortTests.java @@ -0,0 +1,74 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.ui; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for separate management and main service ports. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port:0" }) +class SampleActuatorUiApplicationPortTests { + + @LocalServerPort + private int port; + + @LocalManagementPort + private int managementPort; + + @Test + void testHome() { + ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + } + + @Test + void testMetrics() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void testHealth() { + ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + } + + private String getPassword() { + return "password"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/test/java/smoketest/actuator/ui/SampleActuatorUiApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/test/java/smoketest/actuator/ui/SampleActuatorUiApplicationTests.java new file mode 100644 index 0000000000..dc5c966b32 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator-ui/src/test/java/smoketest/actuator/ui/SampleActuatorUiApplicationTests.java @@ -0,0 +1,87 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator.ui; + +import java.util.Arrays; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleActuatorUiApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHome() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/", + HttpMethod.GET, new HttpEntity<Void>(headers), String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("<title>Hello"); + } + + @Test + void testCss() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); + } + + @Test + void testMetrics() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void testError() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/error", + HttpMethod.GET, new HttpEntity<Void>(headers), String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + assertThat(entity.getBody()).contains("<html>").contains("<body>") + .contains("Please contact the operator with the above information"); + } + + private String getPassword() { + return "password"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/pom.xml new file mode 100644 index 0000000000..d8c4217e12 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/pom.xml @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-actuator</artifactId> + <name>Spring Boot Actuator Smoke Test</name> + <description>Spring Boot Actuator Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jdbc</artifactId> + </dependency> + <!-- Runtime --> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>runtime</scope> + </dependency> + <!-- Optional --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <optional>true</optional> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + </configuration> + <executions> + <execution> + <id>generate build info</id> + <goals> + <goal>build-info</goal> + </goals> + <configuration> + <additionalProperties> + <encoding.source>${project.build.sourceEncoding}</encoding.source> + <encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting> + <java.source>${maven.compiler.source}</java.source> + <java.target>${maven.compiler.target}</java.target> + </additionalProperties> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/ExampleHealthIndicator.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/ExampleHealthIndicator.java new file mode 100644 index 0000000000..11e7ffbdda --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/ExampleHealthIndicator.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.stereotype.Component; + +@Component +public class ExampleHealthIndicator implements HealthIndicator { + + @Override + public Health health() { + return Health.up().withDetail("counter", 42).build(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/ExampleInfoContributor.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/ExampleInfoContributor.java new file mode 100644 index 0000000000..232b32b765 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/ExampleInfoContributor.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import java.util.Collections; + +import org.springframework.boot.actuate.info.Info; +import org.springframework.boot.actuate.info.InfoContributor; +import org.springframework.stereotype.Component; + +@Component +public class ExampleInfoContributor implements InfoContributor { + + @Override + public void contribute(Info.Builder builder) { + builder.withDetail("example", Collections.singletonMap("someKey", "someValue")); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/HelloWorldService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/HelloWorldService.java new file mode 100644 index 0000000000..f4d70a9560 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/HelloWorldService.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import org.springframework.stereotype.Component; + +@Component +public class HelloWorldService { + + private final ServiceProperties configuration; + + public HelloWorldService(ServiceProperties configuration) { + this.configuration = configuration; + } + + public String getHelloMessage() { + return "Hello " + this.configuration.getName(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/SampleActuatorApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/SampleActuatorApplication.java new file mode 100644 index 0000000000..06ac8e7b15 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/SampleActuatorApplication.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class SampleActuatorApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleActuatorApplication.class, args); + } + + @Bean + public HealthIndicator helloHealthIndicator() { + return () -> Health.up().withDetail("hello", "world").build(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/SampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/SampleController.java new file mode 100644 index 0000000000..63bce2060e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/SampleController.java @@ -0,0 +1,82 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import java.util.Collections; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.Map; + +import javax.validation.constraints.NotBlank; + +import org.springframework.context.annotation.Description; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@Description("A controller for handling requests for hello messages") +public class SampleController { + + private final HelloWorldService helloWorldService; + + public SampleController(HelloWorldService helloWorldService) { + this.helloWorldService = helloWorldService; + } + + @GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody + public Map<String, String> hello() { + return Collections.singletonMap("message", this.helloWorldService.getHelloMessage()); + } + + @PostMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody + public Map<String, Object> olleh(@Validated Message message) { + Map<String, Object> model = new LinkedHashMap<>(); + model.put("message", message.getValue()); + model.put("title", "Hello Home"); + model.put("date", new Date()); + return model; + } + + @RequestMapping("/foo") + @ResponseBody + public String foo() { + throw new IllegalArgumentException("Server error"); + } + + protected static class Message { + + @NotBlank(message = "Message value cannot be empty") + private String value; + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/ServiceProperties.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/ServiceProperties.java new file mode 100644 index 0000000000..22a84c7cb9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/ServiceProperties.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) +public class ServiceProperties { + + /** + * Name of the service. + */ + private String name = "World"; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/main/resources/logback.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/resources/logback.xml similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator/src/main/resources/logback.xml rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/resources/logback.xml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java new file mode 100644 index 0000000000..41922918f7 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java @@ -0,0 +1,70 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for endpoints configuration. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ActiveProfiles("endpoints") +class EndpointsPropertiesSampleActuatorApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testCustomErrorPath() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/oops", + Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("error")).isEqualTo("None"); + assertThat(body.get("status")).isEqualTo(999); + } + + @Test + void testCustomContextPath() { + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) + .getForEntity("/admin/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + assertThat(entity.getBody()).contains("\"hello\":\"world\""); + } + + private String getPassword() { + return "password"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementAddressActuatorApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementAddressActuatorApplicationTests.java new file mode 100644 index 0000000000..b31b974824 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementAddressActuatorApplicationTests.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for separate management and main service ports. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=0", + "management.server.address=127.0.0.1", "management.server.servlet.context-path:/admin" }) +class ManagementAddressActuatorApplicationTests { + + @LocalServerPort + private int port; + + @LocalManagementPort + private int managementPort; + + @Test + void testHome() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void testHealth() { + ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/admin/actuator/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + } + + private String getPassword() { + return "password"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java new file mode 100644 index 0000000000..f33d1faf9d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPathSampleActuatorApplicationTests.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for endpoints configuration. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, + properties = { "management.endpoints.web.base-path=/admin" }) +class ManagementPathSampleActuatorApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHealth() { + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) + .getForEntity("/admin/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + } + + @Test + void testHomeIsSecure() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.getForEntity("/", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("error")).isEqualTo("Unauthorized"); + assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); + } + + private String getPassword() { + return "password"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java new file mode 100644 index 0000000000..bc16d4b629 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java @@ -0,0 +1,124 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for separate management and main service ports. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=0", + "management.endpoints.web.base-path=/admin", "management.endpoint.health.show-details=never" }) +class ManagementPortAndPathSampleActuatorApplicationTests { + + @LocalServerPort + private int port; + + @LocalManagementPort + private int managementPort; + + @Autowired + private Environment environment; + + @Test + void testHome() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) + .getForEntity("http://localhost:" + this.port, Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("message")).isEqualTo("Hello Phil"); + } + + @Test + void testMetrics() { + testHome(); // makes sure some requests have been made + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void testHealth() { + ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}"); + } + + @Test + void testEnvNotFound() { + String unknownProperty = "test-does-not-exist"; + assertThat(this.environment.containsProperty(unknownProperty)).isFalse(); + ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()).getForEntity( + "http://localhost:" + this.managementPort + "/admin/env/" + unknownProperty, String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + } + + @Test + void testMissing() { + ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/admin/missing", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + assertThat(entity.getBody()).contains("\"status\":404"); + } + + @Test + void testErrorPage() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) + .getForEntity("http://localhost:" + this.port + "/error", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("status")).isEqualTo(999); + } + + @Test + void testManagementErrorPage() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("status")).isEqualTo(999); + } + + private String getPassword() { + return "password"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortSampleActuatorApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortSampleActuatorApplicationTests.java new file mode 100644 index 0000000000..fa530a5d3f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortSampleActuatorApplicationTests.java @@ -0,0 +1,93 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for separate management and main service ports. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, + properties = { "management.server.port=0", "management.endpoint.health.show-details=always" }) +class ManagementPortSampleActuatorApplicationTests { + + @LocalServerPort + private int port; + + @LocalManagementPort + private int managementPort; + + @Test + void testHome() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) + .getForEntity("http://localhost:" + this.port, Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("message")).isEqualTo("Hello Phil"); + } + + @Test + void testMetrics() { + testHome(); // makes sure some requests have been made + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void testHealth() { + ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + assertThat(entity.getBody()).contains("\"example\""); + assertThat(entity.getBody()).contains("\"counter\":42"); + } + + @Test + void testErrorPage() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) + .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("status")).isEqualTo(999); + } + + private String getPassword() { + return "password"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortWithLazyInitializationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortWithLazyInitializationTests.java new file mode 100644 index 0000000000..518f05fad7 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ManagementPortWithLazyInitializationTests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for separate management and main service ports when + * lazy-initialization is enabled. + * + * @author Madhura Bhave + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = { "management.server.port=0", "spring.main.lazy-initialization=true" }) +class ManagementPortWithLazyInitializationTests { + + @LocalManagementPort + private int managementPort; + + @Test + void testHealth() { + ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password") + .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/NoManagementSampleActuatorApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/NoManagementSampleActuatorApplicationTests.java new file mode 100644 index 0000000000..ab751a0c41 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/NoManagementSampleActuatorApplicationTests.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for switching off management endpoints. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=-1" }) +class NoManagementSampleActuatorApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHome() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", + Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("message")).isEqualTo("Hello Phil"); + } + + @Test + void testMetricsNotAvailable() { + testHome(); // makes sure some requests have been made + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/metrics", + Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + } + + private String getPassword() { + return "password"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java new file mode 100644 index 0000000000..8058b40199 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java @@ -0,0 +1,195 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.context.ApplicationContext; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for service demo application. + * + * @author Dave Syer + * @author Stephane Nicoll + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleActuatorApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Autowired + private ApplicationContext applicationContext; + + @Test + void testHomeIsSecure() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.getForEntity("/", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("error")).isEqualTo("Unauthorized"); + assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); + } + + @Test + void testMetricsIsSecure() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + entity = this.restTemplate.getForEntity("/actuator/metrics/", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + entity = this.restTemplate.getForEntity("/actuator/metrics/foo", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + entity = this.restTemplate.getForEntity("/actuator/metrics.json", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void testHome() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", + Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("message")).isEqualTo("Hello Phil"); + } + + @SuppressWarnings("unchecked") + @Test + void testMetrics() { + testHome(); // makes sure some requests have been made + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) + .getForEntity("/actuator/metrics", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + Map<String, Object> body = entity.getBody(); + assertThat(body).containsKey("names"); + assertThat((List<String>) body.get("names")).contains("jvm.buffer.count"); + + } + + @Test + void testEnv() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) + .getForEntity("/actuator/env", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body).containsKey("propertySources"); + } + + @Test + void healthInsecureByDefault() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + assertThat(entity.getBody()).doesNotContain("\"hello\":\"1\""); + } + + @Test + void infoInsecureByDefault() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/info", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"artifact\":\"spring-boot-smoke-test-actuator\""); + assertThat(entity.getBody()).contains("\"someKey\":\"someValue\""); + assertThat(entity.getBody()).contains("\"java\":{", "\"source\":\"1.8\"", "\"target\":\"1.8\""); + assertThat(entity.getBody()).contains("\"encoding\":{", "\"source\":\"UTF-8\"", "\"reporting\":\"UTF-8\""); + } + + @Test + void testErrorPage() { + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/foo", + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + String body = entity.getBody(); + assertThat(body).contains("\"error\":"); + } + + @Test + void testHtmlErrorPage() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + HttpEntity<?> request = new HttpEntity<Void>(headers); + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/foo", + HttpMethod.GET, request, String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + String body = entity.getBody(); + assertThat(body).as("Body was null").isNotNull(); + assertThat(body).contains("This application has no explicit mapping for /error"); + } + + @Test + void testErrorPageDirectAccess() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/error", + Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("error")).isEqualTo("None"); + assertThat(body.get("status")).isEqualTo(999); + } + + @Test + @SuppressWarnings("unchecked") + void testBeans() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) + .getForEntity("/actuator/beans", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).containsOnlyKeys("contexts"); + } + + @SuppressWarnings("unchecked") + @Test + void testConfigProps() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) + .getForEntity("/actuator/configprops", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + Map<String, Object> body = entity.getBody(); + Map<String, Object> contexts = (Map<String, Object>) body.get("contexts"); + Map<String, Object> context = (Map<String, Object>) contexts.get(this.applicationContext.getId()); + Map<String, Object> beans = (Map<String, Object>) context.get("beans"); + assertThat(beans).containsKey("spring.datasource-" + DataSourceProperties.class.getName()); + } + + private String getPassword() { + return "password"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java new file mode 100644 index 0000000000..bbe7fab573 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ServletPathSampleActuatorApplicationTests.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for endpoints configuration. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.mvc.servlet.path=/spring" }) +class ServletPathSampleActuatorApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testErrorPath() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) + .getForEntity("/spring/error", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("error")).isEqualTo("None"); + assertThat(body.get("status")).isEqualTo(999); + } + + @Test + void testHealth() { + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) + .getForEntity("/spring/actuator/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + } + + @Test + void testHomeIsSecure() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/", Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("error")).isEqualTo("Unauthorized"); + assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); + } + + private String getPassword() { + return "password"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ShutdownSampleActuatorApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ShutdownSampleActuatorApplicationTests.java new file mode 100644 index 0000000000..ee40206df6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/ShutdownSampleActuatorApplicationTests.java @@ -0,0 +1,85 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.actuator; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.test.annotation.DirtiesContext; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for separate management and main service ports. + * + * @author Dave Syer + */ +@SpringBootTest(classes = { ShutdownSampleActuatorApplicationTests.SecurityConfiguration.class, + SampleActuatorApplication.class }, webEnvironment = WebEnvironment.RANDOM_PORT) +class ShutdownSampleActuatorApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHome() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", + Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(body.get("message")).isEqualTo("Hello Phil"); + } + + @Test + @DirtiesContext + void testShutdown() { + @SuppressWarnings("rawtypes") + ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) + .postForEntity("/actuator/shutdown", null, Map.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + @SuppressWarnings("unchecked") + Map<String, Object> body = entity.getBody(); + assertThat(((String) body.get("message"))).contains("Shutting down"); + } + + private String getPassword() { + return "password"; + } + + @Configuration(proxyBeanMethods = false) + static class SecurityConfiguration extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable(); + } + + } + +} diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-endpoints.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/resources/application-endpoints.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-endpoints.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/resources/application-endpoints.properties diff --git a/spring-boot-samples/spring-boot-sample-amqp/docker-compose.yml b/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/docker-compose.yml similarity index 100% rename from spring-boot-samples/spring-boot-sample-amqp/docker-compose.yml rename to spring-boot-smoke-tests/spring-boot-smoke-test-amqp/docker-compose.yml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/pom.xml new file mode 100644 index 0000000000..e5e0a83738 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/pom.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-amqp</artifactId> + <name>Spring Boot AMQP Smoke Test</name> + <description>Spring Boot AMQP Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-amqp</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/src/main/java/smoketest/amqp/SampleAmqpSimpleApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/src/main/java/smoketest/amqp/SampleAmqpSimpleApplication.java new file mode 100644 index 0000000000..b13b9fa901 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/src/main/java/smoketest/amqp/SampleAmqpSimpleApplication.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.amqp; + +import java.util.Date; + +import org.springframework.amqp.core.Queue; +import org.springframework.amqp.rabbit.annotation.RabbitHandler; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.messaging.handler.annotation.Payload; +import org.springframework.scheduling.annotation.EnableScheduling; + +@SpringBootApplication +@RabbitListener(queues = "foo") +@EnableScheduling +public class SampleAmqpSimpleApplication { + + @Bean + public Sender mySender() { + return new Sender(); + } + + @Bean + public Queue fooQueue() { + return new Queue("foo"); + } + + @RabbitHandler + public void process(@Payload String foo) { + System.out.println(new Date() + ": " + foo); + } + + public static void main(String[] args) { + SpringApplication.run(SampleAmqpSimpleApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/src/main/java/smoketest/amqp/Sender.java b/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/src/main/java/smoketest/amqp/Sender.java new file mode 100644 index 0000000000..dbe11c4b53 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-amqp/src/main/java/smoketest/amqp/Sender.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.amqp; + +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; + +public class Sender { + + @Autowired + private RabbitTemplate rabbitTemplate; + + @Scheduled(fixedDelay = 1000L) + public void send() { + this.rabbitTemplate.convertAndSend("foo", "hello"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/pom.xml new file mode 100644 index 0000000000..40fc4b4095 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-animated-banner</artifactId> + <name>Spring Boot Animated Banner Smoke Test</name> + <description>Spring Boot Animated Banner Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/src/main/java/smoketest/animated/SampleAnimatedBannerApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/src/main/java/smoketest/animated/SampleAnimatedBannerApplication.java new file mode 100644 index 0000000000..8319a41284 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/src/main/java/smoketest/animated/SampleAnimatedBannerApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.animated; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleAnimatedBannerApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleAnimatedBannerApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-animated-banner/src/main/resources/banner.gif b/spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/src/main/resources/banner.gif similarity index 100% rename from spring-boot-samples/spring-boot-sample-animated-banner/src/main/resources/banner.gif rename to spring-boot-smoke-tests/spring-boot-smoke-test-animated-banner/src/main/resources/banner.gif diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml new file mode 100644 index 0000000000..31e5018195 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml @@ -0,0 +1,69 @@ +<project + xmlns:ivy="antlib:org.apache.ivy.ant" + xmlns:spring-boot="antlib:org.springframework.boot.ant" + name="spring-boot-smoke-test-ant" + default="build"> + + <description> + Sample ANT build script for a Spring Boot executable JAR project. Uses ivy for + dependency management and spring-boot-antlib for additional tasks. Run with + '$ ant -lib ivy-2.2.jar spring-boot-antlib.jar' (substitute the location of your + actual jars). Run with '$ java -jar target/*.jar'. + </description> + + <property name="ant-spring-boot.version" value="${revision}" /> + <property name="lib.dir" location="${basedir}/target/lib" /> + <property name="start-class" value="smoketest.ant.SampleAntApplication" /> + + <target name="resolve" description="--> retrieve dependencies with ivy"> + <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact]-[type]-[revision].[ext]" /> + </target> + + <target name="classpaths" depends="resolve"> + <path id="compile.classpath"> + <fileset dir="${lib.dir}/compile" includes="*.jar" /> + </path> + </target> + + <target name="init" depends="classpaths"> + <mkdir dir="target/classes" /> + </target> + + <target name="compile" depends="init" description="compile"> + <javac srcdir="src/main/java" destdir="target/classes" classpathref="compile.classpath" /> + </target> + + <target name="clean" description="cleans all created files/dirs"> + <delete dir="target" /> + </target> + + <target name="build" depends="compile"> + <spring-boot:exejar destfile="target/${ant.project.name}-${ant-spring-boot.version}.jar" classes="target/classes"> + <spring-boot:lib> + <fileset dir="${lib.dir}/runtime" /> + </spring-boot:lib> + </spring-boot:exejar> + </target> + <!-- Manual equivalent of the build target --> + <target name="manual" depends="compile"> + <jar destfile="target/${ant.project.name}-${ant-spring-boot.version}.jar" compress="false"> + <mappedresources> + <fileset dir="target/classes" /> + <globmapper from="*" to="BOOT-INF/classes/*"/> + </mappedresources> + <mappedresources> + <fileset dir="src/main/resources" erroronmissingdir="false"/> + <globmapper from="*" to="BOOT-INF/classes/*"/> + </mappedresources> + <mappedresources> + <fileset dir="${lib.dir}/runtime" /> + <globmapper from="*" to="BOOT-INF/lib/*"/> + </mappedresources> + <zipfileset src="${lib.dir}/loader/spring-boot-loader-jar-${ant-spring-boot.version}.jar" /> + <manifest> + <attribute name="Main-Class" value="org.springframework.boot.loader.JarLauncher" /> + <attribute name="Start-Class" value="${start-class}" /> + </manifest> + </jar> + </target> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-ant/ivy.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-ant/ivy.xml new file mode 100644 index 0000000000..192d5281fc --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-ant/ivy.xml @@ -0,0 +1,12 @@ +<ivy-module version="2.0"> + <info organisation="org.springframework.boot" module="spring-boot-smoke-test-ant" /> + <configurations> + <conf name="compile" description="everything needed to compile this module" /> + <conf name="runtime" extends="compile" description="everything needed to run this module" /> + <conf name="loader" description="Spring Boot loader used when manually building an executable archive" /> + </configurations> + <dependencies> + <dependency org="org.springframework.boot" name="spring-boot-starter" rev="${ant-spring-boot.version}" conf="compile" /> + <dependency org="org.springframework.boot" name="spring-boot-loader" rev="${ant-spring-boot.version}" conf="loader->default" /> + </dependencies> +</ivy-module> diff --git a/spring-boot-samples/spring-boot-sample-ant/ivysettings.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-ant/ivysettings.xml similarity index 100% rename from spring-boot-samples/spring-boot-sample-ant/ivysettings.xml rename to spring-boot-smoke-tests/spring-boot-smoke-test-ant/ivysettings.xml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-ant/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-ant/pom.xml new file mode 100644 index 0000000000..f8cd8dced4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-ant/pom.xml @@ -0,0 +1,107 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <!-- This POM is just to trigger the Ant/Ivy smoke tests from Maven and to test --> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-ant</artifactId> + <name>Spring Boot Ant Smoke Test</name> + <description>Spring Boot Ant Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <ant.version>1.9.3</ant.version> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-loader</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-antlib</artifactId> + <version>${project.version}</version> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-loader-tools</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <executions> + <execution> + <id>default-compile</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>antbuild</id> + <phase>package</phase> + <configuration> + <target> + <property name="build.compiler" value="extJavac" /> + <ant dir="${basedir}" /> + </target> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.ant</groupId> + <artifactId>ant</artifactId> + <version>${ant.version}</version> + </dependency> + <dependency> + <groupId>org.apache.ivy</groupId> + <artifactId>ivy</artifactId> + <version>2.4.0</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-antlib</artifactId> + <version>${revision}</version> + </dependency> + </dependencies> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-ant/src/main/java/smoketest/ant/SampleAntApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-ant/src/main/java/smoketest/ant/SampleAntApplication.java new file mode 100644 index 0000000000..d8bba799aa --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-ant/src/main/java/smoketest/ant/SampleAntApplication.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.ant; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleAntApplication implements CommandLineRunner { + + @Override + public void run(String... args) { + System.out.println("Spring Boot Ant Example"); + } + + public static void main(String[] args) { + SpringApplication.run(SampleAntApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-ant/src/test/java/smoketest/ant/SampleAntApplicationIT.java b/spring-boot-smoke-tests/spring-boot-smoke-test-ant/src/test/java/smoketest/ant/SampleAntApplicationIT.java new file mode 100644 index 0000000000..51e870bff4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-ant/src/test/java/smoketest/ant/SampleAntApplicationIT.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.ant; + +import java.io.File; +import java.io.FileFilter; +import java.io.InputStreamReader; +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.loader.tools.JavaExecutable; +import org.springframework.util.FileCopyUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration Tests for {@code SampleAntApplication}. + * + * @author Dave Syer + * @author Phillip Webb + */ +public class SampleAntApplicationIT { + + @Test + void runJar() throws Exception { + File target = new File("target"); + File[] jarFiles = target.listFiles(new FileFilter() { + + @Override + public boolean accept(File file) { + return file.getName().endsWith(".jar"); + } + + }); + assertThat(jarFiles).hasSize(1); + Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start(); + process.waitFor(5, TimeUnit.MINUTES); + assertThat(process.exitValue()).isEqualTo(0); + String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream())); + assertThat(output).contains("Spring Boot Ant Example"); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-ant/src/test/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-ant/src/test/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-ant/src/test/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-ant/src/test/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-aop/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-aop/pom.xml new file mode 100644 index 0000000000..7ddb4c464f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-aop/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-aop</artifactId> + <name>Spring Boot AOP Smoke Test</name> + <description>Spring Boot AOP Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-aop</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/java/smoketest/aop/SampleAopApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/java/smoketest/aop/SampleAopApplication.java new file mode 100644 index 0000000000..09a5abeb87 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/java/smoketest/aop/SampleAopApplication.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.aop; + +import smoketest.aop.service.HelloWorldService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleAopApplication implements CommandLineRunner { + + // Simple example shows how an application can spy on itself with AOP + + @Autowired + private HelloWorldService helloWorldService; + + @Override + public void run(String... args) { + System.out.println(this.helloWorldService.getHelloMessage()); + } + + public static void main(String[] args) { + SpringApplication.run(SampleAopApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/java/smoketest/aop/monitor/ServiceMonitor.java b/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/java/smoketest/aop/monitor/ServiceMonitor.java new file mode 100644 index 0000000000..7289f8aeea --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/java/smoketest/aop/monitor/ServiceMonitor.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.aop.monitor; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; + +import org.springframework.stereotype.Component; + +@Aspect +@Component +public class ServiceMonitor { + + @AfterReturning("execution(* sample..*Service.*(..))") + public void logServiceAccess(JoinPoint joinPoint) { + System.out.println("Completed: " + joinPoint); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/java/smoketest/aop/service/HelloWorldService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/java/smoketest/aop/service/HelloWorldService.java new file mode 100644 index 0000000000..b061ebca2f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/java/smoketest/aop/service/HelloWorldService.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.aop.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class HelloWorldService { + + @Value("${name:World}") + private String name; + + public String getHelloMessage() { + return "Hello " + this.name; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-aop/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-aop/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/test/java/smoketest/aop/SampleAopApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/test/java/smoketest/aop/SampleAopApplicationTests.java new file mode 100644 index 0000000000..a1a93b3b0f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-aop/src/test/java/smoketest/aop/SampleAopApplicationTests.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.aop; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleAopApplication}. + * + * @author Dave Syer + * @author Phillip Webb + */ +@ExtendWith(OutputCaptureExtension.class) +class SampleAopApplicationTests { + + private String profiles; + + @BeforeEach + void init() { + this.profiles = System.getProperty("spring.profiles.active"); + } + + @AfterEach + void after() { + if (this.profiles != null) { + System.setProperty("spring.profiles.active", this.profiles); + } + else { + System.clearProperty("spring.profiles.active"); + } + } + + @Test + void testDefaultSettings(CapturedOutput capturedOutput) throws Exception { + SampleAopApplication.main(new String[0]); + assertThat(capturedOutput).contains("Hello Phil"); + } + + @Test + void testCommandLineOverrides(CapturedOutput capturedOutput) throws Exception { + SampleAopApplication.main(new String[] { "--name=Gordon" }); + assertThat(capturedOutput).contains("Hello Gordon"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/pom.xml new file mode 100644 index 0000000000..91c9fd812a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/pom.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-atmosphere</artifactId> + <name>Spring Boot Atmosphere Smoke Test</name> + <description>Spring Boot Atmosphere Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>1</version> + </dependency> + <dependency> + <groupId>org.atmosphere</groupId> + <artifactId>atmosphere-runtime</artifactId> + <version>2.4.14</version> + </dependency> + <dependency> + <groupId>org.webjars</groupId> + <artifactId>atmosphere-javascript</artifactId> + <version>2.3.4</version> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-websocket</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/java/smoketest/atmosphere/ChatService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/java/smoketest/atmosphere/ChatService.java new file mode 100644 index 0000000000..2dbb3229cd --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/java/smoketest/atmosphere/ChatService.java @@ -0,0 +1,81 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.atmosphere; + +import java.io.IOException; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.atmosphere.config.managed.Decoder; +import org.atmosphere.config.managed.Encoder; +import org.atmosphere.config.service.Disconnect; +import org.atmosphere.config.service.ManagedService; +import org.atmosphere.config.service.Ready; +import org.atmosphere.cpr.AtmosphereResource; +import org.atmosphere.cpr.AtmosphereResourceEvent; + +@ManagedService(path = "/chat") +public class ChatService { + + private final Log logger = LogFactory.getLog(ChatService.class); + + @Ready + public void onReady(AtmosphereResource resource) { + this.logger.info("Connected " + resource.uuid()); + } + + @Disconnect + public void onDisconnect(AtmosphereResourceEvent event) { + this.logger.info("Client " + event.getResource().uuid() + " disconnected [" + + (event.isCancelled() ? "cancelled" : "closed") + "]"); + } + + @org.atmosphere.config.service.Message(encoders = JacksonEncoderDecoder.class, + decoders = JacksonEncoderDecoder.class) + public Message onMessage(Message message) throws IOException { + this.logger.info("Author " + message.getAuthor() + " sent message " + message.getMessage()); + return message; + } + + public static class JacksonEncoderDecoder implements Encoder<Message, String>, Decoder<String, Message> { + + private final ObjectMapper mapper = new ObjectMapper(); + + @Override + public String encode(Message m) { + try { + return this.mapper.writeValueAsString(m); + } + catch (IOException ex) { + throw new IllegalStateException(ex); + } + } + + @Override + public Message decode(String s) { + try { + return this.mapper.readValue(s, Message.class); + } + catch (IOException ex) { + throw new IllegalStateException(ex); + } + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/java/smoketest/atmosphere/Message.java b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/java/smoketest/atmosphere/Message.java new file mode 100644 index 0000000000..2001f1977c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/java/smoketest/atmosphere/Message.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.atmosphere; + +import java.util.Date; + +public class Message { + + private String message; + + private String author; + + private long time = new Date().getTime(); + + public String getMessage() { + return this.message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getAuthor() { + return this.author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public long getTime() { + return this.time; + } + + public void setTime(long time) { + this.time = time; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/java/smoketest/atmosphere/SampleAtmosphereApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/java/smoketest/atmosphere/SampleAtmosphereApplication.java new file mode 100644 index 0000000000..7640b70721 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/java/smoketest/atmosphere/SampleAtmosphereApplication.java @@ -0,0 +1,88 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.atmosphere; + +import java.util.Collections; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; + +import org.atmosphere.cpr.AtmosphereServlet; +import org.atmosphere.cpr.ContainerInitializer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.web.servlet.ServletContextInitializer; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@SpringBootConfiguration +@EnableAutoConfiguration +public class SampleAtmosphereApplication { + + @Bean + public EmbeddedAtmosphereInitializer atmosphereInitializer() { + return new EmbeddedAtmosphereInitializer(); + } + + @Bean + public ServletRegistrationBean<AtmosphereServlet> atmosphereServlet() { + // Dispatcher servlet is mapped to '/home' to allow the AtmosphereServlet + // to be mapped to '/chat' + AtmosphereServlet atmosphereServlet = new AtmosphereServlet(); + atmosphereServlet.framework().setHandlersPath("/"); + ServletRegistrationBean<AtmosphereServlet> registration = new ServletRegistrationBean<>(atmosphereServlet, + "/chat/*"); + registration.addInitParameter("org.atmosphere.cpr.packages", "smoketest"); + registration.addInitParameter( + "org.atmosphere.interceptor.HeartbeatInterceptor" + ".clientHeartbeatFrequencyInSeconds", "10"); + registration.setLoadOnStartup(0); + // Need to occur before the EmbeddedAtmosphereInitializer + registration.setOrder(Ordered.HIGHEST_PRECEDENCE); + return registration; + } + + public static void main(String[] args) throws Exception { + SpringApplication.run(SampleAtmosphereApplication.class, args); + } + + @Configuration(proxyBeanMethods = false) + static class MvcConfiguration implements WebMvcConfigurer { + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/").setViewName("forward:/home/home.html"); + } + + } + + private static class EmbeddedAtmosphereInitializer extends ContainerInitializer + implements ServletContextInitializer { + + @Override + public void onStartup(ServletContext servletContext) throws ServletException { + onStartup(Collections.emptySet(), servletContext); + } + + } + +} diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-atmosphere/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/resources/static/home.html b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/resources/static/home.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-atmosphere/src/main/resources/static/home.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/resources/static/home.html diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/resources/static/javascript/application.js b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/resources/static/javascript/application.js similarity index 100% rename from spring-boot-samples/spring-boot-sample-atmosphere/src/main/resources/static/javascript/application.js rename to spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/resources/static/javascript/application.js diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/main/resources/static/javascript/jquery-1.9.0.js b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/resources/static/javascript/jquery-1.9.0.js similarity index 100% rename from spring-boot-samples/spring-boot-sample-atmosphere/src/main/resources/static/javascript/jquery-1.9.0.js rename to spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/main/resources/static/javascript/jquery-1.9.0.js diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/test/java/smoketest/atmosphere/SampleAtmosphereApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/test/java/smoketest/atmosphere/SampleAtmosphereApplicationTests.java new file mode 100644 index 0000000000..e9a85c5c74 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-atmosphere/src/test/java/smoketest/atmosphere/SampleAtmosphereApplicationTests.java @@ -0,0 +1,120 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.atmosphere; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.client.WebSocketConnectionManager; +import org.springframework.web.socket.client.standard.StandardWebSocketClient; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = SampleAtmosphereApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleAtmosphereApplicationTests { + + private static Log logger = LogFactory.getLog(SampleAtmosphereApplicationTests.class); + + @LocalServerPort + private int port = 1234; + + @Test + void chatEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/chat/websocket") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0L); + assertThat(messagePayloadReference.get()).contains("{\"message\":\"test\",\"author\":\"test\",\"time\":"); + } + + @Configuration(proxyBeanMethods = false) + static class ClientConfiguration implements CommandLineRunner { + + @Value("${websocket.uri}") + private String webSocketUri; + + private final CountDownLatch latch = new CountDownLatch(1); + + private final AtomicReference<String> messagePayload = new AtomicReference<>(); + + @Override + public void run(String... args) throws Exception { + logger.info("Waiting for response: latch=" + this.latch.getCount()); + if (this.latch.await(10, TimeUnit.SECONDS)) { + logger.info("Got response: " + this.messagePayload.get()); + } + else { + logger.info("Response not received: latch=" + this.latch.getCount()); + } + } + + @Bean + public WebSocketConnectionManager wsConnectionManager() { + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); + manager.setAutoStartup(true); + return manager; + } + + @Bean + public StandardWebSocketClient client() { + return new StandardWebSocketClient(); + } + + @Bean + public TextWebSocketHandler handler() { + return new TextWebSocketHandler() { + + @Override + public void afterConnectionEstablished(WebSocketSession session) throws Exception { + session.sendMessage(new TextMessage("{\"author\":\"test\",\"message\":\"test\"}")); + } + + @Override + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + logger.info("Received: " + message + " (" + ClientConfiguration.this.latch.getCount() + ")"); + session.close(); + ClientConfiguration.this.messagePayload.set(message.getPayload()); + ClientConfiguration.this.latch.countDown(); + } + }; + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-batch/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-batch/pom.xml new file mode 100644 index 0000000000..462210765c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-batch/pom.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-batch</artifactId> + <name>Spring Boot Batch Smoke Test</name> + <description>Spring Boot Batch Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-batch</artifactId> + </dependency> + <!-- Runtime --> + <dependency> + <groupId>org.hsqldb</groupId> + <artifactId>hsqldb</artifactId> + <scope>runtime</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java new file mode 100644 index 0000000000..cba6e41a2b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java @@ -0,0 +1,71 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.batch; + +import org.springframework.batch.core.Job; +import org.springframework.batch.core.Step; +import org.springframework.batch.core.StepContribution; +import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; +import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; +import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; +import org.springframework.batch.core.scope.context.ChunkContext; +import org.springframework.batch.core.step.tasklet.Tasklet; +import org.springframework.batch.repeat.RepeatStatus; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +@EnableBatchProcessing +public class SampleBatchApplication { + + @Autowired + private JobBuilderFactory jobs; + + @Autowired + private StepBuilderFactory steps; + + @Bean + protected Tasklet tasklet() { + + return new Tasklet() { + @Override + public RepeatStatus execute(StepContribution contribution, ChunkContext context) { + return RepeatStatus.FINISHED; + } + }; + + } + + @Bean + public Job job() throws Exception { + return this.jobs.get("job").start(step1()).build(); + } + + @Bean + protected Step step1() throws Exception { + return this.steps.get("step1").tasklet(tasklet()).build(); + } + + public static void main(String[] args) { + // System.exit is common for Batch applications since the exit code can be used to + // drive a workflow + System.exit(SpringApplication.exit(SpringApplication.run(SampleBatchApplication.class, args))); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-batch/src/test/java/smoketest/batch/SampleBatchApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-batch/src/test/java/smoketest/batch/SampleBatchApplicationTests.java new file mode 100644 index 0000000000..a115f6a5b6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-batch/src/test/java/smoketest/batch/SampleBatchApplicationTests.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.batch; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(OutputCaptureExtension.class) +class SampleBatchApplicationTests { + + @Test + void testDefaultSettings(CapturedOutput capturedOutput) { + assertThat(SpringApplication.exit(SpringApplication.run(SampleBatchApplication.class))).isEqualTo(0); + assertThat(capturedOutput).contains("completed with the following parameters"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-cache/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/pom.xml new file mode 100644 index 0000000000..b71b483ae6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/pom.xml @@ -0,0 +1,128 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-cache</artifactId> + <name>Spring Boot Cache Smoke Test</name> + <description>Spring Boot Cache Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-cache</artifactId> + </dependency> + <!-- Only used to expose cache metrics --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>caffeine</id> + <dependencies> + <dependency> + <groupId>com.github.ben-manes.caffeine</groupId> + <artifactId>caffeine</artifactId> + </dependency> + </dependencies> + </profile> + <profile> + <id>couchbase</id> + <dependencies> + <dependency> + <groupId>com.couchbase.client</groupId> + <artifactId>java-client</artifactId> + </dependency> + <dependency> + <groupId>com.couchbase.client</groupId> + <artifactId>couchbase-spring-cache</artifactId> + </dependency> + </dependencies> + </profile> + <profile> + <id>ehcache2</id> + <dependencies> + <dependency> + <groupId>net.sf.ehcache</groupId> + <artifactId>ehcache</artifactId> + </dependency> + </dependencies> + </profile> + <profile> + <id>ehcache</id> + <dependencies> + <dependency> + <groupId>javax.cache</groupId> + <artifactId>cache-api</artifactId> + </dependency> + <dependency> + <groupId>org.ehcache</groupId> + <artifactId>ehcache</artifactId> + </dependency> + </dependencies> + </profile> + <profile> + <id>hazelcast</id> + <dependencies> + <dependency> + <groupId>com.hazelcast</groupId> + <artifactId>hazelcast</artifactId> + </dependency> + <dependency> + <groupId>com.hazelcast</groupId> + <artifactId>hazelcast-spring</artifactId> + </dependency> + </dependencies> + </profile> + <profile> + <id>infinispan</id> + <dependencies> + <dependency> + <groupId>org.infinispan</groupId> + <artifactId>infinispan-spring4-embedded</artifactId> + </dependency> + <dependency> + <groupId>org.infinispan</groupId> + <artifactId>infinispan-jcache</artifactId> + </dependency> + </dependencies> + </profile> + <profile> + <id>redis</id> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-redis</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/CacheManagerCheck.java b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/CacheManagerCheck.java new file mode 100644 index 0000000000..82e33af245 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/CacheManagerCheck.java @@ -0,0 +1,44 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.cache; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.cache.CacheManager; +import org.springframework.stereotype.Component; + +@Component +public class CacheManagerCheck implements CommandLineRunner { + + private static final Log logger = LogFactory.getLog(CacheManagerCheck.class); + + private final CacheManager cacheManager; + + public CacheManagerCheck(CacheManager cacheManager) { + this.cacheManager = cacheManager; + } + + @Override + public void run(String... strings) throws Exception { + logger.info("\n\n" + "=========================================================\n" + "Using cache manager: " + + this.cacheManager.getClass().getName() + "\n" + + "=========================================================\n\n"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/Country.java b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/Country.java new file mode 100644 index 0000000000..ddfa400e72 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/Country.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.cache; + +import java.io.Serializable; + +@SuppressWarnings("serial") +public class Country implements Serializable { + + private final String code; + + public Country(String code) { + this.code = code; + } + + public String getCode() { + return this.code; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + Country country = (Country) o; + + return this.code.equals(country.code); + } + + @Override + public int hashCode() { + return this.code.hashCode(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/CountryRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/CountryRepository.java new file mode 100644 index 0000000000..033e3842bc --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/CountryRepository.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.cache; + +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; + +@Component +@CacheConfig(cacheNames = "countries") +public class CountryRepository { + + @Cacheable + public Country findByCode(String code) { + System.out.println("---> Loading country with code '" + code + "'"); + return new Country(code); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/SampleCacheApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/SampleCacheApplication.java new file mode 100644 index 0000000000..1d512a1dd4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/SampleCacheApplication.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.cache; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.scheduling.annotation.EnableScheduling; + +@EnableCaching +@EnableScheduling +@SpringBootApplication +public class SampleCacheApplication { + + public static void main(String[] args) { + new SpringApplicationBuilder().sources(SampleCacheApplication.class).profiles("app").run(args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/SampleClient.java b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/SampleClient.java new file mode 100644 index 0000000000..4b74de1f9f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/java/smoketest/cache/SampleClient.java @@ -0,0 +1,63 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.cache; + +import java.util.Arrays; +import java.util.List; +import java.util.Random; + +import org.springframework.context.annotation.Profile; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +@Profile("app") +class SampleClient { + + private static final List<String> SAMPLE_COUNTRY_CODES = Arrays.asList("AF", "AX", "AL", "DZ", "AS", "AD", "AO", + "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", + "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", + "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", + "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", + "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", + "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", + "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", + "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", + "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", + "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", "KN", + "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", + "ZA", "GS", "SS", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", + "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", + "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW"); + + private final CountryRepository countryService; + + private final Random random; + + SampleClient(CountryRepository countryService) { + this.countryService = countryService; + this.random = new Random(); + } + + @Scheduled(fixedDelay = 500) + public void retrieveCountry() { + String randomCode = SAMPLE_COUNTRY_CODES.get(this.random.nextInt(SAMPLE_COUNTRY_CODES.size())); + System.out.println("Looking for country with code '" + randomCode + "'"); + this.countryService.findByCode(randomCode); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-cache/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/resources/ehcache.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/resources/ehcache.xml similarity index 100% rename from spring-boot-samples/spring-boot-sample-cache/src/main/resources/ehcache.xml rename to spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/resources/ehcache.xml diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/resources/ehcache3.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/resources/ehcache3.xml similarity index 100% rename from spring-boot-samples/spring-boot-sample-cache/src/main/resources/ehcache3.xml rename to spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/resources/ehcache3.xml diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/resources/hazelcast.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/resources/hazelcast.xml similarity index 100% rename from spring-boot-samples/spring-boot-sample-cache/src/main/resources/hazelcast.xml rename to spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/resources/hazelcast.xml diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/resources/infinispan.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/resources/infinispan.xml similarity index 100% rename from spring-boot-samples/spring-boot-sample-cache/src/main/resources/infinispan.xml rename to spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/main/resources/infinispan.xml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/test/java/smoketest/cache/SampleCacheApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/test/java/smoketest/cache/SampleCacheApplicationTests.java new file mode 100644 index 0000000000..27f40dba22 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-cache/src/test/java/smoketest/cache/SampleCacheApplicationTests.java @@ -0,0 +1,47 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.cache; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest +class SampleCacheApplicationTests { + + @Autowired + private CacheManager cacheManager; + + @Autowired + private CountryRepository countryRepository; + + @Test + void validateCache() { + Cache countries = this.cacheManager.getCache("countries"); + assertThat(countries).isNotNull(); + countries.clear(); // Simple test assuming the cache is empty + assertThat(countries.get("BE")).isNull(); + Country be = this.countryRepository.findByCode("BE"); + assertThat((Country) countries.get("BE").get()).isEqualTo(be); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/pom.xml new file mode 100644 index 0000000000..8169a9d93d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/pom.xml @@ -0,0 +1,114 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-custom-layout</artifactId> + <name>Spring Boot Custom Layout Smoke Test</name> + <description>Spring Boot Custom Layout Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-loader-tools</artifactId> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-invoker-plugin</artifactId> + <configuration> + <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> + </configuration> + <executions> + <execution> + <id>prepare-integration-test</id> + <phase>pre-integration-test</phase> + <goals> + <goal>install</goal> + </goals> + </execution> + <execution> + <id>integration-test</id> + <phase>integration-test</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> + <settingsFile>src/it/settings.xml</settingsFile> + <postBuildHookScript>verify</postBuildHookScript> + <addTestClassPath>true</addTestClassPath> + <skipInvocation>${skipTests}</skipInvocation> + <streamLogs>true</streamLogs> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>cleanup-local-integration-repo</id> + <phase>pre-integration-test</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <target> + <replaceregexp match="\$\{revision\}" replace="${project.version}" + flags="g" byline="true"> + <fileset + dir="${project.build.directory}/local-repo/org/springframework/boot/" + includes="**/*.pom" /> + </replaceregexp> + </target> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + </plugin> + </plugins> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.eclipse.m2e</groupId> + <artifactId>lifecycle-mapping</artifactId> + <version>1.0.0</version> + <configuration> + <lifecycleMappingMetadata> + <pluginExecutions> + <pluginExecution> + <pluginExecutionFilter> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <versionRange>[2.10,)</versionRange> + <goals> + <goal>copy</goal> + </goals> + </pluginExecutionFilter> + <action> + <ignore></ignore> + </action> + </pluginExecution> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/custom/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/custom/pom.xml new file mode 100644 index 0000000000..2216ebfca8 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/custom/pom.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.springframework.boot.maven.it</groupId> + <artifactId>custom</artifactId> + <version>0.0.1.BUILD-SNAPSHOT</version> + <properties> + <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>1.8</maven.compiler.target> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + <configuration> + <layoutFactory implementation="smoketest.layout.SampleLayoutFactory"> + <name>custom</name> + </layoutFactory> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>@project.groupId@</groupId> + <artifactId>@project.artifactId@</artifactId> + <version>@project.version@</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> + <dependencies> + </dependencies> +</project> diff --git a/spring-boot-samples/spring-boot-sample-custom-layout/src/it/custom/src/main/java/org/test/SampleApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/custom/src/main/java/org/test/SampleApplication.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-custom-layout/src/it/custom/src/main/java/org/test/SampleApplication.java rename to spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/custom/src/main/java/org/test/SampleApplication.java diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/custom/verify.groovy b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/custom/verify.groovy new file mode 100644 index 0000000000..7da68e56a2 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/custom/verify.groovy @@ -0,0 +1,6 @@ +import java.io.*; +import smoketest.layout.*; + +Verify.verify( + new File(basedir, "target/custom-0.0.1.BUILD-SNAPSHOT.jar"), "custom" +) diff --git a/spring-boot-samples/spring-boot-sample-custom-layout/src/it/default/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/default/pom.xml similarity index 100% rename from spring-boot-samples/spring-boot-sample-custom-layout/src/it/default/pom.xml rename to spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/default/pom.xml diff --git a/spring-boot-samples/spring-boot-sample-custom-layout/src/it/default/src/main/java/org/test/SampleApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/default/src/main/java/org/test/SampleApplication.java similarity index 100% rename from spring-boot-samples/spring-boot-sample-custom-layout/src/it/default/src/main/java/org/test/SampleApplication.java rename to spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/default/src/main/java/org/test/SampleApplication.java diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/default/verify.groovy b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/default/verify.groovy new file mode 100644 index 0000000000..aca02ce428 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/it/default/verify.groovy @@ -0,0 +1,6 @@ +import java.io.*; +import smoketest.layout.*; + +Verify.verify( + new File(basedir, "target/default-0.0.1.BUILD-SNAPSHOT.jar"), "sample" +) diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/main/java/smoketest/layout/SampleLayout.java b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/main/java/smoketest/layout/SampleLayout.java new file mode 100644 index 0000000000..b00963e1cd --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/main/java/smoketest/layout/SampleLayout.java @@ -0,0 +1,44 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.layout; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import org.springframework.boot.loader.tools.CustomLoaderLayout; +import org.springframework.boot.loader.tools.Layouts; +import org.springframework.boot.loader.tools.LoaderClassesWriter; + +/** + * An example layout. + * + * @author Phillip Webb + */ +public class SampleLayout extends Layouts.Jar implements CustomLoaderLayout { + + private String name; + + public SampleLayout(String name) { + this.name = name; + } + + @Override + public void writeLoadedClasses(LoaderClassesWriter writer) throws IOException { + writer.writeEntry(this.name, new ByteArrayInputStream("test".getBytes())); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/main/java/smoketest/layout/SampleLayoutFactory.java b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/main/java/smoketest/layout/SampleLayoutFactory.java new file mode 100644 index 0000000000..475bb915ad --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/main/java/smoketest/layout/SampleLayoutFactory.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.layout; + +import java.io.File; + +import org.springframework.boot.loader.tools.Layout; +import org.springframework.boot.loader.tools.LayoutFactory; + +public class SampleLayoutFactory implements LayoutFactory { + + private String name = "sample"; + + public SampleLayoutFactory() { + } + + public SampleLayoutFactory(String name) { + this.name = name; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + @Override + public Layout getLayout(File source) { + return new SampleLayout(this.name); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/main/resources/META-INF/spring.factories b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..cd58d61f3a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.loader.tools.LayoutFactory=\ +smoketest.layout.SampleLayoutFactory diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/test/java/smoketest/layout/Verify.java b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/test/java/smoketest/layout/Verify.java new file mode 100644 index 0000000000..f7d5c924e8 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-custom-layout/src/test/java/smoketest/layout/Verify.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.layout; + +import java.io.File; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +public final class Verify { + + private Verify() { + } + + public static void verify(File file, String entry) throws Exception { + try (ZipFile zipFile = new ZipFile(file)) { + Enumeration<? extends ZipEntry> entries = zipFile.entries(); + while (entries.hasMoreElements()) { + if (entries.nextElement().getName().equals(entry)) { + return; + } + } + throw new AssertionError("No entry " + entry); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/pom.xml new file mode 100644 index 0000000000..0c22ddd0c4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/pom.xml @@ -0,0 +1,131 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-data-cassandra</artifactId> + <name>Spring Boot Data Cassandra Smoke Test</name> + <description>Spring Boot Data Cassandra Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-cassandra</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.cassandraunit</groupId> + <artifactId>cassandra-unit-spring</artifactId> + <version>3.5.0.1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>reserve-cassandra-port</id> + <goals> + <goal>reserve-network-port</goal> + </goals> + <phase>process-resources</phase> + <configuration> + <portNames> + <portName>cassandra.port.native-transport</portName> + <portName>cassandra.port.storage</portName> + </portNames> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <systemPropertyVariables> + <spring.data.cassandra.port>${cassandra.port.native-transport}</spring.data.cassandra.port> + <cassandra.native_transport_port>${cassandra.port.native-transport}</cassandra.native_transport_port> + <cassandra.storage_port>${cassandra.port.storage}</cassandra.storage_port> + </systemPropertyVariables> + </configuration> + </plugin> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.eclipse.m2e</groupId> + <artifactId>lifecycle-mapping</artifactId> + <version>1.0.0</version> + <configuration> + <lifecycleMappingMetadata> + <pluginExecutions> + <pluginExecution> + <pluginExecutionFilter> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <versionRange>[1.9.1,)</versionRange> + <goals> + <goal>reserve-network-port</goal> + </goals> + </pluginExecutionFilter> + <action> + <ignore /> + </action> + </pluginExecution> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> + <profiles> + <profile> + <id>java9+</id> + <activation> + <jdk>[9,)</jdk> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skipTests>true</skipTests> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/Customer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/Customer.java new file mode 100644 index 0000000000..7449be839d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/Customer.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.cassandra; + +import java.util.UUID; + +import org.springframework.data.cassandra.core.mapping.PrimaryKey; +import org.springframework.data.cassandra.core.mapping.Table; + +@Table +public class Customer { + + @PrimaryKey + private UUID id; + + private String firstName; + + private String lastName; + + public Customer() { + } + + public Customer(UUID id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + @Override + public String toString() { + return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, this.firstName, this.lastName); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/CustomerRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/CustomerRepository.java new file mode 100644 index 0000000000..f3b9f8b95c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/CustomerRepository.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.cassandra; + +import java.util.List; + +import org.springframework.data.cassandra.repository.Query; +import org.springframework.data.repository.CrudRepository; + +public interface CustomerRepository extends CrudRepository<Customer, String> { + + @Query("Select * from customer where firstname=?0") + Customer findByFirstName(String firstName); + + @Query("Select * from customer where lastname=?0") + List<Customer> findByLastName(String lastName); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/SampleCassandraApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/SampleCassandraApplication.java new file mode 100644 index 0000000000..a4a0cf065a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/java/smoketest/data/cassandra/SampleCassandraApplication.java @@ -0,0 +1,64 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.cassandra; + +import com.datastax.driver.core.utils.UUIDs; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleCassandraApplication implements CommandLineRunner { + + @Autowired + private CustomerRepository repository; + + @Override + public void run(String... args) throws Exception { + this.repository.deleteAll(); + + // save a couple of customers + this.repository.save(new Customer(UUIDs.timeBased(), "Alice", "Smith")); + this.repository.save(new Customer(UUIDs.timeBased(), "Bob", "Smith")); + + // fetch all customers + System.out.println("Customers found with findAll():"); + System.out.println("-------------------------------"); + for (Customer customer : this.repository.findAll()) { + System.out.println(customer); + } + System.out.println(); + + // fetch an individual customer + System.out.println("Customer found with findByFirstName('Alice'):"); + System.out.println("--------------------------------"); + System.out.println(this.repository.findByFirstName("Alice")); + + System.out.println("Customers found with findByLastName('Smith'):"); + System.out.println("--------------------------------"); + for (Customer customer : this.repository.findByLastName("Smith")) { + System.out.println(customer); + } + } + + public static void main(String[] args) { + SpringApplication.run(SampleCassandraApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-cassandra/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/OrderedCassandraTestExecutionListener.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/OrderedCassandraTestExecutionListener.java new file mode 100644 index 0000000000..cb5e3a641b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/OrderedCassandraTestExecutionListener.java @@ -0,0 +1,44 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.cassandra; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.cassandraunit.spring.CassandraUnitDependencyInjectionTestExecutionListener; + +import org.springframework.core.Ordered; + +public class OrderedCassandraTestExecutionListener extends CassandraUnitDependencyInjectionTestExecutionListener { + + private static final Log logger = LogFactory.getLog(OrderedCassandraTestExecutionListener.class); + + @Override + public int getOrder() { + return Ordered.HIGHEST_PRECEDENCE; + } + + @Override + protected void cleanServer() { + try { + super.cleanServer(); + } + catch (Exception ex) { + logger.warn("Failure during server cleanup", ex); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationTests.java new file mode 100644 index 0000000000..74e010bc33 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/java/smoketest/data/cassandra/SampleCassandraApplicationTests.java @@ -0,0 +1,56 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.cassandra; + +import java.io.File; + +import org.cassandraunit.spring.CassandraDataSet; +import org.cassandraunit.spring.EmbeddedCassandra; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.test.context.TestExecutionListeners; +import org.springframework.test.context.TestExecutionListeners.MergeMode; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleCassandraApplication}. + */ +@TestExecutionListeners(mergeMode = MergeMode.MERGE_WITH_DEFAULTS, + listeners = { OrderedCassandraTestExecutionListener.class }) +@ExtendWith(OutputCaptureExtension.class) +@SpringBootTest +@CassandraDataSet(keyspace = "mykeyspace", value = "setup.cql") +@EmbeddedCassandra(timeout = 60000) +class SampleCassandraApplicationTests { + + @Test + void testDefaultSettings(CapturedOutput output) { + Assumptions.assumeFalse(this::runningOnWindows); + assertThat(output).contains("firstName='Alice', lastName='Smith'"); + } + + private boolean runningOnWindows() { + return File.separatorChar == '\\'; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/resources/setup.cql b/spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/resources/setup.cql similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-cassandra/src/test/resources/setup.cql rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-cassandra/src/test/resources/setup.cql diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/pom.xml new file mode 100644 index 0000000000..afff777c88 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/pom.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>spring-boot-smoke-tests</artifactId> + <groupId>org.springframework.boot</groupId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-data-couchbase</artifactId> + <name>Spring Boot Data Couchbase Smoke Test</name> + <description>Spring Boot Data Couchbase Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-couchbase</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/java/smoketest/data/couchbase/SampleCouchbaseApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/java/smoketest/data/couchbase/SampleCouchbaseApplication.java new file mode 100644 index 0000000000..014b0c583b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/java/smoketest/data/couchbase/SampleCouchbaseApplication.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.couchbase; + +import java.util.UUID; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleCouchbaseApplication implements CommandLineRunner { + + @Autowired + private UserRepository userRepository; + + public static void main(String[] args) { + SpringApplication.run(SampleCouchbaseApplication.class); + } + + @Override + public void run(String... args) throws Exception { + this.userRepository.deleteAll(); + User user = saveUser(); + System.out.println(this.userRepository.findById(user.getId())); + } + + private User saveUser() { + User user = new User(); + user.setId(UUID.randomUUID().toString()); + user.setFirstName("Alice"); + user.setLastName("Smith"); + return this.userRepository.save(user); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/java/smoketest/data/couchbase/User.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/java/smoketest/data/couchbase/User.java new file mode 100644 index 0000000000..a9650ff7ab --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/java/smoketest/data/couchbase/User.java @@ -0,0 +1,66 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.couchbase; + +import com.couchbase.client.java.repository.annotation.Field; +import com.couchbase.client.java.repository.annotation.Id; + +import org.springframework.data.couchbase.core.mapping.Document; + +@Document +public class User { + + @Id + private String id; + + @Field + private String firstName; + + @Field + private String lastName; + + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFirstName() { + return this.firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return this.lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public String toString() { + return "User{" + "id='" + this.id + '\'' + ", firstName='" + this.firstName + '\'' + ", lastName='" + + this.lastName + '\'' + '}'; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/java/smoketest/data/couchbase/UserRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/java/smoketest/data/couchbase/UserRepository.java new file mode 100644 index 0000000000..0a2657eafd --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/java/smoketest/data/couchbase/UserRepository.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.couchbase; + +import org.springframework.data.couchbase.core.query.ViewIndexed; +import org.springframework.data.couchbase.repository.CouchbaseRepository; + +@ViewIndexed(designDoc = "user", viewName = "all") +public interface UserRepository extends CouchbaseRepository<User, String> { + +} diff --git a/spring-boot-samples/spring-boot-sample-data-couchbase/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-couchbase/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/test/java/smoketest/data/couchbase/SampleCouchbaseApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/test/java/smoketest/data/couchbase/SampleCouchbaseApplicationTests.java new file mode 100644 index 0000000000..dd667c9a51 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-couchbase/src/test/java/smoketest/data/couchbase/SampleCouchbaseApplicationTests.java @@ -0,0 +1,59 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package smoketest.data.couchbase; + +import java.net.ConnectException; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.core.NestedCheckedException; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(OutputCaptureExtension.class) +class SampleCouchbaseApplicationTests { + + @Test + void testDefaultSettings(CapturedOutput capturedOutput) { + try { + new SpringApplicationBuilder(SampleCouchbaseApplication.class).run("--server.port=0"); + } + catch (RuntimeException ex) { + if (serverNotRunning(ex)) { + return; + } + } + assertThat(capturedOutput).contains("firstName='Alice', lastName='Smith'"); + } + + private boolean serverNotRunning(RuntimeException ex) { + @SuppressWarnings("serial") + NestedCheckedException nested = new NestedCheckedException("failed", ex) { + }; + if (nested.contains(ConnectException.class)) { + Throwable root = nested.getRootCause(); + if (root.getMessage().contains("Connection refused")) { + return true; + } + } + return false; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/pom.xml new file mode 100644 index 0000000000..75f26158e9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/pom.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-data-elasticsearch</artifactId> + <name>Spring Boot Data Elasticsearch Smoke Test</name> + <description>Spring Boot Data Elasticsearch Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-elasticsearch</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/java/smoketest/data/elasticsearch/Customer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/java/smoketest/data/elasticsearch/Customer.java new file mode 100644 index 0000000000..ff8bd0b11d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/java/smoketest/data/elasticsearch/Customer.java @@ -0,0 +1,69 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.elasticsearch; + +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; + +@Document(indexName = "customer", type = "customer", shards = 1, replicas = 0, refreshInterval = "-1") +public class Customer { + + @Id + private String id; + + private String firstName; + + private String lastName; + + public Customer() { + } + + public Customer(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFirstName() { + return this.firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return this.lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public String toString() { + return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, this.firstName, this.lastName); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/java/smoketest/data/elasticsearch/CustomerRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/java/smoketest/data/elasticsearch/CustomerRepository.java new file mode 100644 index 0000000000..c009f2fcbc --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/java/smoketest/data/elasticsearch/CustomerRepository.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.elasticsearch; + +import java.util.List; + +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +public interface CustomerRepository extends ElasticsearchRepository<Customer, String> { + + Customer findByFirstName(String firstName); + + List<Customer> findByLastName(String lastName); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/java/smoketest/data/elasticsearch/SampleElasticsearchApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/java/smoketest/data/elasticsearch/SampleElasticsearchApplication.java new file mode 100644 index 0000000000..e4b90f7dd6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/java/smoketest/data/elasticsearch/SampleElasticsearchApplication.java @@ -0,0 +1,68 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.elasticsearch; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleElasticsearchApplication implements CommandLineRunner { + + @Autowired + private CustomerRepository repository; + + @Override + public void run(String... args) throws Exception { + this.repository.deleteAll(); + saveCustomers(); + fetchAllCustomers(); + fetchIndividualCustomers(); + } + + private void saveCustomers() { + this.repository.save(new Customer("Alice", "Smith")); + this.repository.save(new Customer("Bob", "Smith")); + } + + private void fetchAllCustomers() { + System.out.println("Customers found with findAll():"); + System.out.println("-------------------------------"); + for (Customer customer : this.repository.findAll()) { + System.out.println(customer); + } + System.out.println(); + } + + private void fetchIndividualCustomers() { + System.out.println("Customer found with findByFirstName('Alice'):"); + System.out.println("--------------------------------"); + System.out.println(this.repository.findByFirstName("Alice")); + + System.out.println("Customers found with findByLastName('Smith'):"); + System.out.println("--------------------------------"); + for (Customer customer : this.repository.findByLastName("Smith")) { + System.out.println(customer); + } + } + + public static void main(String[] args) { + SpringApplication.run(SampleElasticsearchApplication.class, "--debug").close(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-elasticsearch/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/test/java/smoketest/data/elasticsearch/SampleElasticsearchApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/test/java/smoketest/data/elasticsearch/SampleElasticsearchApplicationTests.java new file mode 100644 index 0000000000..2605eab0c4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-elasticsearch/src/test/java/smoketest/data/elasticsearch/SampleElasticsearchApplicationTests.java @@ -0,0 +1,63 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.elasticsearch; + +import java.net.ConnectException; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleElasticsearchApplication}. + * + * @author Artur Konczak + */ +@ExtendWith(OutputCaptureExtension.class) +class SampleElasticsearchApplicationTests { + + @Test + void testDefaultSettings(CapturedOutput capturedOutput) { + try { + new SpringApplicationBuilder(SampleElasticsearchApplication.class).run(); + } + catch (Exception ex) { + if (!elasticsearchRunning(ex)) { + return; + } + throw ex; + } + assertThat(capturedOutput).contains("firstName='Alice', lastName='Smith'"); + } + + private boolean elasticsearchRunning(Exception ex) { + Throwable candidate = ex; + while (candidate != null) { + if (candidate instanceof ConnectException) { + return false; + } + candidate = candidate.getCause(); + } + return true; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/pom.xml new file mode 100755 index 0000000000..e884c979f6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/pom.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-data-jdbc</artifactId> + <name>Spring Boot Data JDBC Smoke Test</name> + <description>Spring Boot Data JDBC Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jdbc</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <!-- Runtime --> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>runtime</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/Customer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/Customer.java new file mode 100644 index 0000000000..b88363e552 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/Customer.java @@ -0,0 +1,56 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jdbc; + +import java.time.LocalDate; + +import org.springframework.data.annotation.Id; + +class Customer { + + @Id + private Long id; + + private String firstName; + + private LocalDate dateOfBirth; + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getFirstName() { + return this.firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public LocalDate getDateOfBirth() { + return this.dateOfBirth; + } + + public void setDateOfBirth(LocalDate dateOfBirth) { + this.dateOfBirth = dateOfBirth; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/CustomerRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/CustomerRepository.java new file mode 100644 index 0000000000..442eefe1e0 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/CustomerRepository.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jdbc; + +import java.util.List; + +import org.springframework.data.jdbc.repository.query.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; + +interface CustomerRepository extends CrudRepository<Customer, Long> { + + @Query("select id, first_name, date_of_birth from customer where upper(first_name) like '%' || upper(:name) || '%' ") + List<Customer> findByName(@Param("name") String name); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/SampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/SampleController.java new file mode 100644 index 0000000000..894e7f8277 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/SampleController.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jdbc; + +import java.util.List; + +import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class SampleController { + + private final CustomerRepository customerRepository; + + public SampleController(CustomerRepository customerRepository) { + this.customerRepository = customerRepository; + } + + @GetMapping("/") + @ResponseBody + @Transactional(readOnly = true) + public List<Customer> customers(@RequestParam String name) { + return this.customerRepository.findByName(name); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/SampleDataJdbcApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/SampleDataJdbcApplication.java new file mode 100644 index 0000000000..f78dd3d2d9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/java/smoketest/data/jdbc/SampleDataJdbcApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jdbc; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleDataJdbcApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleDataJdbcApplication.class); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/resources/data.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/resources/data.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-jdbc/src/main/resources/data.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/resources/data.sql diff --git a/spring-boot-samples/spring-boot-sample-data-jdbc/src/main/resources/schema.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/resources/schema.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-jdbc/src/main/resources/schema.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/main/resources/schema.sql diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/test/java/smoketest/data/jdbc/CustomerRepositoryIntegrationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/test/java/smoketest/data/jdbc/CustomerRepositoryIntegrationTests.java new file mode 100644 index 0000000000..a4ddb38c59 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/test/java/smoketest/data/jdbc/CustomerRepositoryIntegrationTests.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package smoketest.data.jdbc; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link CustomerRepository}. + * + * @author Andy Wilkinson + */ +@SpringBootTest +@AutoConfigureTestDatabase +class CustomerRepositoryIntegrationTests { + + @Autowired + private CustomerRepository repository; + + @Test + void findAllCustomers() { + assertThat(this.repository.findAll()).hasSize(2); + } + + @Test + void findByNameWithMatch() { + assertThat(this.repository.findByName("joan")).hasSize(1); + } + + @Test + void findByNameWithNoMatch() { + assertThat(this.repository.findByName("hugh")).isEmpty(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/test/java/smoketest/data/jdbc/SampleDataJdbcApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/test/java/smoketest/data/jdbc/SampleDataJdbcApplicationTests.java new file mode 100644 index 0000000000..52ee22cd1d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jdbc/src/test/java/smoketest/data/jdbc/SampleDataJdbcApplicationTests.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jdbc; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * Integration tests for {@link SampleDataJdbcApplication}. + * + * @author Andy Wilkinson + */ +@SpringBootTest +class SampleDataJdbcApplicationTests { + + @Autowired + private WebApplicationContext context; + + private MockMvc mvc; + + @BeforeEach + void setUp() { + this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); + } + + @Test + void testCustomers() throws Exception { + this.mvc.perform(get("/").param("name", "merEDith")).andExpect(status().isOk()) + .andExpect(content().string(containsString("Meredith"))); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/pom.xml new file mode 100755 index 0000000000..a48130a26a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/pom.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-data-jpa</artifactId> + <name>Spring Boot Data JPA Smoke Test</name> + <description>Spring Boot Data JPA Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <!-- Runtime --> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>runtime</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/SampleDataJpaApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/SampleDataJpaApplication.java new file mode 100644 index 0000000000..9898649192 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/SampleDataJpaApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleDataJpaApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleDataJpaApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/City.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/City.java new file mode 100644 index 0000000000..df1dd403b1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/City.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.domain; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.SequenceGenerator; + +@Entity +public class City implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @SequenceGenerator(name = "city_generator", sequenceName = "city_sequence", initialValue = 23) + @GeneratedValue(generator = "city_generator") + private Long id; + + @Column(nullable = false) + private String name; + + @Column(nullable = false) + private String state; + + @Column(nullable = false) + private String country; + + @Column(nullable = false) + private String map; + + protected City() { + } + + public City(String name, String country) { + this.name = name; + this.country = country; + } + + public String getName() { + return this.name; + } + + public String getState() { + return this.state; + } + + public String getCountry() { + return this.country; + } + + public String getMap() { + return this.map; + } + + @Override + public String toString() { + return getName() + "," + getState() + "," + getCountry(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/Hotel.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/Hotel.java new file mode 100644 index 0000000000..7340bf8ecb --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/Hotel.java @@ -0,0 +1,84 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.domain; + +import java.io.Serializable; +import java.util.Set; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.SequenceGenerator; + +import org.hibernate.annotations.NaturalId; + +@Entity +public class Hotel implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @SequenceGenerator(name = "hotel_generator", sequenceName = "hotel_sequence", initialValue = 28) + @GeneratedValue(generator = "hotel_generator") + private Long id; + + @ManyToOne(optional = false) + @NaturalId + private City city; + + @Column(nullable = false) + @NaturalId + private String name; + + @Column(nullable = false) + private String address; + + @Column(nullable = false) + private String zip; + + @OneToMany(fetch = FetchType.LAZY, mappedBy = "hotel") + private Set<Review> reviews; + + protected Hotel() { + } + + public Hotel(City city, String name) { + this.city = city; + this.name = name; + } + + public City getCity() { + return this.city; + } + + public String getName() { + return this.name; + } + + public String getAddress() { + return this.address; + } + + public String getZip() { + return this.zip; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/HotelSummary.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/HotelSummary.java new file mode 100644 index 0000000000..290119bb21 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/HotelSummary.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.domain; + +public interface HotelSummary { + + City getCity(); + + String getName(); + + Double getAverageRating(); + + default Integer getAverageRatingRounded() { + return (getAverageRating() != null) ? (int) Math.round(getAverageRating()) : null; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/Rating.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/Rating.java new file mode 100644 index 0000000000..98cf035e2b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/Rating.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.domain; + +public enum Rating { + + TERRIBLE, POOR, AVERAGE, GOOD, EXCELLENT + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/RatingCount.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/RatingCount.java new file mode 100644 index 0000000000..45b75a4bf1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/RatingCount.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.domain; + +public interface RatingCount { + + Rating getRating(); + + long getCount(); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/Review.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/Review.java new file mode 100644 index 0000000000..341745744d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/Review.java @@ -0,0 +1,132 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.domain; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.SequenceGenerator; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.springframework.util.Assert; + +@Entity +public class Review implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @SequenceGenerator(name = "review_generator", sequenceName = "review_sequence", initialValue = 64) + @GeneratedValue(generator = "review_generator") + private Long id; + + @ManyToOne(optional = false) + private Hotel hotel; + + @Column(nullable = false, name = "idx") + private int index; + + @Column(nullable = false) + @Enumerated(EnumType.ORDINAL) + private Rating rating; + + @Column(nullable = false) + @Temporal(TemporalType.DATE) + private Date checkInDate; + + @Column(nullable = false) + @Enumerated(EnumType.ORDINAL) + private TripType tripType; + + @Column(nullable = false) + private String title; + + @Column(nullable = false, length = 5000) + private String details; + + protected Review() { + } + + public Review(Hotel hotel, int index, ReviewDetails details) { + Assert.notNull(hotel, "Hotel must not be null"); + Assert.notNull(details, "Details must not be null"); + this.hotel = hotel; + this.index = index; + this.rating = details.getRating(); + this.checkInDate = details.getCheckInDate(); + this.tripType = details.getTripType(); + this.title = details.getTitle(); + this.details = details.getDetails(); + } + + public Hotel getHotel() { + return this.hotel; + } + + public int getIndex() { + return this.index; + } + + public Rating getRating() { + return this.rating; + } + + public void setRating(Rating rating) { + this.rating = rating; + } + + public Date getCheckInDate() { + return this.checkInDate; + } + + public void setCheckInDate(Date checkInDate) { + this.checkInDate = checkInDate; + } + + public TripType getTripType() { + return this.tripType; + } + + public void setTripType(TripType tripType) { + this.tripType = tripType; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDetails() { + return this.details; + } + + public void setDetails(String details) { + this.details = details; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/ReviewDetails.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/ReviewDetails.java new file mode 100644 index 0000000000..9975e405b9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/ReviewDetails.java @@ -0,0 +1,79 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.domain; + +import java.io.Serializable; +import java.util.Date; + +public class ReviewDetails implements Serializable { + + private static final long serialVersionUID = 1L; + + private Rating rating; + + private Date checkInDate; + + private TripType tripType; + + private String title; + + private String details; + + public ReviewDetails() { + } + + public Rating getRating() { + return this.rating; + } + + public void setRating(Rating rating) { + this.rating = rating; + } + + public Date getCheckInDate() { + return this.checkInDate; + } + + public void setCheckInDate(Date checkInDate) { + this.checkInDate = checkInDate; + } + + public TripType getTripType() { + return this.tripType; + } + + public void setTripType(TripType tripType) { + this.tripType = tripType; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDetails() { + return this.details; + } + + public void setDetails(String details) { + this.details = details; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/TripType.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/TripType.java new file mode 100644 index 0000000000..0a52e3b91e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/domain/TripType.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.domain; + +public enum TripType { + + BUSINESS, COUPLES, FAMILY, FRIENDS, SOLO + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityRepository.java new file mode 100644 index 0000000000..497503e8f8 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityRepository.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.service; + +import smoketest.data.jpa.domain.City; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.repository.Repository; + +interface CityRepository extends Repository<City, Long> { + + Page<City> findAll(Pageable pageable); + + Page<City> findByNameContainingAndCountryContainingAllIgnoringCase(String name, String country, Pageable pageable); + + City findByNameAndCountryAllIgnoringCase(String name, String country); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CitySearchCriteria.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CitySearchCriteria.java new file mode 100644 index 0000000000..77c4f21305 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CitySearchCriteria.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.service; + +import java.io.Serializable; + +import org.springframework.util.Assert; + +public class CitySearchCriteria implements Serializable { + + private static final long serialVersionUID = 1L; + + private String name; + + public CitySearchCriteria() { + } + + public CitySearchCriteria(String name) { + Assert.notNull(name, "Name must not be null"); + this.name = name; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityService.java new file mode 100644 index 0000000000..27374292c1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityService.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.service; + +import smoketest.data.jpa.domain.City; +import smoketest.data.jpa.domain.HotelSummary; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface CityService { + + Page<City> findCities(CitySearchCriteria criteria, Pageable pageable); + + City getCity(String name, String country); + + Page<HotelSummary> getHotels(City city, Pageable pageable); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityServiceImpl.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityServiceImpl.java new file mode 100644 index 0000000000..7eaf414295 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/CityServiceImpl.java @@ -0,0 +1,77 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.service; + +import smoketest.data.jpa.domain.City; +import smoketest.data.jpa.domain.HotelSummary; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; + +@Component("cityService") +@Transactional +class CityServiceImpl implements CityService { + + private final CityRepository cityRepository; + + private final HotelRepository hotelRepository; + + CityServiceImpl(CityRepository cityRepository, HotelRepository hotelRepository) { + this.cityRepository = cityRepository; + this.hotelRepository = hotelRepository; + } + + @Override + public Page<City> findCities(CitySearchCriteria criteria, Pageable pageable) { + + Assert.notNull(criteria, "Criteria must not be null"); + String name = criteria.getName(); + + if (!StringUtils.hasLength(name)) { + return this.cityRepository.findAll(null); + } + + String country = ""; + int splitPos = name.lastIndexOf(","); + + if (splitPos >= 0) { + country = name.substring(splitPos + 1); + name = name.substring(0, splitPos); + } + + return this.cityRepository.findByNameContainingAndCountryContainingAllIgnoringCase(name.trim(), country.trim(), + pageable); + } + + @Override + public City getCity(String name, String country) { + Assert.notNull(name, "Name must not be null"); + Assert.notNull(country, "Country must not be null"); + return this.cityRepository.findByNameAndCountryAllIgnoringCase(name, country); + } + + @Override + public Page<HotelSummary> getHotels(City city, Pageable pageable) { + Assert.notNull(city, "City must not be null"); + return this.hotelRepository.findByCity(city, pageable); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/HotelRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/HotelRepository.java new file mode 100644 index 0000000000..b092d0fcbe --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/HotelRepository.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.service; + +import java.util.List; + +import smoketest.data.jpa.domain.City; +import smoketest.data.jpa.domain.Hotel; +import smoketest.data.jpa.domain.HotelSummary; +import smoketest.data.jpa.domain.RatingCount; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.Repository; + +interface HotelRepository extends Repository<Hotel, Long> { + + Hotel findByCityAndName(City city, String name); + + @Query("select h.city as city, h.name as name, avg(r.rating) as averageRating " + + "from Hotel h left outer join h.reviews r where h.city = ?1 group by h") + Page<HotelSummary> findByCity(City city, Pageable pageable); + + @Query("select r.rating as rating, count(r) as count " + + "from Review r where r.hotel = ?1 group by r.rating order by r.rating DESC") + List<RatingCount> findRatingCounts(Hotel hotel); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/HotelService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/HotelService.java new file mode 100644 index 0000000000..b9869d5f13 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/HotelService.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.service; + +import smoketest.data.jpa.domain.City; +import smoketest.data.jpa.domain.Hotel; +import smoketest.data.jpa.domain.Review; +import smoketest.data.jpa.domain.ReviewDetails; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface HotelService { + + Hotel getHotel(City city, String name); + + Page<Review> getReviews(Hotel hotel, Pageable pageable); + + Review getReview(Hotel hotel, int index); + + Review addReview(Hotel hotel, ReviewDetails details); + + ReviewsSummary getReviewSummary(Hotel hotel); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/HotelServiceImpl.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/HotelServiceImpl.java new file mode 100644 index 0000000000..78356b1796 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/HotelServiceImpl.java @@ -0,0 +1,99 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import smoketest.data.jpa.domain.City; +import smoketest.data.jpa.domain.Hotel; +import smoketest.data.jpa.domain.Rating; +import smoketest.data.jpa.domain.RatingCount; +import smoketest.data.jpa.domain.Review; +import smoketest.data.jpa.domain.ReviewDetails; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; + +@Component("hotelService") +@Transactional +class HotelServiceImpl implements HotelService { + + private final HotelRepository hotelRepository; + + private final ReviewRepository reviewRepository; + + HotelServiceImpl(HotelRepository hotelRepository, ReviewRepository reviewRepository) { + this.hotelRepository = hotelRepository; + this.reviewRepository = reviewRepository; + } + + @Override + public Hotel getHotel(City city, String name) { + Assert.notNull(city, "City must not be null"); + Assert.hasLength(name, "Name must not be empty"); + return this.hotelRepository.findByCityAndName(city, name); + } + + @Override + public Page<Review> getReviews(Hotel hotel, Pageable pageable) { + Assert.notNull(hotel, "Hotel must not be null"); + return this.reviewRepository.findByHotel(hotel, pageable); + } + + @Override + public Review getReview(Hotel hotel, int reviewNumber) { + Assert.notNull(hotel, "Hotel must not be null"); + return this.reviewRepository.findByHotelAndIndex(hotel, reviewNumber); + } + + @Override + public Review addReview(Hotel hotel, ReviewDetails details) { + Review review = new Review(hotel, 1, details); + return this.reviewRepository.save(review); + } + + @Override + public ReviewsSummary getReviewSummary(Hotel hotel) { + List<RatingCount> ratingCounts = this.hotelRepository.findRatingCounts(hotel); + return new ReviewsSummaryImpl(ratingCounts); + } + + private static class ReviewsSummaryImpl implements ReviewsSummary { + + private final Map<Rating, Long> ratingCount; + + ReviewsSummaryImpl(List<RatingCount> ratingCounts) { + this.ratingCount = new HashMap<>(); + for (RatingCount ratingCount : ratingCounts) { + this.ratingCount.put(ratingCount.getRating(), ratingCount.getCount()); + } + } + + @Override + public long getNumberOfReviewsWithRating(Rating rating) { + Long count = this.ratingCount.get(rating); + return (count != null) ? count : 0; + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/ReviewRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/ReviewRepository.java new file mode 100644 index 0000000000..0e84ec73d3 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/ReviewRepository.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.service; + +import smoketest.data.jpa.domain.Hotel; +import smoketest.data.jpa.domain.Review; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.repository.Repository; + +interface ReviewRepository extends Repository<Review, Long> { + + Page<Review> findByHotel(Hotel hotel, Pageable pageable); + + Review findByHotelAndIndex(Hotel hotel, int index); + + Review save(Review review); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/ReviewsSummary.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/ReviewsSummary.java new file mode 100644 index 0000000000..d55e8d8910 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/service/ReviewsSummary.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.service; + +import smoketest.data.jpa.domain.Rating; + +public interface ReviewsSummary { + + long getNumberOfReviewsWithRating(Rating rating); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/web/SampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/web/SampleController.java new file mode 100644 index 0000000000..8d407e01d6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/java/smoketest/data/jpa/web/SampleController.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa.web; + +import smoketest.data.jpa.service.CityService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class SampleController { + + @Autowired + private CityService cityService; + + @GetMapping("/") + @ResponseBody + @Transactional(readOnly = true) + public String helloWorld() { + return this.cityService.getCity("Bath", "UK").getName(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-jpa/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/resources/import.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/resources/import.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-jpa/src/main/resources/import.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/main/resources/import.sql diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/SampleDataJpaApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/SampleDataJpaApplicationTests.java new file mode 100644 index 0000000000..db319a3abf --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/SampleDataJpaApplicationTests.java @@ -0,0 +1,72 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.jpa; + +import java.lang.management.ManagementFactory; + +import javax.management.ObjectName; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * Integration test to run the application. + * + * @author Oliver Gierke + * @author Dave Syer + */ +// Enable JMX so we can test the MBeans (you can't do this in a properties file) +@SpringBootTest(properties = "spring.jmx.enabled:true") +@ActiveProfiles("scratch") +// Separate profile for web tests to avoid clashing databases +class SampleDataJpaApplicationTests { + + @Autowired + private WebApplicationContext context; + + private MockMvc mvc; + + @BeforeEach + void setUp() { + this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); + } + + @Test + void testHome() throws Exception { + + this.mvc.perform(get("/")).andExpect(status().isOk()).andExpect(content().string("Bath")); + } + + @Test + void testJmx() throws Exception { + assertThat(ManagementFactory.getPlatformMBeanServer() + .queryMBeans(new ObjectName("jpa.sample:type=HikariDataSource,*"), null)).hasSize(1); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/service/CityRepositoryIntegrationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/service/CityRepositoryIntegrationTests.java new file mode 100644 index 0000000000..43b222e95d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/service/CityRepositoryIntegrationTests.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package smoketest.data.jpa.service; + +import org.junit.jupiter.api.Test; +import smoketest.data.jpa.domain.City; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link CityRepository}. + * + * @author Oliver Gierke + */ +@SpringBootTest +class CityRepositoryIntegrationTests { + + @Autowired + CityRepository repository; + + @Test + void findsFirstPageOfCities() { + Page<City> cities = this.repository.findAll(PageRequest.of(0, 10)); + assertThat(cities.getTotalElements()).isGreaterThan(20L); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/service/HotelRepositoryIntegrationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/service/HotelRepositoryIntegrationTests.java new file mode 100644 index 0000000000..7341287540 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/java/smoketest/data/jpa/service/HotelRepositoryIntegrationTests.java @@ -0,0 +1,62 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package smoketest.data.jpa.service; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import smoketest.data.jpa.domain.City; +import smoketest.data.jpa.domain.Hotel; +import smoketest.data.jpa.domain.HotelSummary; +import smoketest.data.jpa.domain.Rating; +import smoketest.data.jpa.domain.RatingCount; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort.Direction; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link HotelRepository}. + * + * @author Oliver Gierke + */ +@SpringBootTest +class HotelRepositoryIntegrationTests { + + @Autowired + CityRepository cityRepository; + + @Autowired + HotelRepository repository; + + @Test + void executesQueryMethodsCorrectly() { + City city = this.cityRepository.findAll(PageRequest.of(0, 1, Direction.ASC, "name")).getContent().get(0); + assertThat(city.getName()).isEqualTo("Atlanta"); + Page<HotelSummary> hotels = this.repository.findByCity(city, PageRequest.of(0, 10, Direction.ASC, "name")); + Hotel hotel = this.repository.findByCityAndName(city, hotels.getContent().get(0).getName()); + assertThat(hotel.getName()).isEqualTo("Doubletree"); + List<RatingCount> counts = this.repository.findRatingCounts(hotel); + assertThat(counts).hasSize(1); + assertThat(counts.get(0).getRating()).isEqualTo(Rating.AVERAGE); + assertThat(counts.get(0).getCount()).isGreaterThan(1L); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/resources/application-scratch.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/resources/application-scratch.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-jpa/src/test/resources/application-scratch.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-jpa/src/test/resources/application-scratch.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/pom.xml new file mode 100644 index 0000000000..5e43bce1e7 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/pom.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-data-ldap</artifactId> + <name>Spring Boot Data LDAP Smoke Test</name> + <description>Spring Boot Data LDAP Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>com.unboundid</groupId> + <artifactId>unboundid-ldapsdk</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-ldap</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/java/smoketest/data/ldap/Person.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/java/smoketest/data/ldap/Person.java new file mode 100644 index 0000000000..bbe0e91813 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/java/smoketest/data/ldap/Person.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.ldap; + +import javax.naming.Name; + +import org.springframework.ldap.odm.annotations.Attribute; +import org.springframework.ldap.odm.annotations.Entry; +import org.springframework.ldap.odm.annotations.Id; + +@Entry(objectClasses = { "person", "top" }) +public class Person { + + @Id + private Name dn; + + @Attribute(name = "telephoneNumber") + private String phone; + + @Override + public String toString() { + return String.format("Customer[dn=%s, phone='%s']", this.dn, this.phone); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/java/smoketest/data/ldap/PersonRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/java/smoketest/data/ldap/PersonRepository.java new file mode 100644 index 0000000000..cbb986bd63 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/java/smoketest/data/ldap/PersonRepository.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.ldap; + +import org.springframework.data.ldap.repository.LdapRepository; + +public interface PersonRepository extends LdapRepository<Person> { + + Person findByPhone(String phone); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/java/smoketest/data/ldap/SampleLdapApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/java/smoketest/data/ldap/SampleLdapApplication.java new file mode 100644 index 0000000000..30a9c968eb --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/java/smoketest/data/ldap/SampleLdapApplication.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.ldap; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleLdapApplication implements CommandLineRunner { + + private final PersonRepository repository; + + public SampleLdapApplication(PersonRepository repository) { + this.repository = repository; + } + + @Override + public void run(String... args) throws Exception { + + // fetch all people + System.out.println("People found with findAll():"); + System.out.println("-------------------------------"); + for (Person person : this.repository.findAll()) { + System.out.println(person); + } + System.out.println(); + + // fetch an individual person + System.out.println("Person found with findByPhone('+46 555-123456'):"); + System.out.println("--------------------------------"); + System.out.println(this.repository.findByPhone("+46 555-123456")); + } + + public static void main(String[] args) { + SpringApplication.run(SampleLdapApplication.class, args).close(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-data-ldap/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-ldap/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-data-ldap/src/main/resources/schema.ldif b/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/resources/schema.ldif similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-ldap/src/main/resources/schema.ldif rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/main/resources/schema.ldif diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/test/java/smoketest/data/ldap/SampleLdapApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/test/java/smoketest/data/ldap/SampleLdapApplicationTests.java new file mode 100644 index 0000000000..98d8409326 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-ldap/src/test/java/smoketest/data/ldap/SampleLdapApplicationTests.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.ldap; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleLdapApplication}. + * + * @author Phillip Webb + */ +@ExtendWith(OutputCaptureExtension.class) +@SpringBootTest +class SampleLdapApplicationTests { + + @Test + void testDefaultSettings(CapturedOutput output) { + assertThat(output).contains("cn=Alice Smith"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/pom.xml new file mode 100644 index 0000000000..8422a367ea --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/pom.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-data-mongodb</artifactId> + <name>Spring Boot Data MongoDB Smoke Test</name> + <description>Spring Boot Data MongoDB Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-mongodb</artifactId> + </dependency> + <dependency> + <groupId>de.flapdoodle.embed</groupId> + <artifactId>de.flapdoodle.embed.mongo</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/Customer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/Customer.java new file mode 100644 index 0000000000..af7f0ee24c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/Customer.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.mongo; + +import org.springframework.data.annotation.Id; + +public class Customer { + + @Id + private String id; + + private String firstName; + + private String lastName; + + public Customer() { + } + + public Customer(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + @Override + public String toString() { + return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, this.firstName, this.lastName); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/CustomerRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/CustomerRepository.java new file mode 100644 index 0000000000..be744ec3ca --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/CustomerRepository.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.mongo; + +import java.util.List; + +import org.springframework.data.mongodb.repository.MongoRepository; + +public interface CustomerRepository extends MongoRepository<Customer, String> { + + Customer findByFirstName(String firstName); + + List<Customer> findByLastName(String lastName); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/SampleMongoApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/SampleMongoApplication.java new file mode 100644 index 0000000000..84b2772cc0 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/main/java/smoketest/data/mongo/SampleMongoApplication.java @@ -0,0 +1,72 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.mongo; + +import java.util.concurrent.TimeUnit; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.mongo.MongoClientSettingsBuilderCustomizer; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class SampleMongoApplication implements CommandLineRunner { + + @Autowired + private CustomerRepository repository; + + @Override + public void run(String... args) throws Exception { + this.repository.deleteAll(); + + // save a couple of customers + this.repository.save(new Customer("Alice", "Smith")); + this.repository.save(new Customer("Bob", "Smith")); + + // fetch all customers + System.out.println("Customers found with findAll():"); + System.out.println("-------------------------------"); + for (Customer customer : this.repository.findAll()) { + System.out.println(customer); + } + System.out.println(); + + // fetch an individual customer + System.out.println("Customer found with findByFirstName('Alice'):"); + System.out.println("--------------------------------"); + System.out.println(this.repository.findByFirstName("Alice")); + + System.out.println("Customers found with findByLastName('Smith'):"); + System.out.println("--------------------------------"); + for (Customer customer : this.repository.findByLastName("Smith")) { + System.out.println(customer); + } + } + + @Bean + public MongoClientSettingsBuilderCustomizer customizer() { + return (builder) -> builder.applyToConnectionPoolSettings( + (connectionPool) -> connectionPool.maxConnectionIdleTime(5, TimeUnit.MINUTES)); + } + + public static void main(String[] args) { + SpringApplication.run(SampleMongoApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/test/java/smoketest/data/mongo/SampleMongoApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/test/java/smoketest/data/mongo/SampleMongoApplicationTests.java new file mode 100644 index 0000000000..bd16164dd6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-mongodb/src/test/java/smoketest/data/mongo/SampleMongoApplicationTests.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.mongo; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleMongoApplication}. + * + * @author Dave Syer + * @author Andy Wilkinson + */ +@ExtendWith(OutputCaptureExtension.class) +@SpringBootTest +class SampleMongoApplicationTests { + + @Test + void testDefaultSettings(CapturedOutput output) { + assertThat(output).contains("firstName='Alice', lastName='Smith'"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/pom.xml new file mode 100644 index 0000000000..a21b1ba761 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-data-neo4j</artifactId> + <name>Spring Boot Data Neo4j Smoke Test</name> + <description>Spring Boot Data Neo4j Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-neo4j</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/java/smoketest/data/neo4j/Customer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/java/smoketest/data/neo4j/Customer.java new file mode 100644 index 0000000000..52b6d59f32 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/java/smoketest/data/neo4j/Customer.java @@ -0,0 +1,47 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.neo4j; + +import org.neo4j.ogm.annotation.GeneratedValue; +import org.neo4j.ogm.annotation.Id; +import org.neo4j.ogm.annotation.NodeEntity; + +@NodeEntity +public class Customer { + + @Id + @GeneratedValue + private Long id; + + private String firstName; + + private String lastName; + + public Customer() { + } + + public Customer(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + @Override + public String toString() { + return String.format("Customer[id=%s, firstName='%s', lastName='%s']", this.id, this.firstName, this.lastName); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/java/smoketest/data/neo4j/CustomerRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/java/smoketest/data/neo4j/CustomerRepository.java new file mode 100644 index 0000000000..e185aac4f0 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/java/smoketest/data/neo4j/CustomerRepository.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.neo4j; + +import java.util.List; + +import org.springframework.data.neo4j.repository.Neo4jRepository; + +public interface CustomerRepository extends Neo4jRepository<Customer, Long> { + + Customer findByFirstName(String firstName); + + List<Customer> findByLastName(String lastName); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/java/smoketest/data/neo4j/SampleNeo4jApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/java/smoketest/data/neo4j/SampleNeo4jApplication.java new file mode 100644 index 0000000000..f91eb54d0f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/java/smoketest/data/neo4j/SampleNeo4jApplication.java @@ -0,0 +1,62 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.neo4j; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleNeo4jApplication implements CommandLineRunner { + + @Autowired + private CustomerRepository repository; + + @Override + public void run(String... args) throws Exception { + this.repository.deleteAll(); + + // save a couple of customers + this.repository.save(new Customer("Alice", "Smith")); + this.repository.save(new Customer("Bob", "Smith")); + + // fetch all customers + System.out.println("Customers found with findAll():"); + System.out.println("-------------------------------"); + for (Customer customer : this.repository.findAll()) { + System.out.println(customer); + } + System.out.println(); + + // fetch an individual customer + System.out.println("Customer found with findByFirstName('Alice'):"); + System.out.println("--------------------------------"); + System.out.println(this.repository.findByFirstName("Alice")); + + System.out.println("Customers found with findByLastName('Smith'):"); + System.out.println("--------------------------------"); + for (Customer customer : this.repository.findByLastName("Smith")) { + System.out.println(customer); + } + } + + public static void main(String[] args) { + SpringApplication.run(SampleNeo4jApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-neo4j/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/test/java/smoketest/data/neo4j/SampleNeo4jApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/test/java/smoketest/data/neo4j/SampleNeo4jApplicationTests.java new file mode 100644 index 0000000000..5360816e6a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-neo4j/src/test/java/smoketest/data/neo4j/SampleNeo4jApplicationTests.java @@ -0,0 +1,56 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.neo4j; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.neo4j.driver.v1.exceptions.ServiceUnavailableException; + +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleNeo4jApplication}. + * + * @author Stephane Nicoll + */ +@ExtendWith(OutputCaptureExtension.class) +class SampleNeo4jApplicationTests { + + @Test + void testDefaultSettings(CapturedOutput capturedOutput) { + try { + SampleNeo4jApplication.main(new String[0]); + } + catch (Exception ex) { + if (!neo4jServerRunning(ex)) { + return; + } + } + assertThat(capturedOutput).contains("firstName='Alice', lastName='Smith'"); + } + + private boolean neo4jServerRunning(Throwable ex) { + if (ex instanceof ServiceUnavailableException) { + return false; + } + return (ex.getCause() == null || neo4jServerRunning(ex.getCause())); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/pom.xml new file mode 100644 index 0000000000..bf1b2f9e38 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/pom.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-data-redis</artifactId> + <name>Spring Boot Data Redis Smoke Test</name> + <description>Spring Boot Data Redis Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-redis</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <profiles> + <profile> + <id>production</id> + <dependencies> + <!-- This sample is a test for the autoconfig when commons-pool is *absent*. + In production it would be useful to enable pooling by using this dependency. --> + <dependency> + <groupId>commons-pool</groupId> + <artifactId>commons-pool</artifactId> + <type>pom.lastUpdated</type> + </dependency> + </dependencies> + </profile> + </profiles> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/src/main/java/smoketest/data/redis/SampleRedisApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/src/main/java/smoketest/data/redis/SampleRedisApplication.java new file mode 100644 index 0000000000..eb90dbb14c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/src/main/java/smoketest/data/redis/SampleRedisApplication.java @@ -0,0 +1,47 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.redis; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.core.ValueOperations; + +@SpringBootApplication +public class SampleRedisApplication implements CommandLineRunner { + + @Autowired + private StringRedisTemplate template; + + @Override + public void run(String... args) throws Exception { + ValueOperations<String, String> ops = this.template.opsForValue(); + String key = "spring.boot.redis.test"; + if (!this.template.hasKey(key)) { + ops.set(key, "foo"); + } + System.out.println("Found key " + key + ", value=" + ops.get(key)); + } + + public static void main(String[] args) { + // Close the context so it doesn't stay awake listening for redis + SpringApplication.run(SampleRedisApplication.class, args).close(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/src/test/java/smoketest/data/redis/SampleRedisApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/src/test/java/smoketest/data/redis/SampleRedisApplicationTests.java new file mode 100644 index 0000000000..0fd6471c3a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-redis/src/test/java/smoketest/data/redis/SampleRedisApplicationTests.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.redis; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.data.redis.RedisConnectionFailureException; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleRedisApplication}. + * + * @author Dave Syer + */ +@ExtendWith(OutputCaptureExtension.class) +class SampleRedisApplicationTests { + + @Test + void testDefaultSettings(CapturedOutput capturedOutput) { + try { + SampleRedisApplication.main(new String[0]); + } + catch (Exception ex) { + if (!redisServerRunning(ex)) { + return; + } + } + assertThat(capturedOutput).contains("Found key spring.boot.redis.test"); + } + + private boolean redisServerRunning(Throwable ex) { + System.out.println(ex.getMessage()); + if (ex instanceof RedisConnectionFailureException) { + return false; + } + return (ex.getCause() == null || redisServerRunning(ex.getCause())); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/pom.xml new file mode 100644 index 0000000000..343845ace8 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/pom.xml @@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-data-rest</artifactId> + <name>Spring Boot Data REST Smoke Test</name> + <description>Spring Boot Data REST Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jetty</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-rest</artifactId> + </dependency> + <!-- Runtime --> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>runtime</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.jayway.jsonpath</groupId> + <artifactId>json-path</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>java9+</id> + <activation> + <jdk>[9,)</jdk> + </activation> + <dependencies> + <dependency> + <groupId>jakarta.xml.bind</groupId> + <artifactId>jakarta.xml.bind-api</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/SampleDataRestApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/SampleDataRestApplication.java new file mode 100644 index 0000000000..2d67384892 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/SampleDataRestApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.rest; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleDataRestApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleDataRestApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/domain/City.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/domain/City.java new file mode 100644 index 0000000000..b233379bdd --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/domain/City.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.rest.domain; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.SequenceGenerator; + +@Entity +public class City implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @SequenceGenerator(name = "city_generator", sequenceName = "city_sequence", initialValue = 23) + @GeneratedValue(generator = "city_generator") + private Long id; + + @Column(nullable = false) + private String name; + + @Column(nullable = false) + private String state; + + @Column(nullable = false) + private String country; + + @Column(nullable = false) + private String map; + + protected City() { + } + + public City(String name, String country) { + this.name = name; + this.country = country; + } + + public String getName() { + return this.name; + } + + public String getState() { + return this.state; + } + + public String getCountry() { + return this.country; + } + + public String getMap() { + return this.map; + } + + @Override + public String toString() { + return getName() + "," + getState() + "," + getCountry(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/domain/Hotel.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/domain/Hotel.java new file mode 100644 index 0000000000..fec1c813b2 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/domain/Hotel.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.rest.domain; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.SequenceGenerator; + +import org.hibernate.annotations.NaturalId; + +@Entity +public class Hotel implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @SequenceGenerator(name = "hotel_generator", sequenceName = "hotel_sequence", initialValue = 28) + @GeneratedValue(generator = "hotel_generator") + private Long id; + + @ManyToOne(optional = false) + @NaturalId + private City city; + + @Column(nullable = false) + @NaturalId + private String name; + + @Column(nullable = false) + private String address; + + @Column(nullable = false) + private String zip; + + protected Hotel() { + } + + public Hotel(City city, String name) { + this.city = city; + this.name = name; + } + + public City getCity() { + return this.city; + } + + public String getName() { + return this.name; + } + + public String getAddress() { + return this.address; + } + + public String getZip() { + return this.zip; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/service/CityRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/service/CityRepository.java new file mode 100644 index 0000000000..3015285ba2 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/service/CityRepository.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.rest.service; + +import smoketest.data.rest.domain.City; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource(collectionResourceRel = "cities", path = "cities") +interface CityRepository extends PagingAndSortingRepository<City, Long> { + + Page<City> findByNameContainingAndCountryContainingAllIgnoringCase(@Param("name") String name, + @Param("country") String country, Pageable pageable); + + City findByNameAndCountryAllIgnoringCase(@Param("name") String name, @Param("country") String country); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/service/CitySearchCriteria.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/service/CitySearchCriteria.java new file mode 100644 index 0000000000..8d30fce9ff --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/service/CitySearchCriteria.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.rest.service; + +import java.io.Serializable; + +import org.springframework.util.Assert; + +public class CitySearchCriteria implements Serializable { + + private static final long serialVersionUID = 1L; + + private String name; + + public CitySearchCriteria() { + } + + public CitySearchCriteria(String name) { + Assert.notNull(name, "Name must not be null"); + this.name = name; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/service/HotelRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/service/HotelRepository.java new file mode 100644 index 0000000000..327ca9e878 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/java/smoketest/data/rest/service/HotelRepository.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.rest.service; + +import smoketest.data.rest.domain.City; +import smoketest.data.rest.domain.Hotel; + +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource(collectionResourceRel = "hotels", path = "hotels") +interface HotelRepository extends PagingAndSortingRepository<Hotel, Long> { + + Hotel findByCityAndName(City city, String name); + +} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-rest/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/resources/import.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/resources/import.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-rest/src/main/resources/import.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/main/resources/import.sql diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/test/java/smoketest/data/rest/SampleDataRestApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/test/java/smoketest/data/rest/SampleDataRestApplicationTests.java new file mode 100644 index 0000000000..57f0456269 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/test/java/smoketest/data/rest/SampleDataRestApplicationTests.java @@ -0,0 +1,75 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.rest; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * Integration test to run the application. + * + * @author Oliver Gierke + * @author Andy Wilkinson + */ +@SpringBootTest +// Separate profile for web tests to avoid clashing databases +class SampleDataRestApplicationTests { + + @Autowired + private WebApplicationContext context; + + private MockMvc mvc; + + @BeforeEach + void setUp() { + this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); + } + + @Test + void testHome() throws Exception { + this.mvc.perform(get("/api")).andExpect(status().isOk()).andExpect(content().string(containsString("hotels"))); + } + + @Test + void findByNameAndCountry() throws Exception { + this.mvc.perform(get("/api/cities/search/findByNameAndCountryAllIgnoringCase?name=Melbourne&country=Australia")) + .andExpect(status().isOk()).andExpect(jsonPath("state", equalTo("Victoria"))) + .andExpect(jsonPath("name", equalTo("Melbourne"))); + } + + @Test + void findByContaining() throws Exception { + this.mvc.perform( + get("/api/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK")) + .andExpect(status().isOk()).andExpect(jsonPath("_embedded.cities", hasSize(3))); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/test/java/smoketest/data/rest/service/CityRepositoryIntegrationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/test/java/smoketest/data/rest/service/CityRepositoryIntegrationTests.java new file mode 100644 index 0000000000..085c0f4a01 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/test/java/smoketest/data/rest/service/CityRepositoryIntegrationTests.java @@ -0,0 +1,61 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.rest.service; + +import org.junit.jupiter.api.Test; +import smoketest.data.rest.domain.City; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link CityRepository}. + * + * @author Oliver Gierke + * @author Andy Wilkinson + */ +@SpringBootTest +class CityRepositoryIntegrationTests { + + @Autowired + CityRepository repository; + + @Test + void findsFirstPageOfCities() { + Page<City> cities = this.repository.findAll(PageRequest.of(0, 10)); + assertThat(cities.getTotalElements()).isGreaterThan(20L); + } + + @Test + void findByNameAndCountry() { + City city = this.repository.findByNameAndCountryAllIgnoringCase("Melbourne", "Australia"); + assertThat(city).isNotNull(); + assertThat(city.getName()).isEqualTo("Melbourne"); + } + + @Test + void findContaining() { + Page<City> cities = this.repository.findByNameContainingAndCountryContainingAllIgnoringCase("", "UK", + PageRequest.of(0, 10)); + assertThat(cities.getTotalElements()).isEqualTo(3L); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/test/resources/application-scratch.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/test/resources/application-scratch.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-data-rest/src/test/resources/application-scratch.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-data-rest/src/test/resources/application-scratch.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/pom.xml new file mode 100644 index 0000000000..72b5b035c3 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-data-solr</artifactId> + <name>Spring Boot Data Solr Smoke Test</name> + <description>Spring Boot Data Solr Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-solr</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/main/java/smoketest/data/solr/Product.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/main/java/smoketest/data/solr/Product.java new file mode 100644 index 0000000000..c62220f579 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/main/java/smoketest/data/solr/Product.java @@ -0,0 +1,100 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.solr; + +import java.util.List; + +import org.apache.solr.client.solrj.beans.Field; + +import org.springframework.data.annotation.Id; +import org.springframework.data.solr.core.geo.Point; +import org.springframework.data.solr.core.mapping.SolrDocument; + +@SolrDocument(solrCoreName = "collection1") +public class Product { + + @Id + @Field + private String id; + + @Field + private String name; + + @Field + private Double price; + + @Field("cat") + private List<String> category; + + @Field("store") + private Point location; + + public Product() { + } + + public Product(String id, String name) { + this.id = id; + this.name = name; + } + + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public Double getPrice() { + return this.price; + } + + public void setPrice(Double price) { + this.price = price; + } + + public List<String> getCategory() { + return this.category; + } + + public void setCategory(List<String> category) { + this.category = category; + } + + public Point getLocation() { + return this.location; + } + + public void setLocation(Point location) { + this.location = location; + } + + @Override + public String toString() { + return "Product [id=" + this.id + ", name=" + this.name + ", price=" + this.price + ", category=" + + this.category + ", location=" + this.location + "]"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/main/java/smoketest/data/solr/ProductRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/main/java/smoketest/data/solr/ProductRepository.java new file mode 100644 index 0000000000..2ecd22e5b3 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/main/java/smoketest/data/solr/ProductRepository.java @@ -0,0 +1,27 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.solr; + +import java.util.List; + +import org.springframework.data.solr.repository.SolrCrudRepository; + +public interface ProductRepository extends SolrCrudRepository<Product, String> { + + List<Product> findByNameStartingWith(String name); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/main/java/smoketest/data/solr/SampleSolrApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/main/java/smoketest/data/solr/SampleSolrApplication.java new file mode 100644 index 0000000000..19e016edcc --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/main/java/smoketest/data/solr/SampleSolrApplication.java @@ -0,0 +1,61 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.solr; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleSolrApplication implements CommandLineRunner { + + @Autowired + private ProductRepository repository; + + @Override + public void run(String... args) throws Exception { + + this.repository.deleteAll(); + + // insert some products + this.repository.save(new Product("1", "Nintendo Entertainment System")); + this.repository.save(new Product("2", "Sega Megadrive")); + this.repository.save(new Product("3", "Sony Playstation")); + + // fetch all + System.out.println("Products found by findAll():"); + System.out.println("----------------------------"); + for (Product product : this.repository.findAll()) { + System.out.println(product); + } + System.out.println(); + + // fetch a single product + System.out.println("Products found with findByNameStartingWith('So'):"); + System.out.println("--------------------------------"); + for (Product product : this.repository.findByNameStartingWith("So")) { + System.out.println(product); + } + System.out.println(); + } + + public static void main(String[] args) { + SpringApplication.run(SampleSolrApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/test/java/smoketest/data/solr/SampleSolrApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/test/java/smoketest/data/solr/SampleSolrApplicationTests.java new file mode 100644 index 0000000000..7aae88c444 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-data-solr/src/test/java/smoketest/data/solr/SampleSolrApplicationTests.java @@ -0,0 +1,55 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.data.solr; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.core.NestedCheckedException; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(OutputCaptureExtension.class) +class SampleSolrApplicationTests { + + @Test + void testDefaultSettings(CapturedOutput capturedOutput) throws Exception { + try { + SampleSolrApplication.main(new String[0]); + } + catch (IllegalStateException ex) { + if (serverNotRunning(ex)) { + return; + } + } + assertThat(capturedOutput).contains("name=Sony Playstation"); + } + + @SuppressWarnings("serial") + private boolean serverNotRunning(IllegalStateException ex) { + NestedCheckedException nested = new NestedCheckedException("failed", ex) { + }; + Throwable root = nested.getRootCause(); + if (root.getMessage().contains("Connection refused")) { + return true; + } + return false; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/pom.xml new file mode 100644 index 0000000000..1fbccae1de --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/pom.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-devtools</artifactId> + <name>Spring Boot Developer Tools Smoke Test</name> + <description>Spring Boot Developer Tools Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-thymeleaf</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-devtools</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/java/smoketest/devtools/Message.java b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/java/smoketest/devtools/Message.java new file mode 100644 index 0000000000..cf4aea1150 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/java/smoketest/devtools/Message.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.devtools; + +public final class Message { + + /** + * Sample message. + */ + public static String MESSAGE = "Message"; + + private Message() { + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/java/smoketest/devtools/MyController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/java/smoketest/devtools/MyController.java new file mode 100644 index 0000000000..2fc3e79f3c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/java/smoketest/devtools/MyController.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.devtools; + +import java.util.Date; + +import javax.annotation.PostConstruct; +import javax.servlet.http.HttpSession; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.servlet.ModelAndView; + +@Controller +public class MyController { + + @PostConstruct + public void slowRestart() throws InterruptedException { + Thread.sleep(5000); + } + + @GetMapping("/") + public ModelAndView get(HttpSession session) { + Object sessionVar = session.getAttribute("var"); + if (sessionVar == null) { + sessionVar = new Date(); + session.setAttribute("var", sessionVar); + } + ModelMap model = new ModelMap("message", Message.MESSAGE).addAttribute("sessionVar", sessionVar); + return new ModelAndView("hello", model); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/java/smoketest/devtools/SampleDevToolsApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/java/smoketest/devtools/SampleDevToolsApplication.java new file mode 100644 index 0000000000..182fd20623 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/java/smoketest/devtools/SampleDevToolsApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.devtools; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleDevToolsApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleDevToolsApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-devtools/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/main/resources/public/public.txt b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/resources/public/public.txt similarity index 100% rename from spring-boot-samples/spring-boot-sample-devtools/src/main/resources/public/public.txt rename to spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/resources/public/public.txt diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/main/resources/static/css/application.css b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/resources/static/css/application.css similarity index 100% rename from spring-boot-samples/spring-boot-sample-devtools/src/main/resources/static/css/application.css rename to spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/resources/static/css/application.css diff --git a/spring-boot-samples/spring-boot-sample-devtools/src/main/resources/templates/hello.html b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/resources/templates/hello.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-devtools/src/main/resources/templates/hello.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/resources/templates/hello.html diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/test/java/smoketest/devtools/SampleDevToolsApplicationIntegrationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/test/java/smoketest/devtools/SampleDevToolsApplicationIntegrationTests.java new file mode 100644 index 0000000000..273e95ee4d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/test/java/smoketest/devtools/SampleDevToolsApplicationIntegrationTests.java @@ -0,0 +1,62 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.devtools; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link SampleDevToolsApplication}. + * + * @author Andy Wilkinson + * @author Phillip Webb + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleDevToolsApplicationIntegrationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testStaticResource() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/application.css", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("color: green;"); + } + + @Test + void testPublicResource() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/public.txt", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("public file"); + } + + @Test + void testClassResource() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/application.properties", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/pom.xml new file mode 100644 index 0000000000..09471436f6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/pom.xml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-flyway</artifactId> + <name>Spring Boot Flyway Smoke Test</name> + <description>Spring Boot Flyway Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.flywaydb</groupId> + <artifactId>flyway-core</artifactId> + </dependency> + <!-- Runtime --> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>runtime</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>java9+</id> + <activation> + <jdk>[9,)</jdk> + </activation> + <dependencies> + <dependency> + <groupId>jakarta.xml.bind</groupId> + <artifactId>jakarta.xml.bind-api</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/java/smoketest/flyway/Person.java b/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/java/smoketest/flyway/Person.java new file mode 100644 index 0000000000..d459639777 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/java/smoketest/flyway/Person.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.flyway; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.SequenceGenerator; + +@Entity +public class Person { + + @Id + @SequenceGenerator(name = "person_generator", sequenceName = "person_sequence", allocationSize = 1) + @GeneratedValue(generator = "person_generator") + private Long id; + + private String firstName; + + private String lastName; + + public String getFirstName() { + return this.firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return this.lastName; + } + + public void setLastName(String lastname) { + this.lastName = lastname; + } + + @Override + public String toString() { + return "Person [firstName=" + this.firstName + ", lastName=" + this.lastName + "]"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/java/smoketest/flyway/PersonRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/java/smoketest/flyway/PersonRepository.java new file mode 100644 index 0000000000..1f328b6b57 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/java/smoketest/flyway/PersonRepository.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.flyway; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface PersonRepository extends CrudRepository<Person, Long> { + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/java/smoketest/flyway/SampleFlywayApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/java/smoketest/flyway/SampleFlywayApplication.java new file mode 100644 index 0000000000..792939e74b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/java/smoketest/flyway/SampleFlywayApplication.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.flyway; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class SampleFlywayApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleFlywayApplication.class, args); + } + + @Bean + public CommandLineRunner runner(PersonRepository repository) { + return new CommandLineRunner() { + + @Override + public void run(String... args) throws Exception { + System.err.println(repository.findAll()); + } + + }; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/db/migration/V1__init.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/resources/db/migration/V1__init.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-flyway/src/main/resources/db/migration/V1__init.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/main/resources/db/migration/V1__init.sql diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/test/java/smoketest/flyway/SampleFlywayApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/test/java/smoketest/flyway/SampleFlywayApplicationTests.java new file mode 100644 index 0000000000..6ee2598c6c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/test/java/smoketest/flyway/SampleFlywayApplicationTests.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.flyway; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest +class SampleFlywayApplicationTests { + + @Autowired + private JdbcTemplate template; + + @Test + void testDefaultSettings() { + assertThat(this.template.queryForObject("SELECT COUNT(*) from PERSON", Integer.class)).isEqualTo(1); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/pom.xml new file mode 100644 index 0000000000..8cc6349f11 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-hateoas</artifactId> + <name>Spring Boot Hateoas Smoke Test</name> + <description>Spring Boot Hateoas Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-hateoas</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/SampleHateoasApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/SampleHateoasApplication.java new file mode 100644 index 0000000000..e4d8496319 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/SampleHateoasApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.hateoas; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleHateoasApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleHateoasApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/Customer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/Customer.java new file mode 100644 index 0000000000..813151bc68 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/Customer.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.hateoas.domain; + +public class Customer { + + private final Long id; + + private final String firstName; + + private final String lastName; + + public Customer(Long id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Long getId() { + return this.id; + } + + public String getFirstName() { + return this.firstName; + } + + public String getLastName() { + return this.lastName; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/CustomerRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/CustomerRepository.java new file mode 100644 index 0000000000..c0399433d4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/CustomerRepository.java @@ -0,0 +1,27 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.hateoas.domain; + +import java.util.List; + +public interface CustomerRepository { + + List<Customer> findAll(); + + Customer findOne(Long id); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/InMemoryCustomerRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/InMemoryCustomerRepository.java new file mode 100644 index 0000000000..049fde435f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/domain/InMemoryCustomerRepository.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.hateoas.domain; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Repository; +import org.springframework.util.ObjectUtils; + +@Repository +public class InMemoryCustomerRepository implements CustomerRepository { + + private final List<Customer> customers = new ArrayList<>(); + + public InMemoryCustomerRepository() { + this.customers.add(new Customer(1L, "Oliver", "Gierke")); + this.customers.add(new Customer(2L, "Andy", "Wilkinson")); + this.customers.add(new Customer(2L, "Dave", "Syer")); + } + + @Override + public List<Customer> findAll() { + return this.customers; + } + + @Override + public Customer findOne(Long id) { + for (Customer customer : this.customers) { + if (ObjectUtils.nullSafeEquals(customer.getId(), id)) { + return customer; + } + } + return null; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/CustomerController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/CustomerController.java new file mode 100644 index 0000000000..6ea2eee8bb --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/main/java/smoketest/hateoas/web/CustomerController.java @@ -0,0 +1,63 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.hateoas.web; + +import smoketest.hateoas.domain.Customer; +import smoketest.hateoas.domain.CustomerRepository; + +import org.springframework.hateoas.CollectionModel; +import org.springframework.hateoas.EntityModel; +import org.springframework.hateoas.server.EntityLinks; +import org.springframework.hateoas.server.ExposesResourceFor; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping("/customers") +@ExposesResourceFor(Customer.class) +public class CustomerController { + + private final CustomerRepository repository; + + private final EntityLinks entityLinks; + + public CustomerController(CustomerRepository repository, EntityLinks entityLinks) { + this.repository = repository; + this.entityLinks = entityLinks; + } + + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + HttpEntity<CollectionModel<Customer>> showCustomers() { + CollectionModel<Customer> resources = new CollectionModel<>(this.repository.findAll()); + resources.add(this.entityLinks.linkToCollectionResource(Customer.class)); + return new ResponseEntity<>(resources, HttpStatus.OK); + } + + @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + HttpEntity<EntityModel<Customer>> showCustomer(@PathVariable Long id) { + EntityModel<Customer> resource = new EntityModel<>(this.repository.findOne(id)); + resource.add(this.entityLinks.linkToItemResource(Customer.class, id)); + return new ResponseEntity<>(resource, HttpStatus.OK); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/test/java/smoketest/hateoas/SampleHateoasApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/test/java/smoketest/hateoas/SampleHateoasApplicationTests.java new file mode 100644 index 0000000000..55b720e06e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-hateoas/src/test/java/smoketest/hateoas/SampleHateoasApplicationTests.java @@ -0,0 +1,59 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.hateoas; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleHateoasApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void hasHalLinks() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/customers/1", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).startsWith("{\"id\":1,\"firstName\":\"Oliver\"" + ",\"lastName\":\"Gierke\""); + assertThat(entity.getBody()).contains("_links\":{\"self\":{\"href\""); + } + + @Test + void producesJsonWhenXmlIsPreferred() { + HttpHeaders headers = new HttpHeaders(); + headers.set(HttpHeaders.ACCEPT, "application/xml;q=0.9,application/json;q=0.8"); + HttpEntity<?> request = new HttpEntity<>(headers); + ResponseEntity<String> response = this.restTemplate.exchange("/customers/1", HttpMethod.GET, request, + String.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getHeaders().getContentType()).isEqualTo(MediaType.parseMediaType("application/json")); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-integration/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/pom.xml new file mode 100644 index 0000000000..3b824579c9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/pom.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-integration</artifactId> + <name>Spring Boot Integration Smoke Test</name> + <description>Spring Boot Integration Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-integration</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.integration</groupId> + <artifactId>spring-integration-file</artifactId> + </dependency> + <!-- Optional --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <optional>true</optional> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/HelloWorldService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/HelloWorldService.java new file mode 100644 index 0000000000..98a2cdd10f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/HelloWorldService.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.integration; + +import org.springframework.stereotype.Service; + +@Service +public class HelloWorldService { + + private final ServiceProperties configuration; + + public HelloWorldService(ServiceProperties configuration) { + this.configuration = configuration; + } + + public String getHelloMessage(String name) { + return this.configuration.getGreeting() + " " + name; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleApplicationRunner.java b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleApplicationRunner.java new file mode 100644 index 0000000000..9ed97d5a6d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleApplicationRunner.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.integration; + +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +@Component +public class SampleApplicationRunner implements ApplicationRunner { + + private final SampleMessageGateway gateway; + + public SampleApplicationRunner(SampleMessageGateway gateway) { + this.gateway = gateway; + } + + @Override + public void run(ApplicationArguments args) throws Exception { + for (String arg : args.getNonOptionArgs()) { + this.gateway.echo(arg); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleEndpoint.java b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleEndpoint.java new file mode 100644 index 0000000000..48ef1ad5de --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleEndpoint.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.integration; + +import java.io.File; +import java.io.FileInputStream; + +import org.springframework.integration.annotation.MessageEndpoint; +import org.springframework.integration.annotation.ServiceActivator; +import org.springframework.util.StreamUtils; + +@MessageEndpoint +public class SampleEndpoint { + + private final HelloWorldService helloWorldService; + + public SampleEndpoint(HelloWorldService helloWorldService) { + this.helloWorldService = helloWorldService; + } + + @ServiceActivator + public String hello(File input) throws Exception { + FileInputStream in = new FileInputStream(input); + String name = new String(StreamUtils.copyToByteArray(in)); + in.close(); + return this.helloWorldService.getHelloMessage(name); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleIntegrationApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleIntegrationApplication.java new file mode 100644 index 0000000000..576a2bd9be --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleIntegrationApplication.java @@ -0,0 +1,84 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.integration; + +import java.util.function.Consumer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.integration.channel.DirectChannel; +import org.springframework.integration.dsl.IntegrationFlow; +import org.springframework.integration.dsl.IntegrationFlows; +import org.springframework.integration.dsl.Pollers; +import org.springframework.integration.dsl.SourcePollingChannelAdapterSpec; +import org.springframework.integration.file.FileReadingMessageSource; +import org.springframework.integration.file.FileWritingMessageHandler; + +@SpringBootApplication +public class SampleIntegrationApplication { + + private final ServiceProperties serviceProperties; + + public SampleIntegrationApplication(ServiceProperties serviceProperties) { + this.serviceProperties = serviceProperties; + } + + @Bean + public FileReadingMessageSource fileReader() { + FileReadingMessageSource reader = new FileReadingMessageSource(); + reader.setDirectory(this.serviceProperties.getInputDir()); + return reader; + } + + @Bean + public DirectChannel inputChannel() { + return new DirectChannel(); + } + + @Bean + public DirectChannel outputChannel() { + return new DirectChannel(); + } + + @Bean + public FileWritingMessageHandler fileWriter() { + FileWritingMessageHandler writer = new FileWritingMessageHandler(this.serviceProperties.getOutputDir()); + writer.setExpectReply(false); + return writer; + } + + @Bean + public IntegrationFlow integrationFlow(SampleEndpoint endpoint) { + return IntegrationFlows.from(fileReader(), new FixedRatePoller()).channel(inputChannel()).handle(endpoint) + .channel(outputChannel()).handle(fileWriter()).get(); + } + + public static void main(String[] args) { + SpringApplication.run(SampleIntegrationApplication.class, args); + } + + private static class FixedRatePoller implements Consumer<SourcePollingChannelAdapterSpec> { + + @Override + public void accept(SourcePollingChannelAdapterSpec spec) { + spec.poller(Pollers.fixedRate(500)); + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleMessageGateway.java b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleMessageGateway.java new file mode 100644 index 0000000000..401effe626 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/SampleMessageGateway.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.integration; + +import org.springframework.integration.annotation.MessagingGateway; + +@MessagingGateway(defaultRequestChannel = "outputChannel") +public interface SampleMessageGateway { + + void echo(String message); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/ServiceProperties.java b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/ServiceProperties.java new file mode 100644 index 0000000000..fba6f7deac --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/java/smoketest/integration/ServiceProperties.java @@ -0,0 +1,60 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.integration; + +import java.io.File; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.jmx.export.annotation.ManagedAttribute; +import org.springframework.jmx.export.annotation.ManagedResource; + +@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) +@ManagedResource +public class ServiceProperties { + + private String greeting = "Hello"; + + private File inputDir; + + private File outputDir; + + @ManagedAttribute + public String getGreeting() { + return this.greeting; + } + + public void setGreeting(String greeting) { + this.greeting = greeting; + } + + public File getInputDir() { + return this.inputDir; + } + + public void setInputDir(File inputDir) { + this.inputDir = inputDir; + } + + public File getOutputDir() { + return this.outputDir; + } + + public void setOutputDir(File outputDir) { + this.outputDir = outputDir; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-integration/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-integration/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/consumer/SampleIntegrationApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/consumer/SampleIntegrationApplicationTests.java new file mode 100644 index 0000000000..bb72a08711 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/consumer/SampleIntegrationApplicationTests.java @@ -0,0 +1,116 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.integration.consumer; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.util.concurrent.Callable; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import smoketest.integration.SampleIntegrationApplication; +import smoketest.integration.ServiceProperties; +import smoketest.integration.producer.ProducerApplication; + +import org.springframework.boot.SpringApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.ResourcePatternUtils; +import org.springframework.util.StreamUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for service demo application. + * + * @author Dave Syer + * @author Andy Wilkinson + */ +class SampleIntegrationApplicationTests { + + private ConfigurableApplicationContext context; + + @AfterEach + void stop() { + if (this.context != null) { + this.context.close(); + } + } + + @Test + void testVanillaExchange(@TempDir Path temp) throws Exception { + File inputDir = new File(temp.toFile(), "input"); + File outputDir = new File(temp.toFile(), "output"); + this.context = SpringApplication.run(SampleIntegrationApplication.class, "--service.input-dir=" + inputDir, + "--service.output-dir=" + outputDir); + SpringApplication.run(ProducerApplication.class, "World", "--service.input-dir=" + inputDir, + "--service.output-dir=" + outputDir); + String output = getOutput(outputDir); + assertThat(output).contains("Hello World"); + } + + @Test + void testMessageGateway(@TempDir Path temp) throws Exception { + File inputDir = new File(temp.toFile(), "input"); + File outputDir = new File(temp.toFile(), "output"); + this.context = SpringApplication.run(SampleIntegrationApplication.class, "testviamg", + "--service.input-dir=" + inputDir, "--service.output-dir=" + outputDir); + String output = getOutput(this.context.getBean(ServiceProperties.class).getOutputDir()); + assertThat(output).contains("testviamg"); + } + + private String getOutput(File outputDir) throws Exception { + Future<String> future = Executors.newSingleThreadExecutor().submit(new Callable<String>() { + @Override + public String call() throws Exception { + Resource[] resources = getResourcesWithContent(outputDir); + while (resources.length == 0) { + Thread.sleep(200); + resources = getResourcesWithContent(outputDir); + } + StringBuilder builder = new StringBuilder(); + for (Resource resource : resources) { + try (InputStream inputStream = resource.getInputStream()) { + builder.append(new String(StreamUtils.copyToByteArray(inputStream))); + } + } + return builder.toString(); + } + }); + return future.get(30, TimeUnit.SECONDS); + } + + private Resource[] getResourcesWithContent(File outputDir) throws IOException { + Resource[] candidates = ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader()) + .getResources("file:" + outputDir.getAbsolutePath() + "/**"); + for (Resource candidate : candidates) { + if ((candidate.getFilename() != null && candidate.getFilename().endsWith(".writing")) + || candidate.contentLength() == 0) { + return new Resource[0]; + } + } + return candidates; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/producer/ProducerApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/producer/ProducerApplication.java new file mode 100644 index 0000000000..3dc4a689c2 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/producer/ProducerApplication.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.integration.producer; + +import java.io.File; +import java.io.FileOutputStream; + +import smoketest.integration.ServiceProperties; + +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +@EnableConfigurationProperties(ServiceProperties.class) +public class ProducerApplication implements ApplicationRunner { + + private final ServiceProperties serviceProperties; + + public ProducerApplication(ServiceProperties serviceProperties) { + this.serviceProperties = serviceProperties; + } + + @Override + public void run(ApplicationArguments args) throws Exception { + this.serviceProperties.getInputDir().mkdirs(); + if (args.getNonOptionArgs().size() > 0) { + FileOutputStream stream = new FileOutputStream( + new File(this.serviceProperties.getInputDir(), "data" + System.currentTimeMillis() + ".txt")); + for (String arg : args.getNonOptionArgs()) { + stream.write(arg.getBytes()); + } + stream.flush(); + stream.close(); + } + } + + public static void main(String[] args) { + SpringApplication.run(ProducerApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/pom.xml new file mode 100644 index 0000000000..75d57cf1cb --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/pom.xml @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-jersey</artifactId> + <packaging>war</packaging> + <name>Spring Boot Jersey Smoke Test</name> + <description>Spring Boot Jersey Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jersey</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <!-- Provided --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + <scope>provided</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <executions> + <execution> + <id>generate build info</id> + <goals> + <goal>build-info</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>java9+</id> + <activation> + <jdk>[9,)</jdk> + </activation> + <dependencies> + <dependency> + <groupId>jakarta.xml.bind</groupId> + <artifactId>jakarta.xml.bind-api</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/Endpoint.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/Endpoint.java new file mode 100644 index 0000000000..93865301fe --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/Endpoint.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jersey; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.springframework.stereotype.Component; + +@Component +@Path("/hello") +public class Endpoint { + + private final Service service; + + public Endpoint(Service service) { + this.service = service; + } + + @GET + public String message() { + return "Hello " + this.service.message(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/JerseyConfig.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/JerseyConfig.java new file mode 100644 index 0000000000..e3c28a98fd --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/JerseyConfig.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jersey; + +import org.glassfish.jersey.server.ResourceConfig; + +import org.springframework.stereotype.Component; + +@Component +public class JerseyConfig extends ResourceConfig { + + public JerseyConfig() { + register(Endpoint.class); + register(ReverseEndpoint.class); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/ReverseEndpoint.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/ReverseEndpoint.java new file mode 100644 index 0000000000..a240ff5cad --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/ReverseEndpoint.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jersey; + +import javax.validation.constraints.NotNull; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +import org.springframework.stereotype.Component; + +@Component +@Path("/reverse") +public class ReverseEndpoint { + + @GET + public String reverse(@QueryParam("input") @NotNull String input) { + return new StringBuilder(input).reverse().toString(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/SampleJerseyApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/SampleJerseyApplication.java new file mode 100644 index 0000000000..52614dd8f6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/SampleJerseyApplication.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jersey; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +@SpringBootApplication +public class SampleJerseyApplication extends SpringBootServletInitializer { + + public static void main(String[] args) { + new SampleJerseyApplication().configure(new SpringApplicationBuilder(SampleJerseyApplication.class)).run(args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/Service.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/Service.java new file mode 100644 index 0000000000..46b4f4aff1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/Service.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jersey; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class Service { + + @Value("${message:World}") + private String msg; + + public String message() { + return this.msg; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/JerseyApplicationPathAndManagementPortTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/JerseyApplicationPathAndManagementPortTests.java new file mode 100644 index 0000000000..11c74243e5 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/JerseyApplicationPathAndManagementPortTests.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package smoketest.jersey; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for separate management and main service ports with custom + * application path. + * + * @author Madhura Bhave + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = { "management.server.port=0", "spring.jersey.application-path=/app" }) +class JerseyApplicationPathAndManagementPortTests { + + @LocalServerPort + private int port; + + @LocalManagementPort + private int managementPort; + + @Autowired + private TestRestTemplate testRestTemplate; + + @Test + void applicationPathShouldNotAffectActuators() { + ResponseEntity<String> entity = this.testRestTemplate + .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/SampleJerseyApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/SampleJerseyApplicationTests.java new file mode 100644 index 0000000000..0771ee6bc8 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/test/java/smoketest/jersey/SampleJerseyApplicationTests.java @@ -0,0 +1,62 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jersey; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleJerseyApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void contextLoads() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/hello", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + } + + @Test + void reverse() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/reverse?input=olleh", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("hello"); + } + + @Test + void validation() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/reverse", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + } + + @Test + void actuatorStatus() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/health", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/pom.xml new file mode 100644 index 0000000000..b7e41cb18a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/pom.xml @@ -0,0 +1,126 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-jetty-jsp</artifactId> + <packaging>war</packaging> + <name>Spring Boot Jetty JSP Smoke Test</name> + <description>Spring Boot Jetty JSP Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> + <servlet-api.version>3.1.0</servlet-api.version> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jstl</artifactId> + </dependency> + <!-- Provided --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jetty</artifactId> + <scope>provided</scope> + <exclusions> + <exclusion> + <groupId>jakarta.servlet</groupId> + <artifactId>jakarta.servlet-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>apache-jsp</artifactId> + <scope>provided</scope> + <exclusions> + <exclusion> + <groupId>javax.annotation</groupId> + <artifactId>javax.annotation-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <executions> + <execution> + <id>enforce-rules</id> + <goals> + <goal>enforce</goal> + </goals> + <configuration> + <rules> + <bannedDependencies> + <includes> + <include>javax.servlet:javax.servlet-api:*</include> + </includes> + <searchTransitive>true</searchTransitive> + </bannedDependencies> + </rules> + <fail>true</fail> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <useSystemClassLoader>false</useSystemClassLoader> + </configuration> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>java9+</id> + <activation> + <jdk>[9,)</jdk> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skipTests>true</skipTests> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/MyException.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/MyException.java new file mode 100644 index 0000000000..11a8624e8d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/MyException.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty.jsp; + +public class MyException extends RuntimeException { + + public MyException(String message) { + super(message); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/MyRestResponse.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/MyRestResponse.java new file mode 100644 index 0000000000..8803c7acfb --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/MyRestResponse.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty.jsp; + +public class MyRestResponse { + + private String message; + + public MyRestResponse(String message) { + this.message = message; + } + + public String getMessage() { + return this.message; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/SampleJettyJspApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/SampleJettyJspApplication.java new file mode 100644 index 0000000000..2ac2c54ea1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/SampleJettyJspApplication.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty.jsp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +@SpringBootApplication +public class SampleJettyJspApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleJettyJspApplication.class); + } + + public static void main(String[] args) { + SpringApplication.run(SampleJettyJspApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/WelcomeController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/WelcomeController.java new file mode 100644 index 0000000000..4a4346c990 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/java/smoketest/jetty/jsp/WelcomeController.java @@ -0,0 +1,59 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty.jsp; + +import java.util.Date; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +@Controller +public class WelcomeController { + + @Value("${application.message:Hello World}") + private String message = "Hello World"; + + @RequestMapping("/") + public String welcome(Map<String, Object> model) { + model.put("time", new Date()); + model.put("message", this.message); + return "welcome"; + } + + @RequestMapping("/fail") + public String fail() { + throw new MyException("Oh dear!"); + } + + @RequestMapping("/fail2") + public String fail2() { + throw new IllegalStateException(); + } + + @ExceptionHandler(MyException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public @ResponseBody MyRestResponse handleMyRuntimeException(MyException exception) { + return new MyRestResponse("Some data I want to send back to the client."); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/webapp/WEB-INF/jsp/welcome.jsp b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/webapp/WEB-INF/jsp/welcome.jsp similarity index 100% rename from spring-boot-samples/spring-boot-sample-jetty-jsp/src/main/webapp/WEB-INF/jsp/welcome.jsp rename to spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/main/webapp/WEB-INF/jsp/welcome.jsp diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/test/java/smoketest/jetty/jsp/SampleWebJspApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/test/java/smoketest/jetty/jsp/SampleWebJspApplicationTests.java new file mode 100644 index 0000000000..0efc6f4bfa --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-jsp/src/test/java/smoketest/jetty/jsp/SampleWebJspApplicationTests.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty.jsp; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for JSP application. + * + * @author Phillip Webb + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebJspApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testJspWithEl() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("/resources/text.txt"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/pom.xml new file mode 100644 index 0000000000..a71d19dbec --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/pom.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-jetty-ssl</artifactId> + <name>Spring Boot Jetty SSL Smoke Test</name> + <description>Spring Boot Jetty SSL Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <servlet-api.version>3.1.0</servlet-api.version> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jetty</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/main/java/smoketest/jetty/ssl/SampleJettySslApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/main/java/smoketest/jetty/ssl/SampleJettySslApplication.java new file mode 100644 index 0000000000..f3f6e664b8 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/main/java/smoketest/jetty/ssl/SampleJettySslApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty.ssl; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleJettySslApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleJettySslApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/main/java/smoketest/jetty/ssl/web/SampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/main/java/smoketest/jetty/ssl/web/SampleController.java new file mode 100644 index 0000000000..58389870fd --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/main/java/smoketest/jetty/ssl/web/SampleController.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty.ssl.web; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class SampleController { + + @GetMapping("/") + public String helloWorld() { + return "Hello World"; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/resources/sample.jks b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/main/resources/sample.jks similarity index 100% rename from spring-boot-samples/spring-boot-sample-jetty-ssl/src/main/resources/sample.jks rename to spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/main/resources/sample.jks diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/test/java/smoketest/jetty/ssl/SampleJettySslApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/test/java/smoketest/jetty/ssl/SampleJettySslApplicationTests.java new file mode 100644 index 0000000000..983c6cd24c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty-ssl/src/test/java/smoketest/jetty/ssl/SampleJettySslApplicationTests.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty.ssl; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleJettySslApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Autowired + private AbstractConfigurableWebServerFactory webServerFactory; + + @Test + void testSsl() { + assertThat(this.webServerFactory.getSsl().isEnabled()).isTrue(); + } + + @Test + void testHome() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/pom.xml new file mode 100644 index 0000000000..ccdfb1d8b4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/pom.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-jetty</artifactId> + <name>Spring Boot Jetty Smoke Test</name> + <description>Spring Boot Jetty Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <servlet-api.version>3.1.0</servlet-api.version> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jetty</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/ExampleServletContextListener.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/ExampleServletContextListener.java new file mode 100644 index 0000000000..4eb8bf7830 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/ExampleServletContextListener.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import org.springframework.stereotype.Component; + +/** + * Simple {@link ServletContextListener} to test gh-2058. + */ +@Component +public class ExampleServletContextListener implements ServletContextListener { + + @Override + public void contextInitialized(ServletContextEvent sce) { + System.out.println("*** contextInitialized"); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + System.out.println("*** contextDestroyed"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/SampleJettyApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/SampleJettyApplication.java new file mode 100644 index 0000000000..c1e164eb35 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/SampleJettyApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleJettyApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleJettyApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/service/HelloWorldService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/service/HelloWorldService.java new file mode 100644 index 0000000000..d74455b18f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/service/HelloWorldService.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class HelloWorldService { + + @Value("${name:World}") + private String name; + + public String getHelloMessage() { + return "Hello " + this.name; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/web/SampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/web/SampleController.java new file mode 100644 index 0000000000..ac3973ae77 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/java/smoketest/jetty/web/SampleController.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty.web; + +import smoketest.jetty.service.HelloWorldService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class SampleController { + + @Autowired + private HelloWorldService helloWorldService; + + @GetMapping("/") + @ResponseBody + public String helloWorld() { + return this.helloWorldService.getHelloMessage(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jetty/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-jetty/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/test/java/smoketest/jetty/SampleJettyApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/test/java/smoketest/jetty/SampleJettyApplicationTests.java new file mode 100644 index 0000000000..049beca8bc --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jetty/src/test/java/smoketest/jetty/SampleJettyApplicationTests.java @@ -0,0 +1,69 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jetty; + +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.util.zip.GZIPInputStream; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.util.StreamUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + * @author Andy Wilkinson + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleJettyApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHome() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); + } + + @Test + void testCompression() throws Exception { + HttpHeaders requestHeaders = new HttpHeaders(); + requestHeaders.set("Accept-Encoding", "gzip"); + HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders); + ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + try (GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()))) { + assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)).isEqualTo("Hello World"); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Author.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Author.java new file mode 100644 index 0000000000..097ad5111e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Author.java @@ -0,0 +1,157 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This class is generated by jOOQ + */ +package smoketest.jooq.domain; + +import java.sql.Date; +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Generated; + +import org.jooq.Field; +import org.jooq.Record; +import org.jooq.Schema; +import org.jooq.Table; +import org.jooq.TableField; +import org.jooq.UniqueKey; +import org.jooq.impl.TableImpl; + +/** + * This class is generated by jOOQ. + */ +@Generated(value = { "https://www.jooq.org", + "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class Author extends TableImpl<Record> { + + private static final long serialVersionUID = 1187406915; + + /** + * The reference instance of <code>PUBLIC.AUTHOR</code> + */ + public static final Author AUTHOR = new Author(); + + /** + * The class holding records for this type + */ + @Override + public Class<Record> getRecordType() { + return Record.class; + } + + /** + * The column <code>PUBLIC.AUTHOR.ID</code>. + */ + public final TableField<Record, Integer> ID = createField("ID", + org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + + /** + * The column <code>PUBLIC.AUTHOR.FIRST_NAME</code>. + */ + public final TableField<Record, String> FIRST_NAME = createField("FIRST_NAME", + org.jooq.impl.SQLDataType.VARCHAR.length(50), this, ""); + + /** + * The column <code>PUBLIC.AUTHOR.LAST_NAME</code>. + */ + public final TableField<Record, String> LAST_NAME = createField("LAST_NAME", + org.jooq.impl.SQLDataType.VARCHAR.length(50).nullable(false), this, ""); + + /** + * The column <code>PUBLIC.AUTHOR.DATE_OF_BIRTH</code>. + */ + public final TableField<Record, Date> DATE_OF_BIRTH = createField("DATE_OF_BIRTH", + org.jooq.impl.SQLDataType.DATE, this, ""); + + /** + * The column <code>PUBLIC.AUTHOR.YEAR_OF_BIRTH</code>. + */ + public final TableField<Record, Integer> YEAR_OF_BIRTH = createField("YEAR_OF_BIRTH", + org.jooq.impl.SQLDataType.INTEGER, this, ""); + + /** + * The column <code>PUBLIC.AUTHOR.DISTINGUISHED</code>. + */ + public final TableField<Record, Byte> DISTINGUISHED = createField("DISTINGUISHED", + org.jooq.impl.SQLDataType.TINYINT, this, ""); + + /** + * Create a <code>PUBLIC.AUTHOR</code> table reference + */ + public Author() { + this("AUTHOR", null); + } + + /** + * Create an aliased <code>PUBLIC.AUTHOR</code> table reference + */ + public Author(String alias) { + this(alias, AUTHOR); + } + + private Author(String alias, Table<Record> aliased) { + this(alias, aliased, null); + } + + private Author(String alias, Table<Record> aliased, Field<?>[] parameters) { + super(alias, null, aliased, parameters, ""); + } + + /** + * {@inheritDoc} + */ + @Override + public Schema getSchema() { + return Public.PUBLIC; + } + + /** + * {@inheritDoc} + */ + @Override + public UniqueKey<Record> getPrimaryKey() { + return Keys.CONSTRAINT_7; + } + + /** + * {@inheritDoc} + */ + @Override + public List<UniqueKey<Record>> getKeys() { + return Arrays.<UniqueKey<Record>>asList(Keys.CONSTRAINT_7); + } + + /** + * {@inheritDoc} + */ + @Override + public Author as(String alias) { + return new Author(alias, this); + } + + /** + * Rename this table + */ + @Override + public Author rename(String name) { + return new Author(name, null); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Book.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Book.java new file mode 100644 index 0000000000..4fb961ec94 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Book.java @@ -0,0 +1,160 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This class is generated by jOOQ + */ +package smoketest.jooq.domain; + +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Generated; + +import org.jooq.Field; +import org.jooq.ForeignKey; +import org.jooq.Record; +import org.jooq.Schema; +import org.jooq.Table; +import org.jooq.TableField; +import org.jooq.UniqueKey; +import org.jooq.impl.TableImpl; + +/** + * This class is generated by jOOQ. + */ +@Generated(value = { "https://www.jooq.org", + "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class Book extends TableImpl<Record> { + + private static final long serialVersionUID = 1176189796; + + /** + * The reference instance of <code>PUBLIC.BOOK</code> + */ + public static final Book BOOK = new Book(); + + /** + * The class holding records for this type + */ + @Override + public Class<Record> getRecordType() { + return Record.class; + } + + /** + * The column <code>PUBLIC.BOOK.ID</code>. + */ + public final TableField<Record, Integer> ID = createField("ID", + org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + + /** + * The column <code>PUBLIC.BOOK.AUTHOR_ID</code>. + */ + public final TableField<Record, Integer> AUTHOR_ID = createField("AUTHOR_ID", + org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + + /** + * The column <code>PUBLIC.BOOK.TITLE</code>. + */ + public final TableField<Record, String> TITLE = createField("TITLE", + org.jooq.impl.SQLDataType.VARCHAR.length(400).nullable(false), this, ""); + + /** + * The column <code>PUBLIC.BOOK.PUBLISHED_IN</code>. + */ + public final TableField<Record, Integer> PUBLISHED_IN = createField("PUBLISHED_IN", + org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + + /** + * The column <code>PUBLIC.BOOK.LANGUAGE_ID</code>. + */ + public final TableField<Record, Integer> LANGUAGE_ID = createField("LANGUAGE_ID", + org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + + /** + * Create a <code>PUBLIC.BOOK</code> table reference + */ + public Book() { + this("BOOK", null); + } + + /** + * Create an aliased <code>PUBLIC.BOOK</code> table reference + */ + public Book(String alias) { + this(alias, BOOK); + } + + private Book(String alias, Table<Record> aliased) { + this(alias, aliased, null); + } + + private Book(String alias, Table<Record> aliased, Field<?>[] parameters) { + super(alias, null, aliased, parameters, ""); + } + + /** + * {@inheritDoc} + */ + @Override + public Schema getSchema() { + return Public.PUBLIC; + } + + /** + * {@inheritDoc} + */ + @Override + public UniqueKey<Record> getPrimaryKey() { + return Keys.CONSTRAINT_1; + } + + /** + * {@inheritDoc} + */ + @Override + public List<UniqueKey<Record>> getKeys() { + return Arrays.<UniqueKey<Record>>asList(Keys.CONSTRAINT_1); + } + + /** + * {@inheritDoc} + */ + @Override + public List<ForeignKey<Record, ?>> getReferences() { + return Arrays.<ForeignKey<Record, ?>>asList(Keys.FK_BOOK_AUTHOR, + Keys.FK_BOOK_LANGUAGE); + } + + /** + * {@inheritDoc} + */ + @Override + public Book as(String alias) { + return new Book(alias, this); + } + + /** + * Rename this table + */ + @Override + public Book rename(String name) { + return new Book(name, null); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/BookStore.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/BookStore.java new file mode 100644 index 0000000000..e630d62afe --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/BookStore.java @@ -0,0 +1,118 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This class is generated by jOOQ + */ +package smoketest.jooq.domain; + +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Generated; + +import org.jooq.Field; +import org.jooq.Record; +import org.jooq.Schema; +import org.jooq.Table; +import org.jooq.TableField; +import org.jooq.UniqueKey; +import org.jooq.impl.TableImpl; + +/** + * This class is generated by jOOQ. + */ +@Generated(value = { "https://www.jooq.org", + "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class BookStore extends TableImpl<Record> { + + private static final long serialVersionUID = -2132596210; + + /** + * The reference instance of <code>PUBLIC.BOOK_STORE</code> + */ + public static final BookStore BOOK_STORE = new BookStore(); + + /** + * The class holding records for this type + */ + @Override + public Class<Record> getRecordType() { + return Record.class; + } + + /** + * The column <code>PUBLIC.BOOK_STORE.NAME</code>. + */ + public final TableField<Record, String> NAME = createField("NAME", + org.jooq.impl.SQLDataType.VARCHAR.length(400).nullable(false), this, ""); + + /** + * Create a <code>PUBLIC.BOOK_STORE</code> table reference + */ + public BookStore() { + this("BOOK_STORE", null); + } + + /** + * Create an aliased <code>PUBLIC.BOOK_STORE</code> table reference + */ + public BookStore(String alias) { + this(alias, BOOK_STORE); + } + + private BookStore(String alias, Table<Record> aliased) { + this(alias, aliased, null); + } + + private BookStore(String alias, Table<Record> aliased, Field<?>[] parameters) { + super(alias, null, aliased, parameters, ""); + } + + /** + * {@inheritDoc} + */ + @Override + public Schema getSchema() { + return Public.PUBLIC; + } + + /** + * {@inheritDoc} + */ + @Override + public List<UniqueKey<Record>> getKeys() { + return Arrays.<UniqueKey<Record>>asList(Keys.CONSTRAINT_F); + } + + /** + * {@inheritDoc} + */ + @Override + public BookStore as(String alias) { + return new BookStore(alias, this); + } + + /** + * Rename this table + */ + @Override + public BookStore rename(String name) { + return new BookStore(name, null); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/BookToBookStore.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/BookToBookStore.java new file mode 100644 index 0000000000..7d56268f97 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/BookToBookStore.java @@ -0,0 +1,148 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This class is generated by jOOQ + */ +package smoketest.jooq.domain; + +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Generated; + +import org.jooq.Field; +import org.jooq.ForeignKey; +import org.jooq.Record; +import org.jooq.Schema; +import org.jooq.Table; +import org.jooq.TableField; +import org.jooq.UniqueKey; +import org.jooq.impl.TableImpl; + +/** + * This class is generated by jOOQ. + */ +@Generated(value = { "https://www.jooq.org", + "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class BookToBookStore extends TableImpl<Record> { + + private static final long serialVersionUID = -1360744633; + + /** + * The reference instance of <code>PUBLIC.BOOK_TO_BOOK_STORE</code> + */ + public static final BookToBookStore BOOK_TO_BOOK_STORE = new BookToBookStore(); + + /** + * The class holding records for this type + */ + @Override + public Class<Record> getRecordType() { + return Record.class; + } + + /** + * The column <code>PUBLIC.BOOK_TO_BOOK_STORE.NAME</code>. + */ + public final TableField<Record, String> NAME = createField("NAME", + org.jooq.impl.SQLDataType.VARCHAR.length(400).nullable(false), this, ""); + + /** + * The column <code>PUBLIC.BOOK_TO_BOOK_STORE.BOOK_ID</code>. + */ + public final TableField<Record, Integer> BOOK_ID = createField("BOOK_ID", + org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + + /** + * The column <code>PUBLIC.BOOK_TO_BOOK_STORE.STOCK</code>. + */ + public final TableField<Record, Integer> STOCK = createField("STOCK", + org.jooq.impl.SQLDataType.INTEGER, this, ""); + + /** + * Create a <code>PUBLIC.BOOK_TO_BOOK_STORE</code> table reference + */ + public BookToBookStore() { + this("BOOK_TO_BOOK_STORE", null); + } + + /** + * Create an aliased <code>PUBLIC.BOOK_TO_BOOK_STORE</code> table reference + */ + public BookToBookStore(String alias) { + this(alias, BOOK_TO_BOOK_STORE); + } + + private BookToBookStore(String alias, Table<Record> aliased) { + this(alias, aliased, null); + } + + private BookToBookStore(String alias, Table<Record> aliased, Field<?>[] parameters) { + super(alias, null, aliased, parameters, ""); + } + + /** + * {@inheritDoc} + */ + @Override + public Schema getSchema() { + return Public.PUBLIC; + } + + /** + * {@inheritDoc} + */ + @Override + public UniqueKey<Record> getPrimaryKey() { + return Keys.CONSTRAINT_2; + } + + /** + * {@inheritDoc} + */ + @Override + public List<UniqueKey<Record>> getKeys() { + return Arrays.<UniqueKey<Record>>asList(Keys.CONSTRAINT_2); + } + + /** + * {@inheritDoc} + */ + @Override + public List<ForeignKey<Record, ?>> getReferences() { + return Arrays.<ForeignKey<Record, ?>>asList(Keys.FK_B2BS_BOOK_STORE, + Keys.FK_B2BS_BOOK); + } + + /** + * {@inheritDoc} + */ + @Override + public BookToBookStore as(String alias) { + return new BookToBookStore(alias, this); + } + + /** + * Rename this table + */ + @Override + public BookToBookStore rename(String name) { + return new BookToBookStore(name, null); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/DefaultCatalog.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/DefaultCatalog.java new file mode 100644 index 0000000000..5596bcb1ad --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/DefaultCatalog.java @@ -0,0 +1,69 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This class is generated by jOOQ + */ +package smoketest.jooq.domain; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Generated; + +import org.jooq.Schema; +import org.jooq.impl.CatalogImpl; + +/** + * This class is generated by jOOQ. + */ +@Generated(value = { "https://www.jooq.org", + "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class DefaultCatalog extends CatalogImpl { + + private static final long serialVersionUID = -1557925562; + + /** + * The reference instance of <code></code> + */ + public static final DefaultCatalog DEFAULT_CATALOG = new DefaultCatalog(); + + /** + * The schema <code>PUBLIC</code>. + */ + public final Public PUBLIC = Public.PUBLIC; + + /** + * No further instances allowed + */ + private DefaultCatalog() { + super(""); + } + + @Override + public final List<Schema> getSchemas() { + List result = new ArrayList(); + result.addAll(getSchemas0()); + return result; + } + + private final List<Schema> getSchemas0() { + return Arrays.<Schema>asList(Public.PUBLIC); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Keys.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Keys.java new file mode 100644 index 0000000000..c4fe748741 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Keys.java @@ -0,0 +1,113 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This class is generated by jOOQ + */ +package smoketest.jooq.domain; + +import javax.annotation.Generated; + +import org.jooq.ForeignKey; +import org.jooq.Record; +import org.jooq.UniqueKey; +import org.jooq.impl.AbstractKeys; + +/** + * A class modelling foreign key relationships between tables of the <code>PUBLIC</code> + * schema + */ +@Generated(value = { "https://www.jooq.org", + "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class Keys { + + // ------------------------------------------------------------------------- + // IDENTITY definitions + // ------------------------------------------------------------------------- + + // ------------------------------------------------------------------------- + // UNIQUE and PRIMARY KEY definitions + // ------------------------------------------------------------------------- + + public static final UniqueKey<Record> CONSTRAINT_C = UniqueKeys0.CONSTRAINT_C; + + public static final UniqueKey<Record> CONSTRAINT_7 = UniqueKeys0.CONSTRAINT_7; + + public static final UniqueKey<Record> CONSTRAINT_1 = UniqueKeys0.CONSTRAINT_1; + + public static final UniqueKey<Record> CONSTRAINT_F = UniqueKeys0.CONSTRAINT_F; + + public static final UniqueKey<Record> CONSTRAINT_2 = UniqueKeys0.CONSTRAINT_2; + + // ------------------------------------------------------------------------- + // FOREIGN KEY definitions + // ------------------------------------------------------------------------- + + public static final ForeignKey<Record, Record> FK_BOOK_AUTHOR = ForeignKeys0.FK_BOOK_AUTHOR; + + public static final ForeignKey<Record, Record> FK_BOOK_LANGUAGE = ForeignKeys0.FK_BOOK_LANGUAGE; + + public static final ForeignKey<Record, Record> FK_B2BS_BOOK_STORE = ForeignKeys0.FK_B2BS_BOOK_STORE; + + public static final ForeignKey<Record, Record> FK_B2BS_BOOK = ForeignKeys0.FK_B2BS_BOOK; + + // ------------------------------------------------------------------------- + // [#1459] distribute members to avoid static initialisers > 64kb + // ------------------------------------------------------------------------- + + private static class UniqueKeys0 extends AbstractKeys { + + public static final UniqueKey<Record> CONSTRAINT_C = createUniqueKey( + Language.LANGUAGE, "CONSTRAINT_C", Language.LANGUAGE.ID); + + public static final UniqueKey<Record> CONSTRAINT_7 = createUniqueKey( + Author.AUTHOR, "CONSTRAINT_7", Author.AUTHOR.ID); + + public static final UniqueKey<Record> CONSTRAINT_1 = createUniqueKey(Book.BOOK, + "CONSTRAINT_1", Book.BOOK.ID); + + public static final UniqueKey<Record> CONSTRAINT_F = createUniqueKey( + BookStore.BOOK_STORE, "CONSTRAINT_F", BookStore.BOOK_STORE.NAME); + + public static final UniqueKey<Record> CONSTRAINT_2 = createUniqueKey( + BookToBookStore.BOOK_TO_BOOK_STORE, "CONSTRAINT_2", + BookToBookStore.BOOK_TO_BOOK_STORE.NAME, + BookToBookStore.BOOK_TO_BOOK_STORE.BOOK_ID); + + } + + private static class ForeignKeys0 extends AbstractKeys { + + public static final ForeignKey<Record, Record> FK_BOOK_AUTHOR = createForeignKey( + Keys.CONSTRAINT_7, Book.BOOK, "FK_BOOK_AUTHOR", + Book.BOOK.AUTHOR_ID); + + public static final ForeignKey<Record, Record> FK_BOOK_LANGUAGE = createForeignKey( + Keys.CONSTRAINT_C, Book.BOOK, "FK_BOOK_LANGUAGE", + Book.BOOK.LANGUAGE_ID); + + public static final ForeignKey<Record, Record> FK_B2BS_BOOK_STORE = createForeignKey( + Keys.CONSTRAINT_F, BookToBookStore.BOOK_TO_BOOK_STORE, + "FK_B2BS_BOOK_STORE", BookToBookStore.BOOK_TO_BOOK_STORE.NAME); + + public static final ForeignKey<Record, Record> FK_B2BS_BOOK = createForeignKey( + Keys.CONSTRAINT_1, BookToBookStore.BOOK_TO_BOOK_STORE, + "FK_B2BS_BOOK", BookToBookStore.BOOK_TO_BOOK_STORE.BOOK_ID); + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Language.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Language.java new file mode 100644 index 0000000000..b6cd7522b4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Language.java @@ -0,0 +1,138 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This class is generated by jOOQ + */ +package smoketest.jooq.domain; + +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Generated; + +import org.jooq.Field; +import org.jooq.Record; +import org.jooq.Schema; +import org.jooq.Table; +import org.jooq.TableField; +import org.jooq.UniqueKey; +import org.jooq.impl.TableImpl; + +/** + * This class is generated by jOOQ. + */ +@Generated(value = { "https://www.jooq.org", + "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class Language extends TableImpl<Record> { + + private static final long serialVersionUID = -1890716744; + + /** + * The reference instance of <code>PUBLIC.LANGUAGE</code> + */ + public static final Language LANGUAGE = new Language(); + + /** + * The class holding records for this type + */ + @Override + public Class<Record> getRecordType() { + return Record.class; + } + + /** + * The column <code>PUBLIC.LANGUAGE.ID</code>. + */ + public final TableField<Record, Integer> ID = createField("ID", + org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + + /** + * The column <code>PUBLIC.LANGUAGE.CD</code>. + */ + public final TableField<Record, String> CD = createField("CD", + org.jooq.impl.SQLDataType.CHAR.length(2).nullable(false), this, ""); + + /** + * The column <code>PUBLIC.LANGUAGE.DESCRIPTION</code>. + */ + public final TableField<Record, String> DESCRIPTION = createField("DESCRIPTION", + org.jooq.impl.SQLDataType.VARCHAR.length(50), this, ""); + + /** + * Create a <code>PUBLIC.LANGUAGE</code> table reference + */ + public Language() { + this("LANGUAGE", null); + } + + /** + * Create an aliased <code>PUBLIC.LANGUAGE</code> table reference + */ + public Language(String alias) { + this(alias, LANGUAGE); + } + + private Language(String alias, Table<Record> aliased) { + this(alias, aliased, null); + } + + private Language(String alias, Table<Record> aliased, Field<?>[] parameters) { + super(alias, null, aliased, parameters, ""); + } + + /** + * {@inheritDoc} + */ + @Override + public Schema getSchema() { + return Public.PUBLIC; + } + + /** + * {@inheritDoc} + */ + @Override + public UniqueKey<Record> getPrimaryKey() { + return Keys.CONSTRAINT_C; + } + + /** + * {@inheritDoc} + */ + @Override + public List<UniqueKey<Record>> getKeys() { + return Arrays.<UniqueKey<Record>>asList(Keys.CONSTRAINT_C); + } + + /** + * {@inheritDoc} + */ + @Override + public Language as(String alias) { + return new Language(alias, this); + } + + /** + * Rename this table + */ + @Override + public Language rename(String name) { + return new Language(name, null); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Public.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Public.java new file mode 100644 index 0000000000..225404c00a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Public.java @@ -0,0 +1,99 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This class is generated by jOOQ + */ +package smoketest.jooq.domain; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Generated; + +import org.jooq.Catalog; +import org.jooq.Table; +import org.jooq.impl.SchemaImpl; + +/** + * This class is generated by jOOQ. + */ +@Generated(value = { "https://www.jooq.org", + "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class Public extends SchemaImpl { + + private static final long serialVersionUID = 217498103; + + /** + * The reference instance of <code>PUBLIC</code> + */ + public static final Public PUBLIC = new Public(); + + /** + * The table <code>PUBLIC.LANGUAGE</code>. + */ + public final Language LANGUAGE = Language.LANGUAGE; + + /** + * The table <code>PUBLIC.AUTHOR</code>. + */ + public final Author AUTHOR = Author.AUTHOR; + + /** + * The table <code>PUBLIC.BOOK</code>. + */ + public final Book BOOK = Book.BOOK; + + /** + * The table <code>PUBLIC.BOOK_STORE</code>. + */ + public final BookStore BOOK_STORE = BookStore.BOOK_STORE; + + /** + * The table <code>PUBLIC.BOOK_TO_BOOK_STORE</code>. + */ + public final BookToBookStore BOOK_TO_BOOK_STORE = BookToBookStore.BOOK_TO_BOOK_STORE; + + /** + * No further instances allowed + */ + private Public() { + super("PUBLIC", null); + } + + /** + * {@inheritDoc} + */ + @Override + public Catalog getCatalog() { + return DefaultCatalog.DEFAULT_CATALOG; + } + + @Override + public final List<Table<?>> getTables() { + List result = new ArrayList(); + result.addAll(getTables0()); + return result; + } + + private final List<Table<?>> getTables0() { + return Arrays.<Table<?>>asList(Language.LANGUAGE, Author.AUTHOR, Book.BOOK, + BookStore.BOOK_STORE, BookToBookStore.BOOK_TO_BOOK_STORE); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Tables.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Tables.java new file mode 100644 index 0000000000..a7d25faa7c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/gensrc/main/java/smoketest/jooq/domain/Tables.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This class is generated by jOOQ + */ +package smoketest.jooq.domain; + +import javax.annotation.Generated; + +/** + * Convenience access to all tables in PUBLIC + */ +@Generated(value = { "https://www.jooq.org", + "jOOQ version:3.8.2" }, comments = "This class is generated by jOOQ") +@SuppressWarnings({ "all", "unchecked", "rawtypes" }) +public class Tables { + + /** + * The table <code>PUBLIC.LANGUAGE</code>. + */ + public static final Language LANGUAGE = Language.LANGUAGE; + + /** + * The table <code>PUBLIC.AUTHOR</code>. + */ + public static final Author AUTHOR = Author.AUTHOR; + + /** + * The table <code>PUBLIC.BOOK</code>. + */ + public static final Book BOOK = Book.BOOK; + + /** + * The table <code>PUBLIC.BOOK_STORE</code>. + */ + public static final BookStore BOOK_STORE = BookStore.BOOK_STORE; + + /** + * The table <code>PUBLIC.BOOK_TO_BOOK_STORE</code>. + */ + public static final BookToBookStore BOOK_TO_BOOK_STORE = BookToBookStore.BOOK_TO_BOOK_STORE; + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/pom.xml new file mode 100644 index 0000000000..2fe1b1d72e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/pom.xml @@ -0,0 +1,199 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-jooq</artifactId> + <name>Spring Boot jOOQ Smoke Test</name> + <description>Spring Boot jOOQ Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jooq</artifactId> + </dependency> + <!-- Runtime --> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>runtime</scope> + </dependency> + <!-- Provided --> + <dependency> + <groupId>org.jooq</groupId> + <artifactId>jooq-codegen</artifactId> + <scope>provided</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <phase>generate-sources</phase> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>gensrc/main/java</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + <pluginManagement> + <plugins> + <!--This plugin's configuration is used to store Eclipse m2e settings + only. It has no influence on the Maven build itself. --> + <plugin> + <groupId>org.eclipse.m2e</groupId> + <artifactId>lifecycle-mapping</artifactId> + <version>1.0.0</version> + <configuration> + <lifecycleMappingMetadata> + <pluginExecutions> + <pluginExecution> + <pluginExecutionFilter> + <groupId>org.jooq</groupId> + <artifactId> + jooq-codegen-maven + </artifactId> + <versionRange> + [3.6.2,) + </versionRange> + <goals> + <goal>generate</goal> + </goals> + </pluginExecutionFilter> + <action> + <ignore /> + </action> + </pluginExecution> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> + <profiles> + <profile> + <id>generate</id> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <executions> + <execution> + <id>generate-jooq-utils</id> + <phase>generate-sources</phase> + <goals> + <goal>compile</goal> + </goals> + <inherited>false</inherited> + <configuration> + <includes> + <include>smoketest/jooq/util/**</include> + </includes> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>sql-maven-plugin</artifactId> + <version>1.5</version> + <executions> + <execution> + <phase>generate-sources</phase> + <goals> + <goal>execute</goal> + </goals> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>${h2.version}</version> + </dependency> + </dependencies> + <configuration> + <driver>org.h2.Driver</driver> + <url>jdbc:h2:~/springbootjooq</url> + <srcFiles> + <srcFile>${basedir}/src/main/resources/reset.sql</srcFile> + <srcFile>${basedir}/src/main/resources/schema.sql</srcFile> + </srcFiles> + </configuration> + </plugin> + <plugin> + <groupId>org.jooq</groupId> + <artifactId>jooq-codegen-maven</artifactId> + <executions> + <execution> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>${h2.version}</version> + </dependency> + </dependencies> + <configuration> + <jdbc> + <driver>org.h2.Driver</driver> + <url>jdbc:h2:~/springbootjooq</url> + </jdbc> + <generator> + <name>org.jooq.util.DefaultGenerator</name> + <database> + <name>org.jooq.util.h2.H2Database</name> + <includes>.*</includes> + <excludes /> + <inputSchema>PUBLIC</inputSchema> + </database> + <strategy> + <name>smoketest.jooq.util.TangleFreeGeneratorStrategy</name> + </strategy> + <target> + <packageName>smoketest.jooq.domain</packageName> + <directory>${basedir}/gensrc/main/java</directory> + </target> + <generate> + <records>false</records> + </generate> + </generator> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/java/smoketest/jooq/JooqExamples.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/java/smoketest/jooq/JooqExamples.java new file mode 100644 index 0000000000..3c27309e16 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/java/smoketest/jooq/JooqExamples.java @@ -0,0 +1,77 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jooq; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import org.jooq.DSLContext; +import org.jooq.Query; +import org.jooq.Record; +import org.jooq.Result; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.stereotype.Component; + +import static smoketest.jooq.domain.Author.AUTHOR; +import static smoketest.jooq.domain.Book.BOOK; + +@Component +public class JooqExamples implements CommandLineRunner { + + private final DSLContext dsl; + + private final JdbcTemplate jdbc; + + public JooqExamples(DSLContext dsl, JdbcTemplate jdbc) { + this.dsl = dsl; + this.jdbc = jdbc; + } + + @Override + public void run(String... args) throws Exception { + jooqFetch(); + jooqSql(); + } + + private void jooqFetch() { + Result<Record> results = this.dsl.select().from(AUTHOR).fetch(); + for (Record result : results) { + Integer id = result.getValue(AUTHOR.ID); + String firstName = result.getValue(AUTHOR.FIRST_NAME); + String lastName = result.getValue(AUTHOR.LAST_NAME); + System.out.println("jOOQ Fetch " + id + " " + firstName + " " + lastName); + } + } + + private void jooqSql() { + Query query = this.dsl.select(BOOK.TITLE, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME).from(BOOK).join(AUTHOR) + .on(BOOK.AUTHOR_ID.equal(AUTHOR.ID)).where(BOOK.PUBLISHED_IN.equal(2015)); + Object[] bind = query.getBindValues().toArray(new Object[0]); + List<String> list = this.jdbc.query(query.getSQL(), bind, new RowMapper<String>() { + @Override + public String mapRow(ResultSet rs, int rowNum) throws SQLException { + return rs.getString(1) + " : " + rs.getString(2) + " " + rs.getString(3); + } + }); + System.out.println("jOOQ SQL " + list); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/java/smoketest/jooq/SampleJooqApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/java/smoketest/jooq/SampleJooqApplication.java new file mode 100644 index 0000000000..33770c0589 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/java/smoketest/jooq/SampleJooqApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jooq; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleJooqApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleJooqApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/java/smoketest/jooq/util/TangleFreeGeneratorStrategy.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/java/smoketest/jooq/util/TangleFreeGeneratorStrategy.java new file mode 100644 index 0000000000..6061a87471 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/java/smoketest/jooq/util/TangleFreeGeneratorStrategy.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jooq.util; + +import org.jooq.codegen.DefaultGeneratorStrategy; +import org.jooq.meta.Definition; + +/** + * Custom {@link DefaultGeneratorStrategy} that doesn't produce tangled packages. Too + * simple for general use but solves false flags for our build. + */ +public class TangleFreeGeneratorStrategy extends DefaultGeneratorStrategy { + + @Override + public String getJavaPackageName(Definition definition, Mode mode) { + return getTargetPackage(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jooq/src/main/resources/data.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/resources/data.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-jooq/src/main/resources/data.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/resources/data.sql diff --git a/spring-boot-samples/spring-boot-sample-jooq/src/main/resources/reset.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/resources/reset.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-jooq/src/main/resources/reset.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/resources/reset.sql diff --git a/spring-boot-samples/spring-boot-sample-jooq/src/main/resources/schema.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/resources/schema.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-jooq/src/main/resources/schema.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/main/resources/schema.sql diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/test/java/smoketest/jooq/SampleJooqApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/test/java/smoketest/jooq/SampleJooqApplicationTests.java new file mode 100644 index 0000000000..57f9349979 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jooq/src/test/java/smoketest/jooq/SampleJooqApplicationTests.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jooq; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link SampleJooqApplication}. + */ +@ExtendWith(OutputCaptureExtension.class) +class SampleJooqApplicationTests { + + private static final String[] NO_ARGS = {}; + + @Test + void outputResults(CapturedOutput capturedOutput) { + SampleJooqApplication.main(NO_ARGS); + assertThat(capturedOutput).contains("jOOQ Fetch 1 Greg Turnquest").contains("jOOQ Fetch 2 Craig Walls") + .contains("jOOQ SQL " + "[Learning Spring Boot : Greg Turnquest, " + + "Spring Boot in Action : Craig Walls]"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/pom.xml new file mode 100644 index 0000000000..0da0ed7d6e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/pom.xml @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-jpa</artifactId> + <name>Spring Boot JPA Smoke Test</name> + <description>Spring Boot JPA Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>jakarta.persistence</groupId> + <artifactId>jakarta.persistence-api</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-freemarker</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-orm</artifactId> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + <exclusions> + <exclusion> + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + </exclusion> + <exclusion> + <groupId>javax.persistence</groupId> + <artifactId>javax.persistence-api</artifactId> + </exclusion> + <exclusion> + <groupId>javax.activation</groupId> + <artifactId>javax.activation-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <!-- Runtime --> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>runtime</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>java9+</id> + <activation> + <jdk>[9,)</jdk> + </activation> + <dependencies> + <dependency> + <groupId>jakarta.xml.bind</groupId> + <artifactId>jakarta.xml.bind-api</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/SampleJpaApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/SampleJpaApplication.java new file mode 100644 index 0000000000..e2738bb42b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/SampleJpaApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jpa; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleJpaApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleJpaApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/domain/Note.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/domain/Note.java new file mode 100644 index 0000000000..5ba294fa89 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/domain/Note.java @@ -0,0 +1,74 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jpa.domain; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.SequenceGenerator; + +@Entity +public class Note { + + @Id + @SequenceGenerator(name = "note_generator", sequenceName = "note_sequence", initialValue = 5) + @GeneratedValue(generator = "note_generator") + private long id; + + private String title; + + private String body; + + @ManyToMany + private List<Tag> tags; + + public long getId() { + return this.id; + } + + public void setId(long id) { + this.id = id; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getBody() { + return this.body; + } + + public void setBody(String body) { + this.body = body; + } + + public List<Tag> getTags() { + return this.tags; + } + + public void setTags(List<Tag> tags) { + this.tags = tags; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/domain/Tag.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/domain/Tag.java new file mode 100644 index 0000000000..07008b9052 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/domain/Tag.java @@ -0,0 +1,64 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jpa.domain; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.SequenceGenerator; + +@Entity +public class Tag { + + @Id + @SequenceGenerator(name = "tag_generator", sequenceName = "tag_sequence", initialValue = 4) + @GeneratedValue(generator = "tag_generator") + private long id; + + private String name; + + @ManyToMany(mappedBy = "tags") + private List<Note> notes; + + public long getId() { + return this.id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public List<Note> getNotes() { + return this.notes; + } + + public void setNotes(List<Note> notes) { + this.notes = notes; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/JpaNoteRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/JpaNoteRepository.java new file mode 100644 index 0000000000..b32c84f76b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/JpaNoteRepository.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jpa.repository; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import smoketest.jpa.domain.Note; + +import org.springframework.stereotype.Repository; + +@Repository +class JpaNoteRepository implements NoteRepository { + + @PersistenceContext + private EntityManager entityManager; + + @Override + public List<Note> findAll() { + return this.entityManager.createQuery("SELECT n FROM Note n", Note.class).getResultList(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/JpaTagRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/JpaTagRepository.java new file mode 100644 index 0000000000..a8e804a5ff --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/JpaTagRepository.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jpa.repository; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import smoketest.jpa.domain.Tag; + +import org.springframework.stereotype.Repository; + +@Repository +class JpaTagRepository implements TagRepository { + + @PersistenceContext + private EntityManager entityManager; + + @Override + public List<Tag> findAll() { + return this.entityManager.createQuery("SELECT t FROM Tag t", Tag.class).getResultList(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/NoteRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/NoteRepository.java new file mode 100644 index 0000000000..a2cf62c21b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/NoteRepository.java @@ -0,0 +1,27 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jpa.repository; + +import java.util.List; + +import smoketest.jpa.domain.Note; + +public interface NoteRepository { + + List<Note> findAll(); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/TagRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/TagRepository.java new file mode 100644 index 0000000000..03b27e4f6f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/repository/TagRepository.java @@ -0,0 +1,27 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jpa.repository; + +import java.util.List; + +import smoketest.jpa.domain.Tag; + +public interface TagRepository { + + List<Tag> findAll(); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/web/IndexController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/web/IndexController.java new file mode 100644 index 0000000000..cfca186d45 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/java/smoketest/jpa/web/IndexController.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jpa.web; + +import java.util.List; + +import smoketest.jpa.domain.Note; +import smoketest.jpa.repository.NoteRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.servlet.ModelAndView; + +@Controller +public class IndexController { + + @Autowired + private NoteRepository noteRepository; + + @GetMapping("/") + @Transactional(readOnly = true) + public ModelAndView index() { + List<Note> notes = this.noteRepository.findAll(); + ModelAndView modelAndView = new ModelAndView("index"); + modelAndView.addObject("notes", notes); + return modelAndView; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-jpa/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/resources/import.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/resources/import.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-jpa/src/main/resources/import.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/resources/import.sql diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/resources/templates/index.ftlh b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/resources/templates/index.ftlh similarity index 100% rename from spring-boot-samples/spring-boot-sample-jpa/src/main/resources/templates/index.ftlh rename to spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/main/resources/templates/index.ftlh diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/test/java/smoketest/jpa/SampleJpaApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/test/java/smoketest/jpa/SampleJpaApplicationTests.java new file mode 100644 index 0000000000..dac16490b1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/test/java/smoketest/jpa/SampleJpaApplicationTests.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jpa; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.xpath; + +/** + * Integration test to run the application. + * + * @author Oliver Gierke + * @author Dave Syer + */ +@SpringBootTest +@WebAppConfiguration +class SampleJpaApplicationTests { + + @Autowired + private WebApplicationContext context; + + private MockMvc mvc; + + @BeforeEach + void setUp() { + this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); + } + + @Test + void testHome() throws Exception { + this.mvc.perform(get("/")).andExpect(status().isOk()).andExpect(xpath("//tbody/tr").nodeCount(4)); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/test/java/smoketest/jpa/repository/JpaNoteRepositoryIntegrationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/test/java/smoketest/jpa/repository/JpaNoteRepositoryIntegrationTests.java new file mode 100644 index 0000000000..46186b4826 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/test/java/smoketest/jpa/repository/JpaNoteRepositoryIntegrationTests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package smoketest.jpa.repository; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import smoketest.jpa.domain.Note; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link JpaNoteRepository}. + * + * @author Andy Wilkinson + */ +@SpringBootTest +@Transactional +class JpaNoteRepositoryIntegrationTests { + + @Autowired + JpaNoteRepository repository; + + @Test + void findsAllNotes() { + List<Note> notes = this.repository.findAll(); + assertThat(notes).hasSize(4); + for (Note note : notes) { + assertThat(note.getTags().size()).isGreaterThan(0); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/test/java/smoketest/jpa/repository/JpaTagRepositoryIntegrationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/test/java/smoketest/jpa/repository/JpaTagRepositoryIntegrationTests.java new file mode 100644 index 0000000000..24fdf3013f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jpa/src/test/java/smoketest/jpa/repository/JpaTagRepositoryIntegrationTests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package smoketest.jpa.repository; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import smoketest.jpa.domain.Tag; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.transaction.annotation.Transactional; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link JpaTagRepository}. + * + * @author Andy Wilkinson + */ +@SpringBootTest +@Transactional +class JpaTagRepositoryIntegrationTests { + + @Autowired + JpaTagRepository repository; + + @Test + void findsAllTags() { + List<Tag> tags = this.repository.findAll(); + assertThat(tags).hasSize(3); + for (Tag tag : tags) { + assertThat(tag.getNotes().size()).isGreaterThan(0); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/pom.xml new file mode 100644 index 0000000000..cd42b7b126 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/pom.xml @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-jta-atomikos</artifactId> + <name>Spring Boot Atomikos JTA Smoke Test</name> + <description>Spring Boot Atomikos JTA Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jms</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jta-atomikos</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-artemis</artifactId> + </dependency> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-server</artifactId> + <exclusions> + <exclusion> + <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.geronimo.specs</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>java9+</id> + <activation> + <jdk>[9,)</jdk> + </activation> + <dependencies> + <dependency> + <groupId>jakarta.xml.bind</groupId> + <artifactId>jakarta.xml.bind-api</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/Account.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/Account.java new file mode 100644 index 0000000000..c73d1cfd1e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/Account.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.atomikos; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Account { + + @Id + @GeneratedValue + private Long id; + + private String username; + + Account() { + } + + public Account(String username) { + this.username = username; + } + + public String getUsername() { + return this.username; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/AccountRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/AccountRepository.java new file mode 100644 index 0000000000..99aed1784f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/AccountRepository.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.atomikos; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AccountRepository extends JpaRepository<Account, Long> { + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/AccountService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/AccountService.java new file mode 100644 index 0000000000..7a0deade0f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/AccountService.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.atomikos; + +import javax.transaction.Transactional; + +import org.springframework.jms.core.JmsTemplate; +import org.springframework.stereotype.Service; + +@Service +@Transactional +public class AccountService { + + private final JmsTemplate jmsTemplate; + + private final AccountRepository accountRepository; + + public AccountService(JmsTemplate jmsTemplate, AccountRepository accountRepository) { + this.jmsTemplate = jmsTemplate; + this.accountRepository = accountRepository; + } + + public void createAccountAndNotify(String username) { + this.jmsTemplate.convertAndSend("accounts", username); + this.accountRepository.save(new Account(username)); + if ("error".equals(username)) { + throw new RuntimeException("Simulated error"); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/Messages.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/Messages.java new file mode 100644 index 0000000000..1f0c90ad9c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/Messages.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.atomikos; + +import org.springframework.jms.annotation.JmsListener; +import org.springframework.stereotype.Component; + +@Component +public class Messages { + + @JmsListener(destination = "accounts") + public void onMessage(String content) { + System.out.println("----> " + content); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/SampleAtomikosApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/SampleAtomikosApplication.java new file mode 100644 index 0000000000..c1bc65e29a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/java/smoketest/atomikos/SampleAtomikosApplication.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.atomikos; + +import java.io.Closeable; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; + +@SpringBootApplication +public class SampleAtomikosApplication { + + public static void main(String[] args) throws Exception { + ApplicationContext context = SpringApplication.run(SampleAtomikosApplication.class, args); + AccountService service = context.getBean(AccountService.class); + AccountRepository repository = context.getBean(AccountRepository.class); + service.createAccountAndNotify("josh"); + System.out.println("Count is " + repository.count()); + try { + service.createAccountAndNotify("error"); + } + catch (Exception ex) { + System.out.println(ex.getMessage()); + } + System.out.println("Count is " + repository.count()); + Thread.sleep(100); + ((Closeable) context).close(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/test/java/smoketest/atomikos/SampleAtomikosApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/test/java/smoketest/atomikos/SampleAtomikosApplicationTests.java new file mode 100644 index 0000000000..e96fc69c84 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-atomikos/src/test/java/smoketest/atomikos/SampleAtomikosApplicationTests.java @@ -0,0 +1,60 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.atomikos; + +import org.assertj.core.api.Condition; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Phillip Webb + */ +@ExtendWith(OutputCaptureExtension.class) +class SampleAtomikosApplicationTests { + + @Test + void testTransactionRollback(CapturedOutput capturedOutput) throws Exception { + SampleAtomikosApplication.main(new String[] {}); + assertThat(capturedOutput.toString()).has(substring(1, "---->")).has(substring(1, "----> josh")) + .has(substring(2, "Count is 1")).has(substring(1, "Simulated error")); + } + + private Condition<String> substring(int times, String substring) { + return new Condition<String>("containing '" + substring + "' " + times + " times") { + + @Override + public boolean matches(String value) { + int i = 0; + while (value.contains(substring)) { + int beginIndex = value.indexOf(substring) + substring.length(); + value = value.substring(beginIndex); + i++; + } + return i == times; + } + + }; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/pom.xml new file mode 100644 index 0000000000..40f5ba77c1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/pom.xml @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-jta-bitronix</artifactId> + <name>Spring Boot Bitronix JTA Smoke Test</name> + <description>Spring Boot Bitronix JTA Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jms</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jta-bitronix</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-artemis</artifactId> + </dependency> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>artemis-jms-server</artifactId> + <exclusions> + <exclusion> + <artifactId>geronimo-jms_2.0_spec</artifactId> + <groupId>org.apache.geronimo.specs</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>java9+</id> + <activation> + <jdk>[9,)</jdk> + </activation> + <dependencies> + <dependency> + <groupId>jakarta.xml.bind</groupId> + <artifactId>jakarta.xml.bind-api</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/Account.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/Account.java new file mode 100644 index 0000000000..548e56370e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/Account.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.bitronix; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Account { + + @Id + @GeneratedValue + private Long id; + + private String username; + + Account() { + } + + public Account(String username) { + this.username = username; + } + + public String getUsername() { + return this.username; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/AccountRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/AccountRepository.java new file mode 100644 index 0000000000..f844533290 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/AccountRepository.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.bitronix; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AccountRepository extends JpaRepository<Account, Long> { + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/AccountService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/AccountService.java new file mode 100644 index 0000000000..e3ef379b42 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/AccountService.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.bitronix; + +import javax.transaction.Transactional; + +import org.springframework.jms.core.JmsTemplate; +import org.springframework.stereotype.Service; + +@Service +@Transactional +public class AccountService { + + private final JmsTemplate jmsTemplate; + + private final AccountRepository accountRepository; + + public AccountService(JmsTemplate jmsTemplate, AccountRepository accountRepository) { + this.jmsTemplate = jmsTemplate; + this.accountRepository = accountRepository; + } + + public void createAccountAndNotify(String username) { + this.jmsTemplate.convertAndSend("accounts", username); + this.accountRepository.save(new Account(username)); + if ("error".equals(username)) { + throw new RuntimeException("Simulated error"); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/Messages.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/Messages.java new file mode 100644 index 0000000000..edb9877dbb --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/Messages.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.bitronix; + +import org.springframework.jms.annotation.JmsListener; +import org.springframework.stereotype.Component; + +@Component +public class Messages { + + @JmsListener(destination = "accounts") + public void onMessage(String content) { + System.out.println("----> " + content); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/SampleBitronixApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/SampleBitronixApplication.java new file mode 100644 index 0000000000..3d3652e372 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/java/smoketest/bitronix/SampleBitronixApplication.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.bitronix; + +import java.io.Closeable; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; + +@SpringBootApplication +public class SampleBitronixApplication { + + public static void main(String[] args) throws Exception { + ApplicationContext context = SpringApplication.run(SampleBitronixApplication.class, args); + AccountService service = context.getBean(AccountService.class); + AccountRepository repository = context.getBean(AccountRepository.class); + service.createAccountAndNotify("josh"); + System.out.println("Count is " + repository.count()); + try { + service.createAccountAndNotify("error"); + } + catch (Exception ex) { + System.out.println(ex.getMessage()); + } + System.out.println("Count is " + repository.count()); + Thread.sleep(100); + ((Closeable) context).close(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/test/java/smoketest/bitronix/SampleBitronixApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/test/java/smoketest/bitronix/SampleBitronixApplicationTests.java new file mode 100644 index 0000000000..5930838b21 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-bitronix/src/test/java/smoketest/bitronix/SampleBitronixApplicationTests.java @@ -0,0 +1,74 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.bitronix; + +import bitronix.tm.resource.jms.PoolingConnectionFactory; +import org.assertj.core.api.Condition; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.context.ApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Phillip Webb + */ +@ExtendWith(OutputCaptureExtension.class) +class SampleBitronixApplicationTests { + + @Test + void testTransactionRollback(CapturedOutput capturedOutput) throws Exception { + SampleBitronixApplication.main(new String[] {}); + assertThat(capturedOutput.toString()).has(substring(1, "---->")).has(substring(1, "----> josh")) + .has(substring(2, "Count is 1")).has(substring(1, "Simulated error")); + } + + @Test + void testExposesXaAndNonXa() { + ApplicationContext context = SpringApplication.run(SampleBitronixApplication.class); + Object jmsConnectionFactory = context.getBean("jmsConnectionFactory"); + Object xaJmsConnectionFactory = context.getBean("xaJmsConnectionFactory"); + Object nonXaJmsConnectionFactory = context.getBean("nonXaJmsConnectionFactory"); + assertThat(jmsConnectionFactory).isSameAs(xaJmsConnectionFactory); + assertThat(jmsConnectionFactory).isInstanceOf(PoolingConnectionFactory.class); + assertThat(nonXaJmsConnectionFactory).isNotInstanceOf(PoolingConnectionFactory.class); + } + + private Condition<String> substring(int times, String substring) { + return new Condition<String>("containing '" + substring + "' " + times + " times") { + + @Override + public boolean matches(String value) { + int i = 0; + while (value.contains(substring)) { + int beginIndex = value.indexOf(substring) + substring.length(); + value = value.substring(beginIndex); + i++; + } + return i == times; + } + + }; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/pom.xml new file mode 100644 index 0000000000..ade9e83785 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/pom.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-jta-jndi</artifactId> + <name>Spring Boot JNDI JTA Smoke Test</name> + <packaging>war</packaging> + <description>Spring Boot JNDI JTA Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jms</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <!-- Provided --> + <dependency> + <groupId>jakarta.servlet</groupId> + <artifactId>jakarta.servlet-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>jakarta.jms</groupId> + <artifactId>jakarta.jms-api</artifactId> + <scope>provided</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <finalName>spring-boot-smoke-test-jta-jndi</finalName> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/Account.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/Account.java new file mode 100644 index 0000000000..9cf53640a4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/Account.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jndi; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Account { + + @Id + @GeneratedValue + private Long id; + + private String username; + + Account() { + } + + public Account(String username) { + this.username = username; + } + + public String getUsername() { + return this.username; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/AccountRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/AccountRepository.java new file mode 100644 index 0000000000..f8c12eeebd --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/AccountRepository.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jndi; + +import org.springframework.data.repository.CrudRepository; + +public interface AccountRepository extends CrudRepository<Account, Long> { + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/AccountService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/AccountService.java new file mode 100644 index 0000000000..9f6be377a6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/AccountService.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jndi; + +import org.springframework.jms.core.JmsTemplate; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +public class AccountService { + + private final JmsTemplate jmsTemplate; + + private final AccountRepository accountRepository; + + public AccountService(JmsTemplate jmsTemplate, AccountRepository accountRepository) { + this.jmsTemplate = jmsTemplate; + this.accountRepository = accountRepository; + } + + public void createAccountAndNotify(String username) { + this.jmsTemplate.convertAndSend("java:/jms/queue/bootdemo", username); + Account entity = new Account(username); + this.accountRepository.save(entity); + if ("error".equals(username)) { + throw new RuntimeException("Simulated error"); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/Messages.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/Messages.java new file mode 100644 index 0000000000..f252c45bec --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/Messages.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jndi; + +import org.springframework.jms.annotation.JmsListener; +import org.springframework.stereotype.Component; + +@Component +public class Messages { + + @JmsListener(destination = "java:/jms/queue/bootdemo") + public void onMessage(String content) { + System.out.println("----> " + content); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/SampleJndiApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/SampleJndiApplication.java new file mode 100644 index 0000000000..9c95b13e62 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/SampleJndiApplication.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jndi; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleJndiApplication { + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/SampleJndiInitializer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/SampleJndiInitializer.java new file mode 100644 index 0000000000..b926df4e29 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/SampleJndiInitializer.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jndi; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +public class SampleJndiInitializer extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleJndiApplication.class); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/WebController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/WebController.java new file mode 100644 index 0000000000..e61afea1ab --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/java/smoketest/jndi/WebController.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jndi; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class WebController { + + private final AccountService service; + + private final AccountRepository repository; + + public WebController(AccountService service, AccountRepository repository) { + this.service = service; + this.repository = repository; + } + + @GetMapping("/") + public String hello() { + System.out.println("Count is " + this.repository.count()); + this.service.createAccountAndNotify("josh"); + try { + this.service.createAccountAndNotify("error"); + } + catch (Exception ex) { + System.out.println(ex.getMessage()); + } + long count = this.repository.count(); + System.out.println("Count is " + count); + return "Count is " + count; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-jta-jndi/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-jta-jndi/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/pom.xml new file mode 100644 index 0000000000..856f24e520 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/pom.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-junit-jupiter</artifactId> + <name>Spring Boot JUnit Jupiter Smoke Test</name> + <description>Spring Boot JUnit Jupiter Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.junit.vintage</groupId> + <artifactId>junit-vintage-engine</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/MessageController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/MessageController.java new file mode 100644 index 0000000000..f8de0add00 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/MessageController.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class MessageController { + + @GetMapping("/hi") + public String hello() { + return "Hello World"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/SampleJUnitJupiterApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/SampleJUnitJupiterApplication.java new file mode 100644 index 0000000000..76173d5442 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/main/java/smoketest/SampleJUnitJupiterApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleJUnitJupiterApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleJUnitJupiterApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/test/java/smoketest/SampleJUnitJupiterApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/test/java/smoketest/SampleJUnitJupiterApplicationTests.java new file mode 100644 index 0000000000..6f05a44f60 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-jupiter/src/test/java/smoketest/SampleJUnitJupiterApplicationTests.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleJUnitJupiterApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testMessage() { + String message = this.restTemplate.getForObject("/hi", String.class); + assertThat(message).isEqualTo("Hello World"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/pom.xml new file mode 100644 index 0000000000..d990dc7a61 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/pom.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-junit-vintage</artifactId> + <name>Spring Boot JUnit Vintage Smoke Test</name> + <description>Spring Boot JUnit Vintage Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/src/main/java/smoketest/MessageController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/src/main/java/smoketest/MessageController.java new file mode 100644 index 0000000000..8c68573412 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/src/main/java/smoketest/MessageController.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +class MessageController { + + @GetMapping("/hi") + public String hello() { + return "Hello World"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/src/main/java/smoketest/SampleJUnitVintageApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/src/main/java/smoketest/SampleJUnitVintageApplication.java new file mode 100644 index 0000000000..4884ede498 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/src/main/java/smoketest/SampleJUnitVintageApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleJUnitVintageApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleJUnitVintageApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/src/test/java/smoketest/SampleJUnitVintageApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/src/test/java/smoketest/SampleJUnitVintageApplicationTests.java new file mode 100644 index 0000000000..daeb5f612c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-junit-vintage/src/test/java/smoketest/SampleJUnitVintageApplicationTests.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; + +@RunWith(SpringRunner.class) +@WebMvcTest +public class SampleJUnitVintageApplicationTests { + + @Autowired + private MockMvc mockMvc; + + @Test + public void testMessage() throws Exception { + this.mockMvc.perform(get("/hi")).andExpect(content().string("Hello World")); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/pom.xml new file mode 100644 index 0000000000..7f9dd43edb --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/pom.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <artifactId>spring-boot-smoke-tests</artifactId> + <groupId>org.springframework.boot</groupId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-kafka</artifactId> + <name>Spring Boot Kafka Smoke Test</name> + <description>Spring Boot Kafka Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-json</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.kafka</groupId> + <artifactId>spring-kafka</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.kafka</groupId> + <artifactId>spring-kafka-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/Consumer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/Consumer.java new file mode 100644 index 0000000000..a01a2d1443 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/Consumer.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.kafka; + +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.stereotype.Component; + +@Component +class Consumer { + + private final List<SampleMessage> messages = new CopyOnWriteArrayList<>(); + + @KafkaListener(topics = "testTopic") + public void processMessage(SampleMessage message) { + this.messages.add(message); + System.out.println("Received sample message [" + message + "]"); + } + + List<SampleMessage> getMessages() { + return this.messages; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/Producer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/Producer.java new file mode 100644 index 0000000000..b10b1517e5 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/Producer.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.kafka; + +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.stereotype.Component; + +@Component +public class Producer { + + private final KafkaTemplate<Object, SampleMessage> kafkaTemplate; + + Producer(KafkaTemplate<Object, SampleMessage> kafkaTemplate) { + this.kafkaTemplate = kafkaTemplate; + } + + public void send(SampleMessage message) { + this.kafkaTemplate.send("testTopic", message); + System.out.println("Sent sample message [" + message + "]"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/SampleKafkaApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/SampleKafkaApplication.java new file mode 100644 index 0000000000..8203494ba5 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/SampleKafkaApplication.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.kafka; + +import org.apache.kafka.clients.admin.NewTopic; + +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class SampleKafkaApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleKafkaApplication.class, args); + } + + @Bean + public NewTopic kafkaTestTopic() { + return new NewTopic("testTopic", 10, (short) 2); + } + + @Bean + public ApplicationRunner runner(Producer producer) { + return (args) -> producer.send(new SampleMessage(1, "A simple test message")); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/SampleMessage.java b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/SampleMessage.java new file mode 100644 index 0000000000..c434be60ba --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/java/smoketest/kafka/SampleMessage.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package smoketest.kafka; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SampleMessage { + + private final Integer id; + + private final String message; + + @JsonCreator + public SampleMessage(@JsonProperty("id") Integer id, @JsonProperty("message") String message) { + this.id = id; + this.message = message; + } + + public Integer getId() { + return this.id; + } + + public String getMessage() { + return this.message; + } + + @Override + public String toString() { + return "SampleMessage{id=" + this.id + ", message='" + this.message + "'}"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/resources/application.properties new file mode 100644 index 0000000000..f9c8d74889 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.kafka.bootstrap-servers=localhost:9092 +spring.kafka.consumer.group-id=testGroup +spring.kafka.consumer.auto-offset-reset=earliest +spring.kafka.consumer.value-deserializer=org.springframework.kafka.support.serializer.JsonDeserializer +spring.kafka.consumer.properties.spring.json.trusted.packages=smoketest.kafka +spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/test/java/smoketest/kafka/SampleKafkaApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/test/java/smoketest/kafka/SampleKafkaApplicationTests.java new file mode 100644 index 0000000000..574573b14e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-kafka/src/test/java/smoketest/kafka/SampleKafkaApplicationTests.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package smoketest.kafka; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.kafka.test.context.EmbeddedKafka; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for demo application. + * + * @author hcxin + * @author Gary Russell + * @author Stephane Nicoll + */ +@SpringBootTest(properties = "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}") +@EmbeddedKafka(topics = "testTopic") +class SampleKafkaApplicationTests { + + @Autowired + private Consumer consumer; + + @Test + void testVanillaExchange() throws Exception { + long end = System.currentTimeMillis() + 10000; + while (this.consumer.getMessages().isEmpty() && System.currentTimeMillis() < end) { + Thread.sleep(250); + } + assertThat(this.consumer.getMessages()).extracting("message").containsOnly("A simple test message"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/pom.xml new file mode 100644 index 0000000000..533a1e4c0e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/pom.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-liquibase</artifactId> + <name>Spring Boot Liquibase Smoke Test</name> + <description>Spring Boot Liquibase Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jdbc</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.liquibase</groupId> + <artifactId>liquibase-core</artifactId> + </dependency> + <!-- Runtime --> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>runtime</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/main/java/smoketest/liquibase/SampleLiquibaseApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/main/java/smoketest/liquibase/SampleLiquibaseApplication.java new file mode 100644 index 0000000000..e0b6b643b9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/main/java/smoketest/liquibase/SampleLiquibaseApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.liquibase; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleLiquibaseApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleLiquibaseApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-liquibase/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-liquibase/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-liquibase/src/main/resources/db/changelog/db.changelog-master.yaml b/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/main/resources/db/changelog/db.changelog-master.yaml similarity index 100% rename from spring-boot-samples/spring-boot-sample-liquibase/src/main/resources/db/changelog/db.changelog-master.yaml rename to spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/main/resources/db/changelog/db.changelog-master.yaml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/test/java/smoketest/liquibase/SampleLiquibaseApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/test/java/smoketest/liquibase/SampleLiquibaseApplicationTests.java new file mode 100644 index 0000000000..9b33e0f005 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-liquibase/src/test/java/smoketest/liquibase/SampleLiquibaseApplicationTests.java @@ -0,0 +1,66 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.liquibase; + +import java.net.ConnectException; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.core.NestedCheckedException; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(OutputCaptureExtension.class) +class SampleLiquibaseApplicationTests { + + @Test + void testDefaultSettings(CapturedOutput capturedOutput) throws Exception { + try { + SampleLiquibaseApplication.main(new String[] { "--server.port=0" }); + } + catch (IllegalStateException ex) { + if (serverNotRunning(ex)) { + return; + } + } + assertThat(capturedOutput).contains("Successfully acquired change log lock") + .contains("Creating database history " + "table with name: PUBLIC.DATABASECHANGELOG") + .contains("Table person created") + .contains("ChangeSet classpath:/db/" + "changelog/db.changelog-master.yaml::1::" + + "marceloverdijk ran successfully") + .contains("New row inserted into person").contains("ChangeSet classpath:/db/changelog/" + + "db.changelog-master.yaml::2::" + "marceloverdijk ran successfully") + .contains("Successfully released change log lock"); + } + + @SuppressWarnings("serial") + private boolean serverNotRunning(IllegalStateException ex) { + NestedCheckedException nested = new NestedCheckedException("failed", ex) { + }; + if (nested.contains(ConnectException.class)) { + Throwable root = nested.getRootCause(); + if (root.getMessage().contains("Connection refused")) { + return true; + } + } + return false; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-logback/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-logback/pom.xml new file mode 100644 index 0000000000..ff394f9ef3 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-logback/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-logback</artifactId> + <name>Spring Boot Logback Smoke Test</name> + <description>Spring Boot Logback Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-logback/src/main/java/smoketest/logback/SampleLogbackApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-logback/src/main/java/smoketest/logback/SampleLogbackApplication.java new file mode 100644 index 0000000000..e331c1fe15 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-logback/src/main/java/smoketest/logback/SampleLogbackApplication.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.logback; + +import javax.annotation.PostConstruct; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleLogbackApplication { + + private static final Logger logger = LoggerFactory.getLogger(SampleLogbackApplication.class); + + @PostConstruct + public void logSomething() { + logger.debug("Sample Debug Message"); + logger.trace("Sample Trace Message"); + } + + public static void main(String[] args) { + SpringApplication.run(SampleLogbackApplication.class, args).close(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-logback/src/main/resources/logback-spring.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-logback/src/main/resources/logback-spring.xml new file mode 100644 index 0000000000..0a8ee5a846 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-logback/src/main/resources/logback-spring.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + <include resource="org/springframework/boot/logging/logback/base.xml" /> + <logger name="smoketest.logback" level="DEBUG" /> + <springProfile name="staging"> + <logger name="smoketest.logback" level="TRACE" /> + </springProfile> +</configuration> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-logback/src/test/java/smoketest/logback/SampleLogbackApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-logback/src/test/java/smoketest/logback/SampleLogbackApplicationTests.java new file mode 100644 index 0000000000..06e8791613 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-logback/src/test/java/smoketest/logback/SampleLogbackApplicationTests.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.logback; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(OutputCaptureExtension.class) +class SampleLogbackApplicationTests { + + @Test + void testLoadedCustomLogbackConfig(CapturedOutput capturedOutput) throws Exception { + SampleLogbackApplication.main(new String[0]); + assertThat(capturedOutput).contains("Sample Debug Message").doesNotContain("Sample Trace Message"); + } + + @Test + void testProfile(CapturedOutput capturedOutput) throws Exception { + SampleLogbackApplication.main(new String[] { "--spring.profiles.active=staging" }); + assertThat(capturedOutput).contains("Sample Debug Message").contains("Sample Trace Message"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/pom.xml new file mode 100644 index 0000000000..3656134a9d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/pom.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-oauth2-client</artifactId> + <name>Spring Boot OAuth2 Client Smoke Test</name> + <description>Spring Boot OAuth2 Client Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-oauth2-client</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/main/java/smoketest/oauth2/client/ExampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/main/java/smoketest/oauth2/client/ExampleController.java new file mode 100644 index 0000000000..0ed5a9a252 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/main/java/smoketest/oauth2/client/ExampleController.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.oauth2.client; + +import java.security.Principal; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ExampleController { + + @RequestMapping("/") + public String email(Principal principal) { + return "Hello " + principal.getName(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/main/java/smoketest/oauth2/client/SampleOAuth2ClientApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/main/java/smoketest/oauth2/client/SampleOAuth2ClientApplication.java new file mode 100644 index 0000000000..256257f782 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/main/java/smoketest/oauth2/client/SampleOAuth2ClientApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.oauth2.client; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleOAuth2ClientApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleOAuth2ClientApplication.class); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-oauth2-client/src/main/resources/application.yml b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/main/resources/application.yml similarity index 100% rename from spring-boot-samples/spring-boot-sample-oauth2-client/src/main/resources/application.yml rename to spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/main/resources/application.yml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/test/java/smoketest/oauth2/client/SampleOAuth2ClientApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/test/java/smoketest/oauth2/client/SampleOAuth2ClientApplicationTests.java new file mode 100644 index 0000000000..6ce6e5efb0 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-client/src/test/java/smoketest/oauth2/client/SampleOAuth2ClientApplicationTests.java @@ -0,0 +1,60 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.oauth2.client; + +import java.net.URI; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = { "APP-CLIENT-ID=my-client-id", "APP-CLIENT-SECRET=my-client-secret", + "YAHOO-CLIENT-ID=my-yahoo-client-id", "YAHOO-CLIENT-SECRET=my-yahoo-client-secret" }) +class SampleOAuth2ClientApplicationTests { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void everythingShouldRedirectToLogin() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation()).isEqualTo(URI.create("http://localhost:" + this.port + "/login")); + } + + @Test + void loginShouldHaveAllOAuth2ClientsToChooseFrom() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/login", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("/oauth2/authorization/yahoo"); + assertThat(entity.getBody()).contains("/oauth2/authorization/github-client-1"); + assertThat(entity.getBody()).contains("/oauth2/authorization/github-client-2"); + assertThat(entity.getBody()).contains("/oauth2/authorization/github-repos"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/pom.xml new file mode 100644 index 0000000000..77a5eab235 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/pom.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-oauth2-resource-server</artifactId> + <name>Spring Boot OAuth2 Resource Server Smoke Test</name> + <description>Spring Boot OAuth2 Resource Server Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-oauth2-resource-server</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>com.squareup.okhttp3</groupId> + <artifactId>mockwebserver</artifactId> + <version>3.9.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/ExampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/ExampleController.java new file mode 100644 index 0000000000..7d66a9a68f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/ExampleController.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package smoketest.oauth2.resource; + +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.oauth2.jwt.Jwt; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ExampleController { + + @GetMapping("/") + public String index(@AuthenticationPrincipal Jwt jwt) { + return String.format("Hello, %s!", jwt.getSubject()); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/SampleOauth2ResourceServerApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/SampleOauth2ResourceServerApplication.java new file mode 100644 index 0000000000..f63c5374f6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/SampleOauth2ResourceServerApplication.java @@ -0,0 +1,28 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package smoketest.oauth2.resource; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleOauth2ResourceServerApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleOauth2ResourceServerApplication.class); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/main/resources/application.yml b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/main/resources/application.yml similarity index 100% rename from spring-boot-samples/spring-boot-sample-oauth2-resource-server/src/main/resources/application.yml rename to spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/main/resources/application.yml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/test/java/smoketest/oauth2/resource/SampleOauth2ResourceServerApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/test/java/smoketest/oauth2/resource/SampleOauth2ResourceServerApplicationTests.java new file mode 100644 index 0000000000..439eb710b6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-oauth2-resource-server/src/test/java/smoketest/oauth2/resource/SampleOauth2ResourceServerApplicationTests.java @@ -0,0 +1,105 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package smoketest.oauth2.resource; + +import java.io.IOException; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class SampleOauth2ResourceServerApplicationTests { + + private static MockWebServer server = new MockWebServer(); + + private static final String VALID_TOKEN = "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0Iiwic2NvcGUiOiJtZXNzYWdlOnJlYWQi" + + "LCJleHAiOjQ2ODM4MDUxNDF9.h-j6FKRFdnTdmAueTZCdep45e6DPwqM68ZQ8doIJ1exi9YxAlbWzOwId6Bd0L5YmCmp63gGQgsBUBLzwnZQ8kLUgU" + + "OBEC3UzSWGRqMskCY9_k9pX0iomX6IfF3N0PaYs0WPC4hO1s8wfZQ-6hKQ4KigFi13G9LMLdH58PRMK0pKEvs3gCbHJuEPw-K5ORlpdnleUTQIwIN" + + "afU57cmK3KocTeknPAM_L716sCuSYGvDl6xUTXO7oPdrXhS_EhxLP6KxrpI1uD4Ea_5OWTh7S0Wx5LLDfU6wBG1DowN20d374zepOIEkR-Jnmr_Ql" + + "R44vmRqS5ncrF-1R0EGcPX49U6A"; + + @Autowired + private TestRestTemplate restTemplate; + + @BeforeAll + public static void setup() throws Exception { + server.start(); + String url = server.url("/.well-known/jwks.json").toString(); + server.enqueue(mockResponse()); + System.setProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri", url); + } + + @AfterAll + public static void shutdown() throws IOException { + server.shutdown(); + System.clearProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri"); + } + + @Test + void withValidBearerTokenShouldAllowAccess() { + HttpHeaders headers = new HttpHeaders(); + headers.setBearerAuth(VALID_TOKEN); + HttpEntity<?> request = new HttpEntity<Void>(headers); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, request, String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + } + + @Test + void withNoBearerTokenShouldNotAllowAccess() { + HttpHeaders headers = new HttpHeaders(); + HttpEntity<?> request = new HttpEntity<Void>(headers); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, request, String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + private static MockResponse mockResponse() { + String body = "{\"keys\":[{\"p\":\"2p-ViY7DE9ZrdWQb544m0Jp7Cv03YCSljqfim9pD4ALhObX0OrAznOiowTjwBky9JGffMw" + + "DBVSfJSD9TSU7aH2sbbfi0bZLMdekKAuimudXwUqPDxrrg0BCyvCYgLmKjbVT3zcdylWSog93CNTxGDPzauu-oc0XPNKCXnaDpNvE\"" + + ",\"kty\":\"RSA\",\"q\":\"sP_QYavrpBvSJ86uoKVGj2AGl78CSsAtpf1ybSY5TwUlorXSdqapRbY69Y271b0aMLzlleUn9ZTBO" + + "1dlKV2_dw_lPADHVia8z3pxL-8sUhIXLsgj4acchMk4c9YX-sFh07xENnyZ-_TXm3llPLuL67HUfBC2eKe800TmCYVWc9U\",\"d\"" + + ":\"bn1nFxCQT4KLTHqo8mo9HvHD0cRNRNdWcKNnnEQkCF6tKbt-ILRyQGP8O40axLd7CoNVG9c9p_-g4-2kwCtLJNv_STLtwfpCY7" + + "VN5o6-ZIpfTjiW6duoPrLWq64Hm_4LOBQTiZfUPcLhsuJRHbWqakj-kV_YbUyC2Ocf_dd8IAQcSrAU2SCcDebhDCWwRUFvaa9V5eq0" + + "851S9goaA-AJz-JXyePH6ZFr8JxmWkWxYZ5kdcMD-sm9ZbxE0CaEk32l4fE4hR-L8x2dDtjWA-ahKCZ091z-gV3HWtR2JOjvxoNRjxUo" + + "3UxaGiFJHWNIl0EYUJZu1Cb-5wIlEI7wPx5mwQ\",\"e\":\"AQAB\",\"use\":\"sig\",\"kid\":\"one\",\"qi\":\"qS0OK4" + + "8M2CIAA6_4Wdw4EbCaAfcTLf5Oy9t5BOF_PFUKqoSpZ6JsT5H0a_4zkjt-oI969v78OTlvBKbmEyKO-KeytzHBAA5CsLmVcz0THrMSg6o" + + "XZqu66MPnvWoZN9FEN5TklPOvBFm8Bg1QZ3k-YMVaM--DLvhaYR95_mqaz50\",\"dp\":\"Too2NozLGD1XrXyhabZvy1E0EuaVFj0UHQ" + + "PDLSpkZ_2g3BK6Art6T0xmE8RYtmqrKIEIdlI3IliAvyvAx_1D7zWTTRaj-xlZyqJFrnXWL7zj8UxT8PkB-r2E-ILZ3NAi1gxIWezlBTZ8" + + "M6NfObDFmbTc_3tJkN_raISo8z_ziIE\",\"dq\":\"U0yhSkY5yOsa9YcMoigGVBWSJLpNHtbg5NypjHrPv8OhWbkOSq7WvSstBkF" + + "k5AtyFvvfZLMLIkWWxxGzV0t6f1MoxBtttLrYYyCxwihiiGFhLbAdSuZ1wnxcqA9bC7UVECvrQmVTpsMs8UupfHKbQBpZ8OWAqrn" + + "uYNNtG4_4Bt0\",\"n\":\"lygtuZj0lJjqOqIWocF8Bb583QDdq-aaFg8PesOp2-EDda6GqCpL-_NZVOflNGX7XIgjsWHcPsQHs" + + "V9gWuOzSJ0iEuWvtQ6eGBP5M6m7pccLNZfwUse8Cb4Ngx3XiTlyuqM7pv0LPyppZusfEHVEdeelou7Dy9k0OQ_nJTI3b2E1WBoHC5" + + "8CJ453lo4gcBm1efURN3LIVc1V9NQY_ESBKVdwqYyoJPEanURLVGRd6cQKn6YrCbbIRHjqAyqOE-z3KmgDJnPriljfR5XhSGyM9eq" + + "D9Xpy6zu_MAeMJJfSArp857zLPk-Wf5VP9STAcjyfdBIybMKnwBYr2qHMT675hQ\"}]}"; + return new MockResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .setResponseCode(200).setBody(body); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/pom.xml new file mode 100644 index 0000000000..c2897ec97a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/pom.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-parent-context</artifactId> + <name>Spring Boot Parent Context Smoke Test</name> + <description>Spring Boot Parent Context Smoke Test</description> + <properties> + <start-class>smoketest.parent.SampleParentContextApplication</start-class> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-integration</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.integration</groupId> + <artifactId>spring-integration-file</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/HelloWorldService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/HelloWorldService.java new file mode 100644 index 0000000000..4fba77637e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/HelloWorldService.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.parent; + +import org.springframework.stereotype.Component; + +@Component +public class HelloWorldService { + + private final ServiceProperties configuration; + + public HelloWorldService(ServiceProperties configuration) { + this.configuration = configuration; + } + + public String getHelloMessage(String name) { + return this.configuration.getGreeting() + " " + name; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/SampleEndpoint.java b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/SampleEndpoint.java new file mode 100644 index 0000000000..57a34bc9ba --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/SampleEndpoint.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.parent; + +import java.io.File; +import java.io.FileInputStream; + +import org.springframework.integration.annotation.MessageEndpoint; +import org.springframework.integration.annotation.ServiceActivator; +import org.springframework.util.StreamUtils; + +@MessageEndpoint +public class SampleEndpoint { + + private final HelloWorldService helloWorldService; + + public SampleEndpoint(HelloWorldService helloWorldService) { + this.helloWorldService = helloWorldService; + } + + @ServiceActivator + public String hello(File input) throws Exception { + FileInputStream in = new FileInputStream(input); + String name = new String(StreamUtils.copyToByteArray(in)); + in.close(); + return this.helloWorldService.getHelloMessage(name); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/SampleParentContextApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/SampleParentContextApplication.java new file mode 100644 index 0000000000..a7157b793e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/SampleParentContextApplication.java @@ -0,0 +1,92 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.parent; + +import java.util.function.Consumer; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.integration.channel.DirectChannel; +import org.springframework.integration.dsl.IntegrationFlow; +import org.springframework.integration.dsl.IntegrationFlows; +import org.springframework.integration.dsl.Pollers; +import org.springframework.integration.dsl.SourcePollingChannelAdapterSpec; +import org.springframework.integration.file.FileReadingMessageSource; +import org.springframework.integration.file.FileWritingMessageHandler; + +@SpringBootApplication +public class SampleParentContextApplication { + + public static void main(String[] args) throws Exception { + new SpringApplicationBuilder(Parent.class).child(SampleParentContextApplication.class).run(args); + } + + @Configuration(proxyBeanMethods = false) + @EnableAutoConfiguration + protected static class Parent { + + private final ServiceProperties serviceProperties; + + public Parent(ServiceProperties serviceProperties) { + this.serviceProperties = serviceProperties; + } + + @Bean + public FileReadingMessageSource fileReader() { + FileReadingMessageSource reader = new FileReadingMessageSource(); + reader.setDirectory(this.serviceProperties.getInputDir()); + return reader; + } + + @Bean + public DirectChannel inputChannel() { + return new DirectChannel(); + } + + @Bean + public DirectChannel outputChannel() { + return new DirectChannel(); + } + + @Bean + public FileWritingMessageHandler fileWriter() { + FileWritingMessageHandler writer = new FileWritingMessageHandler(this.serviceProperties.getOutputDir()); + writer.setExpectReply(false); + return writer; + } + + @Bean + public IntegrationFlow integrationFlow(SampleEndpoint endpoint) { + return IntegrationFlows.from(fileReader(), new FixedRatePoller()).channel(inputChannel()).handle(endpoint) + .channel(outputChannel()).handle(fileWriter()).get(); + } + + private static class FixedRatePoller implements Consumer<SourcePollingChannelAdapterSpec> { + + @Override + public void accept(SourcePollingChannelAdapterSpec spec) { + spec.poller(Pollers.fixedRate(500)); + } + + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/ServiceProperties.java b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/ServiceProperties.java new file mode 100644 index 0000000000..96b7653378 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/ServiceProperties.java @@ -0,0 +1,60 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.parent; + +import java.io.File; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.jmx.export.annotation.ManagedAttribute; +import org.springframework.jmx.export.annotation.ManagedResource; + +@ConfigurationProperties(prefix = "service", ignoreUnknownFields = false) +@ManagedResource +public class ServiceProperties { + + private String greeting = "Hello"; + + private File inputDir; + + private File outputDir; + + @ManagedAttribute + public String getGreeting() { + return this.greeting; + } + + public void setGreeting(String greeting) { + this.greeting = greeting; + } + + public File getInputDir() { + return this.inputDir; + } + + public void setInputDir(File inputDir) { + this.inputDir = inputDir; + } + + public File getOutputDir() { + return this.outputDir; + } + + public void setOutputDir(File outputDir) { + this.outputDir = outputDir; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-parent-context/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-parent-context/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/consumer/SampleIntegrationParentApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/consumer/SampleIntegrationParentApplicationTests.java new file mode 100644 index 0000000000..7c6eebfe14 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/consumer/SampleIntegrationParentApplicationTests.java @@ -0,0 +1,105 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.parent.consumer; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import smoketest.parent.SampleParentContextApplication; +import smoketest.parent.producer.ProducerApplication; + +import org.springframework.boot.SpringApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.ResourcePatternUtils; +import org.springframework.util.StreamUtils; + +import static org.junit.jupiter.api.Assertions.fail; + +/** + * Basic integration tests for service demo application. + * + * @author Dave Syer + * @author Andy Wilkinson + */ +class SampleIntegrationParentApplicationTests { + + @Test + void testVanillaExchange(@TempDir Path temp) throws Exception { + File inputDir = new File(temp.toFile(), "input"); + File outputDir = new File(temp.toFile(), "output"); + ConfigurableApplicationContext app = SpringApplication.run(SampleParentContextApplication.class, + "--service.input-dir=" + inputDir, "--service.output-dir=" + outputDir); + try { + ConfigurableApplicationContext producer = SpringApplication.run(ProducerApplication.class, + "--service.input-dir=" + inputDir, "--service.output-dir=" + outputDir, "World"); + try { + awaitOutputContaining(outputDir, "Hello World"); + } + finally { + producer.close(); + } + } + finally { + app.close(); + } + } + + private void awaitOutputContaining(File outputDir, String requiredContents) throws Exception { + long endTime = System.currentTimeMillis() + 30000; + String output = null; + while (System.currentTimeMillis() < endTime) { + Resource[] resources = findResources(outputDir); + if (resources.length == 0) { + Thread.sleep(200); + resources = findResources(outputDir); + } + else { + output = readResources(resources); + if (output != null && output.contains(requiredContents)) { + return; + } + else { + Thread.sleep(200); + output = readResources(resources); + } + } + } + fail("Timed out awaiting output containing '" + requiredContents + "'. Output was '" + output + "'"); + } + + private Resource[] findResources(File outputDir) throws IOException { + return ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader()) + .getResources("file:" + outputDir.getAbsolutePath() + "/*.txt"); + } + + private String readResources(Resource[] resources) throws IOException { + StringBuilder builder = new StringBuilder(); + for (Resource resource : resources) { + try (InputStream input = resource.getInputStream()) { + builder.append(new String(StreamUtils.copyToByteArray(input))); + } + } + return builder.toString(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/producer/ProducerApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/producer/ProducerApplication.java new file mode 100644 index 0000000000..7cee22afb6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/producer/ProducerApplication.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.parent.producer; + +import java.io.File; +import java.io.FileOutputStream; + +import smoketest.parent.ServiceProperties; + +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +@EnableConfigurationProperties(ServiceProperties.class) +public class ProducerApplication implements ApplicationRunner { + + private final ServiceProperties serviceProperties; + + public ProducerApplication(ServiceProperties serviceProperties) { + this.serviceProperties = serviceProperties; + } + + @Override + public void run(ApplicationArguments args) throws Exception { + this.serviceProperties.getInputDir().mkdirs(); + if (args.getNonOptionArgs().size() > 0) { + FileOutputStream stream = new FileOutputStream( + new File(this.serviceProperties.getInputDir(), "data" + System.currentTimeMillis() + ".txt")); + for (String arg : args.getNonOptionArgs()) { + stream.write(arg.getBytes()); + } + stream.flush(); + stream.close(); + } + } + + public static void main(String[] args) { + SpringApplication.run(ProducerApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-profile/application.yml b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/application.yml similarity index 100% rename from spring-boot-samples/spring-boot-sample-profile/application.yml rename to spring-boot-smoke-tests/spring-boot-smoke-test-profile/application.yml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-profile/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/pom.xml new file mode 100644 index 0000000000..6580a96ac3 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-profile</artifactId> + <name>Spring Boot Profile Smoke Test</name> + <description>Spring Boot Profile Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/SampleProfileApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/SampleProfileApplication.java new file mode 100644 index 0000000000..03487f96a1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/SampleProfileApplication.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.profile; + +import smoketest.profile.service.MessageService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleProfileApplication implements CommandLineRunner { + + // Simple example shows how a command line spring application can execute an + // injected bean service. Also demonstrates how you can use @Value to inject + // command line args ('--name=whatever') or application properties + + @Autowired + private MessageService helloWorldService; + + @Override + public void run(String... args) { + System.out.println(this.helloWorldService.getMessage()); + } + + public static void main(String[] args) { + SpringApplication.run(SampleProfileApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/GenericService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/GenericService.java new file mode 100644 index 0000000000..f4a8d358da --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/GenericService.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.profile.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; + +@Component +@Profile({ "generic" }) +public class GenericService implements MessageService { + + @Value("${hello:Hello}") + private String hello; + + @Value("${name:World}") + private String name; + + @Override + public String getMessage() { + return this.hello + " " + this.name; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/GoodbyeWorldService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/GoodbyeWorldService.java new file mode 100644 index 0000000000..a18cc59594 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/GoodbyeWorldService.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.profile.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; + +@Component +@Profile("goodbye") +public class GoodbyeWorldService implements MessageService { + + @Value("${name:World}") + private String name; + + @Override + public String getMessage() { + return "Goodbye " + this.name; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/HelloWorldService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/HelloWorldService.java new file mode 100644 index 0000000000..33aa6b3c18 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/HelloWorldService.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.profile.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; + +@Component +@Profile({ "hello", "default" }) +public class HelloWorldService implements MessageService { + + @Value("${name:World}") + private String name; + + @Override + public String getMessage() { + return "Hello " + this.name; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/MessageService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/MessageService.java new file mode 100644 index 0000000000..c40a40e528 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/java/smoketest/profile/service/MessageService.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.profile.service; + +public interface MessageService { + + String getMessage(); + +} diff --git a/spring-boot-samples/spring-boot-sample-profile/src/main/resources/application.yml b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/resources/application.yml similarity index 100% rename from spring-boot-samples/spring-boot-sample-profile/src/main/resources/application.yml rename to spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/main/resources/application.yml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/test/java/smoketest/profile/SampleProfileApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/test/java/smoketest/profile/SampleProfileApplicationTests.java new file mode 100644 index 0000000000..b6cf2988ea --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-profile/src/test/java/smoketest/profile/SampleProfileApplicationTests.java @@ -0,0 +1,81 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.profile; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(OutputCaptureExtension.class) +class SampleProfileApplicationTests { + + private String profiles; + + @BeforeEach + void before() { + this.profiles = System.getProperty("spring.profiles.active"); + } + + @AfterEach + void after() { + if (this.profiles != null) { + System.setProperty("spring.profiles.active", this.profiles); + } + else { + System.clearProperty("spring.profiles.active"); + } + } + + @Test + void testDefaultProfile(CapturedOutput capturedOutput) { + SampleProfileApplication.main(new String[0]); + assertThat(capturedOutput).contains("Hello Phil"); + } + + @Test + void testGoodbyeProfile(CapturedOutput capturedOutput) { + System.setProperty("spring.profiles.active", "goodbye"); + SampleProfileApplication.main(new String[0]); + assertThat(capturedOutput).contains("Goodbye Everyone"); + } + + @Test + void testGenericProfile(CapturedOutput capturedOutput) { + /* + * This is a profile that requires a new environment property, and one which is + * only overridden in the current working directory. That file also only contains + * partial overrides, and the default application.yml should still supply the + * "name" property. + */ + System.setProperty("spring.profiles.active", "generic"); + SampleProfileApplication.main(new String[0]); + assertThat(capturedOutput).contains("Bonjour Phil"); + } + + @Test + void testGoodbyeProfileFromCommandline(CapturedOutput capturedOutput) { + SampleProfileApplication.main(new String[] { "--spring.profiles.active=goodbye" }); + assertThat(capturedOutput).contains("Goodbye Everyone"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/pom.xml new file mode 100644 index 0000000000..d10267d7ad --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/pom.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-property-validation</artifactId> + <name>Spring Boot Property Validation Smoke Test</name> + <description>Spring Boot Property Validation Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <!-- Optional --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <optional>true</optional> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/java/smoketest/propertyvalidation/SampleProperties.java b/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/java/smoketest/propertyvalidation/SampleProperties.java new file mode 100644 index 0000000000..72e2dc8ea3 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/java/smoketest/propertyvalidation/SampleProperties.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.propertyvalidation; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; + +@ConfigurationProperties(prefix = "sample") +@Validated +public class SampleProperties { + + /** + * Sample host. + */ + private String host; + + /** + * Sample port. + */ + private Integer port = 8080; + + public String getHost() { + return this.host; + } + + public void setHost(String host) { + this.host = host; + } + + public Integer getPort() { + return this.port; + } + + public void setPort(Integer port) { + this.port = port; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/java/smoketest/propertyvalidation/SamplePropertiesValidator.java b/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/java/smoketest/propertyvalidation/SamplePropertiesValidator.java new file mode 100644 index 0000000000..ecf2913953 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/java/smoketest/propertyvalidation/SamplePropertiesValidator.java @@ -0,0 +1,44 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.propertyvalidation; + +import java.util.regex.Pattern; + +import org.springframework.validation.Errors; +import org.springframework.validation.ValidationUtils; +import org.springframework.validation.Validator; + +public class SamplePropertiesValidator implements Validator { + + final Pattern pattern = Pattern.compile("^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$"); + + @Override + public boolean supports(Class<?> type) { + return type == SampleProperties.class; + } + + @Override + public void validate(Object o, Errors errors) { + ValidationUtils.rejectIfEmpty(errors, "host", "host.empty"); + ValidationUtils.rejectIfEmpty(errors, "port", "port.empty"); + SampleProperties properties = (SampleProperties) o; + if (properties.getHost() != null && !this.pattern.matcher(properties.getHost()).matches()) { + errors.rejectValue("host", "Invalid host"); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/java/smoketest/propertyvalidation/SamplePropertyValidationApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/java/smoketest/propertyvalidation/SamplePropertyValidationApplication.java new file mode 100644 index 0000000000..2fae720527 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/java/smoketest/propertyvalidation/SamplePropertyValidationApplication.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.propertyvalidation; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.validation.Validator; + +@SpringBootApplication +public class SamplePropertyValidationApplication implements CommandLineRunner { + + private final SampleProperties properties; + + public SamplePropertyValidationApplication(SampleProperties properties) { + this.properties = properties; + } + + @Bean + public static Validator configurationPropertiesValidator() { + return new SamplePropertiesValidator(); + } + + @Override + public void run(String... args) { + System.out.println("========================================="); + System.out.println("Sample host: " + this.properties.getHost()); + System.out.println("Sample port: " + this.properties.getPort()); + System.out.println("========================================="); + } + + public static void main(String[] args) { + new SpringApplicationBuilder(SamplePropertyValidationApplication.class).run(args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-property-validation/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/test/java/smoketest/propertyvalidation/SamplePropertyValidationApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/test/java/smoketest/propertyvalidation/SamplePropertyValidationApplicationTests.java new file mode 100644 index 0000000000..4e6919b7e6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-property-validation/src/test/java/smoketest/propertyvalidation/SamplePropertyValidationApplicationTests.java @@ -0,0 +1,81 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.propertyvalidation; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.BeanCreationException; +import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +/** + * Tests for {@link SamplePropertyValidationApplication}. + * + * @author Lucas Saldanha + * @author Stephane Nicoll + */ +class SamplePropertyValidationApplicationTests { + + private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + + @AfterEach + void closeContext() { + this.context.close(); + } + + @Test + void bindValidProperties() { + this.context.register(SamplePropertyValidationApplication.class); + TestPropertyValues.of("sample.host:192.168.0.1", "sample.port:9090").applyTo(this.context); + this.context.refresh(); + SampleProperties properties = this.context.getBean(SampleProperties.class); + assertThat(properties.getHost()).isEqualTo("192.168.0.1"); + assertThat(properties.getPort()).isEqualTo(Integer.valueOf(9090)); + } + + @Test + void bindInvalidHost() { + this.context.register(SamplePropertyValidationApplication.class); + TestPropertyValues.of("sample.host:xxxxxx", "sample.port:9090").applyTo(this.context); + assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> this.context.refresh()) + .withMessageContaining("Failed to bind properties under 'sample'"); + } + + @Test + void bindNullHost() { + this.context.register(SamplePropertyValidationApplication.class); + assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> this.context.refresh()) + .withMessageContaining("Failed to bind properties under 'sample'"); + } + + @Test + void validatorOnlyCalledOnSupportedClass() { + this.context.register(SamplePropertyValidationApplication.class); + this.context.register(ServerProperties.class); // our validator will not apply + TestPropertyValues.of("sample.host:192.168.0.1", "sample.port:9090").applyTo(this.context); + this.context.refresh(); + SampleProperties properties = this.context.getBean(SampleProperties.class); + assertThat(properties.getHost()).isEqualTo("192.168.0.1"); + assertThat(properties.getPort()).isEqualTo(Integer.valueOf(9090)); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/pom.xml new file mode 100644 index 0000000000..bca7e67c1b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/pom.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-quartz</artifactId> + <name>Spring Boot Quartz Smoke Test</name> + <description>Spring Boot Quartz Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-quartz</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/src/main/java/smoketest/quartz/SampleJob.java b/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/src/main/java/smoketest/quartz/SampleJob.java new file mode 100644 index 0000000000..415f64c472 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/src/main/java/smoketest/quartz/SampleJob.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.quartz; + +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +import org.springframework.scheduling.quartz.QuartzJobBean; + +public class SampleJob extends QuartzJobBean { + + private String name; + + // Invoked if a Job data map entry with that name + public void setName(String name) { + this.name = name; + } + + @Override + protected void executeInternal(JobExecutionContext context) throws JobExecutionException { + System.out.println(String.format("Hello %s!", this.name)); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/src/main/java/smoketest/quartz/SampleQuartzApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/src/main/java/smoketest/quartz/SampleQuartzApplication.java new file mode 100644 index 0000000000..680c382280 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/src/main/java/smoketest/quartz/SampleQuartzApplication.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.quartz; + +import org.quartz.JobBuilder; +import org.quartz.JobDetail; +import org.quartz.SimpleScheduleBuilder; +import org.quartz.Trigger; +import org.quartz.TriggerBuilder; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class SampleQuartzApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleQuartzApplication.class, args); + } + + @Bean + public JobDetail sampleJobDetail() { + return JobBuilder.newJob(SampleJob.class).withIdentity("sampleJob").usingJobData("name", "World").storeDurably() + .build(); + } + + @Bean + public Trigger sampleJobTrigger() { + SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(2) + .repeatForever(); + + return TriggerBuilder.newTrigger().forJob(sampleJobDetail()).withIdentity("sampleTrigger") + .withSchedule(scheduleBuilder).build(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/src/test/java/smoketest/quartz/SampleQuartzApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/src/test/java/smoketest/quartz/SampleQuartzApplicationTests.java new file mode 100644 index 0000000000..9475775060 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-quartz/src/test/java/smoketest/quartz/SampleQuartzApplicationTests.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.quartz; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.context.ConfigurableApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleQuartzApplication}. + * + * @author Eddú Meléndez + */ +@ExtendWith(OutputCaptureExtension.class) +class SampleQuartzApplicationTests { + + @Test + void quartzJobIsTriggered(CapturedOutput capturedOutput) throws InterruptedException { + try (ConfigurableApplicationContext context = SpringApplication.run(SampleQuartzApplication.class)) { + long end = System.currentTimeMillis() + 5000; + while ((!capturedOutput.toString().contains("Hello World!")) && System.currentTimeMillis() < end) { + Thread.sleep(100); + } + assertThat(capturedOutput).contains("Hello World!"); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/pom.xml new file mode 100644 index 0000000000..f95bcf96fa --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/pom.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-reactive-oauth2-client</artifactId> + <name>Spring Boot Reactive OAuth2 Client Smoke Test</name> + <description>Spring Boot Reactive OAuth2 Client Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-oauth2-client</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-webflux</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/main/java/smoketest/oauth2/client/ExampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/main/java/smoketest/oauth2/client/ExampleController.java new file mode 100644 index 0000000000..1a9090d0ab --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/main/java/smoketest/oauth2/client/ExampleController.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.oauth2.client; + +import java.security.Principal; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ExampleController { + + @RequestMapping("/") + public String email(Principal principal) { + return "Hello " + principal.getName(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/main/java/smoketest/oauth2/client/SampleReactiveOAuth2ClientApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/main/java/smoketest/oauth2/client/SampleReactiveOAuth2ClientApplication.java new file mode 100644 index 0000000000..12a533454d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/main/java/smoketest/oauth2/client/SampleReactiveOAuth2ClientApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.oauth2.client; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleReactiveOAuth2ClientApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleReactiveOAuth2ClientApplication.class); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/main/resources/application.yml b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/main/resources/application.yml similarity index 100% rename from spring-boot-samples/spring-boot-sample-reactive-oauth2-client/src/main/resources/application.yml rename to spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/main/resources/application.yml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/test/java/smoketest/oauth2/client/SampleReactiveOAuth2ClientApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/test/java/smoketest/oauth2/client/SampleReactiveOAuth2ClientApplicationTests.java new file mode 100644 index 0000000000..8ac3c73bf1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-client/src/test/java/smoketest/oauth2/client/SampleReactiveOAuth2ClientApplicationTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.oauth2.client; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.reactive.server.WebTestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = { "APP-CLIENT-ID=my-client-id", "APP-CLIENT-SECRET=my-client-secret", + "YAHOO-CLIENT-ID=my-google-client-id", "YAHOO-CLIENT-SECRET=my-google-client-secret" }) +class SampleReactiveOAuth2ClientApplicationTests { + + @Autowired + private WebTestClient webTestClient; + + @Test + void everythingShouldRedirectToLogin() { + this.webTestClient.get().uri("/").exchange().expectStatus().isFound().expectHeader().valueEquals("Location", + "/login"); + } + + @Test + void loginShouldHaveBothOAuthClientsToChooseFrom() { + byte[] body = this.webTestClient.get().uri("/login").exchange().expectStatus().isOk().returnResult(String.class) + .getResponseBodyContent(); + String bodyString = new String(body); + assertThat(bodyString).contains("/oauth2/authorization/yahoo"); + assertThat(bodyString).contains("/oauth2/authorization/github-client-1"); + assertThat(bodyString).contains("/oauth2/authorization/github-client-2"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/pom.xml new file mode 100644 index 0000000000..e85865a689 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/pom.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-reactive-oauth2-resource-server</artifactId> + <name>Spring Boot Reactive OAuth2 Resource Server Smoke Test</name> + <description>Spring Boot OAuth2 Reactive Resource Server Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-oauth2-resource-server</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-webflux</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>com.squareup.okhttp3</groupId> + <artifactId>mockwebserver</artifactId> + <version>3.9.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/ExampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/ExampleController.java new file mode 100644 index 0000000000..0e2f473e44 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/ExampleController.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.oauth2.resource; + +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.oauth2.jwt.Jwt; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ExampleController { + + @GetMapping("/") + public String index(@AuthenticationPrincipal Jwt jwt) { + return String.format("Hello, %s!", jwt.getSubject()); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/SampleReactiveOAuth2ResourceServerApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/SampleReactiveOAuth2ResourceServerApplication.java new file mode 100644 index 0000000000..616294e339 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/main/java/smoketest/oauth2/resource/SampleReactiveOAuth2ResourceServerApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.oauth2.resource; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleReactiveOAuth2ResourceServerApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleReactiveOAuth2ResourceServerApplication.class); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/main/resources/application.yml b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/main/resources/application.yml similarity index 100% rename from spring-boot-samples/spring-boot-sample-reactive-oauth2-resource-server/src/main/resources/application.yml rename to spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/main/resources/application.yml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/test/java/smoketest/oauth2/resource/SampleReactiveOAuth2ResourceServerApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/test/java/smoketest/oauth2/resource/SampleReactiveOAuth2ResourceServerApplicationTests.java new file mode 100644 index 0000000000..6a65f728a6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-reactive-oauth2-resource-server/src/test/java/smoketest/oauth2/resource/SampleReactiveOAuth2ResourceServerApplicationTests.java @@ -0,0 +1,93 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.oauth2.resource; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.test.web.reactive.server.WebTestClient; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class SampleReactiveOAuth2ResourceServerApplicationTests { + + @Autowired + private WebTestClient webTestClient; + + private static MockWebServer server = new MockWebServer(); + + private static final String VALID_TOKEN = "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0Iiwic2NvcGUiOiJtZXNzYWdlOnJlYWQi" + + "LCJleHAiOjQ2ODM4MDUxNDF9.h-j6FKRFdnTdmAueTZCdep45e6DPwqM68ZQ8doIJ1exi9YxAlbWzOwId6Bd0L5YmCmp63gGQgsBUBLzwnZQ8kLUgU" + + "OBEC3UzSWGRqMskCY9_k9pX0iomX6IfF3N0PaYs0WPC4hO1s8wfZQ-6hKQ4KigFi13G9LMLdH58PRMK0pKEvs3gCbHJuEPw-K5ORlpdnleUTQIwIN" + + "afU57cmK3KocTeknPAM_L716sCuSYGvDl6xUTXO7oPdrXhS_EhxLP6KxrpI1uD4Ea_5OWTh7S0Wx5LLDfU6wBG1DowN20d374zepOIEkR-Jnmr_Ql" + + "R44vmRqS5ncrF-1R0EGcPX49U6A"; + + @BeforeAll + public static void setup() throws Exception { + server.start(); + String url = server.url("/.well-known/jwks.json").toString(); + server.enqueue(mockResponse()); + System.setProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri", url); + } + + @AfterAll + public static void shutdown() throws Exception { + server.shutdown(); + System.clearProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri"); + } + + @Test + void getWhenValidTokenShouldBeOk() { + this.webTestClient.get().uri("/").headers((headers) -> headers.setBearerAuth(VALID_TOKEN)).exchange() + .expectStatus().isOk().expectBody(String.class).isEqualTo("Hello, subject!"); + } + + @Test + void getWhenNoTokenShouldBeUnauthorized() { + this.webTestClient.get().uri("/").exchange().expectStatus().isUnauthorized().expectHeader() + .valueEquals(HttpHeaders.WWW_AUTHENTICATE, "Bearer"); + } + + private static MockResponse mockResponse() { + String body = "{\"keys\":[{\"p\":\"2p-ViY7DE9ZrdWQb544m0Jp7Cv03YCSljqfim9pD4ALhObX0OrAznOiowTjwBky9JGffMw" + + "DBVSfJSD9TSU7aH2sbbfi0bZLMdekKAuimudXwUqPDxrrg0BCyvCYgLmKjbVT3zcdylWSog93CNTxGDPzauu-oc0XPNKCXnaDpNvE\"" + + ",\"kty\":\"RSA\",\"q\":\"sP_QYavrpBvSJ86uoKVGj2AGl78CSsAtpf1ybSY5TwUlorXSdqapRbY69Y271b0aMLzlleUn9ZTBO" + + "1dlKV2_dw_lPADHVia8z3pxL-8sUhIXLsgj4acchMk4c9YX-sFh07xENnyZ-_TXm3llPLuL67HUfBC2eKe800TmCYVWc9U\",\"d\"" + + ":\"bn1nFxCQT4KLTHqo8mo9HvHD0cRNRNdWcKNnnEQkCF6tKbt-ILRyQGP8O40axLd7CoNVG9c9p_-g4-2kwCtLJNv_STLtwfpCY7" + + "VN5o6-ZIpfTjiW6duoPrLWq64Hm_4LOBQTiZfUPcLhsuJRHbWqakj-kV_YbUyC2Ocf_dd8IAQcSrAU2SCcDebhDCWwRUFvaa9V5eq0" + + "851S9goaA-AJz-JXyePH6ZFr8JxmWkWxYZ5kdcMD-sm9ZbxE0CaEk32l4fE4hR-L8x2dDtjWA-ahKCZ091z-gV3HWtR2JOjvxoNRjxUo" + + "3UxaGiFJHWNIl0EYUJZu1Cb-5wIlEI7wPx5mwQ\",\"e\":\"AQAB\",\"use\":\"sig\",\"kid\":\"one\",\"qi\":\"qS0OK4" + + "8M2CIAA6_4Wdw4EbCaAfcTLf5Oy9t5BOF_PFUKqoSpZ6JsT5H0a_4zkjt-oI969v78OTlvBKbmEyKO-KeytzHBAA5CsLmVcz0THrMSg6o" + + "XZqu66MPnvWoZN9FEN5TklPOvBFm8Bg1QZ3k-YMVaM--DLvhaYR95_mqaz50\",\"dp\":\"Too2NozLGD1XrXyhabZvy1E0EuaVFj0UHQ" + + "PDLSpkZ_2g3BK6Art6T0xmE8RYtmqrKIEIdlI3IliAvyvAx_1D7zWTTRaj-xlZyqJFrnXWL7zj8UxT8PkB-r2E-ILZ3NAi1gxIWezlBTZ8" + + "M6NfObDFmbTc_3tJkN_raISo8z_ziIE\",\"dq\":\"U0yhSkY5yOsa9YcMoigGVBWSJLpNHtbg5NypjHrPv8OhWbkOSq7WvSstBkF" + + "k5AtyFvvfZLMLIkWWxxGzV0t6f1MoxBtttLrYYyCxwihiiGFhLbAdSuZ1wnxcqA9bC7UVECvrQmVTpsMs8UupfHKbQBpZ8OWAqrn" + + "uYNNtG4_4Bt0\",\"n\":\"lygtuZj0lJjqOqIWocF8Bb583QDdq-aaFg8PesOp2-EDda6GqCpL-_NZVOflNGX7XIgjsWHcPsQHs" + + "V9gWuOzSJ0iEuWvtQ6eGBP5M6m7pccLNZfwUse8Cb4Ngx3XiTlyuqM7pv0LPyppZusfEHVEdeelou7Dy9k0OQ_nJTI3b2E1WBoHC5" + + "8CJ453lo4gcBm1efURN3LIVc1V9NQY_ESBKVdwqYyoJPEanURLVGRd6cQKn6YrCbbIRHjqAyqOE-z3KmgDJnPriljfR5XhSGyM9eq" + + "D9Xpy6zu_MAeMJJfSArp857zLPk-Wf5VP9STAcjyfdBIybMKnwBYr2qHMT675hQ\"}]}"; + return new MockResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) + .setResponseCode(200).setBody(body); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/pom.xml new file mode 100644 index 0000000000..28c32b5311 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/pom.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-secure-webflux</artifactId> + <name>Spring Boot Secure WebFlux Smoke Test</name> + <description>Spring Boot Secure WebFlux Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-webflux</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.projectreactor</groupId> + <artifactId>reactor-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <executions> + <execution> + <id>generate build info</id> + <goals> + <goal>build-info</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/java/smoketest/secure/webflux/EchoHandler.java b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/java/smoketest/secure/webflux/EchoHandler.java new file mode 100644 index 0000000000..a57bb40637 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/java/smoketest/secure/webflux/EchoHandler.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.secure.webflux; + +import reactor.core.publisher.Mono; + +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; + +@Component +public class EchoHandler { + + public Mono<ServerResponse> echo(ServerRequest request) { + return ServerResponse.ok().body(request.bodyToMono(String.class), String.class); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/java/smoketest/secure/webflux/SampleSecureWebFluxApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/java/smoketest/secure/webflux/SampleSecureWebFluxApplication.java new file mode 100644 index 0000000000..e044358149 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/java/smoketest/secure/webflux/SampleSecureWebFluxApplication.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.secure.webflux; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.ServerResponse; + +import static org.springframework.web.reactive.function.server.RequestPredicates.POST; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; + +@SpringBootApplication +public class SampleSecureWebFluxApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleSecureWebFluxApplication.class); + } + + @Bean + public RouterFunction<ServerResponse> monoRouterFunction(EchoHandler echoHandler) { + return route(POST("/echo"), echoHandler::echo); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/java/smoketest/secure/webflux/WelcomeController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/java/smoketest/secure/webflux/WelcomeController.java new file mode 100644 index 0000000000..12e4cbdc1c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/java/smoketest/secure/webflux/WelcomeController.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.secure.webflux; + +import java.security.Principal; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class WelcomeController { + + @GetMapping("/") + public String welcome(Principal principal) { + return "Hello " + principal.getName(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-secure-webflux/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-secure-webflux/src/main/resources/static/css/bootstrap.min.css b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/resources/static/css/bootstrap.min.css similarity index 100% rename from spring-boot-samples/spring-boot-sample-secure-webflux/src/main/resources/static/css/bootstrap.min.css rename to spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/main/resources/static/css/bootstrap.min.css diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/ManagementPortSampleSecureWebFluxTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/ManagementPortSampleSecureWebFluxTests.java new file mode 100644 index 0000000000..4a34016b9c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/ManagementPortSampleSecureWebFluxTests.java @@ -0,0 +1,103 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.secure.webflux; + +import java.util.Base64; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest; +import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; +import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; +import org.springframework.boot.autoconfigure.security.reactive.PathRequest; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.web.server.ServerHttpSecurity; +import org.springframework.security.web.server.SecurityWebFilterChain; +import org.springframework.test.web.reactive.server.WebTestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for separate management and main service ports. + * + * @author Madhura Bhave + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port=0" }, classes = { + ManagementPortSampleSecureWebFluxTests.SecurityConfiguration.class, SampleSecureWebFluxApplication.class }) +class ManagementPortSampleSecureWebFluxTests { + + @LocalServerPort + private int port; + + @LocalManagementPort + private int managementPort; + + @Autowired + private WebTestClient webClient; + + @Test + void testHome() { + this.webClient.get().uri("http://localhost:" + this.port, String.class) + .header("Authorization", "basic " + getBasicAuth()).exchange().expectStatus().isOk() + .expectBody(String.class).isEqualTo("Hello user"); + } + + @Test + void actuatorPathOnMainPortShouldNotMatch() { + this.webClient.get().uri("http://localhost:" + this.port + "/actuator", String.class).exchange().expectStatus() + .isUnauthorized(); + this.webClient.get().uri("http://localhost:" + this.port + "/actuator/health", String.class).exchange() + .expectStatus().isUnauthorized(); + } + + @Test + void testSecureActuator() { + this.webClient.get().uri("http://localhost:" + this.managementPort + "/actuator/env", String.class).exchange() + .expectStatus().isUnauthorized(); + } + + @Test + void testInsecureActuator() { + String responseBody = this.webClient.get() + .uri("http://localhost:" + this.managementPort + "/actuator/health", String.class).exchange() + .expectStatus().isOk().expectBody(String.class).returnResult().getResponseBody(); + assertThat(responseBody).contains("\"status\":\"UP\""); + } + + private String getBasicAuth() { + return new String(Base64.getEncoder().encode(("user:password").getBytes())); + } + + @Configuration(proxyBeanMethods = false) + static class SecurityConfiguration { + + @Bean + public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { + return http.authorizeExchange().matchers(EndpointRequest.to("health", "info")).permitAll() + .matchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class)).hasRole("ACTUATOR") + .matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll().pathMatchers("/login") + .permitAll().anyExchange().authenticated().and().httpBasic().and().build(); + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/SampleSecureWebFluxApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/SampleSecureWebFluxApplicationTests.java new file mode 100644 index 0000000000..b2c6817230 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/SampleSecureWebFluxApplicationTests.java @@ -0,0 +1,82 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.secure.webflux; + +import java.util.Base64; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.test.web.reactive.server.WebTestClient; + +/** + * Integration tests for a secure reactive application. + * + * @author Madhura Bhave + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = "management.endpoint.health.show-details=never") +class SampleSecureWebFluxApplicationTests { + + @Autowired + private WebTestClient webClient; + + @Test + void userDefinedMappingsSecureByDefault() { + this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void healthInsecureByDefault() { + this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isOk(); + } + + @Test + void infoInsecureByDefault() { + this.webClient.get().uri("/actuator/info").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk(); + } + + @Test + void otherActuatorsSecureByDefault() { + this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isUnauthorized(); + } + + @Test + void userDefinedMappingsAccessibleOnLogin() { + this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON) + .header("Authorization", "basic " + getBasicAuth()).exchange().expectBody(String.class) + .isEqualTo("Hello user"); + } + + @Test + void actuatorsAccessibleOnLogin() { + this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON) + .header("Authorization", "basic " + getBasicAuth()).exchange().expectBody(String.class) + .isEqualTo("{\"status\":\"UP\"}"); + } + + private String getBasicAuth() { + return new String(Base64.getEncoder().encode(("user:password").getBytes())); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java new file mode 100644 index 0000000000..12ffd4fdf4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-secure-webflux/src/test/java/smoketest/secure/webflux/SampleSecureWebFluxCustomSecurityTests.java @@ -0,0 +1,126 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.secure.webflux; + +import java.util.Base64; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.autoconfigure.security.reactive.EndpointRequest; +import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; +import org.springframework.boot.autoconfigure.security.reactive.PathRequest; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.security.config.web.server.ServerHttpSecurity; +import org.springframework.security.core.userdetails.MapReactiveUserDetailsService; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.web.server.SecurityWebFilterChain; +import org.springframework.test.web.reactive.server.WebTestClient; + +/** + * Integration tests for a secure reactive application with custom security. + * + * @author Madhura Bhave + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { + SampleSecureWebFluxCustomSecurityTests.SecurityConfiguration.class, SampleSecureWebFluxApplication.class }) +class SampleSecureWebFluxCustomSecurityTests { + + @Autowired + private WebTestClient webClient; + + @Test + void userDefinedMappingsSecure() { + this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void healthAndInfoDoNotRequireAuthentication() { + this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isOk(); + this.webClient.get().uri("/actuator/info").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk(); + } + + @Test + void actuatorsSecuredByRole() { + this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON) + .header("Authorization", "basic " + getBasicAuth()).exchange().expectStatus().isForbidden(); + } + + @Test + void actuatorsAccessibleOnCorrectLogin() { + this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON) + .header("Authorization", "basic " + getBasicAuthForAdmin()).exchange().expectStatus().isOk(); + } + + @Test + void actuatorExcludedFromEndpointRequestMatcher() { + this.webClient.get().uri("/actuator/mappings").accept(MediaType.APPLICATION_JSON) + .header("Authorization", "basic " + getBasicAuth()).exchange().expectStatus().isOk(); + } + + @Test + void staticResourceShouldBeAccessible() { + this.webClient.get().uri("/css/bootstrap.min.css").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isOk(); + } + + @Test + void actuatorLinksIsSecure() { + this.webClient.get().uri("/actuator").accept(MediaType.APPLICATION_JSON).exchange().expectStatus() + .isUnauthorized(); + this.webClient.get().uri("/actuator").accept(MediaType.APPLICATION_JSON) + .header("Authorization", "basic " + getBasicAuthForAdmin()).exchange().expectStatus().isOk(); + } + + private String getBasicAuth() { + return new String(Base64.getEncoder().encode(("user:password").getBytes())); + } + + private String getBasicAuthForAdmin() { + return new String(Base64.getEncoder().encode(("admin:admin").getBytes())); + } + + @Configuration(proxyBeanMethods = false) + static class SecurityConfiguration { + + @SuppressWarnings("deprecation") + @Bean + public MapReactiveUserDetailsService userDetailsService() { + return new MapReactiveUserDetailsService( + User.withDefaultPasswordEncoder().username("user").password("password").authorities("ROLE_USER") + .build(), + User.withDefaultPasswordEncoder().username("admin").password("admin") + .authorities("ROLE_ACTUATOR", "ROLE_USER").build()); + } + + @Bean + public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { + return http.authorizeExchange().matchers(EndpointRequest.to("health", "info")).permitAll() + .matchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class)).hasRole("ACTUATOR") + .matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll().pathMatchers("/login") + .permitAll().anyExchange().authenticated().and().httpBasic().and().build(); + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-secure/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-secure/pom.xml new file mode 100644 index 0000000000..27ef9da43f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-secure/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-secure</artifactId> + <name>Spring Boot Security Smoke Test</name> + <description>Spring Boot Security Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/main/java/smoketest/secure/SampleSecureApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/main/java/smoketest/secure/SampleSecureApplication.java new file mode 100644 index 0000000000..5927065c76 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/main/java/smoketest/secure/SampleSecureApplication.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.secure; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.core.authority.AuthorityUtils; +import org.springframework.security.core.context.SecurityContextHolder; + +@EnableAutoConfiguration +@ComponentScan +@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) +public class SampleSecureApplication implements CommandLineRunner { + + @Autowired + private SampleService service; + + @Override + public void run(String... args) throws Exception { + SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("user", "N/A", + AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"))); + try { + System.out.println(this.service.secure()); + } + finally { + SecurityContextHolder.clearContext(); + } + } + + public static void main(String[] args) { + SpringApplication.run(SampleSecureApplication.class, "--debug"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/main/java/smoketest/secure/SampleService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/main/java/smoketest/secure/SampleService.java new file mode 100644 index 0000000000..749ee4590c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/main/java/smoketest/secure/SampleService.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.secure; + +import org.springframework.security.access.annotation.Secured; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; + +@Service +public class SampleService { + + @Secured("ROLE_USER") + public String secure() { + return "Hello Security"; + } + + @PreAuthorize("true") + public String authorized() { + return "Hello World"; + } + + @PreAuthorize("false") + public String denied() { + return "Goodbye World"; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-secure/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-secure/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/test/java/smoketest/secure/SampleSecureApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/test/java/smoketest/secure/SampleSecureApplicationTests.java new file mode 100644 index 0000000000..4a63b387e9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-secure/src/test/java/smoketest/secure/SampleSecureApplicationTests.java @@ -0,0 +1,82 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.secure; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.core.context.SecurityContextHolder; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(classes = { SampleSecureApplication.class }) +class SampleSecureApplicationTests { + + @Autowired + private SampleService service; + + private Authentication authentication; + + @BeforeEach + void init() { + this.authentication = new UsernamePasswordAuthenticationToken("user", "password"); + } + + @AfterEach + void close() { + SecurityContextHolder.clearContext(); + } + + @Test + void secure() { + assertThatExceptionOfType(AuthenticationException.class) + .isThrownBy(() -> SampleSecureApplicationTests.this.service.secure()); + } + + @Test + void authenticated() { + SecurityContextHolder.getContext().setAuthentication(this.authentication); + assertThat("Hello Security").isEqualTo(this.service.secure()); + } + + @Test + void preauth() { + SecurityContextHolder.getContext().setAuthentication(this.authentication); + assertThat("Hello World").isEqualTo(this.service.authorized()); + } + + @Test + void denied() { + SecurityContextHolder.getContext().setAuthentication(this.authentication); + assertThatExceptionOfType(AccessDeniedException.class) + .isThrownBy(() -> SampleSecureApplicationTests.this.service.denied()); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/pom.xml new file mode 100644 index 0000000000..b014e06580 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/pom.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-servlet</artifactId> + <packaging>war</packaging> + <name>Spring Boot Servlet Smoke Test</name> + <description>Spring Boot Servlet Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <!-- Provided --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + <scope>provided</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/src/main/java/smoketest/servlet/SampleServletApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/src/main/java/smoketest/servlet/SampleServletApplication.java new file mode 100644 index 0000000000..cc39d41b46 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/src/main/java/smoketest/servlet/SampleServletApplication.java @@ -0,0 +1,59 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.servlet; + +import java.io.IOException; + +import javax.servlet.GenericServlet; +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.Bean; + +@SpringBootConfiguration +@EnableAutoConfiguration +public class SampleServletApplication extends SpringBootServletInitializer { + + @SuppressWarnings("serial") + @Bean + public Servlet dispatcherServlet() { + return new GenericServlet() { + @Override + public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { + res.setContentType("text/plain"); + res.getWriter().append("Hello World"); + } + }; + } + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleServletApplication.class); + } + + public static void main(String[] args) { + SpringApplication.run(SampleServletApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-servlet/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-servlet/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-servlet/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/src/test/java/smoketest/servlet/SampleServletApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/src/test/java/smoketest/servlet/SampleServletApplicationTests.java new file mode 100644 index 0000000000..516bb92635 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-servlet/src/test/java/smoketest/servlet/SampleServletApplicationTests.java @@ -0,0 +1,68 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.servlet; + +import java.util.Collections; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleServletApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHomeIsSecure() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void testHome() { + ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); + } + + private String getPassword() { + return "password"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/pom.xml new file mode 100644 index 0000000000..4d8bc5cf3a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/pom.xml @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-session-webflux</artifactId> + <name>Spring Boot Session WebFlux Smoke Test</name> + <description>Spring Boot Session WebFlux Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-webflux</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>redis</id> + <dependencies> + <dependency> + <groupId>org.springframework.session</groupId> + <artifactId>spring-session-data-redis</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-redis-reactive</artifactId> + </dependency> + </dependencies> + </profile> + <profile> + <id>mongodb</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <dependencies> + <dependency> + <groupId>org.springframework.session</groupId> + <artifactId>spring-session-data-mongodb</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-mongodb-reactive</artifactId> + </dependency> + <dependency> + <groupId>de.flapdoodle.embed</groupId> + <artifactId>de.flapdoodle.embed.mongo</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/main/java/smoketest/session/HelloRestController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/main/java/smoketest/session/HelloRestController.java new file mode 100644 index 0000000000..0d85e5c45a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/main/java/smoketest/session/HelloRestController.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.session; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.server.WebSession; + +@RestController +public class HelloRestController { + + @GetMapping("/") + String sessionId(WebSession session) { + return session.getId(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/main/java/smoketest/session/SampleSessionWebFluxApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/main/java/smoketest/session/SampleSessionWebFluxApplication.java new file mode 100644 index 0000000000..d06d7f588e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/main/java/smoketest/session/SampleSessionWebFluxApplication.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.session; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.security.config.web.server.ServerHttpSecurity; +import org.springframework.security.web.server.SecurityWebFilterChain; +import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository; + +@SpringBootApplication +public class SampleSessionWebFluxApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleSessionWebFluxApplication.class); + } + + @Bean + public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { + // @formatter:off + return http + .authorizeExchange() + .anyExchange().authenticated() + .and() + .httpBasic().securityContextRepository(new WebSessionServerSecurityContextRepository()) + .and() + .formLogin() + .and() + .build(); + // @formatter:on + } + +} diff --git a/spring-boot-samples/spring-boot-sample-session-webflux/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-session-webflux/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/test/java/smoketest/session/SampleSessionWebFluxApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/test/java/smoketest/session/SampleSessionWebFluxApplicationTests.java new file mode 100644 index 0000000000..abdcc6d06b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-session-webflux/src/test/java/smoketest/session/SampleSessionWebFluxApplicationTests.java @@ -0,0 +1,69 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.session; + +import java.time.Duration; +import java.util.Base64; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseCookie; +import org.springframework.web.reactive.function.client.ClientResponse; +import org.springframework.web.reactive.function.client.WebClient; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link SampleSessionWebFluxApplication}. + * + * @author Vedran Pavic + */ +@SpringBootTest(properties = "server.servlet.session.timeout:2", + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class SampleSessionWebFluxApplicationTests { + + @LocalServerPort + private int port; + + @Autowired + private WebClient.Builder webClientBuilder; + + @Test + void userDefinedMappingsSecureByDefault() throws Exception { + WebClient webClient = this.webClientBuilder.baseUrl("http://localhost:" + this.port + "/").build(); + ClientResponse response = webClient.get().header("Authorization", getBasicAuth()).exchange() + .block(Duration.ofSeconds(30)); + assertThat(response.statusCode()).isEqualTo(HttpStatus.OK); + ResponseCookie sessionCookie = response.cookies().getFirst("SESSION"); + String sessionId = response.bodyToMono(String.class).block(Duration.ofSeconds(30)); + response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30)); + assertThat(response.statusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.bodyToMono(String.class).block(Duration.ofSeconds(30))).isEqualTo(sessionId); + Thread.sleep(2000); + response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30)); + assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + private String getBasicAuth() { + return "Basic " + Base64.getEncoder().encodeToString("user:password".getBytes()); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-session/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-session/pom.xml new file mode 100644 index 0000000000..f1623d905d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-session/pom.xml @@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-session</artifactId> + <name>Spring Boot Session Smoke Test</name> + <description>Spring Boot Session Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>redis</id> + <dependencies> + <dependency> + <groupId>org.springframework.session</groupId> + <artifactId>spring-session-data-redis</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-redis</artifactId> + </dependency> + </dependencies> + </profile> + <profile> + <id>jdbc</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <dependencies> + <dependency> + <groupId>org.springframework.session</groupId> + <artifactId>spring-session-jdbc</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jdbc</artifactId> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + </dependencies> + </profile> + <profile> + <id>hazelcast</id> + <dependencies> + <dependency> + <groupId>org.springframework.session</groupId> + <artifactId>spring-session-hazelcast</artifactId> + </dependency> + <dependency> + <groupId>com.hazelcast</groupId> + <artifactId>hazelcast</artifactId> + </dependency> + </dependencies> + </profile> + <profile> + <id>mongodb</id> + <dependencies> + <dependency> + <groupId>org.springframework.session</groupId> + <artifactId>spring-session-data-mongodb</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-mongodb</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/HelloRestController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/HelloRestController.java new file mode 100644 index 0000000000..961d5ce8bb --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/HelloRestController.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.session; + +import javax.servlet.http.HttpSession; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloRestController { + + @GetMapping("/") + String uid(HttpSession session) { + return session.getId(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/SampleSessionApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/SampleSessionApplication.java new file mode 100644 index 0000000000..1e14afb7fc --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/SampleSessionApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.session; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleSessionApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleSessionApplication.class); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-session/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-session/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-session/src/main/resources/hazelcast.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/hazelcast.xml similarity index 100% rename from spring-boot-samples/spring-boot-sample-session/src/main/resources/hazelcast.xml rename to spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/hazelcast.xml diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/test/java/smoketest/session/SampleSessionApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/test/java/smoketest/session/SampleSessionApplicationTests.java new file mode 100644 index 0000000000..9b04110d6b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/test/java/smoketest/session/SampleSessionApplicationTests.java @@ -0,0 +1,80 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.session; + +import java.net.URI; +import java.util.Base64; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.RequestEntity; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleSessionApplication}. + * + * @author Andy Wilkinson + * @author Vedran Pavic + */ +class SampleSessionApplicationTests { + + @Test + void sessionExpiry() throws Exception { + ConfigurableApplicationContext context = createContext(); + String port = context.getEnvironment().getProperty("local.server.port"); + URI uri = URI.create("http://localhost:" + port + "/"); + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity<String> firstResponse = firstRequest(restTemplate, uri); + String sessionId1 = firstResponse.getBody(); + String cookie = firstResponse.getHeaders().getFirst("Set-Cookie"); + String sessionId2 = nextRequest(restTemplate, uri, cookie).getBody(); + assertThat(sessionId1).isEqualTo(sessionId2); + Thread.sleep(1000); + String loginPage = nextRequest(restTemplate, uri, cookie).getBody(); + assertThat(loginPage).containsIgnoringCase("login"); + } + + private ConfigurableApplicationContext createContext() { + ConfigurableApplicationContext context = new SpringApplicationBuilder().sources(SampleSessionApplication.class) + .properties("server.port:0", "server.servlet.session.timeout:1") + .initializers(new ServerPortInfoApplicationContextInitializer()).run(); + return context; + } + + private ResponseEntity<String> firstRequest(RestTemplate restTemplate, URI uri) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Authorization", "Basic " + Base64.getEncoder().encodeToString("user:password".getBytes())); + RequestEntity<Object> request = new RequestEntity<>(headers, HttpMethod.GET, uri); + return restTemplate.exchange(request, String.class); + } + + private ResponseEntity<String> nextRequest(RestTemplate restTemplate, URI uri, String cookie) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Cookie", cookie); + RequestEntity<Object> request = new RequestEntity<>(headers, HttpMethod.GET, uri); + return restTemplate.exchange(request, String.class); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-simple/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/pom.xml new file mode 100644 index 0000000000..e31db64c70 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/pom.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-simple</artifactId> + <name>Spring Boot Simple Smoke Test</name> + <description>Spring Boot Simple Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>jakarta.validation</groupId> + <artifactId>jakarta.validation-api</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.hibernate.validator</groupId> + <artifactId>hibernate-validator</artifactId> + <exclusions> + <exclusion> + <groupId>javax.validation</groupId> + <artifactId>validation-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/ExitException.java b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/ExitException.java new file mode 100644 index 0000000000..43d49d639a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/ExitException.java @@ -0,0 +1,28 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.simple; + +import org.springframework.boot.ExitCodeGenerator; + +public class ExitException extends RuntimeException implements ExitCodeGenerator { + + @Override + public int getExitCode() { + return 10; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/SampleConfigurationProperties.java b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/SampleConfigurationProperties.java new file mode 100644 index 0000000000..9c9465f07f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/SampleConfigurationProperties.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.simple; + +import javax.validation.constraints.NotNull; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.validation.annotation.Validated; + +@Validated +@ConfigurationProperties(prefix = "sample") +public class SampleConfigurationProperties { + + @NotNull + private String name; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/SampleSimpleApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/SampleSimpleApplication.java new file mode 100644 index 0000000000..2c59d0a836 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/SampleSimpleApplication.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.simple; + +import smoketest.simple.service.HelloWorldService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleSimpleApplication implements CommandLineRunner { + + // Simple example shows how a command line spring application can execute an + // injected bean service. Also demonstrates how you can use @Value to inject + // command line args ('--name=whatever') or application properties + + @Autowired + private HelloWorldService helloWorldService; + + @Override + public void run(String... args) { + System.out.println(this.helloWorldService.getHelloMessage()); + if (args.length > 0 && args[0].equals("exitcode")) { + throw new ExitException(); + } + } + + public static void main(String[] args) { + SpringApplication.run(SampleSimpleApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/service/HelloWorldService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/service/HelloWorldService.java new file mode 100644 index 0000000000..f89c1f5564 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/java/smoketest/simple/service/HelloWorldService.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.simple.service; + +import java.time.Duration; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class HelloWorldService { + + @Value("${name:World}") + private String name; + + @Value("${duration:10s}") + private Duration duration; + + public String getHelloMessage() { + return "Hello " + this.name + " for " + this.duration.getSeconds() + " seconds"; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-simple/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-simple/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-simple/src/main/resources/banner.jpg b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/resources/banner.jpg similarity index 100% rename from spring-boot-samples/spring-boot-sample-simple/src/main/resources/banner.jpg rename to spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/resources/banner.jpg diff --git a/spring-boot-samples/spring-boot-sample-simple/src/main/resources/banner.txt b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/resources/banner.txt similarity index 100% rename from spring-boot-samples/spring-boot-sample-simple/src/main/resources/banner.txt rename to spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/main/resources/banner.txt diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/test/java/smoketest/simple/SampleSimpleApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/test/java/smoketest/simple/SampleSimpleApplicationTests.java new file mode 100644 index 0000000000..069a3da53e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/test/java/smoketest/simple/SampleSimpleApplicationTests.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.simple; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleSimpleApplication}. + * + * @author Dave Syer + * @author Phillip Webb + */ +@ExtendWith(OutputCaptureExtension.class) +class SampleSimpleApplicationTests { + + private String profiles; + + @BeforeEach + void init() { + this.profiles = System.getProperty("spring.profiles.active"); + } + + @AfterEach + void after() { + if (this.profiles != null) { + System.setProperty("spring.profiles.active", this.profiles); + } + else { + System.clearProperty("spring.profiles.active"); + } + } + + @Test + void testDefaultSettings(CapturedOutput capturedOutput) { + SampleSimpleApplication.main(new String[0]); + assertThat(capturedOutput).contains("Hello Phil"); + } + + @Test + void testCommandLineOverrides(CapturedOutput capturedOutput) { + SampleSimpleApplication.main(new String[] { "--name=Gordon", "--duration=1m" }); + assertThat(capturedOutput).contains("Hello Gordon for 60 seconds"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/test/java/smoketest/simple/SpringTestSampleSimpleApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/test/java/smoketest/simple/SpringTestSampleSimpleApplicationTests.java new file mode 100644 index 0000000000..0d86cfd13e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-simple/src/test/java/smoketest/simple/SpringTestSampleSimpleApplicationTests.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.simple; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleSimpleApplication}. + * + * @author Dave Syer + */ +@SpringBootTest +class SpringTestSampleSimpleApplicationTests { + + @Autowired + ApplicationContext ctx; + + @Test + void testContextLoads() { + assertThat(this.ctx).isNotNull(); + assertThat(this.ctx.containsBean("helloWorldService")).isTrue(); + assertThat(this.ctx.containsBean("sampleSimpleApplication")).isTrue(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/pom.xml new file mode 100644 index 0000000000..ef5cd9c2f4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/pom.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-test-nomockito</artifactId> + <name>Spring Boot Test No Mockito Smoke Test</name> + <description>Spring Boot Test No Mockito Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/src/main/java/smoketest/testnomockito/SampleTestNoMockitoApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/src/main/java/smoketest/testnomockito/SampleTestNoMockitoApplication.java new file mode 100644 index 0000000000..6d25e1a206 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/src/main/java/smoketest/testnomockito/SampleTestNoMockitoApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.testnomockito; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleTestNoMockitoApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleTestNoMockitoApplication.class); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/src/test/java/smoketest/testnomockito/SampleTestNoMockitoApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/src/test/java/smoketest/testnomockito/SampleTestNoMockitoApplicationTests.java new file mode 100644 index 0000000000..a80cac8505 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test-nomockito/src/test/java/smoketest/testnomockito/SampleTestNoMockitoApplicationTests.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.testnomockito; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests that {@code ResetMocksTestExecutionListener} and + * {@code MockitoTestExecutionListener} gracefully degrade when Mockito is not on the + * classpath. + * + * @author Madhura Bhave + */ +@ExtendWith(SpringExtension.class) +class SampleTestNoMockitoApplicationTests { + + // gh-7065 + + @Autowired + private ApplicationContext context; + + @Test + void contextLoads() throws Exception { + assertThat(this.context).isNotNull(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-test/pom.xml new file mode 100644 index 0000000000..7cbe489a2c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/pom.xml @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-test</artifactId> + <name>Spring Boot Test Smoke Test</name> + <description>Spring Boot Test Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-api</artifactId> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>htmlunit-driver</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>net.sourceforge.htmlunit</groupId> + <artifactId>htmlunit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>java9+</id> + <activation> + <jdk>[9,)</jdk> + </activation> + <dependencies> + <dependency> + <groupId>jakarta.xml.bind</groupId> + <artifactId>jakarta.xml.bind-api</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/SampleTestApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/SampleTestApplication.java new file mode 100644 index 0000000000..a0bb31155d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/SampleTestApplication.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Sample application to demonstrate testing. + * + * @author Phillip Webb + */ +@SpringBootApplication +public class SampleTestApplication { + + // NOTE: this application will intentionally not start without MySQL, the test will + // still run. + + public static void main(String[] args) { + SpringApplication.run(SampleTestApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/WelcomeCommandLineRunner.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/WelcomeCommandLineRunner.java new file mode 100644 index 0000000000..4d832ea1a8 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/WelcomeCommandLineRunner.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +/** + * Simple component that just prints a message. Used to show how different types of + * integration tests work. + * + * @author Phillip Webb + */ +@Component +public class WelcomeCommandLineRunner implements CommandLineRunner { + + @Override + public void run(String... args) throws Exception { + System.out.println("***** WELCOME TO THE DEMO *****"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/User.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/User.java new file mode 100644 index 0000000000..5272afcfc4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/User.java @@ -0,0 +1,65 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.springframework.util.Assert; + +/** + * A user of the system. + * + * @author Phillip Webb + */ +@Entity +public class User { + + @Id + @GeneratedValue + private Long id; + + @Column(unique = true) + private String username; + + private VehicleIdentificationNumber vin; + + protected User() { + } + + public User(String username, VehicleIdentificationNumber vin) { + Assert.hasLength(username, "Username must not be empty"); + Assert.notNull(vin, "VIN must not be null"); + this.username = username; + this.vin = vin; + } + + public Long getId() { + return this.id; + } + + public String getUsername() { + return this.username; + } + + public VehicleIdentificationNumber getVin() { + return this.vin; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/UserRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/UserRepository.java new file mode 100644 index 0000000000..3bdea2f0a9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/UserRepository.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.domain; + +import org.springframework.data.repository.Repository; + +/** + * Domain repository for {@link User}. + * + * @author Phillip Webb + */ +public interface UserRepository extends Repository<User, Long> { + + User findByUsername(String username); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/VehicleIdentificationNumber.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/VehicleIdentificationNumber.java new file mode 100644 index 0000000000..1ba5e38834 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/VehicleIdentificationNumber.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.domain; + +import org.springframework.util.Assert; + +/** + * A Vehicle Identification Number. + * + * @author Phillip Webb + */ +public final class VehicleIdentificationNumber { + + private String vin; + + public VehicleIdentificationNumber(String vin) { + Assert.notNull(vin, "VIN must not be null"); + Assert.isTrue(vin.length() == 17, "VIN must be exactly 17 characters"); + this.vin = vin; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj == null || obj.getClass() != getClass()) { + return false; + } + return this.vin.equals(((VehicleIdentificationNumber) obj).vin); + } + + @Override + public int hashCode() { + return this.vin.hashCode(); + } + + @Override + public String toString() { + return this.vin; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/VehicleIdentificationNumberAttributeConverter.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/VehicleIdentificationNumberAttributeConverter.java new file mode 100644 index 0000000000..0fe8dd28ae --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/VehicleIdentificationNumberAttributeConverter.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.domain; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +/** + * JPA {@link AttributeConverter} for {@link VehicleIdentificationNumber}. + * + * @author Phillip Webb + */ +@Converter(autoApply = true) +public class VehicleIdentificationNumberAttributeConverter + implements AttributeConverter<VehicleIdentificationNumber, String> { + + @Override + public String convertToDatabaseColumn(VehicleIdentificationNumber attribute) { + return attribute.toString(); + } + + @Override + public VehicleIdentificationNumber convertToEntityAttribute(String dbData) { + return new VehicleIdentificationNumber(dbData); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/RemoteVehicleDetailsService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/RemoteVehicleDetailsService.java new file mode 100644 index 0000000000..50fcb92b2c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/RemoteVehicleDetailsService.java @@ -0,0 +1,62 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.service; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import smoketest.test.domain.VehicleIdentificationNumber; + +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; +import org.springframework.web.client.HttpStatusCodeException; +import org.springframework.web.client.RestTemplate; + +/** + * {@link VehicleDetailsService} backed by a remote REST service. + * + * @author Phillip Webb + */ +@Service +public class RemoteVehicleDetailsService implements VehicleDetailsService { + + private static final Log logger = LogFactory.getLog(RemoteVehicleDetailsService.class); + + private final RestTemplate restTemplate; + + public RemoteVehicleDetailsService(ServiceProperties properties, RestTemplateBuilder restTemplateBuilder) { + this.restTemplate = restTemplateBuilder.rootUri(properties.getVehicleServiceRootUrl()).build(); + } + + @Override + public VehicleDetails getVehicleDetails(VehicleIdentificationNumber vin) + throws VehicleIdentificationNumberNotFoundException { + Assert.notNull(vin, "VIN must not be null"); + logger.debug("Retrieving vehicle data for: " + vin); + try { + return this.restTemplate.getForObject("/vehicle/{vin}/details", VehicleDetails.class, vin); + } + catch (HttpStatusCodeException ex) { + if (HttpStatus.NOT_FOUND.equals(ex.getStatusCode())) { + throw new VehicleIdentificationNumberNotFoundException(vin, ex); + } + throw ex; + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/ServiceProperties.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/ServiceProperties.java new file mode 100644 index 0000000000..eb6466a0c1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/ServiceProperties.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.service; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Properties for the service. + * + * @author Phillip Webb + */ +@ConfigurationProperties +public class ServiceProperties { + + private String vehicleServiceRootUrl = "http://localhost:8080/vs"; + + public String getVehicleServiceRootUrl() { + return this.vehicleServiceRootUrl; + } + + public void setVehicleServiceRootUrl(String vehicleServiceRootUrl) { + this.vehicleServiceRootUrl = vehicleServiceRootUrl; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleDetails.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleDetails.java new file mode 100644 index 0000000000..5fde639205 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleDetails.java @@ -0,0 +1,68 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.springframework.util.Assert; + +/** + * Details of a single vehicle. + * + * @author Phillip Webb + */ +public class VehicleDetails { + + private final String make; + + private final String model; + + @JsonCreator + public VehicleDetails(@JsonProperty("make") String make, @JsonProperty("model") String model) { + Assert.notNull(make, "Make must not be null"); + Assert.notNull(model, "Model must not be null"); + this.make = make; + this.model = model; + } + + public String getMake() { + return this.make; + } + + public String getModel() { + return this.model; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj == null || obj.getClass() != getClass()) { + return false; + } + VehicleDetails other = (VehicleDetails) obj; + return this.make.equals(other.make) && this.model.equals(other.model); + } + + @Override + public int hashCode() { + return this.make.hashCode() * 31 + this.model.hashCode(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleDetailsService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleDetailsService.java new file mode 100644 index 0000000000..6f855328f2 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleDetailsService.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.service; + +import smoketest.test.domain.VehicleIdentificationNumber; + +/** + * A service to obtain {@link VehicleDetails} given a {@link VehicleIdentificationNumber}. + * + * @author Phillip Webb + */ +public interface VehicleDetailsService { + + /** + * Get vehicle details for a given {@link VehicleIdentificationNumber}. + * @param vin the vehicle identification number + * @return vehicle details + * @throws VehicleIdentificationNumberNotFoundException if the VIN is not known + */ + VehicleDetails getVehicleDetails(VehicleIdentificationNumber vin) + throws VehicleIdentificationNumberNotFoundException; + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleIdentificationNumberNotFoundException.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleIdentificationNumberNotFoundException.java new file mode 100644 index 0000000000..2ddae0c5c7 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleIdentificationNumberNotFoundException.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.service; + +import smoketest.test.domain.VehicleIdentificationNumber; + +/** + * Exception thrown when a {@link VehicleIdentificationNumber} is not found. + * + * @author Phillip Webb + */ +public class VehicleIdentificationNumberNotFoundException extends RuntimeException { + + private final VehicleIdentificationNumber vehicleIdentificationNumber; + + public VehicleIdentificationNumberNotFoundException(VehicleIdentificationNumber vin) { + this(vin, null); + } + + public VehicleIdentificationNumberNotFoundException(VehicleIdentificationNumber vin, Throwable cause) { + super("Unable to find VehicleIdentificationNumber " + vin, cause); + this.vehicleIdentificationNumber = vin; + } + + public VehicleIdentificationNumber getVehicleIdentificationNumber() { + return this.vehicleIdentificationNumber; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/web/UserNameNotFoundException.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/web/UserNameNotFoundException.java new file mode 100644 index 0000000000..7d07745216 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/web/UserNameNotFoundException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.web; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(HttpStatus.NOT_FOUND) +public class UserNameNotFoundException extends RuntimeException { + + private final String username; + + public UserNameNotFoundException(String username) { + this.username = username; + } + + public String getUsername() { + return this.username; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/web/UserVehicleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/web/UserVehicleController.java new file mode 100644 index 0000000000..2ccd660407 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/web/UserVehicleController.java @@ -0,0 +1,68 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.web; + +import smoketest.test.domain.User; +import smoketest.test.service.VehicleDetails; +import smoketest.test.service.VehicleIdentificationNumberNotFoundException; + +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +/** + * Controller to return vehicle information for a given {@link User}. + * + * @author Phillip Webb + */ +@RestController +public class UserVehicleController { + + private UserVehicleService userVehicleService; + + public UserVehicleController(UserVehicleService userVehicleService) { + this.userVehicleService = userVehicleService; + } + + @GetMapping(path = "/{username}/vehicle", produces = MediaType.TEXT_PLAIN_VALUE) + public String getVehicleDetailsText(@PathVariable String username) { + VehicleDetails details = this.userVehicleService.getVehicleDetails(username); + return details.getMake() + " " + details.getModel(); + } + + @GetMapping(path = "/{username}/vehicle", produces = MediaType.APPLICATION_JSON_VALUE) + public VehicleDetails VehicleDetailsJson(@PathVariable String username) { + return this.userVehicleService.getVehicleDetails(username); + } + + @GetMapping(path = "/{username}/vehicle.html", produces = MediaType.TEXT_HTML_VALUE) + public String VehicleDetailsHtml(@PathVariable String username) { + VehicleDetails details = this.userVehicleService.getVehicleDetails(username); + String makeAndModel = details.getMake() + " " + details.getModel(); + return "<html><body><h1>" + makeAndModel + "</h1></body></html>"; + } + + @ExceptionHandler + @ResponseStatus(HttpStatus.NOT_FOUND) + private void handleVinNotFound(VehicleIdentificationNumberNotFoundException ex) { + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/web/UserVehicleService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/web/UserVehicleService.java new file mode 100644 index 0000000000..1502d6246f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/java/smoketest/test/web/UserVehicleService.java @@ -0,0 +1,55 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.web; + +import smoketest.test.domain.User; +import smoketest.test.domain.UserRepository; +import smoketest.test.service.VehicleDetails; +import smoketest.test.service.VehicleDetailsService; +import smoketest.test.service.VehicleIdentificationNumberNotFoundException; + +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; + +/** + * Controller service used to provide vehicle information for a given user. + * + * @author Phillip Webb + */ +@Component +public class UserVehicleService { + + private final UserRepository userRepository; + + private final VehicleDetailsService vehicleDetailsService; + + public UserVehicleService(UserRepository userRepository, VehicleDetailsService vehicleDetailsService) { + this.userRepository = userRepository; + this.vehicleDetailsService = vehicleDetailsService; + } + + public VehicleDetails getVehicleDetails(String username) + throws UserNameNotFoundException, VehicleIdentificationNumberNotFoundException { + Assert.notNull(username, "Username must not be null"); + User user = this.userRepository.findByUsername(username); + if (user == null) { + throw new UserNameNotFoundException(username); + } + return this.vehicleDetailsService.getVehicleDetails(user.getVin()); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-test/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-test/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/SampleTestApplicationWebIntegrationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/SampleTestApplicationWebIntegrationTests.java new file mode 100644 index 0000000000..966badeca5 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/SampleTestApplicationWebIntegrationTests.java @@ -0,0 +1,61 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import smoketest.test.domain.VehicleIdentificationNumber; +import smoketest.test.service.VehicleDetails; +import smoketest.test.service.VehicleDetailsService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.web.client.TestRestTemplate; + +import static org.mockito.BDDMockito.given; + +/** + * {@code @SpringBootTest} with a random port for {@link SampleTestApplication}. + * + * @author Phillip Webb + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@AutoConfigureTestDatabase +class SampleTestApplicationWebIntegrationTests { + + private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("01234567890123456"); + + @Autowired + private TestRestTemplate restTemplate; + + @MockBean + private VehicleDetailsService vehicleDetailsService; + + @BeforeEach + void setup() { + given(this.vehicleDetailsService.getVehicleDetails(VIN)).willReturn(new VehicleDetails("Honda", "Civic")); + } + + @Test + void test() { + this.restTemplate.getForEntity("/{username}/vehicle", String.class, "sframework"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/domain/UserEntityTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/domain/UserEntityTests.java new file mode 100644 index 0000000000..4ba858a629 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/domain/UserEntityTests.java @@ -0,0 +1,66 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.domain; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; + +/** + * Data JPA tests for {@link User}. + * + * @author Phillip Webb + */ +@DataJpaTest +class UserEntityTests { + + private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("00000000000000000"); + + @Autowired + private TestEntityManager entityManager; + + @Test + void createWhenUsernameIsNullShouldThrowException() { + assertThatIllegalArgumentException().isThrownBy(() -> new User(null, VIN)) + .withMessage("Username must not be empty"); + } + + @Test + void createWhenUsernameIsEmptyShouldThrowException() { + assertThatIllegalArgumentException().isThrownBy(() -> new User("", VIN)) + .withMessage("Username must not be empty"); + } + + @Test + void createWhenVinIsNullShouldThrowException() { + assertThatIllegalArgumentException().isThrownBy(() -> new User("sboot", null)) + .withMessage("VIN must not be null"); + } + + @Test + void saveShouldPersistData() { + User user = this.entityManager.persistFlushFind(new User("sboot", VIN)); + assertThat(user.getUsername()).isEqualTo("sboot"); + assertThat(user.getVin()).isEqualTo(VIN); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/domain/UserRepositoryTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/domain/UserRepositoryTests.java new file mode 100644 index 0000000000..323b2e8ecd --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/domain/UserRepositoryTests.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.domain; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link UserRepository}. + * + * @author Phillip Webb + */ +@DataJpaTest +class UserRepositoryTests { + + private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("00000000000000000"); + + @Autowired + private TestEntityManager entityManager; + + @Autowired + private UserRepository repository; + + @Test + void findByUsernameShouldReturnUser() { + this.entityManager.persist(new User("sboot", VIN)); + User user = this.repository.findByUsername("sboot"); + assertThat(user.getUsername()).isEqualTo("sboot"); + assertThat(user.getVin()).isEqualTo(VIN); + } + + @Test + void findByUsernameWhenNoUserShouldReturnNull() { + this.entityManager.persist(new User("sboot", VIN)); + User user = this.repository.findByUsername("mmouse"); + assertThat(user).isNull(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/domain/VehicleIdentificationNumberTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/domain/VehicleIdentificationNumberTests.java new file mode 100644 index 0000000000..eb271a2c71 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/domain/VehicleIdentificationNumberTests.java @@ -0,0 +1,69 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.domain; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; + +/** + * Tests for {@link VehicleIdentificationNumber}. + * + * @author Phillip Webb + * @see <a href="https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html"> + * Naming standards for unit tests</a> + * @see <a href="https://joel-costigliola.github.io/assertj/">AssertJ</a> + */ +class VehicleIdentificationNumberTests { + + private static final String SAMPLE_VIN = "41549485710496749"; + + @Test + void createWhenVinIsNullShouldThrowException() { + assertThatIllegalArgumentException().isThrownBy(() -> new VehicleIdentificationNumber(null)) + .withMessage("VIN must not be null"); + } + + @Test + void createWhenVinIsMoreThan17CharsShouldThrowException() { + assertThatIllegalArgumentException().isThrownBy(() -> new VehicleIdentificationNumber("012345678901234567")) + .withMessage("VIN must be exactly 17 characters"); + } + + @Test + void createWhenVinIsLessThan17CharsShouldThrowException() { + assertThatIllegalArgumentException().isThrownBy(() -> new VehicleIdentificationNumber("0123456789012345")) + .withMessage("VIN must be exactly 17 characters"); + } + + @Test + void toStringShouldReturnVin() { + VehicleIdentificationNumber vin = new VehicleIdentificationNumber(SAMPLE_VIN); + assertThat(vin.toString()).isEqualTo(SAMPLE_VIN); + } + + @Test + void equalsAndHashCodeShouldBeBasedOnVin() { + VehicleIdentificationNumber vin1 = new VehicleIdentificationNumber(SAMPLE_VIN); + VehicleIdentificationNumber vin2 = new VehicleIdentificationNumber(SAMPLE_VIN); + VehicleIdentificationNumber vin3 = new VehicleIdentificationNumber("00000000000000000"); + assertThat(vin1.hashCode()).isEqualTo(vin2.hashCode()); + assertThat(vin1).isEqualTo(vin1).isEqualTo(vin2).isNotEqualTo(vin3); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/service/RemoteVehicleDetailsServiceTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/service/RemoteVehicleDetailsServiceTests.java new file mode 100644 index 0000000000..ebd4baf9c2 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/service/RemoteVehicleDetailsServiceTests.java @@ -0,0 +1,87 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.service; + +import org.junit.jupiter.api.Test; +import smoketest.test.domain.VehicleIdentificationNumber; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.test.web.client.MockRestServiceServer; +import org.springframework.web.client.HttpServerErrorException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withServerError; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; + +/** + * Tests for {@link RemoteVehicleDetailsService}. + * + * @author Phillip Webb + */ +@RestClientTest({ RemoteVehicleDetailsService.class, ServiceProperties.class }) +class RemoteVehicleDetailsServiceTests { + + private static final String VIN = "00000000000000000"; + + @Autowired + private RemoteVehicleDetailsService service; + + @Autowired + private MockRestServiceServer server; + + @Test + void getVehicleDetailsWhenVinIsNullShouldThrowException() { + assertThatIllegalArgumentException().isThrownBy(() -> this.service.getVehicleDetails(null)) + .withMessage("VIN must not be null"); + } + + @Test + void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails() { + this.server.expect(requestTo("/vehicle/" + VIN + "/details")) + .andRespond(withSuccess(getClassPathResource("vehicledetails.json"), MediaType.APPLICATION_JSON)); + VehicleDetails details = this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN)); + assertThat(details.getMake()).isEqualTo("Honda"); + assertThat(details.getModel()).isEqualTo("Civic"); + } + + @Test + void getVehicleDetailsWhenResultIsNotFoundShouldThrowException() { + this.server.expect(requestTo("/vehicle/" + VIN + "/details")).andRespond(withStatus(HttpStatus.NOT_FOUND)); + assertThatExceptionOfType(VehicleIdentificationNumberNotFoundException.class) + .isThrownBy(() -> this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN))); + } + + @Test + void getVehicleDetailsWhenResultIServerErrorShouldThrowException() { + this.server.expect(requestTo("/vehicle/" + VIN + "/details")).andRespond(withServerError()); + assertThatExceptionOfType(HttpServerErrorException.class) + .isThrownBy(() -> this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN))); + } + + private ClassPathResource getClassPathResource(String path) { + return new ClassPathResource(path, getClass()); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/service/VehicleDetailsJsonTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/service/VehicleDetailsJsonTests.java new file mode 100644 index 0000000000..c3df1d97f9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/service/VehicleDetailsJsonTests.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.service; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.JsonTest; +import org.springframework.boot.test.json.JacksonTester; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * JSON tests for {@link VehicleDetails}. + * + * @author Phillip Webb + */ +@JsonTest +class VehicleDetailsJsonTests { + + @Autowired + private JacksonTester<VehicleDetails> json; + + @Test + void serializeJson() throws Exception { + VehicleDetails details = new VehicleDetails("Honda", "Civic"); + assertThat(this.json.write(details)).isEqualTo("vehicledetails.json"); + assertThat(this.json.write(details)).isEqualToJson("vehicledetails.json"); + assertThat(this.json.write(details)).hasJsonPathStringValue("@.make"); + assertThat(this.json.write(details)).extractingJsonPathStringValue("@.make").isEqualTo("Honda"); + } + + @Test + void deserializeJson() throws Exception { + String content = "{\"make\":\"Ford\",\"model\":\"Focus\"}"; + assertThat(this.json.parse(content)).isEqualTo(new VehicleDetails("Ford", "Focus")); + assertThat(this.json.parseObject(content).getMake()).isEqualTo("Ford"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerApplicationTests.java new file mode 100644 index 0000000000..55e3f0158d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerApplicationTests.java @@ -0,0 +1,70 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.web; + +import org.junit.jupiter.api.Test; +import smoketest.test.WelcomeCommandLineRunner; +import smoketest.test.service.VehicleDetails; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.ApplicationContext; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * {@code @SpringBootTest} based tests for {@link UserVehicleController}. + * + * @author Phillip Webb + */ +@SpringBootTest +@AutoConfigureMockMvc +@AutoConfigureTestDatabase +class UserVehicleControllerApplicationTests { + + @Autowired + private MockMvc mvc; + + @Autowired + private ApplicationContext applicationContext; + + @MockBean + private UserVehicleService userVehicleService; + + @Test + void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception { + given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); + this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk()) + .andExpect(content().string("Honda Civic")); + } + + @Test + void welcomeCommandLineRunnerShouldBeAvailable() { + // Since we're a @SpringBootTest all beans should be available. + assertThat(this.applicationContext.getBean(WelcomeCommandLineRunner.class)).isNotNull(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerHtmlUnitTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerHtmlUnitTests.java new file mode 100644 index 0000000000..838c8df5af --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerHtmlUnitTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.web; + +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.HtmlPage; +import org.junit.jupiter.api.Test; +import smoketest.test.service.VehicleDetails; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; + +/** + * HtmlUnit based tests for {@link UserVehicleController}. + * + * @author Phillip Webb + */ +@WebMvcTest(UserVehicleController.class) +class UserVehicleControllerHtmlUnitTests { + + @Autowired + private WebClient webClient; + + @MockBean + private UserVehicleService userVehicleService; + + @Test + void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception { + given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); + HtmlPage page = this.webClient.getPage("/sboot/vehicle.html"); + assertThat(page.getBody().getTextContent()).isEqualTo("Honda Civic"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerSeleniumTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerSeleniumTests.java new file mode 100644 index 0000000000..45cc0f4c2a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerSeleniumTests.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.web; + +import org.junit.jupiter.api.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import smoketest.test.service.VehicleDetails; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; + +/** + * Selenium based tests for {@link UserVehicleController}. + * + * @author Phillip Webb + */ +@WebMvcTest(UserVehicleController.class) +class UserVehicleControllerSeleniumTests { + + @Autowired + private WebDriver webDriver; + + @MockBean + private UserVehicleService userVehicleService; + + @Test + void getVehicleWhenRequestingTextShouldReturnMakeAndModel() { + given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); + this.webDriver.get("/sboot/vehicle.html"); + WebElement element = this.webDriver.findElement(By.tagName("h1")); + assertThat(element.getText()).isEqualTo("Honda Civic"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerTests.java new file mode 100644 index 0000000000..75246b7ab6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleControllerTests.java @@ -0,0 +1,100 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.web; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import smoketest.test.WelcomeCommandLineRunner; +import smoketest.test.domain.VehicleIdentificationNumber; +import smoketest.test.service.VehicleDetails; +import smoketest.test.service.VehicleIdentificationNumberNotFoundException; + +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.ApplicationContext; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; + +import static org.hamcrest.Matchers.containsString; +import static org.mockito.BDDMockito.given; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * {@code @WebMvcTest} based tests for {@link UserVehicleController}. + * + * @author Phillip Webb + */ +@WebMvcTest(UserVehicleController.class) +class UserVehicleControllerTests { + + private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("00000000000000000"); + + @Autowired + private MockMvc mvc; + + @Autowired + private ApplicationContext applicationContext; + + @MockBean + private UserVehicleService userVehicleService; + + @Test + void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception { + given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); + this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk()) + .andExpect(content().string("Honda Civic")); + } + + @Test + void getVehicleWhenRequestingJsonShouldReturnMakeAndModel() throws Exception { + given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); + this.mvc.perform(get("/sboot/vehicle").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()) + .andExpect(content().json("{'make':'Honda','model':'Civic'}")); + } + + @Test + void getVehicleWhenRequestingHtmlShouldReturnMakeAndModel() throws Exception { + given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic")); + this.mvc.perform(get("/sboot/vehicle.html").accept(MediaType.TEXT_HTML)).andExpect(status().isOk()) + .andExpect(content().string(containsString("<h1>Honda Civic</h1>"))); + } + + @Test + void getVehicleWhenUserNotFoundShouldReturnNotFound() throws Exception { + given(this.userVehicleService.getVehicleDetails("sboot")).willThrow(new UserNameNotFoundException("sboot")); + this.mvc.perform(get("/sboot/vehicle")).andExpect(status().isNotFound()); + } + + @Test + void getVehicleWhenVinNotFoundShouldReturnNotFound() throws Exception { + given(this.userVehicleService.getVehicleDetails("sboot")) + .willThrow(new VehicleIdentificationNumberNotFoundException(VIN)); + this.mvc.perform(get("/sboot/vehicle")).andExpect(status().isNotFound()); + } + + @Test + void welcomeCommandLineRunnerShouldBeAvailable() { + // Since we're a @WebMvcTest WelcomeCommandLineRunner should not be available. + Assertions.assertThatThrownBy(() -> this.applicationContext.getBean(WelcomeCommandLineRunner.class)) + .isInstanceOf(NoSuchBeanDefinitionException.class); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleServiceTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleServiceTests.java new file mode 100644 index 0000000000..600cf830a9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleServiceTests.java @@ -0,0 +1,80 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.test.web; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import smoketest.test.domain.User; +import smoketest.test.domain.UserRepository; +import smoketest.test.domain.VehicleIdentificationNumber; +import smoketest.test.service.VehicleDetails; +import smoketest.test.service.VehicleDetailsService; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.given; + +/** + * Tests for {@link UserVehicleService}. + * + * @author Phillip Webb + */ +class UserVehicleServiceTests { + + private static final VehicleIdentificationNumber VIN = new VehicleIdentificationNumber("00000000000000000"); + + @Mock + private VehicleDetailsService vehicleDetailsService; + + @Mock + private UserRepository userRepository; + + private UserVehicleService service; + + @BeforeEach + void setup() { + MockitoAnnotations.initMocks(this); + this.service = new UserVehicleService(this.userRepository, this.vehicleDetailsService); + } + + @Test + void getVehicleDetailsWhenUsernameIsNullShouldThrowException() { + assertThatIllegalArgumentException().isThrownBy(() -> this.service.getVehicleDetails(null)) + .withMessage("Username must not be null"); + } + + @Test + void getVehicleDetailsWhenUsernameNotFoundShouldThrowException() { + given(this.userRepository.findByUsername(anyString())).willReturn(null); + assertThatExceptionOfType(UserNameNotFoundException.class) + .isThrownBy(() -> this.service.getVehicleDetails("sboot")); + } + + @Test + void getVehicleDetailsShouldReturnMakeAndModel() { + given(this.userRepository.findByUsername(anyString())).willReturn(new User("sboot", VIN)); + VehicleDetails details = new VehicleDetails("Honda", "Civic"); + given(this.vehicleDetailsService.getVehicleDetails(VIN)).willReturn(details); + VehicleDetails actual = this.service.getVehicleDetails("sboot"); + assertThat(actual).isEqualTo(details); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-test/src/test/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/resources/data.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/resources/data.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-test/src/test/resources/data.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/resources/data.sql diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/resources/sample/test/service/vehicledetails.json b/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/resources/smoketest/test/service/vehicledetails.json similarity index 100% rename from spring-boot-samples/spring-boot-sample-test/src/test/resources/sample/test/service/vehicledetails.json rename to spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/resources/smoketest/test/service/vehicledetails.json diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-testng/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-testng/pom.xml new file mode 100644 index 0000000000..2a0a69fde1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-testng/pom.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-testng</artifactId> + <name>Spring Boot TestNG Smoke Test</name> + <description>Spring Boot TestNG Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-webmvc</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>6.8.13</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/java/smoketest/testng/SampleTestNGApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/java/smoketest/testng/SampleTestNGApplication.java new file mode 100644 index 0000000000..a6b46d4c8f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/java/smoketest/testng/SampleTestNGApplication.java @@ -0,0 +1,55 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.testng; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class SampleTestNGApplication { + + private static Log logger = LogFactory.getLog(SampleTestNGApplication.class); + + @Bean + protected ServletContextListener listener() { + return new ServletContextListener() { + + @Override + public void contextInitialized(ServletContextEvent sce) { + logger.info("ServletContext initialized"); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + logger.info("ServletContext destroyed"); + } + + }; + } + + public static void main(String[] args) { + SpringApplication.run(SampleTestNGApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/java/smoketest/testng/service/HelloWorldService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/java/smoketest/testng/service/HelloWorldService.java new file mode 100644 index 0000000000..5749cc1792 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/java/smoketest/testng/service/HelloWorldService.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.testng.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class HelloWorldService { + + @Value("${name:World}") + private String name; + + public String getHelloMessage() { + return "Hello " + this.name; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/java/smoketest/testng/web/SampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/java/smoketest/testng/web/SampleController.java new file mode 100644 index 0000000000..ee1439319e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/java/smoketest/testng/web/SampleController.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.testng.web; + +import smoketest.testng.service.HelloWorldService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class SampleController { + + @Autowired + private HelloWorldService helloWorldService; + + @GetMapping("/") + @ResponseBody + public String helloWorld() { + return this.helloWorldService.getHelloMessage(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-testng/src/main/resources/public/test.css b/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/resources/public/test.css similarity index 100% rename from spring-boot-samples/spring-boot-sample-testng/src/main/resources/public/test.css rename to spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/main/resources/public/test.css diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/test/java/smoketest/testng/SampleTestNGApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/test/java/smoketest/testng/SampleTestNGApplicationTests.java new file mode 100644 index 0000000000..84cf1b164b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-testng/src/test/java/smoketest/testng/SampleTestNGApplicationTests.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.testng; + +import org.testng.annotations.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Phillip Webb + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleTestNGApplicationTests extends AbstractTestNGSpringContextTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHome() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/pom.xml new file mode 100644 index 0000000000..9bcd0b9a60 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/pom.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-tomcat-jsp</artifactId> + <packaging>war</packaging> + <name>Spring Boot Tomcat JSP Smoke Test</name> + <description>Spring Boot Tomcat JSP Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jstl</artifactId> + </dependency> + <!-- Provided --> + <dependency> + <groupId>org.apache.tomcat.embed</groupId> + <artifactId>tomcat-embed-jasper</artifactId> + <scope>provided</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <useSystemClassLoader>false</useSystemClassLoader> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/MyException.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/MyException.java new file mode 100644 index 0000000000..0749849ebd --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/MyException.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.jsp; + +public class MyException extends RuntimeException { + + public MyException(String message) { + super(message); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/MyRestResponse.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/MyRestResponse.java new file mode 100644 index 0000000000..cc52546cdf --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/MyRestResponse.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.jsp; + +public class MyRestResponse { + + private String message; + + public MyRestResponse(String message) { + this.message = message; + } + + public String getMessage() { + return this.message; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/SampleTomcatJspApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/SampleTomcatJspApplication.java new file mode 100644 index 0000000000..4b15926b60 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/SampleTomcatJspApplication.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.jsp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +@SpringBootApplication +public class SampleTomcatJspApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleTomcatJspApplication.class); + } + + public static void main(String[] args) { + SpringApplication.run(SampleTomcatJspApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/WelcomeController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/WelcomeController.java new file mode 100644 index 0000000000..1c52acea86 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/java/smoketest/tomcat/jsp/WelcomeController.java @@ -0,0 +1,60 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.jsp; + +import java.util.Date; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +@Controller +public class WelcomeController { + + @Value("${application.message:Hello World}") + private String message = "Hello World"; + + @GetMapping("/") + public String welcome(Map<String, Object> model) { + model.put("time", new Date()); + model.put("message", this.message); + return "welcome"; + } + + @RequestMapping("/fail") + public String fail() { + throw new MyException("Oh dear!"); + } + + @RequestMapping("/fail2") + public String fail2() { + throw new IllegalStateException(); + } + + @ExceptionHandler(MyException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public @ResponseBody MyRestResponse handleMyRuntimeException(MyException exception) { + return new MyRestResponse("Some data I want to send back to the client."); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/resources/META-INF/resources/favicon.ico b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/resources/META-INF/resources/favicon.ico similarity index 100% rename from spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/resources/META-INF/resources/favicon.ico rename to spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/resources/META-INF/resources/favicon.ico diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/webapp/WEB-INF/jsp/welcome.jsp b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/webapp/WEB-INF/jsp/welcome.jsp similarity index 100% rename from spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/webapp/WEB-INF/jsp/welcome.jsp rename to spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/main/webapp/WEB-INF/jsp/welcome.jsp diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/test/java/smoketest/tomcat/jsp/SampleWebJspApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/test/java/smoketest/tomcat/jsp/SampleWebJspApplicationTests.java new file mode 100644 index 0000000000..2c311bdc9e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-jsp/src/test/java/smoketest/tomcat/jsp/SampleWebJspApplicationTests.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.jsp; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for JSP application. + * + * @author Phillip Webb + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebJspApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testJspWithEl() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("/resources/text.txt"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/pom.xml new file mode 100644 index 0000000000..28027c3f7f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/pom.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-tomcat-multi-connectors</artifactId> + <name>Spring Boot Multi-Connector Tomcat Smoke Test</name> + <description>Spring Boot Multi-Connector Tomcat Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/main/java/smoketest/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/main/java/smoketest/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java new file mode 100644 index 0000000000..e8a77101ef --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/main/java/smoketest/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java @@ -0,0 +1,53 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.multiconnector; + +import org.apache.catalina.connector.Connector; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.context.annotation.Bean; + +/** + * Sample Application to show Tomcat running two connectors. + * + * @author Brock Mills + * @author Andy Wilkinson + */ +@SpringBootApplication +public class SampleTomcatTwoConnectorsApplication { + + @Bean + public ServletWebServerFactory servletContainer() { + TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); + tomcat.addAdditionalTomcatConnectors(createStandardConnector()); + return tomcat; + } + + private Connector createStandardConnector() { + Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); + connector.setPort(0); + return connector; + } + + public static void main(String[] args) { + SpringApplication.run(SampleTomcatTwoConnectorsApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/main/java/smoketest/tomcat/multiconnector/web/SampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/main/java/smoketest/tomcat/multiconnector/web/SampleController.java new file mode 100644 index 0000000000..e67c9c0b57 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/main/java/smoketest/tomcat/multiconnector/web/SampleController.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.multiconnector.web; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class SampleController { + + @GetMapping("/hello") + public String helloWorld() { + return "hello"; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/sample.jks b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/main/resources/sample.jks similarity index 100% rename from spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/resources/sample.jks rename to spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/main/resources/sample.jks diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/test/java/smoketest/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/test/java/smoketest/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java new file mode 100644 index 0000000000..83ecd7e199 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-multi-connectors/src/test/java/smoketest/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java @@ -0,0 +1,111 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.multiconnector; + +import org.apache.catalina.Service; +import org.apache.catalina.connector.Connector; +import org.junit.jupiter.api.Test; +import smoketest.tomcat.multiconnector.SampleTomcatTwoConnectorsApplicationTests.Ports; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.context.WebServerInitializedEvent; +import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; +import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.ApplicationListener; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for {@link SampleTomcatTwoConnectorsApplication}. + * + * @author Brock Mills + * @author Andy Wilkinson + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@Import(Ports.class) +class SampleTomcatTwoConnectorsApplicationTests { + + @LocalServerPort + private int port; + + @Autowired + private Ports ports; + + @Autowired + private TestRestTemplate restTemplate; + + @Autowired + private AbstractConfigurableWebServerFactory webServerFactory; + + @Test + void testSsl() { + assertThat(this.webServerFactory.getSsl().isEnabled()).isTrue(); + } + + @Test + void testHello() { + assertThat(this.ports.getHttpsPort()).isEqualTo(this.port); + assertThat(this.ports.getHttpPort()).isNotEqualTo(this.port); + ResponseEntity<String> entity = this.restTemplate + .getForEntity("http://localhost:" + this.ports.getHttpPort() + "/hello", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("hello"); + ResponseEntity<String> httpsEntity = this.restTemplate.getForEntity("https://localhost:" + this.port + "/hello", + String.class); + assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(httpsEntity.getBody()).isEqualTo("hello"); + } + + @TestConfiguration + static class Ports implements ApplicationListener<WebServerInitializedEvent> { + + private int httpPort; + + private int httpsPort; + + @Override + public void onApplicationEvent(WebServerInitializedEvent event) { + Service service = ((TomcatWebServer) event.getWebServer()).getTomcat().getService(); + for (Connector connector : service.findConnectors()) { + if (connector.getSecure()) { + this.httpsPort = connector.getLocalPort(); + } + else { + this.httpPort = connector.getLocalPort(); + } + } + } + + int getHttpPort() { + return this.httpPort; + } + + int getHttpsPort() { + return this.httpsPort; + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/pom.xml new file mode 100644 index 0000000000..61a6d43e80 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/pom.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-tomcat-ssl</artifactId> + <name>Spring Boot Tomcat SSL Smoke Test</name> + <description>Spring Boot Tomcat SSL Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/main/java/smoketest/tomcat/ssl/SampleTomcatSslApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/main/java/smoketest/tomcat/ssl/SampleTomcatSslApplication.java new file mode 100644 index 0000000000..6746e4e049 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/main/java/smoketest/tomcat/ssl/SampleTomcatSslApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.ssl; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleTomcatSslApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleTomcatSslApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/main/java/smoketest/tomcat/ssl/web/SampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/main/java/smoketest/tomcat/ssl/web/SampleController.java new file mode 100644 index 0000000000..7b906d59dc --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/main/java/smoketest/tomcat/ssl/web/SampleController.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.ssl.web; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class SampleController { + + @GetMapping("/") + public String helloWorld() { + return "Hello, world"; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/resources/sample.jks b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/main/resources/sample.jks similarity index 100% rename from spring-boot-samples/spring-boot-sample-tomcat-ssl/src/main/resources/sample.jks rename to spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/main/resources/sample.jks diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/test/java/smoketest/tomcat/ssl/SampleTomcatSslApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/test/java/smoketest/tomcat/ssl/SampleTomcatSslApplicationTests.java new file mode 100644 index 0000000000..6c0e844db2 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat-ssl/src/test/java/smoketest/tomcat/ssl/SampleTomcatSslApplicationTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.ssl; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleTomcatSslApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Autowired + private AbstractConfigurableWebServerFactory webServerFactory; + + @Test + void testSsl() { + assertThat(this.webServerFactory.getSsl().isEnabled()).isTrue(); + } + + @Test + void testHome() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello, world"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/pom.xml new file mode 100644 index 0000000000..975bc4d086 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/pom.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-tomcat</artifactId> + <name>Spring Boot Tomcat Smoke Test</name> + <description>Spring Boot Tomcat Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-webmvc</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/java/smoketest/tomcat/SampleTomcatApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/java/smoketest/tomcat/SampleTomcatApplication.java new file mode 100644 index 0000000000..c5b501ab2e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/java/smoketest/tomcat/SampleTomcatApplication.java @@ -0,0 +1,55 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class SampleTomcatApplication { + + private static Log logger = LogFactory.getLog(SampleTomcatApplication.class); + + @Bean + protected ServletContextListener listener() { + return new ServletContextListener() { + + @Override + public void contextInitialized(ServletContextEvent sce) { + logger.info("ServletContext initialized"); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + logger.info("ServletContext destroyed"); + } + + }; + } + + public static void main(String[] args) { + SpringApplication.run(SampleTomcatApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/java/smoketest/tomcat/service/HelloWorldService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/java/smoketest/tomcat/service/HelloWorldService.java new file mode 100644 index 0000000000..b49003bdec --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/java/smoketest/tomcat/service/HelloWorldService.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class HelloWorldService { + + @Value("${name:World}") + private String name; + + public String getHelloMessage() { + return "Hello " + this.name; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/java/smoketest/tomcat/web/SampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/java/smoketest/tomcat/web/SampleController.java new file mode 100644 index 0000000000..d5c1443417 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/java/smoketest/tomcat/web/SampleController.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat.web; + +import smoketest.tomcat.service.HelloWorldService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class SampleController { + + @Autowired + private HelloWorldService helloWorldService; + + @GetMapping("/") + @ResponseBody + public String helloWorld() { + return this.helloWorldService.getHelloMessage(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-tomcat/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/test/java/smoketest/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/test/java/smoketest/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java new file mode 100644 index 0000000000..e1e33f4fe7 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/test/java/smoketest/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java @@ -0,0 +1,72 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat; + +import org.junit.jupiter.api.Test; +import smoketest.tomcat.service.HelloWorldService; +import smoketest.tomcat.web.SampleController; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration; +import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; +import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; +import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class NonAutoConfigurationSampleTomcatApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHome() throws Exception { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); + } + + @Configuration(proxyBeanMethods = false) + @Import({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, + WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class }) + @ComponentScan(basePackageClasses = { SampleController.class, HelloWorldService.class }) + public static class NonAutoConfigurationSampleTomcatApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleTomcatApplication.class, args); + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/test/java/smoketest/tomcat/SampleTomcatApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/test/java/smoketest/tomcat/SampleTomcatApplicationTests.java new file mode 100644 index 0000000000..2b1ebead6a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-tomcat/src/test/java/smoketest/tomcat/SampleTomcatApplicationTests.java @@ -0,0 +1,86 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.tomcat; + +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.util.zip.GZIPInputStream; + +import org.apache.coyote.AbstractProtocol; +import org.apache.coyote.ProtocolHandler; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; +import org.springframework.context.ApplicationContext; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.util.StreamUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + * @author Andy Wilkinson + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleTomcatApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Autowired + private ApplicationContext applicationContext; + + @Test + void testHome() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); + } + + @Test + void testCompression() throws Exception { + HttpHeaders requestHeaders = new HttpHeaders(); + requestHeaders.set("Accept-Encoding", "gzip"); + HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders); + ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + try (GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()))) { + assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)).isEqualTo("Hello World"); + } + } + + @Test + void testTimeout() { + ServletWebServerApplicationContext context = (ServletWebServerApplicationContext) this.applicationContext; + TomcatWebServer embeddedServletContainer = (TomcatWebServer) context.getWebServer(); + ProtocolHandler protocolHandler = embeddedServletContainer.getTomcat().getConnector().getProtocolHandler(); + int timeout = ((AbstractProtocol<?>) protocolHandler).getConnectionTimeout(); + assertThat(timeout).isEqualTo(5000); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/pom.xml new file mode 100644 index 0000000000..91c48707d3 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/pom.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-traditional</artifactId> + <packaging>war</packaging> + <name>Spring Boot Traditional Smoke Test</name> + <description>Spring Boot Traditional Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-webmvc</artifactId> + </dependency> + <!-- Provided (for embedded war support) --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.tomcat.embed</groupId> + <artifactId>tomcat-embed-jasper</artifactId> + <scope>provided</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/java/smoketest/traditional/SampleTraditionalApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/java/smoketest/traditional/SampleTraditionalApplication.java new file mode 100644 index 0000000000..9c567db5ca --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/java/smoketest/traditional/SampleTraditionalApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.traditional; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleTraditionalApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleTraditionalApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/java/smoketest/traditional/config/WebConfig.java b/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/java/smoketest/traditional/config/WebConfig.java new file mode 100644 index 0000000000..6b0114c1e1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/java/smoketest/traditional/config/WebConfig.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.traditional.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.DispatcherServlet; +import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.view.InternalResourceViewResolver; + +@EnableWebMvc +@ComponentScan +@Configuration(proxyBeanMethods = false) +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/").setViewName("home"); + } + + @Bean + public InternalResourceViewResolver viewResolver() { + InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); + viewResolver.setPrefix("/WEB-INF/views/"); + viewResolver.setSuffix(".jsp"); + return viewResolver; + } + + @Bean + // Only used when running in embedded servlet + public DispatcherServlet dispatcherServlet() { + return new DispatcherServlet(); + } + + @Override + public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { + configurer.enable(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/main/webapp/WEB-INF/views/home.jsp b/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/webapp/WEB-INF/views/home.jsp similarity index 100% rename from spring-boot-samples/spring-boot-sample-traditional/src/main/webapp/WEB-INF/views/home.jsp rename to spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/webapp/WEB-INF/views/home.jsp diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/main/webapp/WEB-INF/web.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-boot-samples/spring-boot-sample-traditional/src/main/webapp/WEB-INF/web.xml rename to spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/webapp/WEB-INF/web.xml diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/main/webapp/index.html b/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/webapp/index.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-traditional/src/main/webapp/index.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/main/webapp/index.html diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/test/java/smoketest/traditional/SampleTraditionalApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/test/java/smoketest/traditional/SampleTraditionalApplicationTests.java new file mode 100644 index 0000000000..ea587f0d18 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/test/java/smoketest/traditional/SampleTraditionalApplicationTests.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.traditional; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleTraditionalApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHomeJsp() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + String body = entity.getBody(); + assertThat(body).contains("<html>").contains("<h1>Home</h1>"); + } + + @Test + void testStaticPage() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/index.html", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + String body = entity.getBody(); + assertThat(body).contains("<html>").contains("<h1>Hello</h1>"); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/test/resources/log4j.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/test/resources/log4j.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-traditional/src/test/resources/log4j.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-traditional/src/test/resources/log4j.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/pom.xml new file mode 100644 index 0000000000..b2ea1b76ce --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/pom.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-undertow-ssl</artifactId> + <name>Spring Boot Undertow SSL Smoke Test</name> + <description>Spring Boot Undertow SSL Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-undertow</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/main/java/smoketest/undertow/ssl/SampleUndertowSslApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/main/java/smoketest/undertow/ssl/SampleUndertowSslApplication.java new file mode 100644 index 0000000000..e43dbdd424 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/main/java/smoketest/undertow/ssl/SampleUndertowSslApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.undertow.ssl; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleUndertowSslApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleUndertowSslApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/main/java/smoketest/undertow/ssl/web/SampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/main/java/smoketest/undertow/ssl/web/SampleController.java new file mode 100644 index 0000000000..2e544e04cd --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/main/java/smoketest/undertow/ssl/web/SampleController.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.undertow.ssl.web; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class SampleController { + + @GetMapping("/") + public String helloWorld() { + return "Hello World"; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/resources/sample.jks b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/main/resources/sample.jks similarity index 100% rename from spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/resources/sample.jks rename to spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/main/resources/sample.jks diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/test/java/smoketest/undertow/ssl/SampleUndertowSslApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/test/java/smoketest/undertow/ssl/SampleUndertowSslApplicationTests.java new file mode 100644 index 0000000000..85c8cf3dfe --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow-ssl/src/test/java/smoketest/undertow/ssl/SampleUndertowSslApplicationTests.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.undertow.ssl; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Ivan Sopov + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleUndertowSslApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Autowired + private AbstractConfigurableWebServerFactory webServerFactory; + + @Test + void testSsl() { + assertThat(this.webServerFactory.getSsl().isEnabled()).isTrue(); + } + + @Test + void testHome() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/pom.xml new file mode 100644 index 0000000000..684fa99362 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/pom.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-undertow</artifactId> + <name>Spring Boot Undertow Smoke Test</name> + <description>Spring Boot Undertow Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-undertow</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/main/java/smoketest/undertow/SampleUndertowApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/main/java/smoketest/undertow/SampleUndertowApplication.java new file mode 100644 index 0000000000..089bd333ca --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/main/java/smoketest/undertow/SampleUndertowApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.undertow; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleUndertowApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleUndertowApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/main/java/smoketest/undertow/web/SampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/main/java/smoketest/undertow/web/SampleController.java new file mode 100644 index 0000000000..2c30a41fad --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/main/java/smoketest/undertow/web/SampleController.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.undertow.web; + +import java.util.concurrent.Callable; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class SampleController { + + @GetMapping("/") + public String helloWorld() { + return "Hello World"; + } + + @GetMapping("/async") + public Callable<String> helloWorldAsync() { + return () -> "async: Hello World"; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-undertow/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-undertow/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/test/java/smoketest/undertow/SampleUndertowApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/test/java/smoketest/undertow/SampleUndertowApplicationTests.java new file mode 100644 index 0000000000..36b133c4c9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-undertow/src/test/java/smoketest/undertow/SampleUndertowApplicationTests.java @@ -0,0 +1,79 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.undertow; + +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.util.zip.GZIPInputStream; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.util.StreamUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Ivan Sopov + * @author Andy Wilkinson + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleUndertowApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHome() { + assertOkResponse("/", "Hello World"); + } + + @Test + void testAsync() { + assertOkResponse("/async", "async: Hello World"); + } + + @Test + void testCompression() throws Exception { + HttpHeaders requestHeaders = new HttpHeaders(); + requestHeaders.set("Accept-Encoding", "gzip"); + HttpEntity<?> requestEntity = new HttpEntity<>(requestHeaders); + ResponseEntity<byte[]> entity = this.restTemplate.exchange("/", HttpMethod.GET, requestEntity, byte[].class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + + try (GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody()))) { + assertThat(StreamUtils.copyToString(inflater, StandardCharsets.UTF_8)).isEqualTo("Hello World"); + } + } + + private void assertOkResponse(String path, String body) { + ResponseEntity<String> entity = this.restTemplate.getForEntity(path, String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo(body); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-war/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-war/pom.xml new file mode 100644 index 0000000000..7763c60ab9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-war/pom.xml @@ -0,0 +1,94 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-war</artifactId> + <packaging>war</packaging> + <name>Spring Boot War Smoke Test</name> + <description>Spring Boot War Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> + <!-- To build an executable war use one of the profiles below --> + <groupId>jakarta.servlet</groupId> + <artifactId>jakarta.servlet-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <!-- Provided --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-devtools</artifactId> + <scope>provided</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>tomcat</id> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + </profile> + <profile> + <id>jetty</id> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jetty</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + </profile> + <profile> + <id>undertow</id> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-undertow</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-war/src/main/java/smoketest/war/MyController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-war/src/main/java/smoketest/war/MyController.java new file mode 100644 index 0000000000..fd978eabe7 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-war/src/main/java/smoketest/war/MyController.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.war; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class MyController { + + @GetMapping("/") + public String hello() { + return "Hello World!"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-war/src/main/java/smoketest/war/SampleWarApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-war/src/main/java/smoketest/war/SampleWarApplication.java new file mode 100644 index 0000000000..0ffca3ba8b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-war/src/main/java/smoketest/war/SampleWarApplication.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.war; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.PropertySource; + +@SpringBootApplication +@PropertySource("WEB-INF/custom.properties") +public class SampleWarApplication extends SpringBootServletInitializer { + + public static void main(String[] args) { + SpringApplication.run(SampleWarApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-war/src/main/webapp/WEB-INF/custom.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-war/src/main/webapp/WEB-INF/custom.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-war/src/main/webapp/WEB-INF/custom.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-war/src/main/webapp/WEB-INF/custom.properties diff --git a/spring-boot-samples/spring-boot-sample-war/src/main/webapp/webapp.txt b/spring-boot-smoke-tests/spring-boot-smoke-test-war/src/main/webapp/webapp.txt similarity index 100% rename from spring-boot-samples/spring-boot-sample-war/src/main/webapp/webapp.txt rename to spring-boot-smoke-tests/spring-boot-smoke-test-war/src/main/webapp/webapp.txt diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-war/src/test/java/smoketest/war/WarApplicationResourceTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-war/src/test/java/smoketest/war/WarApplicationResourceTests.java new file mode 100644 index 0000000000..976c3956c9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-war/src/test/java/smoketest/war/WarApplicationResourceTests.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.war; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest +class WarApplicationResourceTests { + + // gh-6371 + + @Value("${demo.string.value}") + private String demoStringValue; + + @Test + void contextLoads() { + assertThat(this.demoStringValue).isEqualTo("demo"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/pom.xml new file mode 100644 index 0000000000..6442f91dc1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/pom.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-web-freemarker</artifactId> + <name>Spring Boot Web FreeMarker Smoke Test</name> + <description>Spring Boot Web FreeMarker Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-freemarker</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <useSystemClassLoader>false</useSystemClassLoader> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/java/smoketest/freemarker/SampleWebFreeMarkerApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/java/smoketest/freemarker/SampleWebFreeMarkerApplication.java new file mode 100644 index 0000000000..7b03cf320a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/java/smoketest/freemarker/SampleWebFreeMarkerApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.freemarker; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleWebFreeMarkerApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleWebFreeMarkerApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/java/smoketest/freemarker/WelcomeController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/java/smoketest/freemarker/WelcomeController.java new file mode 100644 index 0000000000..bba1ba87fa --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/java/smoketest/freemarker/WelcomeController.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.freemarker; + +import java.util.Date; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class WelcomeController { + + @Value("${application.message:Hello World}") + private String message = "Hello World"; + + @GetMapping("/") + public String welcome(Map<String, Object> model) { + model.put("time", new Date()); + model.put("message", this.message); + return "welcome"; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-web-freemarker/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-freemarker/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-web-freemarker/src/main/resources/templates/error.ftlh b/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/resources/templates/error.ftlh similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-freemarker/src/main/resources/templates/error.ftlh rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/resources/templates/error.ftlh diff --git a/spring-boot-samples/spring-boot-sample-web-freemarker/src/main/resources/templates/welcome.ftlh b/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/resources/templates/welcome.ftlh similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-freemarker/src/main/resources/templates/welcome.ftlh rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/main/resources/templates/welcome.ftlh diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/test/java/smoketest/freemarker/SampleWebFreeMarkerApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/test/java/smoketest/freemarker/SampleWebFreeMarkerApplicationTests.java new file mode 100644 index 0000000000..083ab64853 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-freemarker/src/test/java/smoketest/freemarker/SampleWebFreeMarkerApplicationTests.java @@ -0,0 +1,68 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.freemarker; + +import java.util.Arrays; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for FreeMarker application. + * + * @author Phillip Webb + * @author Andy Wilkinson + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebFreeMarkerApplicationTests { + + @Autowired + private TestRestTemplate testRestTemplate; + + @Test + void testFreeMarkerTemplate() { + ResponseEntity<String> entity = this.testRestTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("Hello, Andy"); + } + + @Test + void testFreeMarkerErrorTemplate() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + HttpEntity<String> requestEntity = new HttpEntity<>(headers); + + ResponseEntity<String> responseEntity = this.testRestTemplate.exchange("/does-not-exist", HttpMethod.GET, + requestEntity, String.class); + + assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + assertThat(responseEntity.getBody()).contains("Something went wrong: 404 Not Found"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/pom.xml new file mode 100755 index 0000000000..aa085d8f35 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/pom.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-web-groovy-templates</artifactId> + <name>Spring Boot Web Groovy Templates Smoke Test</name> + <description>Spring Boot Web Groovy Templates Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-groovy-templates</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>java9+</id> + <activation> + <jdk>[9,)</jdk> + </activation> + <dependencies> + <dependency> + <groupId>jakarta.xml.bind</groupId> + <artifactId>jakarta.xml.bind-api</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/InMemoryMessageRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/InMemoryMessageRepository.java new file mode 100644 index 0000000000..8e8f7e924f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/InMemoryMessageRepository.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.groovytemplates; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicLong; + +public class InMemoryMessageRepository implements MessageRepository { + + private static AtomicLong counter = new AtomicLong(); + + private final ConcurrentMap<Long, Message> messages = new ConcurrentHashMap<>(); + + @Override + public Iterable<Message> findAll() { + return this.messages.values(); + } + + @Override + public Message save(Message message) { + Long id = message.getId(); + if (id == null) { + id = counter.incrementAndGet(); + message.setId(id); + } + this.messages.put(id, message); + return message; + } + + @Override + public Message findMessage(Long id) { + return this.messages.get(id); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/Message.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/Message.java new file mode 100644 index 0000000000..4cac51f446 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/Message.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.groovytemplates; + +import java.util.Date; + +import javax.validation.constraints.NotEmpty; + +public class Message { + + private Long id; + + @NotEmpty(message = "Text is required.") + private String text; + + @NotEmpty(message = "Summary is required.") + private String summary; + + private Date created = new Date(); + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getCreated() { + return this.created; + } + + public void setCreated(Date created) { + this.created = created; + } + + public String getText() { + return this.text; + } + + public void setText(String text) { + this.text = text; + } + + public String getSummary() { + return this.summary; + } + + public void setSummary(String summary) { + this.summary = summary; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/MessageRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/MessageRepository.java new file mode 100644 index 0000000000..3471f22e98 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/MessageRepository.java @@ -0,0 +1,27 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.groovytemplates; + +public interface MessageRepository { + + Iterable<Message> findAll(); + + Message save(Message message); + + Message findMessage(Long id); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/SampleGroovyTemplateApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/SampleGroovyTemplateApplication.java new file mode 100644 index 0000000000..2f2260e2b4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/SampleGroovyTemplateApplication.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.groovytemplates; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.core.convert.converter.Converter; + +@SpringBootApplication +public class SampleGroovyTemplateApplication { + + @Bean + public MessageRepository messageRepository() { + return new InMemoryMessageRepository(); + } + + @Bean + public Converter<String, Message> messageConverter() { + return new Converter<String, Message>() { + @Override + public Message convert(String id) { + return messageRepository().findMessage(Long.valueOf(id)); + } + }; + } + + public static void main(String[] args) { + SpringApplication.run(SampleGroovyTemplateApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/mvc/MessageController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/mvc/MessageController.java new file mode 100644 index 0000000000..f16f3733c7 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/mvc/MessageController.java @@ -0,0 +1,91 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.groovytemplates.mvc; + +import java.util.HashMap; +import java.util.Map; + +import javax.validation.Valid; + +import smoketest.groovytemplates.Message; +import smoketest.groovytemplates.MessageRepository; + +import org.springframework.stereotype.Controller; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; +import org.springframework.validation.ObjectError; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; + +@Controller +@RequestMapping("/") +public class MessageController { + + private final MessageRepository messageRepository; + + public MessageController(MessageRepository messageRepository) { + this.messageRepository = messageRepository; + } + + @GetMapping + public ModelAndView list() { + Iterable<Message> messages = this.messageRepository.findAll(); + return new ModelAndView("messages/list", "messages", messages); + } + + @GetMapping("{id}") + public ModelAndView view(@PathVariable("id") Message message) { + return new ModelAndView("messages/view", "message", message); + } + + @GetMapping(params = "form") + public String createForm(@ModelAttribute Message message) { + return "messages/form"; + } + + @PostMapping + public ModelAndView create(@Valid Message message, BindingResult result, RedirectAttributes redirect) { + if (result.hasErrors()) { + ModelAndView mav = new ModelAndView("messages/form"); + mav.addObject("formErrors", result.getAllErrors()); + mav.addObject("fieldErrors", getFieldErrors(result)); + return mav; + } + message = this.messageRepository.save(message); + redirect.addFlashAttribute("globalMessage", "Successfully created a new message"); + return new ModelAndView("redirect:/{message.id}", "message.id", message.getId()); + } + + private Map<String, ObjectError> getFieldErrors(BindingResult result) { + Map<String, ObjectError> map = new HashMap<>(); + for (FieldError error : result.getFieldErrors()) { + map.put(error.getField(), error); + } + return map; + } + + @RequestMapping("foo") + public String foo() { + throw new RuntimeException("Expected exception in controller"); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/static/css/bootstrap.min.css b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/static/css/bootstrap.min.css similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/static/css/bootstrap.min.css rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/static/css/bootstrap.min.css diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/static/js/jquery-1.7.2.js b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/static/js/jquery-1.7.2.js similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/static/js/jquery-1.7.2.js rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/static/js/jquery-1.7.2.js diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/static/js/jquery.validate.js b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/static/js/jquery.validate.js similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/static/js/jquery.validate.js rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/static/js/jquery.validate.js diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/templates/layout.tpl b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/templates/layout.tpl similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/templates/layout.tpl rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/templates/layout.tpl diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/templates/messages/form.tpl b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/templates/messages/form.tpl similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/templates/messages/form.tpl rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/templates/messages/form.tpl diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/templates/messages/list.tpl b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/templates/messages/list.tpl similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/templates/messages/list.tpl rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/templates/messages/list.tpl diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/templates/messages/view.tpl b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/templates/messages/view.tpl similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-groovy-templates/src/main/resources/templates/messages/view.tpl rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/main/resources/templates/messages/view.tpl diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/test/java/smoketest/groovytemplates/MessageControllerWebTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/test/java/smoketest/groovytemplates/MessageControllerWebTests.java new file mode 100755 index 0000000000..98e19bffb0 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/test/java/smoketest/groovytemplates/MessageControllerWebTests.java @@ -0,0 +1,105 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.groovytemplates; + +import java.util.regex.Pattern; + +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * A Basic Spring MVC Test for the Sample Controller" + * + * @author Biju Kunjummen + * @author Doo-Hwan, Kwak + */ +@SpringBootTest +class MessageControllerWebTests { + + @Autowired + private WebApplicationContext wac; + + private MockMvc mockMvc; + + @BeforeEach + void setup() { + this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); + } + + @Test + void testHome() throws Exception { + this.mockMvc.perform(get("/")).andExpect(status().isOk()) + .andExpect(content().string(containsString("<title>Messages"))); + } + + @Test + void testCreate() throws Exception { + this.mockMvc.perform(post("/").param("text", "FOO text").param("summary", "FOO")).andExpect(status().isFound()) + .andExpect(header().string("location", RegexMatcher.matches("/[0-9]+"))); + } + + @Test + void testCreateValidation() throws Exception { + this.mockMvc.perform(post("/").param("text", "").param("summary", "")).andExpect(status().isOk()) + .andExpect(content().string(containsString("is required"))); + } + + private static class RegexMatcher extends TypeSafeMatcher<String> { + + private final String regex; + + RegexMatcher(String regex) { + this.regex = regex; + } + + @Override + public boolean matchesSafely(String item) { + return Pattern.compile(this.regex).matcher(item).find(); + } + + @Override + public void describeMismatchSafely(String item, Description mismatchDescription) { + mismatchDescription.appendText("was \"").appendText(item).appendText("\""); + } + + @Override + public void describeTo(Description description) { + description.appendText("a string that matches regex: ").appendText(this.regex); + } + + public static org.hamcrest.Matcher<java.lang.String> matches(String regex) { + return new RegexMatcher(regex); + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/test/java/smoketest/groovytemplates/SampleGroovyTemplateApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/test/java/smoketest/groovytemplates/SampleGroovyTemplateApplicationTests.java new file mode 100644 index 0000000000..be72ca9e13 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-groovy-templates/src/test/java/smoketest/groovytemplates/SampleGroovyTemplateApplicationTests.java @@ -0,0 +1,73 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.groovytemplates; + +import java.net.URI; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleGroovyTemplateApplicationTests { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHome() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("<title>Messages"); + assertThat(entity.getBody()).doesNotContain("layout:fragment"); + } + + @Test + void testCreate() { + MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); + map.set("text", "FOO text"); + map.set("summary", "FOO"); + URI location = this.restTemplate.postForLocation("/", map); + assertThat(location.toString()).contains("localhost:" + this.port); + } + + @Test + void testCss() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/pom.xml new file mode 100644 index 0000000000..cdd248ac35 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/pom.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-web-jsp</artifactId> + <packaging>war</packaging> + <name>Spring Boot Web JSP Smoke Test</name> + <description>Spring Boot Web JSP Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jstl</artifactId> + </dependency> + <!-- Provided --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.tomcat.embed</groupId> + <artifactId>tomcat-embed-jasper</artifactId> + <scope>provided</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <useSystemClassLoader>false</useSystemClassLoader> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/java/smoketest/jsp/SampleWebJspApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/java/smoketest/jsp/SampleWebJspApplication.java new file mode 100644 index 0000000000..ad543e7ffc --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/java/smoketest/jsp/SampleWebJspApplication.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jsp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +@SpringBootApplication +public class SampleWebJspApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleWebJspApplication.class); + } + + public static void main(String[] args) { + SpringApplication.run(SampleWebJspApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/java/smoketest/jsp/WelcomeController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/java/smoketest/jsp/WelcomeController.java new file mode 100644 index 0000000000..974a8a8262 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/java/smoketest/jsp/WelcomeController.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jsp; + +import java.util.Date; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class WelcomeController { + + @Value("${application.message:Hello World}") + private String message = "Hello World"; + + @GetMapping("/") + public String welcome(Map<String, Object> model) { + model.put("time", new Date()); + model.put("message", this.message); + return "welcome"; + } + + @RequestMapping("/foo") + public String foo(Map<String, Object> model) { + throw new RuntimeException("Foo"); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-jsp/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/main/webapp/WEB-INF/jsp/error.jsp b/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/webapp/WEB-INF/jsp/error.jsp similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-jsp/src/main/webapp/WEB-INF/jsp/error.jsp rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/webapp/WEB-INF/jsp/error.jsp diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/main/webapp/WEB-INF/jsp/welcome.jsp b/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/webapp/WEB-INF/jsp/welcome.jsp similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-jsp/src/main/webapp/WEB-INF/jsp/welcome.jsp rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/main/webapp/WEB-INF/jsp/welcome.jsp diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/test/java/smoketest/jsp/SampleWebJspApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/test/java/smoketest/jsp/SampleWebJspApplicationTests.java new file mode 100644 index 0000000000..cbcf25e9ec --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-jsp/src/test/java/smoketest/jsp/SampleWebJspApplicationTests.java @@ -0,0 +1,65 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.jsp; + +import java.net.URI; +import java.util.Arrays; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.RequestEntity; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for JSP application. + * + * @author Phillip Webb + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebJspApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testJspWithEl() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("/resources/text.txt"); + } + + @Test + void customErrorPage() throws Exception { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + RequestEntity<Void> request = new RequestEntity<>(headers, HttpMethod.GET, URI.create("/foo")); + ResponseEntity<String> entity = this.restTemplate.exchange(request, String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + assertThat(entity.getBody()).contains("Something went wrong: 500 Internal Server Error"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/pom.xml new file mode 100644 index 0000000000..fb484c8b39 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/pom.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-web-method-security</artifactId> + <name>Spring Boot Web Method Security Smoke Test</name> + <description>Spring Boot Web Method Security Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-thymeleaf</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/java/smoketest/security/method/SampleMethodSecurityApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/java/smoketest/security/method/SampleMethodSecurityApplication.java new file mode 100644 index 0000000000..e0e11521e6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/java/smoketest/security/method/SampleMethodSecurityApplication.java @@ -0,0 +1,120 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.security.method; + +import java.util.Date; +import java.util.Map; + +import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.security.access.annotation.Secured; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@SpringBootApplication +@EnableGlobalMethodSecurity(securedEnabled = true) +public class SampleMethodSecurityApplication implements WebMvcConfigurer { + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/login").setViewName("login"); + registry.addViewController("/access").setViewName("access"); + } + + public static void main(String[] args) { + new SpringApplicationBuilder(SampleMethodSecurityApplication.class).run(args); + } + + @Order(Ordered.HIGHEST_PRECEDENCE) + @Configuration(proxyBeanMethods = false) + protected static class AuthenticationSecurity { + + @SuppressWarnings("deprecation") + @Bean + public InMemoryUserDetailsManager inMemoryUserDetailsManager() throws Exception { + return new InMemoryUserDetailsManager( + User.withDefaultPasswordEncoder().username("admin").password("admin") + .roles("ADMIN", "USER", "ACTUATOR").build(), + User.withDefaultPasswordEncoder().username("user").password("user").roles("USER").build()); + } + + } + + @Configuration(proxyBeanMethods = false) + protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + // @formatter:off + http.authorizeRequests() + .antMatchers("/login").permitAll() + .anyRequest().fullyAuthenticated() + .and() + .formLogin().loginPage("/login").failureUrl("/login?error") + .and() + .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")) + .and() + .exceptionHandling().accessDeniedPage("/access?error"); + // @formatter:on + } + + } + + @Configuration(proxyBeanMethods = false) + @Order(1) + protected static class ActuatorSecurity extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + // @formatter:off + http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests() + .anyRequest().authenticated() + .and() + .httpBasic(); + // @formatter:on + } + + } + + @Controller + protected static class HomeController { + + @GetMapping("/") + @Secured("ROLE_ADMIN") + public String home(Map<String, Object> model) { + model.put("message", "Hello World"); + model.put("title", "Hello Home"); + model.put("date", new Date()); + return "home"; + } + + } + +} diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/static/css/bootstrap.min.css b/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/resources/static/css/bootstrap.min.css similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/static/css/bootstrap.min.css rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/resources/static/css/bootstrap.min.css diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/templates/access.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/resources/templates/access.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/templates/access.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/resources/templates/access.html diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/templates/error.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/resources/templates/error.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/templates/error.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/resources/templates/error.html diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/templates/home.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/resources/templates/home.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/templates/home.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/resources/templates/home.html diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/templates/login.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/resources/templates/login.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-method-security/src/main/resources/templates/login.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/resources/templates/login.html diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/test/java/smoketest/security/method/SampleMethodSecurityApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/test/java/smoketest/security/method/SampleMethodSecurityApplicationTests.java new file mode 100644 index 0000000000..b72c0506ed --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/test/java/smoketest/security/method/SampleMethodSecurityApplicationTests.java @@ -0,0 +1,131 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.security.method; + +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.support.BasicAuthenticationInterceptor; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleMethodSecurityApplicationTests { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHome() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("<title>Login"); + } + + @Test + void testLogin() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); + form.set("username", "admin"); + form.set("password", "admin"); + getCsrf(form, headers); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, + new HttpEntity<>(form, headers), String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()).isEqualTo("http://localhost:" + this.port + "/"); + } + + @Test + void testDenied() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); + form.set("username", "user"); + form.set("password", "user"); + getCsrf(form, headers); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, + new HttpEntity<>(form, headers), String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + String cookie = entity.getHeaders().getFirst("Set-Cookie"); + headers.set("Cookie", cookie); + ResponseEntity<String> page = this.restTemplate.exchange(entity.getHeaders().getLocation(), HttpMethod.GET, + new HttpEntity<Void>(headers), String.class); + assertThat(page.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); + assertThat(page.getBody()).contains("Access denied"); + } + + @Test + void testManagementProtected() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); + ResponseEntity<String> entity = this.restTemplate.exchange("/actuator/beans", HttpMethod.GET, + new HttpEntity<Void>(headers), String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + } + + @Test + void testManagementAuthorizedAccess() { + BasicAuthenticationInterceptor basicAuthInterceptor = new BasicAuthenticationInterceptor("admin", "admin"); + this.restTemplate.getRestTemplate().getInterceptors().add(basicAuthInterceptor); + try { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/beans", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + } + finally { + this.restTemplate.getRestTemplate().getInterceptors().remove(basicAuthInterceptor); + } + } + + private void getCsrf(MultiValueMap<String, String> form, HttpHeaders headers) { + ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class); + String cookie = page.getHeaders().getFirst("Set-Cookie"); + headers.set("Cookie", cookie); + String body = page.getBody(); + Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*").matcher(body); + matcher.find(); + form.set("_csrf", matcher.group(1)); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/pom.xml new file mode 100644 index 0000000000..1128fd1e8c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/pom.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-web-mustache</artifactId> + <name>Spring Boot Web Mustache Smoke Test</name> + <description>Spring Boot Web Mustache Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-mustache</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <useSystemClassLoader>false</useSystemClassLoader> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/java/smoketest/mustache/SampleWebMustacheApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/java/smoketest/mustache/SampleWebMustacheApplication.java new file mode 100644 index 0000000000..b1ec10d5ca --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/java/smoketest/mustache/SampleWebMustacheApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.mustache; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleWebMustacheApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleWebMustacheApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/java/smoketest/mustache/WelcomeController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/java/smoketest/mustache/WelcomeController.java new file mode 100644 index 0000000000..f9043ac5d0 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/java/smoketest/mustache/WelcomeController.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.mustache; + +import java.util.Date; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; + +@Controller +public class WelcomeController { + + @Value("${application.message:Hello World}") + private String message = "Hello World"; + + @GetMapping("/") + public String welcome(Map<String, Object> model) { + model.put("time", new Date()); + model.put("message", this.message); + return "welcome"; + } + + @RequestMapping("/serviceUnavailable") + public String ServiceUnavailable() { + throw new ServiceUnavailableException(); + } + + @RequestMapping("/bang") + public String bang() { + throw new RuntimeException("Boom"); + } + + @RequestMapping("/insufficientStorage") + public String insufficientStorage() { + throw new InsufficientStorageException(); + } + + @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE) + private static class ServiceUnavailableException extends RuntimeException { + + } + + @ResponseStatus(HttpStatus.INSUFFICIENT_STORAGE) + private static class InsufficientStorageException extends RuntimeException { + + } + +} diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/public/error/503.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/resources/public/error/503.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/public/error/503.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/resources/public/error/503.html diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/public/error/5xx.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/resources/public/error/5xx.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/public/error/5xx.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/resources/public/error/5xx.html diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/templates/error.mustache b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/resources/templates/error.mustache similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/templates/error.mustache rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/resources/templates/error.mustache diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/templates/error/507.mustache b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/resources/templates/error/507.mustache similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/templates/error/507.mustache rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/resources/templates/error/507.mustache diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/templates/welcome.mustache b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/resources/templates/welcome.mustache similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-mustache/src/main/resources/templates/welcome.mustache rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/main/resources/templates/welcome.mustache diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/test/java/smoketest/mustache/SampleWebMustacheApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/test/java/smoketest/mustache/SampleWebMustacheApplicationTests.java new file mode 100644 index 0000000000..2b495bde4f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-mustache/src/test/java/smoketest/mustache/SampleWebMustacheApplicationTests.java @@ -0,0 +1,99 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.mustache; + +import java.util.Arrays; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for Mustache application. + * + * @author Phillip Webb + * @author Andy Wilkinson + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebMustacheApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testMustacheTemplate() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("Hello, Andy"); + } + + @Test + void testMustacheErrorTemplate() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + HttpEntity<String> requestEntity = new HttpEntity<>(headers); + ResponseEntity<String> responseEntity = this.restTemplate.exchange("/does-not-exist", HttpMethod.GET, + requestEntity, String.class); + assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + assertThat(responseEntity.getBody()).contains("Something went wrong: 404 Not Found"); + } + + @Test + void test503HtmlResource() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + HttpEntity<String> requestEntity = new HttpEntity<>(headers); + ResponseEntity<String> entity = this.restTemplate.exchange("/serviceUnavailable", HttpMethod.GET, requestEntity, + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE); + assertThat(entity.getBody()).contains("I'm a 503"); + } + + @Test + void test5xxHtmlResource() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + HttpEntity<String> requestEntity = new HttpEntity<>(headers); + ResponseEntity<String> entity = this.restTemplate.exchange("/bang", HttpMethod.GET, requestEntity, + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + assertThat(entity.getBody()).contains("I'm a 5xx"); + } + + @Test + void test507Template() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + HttpEntity<String> requestEntity = new HttpEntity<>(headers); + ResponseEntity<String> entity = this.restTemplate.exchange("/insufficientStorage", HttpMethod.GET, + requestEntity, String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INSUFFICIENT_STORAGE); + assertThat(entity.getBody()).contains("I'm a 507"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/pom.xml new file mode 100644 index 0000000000..d69e108f78 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/pom.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-web-secure-custom</artifactId> + <name>Spring Boot Web Secure Custom Smoke Test</name> + <description>Spring Boot Web Secure Custom Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-thymeleaf</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/java/smoketest/web/secure/custom/SampleWebSecureCustomApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/java/smoketest/web/secure/custom/SampleWebSecureCustomApplication.java new file mode 100644 index 0000000000..74ce785f3c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/java/smoketest/web/secure/custom/SampleWebSecureCustomApplication.java @@ -0,0 +1,70 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.secure.custom; + +import java.util.Date; +import java.util.Map; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@SpringBootApplication +@Controller +public class SampleWebSecureCustomApplication implements WebMvcConfigurer { + + @GetMapping("/") + public String home(Map<String, Object> model) { + model.put("message", "Hello World"); + model.put("title", "Hello Home"); + model.put("date", new Date()); + return "home"; + } + + @RequestMapping("/foo") + public String foo() { + throw new RuntimeException("Expected exception in controller"); + } + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/login").setViewName("login"); + } + + public static void main(String[] args) { + new SpringApplicationBuilder(SampleWebSecureCustomApplication.class).run(args); + } + + @Configuration(proxyBeanMethods = false) + protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests().antMatchers("/css/**").permitAll().anyRequest().fullyAuthenticated().and() + .formLogin().loginPage("/login").failureUrl("/login?error").permitAll().and().logout().permitAll(); + } + + } + +} diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/resources/static/css/bootstrap.min.css b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/resources/static/css/bootstrap.min.css similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/resources/static/css/bootstrap.min.css rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/resources/static/css/bootstrap.min.css diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/resources/templates/error.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/resources/templates/error.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/resources/templates/error.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/resources/templates/error.html diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/resources/templates/home.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/resources/templates/home.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/resources/templates/home.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/resources/templates/home.html diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/resources/templates/login.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/resources/templates/login.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure-custom/src/main/resources/templates/login.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/main/resources/templates/login.html diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/test/java/smoketest/web/secure/custom/SampleWebSecureCustomApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/test/java/smoketest/web/secure/custom/SampleWebSecureCustomApplicationTests.java new file mode 100644 index 0000000000..2c1f6958f3 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-custom/src/test/java/smoketest/web/secure/custom/SampleWebSecureCustomApplicationTests.java @@ -0,0 +1,110 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.secure.custom; + +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebSecureCustomApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @LocalServerPort + private int port; + + @Test + void testHome() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/login"); + } + + @Test + void testLoginPage() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, + new HttpEntity<Void>(headers), String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("_csrf"); + } + + @Test + void testLogin() { + HttpHeaders headers = getHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); + form.set("username", "user"); + form.set("password", "password"); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, + new HttpEntity<>(form, headers), String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/"); + assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); + } + + private HttpHeaders getHeaders() { + HttpHeaders headers = new HttpHeaders(); + ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class); + assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK); + String cookie = page.getHeaders().getFirst("Set-Cookie"); + headers.set("Cookie", cookie); + Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"); + Matcher matcher = pattern.matcher(page.getBody()); + assertThat(matcher.matches()).as(page.getBody()).isTrue(); + headers.set("X-CSRF-TOKEN", matcher.group(1)); + return headers; + } + + @Test + void testCss() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/pom.xml new file mode 100644 index 0000000000..db607772c9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/pom.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-web-secure-jdbc</artifactId> + <name>Spring Boot Web Secure JDBC Smoke Test</name> + <description>Spring Boot Web Secure JDBC Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-thymeleaf</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jdbc</artifactId> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/java/smoketest/web/secure/jdbc/SampleWebSecureJdbcApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/java/smoketest/web/secure/jdbc/SampleWebSecureJdbcApplication.java new file mode 100644 index 0000000000..57fa6e5c03 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/java/smoketest/web/secure/jdbc/SampleWebSecureJdbcApplication.java @@ -0,0 +1,81 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.secure.jdbc; + +import java.util.Date; +import java.util.Map; + +import javax.sql.DataSource; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.provisioning.JdbcUserDetailsManager; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@SpringBootApplication +@Controller +public class SampleWebSecureJdbcApplication implements WebMvcConfigurer { + + @GetMapping("/") + public String home(Map<String, Object> model) { + model.put("message", "Hello World"); + model.put("title", "Hello Home"); + model.put("date", new Date()); + return "home"; + } + + @RequestMapping("/foo") + public String foo() { + throw new RuntimeException("Expected exception in controller"); + } + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/login").setViewName("login"); + } + + public static void main(String[] args) { + new SpringApplicationBuilder(SampleWebSecureJdbcApplication.class).run(args); + } + + @Configuration(proxyBeanMethods = false) + protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests().antMatchers("/css/**").permitAll().anyRequest().fullyAuthenticated().and() + .formLogin().loginPage("/login").failureUrl("/login?error").permitAll().and().logout().permitAll(); + } + + @Bean + public JdbcUserDetailsManager jdbcUserDetailsManager(DataSource dataSource) { + JdbcUserDetailsManager jdbcUserDetailsManager = new JdbcUserDetailsManager(); + jdbcUserDetailsManager.setDataSource(dataSource); + return jdbcUserDetailsManager; + } + + } + +} diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/data.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/data.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/data.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/data.sql diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/schema.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/schema.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/schema.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/schema.sql diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/static/css/bootstrap.min.css b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/static/css/bootstrap.min.css similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/static/css/bootstrap.min.css rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/static/css/bootstrap.min.css diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/templates/error.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/templates/error.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/templates/error.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/templates/error.html diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/templates/home.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/templates/home.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/templates/home.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/templates/home.html diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/templates/login.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/templates/login.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/main/resources/templates/login.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/main/resources/templates/login.html diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/test/java/smoketest/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/test/java/smoketest/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java new file mode 100644 index 0000000000..53634d313c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure-jdbc/src/test/java/smoketest/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java @@ -0,0 +1,110 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.secure.jdbc; + +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebSecureJdbcApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @LocalServerPort + private int port; + + @Test + void testHome() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/login"); + } + + @Test + void testLoginPage() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, + new HttpEntity<Void>(headers), String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("_csrf"); + } + + @Test + void testLogin() { + HttpHeaders headers = getHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); + form.set("username", "user"); + form.set("password", "user"); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, + new HttpEntity<>(form, headers), String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/"); + assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); + } + + private HttpHeaders getHeaders() { + HttpHeaders headers = new HttpHeaders(); + ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class); + assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK); + String cookie = page.getHeaders().getFirst("Set-Cookie"); + headers.set("Cookie", cookie); + Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"); + Matcher matcher = pattern.matcher(page.getBody()); + assertThat(matcher.matches()).as(page.getBody()).isTrue(); + headers.set("X-CSRF-TOKEN", matcher.group(1)); + return headers; + } + + @Test + void testCss() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/pom.xml new file mode 100644 index 0000000000..b6f700e81a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/pom.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-web-secure</artifactId> + <name>Spring Boot Web Secure Smoke Test</name> + <description>Spring Boot Web Secure Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-thymeleaf</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/java/smoketest/web/secure/SampleWebSecureApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/java/smoketest/web/secure/SampleWebSecureApplication.java new file mode 100644 index 0000000000..c6cd2a2629 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/java/smoketest/web/secure/SampleWebSecureApplication.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.secure; + +import java.util.Date; +import java.util.Map; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@SpringBootApplication +@Controller +public class SampleWebSecureApplication implements WebMvcConfigurer { + + @GetMapping("/") + public String home(Map<String, Object> model) { + model.put("message", "Hello World"); + model.put("title", "Hello Home"); + model.put("date", new Date()); + return "home"; + } + + @RequestMapping("/foo") + public String foo() { + throw new RuntimeException("Expected exception in controller"); + } + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/login").setViewName("login"); + } + + public static void main(String[] args) { + new SpringApplicationBuilder(SampleWebSecureApplication.class).run(args); + } + + @Configuration(proxyBeanMethods = false) + protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + // @formatter:off + http.authorizeRequests() + .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() + .anyRequest().fullyAuthenticated() + .and() + .formLogin().loginPage("/login").failureUrl("/login?error").permitAll() + .and() + .logout().permitAll(); + // @formatter:on + } + + } + +} diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/schema.sql b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/resources/schema.sql similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/schema.sql rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/resources/schema.sql diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/static/css/bootstrap.min.css b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/resources/static/css/bootstrap.min.css similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/static/css/bootstrap.min.css rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/resources/static/css/bootstrap.min.css diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/templates/error.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/resources/templates/error.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/templates/error.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/resources/templates/error.html diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/templates/home.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/resources/templates/home.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/templates/home.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/resources/templates/home.html diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/templates/login.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/resources/templates/login.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-secure/src/main/resources/templates/login.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/main/resources/templates/login.html diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/SampleSecureApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/SampleSecureApplicationTests.java new file mode 100644 index 0000000000..d41b00b186 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/SampleSecureApplicationTests.java @@ -0,0 +1,110 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.secure; + +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleSecureApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @LocalServerPort + private int port; + + @Test + void testHome() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/login"); + } + + @Test + void testLoginPage() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, + new HttpEntity<Void>(headers), String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("_csrf"); + } + + @Test + void testLogin() { + HttpHeaders headers = getHeaders(); + headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); + form.set("username", "user"); + form.set("password", "password"); + ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, + new HttpEntity<>(form, headers), String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/"); + assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); + } + + private HttpHeaders getHeaders() { + HttpHeaders headers = new HttpHeaders(); + ResponseEntity<String> page = this.restTemplate.getForEntity("/login", String.class); + assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK); + String cookie = page.getHeaders().getFirst("Set-Cookie"); + headers.set("Cookie", cookie); + Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"); + Matcher matcher = pattern.matcher(page.getBody()); + assertThat(matcher.matches()).as(page.getBody()).isTrue(); + headers.set("X-CSRF-TOKEN", matcher.group(1)); + return headers; + } + + @Test + void testCss() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/pom.xml new file mode 100644 index 0000000000..208b6c163b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/pom.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-web-static</artifactId> + <packaging>war</packaging> + <name>Spring Boot Web Static Smoke Test</name> + <description>Spring Boot Web Static Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.webjars</groupId> + <artifactId>bootstrap</artifactId> + <version>3.0.3</version> + </dependency> + <dependency> + <groupId>org.webjars</groupId> + <artifactId>jquery</artifactId> + <version>2.0.3-1</version> + </dependency> + <!-- Provided --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + <scope>provided</scope> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/src/main/java/smoketest/web/staticcontent/SampleWebStaticApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/src/main/java/smoketest/web/staticcontent/SampleWebStaticApplication.java new file mode 100644 index 0000000000..502ec7387a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/src/main/java/smoketest/web/staticcontent/SampleWebStaticApplication.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.staticcontent; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +@SpringBootApplication +public class SampleWebStaticApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleWebStaticApplication.class); + } + + public static void main(String[] args) { + SpringApplication.run(SampleWebStaticApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-web-static/src/main/resources/static/index.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/src/main/resources/static/index.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-static/src/main/resources/static/index.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-static/src/main/resources/static/index.html diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/src/test/java/smoketest/web/staticcontent/SampleWebStaticApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/src/test/java/smoketest/web/staticcontent/SampleWebStaticApplicationTests.java new file mode 100644 index 0000000000..fc96af879c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-static/src/test/java/smoketest/web/staticcontent/SampleWebStaticApplicationTests.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.staticcontent; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebStaticApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testHome() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("<title>Static"); + } + + @Test + void testCss() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/webjars/bootstrap/3.0.3/css/bootstrap.min.css", + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); + assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.valueOf("text/css")); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/pom.xml new file mode 100755 index 0000000000..039f82f332 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/pom.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-web-ui</artifactId> + <name>Spring Boot Web UI Smoke Test</name> + <description>Spring Boot Web UI Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-thymeleaf</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-devtools</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/InMemoryMessageRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/InMemoryMessageRepository.java new file mode 100755 index 0000000000..9ca56fd5b9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/InMemoryMessageRepository.java @@ -0,0 +1,55 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.ui; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicLong; + +public class InMemoryMessageRepository implements MessageRepository { + + private static AtomicLong counter = new AtomicLong(); + + private final ConcurrentMap<Long, Message> messages = new ConcurrentHashMap<>(); + + @Override + public Iterable<Message> findAll() { + return this.messages.values(); + } + + @Override + public Message save(Message message) { + Long id = message.getId(); + if (id == null) { + id = counter.incrementAndGet(); + message.setId(id); + } + this.messages.put(id, message); + return message; + } + + @Override + public Message findMessage(Long id) { + return this.messages.get(id); + } + + @Override + public void deleteMessage(Long id) { + this.messages.remove(id); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/Message.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/Message.java new file mode 100644 index 0000000000..2ee5e99c55 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/Message.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.ui; + +import java.util.Calendar; + +import javax.validation.constraints.NotEmpty; + +public class Message { + + private Long id; + + @NotEmpty(message = "Text is required.") + private String text; + + @NotEmpty(message = "Summary is required.") + private String summary; + + private Calendar created = Calendar.getInstance(); + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public Calendar getCreated() { + return this.created; + } + + public void setCreated(Calendar created) { + this.created = created; + } + + public String getText() { + return this.text; + } + + public void setText(String text) { + this.text = text; + } + + public String getSummary() { + return this.summary; + } + + public void setSummary(String summary) { + this.summary = summary; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/MessageRepository.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/MessageRepository.java new file mode 100755 index 0000000000..abf155dfc6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/MessageRepository.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.ui; + +public interface MessageRepository { + + Iterable<Message> findAll(); + + Message save(Message message); + + Message findMessage(Long id); + + void deleteMessage(Long id); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/SampleWebUiApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/SampleWebUiApplication.java new file mode 100644 index 0000000000..00ac3be5c5 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/SampleWebUiApplication.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.ui; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.core.convert.converter.Converter; + +@SpringBootApplication +public class SampleWebUiApplication { + + @Bean + public MessageRepository messageRepository() { + return new InMemoryMessageRepository(); + } + + @Bean + public Converter<String, Message> messageConverter() { + return new Converter<String, Message>() { + @Override + public Message convert(String id) { + return messageRepository().findMessage(Long.valueOf(id)); + } + }; + } + + public static void main(String[] args) { + SpringApplication.run(SampleWebUiApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/mvc/MessageController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/mvc/MessageController.java new file mode 100755 index 0000000000..0d4ad06313 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/java/smoketest/web/ui/mvc/MessageController.java @@ -0,0 +1,87 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.ui.mvc; + +import javax.validation.Valid; + +import smoketest.web.ui.Message; +import smoketest.web.ui.MessageRepository; + +import org.springframework.stereotype.Controller; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; + +@Controller +@RequestMapping("/") +public class MessageController { + + private final MessageRepository messageRepository; + + public MessageController(MessageRepository messageRepository) { + this.messageRepository = messageRepository; + } + + @GetMapping + public ModelAndView list() { + Iterable<Message> messages = this.messageRepository.findAll(); + return new ModelAndView("messages/list", "messages", messages); + } + + @GetMapping("{id}") + public ModelAndView view(@PathVariable("id") Message message) { + return new ModelAndView("messages/view", "message", message); + } + + @GetMapping(params = "form") + public String createForm(@ModelAttribute Message message) { + return "messages/form"; + } + + @PostMapping + public ModelAndView create(@Valid Message message, BindingResult result, RedirectAttributes redirect) { + if (result.hasErrors()) { + return new ModelAndView("messages/form", "formErrors", result.getAllErrors()); + } + message = this.messageRepository.save(message); + redirect.addFlashAttribute("globalMessage", "view.success"); + return new ModelAndView("redirect:/{message.id}", "message.id", message.getId()); + } + + @RequestMapping("foo") + public String foo() { + throw new RuntimeException("Expected exception in controller"); + } + + @GetMapping("delete/{id}") + public ModelAndView delete(@PathVariable("id") Long id) { + this.messageRepository.deleteMessage(id); + Iterable<Message> messages = this.messageRepository.findAll(); + return new ModelAndView("messages/list", "messages", messages); + } + + @GetMapping("modify/{id}") + public ModelAndView modifyForm(@PathVariable("id") Message message) { + return new ModelAndView("messages/form", "message", message); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/application.properties diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/logback.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/logback.xml similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/logback.xml rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/logback.xml diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/messages.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/messages.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/messages.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/messages.properties diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/static/css/bootstrap.min.css b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/static/css/bootstrap.min.css similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/static/css/bootstrap.min.css rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/static/css/bootstrap.min.css diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/static/favicon.ico b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/static/favicon.ico similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/static/favicon.ico rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/static/favicon.ico diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/fragments.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/templates/fragments.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/fragments.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/templates/fragments.html diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/form.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/templates/messages/form.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/form.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/templates/messages/form.html diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/list.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/templates/messages/list.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/list.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/templates/messages/list.html diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/view.html b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/templates/messages/view.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/view.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/main/resources/templates/messages/view.html diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/test/java/smoketest/web/ui/MessageControllerWebTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/test/java/smoketest/web/ui/MessageControllerWebTests.java new file mode 100644 index 0000000000..b3f672b2c7 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/test/java/smoketest/web/ui/MessageControllerWebTests.java @@ -0,0 +1,105 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.ui; + +import java.util.regex.Pattern; + +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * A Basic Spring MVC Test for the Sample Controller" + * + * @author Biju Kunjummen + * @author Doo-Hwan, Kwak + */ +@SpringBootTest +class MessageControllerWebTests { + + @Autowired + private WebApplicationContext wac; + + private MockMvc mockMvc; + + @BeforeEach + void setup() { + this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); + } + + @Test + void testHome() throws Exception { + this.mockMvc.perform(get("/")).andExpect(status().isOk()) + .andExpect(content().string(containsString("<title>Messages"))); + } + + @Test + void testCreate() throws Exception { + this.mockMvc.perform(post("/").param("text", "FOO text").param("summary", "FOO")).andExpect(status().isFound()) + .andExpect(header().string("location", RegexMatcher.matches("/[0-9]+"))); + } + + @Test + void testCreateValidation() throws Exception { + this.mockMvc.perform(post("/").param("text", "").param("summary", "")).andExpect(status().isOk()) + .andExpect(content().string(containsString("is required"))); + } + + private static class RegexMatcher extends TypeSafeMatcher<String> { + + private final String regex; + + RegexMatcher(String regex) { + this.regex = regex; + } + + @Override + public boolean matchesSafely(String item) { + return Pattern.compile(this.regex).matcher(item).find(); + } + + @Override + public void describeMismatchSafely(String item, Description mismatchDescription) { + mismatchDescription.appendText("was \"").appendText(item).appendText("\""); + } + + @Override + public void describeTo(Description description) { + description.appendText("a string that matches regex: ").appendText(this.regex); + } + + public static org.hamcrest.Matcher<java.lang.String> matches(String regex) { + return new RegexMatcher(regex); + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/test/java/smoketest/web/ui/SampleWebUiApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/test/java/smoketest/web/ui/SampleWebUiApplicationTests.java new file mode 100644 index 0000000000..521a63253e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-web-ui/src/test/java/smoketest/web/ui/SampleWebUiApplicationTests.java @@ -0,0 +1,74 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.web.ui; + +import java.net.URI; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Basic integration tests for demo application. + * + * @author Dave Syer + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebUiApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @LocalServerPort + private int port; + + @Test + void testHome() { + ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("<title>Messages"); + assertThat(entity.getBody()).doesNotContain("layout:fragment"); + } + + @Test + void testCreate() { + MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); + map.set("text", "FOO text"); + map.set("summary", "FOO"); + URI location = this.restTemplate.postForLocation("/", map); + assertThat(location.toString()).contains("localhost:" + this.port); + } + + @Test + void testCss() { + ResponseEntity<String> entity = this.restTemplate + .getForEntity("http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/pom.xml new file mode 100644 index 0000000000..f0b7b169fe --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/pom.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-webflux</artifactId> + <name>Spring Boot WebFlux Smoke Test</name> + <description>Spring Boot WebFlux Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-webflux</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.projectreactor</groupId> + <artifactId>reactor-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <executions> + <execution> + <id>generate build info</id> + <goals> + <goal>build-info</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/EchoHandler.java b/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/EchoHandler.java new file mode 100644 index 0000000000..8ef62d1e7e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/EchoHandler.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.webflux; + +import reactor.core.publisher.Mono; + +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; + +@Component +public class EchoHandler { + + public Mono<ServerResponse> echo(ServerRequest request) { + return ServerResponse.ok().body(request.bodyToMono(String.class), String.class); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/ExampleController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/ExampleController.java new file mode 100644 index 0000000000..b42fbcd2d2 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/ExampleController.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.webflux; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ExampleController { + + @PostMapping(path = "/", consumes = { MediaType.APPLICATION_JSON_VALUE, "!application/xml" }, + produces = MediaType.TEXT_PLAIN_VALUE, headers = "X-Custom=Foo", params = "a!=alpha") + public String example() { + return "Hello World"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/SampleWebFluxApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/SampleWebFluxApplication.java new file mode 100644 index 0000000000..f31e090c01 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/SampleWebFluxApplication.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.webflux; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.ServerResponse; + +import static org.springframework.web.reactive.function.server.RequestPredicates.POST; +import static org.springframework.web.reactive.function.server.RouterFunctions.route; + +@SpringBootApplication +public class SampleWebFluxApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleWebFluxApplication.class, args); + } + + @Bean + public RouterFunction<ServerResponse> monoRouterFunction(EchoHandler echoHandler) { + return route(POST("/echo"), echoHandler::echo); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/WelcomeController.java b/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/WelcomeController.java new file mode 100644 index 0000000000..b7ee83b9c3 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/WelcomeController.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.webflux; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class WelcomeController { + + @GetMapping("/") + public String welcome() { + return "Hello World"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/test/java/smoketest/webflux/SampleWebFluxApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/test/java/smoketest/webflux/SampleWebFluxApplicationTests.java new file mode 100644 index 0000000000..33722d16d9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/test/java/smoketest/webflux/SampleWebFluxApplicationTests.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.webflux; + +import org.junit.jupiter.api.Test; +import reactor.core.publisher.Mono; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.http.MediaType; +import org.springframework.test.web.reactive.server.WebTestClient; + +/** + * Basic integration tests for WebFlux application. + * + * @author Brian Clozel + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebFluxApplicationTests { + + @Autowired + private WebTestClient webClient; + + @Test + void testWelcome() { + this.webClient.get().uri("/").accept(MediaType.TEXT_PLAIN).exchange().expectBody(String.class) + .isEqualTo("Hello World"); + } + + @Test + void testEcho() { + this.webClient.post().uri("/echo").contentType(MediaType.TEXT_PLAIN).accept(MediaType.TEXT_PLAIN) + .body(Mono.just("Hello WebFlux!"), String.class).exchange().expectBody(String.class) + .isEqualTo("Hello WebFlux!"); + } + + @Test + void testActuatorStatus() { + this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk() + .expectBody().json("{\"status\":\"UP\"}"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/pom.xml new file mode 100644 index 0000000000..2d0388c87a --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/pom.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <artifactId>spring-boot-smoke-tests</artifactId> + <groupId>org.springframework.boot</groupId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-webservices</artifactId> + <name>Spring Boot Web Services Smoke Test</name> + <description>Spring Boot Web Services Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web-services</artifactId> + </dependency> + <dependency> + <groupId>jaxen</groupId> + <artifactId>jaxen</artifactId> + </dependency> + <dependency> + <groupId>org.jdom</groupId> + <artifactId>jdom2</artifactId> + </dependency> + <dependency> + <groupId>wsdl4j</groupId> + <artifactId>wsdl4j</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>java11+</id> + <activation> + <jdk>[11,)</jdk> + </activation> + <dependencies> + <dependency> + <groupId>jakarta.activation</groupId> + <artifactId>jakarta.activation-api</artifactId> + </dependency> + <dependency> + <groupId>org.glassfish.jaxb</groupId> + <artifactId>jaxb-runtime</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/SampleWebServicesApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/SampleWebServicesApplication.java new file mode 100644 index 0000000000..69e05936e3 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/SampleWebServicesApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.webservices; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleWebServicesApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleWebServicesApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/WebServiceConfig.java b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/WebServiceConfig.java new file mode 100644 index 0000000000..bc8c10a625 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/WebServiceConfig.java @@ -0,0 +1,38 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.webservices; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.ws.config.annotation.WsConfigurerAdapter; +import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition; +import org.springframework.xml.xsd.XsdSchema; + +@Configuration(proxyBeanMethods = false) +public class WebServiceConfig extends WsConfigurerAdapter { + + @Bean(name = "holiday") + public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) { + DefaultWsdl11Definition wsdl = new DefaultWsdl11Definition(); + wsdl.setPortTypeName("HumanResource"); + wsdl.setLocationUri("/holidayService/"); + wsdl.setTargetNamespace("https://company.example.com/hr/definitions"); + wsdl.setSchema(countriesSchema); + return wsdl; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/endpoint/HolidayEndpoint.java b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/endpoint/HolidayEndpoint.java new file mode 100644 index 0000000000..bd6b862577 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/endpoint/HolidayEndpoint.java @@ -0,0 +1,70 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.webservices.endpoint; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactoryConfigurationException; + +import org.jdom2.Element; +import org.jdom2.JDOMException; +import org.jdom2.Namespace; +import org.jdom2.filter.Filters; +import org.jdom2.xpath.XPathExpression; +import org.jdom2.xpath.XPathFactory; +import smoketest.webservices.service.HumanResourceService; + +import org.springframework.ws.server.endpoint.annotation.Endpoint; +import org.springframework.ws.server.endpoint.annotation.PayloadRoot; +import org.springframework.ws.server.endpoint.annotation.RequestPayload; + +@Endpoint +public class HolidayEndpoint { + + private static final String NAMESPACE_URI = "https://company.example.com/hr/schemas"; + + private XPathExpression<Element> startDateExpression; + + private XPathExpression<Element> endDateExpression; + + private XPathExpression<String> nameExpression; + + private HumanResourceService humanResourceService; + + public HolidayEndpoint(HumanResourceService humanResourceService) + throws JDOMException, XPathFactoryConfigurationException, XPathExpressionException { + this.humanResourceService = humanResourceService; + Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI); + XPathFactory xPathFactory = XPathFactory.instance(); + this.startDateExpression = xPathFactory.compile("//hr:StartDate", Filters.element(), null, namespace); + this.endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(), null, namespace); + this.nameExpression = xPathFactory.compile("concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(), null, + namespace); + } + + @PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest") + public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date startDate = dateFormat.parse(this.startDateExpression.evaluateFirst(holidayRequest).getText()); + Date endDate = dateFormat.parse(this.endDateExpression.evaluateFirst(holidayRequest).getText()); + String name = this.nameExpression.evaluateFirst(holidayRequest); + this.humanResourceService.bookHoliday(startDate, endDate, name); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/service/HumanResourceService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/service/HumanResourceService.java new file mode 100644 index 0000000000..cdfa4547d5 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/service/HumanResourceService.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.webservices.service; + +import java.util.Date; + +public interface HumanResourceService { + + void bookHoliday(Date startDate, Date endDate, String name); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/service/StubHumanResourceService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/service/StubHumanResourceService.java new file mode 100644 index 0000000000..ee8cc8e3be --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/service/StubHumanResourceService.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.webservices.service; + +import java.util.Date; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.stereotype.Service; + +@Service +public class StubHumanResourceService implements HumanResourceService { + + private final Log logger = LogFactory.getLog(StubHumanResourceService.class); + + @Override + public void bookHoliday(Date startDate, Date endDate, String name) { + this.logger.info("Booking holiday for [" + startDate + " - " + endDate + "] for [" + name + "]"); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-webservices/src/main/resources/META-INF/schemas/hr.xsd b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/resources/META-INF/schemas/hr.xsd similarity index 100% rename from spring-boot-samples/spring-boot-sample-webservices/src/main/resources/META-INF/schemas/hr.xsd rename to spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/resources/META-INF/schemas/hr.xsd diff --git a/spring-boot-samples/spring-boot-sample-webservices/src/main/resources/application.properties b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/resources/application.properties similarity index 100% rename from spring-boot-samples/spring-boot-sample-webservices/src/main/resources/application.properties rename to spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/resources/application.properties diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/test/java/smoketest/webservices/SampleWsApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/test/java/smoketest/webservices/SampleWsApplicationTests.java new file mode 100644 index 0000000000..e4a581ce0b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/test/java/smoketest/webservices/SampleWsApplicationTests.java @@ -0,0 +1,64 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.webservices; + +import java.io.StringReader; + +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.ws.client.core.WebServiceTemplate; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ExtendWith(OutputCaptureExtension.class) +class SampleWsApplicationTests { + + private WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); + + @LocalServerPort + private int serverPort; + + @BeforeEach + void setUp() { + this.webServiceTemplate.setDefaultUri("http://localhost:" + this.serverPort + "/services/"); + } + + @Test + void testSendingHolidayRequest(CapturedOutput capturedOutput) { + final String request = "<hr:HolidayRequest xmlns:hr=\"https://company.example.com/hr/schemas\">" + + " <hr:Holiday>" + " <hr:StartDate>2013-10-20</hr:StartDate>" + + " <hr:EndDate>2013-11-22</hr:EndDate>" + " </hr:Holiday>" + " <hr:Employee>" + + " <hr:Number>1</hr:Number>" + " <hr:FirstName>John</hr:FirstName>" + + " <hr:LastName>Doe</hr:LastName>" + " </hr:Employee>" + "</hr:HolidayRequest>"; + StreamSource source = new StreamSource(new StringReader(request)); + StreamResult result = new StreamResult(System.out); + this.webServiceTemplate.sendSourceAndReceiveToResult(source, result); + assertThat(capturedOutput).contains("Booking holiday for"); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/pom.xml new file mode 100755 index 0000000000..c67d7df46e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/pom.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-websocket-jetty</artifactId> + <name>Spring Boot WebSocket Jetty Smoke Test</name> + <description>Spring Boot WebSocket Jetty Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-websocket</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jetty</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/SampleJettyWebSocketsApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/SampleJettyWebSocketsApplication.java new file mode 100644 index 0000000000..98e0405472 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/SampleJettyWebSocketsApplication.java @@ -0,0 +1,90 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty; + +import smoketest.websocket.jetty.client.GreetingService; +import smoketest.websocket.jetty.client.SimpleGreetingService; +import smoketest.websocket.jetty.echo.DefaultEchoService; +import smoketest.websocket.jetty.echo.EchoService; +import smoketest.websocket.jetty.echo.EchoWebSocketHandler; +import smoketest.websocket.jetty.reverse.ReverseWebSocketEndpoint; +import smoketest.websocket.jetty.snake.SnakeWebSocketHandler; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.config.annotation.EnableWebSocket; +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; +import org.springframework.web.socket.handler.PerConnectionWebSocketHandler; +import org.springframework.web.socket.server.standard.ServerEndpointExporter; + +@Configuration(proxyBeanMethods = false) +@EnableAutoConfiguration +@EnableWebSocket +public class SampleJettyWebSocketsApplication extends SpringBootServletInitializer implements WebSocketConfigurer { + + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + registry.addHandler(echoWebSocketHandler(), "/echo").withSockJS(); + registry.addHandler(snakeWebSocketHandler(), "/snake").withSockJS(); + } + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleJettyWebSocketsApplication.class); + } + + @Bean + public EchoService echoService() { + return new DefaultEchoService("Did you say \"%s\"?"); + } + + @Bean + public GreetingService greetingService() { + return new SimpleGreetingService(); + } + + @Bean + public WebSocketHandler echoWebSocketHandler() { + return new EchoWebSocketHandler(echoService()); + } + + @Bean + public WebSocketHandler snakeWebSocketHandler() { + return new PerConnectionWebSocketHandler(SnakeWebSocketHandler.class); + } + + @Bean + public ReverseWebSocketEndpoint reverseWebSocketEndpoint() { + return new ReverseWebSocketEndpoint(); + } + + @Bean + public ServerEndpointExporter serverEndpointExporter() { + return new ServerEndpointExporter(); + } + + public static void main(String[] args) { + SpringApplication.run(SampleJettyWebSocketsApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/client/GreetingService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/client/GreetingService.java new file mode 100644 index 0000000000..4ecf7b1657 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/client/GreetingService.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.client; + +public interface GreetingService { + + String getGreeting(); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/client/SimpleClientWebSocketHandler.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/client/SimpleClientWebSocketHandler.java new file mode 100644 index 0000000000..e17e551df9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/client/SimpleClientWebSocketHandler.java @@ -0,0 +1,60 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.client; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +public class SimpleClientWebSocketHandler extends TextWebSocketHandler { + + protected Log logger = LogFactory.getLog(SimpleClientWebSocketHandler.class); + + private final GreetingService greetingService; + + private final CountDownLatch latch; + + private final AtomicReference<String> messagePayload; + + public SimpleClientWebSocketHandler(GreetingService greetingService, CountDownLatch latch, + AtomicReference<String> message) { + this.greetingService = greetingService; + this.latch = latch; + this.messagePayload = message; + } + + @Override + public void afterConnectionEstablished(WebSocketSession session) throws Exception { + TextMessage message = new TextMessage(this.greetingService.getGreeting()); + session.sendMessage(message); + } + + @Override + public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + this.logger.info("Received: " + message + " (" + this.latch.getCount() + ")"); + session.close(); + this.messagePayload.set(message.getPayload()); + this.latch.countDown(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/client/SimpleGreetingService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/client/SimpleGreetingService.java new file mode 100644 index 0000000000..50fc033191 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/client/SimpleGreetingService.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.client; + +public class SimpleGreetingService implements GreetingService { + + @Override + public String getGreeting() { + return "Hello world!"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/echo/DefaultEchoService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/echo/DefaultEchoService.java new file mode 100644 index 0000000000..2c6b6e6c8f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/echo/DefaultEchoService.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.echo; + +public class DefaultEchoService implements EchoService { + + private final String echoFormat; + + public DefaultEchoService(String echoFormat) { + this.echoFormat = (echoFormat != null) ? echoFormat : "%s"; + } + + @Override + public String getMessage(String message) { + return String.format(this.echoFormat, message); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/echo/EchoService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/echo/EchoService.java new file mode 100644 index 0000000000..8501f0c6fa --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/echo/EchoService.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.echo; + +public interface EchoService { + + String getMessage(String message); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/echo/EchoWebSocketHandler.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/echo/EchoWebSocketHandler.java new file mode 100644 index 0000000000..9ab904ae50 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/echo/EchoWebSocketHandler.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.echo; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.web.socket.CloseStatus; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +/** + * Echo messages by implementing a Spring {@link WebSocketHandler} abstraction. + */ +public class EchoWebSocketHandler extends TextWebSocketHandler { + + private static Log logger = LogFactory.getLog(EchoWebSocketHandler.class); + + private final EchoService echoService; + + public EchoWebSocketHandler(EchoService echoService) { + this.echoService = echoService; + } + + @Override + public void afterConnectionEstablished(WebSocketSession session) { + logger.debug("Opened new session in instance " + this); + } + + @Override + public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + String echoMessage = this.echoService.getMessage(message.getPayload()); + logger.debug(echoMessage); + session.sendMessage(new TextMessage(echoMessage)); + } + + @Override + public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { + session.close(CloseStatus.SERVER_ERROR); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/reverse/ReverseWebSocketEndpoint.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/reverse/ReverseWebSocketEndpoint.java new file mode 100644 index 0000000000..2522e0ff5b --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/reverse/ReverseWebSocketEndpoint.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.reverse; + +import java.io.IOException; + +import javax.websocket.OnMessage; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +@ServerEndpoint("/reverse") +public class ReverseWebSocketEndpoint { + + @OnMessage + public void handleMessage(Session session, String message) throws IOException { + session.getBasicRemote().sendText("Reversed: " + new StringBuilder(message).reverse()); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Direction.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Direction.java new file mode 100644 index 0000000000..a210ae9d66 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Direction.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.snake; + +public enum Direction { + + NONE, NORTH, SOUTH, EAST, WEST + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Location.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Location.java new file mode 100644 index 0000000000..d1e43c6e20 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Location.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.snake; + +public class Location { + + /** + * The X location. + */ + public int x; + + /** + * The Y location. + */ + public int y; + + public Location(int x, int y) { + this.x = x; + this.y = y; + } + + public Location getAdjacentLocation(Direction direction) { + switch (direction) { + case NORTH: + return new Location(this.x, this.y - SnakeUtils.GRID_SIZE); + case SOUTH: + return new Location(this.x, this.y + SnakeUtils.GRID_SIZE); + case EAST: + return new Location(this.x + SnakeUtils.GRID_SIZE, this.y); + case WEST: + return new Location(this.x - SnakeUtils.GRID_SIZE, this.y); + case NONE: + // fall through + default: + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Location location = (Location) o; + if (this.x != location.x) { + return false; + } + if (this.y != location.y) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = this.x; + result = 31 * result + this.y; + return result; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Snake.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Snake.java new file mode 100644 index 0000000000..a996c218dc --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/Snake.java @@ -0,0 +1,156 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.snake; + +import java.util.ArrayDeque; +import java.util.Collection; +import java.util.Deque; + +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; + +public class Snake { + + private static final int DEFAULT_LENGTH = 5; + + private final Deque<Location> tail = new ArrayDeque<>(); + + private final Object monitor = new Object(); + + private final int id; + + private final WebSocketSession session; + + private final String hexColor; + + private Direction direction; + + private int length = DEFAULT_LENGTH; + + private Location head; + + public Snake(int id, WebSocketSession session) { + this.id = id; + this.session = session; + this.hexColor = SnakeUtils.getRandomHexColor(); + resetState(); + } + + private void resetState() { + this.direction = Direction.NONE; + this.head = SnakeUtils.getRandomLocation(); + this.tail.clear(); + this.length = DEFAULT_LENGTH; + } + + private void kill() throws Exception { + synchronized (this.monitor) { + resetState(); + sendMessage("{'type': 'dead'}"); + } + } + + private void reward() throws Exception { + synchronized (this.monitor) { + this.length++; + sendMessage("{'type': 'kill'}"); + } + } + + protected void sendMessage(String msg) throws Exception { + this.session.sendMessage(new TextMessage(msg)); + } + + public void update(Collection<Snake> snakes) throws Exception { + synchronized (this.monitor) { + Location nextLocation = this.head.getAdjacentLocation(this.direction); + if (nextLocation.x >= SnakeUtils.PLAYFIELD_WIDTH) { + nextLocation.x = 0; + } + if (nextLocation.y >= SnakeUtils.PLAYFIELD_HEIGHT) { + nextLocation.y = 0; + } + if (nextLocation.x < 0) { + nextLocation.x = SnakeUtils.PLAYFIELD_WIDTH; + } + if (nextLocation.y < 0) { + nextLocation.y = SnakeUtils.PLAYFIELD_HEIGHT; + } + if (this.direction != Direction.NONE) { + this.tail.addFirst(this.head); + if (this.tail.size() > this.length) { + this.tail.removeLast(); + } + this.head = nextLocation; + } + + handleCollisions(snakes); + } + } + + private void handleCollisions(Collection<Snake> snakes) throws Exception { + for (Snake snake : snakes) { + boolean headCollision = this.id != snake.id && snake.getHead().equals(this.head); + boolean tailCollision = snake.getTail().contains(this.head); + if (headCollision || tailCollision) { + kill(); + if (this.id != snake.id) { + snake.reward(); + } + } + } + } + + public Location getHead() { + synchronized (this.monitor) { + return this.head; + } + } + + public Collection<Location> getTail() { + synchronized (this.monitor) { + return this.tail; + } + } + + public void setDirection(Direction direction) { + synchronized (this.monitor) { + this.direction = direction; + } + } + + public String getLocationsJson() { + synchronized (this.monitor) { + StringBuilder sb = new StringBuilder(); + sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y))); + for (Location location : this.tail) { + sb.append(','); + sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y))); + } + return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb.toString()); + } + } + + public int getId() { + return this.id; + } + + public String getHexColor() { + return this.hexColor; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/SnakeTimer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/SnakeTimer.java new file mode 100644 index 0000000000..eb3a546c73 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/SnakeTimer.java @@ -0,0 +1,117 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.snake; + +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Sets up the timer for the multi-player snake game WebSocket example. + */ +public final class SnakeTimer { + + private static final long TICK_DELAY = 100; + + private static final Object MONITOR = new Object(); + + private static final Log logger = LogFactory.getLog(SnakeTimer.class); + + private static final ConcurrentHashMap<Integer, Snake> snakes = new ConcurrentHashMap<>(); + + private static Timer gameTimer = null; + + private SnakeTimer() { + } + + public static void addSnake(Snake snake) { + synchronized (MONITOR) { + if (snakes.isEmpty()) { + startTimer(); + } + snakes.put(Integer.valueOf(snake.getId()), snake); + } + } + + public static Collection<Snake> getSnakes() { + return Collections.unmodifiableCollection(snakes.values()); + } + + public static void removeSnake(Snake snake) { + synchronized (MONITOR) { + snakes.remove(Integer.valueOf(snake.getId())); + if (snakes.isEmpty()) { + stopTimer(); + } + } + } + + public static void tick() throws Exception { + StringBuilder sb = new StringBuilder(); + for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { + Snake snake = iterator.next(); + snake.update(SnakeTimer.getSnakes()); + sb.append(snake.getLocationsJson()); + if (iterator.hasNext()) { + sb.append(','); + } + } + broadcast(String.format("{'type': 'update', 'data' : [%s]}", sb.toString())); + } + + public static void broadcast(String message) throws Exception { + Collection<Snake> snakes = new CopyOnWriteArrayList<>(SnakeTimer.getSnakes()); + for (Snake snake : snakes) { + try { + snake.sendMessage(message); + } + catch (Throwable ex) { + // if Snake#sendMessage fails the client is removed + removeSnake(snake); + } + } + } + + public static void startTimer() { + gameTimer = new Timer(SnakeTimer.class.getSimpleName() + " Timer"); + gameTimer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + try { + tick(); + } + catch (Throwable ex) { + logger.error("Caught to prevent timer from shutting down", ex); + } + } + }, TICK_DELAY, TICK_DELAY); + } + + public static void stopTimer() { + if (gameTimer != null) { + gameTimer.cancel(); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/SnakeUtils.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/SnakeUtils.java new file mode 100644 index 0000000000..4a097bf120 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/SnakeUtils.java @@ -0,0 +1,66 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.snake; + +import java.awt.Color; +import java.util.Random; + +public final class SnakeUtils { + + /** + * The width of the playfield. + */ + public static final int PLAYFIELD_WIDTH = 640; + + /** + * The height of the playfield. + */ + public static final int PLAYFIELD_HEIGHT = 480; + + /** + * The grid size. + */ + public static final int GRID_SIZE = 10; + + private static final Random random = new Random(); + + private SnakeUtils() { + } + + public static String getRandomHexColor() { + float hue = random.nextFloat(); + // sat between 0.1 and 0.3 + float saturation = (random.nextInt(2000) + 1000) / 10000f; + float luminance = 0.9f; + Color color = Color.getHSBColor(hue, saturation, luminance); + return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); + } + + public static Location getRandomLocation() { + int x = roundByGridSize(random.nextInt(PLAYFIELD_WIDTH)); + int y = roundByGridSize(random.nextInt(PLAYFIELD_HEIGHT)); + return new Location(x, y); + } + + private static int roundByGridSize(int value) { + value = value + (GRID_SIZE / 2); + value = value / GRID_SIZE; + value = value * GRID_SIZE; + return value; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/SnakeWebSocketHandler.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/SnakeWebSocketHandler.java new file mode 100644 index 0000000000..8eaf0a04ca --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/java/smoketest/websocket/jetty/snake/SnakeWebSocketHandler.java @@ -0,0 +1,103 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.snake; + +import java.awt.Color; +import java.util.Iterator; +import java.util.Random; +import java.util.concurrent.atomic.AtomicInteger; + +import org.springframework.web.socket.CloseStatus; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +public class SnakeWebSocketHandler extends TextWebSocketHandler { + + private static final AtomicInteger snakeIds = new AtomicInteger(0); + + private static final Random random = new Random(); + + private final int id; + + private Snake snake; + + public static String getRandomHexColor() { + float hue = random.nextFloat(); + // sat between 0.1 and 0.3 + float saturation = (random.nextInt(2000) + 1000) / 10000f; + float luminance = 0.9f; + Color color = Color.getHSBColor(hue, saturation, luminance); + return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); + } + + public static Location getRandomLocation() { + int x = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_WIDTH)); + int y = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_HEIGHT)); + return new Location(x, y); + } + + private static int roundByGridSize(int value) { + value = value + (SnakeUtils.GRID_SIZE / 2); + value = value / SnakeUtils.GRID_SIZE; + value = value * SnakeUtils.GRID_SIZE; + return value; + } + + public SnakeWebSocketHandler() { + this.id = snakeIds.getAndIncrement(); + } + + @Override + public void afterConnectionEstablished(WebSocketSession session) throws Exception { + this.snake = new Snake(this.id, session); + SnakeTimer.addSnake(this.snake); + StringBuilder sb = new StringBuilder(); + for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { + Snake snake = iterator.next(); + sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor())); + if (iterator.hasNext()) { + sb.append(','); + } + } + SnakeTimer.broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); + } + + @Override + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + String payload = message.getPayload(); + if ("west".equals(payload)) { + this.snake.setDirection(Direction.WEST); + } + else if ("north".equals(payload)) { + this.snake.setDirection(Direction.NORTH); + } + else if ("east".equals(payload)) { + this.snake.setDirection(Direction.EAST); + } + else if ("south".equals(payload)) { + this.snake.setDirection(Direction.SOUTH); + } + } + + @Override + public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { + SnakeTimer.removeSnake(this.snake); + SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/echo.html b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/resources/static/echo.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/echo.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/resources/static/echo.html diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/index.html b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/resources/static/index.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/index.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/resources/static/index.html diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/reverse.html b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/resources/static/reverse.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/reverse.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/resources/static/reverse.html diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/snake.html b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/resources/static/snake.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/resources/static/snake.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/main/resources/static/snake.html diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/test/java/smoketest/websocket/jetty/SampleWebSocketsApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/test/java/smoketest/websocket/jetty/SampleWebSocketsApplicationTests.java new file mode 100644 index 0000000000..c008d10681 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/test/java/smoketest/websocket/jetty/SampleWebSocketsApplicationTests.java @@ -0,0 +1,126 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.jupiter.api.Test; +import smoketest.websocket.jetty.client.GreetingService; +import smoketest.websocket.jetty.client.SimpleClientWebSocketHandler; +import smoketest.websocket.jetty.client.SimpleGreetingService; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.client.WebSocketConnectionManager; +import org.springframework.web.socket.client.standard.StandardWebSocketClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = SampleJettyWebSocketsApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebSocketsApplicationTests { + + private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); + + @LocalServerPort + private int port = 1234; + + @Test + void echoEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); + } + + @Test + void reverseEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/reverse") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); + } + + @Configuration(proxyBeanMethods = false) + static class ClientConfiguration implements CommandLineRunner { + + @Value("${websocket.uri}") + private String webSocketUri; + + private final CountDownLatch latch = new CountDownLatch(1); + + private final AtomicReference<String> messagePayload = new AtomicReference<>(); + + @Override + public void run(String... args) throws Exception { + logger.info("Waiting for response: latch=" + this.latch.getCount()); + if (this.latch.await(10, TimeUnit.SECONDS)) { + logger.info("Got response: " + this.messagePayload.get()); + } + else { + logger.info("Response not received: latch=" + this.latch.getCount()); + } + } + + @Bean + public WebSocketConnectionManager wsConnectionManager() { + + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); + manager.setAutoStartup(true); + + return manager; + } + + @Bean + public StandardWebSocketClient client() { + return new StandardWebSocketClient(); + } + + @Bean + public SimpleClientWebSocketHandler handler() { + return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); + } + + @Bean + public GreetingService greetingService() { + return new SimpleGreetingService(); + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/test/java/smoketest/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/test/java/smoketest/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java new file mode 100644 index 0000000000..674d59b676 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/test/java/smoketest/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java @@ -0,0 +1,141 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.echo; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.jupiter.api.Test; +import smoketest.websocket.jetty.SampleJettyWebSocketsApplication; +import smoketest.websocket.jetty.client.GreetingService; +import smoketest.websocket.jetty.client.SimpleClientWebSocketHandler; +import smoketest.websocket.jetty.client.SimpleGreetingService; +import smoketest.websocket.jetty.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.client.WebSocketConnectionManager; +import org.springframework.web.socket.client.standard.StandardWebSocketClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = { SampleJettyWebSocketsApplication.class, CustomContainerConfiguration.class }, + webEnvironment = WebEnvironment.RANDOM_PORT) +class CustomContainerWebSocketsApplicationTests { + + private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class); + + @LocalServerPort + private int port; + + @Test + void echoEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); + } + + @Test + void reverseEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); + } + + @Configuration(proxyBeanMethods = false) + protected static class CustomContainerConfiguration { + + @Bean + public ServletWebServerFactory webServerFactory() { + return new JettyServletWebServerFactory("/ws", 0); + } + + } + + @Configuration(proxyBeanMethods = false) + static class ClientConfiguration implements CommandLineRunner { + + @Value("${websocket.uri}") + private String webSocketUri; + + private final CountDownLatch latch = new CountDownLatch(1); + + private final AtomicReference<String> messagePayload = new AtomicReference<>(); + + @Override + public void run(String... args) throws Exception { + logger.info("Waiting for response: latch=" + this.latch.getCount()); + if (this.latch.await(10, TimeUnit.SECONDS)) { + logger.info("Got response: " + this.messagePayload.get()); + } + else { + logger.info("Response not received: latch=" + this.latch.getCount()); + } + } + + @Bean + public WebSocketConnectionManager wsConnectionManager() { + + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); + manager.setAutoStartup(true); + + return manager; + } + + @Bean + public StandardWebSocketClient client() { + return new StandardWebSocketClient(); + } + + @Bean + public SimpleClientWebSocketHandler handler() { + return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); + } + + @Bean + public GreetingService greetingService() { + return new SimpleGreetingService(); + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/test/java/smoketest/websocket/jetty/snake/SnakeTimerTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/test/java/smoketest/websocket/jetty/snake/SnakeTimerTests.java new file mode 100644 index 0000000000..538e01f10d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-jetty/src/test/java/smoketest/websocket/jetty/snake/SnakeTimerTests.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.jetty.snake; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.willThrow; +import static org.mockito.Mockito.mock; + +class SnakeTimerTests { + + @Test + void removeDysfunctionalSnakes() throws Exception { + Snake snake = mock(Snake.class); + willThrow(new IOException()).given(snake).sendMessage(anyString()); + SnakeTimer.addSnake(snake); + + SnakeTimer.broadcast(""); + assertThat(SnakeTimer.getSnakes()).hasSize(0); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/pom.xml new file mode 100755 index 0000000000..32a04f1429 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-websocket-tomcat</artifactId> + <name>Spring Boot WebSocket Tomcat Smoke Test</name> + <description>Spring Boot WebSocket Tomcat Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-websocket</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/SampleTomcatWebSocketApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/SampleTomcatWebSocketApplication.java new file mode 100644 index 0000000000..ff50ce1bff --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/SampleTomcatWebSocketApplication.java @@ -0,0 +1,90 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat; + +import smoketest.websocket.tomcat.client.GreetingService; +import smoketest.websocket.tomcat.client.SimpleGreetingService; +import smoketest.websocket.tomcat.echo.DefaultEchoService; +import smoketest.websocket.tomcat.echo.EchoService; +import smoketest.websocket.tomcat.echo.EchoWebSocketHandler; +import smoketest.websocket.tomcat.reverse.ReverseWebSocketEndpoint; +import smoketest.websocket.tomcat.snake.SnakeWebSocketHandler; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.config.annotation.EnableWebSocket; +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; +import org.springframework.web.socket.handler.PerConnectionWebSocketHandler; +import org.springframework.web.socket.server.standard.ServerEndpointExporter; + +@Configuration(proxyBeanMethods = false) +@EnableAutoConfiguration +@EnableWebSocket +public class SampleTomcatWebSocketApplication extends SpringBootServletInitializer implements WebSocketConfigurer { + + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + registry.addHandler(echoWebSocketHandler(), "/echo").withSockJS(); + registry.addHandler(snakeWebSocketHandler(), "/snake").withSockJS(); + } + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleTomcatWebSocketApplication.class); + } + + @Bean + public EchoService echoService() { + return new DefaultEchoService("Did you say \"%s\"?"); + } + + @Bean + public GreetingService greetingService() { + return new SimpleGreetingService(); + } + + @Bean + public WebSocketHandler echoWebSocketHandler() { + return new EchoWebSocketHandler(echoService()); + } + + @Bean + public WebSocketHandler snakeWebSocketHandler() { + return new PerConnectionWebSocketHandler(SnakeWebSocketHandler.class); + } + + @Bean + public ReverseWebSocketEndpoint reverseWebSocketEndpoint() { + return new ReverseWebSocketEndpoint(); + } + + @Bean + public ServerEndpointExporter serverEndpointExporter() { + return new ServerEndpointExporter(); + } + + public static void main(String[] args) { + SpringApplication.run(SampleTomcatWebSocketApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/client/GreetingService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/client/GreetingService.java new file mode 100644 index 0000000000..39390086bb --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/client/GreetingService.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.client; + +public interface GreetingService { + + String getGreeting(); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/client/SimpleClientWebSocketHandler.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/client/SimpleClientWebSocketHandler.java new file mode 100644 index 0000000000..deea079d0e --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/client/SimpleClientWebSocketHandler.java @@ -0,0 +1,60 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.client; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +public class SimpleClientWebSocketHandler extends TextWebSocketHandler { + + protected Log logger = LogFactory.getLog(SimpleClientWebSocketHandler.class); + + private final GreetingService greetingService; + + private final CountDownLatch latch; + + private final AtomicReference<String> messagePayload; + + public SimpleClientWebSocketHandler(GreetingService greetingService, CountDownLatch latch, + AtomicReference<String> message) { + this.greetingService = greetingService; + this.latch = latch; + this.messagePayload = message; + } + + @Override + public void afterConnectionEstablished(WebSocketSession session) throws Exception { + TextMessage message = new TextMessage(this.greetingService.getGreeting()); + session.sendMessage(message); + } + + @Override + public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + this.logger.info("Received: " + message + " (" + this.latch.getCount() + ")"); + session.close(); + this.messagePayload.set(message.getPayload()); + this.latch.countDown(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/client/SimpleGreetingService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/client/SimpleGreetingService.java new file mode 100644 index 0000000000..acf16e2520 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/client/SimpleGreetingService.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.client; + +public class SimpleGreetingService implements GreetingService { + + @Override + public String getGreeting() { + return "Hello world!"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/echo/DefaultEchoService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/echo/DefaultEchoService.java new file mode 100644 index 0000000000..fc60593165 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/echo/DefaultEchoService.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.echo; + +public class DefaultEchoService implements EchoService { + + private final String echoFormat; + + public DefaultEchoService(String echoFormat) { + this.echoFormat = (echoFormat != null) ? echoFormat : "%s"; + } + + @Override + public String getMessage(String message) { + return String.format(this.echoFormat, message); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/echo/EchoService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/echo/EchoService.java new file mode 100644 index 0000000000..f179581639 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/echo/EchoService.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.echo; + +public interface EchoService { + + String getMessage(String message); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/echo/EchoWebSocketHandler.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/echo/EchoWebSocketHandler.java new file mode 100644 index 0000000000..f10b75de0c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/echo/EchoWebSocketHandler.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.echo; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.web.socket.CloseStatus; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +/** + * Echo messages by implementing a Spring {@link WebSocketHandler} abstraction. + */ +public class EchoWebSocketHandler extends TextWebSocketHandler { + + private static Log logger = LogFactory.getLog(EchoWebSocketHandler.class); + + private final EchoService echoService; + + public EchoWebSocketHandler(EchoService echoService) { + this.echoService = echoService; + } + + @Override + public void afterConnectionEstablished(WebSocketSession session) { + logger.debug("Opened new session in instance " + this); + } + + @Override + public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + String echoMessage = this.echoService.getMessage(message.getPayload()); + logger.debug(echoMessage); + session.sendMessage(new TextMessage(echoMessage)); + } + + @Override + public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { + session.close(CloseStatus.SERVER_ERROR); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/reverse/ReverseWebSocketEndpoint.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/reverse/ReverseWebSocketEndpoint.java new file mode 100644 index 0000000000..2e99cff342 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/reverse/ReverseWebSocketEndpoint.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.reverse; + +import java.io.IOException; + +import javax.websocket.OnMessage; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +@ServerEndpoint("/reverse") +public class ReverseWebSocketEndpoint { + + @OnMessage + public void handleMessage(Session session, String message) throws IOException { + session.getBasicRemote().sendText("Reversed: " + new StringBuilder(message).reverse()); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Direction.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Direction.java new file mode 100644 index 0000000000..d8a479e73c --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Direction.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.snake; + +public enum Direction { + + NONE, NORTH, SOUTH, EAST, WEST + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Location.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Location.java new file mode 100644 index 0000000000..1b8ff1bff1 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Location.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.snake; + +public class Location { + + /** + * The X location. + */ + public int x; + + /** + * The Y location. + */ + public int y; + + public Location(int x, int y) { + this.x = x; + this.y = y; + } + + public Location getAdjacentLocation(Direction direction) { + switch (direction) { + case NORTH: + return new Location(this.x, this.y - SnakeUtils.GRID_SIZE); + case SOUTH: + return new Location(this.x, this.y + SnakeUtils.GRID_SIZE); + case EAST: + return new Location(this.x + SnakeUtils.GRID_SIZE, this.y); + case WEST: + return new Location(this.x - SnakeUtils.GRID_SIZE, this.y); + case NONE: + // fall through + default: + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Location location = (Location) o; + if (this.x != location.x) { + return false; + } + if (this.y != location.y) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = this.x; + result = 31 * result + this.y; + return result; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Snake.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Snake.java new file mode 100644 index 0000000000..0d9b5878b3 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/Snake.java @@ -0,0 +1,156 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.snake; + +import java.util.ArrayDeque; +import java.util.Collection; +import java.util.Deque; + +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; + +public class Snake { + + private static final int DEFAULT_LENGTH = 5; + + private final Deque<Location> tail = new ArrayDeque<>(); + + private final Object monitor = new Object(); + + private final int id; + + private final WebSocketSession session; + + private final String hexColor; + + private Direction direction; + + private int length = DEFAULT_LENGTH; + + private Location head; + + public Snake(int id, WebSocketSession session) { + this.id = id; + this.session = session; + this.hexColor = SnakeUtils.getRandomHexColor(); + resetState(); + } + + private void resetState() { + this.direction = Direction.NONE; + this.head = SnakeUtils.getRandomLocation(); + this.tail.clear(); + this.length = DEFAULT_LENGTH; + } + + private void kill() throws Exception { + synchronized (this.monitor) { + resetState(); + sendMessage("{'type': 'dead'}"); + } + } + + private void reward() throws Exception { + synchronized (this.monitor) { + this.length++; + sendMessage("{'type': 'kill'}"); + } + } + + protected void sendMessage(String msg) throws Exception { + this.session.sendMessage(new TextMessage(msg)); + } + + public void update(Collection<Snake> snakes) throws Exception { + synchronized (this.monitor) { + Location nextLocation = this.head.getAdjacentLocation(this.direction); + if (nextLocation.x >= SnakeUtils.PLAYFIELD_WIDTH) { + nextLocation.x = 0; + } + if (nextLocation.y >= SnakeUtils.PLAYFIELD_HEIGHT) { + nextLocation.y = 0; + } + if (nextLocation.x < 0) { + nextLocation.x = SnakeUtils.PLAYFIELD_WIDTH; + } + if (nextLocation.y < 0) { + nextLocation.y = SnakeUtils.PLAYFIELD_HEIGHT; + } + if (this.direction != Direction.NONE) { + this.tail.addFirst(this.head); + if (this.tail.size() > this.length) { + this.tail.removeLast(); + } + this.head = nextLocation; + } + + handleCollisions(snakes); + } + } + + private void handleCollisions(Collection<Snake> snakes) throws Exception { + for (Snake snake : snakes) { + boolean headCollision = this.id != snake.id && snake.getHead().equals(this.head); + boolean tailCollision = snake.getTail().contains(this.head); + if (headCollision || tailCollision) { + kill(); + if (this.id != snake.id) { + snake.reward(); + } + } + } + } + + public Location getHead() { + synchronized (this.monitor) { + return this.head; + } + } + + public Collection<Location> getTail() { + synchronized (this.monitor) { + return this.tail; + } + } + + public void setDirection(Direction direction) { + synchronized (this.monitor) { + this.direction = direction; + } + } + + public String getLocationsJson() { + synchronized (this.monitor) { + StringBuilder sb = new StringBuilder(); + sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y))); + for (Location location : this.tail) { + sb.append(','); + sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y))); + } + return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb.toString()); + } + } + + public int getId() { + return this.id; + } + + public String getHexColor() { + return this.hexColor; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/SnakeTimer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/SnakeTimer.java new file mode 100644 index 0000000000..ab0e1c5aa4 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/SnakeTimer.java @@ -0,0 +1,117 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.snake; + +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Sets up the timer for the multi-player snake game WebSocket example. + */ +public final class SnakeTimer { + + private static final long TICK_DELAY = 100; + + private static final Object MONITOR = new Object(); + + private static final Log logger = LogFactory.getLog(SnakeTimer.class); + + private static final ConcurrentHashMap<Integer, Snake> snakes = new ConcurrentHashMap<>(); + + private static Timer gameTimer = null; + + private SnakeTimer() { + } + + public static void addSnake(Snake snake) { + synchronized (MONITOR) { + if (snakes.isEmpty()) { + startTimer(); + } + snakes.put(Integer.valueOf(snake.getId()), snake); + } + } + + public static Collection<Snake> getSnakes() { + return Collections.unmodifiableCollection(snakes.values()); + } + + public static void removeSnake(Snake snake) { + synchronized (MONITOR) { + snakes.remove(Integer.valueOf(snake.getId())); + if (snakes.isEmpty()) { + stopTimer(); + } + } + } + + public static void tick() throws Exception { + StringBuilder sb = new StringBuilder(); + for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { + Snake snake = iterator.next(); + snake.update(SnakeTimer.getSnakes()); + sb.append(snake.getLocationsJson()); + if (iterator.hasNext()) { + sb.append(','); + } + } + broadcast(String.format("{'type': 'update', 'data' : [%s]}", sb.toString())); + } + + public static void broadcast(String message) throws Exception { + Collection<Snake> snakes = new CopyOnWriteArrayList<>(SnakeTimer.getSnakes()); + for (Snake snake : snakes) { + try { + snake.sendMessage(message); + } + catch (Throwable ex) { + // if Snake#sendMessage fails the client is removed + removeSnake(snake); + } + } + } + + public static void startTimer() { + gameTimer = new Timer(SnakeTimer.class.getSimpleName() + " Timer"); + gameTimer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + try { + tick(); + } + catch (Throwable ex) { + logger.error("Caught to prevent timer from shutting down", ex); + } + } + }, TICK_DELAY, TICK_DELAY); + } + + public static void stopTimer() { + if (gameTimer != null) { + gameTimer.cancel(); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/SnakeUtils.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/SnakeUtils.java new file mode 100644 index 0000000000..91315a242d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/SnakeUtils.java @@ -0,0 +1,66 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.snake; + +import java.awt.Color; +import java.util.Random; + +public final class SnakeUtils { + + /** + * The width of the playfield. + */ + public static final int PLAYFIELD_WIDTH = 640; + + /** + * The height of the playfield. + */ + public static final int PLAYFIELD_HEIGHT = 480; + + /** + * The grid size. + */ + public static final int GRID_SIZE = 10; + + private static final Random random = new Random(); + + private SnakeUtils() { + } + + public static String getRandomHexColor() { + float hue = random.nextFloat(); + // sat between 0.1 and 0.3 + float saturation = (random.nextInt(2000) + 1000) / 10000f; + float luminance = 0.9f; + Color color = Color.getHSBColor(hue, saturation, luminance); + return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); + } + + public static Location getRandomLocation() { + int x = roundByGridSize(random.nextInt(PLAYFIELD_WIDTH)); + int y = roundByGridSize(random.nextInt(PLAYFIELD_HEIGHT)); + return new Location(x, y); + } + + private static int roundByGridSize(int value) { + value = value + (GRID_SIZE / 2); + value = value / GRID_SIZE; + value = value * GRID_SIZE; + return value; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/SnakeWebSocketHandler.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/SnakeWebSocketHandler.java new file mode 100644 index 0000000000..d101119b16 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/java/smoketest/websocket/tomcat/snake/SnakeWebSocketHandler.java @@ -0,0 +1,103 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.snake; + +import java.awt.Color; +import java.util.Iterator; +import java.util.Random; +import java.util.concurrent.atomic.AtomicInteger; + +import org.springframework.web.socket.CloseStatus; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +public class SnakeWebSocketHandler extends TextWebSocketHandler { + + private static final AtomicInteger snakeIds = new AtomicInteger(0); + + private static final Random random = new Random(); + + private final int id; + + private Snake snake; + + public static String getRandomHexColor() { + float hue = random.nextFloat(); + // sat between 0.1 and 0.3 + float saturation = (random.nextInt(2000) + 1000) / 10000f; + float luminance = 0.9f; + Color color = Color.getHSBColor(hue, saturation, luminance); + return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); + } + + public static Location getRandomLocation() { + int x = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_WIDTH)); + int y = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_HEIGHT)); + return new Location(x, y); + } + + private static int roundByGridSize(int value) { + value = value + (SnakeUtils.GRID_SIZE / 2); + value = value / SnakeUtils.GRID_SIZE; + value = value * SnakeUtils.GRID_SIZE; + return value; + } + + public SnakeWebSocketHandler() { + this.id = snakeIds.getAndIncrement(); + } + + @Override + public void afterConnectionEstablished(WebSocketSession session) throws Exception { + this.snake = new Snake(this.id, session); + SnakeTimer.addSnake(this.snake); + StringBuilder sb = new StringBuilder(); + for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { + Snake snake = iterator.next(); + sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor())); + if (iterator.hasNext()) { + sb.append(','); + } + } + SnakeTimer.broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); + } + + @Override + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + String payload = message.getPayload(); + if ("west".equals(payload)) { + this.snake.setDirection(Direction.WEST); + } + else if ("north".equals(payload)) { + this.snake.setDirection(Direction.NORTH); + } + else if ("east".equals(payload)) { + this.snake.setDirection(Direction.EAST); + } + else if ("south".equals(payload)) { + this.snake.setDirection(Direction.SOUTH); + } + } + + @Override + public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { + SnakeTimer.removeSnake(this.snake); + SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/echo.html b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/resources/static/echo.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/echo.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/resources/static/echo.html diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/index.html b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/resources/static/index.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/index.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/resources/static/index.html diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/reverse.html b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/resources/static/reverse.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/reverse.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/resources/static/reverse.html diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/snake.html b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/resources/static/snake.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/resources/static/snake.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/main/resources/static/snake.html diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/test/java/smoketest/websocket/tomcat/SampleWebSocketsApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/test/java/smoketest/websocket/tomcat/SampleWebSocketsApplicationTests.java new file mode 100644 index 0000000000..482d222a42 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/test/java/smoketest/websocket/tomcat/SampleWebSocketsApplicationTests.java @@ -0,0 +1,126 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.jupiter.api.Test; +import smoketest.websocket.tomcat.client.GreetingService; +import smoketest.websocket.tomcat.client.SimpleClientWebSocketHandler; +import smoketest.websocket.tomcat.client.SimpleGreetingService; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.client.WebSocketConnectionManager; +import org.springframework.web.socket.client.standard.StandardWebSocketClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = SampleTomcatWebSocketApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebSocketsApplicationTests { + + private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); + + @LocalServerPort + private int port = 1234; + + @Test + void echoEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); + } + + @Test + void reverseEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/reverse") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); + } + + @Configuration(proxyBeanMethods = false) + static class ClientConfiguration implements CommandLineRunner { + + @Value("${websocket.uri}") + private String webSocketUri; + + private final CountDownLatch latch = new CountDownLatch(1); + + private final AtomicReference<String> messagePayload = new AtomicReference<>(); + + @Override + public void run(String... args) throws Exception { + logger.info("Waiting for response: latch=" + this.latch.getCount()); + if (this.latch.await(10, TimeUnit.SECONDS)) { + logger.info("Got response: " + this.messagePayload.get()); + } + else { + logger.info("Response not received: latch=" + this.latch.getCount()); + } + } + + @Bean + public WebSocketConnectionManager wsConnectionManager() { + + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); + manager.setAutoStartup(true); + + return manager; + } + + @Bean + public StandardWebSocketClient client() { + return new StandardWebSocketClient(); + } + + @Bean + public SimpleClientWebSocketHandler handler() { + return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); + } + + @Bean + public GreetingService greetingService() { + return new SimpleGreetingService(); + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/test/java/smoketest/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/test/java/smoketest/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java new file mode 100644 index 0000000000..fc55bbc3f9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/test/java/smoketest/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java @@ -0,0 +1,141 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.echo; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.jupiter.api.Test; +import smoketest.websocket.tomcat.SampleTomcatWebSocketApplication; +import smoketest.websocket.tomcat.client.GreetingService; +import smoketest.websocket.tomcat.client.SimpleClientWebSocketHandler; +import smoketest.websocket.tomcat.client.SimpleGreetingService; +import smoketest.websocket.tomcat.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.client.WebSocketConnectionManager; +import org.springframework.web.socket.client.standard.StandardWebSocketClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = { SampleTomcatWebSocketApplication.class, CustomContainerConfiguration.class }, + webEnvironment = WebEnvironment.RANDOM_PORT) +class CustomContainerWebSocketsApplicationTests { + + private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class); + + @LocalServerPort + private int port; + + @Test + void echoEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); + } + + @Test + void reverseEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); + } + + @Configuration(proxyBeanMethods = false) + protected static class CustomContainerConfiguration { + + @Bean + public ServletWebServerFactory webServerFactory() { + return new TomcatServletWebServerFactory("/ws", 0); + } + + } + + @Configuration(proxyBeanMethods = false) + static class ClientConfiguration implements CommandLineRunner { + + @Value("${websocket.uri}") + private String webSocketUri; + + private final CountDownLatch latch = new CountDownLatch(1); + + private final AtomicReference<String> messagePayload = new AtomicReference<>(); + + @Override + public void run(String... args) throws Exception { + logger.info("Waiting for response: latch=" + this.latch.getCount()); + if (this.latch.await(10, TimeUnit.SECONDS)) { + logger.info("Got response: " + this.messagePayload.get()); + } + else { + logger.info("Response not received: latch=" + this.latch.getCount()); + } + } + + @Bean + public WebSocketConnectionManager wsConnectionManager() { + + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); + manager.setAutoStartup(true); + + return manager; + } + + @Bean + public StandardWebSocketClient client() { + return new StandardWebSocketClient(); + } + + @Bean + public SimpleClientWebSocketHandler handler() { + return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); + } + + @Bean + public GreetingService greetingService() { + return new SimpleGreetingService(); + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/test/java/smoketest/websocket/tomcat/snake/SnakeTimerTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/test/java/smoketest/websocket/tomcat/snake/SnakeTimerTests.java new file mode 100644 index 0000000000..de16bcbf85 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-tomcat/src/test/java/smoketest/websocket/tomcat/snake/SnakeTimerTests.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.tomcat.snake; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.willThrow; +import static org.mockito.Mockito.mock; + +class SnakeTimerTests { + + @Test + void removeDysfunctionalSnakes() throws Exception { + Snake snake = mock(Snake.class); + willThrow(new IOException()).given(snake).sendMessage(anyString()); + SnakeTimer.addSnake(snake); + SnakeTimer.broadcast(""); + assertThat(SnakeTimer.getSnakes()).hasSize(0); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/pom.xml new file mode 100755 index 0000000000..8d97a86999 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/pom.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-websocket-undertow</artifactId> + <name>Spring Boot WebSocket Undertow Smoke Test</name> + <description>Spring Boot WebSocket Undertow Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-websocket</artifactId> + <exclusions> + <exclusion> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-undertow</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/SampleUndertowWebSocketsApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/SampleUndertowWebSocketsApplication.java new file mode 100644 index 0000000000..d9be3aeeed --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/SampleUndertowWebSocketsApplication.java @@ -0,0 +1,90 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow; + +import smoketest.websocket.undertow.client.GreetingService; +import smoketest.websocket.undertow.client.SimpleGreetingService; +import smoketest.websocket.undertow.echo.DefaultEchoService; +import smoketest.websocket.undertow.echo.EchoService; +import smoketest.websocket.undertow.echo.EchoWebSocketHandler; +import smoketest.websocket.undertow.reverse.ReverseWebSocketEndpoint; +import smoketest.websocket.undertow.snake.SnakeWebSocketHandler; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.config.annotation.EnableWebSocket; +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; +import org.springframework.web.socket.handler.PerConnectionWebSocketHandler; +import org.springframework.web.socket.server.standard.ServerEndpointExporter; + +@Configuration(proxyBeanMethods = false) +@EnableAutoConfiguration +@EnableWebSocket +public class SampleUndertowWebSocketsApplication extends SpringBootServletInitializer implements WebSocketConfigurer { + + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + registry.addHandler(echoWebSocketHandler(), "/echo").setAllowedOrigins("*").withSockJS(); + registry.addHandler(snakeWebSocketHandler(), "/snake").setAllowedOrigins("*").withSockJS(); + } + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleUndertowWebSocketsApplication.class); + } + + @Bean + public EchoService echoService() { + return new DefaultEchoService("Did you say \"%s\"?"); + } + + @Bean + public GreetingService greetingService() { + return new SimpleGreetingService(); + } + + @Bean + public WebSocketHandler echoWebSocketHandler() { + return new EchoWebSocketHandler(echoService()); + } + + @Bean + public WebSocketHandler snakeWebSocketHandler() { + return new PerConnectionWebSocketHandler(SnakeWebSocketHandler.class); + } + + @Bean + public ReverseWebSocketEndpoint reverseWebSocketEndpoint() { + return new ReverseWebSocketEndpoint(); + } + + @Bean + public ServerEndpointExporter serverEndpointExporter() { + return new ServerEndpointExporter(); + } + + public static void main(String[] args) { + SpringApplication.run(SampleUndertowWebSocketsApplication.class, args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/client/GreetingService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/client/GreetingService.java new file mode 100644 index 0000000000..cd93c7a180 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/client/GreetingService.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.client; + +public interface GreetingService { + + String getGreeting(); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/client/SimpleClientWebSocketHandler.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/client/SimpleClientWebSocketHandler.java new file mode 100644 index 0000000000..312d02fdc5 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/client/SimpleClientWebSocketHandler.java @@ -0,0 +1,60 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.client; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +public class SimpleClientWebSocketHandler extends TextWebSocketHandler { + + protected Log logger = LogFactory.getLog(SimpleClientWebSocketHandler.class); + + private final GreetingService greetingService; + + private final CountDownLatch latch; + + private final AtomicReference<String> messagePayload; + + public SimpleClientWebSocketHandler(GreetingService greetingService, CountDownLatch latch, + AtomicReference<String> message) { + this.greetingService = greetingService; + this.latch = latch; + this.messagePayload = message; + } + + @Override + public void afterConnectionEstablished(WebSocketSession session) throws Exception { + TextMessage message = new TextMessage(this.greetingService.getGreeting()); + session.sendMessage(message); + } + + @Override + public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + this.logger.info("Received: " + message + " (" + this.latch.getCount() + ")"); + session.close(); + this.messagePayload.set(message.getPayload()); + this.latch.countDown(); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/client/SimpleGreetingService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/client/SimpleGreetingService.java new file mode 100644 index 0000000000..c140977d04 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/client/SimpleGreetingService.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.client; + +public class SimpleGreetingService implements GreetingService { + + @Override + public String getGreeting() { + return "Hello world!"; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/echo/DefaultEchoService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/echo/DefaultEchoService.java new file mode 100644 index 0000000000..48a964920f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/echo/DefaultEchoService.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.echo; + +public class DefaultEchoService implements EchoService { + + private final String echoFormat; + + public DefaultEchoService(String echoFormat) { + this.echoFormat = (echoFormat != null) ? echoFormat : "%s"; + } + + @Override + public String getMessage(String message) { + return String.format(this.echoFormat, message); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/echo/EchoService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/echo/EchoService.java new file mode 100644 index 0000000000..837fcb1873 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/echo/EchoService.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.echo; + +public interface EchoService { + + String getMessage(String message); + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/echo/EchoWebSocketHandler.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/echo/EchoWebSocketHandler.java new file mode 100644 index 0000000000..543946e7ba --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/echo/EchoWebSocketHandler.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.echo; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.web.socket.CloseStatus; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +/** + * Echo messages by implementing a Spring {@link WebSocketHandler} abstraction. + */ +public class EchoWebSocketHandler extends TextWebSocketHandler { + + private static Log logger = LogFactory.getLog(EchoWebSocketHandler.class); + + private final EchoService echoService; + + public EchoWebSocketHandler(EchoService echoService) { + this.echoService = echoService; + } + + @Override + public void afterConnectionEstablished(WebSocketSession session) { + logger.debug("Opened new session in instance " + this); + } + + @Override + public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + String echoMessage = this.echoService.getMessage(message.getPayload()); + logger.debug(echoMessage); + session.sendMessage(new TextMessage(echoMessage)); + } + + @Override + public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { + session.close(CloseStatus.SERVER_ERROR); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/reverse/ReverseWebSocketEndpoint.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/reverse/ReverseWebSocketEndpoint.java new file mode 100644 index 0000000000..fcfcd11738 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/reverse/ReverseWebSocketEndpoint.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.reverse; + +import java.io.IOException; + +import javax.websocket.OnMessage; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +@ServerEndpoint("/reverse") +public class ReverseWebSocketEndpoint { + + @OnMessage + public void handleMessage(Session session, String message) throws IOException { + session.getBasicRemote().sendText("Reversed: " + new StringBuilder(message).reverse()); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Direction.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Direction.java new file mode 100644 index 0000000000..3648e33367 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Direction.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.snake; + +public enum Direction { + + NONE, NORTH, SOUTH, EAST, WEST + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Location.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Location.java new file mode 100644 index 0000000000..ae6999b8a6 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Location.java @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.snake; + +public class Location { + + /** + * The X location. + */ + public int x; + + /** + * The Y location. + */ + public int y; + + public Location(int x, int y) { + this.x = x; + this.y = y; + } + + public Location getAdjacentLocation(Direction direction) { + switch (direction) { + case NORTH: + return new Location(this.x, this.y - SnakeUtils.GRID_SIZE); + case SOUTH: + return new Location(this.x, this.y + SnakeUtils.GRID_SIZE); + case EAST: + return new Location(this.x + SnakeUtils.GRID_SIZE, this.y); + case WEST: + return new Location(this.x - SnakeUtils.GRID_SIZE, this.y); + case NONE: + // fall through + default: + return this; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Location location = (Location) o; + if (this.x != location.x) { + return false; + } + if (this.y != location.y) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = this.x; + result = 31 * result + this.y; + return result; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Snake.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Snake.java new file mode 100644 index 0000000000..f996c36417 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/Snake.java @@ -0,0 +1,156 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.snake; + +import java.util.ArrayDeque; +import java.util.Collection; +import java.util.Deque; + +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; + +public class Snake { + + private static final int DEFAULT_LENGTH = 5; + + private final Deque<Location> tail = new ArrayDeque<>(); + + private final Object monitor = new Object(); + + private final int id; + + private final WebSocketSession session; + + private final String hexColor; + + private Direction direction; + + private int length = DEFAULT_LENGTH; + + private Location head; + + public Snake(int id, WebSocketSession session) { + this.id = id; + this.session = session; + this.hexColor = SnakeUtils.getRandomHexColor(); + resetState(); + } + + private void resetState() { + this.direction = Direction.NONE; + this.head = SnakeUtils.getRandomLocation(); + this.tail.clear(); + this.length = DEFAULT_LENGTH; + } + + private void kill() throws Exception { + synchronized (this.monitor) { + resetState(); + sendMessage("{'type': 'dead'}"); + } + } + + private void reward() throws Exception { + synchronized (this.monitor) { + this.length++; + sendMessage("{'type': 'kill'}"); + } + } + + protected void sendMessage(String msg) throws Exception { + this.session.sendMessage(new TextMessage(msg)); + } + + public void update(Collection<Snake> snakes) throws Exception { + synchronized (this.monitor) { + Location nextLocation = this.head.getAdjacentLocation(this.direction); + if (nextLocation.x >= SnakeUtils.PLAYFIELD_WIDTH) { + nextLocation.x = 0; + } + if (nextLocation.y >= SnakeUtils.PLAYFIELD_HEIGHT) { + nextLocation.y = 0; + } + if (nextLocation.x < 0) { + nextLocation.x = SnakeUtils.PLAYFIELD_WIDTH; + } + if (nextLocation.y < 0) { + nextLocation.y = SnakeUtils.PLAYFIELD_HEIGHT; + } + if (this.direction != Direction.NONE) { + this.tail.addFirst(this.head); + if (this.tail.size() > this.length) { + this.tail.removeLast(); + } + this.head = nextLocation; + } + + handleCollisions(snakes); + } + } + + private void handleCollisions(Collection<Snake> snakes) throws Exception { + for (Snake snake : snakes) { + boolean headCollision = this.id != snake.id && snake.getHead().equals(this.head); + boolean tailCollision = snake.getTail().contains(this.head); + if (headCollision || tailCollision) { + kill(); + if (this.id != snake.id) { + snake.reward(); + } + } + } + } + + public Location getHead() { + synchronized (this.monitor) { + return this.head; + } + } + + public Collection<Location> getTail() { + synchronized (this.monitor) { + return this.tail; + } + } + + public void setDirection(Direction direction) { + synchronized (this.monitor) { + this.direction = direction; + } + } + + public String getLocationsJson() { + synchronized (this.monitor) { + StringBuilder sb = new StringBuilder(); + sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y))); + for (Location location : this.tail) { + sb.append(','); + sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y))); + } + return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb.toString()); + } + } + + public int getId() { + return this.id; + } + + public String getHexColor() { + return this.hexColor; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/SnakeTimer.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/SnakeTimer.java new file mode 100644 index 0000000000..7c2786bbf9 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/SnakeTimer.java @@ -0,0 +1,117 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.snake; + +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Sets up the timer for the multi-player snake game WebSocket example. + */ +public final class SnakeTimer { + + private static final long TICK_DELAY = 100; + + private static final Object MONITOR = new Object(); + + private static final Log logger = LogFactory.getLog(SnakeTimer.class); + + private static final ConcurrentHashMap<Integer, Snake> snakes = new ConcurrentHashMap<>(); + + private static Timer gameTimer = null; + + private SnakeTimer() { + } + + public static void addSnake(Snake snake) { + synchronized (MONITOR) { + if (snakes.isEmpty()) { + startTimer(); + } + snakes.put(Integer.valueOf(snake.getId()), snake); + } + } + + public static Collection<Snake> getSnakes() { + return Collections.unmodifiableCollection(snakes.values()); + } + + public static void removeSnake(Snake snake) { + synchronized (MONITOR) { + snakes.remove(Integer.valueOf(snake.getId())); + if (snakes.isEmpty()) { + stopTimer(); + } + } + } + + public static void tick() throws Exception { + StringBuilder sb = new StringBuilder(); + for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { + Snake snake = iterator.next(); + snake.update(SnakeTimer.getSnakes()); + sb.append(snake.getLocationsJson()); + if (iterator.hasNext()) { + sb.append(','); + } + } + broadcast(String.format("{'type': 'update', 'data' : [%s]}", sb.toString())); + } + + public static void broadcast(String message) throws Exception { + Collection<Snake> snakes = new CopyOnWriteArrayList<>(SnakeTimer.getSnakes()); + for (Snake snake : snakes) { + try { + snake.sendMessage(message); + } + catch (Throwable ex) { + // if Snake#sendMessage fails the client is removed + removeSnake(snake); + } + } + } + + public static void startTimer() { + gameTimer = new Timer(SnakeTimer.class.getSimpleName() + " Timer"); + gameTimer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + try { + tick(); + } + catch (Throwable ex) { + logger.error("Caught to prevent timer from shutting down", ex); + } + } + }, TICK_DELAY, TICK_DELAY); + } + + public static void stopTimer() { + if (gameTimer != null) { + gameTimer.cancel(); + } + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/SnakeUtils.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/SnakeUtils.java new file mode 100644 index 0000000000..a069bd9ee0 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/SnakeUtils.java @@ -0,0 +1,66 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.snake; + +import java.awt.Color; +import java.util.Random; + +public final class SnakeUtils { + + /** + * The width of the playfield. + */ + public static final int PLAYFIELD_WIDTH = 640; + + /** + * The height of the playfield. + */ + public static final int PLAYFIELD_HEIGHT = 480; + + /** + * The grid size. + */ + public static final int GRID_SIZE = 10; + + private static final Random random = new Random(); + + private SnakeUtils() { + } + + public static String getRandomHexColor() { + float hue = random.nextFloat(); + // sat between 0.1 and 0.3 + float saturation = (random.nextInt(2000) + 1000) / 10000f; + float luminance = 0.9f; + Color color = Color.getHSBColor(hue, saturation, luminance); + return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); + } + + public static Location getRandomLocation() { + int x = roundByGridSize(random.nextInt(PLAYFIELD_WIDTH)); + int y = roundByGridSize(random.nextInt(PLAYFIELD_HEIGHT)); + return new Location(x, y); + } + + private static int roundByGridSize(int value) { + value = value + (GRID_SIZE / 2); + value = value / GRID_SIZE; + value = value * GRID_SIZE; + return value; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/SnakeWebSocketHandler.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/SnakeWebSocketHandler.java new file mode 100644 index 0000000000..8583e86cbb --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/java/smoketest/websocket/undertow/snake/SnakeWebSocketHandler.java @@ -0,0 +1,103 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.snake; + +import java.awt.Color; +import java.util.Iterator; +import java.util.Random; +import java.util.concurrent.atomic.AtomicInteger; + +import org.springframework.web.socket.CloseStatus; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +public class SnakeWebSocketHandler extends TextWebSocketHandler { + + private static final AtomicInteger snakeIds = new AtomicInteger(0); + + private static final Random random = new Random(); + + private final int id; + + private Snake snake; + + public static String getRandomHexColor() { + float hue = random.nextFloat(); + // sat between 0.1 and 0.3 + float saturation = (random.nextInt(2000) + 1000) / 10000f; + float luminance = 0.9f; + Color color = Color.getHSBColor(hue, saturation, luminance); + return '#' + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1); + } + + public static Location getRandomLocation() { + int x = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_WIDTH)); + int y = roundByGridSize(random.nextInt(SnakeUtils.PLAYFIELD_HEIGHT)); + return new Location(x, y); + } + + private static int roundByGridSize(int value) { + value = value + (SnakeUtils.GRID_SIZE / 2); + value = value / SnakeUtils.GRID_SIZE; + value = value * SnakeUtils.GRID_SIZE; + return value; + } + + public SnakeWebSocketHandler() { + this.id = snakeIds.getAndIncrement(); + } + + @Override + public void afterConnectionEstablished(WebSocketSession session) throws Exception { + this.snake = new Snake(this.id, session); + SnakeTimer.addSnake(this.snake); + StringBuilder sb = new StringBuilder(); + for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) { + Snake snake = iterator.next(); + sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor())); + if (iterator.hasNext()) { + sb.append(','); + } + } + SnakeTimer.broadcast(String.format("{'type': 'join','data':[%s]}", sb.toString())); + } + + @Override + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + String payload = message.getPayload(); + if ("west".equals(payload)) { + this.snake.setDirection(Direction.WEST); + } + else if ("north".equals(payload)) { + this.snake.setDirection(Direction.NORTH); + } + else if ("east".equals(payload)) { + this.snake.setDirection(Direction.EAST); + } + else if ("south".equals(payload)) { + this.snake.setDirection(Direction.SOUTH); + } + } + + @Override + public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { + SnakeTimer.removeSnake(this.snake); + SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id))); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/echo.html b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/resources/static/echo.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/echo.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/resources/static/echo.html diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/index.html b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/resources/static/index.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/index.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/resources/static/index.html diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/reverse.html b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/resources/static/reverse.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/reverse.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/resources/static/reverse.html diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/snake.html b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/resources/static/snake.html similarity index 100% rename from spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/resources/static/snake.html rename to spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/main/resources/static/snake.html diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/test/java/smoketest/websocket/undertow/SampleWebSocketsApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/test/java/smoketest/websocket/undertow/SampleWebSocketsApplicationTests.java new file mode 100644 index 0000000000..725fe8779d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/test/java/smoketest/websocket/undertow/SampleWebSocketsApplicationTests.java @@ -0,0 +1,126 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.jupiter.api.Test; +import smoketest.websocket.undertow.client.GreetingService; +import smoketest.websocket.undertow.client.SimpleClientWebSocketHandler; +import smoketest.websocket.undertow.client.SimpleGreetingService; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.client.WebSocketConnectionManager; +import org.springframework.web.socket.client.standard.StandardWebSocketClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = SampleUndertowWebSocketsApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleWebSocketsApplicationTests { + + private static Log logger = LogFactory.getLog(SampleWebSocketsApplicationTests.class); + + @LocalServerPort + private int port = 1234; + + @Test + void echoEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); + } + + @Test + void reverseEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/reverse") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); + } + + @Configuration(proxyBeanMethods = false) + static class ClientConfiguration implements CommandLineRunner { + + @Value("${websocket.uri}") + private String webSocketUri; + + private final CountDownLatch latch = new CountDownLatch(1); + + private final AtomicReference<String> messagePayload = new AtomicReference<>(); + + @Override + public void run(String... args) throws Exception { + logger.info("Waiting for response: latch=" + this.latch.getCount()); + if (this.latch.await(10, TimeUnit.SECONDS)) { + logger.info("Got response: " + this.messagePayload.get()); + } + else { + logger.info("Response not received: latch=" + this.latch.getCount()); + } + } + + @Bean + public WebSocketConnectionManager wsConnectionManager() { + + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); + manager.setAutoStartup(true); + + return manager; + } + + @Bean + public StandardWebSocketClient client() { + return new StandardWebSocketClient(); + } + + @Bean + public SimpleClientWebSocketHandler handler() { + return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); + } + + @Bean + public GreetingService greetingService() { + return new SimpleGreetingService(); + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/test/java/smoketest/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/test/java/smoketest/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java new file mode 100644 index 0000000000..9dfc5eeae0 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/test/java/smoketest/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java @@ -0,0 +1,141 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.echo; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.jupiter.api.Test; +import smoketest.websocket.undertow.SampleUndertowWebSocketsApplication; +import smoketest.websocket.undertow.client.GreetingService; +import smoketest.websocket.undertow.client.SimpleClientWebSocketHandler; +import smoketest.websocket.undertow.client.SimpleGreetingService; +import smoketest.websocket.undertow.echo.CustomContainerWebSocketsApplicationTests.CustomContainerConfiguration; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.client.WebSocketConnectionManager; +import org.springframework.web.socket.client.standard.StandardWebSocketClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = { SampleUndertowWebSocketsApplication.class, CustomContainerConfiguration.class }, + webEnvironment = WebEnvironment.RANDOM_PORT) +class CustomContainerWebSocketsApplicationTests { + + private static Log logger = LogFactory.getLog(CustomContainerWebSocketsApplicationTests.class); + + @LocalServerPort + private int port; + + @Test + void echoEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Did you say \"Hello world!\"?"); + } + + @Test + void reverseEndpoint() { + ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, + PropertyPlaceholderAutoConfiguration.class) + .properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse") + .run("--spring.main.web-application-type=none"); + long count = context.getBean(ClientConfiguration.class).latch.getCount(); + AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload; + context.close(); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); + } + + @Configuration(proxyBeanMethods = false) + protected static class CustomContainerConfiguration { + + @Bean + public ServletWebServerFactory webServerFactory() { + return new UndertowServletWebServerFactory("/ws", 0); + } + + } + + @Configuration(proxyBeanMethods = false) + static class ClientConfiguration implements CommandLineRunner { + + @Value("${websocket.uri}") + private String webSocketUri; + + private final CountDownLatch latch = new CountDownLatch(1); + + private final AtomicReference<String> messagePayload = new AtomicReference<>(); + + @Override + public void run(String... args) throws Exception { + logger.info("Waiting for response: latch=" + this.latch.getCount()); + if (this.latch.await(10, TimeUnit.SECONDS)) { + logger.info("Got response: " + this.messagePayload.get()); + } + else { + logger.info("Response not received: latch=" + this.latch.getCount()); + } + } + + @Bean + public WebSocketConnectionManager wsConnectionManager() { + + WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), this.webSocketUri); + manager.setAutoStartup(true); + + return manager; + } + + @Bean + public StandardWebSocketClient client() { + return new StandardWebSocketClient(); + } + + @Bean + public SimpleClientWebSocketHandler handler() { + return new SimpleClientWebSocketHandler(greetingService(), this.latch, this.messagePayload); + } + + @Bean + public GreetingService greetingService() { + return new SimpleGreetingService(); + } + + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/test/java/smoketest/websocket/undertow/snake/SnakeTimerTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/test/java/smoketest/websocket/undertow/snake/SnakeTimerTests.java new file mode 100644 index 0000000000..246231ad6d --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-websocket-undertow/src/test/java/smoketest/websocket/undertow/snake/SnakeTimerTests.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.websocket.undertow.snake; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.willThrow; +import static org.mockito.Mockito.mock; + +class SnakeTimerTests { + + @Test + void removeDysfunctionalSnakes() throws Exception { + Snake snake = mock(Snake.class); + willThrow(new IOException()).given(snake).sendMessage(anyString()); + SnakeTimer.addSnake(snake); + SnakeTimer.broadcast(""); + assertThat(SnakeTimer.getSnakes()).hasSize(0); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-xml/pom.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-xml/pom.xml new file mode 100644 index 0000000000..d93daf947f --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-xml/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <!-- Your own application should inherit from spring-boot-starter-parent --> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-smoke-tests</artifactId> + <version>${revision}</version> + </parent> + <artifactId>spring-boot-smoke-test-xml</artifactId> + <name>Spring Boot XML Smoke Test</name> + <description>Spring Boot XML Smoke Test</description> + <properties> + <main.basedir>${basedir}/../..</main.basedir> + </properties> + <dependencies> + <!-- Compile --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <!-- Test --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/main/java/smoketest/xml/SampleSpringXmlApplication.java b/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/main/java/smoketest/xml/SampleSpringXmlApplication.java new file mode 100644 index 0000000000..4b0dd3f132 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/main/java/smoketest/xml/SampleSpringXmlApplication.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.xml; + +import java.util.Collections; + +import smoketest.xml.service.HelloWorldService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; + +public class SampleSpringXmlApplication implements CommandLineRunner { + + private static final String CONTEXT_XML = "classpath:/META-INF/application-context.xml"; + + @Autowired + private HelloWorldService helloWorldService; + + @Override + public void run(String... args) { + System.out.println(this.helloWorldService.getHelloMessage()); + } + + public static void main(String[] args) { + SpringApplication application = new SpringApplication(); + application.setSources(Collections.singleton(CONTEXT_XML)); + application.run(args); + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/main/java/smoketest/xml/service/HelloWorldService.java b/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/main/java/smoketest/xml/service/HelloWorldService.java new file mode 100644 index 0000000000..675d864a48 --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/main/java/smoketest/xml/service/HelloWorldService.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.xml.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class HelloWorldService { + + @Value("${name:World}") + private String name; + + public String getHelloMessage() { + return "Hello " + this.name; + } + +} diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/main/resources/META-INF/application-context.xml b/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/main/resources/META-INF/application-context.xml new file mode 100644 index 0000000000..3453177bdc --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/main/resources/META-INF/application-context.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"> + + <context:annotation-config/> + <context:property-placeholder/> + + <bean id="helloService" class="smoketest.xml.service.HelloWorldService"/> + <bean id="application" class="smoketest.xml.SampleSpringXmlApplication"/> + +</beans> diff --git a/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/test/java/smoketest/xml/SampleSpringXmlApplicationTests.java b/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/test/java/smoketest/xml/SampleSpringXmlApplicationTests.java new file mode 100644 index 0000000000..cb721c17fd --- /dev/null +++ b/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/test/java/smoketest/xml/SampleSpringXmlApplicationTests.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.xml; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(OutputCaptureExtension.class) +class SampleSpringXmlApplicationTests { + + @Test + void testDefaultSettings(CapturedOutput capturedOutput) throws Exception { + SampleSpringXmlApplication.main(new String[0]); + assertThat(capturedOutput).contains("Hello World"); + } + +} diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml index 8012edb4a8..d9cc49a3c1 100644 --- a/src/checkstyle/checkstyle-suppressions.xml +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -17,8 +17,8 @@ <suppress files="[\\/]autoconfigure[\\/]" checks="JavadocType" /> <suppress files="[\\/]autoconfigure[\\/]" checks="JavadocVariable" /> <suppress files="[\\/]spring-boot-docs[\\/]" checks="JavadocType" /> - <suppress files="[\\/]spring-boot-samples[\\/]" checks="JavadocType" /> - <suppress files="[\\/]spring-boot-samples[\\/]" checks="ImportControl" /> + <suppress files="[\\/]spring-boot-smoke-tests[\\/]" checks="JavadocType" /> + <suppress files="[\\/]spring-boot-smoke-tests[\\/]" checks="ImportControl" /> <suppress files="[\\/]spring-boot-deployment-tests[\\/]" checks="JavadocType" /> <suppress files="[\\/]spring-boot-integration-tests[\\/]" checks="JavadocType" /> <suppress files="Ansi.*\.java" checks="JavadocVariable" />