Skip to content

Commit

Permalink
[wicket-poi] Fixing a test failing on jenkins CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
akiraly committed Apr 18, 2011
1 parent 93634e2 commit e35945a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 78 deletions.
45 changes: 4 additions & 41 deletions jdk-1.5-parent/wicket-poi-parent/wicket-poi-examples/pom.xml
Expand Up @@ -15,10 +15,6 @@

<name>WicketStuff POI - Example Web Application</name>

<properties>
<jetty.version>7.3.0.v20110203</jetty.version>
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
Expand All @@ -35,62 +31,29 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>

<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>inmethod-grid-examples</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</dependency>

<!-- JUNIT DEPENDENCY FOR TESTING -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>

<!-- JETTY DEPENDENCIES FOR TESTING -->
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all-server</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main/resources</directory>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<filtering>false</filtering>
<directory>src/test/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
</plugin>
</plugins>
</build>
Expand Down
Expand Up @@ -35,7 +35,6 @@
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.wicketstuff.minis.component.ListViewFormComponentReuseManager;
import org.wicketstuff.poi.excel.TableComponentAsXlsHandler;

Expand All @@ -50,15 +49,27 @@ public static class Row implements Serializable

public String key;
public Integer value;

public Row()
{
}

public Row(String key, Integer value)
{
this.key = key;
this.value = value;
}
}

private static final long serialVersionUID = 1L;

private final List<Row> rows = new ArrayList<Row>();

@SuppressWarnings("serial")
public ListViewFormComponentReuseManagerPage(final PageParameters parameters)
public ListViewFormComponentReuseManagerPage()
{
rows.add(new Row("foo", 0));
rows.add(new Row("bar", 1));
final Form<List<Row>> form = new Form<List<Row>>("rowsForm");
add(form);
form.add(new Button("addRowButton")
Expand All @@ -75,7 +86,7 @@ public void onSubmit()
public void onClick()
{
IRequestHandler handler = new TableComponentAsXlsHandler(form.get("rowsList"),
"example.xls");
"example.xls");
RequestCycle.get().scheduleRequestHandlerAfterCurrent(handler);
}
});
Expand All @@ -95,9 +106,9 @@ public Integer getObject()
}
}));
ListViewFormComponentReuseManager.addOrReuse(item, new RequiredTextField<String>(
"key", new PropertyModel<String>(row, "key")));
"key", new PropertyModel<String>(row, "key")));
ListViewFormComponentReuseManager.addOrReuse(item, new TextField<Integer>("value",
new PropertyModel<Integer>(row, "value")));
new PropertyModel<Integer>(row, "value")));

item.add(new SubmitLink("removeRowLink")
{
Expand Down
@@ -1,4 +1,4 @@
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" >
<html xmlns:wicket="http://wicket.apache.org" >
<head><title>ListViewFormComponentReuseManager Test</title></head>
<body>
Add rows, enter values and move them around without submit the values via the submit button first.
Expand Down
Expand Up @@ -16,10 +16,6 @@
*/
package org.wicketstuff.poi;

import java.awt.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import junit.framework.TestCase;
Expand All @@ -30,53 +26,31 @@
import org.apache.wicket.util.tester.WicketTester;
import org.wicketstuff.poi.excel.TableComponentAsXlsHandler;

import com.inmethod.grid.examples.pages.datagrid.SimpleDataGridPage;

/**
* @author Pedro Santos
*/
public class SimpleDataGridPageTest extends TestCase
{
public void testExportToExcel() throws IOException
{
WicketTester tester = new WicketTester(new com.inmethod.grid.examples.WicketApplication());
WicketTester tester = new WicketTester(new WicketApplication());
tester.startPage(TestPage.class);
tester.executeListener(tester.getLastRenderedPage(), ILinkListener.INTERFACE);
assertTrue(tester.getLastResponse().getHeader("Content-Disposition").contains(".xls"));
// openFileInResponse(tester);
}

public static class TestPage extends SimpleDataGridPage implements ILinkListener
public static class TestPage extends ListViewFormComponentReuseManagerPage implements
ILinkListener
{
/** */
private static final long serialVersionUID = 1L;

public void onLinkClicked()
{
IRequestHandler handler = new TableComponentAsXlsHandler(
get("grid:form:bodyContainer:body"), "example.xls");
IRequestHandler handler = new TableComponentAsXlsHandler(get("rowsForm:rowsList"),
"example.xls");
RequestCycle.get().scheduleRequestHandlerAfterCurrent(handler);
}

}

/**
* Utility method for test
*
* @param tester
* @throws IOException
* @throws FileNotFoundException
*/
public static void openFileInResponse(WicketTester tester) throws IOException,
FileNotFoundException
{
File f = new File(System.getProperty("user.home") + "\\test.xls");
f.delete();
f.createNewFile();
FileOutputStream out = new FileOutputStream(f);
out.write(tester.getLastResponse().getBinaryContent());
out.close();
Desktop d = Desktop.getDesktop();
d.open(f);
}
}

0 comments on commit e35945a

Please sign in to comment.