parent
48c0e41791
commit
8b028a2946
@ -45,6 +45,20 @@
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.serenity-bdd.maven.plugins</groupId>
|
||||
<artifactId>serenity-maven-plugin</artifactId>
|
||||
<version>${serenity.plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>serenity-reports</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>aggregate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@ -123,26 +137,6 @@
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons.io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons.io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.flink</groupId>
|
||||
<artifactId>flink-core</artifactId>
|
||||
@ -176,6 +170,36 @@
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>3.6.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-core</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-junit</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-jbehave</artifactId>
|
||||
<version>${serenity.jbehave.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-rest-assured</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-jira-requirements-provider</artifactId>
|
||||
<version>${serenity.jira.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
@ -195,6 +219,11 @@
|
||||
<httpclient.version>4.5.3</httpclient.version>
|
||||
<commons.io.version>2.5</commons.io.version>
|
||||
<flink.version>1.2.0</flink.version>
|
||||
<jackson.version>2.8.5</jackson.version>
|
||||
<serenity.version>1.2.5-rc.11</serenity.version>
|
||||
<serenity.jbehave.version>1.24.0</serenity.jbehave.version>
|
||||
<serenity.jira.version>1.1.3-rc.5</serenity.jira.version>
|
||||
<serenity.plugin.version>1.2.5-rc.6</serenity.plugin.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
</properties>
|
||||
|
||||
|
4
libraries/serenity.properties
Normal file
4
libraries/serenity.properties
Normal file
@ -0,0 +1,4 @@
|
||||
jira.url=<jira-url>
|
||||
jira.project=<jira-project>
|
||||
jira.username=<jira-username>
|
||||
jira.password=<jira-password>
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.baeldung.serenity.membership;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public enum MemberGrade {
|
||||
|
||||
Bronze, Silver, Gold;
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.baeldung.serenity;
|
||||
|
||||
import net.serenitybdd.jbehave.SerenityStory;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class GithubUserProfilePayloadTest extends SerenityStory {
|
||||
|
||||
}
|
@ -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 <code>@Ignore</code> to see how failed test can be reflected in Serenity report. <br/>
|
||||
* Remember to add <code><testFailureIgnore>true</testFailureIgnore></code> 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);
|
||||
}
|
||||
|
||||
}
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
@ -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> T retrieveResourceFromResponse(final HttpResponse response, final Class<T> 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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user