FINERACT-1040 Re-enabling and fixing CampaignTests

This commit is contained in:
Petri Tuomola
2020-06-20 22:29:50 +02:00
committed by Michael Vorburger ⛑️
parent 3c2f178180
commit f3862bca8b
6 changed files with 58 additions and 43 deletions
+1
View File
@@ -114,6 +114,7 @@ dependencyManagement {
dependency 'org.awaitility:awaitility:4.0.3'
dependency 'com.github.spotbugs:spotbugs-annotations:4.0.4'
dependency 'javax.cache:cache-api:1.1.1'
dependency 'org.mock-server:mockserver-junit-jupiter:5.10'
// If this is upgraded, you need to change path in WebFrontEndConfiguration
dependency 'org.webjars.npm:swagger-ui-dist:3.27.0'
+4
View File
@@ -124,6 +124,10 @@ dependencies {
'io.github.classgraph:classgraph',
'org.awaitility:awaitility'
)
testImplementation('org.mock-server:mockserver-junit-jupiter') {
exclude group: 'com.sun.mail', module: 'mailapi'
exclude group: 'javax.servlet', module: 'javax.servlet-api'
}
testImplementation ('io.rest-assured:rest-assured') {
exclude group: 'commons-logging'
exclude group: 'org.apache.sling'
@@ -22,12 +22,9 @@ import static io.restassured.RestAssured.given;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.restassured.path.json.JsonPath;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.fineract.integrationtests.common.Utils;
@@ -166,28 +163,22 @@ public class CampaignsHelper {
return json;
}
public ArrayList<ReportData> getReports() {
public List<ReportData> getReports() {
return getReports(BUSINESS_RULE_OPTIONS);
}
private ArrayList<ReportData> getReports(String jsonAttributeToGetBack) {
private List<ReportData> getReports(String jsonAttributeToGetBack) {
LOG.info("--------------------------------- GET REPORTS OPTIONS -------------------------------");
Assert.notNull(jsonAttributeToGetBack, "jsonAttributeToGetBack may not be null");
final String templateUrl = SMS_CAMPAIGNS_URL + "/template?" + Utils.TENANT_IDENTIFIER;
final String json = given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(templateUrl).andReturn()
.asString();
Assert.notNull(json, "json");
ArrayList<ReportData> reportsList = new ArrayList<>();
String reportsString = new Gson().toJson(JsonPath.from(json).get(jsonAttributeToGetBack));
Assert.notNull(reportsString, "reportsString");
final Gson gson = new Gson();
final Type typeOfHashMap = new TypeToken<List<ReportData>>() {}.getType();
reportsList = gson.fromJson(reportsString, typeOfHashMap);
return reportsList;
return JsonPath.from(json).getList(jsonAttributeToGetBack, ReportData.class);
}
private Long getSelectedReportId(final String reportName) {
ArrayList<ReportData> reports = getReports();
List<ReportData> reports = getReports();
if (reports != null && !reports.isEmpty()) {
for (ReportData reportData : reports) {
@@ -19,6 +19,8 @@
package org.apache.fineract.integrationtests.common.organisation;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
@@ -30,10 +32,16 @@ import java.util.HashMap;
import org.apache.fineract.integrationtests.common.CommonConstants;
import org.apache.fineract.integrationtests.common.Utils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.junit.jupiter.MockServerExtension;
import org.mockserver.junit.jupiter.MockServerSettings;
import org.mockserver.model.MediaType;
@ExtendWith(MockServerExtension.class)
@MockServerSettings(ports = { 9191 })
@Disabled
public class CampaignsTest {
private RequestSpecification requestSpec;
@@ -53,6 +61,25 @@ public class CampaignsTest {
public static final String DATE_FORMAT = "dd MMMM yyyy";
private final ClientAndServer client;
public CampaignsTest(ClientAndServer client) {
this.client = client;
// Set up mock server for message-gateway
this.client.when(request().withMethod("GET").withPath("/smsbridges"))
.respond(response().withContentType(MediaType.APPLICATION_JSON).withBody("[\n" + //
" {\n" + //
" \"id\": 1,\n" + //
" \"tenantId\": 1,\n" + //
" \"phoneNo\": \"+1234567890\",\n" + //
" \"providerName\": \"Dummy SMS Provider - Testing\",\n" + //
" \"providerDescription\": \"Dummy, just for testing\"\n" + //
" }\n" + //
"]") //
);
}
@BeforeEach
public void setup() {
Utils.initializeRESTAssured();
@@ -177,11 +204,11 @@ public class CampaignsTest {
this.campaignsHelper.verifyCampaignCreatedOnServer(this.requestSpec, this.responseSpec, campaignId);
// activating campaign with failure
ArrayList<HashMap> campaignDateValidationData = (ArrayList<HashMap>) campaignsHelperWithError.performActionsOnCampaignWithFailure(
campaignId, ACTIVATE_COMMAND, Utils.getLocalDateOfTenant().plusDays(1).toString(DATE_FORMAT),
CommonConstants.RESPONSE_ERROR);
ArrayList<HashMap<String, Object>> campaignDateValidationData = (ArrayList<HashMap<String, Object>>) campaignsHelperWithError
.performActionsOnCampaignWithFailure(campaignId, ACTIVATE_COMMAND,
Utils.getLocalDateOfTenant().plusDays(1).toString(DATE_FORMAT), CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.campaign.activationDate.in.the.future",
((HashMap<String, Object>) campaignDateValidationData.get(0)).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
campaignDateValidationData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
// activating campaign
Integer activatedCampaignId = this.campaignsHelper.performActionsOnCampaign(this.requestSpec, this.responseSpec, campaignId,
@@ -189,10 +216,10 @@ public class CampaignsTest {
assertEquals(activatedCampaignId, campaignId);
// activating campaign with failure
ArrayList<HashMap> campaignErrorData = (ArrayList<HashMap>) campaignsHelperWithError.performActionsOnCampaignWithFailure(
activatedCampaignId, ACTIVATE_COMMAND, Utils.getLocalDateOfTenant().toString(DATE_FORMAT), CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.campaign.already.active",
((HashMap<String, Object>) campaignErrorData.get(0)).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
ArrayList<HashMap<String, Object>> campaignErrorData = (ArrayList<HashMap<String, Object>>) campaignsHelperWithError
.performActionsOnCampaignWithFailure(activatedCampaignId, ACTIVATE_COMMAND,
Utils.getLocalDateOfTenant().toString(DATE_FORMAT), CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.campaign.already.active", campaignErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
// closing campaign again for deletion
Integer closedCampaignId = this.campaignsHelper.performActionsOnCampaign(this.requestSpec, this.responseSpec, campaignId,
@@ -22,17 +22,19 @@ import java.util.Map;
public class ReportData {
private final Long reportId;
private Long reportId;
private final String reportName;
private String reportName;
private final String reportType;
private String reportType;
private final String reportSubType;
private String reportSubType;
private final String reportDescription;
private String reportDescription;
private final Map<String, Object> reportParamName;
private Map<String, Object> reportParamName;
public ReportData() {}
public ReportData(final Long reportId, final String reportName, final String reportType, final String reportSubType,
final Map<String, Object> reportParamName, final String reportDescription) {
@@ -89,20 +89,7 @@ public class ClasspathHellDuplicatesChecker {
private boolean skipJAR(String jarPath) {
// ./gradlew test finds classes from the Gradle Wrapper (which don't
// show up in-IDE), exclude those
return jarPath.contains("/.gradle/wrapper/dists/") || jarPath.contains("/io.rest-assured/"); // TODO
// FINERACT-884
// remove
// when
// RestAssured
// was
// bumped
// from
// 3.3.0
// to
// 4.3.0
// in
// Spring
// BOM
return jarPath.contains("/.gradle/wrapper/dists/");
}
protected boolean isHarmlessDuplicate(String resourcePath) {
@@ -121,6 +108,9 @@ public class ClasspathHellDuplicatesChecker {
|| resourcePath.startsWith("org/opendaylight/blueprint/") || resourcePath.endsWith("reference.conf") // in
// Akka's
// JARs
// json-schema-core and json-schema-validator depend on each
// other and include these files
|| resourcePath.equals("draftv4/schema") || resourcePath.equals("draftv3/schema") //
|| resourcePath.equals("WEB-INF/web.xml") || resourcePath.equals("META-INF/web-fragment.xml")
|| resourcePath.equals("META-INF/eclipse.inf") || resourcePath.equals("META-INF/ECLIPSE_.SF")
|| resourcePath.equals("META-INF/ECLIPSE_.RSA") || resourcePath.equals("META-INF/BC2048KE.DSA")