summaryrefslogtreecommitdiffstats
path: root/uitest/src
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-04-03 10:23:58 +0300
committerArtur Signell <artur@vaadin.com>2013-04-03 10:24:00 +0300
commitd7bfb3a99cf2dee5a7622645357bfd606585b283 (patch)
treed4353f87d3ef52743426343c937eefe9a4aca9ed /uitest/src
parentce2df6d10370c669a512e96f0693fc37cf02aca1 (diff)
parent5d8b1862b63d32070b4084d7e49cae1f4bc66953 (diff)
downloadvaadin-framework-d7bfb3a99cf2dee5a7622645357bfd606585b283.tar.gz
vaadin-framework-d7bfb3a99cf2dee5a7622645357bfd606585b283.zip
Merge commit '5d8b1862b63d32070b4084d7e49cae1f4bc66953'
Change-Id: I329cab3a4a039cd41486353d41d678abf29cb6a9
Diffstat (limited to 'uitest/src')
-rw-r--r--uitest/src/com/vaadin/tests/integration/JSR286Portlet.java214
-rw-r--r--uitest/src/com/vaadin/tests/integration/JSR286PortletApplication.java195
2 files changed, 214 insertions, 195 deletions
diff --git a/uitest/src/com/vaadin/tests/integration/JSR286Portlet.java b/uitest/src/com/vaadin/tests/integration/JSR286Portlet.java
new file mode 100644
index 0000000000..859175394d
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/integration/JSR286Portlet.java
@@ -0,0 +1,214 @@
+package com.vaadin.tests.integration;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.EventRequest;
+import javax.portlet.EventResponse;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletURL;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import javax.portlet.WindowState;
+
+import com.vaadin.annotations.StyleSheet;
+import com.vaadin.server.ExternalResource;
+import com.vaadin.server.VaadinPortletRequest;
+import com.vaadin.server.VaadinPortletService;
+import com.vaadin.server.VaadinPortletSession;
+import com.vaadin.server.VaadinPortletSession.PortletListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.ui.Embedded;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Link;
+import com.vaadin.ui.Notification;
+import com.vaadin.ui.Notification.Type;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.Upload;
+import com.vaadin.ui.Upload.Receiver;
+import com.vaadin.ui.VerticalLayout;
+
+/**
+ * Adapted from old PortletDemo to support integration testing.
+ */
+@StyleSheet("PortletConnectorResource.css")
+public class JSR286Portlet extends UI {
+
+ TextField tf = new TextField("Some value");
+ Label userInfo = new Label();
+ Link portletEdit = new Link();
+ Link portletMax = new Link();
+ Link someAction = null;
+ private VerticalLayout main = new VerticalLayout();
+
+ @Override
+ protected void init(VaadinRequest request) {
+ setContent(main);
+ Embedded appResourceTest = new Embedded(
+ "Test of ApplicationResources with full path",
+ new FlagSeResource());
+ main.addComponent(appResourceTest);
+ Embedded specialNameResourceTest = new Embedded(
+ "Test ApplicationResources with special names",
+ new SpecialNameResource());
+ specialNameResourceTest.addStyleName("hugeBorder");
+ main.addComponent(specialNameResourceTest);
+
+ userInfo.setCaption("User info");
+ userInfo.setContentMode(ContentMode.PREFORMATTED);
+ main.addComponent(userInfo);
+
+ tf.setEnabled(false);
+ tf.setImmediate(true);
+ main.addComponent(tf);
+
+ portletEdit.setEnabled(false);
+ main.addComponent(portletEdit);
+ portletMax.setEnabled(false);
+ main.addComponent(portletMax);
+
+ Upload upload = new Upload("Upload a file", new Receiver() {
+
+ @Override
+ public OutputStream receiveUpload(String filename, String mimeType) {
+ return new ByteArrayOutputStream();
+ }
+ });
+ main.addComponent(upload);
+
+ possiblyChangedModeOrState();
+ getSession().addPortletListener(new DemoPortletListener());
+ }
+
+ @Override
+ public VaadinPortletSession getSession() {
+ return (VaadinPortletSession) super.getSession();
+ }
+
+ private void possiblyChangedModeOrState() {
+ VaadinPortletRequest request = (VaadinPortletRequest) VaadinPortletService
+ .getCurrentRequest();
+
+ boolean inViewMode = (request.getPortletMode() == PortletMode.VIEW);
+ boolean inNormalState = (request.getWindowState() == WindowState.NORMAL);
+ // Portlet up-and-running, enable stuff
+ portletEdit.setEnabled(true);
+ portletMax.setEnabled(true);
+
+ // Editable if we're in editmode
+ tf.setEnabled(!inViewMode);
+
+ // Show notification about current mode and state
+ getPage().showNotification(
+ new Notification("Portlet status", "Mode: "
+ + request.getPortletMode() + " State: "
+ + request.getWindowState(), Type.WARNING_MESSAGE));
+
+ // Display current user info
+ Map<?, ?> uinfo = (Map<?, ?>) request
+ .getAttribute(PortletRequest.USER_INFO);
+ if (uinfo != null) {
+ String s = "";
+ for (Iterator<?> it = uinfo.keySet().iterator(); it.hasNext();) {
+ Object key = it.next();
+ Object val = uinfo.get(key);
+ s += key + ": " + val + "\n";
+ }
+ if (request.isUserInRole("administrator")) {
+ s += "(administrator)";
+ }
+ userInfo.setValue(s);
+ } else {
+ userInfo.setValue("-");
+ }
+
+ // Create Edit/Done link (actionUrl)
+ PortletURL url = getSession().generateActionURL("changeMode");
+ try {
+ if (inViewMode) {
+ url.setPortletMode(PortletMode.EDIT);
+ portletEdit.setCaption("Edit");
+ } else {
+ url.setPortletMode(PortletMode.VIEW);
+ portletEdit.setCaption("Done");
+ }
+ portletEdit.setResource(new ExternalResource(url.toString()));
+ } catch (Exception e) {
+ portletEdit.setEnabled(false);
+ Logger.getLogger(getClass().getName()).log(Level.SEVERE,
+ "Error creating edit mode link", e);
+ }
+
+ // Create Maximize/Normal link (actionUrl)
+ url = getSession().generateActionURL("changeState");
+ try {
+ if (inNormalState) {
+ url.setWindowState(WindowState.MAXIMIZED);
+ portletMax.setCaption("Maximize");
+ } else {
+ url.setWindowState(WindowState.NORMAL);
+ portletMax.setCaption("Back to normal");
+
+ }
+ portletMax.setResource(new ExternalResource(url.toString()));
+ } catch (Exception e) {
+ portletMax.setEnabled(false);
+ Logger.getLogger(getClass().getName()).log(Level.SEVERE,
+ "Error creating state change link", e);
+ }
+
+ if (someAction == null) {
+ url = getSession().generateActionURL("someAction");
+ try {
+ someAction = new Link("An action", new ExternalResource(
+ url.toString()));
+ main.addComponent(someAction);
+ } catch (Exception e) {
+ // Oops
+ System.err.println("Could not create someAction: " + e);
+ }
+
+ }
+ }
+
+ private class DemoPortletListener implements PortletListener {
+
+ @Override
+ public void handleActionRequest(ActionRequest request,
+ ActionResponse response, UI window) {
+ main.addComponent(new Label("Action '"
+ + request.getParameter("javax.portlet.action")
+ + "' received"));
+ }
+
+ @Override
+ public void handleRenderRequest(RenderRequest request,
+ RenderResponse response, UI window) {
+ possiblyChangedModeOrState();
+ }
+
+ @Override
+ public void handleEventRequest(EventRequest request,
+ EventResponse response, UI window) {
+ // events not used by this test
+ }
+
+ @Override
+ public void handleResourceRequest(ResourceRequest request,
+ ResourceResponse response, UI window) {
+ // nothing special to do here
+ }
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/integration/JSR286PortletApplication.java b/uitest/src/com/vaadin/tests/integration/JSR286PortletApplication.java
deleted file mode 100644
index 81b7ebb653..0000000000
--- a/uitest/src/com/vaadin/tests/integration/JSR286PortletApplication.java
+++ /dev/null
@@ -1,195 +0,0 @@
-package com.vaadin.tests.integration;
-
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.EventRequest;
-import javax.portlet.EventResponse;
-import javax.portlet.PortletMode;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletURL;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.portlet.ResourceRequest;
-import javax.portlet.ResourceResponse;
-import javax.portlet.WindowState;
-
-import com.vaadin.annotations.StyleSheet;
-import com.vaadin.server.ExternalResource;
-import com.vaadin.server.LegacyApplication;
-import com.vaadin.server.VaadinPortletSession;
-import com.vaadin.server.VaadinPortletSession.PortletListener;
-import com.vaadin.shared.ui.label.ContentMode;
-import com.vaadin.ui.Embedded;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.LegacyWindow;
-import com.vaadin.ui.Link;
-import com.vaadin.ui.Notification;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.UI;
-import com.vaadin.ui.Upload;
-import com.vaadin.ui.Upload.Receiver;
-
-/**
- * Adapted from old PortletDemo to support integration testing.
- */
-public class JSR286PortletApplication extends LegacyApplication {
-
- @StyleSheet("PortletConnectorResource.css")
- public final class LegacyWindowWithStylesheet extends LegacyWindow {
-
- }
-
- LegacyWindow main = new LegacyWindowWithStylesheet();
- TextField tf = new TextField("Some value");
- Label userInfo = new Label();
- Link portletEdit = new Link();
- Link portletMax = new Link();
- Link someAction = null;
-
- @Override
- public void init() {
- setMainWindow(main);
-
- Embedded appResourceTest = new Embedded(
- "Test of ApplicationResources with full path",
- new FlagSeResource());
- main.addComponent(appResourceTest);
- Embedded specialNameResourceTest = new Embedded(
- "Test ApplicationResources with special names",
- new SpecialNameResource());
- specialNameResourceTest.addStyleName("hugeBorder");
- main.addComponent(specialNameResourceTest);
-
- userInfo.setCaption("User info");
- userInfo.setContentMode(ContentMode.PREFORMATTED);
- main.addComponent(userInfo);
-
- tf.setEnabled(false);
- tf.setImmediate(true);
- main.addComponent(tf);
-
- portletEdit.setEnabled(false);
- main.addComponent(portletEdit);
- portletMax.setEnabled(false);
- main.addComponent(portletMax);
-
- Upload upload = new Upload("Upload a file", new Receiver() {
-
- @Override
- public OutputStream receiveUpload(String filename, String mimeType) {
- return new ByteArrayOutputStream();
- }
- });
- main.addComponent(upload);
-
- if (getContext() instanceof VaadinPortletSession) {
- VaadinPortletSession ctx = (VaadinPortletSession) getContext();
- ctx.addPortletListener(new DemoPortletListener());
- } else {
- getMainWindow().showNotification("Not inited via Portal!",
- Notification.TYPE_ERROR_MESSAGE);
- }
-
- }
-
- private class DemoPortletListener implements PortletListener {
-
- @Override
- public void handleActionRequest(ActionRequest request,
- ActionResponse response, UI window) {
- main.addComponent(new Label("Action received"));
- }
-
- @Override
- public void handleRenderRequest(RenderRequest request,
- RenderResponse response, UI window) {
- // Portlet up-and-running, enable stuff
- portletEdit.setEnabled(true);
- portletMax.setEnabled(true);
-
- // Editable if we're in editmode
- tf.setEnabled((request.getPortletMode() == PortletMode.EDIT));
-
- // Show notification about current mode and state
- getMainWindow().showNotification(
- "Portlet status",
- "Mode: " + request.getPortletMode() + " State: "
- + request.getWindowState(),
- Notification.TYPE_WARNING_MESSAGE);
-
- // Display current user info
- Map<?, ?> uinfo = (Map<?, ?>) request
- .getAttribute(PortletRequest.USER_INFO);
- if (uinfo != null) {
- String s = "";
- for (Iterator<?> it = uinfo.keySet().iterator(); it.hasNext();) {
- Object key = it.next();
- Object val = uinfo.get(key);
- s += key + ": " + val + "\n";
- }
- if (request.isUserInRole("administrator")) {
- s += "(administrator)";
- }
- userInfo.setValue(s);
- } else {
- userInfo.setValue("-");
- }
-
- // Create Edit/Done link (actionUrl)
- PortletURL url = response.createActionURL();
- try {
- url.setPortletMode((request.getPortletMode() == PortletMode.VIEW ? PortletMode.EDIT
- : PortletMode.VIEW));
- portletEdit.setResource(new ExternalResource(url.toString()));
- portletEdit
- .setCaption((request.getPortletMode() == PortletMode.VIEW ? "Edit"
- : "Done"));
- } catch (Exception e) {
- portletEdit.setEnabled(false);
- }
- // Create Maximize/Normal link (actionUrl)
- url = response.createActionURL();
- try {
- url.setWindowState((request.getWindowState() == WindowState.NORMAL ? WindowState.MAXIMIZED
- : WindowState.NORMAL));
- portletMax.setResource(new ExternalResource(url.toString()));
- portletMax
- .setCaption((request.getWindowState() == WindowState.NORMAL ? "Maximize"
- : "Back to normal"));
- } catch (Exception e) {
- portletMax.setEnabled(false);
- }
-
- if (someAction == null) {
- url = response.createActionURL();
- try {
- someAction = new Link("An action", new ExternalResource(
- url.toString()));
- main.addComponent(someAction);
- } catch (Exception e) {
- // Oops
- System.err.println("Could not create someAction: " + e);
- }
-
- }
- }
-
- @Override
- public void handleEventRequest(EventRequest request,
- EventResponse response, UI window) {
- // events not used by this test
- }
-
- @Override
- public void handleResourceRequest(ResourceRequest request,
- ResourceResponse response, UI window) {
- // nothing special to do here
- }
- }
-
-}