-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3517b25
Showing
12 changed files
with
471 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# LibertySwagger | ||
|
||
This project was generated by the [Liberty app accelerator](http://liberty-starter.wasdev.developer.ibm.com/start/api/). To build the code clone the repository and run: | ||
|
||
``` | ||
gradle build libertyStart | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
group = 'de.huk.example' | ||
version = '1.0-SNAPSHOT' | ||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath 'net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:1.0' | ||
classpath files('gradle/wlp-anttasks.jar') | ||
classpath 'org.cloudfoundry:cf-gradle-plugin:1.1.2' | ||
} | ||
} | ||
|
||
apply plugin: 'war' | ||
apply plugin: 'liberty' | ||
apply plugin: 'cloudfoundry' | ||
|
||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
|
||
compileJava.options.encoding = 'UTF-8' | ||
|
||
ext { | ||
// Liberty server properties | ||
wlpServerName = 'LibertyProjectServer' | ||
serverDirectory = "${buildDir}/wlp/usr/servers/${wlpServerName}" | ||
testServerHttpPort = 9080 | ||
testServerHttpsPort = 9443 | ||
|
||
// This is set in the ibm-web-ext.xml file | ||
warContext = 'myLibertyApp' | ||
appName = 'LibertySwagger' | ||
packageFile = "${project.buildDir}/${appName}.zip" | ||
packagingType = 'usr' | ||
|
||
// Cloud Foundry/Bluemix properties | ||
// This is the host for your app in Bluemix and what it will be called in the dashboard. | ||
cfHost = appName | ||
cfContext = 'mybluemix.net' | ||
cfTarget = 'https://api.ng.bluemix.net' | ||
cfSpace = 'dev' | ||
cfContextRoot = "${cfHost}.${cfContext}/${warContext}" | ||
|
||
// The Cloud Foundry or Bluemix organization, username and password can be entered here. | ||
// cfOrg = '' | ||
// cfUsername = '' | ||
// cfPassword = '' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven { | ||
name 'liberty-starter-maven-repo' | ||
url 'http://liberty-starter.wasdev.developer.ibm.com/start/api/v1/repo' | ||
} | ||
} | ||
|
||
dependencies { | ||
testCompile 'junit:junit:4.12' | ||
testCompile 'org.apache.cxf:cxf-rt-rs-client:3.1.1' | ||
testCompile 'org.glassfish:javax.json:1.0.4' | ||
|
||
providedCompile 'net.wasdev.wlp.starters.swagger:provided-pom:0.0.3' | ||
|
||
runtime 'net.wasdev.wlp.starters.swagger:runtime-pom:0.0.3' | ||
} | ||
|
||
test { | ||
reports.html.destination = file("$buildDir/reports/unit") | ||
reports.junitXml.destination = file("$buildDir/test-results/unit") | ||
exclude '**/it/**' | ||
} | ||
|
||
task integrationTest(type: Test) { | ||
group 'Verification' | ||
description 'Runs the integration tests.' | ||
reports.html.destination = file("$buildDir/reports/it") | ||
reports.junitXml.destination = file("$buildDir/test-results/it") | ||
include '**/it/**' | ||
exclude '**/unit/**' | ||
|
||
systemProperties = ['liberty.test.port': testServerHttpPort, 'war.name': warContext, 'running.bluemix': 'false', 'cf.context.root': cfContextRoot ] | ||
} | ||
|
||
gradle.taskGraph.whenReady { graph -> | ||
if (graph.hasTask(cfPush)) { | ||
integrationTest.systemProperties['running.bluemix'] = 'true' | ||
} | ||
} | ||
|
||
task copyConfigSnippetsToServer { | ||
doLast { | ||
def serverSnippetCopySpecs = [] | ||
configurations.runtime.resolvedConfiguration.getFirstLevelModuleDependencies().each { | ||
addServerSnippetDependencies(it, serverSnippetCopySpecs) | ||
} | ||
copy { | ||
into "${serverDirectory}/configDropins/defaults" | ||
with serverSnippetCopySpecs.toArray(new CopySpec[serverSnippetCopySpecs.size()]) | ||
} | ||
} | ||
} | ||
|
||
task printMessageAboutRunningServer { | ||
doLast { | ||
println "The server is now running at http://localhost:${testServerHttpPort}/${warContext}" | ||
println "To stop the server run 'gradle libertyStop'" | ||
} | ||
} | ||
|
||
def addServerSnippetDependencies(resolvedDependency, copySpecs) { | ||
if ("server-snippet".equals(resolvedDependency.getModuleName())) { | ||
resolvedDependency.getModuleArtifacts().each { artifact -> | ||
copySpecs.add(copySpec { | ||
from artifact.getFile() | ||
rename { String fileName -> | ||
resolvedDependency.getModuleGroup() + fileName | ||
} | ||
}) | ||
} | ||
} | ||
resolvedDependency.getChildren().each { | ||
addServerSnippetDependencies(it, copySpecs) | ||
} | ||
} | ||
|
||
task publishServerConfig(type: Copy) { | ||
from 'src/main/liberty/config/server.xml' | ||
into serverDirectory | ||
} | ||
|
||
task publishWar(type: Copy) { | ||
from(war) | ||
into("${serverDirectory}/dropins") | ||
} | ||
|
||
task createServerBootstrap() { | ||
outputs.file("${serverDirectory}/bootstrap.properties") | ||
doLast { | ||
def bootstrapProperties = file("${serverDirectory}/bootstrap.properties") | ||
if (!bootstrapProperties.exists()) { | ||
bootstrapProperties << "default.http.port=${testServerHttpPort}\ndefault.https.port=${testServerHttpsPort}" | ||
} | ||
} | ||
} | ||
|
||
liberty { | ||
install { | ||
runtimeUrl = "http://repo1.maven.org/maven2/com/ibm/websphere/appserver/runtime/wlp-webProfile7/16.0.0.3/wlp-webProfile7-16.0.0.3.zip" | ||
} | ||
serverName = wlpServerName | ||
packageLiberty { | ||
archive = packageFile | ||
include = packagingType | ||
} | ||
features { | ||
name = ['apiDiscovery-1.0'] | ||
acceptLicense = true | ||
} | ||
} | ||
|
||
task libertyStartTestServer(type: net.wasdev.wlp.gradle.plugins.tasks.StartTask){ | ||
description 'Starts the WebSphere Liberty Profile server for testing.' | ||
logging.level = LogLevel.INFO | ||
} | ||
|
||
task checkBluemixPropertiesSet() { | ||
doLast { | ||
checkPropertySet('cfOrg') | ||
checkPropertySet('cfUsername') | ||
checkPropertySet('cfPassword') | ||
} | ||
} | ||
|
||
task printBluemixProperties(dependsOn: 'checkBluemixPropertiesSet') { | ||
doLast { | ||
println "Running bluemix profile with the following properties:\n" + | ||
"\tcf.target=${cfTarget}\n" + | ||
"\tcf.space=${cfSpace}\n" + | ||
"\tcf.org=${cfOrg}\n" + | ||
"\tcf.username=${cfUsername}\n" + | ||
"The application will be accessed at context root ${cfContextRoot}" | ||
} | ||
} | ||
|
||
def checkPropertySet(propertyName) { | ||
if (!project.hasProperty(propertyName)) { | ||
throw new GradleException("The ${propertyName} property must be provided to run the cfPush task, this can be supplied on the command line with -P${propertyName}=<value>.") | ||
} | ||
} | ||
|
||
cloudfoundry { | ||
target = cfTarget | ||
if (project.hasProperty('cfOrg')) { | ||
organization = cfOrg | ||
} | ||
space = cfSpace | ||
file = file(packageFile) | ||
memory = 512 | ||
appName = cfHost | ||
} | ||
|
||
tasks.create('setupServer') | ||
check.dependsOn 'integrationTest' | ||
installFeature.dependsOn 'installLiberty' | ||
setupServer.dependsOn 'installFeature' | ||
setupServer.dependsOn 'installLiberty', 'createServerBootstrap', 'publishServerConfig', 'copyConfigSnippetsToServer', 'publishWar' | ||
createServerBootstrap.mustRunAfter 'installLiberty' | ||
publishServerConfig.mustRunAfter 'installLiberty' | ||
copyConfigSnippetsToServer.mustRunAfter 'installLiberty' | ||
publishWar.mustRunAfter 'installLiberty' | ||
publishWar.dependsOn 'war' | ||
libertyStart.dependsOn 'setupServer' | ||
integrationTest.dependsOn 'libertyStartTestServer', 'testClasses' | ||
integrationTest.finalizedBy 'libertyStop' | ||
libertyStartTestServer.dependsOn 'setupServer' | ||
assemble.dependsOn 'libertyPackage' | ||
libertyPackage.dependsOn 'setupServer' | ||
cfPush.dependsOn 'printBluemixProperties' | ||
integrationTest.mustRunAfter 'cfPush' | ||
libertyStart.finalizedBy 'printMessageAboutRunningServer' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = 'libertyswagger' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 IBM Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
package application; | ||
|
||
public class Application { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!-- Copyright (c) 2015 IBM Corp. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License.--> | ||
<server description="Sample Liberty server"> | ||
|
||
<!-- The features installed by the Liberty application accelerator will not appear here. | ||
Once the application is built the configured features can be found in the | ||
configDropins/defaults folder in the target/wlp folder. --> | ||
|
||
<!-- To extend the feature list either add the app accelerator Maven dependencies, add the features | ||
below or put a server.xml file in configDropins/overrides. Note: you may need to add Maven provided | ||
dependencies for use at compile time if not using app accelerator dependencies. --> | ||
|
||
<!-- | ||
<featureManager> | ||
<feature><feature> | ||
</featureManager> | ||
--> | ||
|
||
<httpEndpoint httpPort="${default.http.port}" httpsPort="${default.https.port}" | ||
id="defaultHttpEndpoint" /> | ||
|
||
</server> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!-- | ||
Copyright (c) 2016 IBM Corp. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<!DOCTYPE xml> | ||
<web-ext | ||
xmlns="http://websphere.ibm.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd" | ||
version="1.0"> | ||
<context-root uri="/myLibertyApp"/> | ||
</web-ext> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" | ||
version="3.1"> | ||
<display-name>Liberty Project</display-name> | ||
|
||
<welcome-file-list> | ||
<welcome-file>index.html</welcome-file> | ||
</welcome-file-list> | ||
</web-app> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 IBM Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
package it; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.client.Invocation; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.core.Response; | ||
|
||
public class EndpointTest { | ||
|
||
public void testEndpoint(String endpoint, String expectedOutput) { | ||
String port = System.getProperty("liberty.test.port"); | ||
String war = System.getProperty("war.name"); | ||
String url = "http://localhost:" + port + "/" + war + endpoint; | ||
System.out.println("Testing " + url); | ||
Response response = sendRequest(url, "GET"); | ||
int responseCode = response.getStatus(); | ||
assertTrue("Incorrect response code: " + responseCode, | ||
responseCode == 200); | ||
|
||
String responseString = response.readEntity(String.class); | ||
response.close(); | ||
assertTrue("Incorrect response, response is " + responseString, responseString.contains(expectedOutput)); | ||
} | ||
|
||
public Response sendRequest(String url, String requestType) { | ||
Client client = ClientBuilder.newClient(); | ||
System.out.println("Testing " + url); | ||
WebTarget target = client.target(url); | ||
Invocation.Builder invoBuild = target.request(); | ||
Response response = invoBuild.build(requestType).invoke(); | ||
return response; | ||
} | ||
} |
Oops, something went wrong.