Author: mwringe
Date: 2010-08-06 17:36:43 -0400 (Fri, 06 Aug 2010)
New Revision: 3768
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.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/PortletManagementHandler.java
components/wsrp/trunk/wsrp-producer-war/pom.xml
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
Log:
GTNWSRP-55: Import/Export bug fixes and updated tests.
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
===================================================================
---
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-08-06
19:39:29 UTC (rev 3767)
+++
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java 2010-08-06
21:36:43 UTC (rev 3768)
@@ -1433,7 +1433,7 @@
return importPortlets;
}
- public static ImportPortlet createImportPorlet(String importID, byte[] exportData)
+ public static ImportPortlet createImportPortlet(String importID, byte[] exportData)
{
ParameterValidation.throwIllegalArgExceptionIfNull(importID,
"ImportID");
ParameterValidation.throwIllegalArgExceptionIfNull(exportData,
"ExportData");
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-06
19:39:29 UTC (rev 3767)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/ExportManager.java 2010-08-06
21:36:43 UTC (rev 3768)
@@ -44,11 +44,11 @@
ExportContext createExportContext(boolean exportByValueRequired, Lifetime lifetime)
throws UnsupportedEncodingException;
- ExportContext createExportContext(byte[] bytes);
+ ExportContext createExportContext(byte[] bytes) throws OperationFailed;
ExportPortletData createExportPortletData(ExportContext exportContextData, String
portletHandle, byte[] portletState) throws UnsupportedEncodingException;
- ExportPortletData createExportPortletData(ExportContext exportContext, Lifetime
lifetime, byte[] bytes);
+ ExportPortletData createExportPortletData(ExportContext exportContext, Lifetime
lifetime, byte[] bytes) throws OperationFailed;
byte[] encodeExportPortletData(ExportContext exportContextData, ExportPortletData
exportPortletData) throws UnsupportedEncodingException;
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.java 2010-08-06
19:39:29 UTC (rev 3767)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/data/ExportData.java 2010-08-06
21:36:43 UTC (rev 3768)
@@ -56,46 +56,70 @@
public static double getVersion(byte[] bytes) throws UnsupportedEncodingException
{
- String dataString = new String(bytes, ENCODING);
- String[] split = dataString.split(SEPARATOR, 3);
-
- if (split.length >= 2)
+ if (bytes != null && bytes.length > 0)
{
- double version = Double.parseDouble(split[1]);
- return version;
+ String dataString = new String(bytes, ENCODING);
+ String[] split = dataString.split(SEPARATOR, 3);
+
+ if (split.length >= 2)
+ {
+ double version = Double.parseDouble(split[1]);
+ return version;
+ }
+ else
+ {
+ //if a version could not be found, return -1
+ return -1;
+ }
}
-
- //if a version could not be found, return -1
- return -1;
+ else
+ {
+ return -1;
+ }
}
public static String getType(byte[] bytes) throws UnsupportedEncodingException
{
- String dataString = new String(bytes, ENCODING);
- String[] split = dataString.split(SEPARATOR, 2);
-
- if (split.length >= 2)
+ if (bytes != null && bytes.length > 0)
{
- return split[0];
+ String dataString = new String(bytes, ENCODING);
+ String[] split = dataString.split(SEPARATOR, 2);
+
+ if (split.length >= 2)
+ {
+ return split[0];
+ }
+ else
+ {
+ return null;
+ }
}
-
- //if we could not find a type, then return null
- return null;
+ else
+ {
+ return null;
+ }
}
public static byte[] getInternalBytes(byte[] bytes) throws
UnsupportedEncodingException
{
- String dataString = new String(bytes, ENCODING);
- String[] split = dataString.split(SEPARATOR, 3);
-
- if (split.length >= 3)
+ if (bytes != null && bytes.length > 0)
{
- String internalString = split[2];
- return internalString.getBytes(ENCODING);
+ String dataString = new String(bytes, ENCODING);
+ String[] split = dataString.split(SEPARATOR, 3);
+
+ if (split.length >= 3)
+ {
+ String internalString = split[2];
+ return internalString.getBytes(ENCODING);
+ }
+ else
+ {
+ //if we could not find the internal bytes, return null
+ return null;
+ }
}
else
{
- //if we could not find the internal bytes, return null
return null;
}
}
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-06
19:39:29 UTC (rev 3767)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/exports/impl/ExportManagerImpl.java 2010-08-06
21:36:43 UTC (rev 3768)
@@ -77,28 +77,26 @@
return supportExportByValue;
}
- public ExportContext createExportContext(byte[] bytes)
+ public ExportContext createExportContext(byte[] bytes) throws OperationFailed
{
try
{
- String type = ExportData.getType(bytes);
- double version = ExportData.getVersion(bytes);
- if (ExportContext.TYPE.equals(type) && ExportContext.VERSION==version)
- {
- byte[] internalBytes = ExportData.getInternalBytes(bytes);
- return ExportContext.create(internalBytes);
- }
- else
- {
- //TODO: throw an error here about not being a recognized type
- throw new IllegalArgumentException("byte[] format unreconized.");
- }
+ String type = ExportData.getType(bytes);
+ double version = ExportData.getVersion(bytes);
+ if (ExportContext.TYPE.equals(type) && ExportContext.VERSION==version)
+ {
+ byte[] internalBytes = ExportData.getInternalBytes(bytes);
+ return ExportContext.create(internalBytes);
}
- catch (Exception e)
+ else
{
- e.printStackTrace();
- throw new NotYetImplemented();
+ throw WSRPExceptionFactory.createWSException(OperationFailed.class, "Byte
array format not compatible.", null);
}
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw WSRPExceptionFactory.createWSException(OperationFailed.class, "Could
not decode the byte array.", e);
+ }
}
public ExportPortletData createExportPortletData(ExportContext exportContextData,
String portletHandle,
@@ -107,7 +105,7 @@
return new ExportPortletData(portletHandle, portletState);
}
- public ExportPortletData createExportPortletData(ExportContext exportContextData,
Lifetime lifetime, byte[] bytes)
+ public ExportPortletData createExportPortletData(ExportContext exportContextData,
Lifetime lifetime, byte[] bytes) throws OperationFailed
{
try
{
@@ -120,14 +118,12 @@
}
else
{
- //TODO: throw an error here about not being a recognized type
- throw new IllegalArgumentException("byte[] format unreconized.");
+ throw WSRPExceptionFactory.createWSException(OperationFailed.class,
"Bytes array format not compatible", null);
}
}
- catch (Exception e)
+ catch (UnsupportedEncodingException e)
{
- e.printStackTrace();
- throw new NotYetImplemented();
+ throw WSRPExceptionFactory.createWSException(OperationFailed.class, "Could
not decode the byte array.", e);
}
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java 2010-08-06
19:39:29 UTC (rev 3767)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/PortletManagementHandler.java 2010-08-06
21:36:43 UTC (rev 3768)
@@ -28,6 +28,8 @@
import org.gatein.common.NotYetImplemented;
import org.gatein.common.i18n.LocalizedString;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
import org.gatein.exports.data.ExportContext;
import org.gatein.exports.data.ExportPortletData;
import org.gatein.pc.api.InvalidPortletIdException;
@@ -59,7 +61,6 @@
import org.oasis.wsrp.v2.ExportPortlets;
import org.oasis.wsrp.v2.ExportPortletsResponse;
import org.oasis.wsrp.v2.ExportedPortlet;
-import org.oasis.wsrp.v2.ExportNoLongerValid;
import org.oasis.wsrp.v2.Extension;
import org.oasis.wsrp.v2.FailedPortlets;
import org.oasis.wsrp.v2.GetPortletDescription;
@@ -100,7 +101,6 @@
import org.oasis.wsrp.v2.SetPortletsLifetimeResponse;
import org.oasis.wsrp.v2.UserContext;
-import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -120,10 +120,13 @@
private static final String GET_PORTLET_PROPERTIES =
"GetPortletProperties";
private static final String PORTLET_CONTEXT = "PortletContext";
private static final String GET_PORTLET_DESCRIPTION =
"GetPortletDescription";
+
+ private final Logger log;
PortletManagementHandler(WSRPProducerImpl producer)
{
super(producer);
+ log = LoggerFactory.getLogger(PortletManagementHandler.class);
}
public PortletDescriptionResponse getPortletDescription(GetPortletDescription
getPortletDescription)
@@ -469,19 +472,30 @@
ExportByValueNotSupported, InconsistentParameters, InvalidHandle,
InvalidRegistration, InvalidUserCategory,
MissingParameters, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
{
- WSRP2ExceptionFactory.throwOperationFailedIfValueIsMissing(exportPortlets,
"ExportPortlets");
+ WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(exportPortlets,
"ExportPortlets", "ExportPortlets");
List<PortletContext> portletContexts = exportPortlets.getPortletContext();
- WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletContexts,
"PortletContext", "ExportPortlets");
-
+ if (portletContexts == null || portletContexts.isEmpty())
+ {
+ throw WSRP2ExceptionFactory.createWSException(MissingParameters.class,
"Missing required portletContext in ExportPortlets.", null);
+ }
Registration registration =
producer.getRegistrationOrFailIfInvalid(exportPortlets.getRegistrationContext());
UserContext userContext = exportPortlets.getUserContext();
checkUserAuthorization(userContext);
- boolean exportByValueRequired = exportPortlets.isExportByValueRequired();
+ boolean exportByValueRequired;
+ if (exportPortlets.isExportByValueRequired() != null)
+ {
+ exportByValueRequired = exportPortlets.isExportByValueRequired();
+ }
+ else
+ {
+ exportByValueRequired = false;
+ }
+
//check that the export manager can handle export by value
if (exportByValueRequired &&
!producer.getExportManager().supportExportByValue())
{
@@ -498,7 +512,7 @@
RegistrationLocal.setRegistration(registration);
//TODO: try catch here?
- ExportContext exportContext =
producer.getExportManager().createExportContext(exportPortlets.isExportByValueRequired(),
exportPortlets.getLifetime());
+ ExportContext exportContext =
producer.getExportManager().createExportContext(exportByValueRequired,
exportPortlets.getLifetime());
for (PortletContext portletContext : exportPortlets.getPortletContext())
{
@@ -530,76 +544,42 @@
exportedPortlets.add(exportedPortlet);
}
- //TODO: this is very messy, make this better
- catch (UnsupportedEncodingException e)
+ catch (Exception e)
{
- if(!failedPortletsMap.containsKey(e.getClass().toString()))
+ if (log.isWarnEnabled())
{
- List<String> portletHandles = new ArrayList<String>();
- portletHandles.add(portletContext.getPortletHandle());
-
- FailedPortlets failedPortlets =
WSRPTypeFactory.createFailedPortlets(portletHandles, ErrorCodes.Codes.OPERATIONFAILED,
"Error encoding the portlet for export.");
- failedPortletsMap.put(e.getClass().toString(), failedPortlets);
+ log.warn("Error occured while trying to export a portlet.",
e);
}
- else
+
+ ErrorCodes.Codes errorCode;
+ String reason;
+ if (e instanceof NoSuchPortletException || e instanceof InvalidHandle)
{
- FailedPortlets failedPortlets =
failedPortletsMap.get(e.getClass().toString());
-
failedPortlets.getPortletHandles().add(portletContext.getPortletHandle());
+ errorCode = ErrorCodes.Codes.INVALIDHANDLE;
+ reason = "The specified portlet handle is invalid";
}
- }
- catch (NoSuchPortletException e)
- {
- if(!failedPortletsMap.containsKey(e.getClass().toString()))
+ else // default error message.
{
- List<String> portletHandles = new ArrayList<String>();
- portletHandles.add(portletContext.getPortletHandle());
-
- FailedPortlets failedPortlets =
WSRPTypeFactory.createFailedPortlets(portletHandles, ErrorCodes.Codes.INVALIDHANDLE,
"The specified porlet handle is invalid.");
- failedPortletsMap.put(e.getClass().toString(), failedPortlets);
+ errorCode = ErrorCodes.Codes.OPERATIONFAILED;
+ reason = "Error preparing portlet for export";
}
- else
+
+ if(!failedPortletsMap.containsKey(errorCode.name()))
{
- FailedPortlets failedPortlets =
failedPortletsMap.get(e.getClass().toString());
-
failedPortlets.getPortletHandles().add(portletContext.getPortletHandle());
- }
- }
- catch (InvalidHandle e)
- {
- if(!failedPortletsMap.containsKey(e.getClass().toString()))
- {
List<String> portletHandles = new ArrayList<String>();
portletHandles.add(portletContext.getPortletHandle());
- FailedPortlets failedPortlets =
WSRPTypeFactory.createFailedPortlets(portletHandles, ErrorCodes.Codes.INVALIDHANDLE,
"The specified portlet handle is invalid.");
- failedPortletsMap.put(e.getClass().toString(), failedPortlets);
+ FailedPortlets failedPortlets =
WSRPTypeFactory.createFailedPortlets(portletHandles, errorCode, reason);
+ failedPortletsMap.put(errorCode.name(), failedPortlets);
}
else
{
- FailedPortlets failedPortlets =
failedPortletsMap.get(e.getClass().toString());
+ FailedPortlets failedPortlets =
failedPortletsMap.get(errorCode.name());
failedPortlets.getPortletHandles().add(portletContext.getPortletHandle());
}
}
- catch (Exception e)
- {
- if(!failedPortletsMap.containsKey(e.getClass().toString()))
- {
- List<String> portletHandles = new ArrayList<String>();
- portletHandles.add(portletContext.getPortletHandle());
-
- FailedPortlets failedPortlets =
WSRPTypeFactory.createFailedPortlets(portletHandles, ErrorCodes.Codes.OPERATIONFAILED,
"An exception occured when trying to export this portlet for export.");
- e.printStackTrace();
- failedPortletsMap.put(e.getClass().toString(), failedPortlets);
- }
- else
- {
- FailedPortlets failedPortlets =
failedPortletsMap.get(e.getClass().toString());
-
failedPortlets.getPortletHandles().add(portletContext.getPortletHandle());
- }
- }
}
-
-
//TODO: handle resourceLists better (should be using for things like errors)
ResourceList resourceList = null;
@@ -640,7 +620,15 @@
List<ImportedPortlet> importedPortlets = new
ArrayList<ImportedPortlet>();
Map<String, ImportPortletsFailed> failedPortletsMap = new
HashMap<String, ImportPortletsFailed>();
- ExportContext exportContext =
producer.getExportManager().createExportContext(importContext);
+ ExportContext exportContext;
+ try
+ {
+ exportContext =
producer.getExportManager().createExportContext(importContext);
+ }
+ catch (Exception e)
+ {
+ throw WSRPExceptionFactory.createWSException(OperationFailed.class,
"Invalid ImportContext.", e);
+ }
for (ImportPortlet importPortlet : importPortletList)
{
@@ -665,19 +653,45 @@
}
catch (Exception e)
{
- e.printStackTrace();
- if(!failedPortletsMap.containsKey(e.getClass().toString()))
+ if (log.isWarnEnabled())
{
- List<String> importIds = new ArrayList<String>();
- importIds.add(importPortlet.getImportID());
+ log.warn("Error occured while trying to import a portlet.",
e);
+ }
+
+ ErrorCodes.Codes errorCode;
+ String reason;
+ if (e instanceof NoSuchPortletException || e instanceof InvalidHandle)
+ {
+ errorCode = ErrorCodes.Codes.INVALIDHANDLE;
+ reason = "The specified portlet handle is invalid";
+ }
+ else if (e instanceof OperationFailed)
+ {
+ errorCode = ErrorCodes.Codes.OPERATIONFAILED;
+ reason = e.getMessage();
+ }
+ else if (e instanceof PortletInvokerException || e instanceof
UnsupportedOperationException || e instanceof IllegalArgumentException)
+ {
+ errorCode = ErrorCodes.Codes.OPERATIONFAILED;
+ reason = "Error trying to create imported portlet.";
+ }
+ else // default error message.
+ {
+ errorCode = ErrorCodes.Codes.OPERATIONFAILED;
+ reason = "Error preparing portlet for export";
+ }
+
+ if(!failedPortletsMap.containsKey(errorCode.name()))
+ {
+ List<String> portleIDs = new ArrayList<String>();
+ portleIDs.add(importPortlet.getImportID());
- ImportPortletsFailed failedPortlets =
WSRPTypeFactory.createImportPortletsFailed(importIds, ErrorCodes.Codes.OPERATIONFAILED,
"The import portlet operation failed");
-
- failedPortletsMap.put(e.getClass().toString(), failedPortlets);
+ ImportPortletsFailed failedPortlets =
WSRPTypeFactory.createImportPortletsFailed(portleIDs, errorCode, reason);
+ failedPortletsMap.put(errorCode.name(), failedPortlets);
}
else
{
- ImportPortletsFailed failedPortlets =
failedPortletsMap.get(e.getClass().toString());
+ ImportPortletsFailed failedPortlets =
failedPortletsMap.get(errorCode.name());
failedPortlets.getImportID().add(importPortlet.getImportID());
}
}
@@ -687,12 +701,6 @@
return WSRPTypeFactory.createImportPortletsResponse(importedPortlets, new
ArrayList<ImportPortletsFailed>(failedPortletsMap.values()), resourceList);
}
- catch (Exception e)
- {
- //TODO: put proper error messages here
- e.printStackTrace();
- throw new NotYetImplemented();
- }
finally
{
RegistrationLocal.setRegistration(null);
@@ -711,8 +719,10 @@
}
catch (Exception e)
{
- //TODO: this method doesn't return anything, should we do more than just
output the stacktrace?
- e.printStackTrace();
+ if (log.isWarnEnabled())
+ {
+ log.warn("Error occured while trying to perform a ReleaseExport",
e);
+ }
}
//this method shouldn't return anything
Modified: components/wsrp/trunk/wsrp-producer-war/pom.xml
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/pom.xml 2010-08-06 19:39:29 UTC (rev 3767)
+++ components/wsrp/trunk/wsrp-producer-war/pom.xml 2010-08-06 21:36:43 UTC (rev 3768)
@@ -417,11 +417,12 @@
<configuration>
<skip>${maven.test.skip}</skip>
<includes>
-
<include>org/gatein/wsrp/protocol/v1/MarkupTestCase.class</include>
+
<include>org/gatein/wsrp/protocol/v1/MarkupTestCase.class</include>
<include>org/gatein/wsrp/protocol/v1/PortletManagementTestCase.class</include>
<include>org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.class</include>
<include>org/gatein/wsrp/protocol/v1/ServiceDescriptionTestCase.class</include>
<include>org/gatein/wsrp/protocol/v1/RegistrationTestCase.class</include>
+
<include>org/gatein/wsrp/protocol/v2/MarkupTestCase.class</include>
<!--
<include>org/gatein/wsrp/protocol/v2/ResourceTestCase.class</include> -->
<include>org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.class</include>
<include>org/gatein/wsrp/protocol/v2/PortletManagementTestCase.class</include>
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-06
19:39:29 UTC (rev 3767)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-06
21:36:43 UTC (rev 3768)
@@ -22,11 +22,14 @@
******************************************************************************/
package org.gatein.wsrp.protocol.v2;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
+import org.gatein.exports.ExportManager;
import org.gatein.exports.data.ExportContext;
import org.gatein.exports.data.ExportPortletData;
+import org.gatein.exports.impl.ExportManagerImpl;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.producer.WSRPProducerBaseTest;
import org.gatein.wsrp.servlet.ServletAccess;
@@ -45,12 +48,19 @@
import org.oasis.wsrp.v2.ExportPortletsResponse;
import org.oasis.wsrp.v2.ExportedPortlet;
import org.oasis.wsrp.v2.FailedPortlets;
+import org.oasis.wsrp.v2.GetMarkup;
import org.oasis.wsrp.v2.ImportPortlet;
import org.oasis.wsrp.v2.ImportPortlets;
import org.oasis.wsrp.v2.ImportPortletsResponse;
+import org.oasis.wsrp.v2.ImportedPortlet;
+import org.oasis.wsrp.v2.InvalidRegistration;
import org.oasis.wsrp.v2.Lifetime;
+import org.oasis.wsrp.v2.MarkupResponse;
+import org.oasis.wsrp.v2.MissingParameters;
+import org.oasis.wsrp.v2.OperationFailed;
import org.oasis.wsrp.v2.PortletContext;
import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.RegistrationData;
import org.oasis.wsrp.v2.UserContext;
/**
@@ -60,7 +70,7 @@
@RunWith(Arquillian.class)
public class PortletManagementTestCase extends NeedPortletHandleTest
{
- private static final String TEST_BASIC_PORTLET_WAR =
"test-basic-portlet.war";
+ private static final String TEST_BASIC_PORTLET_WAR =
"test-markup-portlet.war";
public PortletManagementTestCase() throws Exception
@@ -99,37 +109,18 @@
}
}
- /*TO TEST
- * - export
- * - import
- * - releaseExport
- * - test a valid setup that the producer is no longer holding any data
- * - test an invalid setup that we get back the proper errors
- * - test with invalid portlet handles
- * - setExportLifeTime
- * - test a valid setup that the export lifetime has been updated
- * - test an invalid setup that we get an error back
- * - use an invalid export context
- * - use an export context that is set to export by value
- * - invalid registration, usercontext, etc..
+ /*TODO:
+ * - tests usercontexts (not sure exactly what needs to be tested for this)
+ * - test portlet states
*/
@Test
public void testExport() throws Exception
- {
- boolean exportByValue = true;
- Lifetime lifetime = null;
- UserContext userContext = null;
- RegistrationContext registrationContext = null;
-
+ {
String handle = getDefaultHandle();
- PortletContext defaultContext = WSRPTypeFactory.createPortletContext(handle);
+ List<PortletContext> portletContexts = createPortletContextList(handle);
- List<PortletContext> portletContexts = new
ArrayList<PortletContext>();
- portletContexts.add(defaultContext);
-
- ExportPortlets exportPortlets =
WSRPTypeFactory.createExportPortlets(registrationContext, portletContexts, userContext,
lifetime, exportByValue);
-
+ ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
assertNotNull(response.getExportContext());
@@ -164,14 +155,13 @@
assertTrue(failedPortlet.getPortletHandles().contains(nonExistantHandle));
assertEquals("InvalidHandle",failedPortlet.getErrorCode().getLocalPart());
- assertTrue(failedPortlet.getPortletHandles().contains(nonExistantHandle));
}
@Test
public void testExportNullHandle() throws Exception
{
- String nonExistantHandle = null;
- List<PortletContext> portletContexts =
createPortletContextList(nonExistantHandle);
+ String nullHandle = null;
+ List<PortletContext> portletContexts = createPortletContextList(nullHandle);
ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
@@ -184,11 +174,122 @@
assertEquals(1, response.getFailedPortlets().size());
FailedPortlets failedPortlet = response.getFailedPortlets().get(0);
- assertTrue(failedPortlet.getPortletHandles().contains(nonExistantHandle));
+ assertTrue(failedPortlet.getPortletHandles().contains(nullHandle));
assertEquals("InvalidHandle",failedPortlet.getErrorCode().getLocalPart());
- assertTrue(failedPortlet.getPortletHandles().contains(nonExistantHandle));
}
+ @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);
+
+ String handle = getDefaultHandle();
+ List<PortletContext> portletContexts = createPortletContextList(handle);
+
+ ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
+
+ try
+ {
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+ ExtendedAssert.fail("ImportPortlets should fail if registration is required
and non is provided");
+ }
+ catch (InvalidRegistration e)
+ {
+ //expected
+ }
+ }
+
+ @Test
+ public void testExportRegistrationRequired() throws Exception
+ {
+
producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
+
+ 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());
+ }
+
+ @Test
+ public void testExports() throws Exception
+ {
+ String nullHandle = null;
+ String nonExistantHandle = "123FakeHandle";
+ String handle = getDefaultHandle();
+ List<PortletContext> portletContexts = createPortletContextList(nullHandle,
nonExistantHandle, handle);
+
+ ExportPortlets exportPortlets = createSimpleExportPortlets(portletContexts);
+
+ ExportPortletsResponse response = producer.exportPortlets(exportPortlets);
+
+ assertNotNull(response.getExportContext());
+ assertNull(response.getLifetime());
+ assertFalse(response.getExportedPortlet().isEmpty());
+ assertFalse(response.getFailedPortlets().isEmpty());
+
+ assertEquals(1, response.getExportedPortlet().size());
+
+ //Should provide the same error code and so should only produce on set of
FailedPortlets
+ assertEquals(1, response.getFailedPortlets().size());
+
+ ExportedPortlet exportPortlet = response.getExportedPortlet().get(0);
+ assertEquals(handle, exportPortlet.getPortletHandle());
+
+ FailedPortlets failedPortlets = response.getFailedPortlets().get(0);
+
assertEquals("InvalidHandle",failedPortlets.getErrorCode().getLocalPart());
+ assertEquals(2, failedPortlets.getPortletHandles().size());
+ assertTrue(failedPortlets.getPortletHandles().contains(nullHandle));
+ assertTrue(failedPortlets.getPortletHandles().contains(nonExistantHandle));
+ }
+
protected List<PortletContext> createPortletContextList(String...
portletHandles)
{
List<PortletContext> portletContexts = new
ArrayList<PortletContext>();
@@ -212,15 +313,243 @@
return WSRPTypeFactory.createExportPortlets(registrationContext, portletContexts,
userContext, lifetime, exportByValueRequired);
}
-
@Test
public void testImport() throws Exception
{
String importID = "foo";
+
+ List<String> portletList = new ArrayList<String>();
+ portletList.add(getDefaultHandle());
+ byte[] importContext = new ExportContext().encodeAsBytes();
- ExportPortletData exportPortletData = new ExportPortletData(getDefaultHandle(),
null);
+ ImportPortlet importPortlet = createSimpleImportPortlet(importID,
getDefaultHandle());
+
+ List<ImportPortlet> importPortletsList =
createImportPortletList(importPortlet);
+
+ ImportPortlets importPortlets = createSimpleImportPortlets(importContext,
importPortletsList);
+ ImportPortletsResponse response = producer.importPortlets(importPortlets);
+
+ assertEquals(1,response.getImportedPortlets().size());
+ ImportedPortlet portlet = response.getImportedPortlets().get(0);
+
+ assertEquals(importID, portlet.getImportID());
+
+ PortletContext portletContext = portlet.getNewPortletContext();
+ //check that we are getting a new portlet handle back and not the original one
+ ExtendedAssert.assertNotSame(getDefaultHandle(),
portletContext.getPortletHandle());
+
+ //check that the new portlet handle is valid and we can access the portlet
+ GetMarkup markup = createMarkupRequest(portletContext.getPortletHandle());
+ MarkupResponse markupResponse = producer.getMarkup(markup);
+ assertNotNull(markupResponse.getMarkupContext());
+ assertEquals("<p>symbol unset stock value: value unset</p>",
new String(markupResponse.getMarkupContext().getItemString()));
+ }
+
+ @Test
+ public void testImportNoRegistrationWhenRequired() throws Exception
+ {
+
producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
+
+ String importID = "foo";
+
+ List<String> portletList = new ArrayList<String>();
+ portletList.add(getDefaultHandle());
+ byte[] importContext = new ExportContext().encodeAsBytes();
+
+ ImportPortlet importPortlet = createSimpleImportPortlet(importID,
getDefaultHandle());
+ List<ImportPortlet> importPortletsList =
createImportPortletList(importPortlet);
+ ImportPortlets importPortlets = createSimpleImportPortlets(importContext,
importPortletsList);
+
+ try
+ {
+ ImportPortletsResponse response = producer.importPortlets(importPortlets);
+ ExtendedAssert.fail("ImportPortlets should fail if registration is required
and non is provided");
+ }
+ catch (InvalidRegistration e)
+ {
+ //expected
+ }
+ }
+
+ @Test
+ public void testImportRegistrationRequired() throws Exception
+ {
+
producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
+ RegistrationData registrationData =
WSRPTypeFactory.createRegistrationData("CONSUMER", true);
+ RegistrationContext registrationContext = producer.register(registrationData);
+
+ String importID = "foo";
+
+ Lifetime lifetime = null;
+ UserContext userContext = null;
+
+ List<String> portletList = new ArrayList<String>();
+ portletList.add(getDefaultHandle());
+ ExportContext exportContextData = new ExportContext();
+ byte[] importContext = exportContextData.encodeAsBytes();
+
+ ImportPortlet importPortlet = createSimpleImportPortlet(importID,
getDefaultHandle());
+ List<ImportPortlet> importPortletsList =
createImportPortletList(importPortlet);
+
+ ImportPortlets importPortlets =
WSRPTypeFactory.createImportPortlets(registrationContext, importContext,
importPortletsList, userContext, lifetime);
+ ImportPortletsResponse response = producer.importPortlets(importPortlets);
+
+ assertEquals(1,response.getImportedPortlets().size());
+ ImportedPortlet portlet = response.getImportedPortlets().get(0);
+
+ assertEquals(importID, portlet.getImportID());
+
+ PortletContext portletContext = portlet.getNewPortletContext();
+ //check that we are getting a new portlet handle back and not the original one
+ ExtendedAssert.assertNotSame(getDefaultHandle(),
portletContext.getPortletHandle());
+
+ //check that the new portlet handle is valid and we can access the portlet
+ GetMarkup markup = createMarkupRequest(portletContext.getPortletHandle());
+ markup.setRegistrationContext(registrationContext);
+
+ MarkupResponse markupResponse = producer.getMarkup(markup);
+ assertNotNull(markupResponse.getMarkupContext());
+ assertEquals("<p>symbol unset stock value: value unset</p>",
new String(markupResponse.getMarkupContext().getItemString()));
+ }
+
+ @Test
+ public void testImportNullImportContext() throws Exception
+ {
+ String importId = "importInvalidPortletContext";
+
+ ImportPortlet importPortlet = createSimpleImportPortlet(importId,
getDefaultHandle());
+
+ byte[] importContext = null;
+ List<ImportPortlet> importPortletsList =
createImportPortletList(importPortlet);
+
+ ImportPortlets importPortlets = createSimpleImportPortlets(importContext,
importPortletsList);
+
+ try
+ {
+ ImportPortletsResponse response = producer.importPortlets(importPortlets);
+ ExtendedAssert.fail("Should have thrown an OperationFailedFault");
+ }
+ catch (OperationFailed e)
+ {
+ //expected
+ }
+ }
+
+ @Test
+ public void testImportInvalidImportContext() throws Exception
+ {
+ String importId = "importInvalidPortletContext";
+
+ ImportPortlet importPortlet = createSimpleImportPortlet(importId,
getDefaultHandle());
+
+ byte[] importContext = new
byte[]{1,2,3,'f','a','k','e'};
+ List<ImportPortlet> importPortletsList =
createImportPortletList(importPortlet);
+
+ ImportPortlets importPortlets = createSimpleImportPortlets(importContext,
importPortletsList);
+
+ try
+ {
+ ImportPortletsResponse response = producer.importPortlets(importPortlets);
+ ExtendedAssert.fail("Should have thrown an OperationFailedFault");
+ }
+ catch (OperationFailed e)
+ {
+ //expected
+ }
+ }
+
+ @Test
+ public void testImportNullExportData() throws Exception
+ {
+ String importId = "nullExportData";
+
+ ImportPortlet importPortlet = new ImportPortlet();
+ importPortlet.setExportData(null);
+ importPortlet.setImportID(importId);
+
+ List<ImportPortlet> importPortletsList =
createImportPortletList(importPortlet);
+
+ byte[] importContext = new ExportContext().encodeAsBytes();
+
+ ImportPortlets importPortlets = createSimpleImportPortlets(importContext,
importPortletsList);
+
+ ImportPortletsResponse response = producer.importPortlets(importPortlets);
+
+ assertNotNull(response.getImportFailed());
+ assertEquals(1, response.getImportFailed().size());
+
+ assertEquals(importId, response.getImportFailed().get(0).getImportID().get(0));
+ assertEquals("OperationFailed",
response.getImportFailed().get(0).getErrorCode().getLocalPart());
+ }
+
+ @Test
+ public void testImportInvalidExportData() throws Exception
+ {
+ String importId = "invalidExportData";
+
+ ImportPortlet importPortlet = new ImportPortlet();
+ importPortlet.setExportData("fake_export_data_123".getBytes());
+ importPortlet.setImportID(importId);
+
+ List<ImportPortlet> importPortletsList =
createImportPortletList(importPortlet);
+
+ ExportContext exportContextData = new ExportContext();
+ byte[] importContext = exportContextData.encodeAsBytes();
+
+ ImportPortlets importPortlets = createSimpleImportPortlets(importContext,
importPortletsList);
+
+ ImportPortletsResponse response = producer.importPortlets(importPortlets);
+
+ assertNotNull(response.getImportFailed());
+ assertEquals(1, response.getImportFailed().size());
+
+ assertEquals(importId, response.getImportFailed().get(0).getImportID().get(0));
+ assertEquals("OperationFailed",
response.getImportFailed().get(0).getErrorCode().getLocalPart());
+ }
+
+ @Test
+ public void testImportNonExistantPortletData() throws Exception
+ {
+ String importId = "invalidExportData";
+
+ ExportManager exportManager = new ExportManagerImpl();
+ ExportPortletData exportPortletData = exportManager.createExportPortletData(null,
"non_existant_portlet_handle", null);
byte[] exportData = exportPortletData.encodeAsBytes();
+ ImportPortlet importPortlet = WSRPTypeFactory.createImportPortlet(importId,
exportData);
+
+ List<ImportPortlet> importPortletsList =
createImportPortletList(importPortlet);
+
+ ExportContext exportContextData = new ExportContext();
+ byte[] importContext = exportContextData.encodeAsBytes();
+
+ ImportPortlets importPortlets = createSimpleImportPortlets(importContext,
importPortletsList);
+
+ ImportPortletsResponse response = producer.importPortlets(importPortlets);
+
+ assertNotNull(response.getImportFailed());
+ assertEquals(1, response.getImportFailed().size());
+
+ assertEquals(importId, response.getImportFailed().get(0).getImportID().get(0));
+ assertEquals("InvalidHandle",
response.getImportFailed().get(0).getErrorCode().getLocalPart());
+ }
+
+ @Test
+ public void testImports() throws Exception
+ {
+ String importID = "foo";
+ String nullImportID = "null";
+ String invalidImportID = "invalid";
+
+ ExportManager exportManager = new ExportManagerImpl();
+ ExportPortletData exportPortletData = exportManager.createExportPortletData(null,
getDefaultHandle(), null);
+ byte[] exportData = exportPortletData.encodeAsBytes();
+
+ byte[] nullExportData = null;
+
+ ExportPortletData invalidExportPortletData =
exportManager.createExportPortletData(null, "InvalidHandle", null);
+ byte[] invalidExportData = invalidExportPortletData.encodeAsBytes();
+
Lifetime lifetime = null;
UserContext userContext = null;
RegistrationContext registrationContext = null;
@@ -230,17 +559,64 @@
ExportContext exportContextData = new ExportContext();
byte[] importContext = exportContextData.encodeAsBytes();
- ImportPortlet importPortlet = WSRPTypeFactory.createImportPorlet(importID,
exportData);
+ ImportPortlet nullPortlet = new ImportPortlet();
+ nullPortlet.setImportID(nullImportID);
+ nullPortlet.setExportData(nullExportData);
+ ImportPortlet importPortlet = WSRPTypeFactory.createImportPortlet(importID,
exportData);
+ ImportPortlet invalidPortlet = WSRPTypeFactory.createImportPortlet(invalidImportID,
invalidExportData);
List<ImportPortlet> importPortletsList = new
ArrayList<ImportPortlet>();
+ importPortletsList.add(invalidPortlet);
importPortletsList.add(importPortlet);
+ importPortletsList.add(nullPortlet);
ImportPortlets importPortlets =
WSRPTypeFactory.createImportPortlets(registrationContext, importContext,
importPortletsList, userContext, lifetime);
ImportPortletsResponse response = producer.importPortlets(importPortlets);
+
+ assertEquals(2, response.getImportFailed().size());
+
+ assertEquals(1,response.getImportedPortlets().size());
+
+ ImportedPortlet portlet = response.getImportedPortlets().get(0);
+ assertEquals(importID, portlet.getImportID());
+
+ PortletContext portletContext = portlet.getNewPortletContext();
+ //check that we are getting a new portlet handle back and not the original one
+ ExtendedAssert.assertNotSame(getDefaultHandle(),
portletContext.getPortletHandle());
+
+ //check that the new portlet handle is valid and we can access the portlet
+ GetMarkup markup = createMarkupRequest(portletContext.getPortletHandle());
+ MarkupResponse markupResponse = producer.getMarkup(markup);
+ assertNotNull(markupResponse.getMarkupContext());
+ assertEquals("<p>symbol unset stock value: value unset</p>",
new String(markupResponse.getMarkupContext().getItemString()));
}
+ protected ImportPortlet createSimpleImportPortlet(String importId, String handle)
throws UnsupportedEncodingException
+ {
+ ExportPortletData exportPortletData = new ExportPortletData(handle, null);
+ byte[] exportData = exportPortletData.encodeAsBytes();
+ return WSRPTypeFactory.createImportPortlet(importId, exportData);
+ }
+ protected List<ImportPortlet> createImportPortletList(ImportPortlet...
importPortlets)
+ {
+ List<ImportPortlet> importPortletList = new
ArrayList<ImportPortlet>();
+
+ for (ImportPortlet importPortlet : importPortlets)
+ {
+ importPortletList.add(importPortlet);
+ }
+ return importPortletList;
+ }
+ protected ImportPortlets createSimpleImportPortlets(byte[] importContext,
List<ImportPortlet> importPortletsList)
+ {
+ Lifetime lifetime = null;
+ UserContext userContext = null;
+ RegistrationContext registrationContext = null;
+
+ return WSRPTypeFactory.createImportPortlets(registrationContext, importContext,
importPortletsList, userContext, lifetime);
+ }
@Override
protected String getMostUsedPortletWARFileName()