Skip to content

Commit

Permalink
Merge pull request #73 from dvsa/registerUserThreadSafe
Browse files Browse the repository at this point in the history
chore:thread safety for register user
  • Loading branch information
sr4850 authored Aug 9, 2024
2 parents 1574e88 + a87a469 commit b08618d
Showing 1 changed file with 52 additions and 42 deletions.
94 changes: 52 additions & 42 deletions src/main/java/apiCalls/actions/RegisterUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import apiCalls.Utils.volBuilders.SelfServeUserRegistrationDetailsBuilder;
import apiCalls.Utils.generic.Headers;
import activesupport.http.RestUtils;

import activesupport.system.Properties;

import apiCalls.Utils.generic.Utils;
import apiCalls.enums.BusinessType;
import apiCalls.enums.UserTitle;
Expand All @@ -19,7 +17,6 @@
import org.dvsa.testing.lib.url.api.URL;
import org.dvsa.testing.lib.url.utils.EnvironmentType;


public class RegisterUser {

private String title;
Expand All @@ -32,102 +29,115 @@ public class RegisterUser {
private String businessType;
private String userId;

public void setTitle(String title) {
private final EnvironmentType env;
private final Headers apiHeaders = new Headers();

public RegisterUser() {
env = EnvironmentType.getEnum(Properties.get("env", true));
FakerUtils faker = new FakerUtils();

synchronized (this) {
this.foreName = faker.generateFirstName().concat(String.valueOf(Int.random(100, 999)));
this.familyName = faker.generateLastName().concat(String.valueOf(Int.random(100, 999)));
this.birthDate = Int.random(1900, 2018) + "-" + Int.random(1, 12) + "-" + Int.random(1, 28);
this.userName = String.format("%s%s%s", foreName, familyName, Int.random(1000,9999));
this.emailAddress = String.format("%s_%s%[email protected]", foreName, familyName, Int.random(10000, 99999));
this.title = UserTitle.MR.asString();
this.organisationName = faker.generateCompanyName();
this.businessType = BusinessType.LIMITED_COMPANY.asString();
}
}

public synchronized void setTitle(String title) {
this.title = title;
}

public String getTitle() {
public synchronized String getTitle() {
return title;
}

public void setForeName(String foreName) {
public synchronized void setForeName(String foreName) {
this.foreName = foreName;
}

public String getForeName() {
public synchronized String getForeName() {
return foreName;
}

public void setFamilyName(String familyName) {
public synchronized void setFamilyName(String familyName) {
this.familyName = familyName;
}

public String getFamilyName() {
public synchronized String getFamilyName() {
return familyName;
}

public void setUserName(String userName) {
public synchronized void setUserName(String userName) {
this.userName = userName;
}

public String getUserName() {
public synchronized String getUserName() {
return userName;
}

public String getBirthDate() {
public synchronized String getBirthDate() {
return birthDate;
}

public void setBirthDate(String birthDate) {
public synchronized void setBirthDate(String birthDate) {
this.birthDate = birthDate;
}

public String getEmailAddress() {
public synchronized String getEmailAddress() {
return emailAddress;
}

public void setEmailAddress(String emailAddress) {
public synchronized void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}

public String getOrganisationName() {
public synchronized String getOrganisationName() {
return organisationName;
}

public void setOrganisationName(String organisationName) {
public synchronized void setOrganisationName(String organisationName) {
this.organisationName = organisationName;
}

public String getBusinessType() {
public synchronized String getBusinessType() {
return businessType;
}

public void setBusinessType(String businessType) {
public synchronized void setBusinessType(String businessType) {
this.businessType = businessType;
}

public void setUserId(String userId) {
public synchronized void setUserId(String userId) {
this.userId = userId;
}

public String getUserId() {
public synchronized String getUserId() {
return userId;
}

private EnvironmentType env = EnvironmentType.getEnum(Properties.get("env", true));

private final Headers apiHeaders = new Headers();

public RegisterUser() {
FakerUtils faker = new FakerUtils();
setForeName( faker.generateFirstName().concat(String.valueOf(Int.random(100, 999))) );
setFamilyName( faker.generateLastName().concat(String.valueOf(Int.random(100, 999))) );
setBirthDate( Int.random(1900, 2018) + "-" + Int.random(1, 12) + "-" + Int.random(1, 28) );
setUserName( String.format("%s%s%s", getForeName(), getFamilyName(), Int.random(1000,9999)) );
setEmailAddress( String.format("%s_%s%[email protected]", getForeName(), getFamilyName(), Int.random(10000, 99999)) );
setTitle( UserTitle.MR.asString() );
setOrganisationName( faker.generateCompanyName() );
setBusinessType( BusinessType.LIMITED_COMPANY.asString() );
}

public synchronized ValidatableResponse registerUser() throws HttpException {
String registerResource = URL.build(env, "user/selfserve/register").toString();

PersonBuilder personBuilder = new PersonBuilder().withTitle(getTitle()).withForename(getForeName()).withFamilyName(getFamilyName()).withBirthDate(getBirthDate());
ContactDetailsBuilder contactDetailsBuilder = new ContactDetailsBuilder().withEmailAddress(getEmailAddress()).withPerson(personBuilder);

SelfServeUserRegistrationDetailsBuilder selfServeUserRegistrationDetailsBuilder = new SelfServeUserRegistrationDetailsBuilder().withLoginId(getUserName()).withContactDetails(contactDetailsBuilder)
.withOrganisationName(getOrganisationName()).withBusinessType(getBusinessType());
PersonBuilder personBuilder = new PersonBuilder()
.withTitle(getTitle())
.withForename(getForeName())
.withFamilyName(getFamilyName())
.withBirthDate(getBirthDate());

ContactDetailsBuilder contactDetailsBuilder = new ContactDetailsBuilder()
.withEmailAddress(getEmailAddress())
.withPerson(personBuilder);

SelfServeUserRegistrationDetailsBuilder selfServeUserRegistrationDetailsBuilder = new SelfServeUserRegistrationDetailsBuilder()
.withLoginId(getUserName())
.withContactDetails(contactDetailsBuilder)
.withOrganisationName(getOrganisationName())
.withBusinessType(getBusinessType());

ValidatableResponse apiResponse = RestUtils.post(selfServeUserRegistrationDetailsBuilder, registerResource, apiHeaders.getApiHeader());

Expand Down

0 comments on commit b08618d

Please sign in to comment.