Author: mwringe
Date: 2010-08-16 18:42:41 -0400 (Mon, 16 Aug 2010)
New Revision: 3836
Added:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/support/
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/v2/WSRP2Producer.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/portlet/StatePortlet.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
Log:
GTNPC-26: Add tests for the persistence export manager, fix issues with exporting by
value.
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java 2010-08-16
17:09:43 UTC (rev 3835)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java 2010-08-16
22:42:41 UTC (rev 3836)
@@ -26,6 +26,7 @@
import java.io.UnsupportedEncodingException;
import org.gatein.exports.data.ExportContext;
+import org.gatein.exports.data.ExportData;
import org.gatein.exports.data.ExportPortletData;
import org.oasis.wsrp.v2.Lifetime;
import org.oasis.wsrp.v2.OperationFailed;
@@ -57,6 +58,6 @@
Lifetime setExportLifetime(ExportContext exportContext, Lifetime lifetime) throws
OperationFailed, OperationNotSupported;
- void releaseExport(ExportContext exportContext);
+ void releaseExport(byte[] bytes) throws IOException;
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java 2010-08-16
17:09:43 UTC (rev 3835)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportPersistenceManager.java 2010-08-16
22:42:41 UTC (rev 3836)
@@ -22,6 +22,9 @@
******************************************************************************/
package org.gatein.exports;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
import org.gatein.exports.data.ExportContext;
import org.gatein.exports.data.ExportPortletData;
import org.oasis.wsrp.v2.Lifetime;
@@ -31,8 +34,7 @@
* @version $Revision$
*/
public interface ExportPersistenceManager
-{
-
+{
String storeExportContextData(ExportContext exportContextData);
String storeExportPortletData(ExportPortletData exportPortletData);
@@ -43,6 +45,32 @@
Lifetime updateExportLifetime(ExportContext exportContext, Lifetime lifetime);
- void releaseExport(ExportContext exportContext);
+ void releaseExport(byte[] bytes);
+
+ /**
+ * Returns true if the PersistenceManager knows how to decode a byte array with
+ * the specified type and version.
+ *
+ * @param type The type of export
+ * @param version The version of the export
+ * @return True if the persistence manager can support the specified type and
version.
+ */
+ boolean supports(String type, double version);
+
+ /**
+ * Based on the specified type and version, the bytes will be
+ * decoded into an ExportContext.
+ *
+ * @param type The type
+ * @param version The version
+ * @param bytes The bytes to decode
+ * @return
+ * @throws UnsupportedEncodingException
+ */
+ ExportContext getExportContext(String type, double version, byte[] bytes) throws
UnsupportedEncodingException;
+
+ byte[] encodeExportPortletData(ExportContext exportContext, ExportPortletData
exportPortlet);
+
+ byte[] encodeExportContextData(ExportContext exportContext) throws IOException;
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java 2010-08-16
17:09:43 UTC (rev 3835)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/PersistedExportData.java 2010-08-16
22:42:41 UTC (rev 3836)
@@ -36,11 +36,12 @@
{
protected final String type;
protected final String refID;
- protected static final double VERSION = 1.0;
protected static final String REFIDKEY = "rID";
protected static final String TYPEKEY = "type";
+ protected double version = 1.0;
+
public PersistedExportData(String type, String refID)
{
this.type = type;
@@ -54,14 +55,24 @@
public double getVersion()
{
- return VERSION;
+ return version;
}
+
+ public String getRefId()
+ {
+ return refID;
+ }
+
+ public void setVersion(double version)
+ {
+ this.version = version;
+ }
protected byte[] internalEncodeAsBytes() throws UnsupportedEncodingException
{
ParametersStateString parameterStateString = ParametersStateString.create();
- parameterStateString.setValue(REFIDKEY, REFIDKEY);
+ parameterStateString.setValue(REFIDKEY, refID);
parameterStateString.setValue(TYPEKEY, type);
String stateString = parameterStateString.getStringValue();
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java 2010-08-16
17:09:43 UTC (rev 3835)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java 2010-08-16
22:42:41 UTC (rev 3836)
@@ -31,6 +31,7 @@
import org.gatein.exports.data.ExportContext;
import org.gatein.exports.data.ExportData;
import org.gatein.exports.data.ExportPortletData;
+import org.gatein.exports.data.PersistedExportData;
import org.gatein.wsrp.WSRPExceptionFactory;
import org.oasis.wsrp.v2.Lifetime;
import org.oasis.wsrp.v2.OperationFailed;
@@ -78,6 +79,11 @@
return supportExportByValue;
}
+ public void setPreferExportByValue(boolean preferExportByValue)
+ {
+ this.preferExportByValue = preferExportByValue;
+ }
+
public ExportContext createExportContext(byte[] bytes) throws OperationFailed
{
try
@@ -89,6 +95,10 @@
byte[] internalBytes = ExportData.getInternalBytes(bytes);
return ExportContext.create(internalBytes);
}
+ else if (exportPersistenceManager != null &&
exportPersistenceManager.supports(type, version))
+ {
+ return exportPersistenceManager.getExportContext(type, version,
ExportData.getInternalBytes(bytes));
+ }
else
{
throw WSRPExceptionFactory.createWSException(OperationFailed.class, "Byte
array format not compatible.", null);
@@ -144,7 +154,7 @@
}
else
{
- throw new NotYetImplemented();
+ return exportPersistenceManager.encodeExportPortletData(exportContextData,
exportPortletData);
}
}
@@ -156,30 +166,35 @@
}
else
{
- throw new NotYetImplemented();
+ return exportPersistenceManager.encodeExportContextData(exportContextData);
}
}
public Lifetime setExportLifetime(ExportContext exportContext, Lifetime lifetime)
throws OperationFailed, OperationNotSupported
{
- if (exportContext.isExportByValue())
- {
- WSRPExceptionFactory.throwWSException(OperationFailed.class, "Cannot set
the lifetime for an export that was exported by value.", null);
- }
if (getPersistenceManager() == null)
{
WSRPExceptionFactory.throwWSException(OperationNotSupported.class, "The
producer only supports export by value. Cannot call setExportLifetime on this
producer", null);
}
-
+ else if (exportContext.isExportByValue())
+ {
+ WSRPExceptionFactory.throwWSException(OperationFailed.class, "Cannot set
the lifetime for an export that was exported by value.", null);
+ }
+
return getPersistenceManager().updateExportLifetime(exportContext, lifetime);
}
- public void releaseExport(ExportContext exportContext)
+ public void releaseExport(byte[] bytes) throws IOException
{
//TODO: since we can't return any errors, we should at least log messages if
this method is called and it can't be completed for some reason.
- if (exportContext != null && !exportContext.isExportByValue() &&
exportPersistenceManager!= null)
+ if (bytes != null && bytes.length > 0 &&
exportPersistenceManager!= null)
{
- exportPersistenceManager.releaseExport(exportContext);
+ String type = ExportData.getType(bytes);
+ double version = ExportData.getVersion(bytes);
+ if (exportPersistenceManager.supports(type, version))
+ {
+ exportPersistenceManager.releaseExport(ExportData.getInternalBytes(bytes));
+ }
}
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java 2010-08-16
17:09:43 UTC (rev 3835)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/PortletManagementHandler.java 2010-08-16
22:42:41 UTC (rev 3836)
@@ -550,6 +550,7 @@
ExportPortletData exportPortletData =
producer.getExportManager().createExportPortletData(exportContext, portletHandle,
portletState);
//Create the exportedPortlet
+ byte[] exportPortletBytes =
producer.getExportManager().encodeExportPortletData(exportContext, exportPortletData);
ExportedPortlet exportedPortlet =
WSRPTypeFactory.createExportedPortlet(portletHandle, exportPortletData.encodeAsBytes());
exportedPortlets.add(exportedPortlet);
}
@@ -593,12 +594,13 @@
//TODO: handle resourceLists better (should be using for things like errors)
ResourceList resourceList = null;
- return
WSRPTypeFactory.createExportPortletsResponse(exportContext.encodeAsBytes(),
exportedPortlets, new ArrayList<FailedPortlets>(failedPortletsMap.values()),
exportContext.getLifeTime(), resourceList);
+ byte[] exportContextBytes =
producer.getExportManager().encodeExportContextData(exportContext);
+
+ return WSRPTypeFactory.createExportPortletsResponse(exportContextBytes,
exportedPortlets, new ArrayList<FailedPortlets>(failedPortletsMap.values()),
exportContext.getLifeTime(), resourceList);
}
- catch (Exception e)//TODO ADD PROPER EXCEPTION HANDLING
+ catch (Exception e)
{
- e.printStackTrace();
- throw new OperationFailed("TODO: add proper error handling", new
OperationFailedFault());
+ throw new OperationFailed("Operation Failed while trying to
ExportPortlets.", new OperationFailedFault());
}
finally
{
@@ -721,10 +723,9 @@
{
try
{
- if (releaseExport != null)
+ if (releaseExport != null && releaseExport.getExportContext() != null)
{
- ExportContext exportContext =
producer.getExportManager().createExportContext(releaseExport.getExportContext());
- producer.getExportManager().releaseExport(exportContext);
+ producer.getExportManager().releaseExport(releaseExport.getExportContext());
}
}
catch (Exception e)
@@ -739,8 +740,14 @@
return new ReturnAny().getExtensions();
}
- public Lifetime setExportLifetime(SetExportLifetime setExportLifetime) throws
OperationFailed, InvalidRegistration
+ public Lifetime setExportLifetime(SetExportLifetime setExportLifetime) throws
OperationFailed, InvalidRegistration, OperationNotSupported
{
+ //this method is only valid if the producer can handle exporting by reference.
+ if (producer.getExportManager().getPersistenceManager() == null)
+ {
+ WSRP2ExceptionFactory.throwWSException(OperationNotSupported.class, "This
producer does not support export by reference.", null);
+ }
+
WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(setExportLifetime,
"setExportLifetimePortlets");
byte[] exportContextBytes = setExportLifetime.getExportContext();
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/v2/WSRP2Producer.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/v2/WSRP2Producer.java 2010-08-16
17:09:43 UTC (rev 3835)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/v2/WSRP2Producer.java 2010-08-16
22:42:41 UTC (rev 3836)
@@ -23,6 +23,7 @@
package org.gatein.wsrp.producer.v2;
+import org.gatein.exports.ExportManager;
import org.gatein.wsrp.producer.MarkupInterface;
import org.gatein.wsrp.producer.PortletManagementInterface;
import org.gatein.wsrp.producer.RegistrationInterface;
@@ -36,4 +37,17 @@
public interface WSRP2Producer extends WSRPProducer, MarkupInterface,
PortletManagementInterface,
RegistrationInterface, ServiceDescriptionInterface
{
+ /**
+ * Retrieves the ExportManager used by this WSRPProducer.
+ *
+ * @return The ExportManager used by this WSRPProducer to manage exports
+ */
+ ExportManager getExportManager();
+
+ /**
+ * Sets the ExportManager used by this WSRPProducer
+ *
+ * @param The ExportManager to be used by this WSRPProducer
+ */
+ void setExportManager(ExportManager exportManager);
}
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/portlet/StatePortlet.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/portlet/StatePortlet.java 2010-08-16
17:09:43 UTC (rev 3835)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/portlet/StatePortlet.java 2010-08-16
22:42:41 UTC (rev 3836)
@@ -44,7 +44,6 @@
public void processAction(ActionRequest request, ActionResponse response) throws
PortletException, PortletSecurityException, IOException
{
- System.out.println("PROCESSACTION");
String value = request.getParameter("value");
if (value == null)
{
@@ -58,34 +57,10 @@
protected void doView(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
{
- System.out.println("DOVIEW");
resp.setContentType("text/html");
PortletPreferences pp = req.getPreferences();
String value = pp.getValue("name", "default");
resp.getWriter().write(value);
}
-
-
-// protected void doView(RenderRequest req, RenderResponse resp) throws
PortletException, PortletSecurityException, IOException
-// {
-// resp.setContentType("text/html");
-// PrintWriter writer = resp.getWriter();
-//
-// PortletPreferences pp = req.getPreferences();
-// int count = 0;
-//
-// if (!pp.getValue(COUNT, "0").equals("0"))
-// {
-// count = Integer.parseInt(pp.getValue(COUNT, "0")) + 1;
-// }
-//
-// pp.setValue(COUNT, "" + count);
-// pp.store();
-//
-// writer.write("<p>count = " + count + "</p>");
-//
-// //
-// writer.close();
-// }
}
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java 2010-08-16
17:09:43 UTC (rev 3835)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java 2010-08-16
22:42:41 UTC (rev 3836)
@@ -147,7 +147,6 @@
// so we need to wait for the proper case to init the registration context...
Hackish! :(
if (index == 0)
{
- System.out.println("REGISTRATIONCONTEXT : " +
releaseSessions.getRegistrationContext());
releaseSessions.setRegistrationContext(registerConsumer());
}
}
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-16
17:09:43 UTC (rev 3835)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-16
22:42:41 UTC (rev 3836)
@@ -23,8 +23,6 @@
package org.gatein.wsrp.protocol.v2;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -32,20 +30,18 @@
import org.gatein.exports.ExportManager;
import org.gatein.exports.data.ExportContext;
-import org.gatein.exports.data.ExportData;
import org.gatein.exports.data.ExportPortletData;
+import org.gatein.exports.data.PersistedExportData;
import org.gatein.exports.impl.ExportManagerImpl;
-import org.gatein.pc.api.Portlet;
import org.gatein.pc.api.PortletStateType;
import org.gatein.pc.api.state.PropertyMap;
import org.gatein.pc.portlet.state.SimplePropertyMap;
import org.gatein.pc.portlet.state.producer.PortletState;
import org.gatein.pc.portlet.state.producer.ProducerPortletInvoker;
import org.gatein.wsrp.WSRPTypeFactory;
-import org.gatein.wsrp.WSRPUtils;
import org.gatein.wsrp.producer.WSRPProducerBaseTest;
import org.gatein.wsrp.servlet.ServletAccess;
-import org.gatein.wsrp.spec.v2.WSRP2RewritingConstants;
+import org.gatein.wsrp.support.TestMockExportPersistenceManager;
import org.gatein.wsrp.test.ExtendedAssert;
import org.gatein.wsrp.test.support.MockHttpServletRequest;
import org.gatein.wsrp.test.support.MockHttpServletResponse;
@@ -57,7 +53,6 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.oasis.wsrp.v2.AccessDenied;
import org.oasis.wsrp.v2.BlockingInteractionResponse;
import org.oasis.wsrp.v2.ExportPortlets;
import org.oasis.wsrp.v2.ExportPortletsResponse;
@@ -68,30 +63,20 @@
import org.oasis.wsrp.v2.ImportPortlets;
import org.oasis.wsrp.v2.ImportPortletsResponse;
import org.oasis.wsrp.v2.ImportedPortlet;
-import org.oasis.wsrp.v2.InconsistentParameters;
-import org.oasis.wsrp.v2.InvalidCookie;
-import org.oasis.wsrp.v2.InvalidHandle;
import org.oasis.wsrp.v2.InvalidRegistration;
-import org.oasis.wsrp.v2.InvalidSession;
-import org.oasis.wsrp.v2.InvalidUserCategory;
import org.oasis.wsrp.v2.Lifetime;
-import org.oasis.wsrp.v2.MarkupContext;
-import org.oasis.wsrp.v2.MarkupParams;
import org.oasis.wsrp.v2.MarkupResponse;
import org.oasis.wsrp.v2.MissingParameters;
-import org.oasis.wsrp.v2.ModifyRegistrationRequired;
import org.oasis.wsrp.v2.NamedString;
import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.OperationNotSupported;
import org.oasis.wsrp.v2.PerformBlockingInteraction;
import org.oasis.wsrp.v2.PortletContext;
import org.oasis.wsrp.v2.RegistrationContext;
import org.oasis.wsrp.v2.RegistrationData;
-import org.oasis.wsrp.v2.ResourceSuspended;
+import org.oasis.wsrp.v2.ReleaseExport;
+import org.oasis.wsrp.v2.SetExportLifetime;
import org.oasis.wsrp.v2.StateChange;
-import org.oasis.wsrp.v2.UnsupportedLocale;
-import org.oasis.wsrp.v2.UnsupportedMimeType;
-import org.oasis.wsrp.v2.UnsupportedMode;
-import org.oasis.wsrp.v2.UnsupportedWindowState;
import org.oasis.wsrp.v2.UserContext;
/**
@@ -115,6 +100,7 @@
jar.addClass(NeedPortletHandleTest.class);
jar.addClass(V2ProducerBaseTest.class);
jar.addClass(WSRPProducerBaseTest.class);
+ jar.addClass(TestMockExportPersistenceManager.class);
return jar;
}
@@ -127,6 +113,8 @@
//hack to get around having to have a httpservletrequest when accessing the
producer services
//I don't know why its really needed, seems to be a dependency where wsrp
connects with the pc module
ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(null),
MockHttpServletResponse.createMockResponse());
+ producer.getExportManager().setPersistanceManager(null);
+ ((ExportManagerImpl)(producer.getExportManager())).setPreferExportByValue(true);
}
}
@@ -152,18 +140,9 @@
ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
- assertNotNull(response.getExportContext());
- assertNull(response.getLifetime());
- assertTrue(response.getFailedPortlets().isEmpty());
+ checkValidHandle(response, handle);
+ }
- assertEquals(1, response.getExportedPortlet().size());
-
- ExportedPortlet exportPortlet = response.getExportedPortlet().get(0);
-
- assertEquals(handle, exportPortlet.getPortletHandle());
- }
-
-
@Test
public void testExportNonExistantHandle() throws Exception
{
@@ -171,19 +150,9 @@
List<PortletContext> portletContexts =
createPortletContextList(nonExistantHandle);
ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
-
ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
- assertNotNull(response.getExportContext());
- assertNull(response.getLifetime());
- assertTrue(response.getExportedPortlet().isEmpty());
-
- assertEquals(1, response.getFailedPortlets().size());
-
- FailedPortlets failedPortlet = response.getFailedPortlets().get(0);
-
- assertTrue(failedPortlet.getPortletHandles().contains(nonExistantHandle));
-
assertEquals("InvalidHandle",failedPortlet.getErrorCode().getLocalPart());
+ checkInvalidHandle(response, nonExistantHandle);
}
@Test
@@ -196,47 +165,10 @@
ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
- assertNotNull(response.getExportContext());
- assertNull(response.getLifetime());
- assertTrue(response.getExportedPortlet().isEmpty());
-
- assertEquals(1, response.getFailedPortlets().size());
-
- FailedPortlets failedPortlet = response.getFailedPortlets().get(0);
- assertTrue(failedPortlet.getPortletHandles().contains(nullHandle));
-
assertEquals("InvalidHandle",failedPortlet.getErrorCode().getLocalPart());
+ checkInvalidHandle(response, nullHandle);
}
@Test
- public void testExportNullExportContext() throws Exception
- {
- ExportPortlets exportPortlets = new ExportPortlets();
- try
- {
- ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
- ExtendedAssert.fail("Should have thrown a MissingParameters fault if no
portlets passed for export.");
- }
- catch (MissingParameters e)
- {
- //expected
- }
- }
-
- @Test
- public void testExportNullExportPortlets() throws Exception
- {
- try
- {
- ExportPortletsResponse response = producer.exportPortlets(null);
- ExtendedAssert.fail("Should have failed if sending a null exportPortlet
object");
- }
- catch (MissingParameters e)
- {
- //expected
- }
- }
-
- @Test
public void testExportNoRegistrationWhenRequired() throws Exception
{
producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
@@ -256,7 +188,7 @@
//expected
}
}
-
+
@Test
public void testExportBadRegistrationHandle() throws Exception
{
@@ -269,7 +201,6 @@
boolean exportByValueRequired = true;
Lifetime lifetime = null;
UserContext userContext = null;
-
ExportPortlets exportPortlets =
WSRPTypeFactory.createExportPortlets(registrationContext, portletContexts, userContext,
lifetime, exportByValueRequired);
try
@@ -282,7 +213,7 @@
//expected
}
}
-
+
@Test
public void testExportRegistrationRequired() throws Exception
{
@@ -291,29 +222,48 @@
RegistrationData registrationData =
WSRPTypeFactory.createRegistrationData("CONSUMER", true);
RegistrationContext registrationContext = producer.register(registrationData);
-
List<PortletContext> portletContexts =
createPortletContextList(getDefaultHandle());
boolean exportByValueRequired = true;
Lifetime lifetime = null;
UserContext userContext = null;
-
ExportPortlets exportPortlets =
WSRPTypeFactory.createExportPortlets(registrationContext, portletContexts, userContext,
lifetime, exportByValueRequired);
ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
- assertNotNull(response.getExportContext());
- assertNull(response.getLifetime());
- assertTrue(response.getFailedPortlets().isEmpty());
-
- assertEquals(1, response.getExportedPortlet().size());
-
- ExportedPortlet exportPortlet = response.getExportedPortlet().get(0);
-
- assertEquals(getDefaultHandle(), exportPortlet.getPortletHandle());
+ checkValidHandle(response, getDefaultHandle());
}
+
+ @Test
+ public void testExportNullExportContext() throws Exception
+ {
+ ExportPortlets exportPortlets = new ExportPortlets();
+ try
+ {
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+ ExtendedAssert.fail("Should have thrown a MissingParameters fault if no
portlets passed for export.");
+ }
+ catch (MissingParameters e)
+ {
+ //expected
+ }
+ }
@Test
+ public void testExportNullExportPortlets() throws Exception
+ {
+ try
+ {
+ ExportPortletsResponse response = producer.exportPortlets(null);
+ ExtendedAssert.fail("Should have failed if sending a null exportPortlet
object");
+ }
+ catch (MissingParameters e)
+ {
+ //expected
+ }
+ }
+
+ @Test
public void testExports() throws Exception
{
String nullHandle = null;
@@ -345,6 +295,27 @@
assertTrue(failedPortlets.getPortletHandles().contains(nonExistantHandle));
}
+ protected void checkInvalidHandle(ExportPortletsResponse response, String handle)
throws Exception
+ {
+ assertNotNull(response.getExportContext());
+ assertNull(response.getLifetime());
+ assertTrue(response.getExportedPortlet().isEmpty());
+ assertEquals(1, response.getFailedPortlets().size());
+ FailedPortlets failedPortlet = response.getFailedPortlets().get(0);
+ assertTrue(failedPortlet.getPortletHandles().contains(handle));
+
assertEquals("InvalidHandle",failedPortlet.getErrorCode().getLocalPart());
+ }
+
+ protected void checkValidHandle(ExportPortletsResponse response, String handle) throws
Exception
+ {
+ assertNotNull(response.getExportContext());
+ assertNull(response.getLifetime());
+ assertTrue(response.getFailedPortlets().isEmpty());
+ assertEquals(1, response.getExportedPortlet().size());
+ ExportedPortlet exportPortlet = response.getExportedPortlet().get(0);
+ assertEquals(handle, exportPortlet.getPortletHandle());
+ }
+
protected List<PortletContext> createPortletContextList(String...
portletHandles)
{
List<PortletContext> portletContexts = new
ArrayList<PortletContext>();
@@ -509,7 +480,7 @@
try
{
- ImportPortletsResponse response = producer.importPortlets(importPortlets);
+ producer.importPortlets(importPortlets);
ExtendedAssert.fail("Should have thrown an OperationFailedFault");
}
catch (OperationFailed e)
@@ -532,7 +503,7 @@
try
{
- ImportPortletsResponse response = producer.importPortlets(importPortlets);
+ producer.importPortlets(importPortlets);
ExtendedAssert.fail("Should have thrown an OperationFailedFault");
}
catch (OperationFailed e)
@@ -823,6 +794,158 @@
}
}
+ @Test
+ public void testReleaseExportsThrowsNoErrors() throws Exception
+ {
+ //NOTE: this test should never cause any errors
+ //TODO: once the export by reference is done, we need to write tests that this
works
+
+ //null releaseExport
+ producer.releaseExport(null);
+
+ //empty releaseExport
+ ReleaseExport releaseExport = new ReleaseExport();
+ producer.releaseExport(releaseExport);
+
+ //empty releaseExport with a bad export context
+ releaseExport = new ReleaseExport();
+ releaseExport.setExportContext(new byte[]{-12, 12, 25, 21, 53});
+ producer.releaseExport(releaseExport);
+
+ //bad registration handle
+ releaseExport = new ReleaseExport();
+ RegistrationContext registrationContext = new RegistrationContext();
+ registrationContext.setRegistrationHandle("badRegistrationHandle");
+ releaseExport.setRegistrationContext(registrationContext);
+ producer.releaseExport(releaseExport);
+
+ //bad user context
+ releaseExport = new ReleaseExport();
+ UserContext userContext = new UserContext();
+ userContext.setUserContextKey("baduckey");
+ releaseExport.setUserContext(userContext);
+ producer.releaseExport(releaseExport);
+ }
+
+ @Test
+ public void testReleaseExportsNoErrorsRequiresRegistraion() throws Exception
+ {
+
producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
+ this.testReleaseExportsThrowsNoErrors();
+ }
+
+ @Test
+ public void testExportPortletPM() throws Exception
+ {
+ exportPortletToPM();
+ }
+
+ @Test
+ public void testReleaseExportPM() throws Exception
+ {
+ ExportPortletsResponse response = exportPortletToPM();
+
+ ReleaseExport releaseExport = WSRPTypeFactory.createReleaseExport(null,
response.getExportContext(), null);
+ producer.releaseExport(releaseExport);
+
+ //Test that doing a release export actually removed the stored RefId
+ TestMockExportPersistenceManager persistenceManager =
(TestMockExportPersistenceManager)producer.getExportManager().getPersistenceManager();
+ ExtendedAssert.assertEquals(0,
persistenceManager.getExportContexts().keySet().size());
+ }
+
+ @Test
+ public void testImportPortletPM() throws Exception
+ {
+ ExportPortletsResponse response = exportPortletToPM();
+
+ String importID = "foo";
+ ImportPortlet importPortlet = WSRPTypeFactory.createImportPortlet(importID,
response.getExportedPortlet().get(0).getExportData());
+
+ List<ImportPortlet> importPortletsList =
createImportPortletList(importPortlet);
+
+ ImportPortlets importPortlets =
createSimpleImportPortlets(response.getExportContext(), importPortletsList);
+ ImportPortletsResponse importResponse = producer.importPortlets(importPortlets);
+
+ ExtendedAssert.assertEquals(1, importResponse.getImportedPortlets().size());
+ ExtendedAssert.assertEquals(importID,
importResponse.getImportedPortlets().get(0).getImportID());
+
ExtendedAssert.assertNotNull(importResponse.getImportedPortlets().get(0).getNewPortletContext().getPortletHandle());
+ }
+
+ protected ExportPortletsResponse exportPortletToPM() throws Exception
+ {
+ TestMockExportPersistenceManager persistenceManager = new
TestMockExportPersistenceManager();
+ producer.getExportManager().setPersistanceManager(persistenceManager);
+ ((ExportManagerImpl)producer.getExportManager()).setPreferExportByValue(false);
+
+ String handle = getDefaultHandle();
+ List<PortletContext> portletContexts = createPortletContextList(handle);
+
+ ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
+ exportPortlets.setExportByValueRequired(false);
+
+ //Test that we don't have anything in the PM before doing an export
+ ExtendedAssert.assertEquals(0,
persistenceManager.getExportContexts().keySet().size());
+
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+
+ //Test that we have an entry in the PM after doing an export
+ ExtendedAssert.assertEquals(1,
persistenceManager.getExportContexts().keySet().size());
+
+ return response;
+ }
+
+ @Test
+ public void testSetExportLifetimeNull() throws Exception
+ {
+ try
+ {
+ producer.setExportLifetime(null);
+ ExtendedAssert.fail();
+ }
+ catch (OperationNotSupported e)
+ {
+ //expected
+ }
+ }
+
+ @Test
+ public void testSetExportLifetimeInvalidExportContext() throws Exception
+ {
+ try
+ {
+ SetExportLifetime setExportLifetime =
WSRPTypeFactory.createSetExportLifetime(null, new byte[]{-10, 24, 24, 54, 'a',
'f', 'g'}, null, null);
+ producer.setExportLifetime(setExportLifetime);
+ ExtendedAssert.fail();
+ }
+ catch (OperationNotSupported e)
+ {
+ //expected
+ }
+ }
+
+ @Test
+ public void testSetExport() throws Exception
+ {
+ String handle = getDefaultHandle();
+ List<PortletContext> portletContexts = createPortletContextList(handle);
+
+ ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+
+ try
+ {
+ PersistedExportData exportData = new PersistedExportData("foo",
"bar");
+
+ SetExportLifetime setExportLifetime =
WSRPTypeFactory.createSetExportLifetime(null,exportData.encodeAsBytes(), null, null);
+ producer.setExportLifetime(setExportLifetime);
+ ExtendedAssert.fail();
+ }
+ catch (OperationNotSupported e)
+ {
+ //expected
+ }
+ }
+
protected List<PortletContext> getPortletContext(ExportPortletsResponse
exportPortletsResponse) throws Exception
{
List<PortletContext> portletContexts = new
ArrayList<PortletContext>();