Esempio n. 1
0
  @Test
  public void testPerformBlockingInteractionRedirect() throws Exception {
    V1PerformBlockingInteraction performBlockingInteraction =
        createDefaultPerformBlockingInteraction(getDefaultHandle());
    V1InteractionParams interactionParams = performBlockingInteraction.getInteractionParams();

    // crappy way but this is a test! ;)
    V1NamedString namedString = new V1NamedString();
    namedString.setName("symbol");
    namedString.setValue("HELP");
    interactionParams.getFormParameters().add(namedString);

    V1BlockingInteractionResponse response =
        producer.performBlockingInteraction(performBlockingInteraction);
    ExtendedAssert.assertNotNull(response);

    // this is a redirect...
    String redirectURL = response.getRedirectURL();
    ExtendedAssert.assertNotNull(redirectURL);
    ExtendedAssert.assertEquals(
        "/WEB-INF/jsp/help.jsp", redirectURL); // fix-me: handle URL re-writing

    // no update response
    V1UpdateResponse updateResponse = response.getUpdateResponse();
    ExtendedAssert.assertNull(updateResponse);
  }
Esempio n. 2
0
  @Test
  public void testInitCookieNoRegistrationWhenRegistrationRequired() throws Exception {
    configureRegistrationSettings(true, false);

    V1InitCookie initCookie = WSRP1TypeFactory.createInitCookie(null);
    try {
      producer.initCookie(initCookie);
      ExtendedAssert.fail("Should have thrown InvalidRegistration!");
    } catch (V1InvalidRegistration invalidRegistration) {
      // expected
    } catch (Exception e) {
      ExtendedAssert.fail(e.getMessage());
    }
  }
Esempio n. 3
0
  private String checkPBIAndGetNavigationalState(String symbol) throws Exception {
    V1PerformBlockingInteraction performBlockingInteraction =
        createDefaultPerformBlockingInteraction(getDefaultHandle());
    V1InteractionParams interactionParams = performBlockingInteraction.getInteractionParams();
    interactionParams.getFormParameters().add(createNamedString("symbol", symbol));

    V1BlockingInteractionResponse response =
        producer.performBlockingInteraction(performBlockingInteraction);
    ExtendedAssert.assertNotNull(response);

    // this is not a redirect...
    ExtendedAssert.assertNull(response.getRedirectURL());

    // check update response
    V1UpdateResponse updateResponse = response.getUpdateResponse();
    ExtendedAssert.assertNotNull(updateResponse);
    // request was readOnly so no updated portlet context
    ExtendedAssert.assertNull(updateResponse.getPortletContext());
    // check that no sessionId is getting passed.
    ExtendedAssert.assertNull(updateResponse.getSessionContext());

    String navigationalState = updateResponse.getNavigationalState();
    ExtendedAssert.assertNotNull(navigationalState);
    ExtendedAssert.assertEquals(updateResponse.getNewMode(), WSRPConstants.VIEW_MODE);
    V1MarkupContext markupContext = updateResponse.getMarkupContext();
    ExtendedAssert.assertNull(markupContext); // we don't return markup for now

    return navigationalState;
  }
Esempio n. 4
0
  @Test
  public void testGetMarkupNoRegistrationWhenRegistrationRequired() throws Exception {
    configureRegistrationSettings(true, false);

    V1GetMarkup gm = createMarkupRequest();
    try {
      producer.getMarkup(gm);
      ExtendedAssert.fail("Should have thrown InvalidRegistration!");
    } catch (V1InvalidRegistration invalidRegistration) {
      // expected
    } catch (Exception e) {
      ExtendedAssert.fail(e.getMessage());
    }
  }
Esempio n. 5
0
  @Test
  public void testGetMarkupWithNonURLEncodedResource() throws Exception {
    undeploy(DEFAULT_MARKUP_PORTLET_WAR);
    String archive = "test-resourcenoencodeurl-portlet.war";
    deploy(archive);

    try {
      V1GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
      V1MarkupResponse res = producer.getMarkup(gm);
      String markupString = res.getMarkupContext().getMarkupString();

      // accept either localhost or 127.0.0.1 for the host part of the generated markup
      // note that we are using a MockHttpServletRequest, so the host and port come from there.
      String markupStart = "<img src='http://";
      String markupEnd = ":8080/test-resourcenoencodeurl-portlet/gif/logo.gif'/>";
      String localhostMarkup = markupStart + "localhost" + markupEnd;
      String homeIPMarkup = markupStart + "127.0.0.1" + markupEnd;
      boolean result = localhostMarkup.equals(markupString) || homeIPMarkup.equals(markupString);
      ExtendedAssert.assertTrue(
          "Expectd '"
              + localhostMarkup
              + "' or '"
              + homeIPMarkup
              + "' but received '"
              + markupString
              + "'.",
          result);
    } finally {
      undeploy(archive);
    }
  }
Esempio n. 6
0
  @Test
  public void testGetMarkupWithResource() throws Exception {
    undeploy(DEFAULT_MARKUP_PORTLET_WAR);
    String archive = "test-resource-portlet.war";
    deploy(archive);

    try {
      V1GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
      V1MarkupResponse res = producer.getMarkup(gm);
      String markupString = res.getMarkupContext().getMarkupString();

      // accept either localhost or 127.0.0.1 for the host part of the generated markup
      // note that we are using a MockHttpServletRequest, so the host and port come from there.
      String markupStart =
          "<img src='wsrp_rewrite?wsrp-urlType=resource&amp;wsrp-url=http%3A%2F%2F";
      String markupEnd =
          "%3A8080%2Ftest-resource-portlet%2Fgif%2Flogo.gif&amp;wsrp-requiresRewrite=true/wsrp_rewrite'/>";
      String localhostMarkup = markupStart + "localhost" + markupEnd;
      String homeIPMarkup = markupStart + "127.0.0.1" + markupEnd;
      boolean result = localhostMarkup.equals(markupString) || homeIPMarkup.equals(markupString);
      ExtendedAssert.assertTrue(
          "Expectd '"
              + localhostMarkup
              + "' or '"
              + homeIPMarkup
              + "' but received '"
              + markupString
              + "'.",
          result);
    } finally {
      undeploy(archive);
    }
  }
Esempio n. 7
0
  @Test
  public void testGetMarkupWithNonStandardLocalesStrictMode() throws Exception {
    undeploy(DEFAULT_MARKUP_PORTLET_WAR);
    String getLocalesPortletArchive = "test-getlocales-portlet.war";
    deploy(getLocalesPortletArchive);

    V1GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
    // we need to clear the value first for this test since the getLocales will be populated
    // with default values for the system, and since en_US is not marked as a supported-locale in
    // portlet.xml
    // the default values will be used.
    getMarkup.getMarkupParams().getLocales().clear();
    getMarkup.getMarkupParams().getLocales().add("en_US");

    try {
      producer.getMarkup(getMarkup);
      // fail("Should have thrown an UnsupportetLocaleFault"); // ideally cf
      // http://jira.jboss.com/jira/browse/JBPORTAL-857
      ExtendedAssert.fail("Should have thrown an exception"); // right now
    } catch (Exception expected) {
      // expected
    } finally {
      // checkMarkupResponse(response, "GetLocalesPortlet"); // should we return try to generate
      // markup regardless?
      undeploy(getLocalesPortletArchive);
    }
  }
Esempio n. 8
0
  @Test
  public void testPerformBlockingInteractionNoRegistrationWhenRegistrationRequired()
      throws Exception {
    configureRegistrationSettings(true, false);

    V1PerformBlockingInteraction pbi =
        createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
    try {
      producer.performBlockingInteraction(pbi);
      ExtendedAssert.fail("Should have thrown InvalidRegistration!");
    } catch (V1InvalidRegistration invalidRegistration) {
      // expected
    } catch (Exception e) {
      ExtendedAssert.fail(e.getMessage());
    }
  }
Esempio n. 9
0
  private void checkMarkupResponseWithSession(V1MarkupResponse response, int count)
      throws RemoteException, V1InvalidRegistration, V1OperationFailed {
    ExtendedAssert.assertNotNull(response);

    // Markup context
    V1MarkupContext markupContext = response.getMarkupContext();
    ExtendedAssert.assertNotNull(markupContext);
    String markupString = markupContext.getMarkupString();
    ExtendedAssert.assertString1ContainsString2(markupString, "count = " + count);
    // SessionPortlet outputs URLs using toString so *NOT* XML-encoded
    ExtendedAssert.assertString1ContainsString2(
        markupString,
        "<a href='wsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewrite'>render</a>");

    // checking session
    checkSessionForCurrentlyDeployedPortlet(response);
  }
 public void testInvalidSetProperties() throws Exception {
   PortletContext original =
       PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE, false);
   try {
     consumer.setProperties(original, null);
     ExtendedAssert.fail("Shouldn't be possible to set properties with null changes");
   } catch (IllegalArgumentException expected) {
     // expected
   }
 }
Esempio n. 11
0
  @Test
  public void testImplicitCloning() throws Exception {
    undeploy(DEFAULT_MARKUP_PORTLET_WAR);
    String archiveName = "test-implicitcloning-portlet.war";
    deploy(archiveName);

    try {
      // check the initial value
      V1GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
      V1MarkupResponse res = producer.getMarkup(gm);
      String markupString = res.getMarkupContext().getMarkupString();
      ExtendedAssert.assertEquals("initial", markupString);

      // modify the preference value
      V1PerformBlockingInteraction pbi =
          createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
      pbi.getInteractionParams()
          .setPortletStateChange(V1StateChange.CLONE_BEFORE_WRITE); // request cloning if needed
      String value = "new value";
      pbi.getInteractionParams().getFormParameters().add(createNamedString("value", value));
      V1BlockingInteractionResponse response = producer.performBlockingInteraction(pbi);
      ExtendedAssert.assertNotNull(response);

      // check that we got a new portlet context
      V1PortletContext pc = response.getUpdateResponse().getPortletContext();
      ExtendedAssert.assertNotNull(pc);

      // get the markup again and check that we still get the initial value with the initial portlet
      // context
      res = producer.getMarkup(gm);
      markupString = res.getMarkupContext().getMarkupString();
      ExtendedAssert.assertEquals("initial", markupString);

      // retrieving the markup with the new portlet context should return the new value
      gm.setPortletContext(pc);
      res = producer.getMarkup(gm);
      markupString = res.getMarkupContext().getMarkupString();
      ExtendedAssert.assertEquals(value, markupString);
    } finally {
      undeploy(archiveName);
    }
  }
Esempio n. 12
0
  @Test
  public void testInvalidGetMarkup() throws Exception {
    V1GetMarkup getMarkup = createMarkupRequest();
    getMarkup.getMarkupParams().setMode("invalid mode");

    try {
      producer.getMarkup(getMarkup);
      ExtendedAssert.fail();
    } catch (V1UnsupportedMode unsupportedMode) {
      // expected
    }
  }
Esempio n. 13
0
  @Test
  public void testMarkupCaching() throws Exception {
    V1GetMarkup getMarkup = createMarkupRequest();

    V1MarkupResponse response = producer.getMarkup(getMarkup);

    V1CacheControl cacheControl = response.getMarkupContext().getCacheControl();
    ExtendedAssert.assertNotNull(cacheControl);
    ExtendedAssert.assertEquals(WSRPConstants.CACHE_PER_USER, cacheControl.getUserScope());
    ExtendedAssert.assertEquals(15, cacheControl.getExpires());

    undeploy(DEFAULT_MARKUP_PORTLET_WAR);
    String sessionPortletArchive = "test-session-portlet.war";
    deploy(sessionPortletArchive);

    response = producer.getMarkup(createMarkupRequestForCurrentlyDeployedPortlet());

    cacheControl = response.getMarkupContext().getCacheControl();
    ExtendedAssert.assertNull(cacheControl);

    undeploy(sessionPortletArchive);
  }
Esempio n. 14
0
  @Test
  public void testGetMarkupWithSessionID() throws Exception {
    // The consumer should never have access to or be able to set a sessionID. Sessions are handled
    // by the Producer using cookies.
    V1GetMarkup getMarkup = createMarkupRequest();
    getMarkup.getRuntimeContext().setSessionID("Hello World");

    try {
      producer.getMarkup(getMarkup);
      ExtendedAssert.fail("A sessionID should not be allowed to be passed in GetMarkup()");
    } catch (V1OperationFailed operationFailed) {
      // expected
    }
  }
Esempio n. 15
0
  @Test
  public void testPBIWithSessionID() throws Exception {
    String portletHandle = getDefaultHandle();
    V1PerformBlockingInteraction performBlockingInteraction =
        createDefaultPerformBlockingInteraction(portletHandle);

    V1RuntimeContext runtimeContext = performBlockingInteraction.getRuntimeContext();
    // the sessionID should never be set by the consumer. Sessions are handled by cookies instead
    runtimeContext.setSessionID("Hello World");

    try {
      producer.performBlockingInteraction(performBlockingInteraction);
      ExtendedAssert.fail(
          "Should not be able to pass a sessionID in a PerformBlockingInteraction()");
    } catch (V1OperationFailed expected) {
      // expected
    }
  }
  public void testDestroyClones() throws Exception {
    // switch the behavior for portlet management
    BehaviorRegistry behaviorRegistry = producer.getBehaviorRegistry();
    behaviorRegistry.setPortletManagementBehavior(
        new DestroyClonesPortletManagementBehavior(behaviorRegistry));

    PortletContext original =
        PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE, false);
    PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original);
    ExtendedAssert.assertNotNull(clone);
    Portlet portlet = consumer.getPortlet(clone);
    ExtendedAssert.assertNotNull(portlet);
    ExtendedAssert.assertEquals(
        BasicPortletManagementBehavior.CLONED_HANDLE, portlet.getContext().getId());

    List clones = new ArrayList(1);
    clones.add(clone);
    List result = consumer.destroyClones(clones);
    ExtendedAssert.assertTrue(result.isEmpty());
    try {
      consumer.getPortlet(clone);
      ExtendedAssert.fail("Should have failed: clone should not exist anymore!");
    } catch (PortletInvokerException expected) {
    }

    // re-create clone and try again with an added invalid portlet context
    clone = consumer.createClone(PortletStateType.OPAQUE, original);
    PortletContext invalidContext = PortletContext.createPortletContext("invalid", false);
    clones.add(invalidContext);
    result = consumer.destroyClones(clones);
    ExtendedAssert.assertEquals(1, result.size());
    DestroyCloneFailure failure = (DestroyCloneFailure) result.get(0);
    ExtendedAssert.assertEquals("invalid", failure.getPortletId());
    try {
      consumer.getPortlet(clone);
      ExtendedAssert.fail("Should have failed: clone should not exist anymore!");
    } catch (PortletInvokerException expected) {
    }
  }
Esempio n. 17
0
  private V1MarkupContext checkMarkupResponse(V1MarkupResponse response, String markupString) {
    ExtendedAssert.assertNotNull(response);

    // Markup context
    V1MarkupContext markupContext = response.getMarkupContext();
    ExtendedAssert.assertNotNull(markupContext);
    ExtendedAssert.assertEquals("text/html", markupContext.getMimeType());
    ExtendedAssert.assertEquals("title", markupContext.getPreferredTitle());
    if (!ParameterValidation.isNullOrEmpty(markupString)) {
      ExtendedAssert.assertTrue(markupContext.isRequiresUrlRewriting());
    } else {
      ExtendedAssert.assertFalse(markupContext.isRequiresUrlRewriting());
    }
    ExtendedAssert.assertEquals(markupString, markupContext.getMarkupString());

    // Session context
    V1SessionContext sessionContext = response.getSessionContext();
    // The session information is should never be sent to the consumer, Cookies are used instead.
    ExtendedAssert.assertNull(sessionContext);

    return markupContext;
  }
Esempio n. 18
0
  @Test
  public void testGetMarkupRenderParameters() throws Exception {
    undeploy(DEFAULT_MARKUP_PORTLET_WAR);
    String archiveName = "test-renderparam-portlet.war";
    deploy(archiveName);

    try {
      V1GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
      V1MarkupResponse res = producer.getMarkup(gm);

      String markupString = res.getMarkupContext().getMarkupString();

      String julienLink = extractLink(markupString, 0);
      WSRPPortletURL julienURL = WSRPPortletURL.create(julienLink);

      ExtendedAssert.assertString1ContainsString2(markupString, "Hello, Anonymous!");
      ExtendedAssert.assertString1ContainsString2(markupString, "Counter: 0");

      ExtendedAssert.assertTrue(julienURL instanceof WSRPRenderURL);
      WSRPRenderURL julienRender = (WSRPRenderURL) julienURL;

      // We're now trying to get a hello for Julien ;)
      gm.getMarkupParams()
          .setNavigationalState(julienRender.getNavigationalState().getStringValue());
      res = producer.getMarkup(gm);
      markupString = res.getMarkupContext().getMarkupString();
      ExtendedAssert.assertString1ContainsString2(markupString, "Hello, Julien!");

      // julien.length() * 2 to bypass second link
      WSRPPortletURL incrementURL =
          WSRPPortletURL.create(extractLink(markupString, julienLink.length() * 2));
      ExtendedAssert.assertTrue(incrementURL instanceof WSRPActionURL);
      WSRPActionURL incrementAction = (WSRPActionURL) incrementURL;

      // let's see now if we can increment the counter
      V1PerformBlockingInteraction performBlockingInteraction =
          createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
      V1InteractionParams interactionParams = performBlockingInteraction.getInteractionParams();
      interactionParams.setInteractionState(incrementAction.getInteractionState().getStringValue());
      producer.performBlockingInteraction(performBlockingInteraction);
      res = producer.getMarkup(gm);
      markupString = res.getMarkupContext().getMarkupString();
      ExtendedAssert.assertString1ContainsString2(markupString, "Counter: 1");
    } finally {
      undeploy(archiveName);
    }
  }
  public void testClone() throws Exception {
    PortletContext original =
        PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE, false);
    PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original);
    ExtendedAssert.assertNotNull(clone);
    ExtendedAssert.assertFalse(original.equals(clone));
    ExtendedAssert.assertEquals(BasicPortletManagementBehavior.CLONED_HANDLE, clone.getId());

    Portlet originalPortlet = consumer.getPortlet(original);
    Portlet clonePortlet = consumer.getPortlet(clone);
    ExtendedAssert.assertNotNull(clonePortlet);
    ExtendedAssert.assertFalse(originalPortlet.getContext().equals(clonePortlet.getContext()));

    // information about the portlet should be the same
    MetaInfo originalInfo = originalPortlet.getInfo().getMeta();
    MetaInfo cloneInfo = clonePortlet.getInfo().getMeta();
    ExtendedAssert.assertEquals(
        originalInfo.getMetaValue(MetaInfo.TITLE), cloneInfo.getMetaValue(MetaInfo.TITLE));
    ExtendedAssert.assertEquals(
        originalInfo.getMetaValue(MetaInfo.DESCRIPTION),
        cloneInfo.getMetaValue(MetaInfo.DESCRIPTION));
  }
 private void checkProperties(PropertyMap props, String expectedValue) {
   ExtendedAssert.assertNotNull(props);
   ExtendedAssert.assertEquals(1, props.size());
   ExtendedAssert.assertEquals(
       expectedValue, props.getProperty(BasicPortletManagementBehavior.PROPERTY_NAME).get(0));
 }