From 9c9c0ae2a007129b3f5f82107af330467373c955 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Sun, 23 Apr 2017 12:08:32 -0500 Subject: [PATCH 01/17] BAEL-555: Updated README.md (#1711) * Add files via upload * Update pom.xml * Update RunGuice.java * Update Communication.java * Update CommunicationMode.java * Update DefaultCommunicator.java * Update EmailCommunicationMode.java * Update IMCommunicationMode.java * Update SMSCommunicationMode.java * Update MessageLogger.java * Update MessageSentLoggable.java * Update AOPModule.java * Update BasicModule.java * Update CommunicationModel.java * Update Communicator.java * Update BasicModule.java * Update RunGuice.java * Update MessageLogger.java * Update Communicator.java * Update pom.xml * BAEL-278: Updated README.md * BAEL-554: Add and update README.md files * Update pom.xml * Update pom.xml * Update pom.xml * BAEL-345: fixed assertion * BAEL-109: Updated README.md * BAEL-345: Added README.md * Reinstating reactor-core module in root-level pom * BAEL-393: Adding guide-intro module to root pom * BAEL-9: Updated README.md * BAEL-157: README.md updated * Changed project name * Update RunGuice.java Removed references to message logging and output * Update Communication.java Removed message logging-related code * BAEL-566: Updated README.md * New project name * BAEL-393: removing guice-intro directory * BAEL-393: renamed module guice-intro to guice in root pom.xml * BAEL-393 and BAEL-541 README.md files * BAEL-731: Updated README.md * BAEL-680: renamed test methods * BAEL-714: Updated README.md * BAEL-737: Updated README.md * BAEL-680 and BAEL-756 README.md updates * BAEL-666: Updated README * BAEL-415: Custom Scope * BAEL-415: Custom Scope - renamed classes to reflect TenantScope * README file updates for BAEL-723, BAEL-763, and BAEL-415 * BAEL-735: README * BAEL-567: README * BAEL-736: README * BAEL-766: Update README * BAEL-555: README update --- spring-remoting/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-remoting/README.md b/spring-remoting/README.md index 41bbd59f01..96a68977a5 100644 --- a/spring-remoting/README.md +++ b/spring-remoting/README.md @@ -3,6 +3,7 @@ ### Relevant Articles - [Intro to Spring Remoting with HTTP Invokers](http://www.baeldung.com/spring-remoting-http-invoker) - [Spring Remoting with Hessian and Burlap](http://www.baeldung.com/spring-remoting-hessian-burlap) +- [Spring Remoting with AMQP](http://www.baeldung.com/spring-remoting-amqp) ### Overview This Maven project contains the Java source code for various modules used in the Spring Remoting series of articles. From c4d9be177fa4647d2408b4b459dbebd16464c721 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Sun, 23 Apr 2017 13:51:45 -0500 Subject: [PATCH 02/17] BAEL-761: Updated README.md (#1713) * Add files via upload * Update pom.xml * Update RunGuice.java * Update Communication.java * Update CommunicationMode.java * Update DefaultCommunicator.java * Update EmailCommunicationMode.java * Update IMCommunicationMode.java * Update SMSCommunicationMode.java * Update MessageLogger.java * Update MessageSentLoggable.java * Update AOPModule.java * Update BasicModule.java * Update CommunicationModel.java * Update Communicator.java * Update BasicModule.java * Update RunGuice.java * Update MessageLogger.java * Update Communicator.java * Update pom.xml * BAEL-278: Updated README.md * BAEL-554: Add and update README.md files * Update pom.xml * Update pom.xml * Update pom.xml * BAEL-345: fixed assertion * BAEL-109: Updated README.md * BAEL-345: Added README.md * Reinstating reactor-core module in root-level pom * BAEL-393: Adding guide-intro module to root pom * BAEL-9: Updated README.md * BAEL-157: README.md updated * Changed project name * Update RunGuice.java Removed references to message logging and output * Update Communication.java Removed message logging-related code * BAEL-566: Updated README.md * New project name * BAEL-393: removing guice-intro directory * BAEL-393: renamed module guice-intro to guice in root pom.xml * BAEL-393 and BAEL-541 README.md files * BAEL-731: Updated README.md * BAEL-680: renamed test methods * BAEL-714: Updated README.md * BAEL-737: Updated README.md * BAEL-680 and BAEL-756 README.md updates * BAEL-666: Updated README * BAEL-415: Custom Scope * BAEL-415: Custom Scope - renamed classes to reflect TenantScope * README file updates for BAEL-723, BAEL-763, and BAEL-415 * BAEL-735: README * BAEL-567: README * BAEL-736: README * BAEL-766: Update README * BAEL-555: README update * BAEL-761: README update --- spring-boot/README.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot/README.MD b/spring-boot/README.MD index dfd1327781..a1168106cb 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -20,3 +20,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Dynamic DTO Validation Config Retrieved from DB](http://www.baeldung.com/spring-dynamic-dto-validation) - [Custom Information in Spring Boot Info Endpoint](http://www.baeldung.com/spring-boot-info-actuator-custom) - [Using @JsonComponent in Spring Boot](http://www.baeldung.com/spring-boot-jsoncomponent) +- [Create a Custom Auto-Configuration with Spring Boot](http://www.baeldung.com/spring-boot-custom-auto-configuration) From 48c0e417913e634f96ca06e03921ad5bf43a0725 Mon Sep 17 00:00:00 2001 From: Doha2012 Date: Sun, 23 Apr 2017 22:10:56 +0200 Subject: [PATCH 03/17] fix commons-logging issue (#1714) * upgrade to spring boot 1.5.2 * add full update to REST API * modify ratings controller * upgrade herold * fix integration test * fix integration test * minor fix * fix integration test * fix integration test * minor cleanup * minor cleanup * remove log4j properties * use standard logbook.xml * remove log4j dependencies * remove commons-logging * merge * fix conflict * exclude commons-logging dependency * cleanup * minor fix * minor fix * fix dependency issues * Revert "fix dependency issues" This reverts commit 83bf1f9fd2e1a9a55f9cacb085669568b06b49ec. * fix dependency issues * minor fix * minor fix * minor fix * cleanup generated files * fix commons-logging issue --- cdi/pom.xml | 8 +------- mapstruct/pom.xml | 8 +------- rest-assured/pom.xml | 16 ++-------------- spring-akka/pom.xml | 8 +------- spring-hibernate3/pom.xml | 8 +------- spring-integration/pom.xml | 8 +------- spring-mvc-velocity/pom.xml | 8 +------- spring-spel/pom.xml | 8 +------- 8 files changed, 9 insertions(+), 63 deletions(-) diff --git a/cdi/pom.xml b/cdi/pom.xml index d2fcec59d7..e77e5d9a10 100644 --- a/cdi/pom.xml +++ b/cdi/pom.xml @@ -11,13 +11,7 @@ org.springframework spring-core - ${spring.version} - - - commons-logging - commons-logging - - + ${spring.version} org.springframework diff --git a/mapstruct/pom.xml b/mapstruct/pom.xml index 81bcdb4cb9..4ee6c1e822 100644 --- a/mapstruct/pom.xml +++ b/mapstruct/pom.xml @@ -31,13 +31,7 @@ org.springframework spring-context - ${springframework.version} - - - commons-logging - commons-logging - - + ${springframework.version} org.springframework diff --git a/rest-assured/pom.xml b/rest-assured/pom.xml index 0c3bf38dc5..f96897852f 100644 --- a/rest-assured/pom.xml +++ b/rest-assured/pom.xml @@ -144,13 +144,7 @@ org.apache.httpcomponents httpclient - ${httpclient.version} - - - commons-logging - commons-logging - - + ${httpclient.version} @@ -183,13 +177,7 @@ com.github.fge json-schema-core - ${json-schema-core.version} - - - commons-logging - commons-logging - - + ${json-schema-core.version} junit diff --git a/spring-akka/pom.xml b/spring-akka/pom.xml index 497022064c..f73c6aeaa7 100644 --- a/spring-akka/pom.xml +++ b/spring-akka/pom.xml @@ -11,13 +11,7 @@ org.springframework - spring-context - - - commons-logging - commons-logging - - + spring-context diff --git a/spring-hibernate3/pom.xml b/spring-hibernate3/pom.xml index c45c9bb15e..32ea394311 100644 --- a/spring-hibernate3/pom.xml +++ b/spring-hibernate3/pom.xml @@ -13,13 +13,7 @@ org.springframework spring-context - ${org.springframework.version} - - - commons-logging - commons-logging - - + ${org.springframework.version} diff --git a/spring-integration/pom.xml b/spring-integration/pom.xml index 34c40cb00f..9add0cc290 100644 --- a/spring-integration/pom.xml +++ b/spring-integration/pom.xml @@ -95,13 +95,7 @@ org.springframework.integration spring-integration-core - ${spring.integration.version} - - - commons-logging - commons-logging - - + ${spring.integration.version} javax.activation diff --git a/spring-mvc-velocity/pom.xml b/spring-mvc-velocity/pom.xml index 51348acd4a..5bfedc9df6 100644 --- a/spring-mvc-velocity/pom.xml +++ b/spring-mvc-velocity/pom.xml @@ -25,13 +25,7 @@ org.springframework spring-core - ${org.springframework.version} - - - commons-logging - commons-logging - - + ${org.springframework.version} org.springframework diff --git a/spring-spel/pom.xml b/spring-spel/pom.xml index 5bb8480715..6ebeb70bc5 100644 --- a/spring-spel/pom.xml +++ b/spring-spel/pom.xml @@ -30,13 +30,7 @@ org.springframework spring-context - ${springframework.version} - - - commons-logging - commons-logging - - + ${springframework.version} org.springframework From 8b028a29466586d8cb4478f6eca2fb6b600cf624 Mon Sep 17 00:00:00 2001 From: Tian Baoqiang Date: Mon, 24 Apr 2017 01:36:58 -0500 Subject: [PATCH 04/17] BAEL-758 (#1704) * BAEL-758 * remove unnecessary pom configurations --- libraries/pom.xml | 69 +++++++++++++----- libraries/serenity.properties | 4 + .../baeldung/serenity/github/GitHubUser.java | 19 +++++ .../serenity/membership/Commodity.java | 16 ++++ .../baeldung/serenity/membership/Member.java | 34 +++++++++ .../serenity/membership/MemberGrade.java | 10 +++ .../GithubUserProfilePayloadTest.java | 10 +++ .../baeldung/serenity/MemberStatusTest.java | 73 +++++++++++++++++++ .../github/GithubRestAssuredUserAPISteps.java | 33 +++++++++ .../github/GithubRestUserAPISteps.java | 54 ++++++++++++++ ...thubUserProfilePayloadStepDefinitions.java | 33 +++++++++ .../membership/MemberStatusSteps.java | 47 ++++++++++++ .../github_user_profile_payload_test.story | 13 ++++ 13 files changed, 395 insertions(+), 20 deletions(-) create mode 100644 libraries/serenity.properties create mode 100644 libraries/src/main/java/com/baeldung/serenity/github/GitHubUser.java create mode 100644 libraries/src/main/java/com/baeldung/serenity/membership/Commodity.java create mode 100644 libraries/src/main/java/com/baeldung/serenity/membership/Member.java create mode 100644 libraries/src/main/java/com/baeldung/serenity/membership/MemberGrade.java create mode 100644 libraries/src/test/java/com/baeldung/serenity/GithubUserProfilePayloadTest.java create mode 100644 libraries/src/test/java/com/baeldung/serenity/MemberStatusTest.java create mode 100644 libraries/src/test/java/com/baeldung/serenity/github/GithubRestAssuredUserAPISteps.java create mode 100644 libraries/src/test/java/com/baeldung/serenity/github/GithubRestUserAPISteps.java create mode 100644 libraries/src/test/java/com/baeldung/serenity/github/GithubUserProfilePayloadStepDefinitions.java create mode 100644 libraries/src/test/java/com/baeldung/serenity/membership/MemberStatusSteps.java create mode 100644 libraries/src/test/resources/stories/github_rest/user_profile/github_user_profile_payload_test.story diff --git a/libraries/pom.xml b/libraries/pom.xml index 0643e8257b..021e081eb5 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -45,6 +45,20 @@ + + net.serenity-bdd.maven.plugins + serenity-maven-plugin + ${serenity.plugin.version} + + + serenity-reports + post-integration-test + + aggregate + + + + @@ -123,26 +137,6 @@ commons-io ${commons.io.version} - - org.eclipse.jetty - jetty-server - ${jetty.version} - - - org.eclipse.jetty - jetty-servlet - ${jetty.version} - - - org.apache.httpcomponents - httpclient - ${httpclient.version} - - - commons-io - commons-io - ${commons.io.version} - org.apache.flink flink-core @@ -176,6 +170,36 @@ commons-math3 3.6.1 + + net.serenity-bdd + serenity-core + ${serenity.version} + + + net.serenity-bdd + serenity-junit + ${serenity.version} + + + net.serenity-bdd + serenity-jbehave + ${serenity.jbehave.version} + + + net.serenity-bdd + serenity-rest-assured + ${serenity.version} + + + net.serenity-bdd + serenity-jira-requirements-provider + ${serenity.jira.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + @@ -195,6 +219,11 @@ 4.5.3 2.5 1.2.0 + 2.8.5 + 1.2.5-rc.11 + 1.24.0 + 1.1.3-rc.5 + 1.2.5-rc.6 2.19.1 diff --git a/libraries/serenity.properties b/libraries/serenity.properties new file mode 100644 index 0000000000..c77df9c0f7 --- /dev/null +++ b/libraries/serenity.properties @@ -0,0 +1,4 @@ +jira.url= +jira.project= +jira.username= +jira.password= \ No newline at end of file diff --git a/libraries/src/main/java/com/baeldung/serenity/github/GitHubUser.java b/libraries/src/main/java/com/baeldung/serenity/github/GitHubUser.java new file mode 100644 index 0000000000..5b0998dba1 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/serenity/github/GitHubUser.java @@ -0,0 +1,19 @@ +package com.baeldung.serenity.github; + +public class GitHubUser { + + private String login; + + public GitHubUser() { + super(); + } + + public String getLogin() { + return login; + } + + public void setLogin(final String login) { + this.login = login; + } + +} diff --git a/libraries/src/main/java/com/baeldung/serenity/membership/Commodity.java b/libraries/src/main/java/com/baeldung/serenity/membership/Commodity.java new file mode 100644 index 0000000000..208b73d4af --- /dev/null +++ b/libraries/src/main/java/com/baeldung/serenity/membership/Commodity.java @@ -0,0 +1,16 @@ +package com.baeldung.serenity.membership; + +/** + * @author aiet + */ +public enum Commodity { + + MacBookPro(1499), GoProHero5(400); + + public final int price; + + Commodity(int price){ + this.price = price; + } + +} diff --git a/libraries/src/main/java/com/baeldung/serenity/membership/Member.java b/libraries/src/main/java/com/baeldung/serenity/membership/Member.java new file mode 100644 index 0000000000..6e7c4db08e --- /dev/null +++ b/libraries/src/main/java/com/baeldung/serenity/membership/Member.java @@ -0,0 +1,34 @@ +package com.baeldung.serenity.membership; + +import static com.baeldung.serenity.membership.MemberGrade.Bronze; +import static com.baeldung.serenity.membership.MemberGrade.Gold; +import static com.baeldung.serenity.membership.MemberGrade.Silver; + +/** + * @author aiet + */ +public class Member { + + private int points; + + private Member(int points) { + if (points < 0) throw new IllegalArgumentException("points must not be negative!"); + this.points = points; + + } + + public static Member withInitialPoints(int initialPoints) { + return new Member(initialPoints); + } + + public MemberGrade getGrade() { + if (points < 1000) return Bronze; + else if (points >= 1000 && points < 5000) return Silver; + else return Gold; + } + + public void spend(int moneySpent) { + points += moneySpent / 10; + } + +} diff --git a/libraries/src/main/java/com/baeldung/serenity/membership/MemberGrade.java b/libraries/src/main/java/com/baeldung/serenity/membership/MemberGrade.java new file mode 100644 index 0000000000..7bb6f76495 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/serenity/membership/MemberGrade.java @@ -0,0 +1,10 @@ +package com.baeldung.serenity.membership; + +/** + * @author aiet + */ +public enum MemberGrade { + + Bronze, Silver, Gold; + +} diff --git a/libraries/src/test/java/com/baeldung/serenity/GithubUserProfilePayloadTest.java b/libraries/src/test/java/com/baeldung/serenity/GithubUserProfilePayloadTest.java new file mode 100644 index 0000000000..f8a2d6fa3c --- /dev/null +++ b/libraries/src/test/java/com/baeldung/serenity/GithubUserProfilePayloadTest.java @@ -0,0 +1,10 @@ +package com.baeldung.serenity; + +import net.serenitybdd.jbehave.SerenityStory; + +/** + * @author aiet + */ +public class GithubUserProfilePayloadTest extends SerenityStory { + +} diff --git a/libraries/src/test/java/com/baeldung/serenity/MemberStatusTest.java b/libraries/src/test/java/com/baeldung/serenity/MemberStatusTest.java new file mode 100644 index 0000000000..5c90e90eb7 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/serenity/MemberStatusTest.java @@ -0,0 +1,73 @@ +package com.baeldung.serenity; + +import com.baeldung.serenity.membership.MemberStatusSteps; +import net.serenitybdd.junit.runners.SerenityRunner; +import net.thucydides.core.annotations.Steps; +import net.thucydides.core.annotations.Title; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static com.baeldung.serenity.membership.Commodity.MacBookPro; +import static com.baeldung.serenity.membership.MemberGrade.Bronze; +import static com.baeldung.serenity.membership.MemberGrade.Gold; +import static com.baeldung.serenity.membership.MemberGrade.Silver; + +@RunWith(SerenityRunner.class) +public class MemberStatusTest { + + @Steps MemberStatusSteps memberSteps; + + @Test + public void membersShouldStartWithBronzeStatus() { + memberSteps.aClientJoinsTheMemberProgram(); + memberSteps.theMemberShouldHaveAStatusOf(Bronze); + } + + @Test + @Title("Members earn Silver grade after 1000 points ($10,000)") + public void earnsSilverAfterSpends$10000() { + memberSteps.aClientJoinsTheMemberProgram(); + memberSteps.theMemberSpends(10_000); + memberSteps.theMemberShouldHaveAStatusOf(Silver); + } + + @Test + @Title("Members with 2,000 points should earn Gold grade when added 3,000 points ($30,000)") + public void memberWith2000PointsEarnsGoldAfterSpends$30000() { + memberSteps.aMemberHasPointsOf(2000); + memberSteps.theMemberSpends(30_000); + memberSteps.theMemberShouldHaveAStatusOf(Gold); + } + + @Test + @Title("Members with 50,000 points can exchange a MacBook Pro") + public void memberWith50000PointsCanExchangeAMacbookpro(){ + memberSteps.aMemberHasPointsOf(50_000); + memberSteps.aMemberExchangeA(MacBookPro); + memberSteps.memberShouldHavePointsLeft(); + } + + /** + * This test should fail, comment out @Ignore to see how failed test can be reflected in Serenity report.
+ * Remember to add <testFailureIgnore>true</testFailureIgnore> under maven-surefire-plugin configuration. + */ + @Test + @Ignore + @Title("Members with 500 points should have a Gold status when added 4,000 points ($40,000)") + public void memberWith500PointsEarnsGoldAfterSpends$40000(){ + memberSteps.aMemberHasPointsOf(500); + memberSteps.theMemberSpends(40_000); + memberSteps.theMemberShouldHaveAStatusOf(Gold); + } + + @Test + @Ignore + @Title("Members with 100 points would have a Gold status when added 10,000 points ($100,000)") + public void memberWith100EarnsGoldAfterSpends$100000(){ + memberSteps.aMemberHasPointsOf(100); + memberSteps.theMemberSpends(100_000); + memberSteps.theMemberShouldHaveAStatusOf(Gold); + } + +} diff --git a/libraries/src/test/java/com/baeldung/serenity/github/GithubRestAssuredUserAPISteps.java b/libraries/src/test/java/com/baeldung/serenity/github/GithubRestAssuredUserAPISteps.java new file mode 100644 index 0000000000..cc434d6d19 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/serenity/github/GithubRestAssuredUserAPISteps.java @@ -0,0 +1,33 @@ +package com.baeldung.serenity.github; + +import net.thucydides.core.annotations.Step; +import org.hamcrest.Matchers; + +import java.io.IOException; + +import static net.serenitybdd.rest.SerenityRest.rest; +import static net.serenitybdd.rest.SerenityRest.then; + +/** + * @author aiet + */ +public class GithubRestAssuredUserAPISteps { + + private String api; + + @Step("Given the github REST API for user profile") + public void withUserProfileAPIEndpoint() { + api = "https://api.github.com/users/{username}"; + } + + @Step("When looking for {0} via the api") + public void getProfileOfUser(String username) throws IOException { + rest().get(api, username); + } + + @Step("Then there should be a login field with value {0} in payload of user {0}") + public void profilePayloadShouldContainLoginValue(String username) { + then().body("login", Matchers.equalTo(username)); + } + +} diff --git a/libraries/src/test/java/com/baeldung/serenity/github/GithubRestUserAPISteps.java b/libraries/src/test/java/com/baeldung/serenity/github/GithubRestUserAPISteps.java new file mode 100644 index 0000000000..6e7fbace49 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/serenity/github/GithubRestUserAPISteps.java @@ -0,0 +1,54 @@ +package com.baeldung.serenity.github; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import net.thucydides.core.annotations.Step; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; +import org.hamcrest.Matchers; + +import java.io.IOException; + +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * @author aiet + */ +public class GithubRestUserAPISteps { + + private String api; + private GitHubUser resource; + + @Step("Given the github REST API for user profile") + public void withUserProfileAPIEndpoint() { + api = "https://api.github.com/users/%s"; + } + + @Step("When looking for {0} via the api") + public void getProfileOfUser(String username) throws IOException { + HttpResponse httpResponse = getGithubUserProfile(api, username); + resource = retrieveResourceFromResponse(httpResponse, GitHubUser.class); + } + + @Step("Then there should be a login field with value {0} in payload of user {0}") + public void profilePayloadShouldContainLoginValue(String username) { + assertThat(username, Matchers.is(resource.getLogin())); + } + + private static T retrieveResourceFromResponse(final HttpResponse response, final Class clazz) throws IOException { + final String jsonFromResponse = EntityUtils.toString(response.getEntity()); + final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + return mapper.readValue(jsonFromResponse, clazz); + } + + private static HttpResponse getGithubUserProfile(String api, String username) throws IOException { + HttpUriRequest request = new HttpGet(String.format(api, username)); + return HttpClientBuilder + .create() + .build() + .execute(request); + } +} diff --git a/libraries/src/test/java/com/baeldung/serenity/github/GithubUserProfilePayloadStepDefinitions.java b/libraries/src/test/java/com/baeldung/serenity/github/GithubUserProfilePayloadStepDefinitions.java new file mode 100644 index 0000000000..f3b374b66c --- /dev/null +++ b/libraries/src/test/java/com/baeldung/serenity/github/GithubUserProfilePayloadStepDefinitions.java @@ -0,0 +1,33 @@ +package com.baeldung.serenity.github; + +import net.thucydides.core.annotations.Steps; +import org.jbehave.core.annotations.Given; +import org.jbehave.core.annotations.Then; +import org.jbehave.core.annotations.When; + +import java.io.IOException; + +public class GithubUserProfilePayloadStepDefinitions { + +// @Steps +// GithubRestUserAPISteps userAPISteps; + + @Steps + GithubRestAssuredUserAPISteps userAPISteps; + + @Given("github user profile api") + public void givenGithubUserProfileApi() { + userAPISteps.withUserProfileAPIEndpoint(); + } + + @When("looking for $user via the api") + public void whenLookingForProfileOf(String user) throws IOException { + userAPISteps.getProfileOfUser(user); + } + + @Then("github's response contains a 'login' payload same as $user") + public void thenGithubsResponseContainsAloginPayloadSameAs(String user) { + userAPISteps.profilePayloadShouldContainLoginValue(user); + } + +} diff --git a/libraries/src/test/java/com/baeldung/serenity/membership/MemberStatusSteps.java b/libraries/src/test/java/com/baeldung/serenity/membership/MemberStatusSteps.java new file mode 100644 index 0000000000..02b3f0130e --- /dev/null +++ b/libraries/src/test/java/com/baeldung/serenity/membership/MemberStatusSteps.java @@ -0,0 +1,47 @@ +package com.baeldung.serenity.membership; + +import net.thucydides.core.annotations.Pending; +import net.thucydides.core.annotations.Step; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +/** + * @author aiet + */ +public class MemberStatusSteps { + + Member member; + + @Step("Given a member has {0} points") + public void aMemberHasPointsOf(int points) { + member = Member.withInitialPoints(points); + } + + @Step("Then the member grade should be {0}") + public void theMemberShouldHaveAStatusOf(MemberGrade grade) { + assertThat(member.getGrade(), equalTo(grade)); + } + + @Step("When the member spends ${0} ") + public void theMemberSpends(int moneySpent) { + member.spend(moneySpent); + } + + @Step("Given client joins membership program") + public void aClientJoinsTheMemberProgram() { + member = Member.withInitialPoints(0); + } + + @Pending + @Step("When the member exchange {}") + public void aMemberExchangeA(Commodity commodity){ + //TODO + } + + @Pending + @Step("Then the member should have points left") + public void memberShouldHavePointsLeft() { + + } +} diff --git a/libraries/src/test/resources/stories/github_rest/user_profile/github_user_profile_payload_test.story b/libraries/src/test/resources/stories/github_rest/user_profile/github_user_profile_payload_test.story new file mode 100644 index 0000000000..841bf901b5 --- /dev/null +++ b/libraries/src/test/resources/stories/github_rest/user_profile/github_user_profile_payload_test.story @@ -0,0 +1,13 @@ + +Meta: + +Narrative: +As a user +I want to look up a valid user's profile on github +So that I can know the login payload should be the same as username + +Scenario: Github user's profile should have a login payload same as username + +Given github user profile api +When looking for eugenp via the api +Then github's response contains a 'login' payload same as eugenp From 4d17d264052836ad1892a6b36432f98e0a37122d Mon Sep 17 00:00:00 2001 From: Chandravadan S Date: Mon, 24 Apr 2017 12:08:53 +0530 Subject: [PATCH 05/17] Bael 697 - @ConfigurationProperties in Spring Boot (#1712) * Initial commit for @ConfigurationProperties (BAEL-697) * Additional validations added (BAEL-697) * Formatting changes * Updated main properties file * Minor changes to pass TravisCI (BAEL-697) * Optimisation of imports (BAEL-697) * Renamed ConfigPropertiesTest to Integration test (BAEL-697) --- .../baeldung/properties/ConfigProperties.java | 117 ++++++++++++++++++ .../ConfigPropertiesDemoApplication.java | 15 +++ .../src/main/resources/configprops.properties | 20 +++ .../ConfigPropertiesIntegrationTest.java | 52 ++++++++ .../resources/configprops-test.properties | 19 +++ 5 files changed, 223 insertions(+) create mode 100644 spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java create mode 100644 spring-boot/src/main/java/org/baeldung/properties/ConfigPropertiesDemoApplication.java create mode 100644 spring-boot/src/main/resources/configprops.properties create mode 100644 spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java create mode 100644 spring-boot/src/test/resources/configprops-test.properties diff --git a/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java b/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java new file mode 100644 index 0000000000..2c815fe998 --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java @@ -0,0 +1,117 @@ +package org.baeldung.properties; + +import java.util.List; +import java.util.Map; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.Pattern; + +import org.hibernate.validator.constraints.Length; +import org.hibernate.validator.constraints.NotBlank; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.validation.annotation.Validated; + +@Configuration +@PropertySource("classpath:configprops.properties") +@ConfigurationProperties(prefix = "mail") +@Validated +public class ConfigProperties { + + @Validated + public static class Credentials { + + @Length(max = 4, min = 1) + private String authMethod; + private String username; + private String password; + + public String getAuthMethod() { + return authMethod; + } + + public void setAuthMethod(String authMethod) { + this.authMethod = authMethod; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + } + + @NotBlank + private String host; + + @Min(1025) + @Max(65536) + private int port; + + @Pattern(regexp = "^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,6}$") + private String from; + + private Credentials credentials; + private List defaultRecipients; + private Map additionalHeaders; + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public Credentials getCredentials() { + return credentials; + } + + public void setCredentials(Credentials credentials) { + this.credentials = credentials; + } + + public List getDefaultRecipients() { + return defaultRecipients; + } + + public void setDefaultRecipients(List defaultRecipients) { + this.defaultRecipients = defaultRecipients; + } + + public Map getAdditionalHeaders() { + return additionalHeaders; + } + + public void setAdditionalHeaders(Map additionalHeaders) { + this.additionalHeaders = additionalHeaders; + } +} diff --git a/spring-boot/src/main/java/org/baeldung/properties/ConfigPropertiesDemoApplication.java b/spring-boot/src/main/java/org/baeldung/properties/ConfigPropertiesDemoApplication.java new file mode 100644 index 0000000000..8ebda17f7d --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/properties/ConfigPropertiesDemoApplication.java @@ -0,0 +1,15 @@ +package org.baeldung.properties; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; + +import com.baeldung.autoconfiguration.MySQLAutoconfiguration; + +@EnableAutoConfiguration(exclude = MySQLAutoconfiguration.class) +@ComponentScan(basePackageClasses = ConfigProperties.class) +public class ConfigPropertiesDemoApplication { + public static void main(String[] args) { + SpringApplication.run(ConfigPropertiesDemoApplication.class); + } +} diff --git a/spring-boot/src/main/resources/configprops.properties b/spring-boot/src/main/resources/configprops.properties new file mode 100644 index 0000000000..e5d9ae621d --- /dev/null +++ b/spring-boot/src/main/resources/configprops.properties @@ -0,0 +1,20 @@ +#Simple properties +mail.host=mailer@mail.com +mail.port=9000 +mail.from=mailer@mail.com + +#List properties +mail.defaultRecipients[0]=admin@mail.com +mail.defaultRecipients[1]=owner@mail.com + +#Map Properties +mail.additionalHeaders.redelivery=true +mail.additionalHeaders.secure=true +mail.additionalHeaders.p3=value + +#Object properties +mail.credentials.username=john +mail.credentials.password=password +mail.credentials.authMethod=SHA1 + + diff --git a/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java new file mode 100644 index 0000000000..ffd5bf55d6 --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java @@ -0,0 +1,52 @@ +package org.baeldung.properties; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ConfigPropertiesDemoApplication.class) +@TestPropertySource("classpath:configprops-test.properties") +public class ConfigPropertiesIntegrationTest { + + @Autowired + private ConfigProperties properties; + + @Test + public void whenSimplePropertyQueriedthenReturnsProperty() throws Exception { + Assert.assertTrue("From address is read as null!", properties.getFrom() != null); + } + + @Test + public void whenListPropertyQueriedthenReturnsProperty() throws Exception { + Assert.assertTrue("Couldn't bind list property!", properties.getDefaultRecipients() + .size() == 2); + Assert.assertTrue("Incorrectly bound list property. Expected 2 entries!", properties.getDefaultRecipients() + .size() == 2); + } + + @Test + public void whenMapPropertyQueriedthenReturnsProperty() throws Exception { + Assert.assertTrue("Couldn't bind map property!", properties.getAdditionalHeaders() != null); + Assert.assertTrue("Incorrectly bound map property. Expected 3 Entries!", properties.getAdditionalHeaders() + .size() == 3); + } + + @Test + public void whenObjectPropertyQueriedthenReturnsProperty() throws Exception { + Assert.assertTrue("Couldn't bind map property!", properties.getCredentials() != null); + Assert.assertTrue("Incorrectly bound object property!", properties.getCredentials() + .getAuthMethod() + .equals("SHA1")); + Assert.assertTrue("Incorrectly bound object property!", properties.getCredentials() + .getUsername() + .equals("john")); + Assert.assertTrue("Incorrectly bound object property!", properties.getCredentials() + .getPassword() + .equals("password")); + } +} diff --git a/spring-boot/src/test/resources/configprops-test.properties b/spring-boot/src/test/resources/configprops-test.properties new file mode 100644 index 0000000000..b27cf2107a --- /dev/null +++ b/spring-boot/src/test/resources/configprops-test.properties @@ -0,0 +1,19 @@ +#Simple properties +mail.host=mailer@mail.com +mail.port=9000 +mail.from=mailer@mail.com + +#List properties +mail.defaultRecipients[0]=admin@mail.com +mail.defaultRecipients[1]=owner@mail.com + +#Map Properties +mail.additionalHeaders.redelivery=true +mail.additionalHeaders.secure=true +mail.additionalHeaders.p3=value + +#Object properties +mail.credentials.username=john +mail.credentials.password=password +mail.credentials.authMethod=SHA1 + From b0df0937f2352e99e7039df775cbe7c11763e54a Mon Sep 17 00:00:00 2001 From: pedja4 Date: Mon, 24 Apr 2017 16:16:05 +0200 Subject: [PATCH 06/17] BAEL-845 TransferQueueTest.java (#1719) --- .../com/baeldung/transferqueue/TransferQueueTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core-java/src/test/java/com/baeldung/transferqueue/TransferQueueTest.java b/core-java/src/test/java/com/baeldung/transferqueue/TransferQueueTest.java index 4a1a663ce4..1af9821ed0 100644 --- a/core-java/src/test/java/com/baeldung/transferqueue/TransferQueueTest.java +++ b/core-java/src/test/java/com/baeldung/transferqueue/TransferQueueTest.java @@ -12,7 +12,7 @@ import static junit.framework.TestCase.assertEquals; public class TransferQueueTest { @Test - public void givenTransferQueue_whenUseMultipleConsumersAndMultipleProducers_thenShouldProcessAllMessages() throws InterruptedException { + public void whenMultipleConsumersAndProducers_thenProcessAllMessages() throws InterruptedException { //given TransferQueue transferQueue = new LinkedTransferQueue<>(); ExecutorService exService = Executors.newFixedThreadPool(3); @@ -28,7 +28,7 @@ public class TransferQueueTest { exService.execute(consumer2); //then - exService.awaitTermination(10_000, TimeUnit.MILLISECONDS); + exService.awaitTermination(5000, TimeUnit.MILLISECONDS); exService.shutdown(); assertEquals(producer1.numberOfProducedMessages.intValue(), 3); @@ -36,7 +36,7 @@ public class TransferQueueTest { } @Test - public void givenTransferQueue_whenUseOneConsumerAndOneProducer_thenShouldProcessAllMessages() throws InterruptedException { + public void whenUseOneConsumerAndOneProducer_thenShouldProcessAllMessages() throws InterruptedException { //given TransferQueue transferQueue = new LinkedTransferQueue<>(); ExecutorService exService = Executors.newFixedThreadPool(2); @@ -56,7 +56,7 @@ public class TransferQueueTest { } @Test - public void givenTransferQueue_whenUseOneProducerAndNoConsumers_thenShouldFailWithTimeout() throws InterruptedException { + public void whenUseOneProducerAndNoConsumers_thenShouldFailWithTimeout() throws InterruptedException { //given TransferQueue transferQueue = new LinkedTransferQueue<>(); ExecutorService exService = Executors.newFixedThreadPool(2); From 91552e127d6319578546f4b0a98c78a82d07c1cb Mon Sep 17 00:00:00 2001 From: lor6 Date: Mon, 24 Apr 2017 21:52:34 +0300 Subject: [PATCH 07/17] update boot version (#1720) --- spring-data-dynamodb/pom.xml | 4 ++-- .../repository/ProductInfoRepositoryIntegrationTest.java | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/spring-data-dynamodb/pom.xml b/spring-data-dynamodb/pom.xml index 3216318665..37a70b819b 100644 --- a/spring-data-dynamodb/pom.xml +++ b/spring-data-dynamodb/pom.xml @@ -11,7 +11,7 @@ spring-boot-starter-parent org.springframework.boot - 1.4.4.RELEASE + 1.5.3.RELEASE @@ -32,7 +32,7 @@ org.springframework.data spring-data-releasetrain - Gosling-SR1 + Hopper-SR10 pom import diff --git a/spring-data-dynamodb/src/test/java/com/baeldung/spring/data/dynamodb/repository/ProductInfoRepositoryIntegrationTest.java b/spring-data-dynamodb/src/test/java/com/baeldung/spring/data/dynamodb/repository/ProductInfoRepositoryIntegrationTest.java index 05badc74b4..2ff418b4ec 100644 --- a/spring-data-dynamodb/src/test/java/com/baeldung/spring/data/dynamodb/repository/ProductInfoRepositoryIntegrationTest.java +++ b/spring-data-dynamodb/src/test/java/com/baeldung/spring/data/dynamodb/repository/ProductInfoRepositoryIntegrationTest.java @@ -13,8 +13,7 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.IntegrationTest; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -25,9 +24,8 @@ import java.util.List; import static org.junit.Assert.assertTrue; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = Application.class) +@SpringBootTest(classes = Application.class) @WebAppConfiguration -@IntegrationTest @ActiveProfiles("local") @TestPropertySource(properties = { "amazon.dynamodb.endpoint=http://localhost:8000/", "amazon.aws.accesskey=test1", "amazon.aws.secretkey=test231" }) public class ProductInfoRepositoryIntegrationTest { From 4eb3f44b14ca81a8f7ed9d6f665f50f104f325ce Mon Sep 17 00:00:00 2001 From: maibin Date: Tue, 25 Apr 2017 03:29:26 +0200 Subject: [PATCH 08/17] HashSet and TreeSet comparison (#1698) --- .../java/com/baeldung/java/set/SetTest.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 core-java/src/test/java/com/baeldung/java/set/SetTest.java diff --git a/core-java/src/test/java/com/baeldung/java/set/SetTest.java b/core-java/src/test/java/com/baeldung/java/set/SetTest.java new file mode 100644 index 0000000000..59e135283f --- /dev/null +++ b/core-java/src/test/java/com/baeldung/java/set/SetTest.java @@ -0,0 +1,89 @@ +package com.baeldung.java.set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ConcurrentModificationException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; + +import org.junit.Test; + +public class SetTest { + + @Test + public void givenTreeSet_whenRetrievesObjects_thenNaturalOrder() { + Set set = new TreeSet<>(); + set.add("Baeldung"); + set.add("is"); + set.add("Awesome"); + assertEquals(3, set.size()); + assertTrue(set.iterator() + .next() + .equals("Awesome")); + } + + @Test(expected = NullPointerException.class) + public void givenTreeSet_whenAddNullObject_thenNullPointer() { + Set set = new TreeSet<>(); + set.add("Baeldung"); + set.add("is"); + set.add(null); + } + + @Test + public void givenHashSet_whenAddNullObject_thenOK() { + Set set = new HashSet<>(); + set.add("Baeldung"); + set.add("is"); + set.add(null); + assertEquals(3, set.size()); + } + + @Test + public void givenHashSetAndTreeSet_whenAddObjects_thenHashSetIsFaster() { + Set set = new HashSet<>(); + long startTime = System.nanoTime(); + set.add("Baeldung"); + set.add("is"); + set.add("Awesome"); + long endTime = System.nanoTime(); + long duration1 = (endTime - startTime); + + Set set2 = new TreeSet<>(); + startTime = System.nanoTime(); + set2.add("Baeldung"); + set2.add("is"); + set2.add("Awesome"); + endTime = System.nanoTime(); + long duration2 = (endTime - startTime); + assertTrue(duration1 < duration2); + } + + @Test + public void givenHashSetAndTreeSet_whenAddDuplicates_thenOnlyUnique() { + Set set = new HashSet<>(); + set.add("Baeldung"); + set.add("Baeldung"); + assertTrue(set.size() == 1); + + Set set2 = new TreeSet<>(); + set2.add("Baeldung"); + set2.add("Baeldung"); + assertTrue(set2.size() == 1); + } + + @Test(expected = ConcurrentModificationException.class) + public void givenHashSet_whenModifyWhenIterator_thenFailFast() { + Set set = new HashSet<>(); + set.add("Baeldung"); + Iterator it = set.iterator(); + + while (it.hasNext()) { + set.add("Awesome"); + it.next(); + } + } +} From c10f709e177e8002a2af491d7970c0467aa1147d Mon Sep 17 00:00:00 2001 From: lor6 Date: Tue, 25 Apr 2017 05:24:41 +0300 Subject: [PATCH 09/17] Bael 830 (#1682) * java http request * httpclient code * small fixes * remove try catch --- .../com/baeldung/http/HttpRequestBuilder.java | 49 +++++++ .../baeldung/http/HttpResponseWrapper.java | 31 +++++ .../baeldung/http/ParameterStringBuilder.java | 27 ++++ .../httpclient/HttpClientRequestBuilder.java | 124 ++++++++++++++++++ .../baeldung/http/HttpRequestBuilderTest.java | 40 ++++++ .../HttpClientRequestBuilderTest.java | 46 +++++++ 6 files changed, 317 insertions(+) create mode 100644 libraries/src/main/java/com/baeldung/http/HttpRequestBuilder.java create mode 100644 libraries/src/main/java/com/baeldung/http/HttpResponseWrapper.java create mode 100644 libraries/src/main/java/com/baeldung/http/ParameterStringBuilder.java create mode 100644 libraries/src/main/java/com/baeldung/httpclient/HttpClientRequestBuilder.java create mode 100644 libraries/src/test/java/com/baeldung/http/HttpRequestBuilderTest.java create mode 100644 libraries/src/test/java/com/baeldung/httpclient/HttpClientRequestBuilderTest.java diff --git a/libraries/src/main/java/com/baeldung/http/HttpRequestBuilder.java b/libraries/src/main/java/com/baeldung/http/HttpRequestBuilder.java new file mode 100644 index 0000000000..bfa7cc121b --- /dev/null +++ b/libraries/src/main/java/com/baeldung/http/HttpRequestBuilder.java @@ -0,0 +1,49 @@ +package com.baeldung.http; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Map; + +import org.apache.log4j.Logger; + +public class HttpRequestBuilder { + + private static final Logger LOG = Logger.getLogger(HttpRequestBuilder.class); + + public HttpResponseWrapper sendRequest(String urlString, String method, Map parameters, Map properties) throws IOException{ + URL url = new URL(urlString); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod(method); + if (properties != null) { + properties.forEach((key, value) -> con.setRequestProperty(key, value)); + } + if (parameters != null) { + con.setDoOutput(true); + DataOutputStream out = new DataOutputStream(con.getOutputStream()); + out.writeBytes(ParameterStringBuilder.getParamsString(parameters)); + out.flush(); + out.close(); + } + + int status = con.getResponseCode(); + + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + + HttpResponseWrapper responseWrapper = new HttpResponseWrapper(); + responseWrapper.setStatus(status); + responseWrapper.setContent(content.toString()); + + return responseWrapper; + } + +} diff --git a/libraries/src/main/java/com/baeldung/http/HttpResponseWrapper.java b/libraries/src/main/java/com/baeldung/http/HttpResponseWrapper.java new file mode 100644 index 0000000000..c0f68ac18b --- /dev/null +++ b/libraries/src/main/java/com/baeldung/http/HttpResponseWrapper.java @@ -0,0 +1,31 @@ +package com.baeldung.http; + +public class HttpResponseWrapper { + private int status; + private String content; + + public HttpResponseWrapper(){ } + + public HttpResponseWrapper(int status, String content) { + super(); + this.status = status; + this.content = content; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + +} diff --git a/libraries/src/main/java/com/baeldung/http/ParameterStringBuilder.java b/libraries/src/main/java/com/baeldung/http/ParameterStringBuilder.java new file mode 100644 index 0000000000..b148ddb3fd --- /dev/null +++ b/libraries/src/main/java/com/baeldung/http/ParameterStringBuilder.java @@ -0,0 +1,27 @@ +package com.baeldung.http; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Map; + +public class ParameterStringBuilder { + public static String getParamsString(Map params) { + StringBuilder result = new StringBuilder(); + + params.forEach((key, value) -> { + try { + result.append(URLEncoder.encode(key, "UTF-8")); + result.append("="); + result.append(URLEncoder.encode(value, "UTF-8")); + result.append("&"); + } catch (UnsupportedEncodingException exc) { + } + }); + + String resultString = result.toString(); + if (resultString.length() > 0) { + resultString = resultString.substring(0, resultString.length() - 1); + } + return resultString; + } +} diff --git a/libraries/src/main/java/com/baeldung/httpclient/HttpClientRequestBuilder.java b/libraries/src/main/java/com/baeldung/httpclient/HttpClientRequestBuilder.java new file mode 100644 index 0000000000..b2f6c36a4f --- /dev/null +++ b/libraries/src/main/java/com/baeldung/httpclient/HttpClientRequestBuilder.java @@ -0,0 +1,124 @@ +package com.baeldung.httpclient; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.message.BasicNameValuePair; + +import com.baeldung.http.HttpResponseWrapper; +import com.baeldung.http.ParameterStringBuilder; + +public class HttpClientRequestBuilder { + + public HttpResponseWrapper sendGetRequest(String url, Map parameters) { + HttpClient client = HttpClientBuilder.create() + .build(); + if (parameters != null) { + url += "?" + ParameterStringBuilder.getParamsString(parameters); + } + HttpGet request = new HttpGet(url); + try { + HttpResponse response = client.execute(request); + + HttpResponseWrapper responseWrapper = new HttpResponseWrapper(); + responseWrapper.setStatus(response.getStatusLine() + .getStatusCode()); + BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity() + .getContent())); + + String line = "", content = ""; + while ((line = in.readLine()) != null) { + content += line; + } + responseWrapper.setContent(content); + return responseWrapper; + } catch (ClientProtocolException e) { + e.printStackTrace(); + return null; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + public HttpResponseWrapper sendPostRequestWithParameters(String url, Map parameters) { + HttpClient client = HttpClientBuilder.create() + .build(); + HttpPost request = new HttpPost(url); + + try { + if (parameters != null) { + List nameValuePairs = new ArrayList<>(); + parameters.forEach((key, value) -> nameValuePairs.add(new BasicNameValuePair(key, value))); + request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); + } + + HttpResponse response = client.execute(request); + + HttpResponseWrapper responseWrapper = new HttpResponseWrapper(); + responseWrapper.setStatus(response.getStatusLine() + .getStatusCode()); + BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity() + .getContent())); + + String line = "", content = ""; + while ((line = in.readLine()) != null) { + content += line; + } + responseWrapper.setContent(content); + return responseWrapper; + } catch (ClientProtocolException e) { + e.printStackTrace(); + return null; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + public HttpResponseWrapper sendPostRequestWithJson(String url, String json) { + HttpClient client = HttpClientBuilder.create() + .build(); + HttpPost request = new HttpPost(url); + + try { + request.addHeader("Content-Type", "application/json"); + request.setEntity(new StringEntity(json)); + + HttpResponse response = client.execute(request); + + HttpResponseWrapper responseWrapper = new HttpResponseWrapper(); + responseWrapper.setStatus(response.getStatusLine() + .getStatusCode()); + BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity() + .getContent())); + + String line = "", content = ""; + while ((line = in.readLine()) != null) { + content += line; + } + responseWrapper.setContent(content); + return responseWrapper; + } catch (ClientProtocolException e) { + e.printStackTrace(); + return null; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/libraries/src/test/java/com/baeldung/http/HttpRequestBuilderTest.java b/libraries/src/test/java/com/baeldung/http/HttpRequestBuilderTest.java new file mode 100644 index 0000000000..7f5992fbd9 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/http/HttpRequestBuilderTest.java @@ -0,0 +1,40 @@ +package com.baeldung.http; + +import org.junit.Test; +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Before; + +import java.io.IOException; + +public class HttpRequestBuilderTest { + + private HttpRequestBuilder requestPerformer; + + @Before + public void setup() { + requestPerformer = new HttpRequestBuilder(); + } + + @Test + public void whenGetRequest_thenOk() throws IOException { + HttpResponseWrapper response = requestPerformer.sendRequest("http://www.example.com", "GET", null, null); + assertEquals("status code incorrect", response.getStatus(), 200); + assertTrue("content incorrect", response.getContent() + .contains("Example Domain")); + } + + @Test + public void whenPostRequest_thenOk() throws IOException { + Map parameters = new HashMap<>(); + parameters.put("param1", "val"); + Map properties = new HashMap<>(); + properties.put("Content-Type", "application/json"); + HttpResponseWrapper response = requestPerformer.sendRequest("http://www.example.com", "POST", parameters, properties); + assertEquals("status code incorrect", response.getStatus(), 200); + } + +} diff --git a/libraries/src/test/java/com/baeldung/httpclient/HttpClientRequestBuilderTest.java b/libraries/src/test/java/com/baeldung/httpclient/HttpClientRequestBuilderTest.java new file mode 100644 index 0000000000..886d2649a3 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/httpclient/HttpClientRequestBuilderTest.java @@ -0,0 +1,46 @@ +package com.baeldung.httpclient; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.http.HttpResponseWrapper; + +public class HttpClientRequestBuilderTest { + private HttpClientRequestBuilder requestBuilder; + + @Before + public void setup() { + requestBuilder = new HttpClientRequestBuilder(); + } + + @Test + public void whenGetRequest_thenOk() { + Map parameters = new HashMap<>(); + parameters.put("param1", "val"); + HttpResponseWrapper response = requestBuilder.sendGetRequest("http://www.example.com",parameters); + assertEquals("status code incorrect", response.getStatus(), 200); + assertTrue("content incorrect", response.getContent() + .contains("Example Domain")); + } + + @Test + public void whenPostRequestWithParameters_thenOk() { + Map parameters = new HashMap<>(); + parameters.put("param1", "val"); + HttpResponseWrapper response = requestBuilder.sendPostRequestWithParameters("http://www.example.com", parameters); + assertEquals("status code incorrect", response.getStatus(), 200); + } + + @Test + public void whenPostRequestWithJson_thenOk() { + String json = "{\"id\":\"1\"}"; + HttpResponseWrapper response = requestBuilder.sendPostRequestWithJson("http://www.example.com",json); + assertEquals("status code incorrect", response.getStatus(), 200); + } +} From a7b7ccad2da4a4e4b767b8b36a025f16011508fc Mon Sep 17 00:00:00 2001 From: "Eunice A. Obugyei" Date: Tue, 25 Apr 2017 04:55:34 +0000 Subject: [PATCH 10/17] Introduction to JAX-WS (#1696) * Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611] * Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611] * Removed unnecessary comment * Added mockito-core dependency * Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611] Added Exception test cases * Applied baeldung formatter in Eclipse * Merged from https://github.com/eugenp/tutorials Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611] * Revert "Merged from https://github.com/eugenp/tutorials" This reverts commit 74447a163b9e3f244a2578315fbdb525d20cd16b. * Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611] * Removed mockito version from properties * Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611] --- .../jaxws/client/EmployeeServiceClient.java | 25 +++++ .../config/EmployeeServicePublisher.java | 12 --- .../bottomup}/EmployeeService.java | 8 +- .../bottomup}/EmployeeServiceImpl.java | 12 +-- .../exception/EmployeeAlreadyExists.java | 2 +- .../bottomup}/exception/EmployeeNotFound.java | 2 +- .../{ => server/bottomup}/model/Employee.java | 2 +- .../config/EmployeeServicePublisher.java | 14 +++ .../repository/EmployeeRepository.java | 8 +- .../repository/EmployeeRepositoryImpl.java | 8 +- .../topdown/EmployeeServiceTopDown.java | 34 +++++++ .../topdown/EmployeeServiceTopDownImpl.java | 19 ++++ .../EmployeeServiceTopDown_Service.java | 94 +++++++++++++++++++ .../jaxws/server/topdown/ObjectFactory.java | 45 +++++++++ .../jaxws/wsdl/employeeservicetopdown.wsdl | 42 +++++++++ 15 files changed, 294 insertions(+), 33 deletions(-) create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/EmployeeServiceClient.java delete mode 100644 jee7/src/main/java/com/baeldung/jaxws/config/EmployeeServicePublisher.java rename jee7/src/main/java/com/baeldung/jaxws/{ => server/bottomup}/EmployeeService.java (69%) rename jee7/src/main/java/com/baeldung/jaxws/{ => server/bottomup}/EmployeeServiceImpl.java (76%) rename jee7/src/main/java/com/baeldung/jaxws/{ => server/bottomup}/exception/EmployeeAlreadyExists.java (83%) rename jee7/src/main/java/com/baeldung/jaxws/{ => server/bottomup}/exception/EmployeeNotFound.java (82%) rename jee7/src/main/java/com/baeldung/jaxws/{ => server/bottomup}/model/Employee.java (90%) create mode 100644 jee7/src/main/java/com/baeldung/jaxws/server/config/EmployeeServicePublisher.java rename jee7/src/main/java/com/baeldung/jaxws/{ => server}/repository/EmployeeRepository.java (61%) rename jee7/src/main/java/com/baeldung/jaxws/{ => server}/repository/EmployeeRepositoryImpl.java (87%) create mode 100644 jee7/src/main/java/com/baeldung/jaxws/server/topdown/EmployeeServiceTopDown.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/server/topdown/EmployeeServiceTopDownImpl.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/server/topdown/EmployeeServiceTopDown_Service.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/server/topdown/ObjectFactory.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/wsdl/employeeservicetopdown.wsdl diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeServiceClient.java b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeServiceClient.java new file mode 100644 index 0000000000..3d5450690a --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeServiceClient.java @@ -0,0 +1,25 @@ +package com.baeldung.jaxws.client; + + +import com.baeldung.jaxws.server.bottomup.EmployeeService; + +import javax.xml.namespace.QName; +import javax.xml.ws.Service; +import java.net.URL; + +public class EmployeeServiceClient { + + public static void main(String[] args) throws Exception { + + URL url = new URL("http://localhost:8081/employeeservice?wsdl"); + QName qname = new QName("http://bottomup.server.jaxws.baeldung.com/", "EmployeeServiceImplService"); + + Service service = Service.create(url, qname); + + EmployeeService employeeService = service.getPort(EmployeeService.class); + employeeService.countEmployees(); + + System.out.println(employeeService.countEmployees()); + + } +} \ No newline at end of file diff --git a/jee7/src/main/java/com/baeldung/jaxws/config/EmployeeServicePublisher.java b/jee7/src/main/java/com/baeldung/jaxws/config/EmployeeServicePublisher.java deleted file mode 100644 index ac3b049320..0000000000 --- a/jee7/src/main/java/com/baeldung/jaxws/config/EmployeeServicePublisher.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.jaxws.config; - -import javax.xml.ws.Endpoint; - -import com.baeldung.jaxws.EmployeeServiceImpl; - -public class EmployeeServicePublisher { - - public static void main(String[] args) { - Endpoint.publish("http://localhost:8080/employeeservice", new EmployeeServiceImpl()); - } -} diff --git a/jee7/src/main/java/com/baeldung/jaxws/EmployeeService.java b/jee7/src/main/java/com/baeldung/jaxws/server/bottomup/EmployeeService.java similarity index 69% rename from jee7/src/main/java/com/baeldung/jaxws/EmployeeService.java rename to jee7/src/main/java/com/baeldung/jaxws/server/bottomup/EmployeeService.java index 9735607da6..7381e58dad 100644 --- a/jee7/src/main/java/com/baeldung/jaxws/EmployeeService.java +++ b/jee7/src/main/java/com/baeldung/jaxws/server/bottomup/EmployeeService.java @@ -1,13 +1,13 @@ -package com.baeldung.jaxws; +package com.baeldung.jaxws.server.bottomup; import java.util.List; import javax.jws.WebMethod; import javax.jws.WebService; -import com.baeldung.jaxws.exception.EmployeeAlreadyExists; -import com.baeldung.jaxws.exception.EmployeeNotFound; -import com.baeldung.jaxws.model.Employee; +import com.baeldung.jaxws.server.bottomup.exception.EmployeeAlreadyExists; +import com.baeldung.jaxws.server.bottomup.exception.EmployeeNotFound; +import com.baeldung.jaxws.server.bottomup.model.Employee; @WebService public interface EmployeeService { diff --git a/jee7/src/main/java/com/baeldung/jaxws/EmployeeServiceImpl.java b/jee7/src/main/java/com/baeldung/jaxws/server/bottomup/EmployeeServiceImpl.java similarity index 76% rename from jee7/src/main/java/com/baeldung/jaxws/EmployeeServiceImpl.java rename to jee7/src/main/java/com/baeldung/jaxws/server/bottomup/EmployeeServiceImpl.java index c1c9cd4385..602a2f7336 100644 --- a/jee7/src/main/java/com/baeldung/jaxws/EmployeeServiceImpl.java +++ b/jee7/src/main/java/com/baeldung/jaxws/server/bottomup/EmployeeServiceImpl.java @@ -1,4 +1,4 @@ -package com.baeldung.jaxws; +package com.baeldung.jaxws.server.bottomup; import java.util.List; @@ -6,12 +6,12 @@ import javax.inject.Inject; import javax.jws.WebMethod; import javax.jws.WebService; -import com.baeldung.jaxws.exception.EmployeeAlreadyExists; -import com.baeldung.jaxws.exception.EmployeeNotFound; -import com.baeldung.jaxws.model.Employee; -import com.baeldung.jaxws.repository.EmployeeRepository; +import com.baeldung.jaxws.server.bottomup.exception.EmployeeAlreadyExists; +import com.baeldung.jaxws.server.bottomup.exception.EmployeeNotFound; +import com.baeldung.jaxws.server.bottomup.model.Employee; +import com.baeldung.jaxws.server.repository.EmployeeRepository; -@WebService(serviceName = "EmployeeService", endpointInterface = "com.baeldung.jaxws.EmployeeService") +@WebService(serviceName = "EmployeeService", endpointInterface = "com.baeldung.jaxws.server.bottomup.EmployeeService") public class EmployeeServiceImpl implements EmployeeService { @Inject diff --git a/jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeAlreadyExists.java b/jee7/src/main/java/com/baeldung/jaxws/server/bottomup/exception/EmployeeAlreadyExists.java similarity index 83% rename from jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeAlreadyExists.java rename to jee7/src/main/java/com/baeldung/jaxws/server/bottomup/exception/EmployeeAlreadyExists.java index 8a96f8aec0..26fd80f1e5 100644 --- a/jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeAlreadyExists.java +++ b/jee7/src/main/java/com/baeldung/jaxws/server/bottomup/exception/EmployeeAlreadyExists.java @@ -1,4 +1,4 @@ -package com.baeldung.jaxws.exception; +package com.baeldung.jaxws.server.bottomup.exception; import javax.xml.ws.WebFault; diff --git a/jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeNotFound.java b/jee7/src/main/java/com/baeldung/jaxws/server/bottomup/exception/EmployeeNotFound.java similarity index 82% rename from jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeNotFound.java rename to jee7/src/main/java/com/baeldung/jaxws/server/bottomup/exception/EmployeeNotFound.java index 3de2ca8db6..52397d55a3 100644 --- a/jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeNotFound.java +++ b/jee7/src/main/java/com/baeldung/jaxws/server/bottomup/exception/EmployeeNotFound.java @@ -1,4 +1,4 @@ -package com.baeldung.jaxws.exception; +package com.baeldung.jaxws.server.bottomup.exception; import javax.xml.ws.WebFault; diff --git a/jee7/src/main/java/com/baeldung/jaxws/model/Employee.java b/jee7/src/main/java/com/baeldung/jaxws/server/bottomup/model/Employee.java similarity index 90% rename from jee7/src/main/java/com/baeldung/jaxws/model/Employee.java rename to jee7/src/main/java/com/baeldung/jaxws/server/bottomup/model/Employee.java index dbbdc234cf..089ff88aa2 100644 --- a/jee7/src/main/java/com/baeldung/jaxws/model/Employee.java +++ b/jee7/src/main/java/com/baeldung/jaxws/server/bottomup/model/Employee.java @@ -1,4 +1,4 @@ -package com.baeldung.jaxws.model; +package com.baeldung.jaxws.server.bottomup.model; public class Employee { private int id; diff --git a/jee7/src/main/java/com/baeldung/jaxws/server/config/EmployeeServicePublisher.java b/jee7/src/main/java/com/baeldung/jaxws/server/config/EmployeeServicePublisher.java new file mode 100644 index 0000000000..8659833f99 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/server/config/EmployeeServicePublisher.java @@ -0,0 +1,14 @@ +package com.baeldung.jaxws.server.config; + +import javax.xml.ws.Endpoint; + +import com.baeldung.jaxws.server.bottomup.EmployeeServiceImpl; +import com.baeldung.jaxws.server.topdown.EmployeeServiceTopDownImpl; + +public class EmployeeServicePublisher { + + public static void main(String[] args) { + Endpoint.publish("http://localhost:8080/employeeservicetopdown", new EmployeeServiceTopDownImpl()); + Endpoint.publish("http://localhost:8080/employeeservice", new EmployeeServiceImpl()); + } +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/repository/EmployeeRepository.java b/jee7/src/main/java/com/baeldung/jaxws/server/repository/EmployeeRepository.java similarity index 61% rename from jee7/src/main/java/com/baeldung/jaxws/repository/EmployeeRepository.java rename to jee7/src/main/java/com/baeldung/jaxws/server/repository/EmployeeRepository.java index 0d5dec0462..c9d8b4d33c 100644 --- a/jee7/src/main/java/com/baeldung/jaxws/repository/EmployeeRepository.java +++ b/jee7/src/main/java/com/baeldung/jaxws/server/repository/EmployeeRepository.java @@ -1,10 +1,10 @@ -package com.baeldung.jaxws.repository; +package com.baeldung.jaxws.server.repository; import java.util.List; -import com.baeldung.jaxws.exception.EmployeeAlreadyExists; -import com.baeldung.jaxws.exception.EmployeeNotFound; -import com.baeldung.jaxws.model.Employee; +import com.baeldung.jaxws.server.bottomup.exception.EmployeeAlreadyExists; +import com.baeldung.jaxws.server.bottomup.exception.EmployeeNotFound; +import com.baeldung.jaxws.server.bottomup.model.Employee; public interface EmployeeRepository { diff --git a/jee7/src/main/java/com/baeldung/jaxws/repository/EmployeeRepositoryImpl.java b/jee7/src/main/java/com/baeldung/jaxws/server/repository/EmployeeRepositoryImpl.java similarity index 87% rename from jee7/src/main/java/com/baeldung/jaxws/repository/EmployeeRepositoryImpl.java rename to jee7/src/main/java/com/baeldung/jaxws/server/repository/EmployeeRepositoryImpl.java index f67509fff5..f211c4f25b 100644 --- a/jee7/src/main/java/com/baeldung/jaxws/repository/EmployeeRepositoryImpl.java +++ b/jee7/src/main/java/com/baeldung/jaxws/server/repository/EmployeeRepositoryImpl.java @@ -1,11 +1,11 @@ -package com.baeldung.jaxws.repository; +package com.baeldung.jaxws.server.repository; import java.util.ArrayList; import java.util.List; -import com.baeldung.jaxws.exception.EmployeeAlreadyExists; -import com.baeldung.jaxws.exception.EmployeeNotFound; -import com.baeldung.jaxws.model.Employee; +import com.baeldung.jaxws.server.bottomup.exception.EmployeeAlreadyExists; +import com.baeldung.jaxws.server.bottomup.exception.EmployeeNotFound; +import com.baeldung.jaxws.server.bottomup.model.Employee; public class EmployeeRepositoryImpl implements EmployeeRepository { private List employeeList; diff --git a/jee7/src/main/java/com/baeldung/jaxws/server/topdown/EmployeeServiceTopDown.java b/jee7/src/main/java/com/baeldung/jaxws/server/topdown/EmployeeServiceTopDown.java new file mode 100644 index 0000000000..ec4103438b --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/server/topdown/EmployeeServiceTopDown.java @@ -0,0 +1,34 @@ + +package com.baeldung.jaxws.server.topdown; + +import javax.jws.WebMethod; +import javax.jws.WebResult; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; +import javax.xml.bind.annotation.XmlSeeAlso; + + +/** + * This class was generated by the JAX-WS RI. + * JAX-WS RI 2.2.4-b01 + * Generated source version: 2.2 + * + */ +@WebService(name = "EmployeeServiceTopDown", targetNamespace = "http://topdown.server.jaxws.baeldung.com/") +@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) +@XmlSeeAlso({ + ObjectFactory.class +}) +public interface EmployeeServiceTopDown { + + + /** + * + * @return + * returns int + */ + @WebMethod(action = "http://topdown.server.jaxws.baeldung.com/EmployeeServiceTopDown/countEmployees") + @WebResult(name = "countEmployeesResponse", targetNamespace = "http://topdown.server.jaxws.baeldung.com/", partName = "parameters") + public int countEmployees(); + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/server/topdown/EmployeeServiceTopDownImpl.java b/jee7/src/main/java/com/baeldung/jaxws/server/topdown/EmployeeServiceTopDownImpl.java new file mode 100644 index 0000000000..bd46c025b7 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/server/topdown/EmployeeServiceTopDownImpl.java @@ -0,0 +1,19 @@ +package com.baeldung.jaxws.server.topdown; + +import com.baeldung.jaxws.server.repository.EmployeeRepository; + +import javax.inject.Inject; +import javax.jws.WebMethod; +import javax.jws.WebService; + + +@WebService(name = "EmployeeServiceTopDown", targetNamespace = "http://topdown.server.jaxws.baeldung.com/", endpointInterface = "com.baeldung.jaxws.server.topdown.EmployeeServiceTopDown") +public class EmployeeServiceTopDownImpl implements EmployeeServiceTopDown { + + @Inject private EmployeeRepository employeeRepositoryImpl; + + @WebMethod + public int countEmployees() { + return employeeRepositoryImpl.count(); + } +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/server/topdown/EmployeeServiceTopDown_Service.java b/jee7/src/main/java/com/baeldung/jaxws/server/topdown/EmployeeServiceTopDown_Service.java new file mode 100644 index 0000000000..ee3382adb6 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/server/topdown/EmployeeServiceTopDown_Service.java @@ -0,0 +1,94 @@ + +package com.baeldung.jaxws.server.topdown; + +import java.net.MalformedURLException; +import java.net.URL; +import javax.xml.namespace.QName; +import javax.xml.ws.Service; +import javax.xml.ws.WebEndpoint; +import javax.xml.ws.WebServiceClient; +import javax.xml.ws.WebServiceException; +import javax.xml.ws.WebServiceFeature; + + +/** + * This class was generated by the JAX-WS RI. + * JAX-WS RI 2.2.4-b01 + * Generated source version: 2.2 + * + */ +@WebServiceClient(name = "EmployeeServiceTopDown", targetNamespace = "http://topdown.server.jaxws.baeldung.com/", wsdlLocation = "file:/Users/do-enr-lap-4/Developer/baeldung/source/tutorials/jee7/src/main/java/com/baeldung/jaxws/server/topdown/wsdl/employeeservicetopdown.wsdl") +public class EmployeeServiceTopDown_Service + extends Service +{ + + private final static URL EMPLOYEESERVICETOPDOWN_WSDL_LOCATION; + private final static WebServiceException EMPLOYEESERVICETOPDOWN_EXCEPTION; + private final static QName EMPLOYEESERVICETOPDOWN_QNAME = new QName("http://topdown.server.jaxws.baeldung.com/", "EmployeeServiceTopDown"); + + static { + URL url = null; + WebServiceException e = null; + try { + url = new URL("file:/Users/do-enr-lap-4/Developer/baeldung/source/tutorials/jee7/src/main/java/com/baeldung/jaxws/server/topdown/wsdl/employeeservicetopdown.wsdl"); + } catch (MalformedURLException ex) { + e = new WebServiceException(ex); + } + EMPLOYEESERVICETOPDOWN_WSDL_LOCATION = url; + EMPLOYEESERVICETOPDOWN_EXCEPTION = e; + } + + public EmployeeServiceTopDown_Service() { + super(__getWsdlLocation(), EMPLOYEESERVICETOPDOWN_QNAME); + } + + public EmployeeServiceTopDown_Service(WebServiceFeature... features) { + super(__getWsdlLocation(), EMPLOYEESERVICETOPDOWN_QNAME, features); + } + + public EmployeeServiceTopDown_Service(URL wsdlLocation) { + super(wsdlLocation, EMPLOYEESERVICETOPDOWN_QNAME); + } + + public EmployeeServiceTopDown_Service(URL wsdlLocation, WebServiceFeature... features) { + super(wsdlLocation, EMPLOYEESERVICETOPDOWN_QNAME, features); + } + + public EmployeeServiceTopDown_Service(URL wsdlLocation, QName serviceName) { + super(wsdlLocation, serviceName); + } + + public EmployeeServiceTopDown_Service(URL wsdlLocation, QName serviceName, WebServiceFeature... features) { + super(wsdlLocation, serviceName, features); + } + + /** + * + * @return + * returns EmployeeServiceTopDown + */ + @WebEndpoint(name = "EmployeeServiceTopDownSOAP") + public EmployeeServiceTopDown getEmployeeServiceTopDownSOAP() { + return super.getPort(new QName("http://topdown.server.jaxws.baeldung.com/", "EmployeeServiceTopDownSOAP"), EmployeeServiceTopDown.class); + } + + /** + * + * @param features + * A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the features parameter will have their default values. + * @return + * returns EmployeeServiceTopDown + */ + @WebEndpoint(name = "EmployeeServiceTopDownSOAP") + public EmployeeServiceTopDown getEmployeeServiceTopDownSOAP(WebServiceFeature... features) { + return super.getPort(new QName("http://topdown.server.jaxws.baeldung.com/", "EmployeeServiceTopDownSOAP"), EmployeeServiceTopDown.class, features); + } + + private static URL __getWsdlLocation() { + if (EMPLOYEESERVICETOPDOWN_EXCEPTION!= null) { + throw EMPLOYEESERVICETOPDOWN_EXCEPTION; + } + return EMPLOYEESERVICETOPDOWN_WSDL_LOCATION; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/server/topdown/ObjectFactory.java b/jee7/src/main/java/com/baeldung/jaxws/server/topdown/ObjectFactory.java new file mode 100644 index 0000000000..53e23eee5d --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/server/topdown/ObjectFactory.java @@ -0,0 +1,45 @@ + +package com.baeldung.jaxws.server.topdown; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.namespace.QName; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the com.baeldung.jaxws.server.topdown package. + *

An ObjectFactory allows you to programatically + * construct new instances of the Java representation + * for XML content. The Java representation of XML + * content can consist of schema derived interfaces + * and classes representing the binding of schema + * type definitions, element declarations and model + * groups. Factory methods for each of these are + * provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + private final static QName _CountEmployeesResponse_QNAME = new QName("http://topdown.server.jaxws.baeldung.com/", "countEmployeesResponse"); + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.baeldung.jaxws.server.topdown + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link Integer }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://topdown.server.jaxws.baeldung.com/", name = "countEmployeesResponse") + public JAXBElement createCountEmployeesResponse(Integer value) { + return new JAXBElement(_CountEmployeesResponse_QNAME, Integer.class, null, value); + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/wsdl/employeeservicetopdown.wsdl b/jee7/src/main/java/com/baeldung/jaxws/wsdl/employeeservicetopdown.wsdl new file mode 100644 index 0000000000..426717f90e --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/wsdl/employeeservicetopdown.wsdl @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From cee7e71400c627a5a099f989975982e090992f28 Mon Sep 17 00:00:00 2001 From: Yasin Date: Tue, 25 Apr 2017 10:35:40 +0530 Subject: [PATCH 11/17] BAEL-88 Testing in Spring Boot (#1722) --- .../boot/boottest/EmployeeRepository.java | 5 +- .../boot/boottest/EmployeeService.java | 5 +- .../boot/boottest/EmployeeServiceImpl.java | 5 +- .../EmployeeRepositoryIntegrationTest.java | 35 ++++++------- .../EmployeeServiceImplIntegrationTest.java | 49 ++++++++----------- 5 files changed, 41 insertions(+), 58 deletions(-) diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRepository.java b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRepository.java index fa234f0e3a..98d1c33212 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRepository.java +++ b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRepository.java @@ -1,7 +1,6 @@ package org.baeldung.boot.boottest; import java.util.List; -import java.util.Optional; import javax.transaction.Transactional; @@ -12,9 +11,9 @@ import org.springframework.stereotype.Repository; @Transactional public interface EmployeeRepository extends JpaRepository { - public Optional findByName(String name); + public Employee findByName(String name); - public Optional findById(Long id); + public Employee findById(Long id); public List findAll(); diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeService.java b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeService.java index f0ed49e699..13b5ca56e0 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeService.java +++ b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeService.java @@ -1,13 +1,12 @@ package org.baeldung.boot.boottest; import java.util.List; -import java.util.Optional; public interface EmployeeService { - public Optional getEmployeeById(Long id); + public Employee getEmployeeById(Long id); - public Optional getEmployeeByName(String name); + public Employee getEmployeeByName(String name); public List getAllEmployees(); diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java index 6d5bf426ec..3fbfa92bc8 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java +++ b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java @@ -1,7 +1,6 @@ package org.baeldung.boot.boottest; import java.util.List; -import java.util.Optional; import javax.transaction.Transactional; @@ -16,12 +15,12 @@ public class EmployeeServiceImpl implements EmployeeService { private EmployeeRepository employeeRepository; @Override - public Optional getEmployeeById(Long id) { + public Employee getEmployeeById(Long id) { return employeeRepository.findById(id); } @Override - public Optional getEmployeeByName(String name) { + public Employee getEmployeeByName(String name) { return employeeRepository.findByName(name); } diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryIntegrationTest.java index cf94f4be49..ec599beedf 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryIntegrationTest.java @@ -3,11 +3,7 @@ package org.baeldung.boot.boottest; import static org.assertj.core.api.Assertions.assertThat; import java.util.List; -import java.util.NoSuchElementException; -import java.util.Optional; -import org.baeldung.boot.boottest.Employee; -import org.baeldung.boot.boottest.EmployeeRepository; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -27,18 +23,17 @@ public class EmployeeRepositoryIntegrationTest { @Test public void whenFindByName_thenReturnEmployee() { - Employee emp = new Employee("test"); - entityManager.persistAndFlush(emp); + Employee alex = new Employee("alex"); + entityManager.persistAndFlush(alex); - Optional fromDb = employeeRepository.findByName(emp.getName()); - assertThat(fromDb.get() - .getName()).isEqualTo(emp.getName()); + Employee found = employeeRepository.findByName(alex.getName()); + assertThat(found.getName()).isEqualTo(alex.getName()); } - @Test(expected = NoSuchElementException.class) - public void whenInvalidName_thenNoSuchElementException() { - Optional fromDb = employeeRepository.findByName("doesNotExist"); - fromDb.get(); + @Test + public void whenInvalidName_thenReturnNull() { + Employee fromDb = employeeRepository.findByName("doesNotExist"); + assertThat(fromDb).isNull(); } @Test @@ -46,15 +41,14 @@ public class EmployeeRepositoryIntegrationTest { Employee emp = new Employee("test"); entityManager.persistAndFlush(emp); - Optional fromDb = employeeRepository.findById(emp.getId()); - assertThat(fromDb.get() - .getName()).isEqualTo(emp.getName()); + Employee fromDb = employeeRepository.findById(emp.getId()); + assertThat(fromDb.getName()).isEqualTo(emp.getName()); } - @Test(expected = NoSuchElementException.class) - public void whenInvalidId_thenNoSuchElementException() { - Optional fromDb = employeeRepository.findById(-11L); - fromDb.get(); + @Test + public void whenInvalidId_thenReturnNull() { + Employee fromDb = employeeRepository.findById(-11L); + assertThat(fromDb).isNull(); } @Test @@ -74,5 +68,4 @@ public class EmployeeRepositoryIntegrationTest { .extracting(Employee::getName) .containsOnly(alex.getName(), ron.getName(), bob.getName()); } - } diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplIntegrationTest.java index e8a585a23e..8038ae4373 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplIntegrationTest.java @@ -4,13 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; import java.util.List; -import java.util.NoSuchElementException; -import java.util.Optional; -import org.baeldung.boot.boottest.Employee; -import org.baeldung.boot.boottest.EmployeeRepository; -import org.baeldung.boot.boottest.EmployeeService; -import org.baeldung.boot.boottest.EmployeeServiceImpl; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -44,38 +38,38 @@ public class EmployeeServiceImplIntegrationTest { Employee john = new Employee("john"); john.setId(11L); - Optional emp = Optional.of(john); - Employee bob = new Employee("bob"); Employee alex = new Employee("alex"); List allEmployees = Arrays.asList(john, bob, alex); Mockito.when(employeeRepository.findByName(john.getName())) - .thenReturn(emp); + .thenReturn(john); + Mockito.when(employeeRepository.findByName(alex.getName())) + .thenReturn(alex); Mockito.when(employeeRepository.findByName("wrong_name")) - .thenReturn(Optional.empty()); + .thenReturn(null); Mockito.when(employeeRepository.findById(john.getId())) - .thenReturn(emp); + .thenReturn(john); Mockito.when(employeeRepository.findAll()) .thenReturn(allEmployees); Mockito.when(employeeRepository.findById(-99L)) - .thenReturn(Optional.empty()); + .thenReturn(null); } @Test public void whenValidName_thenEmployeeShouldBeFound() { - Optional fromDb = employeeService.getEmployeeByName("john"); - assertThat(fromDb.get() - .getName()).isEqualTo("john"); + String name = "alex"; + Employee found = employeeService.getEmployeeByName(name); + + assertThat(found.getName()) + .isEqualTo(name); + } - verifyFindByNameIsCalledOnce("john"); - } - - @Test(expected = NoSuchElementException.class) + @Test public void whenInValidName_thenEmployeeShouldNotBeFound() { - Optional fromDb = employeeService.getEmployeeByName("wrong_name"); - fromDb.get(); + Employee fromDb = employeeService.getEmployeeByName("wrong_name"); + assertThat(fromDb).isNull(); verifyFindByNameIsCalledOnce("wrong_name"); } @@ -97,19 +91,18 @@ public class EmployeeServiceImplIntegrationTest { } @Test - public void whenValidI_thendEmployeeShouldBeFound() { - Optional fromDb = employeeService.getEmployeeById(11L); - assertThat(fromDb.get() - .getName()).isEqualTo("john"); + public void whenValidId_thenEmployeeShouldBeFound() { + Employee fromDb = employeeService.getEmployeeById(11L); + assertThat(fromDb.getName()).isEqualTo("john"); verifyFindByIdIsCalledOnce(); } - @Test(expected = NoSuchElementException.class) + @Test public void whenInValidId_thenEmployeeShouldNotBeFound() { - Optional fromDb = employeeService.getEmployeeById(-99L); + Employee fromDb = employeeService.getEmployeeById(-99L); verifyFindByIdIsCalledOnce(); - fromDb.get(); + assertThat(fromDb).isNull(); } @Test From 6aeb90de5b5b5cfc7b25b119085c7606475e6d41 Mon Sep 17 00:00:00 2001 From: Sunil Mogadati Date: Tue, 25 Apr 2017 00:56:08 -0600 Subject: [PATCH 12/17] BAEL-611 Add JAX-WS client and JUnit Test (#1725) * Add NDC and JBoss Logging to the demo application * NDC for Log4j, Log4j2 and JBoss Logging * Simplify NDC example by making it a single operation instead of two * Make NDC example as RestController, Use JBoss Logging only as a logging bridge * Fix merge conflicts in pull request - log-mdc pom.xml updated * BAEL-445 Update to Spring security SpEL example * BAEL-445: Change tabs to spaces in the updated code * BAEL-245: Add Enum Serialization exmaple * BAEL-245: Remove the folder jackson/src/test/java/com/baeldung/jackson/dtos/withEnum as the example is not used anymore * Add more enum serialization examples to align with previous example and prevent build fail * BAEL-611: Minor formatting changes * BAEL-611: Update Test case method names * BAEL-611 Add JAX-WS client and JUnit Test --- jee7/pom.xml | 1 + .../baeldung/jaxws/client/AddEmployee.java | 79 +++++ .../jaxws/client/AddEmployeeResponse.java | 62 ++++ .../baeldung/jaxws/client/CountEmployees.java | 32 ++ .../jaxws/client/CountEmployeesResponse.java | 54 ++++ .../baeldung/jaxws/client/DeleteEmployee.java | 52 +++ .../jaxws/client/DeleteEmployeeResponse.java | 54 ++++ .../com/baeldung/jaxws/client/Employee.java | 79 +++++ .../jaxws/client/EmployeeAlreadyExists.java | 60 ++++ .../EmployeeAlreadyExists_Exception.java | 54 ++++ .../jaxws/client/EmployeeNotFound.java | 60 ++++ .../client/EmployeeNotFound_Exception.java | 54 ++++ .../jaxws/client/EmployeeService.java | 139 +++++++++ .../jaxws/client/EmployeeServiceClient.java | 17 +- .../jaxws/client/EmployeeService_Service.java | 94 ++++++ .../jaxws/client/GetAllEmployees.java | 32 ++ .../jaxws/client/GetAllEmployeesResponse.java | 69 ++++ .../baeldung/jaxws/client/GetEmployee.java | 52 +++ .../jaxws/client/GetEmployeeResponse.java | 62 ++++ .../baeldung/jaxws/client/ObjectFactory.java | 295 ++++++++++++++++++ .../baeldung/jaxws/client/UpdateEmployee.java | 79 +++++ .../jaxws/client/UpdateEmployeeResponse.java | 62 ++++ .../baeldung/jaxws/client/package-info.java | 2 + .../jaxws/EmployeeServiceLiveTest.java | 51 +-- 24 files changed, 1559 insertions(+), 36 deletions(-) create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/AddEmployee.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/AddEmployeeResponse.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/CountEmployees.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/CountEmployeesResponse.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/DeleteEmployee.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/DeleteEmployeeResponse.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/Employee.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/EmployeeAlreadyExists.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/EmployeeAlreadyExists_Exception.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/EmployeeNotFound.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/EmployeeNotFound_Exception.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/EmployeeService.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/EmployeeService_Service.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/GetAllEmployees.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/GetAllEmployeesResponse.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/GetEmployee.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/GetEmployeeResponse.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/ObjectFactory.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/UpdateEmployee.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/UpdateEmployeeResponse.java create mode 100644 jee7/src/main/java/com/baeldung/jaxws/client/package-info.java diff --git a/jee7/pom.xml b/jee7/pom.xml index e398651055..8ed6eee6be 100644 --- a/jee7/pom.xml +++ b/jee7/pom.xml @@ -171,6 +171,7 @@ **/*IntegrationTest.java **/*LongRunningUnitTest.java **/*ManualTest.java + **/*LiveTest.java diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/AddEmployee.java b/jee7/src/main/java/com/baeldung/jaxws/client/AddEmployee.java new file mode 100644 index 0000000000..85f217398d --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/AddEmployee.java @@ -0,0 +1,79 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for addEmployee complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="addEmployee">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="arg0" type="{http://www.w3.org/2001/XMLSchema}int"/>
+ *         <element name="arg1" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "addEmployee", propOrder = { + "arg0", + "arg1" +}) +public class AddEmployee { + + protected int arg0; + protected String arg1; + + /** + * Gets the value of the arg0 property. + * + */ + public int getArg0() { + return arg0; + } + + /** + * Sets the value of the arg0 property. + * + */ + public void setArg0(int value) { + this.arg0 = value; + } + + /** + * Gets the value of the arg1 property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getArg1() { + return arg1; + } + + /** + * Sets the value of the arg1 property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setArg1(String value) { + this.arg1 = value; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/AddEmployeeResponse.java b/jee7/src/main/java/com/baeldung/jaxws/client/AddEmployeeResponse.java new file mode 100644 index 0000000000..8d274942b5 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/AddEmployeeResponse.java @@ -0,0 +1,62 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for addEmployeeResponse complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="addEmployeeResponse">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="return" type="{http://bottomup.server.jaxws.baeldung.com/}employee" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "addEmployeeResponse", propOrder = { + "_return" +}) +public class AddEmployeeResponse { + + @XmlElement(name = "return") + protected Employee _return; + + /** + * Gets the value of the return property. + * + * @return + * possible object is + * {@link Employee } + * + */ + public Employee getReturn() { + return _return; + } + + /** + * Sets the value of the return property. + * + * @param value + * allowed object is + * {@link Employee } + * + */ + public void setReturn(Employee value) { + this._return = value; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/CountEmployees.java b/jee7/src/main/java/com/baeldung/jaxws/client/CountEmployees.java new file mode 100644 index 0000000000..d87ed31634 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/CountEmployees.java @@ -0,0 +1,32 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for countEmployees complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="countEmployees">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "countEmployees") +public class CountEmployees { + + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/CountEmployeesResponse.java b/jee7/src/main/java/com/baeldung/jaxws/client/CountEmployeesResponse.java new file mode 100644 index 0000000000..2d71ddd0b5 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/CountEmployeesResponse.java @@ -0,0 +1,54 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for countEmployeesResponse complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="countEmployeesResponse">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="return" type="{http://www.w3.org/2001/XMLSchema}int"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "countEmployeesResponse", propOrder = { + "_return" +}) +public class CountEmployeesResponse { + + @XmlElement(name = "return") + protected int _return; + + /** + * Gets the value of the return property. + * + */ + public int getReturn() { + return _return; + } + + /** + * Sets the value of the return property. + * + */ + public void setReturn(int value) { + this._return = value; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/DeleteEmployee.java b/jee7/src/main/java/com/baeldung/jaxws/client/DeleteEmployee.java new file mode 100644 index 0000000000..0bd3a783a7 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/DeleteEmployee.java @@ -0,0 +1,52 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for deleteEmployee complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="deleteEmployee">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="arg0" type="{http://www.w3.org/2001/XMLSchema}int"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "deleteEmployee", propOrder = { + "arg0" +}) +public class DeleteEmployee { + + protected int arg0; + + /** + * Gets the value of the arg0 property. + * + */ + public int getArg0() { + return arg0; + } + + /** + * Sets the value of the arg0 property. + * + */ + public void setArg0(int value) { + this.arg0 = value; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/DeleteEmployeeResponse.java b/jee7/src/main/java/com/baeldung/jaxws/client/DeleteEmployeeResponse.java new file mode 100644 index 0000000000..216f766640 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/DeleteEmployeeResponse.java @@ -0,0 +1,54 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for deleteEmployeeResponse complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="deleteEmployeeResponse">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="return" type="{http://www.w3.org/2001/XMLSchema}boolean"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "deleteEmployeeResponse", propOrder = { + "_return" +}) +public class DeleteEmployeeResponse { + + @XmlElement(name = "return") + protected boolean _return; + + /** + * Gets the value of the return property. + * + */ + public boolean isReturn() { + return _return; + } + + /** + * Sets the value of the return property. + * + */ + public void setReturn(boolean value) { + this._return = value; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/Employee.java b/jee7/src/main/java/com/baeldung/jaxws/client/Employee.java new file mode 100644 index 0000000000..8a89a5b97c --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/Employee.java @@ -0,0 +1,79 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for employee complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="employee">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="firstName" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="id" type="{http://www.w3.org/2001/XMLSchema}int"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "employee", propOrder = { + "firstName", + "id" +}) +public class Employee { + + protected String firstName; + protected int id; + + /** + * Gets the value of the firstName property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getFirstName() { + return firstName; + } + + /** + * Sets the value of the firstName property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setFirstName(String value) { + this.firstName = value; + } + + /** + * Gets the value of the id property. + * + */ + public int getId() { + return id; + } + + /** + * Sets the value of the id property. + * + */ + public void setId(int value) { + this.id = value; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeAlreadyExists.java b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeAlreadyExists.java new file mode 100644 index 0000000000..3c9c726552 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeAlreadyExists.java @@ -0,0 +1,60 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for EmployeeAlreadyExists complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="EmployeeAlreadyExists">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="message" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "EmployeeAlreadyExists", propOrder = { + "message" +}) +public class EmployeeAlreadyExists { + + protected String message; + + /** + * Gets the value of the message property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getMessage() { + return message; + } + + /** + * Sets the value of the message property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setMessage(String value) { + this.message = value; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeAlreadyExists_Exception.java b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeAlreadyExists_Exception.java new file mode 100644 index 0000000000..4d6a867b0d --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeAlreadyExists_Exception.java @@ -0,0 +1,54 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.ws.WebFault; + + +/** + * This class was generated by the JAX-WS RI. + * JAX-WS RI 2.2.9-b130926.1035 + * Generated source version: 2.2 + * + */ +@WebFault(name = "EmployeeAlreadyExists", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/") +public class EmployeeAlreadyExists_Exception + extends Exception +{ + + /** + * Java type that goes as soapenv:Fault detail element. + * + */ + private EmployeeAlreadyExists faultInfo; + + /** + * + * @param faultInfo + * @param message + */ + public EmployeeAlreadyExists_Exception(String message, EmployeeAlreadyExists faultInfo) { + super(message); + this.faultInfo = faultInfo; + } + + /** + * + * @param faultInfo + * @param cause + * @param message + */ + public EmployeeAlreadyExists_Exception(String message, EmployeeAlreadyExists faultInfo, Throwable cause) { + super(message, cause); + this.faultInfo = faultInfo; + } + + /** + * + * @return + * returns fault bean: com.baeldung.jaxws.client.EmployeeAlreadyExists + */ + public EmployeeAlreadyExists getFaultInfo() { + return faultInfo; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeNotFound.java b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeNotFound.java new file mode 100644 index 0000000000..ba3be93571 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeNotFound.java @@ -0,0 +1,60 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for EmployeeNotFound complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="EmployeeNotFound">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="message" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "EmployeeNotFound", propOrder = { + "message" +}) +public class EmployeeNotFound { + + protected String message; + + /** + * Gets the value of the message property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getMessage() { + return message; + } + + /** + * Sets the value of the message property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setMessage(String value) { + this.message = value; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeNotFound_Exception.java b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeNotFound_Exception.java new file mode 100644 index 0000000000..957e59fdc9 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeNotFound_Exception.java @@ -0,0 +1,54 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.ws.WebFault; + + +/** + * This class was generated by the JAX-WS RI. + * JAX-WS RI 2.2.9-b130926.1035 + * Generated source version: 2.2 + * + */ +@WebFault(name = "EmployeeNotFound", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/") +public class EmployeeNotFound_Exception + extends Exception +{ + + /** + * Java type that goes as soapenv:Fault detail element. + * + */ + private EmployeeNotFound faultInfo; + + /** + * + * @param faultInfo + * @param message + */ + public EmployeeNotFound_Exception(String message, EmployeeNotFound faultInfo) { + super(message); + this.faultInfo = faultInfo; + } + + /** + * + * @param faultInfo + * @param cause + * @param message + */ + public EmployeeNotFound_Exception(String message, EmployeeNotFound faultInfo, Throwable cause) { + super(message, cause); + this.faultInfo = faultInfo; + } + + /** + * + * @return + * returns fault bean: com.baeldung.jaxws.client.EmployeeNotFound + */ + public EmployeeNotFound getFaultInfo() { + return faultInfo; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeService.java b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeService.java new file mode 100644 index 0000000000..a2c007c5a0 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeService.java @@ -0,0 +1,139 @@ + +package com.baeldung.jaxws.client; + +import java.util.List; +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.jws.WebService; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.ws.Action; +import javax.xml.ws.FaultAction; +import javax.xml.ws.RequestWrapper; +import javax.xml.ws.ResponseWrapper; + + +/** + * This class was generated by the JAX-WS RI. + * JAX-WS RI 2.2.9-b130926.1035 + * Generated source version: 2.2 + * + */ +@WebService(name = "EmployeeService", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/") +@XmlSeeAlso({ + ObjectFactory.class +}) +public interface EmployeeService { + + + /** + * + * @param arg0 + * @return + * returns com.baeldung.jaxws.client.Employee + * @throws EmployeeNotFound_Exception + */ + @WebMethod + @WebResult(targetNamespace = "") + @RequestWrapper(localName = "getEmployee", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", className = "com.baeldung.jaxws.client.GetEmployee") + @ResponseWrapper(localName = "getEmployeeResponse", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", className = "com.baeldung.jaxws.client.GetEmployeeResponse") + @Action(input = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/getEmployeeRequest", output = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/getEmployeeResponse", fault = { + @FaultAction(className = EmployeeNotFound_Exception.class, value = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/getEmployee/Fault/EmployeeNotFound") + }) + public Employee getEmployee( + @WebParam(name = "arg0", targetNamespace = "") + int arg0) + throws EmployeeNotFound_Exception + ; + + /** + * + * @param arg1 + * @param arg0 + * @return + * returns com.baeldung.jaxws.client.Employee + * @throws EmployeeNotFound_Exception + */ + @WebMethod + @WebResult(targetNamespace = "") + @RequestWrapper(localName = "updateEmployee", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", className = "com.baeldung.jaxws.client.UpdateEmployee") + @ResponseWrapper(localName = "updateEmployeeResponse", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", className = "com.baeldung.jaxws.client.UpdateEmployeeResponse") + @Action(input = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/updateEmployeeRequest", output = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/updateEmployeeResponse", fault = { + @FaultAction(className = EmployeeNotFound_Exception.class, value = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/updateEmployee/Fault/EmployeeNotFound") + }) + public Employee updateEmployee( + @WebParam(name = "arg0", targetNamespace = "") + int arg0, + @WebParam(name = "arg1", targetNamespace = "") + String arg1) + throws EmployeeNotFound_Exception + ; + + /** + * + * @return + * returns java.util.List + */ + @WebMethod + @WebResult(targetNamespace = "") + @RequestWrapper(localName = "getAllEmployees", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", className = "com.baeldung.jaxws.client.GetAllEmployees") + @ResponseWrapper(localName = "getAllEmployeesResponse", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", className = "com.baeldung.jaxws.client.GetAllEmployeesResponse") + @Action(input = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/getAllEmployeesRequest", output = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/getAllEmployeesResponse") + public List getAllEmployees(); + + /** + * + * @param arg0 + * @return + * returns boolean + * @throws EmployeeNotFound_Exception + */ + @WebMethod + @WebResult(targetNamespace = "") + @RequestWrapper(localName = "deleteEmployee", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", className = "com.baeldung.jaxws.client.DeleteEmployee") + @ResponseWrapper(localName = "deleteEmployeeResponse", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", className = "com.baeldung.jaxws.client.DeleteEmployeeResponse") + @Action(input = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/deleteEmployeeRequest", output = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/deleteEmployeeResponse", fault = { + @FaultAction(className = EmployeeNotFound_Exception.class, value = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/deleteEmployee/Fault/EmployeeNotFound") + }) + public boolean deleteEmployee( + @WebParam(name = "arg0", targetNamespace = "") + int arg0) + throws EmployeeNotFound_Exception + ; + + /** + * + * @param arg1 + * @param arg0 + * @return + * returns com.baeldung.jaxws.client.Employee + * @throws EmployeeAlreadyExists_Exception + */ + @WebMethod + @WebResult(targetNamespace = "") + @RequestWrapper(localName = "addEmployee", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", className = "com.baeldung.jaxws.client.AddEmployee") + @ResponseWrapper(localName = "addEmployeeResponse", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", className = "com.baeldung.jaxws.client.AddEmployeeResponse") + @Action(input = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/addEmployeeRequest", output = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/addEmployeeResponse", fault = { + @FaultAction(className = EmployeeAlreadyExists_Exception.class, value = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/addEmployee/Fault/EmployeeAlreadyExists") + }) + public Employee addEmployee( + @WebParam(name = "arg0", targetNamespace = "") + int arg0, + @WebParam(name = "arg1", targetNamespace = "") + String arg1) + throws EmployeeAlreadyExists_Exception + ; + + /** + * + * @return + * returns int + */ + @WebMethod + @WebResult(targetNamespace = "") + @RequestWrapper(localName = "countEmployees", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", className = "com.baeldung.jaxws.client.CountEmployees") + @ResponseWrapper(localName = "countEmployeesResponse", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", className = "com.baeldung.jaxws.client.CountEmployeesResponse") + @Action(input = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/countEmployeesRequest", output = "http://bottomup.server.jaxws.baeldung.com/EmployeeService/countEmployeesResponse") + public int countEmployees(); + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeServiceClient.java b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeServiceClient.java index 3d5450690a..d2d5111109 100644 --- a/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeServiceClient.java +++ b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeServiceClient.java @@ -1,25 +1,18 @@ package com.baeldung.jaxws.client; - -import com.baeldung.jaxws.server.bottomup.EmployeeService; - -import javax.xml.namespace.QName; -import javax.xml.ws.Service; import java.net.URL; +import java.util.List; public class EmployeeServiceClient { public static void main(String[] args) throws Exception { - URL url = new URL("http://localhost:8081/employeeservice?wsdl"); - QName qname = new QName("http://bottomup.server.jaxws.baeldung.com/", "EmployeeServiceImplService"); + URL url = new URL("http://localhost:8080/employeeservice?wsdl"); - Service service = Service.create(url, qname); + EmployeeService_Service employeeService_Service = new EmployeeService_Service(url); + EmployeeService employeeServiceProxy = employeeService_Service.getEmployeeServiceImplPort(); - EmployeeService employeeService = service.getPort(EmployeeService.class); - employeeService.countEmployees(); - - System.out.println(employeeService.countEmployees()); + List allEmployees = employeeServiceProxy.getAllEmployees(); } } \ No newline at end of file diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeService_Service.java b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeService_Service.java new file mode 100644 index 0000000000..b214f9cd90 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/EmployeeService_Service.java @@ -0,0 +1,94 @@ + +package com.baeldung.jaxws.client; + +import java.net.MalformedURLException; +import java.net.URL; +import javax.xml.namespace.QName; +import javax.xml.ws.Service; +import javax.xml.ws.WebEndpoint; +import javax.xml.ws.WebServiceClient; +import javax.xml.ws.WebServiceException; +import javax.xml.ws.WebServiceFeature; + + +/** + * This class was generated by the JAX-WS RI. + * JAX-WS RI 2.2.9-b130926.1035 + * Generated source version: 2.2 + * + */ +@WebServiceClient(name = "EmployeeService", targetNamespace = "http://bottomup.server.jaxws.baeldung.com/", wsdlLocation = "http://localhost:8080/employeeservice?wsdl") +public class EmployeeService_Service + extends Service +{ + + private final static URL EMPLOYEESERVICE_WSDL_LOCATION; + private final static WebServiceException EMPLOYEESERVICE_EXCEPTION; + private final static QName EMPLOYEESERVICE_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "EmployeeService"); + + static { + URL url = null; + WebServiceException e = null; + try { + url = new URL("http://localhost:8080/employeeservice?wsdl"); + } catch (MalformedURLException ex) { + e = new WebServiceException(ex); + } + EMPLOYEESERVICE_WSDL_LOCATION = url; + EMPLOYEESERVICE_EXCEPTION = e; + } + + public EmployeeService_Service() { + super(__getWsdlLocation(), EMPLOYEESERVICE_QNAME); + } + + public EmployeeService_Service(WebServiceFeature... features) { + super(__getWsdlLocation(), EMPLOYEESERVICE_QNAME, features); + } + + public EmployeeService_Service(URL wsdlLocation) { + super(wsdlLocation, EMPLOYEESERVICE_QNAME); + } + + public EmployeeService_Service(URL wsdlLocation, WebServiceFeature... features) { + super(wsdlLocation, EMPLOYEESERVICE_QNAME, features); + } + + public EmployeeService_Service(URL wsdlLocation, QName serviceName) { + super(wsdlLocation, serviceName); + } + + public EmployeeService_Service(URL wsdlLocation, QName serviceName, WebServiceFeature... features) { + super(wsdlLocation, serviceName, features); + } + + /** + * + * @return + * returns EmployeeService + */ + @WebEndpoint(name = "EmployeeServiceImplPort") + public EmployeeService getEmployeeServiceImplPort() { + return super.getPort(new QName("http://bottomup.server.jaxws.baeldung.com/", "EmployeeServiceImplPort"), EmployeeService.class); + } + + /** + * + * @param features + * A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the features parameter will have their default values. + * @return + * returns EmployeeService + */ + @WebEndpoint(name = "EmployeeServiceImplPort") + public EmployeeService getEmployeeServiceImplPort(WebServiceFeature... features) { + return super.getPort(new QName("http://bottomup.server.jaxws.baeldung.com/", "EmployeeServiceImplPort"), EmployeeService.class, features); + } + + private static URL __getWsdlLocation() { + if (EMPLOYEESERVICE_EXCEPTION!= null) { + throw EMPLOYEESERVICE_EXCEPTION; + } + return EMPLOYEESERVICE_WSDL_LOCATION; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/GetAllEmployees.java b/jee7/src/main/java/com/baeldung/jaxws/client/GetAllEmployees.java new file mode 100644 index 0000000000..137cf06704 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/GetAllEmployees.java @@ -0,0 +1,32 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for getAllEmployees complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="getAllEmployees">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "getAllEmployees") +public class GetAllEmployees { + + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/GetAllEmployeesResponse.java b/jee7/src/main/java/com/baeldung/jaxws/client/GetAllEmployeesResponse.java new file mode 100644 index 0000000000..be3d502222 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/GetAllEmployeesResponse.java @@ -0,0 +1,69 @@ + +package com.baeldung.jaxws.client; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for getAllEmployeesResponse complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="getAllEmployeesResponse">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="return" type="{http://bottomup.server.jaxws.baeldung.com/}employee" maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "getAllEmployeesResponse", propOrder = { + "_return" +}) +public class GetAllEmployeesResponse { + + @XmlElement(name = "return") + protected List _return; + + /** + * Gets the value of the return property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the return property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getReturn().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Employee } + * + * + */ + public List getReturn() { + if (_return == null) { + _return = new ArrayList(); + } + return this._return; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/GetEmployee.java b/jee7/src/main/java/com/baeldung/jaxws/client/GetEmployee.java new file mode 100644 index 0000000000..333073be69 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/GetEmployee.java @@ -0,0 +1,52 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for getEmployee complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="getEmployee">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="arg0" type="{http://www.w3.org/2001/XMLSchema}int"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "getEmployee", propOrder = { + "arg0" +}) +public class GetEmployee { + + protected int arg0; + + /** + * Gets the value of the arg0 property. + * + */ + public int getArg0() { + return arg0; + } + + /** + * Sets the value of the arg0 property. + * + */ + public void setArg0(int value) { + this.arg0 = value; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/GetEmployeeResponse.java b/jee7/src/main/java/com/baeldung/jaxws/client/GetEmployeeResponse.java new file mode 100644 index 0000000000..6926c8a6f6 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/GetEmployeeResponse.java @@ -0,0 +1,62 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for getEmployeeResponse complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="getEmployeeResponse">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="return" type="{http://bottomup.server.jaxws.baeldung.com/}employee" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "getEmployeeResponse", propOrder = { + "_return" +}) +public class GetEmployeeResponse { + + @XmlElement(name = "return") + protected Employee _return; + + /** + * Gets the value of the return property. + * + * @return + * possible object is + * {@link Employee } + * + */ + public Employee getReturn() { + return _return; + } + + /** + * Sets the value of the return property. + * + * @param value + * allowed object is + * {@link Employee } + * + */ + public void setReturn(Employee value) { + this._return = value; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/ObjectFactory.java b/jee7/src/main/java/com/baeldung/jaxws/client/ObjectFactory.java new file mode 100644 index 0000000000..a16ae2567b --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/ObjectFactory.java @@ -0,0 +1,295 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.namespace.QName; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the com.baeldung.jaxws.client package. + *

An ObjectFactory allows you to programatically + * construct new instances of the Java representation + * for XML content. The Java representation of XML + * content can consist of schema derived interfaces + * and classes representing the binding of schema + * type definitions, element declarations and model + * groups. Factory methods for each of these are + * provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + private final static QName _AddEmployeeResponse_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "addEmployeeResponse"); + private final static QName _EmployeeAlreadyExists_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "EmployeeAlreadyExists"); + private final static QName _GetEmployeeResponse_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "getEmployeeResponse"); + private final static QName _EmployeeNotFound_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "EmployeeNotFound"); + private final static QName _CountEmployees_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "countEmployees"); + private final static QName _UpdateEmployee_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "updateEmployee"); + private final static QName _DeleteEmployeeResponse_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "deleteEmployeeResponse"); + private final static QName _GetAllEmployeesResponse_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "getAllEmployeesResponse"); + private final static QName _DeleteEmployee_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "deleteEmployee"); + private final static QName _UpdateEmployeeResponse_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "updateEmployeeResponse"); + private final static QName _AddEmployee_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "addEmployee"); + private final static QName _GetAllEmployees_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "getAllEmployees"); + private final static QName _CountEmployeesResponse_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "countEmployeesResponse"); + private final static QName _GetEmployee_QNAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "getEmployee"); + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.baeldung.jaxws.client + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link EmployeeNotFound } + * + */ + public EmployeeNotFound createEmployeeNotFound() { + return new EmployeeNotFound(); + } + + /** + * Create an instance of {@link CountEmployees } + * + */ + public CountEmployees createCountEmployees() { + return new CountEmployees(); + } + + /** + * Create an instance of {@link AddEmployeeResponse } + * + */ + public AddEmployeeResponse createAddEmployeeResponse() { + return new AddEmployeeResponse(); + } + + /** + * Create an instance of {@link EmployeeAlreadyExists } + * + */ + public EmployeeAlreadyExists createEmployeeAlreadyExists() { + return new EmployeeAlreadyExists(); + } + + /** + * Create an instance of {@link GetEmployeeResponse } + * + */ + public GetEmployeeResponse createGetEmployeeResponse() { + return new GetEmployeeResponse(); + } + + /** + * Create an instance of {@link DeleteEmployeeResponse } + * + */ + public DeleteEmployeeResponse createDeleteEmployeeResponse() { + return new DeleteEmployeeResponse(); + } + + /** + * Create an instance of {@link GetAllEmployeesResponse } + * + */ + public GetAllEmployeesResponse createGetAllEmployeesResponse() { + return new GetAllEmployeesResponse(); + } + + /** + * Create an instance of {@link UpdateEmployee } + * + */ + public UpdateEmployee createUpdateEmployee() { + return new UpdateEmployee(); + } + + /** + * Create an instance of {@link CountEmployeesResponse } + * + */ + public CountEmployeesResponse createCountEmployeesResponse() { + return new CountEmployeesResponse(); + } + + /** + * Create an instance of {@link GetEmployee } + * + */ + public GetEmployee createGetEmployee() { + return new GetEmployee(); + } + + /** + * Create an instance of {@link DeleteEmployee } + * + */ + public DeleteEmployee createDeleteEmployee() { + return new DeleteEmployee(); + } + + /** + * Create an instance of {@link UpdateEmployeeResponse } + * + */ + public UpdateEmployeeResponse createUpdateEmployeeResponse() { + return new UpdateEmployeeResponse(); + } + + /** + * Create an instance of {@link AddEmployee } + * + */ + public AddEmployee createAddEmployee() { + return new AddEmployee(); + } + + /** + * Create an instance of {@link GetAllEmployees } + * + */ + public GetAllEmployees createGetAllEmployees() { + return new GetAllEmployees(); + } + + /** + * Create an instance of {@link Employee } + * + */ + public Employee createEmployee() { + return new Employee(); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link AddEmployeeResponse }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "addEmployeeResponse") + public JAXBElement createAddEmployeeResponse(AddEmployeeResponse value) { + return new JAXBElement(_AddEmployeeResponse_QNAME, AddEmployeeResponse.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link EmployeeAlreadyExists }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "EmployeeAlreadyExists") + public JAXBElement createEmployeeAlreadyExists(EmployeeAlreadyExists value) { + return new JAXBElement(_EmployeeAlreadyExists_QNAME, EmployeeAlreadyExists.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link GetEmployeeResponse }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "getEmployeeResponse") + public JAXBElement createGetEmployeeResponse(GetEmployeeResponse value) { + return new JAXBElement(_GetEmployeeResponse_QNAME, GetEmployeeResponse.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link EmployeeNotFound }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "EmployeeNotFound") + public JAXBElement createEmployeeNotFound(EmployeeNotFound value) { + return new JAXBElement(_EmployeeNotFound_QNAME, EmployeeNotFound.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link CountEmployees }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "countEmployees") + public JAXBElement createCountEmployees(CountEmployees value) { + return new JAXBElement(_CountEmployees_QNAME, CountEmployees.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link UpdateEmployee }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "updateEmployee") + public JAXBElement createUpdateEmployee(UpdateEmployee value) { + return new JAXBElement(_UpdateEmployee_QNAME, UpdateEmployee.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link DeleteEmployeeResponse }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "deleteEmployeeResponse") + public JAXBElement createDeleteEmployeeResponse(DeleteEmployeeResponse value) { + return new JAXBElement(_DeleteEmployeeResponse_QNAME, DeleteEmployeeResponse.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link GetAllEmployeesResponse }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "getAllEmployeesResponse") + public JAXBElement createGetAllEmployeesResponse(GetAllEmployeesResponse value) { + return new JAXBElement(_GetAllEmployeesResponse_QNAME, GetAllEmployeesResponse.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link DeleteEmployee }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "deleteEmployee") + public JAXBElement createDeleteEmployee(DeleteEmployee value) { + return new JAXBElement(_DeleteEmployee_QNAME, DeleteEmployee.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link UpdateEmployeeResponse }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "updateEmployeeResponse") + public JAXBElement createUpdateEmployeeResponse(UpdateEmployeeResponse value) { + return new JAXBElement(_UpdateEmployeeResponse_QNAME, UpdateEmployeeResponse.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link AddEmployee }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "addEmployee") + public JAXBElement createAddEmployee(AddEmployee value) { + return new JAXBElement(_AddEmployee_QNAME, AddEmployee.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link GetAllEmployees }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "getAllEmployees") + public JAXBElement createGetAllEmployees(GetAllEmployees value) { + return new JAXBElement(_GetAllEmployees_QNAME, GetAllEmployees.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link CountEmployeesResponse }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "countEmployeesResponse") + public JAXBElement createCountEmployeesResponse(CountEmployeesResponse value) { + return new JAXBElement(_CountEmployeesResponse_QNAME, CountEmployeesResponse.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link GetEmployee }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://bottomup.server.jaxws.baeldung.com/", name = "getEmployee") + public JAXBElement createGetEmployee(GetEmployee value) { + return new JAXBElement(_GetEmployee_QNAME, GetEmployee.class, null, value); + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/UpdateEmployee.java b/jee7/src/main/java/com/baeldung/jaxws/client/UpdateEmployee.java new file mode 100644 index 0000000000..d1850428e8 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/UpdateEmployee.java @@ -0,0 +1,79 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for updateEmployee complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="updateEmployee">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="arg0" type="{http://www.w3.org/2001/XMLSchema}int"/>
+ *         <element name="arg1" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "updateEmployee", propOrder = { + "arg0", + "arg1" +}) +public class UpdateEmployee { + + protected int arg0; + protected String arg1; + + /** + * Gets the value of the arg0 property. + * + */ + public int getArg0() { + return arg0; + } + + /** + * Sets the value of the arg0 property. + * + */ + public void setArg0(int value) { + this.arg0 = value; + } + + /** + * Gets the value of the arg1 property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getArg1() { + return arg1; + } + + /** + * Sets the value of the arg1 property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setArg1(String value) { + this.arg1 = value; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/UpdateEmployeeResponse.java b/jee7/src/main/java/com/baeldung/jaxws/client/UpdateEmployeeResponse.java new file mode 100644 index 0000000000..56119c6546 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/UpdateEmployeeResponse.java @@ -0,0 +1,62 @@ + +package com.baeldung.jaxws.client; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for updateEmployeeResponse complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="updateEmployeeResponse">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="return" type="{http://bottomup.server.jaxws.baeldung.com/}employee" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "updateEmployeeResponse", propOrder = { + "_return" +}) +public class UpdateEmployeeResponse { + + @XmlElement(name = "return") + protected Employee _return; + + /** + * Gets the value of the return property. + * + * @return + * possible object is + * {@link Employee } + * + */ + public Employee getReturn() { + return _return; + } + + /** + * Sets the value of the return property. + * + * @param value + * allowed object is + * {@link Employee } + * + */ + public void setReturn(Employee value) { + this._return = value; + } + +} diff --git a/jee7/src/main/java/com/baeldung/jaxws/client/package-info.java b/jee7/src/main/java/com/baeldung/jaxws/client/package-info.java new file mode 100644 index 0000000000..c264b876f9 --- /dev/null +++ b/jee7/src/main/java/com/baeldung/jaxws/client/package-info.java @@ -0,0 +1,2 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://bottomup.server.jaxws.baeldung.com/") +package com.baeldung.jaxws.client; diff --git a/jee7/src/test/java/com/baeldung/jaxws/EmployeeServiceLiveTest.java b/jee7/src/test/java/com/baeldung/jaxws/EmployeeServiceLiveTest.java index 4429703468..5663db712e 100644 --- a/jee7/src/test/java/com/baeldung/jaxws/EmployeeServiceLiveTest.java +++ b/jee7/src/test/java/com/baeldung/jaxws/EmployeeServiceLiveTest.java @@ -1,4 +1,4 @@ -/*package com.baeldung.jaxws; +package com.baeldung.jaxws; import static org.junit.Assert.assertEquals; @@ -7,7 +7,6 @@ import java.net.URL; import java.util.List; import javax.xml.namespace.QName; -import javax.xml.ws.Service; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; @@ -19,17 +18,18 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import com.baeldung.jaxws.exception.EmployeeAlreadyExists; -import com.baeldung.jaxws.exception.EmployeeNotFound; -import com.baeldung.jaxws.model.Employee; -import com.baeldung.jaxws.repository.EmployeeRepository; +import com.baeldung.jaxws.client.Employee; +import com.baeldung.jaxws.client.EmployeeAlreadyExists_Exception; +import com.baeldung.jaxws.client.EmployeeNotFound_Exception; +import com.baeldung.jaxws.client.EmployeeService; +import com.baeldung.jaxws.client.EmployeeService_Service; @RunWith(Arquillian.class) public class EmployeeServiceLiveTest { private static final String APP_NAME = "jee7"; private static final String WSDL_PATH = "EmployeeService?wsdl"; - private static QName SERVICE_NAME = new QName("http://jaxws.baeldung.com/", "EmployeeService"); + private static QName SERVICE_NAME = new QName("http://bottomup.server.jaxws.baeldung.com/", "EmployeeService"); private static URL wsdlUrl; @ArquillianResource @@ -39,8 +39,12 @@ public class EmployeeServiceLiveTest { @Deployment(testable = false) public static WebArchive createDeployment() { - return ShrinkWrap.create(WebArchive.class, APP_NAME + ".war").addPackage(EmployeeService.class.getPackage()).addPackage(Employee.class.getPackage()).addPackage(EmployeeNotFound.class.getPackage()).addPackage(EmployeeRepository.class.getPackage()) - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + return ShrinkWrap.create(WebArchive.class, APP_NAME + ".war") + .addPackage(com.baeldung.jaxws.server.bottomup.EmployeeService.class.getPackage()) + .addPackage(com.baeldung.jaxws.server.bottomup.model.Employee.class.getPackage()) + .addPackage(com.baeldung.jaxws.server.bottomup.exception.EmployeeNotFound.class.getPackage()) + .addPackage(com.baeldung.jaxws.server.repository.EmployeeRepository.class.getPackage()) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); } @Before @@ -51,8 +55,8 @@ public class EmployeeServiceLiveTest { e.printStackTrace(); } - Service service = Service.create(wsdlUrl, SERVICE_NAME); - employeeServiceProxy = service.getPort(EmployeeService.class); + EmployeeService_Service employeeService_Service = new EmployeeService_Service(wsdlUrl); + employeeServiceProxy = employeeService_Service.getEmployeeServiceImplPort(); } @Test @@ -63,49 +67,48 @@ public class EmployeeServiceLiveTest { } @Test - public void givenEmployees_whenGetAvailableEmployee_thenCorrectEmployeeReturned() throws EmployeeNotFound { + public void givenEmployees_whenGetAvailableEmployee_thenCorrectEmployeeReturned() throws EmployeeNotFound_Exception { Employee employee = employeeServiceProxy.getEmployee(2); assertEquals(employee.getFirstName(), "Jack"); } - @Test(expected = EmployeeNotFound.class) - public void givenEmployees_whenGetNonAvailableEmployee_thenEmployeeNotFoundException() throws EmployeeNotFound { + @Test(expected = EmployeeNotFound_Exception.class) + public void givenEmployees_whenGetNonAvailableEmployee_thenEmployeeNotFoundException() throws EmployeeNotFound_Exception { employeeServiceProxy.getEmployee(20); } @Test - public void givenEmployees_whenAddNewEmployee_thenEmployeeCountIncreased() throws EmployeeAlreadyExists { + public void givenEmployees_whenAddNewEmployee_thenEmployeeCountIncreased() throws EmployeeAlreadyExists_Exception { int employeeCount = employeeServiceProxy.countEmployees(); employeeServiceProxy.addEmployee(4, "Anna"); assertEquals(employeeServiceProxy.countEmployees(), employeeCount + 1); } - @Test(expected = EmployeeAlreadyExists.class) - public void givenEmployees_whenAddAlreadyExistingEmployee_thenEmployeeAlreadyExistsException() throws EmployeeAlreadyExists { + @Test(expected = EmployeeAlreadyExists_Exception.class) + public void givenEmployees_whenAddAlreadyExistingEmployee_thenEmployeeAlreadyExistsException() throws EmployeeAlreadyExists_Exception { employeeServiceProxy.addEmployee(1, "Anna"); } @Test - public void givenEmployees_whenUpdateExistingEmployee_thenUpdatedEmployeeReturned() throws EmployeeNotFound { + public void givenEmployees_whenUpdateExistingEmployee_thenUpdatedEmployeeReturned() throws EmployeeNotFound_Exception { Employee updated = employeeServiceProxy.updateEmployee(1, "Joan"); assertEquals(updated.getFirstName(), "Joan"); } - @Test(expected = EmployeeNotFound.class) - public void givenEmployees_whenUpdateNonExistingEmployee_thenEmployeeNotFoundException() throws EmployeeNotFound { + @Test(expected = EmployeeNotFound_Exception.class) + public void givenEmployees_whenUpdateNonExistingEmployee_thenEmployeeNotFoundException() throws EmployeeNotFound_Exception { employeeServiceProxy.updateEmployee(20, "Joan"); } @Test - public void givenEmployees_whenDeleteExistingEmployee_thenSuccessReturned() throws EmployeeNotFound { + public void givenEmployees_whenDeleteExistingEmployee_thenSuccessReturned() throws EmployeeNotFound_Exception { boolean deleteEmployee = employeeServiceProxy.deleteEmployee(3); assertEquals(deleteEmployee, true); } - @Test(expected = EmployeeNotFound.class) - public void givenEmployee_whenDeleteNonExistingEmployee_thenEmployeeNotFoundException() throws EmployeeNotFound { + @Test(expected = EmployeeNotFound_Exception.class) + public void givenEmployee_whenDeleteNonExistingEmployee_thenEmployeeNotFoundException() throws EmployeeNotFound_Exception { employeeServiceProxy.deleteEmployee(20); } } -*/ \ No newline at end of file From 1c53e626419b61147779b72cec7a48ce0ffbddee Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Tue, 25 Apr 2017 09:44:59 +0200 Subject: [PATCH 13/17] Bael 845 transfer queue (#1727) * BAEL-845 tranferqueue article * BAEL-845 m to m example * BAEL-845 move code to test * BAEL-845 use tryTransfer * BAEL-845 proper if logic * BAEL-845 proper test * BAEL-845 robust test * BAEL-856 invert logic --- .../src/main/java/com/baeldung/transferqueue/Producer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/transferqueue/Producer.java b/core-java/src/main/java/com/baeldung/transferqueue/Producer.java index c9edc69e33..c6edc99bb5 100644 --- a/core-java/src/main/java/com/baeldung/transferqueue/Producer.java +++ b/core-java/src/main/java/com/baeldung/transferqueue/Producer.java @@ -22,11 +22,11 @@ public class Producer implements Runnable { try { System.out.println("Producer: " + name + " is waiting to transfer..."); boolean added = transferQueue.tryTransfer("A" + i, 4000, TimeUnit.MILLISECONDS); - if (!added) { - System.out.println("can not add an element due to the timeout"); - } else { + if (added) { numberOfProducedMessages.incrementAndGet(); System.out.println("Producer: " + name + " transferred element: A" + i); + } else { + System.out.println("can not add an element due to the timeout"); } } catch (InterruptedException e) { e.printStackTrace(); From d6e58f6efd01ed4816565892893c401e0fc51138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20G=C3=B3mez?= Date: Tue, 25 Apr 2017 01:50:02 -0600 Subject: [PATCH 14/17] Feature/kotlin interop (#1709) * Add project for hibernate immutable article Add Event entity Add hibernate configuration file Add hibernateutil for configuration Add test to match snippets from article * Update master * Add Kotlin Java Interoperability Add kotlin-reflect dependency * Fix test for customer Remove unused imports --- kotlin/pom.xml | 7 ++++ .../java/com/baeldung/java/ArrayExample.java | 24 ++++++++++++ .../main/java/com/baeldung/java/Customer.java | 24 ++++++++++++ .../kotlin/com/baeldung/kotlin/ArrayTest.kt | 39 +++++++++++++++++++ .../com/baeldung/kotlin/CustomerTest.kt | 23 +++++++++++ 5 files changed, 117 insertions(+) create mode 100644 kotlin/src/main/java/com/baeldung/java/ArrayExample.java create mode 100644 kotlin/src/main/java/com/baeldung/java/Customer.java create mode 100644 kotlin/src/test/kotlin/com/baeldung/kotlin/ArrayTest.kt create mode 100644 kotlin/src/test/kotlin/com/baeldung/kotlin/CustomerTest.kt diff --git a/kotlin/pom.xml b/kotlin/pom.xml index 07fb6863d4..89d9e2b292 100644 --- a/kotlin/pom.xml +++ b/kotlin/pom.xml @@ -26,6 +26,12 @@ ${junit.version} test
+ + org.jetbrains.kotlin + kotlin-reflect + ${kotlin-reflect.version} + test + @@ -93,6 +99,7 @@ 1.1.1 1.1.1 1.1.1 + 1.1.1 \ No newline at end of file diff --git a/kotlin/src/main/java/com/baeldung/java/ArrayExample.java b/kotlin/src/main/java/com/baeldung/java/ArrayExample.java new file mode 100644 index 0000000000..ef91db517b --- /dev/null +++ b/kotlin/src/main/java/com/baeldung/java/ArrayExample.java @@ -0,0 +1,24 @@ +package com.baeldung.java; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +public class ArrayExample { + + public int sumValues(int[] nums) { + int res = 0; + + for (int x:nums) { + res += x; + } + + return res; + } + + public void writeList() throws IOException { + File file = new File("E://file.txt"); + FileReader fr = new FileReader(file); + fr.close(); + } +} diff --git a/kotlin/src/main/java/com/baeldung/java/Customer.java b/kotlin/src/main/java/com/baeldung/java/Customer.java new file mode 100644 index 0000000000..0156bf7b44 --- /dev/null +++ b/kotlin/src/main/java/com/baeldung/java/Customer.java @@ -0,0 +1,24 @@ +package com.baeldung.java; + +public class Customer { + + private String firstName; + private String lastName; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + +} diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/ArrayTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/ArrayTest.kt new file mode 100644 index 0000000000..f7d1c53b13 --- /dev/null +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/ArrayTest.kt @@ -0,0 +1,39 @@ +package com.baeldung.kotlin + +import com.baeldung.java.ArrayExample +import com.baeldung.java.Customer +import org.junit.Test +import kotlin.test.assertEquals + +class ArrayTest { + + @Test + fun givenArray_whenValidateArrayType_thenComplete () { + val ex = ArrayExample() + val numArray = intArrayOf(1, 2, 3) + + assertEquals(ex.sumValues(numArray), 6) + } + + @Test + fun givenCustomer_whenGetSuperType_thenComplete() { + val instance = Customer::class + val supertypes = instance.supertypes + + assertEquals(supertypes[0].toString(), "kotlin.Any") + } + + @Test + fun givenCustomer_whenGetConstructor_thenComplete() { + val instance = Customer::class.java + val constructors = instance.constructors + + assertEquals(constructors.size, 1) + assertEquals(constructors[0].name, "com.baeldung.java.Customer") + } + + fun makeReadFile() { + val ax = ArrayExample() + ax.writeList() + } +} \ No newline at end of file diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/CustomerTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/CustomerTest.kt new file mode 100644 index 0000000000..6395dfcfed --- /dev/null +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/CustomerTest.kt @@ -0,0 +1,23 @@ +package com.baeldung.kotlin + +import com.baeldung.java.Customer +import org.junit.Test +import kotlin.test.assertEquals + +class CustomerTest { + + @Test + fun givenCustomer_whenNameAndLastNameAreAssigned_thenComplete() { + val customer = Customer() + + // Setter method is being called + customer.firstName = "Frodo" + customer.lastName = "Baggins" + + // Getter method is being called + assertEquals(customer.firstName, "Frodo") + assertEquals(customer.lastName, "Baggins") + } + +} + From 3751e272889fd0417573e4a923ecdb8d0aa61910 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Tue, 25 Apr 2017 14:18:07 +0200 Subject: [PATCH 15/17] Rename tests (#1728) --- .../jetty/{JettyTest.java => JettyIntegrationTest.java} | 2 +- ...adTest.java => GithubUserProfilePayloadIntegrationTest.java} | 2 +- .../{MemberStatusTest.java => MemberStatusIntegrationTest.java} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename libraries/src/test/java/com/baeldung/jetty/{JettyTest.java => JettyIntegrationTest.java} (98%) rename libraries/src/test/java/com/baeldung/serenity/{GithubUserProfilePayloadTest.java => GithubUserProfilePayloadIntegrationTest.java} (57%) rename libraries/src/test/java/com/baeldung/serenity/{MemberStatusTest.java => MemberStatusIntegrationTest.java} (98%) diff --git a/libraries/src/test/java/com/baeldung/jetty/JettyTest.java b/libraries/src/test/java/com/baeldung/jetty/JettyIntegrationTest.java similarity index 98% rename from libraries/src/test/java/com/baeldung/jetty/JettyTest.java rename to libraries/src/test/java/com/baeldung/jetty/JettyIntegrationTest.java index caf70f9af3..151bcc78a2 100644 --- a/libraries/src/test/java/com/baeldung/jetty/JettyTest.java +++ b/libraries/src/test/java/com/baeldung/jetty/JettyIntegrationTest.java @@ -14,7 +14,7 @@ import java.nio.charset.StandardCharsets; import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; -public class JettyTest { +public class JettyIntegrationTest { private JettyServer jettyServer; @Before diff --git a/libraries/src/test/java/com/baeldung/serenity/GithubUserProfilePayloadTest.java b/libraries/src/test/java/com/baeldung/serenity/GithubUserProfilePayloadIntegrationTest.java similarity index 57% rename from libraries/src/test/java/com/baeldung/serenity/GithubUserProfilePayloadTest.java rename to libraries/src/test/java/com/baeldung/serenity/GithubUserProfilePayloadIntegrationTest.java index f8a2d6fa3c..bfec945e63 100644 --- a/libraries/src/test/java/com/baeldung/serenity/GithubUserProfilePayloadTest.java +++ b/libraries/src/test/java/com/baeldung/serenity/GithubUserProfilePayloadIntegrationTest.java @@ -5,6 +5,6 @@ import net.serenitybdd.jbehave.SerenityStory; /** * @author aiet */ -public class GithubUserProfilePayloadTest extends SerenityStory { +public class GithubUserProfilePayloadIntegrationTest extends SerenityStory { } diff --git a/libraries/src/test/java/com/baeldung/serenity/MemberStatusTest.java b/libraries/src/test/java/com/baeldung/serenity/MemberStatusIntegrationTest.java similarity index 98% rename from libraries/src/test/java/com/baeldung/serenity/MemberStatusTest.java rename to libraries/src/test/java/com/baeldung/serenity/MemberStatusIntegrationTest.java index 5c90e90eb7..30faf92c6e 100644 --- a/libraries/src/test/java/com/baeldung/serenity/MemberStatusTest.java +++ b/libraries/src/test/java/com/baeldung/serenity/MemberStatusIntegrationTest.java @@ -14,7 +14,7 @@ import static com.baeldung.serenity.membership.MemberGrade.Gold; import static com.baeldung.serenity.membership.MemberGrade.Silver; @RunWith(SerenityRunner.class) -public class MemberStatusTest { +public class MemberStatusIntegrationTest { @Steps MemberStatusSteps memberSteps; From 129c751cb43e6ba246f77bfb02ca34f9536cd407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Soares?= Date: Tue, 25 Apr 2017 13:36:21 +0100 Subject: [PATCH 16/17] Simplify annotation usage (#1729) BAEL-742 --- .../main/java/com/baeldung/stripe/ChargeController.java | 5 ++--- .../src/main/java/com/baeldung/stripe/ChargeRequest.java | 8 ++------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/stripe/src/main/java/com/baeldung/stripe/ChargeController.java b/stripe/src/main/java/com/baeldung/stripe/ChargeController.java index cd3f057cd8..d609f48fb7 100644 --- a/stripe/src/main/java/com/baeldung/stripe/ChargeController.java +++ b/stripe/src/main/java/com/baeldung/stripe/ChargeController.java @@ -8,8 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RequestMapping; -import static org.springframework.web.bind.annotation.RequestMethod.POST; +import org.springframework.web.bind.annotation.PostMapping; @Log @Controller @@ -18,7 +17,7 @@ public class ChargeController { @Autowired StripeService paymentsService; - @RequestMapping(value = "/charge", method = POST) + @PostMapping("/charge") public String charge(ChargeRequest chargeRequest, Model model) throws StripeException { chargeRequest.setDescription("Example charge"); chargeRequest.setCurrency(Currency.EUR); diff --git a/stripe/src/main/java/com/baeldung/stripe/ChargeRequest.java b/stripe/src/main/java/com/baeldung/stripe/ChargeRequest.java index 76cdea7bb4..a5c056b659 100644 --- a/stripe/src/main/java/com/baeldung/stripe/ChargeRequest.java +++ b/stripe/src/main/java/com/baeldung/stripe/ChargeRequest.java @@ -1,12 +1,8 @@ package com.baeldung.stripe; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.Data; -@Getter -@Setter -@ToString(includeFieldNames = false) +@Data public class ChargeRequest { public enum Currency { From b0e15fcca07000e0e04d4c6bf76f80242a6aee88 Mon Sep 17 00:00:00 2001 From: Jesus Boadas Date: Tue, 25 Apr 2017 14:54:32 -0400 Subject: [PATCH 17/17] Guide to JDO (#1730) * Guide to JDO * Guide to JDO * Guide to JDO --- core-java/log4j.properties | 0 core-java/pom.xml | 95 ++++++++++++++---- .../java/com/baeldung/jdo/GuideToJDO.java | 83 ++++++++++++++++ .../main/java/com/baeldung/jdo/Product.java | 43 +++++++++ .../main/resources/META-INF/persistence.xml | 20 ++++ .../baeldung/java8/comparator/Employee.java | 4 +- .../java8/comparator/Java8ComparatorTest.java | 3 +- .../java/com/baeldung/jdo/GuideToJDOTest.java | 96 +++++++++++++++++++ 8 files changed, 323 insertions(+), 21 deletions(-) create mode 100644 core-java/log4j.properties create mode 100644 core-java/src/main/java/com/baeldung/jdo/GuideToJDO.java create mode 100644 core-java/src/main/java/com/baeldung/jdo/Product.java create mode 100644 core-java/src/main/resources/META-INF/persistence.xml create mode 100644 core-java/src/test/java/com/baeldung/jdo/GuideToJDOTest.java diff --git a/core-java/log4j.properties b/core-java/log4j.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/core-java/pom.xml b/core-java/pom.xml index b4741d5b80..4ee3efb297 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -165,19 +165,61 @@ org.javamoney moneta 1.1 -
+
+ + org.owasp.esapi + esapi + 2.1.0.1 + + + commons-logging + commons-logging + + + + + + org.datanucleus + javax.jdo + 3.2.0-m6 + + + org.datanucleus + datanucleus-core + 5.1.0-m1 + + + org.datanucleus + datanucleus-api-jdo + 5.1.0-m1 + + + org.datanucleus + datanucleus-rdbms + 5.1.0-m1 + + + org.datanucleus + datanucleus-maven-plugin + 5.0.2 + + + com.h2database + h2 + 1.4.194 + - - org.owasp.esapi - esapi - 2.1.0.1 - - - commons-logging - commons-logging - - - + + org.owasp.esapi + esapi + 2.1.0.1 + + + commons-logging + commons-logging + + + @@ -191,7 +233,6 @@ - org.apache.maven.plugins maven-compiler-plugin @@ -201,7 +242,6 @@ 1.8 - org.apache.maven.plugins maven-surefire-plugin @@ -214,7 +254,6 @@ true - org.apache.maven.plugins maven-dependency-plugin @@ -245,7 +284,6 @@ - org.apache.maven.plugins maven-assembly-plugin @@ -269,7 +307,6 @@ - org.apache.maven.plugins maven-shade-plugin @@ -290,7 +327,6 @@ - com.jolira onejar-maven-plugin @@ -307,7 +343,6 @@ - org.springframework.boot spring-boot-maven-plugin @@ -323,6 +358,28 @@ + + + + + org.datanucleus + datanucleus-maven-plugin + 5.0.2 + + JDO + ${basedir}/datanucleus.properties + ${basedir}/log4j.properties + true + + + + process-classes + + enhance + + + + diff --git a/core-java/src/main/java/com/baeldung/jdo/GuideToJDO.java b/core-java/src/main/java/com/baeldung/jdo/GuideToJDO.java new file mode 100644 index 0000000000..e17004c149 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/jdo/GuideToJDO.java @@ -0,0 +1,83 @@ +package com.baeldung.jdo; + +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Query; +import javax.jdo.Transaction; + +public class GuideToJDO { + + private static final Logger LOGGER = Logger.getLogger(GuideToJDO.class.getName()); + private Random rnd = new Random(); + + public static void main(String[] args) { + new GuideToJDO(); + } + + public GuideToJDO() { + CreateProducts(); + ListProducts(); + } + + public void CreateProducts() { + PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("Tutorial"); + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + Product product = new Product("Tablet", 80.0); + pm.makePersistent(product); + Product product2 = new Product("Phone", 20.0); + pm.makePersistent(product2); + Product product3 = new Product("Laptop", 200.0); + pm.makePersistent(product3); + for (int i = 0; i < 100; i++) { + String nam = "Product-" + i; + double price = rnd.nextDouble(); + Product productx = new Product(nam, price); + pm.makePersistent(productx); + } + tx.commit(); + } finally { + if (tx.isActive()) { + tx.rollback(); + } + pm.close(); + } + + } + + @SuppressWarnings("unchecked") + public void ListProducts() { + PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("Tutorial"); + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + + @SuppressWarnings("rawtypes") + Query q = pm.newQuery("SELECT FROM " + Product.class.getName() + " WHERE price < 1"); + List products = (List) q.execute(); + Iterator iter = products.iterator(); + while (iter.hasNext()) { + Product p = iter.next(); + LOGGER.log(Level.WARNING, "Product name: {0} - Price: {1}", new Object[] { p.name, p.price }); + } + + tx.commit(); + } finally { + if (tx.isActive()) { + tx.rollback(); + } + + pm.close(); + } + } +} diff --git a/core-java/src/main/java/com/baeldung/jdo/Product.java b/core-java/src/main/java/com/baeldung/jdo/Product.java new file mode 100644 index 0000000000..124428d671 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/jdo/Product.java @@ -0,0 +1,43 @@ +package com.baeldung.jdo; + +import javax.jdo.annotations.IdGeneratorStrategy; +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.Persistent; +import javax.jdo.annotations.PrimaryKey; + +@PersistenceCapable +public class Product { + + @PrimaryKey + @Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT) + long id; + String name = null; + Double price = 0.0; + + public Product() { + this.name = null; + this.price = 0.0; + } + + public Product(String name, Double price) { + this.name = name; + this.price = price; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } + +} \ No newline at end of file diff --git a/core-java/src/main/resources/META-INF/persistence.xml b/core-java/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000000..3966afdcda --- /dev/null +++ b/core-java/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + diff --git a/core-java/src/test/java/com/baeldung/java8/comparator/Employee.java b/core-java/src/test/java/com/baeldung/java8/comparator/Employee.java index bbc4e3e320..0ef10410a9 100644 --- a/core-java/src/test/java/com/baeldung/java8/comparator/Employee.java +++ b/core-java/src/test/java/com/baeldung/java8/comparator/Employee.java @@ -1,4 +1,5 @@ package com.baeldung.java8.comparator; +/* import lombok.AllArgsConstructor; import lombok.Data; @@ -15,9 +16,10 @@ public class Employee implements Comparable{ double salary; long mobile; - @Override public int compareTo(Employee argEmployee) { return name.compareTo(argEmployee.getName()); } + } +*/ \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/java8/comparator/Java8ComparatorTest.java b/core-java/src/test/java/com/baeldung/java8/comparator/Java8ComparatorTest.java index ebcbb7a3fc..8e1cfa67af 100644 --- a/core-java/src/test/java/com/baeldung/java8/comparator/Java8ComparatorTest.java +++ b/core-java/src/test/java/com/baeldung/java8/comparator/Java8ComparatorTest.java @@ -1,5 +1,5 @@ package com.baeldung.java8.comparator; - +/* import java.util.Arrays; import java.util.Comparator; @@ -165,3 +165,4 @@ public class Java8ComparatorTest { } +*/ \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/jdo/GuideToJDOTest.java b/core-java/src/test/java/com/baeldung/jdo/GuideToJDOTest.java new file mode 100644 index 0000000000..6ab7481118 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/jdo/GuideToJDOTest.java @@ -0,0 +1,96 @@ +package com.baeldung.jdo; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.util.Iterator; +import java.util.List; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Query; +import javax.jdo.Transaction; + +import org.junit.Test; + +public class GuideToJDOTest { + @Test + public void givenProduct_WhenNewThenPerformTransaction() { + PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("Tutorial"); + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + for (int i = 0; i < 100; i++){ + String nam = "Product-" + i; + double price = i; + Product productx = new Product(nam, price); + pm.makePersistent(productx); + } + tx.commit(); + } catch (Throwable thr) { + fail("Failed test : " + thr.getMessage()); + } finally { + if (tx.isActive()) { + tx.rollback(); + } + pm.close(); + } + + pmf.close(); + } + + @Test + public void givenProduct_WhenQueryThenExist() { + PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("Tutorial"); + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + Product product = new Product("Tablet", 80.0); + pm.makePersistent(product); + Product product2 = new Product("Phone", 20.0); + pm.makePersistent(product2); + Product product3 = new Product("Laptop", 200.0); + pm.makePersistent(product3); + tx.commit(); + } catch (Throwable thr) { + fail("Failed test : " + thr.getMessage()); + } finally { + if (tx.isActive()) { + tx.rollback(); + } + pm.close(); + } + + pmf.close(); + + PersistenceManagerFactory pmf2 = JDOHelper.getPersistenceManagerFactory("Tutorial"); + PersistenceManager pm2 = pmf2.getPersistenceManager(); + Transaction tx2 = pm2.currentTransaction(); + try { + tx2.begin(); + + @SuppressWarnings("rawtypes") + Query q = pm2.newQuery("SELECT FROM " + Product.class.getName() + " WHERE price == 200"); + @SuppressWarnings("unchecked") + List products = (List) q.execute(); + Iterator iter = products.iterator(); + while (iter.hasNext()) { + Product p = iter.next(); + assertEquals("Laptop", p.name); + } + + tx2.commit(); + } finally { + if (tx2.isActive()) { + tx2.rollback(); + } + + pm2.close(); + } + } + + +}