Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
HELP.md
target/
!customer-service/.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
!tests/smoke-tests/src/main/**/target/
!tests/smoke-tests/src/test/**/target/
.DS_Store

### STS ###
Expand All @@ -27,8 +27,8 @@ target/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
!tests/smoke-tests/src/main/**/build/
!tests/smoke-tests/src/test/**/build/

### VS Code ###
.vscode/
39 changes: 38 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<log4j.version>2.17.1</log4j.version>
<bson.version>2.3</bson.version>
<fusionauth.version>5.3.0</fusionauth.version>
<jcommander.version>1.82</jcommander.version>
<gson.version>2.10.1</gson.version>
<rest-assured.version>5.3.1</rest-assured.version>
<jackson-asl.version>0.9.5</jackson-asl.version>
<javafaker.version>1.0.2</javafaker.version>

</properties>

<dependencies>
Expand Down Expand Up @@ -92,8 +98,39 @@
<artifactId>aws-java-sdk-sts</artifactId>
<version>${amazonaws.version}</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.3.1</version>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are still using version directly on this line, use property instead.
You defined properties on line 28 for this then don't use 5.3.1 directly here, refer to line 99 to understand how to use properties.

<exclusions>
<exclusion>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-xml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.82</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-asl</artifactId>
<version>0.9.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.javafaker/javafaker -->
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.techorgx.api;

import com.github.javafaker.Faker;
import com.techorgx.api.endpoints.UserEndPoints;
import com.techorgx.api.payload.User;
import io.restassured.response.Response;
import org.apache.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class CustomerServiceTest {
Faker faker;
User userPayload;

@BeforeClass
public void setupData() {
faker = new Faker();
userPayload = new User();
userPayload.setUsername(faker.name().username());
userPayload.setFirstName(faker.name().firstName());
userPayload.setLastName(faker.name().lastName());
userPayload.setAddress(faker.address().streetAddress());
userPayload.setCity(faker.address().city());
userPayload.setPincode(faker.address().zipCode());
userPayload.setEmail(faker.internet().safeEmailAddress());
}

@Test(priority = 1)
public void testPostUser() {
Response response = UserEndPoints.createUser(userPayload);
response.then().log().all()
.statusCode(HttpStatus.SC_ACCEPTED);
}

@Test(priority = 2)
public void testGetUserByName() {
Response response = UserEndPoints.readUser(this.userPayload.getUsername());
response.then().log().all()
.statusCode(HttpStatus.SC_OK);
}

@Test(priority = 3)
public void testUpdateUser() {

userPayload.setFirstName(faker.name().firstName());
userPayload.setLastName(faker.name().lastName());

Response response = UserEndPoints.updateUser(this.userPayload.getUsername(), userPayload);
response.then().log().all()
.statusCode(HttpStatus.SC_OK);

//Checking data after update
Response responseAfterUpdation=UserEndPoints.readUser (this.userPayload.getUsername());
responseAfterUpdation.then().log().all()
.statusCode(HttpStatus.SC_OK);
}

@Test(priority = 4)
public void testDeleteUserByName() {
Response response = UserEndPoints.deleteUser(this.userPayload.getUsername());
response.then().log().all()
.statusCode(HttpStatus.SC_OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.techorgx.api.endpoints;

//Base url: http://localhost:7979/v1/customer-service
//Create user(POST) : http://localhost:7979/v1/customer-service/add-customer
//Get User (GET): http://localhost:7979/v1/customer-service/get-customer?id=
public class Routes {
public final static String BASE_URL = "http://localhost:7979/v1/customer-service";
public final static String POST_URL = BASE_URL + "/add-customer";
public final static String GET_URL = BASE_URL + "/get-customer";
public static String UPDATE_URL = BASE_URL + "/update-customer";
public static String DELETE_URL = BASE_URL + "/delete-customer";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.techorgx.api.endpoints;

// UserEndPints.java
// Created for perform Create, Read, Update, Delete requests t the user API
import com.techorgx.api.payload.User;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import static io.restassured.RestAssured.given;
public class UserEndPoints {

private final static String CLIENT_ID = "test";
public static Response createUser(User payload) {
Response response = given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.header("client-id", CLIENT_ID)
.body(payload)
.when()
.post(Routes.POST_URL);
return response;
}
public static Response readUser(String username) {
System.out.println("readUser " + username);
String id = username;
Response response = given()
.queryParam("id", username)
.header("client-id", CLIENT_ID)
.when()
.get(Routes.GET_URL);
return response;
}
public static Response updateUser (String username, User payload)
{
Response response=given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.queryParam("id" , username)
.header("client-id", CLIENT_ID)
.body (payload)
.when()
.put(Routes.UPDATE_URL);
return response;
}
public static Response deleteUser (String username)
{
Response response=given()
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.queryParam("id" , username)
.header("client-id", CLIENT_ID)
.when()
.delete(Routes.DELETE_URL);
return response;
}
}
54 changes: 54 additions & 0 deletions tests/smoke-tests/src/main/java/com/techorgx/api/payload/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.techorgx.api.payload;

public class User {
private String city;
private String pincode;
private String email;
private String username;
private String firstName;
private String lastName;
private String address;

public String getUsername() {
Comment thread
Pradhumn-1 marked this conversation as resolved.
return username;
}
public void setUsername(String username) {
this.username = username;
}
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;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPincode() {
return pincode;
}
public void setPincode(String pincode) {
this.pincode = pincode;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}