-
-
Save braghome/12596a164888125b5b0f to your computer and use it in GitHub Desktop.
xtend code to verify mailbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[INFO] Running story valid_migrated_mailbox.story | |
validate all migration occurring on stage, have a valid mailbox | |
(valid_migrated_mailbox.story) | |
Meta: | |
@Category hourlyYoltMigration | |
@Color red | |
@Theme hourlyMigration | |
Narrative: | |
In order to communicate effectively to the business agent migration | |
As a development team | |
I want to verify agent mailbox | |
Scenario: verify all migrations have valid value for mailbox | |
[INFO] query: /some/ | |
[INFO] apiHost: https://service.com:8121/endpoints | |
[INFO] read object [Data@2eca16d1[ | |
creationDate=Fri Jan 15 13:24:07 PST 2016 | |
mailbox=jasonchan1sunsetparkside | |
migrationComplete=1 | |
partnerId=2089 | |
updateDate=Fri Jan 15 13:24:35 PST 2016 | |
], Data@6b524e97[ | |
creationDate=Fri Jan 08 08:43:53 PST 2016 | |
mailbox=cricketyee | |
migrationComplete=1 | |
partnerId=5625 | |
updateDate=Fri Jan 15 10:44:35 PST 2016 | |
], Data@659938be[ | |
creationDate=Wed Nov 11 11:39:32 PST 2015 | |
mailbox=thomascrimmins | |
migrationComplete=1 | |
partnerId=5534 | |
updateDate=Fri Jan 15 01:49:23 PST 2016 | |
], Data@4c6ee96e[ | |
creationDate=Wed Nov 11 11:39:31 PST 2015 | |
mailbox=jonsalmon | |
migrationComplete=1 | |
partnerId=1881 | |
updateDate=Fri Jan 15 01:23:47 PST 2016 | |
], Data@32ec12ac[ | |
creationDate=Thu Jan 14 17:07:17 PST 2016 | |
mailbox=percycheung | |
migrationComplete=1 | |
partnerId=1650 | |
updateDate=Thu Jan 14 17:09:42 PST 2016 | |
]] | |
[INFO] HV000001: Hibernate Validator 5.0.2.Final | |
Given pull top migrated agents | |
[INFO] query: /z2089 | |
[INFO] apiHost: http://user.com/account | |
[INFO] read object UserReader@3e964687[ | |
metadata=userprofile.Metadata@7612a6f9[ | |
totalTime=0.0170419216156 | |
status=200 | |
] | |
data=userprofile.Data@69dc5323[ | |
zuid=2089 | |
name=Jason Chan - #1 Sunset/Parkside! | |
] | |
] | |
[INFO] query: /z5625 | |
[INFO] apiHost: http://user.com/account | |
[INFO] read object UserReader@3e964687[ | |
metadata=userprofile.Metadata@11f8bd57[ | |
totalTime=0.0120418071747 | |
status=200 | |
] | |
data=userprofile.Data@34461606[ | |
zuid=5625 | |
name=Cricket Yee | |
] | |
] | |
[INFO] query: /z5534 | |
[INFO] apiHost: http://user.com/account | |
[INFO] read object UserReader@3e964687[ | |
metadata=userprofile.Metadata@45681d6[ | |
totalTime=0.0172760486603 | |
status=200 | |
] | |
data=userprofile.Data@3764fa49[ | |
zuid=5534238 | |
name=Thomas Crimmins | |
] | |
] | |
[INFO] query: /z1881 | |
[INFO] apiHost: http://user.com/account | |
[INFO] read object UserReader@3e964687[ | |
metadata=userprofile.Metadata@1416d7a8[ | |
totalTime=0.0114531517029 | |
status=200 | |
] | |
data=userprofile.Data@2e626ac2[ | |
zuid=1881 | |
name=Jon Salmon | |
] | |
] | |
[INFO] query: /z1650 | |
[INFO] apiHost: http://user.com/account | |
[INFO] read object UserReader@3e964687[ | |
metadata=userprofile.Metadata@206623b4[ | |
totalTime=0.0115740299225 | |
status=200 | |
] | |
data=userprofile.Data@48a4801e[ | |
zuid=1650 | |
name=Percy Cheung | |
] | |
] | |
When verify if agent name is empty skip to validate next agent | |
And verify validated agent list without name is not empty | |
Then verify the mail box matches agent name (FAILED) | |
(java.lang.AssertionError: matched user profile should not be null | |
Expected: not null | |
but: was null) | |
Code | |
==== | |
class ValidMigratedMailbox { | |
@Autowired CrmMigration crmMigrationImpl | |
CrmInstance crmInstance | |
@Given("pull top migrated agents") | |
def void pullTopMigratedAgents() { | |
crmInstance = new CrmInstance(crmMigrationImpl.agentMigration, null, null) | |
} | |
@When("verify if agent name is empty skip to validate next agent") | |
def void verifyIfAgentNameIsEmptySkipToValidateNextAgent() { | |
crmInstance = crmInstance.withUData(new ArrayList) | |
val validAgentList = crmInstance.crmAgent.filter[ | |
crmMigrationImpl.verifyProfileName(partnerId, crmInstance.UData) | |
].toList | |
assertThat("can't have a list less then 5 elements", validAgentList.size, equalTo(5)) | |
crmInstance = crmInstance.withValidAgent(validAgentList) | |
} | |
@When("verify validated agent list without name is not empty") | |
def void validatedAgentList() { | |
assertThat(crmInstance.validAgent, not(equalTo(Collections.EMPTY_LIST))) | |
} | |
@Then("verify the mail box matches agent name") | |
def void verifyTheMailMatchesAgentName() { | |
crmInstance.validAgent.forEach[crmMigrationImpl.validateMailbox(it, crmInstance.UData)] | |
} | |
} | |
def private ResponseStatus getUserAgentList() throws AssertionError { | |
val ResponseStatus status = appCommon.validGetRequest(AGENT.toString, QACOLLAB.toString) | |
try { | |
assertThat(status.getCode(), equalTo(200)) | |
assertThat('''agent body missing required fields «status.getBody»''', status.getBody(), | |
AllOf.<String>allOf(containsString("mailbox"), containsString("agentId"))) | |
} catch (AssertionError ae) { | |
throw new AssertionError(ae.getMessage, ae.getCause) | |
} | |
return status | |
} | |
def private List<CrmAgent> crmAgentReader(String body) { | |
val Reader r = new BufferedReader(new StringReader(body)) | |
crmAgentReader.reader(r) | |
crmAgentReader.getType | |
} | |
def private void constraintValidation(List<CrmAgent> s) throws AssertionError { | |
appAsserts.constraintViolations(validateGeneric.checkConstraints(s)) | |
} | |
override getAgentMigration() throws AssertionError { | |
val crmAgent = crmAgentReader(getUserAgentList.getBody) | |
constraintValidation(crmAgent) | |
crmAgent | |
} | |
override verifyProfileName(String agentPartnerId, List<UserProfile<Data>> uData) throws AssertionError { | |
val p = userProfileImpl.getProdUserProfleService( | |
Z.toString + agentPartnerId | |
) | |
try { | |
assertThat(p, notNullValue) | |
} catch (AssertionError ae) { | |
throw new AssertionError(ae.getMessage, ae.getCause) | |
} | |
val is = !p.data.name.isEmpty | |
if (is) uData.add(p) else is | |
} | |
override matchPfrofileName(String agentPartnerId, List<UserProfile<Data>> uData) throws AssertionError { | |
val d = uData.findFirst[data.zuid == Integer.valueOf(agentPartnerId)] | |
try { | |
assertThat('''matched user profile should not be null «d»''', d, notNullValue) | |
} catch (AssertionError ae) { | |
throw new AssertionError(ae.getMessage, ae.getCause) | |
} | |
d | |
} | |
override validateMailbox(CrmAgent a, List<UserProfile<Data>> ud) throws AssertionError { | |
val removeSpace = matchPfrofileName(a.partnerId, ud) | |
.data | |
.name | |
.toLowerCase | |
try { | |
assertThat(removeSpace, notNullValue) | |
assertThat(a.mailbox, equalTo(removeSpace.replaceAll("[^a-zA-Z0-9]", ""))) | |
} catch (AssertionError ae) { | |
throw new AssertionError(ae.getMessage, ae.getCause) | |
} | |
} | |
interface CrmMigration { | |
def List<CrmAgent> getAgentMigration() throws AssertionError | |
def Boolean verifyProfileName(String agentPartnerId, List<UserProfile<Data>> uData) throws AssertionError | |
def UserProfile<Data> matchPfrofileName(String agentPartnerId, | |
List<UserProfile<Data>> uData | |
) throws AssertionError | |
def void validateMailbox(CrmAgent a, List<UserProfile<Data>> ud) throws AssertionError | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment