Esempio n. 1
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. 2
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. 3
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);
    }
  }
Esempio n. 4
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. 5
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. 6
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. 7
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);
  }