dva1946
13 years agoOccasional Contributor
Assertion - Validate Multiple metadata Responses to Source
Why did we write this assertion?
1) Learn how to assert against metadata
2) Learn how to assert against dynamic metadata
3) Master complex assertions
4) Build an assertion that can be our model for many different assertions.
5) Also learned about count & getNodeValue
6) Learned how to use automated features to get a single result, then automate it.
NOTE: If you want a text version of this post, email me from here.
Web Service Request & Response = APP getCatalogOffering
Overview:
The objective of this assertion is the automatic of validation of a
WS response metadata for categories:
<ns2:metadata value="/B1/B2/B3" name="MOD::Category"/>
<ns2:metadata value="/A1/A2/A3" name="MOD::Category"/>
<ns2:metadata value="/C1/C2/C3" name="MOD::Category"/>
<ns2:metadata value="/All Movies" name="MOD::Category"/>
This is not a simple process!
In our test case model, we had manually also added a specific offering to
another category = /All Movies
Therefore, when calling getCatalogOffering, it had 4 categories.
For a negative test condition, change one DataGen property category value.
ASSERTION - getCatalogOffering (5-16-12)
This is a complete FUNCTIONAL assertion, based on:
CGW v31
VOD v31
Data Gen - 8 pre-defined properties (not all used)
OfferingOne = 37963
Cat-A3 = 179018
Cat-B3 = 179015
Cat-C3 = 179021
Cat-A1-A2-A3-value = /A1/A2/A3
Cat-B1-B2-B3-value = /B1/B2/B3
Cat-C1-C2-C3-value = /C1/C2/C3
Cat-AllMovies = /All Movies
Automated steps
DataGen
Property Transfer-OfferingId
CGW addOfferingsToCategory
Delay After Adds
APP getCatalogOffering
Assertion All TestStep
Assertion = getCategory-getNodeValueAutoDirectories
// The Complete Assertion is Below //
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder( "APP getCatalogOffering#Response" )
// GET addOfferingsToCategory added CATEGORIES //
def catc3 = context.expand( '${DataGen#Cat-C1-C2-C3-Value}' ); // read from DataGen properties (3 values)
def cata3 = context.expand( '${DataGen#Cat-A1-A2-A3-Value}' );
def catb3 = context.expand( '${DataGen#Cat-B1-B2-B3-Value}' );
def catAllMovies= context.expand( '${DataGen#Cat-AllMovies}' ); // Added a 4th so I can refine the assertions area dynamically below
def datagenlist = [cata3, catb3, catc3, catAllMovies];
def cntdatagencategories = datagenlist.size();
//log.info " DATAGEN Category Count = $cntdatagencategories";
//log.info datagenlist;
// Below line generated with RIGHT-CLICK to get count and getNodeValue code, tested and then commented out.
//def response = context.expand( '${APP getCatalogOffering#Response#declare namespace ns1=\'urn:n2bb:OpenStreamVODModule_v31\'; declare namespace ns2=\'urn:n2bb:OpenStreamVODTypes_v31\'; //ns1:GetCatalogOfferingResponse[1]/ns1:offering[1]/ns2:metadataOverrides[1]/ns2:metadata[1]/@value}' )
//log.info " RESPONSE $response";
// get count of categories
def cntcategories = holder["count(//ns1:GetCatalogOfferingResponse[1]/ns1:offering[1]/ns2:metadataOverrides[1]/ns2:metadata)"] as int;
//log.info " RESPONSE Category Count = $cntcategories";
def aa = 1 as int; // must start at 1, not zero
def addedcat = ""; // variable for found category
def categorieslist = []; // empty array
while (aa <= cntcategories) {
addedcat = holder.getNodeValue("//ns1:GetCatalogOfferingResponse[1]/ns1:offering[1]/ns2:metadataOverrides[1]/ns2:metadata[$aa]/@value") // code returns
categorieslist.add(addedcat); // add category to a list
aa++
}
cntcategories = categorieslist.size() as int; // give # of elements in the array
//log.info categorieslist;
//log.info cntcategories;
log.info " ** ASSERTION ZONE **";
// Assert "DataGen Properties" == "APP getCatalogOffering#Response"
// Array for DataGen = offeringcatlist
// Array for get categories = categorieslist
def cp = 0 as int; // Outside "while" control
def pass = 0 as int; // default untested
def fail = 0 as int; // default untested
def alike = 0 as int; // need alike == both counts, else have failure
def bb = ""; // used for the individual offering category from the array
def cc = 0 as int; // Loop 3 control
def dd = ""; // category
def matlst= []; // matched list, as can not seem to make strings work very well
def ee = 0 as int // matlst control
def ff = 0 as int // matlst control
def gg = 0 as int // matlst control
def hh = ""; // matlst control
while ((cntcategories == cntdatagencategories) && (cp < cntdatagencategories)) {
//log.info " Outer Loop: $cp";
// loop through each offeringcatlist
aa = 1;
while (aa <= cntdatagencategories) {
bb = datagenlist[aa -1]; // category from offering list
cc = 1; // use for loop through categorieslist
//log.info " Each offering category: $bb";
// loop through categorieslist and compare to individual offeringcatlist item (bb)
while (cc <= cntcategories) {
dd = categorieslist[cc -1];
if (bb =~ dd) {
// CHECK PREVIOUS MATCH: Must use an array, as string matches do not behave very well unfortunately
//log.info " Inside L3: $dd $curmat";
ee = 0;
ff = 0;
gg = 0;
hh = "";
ff = matlst.size();
while ((ff) && (gg < ff)) {
hh = matlst[gg];
if (hh =~ dd) {
ee =1; // control to skip match below
gg = ff; // skip reset of the loop, as have a match
}
gg++;
}
// Not previously matched, so now a valid match: add to matlist & set 2 variables to skip loops
if (!ee) {
//log.info " NEW MATCH: $bb $dd";
matlst.add(dd);
alike++;
cc = cntcategories; // will incr out below
aa = cntdatagencategories; // will incr out below
}
}
cc++;
}
aa++;
}
cp++;
}
log.info matlst;
if (alike == cntcategories) {
pass = 1;
}else {
pass = 0;
fail = 1;
}
log.info "cntcategories = $cntcategories, alike = $alike, pass = $pass, fail = $fail";
// ** ASSERTION **//
if (alike == cntcategories) {
assert pass != fail; // pass will be "1" if all match; fail will be "0" if all pass
} else {
assert pass == fail; // pass will be "0" if all match; fail will be "1" if all pass
}
//****************//
Log output
----------
Wed May 16 10:44:38 MDT 2012:INFO: ** ASSERTION ZONE **
Wed May 16 10:44:38 MDT 2012:INFO:[/A1/A2/A3, /B1/B2/B3, /C1/C2/C3, /All Movies]
Wed May 16 10:44:38 MDT 2012:INFO:cntcategories = 4, alike = 4, pass = 1, fail = 0
Web Service Request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:n2bb:OpenStreamVODModule_v31" xmlns:urn1="urn:n2bb:OpenStreamVODTypes_v31">
<soapenv:Header/>
<soapenv:Body>
<urn:GetCatalogOfferingRequest>
<!--1 or more repetitions:-->
<urn:offeringRef>
<!--You have a CHOICE of the next 3 items at this level-->
<urn1:offeringId>37963</urn1:offeringId>
</urn:offeringRef>
<urn:includeAssetMetadata>true</urn:includeAssetMetadata><urn:catalogId>0</urn:catalogId>
<!--You have a CHOICE of the next 2 items at this level-->
<!--Optional:-->
<!--Optional:-->
</urn:GetCatalogOfferingRequest>
</soapenv:Body>
</soapenv:Envelope>
Web Service Response - some content removed ...
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
<GetCatalogOfferingResponse xmlns="urn:n2bb:OpenStreamVODModule_v31" xmlns:ns2="urn:n2bb:OpenStreamVODTypes_v31">
<offering packageName="MyStdMOD-1" serviceName="MOD" modifiedTime="2012-05-16T16:23:17.717Z" createTime="2012-05-09T17:07:48.000Z" expirationDate="2012-11-07T07:00:00.000Z" startDate="2004-01-01T07:00:00.000Z" rentalDuration="86400" price="0" serviceType="MOD" type="MOD" offeringId="37963">
<ns2:description>MyStdMOD-1 TITLE Title</ns2:description>
<ns2:metadataOverrides>
<ns2:asset>
<ns2:providerId>arrivo.com</ns2:providerId>
<ns2:assetId>BDTL0001336583264616</ns2:assetId>
</ns2:asset>
<ns2:metadata value="/B1/B2/B3" name="MOD::Category"/>
<ns2:metadata value="/A1/A2/A3" name="MOD::Category"/>
<ns2:metadata value="/C1/C2/C3" name="MOD::Category"/>
<ns2:metadata value="/All Movies" name="MOD::Category"/>
</ns2:metadataOverrides>
<ns2:offeringRef>37964</ns2:offeringRef>
<ns2:packageAsset assetId="BDPK0001336583264616" providerId="arrivo.com" assetName="MyStdMOD-1" assetClass="PackageAsset">
<ns2:metadata value="arrivo1" name="MOD::Provider_Content_Tier"/>
<ns2:metadata value="MOD" name="AMS::Product"/>
<ns2:metadata value="2004-11-22" name="AMS::Creation_Date"/>
</ns2:packageAsset>
<ns2:titleAsset releaseYear="2003" rating="PG-13" runTime="3671" shortTitle="MyStdMOD-1" title="MyStdMOD-1 TITLE Title" assetId="BDTL0001336583264616" providerId="arrivo.com" assetName="arrivo.com::BDTL0001336583264616" assetClass="TitleAsset">
<ns2:metadata value="N" name="MOD::Closed_Captioning"/>
<ns2:metadata value="TITLE Episode Brief" name="MOD::Episode_Name"/>
<ns2:description>This is the TITLE Summary Short</ns2:description>
<ns2:actor>Nick Actor</ns2:actor>
<ns2:actor>Mark Actor</ns2:actor>
<ns2:actor>Wilma Actor</ns2:actor>
<ns2:actor>Lana Actor</ns2:actor>
</ns2:titleAsset>
<ns2:movieAsset bitRate="0" releaseYear="2003" rating="PG-13" runTime="3671" shortTitle="MyStdMOD-1" title="MyStdMOD-1 TITLE Title" assetId="BDMV0001336583264616" providerId="arrivo.com" assetName="arrivo.com::BDMV0001336583264616" assetClass="MovieAsset">
<ns2:metadata value="fr" name="MOD::Dubbed_Languages"/>
<ns2:actor>Nick Actor</ns2:actor>
<ns2:actor>Mark Actor</ns2:actor>
<ns2:actor>Wilma Actor</ns2:actor>
<ns2:actor>Lana Actor</ns2:actor>
</ns2:movieAsset>
<ns2:viewingWindow>
<ns2:startDate>2004-01-01T07:00:00.000Z</ns2:startDate>
<ns2:endDate>2012-11-07T07:00:00.000Z</ns2:endDate>
</ns2:viewingWindow>
<ns2:deliveryType>
<ns2:deliveryMethod>dsmcc-openstream-streaming</ns2:deliveryMethod>
<ns2:deliverableAssetClass>
<ns2:assetClass>MovieAsset</ns2:assetClass>
</ns2:deliverableAssetClass>
</ns2:deliveryType>
<ns2:deliveryType>
<ns2:deliveryMethod>rtsp-openstream-streaming</ns2:deliveryMethod>
<ns2:deliverableAssetClass>
<ns2:assetClass>MovieAsset</ns2:assetClass>
</ns2:deliverableAssetClass>
</ns2:deliveryType>
</offering>
</GetCatalogOfferingResponse>
</env:Body>
</env:Envelope>
1) Learn how to assert against metadata
2) Learn how to assert against dynamic metadata
3) Master complex assertions
4) Build an assertion that can be our model for many different assertions.
5) Also learned about count & getNodeValue
6) Learned how to use automated features to get a single result, then automate it.
NOTE: If you want a text version of this post, email me from here.
Web Service Request & Response = APP getCatalogOffering
Overview:
The objective of this assertion is the automatic of validation of a
WS response metadata for categories:
<ns2:metadata value="/B1/B2/B3" name="MOD::Category"/>
<ns2:metadata value="/A1/A2/A3" name="MOD::Category"/>
<ns2:metadata value="/C1/C2/C3" name="MOD::Category"/>
<ns2:metadata value="/All Movies" name="MOD::Category"/>
This is not a simple process!
In our test case model, we had manually also added a specific offering to
another category = /All Movies
Therefore, when calling getCatalogOffering, it had 4 categories.
For a negative test condition, change one DataGen property category value.
ASSERTION - getCatalogOffering (5-16-12)
This is a complete FUNCTIONAL assertion, based on:
CGW v31
VOD v31
Data Gen - 8 pre-defined properties (not all used)
OfferingOne = 37963
Cat-A3 = 179018
Cat-B3 = 179015
Cat-C3 = 179021
Cat-A1-A2-A3-value = /A1/A2/A3
Cat-B1-B2-B3-value = /B1/B2/B3
Cat-C1-C2-C3-value = /C1/C2/C3
Cat-AllMovies = /All Movies
Automated steps
DataGen
Property Transfer-OfferingId
CGW addOfferingsToCategory
Delay After Adds
APP getCatalogOffering
Assertion All TestStep
Assertion = getCategory-getNodeValueAutoDirectories
// The Complete Assertion is Below //
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder( "APP getCatalogOffering#Response" )
// GET addOfferingsToCategory added CATEGORIES //
def catc3 = context.expand( '${DataGen#Cat-C1-C2-C3-Value}' ); // read from DataGen properties (3 values)
def cata3 = context.expand( '${DataGen#Cat-A1-A2-A3-Value}' );
def catb3 = context.expand( '${DataGen#Cat-B1-B2-B3-Value}' );
def catAllMovies= context.expand( '${DataGen#Cat-AllMovies}' ); // Added a 4th so I can refine the assertions area dynamically below
def datagenlist = [cata3, catb3, catc3, catAllMovies];
def cntdatagencategories = datagenlist.size();
//log.info " DATAGEN Category Count = $cntdatagencategories";
//log.info datagenlist;
// Below line generated with RIGHT-CLICK to get count and getNodeValue code, tested and then commented out.
//def response = context.expand( '${APP getCatalogOffering#Response#declare namespace ns1=\'urn:n2bb:OpenStreamVODModule_v31\'; declare namespace ns2=\'urn:n2bb:OpenStreamVODTypes_v31\'; //ns1:GetCatalogOfferingResponse[1]/ns1:offering[1]/ns2:metadataOverrides[1]/ns2:metadata[1]/@value}' )
//log.info " RESPONSE $response";
// get count of categories
def cntcategories = holder["count(//ns1:GetCatalogOfferingResponse[1]/ns1:offering[1]/ns2:metadataOverrides[1]/ns2:metadata)"] as int;
//log.info " RESPONSE Category Count = $cntcategories";
def aa = 1 as int; // must start at 1, not zero
def addedcat = ""; // variable for found category
def categorieslist = []; // empty array
while (aa <= cntcategories) {
addedcat = holder.getNodeValue("//ns1:GetCatalogOfferingResponse[1]/ns1:offering[1]/ns2:metadataOverrides[1]/ns2:metadata[$aa]/@value") // code returns
categorieslist.add(addedcat); // add category to a list
aa++
}
cntcategories = categorieslist.size() as int; // give # of elements in the array
//log.info categorieslist;
//log.info cntcategories;
log.info " ** ASSERTION ZONE **";
// Assert "DataGen Properties" == "APP getCatalogOffering#Response"
// Array for DataGen = offeringcatlist
// Array for get categories = categorieslist
def cp = 0 as int; // Outside "while" control
def pass = 0 as int; // default untested
def fail = 0 as int; // default untested
def alike = 0 as int; // need alike == both counts, else have failure
def bb = ""; // used for the individual offering category from the array
def cc = 0 as int; // Loop 3 control
def dd = ""; // category
def matlst= []; // matched list, as can not seem to make strings work very well
def ee = 0 as int // matlst control
def ff = 0 as int // matlst control
def gg = 0 as int // matlst control
def hh = ""; // matlst control
while ((cntcategories == cntdatagencategories) && (cp < cntdatagencategories)) {
//log.info " Outer Loop: $cp";
// loop through each offeringcatlist
aa = 1;
while (aa <= cntdatagencategories) {
bb = datagenlist[aa -1]; // category from offering list
cc = 1; // use for loop through categorieslist
//log.info " Each offering category: $bb";
// loop through categorieslist and compare to individual offeringcatlist item (bb)
while (cc <= cntcategories) {
dd = categorieslist[cc -1];
if (bb =~ dd) {
// CHECK PREVIOUS MATCH: Must use an array, as string matches do not behave very well unfortunately
//log.info " Inside L3: $dd $curmat";
ee = 0;
ff = 0;
gg = 0;
hh = "";
ff = matlst.size();
while ((ff) && (gg < ff)) {
hh = matlst[gg];
if (hh =~ dd) {
ee =1; // control to skip match below
gg = ff; // skip reset of the loop, as have a match
}
gg++;
}
// Not previously matched, so now a valid match: add to matlist & set 2 variables to skip loops
if (!ee) {
//log.info " NEW MATCH: $bb $dd";
matlst.add(dd);
alike++;
cc = cntcategories; // will incr out below
aa = cntdatagencategories; // will incr out below
}
}
cc++;
}
aa++;
}
cp++;
}
log.info matlst;
if (alike == cntcategories) {
pass = 1;
}else {
pass = 0;
fail = 1;
}
log.info "cntcategories = $cntcategories, alike = $alike, pass = $pass, fail = $fail";
// ** ASSERTION **//
if (alike == cntcategories) {
assert pass != fail; // pass will be "1" if all match; fail will be "0" if all pass
} else {
assert pass == fail; // pass will be "0" if all match; fail will be "1" if all pass
}
//****************//
Log output
----------
Wed May 16 10:44:38 MDT 2012:INFO: ** ASSERTION ZONE **
Wed May 16 10:44:38 MDT 2012:INFO:[/A1/A2/A3, /B1/B2/B3, /C1/C2/C3, /All Movies]
Wed May 16 10:44:38 MDT 2012:INFO:cntcategories = 4, alike = 4, pass = 1, fail = 0
Web Service Request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:n2bb:OpenStreamVODModule_v31" xmlns:urn1="urn:n2bb:OpenStreamVODTypes_v31">
<soapenv:Header/>
<soapenv:Body>
<urn:GetCatalogOfferingRequest>
<!--1 or more repetitions:-->
<urn:offeringRef>
<!--You have a CHOICE of the next 3 items at this level-->
<urn1:offeringId>37963</urn1:offeringId>
</urn:offeringRef>
<urn:includeAssetMetadata>true</urn:includeAssetMetadata><urn:catalogId>0</urn:catalogId>
<!--You have a CHOICE of the next 2 items at this level-->
<!--Optional:-->
<!--Optional:-->
</urn:GetCatalogOfferingRequest>
</soapenv:Body>
</soapenv:Envelope>
Web Service Response - some content removed ...
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
<GetCatalogOfferingResponse xmlns="urn:n2bb:OpenStreamVODModule_v31" xmlns:ns2="urn:n2bb:OpenStreamVODTypes_v31">
<offering packageName="MyStdMOD-1" serviceName="MOD" modifiedTime="2012-05-16T16:23:17.717Z" createTime="2012-05-09T17:07:48.000Z" expirationDate="2012-11-07T07:00:00.000Z" startDate="2004-01-01T07:00:00.000Z" rentalDuration="86400" price="0" serviceType="MOD" type="MOD" offeringId="37963">
<ns2:description>MyStdMOD-1 TITLE Title</ns2:description>
<ns2:metadataOverrides>
<ns2:asset>
<ns2:providerId>arrivo.com</ns2:providerId>
<ns2:assetId>BDTL0001336583264616</ns2:assetId>
</ns2:asset>
<ns2:metadata value="/B1/B2/B3" name="MOD::Category"/>
<ns2:metadata value="/A1/A2/A3" name="MOD::Category"/>
<ns2:metadata value="/C1/C2/C3" name="MOD::Category"/>
<ns2:metadata value="/All Movies" name="MOD::Category"/>
</ns2:metadataOverrides>
<ns2:offeringRef>37964</ns2:offeringRef>
<ns2:packageAsset assetId="BDPK0001336583264616" providerId="arrivo.com" assetName="MyStdMOD-1" assetClass="PackageAsset">
<ns2:metadata value="arrivo1" name="MOD::Provider_Content_Tier"/>
<ns2:metadata value="MOD" name="AMS::Product"/>
<ns2:metadata value="2004-11-22" name="AMS::Creation_Date"/>
</ns2:packageAsset>
<ns2:titleAsset releaseYear="2003" rating="PG-13" runTime="3671" shortTitle="MyStdMOD-1" title="MyStdMOD-1 TITLE Title" assetId="BDTL0001336583264616" providerId="arrivo.com" assetName="arrivo.com::BDTL0001336583264616" assetClass="TitleAsset">
<ns2:metadata value="N" name="MOD::Closed_Captioning"/>
<ns2:metadata value="TITLE Episode Brief" name="MOD::Episode_Name"/>
<ns2:description>This is the TITLE Summary Short</ns2:description>
<ns2:actor>Nick Actor</ns2:actor>
<ns2:actor>Mark Actor</ns2:actor>
<ns2:actor>Wilma Actor</ns2:actor>
<ns2:actor>Lana Actor</ns2:actor>
</ns2:titleAsset>
<ns2:movieAsset bitRate="0" releaseYear="2003" rating="PG-13" runTime="3671" shortTitle="MyStdMOD-1" title="MyStdMOD-1 TITLE Title" assetId="BDMV0001336583264616" providerId="arrivo.com" assetName="arrivo.com::BDMV0001336583264616" assetClass="MovieAsset">
<ns2:metadata value="fr" name="MOD::Dubbed_Languages"/>
<ns2:actor>Nick Actor</ns2:actor>
<ns2:actor>Mark Actor</ns2:actor>
<ns2:actor>Wilma Actor</ns2:actor>
<ns2:actor>Lana Actor</ns2:actor>
</ns2:movieAsset>
<ns2:viewingWindow>
<ns2:startDate>2004-01-01T07:00:00.000Z</ns2:startDate>
<ns2:endDate>2012-11-07T07:00:00.000Z</ns2:endDate>
</ns2:viewingWindow>
<ns2:deliveryType>
<ns2:deliveryMethod>dsmcc-openstream-streaming</ns2:deliveryMethod>
<ns2:deliverableAssetClass>
<ns2:assetClass>MovieAsset</ns2:assetClass>
</ns2:deliverableAssetClass>
</ns2:deliveryType>
<ns2:deliveryType>
<ns2:deliveryMethod>rtsp-openstream-streaming</ns2:deliveryMethod>
<ns2:deliverableAssetClass>
<ns2:assetClass>MovieAsset</ns2:assetClass>
</ns2:deliverableAssetClass>
</ns2:deliveryType>
</offering>
</GetCatalogOfferingResponse>
</env:Body>
</env:Envelope>