Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Aug 22, 2022
2 parents bc622bd + 1e5847e commit bc33be0
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 97 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
* Copyright (C) 2010-2022 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 @@ -19,22 +19,22 @@
import java.util.Date;
import java.util.List;

import com.evolveum.midpoint.notifications.api.transports.Message;
import com.evolveum.midpoint.prism.path.ItemName;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;

import com.evolveum.midpoint.model.test.AbstractModelIntegrationTest;
import com.evolveum.midpoint.notifications.api.transports.Message;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.crypto.EncryptionException;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.repo.api.RepoAddOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

/**
Expand All @@ -46,12 +46,12 @@
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public abstract class EmptyReportIntegrationTest extends AbstractModelIntegrationTest {

public static final int DONT_COUNT_ROWS = -1;

static final File TEST_DIR_REPORTS = new File("src/test/resources/reports");
static final File TEST_DIR_COMMON = new File("src/test/resources/common");
private static final File EXPORT_DIR = new File("target/midpoint-home/export");

// private static final TestResource<ReportType> REPORT_OBJECT_COLLECTION_USERS = new TestResource<>(TEST_DIR_REPORTS,
// "report-object-collection-users.xml", "64e13165-21e5-419a-8d8b-732895109f84");
static final TestResource<ReportType> REPORT_AUDIT_COLLECTION_WITH_DEFAULT_COLUMN = new TestResource<>(TEST_DIR_REPORTS,
"report-audit-collection-with-default-column.xml", "2b44aa2e-dd86-4842-bcf5-762c8a9a85bc");
static final TestResource<ReportType> REPORT_AUDIT_COLLECTION_WITH_VIEW = new TestResource<>(TEST_DIR_REPORTS,
Expand Down Expand Up @@ -186,13 +186,14 @@ void createUsers(int users, Task initTask, OperationResult initResult) throws Co
System.out.printf("%d users created", users);
}

List<String> getLinesOfOutputFile(PrismObject<ReportType> report) throws IOException, SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException, ParseException {
List<String> getLinesOfOutputFile(PrismObject<ReportType> report) throws IOException, ParseException {
File outputFile = findOutputFile(report);
displayValue("Found report file", outputFile);
assertNotNull("No output file for " + report, outputFile);
List<String> lines = Files.readAllLines(Paths.get(outputFile.getPath()));
displayValue("Report content (" + lines.size() + " lines)", String.join("\n", lines));
outputFile.renameTo(new File(outputFile.getParentFile(), "processed-" + outputFile.getName()));
assertThat(outputFile.renameTo(new File(outputFile.getParentFile(), "processed-" + outputFile.getName())))
.isTrue();
return lines;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2019 Evolveum and contributors
* Copyright (C) 2010-2022 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,19 +10,16 @@
import java.text.ParseException;
import java.util.List;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.test.TestResource;
import com.evolveum.midpoint.util.exception.*;

import com.evolveum.midpoint.xml.ns._public.common.common_3.FileFormatConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FileFormatTypeType;

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.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;

@ContextConfiguration(locations = { "classpath:ctx-report-test-main.xml" })
Expand All @@ -36,14 +33,21 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
addObject(USER_JACK, initTask, initResult);
}

List<String> basicCheckOutputFile(PrismObject<ReportType> report, int expectedRow, int expectedColumns, CharSequence lastLine) throws IOException, SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException, ParseException {
List<String> basicCheckOutputFile(PrismObject<ReportType> report, int expectedRows, int expectedColumns, String lastLine)
throws IOException, ParseException {

if (expectedRows != DONT_COUNT_ROWS) {
// +1 for the final line with the subscription appeal
expectedRows += 1;
}

List<String> lines = getLinesOfOutputFile(report);

if (expectedRow != -1 && lines.size() != expectedRow) {
fail("Unexpected count of rows of csv report. Expected: " + expectedRow + ", Actual: " + lines.size());
if (expectedRows != DONT_COUNT_ROWS && lines.size() != expectedRows) {
fail("Unexpected count of rows of csv report. Expected: " + expectedRows + ", Actual: " + lines.size());
}

if (expectedRow == -1 && lines.size() < 2) {
if (expectedRows == DONT_COUNT_ROWS && lines.size() < 2) {
fail("Unexpected count of rows of csv report. Expected: more as one, Actual: " + lines.size());
}

Expand All @@ -52,7 +56,8 @@ List<String> basicCheckOutputFile(PrismObject<ReportType> report, int expectedRo
fail("Unexpected count of columns of csv report. Expected: " + expectedColumns + ", Actual: " + actualColumns);
}

String lastRealLine = lines.get(lines.size() - 1);
// Last content line before the subscription appeal, hence -2, not -1.
String lastRealLine = lines.get(lines.size() - 2);
if (StringUtils.isNoneEmpty(lastLine) && !lastRealLine.equals(lastLine)) {
fail("Unexpected last line of csv report. Expected: '" + lastLine + "', Actual: '" + lastRealLine + "'");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
/*
* Copyright (c) 2010-2019 Evolveum and contributors
* Copyright (C) 2010-2022 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 java.io.File;

import com.evolveum.midpoint.prism.*;

import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.report.api.ReportConstants;
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import static org.testng.AssertJUnit.assertTrue;

import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
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.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.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 javax.xml.namespace.QName;

import static org.testng.AssertJUnit.assertTrue;
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import com.evolveum.midpoint.util.exception.SchemaException;
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 @@ -92,17 +91,17 @@ public void test004DashboardReportEmpty() throws Exception {

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

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

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

@Test
Expand Down Expand Up @@ -182,8 +181,8 @@ public void test121RunMidpointUsersScript() throws Exception {
assertTrue("Target file is not there", targetFile.exists());
}

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

Task task = getTestTask();
Expand All @@ -195,12 +194,10 @@ private void runTest(TestResource<ReportType> reportResource, int expectedRows,
ItemPath.create(TaskType.F_ACTIVITY,
ActivityDefinitionType.F_WORK,
WorkDefinitionsType.F_REPORT_EXPORT,
ClassicReportImportWorkDefinitionType.F_REPORT_PARAM
),
ClassicReportImportWorkDefinitionType.F_REPORT_PARAM),
task,
result,
parameters
);
parameters);
}

dummyTransport.clearMessages();
Expand All @@ -218,24 +215,19 @@ private void runTest(TestResource<ReportType> reportResource, int expectedRows,
.display();

PrismObject<ReportType> report = getObject(ReportType.class, reportResource.oid);
basicCheckOutputFile(report, expectedRows, expectedColumns, lastline);
basicCheckOutputFile(report, expectedRows, expectedColumns, lastLine);

assertNotificationMessage(reportResource);
}

private void runTest(TestResource<ReportType> reportResource, int expectedRows, int expectedColumns, CharSequence lastline)
private void runTest(TestResource<ReportType> reportResource, int expectedRows, int expectedColumns, String lastLine)
throws Exception {
runTest(reportResource, expectedRows, expectedColumns, lastline, null);
runTest(reportResource, expectedRows, expectedColumns, lastLine, null);
}

private ReportParameterType getParameters(String name, Class<String> type, Object realValue) throws SchemaException {
// PrismContainerDefinition<ReportParameterType> paramContainerDef = prismContext.getSchemaRegistry().findContainerDefinitionByElementName(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
// PrismContainer<ReportParameterType> paramContainer;
// paramContainer = paramContainerDef.instantiate();
ReportParameterType reportParam = new ReportParameterType();
PrismContainerValue<ReportParameterType> reportParamValue = reportParam.asPrismContainerValue();
// reportParamValue.revive(prismContext);
// paramContainer.add(reportParamValue);

QName typeName = prismContext.getSchemaRegistry().determineTypeForClass(type);
MutablePrismPropertyDefinition<Object> def = prismContext.definitionFactory().createPropertyDefinition(
Expand All @@ -244,7 +236,7 @@ private ReportParameterType getParameters(String name, Class<String> type, Objec
def.setRuntimeSchema(true);
def.toMutable().setMaxOccurs(1);

PrismProperty prop = def.instantiate();
PrismProperty<Object> prop = def.instantiate();
prop.addRealValue(realValue);
reportParamValue.add(prop);

Expand Down

0 comments on commit bc33be0

Please sign in to comment.