Package org.apache.pluto.testsuite

Examples of org.apache.pluto.testsuite.TestResult


 
 
  // Test Methods ------------------------------------------------------------
 
  protected TestResult checkSessionInvalidated(PortletRequest request) {
        TestResult result = new TestResult();
        result.setDescription("Ensure portlet session is invalidated after "
            + "the max inactive interval.");
        result.setSpecPLT("15.6");
       
        // Check if max inactive interval is set to the portlet session.
        String maxInactiveIntervalSet = request.getParameter(
            MAX_INACTIVE_INTERVAL_SET);
        if (LOG.isDebugEnabled()) {
          LOG.debug("Retrieved render parameter: " + MAX_INACTIVE_INTERVAL_SET
              + " = " + maxInactiveIntervalSet);
        }
       
        // If the max inactive interval is set to portlet session, the portlet
        //   session should have been invalidated by the container.
        if (Boolean.TRUE.toString().equals(maxInactiveIntervalSet)) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Max inactive interval is set to portlet session: "
                + "portlet session should have expired "
                + "(current time millis: "
                + System.currentTimeMillis() + ")...");
          }
            PortletSession session = request.getPortletSession(false);
            if (session == null) {
              result.setReturnCode(TestResult.PASSED);
            } else {
              result.setReturnCode(TestResult.FAILED);
              result.setResultMessage("PortletSession should have expired "
                  + "and have been invalidated, but is still available. "
                  + "Make sure that other portlets did not create a new "
                  + "portlet session.");
            }
        }
       
        // If the max inactive interval is not set to portlet session, set its
        //   value to 5 (seconds). In this way, next time the test portlet is
        //   rendered, the portlet session should have been invalidated.
        else {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Max inactive interval is not set to portlet session: "
                + "setting to 5 seconds (current time millis: "
                + System.currentTimeMillis() + ")...");
          }
            PortletSession session = request.getPortletSession(true);
            session.setMaxInactiveInterval(5);
            result.setReturnCode(TestResult.WARNING);
            result.setResultMessage("Click the provided link to validate test.");
        }
       
        // Return the test result:
        //   PASSED - the test is passed.
        //   FAILED - the test is failed.
View Full Code Here


   
   
    // Test Methods ------------------------------------------------------------
   
    protected TestResult checkPreferenceValidator(PortletRequest request) {
        TestResult result = new TestResult();
        result.setDescription("Ensure the validator catches invalid preferences.");
        result.setSpecPLT("14.4");
       
        PortletPreferences preferences = request.getPreferences();
        if (LOG.isDebugEnabled()) {
          LOG.debug("Original preferences:");
          logPreferences(preferences);
        }
        boolean exceptionThrown = false;
        try {
            preferences.setValue("TEST", " Spaces removed by trim ");
            if (LOG.isDebugEnabled()) {
              LOG.debug("Modified VALIDATION_TEST_KEY preference:");
              logPreferences(preferences);
            }
            // Call store() method to invoke the validator.
            preferences.store();
           
        } catch (ReadOnlyException ex) {
          TestUtils.failOnException("Unable to set preference value.", ex, result);
          return result;
         
        } catch (IOException ex) {
          TestUtils.failOnException("Unable to store preference value.", ex, result);
          return result;
         
        } catch (ValidatorException ex) {
          // We are expecting this exception!
            exceptionThrown = true;
            // FIXME: what is going on below?
            try {
              //get rid of spaces because it causes problems with reset() call.
                preferences.setValue("TEST", "OK");
              preferences.reset("TEST");
            } catch (Throwable th) {
              LOG.error(th);             
            }
        }
       
        if (exceptionThrown) {
          result.setReturnCode(TestResult.PASSED);
        } else {
          result.setReturnCode(TestResult.FAILED);
          result.setResultMessage("Illegal value not caught by validator.");
        }
        return result;
    }
View Full Code Here

        return result;
    }
   
    protected TestResult checkOnePreferenceValidatorPerPortletDefinition(
        PortletRequest request) {
        TestResult result = new TestResult();
        result.setDescription("Ensure only one validator instance is created "
            + "per portlet definition.");
        result.setSpecPLT("14.4");
       
        PortletPreferences preferences = request.getPreferences();
        try {
            preferences.setValue(
                PreferencesValidatorImpl.CHECK_VALIDATOR_COUNT,
                "true");
            // Call store() method to invoke the validator.
            preferences.store();
            result.setReturnCode(TestResult.PASSED);
        } catch (ReadOnlyException ex) {
          TestUtils.failOnException("Unable to set preference value.", ex, result);
        } catch (IOException ex) {
          TestUtils.failOnException("Unable to store preference value.", ex, result);
        } catch (ValidatorException ex) {
View Full Code Here

        }
        return result;
    }

    protected TestResult checkStorePreferences(PortletRequest request) {
        TestResult result = new TestResult();
        result.setDescription("Ensure storage works for portlet preferences.");
        result.setSpecPLT("14.1");
       
        PortletPreferences preferences = request.getPreferences();
        if (LOG.isDebugEnabled()) {
          LOG.debug("Preferences to store: " + preferences);
        }
       
        boolean setOccured = false;
        boolean storeOccured = false;
       
        try {
          // Set new value for preference "dummyName".
            preferences.setValue(PREF_NAME, NEW_VALUE);
            String value = preferences.getValue(PREF_NAME, DEF_VALUE);
            if (NEW_VALUE.equals(value)) {
                setOccured = true;
            }
            // Store the preference and get value.
            preferences.store();
            value = preferences.getValue(PREF_NAME, DEF_VALUE);
            if (NEW_VALUE.equals(value)) {
                storeOccured = true;
            }
        } catch (ReadOnlyException ex) {
          TestUtils.failOnException("Unable to set preference value.", ex, result);
          return result;
        } catch (ValidatorException ex) {
          TestUtils.failOnException("Unable to store preference value.", ex, result);
          return result;
        } catch(IOException ex) {
          TestUtils.failOnException("Unable to store preference value.", ex, result);
          return result;
        } finally {
            // Reset preference to default value, and store!
          try {
            preferences.reset(PREF_NAME);
            preferences.store();
          } catch (Exception ex) {
              TestUtils.failOnException("Unable to set preference value.", ex, result);
              return result;
          }
        }
       
        // Everything is OK.
        if (setOccured && storeOccured) {
          result.setReturnCode(TestResult.PASSED);
        }
        // Error occurred when setting preference value.
        else if (!setOccured) {
          result.setReturnCode(TestResult.WARNING);
          result.setResultMessage("A function upon which the reset test "
              + "depends failed to execute as expected. "
              + "Check the other test results in this test suite.");
        }
        // Error occurred when storing preference value.
        else {
          result.setReturnCode(TestResult.FAILED);
          result.setResultMessage("Preferences not successfully stored.");
        }
        return result;
    }
View Full Code Here

        }
        return result;
    }
   
    protected TestResult checkIsUserIndUndeclaredRole(PortletRequest request) {
        TestResult result = isUserLoggedIn(request);
        result.setDescription("Test if user is in undeclared role");
        if (result.getReturnCode() == TestResult.WARNING) {
            return result;
        }
       
        String fakeRole = "fakeTestRoleFooBar";
        if (!request.isUserInRole(fakeRole)) {
          result.setReturnCode(TestResult.PASSED);
        } else {
          result.setReturnCode(TestResult.FAILED);
          result.setResultMessage("User is in the fake role named " + fakeRole);
        }
        return result;
    }
View Full Code Here

   
   
    // Private Methods ---------------------------------------------------------
   
    private TestResult isUserLoggedIn(PortletRequest request) {
      TestResult result = new TestResult();
        if (request.getRemoteUser() == null) {
            result.setReturnCode(TestResult.WARNING);
            result.setResultMessage("User is not logged in.");
        }
        return result;
    }
View Full Code Here

   
   
    // Test Methods ------------------------------------------------------------
   
    protected TestResult checkGetNullAttribute(PortletRequest req) {
        TestResult result = new TestResult();
        result.setDescription("Ensure that if an attribute bound to an invalid "
            + "key is retrieved, null is returned.");

        Object val = req.getAttribute(KEY);
        if (val == null) {
          result.setReturnCode(TestResult.PASSED);
        } else {
          TestUtils.failOnAssertion("unbound attribute", val, null, result);
        }
        return result;
    }
View Full Code Here

        return result;
    }


    protected TestResult checkSetAttribute(PortletRequest req) {
        TestResult result = new TestResult();
        result.setDescription("Ensure that attributes can be set to "
            + "portlet request.");

        req.setAttribute(KEY, VAL);
        Object val = req.getAttribute(KEY);
        if (VAL.equals(val)) {
          result.setReturnCode(TestResult.PASSED);
        } else {
          TestUtils.failOnAssertion("attribute", val, VAL, result);
        }

        req.removeAttribute(KEY);
View Full Code Here

        req.removeAttribute(KEY);
        return result;
    }

    protected TestResult checkRemoveAttribute(PortletRequest req) {
        TestResult result = new TestResult();
        result.setDescription("Ensure that attributes can be removed from "
            + "portlet request.");
       
        req.setAttribute(KEY, VAL);
        req.removeAttribute(KEY);
        Object val = req.getAttribute(KEY);
        if (val == null) {
          result.setReturnCode(TestResult.PASSED);
        } else {
          TestUtils.failOnAssertion("removed attribute", val, null, result);
        }
        return result;
    }
View Full Code Here

        }
        return result;
    }

    protected TestResult checkEnumerateAttributes(PortletRequest req) {
        TestResult result = new TestResult();
        result.setDescription("Ensure that all attribute names appear in the "
            + "attribute name enumeration returned by portlet request.");
       
        int count = 5;
        for (int i = 0; i < count; i++) {
            req.setAttribute(KEY + "." + i, VAL);
        }
       
        int found = 0;
        for (Enumeration en = req.getAttributeNames();
            en.hasMoreElements(); ) {
            if (en.nextElement().toString().startsWith(KEY)) {
                found++;
            }
        }

        if (count == found) {
          result.setReturnCode(TestResult.PASSED);
        } else {
          TestUtils.failOnAssertion("count of attribute names",
              String.valueOf(found), String.valueOf(count), result);
        }
        return result;
View Full Code Here

TOP

Related Classes of org.apache.pluto.testsuite.TestResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.