2 Replies Latest reply on Jul 10, 2006 2:27 AM by jaikiran

    Expected behavior of FQN?

    jaikiran

      Hi,
      Looks like the FQN created by passing a string and FQN created using Fqn.fromString() are NOT *equal*. Here's a sample program:

      package org.myapp;
      
      import org.jboss.cache.Fqn;
      import org.jboss.cache.PropertyConfigurator;
      import org.jboss.cache.TreeCache;
      
      /**
       * @author Jaikiran Pai
       *
       */
      public class TestFQN {
      
       public static void main(String[] args) {
       try {
       TreeCache treeCache = new TreeCache();
       PropertyConfigurator config = new PropertyConfigurator(); // configure tree cache. Needs to be in the classpath
       config.configure(treeCache, "D:\\SchedulerInJBoss\\local-eviction-service.xml");
       treeCache.start();
      
       Fqn fqn = new Fqn("a/b/c");
       Fqn fqnFromString = Fqn.fromString("a/b/c");
      
       System.out.println("fqn equals fqnFromString? : " + fqn.equals(fqnFromString));
      
       /*treeCache.put("a/b/c",new Integer("1"),"1");
       System.out.println("Exists fqn? (created WITHOUT using fromString) : " + treeCache.exists(new Fqn("a/b/c")));
       System.out.println("Exists fqn? (created using fromString) : " + treeCache.exists(Fqn.fromString("a/b/c")));
       */
      
      
      
       } catch (Exception e) {
       e.printStackTrace();
       }
      
      
       }
      }


      This programs returns false when equals method is invoked on the two Fqns.
      Is this the expected behavior of Fqn?



        • 1. Re: Expected behavior of FQN?
          jaikiran

          Had a look at the test cases and the FqnTest.java does not have a test case for this specific scenario. I added the following test case to the same:

          /**
           * @testDesc Tests the {@link Fqn#equals(Object)} method. Two Fqn will be created, one
           * will use the {@link Fqn#Fqn(Object)} and the other will use {@link Fqn#fromString(String)}.
           * These two objects will then be checked for equality
           */
           public void testEquals4() {
           String fqnPath = "a/b/c";
           Fqn fqnUsingFromStringMethod = Fqn.fromString(fqnPath);
           Fqn fqnPassingStringToConstructor = new Fqn(fqnPath);
          
           assertTrue("Fqn created using fromString() is NOT equal to Fqn create using Fqn(Object obj) constructor", fqnUsingFromStringMethod.equals(fqnPassingStringToConstructor));
          
           }


          This test case shows that the equals() method is failing in this scenario.



          • 2. Re: Expected behavior of FQN?
            jaikiran

            Is this behavior of Fqn correct? If yes, shouldnt this be documented through the javadocs?