예제 #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);
  }
예제 #2
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;
  }
예제 #3
0
  @Test
  public void testGetMarkupMultiValuedFormParams() throws Exception {
    undeploy(DEFAULT_MARKUP_PORTLET_WAR);
    String multiValuedPortletArchive = "test-multivalued-portlet.war";
    deploy(multiValuedPortletArchive);

    V1NamedString namedString = createNamedString("multi", "value1");
    try {
      V1PerformBlockingInteraction action =
          createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
      List<V1NamedString> formParameters = action.getInteractionParams().getFormParameters();
      formParameters.add(namedString);
      V1BlockingInteractionResponse actionResponse = producer.performBlockingInteraction(action);
      V1GetMarkup markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
      markupRequest
          .getMarkupParams()
          .setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
      V1MarkupResponse response = producer.getMarkup(markupRequest);
      checkMarkupResponse(response, "multi: value1");

      formParameters.clear();
      formParameters.add(namedString);
      formParameters.add(createNamedString("multi", "value2"));
      actionResponse = producer.performBlockingInteraction(action);
      markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
      markupRequest
          .getMarkupParams()
          .setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
      response = producer.getMarkup(markupRequest);
      checkMarkupResponse(response, "multi: value1, value2");

      formParameters.clear();
      // TODO: use the WSRP1TypeFactory to create the named string
      formParameters.add(createNamedString("foo", null));
      actionResponse = producer.performBlockingInteraction(action);
      markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
      markupRequest
          .getMarkupParams()
          .setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
      response = producer.getMarkup(markupRequest);
      checkMarkupResponse(response, "multi: ");
    } catch (Exception e) {
      // Print error to the server logs since arquillian can't handle non serialzable errors
      System.out.println("Failure in TestGetMarkupMultiValuedFromParams");
      e.printStackTrace();
      throw new Exception(e);
    } finally {
      undeploy(multiValuedPortletArchive);
    }
  }
예제 #4
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);
    }
  }
예제 #5
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
    }
  }
예제 #6
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);
    }
  }
예제 #7
0
  @Test
  public void testApplicationScopeVariableHandling() throws Exception {
    undeploy(DEFAULT_MARKUP_PORTLET_WAR);
    String archive = "test-applicationscope-portlet.war";
    deploy(archive);

    try {
      // set appVar to value in the application scope by the first portlet
      V1PerformBlockingInteraction pbi =
          createDefaultPerformBlockingInteraction(getPortletHandleFrom("Set"));
      pbi.getInteractionParams().getFormParameters().add(createNamedString("appVar", "value"));
      producer.performBlockingInteraction(pbi);

      // the second portlet reads the appVar value and outputs it
      V1GetMarkup gm = createMarkupRequest(getPortletHandleFrom("Get"));
      V1MarkupResponse res = producer.getMarkup(gm);
      checkMarkupResponse(res, "appVar=value");
    } finally {
      undeploy(archive);
    }
  }