/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Portions Copyright 2012-2015 ForgeRock AS
*/
/**
* A set of test cases for the entity tag virtual attribute provider.
*/
{
private boolean changeListenerRemoved;
private boolean changeListenerAdded;
{
public void addChangeListener(
{
// Should not be called.
throw new IllegalStateException();
}
public void addEntityTagChangeListener(
{
changeListenerAdded = true;
}
{
// Not needed.
return null;
}
{
// Not needed.
return null;
}
public AttributeType getAttributeType()
{
// Not needed.
return null;
}
{
// Not needed.
return null;
}
public ChecksumAlgorithm getChecksumAlgorithm()
{
return ChecksumAlgorithm.ADLER_32;
}
public ConflictBehavior getConflictBehavior()
{
// Not needed.
return null;
}
{
return excludedAttributes;
}
{
// Not needed.
return null;
}
{
// Not needed.
return null;
}
public String getJavaClass()
{
// Not needed.
return null;
}
{
// Not needed.
return null;
}
public boolean isEnabled()
{
return true;
}
public void removeChangeListener(
{
// Should not be called.
throw new IllegalStateException();
}
public void removeEntityTagChangeListener(
{
changeListenerRemoved = true;
}
};
/**
* Ensures that the Directory Server is running.
*
* @throws Exception
* If an unexpected problem occurs.
*/
{
// Initialize the provider.
}
/**
* Tests that approximate matching is not supported.
*/
@Test
public void testApproximatelyEqualTo()
{
}
/**
* Tests that finalization removes the change listener.
*/
@Test
public void testFinalizeVirtualAttributeProvider()
{
}
/**
* Tests the getValues method returns an ETag whose value represents a 64-bit
* non-zero long encoded as hex.
*
* @throws Exception
* If an unexpected exception occurred.
*/
@Test
{
"objectClass: top", "objectClass: domain", "dc: example");
getEntityTag(e, getRule());
}
/**
* Tests the getValues method returns a different value for entries which are
* different.
*
* @throws Exception
* If an unexpected exception occurred.
*/
@Test
{
"objectClass: top", "objectClass: domain", "dc: example1");
"objectClass: top", "objectClass: domain", "dc: example2");
}
/**
* Tests the getValues method ignores excluded attributes.
*
* @throws Exception
* If an unexpected exception occurred.
*/
@Test
{
"objectClass: top", "objectClass: domain", "dc: example");
"objectClass: top", "objectClass: domain", "dc: example",
"modifyTimestamp: 20120222232918Z");
}
/**
* Tests the getValues method returns the same value for entries having the
* same content but with attributes in a different order.
*
* @throws Exception
* If an unexpected exception occurred.
*/
@Test
{
"objectClass: top", "objectClass: domain", "description: one",
"description: two", "dc: example");
"objectClass: top", "objectClass: domain", "dc: example",
"description: two", "description: one");
}
/**
* Tests the getValues method returns the same value for different instances
* of the same entry.
*
* @throws Exception
* If an unexpected exception occurred.
*/
@Test
{
"objectClass: top", "objectClass: domain", "dc: example");
"objectClass: top", "objectClass: domain", "dc: example");
}
/**
* Tests that ordering matching is not supported.
*/
@Test
public void testGreaterThanOrEqualTo()
{
}
/**
* Tests hasAllValues() membership.
*
* @throws Exception
* If an unexpected exception occurred.
*/
@Test
{
"objectClass: top", "objectClass: domain", "dc: example");
}
/**
* Tests that the etags are always present.
*/
@Test
public void testHasValue1()
{
}
/**
* Tests testHasValue membership.
*
* @throws Exception
* If an unexpected exception occurred.
*/
@Test
{
"objectClass: top", "objectClass: domain", "dc: example");
}
/**
* Tests that initialization adds the change listener.
*/
@Test
public void testInitializeVirtualAttributeProvider()
{
// This was actually done during initialization of this test. Check that the
// listener was registered.
}
/**
* Tests that isConfigurationAcceptable always returns true.
*/
@Test
public void testIsConfigurationAcceptable()
{
}
/**
* Tests that the etags are single-valued.
*/
@Test
public void testIsMultiValued()
{
}
/**
* Tests that searching based on etag filters is not supported.
*/
@Test
public void testIsSearchable()
{
}
/**
* Tests that ordering matching is not supported.
*/
@Test
public void testLessThanOrEqualTo()
{
}
/**
* Tests that substring matching is not supported.
*/
@Test
public void testMatchesSubstring()
{
}
/**
* Tests that searching based on etag filters is not supported.
*/
@Test
public void testProcessSearch()
{
final ArgumentCaptor<LocalizableMessage> errorMsg = ArgumentCaptor.forClass(LocalizableMessage.class);
}
/**
* Simulates the main use case for entity tag support: optimistic concurrency.
* <p>
* This test reads an entry requesting its etag, then performs an update using
* an assertion control to prevent the change from being applied if the etag
* has changed since the read was performed.
*
* @throws Exception
* If an unexpected exception occurred.
*/
@Test
{
// Use an internal connection.
// Create a test backend containing the user entry to be modified.
// @formatter:off
"dn: ou=People,o=test",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: People",
"",
"dn: uid=test.user,ou=People,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User",
"userPassword: password");
// @formatter:on
// Read the user entry and get the etag.
// Apply a change using the assertion control for optimistic concurrency.
Control c = new LDAPAssertionRequestControl(true, LDAPFilter.createEqualityFilter(ETAG, ByteString.valueOfUtf8(etag1)));
// Reread the entry and check that the description has been added and that
// the etag has changed.
// Simulate a concurrent update: perform another update using the old etag.
// Reread the entry and check that the description and etag have not changed
}
/**
* Tests that the etag returned with a pre-read control after a modify
* operation is correct. See OPENDJ-861.
*
* @throws Exception
* If an unexpected exception occurred.
*/
@Test
{
// Create a test backend containing the user entry to be modified.
// @formatter:off
"dn: ou=People,o=test",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: People",
"",
"dn: uid=test.user,ou=People,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User",
"userPassword: password",
"description: initial value");
// @formatter:on
// Read the user entry and get the etag.
// Apply a change using the pre and post read controls.
List<Control> ctrls = singletonList((Control) new LDAPPreReadRequestControl(true, singleton(ETAG)));
// Reread the entry and check that the description has been added and that
// the etag has changed.
// Now check that the pre-read is the same as the initial etag.
}
/**
* Tests that the etag returned with a post-read control after a modify
* operation is correct. See OPENDJ-861.
*
* @throws Exception
* If an unexpected exception occurred.
*/
@Test
{
// Create a test backend containing the user entry to be modified.
// @formatter:off
"dn: ou=People,o=test",
"objectClass: top",
"objectClass: organizationalUnit",
"ou: People",
"",
"dn: uid=test.user,ou=People,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User",
"userPassword: password",
"description: initial value");
// @formatter:on
// Read the user entry and get the etag.
// Apply a change using the pre and post read controls.
List<Control> ctrls = singletonList((Control) new LDAPPostReadRequestControl(true, singleton(ETAG)));
// Reread the entry and check that the description has been added and that
// the etag has changed.
// Now check that the post-read is the same as the initial etag.
}
{
{
if (control instanceof LDAPPostReadResponseControl)
{
return (LDAPPostReadResponseControl) control;
}
}
fail("Expected the ModifyOperation to have a LDAPPostReadResponseControl");
return null;
}
{
{
if (control instanceof LDAPPreReadResponseControl)
{
return (LDAPPreReadResponseControl) control;
}
}
fail("Expected the ModifyOperation to have a LDAPPreReadResponseControl");
return null;
}
{
SearchRequest request = Requests.newSearchRequest(userDN, SearchScope.BASE_OBJECT).addAttribute("*", ETAG);
assertNotNull(e);
return e;
}
{
for (int i = 0; i < 16; i++)
{
{
return value;
}
}
fail("Expected to find a non zero byte");
return null;
}
{
}
}