Skip to content

Commit

Permalink
CSV report tests: runTest extracted higher as testClassicExport()
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Feb 16, 2023
1 parent 1ba6814 commit a938324
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 133 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2022 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -10,20 +10,17 @@
import java.text.ParseException;
import java.util.List;

import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;

import org.apache.commons.lang3.StringUtils;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FileFormatConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FileFormatTypeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

@ContextConfiguration(locations = { "classpath:ctx-report-test-main.xml" })
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
Expand Down Expand Up @@ -85,4 +82,46 @@ protected FileFormatConfigurationType getFileFormatConfiguration() {
void assertNotificationMessage(TestResource<ReportType> reportTestResource) {
assertNotificationMessage(reportTestResource.getObjectable(), "text/csv");
}

protected void testClassicExport(TestResource<ReportType> reportResource, int expectedRows, int expectedColumns,
String lastLine, ReportParameterType parameters) throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();

if (parameters != null) {
modifyObjectReplaceContainer(TaskType.class,
TASK_EXPORT_CLASSIC.oid,
ItemPath.create(TaskType.F_ACTIVITY,
ActivityDefinitionType.F_WORK,
WorkDefinitionsType.F_REPORT_EXPORT,
ClassicReportImportWorkDefinitionType.F_REPORT_PARAM),
task,
result,
parameters);
}

dummyTransport.clearMessages();

when();
runExportTaskClassic(reportResource, result);
waitForTaskCloseOrSuspend(TASK_EXPORT_CLASSIC.oid);

then();
assertTask(TASK_EXPORT_CLASSIC.oid, "after")
.assertSuccess()
.display()
.assertHasArchetype(SystemObjectsType.ARCHETYPE_REPORT_EXPORT_CLASSIC_TASK.value());

PrismObject<TaskType> reportTask = getObject(TaskType.class, TASK_EXPORT_CLASSIC.oid);
basicCheckOutputFile(reportTask, expectedRows, expectedColumns, lastLine);

assertNotificationMessage(reportResource);
}

protected void testClassicExport(TestResource<ReportType> reportResource,
int expectedRows, int expectedColumns, String lastLine)
throws Exception {
testClassicExport(reportResource, expectedRows, expectedColumns, lastLine, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.model.impl.expr.MidpointFunctionsImpl;
import com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl;
import com.evolveum.midpoint.report.impl.ReportServiceImpl;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.TestResource;
Expand Down Expand Up @@ -79,51 +80,6 @@ public void test100RunReport() throws Exception {
skipIfNotNativeRepository();
// 50 * 3 (normal) + 50 // 3 (direct assignments) + 3 (without metadata) + jack + header
// (subscription footer is considered automatically later, do not count it here)
runTest(REPORT_INDIRECT_ASSIGNMENTS, 171, 7, null);
}

private void runTest(TestResource<ReportType> reportResource, int expectedRows, int expectedColumns,
String lastLine, ReportParameterType parameters) throws Exception {
given();

Task task = getTestTask();
OperationResult result = task.getResult();

if (parameters != null) {
modifyObjectReplaceContainer(TaskType.class,
TASK_EXPORT_CLASSIC.oid,
ItemPath.create(TaskType.F_ACTIVITY,
ActivityDefinitionType.F_WORK,
WorkDefinitionsType.F_REPORT_EXPORT,
ClassicReportImportWorkDefinitionType.F_REPORT_PARAM),
task,
result,
parameters);
}

dummyTransport.clearMessages();

runExportTaskClassic(reportResource, result);

when();

waitForTaskCloseOrSuspend(TASK_EXPORT_CLASSIC.oid);

then();

assertTask(TASK_EXPORT_CLASSIC.oid, "after")
.assertSuccess()
.display()
.assertHasArchetype(SystemObjectsType.ARCHETYPE_REPORT_EXPORT_CLASSIC_TASK.value());

PrismObject<TaskType> reportTask = getObject(TaskType.class, TASK_EXPORT_CLASSIC.oid);
basicCheckOutputFile(reportTask, expectedRows, expectedColumns, lastLine);

assertNotificationMessage(reportResource);
}

private void runTest(TestResource<ReportType> reportResource, int expectedRows, int expectedColumns, String lastLine)
throws Exception {
runTest(reportResource, expectedRows, expectedColumns, lastLine, null);
testClassicExport(REPORT_INDIRECT_ASSIGNMENTS, 171, 7, null);
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
/*
* Copyright (C) 2010-2022 Evolveum and contributors
* Copyright (C) 2010-2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.report;

import static org.testng.AssertJUnit.assertTrue;

import java.io.File;
import javax.xml.namespace.QName;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;

import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.prism.MutablePrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.report.api.ReportConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;

import javax.xml.namespace.QName;
import java.io.File;

import static org.testng.AssertJUnit.assertTrue;

@ContextConfiguration(locations = { "classpath:ctx-report-test-main.xml" })
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class TestCsvReportExportClassic extends TestCsvReport {
Expand Down Expand Up @@ -86,93 +84,93 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti

@Test
public void test001DashboardReportWithDefaultColumn() throws Exception {
runTest(REPORT_DASHBOARD_WITH_DEFAULT_COLUMN, 8, 3, null);
testClassicExport(REPORT_DASHBOARD_WITH_DEFAULT_COLUMN, 8, 3, null);
}

@Test
public void test004DashboardReportEmpty() throws Exception {
runTest(REPORT_DASHBOARD_EMPTY, 3, 3, null);
testClassicExport(REPORT_DASHBOARD_EMPTY, 3, 3, null);
}

@Test
public void test100AuditCollectionReportWithDefaultColumn() throws Exception {
runTest(REPORT_AUDIT_COLLECTION_WITH_DEFAULT_COLUMN, DONT_COUNT_ROWS, 8, null);
testClassicExport(REPORT_AUDIT_COLLECTION_WITH_DEFAULT_COLUMN, DONT_COUNT_ROWS, 8, null);
}

@Test
public void test101AuditCollectionReportWithView() throws Exception {
runTest(REPORT_AUDIT_COLLECTION_WITH_VIEW, DONT_COUNT_ROWS, 2, null);
testClassicExport(REPORT_AUDIT_COLLECTION_WITH_VIEW, DONT_COUNT_ROWS, 2, null);
}

@Test
public void test102AuditCollectionReportWithDoubleView() throws Exception {
runTest(REPORT_AUDIT_COLLECTION_WITH_DOUBLE_VIEW, DONT_COUNT_ROWS, 3, null);
testClassicExport(REPORT_AUDIT_COLLECTION_WITH_DOUBLE_VIEW, DONT_COUNT_ROWS, 3, null);
}

@Test
public void test103AuditCollectionReportWithCondition() throws Exception {
runTest(REPORT_AUDIT_COLLECTION_WITH_CONDITION, 2, 8, null);
testClassicExport(REPORT_AUDIT_COLLECTION_WITH_CONDITION, 2, 8, null);
}

@Test
public void test104AuditCollectionReportEmpty() throws Exception {
runTest(REPORT_AUDIT_COLLECTION_EMPTY, 1, 8, null);
testClassicExport(REPORT_AUDIT_COLLECTION_EMPTY, 1, 8, null);
}

@Test
public void test110ObjectCollectionReportWithDefaultColumn() throws Exception {
runTest(REPORT_OBJECT_COLLECTION_WITH_DEFAULT_COLUMN, 54, 6, null);
testClassicExport(REPORT_OBJECT_COLLECTION_WITH_DEFAULT_COLUMN, 54, 6, null);
}

@Test
public void test111ObjectCollectionReportWithView() throws Exception {
runTest(REPORT_OBJECT_COLLECTION_WITH_VIEW, 2, 2, null);
testClassicExport(REPORT_OBJECT_COLLECTION_WITH_VIEW, 2, 2, null);
}

@Test
public void test112ObjectCollectionReportWithDoubleView() throws Exception {
runTest(REPORT_OBJECT_COLLECTION_WITH_DOUBLE_VIEW, 54, 3, null);
testClassicExport(REPORT_OBJECT_COLLECTION_WITH_DOUBLE_VIEW, 54, 3, null);
}

@Test
public void test113ObjectCollectionReportWithFilter() throws Exception {
runTest(REPORT_OBJECT_COLLECTION_WITH_FILTER, 3, 2, null);
testClassicExport(REPORT_OBJECT_COLLECTION_WITH_FILTER, 3, 2, null);
}

@Test
public void test114ObjectCollectionReportWithFilterAndBasicCollection() throws Exception {
runTest(REPORT_OBJECT_COLLECTION_WITH_FILTER_AND_BASIC_COLLECTION, 2, 2, null);
testClassicExport(REPORT_OBJECT_COLLECTION_WITH_FILTER_AND_BASIC_COLLECTION, 2, 2, null);
}

@Test
public void test115ObjectCollectionReportWithCondition() throws Exception {
runTest(REPORT_OBJECT_COLLECTION_WITH_CONDITION, 2, 6, null);
testClassicExport(REPORT_OBJECT_COLLECTION_WITH_CONDITION, 2, 6, null);
}

@Test
public void test116ObjectCollectionEmptyReport() throws Exception {
runTest(REPORT_OBJECT_COLLECTION_EMPTY, 1, 6, null);
testClassicExport(REPORT_OBJECT_COLLECTION_EMPTY, 1, 6, null);
}

@Test
public void test117ObjectCollectionReportWithFilterAndBasicCollectionWithoutView() throws Exception {
runTest(REPORT_OBJECT_COLLECTION_FILTER_BASIC_COLLECTION_WITHOUT_VIEW, 2, 1, null);
testClassicExport(REPORT_OBJECT_COLLECTION_FILTER_BASIC_COLLECTION_WITHOUT_VIEW, 2, 1, null);
}

@Test
public void test118ObjectCollectionWithParamReport() throws Exception {
ReportParameterType parameters = getParameters("givenName", String.class, "Will");
runTest(REPORT_OBJECT_COLLECTION_WITH_PARAM, 2, 2, null, parameters);
testClassicExport(REPORT_OBJECT_COLLECTION_WITH_PARAM, 2, 2, null, parameters);
}

@Test
public void test119ObjectCollectionWithSubreportParamReport() throws Exception {
runTest(REPORT_OBJECT_COLLECTION_WITH_SUBREPORT_PARAM, 2, 2, "\"will\";\"TestRole1230,TestRole123010\"");
testClassicExport(REPORT_OBJECT_COLLECTION_WITH_SUBREPORT_PARAM, 2, 2, "\"will\";\"TestRole1230,TestRole123010\"");
}

@Test
public void test120RunMidpointUsers() throws Exception {
runTest(REPORT_USER_LIST, 54, 6, null);
testClassicExport(REPORT_USER_LIST, 54, 6, null);
}

@Test
Expand All @@ -181,7 +179,7 @@ public void test121RunMidpointUsersScript() throws Exception {
displaySkip();
return;
}
runTest(REPORT_USER_LIST_SCRIPT, 54, 6, null);
testClassicExport(REPORT_USER_LIST_SCRIPT, 54, 6, null);
File targetFile = new File(MidPointTestConstants.TARGET_DIR_PATH, "report-users");
assertTrue("Target file is not there", targetFile.exists());
}
Expand All @@ -194,7 +192,7 @@ public void test130ExportUsersWithAssignments() throws Exception {
.assignment(new AssignmentType().targetRef(SystemObjectsType.ROLE_APPROVER.value(), RoleType.COMPLEX_TYPE));
addObject(user.asPrismObject(), getTestTask(), getTestTask().getResult());

runTest(REPORT_SUBREPORT_AS_ROW_USERS, 56, 3, null);
testClassicExport(REPORT_SUBREPORT_AS_ROW_USERS, 56, 3, null);
}

@Test
Expand Down Expand Up @@ -230,52 +228,7 @@ public void test140ExportAuditRecords() throws Exception {

ReportParameterType parameters = getParameters("targetName", String.class, name);

runTest(REPORT_SUBREPORT_AUDIT, 5, 4, null, parameters);
}

private void runTest(TestResource<ReportType> reportResource, int expectedRows, int expectedColumns,
String lastLine, ReportParameterType parameters) throws Exception {
given();

Task task = getTestTask();
OperationResult result = task.getResult();

if (parameters != null) {
modifyObjectReplaceContainer(TaskType.class,
TASK_EXPORT_CLASSIC.oid,
ItemPath.create(TaskType.F_ACTIVITY,
ActivityDefinitionType.F_WORK,
WorkDefinitionsType.F_REPORT_EXPORT,
ClassicReportImportWorkDefinitionType.F_REPORT_PARAM),
task,
result,
parameters);
}

dummyTransport.clearMessages();

runExportTaskClassic(reportResource, result);

when();

waitForTaskCloseOrSuspend(TASK_EXPORT_CLASSIC.oid);

then();

assertTask(TASK_EXPORT_CLASSIC.oid, "after")
.assertSuccess()
.display()
.assertHasArchetype(SystemObjectsType.ARCHETYPE_REPORT_EXPORT_CLASSIC_TASK.value());

PrismObject<TaskType> reportTask = getObject(TaskType.class, TASK_EXPORT_CLASSIC.oid);
basicCheckOutputFile(reportTask, expectedRows, expectedColumns, lastLine);

assertNotificationMessage(reportResource);
}

private void runTest(TestResource<ReportType> reportResource, int expectedRows, int expectedColumns, String lastLine)
throws Exception {
runTest(reportResource, expectedRows, expectedColumns, lastLine, null);
testClassicExport(REPORT_SUBREPORT_AUDIT, 5, 4, null, parameters);
}

private ReportParameterType getParameters(String name, Class<String> type, Object realValue) throws SchemaException {
Expand Down

0 comments on commit a938324

Please sign in to comment.