| | |
| | | import org.opends.server.admin.AdminTestCase; |
| | | import org.opends.server.admin.TestCfg; |
| | | import org.opends.server.admin.TestChildCfg; |
| | | import org.opends.server.admin.TestChildCfgDefn; |
| | | import org.opends.server.admin.TestParentCfg; |
| | | import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor; |
| | | import org.opends.server.admin.std.server.RootCfg; |
| | |
| | | public final class ConstraintTest extends AdminTestCase { |
| | | |
| | | // Child DN. |
| | | private static final String TEST_CHILD_1_DN = |
| | | "cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config"; |
| | | private static final String TEST_CHILD_1_DN = "cn=test child 1,cn=test children,cn=test parent 1,cn=test parents,cn=config"; |
| | | |
| | | |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * Tests that retrieval can succeed. |
| | | * |
| | | * @throws Exception |
| | | * If the test unexpectedly fails. |
| | | */ |
| | | @Test |
| | | public void testGetManagedObjectSuccess() throws Exception { |
| | | MockConstraint constraint = new MockConstraint(true, false); |
| | | |
| | | try { |
| | | TestCaseUtils.addEntry(TEST_CHILD_1); |
| | | TestCfg.addConstraint(constraint); |
| | | |
| | | TestParentCfg parent = getParent("test parent 1"); |
| | | parent.getTestChild("test child 1"); |
| | | } finally { |
| | | TestCfg.removeConstraint(constraint); |
| | | |
| | | try { |
| | | deleteSubtree(TEST_CHILD_1_DN); |
| | | } catch (Exception e) { |
| | | // Do nothing. |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests that retrieval can fail. |
| | | * |
| | | * @throws Exception |
| | | * If the test unexpectedly fails. |
| | | */ |
| | | @Test |
| | | public void testGetManagedObjectFail() throws Exception { |
| | | MockConstraint constraint = new MockConstraint(false, true); |
| | | |
| | | try { |
| | | TestCaseUtils.addEntry(TEST_CHILD_1); |
| | | TestCfg.addConstraint(constraint); |
| | | |
| | | TestParentCfg parent = getParent("test parent 1"); |
| | | parent.getTestChild("test child 1"); |
| | | } catch (ConfigException e) { |
| | | Throwable cause = e.getCause(); |
| | | if (cause instanceof ConstraintViolationException) { |
| | | ConstraintViolationException cve = (ConstraintViolationException) cause; |
| | | Assert.assertEquals(cve.getMessages().size(), 1); |
| | | Assert.assertSame(cve.getManagedObject().getManagedObjectDefinition(), |
| | | TestChildCfgDefn.getInstance()); |
| | | } else { |
| | | // Wrong cause. |
| | | throw e; |
| | | } |
| | | } finally { |
| | | TestCfg.removeConstraint(constraint); |
| | | |
| | | try { |
| | | deleteSubtree(TEST_CHILD_1_DN); |
| | | } catch (Exception e) { |
| | | // Do nothing. |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests that an add constraint can succeed. |
| | | * |
| | | * @throws Exception |
| | |
| | | AddListener listener = new AddListener(); |
| | | parent.addTestChildAddListener(listener); |
| | | |
| | | MockConstraint constraint = new MockConstraint(true, false, false); |
| | | MockConstraint constraint = new MockConstraint(true, false); |
| | | TestCfg.addConstraint(constraint); |
| | | |
| | | try { |
| | |
| | | AddListener listener = new AddListener(); |
| | | parent.addTestChildAddListener(listener); |
| | | |
| | | MockConstraint constraint = new MockConstraint(false, true, true); |
| | | MockConstraint constraint = new MockConstraint(false, true); |
| | | TestCfg.addConstraint(constraint); |
| | | |
| | | try { |
| | |
| | | DeleteListener listener = new DeleteListener(); |
| | | parent.addTestChildDeleteListener(listener); |
| | | |
| | | MockConstraint constraint = new MockConstraint(false, false, true); |
| | | MockConstraint constraint = new MockConstraint(false, true); |
| | | TestCfg.addConstraint(constraint); |
| | | |
| | | try { |
| | |
| | | DeleteListener listener = new DeleteListener(); |
| | | parent.addTestChildDeleteListener(listener); |
| | | |
| | | MockConstraint constraint = new MockConstraint(true, true, false); |
| | | MockConstraint constraint = new MockConstraint(true, false); |
| | | TestCfg.addConstraint(constraint); |
| | | |
| | | try { |
| | |
| | | public void testChangeConstraintSuccess() throws Exception { |
| | | TestParentCfg parent = getParent("test parent 1"); |
| | | |
| | | MockConstraint constraint = new MockConstraint(false, true, false); |
| | | TestCfg.addConstraint(constraint); |
| | | MockConstraint constraint = new MockConstraint(true, false); |
| | | |
| | | try { |
| | | // Add the entry. |
| | | TestCaseUtils.addEntry(TEST_CHILD_1); |
| | | TestChildCfg child = parent.getTestChild("test child 1"); |
| | | |
| | | TestCfg.addConstraint(constraint); |
| | | ChangeListener listener = new ChangeListener(); |
| | | child.addChangeListener(listener); |
| | | |
| | |
| | | @Test |
| | | public void testChangeConstraintFail() throws Exception { |
| | | TestParentCfg parent = getParent("test parent 1"); |
| | | |
| | | MockConstraint constraint = new MockConstraint(true, false, true); |
| | | TestCfg.addConstraint(constraint); |
| | | MockConstraint constraint = new MockConstraint(false, true); |
| | | |
| | | try { |
| | | // Add the entry. |
| | | TestCaseUtils.addEntry(TEST_CHILD_1); |
| | | TestChildCfg child = parent.getTestChild("test child 1"); |
| | | |
| | | TestCfg.addConstraint(constraint); |
| | | ChangeListener listener = new ChangeListener(); |
| | | child.addChangeListener(listener); |
| | | |