Skip to content

Commit

Permalink
Test/updated tests (#4502)
Browse files Browse the repository at this point in the history
* updated tests

* form data for another app
  • Loading branch information
jeevananthank authored Jul 7, 2020
1 parent fe4d456 commit dfa0ea4
Show file tree
Hide file tree
Showing 22 changed files with 370 additions and 252 deletions.
2 changes: 1 addition & 1 deletion src/test/K6/src/api/app/instantiation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function beforeInstanceCreation(altinnStudioRuntimeCookie, partyId, appOw
req = [
{
"method": "get",
"url": config.appApiBaseUrl(appOwner, appName) + config.appResources["textresources"],
"url": config.appApiBaseUrl(appOwner, appName) + config.appResources["texts"] + "nb",
"params": requestParams
},{
"method": "get",
Expand Down
10 changes: 10 additions & 0 deletions src/test/K6/src/api/app/texts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import http from "k6/http";
import * as config from "../../config.js";
import * as header from "../../buildrequestheaders.js"

//Api call to App Api:Texts to get app texts based on language
export function getAppTexts(altinnStudioRuntimeCookie, appOwner, appName, language){
var endpoint = config.appApiBaseUrl(appOwner, appName) + config.appResources["texts"] + language,
var params = header.buildHearderWithRuntime(altinnStudioRuntimeCookie, "app");
return http.get(endpoint, params);
};
7 changes: 0 additions & 7 deletions src/test/K6/src/api/storage/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,4 @@ export function deleteData(altinnStudioRuntimeCookie, partyId, instanceId, dataI
var endpoint = config.buildStorageUrls(partyId, instanceId, dataId, "dataid");
var params = header.buildHearderWithRuntime(altinnStudioRuntimeCookie, "platform");
return http.del(endpoint, null, params);
};

//Api call to Platform:Storage to confirm all the data elements has been downloaded
export function putConfirmDownloadAll(altinnStudioRuntimeCookie, partyId, instanceId){
var endpoint = config.buildStorageUrls(partyId, instanceId, "", "confirmdownloadall");
var params = header.buildHearderWithRuntime(altinnStudioRuntimeCookie, "platform");
return http.put(endpoint, null , params);
};
8 changes: 0 additions & 8 deletions src/test/K6/src/api/storage/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,3 @@ export function getEvent(altinnStudioRuntimeCookie, partyId, instanceId, eventId
var params = header.buildHearderWithRuntime(altinnStudioRuntimeCookie, "platform");
return http.get(endpoint, params);
};


//Api call to Platform:Storage to Delete all events from an instance
export function deleteEvent(altinnStudioRuntimeCookie, partyId, instanceId){
var endpoint = config.buildStorageUrls(partyId, instanceId, "", "events");
var params = header.buildHearderWithRuntime(altinnStudioRuntimeCookie, "platform");
return http.del(endpoint, null, params);
};
8 changes: 3 additions & 5 deletions src/test/K6/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ export function buildStorageUrls(instanceOwnerId, instanceId, dataId, type){
break;
case "process":
value = platformStorage["instances"] + "/" + instanceOwnerId + "/" + instanceId + "/process";
break;
case "confirmdownloadall":
value = platformStorage["instances"] + "/" + instanceOwnerId + "/" + instanceId + "/dataelements/confirmDownload";
break;
break;
case "completeconfirmation":
value = platformStorage["instances"] + "/" + instanceOwnerId + "/" + instanceId + "/complete";
break;
Expand Down Expand Up @@ -138,7 +135,8 @@ export var appResources = {
"servicemetadata": "/api/metadata/ServiceMetaData",
"formlayout": "/api/resource/FormLayout.json",
"rulehandler": "/api/resource/RuleHandler.js",
"ruleconfiguration": "/api/resource/RuleConfiguration.json"
"ruleconfiguration": "/api/resource/RuleConfiguration.json",
"texts": "/api/v1/texts/"
};

//App Authorization
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions src/test/K6/src/data/apps-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<Skjema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" skjemanummer="1472" spesifikasjonsnummer="9812" blankettnummer="AFP-01" tittel="Arbeidsgiverskjema AFP" gruppeid="8818">
<OpplysningerOmArbeidstakeren-grp-8819 gruppeid="8819">
<Skjemainstans-grp-8854 gruppeid="8854">
<Journalnummer-datadef-33316 orid="33316">98274</Journalnummer-datadef-33316>
</Skjemainstans-grp-8854>
</OpplysningerOmArbeidstakeren-grp-8819>
</Skjema>
2 changes: 1 addition & 1 deletion src/test/K6/src/tests/app/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const userName = __ENV.username;
const userPassword = __ENV.userpwd;
const appOwner = __ENV.org;
const level2App = __ENV.level2app;
let instanceFormDataXml = open("../../data/instanceformdata.xml");
let instanceFormDataXml = open("../../data/"+ level2App +".xml");
let pdfAttachment = open("../../data/test_file_pdf.pdf", "b");


Expand Down
2 changes: 1 addition & 1 deletion src/test/K6/src/tests/app/e2erf0002.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const level2App = __ENV.level2app;
const environment = (__ENV.env).toLowerCase();
const fileName = "users_"+ environment +".json";

let instanceFormDataXml = open("../../data/rf-0002.xml");
let instanceFormDataXml = open("../../data/"+ level2App +".xml");
let users = JSON.parse(open("../../data/" + fileName));
const usersCount = users.length;

Expand Down
2 changes: 1 addition & 1 deletion src/test/K6/src/tests/app/end2end.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const userName = __ENV.username;
const userPassword = __ENV.userpwd;
const appOwner = __ENV.org;
const level2App = __ENV.level2app;
let instanceFormDataXml = open("../../data/instanceformdata.xml");
let instanceFormDataXml = open("../../data/"+ level2App +".xml");
let pdfAttachment = open("../../data/test_file_pdf.pdf", "b");
let bigAttachment = open("../../data/test_file_morethan_1mb.txt", "b");

Expand Down
141 changes: 141 additions & 0 deletions src/test/K6/src/tests/app/portalsimulation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
Create and archive instances of T3.0 apps with attachment component and simulate all the api calls from portal
example: k6 run -i 20 --duration 1m /src/tests/app/portalsimulation.js -e env=test -e org=ttd -e level2app=apps-test -e subskey=*** -e sblaccesskey=*** -e username=*** -e userpwd=***
*/

import { check } from "k6";
import {addErrorCount, printResponseToConsole} from "../../errorcounter.js";
import * as appInstances from "../../api/app/instances.js"
import * as appData from "../../api/app/data.js"
import * as appProcess from "../../api/app/process.js"
import * as platformInstances from "../../api/storage/instances.js"
import * as platformApps from "../../api/storage/applications.js"
import * as setUpData from "../../setup.js";
import * as appInstantiation from "../../api/app/instantiation.js"
import * as appResources from "../../api/app/resources.js"

const userName = __ENV.username;
const userPassword = __ENV.userpwd;
const appOwner = __ENV.org;
const level2App = __ENV.level2app;

let instanceFormDataXml = open("../../data/"+ level2App +".xml");
let pdfAttachment = open("../../data/test_file_pdf.pdf", "b");

export const options = {
thresholds:{
"errors": ["count<1"]
},
setupTimeout: '1m'
};

//Function to setup data and return AltinnstudioRuntime Token
export function setup(){
var aspxauthCookie = setUpData.authenticateUser(userName, userPassword);
var altinnStudioRuntimeCookie = setUpData.getAltinnStudioRuntimeToken(aspxauthCookie);
var data = setUpData.getUserData(altinnStudioRuntimeCookie, appOwner, level2App);
data.RuntimeToken = altinnStudioRuntimeCookie;
setUpData.clearCookies();
return data;
};

//Tests for App API : Portal simulation
export default function(data) {
const runtimeToken = data["RuntimeToken"];
const partyId = data["partyId"];
var instanceId, dataId, res, success, attachmentDataType;

//Batch api calls before creating an app instance
res = appInstantiation.beforeInstanceCreation(runtimeToken, partyId, appOwner, level2App);
for(var i = 0; i < res.length; i++){
success = check(res[i], {
"Batch request before app Instantiation:": (r) => r.status === 200
});
addErrorCount(success);
printResponseToConsole("Batch request before app Instantiation:", success, res[i]);
};

attachmentDataType = platformApps.findAttachmentDataType(res[2].body);

//Test to create an instance with App api and validate the response
res = appInstances.postInstance(runtimeToken, partyId, appOwner, level2App);
success = check(res, {
"E2E App POST Create Instance status is 201:": (r) => r.status === 201
});
addErrorCount(success);
printResponseToConsole("E2E App POST Create Instance:", success, res);

try {
dataId = appData.findDataId(res.body);
instanceId = platformInstances.findInstanceId(res.body);
} catch (error) {
printResponseToConsole("Instance id and data id not retrieved:", false , null);
};

//Test to get the current process of an app instance
res = appProcess.getCurrentProcess(runtimeToken, partyId, instanceId, appOwner, level2App);
success = check(res, {
"Get Current process of instance:": (r) => r.status === 200
});
addErrorCount(success);
printResponseToConsole("Get Current process of instance:", success, res);

//Test to get the form data xml by id
res = appData.getDataById(runtimeToken, partyId, instanceId, dataId, appOwner, level2App);
success = check(res, {
"Get form data XML by id:": (r) => r.status === 200
});
addErrorCount(success);
printResponseToConsole("Get form data XML by id:", success, res);

//Batch request to get the app resources
res = appResources.batchGetAppResources(runtimeToken, appOwner, level2App);
for(var i = 0; i < res.length; i++){
success = check(res[i], {
"Batch request to get app resources:": (r) => r.status === 200
});
addErrorCount(success);
printResponseToConsole("Batch request to get app resources:", success, res[i]);
};

//Test to edit a form data in an instance with App APi and validate the response

res = appData.putDataById(runtimeToken, partyId, instanceId, dataId, "default", instanceFormDataXml, appOwner, level2App);
success = check(res, {
"E2E PUT Edit Data by Id status is 201:": (r) => r.status === 201
});
addErrorCount(success);
printResponseToConsole("E2E PUT Edit Data by Id:", success, res);

//upload a valid attachment to an instance with App API
res = appData.postData(runtimeToken, partyId, instanceId, attachmentDataType, pdfAttachment, appOwner, level2App);
success = check(res, {
"E2E POST Upload Data status is 201:": (r) => r.status === 201
});
addErrorCount(success);
printResponseToConsole("E2E POST Upload Data:", success, res);

//Test to get validate instance and verify that validation of instance is ok
res = appInstances.getValidateInstance(runtimeToken, partyId, instanceId, appOwner, level2App);
success = check(res, {
"E2E App GET Validate Instance validation OK:": (r) => r.body && (JSON.parse(r.body)).length === 0
});
addErrorCount(success);
printResponseToConsole("E2E App GET Validate Instance is not OK:", success, res);

//Test to move the process of an app instance to the next process element and verify response code to be 200
res = appProcess.putNextProcess(runtimeToken, partyId, instanceId, "EndEvent_1", appOwner, level2App);
success = check(res, {
"E2E App PUT Move process to Next element status is 200:": (r) => r.status === 200
});
addErrorCount(success);
printResponseToConsole("E2E App PUT Move process to Next element:", success, res);

//Test to call get instance details and verify the presence of archived date
res = appInstances.getInstanceById(runtimeToken, partyId, instanceId, appOwner, level2App);
success = check(res, {
"E2E App Instance is archived:": (r) => r.body.length > 0 && (JSON.parse(r.body)).status.archived != null
});
addErrorCount(success);
printResponseToConsole("E2E App Instance is not archived:", success, res);
};
2 changes: 1 addition & 1 deletion src/test/K6/src/tests/app/rf0002portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const level2App = __ENV.level2app;
const environment = (__ENV.env).toLowerCase();
const fileName = "users_"+ environment +".json";

let instanceFormDataXml = open("../../data/rf-0002.xml");
let instanceFormDataXml = open("../../data/"+ level2App +".xml");
let users = JSON.parse(open("../../data/" + fileName));
const usersCount = users.length;

Expand Down
2 changes: 1 addition & 1 deletion src/test/K6/src/tests/app/rf0002withattachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as apps from "../../api/storage/applications.js"
import {deleteSblInstance} from "../../api/storage/messageboxinstances.js"
import * as setUpData from "../../setup.js";

const instanceFormDataXml = open("../../data/rf-0002.xml");
const instanceFormDataXml = open("../../data/"+ level2App +".xml");
const appOwner = __ENV.org;
const level2App = __ENV.level2app;
const environment = (__ENV.env).toLowerCase();
Expand Down
2 changes: 1 addition & 1 deletion src/test/K6/src/tests/app/uploadanddownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import * as storageData from "../../api/storage/data.js"
import {deleteSblInstance} from "../../api/storage/messageboxinstances.js"
import * as setUpData from "../../setup.js";

const instanceFormDataXml = open("../../data/rf-0002.xml");
const instanceFormDataXml = open("../../data/"+ level2App +".xml");
const appOwner = __ENV.org;
const level2App = __ENV.level2app;
const environment = (__ENV.env).toLowerCase();
Expand Down
2 changes: 1 addition & 1 deletion src/test/K6/src/tests/platform/storage/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const userPassword = __ENV.userpwd;
const appOwner = __ENV.org;
const level2App = __ENV.level2app;
let instanceJson = open("../../../data/instance.json");
let instanceFormDataXml = open("../../../data/instanceformdata.xml");
let instanceFormDataXml = open("../../../data/"+ level2App +".xml");
let pdfAttachment = open("../../../data/test_file_pdf.pdf", "b");

export const options = {
Expand Down
8 changes: 0 additions & 8 deletions src/test/K6/src/tests/platform/storage/downloadinstances.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,6 @@ export default function(data){
printResponseToConsole("Instance Data is not downloaded:", success, res);
};

//Confirm that all the dataelements are downloaded by the appOwner
res = storageData.putConfirmDownloadAll(runtimeToken, partyId, instanceId);
success = check(res, {
"Instance Data download is confirmed:": (r) => r.status === 200
});
addErrorCount(success);
printResponseToConsole("Instance Data download is not confirmed:", success, res);

//Complete confirm the app instance as an appOwner
res = storageInstances.postCompleteConfirmation(runtimeToken, partyId, instanceId);
success = check(res, {
Expand Down
8 changes: 1 addition & 7 deletions src/test/K6/src/tests/platform/storage/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@ export default function(data) {
"GET Instance Events by EventType status is 200:": (r) => r.status === 200
});
addErrorCount(success);

//Test to delete all instance events from an instance with storage api and validate the response
res = events.deleteEvent(runtimeToken, partyId, instanceId);
success = check(res, {
"DELETE All Instance Events status is 200:": (r) => r.status === 200
});
addErrorCount(success);

};

//Delete the instance created
Expand Down
2 changes: 1 addition & 1 deletion src/test/K6/src/tests/platform/storage/rf0002.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const level2App = __ENV.level2app;
const environment = (__ENV.env).toLowerCase();
const fileName = "users_"+ environment +".json";

let instanceFormDataXml = open("../../../data/rf-0002.xml");
let instanceFormDataXml = open("../../../data/"+ level2App +".xml");
let instanceJson = open("../../../data/instance.json");
let users = JSON.parse(open("../../data/" + fileName));
const usersCount = users.length;
Expand Down
Loading

0 comments on commit dfa0ea4

Please sign in to comment.