Skip to content

Commit 8b028a2

Browse files
Tian Baoqiangpivovarit
authored andcommitted
BAEL-758 (eugenp#1704)
* BAEL-758 * remove unnecessary pom configurations
1 parent 48c0e41 commit 8b028a2

13 files changed

Lines changed: 395 additions & 20 deletions

File tree

‎libraries/pom.xml‎

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@
4545
</excludes>
4646
</configuration>
4747
</plugin>
48+
<plugin>
49+
<groupId>net.serenity-bdd.maven.plugins</groupId>
50+
<artifactId>serenity-maven-plugin</artifactId>
51+
<version>${serenity.plugin.version}</version>
52+
<executions>
53+
<execution>
54+
<id>serenity-reports</id>
55+
<phase>post-integration-test</phase>
56+
<goals>
57+
<goal>aggregate</goal>
58+
</goals>
59+
</execution>
60+
</executions>
61+
</plugin>
4862
</plugins>
4963
</build>
5064

@@ -123,26 +137,6 @@
123137
<artifactId>commons-io</artifactId>
124138
<version>${commons.io.version}</version>
125139
</dependency>
126-
<dependency>
127-
<groupId>org.eclipse.jetty</groupId>
128-
<artifactId>jetty-server</artifactId>
129-
<version>${jetty.version}</version>
130-
</dependency>
131-
<dependency>
132-
<groupId>org.eclipse.jetty</groupId>
133-
<artifactId>jetty-servlet</artifactId>
134-
<version>${jetty.version}</version>
135-
</dependency>
136-
<dependency>
137-
<groupId>org.apache.httpcomponents</groupId>
138-
<artifactId>httpclient</artifactId>
139-
<version>${httpclient.version}</version>
140-
</dependency>
141-
<dependency>
142-
<groupId>commons-io</groupId>
143-
<artifactId>commons-io</artifactId>
144-
<version>${commons.io.version}</version>
145-
</dependency>
146140
<dependency>
147141
<groupId>org.apache.flink</groupId>
148142
<artifactId>flink-core</artifactId>
@@ -176,6 +170,36 @@
176170
<artifactId>commons-math3</artifactId>
177171
<version>3.6.1</version>
178172
</dependency>
173+
<dependency>
174+
<groupId>net.serenity-bdd</groupId>
175+
<artifactId>serenity-core</artifactId>
176+
<version>${serenity.version}</version>
177+
</dependency>
178+
<dependency>
179+
<groupId>net.serenity-bdd</groupId>
180+
<artifactId>serenity-junit</artifactId>
181+
<version>${serenity.version}</version>
182+
</dependency>
183+
<dependency>
184+
<groupId>net.serenity-bdd</groupId>
185+
<artifactId>serenity-jbehave</artifactId>
186+
<version>${serenity.jbehave.version}</version>
187+
</dependency>
188+
<dependency>
189+
<groupId>net.serenity-bdd</groupId>
190+
<artifactId>serenity-rest-assured</artifactId>
191+
<version>${serenity.version}</version>
192+
</dependency>
193+
<dependency>
194+
<groupId>net.serenity-bdd</groupId>
195+
<artifactId>serenity-jira-requirements-provider</artifactId>
196+
<version>${serenity.jira.version}</version>
197+
</dependency>
198+
<dependency>
199+
<groupId>com.fasterxml.jackson.core</groupId>
200+
<artifactId>jackson-databind</artifactId>
201+
<version>${jackson.version}</version>
202+
</dependency>
179203
</dependencies>
180204

181205
<properties>
@@ -195,6 +219,11 @@
195219
<httpclient.version>4.5.3</httpclient.version>
196220
<commons.io.version>2.5</commons.io.version>
197221
<flink.version>1.2.0</flink.version>
222+
<jackson.version>2.8.5</jackson.version>
223+
<serenity.version>1.2.5-rc.11</serenity.version>
224+
<serenity.jbehave.version>1.24.0</serenity.jbehave.version>
225+
<serenity.jira.version>1.1.3-rc.5</serenity.jira.version>
226+
<serenity.plugin.version>1.2.5-rc.6</serenity.plugin.version>
198227
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
199228
</properties>
200229

‎libraries/serenity.properties‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
jira.url=<jira-url>
2+
jira.project=<jira-project>
3+
jira.username=<jira-username>
4+
jira.password=<jira-password>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.serenity.github;
2+
3+
public class GitHubUser {
4+
5+
private String login;
6+
7+
public GitHubUser() {
8+
super();
9+
}
10+
11+
public String getLogin() {
12+
return login;
13+
}
14+
15+
public void setLogin(final String login) {
16+
this.login = login;
17+
}
18+
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.serenity.membership;
2+
3+
/**
4+
* @author aiet
5+
*/
6+
public enum Commodity {
7+
8+
MacBookPro(1499), GoProHero5(400);
9+
10+
public final int price;
11+
12+
Commodity(int price){
13+
this.price = price;
14+
}
15+
16+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.baeldung.serenity.membership;
2+
3+
import static com.baeldung.serenity.membership.MemberGrade.Bronze;
4+
import static com.baeldung.serenity.membership.MemberGrade.Gold;
5+
import static com.baeldung.serenity.membership.MemberGrade.Silver;
6+
7+
/**
8+
* @author aiet
9+
*/
10+
public class Member {
11+
12+
private int points;
13+
14+
private Member(int points) {
15+
if (points < 0) throw new IllegalArgumentException("points must not be negative!");
16+
this.points = points;
17+
18+
}
19+
20+
public static Member withInitialPoints(int initialPoints) {
21+
return new Member(initialPoints);
22+
}
23+
24+
public MemberGrade getGrade() {
25+
if (points < 1000) return Bronze;
26+
else if (points >= 1000 && points < 5000) return Silver;
27+
else return Gold;
28+
}
29+
30+
public void spend(int moneySpent) {
31+
points += moneySpent / 10;
32+
}
33+
34+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.serenity.membership;
2+
3+
/**
4+
* @author aiet
5+
*/
6+
public enum MemberGrade {
7+
8+
Bronze, Silver, Gold;
9+
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.serenity;
2+
3+
import net.serenitybdd.jbehave.SerenityStory;
4+
5+
/**
6+
* @author aiet
7+
*/
8+
public class GithubUserProfilePayloadTest extends SerenityStory {
9+
10+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.baeldung.serenity;
2+
3+
import com.baeldung.serenity.membership.MemberStatusSteps;
4+
import net.serenitybdd.junit.runners.SerenityRunner;
5+
import net.thucydides.core.annotations.Steps;
6+
import net.thucydides.core.annotations.Title;
7+
import org.junit.Ignore;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static com.baeldung.serenity.membership.Commodity.MacBookPro;
12+
import static com.baeldung.serenity.membership.MemberGrade.Bronze;
13+
import static com.baeldung.serenity.membership.MemberGrade.Gold;
14+
import static com.baeldung.serenity.membership.MemberGrade.Silver;
15+
16+
@RunWith(SerenityRunner.class)
17+
public class MemberStatusTest {
18+
19+
@Steps MemberStatusSteps memberSteps;
20+
21+
@Test
22+
public void membersShouldStartWithBronzeStatus() {
23+
memberSteps.aClientJoinsTheMemberProgram();
24+
memberSteps.theMemberShouldHaveAStatusOf(Bronze);
25+
}
26+
27+
@Test
28+
@Title("Members earn Silver grade after 1000 points ($10,000)")
29+
public void earnsSilverAfterSpends$10000() {
30+
memberSteps.aClientJoinsTheMemberProgram();
31+
memberSteps.theMemberSpends(10_000);
32+
memberSteps.theMemberShouldHaveAStatusOf(Silver);
33+
}
34+
35+
@Test
36+
@Title("Members with 2,000 points should earn Gold grade when added 3,000 points ($30,000)")
37+
public void memberWith2000PointsEarnsGoldAfterSpends$30000() {
38+
memberSteps.aMemberHasPointsOf(2000);
39+
memberSteps.theMemberSpends(30_000);
40+
memberSteps.theMemberShouldHaveAStatusOf(Gold);
41+
}
42+
43+
@Test
44+
@Title("Members with 50,000 points can exchange a MacBook Pro")
45+
public void memberWith50000PointsCanExchangeAMacbookpro(){
46+
memberSteps.aMemberHasPointsOf(50_000);
47+
memberSteps.aMemberExchangeA(MacBookPro);
48+
memberSteps.memberShouldHavePointsLeft();
49+
}
50+
51+
/**
52+
* This test should fail, comment out <code>@Ignore</code> to see how failed test can be reflected in Serenity report. <br/>
53+
* Remember to add <code>&lt;testFailureIgnore&gt;true&lt;/testFailureIgnore&gt;</code> under maven-surefire-plugin configuration.
54+
*/
55+
@Test
56+
@Ignore
57+
@Title("Members with 500 points should have a Gold status when added 4,000 points ($40,000)")
58+
public void memberWith500PointsEarnsGoldAfterSpends$40000(){
59+
memberSteps.aMemberHasPointsOf(500);
60+
memberSteps.theMemberSpends(40_000);
61+
memberSteps.theMemberShouldHaveAStatusOf(Gold);
62+
}
63+
64+
@Test
65+
@Ignore
66+
@Title("Members with 100 points would have a Gold status when added 10,000 points ($100,000)")
67+
public void memberWith100EarnsGoldAfterSpends$100000(){
68+
memberSteps.aMemberHasPointsOf(100);
69+
memberSteps.theMemberSpends(100_000);
70+
memberSteps.theMemberShouldHaveAStatusOf(Gold);
71+
}
72+
73+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.serenity.github;
2+
3+
import net.thucydides.core.annotations.Step;
4+
import org.hamcrest.Matchers;
5+
6+
import java.io.IOException;
7+
8+
import static net.serenitybdd.rest.SerenityRest.rest;
9+
import static net.serenitybdd.rest.SerenityRest.then;
10+
11+
/**
12+
* @author aiet
13+
*/
14+
public class GithubRestAssuredUserAPISteps {
15+
16+
private String api;
17+
18+
@Step("Given the github REST API for user profile")
19+
public void withUserProfileAPIEndpoint() {
20+
api = "https://api.github.com/users/{username}";
21+
}
22+
23+
@Step("When looking for {0} via the api")
24+
public void getProfileOfUser(String username) throws IOException {
25+
rest().get(api, username);
26+
}
27+
28+
@Step("Then there should be a login field with value {0} in payload of user {0}")
29+
public void profilePayloadShouldContainLoginValue(String username) {
30+
then().body("login", Matchers.equalTo(username));
31+
}
32+
33+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.baeldung.serenity.github;
2+
3+
import com.fasterxml.jackson.databind.DeserializationFeature;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import net.thucydides.core.annotations.Step;
6+
import org.apache.http.HttpResponse;
7+
import org.apache.http.client.methods.HttpGet;
8+
import org.apache.http.client.methods.HttpUriRequest;
9+
import org.apache.http.impl.client.HttpClientBuilder;
10+
import org.apache.http.util.EntityUtils;
11+
import org.hamcrest.Matchers;
12+
13+
import java.io.IOException;
14+
15+
import static org.hamcrest.MatcherAssert.assertThat;
16+
17+
/**
18+
* @author aiet
19+
*/
20+
public class GithubRestUserAPISteps {
21+
22+
private String api;
23+
private GitHubUser resource;
24+
25+
@Step("Given the github REST API for user profile")
26+
public void withUserProfileAPIEndpoint() {
27+
api = "https://api.github.com/users/%s";
28+
}
29+
30+
@Step("When looking for {0} via the api")
31+
public void getProfileOfUser(String username) throws IOException {
32+
HttpResponse httpResponse = getGithubUserProfile(api, username);
33+
resource = retrieveResourceFromResponse(httpResponse, GitHubUser.class);
34+
}
35+
36+
@Step("Then there should be a login field with value {0} in payload of user {0}")
37+
public void profilePayloadShouldContainLoginValue(String username) {
38+
assertThat(username, Matchers.is(resource.getLogin()));
39+
}
40+
41+
private static <T> T retrieveResourceFromResponse(final HttpResponse response, final Class<T> clazz) throws IOException {
42+
final String jsonFromResponse = EntityUtils.toString(response.getEntity());
43+
final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
44+
return mapper.readValue(jsonFromResponse, clazz);
45+
}
46+
47+
private static HttpResponse getGithubUserProfile(String api, String username) throws IOException {
48+
HttpUriRequest request = new HttpGet(String.format(api, username));
49+
return HttpClientBuilder
50+
.create()
51+
.build()
52+
.execute(request);
53+
}
54+
}

0 commit comments

Comments
 (0)