├── .gitignore ├── .java-version ├── LICENSE ├── NOTICE ├── README.md ├── build.gradle ├── ci ├── Dockerfile ├── build.sh ├── build.yml ├── builder.yml ├── unit-test.sh └── unit-test.yml ├── core ├── build.gradle └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── cloudfoundry │ │ │ └── test │ │ │ └── core │ │ │ ├── AbstractServiceUtils.java │ │ │ ├── HealthUtils.java │ │ │ ├── HumanReadableMemoryFormatter.java │ │ │ ├── InitializationUtils.java │ │ │ ├── MemoryExhauster.java │ │ │ ├── MemorySizeLogger.java │ │ │ ├── MemoryUtils.java │ │ │ ├── RuntimeUtils.java │ │ │ └── ServiceUtils.java │ └── resources │ │ └── META-INF │ │ └── beans.xml │ └── test │ └── java │ └── org │ └── cloudfoundry │ └── test │ └── core │ ├── HealthUtilsTest.java │ ├── InitializationUtilsTest.java │ ├── MemoryUtilsTest.java │ └── RuntimeUtilsTest.java ├── dist-zip-application ├── build.gradle ├── manifest.yml └── src │ └── main │ └── java │ └── org │ └── cloudfoundry │ └── test │ └── Application.java ├── ejb-application ├── build.gradle ├── manifest.yml └── src │ └── main │ └── java │ └── org │ └── cloudfoundry │ └── test │ ├── AbstractEjbServiceUtils.java │ ├── Application.java │ ├── EjbHealthUtils.java │ ├── EjbMemoryUtils.java │ └── EjbRuntimeUtils.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── groovy-application ├── .gitignore ├── Application.groovy ├── build.gradle └── manifest.yml ├── java-main-application ├── build.gradle ├── manifest.yml └── src │ └── main │ └── java │ └── org │ └── cloudfoundry │ └── test │ └── Application.java ├── java-test-applications.iml ├── ratpack-application ├── build.gradle ├── manifest.yml └── src │ └── ratpack │ └── ratpack.groovy ├── settings.gradle ├── spring-boot-cli-application ├── .gitignore ├── ApplicationConfiguration.groovy ├── build.gradle └── manifest.yml ├── spring-boot-cli-jar-application ├── .gitignore ├── ApplicationConfiguration.groovy ├── build.gradle └── manifest.yml ├── spring-common └── build.gradle ├── web-application ├── build.gradle ├── manifest.yml └── src │ └── main │ └── java │ └── org │ └── cloudfoundry │ └── test │ ├── ApplicationConfiguration.java │ └── ApplicationInitializer.java └── web-servlet-2-application ├── build.gradle ├── manifest.yml └── src └── main ├── java └── org │ └── cloudfoundry │ └── test │ └── ApplicationConfiguration.java └── webapp └── WEB-INF └── web.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | .gradle 16 | .idea/ 17 | .vscode/ 18 | build 19 | out 20 | bin 21 | -------------------------------------------------------------------------------- /.java-version: -------------------------------------------------------------------------------- 1 | 1.8 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Cloud Foundry Java Test Applications 2 | 3 | Copyright (c) 2013-Present CloudFoundry.org Foundation, Inc. All Rights Reserved. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java Test Applications 2 | 3 | A collection of applications used for testing the Java buildpack. 4 | 5 | ## Applications 6 | | Name | Description 7 | | ---- | ----------- 8 | | `dist-zip-application` | A Spring Boot application, deployed as a `distZip` 9 | | `ejb-application` | A JEE EJB application using Servlet 3 10 | | `groovy-application` | An application started with `groovy` 11 | | `java-main-application` | A Spring Boot application started with `java -jar` 12 | | `ratpack-application` | A Ratpack application, deployed as a `distZip` 13 | | `spring-boot-cli-application` | A Spring Boot CLI application, deployed with `spring grab` 14 | | `spring-boot-cli-jar-application` | A Spring Boot CLI application, deployed with `spring jar` 15 | | `web-application` | A Spring MVC application using Servlet 3 16 | | `web-servlet-2-application` | A Spring MVC application using Servlet 2 17 | 18 | ### Output Content 19 | All applications support the following REST operations: 20 | 21 | | URI | Description 22 | | --- | ----------- 23 | | `GET /` | The health of the application 24 | | `GET /class-path` | The classpath of the application 25 | | `GET /environment-variables` | The environment variables available to the application 26 | | `GET /input-arguments` | The list of JVM input arguments for the application 27 | | `POST /out-of-memory` | The URL to trigger an out of memory error 28 | | `GET /request-headers` | The http request headers of the current request 29 | | `GET /security-providers` | The system security providers available to the application 30 | | `GET /system-properties` | The system properties available to the application 31 | 32 | ## Building 33 | 34 | Before building the project, the following tools must be installed: 35 | * [JDK 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html) 36 | * [Spring Boot 2 CLI](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#getting-started-installing-the-cli) 37 | 38 | This project is built with Gradle. After installing the pre-requisites, run: 39 | 40 | ```plain 41 | ./gradlew 42 | ``` 43 | 44 | ### Building Behind a Proxy 45 | Since this project downloads its dependencies from the internet, building behing a proxy requires some extra effort. In order configure gradle properly, use the following system properties. More information can be found [here][]. 46 | 47 | ```plain 48 | ./gradlew -Dhttp.proxyHost= -Dhttp.proxyPort= 49 | ``` 50 | 51 | ## Deploying to Cloud Foundry 52 | Each test application contains a `manifest.yml` file which allows the built application to be deployed to Cloud Foundry by simply issuing: 53 | 54 | ```plain 55 | cf push 56 | ``` 57 | 58 | To avoid clashing with the URLs of other applications, you should specify your own subdomain for the application (unless the test application does not need a subdomain). 59 | 60 | ## Failure Testing 61 | Failure testing is supported for each of the above applications by setting a suitable environment variable. 62 | 63 | If the environment variable FAIL_INIT is set, the application will fail to initialize: 64 | 65 | ```plain 66 | cf set-env FAIL_INIT true 67 | ``` 68 | 69 | If the environment variable FAIL_OOM is set, the application will repeatedly exhaust the heap until the JVM is killed: 70 | 71 | ```plain 72 | cf set-env FAIL_OOM true 73 | ``` 74 | 75 | ## Running Tests 76 | To run the tests, do the following: 77 | 78 | ```bash 79 | ./gradlew 80 | ``` 81 | 82 | ## License 83 | The Tomcat Builder is released under version 2.0 of the [Apache License][]. 84 | 85 | [Apache License]: http://www.apache.org/licenses/LICENSE-2.0 86 | [here]: http://stackoverflow.com/questions/5991194/gradle-proxy-configuration 87 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | buildscript { 18 | ext { 19 | ratpackVersion = '1.9.0' 20 | springBootVersion = '2.6.7' 21 | } 22 | 23 | repositories { 24 | mavenCentral() 25 | } 26 | 27 | dependencies { 28 | classpath "io.ratpack:ratpack-gradle:${ratpackVersion}" 29 | classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" 30 | } 31 | } 32 | 33 | plugins { 34 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 35 | } 36 | 37 | subprojects { 38 | apply plugin: 'io.spring.dependency-management' 39 | 40 | group = 'org.cloudfoundry.test' 41 | version = '1.0.0.BUILD-SNAPSHOT' 42 | 43 | repositories { 44 | mavenCentral() 45 | } 46 | 47 | dependencyManagement { 48 | imports { 49 | mavenBom 'org.springframework.boot:spring-boot-dependencies:2.6.7' 50 | } 51 | 52 | dependencies { 53 | dependency 'com.google.code.findbugs:jsr305:3.0.1' 54 | dependency 'org.apache.openejb:javaee-api:6.0-6' 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ci/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk 2 | 3 | RUN apt-get update && apt-get install --no-install-recommends -y \ 4 | curl \ 5 | && rm -rf /var/lib/apt/lists/* 6 | 7 | RUN curl https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.6.7/spring-boot-cli-2.6.7-bin.tar.gz | tar xzf - -C $HOME \ 8 | && ln -s $HOME/spring-2.6.7/bin/spring /usr/local/bin 9 | -------------------------------------------------------------------------------- /ci/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | export TERM=${TERM:-dumb} 6 | 7 | [[ -d $PWD/gradle && ! -d $HOME/.gradle ]] && ln -s $PWD/gradle $HOME/.gradle 8 | 9 | git clone java-test-applications java-test-applications-built 10 | 11 | cd java-test-applications-built 12 | ./gradlew -Dorg.gradle.native=false build -x test 13 | -------------------------------------------------------------------------------- /ci/build.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: registry-image 6 | source: 7 | repository: cfje/java-test-applications 8 | tag: boot-2 9 | 10 | inputs: 11 | - name: java-test-applications 12 | 13 | outputs: 14 | - name: java-test-applications-built 15 | 16 | caches: 17 | - path: gradle 18 | 19 | run: 20 | path: java-test-applications/ci/build.sh 21 | -------------------------------------------------------------------------------- /ci/builder.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: registry-image 6 | source: 7 | repository: concourse/builder 8 | 9 | inputs: 10 | - name: builder 11 | 12 | outputs: 13 | - name: image 14 | 15 | caches: 16 | - path: cache 17 | 18 | run: 19 | path: build 20 | 21 | params: 22 | CONTEXT: builder/ci 23 | -------------------------------------------------------------------------------- /ci/unit-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | export TERM=${TERM:-dumb} 6 | 7 | [[ -d $PWD/gradle && ! -d $HOME/.gradle ]] && ln -s $PWD/gradle $HOME/.gradle 8 | 9 | cd java-test-applications 10 | ./gradlew -Dorg.gradle.native=false build 11 | -------------------------------------------------------------------------------- /ci/unit-test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: registry-image 6 | source: 7 | repository: cfje/java-test-applications 8 | tag: boot-2 9 | 10 | inputs: 11 | - name: java-test-applications 12 | 13 | caches: 14 | - path: gradle 15 | 16 | run: 17 | path: java-test-applications/ci/unit-test.sh 18 | -------------------------------------------------------------------------------- /core/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'java-library' 18 | apply plugin: 'maven-publish' 19 | 20 | dependencies { 21 | compileOnly 'com.google.code.findbugs:jsr305' 22 | compileOnly 'javax.servlet:javax.servlet-api' 23 | compileOnly 'org.springframework.boot:spring-boot-starter-web' 24 | 25 | runtimeOnly 'org.reactivestreams:reactive-streams' 26 | 27 | testImplementation 'javax.servlet:javax.servlet-api' 28 | testImplementation 'org.apache.tomcat:tomcat-jdbc' 29 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 30 | 31 | testCompileOnly 'org.springframework.boot:spring-boot-starter-web' 32 | } 33 | 34 | publishing { 35 | publications { 36 | maven(MavenPublication) { 37 | from components.java 38 | 39 | versionMapping { 40 | usage('java-api') { 41 | fromResolutionOf('runtimeClasspath') 42 | } 43 | usage('java-runtime') { 44 | fromResolutionResult() 45 | } 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /core/src/main/java/org/cloudfoundry/test/core/AbstractServiceUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | import org.springframework.util.ReflectionUtils; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RequestMethod; 22 | 23 | import java.lang.reflect.Field; 24 | import java.lang.reflect.Method; 25 | 26 | public abstract class AbstractServiceUtils implements ServiceUtils { 27 | 28 | private final SC serviceConnector; 29 | 30 | protected AbstractServiceUtils(SC serviceConnector) { 31 | this.serviceConnector = serviceConnector; 32 | } 33 | 34 | @RequestMapping(method = RequestMethod.GET, value = "/check-access") 35 | public final String checkAccess() { 36 | return checkAccess(this.serviceConnector); 37 | } 38 | 39 | @RequestMapping(method = RequestMethod.GET, value = "/url") 40 | public final String url() { 41 | return getUrl(this.serviceConnector); 42 | } 43 | 44 | @SuppressWarnings("unchecked") 45 | protected final T getField(Object target, String fieldName) { 46 | Field field = ReflectionUtils.findField(target.getClass(), fieldName); 47 | ReflectionUtils.makeAccessible(field); 48 | return (T) ReflectionUtils.getField(field, target); 49 | } 50 | 51 | @SuppressWarnings("unchecked") 52 | protected final T invokeMethod(Object target, String methodName, Object... args) { 53 | Method method = ReflectionUtils.findMethod(target.getClass(), methodName); 54 | ReflectionUtils.makeAccessible(method); 55 | return (T) ReflectionUtils.invokeMethod(method, target, args); 56 | } 57 | 58 | protected final boolean isClass(SC serviceConnector, String className) { 59 | return serviceConnector.getClass().getName().equals(className); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /core/src/main/java/org/cloudfoundry/test/core/HealthUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RequestMethod; 21 | import org.springframework.web.bind.annotation.RestController; 22 | 23 | /** 24 | * Utility methods for determining the health of an application 25 | */ 26 | @RestController 27 | public final class HealthUtils { 28 | 29 | private static final String HEALTH = "ok"; 30 | 31 | @RequestMapping(method = RequestMethod.GET, value = "") 32 | public String health() { 33 | return HEALTH; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/org/cloudfoundry/test/core/HumanReadableMemoryFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | final class HumanReadableMemoryFormatter { 20 | 21 | private static final double BYTE = 1; 22 | 23 | private static final double KIBI = 1024 * BYTE; 24 | 25 | private static final double MIBI = 1024 * KIBI; 26 | 27 | private static final double GIBI = 1048 * MIBI; 28 | 29 | static String toIbi(long size) { 30 | if (size > GIBI) { 31 | return String.format("%.1f GiB", (size / GIBI)); 32 | } else if (size > MIBI) { 33 | return String.format("%.1f MiB", (size / MIBI)); 34 | } else if (size > KIBI) { 35 | return String.format("%.1f KiB", (size / KIBI)); 36 | } else { 37 | return String.format("%d B", size); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/org/cloudfoundry/test/core/InitializationUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | import org.springframework.stereotype.Component; 20 | 21 | import java.util.Map; 22 | import java.util.Optional; 23 | 24 | /** 25 | * Utility methods used during application initialization 26 | */ 27 | @Component 28 | public final class InitializationUtils { 29 | 30 | private final Map environment; 31 | 32 | /** 33 | * Create a new instance of the utility 34 | */ 35 | public InitializationUtils() { 36 | this(System.getenv()); 37 | } 38 | 39 | InitializationUtils(Map environment) { 40 | this.environment = environment; 41 | } 42 | 43 | /** 44 | * Generates a {@link RuntimeException} if the {@code FAIL_INIT} environment variable is {@code true}. Otherwise does nothing. 45 | */ 46 | public void fail() { 47 | Optional.ofNullable(this.environment.get("FAIL_INIT")) 48 | .map(Boolean::parseBoolean) 49 | .filter(b -> b) 50 | .ifPresent(f -> { 51 | System.err.println("$FAIL_INIT caused initialization to fail"); 52 | throw new RuntimeException("$FAIL_INIT caused initialization to fail"); 53 | }); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/org/cloudfoundry/test/core/MemoryExhauster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | import java.util.concurrent.Callable; 20 | 21 | import static org.cloudfoundry.test.core.HumanReadableMemoryFormatter.toIbi; 22 | 23 | final class MemoryExhauster implements Callable { 24 | 25 | private final MemorySizeLogger memorySizeLogger; 26 | 27 | private final long outOfMemorySize; 28 | 29 | MemoryExhauster(MemorySizeLogger memorySizeLogger, long outOfMemorySize) { 30 | this.memorySizeLogger = memorySizeLogger; 31 | this.outOfMemorySize = outOfMemorySize; 32 | } 33 | 34 | @Override 35 | public byte[][] call() throws Exception { 36 | System.out.printf("Exhausting %s of memory\n", toIbi(this.outOfMemorySize)); 37 | this.memorySizeLogger.enable(); 38 | 39 | int size = (int) Math.sqrt(this.outOfMemorySize); 40 | byte[][] bytes = new byte[size][]; 41 | 42 | for (int i = 0; i < bytes.length; i++) { 43 | bytes[i] = new byte[size]; 44 | } 45 | 46 | return bytes; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /core/src/main/java/org/cloudfoundry/test/core/MemorySizeLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | import java.lang.management.ManagementFactory; 20 | import java.lang.management.MemoryMXBean; 21 | import java.lang.management.MemoryUsage; 22 | import java.util.concurrent.CountDownLatch; 23 | 24 | import static org.cloudfoundry.test.core.HumanReadableMemoryFormatter.toIbi; 25 | 26 | final class MemorySizeLogger implements Runnable { 27 | 28 | private final CountDownLatch latch = new CountDownLatch(1); 29 | 30 | private final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); 31 | 32 | @Override 33 | public void run() { 34 | try { 35 | this.latch.await(); 36 | 37 | for (; ; ) { 38 | System.out.println(message()); 39 | Thread.sleep(100); 40 | } 41 | } catch (InterruptedException e) { 42 | Thread.interrupted(); 43 | } 44 | } 45 | 46 | void enable() { 47 | this.latch.countDown(); 48 | } 49 | 50 | private String message() { 51 | MemoryUsage heapMemoryUsage = this.memoryMXBean.getHeapMemoryUsage(); 52 | long used = heapMemoryUsage.getUsed(); 53 | long max = heapMemoryUsage.getMax(); 54 | 55 | return String.format("%s of %s used", toIbi(used), toIbi(max)); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/org/cloudfoundry/test/core/MemoryUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RequestMethod; 21 | import org.springframework.web.bind.annotation.RestController; 22 | 23 | import javax.annotation.PostConstruct; 24 | import java.lang.management.ManagementFactory; 25 | import java.util.Map; 26 | import java.util.Optional; 27 | import java.util.concurrent.ExecutionException; 28 | import java.util.concurrent.ExecutorService; 29 | import java.util.concurrent.Executors; 30 | 31 | /** 32 | * Utility methods for mutating the memory of an application 33 | */ 34 | @RestController 35 | public class MemoryUtils { 36 | 37 | private final Map environment; 38 | 39 | private final ExecutorService executor = Executors.newFixedThreadPool(2); 40 | 41 | private final long outOfMemorySize; 42 | 43 | /** 44 | * Create an instance of the utility 45 | */ 46 | public MemoryUtils() { 47 | this(System.getenv(), ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax()); 48 | } 49 | 50 | MemoryUtils(Map environment, long outOfMemorySize) { 51 | this.environment = environment; 52 | this.outOfMemorySize = outOfMemorySize; 53 | } 54 | 55 | /** 56 | * Generates an {@link OutOfMemoryError} if the {@code FAIL_OOM} environment variable is {@code true}. Otherwise does nothing. 57 | * 58 | * @return Never returns as it will generate an {@link OutOfMemoryError} 59 | */ 60 | @RequestMapping(method = RequestMethod.POST, value = "/out-of-memory") 61 | public byte[][] outOfMemory() { 62 | try { 63 | MemorySizeLogger memorySizeLogger = new MemorySizeLogger(); 64 | 65 | this.executor.submit(memorySizeLogger); 66 | return this.executor.submit(new MemoryExhauster(memorySizeLogger, this.outOfMemorySize)).get(); 67 | } catch (InterruptedException | ExecutionException e) { 68 | throw new RuntimeException(e); 69 | } 70 | } 71 | 72 | @PostConstruct 73 | void outOfMemoryOnStart() { 74 | Optional.ofNullable(this.environment.get("FAIL_OOM")) 75 | .map(Boolean::parseBoolean) 76 | .filter(b -> b) 77 | .ifPresent(f -> { 78 | System.err.println("$FAIL_OOM caused memory exhaustion"); 79 | outOfMemory(); 80 | }); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /core/src/main/java/org/cloudfoundry/test/core/RuntimeUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RequestMethod; 21 | import org.springframework.web.bind.annotation.RestController; 22 | 23 | import javax.servlet.http.HttpServletRequest; 24 | import java.lang.management.ManagementFactory; 25 | import java.lang.management.RuntimeMXBean; 26 | import java.security.Provider; 27 | import java.security.Security; 28 | import java.util.Arrays; 29 | import java.util.Collections; 30 | import java.util.List; 31 | import java.util.Map; 32 | import java.util.TreeMap; 33 | import java.util.function.Function; 34 | import java.util.stream.Collectors; 35 | 36 | /** 37 | * Utility methods used to get information about the current runtime 38 | */ 39 | @RestController 40 | public final class RuntimeUtils { 41 | 42 | private final Map environment; 43 | 44 | private final RuntimeMXBean runtimeMXBean; 45 | 46 | private final Provider[] securityProviders; 47 | 48 | private final Map systemProperties; 49 | 50 | public RuntimeUtils() { 51 | this(System.getenv(), ManagementFactory.getRuntimeMXBean(), Security.getProviders(), System.getProperties()); 52 | } 53 | 54 | RuntimeUtils(Map environment, RuntimeMXBean runtimeMXBean, Provider[] securityProviders, Map systemProperties) { 55 | this.environment = environment; 56 | this.runtimeMXBean = runtimeMXBean; 57 | this.securityProviders = securityProviders; 58 | this.systemProperties = systemProperties; 59 | } 60 | 61 | @RequestMapping(method = RequestMethod.GET, value = "/class-path") 62 | public List classPath() { 63 | return Arrays.asList(this.runtimeMXBean.getClassPath().split(":")); 64 | } 65 | 66 | @RequestMapping(method = RequestMethod.GET, value = "/environment-variables") 67 | public Map environmentVariables() { 68 | return new TreeMap<>(this.environment); 69 | } 70 | 71 | @RequestMapping(method = RequestMethod.GET, value = "/input-arguments") 72 | public List inputArguments() { 73 | return this.runtimeMXBean.getInputArguments(); 74 | } 75 | 76 | @RequestMapping(method = RequestMethod.GET, value = "/request-headers") 77 | public Map> requestHeaders(HttpServletRequest request) { 78 | return Collections.list(request.getHeaderNames()).stream() 79 | .collect(Collectors.toMap(Function.identity(), name -> Collections.list(request.getHeaders(name)), this::throwingMerge, TreeMap::new)); 80 | } 81 | 82 | @RequestMapping(method = RequestMethod.GET, value = "/security-providers") 83 | public List securityProviders() { 84 | return Arrays.stream(this.securityProviders) 85 | .map(Provider::toString) 86 | .collect(Collectors.toList()); 87 | } 88 | 89 | @RequestMapping(method = RequestMethod.GET, value = "/system-properties") 90 | public Map systemProperties() { 91 | return new TreeMap<>(this.systemProperties); 92 | } 93 | 94 | private T throwingMerge(T u, T v) { 95 | throw new IllegalStateException(String.format("Duplicate key %s", u)); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /core/src/main/java/org/cloudfoundry/test/core/ServiceUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | /** 20 | * Services abstraction. 21 | */ 22 | public interface ServiceUtils { 23 | 24 | /** 25 | * Checks whether the service can be accessed. 26 | * 27 | * @param serviceConnector the service connector 28 | * @return {@code ok} if and only if the service can be accessed 29 | */ 30 | String checkAccess(SC serviceConnector); 31 | 32 | /** 33 | * Gets the URL of the service. 34 | * 35 | * @param serviceConnector the service connector 36 | * @return a String representation of the service URL 37 | */ 38 | String getUrl(SC serviceConnector); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /core/src/test/java/org/cloudfoundry/test/core/HealthUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | public final class HealthUtilsTest { 24 | 25 | private final HealthUtils healthUtils = new HealthUtils(); 26 | 27 | @Test 28 | public void health() throws Exception { 29 | assertThat(this.healthUtils.health()).isEqualTo("ok"); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /core/src/test/java/org/cloudfoundry/test/core/InitializationUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | import java.util.Collections; 20 | import java.util.Map; 21 | 22 | import org.junit.jupiter.api.Assertions; 23 | import org.junit.jupiter.api.Test; 24 | 25 | public final class InitializationUtilsTest { 26 | 27 | @Test 28 | public void failFalse() { 29 | Map environment = Collections.singletonMap("FAIL_INIT", "false"); 30 | new InitializationUtils(environment).fail(); 31 | } 32 | 33 | @Test 34 | public void failNull() { 35 | Map environment = Collections.emptyMap(); 36 | new InitializationUtils(environment).fail(); 37 | } 38 | 39 | @Test 40 | public void failTrue() { 41 | Assertions.assertThrows(RuntimeException.class, () -> { 42 | Map environment = Collections.singletonMap("FAIL_INIT", "true"); 43 | new InitializationUtils(environment).fail(); 44 | }); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /core/src/test/java/org/cloudfoundry/test/core/MemoryUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | 21 | import java.util.Collections; 22 | 23 | import org.junit.jupiter.api.Test; 24 | 25 | 26 | public final class MemoryUtilsTest { 27 | 28 | @Test 29 | public void outOfMemory() { 30 | assertThat(new MemoryUtils(Collections.emptyMap(), 0).outOfMemory()).isNotNull(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /core/src/test/java/org/cloudfoundry/test/core/RuntimeUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test.core; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import static org.assertj.core.api.Assertions.entry; 21 | import static org.mockito.Mockito.mock; 22 | import static org.mockito.Mockito.when; 23 | 24 | import java.lang.management.RuntimeMXBean; 25 | import java.security.Provider; 26 | import java.util.Arrays; 27 | import java.util.Collections; 28 | import java.util.Map; 29 | 30 | import org.junit.jupiter.api.Test; 31 | import org.springframework.mock.web.MockHttpServletRequest; 32 | 33 | public final class RuntimeUtilsTest { 34 | 35 | private final Map environment = Collections.singletonMap("test-key-1", "test-value-1"); 36 | 37 | private final Provider provider = mock(Provider.class); 38 | 39 | private final RuntimeMXBean runtimeMXBean = mock(RuntimeMXBean.class); 40 | 41 | private final Map systemProperties = Collections.singletonMap("test-key-2", "test-value-2"); 42 | 43 | private Provider[] securityProviders = new Provider[]{this.provider}; 44 | 45 | private final RuntimeUtils runtimeUtils = new RuntimeUtils(this.environment, this.runtimeMXBean, 46 | this.securityProviders, this.systemProperties); 47 | 48 | @Test 49 | public void classPath() { 50 | when(this.runtimeMXBean.getClassPath()).thenReturn("alpha:bravo"); 51 | assertThat(this.runtimeUtils.classPath()).containsExactly("alpha", "bravo"); 52 | } 53 | 54 | @Test 55 | public void environmentVariables() { 56 | assertThat(this.runtimeUtils.environmentVariables()).isEqualTo(this.environment); 57 | } 58 | 59 | @Test 60 | public void inputArguments() { 61 | when(this.runtimeMXBean.getInputArguments()).thenReturn(Arrays.asList("alpha", "bravo")); 62 | assertThat(this.runtimeUtils.inputArguments()).containsExactly("alpha", "bravo"); 63 | } 64 | 65 | @Test 66 | public void requestHeaders() { 67 | MockHttpServletRequest request = new MockHttpServletRequest(); 68 | request.addHeader("test-key", "test-value-1"); 69 | request.addHeader("test-key", "test-value-2"); 70 | 71 | assertThat(this.runtimeUtils.requestHeaders(request)).containsExactly(entry("test-key", Arrays.asList("test-value-1", "test-value-2"))); 72 | } 73 | 74 | @Test 75 | public void securityProviders() { 76 | when(this.provider.toString()).thenReturn("test-provider"); 77 | assertThat(this.runtimeUtils.securityProviders()).containsExactly("test-provider"); 78 | } 79 | 80 | @Test 81 | public void systemProperties() { 82 | assertThat(this.runtimeUtils.systemProperties()).isEqualTo(this.systemProperties); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /dist-zip-application/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'application' 18 | 19 | mainClassName = 'org.cloudfoundry.test.Application' 20 | 21 | dependencies { 22 | implementation project(':spring-common') 23 | } 24 | -------------------------------------------------------------------------------- /dist-zip-application/manifest.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | applications: 17 | - name: dist-zip-application 18 | path: build/distributions/dist-zip-application-1.0.0.BUILD-SNAPSHOT.zip 19 | buildpacks: 20 | - https://github.com/cloudfoundry/java-buildpack.git 21 | -------------------------------------------------------------------------------- /dist-zip-application/src/main/java/org/cloudfoundry/test/Application.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test; 18 | 19 | import org.cloudfoundry.test.core.InitializationUtils; 20 | import org.springframework.boot.SpringApplication; 21 | import org.springframework.boot.autoconfigure.SpringBootApplication; 22 | 23 | @SpringBootApplication 24 | public class Application { 25 | 26 | public static void main(String[] args) { 27 | new InitializationUtils().fail(); 28 | SpringApplication.run(Application.class, args); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /ejb-application/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'war' 18 | 19 | dependencies { 20 | implementation project(':core') 21 | implementation 'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider' 22 | implementation 'org.apache.openejb:javaee-api' 23 | 24 | compileOnly 'org.springframework.boot:spring-boot-starter-web' 25 | } 26 | -------------------------------------------------------------------------------- /ejb-application/manifest.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | applications: 17 | - name: ejb-application 18 | path: build/libs/ejb-application-1.0.0.BUILD-SNAPSHOT.war 19 | buildpacks: 20 | - https://github.com/cloudfoundry/java-buildpack.git 21 | env: 22 | JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{ enabled: false }' 23 | -------------------------------------------------------------------------------- /ejb-application/src/main/java/org/cloudfoundry/test/AbstractEjbServiceUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test; 18 | 19 | import org.cloudfoundry.test.core.AbstractServiceUtils; 20 | 21 | import javax.ws.rs.GET; 22 | import javax.ws.rs.Path; 23 | import javax.ws.rs.Produces; 24 | import javax.ws.rs.core.MediaType; 25 | 26 | 27 | @Produces(MediaType.TEXT_PLAIN) 28 | public abstract class AbstractEjbServiceUtils> { 29 | 30 | private final T serviceUtils; 31 | 32 | protected AbstractEjbServiceUtils(T serviceUtils) { 33 | this.serviceUtils = serviceUtils; 34 | } 35 | 36 | @GET 37 | @Path("/check-access") 38 | public final String checkAccess() { 39 | return this.serviceUtils.checkAccess(); 40 | } 41 | 42 | @GET 43 | @Path("/url") 44 | public final String url() { 45 | return this.serviceUtils.url(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /ejb-application/src/main/java/org/cloudfoundry/test/Application.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test; 18 | 19 | import org.cloudfoundry.test.core.InitializationUtils; 20 | 21 | import javax.ws.rs.ApplicationPath; 22 | 23 | @ApplicationPath("/") 24 | public class Application extends javax.ws.rs.core.Application { 25 | 26 | public Application() { 27 | new InitializationUtils().fail(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /ejb-application/src/main/java/org/cloudfoundry/test/EjbHealthUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test; 18 | 19 | import org.cloudfoundry.test.core.HealthUtils; 20 | 21 | import javax.inject.Inject; 22 | import javax.ws.rs.GET; 23 | import javax.ws.rs.Path; 24 | import javax.ws.rs.Produces; 25 | import javax.ws.rs.core.MediaType; 26 | 27 | @Path("/") 28 | @Produces(MediaType.APPLICATION_JSON) 29 | public class EjbHealthUtils { 30 | 31 | @Inject 32 | private HealthUtils healthUtils; 33 | 34 | @GET 35 | @Path("/") 36 | public String health() { 37 | return this.healthUtils.health(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /ejb-application/src/main/java/org/cloudfoundry/test/EjbMemoryUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test; 18 | 19 | import org.cloudfoundry.test.core.MemoryUtils; 20 | 21 | import javax.inject.Inject; 22 | import javax.ws.rs.POST; 23 | import javax.ws.rs.Path; 24 | import javax.ws.rs.Produces; 25 | import javax.ws.rs.core.MediaType; 26 | 27 | @Path("/") 28 | @Produces(MediaType.APPLICATION_JSON) 29 | public class EjbMemoryUtils { 30 | 31 | @Inject 32 | private MemoryUtils memoryUtils; 33 | 34 | @POST 35 | @Path("/out-of-memory") 36 | public byte[][] outOfMemory() { 37 | return this.memoryUtils.outOfMemory(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /ejb-application/src/main/java/org/cloudfoundry/test/EjbRuntimeUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test; 18 | 19 | import org.cloudfoundry.test.core.RuntimeUtils; 20 | 21 | import javax.inject.Inject; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.ws.rs.GET; 24 | import javax.ws.rs.Path; 25 | import javax.ws.rs.Produces; 26 | import javax.ws.rs.core.Context; 27 | import javax.ws.rs.core.MediaType; 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | @Path("/") 32 | @Produces(MediaType.APPLICATION_JSON) 33 | public class EjbRuntimeUtils { 34 | 35 | @Inject 36 | private RuntimeUtils runtimeUtils; 37 | 38 | @GET 39 | @Path("/class-path") 40 | public List classPath() { 41 | return this.runtimeUtils.classPath(); 42 | } 43 | 44 | @GET 45 | @Path("/environment-variables") 46 | public Map environmentVariables() { 47 | return this.runtimeUtils.environmentVariables(); 48 | } 49 | 50 | @GET 51 | @Path("/input-arguments") 52 | public List inputArguments() { 53 | return this.runtimeUtils.inputArguments(); 54 | } 55 | 56 | @GET 57 | @Path("/request-headers") 58 | public Map> requestHeaders(@Context HttpServletRequest request) { 59 | return this.runtimeUtils.requestHeaders(request); 60 | } 61 | 62 | @GET 63 | @Path("/security-providers") 64 | public List securityProviders() { 65 | return this.runtimeUtils.securityProviders(); 66 | } 67 | 68 | @GET 69 | @Path("/system-properties") 70 | public Map systemProperties() { 71 | return this.runtimeUtils.systemProperties(); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudfoundry/java-test-applications/9e8e5c43eee655384c68e5a45c74a560bbe4507f/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /groovy-application/.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | lib 16 | -------------------------------------------------------------------------------- /groovy-application/Application.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import org.springframework.boot.SpringApplication 18 | import org.springframework.boot.autoconfigure.SpringBootApplication 19 | 20 | @SpringBootApplication(scanBasePackages = 'org.cloudfoundry.test') 21 | class Application { 22 | 23 | static void main(String[] args) { 24 | args += '--server.port=' + System.env['PORT'] 25 | new SpringApplication(Application.class).run(args) 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /groovy-application/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'groovy' 18 | 19 | dependencies { 20 | implementation project(':spring-common') 21 | } 22 | 23 | task libraries(type: Copy) { 24 | from configurations.runtimeClasspath 25 | into 'lib' 26 | } 27 | 28 | jar.enabled = false 29 | 30 | build.dependsOn libraries 31 | clean.dependsOn cleanLibraries 32 | -------------------------------------------------------------------------------- /groovy-application/manifest.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | applications: 17 | - name: groovy-application 18 | path: '.' 19 | buildpacks: 20 | - https://github.com/cloudfoundry/java-buildpack.git 21 | -------------------------------------------------------------------------------- /java-main-application/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'java' 18 | apply plugin: 'org.springframework.boot' 19 | 20 | dependencies { 21 | implementation project(':spring-common') 22 | } 23 | -------------------------------------------------------------------------------- /java-main-application/manifest.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | applications: 17 | - name: java-main-application 18 | path: build/libs/java-main-application-1.0.0.BUILD-SNAPSHOT.jar 19 | buildpacks: 20 | - https://github.com/cloudfoundry/java-buildpack.git 21 | -------------------------------------------------------------------------------- /java-main-application/src/main/java/org/cloudfoundry/test/Application.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test; 18 | 19 | import org.cloudfoundry.test.core.InitializationUtils; 20 | import org.springframework.boot.SpringApplication; 21 | import org.springframework.boot.autoconfigure.SpringBootApplication; 22 | 23 | @SpringBootApplication 24 | public class Application { 25 | 26 | public static void main(String[] args) { 27 | new InitializationUtils().fail(); 28 | SpringApplication.run(Application.class, args); 29 | } 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /java-test-applications.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ratpack-application/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'io.ratpack.ratpack-groovy' 18 | 19 | String groovyVersion = "2.5.16" 20 | 21 | dependencies { 22 | implementation project(':core') 23 | implementation "org.codehaus.groovy:groovy:${groovyVersion}" 24 | implementation "org.codehaus.groovy:groovy-ant:${groovyVersion}" 25 | implementation "org.codehaus.groovy:groovy-cli-commons:${groovyVersion}" 26 | implementation "org.codehaus.groovy:groovy-cli-picocli:${groovyVersion}" 27 | implementation "org.codehaus.groovy:groovy-console:${groovyVersion}" 28 | implementation "org.codehaus.groovy:groovy-datetime:${groovyVersion}" 29 | implementation "org.codehaus.groovy:groovy-docgenerator:${groovyVersion}" 30 | implementation "org.codehaus.groovy:groovy-groovydoc:${groovyVersion}" 31 | implementation "org.codehaus.groovy:groovy-groovysh:${groovyVersion}" 32 | implementation "org.codehaus.groovy:groovy-jmx:${groovyVersion}" 33 | implementation "org.codehaus.groovy:groovy-json:${groovyVersion}" 34 | implementation "org.codehaus.groovy:groovy-jsr223:${groovyVersion}" 35 | implementation "org.codehaus.groovy:groovy-macro:${groovyVersion}" 36 | implementation "org.codehaus.groovy:groovy-nio:${groovyVersion}" 37 | implementation "org.codehaus.groovy:groovy-servlet:${groovyVersion}" 38 | implementation "org.codehaus.groovy:groovy-sql:${groovyVersion}" 39 | implementation "org.codehaus.groovy:groovy-swing:${groovyVersion}" 40 | implementation "org.codehaus.groovy:groovy-templates:${groovyVersion}" 41 | implementation "org.codehaus.groovy:groovy-test:${groovyVersion}" 42 | implementation "org.codehaus.groovy:groovy-test-junit5:${groovyVersion}" 43 | implementation "org.codehaus.groovy:groovy-testng:${groovyVersion}" 44 | implementation "org.codehaus.groovy:groovy-xml:${groovyVersion}" 45 | 46 | runtimeOnly 'javax.servlet:javax.servlet-api' 47 | } 48 | -------------------------------------------------------------------------------- /ratpack-application/manifest.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | applications: 17 | - name: ratpack-application 18 | path: build/distributions/ratpack-application-1.0.0.BUILD-SNAPSHOT.zip 19 | buildpacks: 20 | - https://github.com/cloudfoundry/java-buildpack.git 21 | -------------------------------------------------------------------------------- /ratpack-application/src/ratpack/ratpack.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | import org.cloudfoundry.test.core.HealthUtils 19 | import org.cloudfoundry.test.core.InitializationUtils 20 | import org.cloudfoundry.test.core.MemoryUtils 21 | import org.cloudfoundry.test.core.RuntimeUtils 22 | 23 | import static ratpack.groovy.Groovy.ratpack 24 | import static ratpack.jackson.Jackson.json 25 | 26 | ratpack { 27 | new InitializationUtils().fail() 28 | 29 | def memoryUtils = new MemoryUtils() 30 | memoryUtils.outOfMemoryOnStart() 31 | 32 | def healthUtils = new HealthUtils() 33 | def runtimeUtils = new RuntimeUtils() 34 | 35 | handlers { 36 | 37 | get('') { 38 | response.send healthUtils.health() 39 | } 40 | 41 | get('class-path') { 42 | render json(runtimeUtils.classPath()) 43 | } 44 | 45 | get('environment-variables') { 46 | render json(runtimeUtils.environmentVariables()) 47 | } 48 | 49 | get('request-headers') { 50 | TreeMap> headers = request.getHeaders().getNames().collectEntries { name -> 51 | [(name): request.getHeaders().getAll(name)] 52 | } 53 | render json(headers) 54 | } 55 | 56 | get('input-arguments') { 57 | render json(runtimeUtils.inputArguments()) 58 | } 59 | 60 | post('out-of-memory') { 61 | response.send memoryUtils.outOfMemory() 62 | } 63 | 64 | get('security-providers') { 65 | render json(runtimeUtils.securityProviders()) 66 | } 67 | 68 | get('system-properties') { 69 | render json(runtimeUtils.systemProperties()) 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | rootProject.name = 'java-test-applications' 18 | 19 | include 'core' 20 | include 'dist-zip-application' 21 | include 'ejb-application' 22 | include 'groovy-application' 23 | include 'java-main-application' 24 | include 'ratpack-application' 25 | include 'spring-boot-cli-application' 26 | include 'spring-boot-cli-jar-application' 27 | include 'spring-common' 28 | include 'web-application' 29 | include 'web-servlet-2-application' 30 | -------------------------------------------------------------------------------- /spring-boot-cli-application/.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | repository 16 | -------------------------------------------------------------------------------- /spring-boot-cli-application/ApplicationConfiguration.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import org.springframework.context.annotation.ComponentScan 18 | import org.springframework.context.annotation.Configuration 19 | import org.springframework.web.servlet.config.annotation.EnableWebMvc 20 | 21 | @Configuration 22 | @ComponentScan('org.cloudfoundry.test') 23 | @DependencyManagementBom('org.springframework.boot:spring-boot-dependencies:2.6.7') 24 | @EnableWebMvc 25 | @Grab('org.cloudfoundry.test:core:1.0.0.BUILD-SNAPSHOT') 26 | class ApplicationConfiguration { 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-cli-application/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'groovy' 18 | 19 | dependencies { 20 | implementation project(':core') 21 | } 22 | 23 | task repository(type: Exec, dependsOn: ':spring-common:publishToMavenLocal') { 24 | inputs.file 'ApplicationConfiguration.groovy' 25 | outputs.dir 'repository' 26 | commandLine 'spring', 'grab', 'ApplicationConfiguration.groovy' 27 | } 28 | 29 | jar.enabled = false 30 | 31 | build.dependsOn repository 32 | clean.dependsOn cleanRepository 33 | -------------------------------------------------------------------------------- /spring-boot-cli-application/manifest.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | applications: 17 | - name: spring-boot-cli-application 18 | path: '.' 19 | buildpacks: 20 | - https://github.com/cloudfoundry/java-buildpack.git 21 | -------------------------------------------------------------------------------- /spring-boot-cli-jar-application/.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | *.jar 16 | *.jar.original 17 | -------------------------------------------------------------------------------- /spring-boot-cli-jar-application/ApplicationConfiguration.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import org.springframework.context.annotation.ComponentScan 18 | import org.springframework.context.annotation.Configuration 19 | import org.springframework.web.servlet.config.annotation.EnableWebMvc 20 | 21 | @Configuration 22 | @ComponentScan('org.cloudfoundry.test') 23 | @DependencyManagementBom('org.springframework.boot:spring-boot-dependencies:2.6.7') 24 | @EnableWebMvc 25 | @Grab('org.cloudfoundry.test:core:1.0.0.BUILD-SNAPSHOT') 26 | class ApplicationConfiguration { 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-cli-jar-application/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'groovy' 18 | 19 | dependencies { 20 | implementation project(':core') 21 | } 22 | 23 | task springJar(type: Exec, dependsOn: ':spring-common:publishToMavenLocal') { 24 | inputs.file 'ApplicationConfiguration.groovy' 25 | outputs.files 'spring-boot-cli-jar-application-1.0.0.BUILD-SNAPSHOT.jar', 'spring-boot-cli-jar-application-1.0.0.BUILD-SNAPSHOT.jar.original' 26 | commandLine 'spring', 'jar', 'spring-boot-cli-jar-application-1.0.0.BUILD-SNAPSHOT.jar', 'ApplicationConfiguration.groovy' 27 | } 28 | 29 | build.dependsOn springJar 30 | clean.dependsOn cleanSpringJar 31 | -------------------------------------------------------------------------------- /spring-boot-cli-jar-application/manifest.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | applications: 17 | - name: spring-boot-cli-jar-application 18 | path: spring-boot-cli-jar-application-1.0.0.BUILD-SNAPSHOT.jar 19 | buildpacks: 20 | - https://github.com/cloudfoundry/java-buildpack.git 21 | -------------------------------------------------------------------------------- /spring-common/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'java-library' 18 | apply plugin: 'maven-publish' 19 | 20 | dependencies { 21 | api project(':core') 22 | api('org.springframework.boot:spring-boot-starter-web') { 23 | exclude group: 'org.apache.tomcat.embed', module: 'tomcat-embed-websocket' 24 | exclude group: 'org.hibernate.validator', module: 'hibernate-validator' 25 | } 26 | } 27 | 28 | publishToMavenLocal.dependsOn ':core:publishToMavenLocal' 29 | 30 | publishing { 31 | publications { 32 | maven(MavenPublication) { 33 | from components.java 34 | 35 | versionMapping { 36 | usage('java-api') { 37 | fromResolutionOf('runtimeClasspath') 38 | } 39 | usage('java-runtime') { 40 | fromResolutionResult() 41 | } 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /web-application/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'war' 18 | 19 | dependencies { 20 | implementation project(':spring-common') 21 | 22 | compileOnly 'javax.servlet:javax.servlet-api' 23 | } 24 | -------------------------------------------------------------------------------- /web-application/manifest.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | applications: 17 | - name: web-application 18 | path: build/libs/web-application-1.0.0.BUILD-SNAPSHOT.war 19 | buildpacks: 20 | - https://github.com/cloudfoundry/java-buildpack.git 21 | -------------------------------------------------------------------------------- /web-application/src/main/java/org/cloudfoundry/test/ApplicationConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test; 18 | 19 | import org.springframework.context.annotation.ComponentScan; 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 22 | 23 | @Configuration 24 | @ComponentScan 25 | @EnableWebMvc 26 | class ApplicationConfiguration { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /web-application/src/main/java/org/cloudfoundry/test/ApplicationInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test; 18 | 19 | import org.cloudfoundry.test.core.InitializationUtils; 20 | import org.springframework.web.WebApplicationInitializer; 21 | import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; 22 | import org.springframework.web.servlet.DispatcherServlet; 23 | 24 | import javax.servlet.ServletContext; 25 | import javax.servlet.ServletException; 26 | import javax.servlet.ServletRegistration; 27 | 28 | /** 29 | * The initializer that starts the web application 30 | */ 31 | public final class ApplicationInitializer implements WebApplicationInitializer { 32 | 33 | public ApplicationInitializer() { 34 | new InitializationUtils().fail(); 35 | } 36 | 37 | @Override 38 | public void onStartup(ServletContext servletContext) throws ServletException { 39 | AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext(); 40 | webContext.register(ApplicationConfiguration.class); 41 | 42 | ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(webContext)); 43 | dispatcherServlet.setLoadOnStartup(1); 44 | dispatcherServlet.addMapping("/"); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /web-servlet-2-application/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'war' 18 | 19 | dependencies { 20 | implementation project(':spring-common') 21 | } 22 | -------------------------------------------------------------------------------- /web-servlet-2-application/manifest.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2019 the original author or authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | --- 16 | applications: 17 | - name: web-servlet-2-application 18 | path: build/libs/web-servlet-2-application-1.0.0.BUILD-SNAPSHOT.war 19 | buildpacks: 20 | - https://github.com/cloudfoundry/java-buildpack.git 21 | -------------------------------------------------------------------------------- /web-servlet-2-application/src/main/java/org/cloudfoundry/test/ApplicationConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.cloudfoundry.test; 18 | 19 | import org.springframework.context.annotation.ComponentScan; 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 22 | 23 | @Configuration 24 | @ComponentScan 25 | @EnableWebMvc 26 | class ApplicationConfiguration { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /web-servlet-2-application/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 24 | 25 | 26 | dispatcherServlet 27 | org.springframework.web.servlet.DispatcherServlet 28 | 1 29 | 30 | contextClass 31 | org.springframework.web.context.support.AnnotationConfigWebApplicationContext 32 | 33 | 34 | contextConfigLocation 35 | org.cloudfoundry.test.ApplicationConfiguration 36 | 37 | 38 | 39 | 40 | dispatcherServlet 41 | / 42 | 43 | 44 | 45 | --------------------------------------------------------------------------------