From cc08b5573ab5fb3b88ef64a48d3edeae475b852a Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Tue, 04 Sep 2007 19:27:20 +0000
Subject: [PATCH] Move the DNBuilder implementation into the core ManagedObjectPath class and add the following methods:

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/admin/ManagedObjectPathTest.java |   84 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/ManagedObjectPathTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/ManagedObjectPathTest.java
index ff3f06d..ea8a1f1 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/ManagedObjectPathTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/admin/ManagedObjectPathTest.java
@@ -47,6 +47,7 @@
 import org.opends.server.admin.std.server.ConnectionHandlerCfg;
 import org.opends.server.admin.std.server.GlobalCfg;
 import org.opends.server.admin.std.server.LDAPConnectionHandlerCfg;
+import org.opends.server.types.DN;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
@@ -258,4 +259,87 @@
         ManagedObjectPath
             .valueOf("/relation=synchronization-provider+type=multimaster-synchronization-provider+name=MMR/relation=multimaster-domain+name=Domain"));
   }
+
+  /**
+   * Tests matches and equals methods behave differently.
+   */
+  @Test
+  public void testMatches() {
+    ManagedObjectPath<?, ?> path = ManagedObjectPath.emptyPath();
+
+    ManagedObjectPath<ConnectionHandlerCfgClient, ConnectionHandlerCfg> child1 = path
+        .child(RootCfgDefn.getInstance()
+            .getConnectionHandlersRelationDefinition(),
+            "LDAP connection handler");
+
+    ManagedObjectPath<LDAPConnectionHandlerCfgClient, LDAPConnectionHandlerCfg> child2 = path
+        .child(RootCfgDefn.getInstance()
+            .getConnectionHandlersRelationDefinition(),
+            LDAPConnectionHandlerCfgDefn.getInstance(),
+            "LDAP connection handler");
+
+    ManagedObjectPath<LDAPConnectionHandlerCfgClient, LDAPConnectionHandlerCfg> child3 = path
+        .child(RootCfgDefn.getInstance()
+            .getConnectionHandlersRelationDefinition(),
+            LDAPConnectionHandlerCfgDefn.getInstance(),
+            "Another LDAP connection handler");
+
+    assertTrue(child1.matches(child1));
+    assertTrue(child2.matches(child2));
+    assertTrue(child1.matches(child2));
+    assertTrue(child2.matches(child1));
+    
+    assertTrue(child1.equals(child1));
+    assertTrue(child2.equals(child2));
+    assertFalse(child1.equals(child2));
+    assertFalse(child2.equals(child1));
+    
+    assertFalse(child1.matches(child3));
+    assertFalse(child2.matches(child3));
+    assertFalse(child3.matches(child1));
+    assertFalse(child3.matches(child2));
+    
+    assertFalse(child1.equals(child3));
+    assertFalse(child2.equals(child3));
+    assertFalse(child3.equals(child1));
+    assertFalse(child3.equals(child2));
+  }
+  
+  /**
+   * Tests toDN method.
+   * 
+   * @throws Exception
+   *           If an unexpected error occurred.
+   */
+  @Test
+  public void testToDN() throws Exception {
+    ManagedObjectPath<?, ?> path = ManagedObjectPath.emptyPath();
+
+    ManagedObjectPath<ConnectionHandlerCfgClient, ConnectionHandlerCfg> child1 = path
+        .child(RootCfgDefn.getInstance()
+            .getConnectionHandlersRelationDefinition(),
+            "LDAP connection handler");
+
+    ManagedObjectPath<LDAPConnectionHandlerCfgClient, LDAPConnectionHandlerCfg> child2 = path
+        .child(RootCfgDefn.getInstance()
+            .getConnectionHandlersRelationDefinition(),
+            LDAPConnectionHandlerCfgDefn.getInstance(),
+            "LDAP connection handler");
+
+    ManagedObjectPath<LDAPConnectionHandlerCfgClient, LDAPConnectionHandlerCfg> child3 = path
+        .child(RootCfgDefn.getInstance()
+            .getConnectionHandlersRelationDefinition(),
+            LDAPConnectionHandlerCfgDefn.getInstance(),
+            "Another LDAP connection handler");
+    
+    DN expectedEmpty = DN.nullDN();
+    DN expectedChild1 = DN.decode("cn=LDAP connection handler,cn=connection handlers,cn=config");
+    DN expectedChild2 = DN.decode("cn=LDAP connection handler,cn=connection handlers,cn=config");
+    DN expectedChild3 = DN.decode("cn=Another LDAP connection handler,cn=connection handlers,cn=config");
+    
+    assertEquals(path.toDN(), expectedEmpty);
+    assertEquals(child1.toDN(), expectedChild1);
+    assertEquals(child2.toDN(), expectedChild2);
+    assertEquals(child3.toDN(), expectedChild3);
+  }
 }

--
Gitblit v1.10.0