Skip to content

Commit

Permalink
Merge pull request #383 from thehyve/add-integration-test
Browse files Browse the repository at this point in the history
Add integration test
  • Loading branch information
janblom committed Jul 14, 2023
2 parents 9624649 + 79a7107 commit bcbc1d8
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 18 deletions.
96 changes: 96 additions & 0 deletions rabbitinahat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,110 @@
</programs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<!-- unpack the examples zip so that the contents can be used as test resources -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-test-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<unzip src="${project.basedir}/../examples.zip" dest="${basedir}/target/test-classes" overwrite="true"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
</build>

<!-- profiles>
<profile>
<id>surefire-java17</id>
<activation>
<property>
<name>jdk.version</name>
<value>17</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M8</version>
<configuration>
<systemPropertyVariables>
<java.awt.headless>false</java.awt.headless>
<awt.toolkit>CTCToolkit</awt.toolkit>
<java.awt.graphicsenv>CTCGraphicsEnvironment</java.awt.graphicsenv>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles -->
<dependencies>
<dependency>
<groupId>org.ohdsi</groupId>
<artifactId>rabbit-core</artifactId>
<version>${project.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<scope>test</scope>
</dependency>
<!-- causes warning for CVE-2020-15250 but is only used in test scope -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-swing-junit</artifactId>
<version>3.17.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.caciocavallosilano</groupId>
<artifactId>cacio-tta</artifactId>
<version>1.10</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-antrun-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ public List<LabeledRectangle> getVisibleTargetComponents() {
return getVisibleRectangles(cdmComponents);
}


public List<Arrow> getArrows() {
return arrows;
}

public void setSlaveMappingPanel(MappingPanel mappingPanel) {
this.slaveMappingPanel = mappingPanel;
}
Expand Down Expand Up @@ -807,6 +812,7 @@ private void makeMapSourceToTarget(LabeledRectangle source, LabeledRectangle tar
for (Arrow other : arrows) {
if (source == other.getSource() && target == other.getTarget()) {
isNew = false;
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.*;
import javax.swing.border.TitledBorder;
Expand Down Expand Up @@ -87,6 +89,12 @@ public class RabbitInAHatMain implements ResizeListener {
public final static String ACTION_MARK_COMPLETED = "Mark Highlighted As Complete";
public final static String ACTION_UNMARK_COMPLETED = "Mark Highlighted As Incomplete";
public final static String ACTION_HELP = "Open documentation";
public final static String ACTION_EXIT = "Exit";
public final static String TITLE_SELECT_FILE = "Select File";
public final static String TITLE_SELECT_FOLDER = "Select Folder";

public final static String PANEL_TABLE_MAPPING = "Table Mapping";
public final static String PANEL_FIELD_MAPPING = "Field Mapping";

public final static String DOCUMENTATION_URL = "http://ohdsi.github.io/WhiteRabbit/RabbitInAHat.html";
private final static FileFilter FILE_FILTER_GZ = new FileNameExtensionFilter("GZIP Files (*.gz)", "gz");
Expand Down Expand Up @@ -122,22 +130,13 @@ public RabbitInAHatMain(String[] args) {

frame = new JFrame("Rabbit in a Hat");

frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
String[] objButtons = {"Yes","No"};
int PromptResult = JOptionPane.showOptionDialog(
null,
"Do you want to exit?\nPlease make sure that any work is saved",
"Rabbit In A Hat", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, objButtons, objButtons[1]
);
if (PromptResult==JOptionPane.YES_OPTION) {
System.exit(0);
}
doAskIfSavedBeforeExit();
}
});
frame.setPreferredSize(new Dimension(700, 600));
frame.setPreferredSize(getPreferredDimension());
frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
frame.setJMenuBar(createMenuBar());

Expand All @@ -147,6 +146,7 @@ public void windowClosing(WindowEvent e) {
ObjectExchange.etl = etl;

tableMappingPanel = new MappingPanel(etl.getTableToTableMapping());
tableMappingPanel.setName(PANEL_TABLE_MAPPING);
tableMappingPanel.addResizeListener(this);
scrollPane1 = new JScrollPane(tableMappingPanel);
scrollPane1.setBorder(new TitledBorder("Tables"));
Expand All @@ -157,6 +157,7 @@ public void windowClosing(WindowEvent e) {
scrollPane1.setBackground(Color.WHITE);

fieldMappingPanel = new MappingPanel(etl.getTableToTableMapping());
fieldMappingPanel.setName(PANEL_FIELD_MAPPING);
tableMappingPanel.setSlaveMappingPanel(fieldMappingPanel);
fieldMappingPanel.addResizeListener(this);
scrollPane2 = new JScrollPane(fieldMappingPanel);
Expand All @@ -168,6 +169,7 @@ public void windowClosing(WindowEvent e) {
tableFieldSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane1, scrollPane2);
tableFieldSplitPane.setDividerLocation(600);
tableFieldSplitPane.setDividerSize(0);
tableFieldSplitPane.setName("splitpane");

detailsPanel = new DetailsPanel();
detailsPanel.setBorder(new TitledBorder("Details"));
Expand Down Expand Up @@ -198,6 +200,20 @@ public void windowClosing(WindowEvent e) {
}
}

private void doAskIfSavedBeforeExit() {
String[] objButtons = {"Yes","No"};
int PromptResult = JOptionPane.showOptionDialog(
null,
"Do you want to exit?\nPlease make sure that any work is saved",
"Rabbit In A Hat", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, objButtons, objButtons[1]
);
if (PromptResult == JOptionPane.YES_OPTION) {
frame.dispose();
frame.invalidate();
}
}

private void loadIcons(JFrame f) {
List<Image> icons = new ArrayList<>();
icons.add(loadIcon("RabbitInAHat16.png", f));
Expand Down Expand Up @@ -228,10 +244,11 @@ private JMenuBar createMenuBar() {

menuBar.add(fileMenu);

addMenuItem(fileMenu, ACTION_OPEN_SCAN_REPORT, evt -> this.doOpenScanReport(), KeyEvent.VK_W);
addMenuItem(fileMenu, ACTION_OPEN_ETL_SPECS, evt -> this.doOpenSpecs(), KeyEvent.VK_O);
addMenuItem(fileMenu, ACTION_OPEN_SCAN_REPORT, evt -> this.doOpenScanReport(), KeyEvent.VK_W).setName(ACTION_OPEN_SCAN_REPORT);
addMenuItem(fileMenu, ACTION_OPEN_ETL_SPECS, evt -> this.doOpenSpecs(), KeyEvent.VK_O).setName(ACTION_OPEN_ETL_SPECS);
addMenuItem(fileMenu, ACTION_SAVE, evt -> this.doSave(), KeyEvent.VK_S);
addMenuItem(fileMenu, ACTION_SAVE_AS, evt -> this.doSaveAs());
addMenuItem(fileMenu, ACTION_EXIT, evt -> doAskIfSavedBeforeExit()).setName(ACTION_EXIT);

JMenu editMenu = new JMenu("Edit");
menuBar.add(editMenu);
Expand Down Expand Up @@ -301,6 +318,10 @@ private JMenuBar createMenuBar() {
return menuBar;
}

public JFrame getFrame() {
return this.frame;
}

public JMenuItem addMenuItem(JMenu menu, String description, ActionListener actionListener) {
return addMenuItem(menu, description, actionListener, null);
}
Expand Down Expand Up @@ -358,10 +379,10 @@ private String choosePath(boolean saveMode, boolean directoryMode, String preset
chooser.resetChoosableFileFilters();

if (directoryMode) {
chooser.setDialogTitle("Select Folder");
chooser.setDialogTitle(TITLE_SELECT_FOLDER);
chooser.setAcceptAllFileFilterUsed(false);
} else {
chooser.setDialogTitle("Select File");
chooser.setDialogTitle(TITLE_SELECT_FILE);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(primaryFileFilter);
for (int i = 1; i < filter.length; i++) {
Expand Down Expand Up @@ -449,8 +470,7 @@ private void doOpenDocumentation() {
try {
Desktop desktop = Desktop.getDesktop();
desktop.browse(new URI(DOCUMENTATION_URL));
} catch (URISyntaxException | IOException ex) {

} catch (URISyntaxException | IOException ignored) {
}
}

Expand Down Expand Up @@ -706,4 +726,24 @@ private void doUnmarkCompleted() {
this.tableMappingPanel.unmarkCompleted();
this.fieldMappingPanel.unmarkCompleted();
}

private Dimension getPreferredDimension() {
int preferredHeight = 700;
int preferredWidth = 600;

// for automated GUI testing: if screen size has been set for cacio: use it
String cacioScreenSize = System.getProperty("cacio.managed.screensize");
if (cacioScreenSize != null) {
Matcher matcher = Pattern.compile("^(\\d+)x(\\d+)$").matcher(cacioScreenSize);
if (matcher.matches()) {
if (matcher.groupCount() == 2) {
preferredHeight = Integer.parseInt(matcher.group(1));
preferredWidth = Integer.parseInt(matcher.group(2));
//System.out.println("Using cacio screen size: " + cacioScreenSize);
}
}
}

return new Dimension(preferredHeight, preferredWidth);
}
}
Loading

0 comments on commit bcbc1d8

Please sign in to comment.