Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getHierarchy FT #255

Open
wants to merge 9 commits into
base: kp-test
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
gethierarchy ft
neha0305verma committed Dec 27, 2019
commit 30412c82204b607e9b828828b381f19c1a9cb55d
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ public class BaseCitrusTestRunner extends TestNGCitrusTestRunner {
public static final String REQUEST_JSON = "request.json";
public static final String RESPONSE_JSON = "response.json";
public static final String VALIDATE_JSON = "validate.json";
public static final String RESPONSE_JSON_IMAGE = "response_image.json";

private static final String API_KEY = AppConfig.config.getString("kp_api_key");
private static final Boolean IS_USER_AUTH_REQUIRED = AppConfig.config.getBoolean("user_auth_enable");
Original file line number Diff line number Diff line change
@@ -477,16 +477,6 @@ public class ContentV3Scenario {
public static final String TEST_GET_HIERARCHY_AFTER_FLAG_ACCEPT = "testGetHierarchyAfterFlagAccept";
public static final String TEST_GET_HIERARCHY_AFTER_DISCARD = "testGetHierarchyAfterDiscard";
public static final String TEST_GET_HIERARCHY_AFTER_RETIRE = "testGetHierarchyAfterRetire";
public static final String TEST_GET_HIERARCHY_AFTER_UPDATE_LIVE = "testGetHierarchyAfterRetire";
public static final String TEST_GET_HIERARCHY_BEFORE_UPDATE_WITH_MODE = "testGetHierarchyBeforeUpdateWithMode";
public static final String TEST_GET_HIERARCHY_AFTER_UPDATE_WITH_MODE = "testGetHierarchyAfterUpdateWithMode";
public static final String TEST_GET_HIERARCHY_AFTER_REVIEW_WITH_MODE = "testGetHierarchyAfterReviewWithMode";
public static final String TEST_GET_HIERARCHY_AFTER_REJECT_WITH_MODE = "testGetHierarchyAfterRejectWithMode";
public static final String TEST_GET_HIERARCHY_AFTER_FLAG_WITH_MODE = "testGetHierarchyAfterFlagWithMode";
public static final String TEST_GET_HIERARCHY_AFTER_FLAG_REJECT_WITH_MODE = "testGetHierarchyAfterFlagRejectWithMode";
public static final String TEST_GET_HIERARCHY_AFTER_FLAG_ACCEPT_WITH_MODE = "testGetHierarchyAfterFlagAcceptWithMode";
public static final String TEST_GET_HIERARCHY_AFTER_DISCARD_WITH_MODE = "testGetHierarchyAfterDiscardWithMode";
public static final String TEST_GET_HIERARCHY_AFTER_RETIRE_WITH_MODE = "testGetHierarchyAfterRetireWithMode";
public static final String TEST_GET_HIERARCHY_AFTER_UPDATE_LIVE_WITH_MODE = "testGetHierarchyAfterRetireWithMode";
public static final String TEST_GET_HIERARCHY_AFTER_UPDATE_LIVE = "testGetHierarchyAfterUpdateLive";
}

Original file line number Diff line number Diff line change
@@ -34,19 +34,16 @@ public class getHierarchyTest extends BaseCitrusTestRunner {
// @AfterClass
// public static void populateAssertionData() {
// TestSetupUtil.createDirectoriesForTestCases(dirIdMap, "response.json", TEMPLATE_DIR);
//// TestSetupUtil.createDirectoriesForTestCases(dirIdMap, "response_image.json", TEMPLATE_DIR);
// }

@Test(dataProvider = "getHierarchyWithValidRequest")
@CitrusParameters ({"testName", "workFlowStatus", "payload", "collectionType", "resourceCount", "publish"})
@CitrusParameters ({"testName", "workFlowStatus", "payload", "collectionType", "resourceCount"})
@CitrusTest
public void getHierarchyWithValidRequest(String testName, String workFlowStatus, String payload, String collectionType, Integer resourceCount, Boolean publish) {
public void getHierarchyWithValidRequest(String testName, String workFlowStatus, String payload, String collectionType, Integer resourceCount) {
Map<String, Object> collectionMap = CollectionUtil.prepareTestCollection(workFlowStatus, this, new HashMap<String,String>() {{put("updateHierarchy", payload);}}, collectionType, 0, resourceCount, "application/vnd.ekstep.ecml-archive");
identifier = (String) collectionMap.get("content_id");
if(publish){
ContentUtil.publishContent(this, null, "public", identifier, null);
}
this.variable("rootId", identifier);
//dirIdMap.put(testName, identifier);
performGetTest(
this,
TEMPLATE_DIR,
@@ -66,7 +63,7 @@ public void getHierarchyWithInvalidRequest(String testName, String workFlowStatu
Map<String, Object> collectionMap = CollectionUtil.prepareTestCollection(workFlowStatus, this,
new HashMap<String,String>() {{put("updateHierarchy", payload);}}, collectionType, 0, resourceCount, "application/vnd.ekstep.ecml-archive");
identifier = (String) collectionMap.get("content_id");
ContentUtil.publishContent(this, null, "public", identifier, null);
//ContentUtil.publishContent(this, null, "public", identifier, null);
performGetTest(
this,
TEMPLATE_DIR,
@@ -100,11 +97,12 @@ public void getHierarchyWithMode(String testName, String workFlowStatus, String
);
}

@Test(dataProvider = "getHierarchyWithDifferentStatusWithoutMode")
@Test(dataProvider = "getHierarchyWithDifferentStatus")
@CitrusParameters ({"testName", "workFlowStatus", "payload", "collectionType", "resourceCount"})
@CitrusTest
public void getHierarchyWithDifferentStatusWithoutMode(String testName, String workFlowStatus, String payload, String collectionType, Integer resourceCount) {
Map<String, Object> collectionMap = CollectionUtil.prepareTestCollectionWithoutUpdateHierarchy(workFlowStatus, this,null, collectionType, 0, resourceCount, "application/vnd.ekstep.ecml-archive");
public void getHierarchyWithDifferentStatus(String testName, String workFlowStatus, String payload, String collectionType, Integer resourceCount) {
Map<String, Object> collectionMap = CollectionUtil.prepareTestCollection(workFlowStatus, this,
new HashMap<String,String>() {{put("updateHierarchy", payload);}}, collectionType, 0, resourceCount, "application/vnd.ekstep.ecml-archive");
identifier = (String) collectionMap.get("content_id");
this.variable("rootId", identifier);
//dirIdMap.put(testName, identifier);
@@ -114,48 +112,58 @@ public void getHierarchyWithDifferentStatusWithoutMode(String testName, String w
testName,
APIUrl.READ_CONTENT_HIERARCHY + identifier,
null,
HttpStatus.OK,
HttpStatus.NOT_FOUND,
null,
RESPONSE_JSON
);
// performGetTest(
// this,
// TEMPLATE_DIR,
// testName,
// APIUrl.READ_CONTENT_HIERARCHY + identifier + MODE + "edit",
// null,
// HttpStatus.OK,
// null,
// RESPONSE_JSON_IMAGE
// );
}

@Test(dataProvider = "getHierarchyWithDifferentStatusWithMode")
@CitrusParameters ({"testName", "workFlowStatus", "payload", "collectionType", "resourceCount", "mode"})
@Test
@CitrusTest
public void getHierarchyWithDifferentStatusWithMode(String testName, String workFlowStatus, String payload, String collectionType, Integer resourceCount, String mode) {
Map<String, Object> collectionMap = CollectionUtil.prepareTestCollectionWithoutUpdateHierarchy(workFlowStatus, this,null, collectionType, 0, resourceCount, "application/vnd.ekstep.ecml-archive");
public void getHierarchyAfterReview(){
Map<String, Object> collectionMap = CollectionUtil.prepareTestCollection("collectionReview", this,
new HashMap<String,String>() {{put("updateHierarchy", CollectionUtilPayload.UPDATE_HIERARCHY_1_UNIT_1_RESOURCE);}}, "textBook", 0, 1, "application/vnd.ekstep.ecml-archive");
identifier = (String) collectionMap.get("content_id");
this.variable("rootId", identifier);
//dirIdMap.put(testName, identifier);
performGetTest(
this,
TEMPLATE_DIR,
testName,
APIUrl.READ_CONTENT_HIERARCHY + identifier + MODE + mode,
ContentV3Scenario.TEST_GET_HIERARCHY_AFTER_REVIEW,
APIUrl.READ_CONTENT_HIERARCHY + identifier,
null,
HttpStatus.OK,
HttpStatus.NOT_FOUND,
null,
RESPONSE_JSON
);
performGetTest(
this,
TEMPLATE_DIR,
ContentV3Scenario.TEST_GET_HIERARCHY_AFTER_REVIEW,
APIUrl.READ_CONTENT_HIERARCHY + identifier + MODE + "edit",
null,
HttpStatus.OK,
null,
RESPONSE_JSON_IMAGE
);
}


@DataProvider
public static Object[][] getHierarchyWithValidRequest() {
return new Object[][]{
new Object[]{
ContentV3Scenario.TEST_GET_HIERARCHY_WITH_VALID_IDENTIFIER, "collectionUnitsInLive", CollectionUtilPayload.UPDATE_HIERARCHY_1_UNIT_1_RESOURCE, "textBook", 1, true
},
new Object[]{
ContentV3Scenario.TEST_GET_HIERARCHY_AFTER_UPDATE, "collectionUnitsInDraft", CollectionUtilPayload.UPDATE_HIERARCHY_1_UNIT_1_RESOURCE, "textBook", 1, true
},
new Object[]{
ContentV3Scenario.TEST_GET_HIERARCHY_AFTER_REVIEW, "collectionReview", CollectionUtilPayload.UPDATE_HIERARCHY_1_UNIT_1_RESOURCE, "textBook", 1, false
},
new Object[]{
ContentV3Scenario.TEST_GET_HIERARCHY_AFTER_RETIRE, "collectionRetire", CollectionUtilPayload.UPDATE_HIERARCHY_1_UNIT_1_RESOURCE, "textBook", 1, false
}

};
}

@@ -182,33 +190,24 @@ public static Object[][] getHierarchyWithMode() {
},
new Object[]{
ContentV3Scenario.TEST_GET_HIERARCHY_WITH_NULL_MODE, "collectionUnitsInLive", CollectionUtilPayload.UPDATE_HIERARCHY_1_UNIT_1_RESOURCE, "textBook", 1, null
},
new Object[]{
ContentV3Scenario.TEST_GET_HIERARCHY_AFTER_UPDATE_WITH_MODE, "collectionUnitsInDraft", CollectionUtilPayload.UPDATE_HIERARCHY_1_UNIT_1_RESOURCE, "textBook", 1, "edit"
},
new Object[]{
ContentV3Scenario.TEST_GET_HIERARCHY_AFTER_REVIEW_WITH_MODE, "collectionReview", CollectionUtilPayload.UPDATE_HIERARCHY_1_UNIT_1_RESOURCE, "textBook", 1, "edit"
},
new Object[]{
ContentV3Scenario.TEST_GET_HIERARCHY_AFTER_RETIRE_WITH_MODE, "collectionRetire", CollectionUtilPayload.UPDATE_HIERARCHY_1_UNIT_1_RESOURCE, "textBook", 1, "edit"
}
};
}

@DataProvider
public static Object[][] getHierarchyWithDifferentStatusWithoutMode() {
return new Object[][]{
new Object[]{
ContentV3Scenario.TEST_GET_HIERARCHY_BEFORE_UPDATE, "collectionCreate", null, "textBook", 1
}
};
}

@DataProvider
public static Object[][] getHierarchyWithDifferentStatusWithMode() {
public static Object[][] getHierarchyWithDifferentStatus() {
return new Object[][]{
// new Object[]{
// ContentV3Scenario.TEST_GET_HIERARCHY_AFTER_UPDATE, "collectionUnitsInDraft", CollectionUtilPayload.UPDATE_HIERARCHY_1_UNIT_1_RESOURCE, "textBook", 1
// },
// new Object[]{
// ContentV3Scenario.TEST_GET_HIERARCHY_AFTER_RETIRE, "collectionRetire", CollectionUtilPayload.UPDATE_HIERARCHY_1_UNIT_1_RESOURCE, "textBook", 1
// },
// new Object[]{
// ContentV3Scenario.TEST_GET_HIERARCHY_BEFORE_UPDATE, "collectionCreate", null, "textBook", 1
// },
new Object[]{
ContentV3Scenario.TEST_GET_HIERARCHY_BEFORE_UPDATE_WITH_MODE, "collectionCreate", null, "textBook", 1, "edit"
ContentV3Scenario.TEST_GET_HIERARCHY_AFTER_FLAG, "collectionInFlagged", CollectionUtilPayload.UPDATE_HIERARCHY_1_UNIT_1_RESOURCE, "textBook", 1
}
};
}
Original file line number Diff line number Diff line change
@@ -120,54 +120,4 @@ public static List<String> getLiveAsset(BaseCitrusTestRunner runner, Integer ass
});
return assetIds;
}

/**
* This method will add resources or asset to a Payload collection provided as user's requirements.
* The number of asset or resources to be created should be equal to the placeholders in the dynamic payload.
* <p>
* Resource placeholder should be resource_N, for eg: resource_1
* Asset placeholder should be resource_N for eg: asset_2.
*
* @param workFlow (Mandatory)
* @param runner
* @param payloadMap (Mandatory -> Send new HashMap with (updateHierarchy -> Payload String), If you want to custom resource, pass createResource)
* @param collectionType (For valid collection type see ContentUtil)
* @param assetCount (Number of assets that are needed to replace in the payload)
* @param resourceCount (Number of resources that are needed to replace in the payload
* @param mimeType (This field is optional and can be passed as null for random valid mimeType generation
* @return a map of all the resources/assets added, all unit identifiers and textBook identifier
* @see ContentUtil
*/
public static Map<String, Object> prepareTestCollectionWithoutUpdateHierarchy(String workFlow, BaseCitrusTestRunner runner, Map<String, String> payloadMap, String collectionType,
Integer assetCount, Integer resourceCount, String mimeType) {
Map<String, Object> collectionMap = new HashMap<>();
collectionMap.putAll(ContentUtil.createCollectionContent(runner, null, collectionType, null));

//Map also has identifiers which is a map of all id's of unit's etc TODO: Return that too
String contentId = (String) collectionMap.get("content_id");
runner.variable("collectionIdVal", contentId);
runner.variable("versionKey", collectionMap.get("versionKey"));
Map collectionWorkMap = null;
try {
collectionWorkMap = mapper.readValue(WorkflowConstants.collectionWorkFlows, new TypeReference<Map<String, Object>>() {
});
List contentWorkList = (List<String>) collectionWorkMap.get(workFlow);
Map<String, Supplier<Map<String, Object>>> actionMap = ContentUtil.getCollectionWorkFlowMap(runner, contentId, null, null, null);
if (!CollectionUtils.isEmpty(contentWorkList)) {
contentWorkList.forEach(action -> {
Map response = actionMap.get(action).get();
if (response.get("content") != null)
response = (Map<String, Object>) response.get("content");
if( null != response.get("identifiers"))
collectionMap.put("identifiers", response.get("identifiers"));
if (StringUtils.isNotBlank((String) response.get("versionKey")))
runner.variable("versionKeyVal", response.get("versionKey"));
});
}
} catch (IOException e) {
e.printStackTrace();
}
// collectionMap = ContentUtil.readCollectionHierarchy(runner, contentId)
return collectionMap;
}
}
Original file line number Diff line number Diff line change
@@ -40,7 +40,8 @@ public class WorkflowConstants {
"\"collectionUnitsResourcesInDraft\":[\"CreateResources\", \"Update\"],\n" +
"\"collectionCreate\":[\"Create\"],\n"+
"\"collectionReview\":[\"Update\", \"Review\"],\n"+
"\"collectionRetire\":[\"Update\", \"Publish\", \"Retire\"]\n"+
"\"collectionRetire\":[\"Update\", \"Publish\", \"Retire\"],\n"+
"\"collectionInFlagged\":[\"Update\", \"Publish\", \"Flag\"]\n"+
"}";
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"id" : "api.content.hierarchy.get",
"ver" : "3.0",
"ts" : "@matchesDatePattern('yyyy-MM-dd')@",
"params" : {
"resmsgid" : "@ignore@",
"msgid" : null,
"err" : null,
"status" : "successful",
"errmsg" : null
},
"responseCode" : "OK",
"result" : {
"content" : {
"lastStatusChangedOn" : "@matchesDatePattern('yyyy-MM-dd')@",
"children" : [ {
"parent" : "@ignore@",
"identifier" : "@ignore@",
"lastStatusChangedOn" : "@matchesDatePattern('yyyy-MM-dd')@",
"code" : "@ignore@",
"visibility" : "Parent",
"description" : "@ignore@",
"index" : 1,
"mimeType" : "application/vnd.ekstep.content-collection",
"createdOn" : "@matchesDatePattern('yyyy-MM-dd')@",
"versionKey" : "@ignore@",
"depth" : 1,
"children" : [ ],
"name" : "@ignore@",
"lastUpdatedOn" : "@matchesDatePattern('yyyy-MM-dd')@",
"contentType" : "TextBook",
"status" : "Live",
"compatibilityLevel" : "@isNumber()@",
"lastPublishedOn" : "@matchesDatePattern('yyyy-MM-dd')@",
"pkgVersion" : "@isNumber()@",
"leafNodesCount" : "@isNumber()@",
"downloadUrl" : "@ignore@",
"variants" : "@ignore@"
} ],
"mediaType" : "content",
"name" : "KP Integration Test Collection Content",
"toc_url" : "@ignore@",
"createdOn" : "@matchesDatePattern('yyyy-MM-dd')@",
"channel" : "channel-01",
"lastUpdatedOn" : "@matchesDatePattern('yyyy-MM-dd')@",
"size" : "@isNumber()@",
"identifier" : "${rootId}",
"description" : "KP Integration Test Collection Content",
"ownershipType" : [ "createdBy" ],
"compatibilityLevel" : "@isNumber()@",
"audience" : [ "Learner" ],
"os" : [ "All" ],
"SYS_INTERNAL_LAST_UPDATED_ON" : "@matchesDatePattern('yyyy-MM-dd')@",
"downloadUrl" : "@ignore@",
"framework" : "NCF",
"totalCompressedSize" : "@isNumber()@",
"versionKey" : "@ignore@",
"mimeType" : "application/vnd.ekstep.content-collection",
"code" : "kp.ft.collection.textbook",
"license" : "CC BY 4.0",
"version" : "@isNumber()@",
"contentType" : "TextBook",
"language" : [ "English" ],
"lastPublishedOn" : "@matchesDatePattern('yyyy-MM-dd')@",
"contentTypesCount" : "{\"TextBook\":1}",
"objectType" : "Content",
"lastUpdatedBy" : "KP_FT_PUBLISHER",
"status" : "Live",
"publisher" : "KP_FT_PUBLISHER",
"publishComment" : "OK",
"dialcodeRequired" : "No",
"idealScreenSize" : "normal",
"contentEncoding" : "gzip",
"leafNodesCount" : "@isNumber()@",
"depth" : 0,
"consumerId" : "@ignore@",
"lastPublishedBy" : "KP_FT_PUBLISHER",
"mimeTypesCount" : "{\"application/vnd.ekstep.content-collection\":1}",
"osId" : "org.ekstep.quiz.app",
"s3Key" : "@ignore@",
"contentDisposition" : "inline",
"childNodes" : "@ignore@",
"visibility" : "Default",
"variants" : {
"online" : {
"ecarUrl" : "@ignore@",
"size" : "@isNumber()@"
},
"spine" : {
"ecarUrl" : "@ignore@",
"size" : "@isNumber()@"
}
},
"pkgVersion" : "@isNumber()@",
"idealScreenDensity" : "hdpi"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "api.content.hierarchy.get",
"ver": "3.0",
"ts": "@matchesDatePattern('yyyy-MM-dd')@",
"params": {
"resmsgid": "@ignore@",
"msgid": null,
"err": "RESOURCE_NOT_FOUND",
"status": "failed",
"errmsg": "@ignore@"
},
"responseCode": "RESOURCE_NOT_FOUND",
"result": {}
}
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@
"dialcodeRequired" : "No",
"contentType" : "Resource",
"lastUpdatedBy" : "KP_FT_PUBLISHER",
"identifier" : "${rootId}",
"identifier" : "@ignore@",
"audience" : [ "Learner" ],
"lastStatusChangedOn" : "@matchesDatePattern('yyyy-MM-dd')@",
"os" : [ "All" ],