[gatein-commits] gatein SVN: r4562 - in components/wsrp/trunk/common/src: main/java/org/gatein/wsrp/spec/v1 and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Oct 6 17:35:51 EDT 2010


Author: mwringe
Date: 2010-10-06 17:35:50 -0400 (Wed, 06 Oct 2010)
New Revision: 4562

Modified:
   components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java
   components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V2ToV1Converter.java
   components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/spec/v1/V2ToV1ConverterTestCase.java
Log:
GTNWSRP-92: Fix remaining issues with potential compatibilities between the V1 and V2 schemas. The V2ToV1Converter should now make sure to return required values in v1 which became optional in v2.

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-10-06 21:09:46 UTC (rev 4561)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPTypeFactory.java	2010-10-06 21:35:50 UTC (rev 4562)
@@ -664,8 +664,6 @@
     */
    public static SessionContext createSessionContext(String sessionID, int expires)
    {
-      //TODO: a sessionID is minOccurs 0, it shouldn't be required, expires also is minOccurs 0
-      ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(sessionID, "session Id", "SessionContext");
       if (expires < 0)
       {
          throw new IllegalArgumentException("SessionContext requires a positive expiration time.");

Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V2ToV1Converter.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V2ToV1Converter.java	2010-10-06 21:09:46 UTC (rev 4561)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/spec/v1/V2ToV1Converter.java	2010-10-06 21:35:50 UTC (rev 4562)
@@ -753,7 +753,7 @@
 
    public static V1SessionContext toV1SessionContext(SessionContext sessionContext)
    {
-      if (sessionContext != null)
+      if (sessionContext != null && !ParameterValidation.isNullOrEmpty(sessionContext.getSessionID()))
       {
          V1SessionContext v1SessionContext = WSRP1TypeFactory.createSessionContext(sessionContext.getSessionID(), sessionContext.getExpires());
          v1SessionContext.getExtensions().addAll(Lists.transform(sessionContext.getExtensions(), EXTENSION));
@@ -781,7 +781,19 @@
          {
             QName errorCode = failedPortlets.getErrorCode();
             V1LocalizedString reason = toV1LocalizedString(failedPortlets.getReason());
-            String v1Reason = errorCode.toString() + ": " + reason.getValue();
+            
+            String v1Reason;
+            //failedPortlets.getReason is optional in V2, but errorCode is required.
+            //for V2DestroyFailed the reason is required
+            if (reason != null && reason.getValue() != null)
+            {
+               v1Reason = errorCode.toString() + ": " + reason.getValue();
+            }
+            else
+            {
+               v1Reason = errorCode.toString();
+            }
+            
             for (String handle : failedPortlets.getPortletHandles())
             {
                V1DestroyFailed destroyFailed = WSRP1TypeFactory.createDestroyFailed(handle, v1Reason);
@@ -1180,7 +1192,18 @@
          {
             V1ItemDescription result = new V1ItemDescription();
             result.setItemName(from.getItemName());
-            result.setDescription(LOCALIZEDSTRING.apply(from.getDescription()));
+            if (from.getDescription() != null)
+            {
+               result.setDescription(LOCALIZEDSTRING.apply(from.getDescription()));
+            }
+            else if (from.getDisplayName() != null)
+            {
+               result.setDescription(LOCALIZEDSTRING.apply(from.getDisplayName()));
+            }
+            else
+            {
+               result.setDescription(WSRP1TypeFactory.createLocalizedString("No Description Available"));
+            }
             List<V1Extension> extensions = WSRPUtils.transform(from.getExtensions(), EXTENSION);
             if (extensions != null)
             {
@@ -1204,7 +1227,16 @@
          {
             V1NamedString result = new V1NamedString();
             result.setName(namedString.getName());
-            result.setValue(namedString.getValue());
+            //GetValue is required for V1, but optional for V2. If we receive a null
+            //value from V2, then just set the value to be equal to the name.
+            if (namedString.getValue() == null)
+            {
+               result.setValue(namedString.getName());
+            }
+            else
+            {
+               result.setValue(namedString.getValue());
+            }
             return result;
          }
          else

Modified: components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/spec/v1/V2ToV1ConverterTestCase.java
===================================================================
--- components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/spec/v1/V2ToV1ConverterTestCase.java	2010-10-06 21:09:46 UTC (rev 4561)
+++ components/wsrp/trunk/common/src/test/java/org/gatein/wsrp/spec/v1/V2ToV1ConverterTestCase.java	2010-10-06 21:35:50 UTC (rev 4562)
@@ -23,14 +23,29 @@
 
 package org.gatein.wsrp.spec.v1;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import junit.framework.TestCase;
 
 import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.spec.v2.ErrorCodes;
+import org.gatein.wsrp.spec.v2.ErrorCodes.Codes;
+import org.oasis.wsrp.v1.V1DestroyFailed;
 import org.oasis.wsrp.v1.V1InvalidSession;
+import org.oasis.wsrp.v1.V1ItemDescription;
+import org.oasis.wsrp.v1.V1NamedString;
 import org.oasis.wsrp.v1.V1OperationFailed;
+import org.oasis.wsrp.v1.V1SessionContext;
+import org.oasis.wsrp.v2.FailedPortlets;
+import org.oasis.wsrp.v2.ItemDescription;
+import org.oasis.wsrp.v2.LocalizedString;
+import org.oasis.wsrp.v2.NamedString;
 import org.oasis.wsrp.v2.OperationFailed;
-import org.oasis.wsrp.v2.OperationFailedFault;
+import org.oasis.wsrp.v2.SessionContext;
 
+import com.google.common.collect.Lists;
+
 /**
  * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
  * @version $Revision$
@@ -91,5 +106,126 @@
          // expected
       }
    }
+   
+   public void testNamedString()
+   {
+      NamedString namedString = WSRPTypeFactory.createNamedString("name1", "value1");
+      V1NamedString v1NamedString = convertNamedStringToV1NamedString(namedString);
+      assertEquals("name1", v1NamedString.getName());
+      assertEquals("value1", v1NamedString.getValue());
+      
+      //value is optional in v2, but not in v1, if a null value is passed the V1NamedString should use the name instead of the value
+      namedString = WSRPTypeFactory.createNamedString("name2", null);
+      v1NamedString = convertNamedStringToV1NamedString(namedString);
+      assertEquals("name2", v1NamedString.getName());
+      assertEquals("name2", v1NamedString.getValue());
+      
+      //TODO; should an empty value be valid?
+      namedString = WSRPTypeFactory.createNamedString("name3", "");
+      v1NamedString = convertNamedStringToV1NamedString(namedString);
+      assertEquals("name3", v1NamedString.getName());
+      assertEquals("", v1NamedString.getValue());
+   }
+   
+   private V1NamedString convertNamedStringToV1NamedString(NamedString namedString)
+   {
+      List<NamedString> namedStringList = new ArrayList<NamedString>();
+      namedStringList.add(namedString);
+      
+      List<V1NamedString> v1NamedStringList = Lists.transform(namedStringList, V2ToV1Converter.NAMEDSTRING);
+      
+      assertEquals(1, v1NamedStringList.size());
+      
+      return v1NamedStringList.iterator().next();
+   }
+   
+   public void testSessionContext()
+   {
+      SessionContext sessionContext = WSRPTypeFactory.createSessionContext("session1234", 0);
+      V1SessionContext v1SessionContext = V2ToV1Converter.toV1SessionContext(sessionContext);
+      assertEquals("session1234", v1SessionContext.getSessionID());
+      assertEquals(0, v1SessionContext.getExpires());
+      
+      sessionContext = WSRPTypeFactory.createSessionContext(null, 0);
+      v1SessionContext = V2ToV1Converter.toV1SessionContext(sessionContext);
+      assertNull(v1SessionContext);
+      
+      sessionContext = WSRPTypeFactory.createSessionContext("", 0);
+      v1SessionContext = V2ToV1Converter.toV1SessionContext(sessionContext);
+      assertNull(v1SessionContext);
+   }
+   
+   public void testItemDescription()
+   {
+      V1ItemDescription v1ItemDescription = convertItemDescriptionToV1ItemDescription("desc1", "dn1", "item1");
+      assertEquals("desc1", v1ItemDescription.getDescription().getValue());
+      assertEquals("item1", v1ItemDescription.getItemName());
+      
+      v1ItemDescription = convertItemDescriptionToV1ItemDescription(null, "dn1", "item1");
+      assertEquals("dn1", v1ItemDescription.getDescription().getValue());
+      assertEquals("item1", v1ItemDescription.getItemName());
 
+      v1ItemDescription = convertItemDescriptionToV1ItemDescription("", "dn1", "item1");
+      assertEquals("", v1ItemDescription.getDescription().getValue());
+      assertEquals("item1", v1ItemDescription.getItemName());
+      
+      v1ItemDescription = convertItemDescriptionToV1ItemDescription(null, null, "item1");
+      assertNotNull(v1ItemDescription.getDescription().getValue());
+      assertEquals("item1", v1ItemDescription.getItemName());
+   }
+   
+   private V1ItemDescription convertItemDescriptionToV1ItemDescription (String description, String displayName, String itemName)
+   {  
+      LocalizedString descriptionLS = null;
+      if (description != null)
+      {   
+         descriptionLS = WSRPTypeFactory.createLocalizedString(description);
+      }
+      
+      LocalizedString displayNameLS = null;
+      if (displayName != null)
+      {
+         displayNameLS = WSRPTypeFactory.createLocalizedString(displayName);
+      }
+      
+      ItemDescription itemDescription = WSRPTypeFactory.createItemDescription(descriptionLS, displayNameLS, itemName);
+      
+      List<ItemDescription> itemDescriptionList = new ArrayList<ItemDescription>();
+      itemDescriptionList.add(itemDescription);
+      
+      List<V1ItemDescription> v1ItemDesciptionList = Lists.transform(itemDescriptionList, V2ToV1Converter.ITEMDESCRIPTION);
+      
+      assertEquals(1, v1ItemDesciptionList.size());
+      
+      return v1ItemDesciptionList.iterator().next();
+   }
+   
+   public void testDestroyedFailed()
+   {
+      V1DestroyFailed destroyFailed = convertFailedPortletsToDestroyFailed("handle1", Codes.OPERATIONFAILED, "this failed for some reason");
+      assertEquals("handle1", destroyFailed.getPortletHandle());
+      assertTrue(destroyFailed.getReason().contains(ErrorCodes.getQname(Codes.OPERATIONFAILED).toString()));
+      assertTrue(destroyFailed.getReason().contains("this failed for some reason"));
+      
+      destroyFailed = convertFailedPortletsToDestroyFailed("handle1", Codes.OPERATIONFAILED, null);
+      assertEquals("handle1", destroyFailed.getPortletHandle());
+      assertEquals(ErrorCodes.getQname(Codes.OPERATIONFAILED).toString(), destroyFailed.getReason());
+   }
+   
+   private V1DestroyFailed convertFailedPortletsToDestroyFailed(String portletHandle, Codes errorCode, String reason)
+   {
+      List<String> portletHandles = new ArrayList<String>();
+      portletHandles.add(portletHandle);
+      
+      FailedPortlets failedPortlets = WSRPTypeFactory.createFailedPortlets(portletHandles, errorCode, reason);
+      List<FailedPortlets> failedPortletsList = new ArrayList<FailedPortlets>();
+      failedPortletsList.add(failedPortlets);
+      
+      List<V1DestroyFailed> destroyFailedList = V2ToV1Converter.toV1DestroyFailed(failedPortletsList);
+      
+      assertEquals(1, destroyFailedList.size());
+      
+      return destroyFailedList.iterator().next();
+   }
+
 }



More information about the gatein-commits mailing list