Skip to content

Commit 7512d25

Browse files
committed
updated date format in booking data builder
1 parent 3d37eec commit 7512d25

File tree

6 files changed

+110
-7
lines changed

6 files changed

+110
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
<playwright-version>1.45.1</playwright-version>
15+
<playwright-version>1.47.0</playwright-version>
1616
<testng-version>7.10.2</testng-version>
1717
<hamcrest-all-version>1.3</hamcrest-all-version>
1818
<json-simple-version>1.1.1</json-simple-version>

src/test/java/io/github/mfaisalkhatri/api/restfulbooker/data/BookingDataBuilder.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public final class BookingDataBuilder {
1414
private static final Faker FAKER = new Faker();
1515

1616
public static BookingData getBookingData() {
17-
final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
1817
return BookingData.builder()
1918
.firstname(FAKER.name()
2019
.firstName())
@@ -24,11 +23,10 @@ public static BookingData getBookingData() {
2423
.numberBetween(1, 2000))
2524
.depositpaid(true)
2625
.bookingdates(BookingDates.builder()
27-
.checkin(formatter.format(FAKER.date()
28-
.past(20, TimeUnit.DAYS)))
29-
.checkout(formatter.format(FAKER.date()
30-
.future(5, TimeUnit.DAYS)))
31-
.build())
26+
.checkin(FAKER.timeAndDate()
27+
.past(20, TimeUnit.DAYS,"yyyy-MM-dd"))
28+
.checkout(FAKER.timeAndDate()
29+
.future(5, TimeUnit.DAYS, "yyyy-MM-dd")).build())
3230
.additionalneeds("Breakfast")
3331
.build();
3432

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.github.mfaisalkhatri.api.restfulecommerce;
2+
3+
4+
import org.testng.annotations.Test;
5+
6+
public class APITests extends BaseTest{
7+
8+
@Test
9+
public void testShouldCreateNewOrders() {
10+
//request.post("/addOrder").body()
11+
}
12+
13+
14+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package io.github.mfaisalkhatri.api.restfulecommerce;
2+
3+
import com.microsoft.playwright.APIRequest;
4+
import com.microsoft.playwright.APIRequestContext;
5+
import com.microsoft.playwright.Playwright;
6+
import org.testng.annotations.AfterClass;
7+
import org.testng.annotations.BeforeClass;
8+
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
public class BaseTest {
13+
14+
protected Playwright playwright;
15+
protected APIRequestContext request;
16+
private static final String BASE_URL = "http://localhost:3004";
17+
18+
@BeforeClass
19+
public void setup() {
20+
createPlaywright();
21+
createAPIRequestContext();
22+
}
23+
24+
@AfterClass
25+
public void tearDown() {
26+
disposeAPIRequestContext();
27+
closePlaywright();
28+
29+
}
30+
31+
private void createPlaywright() {
32+
playwright = Playwright.create();
33+
}
34+
35+
private void createAPIRequestContext() {
36+
Map<String, String> headers = new HashMap<>();
37+
headers.put("Content-Type", "application/json");
38+
39+
request = playwright.request().newContext(new APIRequest.NewContextOptions()
40+
.setBaseURL(BASE_URL)
41+
.setExtraHTTPHeaders(headers));
42+
}
43+
44+
45+
private void closePlaywright() {
46+
if (playwright != null) {
47+
playwright.close();
48+
playwright = null;
49+
}
50+
}
51+
52+
private void disposeAPIRequestContext() {
53+
if (request != null) {
54+
request.dispose();
55+
request = null;
56+
}
57+
}
58+
59+
60+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.github.mfaisalkhatri.api.restfulecommerce.testdata;
2+
3+
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.Builder;
6+
import lombok.Getter;
7+
8+
@Getter
9+
@Builder
10+
public class OrderData {
11+
@SerializedName("user_id")
12+
private String userId;
13+
@SerializedName("product_id")
14+
private String productId;
15+
@SerializedName("product_name")
16+
private String productName;
17+
@SerializedName("product_amount")
18+
private int productAmount;
19+
private int qty;
20+
@SerializedName("tax_amt")
21+
private int taxAmt;
22+
@SerializedName("total_amt")
23+
private int totalAmt;
24+
25+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.github.mfaisalkhatri.api.restfulecommerce.testdata;
2+
3+
public class OrderDataBuilder {
4+
5+
6+
}

0 commit comments

Comments
 (0)