Skip to content

Commit

Permalink
Merge pull request #114 from project-sunbird/BadgingFunctionalTestFix
Browse files Browse the repository at this point in the history
Badging functional test fix
  • Loading branch information
bvinayakumar authored Oct 10, 2018
2 parents 2243e5e + 463e306 commit 3b6459b
Show file tree
Hide file tree
Showing 14 changed files with 290 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public static String getCreateIssuerUrl(BaseCitrusTestRunner runner) {
return runner.getLmsApiUriPath("/api/badging/v1/issuer/create", "/v1/issuer/create");
}

public static String getDeleteIssuerUrl(BaseCitrusTestRunner runner, String pathParam) {
return runner.getLmsApiUriPath("/api/badging/v1/issuer/delete", "/v1/issuer/delete", pathParam);
}

public static void createIssuer(
BaseCitrusTestRunner runner,
TestContext testContext,
Expand Down Expand Up @@ -42,4 +46,22 @@ public static void createIssuer(
"$.result.issuerId",
Constant.EXTRACT_VAR_ISSUER_ID));
}

public static void deleteIssuer(
BaseCitrusTestRunner runner,
TestContext testContext,
TestGlobalProperty config,
String issuerId) {
runner.http(
builder ->
TestActionUtil.getDeleteRequestTestAction(
builder,
Constant.LMS_ENDPOINT,
null,
null,
getDeleteIssuerUrl(runner, issuerId),
null,
null,
null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.http.HttpStatus;
import org.sunbird.common.action.IssuerUtil;
import org.sunbird.common.action.OrgUtil;
import org.sunbird.common.util.Constant;
import org.sunbird.integration.test.common.BaseCitrusTestRunner;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -86,7 +87,7 @@ public void testCreateBadgeClassSuccess(String testName) {
false,
HttpStatus.OK,
RESPONSE_JSON);
afterTest();
afterTest(true);
}

@Test(dataProvider = "createBadgeClassDataProviderFailure")
Expand Down Expand Up @@ -114,14 +115,21 @@ private void beforeTest(Boolean canCreateOrg, Boolean canCreateIssuer) {
}
if (canCreateIssuer) {
IssuerUtil.createIssuer(
this,
testContext,
config,
BT_CREATE_ISSUER_TEMPLATE_DIR,
BT_TEST_NAME_CREATE_ISSUER_SUCCESS,
HttpStatus.OK);
this,
testContext,
config,
BT_CREATE_ISSUER_TEMPLATE_DIR,
BT_TEST_NAME_CREATE_ISSUER_SUCCESS,
HttpStatus.OK);
}
}

private void afterTest() {}
private void afterTest(boolean isIssuerCreated) {
if (isIssuerCreated)
IssuerUtil.deleteIssuer(
this,
testContext,
config,
(String) testContext.getVariables().get(Constant.EXTRACT_VAR_ISSUER_ID));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.sunbird.integration.test.badge;

import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.http.client.HttpClient;
import com.consol.citrus.testng.CitrusParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -29,15 +28,9 @@ public class CreateIssuerTest extends BaseCitrusTestRunner {
"testCreateIssuerFailureWithInvalidEmail";

public static final String TEMPLATE_DIR = "templates/badge/issuer/create";

public static final String RESPONSE_JSON = "response.json";

@Autowired private HttpClient restTestClient;

@Autowired private TestGlobalProperty initGlobalValues;

private String getCreateIssuerUrl() {
System.out.println("initGlobalValues = " + initGlobalValues);
return initGlobalValues.getLmsUrl().contains("localhost")
? "/v1/issuer/create"
: "/api/badging/v1/issuer/create";
Expand All @@ -46,64 +39,53 @@ private String getCreateIssuerUrl() {
@DataProvider(name = "createIssuerDataProviderSuccess")
public Object[][] createIssuerDataProviderSuccess() {
return new Object[][] {
new Object[] {REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_SUCCESS},
new Object[] {REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_SUCCESS_WITH_IMAGE}
new Object[] {TEST_NAME_CREATE_ISSUER_SUCCESS},
new Object[] {TEST_NAME_CREATE_ISSUER_SUCCESS_WITH_IMAGE}
};
}

@DataProvider(name = "createIssuerDataProviderFailure")
public Object[][] createIssuerDataProviderFailure() {
return new Object[][] {
new Object[] {REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_NAME},
new Object[] {
REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_DESCRIPTION
},
new Object[] {REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_URL},
new Object[] {
REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_URL
},
new Object[] {
REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_EMAIL
},
new Object[] {
REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_EMAIL
}
new Object[] {TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_NAME},
new Object[] {TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_DESCRIPTION},
new Object[] {TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_URL},
new Object[] {TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_URL},
new Object[] {TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_EMAIL},
new Object[] {TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_EMAIL}
};
}

@Test(dataProvider = "createIssuerDataProviderSuccess")
@CitrusParameters({"requestFormData", "responseJson", "testName"})
@CitrusParameters({"testName"})
@CitrusTest
public void testCreateIssuerSuccess(
String requestFormData, String responseJson, String testName) {
public void testCreateIssuerSuccess(String testName) {
System.out.println("initGlobalValues = " + initGlobalValues);
performMultipartTest(
this,
TEMPLATE_DIR,
testName,
getCreateIssuerUrl(),
requestFormData,
REQUEST_FORM_DATA,
null,
false,
HttpStatus.OK,
responseJson);
RESPONSE_JSON);
}

@Test(dataProvider = "createIssuerDataProviderFailure")
@CitrusParameters({"requestFormData", "responseJson", "testName"})
@CitrusParameters({"testName"})
@CitrusTest
public void testCreateIssuerFailure(
String requestFormData, String responseJson, String testName) {
System.out.println("initGlobalValues = " + initGlobalValues);
public void testCreateIssuerFailure(String testName) {
performMultipartTest(
this,
TEMPLATE_DIR,
testName,
getCreateIssuerUrl(),
requestFormData,
REQUEST_FORM_DATA,
null,
false,
HttpStatus.BAD_REQUEST,
responseJson);
RESPONSE_JSON);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.sunbird.integration.test.geolocation;

import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.testng.CitrusParameters;
import javax.ws.rs.core.MediaType;
import org.springframework.http.HttpStatus;
import org.sunbird.common.action.OrgUtil;
import org.sunbird.integration.test.common.BaseCitrusTestRunner;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class CreateGeolocationTest extends BaseCitrusTestRunner {

private static final String TEST_NAME_CREATE_GEOLOCATION_FAILURE_WITHOUT_ROOT_ORG_ID =
"testCreateGeolocationFailureWithoutRootOrgId";
private static final String TEST_NAME_CREATE_GEOLOCATION_FAILURE_WITH_EMPTY_ROOT_ORG_ID =
"testCreateGeolocationFailureWithEmptyRootOrgId";
private static final String TEST_NAME_CREATE_GEOLOCATION_FAILURE_WITH_INVALID_ROOT_ORG_ID =
"testCreateGeolocationFailureWithInvalidRootOrgId";

private static final String TEST_NAME_CREATE_GEOLOCATION_SUCCESS_WITH_ROOT_ORG_ID =
"testCreateGeolocationSuccessWithRootOrgId";
private static final String TEST_NAME_CREATE_GEOLOCATION_SUCCESS_WITH_SUB_ORG_ID =
"testCreateGeolocationSuccessWithSubOrgId";

private static final String TEMPLATE_DIR = "templates/geolocation/create";

private String getCreateGeolocationUrl() {
return getLmsApiUriPath("/api/org/v1/location/create", "/v1/notification/location/create");
}

@DataProvider(name = "createGeolocationDataProviderFailure")
public Object[][] createGeolocationDataProviderFailure() {
return new Object[][] {
new Object[] {TEST_NAME_CREATE_GEOLOCATION_FAILURE_WITHOUT_ROOT_ORG_ID},
new Object[] {TEST_NAME_CREATE_GEOLOCATION_FAILURE_WITH_EMPTY_ROOT_ORG_ID},
new Object[] {TEST_NAME_CREATE_GEOLOCATION_FAILURE_WITH_INVALID_ROOT_ORG_ID}
};
}

@DataProvider(name = "createGeolocationDataProviderSuccess")
public Object[][] createGeolocationDataProviderSuccess() {
return new Object[][] {
new Object[] {TEST_NAME_CREATE_GEOLOCATION_SUCCESS_WITH_ROOT_ORG_ID, true},
new Object[] {TEST_NAME_CREATE_GEOLOCATION_SUCCESS_WITH_SUB_ORG_ID, false}
};
}

@Test(dataProvider = "createGeolocationDataProviderSuccess")
@CitrusParameters({"testName", "canCreateRootOrg"})
@CitrusTest
public void testCreateGeolocationSuccess(String testName, boolean canCreateRootOrg) {
beforeTest(testName, canCreateRootOrg);
performPostTest(
this,
TEMPLATE_DIR,
testName,
getCreateGeolocationUrl(),
REQUEST_JSON,
MediaType.APPLICATION_JSON,
true,
HttpStatus.OK,
RESPONSE_JSON);
}

@Test(dataProvider = "createGeolocationDataProviderFailure")
@CitrusParameters({"testName"})
@CitrusTest
public void testCreateGeolocationFailure(String testName) {
getTestCase().setName(testName);
getAuthToken(this, true);
performPostTest(
this,
TEMPLATE_DIR,
testName,
getCreateGeolocationUrl(),
REQUEST_JSON,
MediaType.APPLICATION_JSON,
true,
HttpStatus.BAD_REQUEST,
RESPONSE_JSON);
}

private void beforeTest(String testName, boolean canCreateRootOrg) {
getTestCase().setName(testName);
getAuthToken(this, true);
if (canCreateRootOrg) {
variable("rootOrgChannel", OrgUtil.getRootOrgChannel());
OrgUtil.getRootOrgId(this, testContext);
} else {
variable("externalId", OrgUtil.getRootOrgChannel());
variable("provider", OrgUtil.getRootOrgChannel());
OrgUtil.createSubOrgId(this, testContext);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"request": {
"rootOrgId": "",
"data": [
{
"location": "someLocation",
"type": "someType"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "api.notification.location.create",
"ver": "@ignore@",
"ts": "@ignore@",
"params": {
"resmsgid": "@ignore@",
"msgid": "@ignore@",
"err": "INVALID_ORG_ID",
"status": "INVALID_ORG_ID",
"errmsg": "INVALID_ORG_ID"
},
"responseCode": "CLIENT_ERROR",
"result": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"request": {
"rootOrgId": "invalidOrgId",
"data": [
{
"location": "someLocation",
"type": "someType"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "api.notification.location.create",
"ver": "@ignore@",
"ts": "@ignore@",
"params": {
"resmsgid": "@ignore@",
"msgid": "@ignore@",
"err": "INVALID_ORG_ID",
"status": "INVALID_ORG_ID",
"errmsg": "INVALID_ORG_ID"
},
"responseCode": "CLIENT_ERROR",
"result": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"request": {
"data": [
{
"location": "someLocation",
"type": "someType"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "api.notification.location.create",
"ver": "@ignore@",
"ts": "@ignore@",
"params": {
"resmsgid": "@ignore@",
"msgid": "@ignore@",
"err": "INVALID_ORG_ID",
"status": "INVALID_ORG_ID",
"errmsg": "INVALID_ORG_ID"
},
"responseCode": "CLIENT_ERROR",
"result": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"request": {
"rootOrgId": "${organisationId}",
"data": [
{
"location": "someLocation",
"type": "someType"
}
]
}
}
Loading

0 comments on commit 3b6459b

Please sign in to comment.