-
Notifications
You must be signed in to change notification settings - Fork 8
Added main class and test for java lab1 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
upkarlidder
wants to merge
2
commits into
IBMDeveloperSF:master
Choose a base branch
from
upkarlidder:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -72,4 +72,5 @@ fabric.properties | |
|
|
||
| # Maven | ||
| log/ | ||
| target/ | ||
| target/ | ||
| dependency-reduced-pom.xml | ||
This file contains hidden or 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,112 @@ | ||
| ## Steps to finish Lab | ||
|
|
||
| ### Step 1: Install IBMCloud CLI | ||
|
|
||
| ### Step 2: Deploy the function to IBM Cloud | ||
| Run mvn package to create the fat jar | ||
| ``` | ||
| » mvn package [16:14:07] | ||
| [INFO] Scanning for projects... | ||
| [INFO] | ||
| [INFO] ---------< com.ibmdevelopersf.serverless_lab1:serverless_lab1 >--------- | ||
| [INFO] Building serverless_lab1 1.0-SNAPSHOT | ||
| [INFO] --------------------------------[ jar ]--------------------------------- | ||
| [INFO] | ||
| [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ serverless_lab1 --- | ||
| [INFO] Using 'UTF-8' encoding to copy filtered resources. | ||
| [INFO] skip non existing resourceDirectory /Users/ulidder/Documents/icloud-documents/code-upkar/serverless-labs/java/serverless_lab1/src/main/resources | ||
| [INFO] | ||
| [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ serverless_lab1 --- | ||
| [INFO] Changes detected - recompiling the module! | ||
| [INFO] Compiling 1 source file to /Users/ulidder/Documents/icloud-documents/code-upkar/serverless-labs/java/serverless_lab1/target/classes | ||
| [INFO] | ||
| [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ serverless_lab1 --- | ||
| [INFO] Using 'UTF-8' encoding to copy filtered resources. | ||
| [INFO] skip non existing resourceDirectory /Users/ulidder/Documents/icloud-documents/code-upkar/serverless-labs/java/serverless_lab1/src/test/resources | ||
| [INFO] | ||
| [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ serverless_lab1 --- | ||
| [INFO] Changes detected - recompiling the module! | ||
| [INFO] Compiling 1 source file to /Users/ulidder/Documents/icloud-documents/code-upkar/serverless-labs/java/serverless_lab1/target/test-classes | ||
| [INFO] | ||
| [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ serverless_lab1 --- | ||
| [INFO] Surefire report directory: /Users/ulidder/Documents/icloud-documents/code-upkar/serverless-labs/java/serverless_lab1/target/surefire-reports | ||
|
|
||
| ------------------------------------------------------- | ||
| T E S T S | ||
| ------------------------------------------------------- | ||
| Running com.ibmdevelopersf.serverless_lab1.ServerlessLab1Test | ||
| Nov 26, 2019 4:14:14 PM com.ibmdevelopersf.serverless_lab1.ServerlessLab1 main | ||
| INFO: exiting ServerlessLab1 | ||
| Nov 26, 2019 4:14:14 PM com.ibmdevelopersf.serverless_lab1.ServerlessLab1 main | ||
| INFO: exiting ServerlessLab1 | ||
| Nov 26, 2019 4:14:14 PM com.ibmdevelopersf.serverless_lab1.ServerlessLab1 main | ||
| INFO: exiting ServerlessLab1 | ||
| Nov 26, 2019 4:14:14 PM com.ibmdevelopersf.serverless_lab1.ServerlessLab1 main | ||
| INFO: exiting ServerlessLab1 | ||
| Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.082 sec | ||
|
|
||
| Results : | ||
|
|
||
| Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 | ||
|
|
||
| [INFO] | ||
| [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ serverless_lab1 --- | ||
| [INFO] Building jar: /Users/ulidder/Documents/icloud-documents/code-upkar/serverless-labs/java/serverless_lab1/target/serverless_lab1.jar | ||
| [INFO] | ||
| [INFO] --- maven-shade-plugin:3.1.0:shade (default) @ serverless_lab1 --- | ||
| [INFO] Including com.google.code.gson:gson:jar:2.8.2 in the shaded jar. | ||
| [INFO] Replacing original artifact with shaded artifact. | ||
| [INFO] Replacing /Users/ulidder/Documents/icloud-documents/code-upkar/serverless-labs/java/serverless_lab1/target/serverless_lab1.jar with /Users/ulidder/Documents/icloud-documents/code-upkar/serverless-labs/java/serverless_lab1/target/serverless_lab1-1.0-SNAPSHOT-shaded.jar | ||
| [INFO] Dependency-reduced POM written at: /Users/ulidder/Documents/icloud-documents/code-upkar/serverless-labs/java/serverless_lab1/dependency-reduced-pom.xml | ||
| [INFO] ------------------------------------------------------------------------ | ||
| [INFO] BUILD SUCCESS | ||
| [INFO] ------------------------------------------------------------------------ | ||
| [INFO] Total time: 3.398 s | ||
| [INFO] Finished at: 2019-11-26T16:14:15-08:00 | ||
| [INFO] ------------------------------------------------------------------------ | ||
|
|
||
| ``` | ||
|
|
||
| This creates `serverless_lab1.jar` file in `./target` folder. | ||
|
|
||
| ### Step 3: deploy the function to IBM Cloud using the CLI | ||
| 1. Ensure you are logged into IBM Cloud | ||
| ```$java | ||
| » ibmcloud target [16:15:49] | ||
|
|
||
|
|
||
| API endpoint: https://cloud.ibm.com | ||
| Region: us-south | ||
| User: [email protected] | ||
| Account: Upkar Lidder's Account (a086ce7d00df4423ab024b123b587e76) | ||
| Resource group: No resource group targeted, use 'ibmcloud target -g RESOURCE_GROUP' | ||
| CF API endpoint: https://api.us-south.cf.cloud.ibm.com (API version: 2.142.0) | ||
| Org: [email protected] | ||
| Space: dev | ||
|
|
||
| ``` | ||
|
|
||
| 2. deploy the jar file to ibm cloud | ||
| ```$xslt | ||
| » ibmcloud fn action update helloJava target/serverless_lab1.jar --kind java:8 --main com.ibmdevelopersf.serverless_lab1.ServerlessLab1 | ||
| ok: updated action helloJava | ||
|
|
||
| ``` | ||
|
|
||
| 3. invoke the function to ensure it works | ||
| ```$xslt | ||
| » ibmcloud fn action invoke helloJava -r | ||
| { | ||
| "greeting": "Hello World!" | ||
| } | ||
|
|
||
| ``` | ||
|
|
||
| 4. Let's try with a param now | ||
| ```$xslt | ||
| » ibmcloud fn action invoke helloJava -r -p name "upkar lidder" | ||
| { | ||
| "greeting": "Hello upkar lidder" | ||
| } | ||
|
|
||
| ``` |
This file contains hidden or 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
13 changes: 0 additions & 13 deletions
13
java/serverless_lab1/src/main/java/com/ibmdevelopersf/serverless_lab1/App.java
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
java/serverless_lab1/src/main/java/com/ibmdevelopersf/serverless_lab1/ServerlessLab1.java
This file contains hidden or 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,26 @@ | ||
| package com.ibmdevelopersf.serverless_lab1; | ||
|
|
||
| import com.google.gson.JsonObject; | ||
| import com.google.gson.JsonPrimitive; | ||
|
|
||
| import java.util.logging.Logger; | ||
|
|
||
| public class ServerlessLab1 { | ||
|
|
||
| protected static final Logger logger = Logger.getLogger("ServerlessLab1"); | ||
|
|
||
| public static JsonObject main(JsonObject args) { | ||
| JsonObject response = new JsonObject(); | ||
| JsonPrimitive nameArg = args.getAsJsonPrimitive("name"); | ||
| String result; | ||
| if (nameArg == null) { | ||
| result = "Hello World!"; | ||
| } else { | ||
| result = "Hello " + nameArg.getAsString(); | ||
| } | ||
| response.addProperty("greeting", result); | ||
|
|
||
| logger.info("exiting ServerlessLab1"); | ||
| return response; | ||
| } | ||
| } | ||
20 changes: 0 additions & 20 deletions
20
java/serverless_lab1/src/test/java/com/ibmdevelopersf/serverless_lab1/AppTest.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
.../serverless_lab1/src/test/java/com/ibmdevelopersf/serverless_lab1/ServerlessLab1Test.java
This file contains hidden or 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 @@ | ||
| package com.ibmdevelopersf.serverless_lab1; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.*; | ||
| import static org.junit.Assert.assertNotNull; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
|
|
||
| import com.google.gson.JsonObject; | ||
|
|
||
| import org.hamcrest.core.IsEqual; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Unit test for simple App. | ||
| */ | ||
| public class ServerlessLab1Test { | ||
|
|
||
| @Test | ||
| public void testMainFunctionDoesNotReturnNull() { | ||
| JsonObject args = new JsonObject(); | ||
| JsonObject response = ServerlessLab1.main(args); | ||
| assertNotNull(response); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void testMainFunctionReturnsJsonObject() { | ||
| JsonObject args = new JsonObject(); | ||
| JsonObject response = ServerlessLab1.main(args); | ||
| assertThat(response, instanceOf(JsonObject.class)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMainFunctionReturnsHelloWorld() { | ||
| JsonObject args = new JsonObject(); | ||
| final String greeting = "Hello World!"; | ||
| JsonObject response = ServerlessLab1.main(args); | ||
| assertThat(response.get("greeting"), is(notNullValue())); | ||
| assertThat(response.get("greeting").getAsString(), is(equalTo(greeting))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMainFunctionReturnsGreetingsWithName() { | ||
| JsonObject args = new JsonObject(); | ||
| final String name = "Upkar Lidder"; | ||
| args.addProperty("name", name); | ||
| JsonObject response = ServerlessLab1.main(args); | ||
| assertThat(response.get("greeting"), is(notNullValue())); | ||
| assertThat(response.get("greeting").getAsString(), is(equalTo("Hello " | ||
| + name))); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blumareks I do have quotes. I forgot to add in the comments :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/IBMDeveloperSF/serverless-labs/pull/7/files#diff-3358af545e312f75e2e5c326de5f1024R21