Package org.apache.jetspeed.profiler.rules

Examples of org.apache.jetspeed.profiler.rules.ProfilingRule


    {
        assertNotNull("profiler service is null", profiler);
        System.out.println("START: running test user role fallback...");
       
        // make sure rule is set correctly
        ProfilingRule rule = profiler.getRule("user-role-fallback");
        assertNotNull("rule is null ", rule);
        Iterator c = rule.getRuleCriteria().iterator();
        int ix = 0;
        while (c.hasNext())
        {
            RuleCriterion rc = (RuleCriterion)c.next();
            assertTrue("criterion type check " + rc.getType(), rc.getType().equals(URF_CRITERIA[ix]));
            System.out.println(rc.getType());
            ix++;
        }
       
        // test applying it
        RequestContext context = new MockRequestContext();
        Subject subject = createSubject();
        context.setPath("/homepage.psml");       
        context.setSubject(subject);
        ProfileLocator locator = rule.apply(context, profiler);
        System.out.println("locator = " + locator);
        assertTrue("locator string " + locator.toString(), locator.toString().equals("/homepage.psml:user:david:navigation:/:role:ATP:role:NB:role:ATP-NB:page:/homepage.psml"));
       
        System.out.println("COMPLETED: running test user role fallback.");
    }
View Full Code Here


    {
        assertNotNull("profiler service is null", profiler);
        System.out.println("START: running test user rolecombo fallback...");
       
        // make sure rule is set correctly
        ProfilingRule rule = profiler.getRule("user-rolecombo-fallback");
        assertNotNull("rule is null ", rule);
        Iterator c = rule.getRuleCriteria().iterator();
        int ix = 0;
        while (c.hasNext())
        {
            RuleCriterion rc = (RuleCriterion)c.next();
            assertTrue("criterion type check " + rc.getType(), rc.getType().equals(URCF_CRITERIA[ix]));
            System.out.println(rc.getType());
            ix++;
        }
       
        // test applying it
        RequestContext context = new MockRequestContext();
        Subject subject = createSubject2();
        context.setPath("/homepage.psml");       
        context.setSubject(subject);
        ProfileLocator locator = rule.apply(context, profiler);
        System.out.println("locator = " + locator);
        assertTrue("locator string " + locator.toString(), locator.toString().equals("/homepage.psml:user:david:navigation:/:role:ATP-NB:page:/homepage.psml"));
       
        System.out.println("COMPLETED: running test user role fallback.");
    }
View Full Code Here

    public void testRules() throws Exception
    {
        assertNotNull("profiler service is null", profiler);

        // Test Default Rule
        ProfilingRule rule = profiler.getDefaultRule();
        assertNotNull("Default profiling rule is null", rule);
        assertTrue("default rule unexpected, = " + rule.getId(), rule.getId().equals(DEFAULT_RULE));
        assertTrue("default rule class not mapped", rule instanceof StandardProfilingRule);

        // Test anonymous principal-rule
        ProfilingRule anonRule = profiler.getRuleForPrincipal(new UserPrincipalImpl("anon"),
                ProfileLocator.PAGE_LOCATOR);
        assertNotNull("anonymous rule is null", anonRule);
        assertTrue("anonymous rule is j1", anonRule.getId().equals(DEFAULT_RULE));

        // Test Retrieving All Rules
        int standardCount = 0;
        int fallbackCount = 0;
        Iterator rules = profiler.getRules().iterator();
View Full Code Here

    public void testPath() throws Exception
    {
        assertNotNull("profiler service is null", profiler);

        RequestContext request = new MockRequestContext("/football/nfl/chiefs");
        ProfilingRule rule = profiler.getRule("path");
        ProfileLocator locator = profiler.getProfile(request, rule);
        assertNotNull("rule test on getProfile returned null", locator);
        String path = locator.getLocatorPath();
        System.out.println("locator = " + path);
        assertTrue("locator path: " + path, path.equals("path:/football/nfl/chiefs"));
View Full Code Here

    public void testMaintenance() throws Exception
    {
        System.out.println("Maintenance tests commencing....");
        assertNotNull("profiler service is null", profiler);
        ProfilingRule rule = new StandardProfilingRule(resolvers);
        rule.setClassname("org.apache.jetspeed.profiler.rules.impl.StandardProfilingRule");
        rule.setId("testmo");
        rule.setTitle("The Grand Title");
        profiler.storeProfilingRule(rule);
        ProfilingRule rule2 = profiler.getRule("testmo");
        assertNotNull("rule couldnt be added", rule2);
        assertTrue("rule id bad", rule.getId().equals(rule2.getId()));

        rule2.setTitle("The New Title");
        profiler.storeProfilingRule(rule2);

        ProfilingRule rule3 = profiler.getRule("testmo");
        assertNotNull("rule couldnt be retrieved", rule3);
        assertTrue("rule title is bad", rule3.getTitle().equals(rule2.getTitle()));

        profiler.deleteProfilingRule(rule);
        ProfilingRule rule4 = profiler.getRule("testmo");
        assertNull("rule couldnt be deleted", rule4);

        System.out.println("Maintenance tests completed.");
    }
View Full Code Here

        String ruleId1 = "j1-test";
        String ruleId2 = "j2-test";
       
       
        // create org.apache.jetspeed.profiler.rules.impl.StandardProfilingRule
        ProfilingRule rule = profiler.createProfilingRule(true);
        assertNotNull("rule is null ", rule);
        rule.setId(ruleId1);
        rule.setTitle("Test Rule 1");
        this.createStandardCriteria(rule);
       
        profiler.storeProfilingRule(rule);
        //Check
        ProfilingRule rule2 = profiler.getRule(ruleId1);
        assertNotNull("default rule couldnt be added", rule2);
        assertTrue("default rule id bad", rule.getId().equals(rule2.getId()));
       
        rule = profiler.createProfilingRule(false);
        assertNotNull("rule is null ", rule);
        rule.setId(ruleId2);
        rule.setTitle("Test Rule 2");
       
        this.createFallbackCriteria(rule);

        profiler.storeProfilingRule(rule);
        //Check
        rule2 = profiler.getRule(ruleId2);
        assertNotNull("fallback rule couldnt be added", rule2);
        assertTrue("fallback rule id bad", rule.getId().equals(rule2.getId()));

        // Test Retrieving All Rules
        int standardCount = 0;
        int fallbackCount = 0;
        Iterator rules = profiler.getRules().iterator();
View Full Code Here

              {
                Iterator _itRoles = jsRules.iterator();
                  while (_itRoles.hasNext())
                  {
                    JSPrincipalRule pr = (JSPrincipalRule) _itRoles.next();
                    ProfilingRule pRule = pm.getRule(pr.getRule());
                   
                    try
                    {
                      PrincipalRule p1 = pm.createPrincipalRule();
                      p1.setLocatorName(pr.getLocator());
View Full Code Here

                    SerializerException.COMPONENTMANAGER_DOES_NOT_EXIST
                            .create("org.apache.jetspeed.profiler.Profiler"));
        Class standardRuleClass = null;
        try
        {
          ProfilingRule tempStandardRule = pm.createProfilingRule(true);
          standardRuleClass = tempStandardRule.getClass();
        }
        catch (Exception e)
        {
          throw new SerializerException(
                SerializerException.CREATE_OBJECT_FAILED
                        .create(new String[]
                        { "Standard Rule", e.getMessage()}));
        }
       
        Iterator list = null;
        try
        {
            list = pm.getRules().iterator();
        } catch (Exception e)
        {
            throw new SerializerException(
                    SerializerException.GET_EXISTING_OBJECTS
                            .create(new String[]
                            { "ProfilingRules", e.getMessage()}));
        }
        while (list.hasNext())
        {
            try
            {
                ProfilingRule p = (ProfilingRule) list.next();
                if (!(this.rulesMap.containsKey(p.getId())))
                {
                    JSProfilingRule rule = createProfilingRule(p, (standardRuleClass == p.getClass()));
                    rulesMap.put(rule.getId(), rule);
                    ((JSSeedData)getSnapshot()).getRules().add(rule);

                }
            } catch (Exception e)
            {
                throw new SerializerException(
                        SerializerException.CREATE_SERIALIZED_OBJECT_FAILED
                                .create(new String[]
                                { "ProfilingRules", e.getMessage()}));
            }
        }

        // determine the defualt rule
        ProfilingRule defaultRule = pm.getDefaultRule();
        if (defaultRule != null)
          ((JSSeedData)getSnapshot()).setDefaultRule(defaultRule.getId());

        // get Rules for each user

        Iterator _itUsers = this.userMap.values().iterator();
        while (_itUsers.hasNext())
View Full Code Here

     * @
     * @throws SerializerException, ClassNotFoundException, ProfilerException
     */
     protected ProfilingRule recreateRule(Profiler profiler, ProfilingRule existingRule, JSProfilingRule jsp) throws SerializerException, ClassNotFoundException, ProfilerException
     {
       ProfilingRule rule = null;
       boolean existing = false;
      
       if (existingRule == null)
       {
         rule = profiler.getRule(jsp.getId());
         if (jsp.isStandardRule())
             rule = profiler.createProfilingRule(true);  
         else
             rule = profiler.createProfilingRule(false);
         rule.setId(jsp.getId());
       }
       else
       {
         rule = existingRule;
         existing = true;
       }
        
       rule.setTitle(jsp.getDescription());
      
       JSRuleCriterions col = jsp.getCriterions();
        
       Iterator _it = col.iterator();
       while (_it.hasNext())
       {
           RuleCriterion c = recreateRuleCriterion(profiler, (JSRuleCriterion) _it.next(),rule);
           if (c != null)
           {
             Collection cHelp = rule.getRuleCriteria();
             if ((existing) && (cHelp.contains(c)))
               cHelp.remove(c); //remove existing duplicate
             cHelp.add(c); // add the current version back in
           }
       }
View Full Code Here

          {
            JSProfilingRule _c = (JSProfilingRule)_it.next();

            try
            {
              ProfilingRule rule = null;
                
                 rule = pm.getRule(_c.getId());
                 if ((rule == null) || (this.getSetting(JetspeedSerializer.KEY_OVERWRITE_EXISTING)))
                 {
                   rule = recreateRule(pm,rule, _c);
                   pm.storeProfilingRule(rule);
                 }
            }
            catch (Exception e)
            {
              throw new SerializerException(
                        SerializerException.CREATE_OBJECT_FAILED
                          .create("org.apache.jetspeed.capabilities.Capabilities",e.getLocalizedMessage()));
         }
          }
          /** reset the default profiling rule */
          String defaultRuleID = ((JSSeedData)getSnapshot()).getDefaultRule();
          if (defaultRuleID != null)
          {
            ProfilingRule defaultRule = pm.getRule(defaultRuleID);
            if (defaultRule != null)
              pm.setDefaultRule(defaultRuleID);
          }
        }
        else
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.profiler.rules.ProfilingRule

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.