Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ public interface CacheId {
*/
public static final String TABLE_TOPOLOGICAL_CELL = "topologicalCell";

/**
* Separator for file name by compare plan
*/
public static final String TITLE_FILE_NAME_SEPARATOR = " ⇔ ";

/**
* The tolerance value between TOP_Kante length and the sum of GEO_Kanten
* length, which belong to this TOP_Kante (in Meter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
package org.eclipse.set.feature.validation.session;

import static org.eclipse.set.basis.constants.ToolboxConstants.TITLE_FILE_NAME_SEPARATOR;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -155,7 +157,6 @@ public static class ServiceProvider {
private static final String APPLICATION_NAME = "Werkzeugkoffer"; //$NON-NLS-1$
private static final String SESSIONS_SUBDIR = "sessions"; //$NON-NLS-1$
protected static final String TITLE_SEPARATOR = " - "; //$NON-NLS-1$
protected static final String TITLE_FILE_NAME_SEPARATOR = " ⇔ "; //$NON-NLS-1$
static final Logger logger = LoggerFactory.getLogger(ModelSession.class);

private static String getSessionsSubDir() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
formatter_settings_version=23
1 change: 1 addition & 0 deletions java/bundles/org.eclipse.set.swtbot/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Import-Package: jakarta.inject,
org.eclipse.set.browser,
org.eclipse.set.browser.swt,
org.eclipse.set.utils.table,
org.eclipse.set.utils.table.export,
org.eclipse.ui,
org.slf4j
Bundle-ActivationPolicy: lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@

import static org.junit.jupiter.api.Assertions.*;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import org.apache.commons.csv.CSVRecord;
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
import org.eclipse.set.swtbot.table.AbstractTableTest;
import org.eclipse.set.swtbot.table.TestFailHandle;
import org.eclipse.set.swtbot.utils.AbstractSWTBotTest;
import org.eclipse.set.swtbot.utils.SWTBotUtils;
import org.eclipse.set.utils.table.export.ExportToCSV;
import org.eclipse.swtbot.nebula.nattable.finder.widgets.SWTBotNatTable;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -29,6 +36,7 @@
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;

/**
* Test for changes in Validation View
Expand All @@ -37,6 +45,54 @@
*/
@TestInstance(Lifecycle.PER_CLASS)
public class ValidationViewTest extends AbstractTableTest {
private static class ValidationViewFailHandle extends TestFailHandle {
String csvHeader = "\"Item Group\";\"Item label\";\"Expect Value\""
+ System.lineSeparator();

@Override
public void testFailed(final ExtensionContext context,
final Throwable cause) {
final Optional<Object> testInstance = context.getTestInstance();
if (testInstance.isPresent() && testInstance
.get() instanceof final ValidationViewTest tableTest) {
exportWidgeValue(tableTest);
exportReferenceCSV(tableTest.getTestFile(),
VALIDATION_INFORMATION_CSV, tableTest.getReferenceDir(),
tableTest.getTestResourceClass().getClassLoader(),
tableTest.getClass());
}
}

private void exportWidgeValue(final ValidationViewTest testInstance) {

final List<String> currentValues = new ArrayList<>();
final List<CSVRecord> referenceFile = testInstance.informationReference;
for (int i = 1; i < referenceFile.size(); i++) {
final String itemGroup = referenceFile.get(i).get(0);
final String itemLabel = referenceFile.get(i).get(1);
final SWTBotText currentValue = AbstractSWTBotTest.bot
.textWithLabelInGroup(itemLabel, itemGroup);
final String csvEntry = String.format("\"%s\";\"%s\";\"%s\"",
itemGroup, itemLabel, currentValue.getText())
+ System.lineSeparator();

currentValues.add(csvEntry);
}
final ExportToCSV<String> exportToCSV = new ExportToCSV<>(
csvHeader);
final File file = getExportFile(testInstance.getTestFile(),
VALIDATION_INFORMATION_CSV + "_current.csv",
testInstance.getClass());
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
exportToCSV.exportToCSV(Optional.of(file.toPath()), currentValues);
SWTBotUtils.botWaitUntil(AbstractSWTBotTest.bot,
() -> Boolean.valueOf(Files.exists(file.toPath(),
LinkOption.NOFOLLOW_LINKS)));
}
}

protected static final String RICHTEXT_REPLACE_REGEX = "<[^>]+>";
protected static final String VALIDATION_INFORMATION_CSV = "validation_information";
protected static final String VALIDATION_TABLE_NAME = "validation_view";
Expand All @@ -47,7 +103,7 @@ private static List<String> splitString(final String text,
return asList.stream().map(e -> e.replaceAll(" ", "")).toList();
}

private List<CSVRecord> informationReference;
protected List<CSVRecord> informationReference;

@BeforeEach
@Override
Expand Down Expand Up @@ -116,6 +172,7 @@ protected void loadCsvResources() throws IOException {
}

@Test
@ExtendWith(ValidationViewFailHandle.class)
protected void testInformation() throws Exception {
whenOpeningValidateView();
loadCsvResources();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright (c) 2025 DB InfraGO AG and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
*/
package org.eclipse.set.swtbot.plancomapre;

import java.util.List;
import java.util.Optional;

import org.eclipse.set.swtbot.utils.AbstractPPHNTest;
import org.eclipse.set.swtbot.utils.SWTBotTestFile;
import org.eclipse.set.swtbot.utils.SWTBotUtils;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Abstract class for test compare plan
*
* @author truong
*/
public abstract class AbstractPlanCompareTest extends AbstractPPHNTest {
private final Logger LOGGER = LoggerFactory
.getLogger(AbstractPlanCompareTest.class);

protected void openSecondPlan() throws Exception {
LOGGER.info(getFilePath(getComparePlan().getFullName()).toString());
getDialogService().openFileDialogHandler = filters -> Optional
.of(getFilePath(getComparePlan().getFullName()));

bot.waitUntil(SWTBotUtils.botWaitUntil(bot, () -> {
final var shell = bot.activeShell();
return Boolean.valueOf(shell.getText()
.endsWith(SWTBotTestFile.PPHN_1_10_0_3.getFullName()));
}));

SWTBotMenu dateiMenu = bot.menu("Datei");
SWTBotMenu comparePlanMenu = dateiMenu.menu("Vergleichsplanung laden");
comparePlanMenu.menu("Andere Planung laden...").click();
bot.waitUntil(SWTBotUtils.botWaitUntil(bot, () -> {
final var shell = List.of(bot.shells());
return Boolean.valueOf(shell.stream()
.filter(c -> "Statusinformationen".equals(c.getText()))
.findAny()
.isEmpty());
}), 5l * 60 * 1000);
bot.sleep(500);
}

@Override
public String getReferenceDir() {
return TEST_RESOURCE_DIR + "table_reference/"
+ getTestFile().getShortName() + "/";
}

protected SWTBotTestFile getComparePlan() {
return SWTBotTestFile.PPHN_1_10_0_1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright (c) 2025 DB InfraGO AG and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
*/
package org.eclipse.set.swtbot.plancomapre;

import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.*;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.List;
import java.util.stream.Stream;

import org.eclipse.set.swtbot.table.PtTable;
import org.eclipse.set.swtbot.utils.SWTBotUtils;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.swtbot.nebula.nattable.finder.widgets.SWTBotNatTable;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotExpandItem;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Test table by compare plan
*
* @author truong
*/
@TestInstance(Lifecycle.PER_CLASS)
public class PlanCompareTableTest extends AbstractPlanCompareTest {
SWTBotNatTable nattableBot;

protected static Stream<Arguments> providesPtTable() {
return PtTable.tablesToTest.stream().map(table -> Arguments.of(table));
}

@BeforeEach
@Override
public void beforeEach() throws Exception {
// do nothing
}

// The test file should only open one times by this test
@BeforeAll
void beforeAll() throws Exception {
super.beforeEach();
openSecondPlan();
@SuppressWarnings("unchecked")
final List<? extends ExpandItem> expandItems = bot
.widgets(allOf(widgetOfType(ExpandItem.class), withRegex(
"^.+ – (Zusatzt|T)abellen( \\(in Entwicklung\\))?$")));
expandItems.forEach(item -> {
final SWTBotExpandItem swtBotExpandItem = new SWTBotExpandItem(
item);
assertNotNull(swtBotExpandItem);
swtBotExpandItem.expand();
});
}

/**
* Test Open Table
*
* @param table
*/
@ParameterizedTest
@MethodSource("providesPtTable")
protected void testOpenTable(PtTable table) {
givenNattableBot(table.tableName());
assertNotNull(nattableBot);

}

protected void givenNattableBot(final String tableName) {
bot.button(tableName).click();
nattableBot = SWTBotUtils.waitForNattable(bot, 30000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright (c) 2025 DB InfraGO AG and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
*/
package org.eclipse.set.swtbot.plancomapre;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

import java.util.Optional;

import org.eclipse.set.basis.constants.ToolboxConstants;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.junit.jupiter.api.Test;

/**
* Test open and close compare plan
*
* @author truong
*/
public class PlanCompareTest extends AbstractPlanCompareTest {
@Test
void testOpenComparePlan() {
assertDoesNotThrow(this::openSecondPlan);
expectApplicationTitleAfterOpenComparePlanEquals();
}

@Test
void testOpenCloseComparePlan() {
assertDoesNotThrow(this::openSecondPlan);
expectApplicationTitleAfterOpenComparePlanEquals();
assertDoesNotThrow(this::whenCloseComparePlan);
expectApplicationTitleAfterCloseComparePlanEquals();
}

void whenCloseComparePlan() {
getDialogService().openFileDialogHandler = filter -> Optional.empty();
SWTBotMenu dateiMenu = bot.menu("Datei");
SWTBotMenu comparePlanMenu = dateiMenu.menu("Vergleichsplanung laden");
comparePlanMenu.menu("Andere Planung laden...").click();
bot.sleep(500);
}

protected void expectApplicationTitleAfterOpenComparePlanEquals() {
String applicationTitle = bot.activeShell().getText();
assertTrue(applicationTitle.endsWith(getTestFile().getFullName()
+ ToolboxConstants.TITLE_FILE_NAME_SEPARATOR
+ getComparePlan().getFullName()));
}

protected void expectApplicationTitleAfterCloseComparePlanEquals() {
String applicationTitle = bot.activeShell().getText();
assertTrue(applicationTitle.endsWith(getTestFile().getFullName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public void beforeEach() throws Exception {
assertNotNull(swtBotExpandItem);
swtBotExpandItem.expand();
});

}

@Override
Expand Down
Loading
Loading