/*
* 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
*
*
* Copyright 2009-2010 Sun Microsystems, Inc.
* Portions Copyright 2010-2015 ForgeRock AS.
*/
/** This class tests various time-based matching rules. */
@SuppressWarnings("javadoc")
public final class TimeBasedMatchingRuleTest
extends SchemaTestCase
{
/** User DNs to be used in tests. */
/**
* Ensures that the Directory Server is running before executing the
* testcases.
*
* @throws Exception If an unexpected problem occurs.
*/
public void startServer()
throws Exception
{
/*
Extend the schema and add an attribute which is based on
generalizedTimeSyntax. Since all the existing attributes based
on that syntax are read-only, let us create a new attribute and
add it.*/
"dn: cn=schema",
"changetype: modify",
"add: attributeTypes",
"attributeTypes: ( test-time-oid NAME 'test-time' DESC 'Test time attribute' EQUALITY " +
"generalizedTimeMatch ORDERING generalizedTimeOrderingMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 SINGLE-VALUE )",
"attributeTypes: ( test-date-oid NAME 'test-date' DESC 'Test date attribute' EQUALITY " +
"generalizedTimeMatch ORDERING generalizedTimeOrderingMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 SINGLE-VALUE )",
"-",
"add: objectclasses",
"objectclasses: ( testoc-oid NAME 'testOC' SUP top AUXILIARY MUST test-time)",
"objectclasses: ( testoc2-oid NAME 'testOC2' SUP top AUXILIARY MUST test-date)"
);
}
{
return new Object[][] {
// relativeTime less than expired events
// relativeTime less than future events
{ TIME_ATTR + ":" + EXT_OMR_RELATIVE_TIME_LT_OID + ":=1d", new DN[] { user1, user2, user3, user5, } },
// relativeTime greater than expired events
// relativeTime greater than future events
};
}
{
}
{
{
{
{
}
}
}
return results;
}
/** Test to search using the relative time matching rule with index. */
{
}
{
{
}
return results;
}
/**
* Test to match the attribute and the assertion values using a partial date and time
* matching rule.
*/
public void testPartialDateNTimeMatch(long timeInMillis, String generalizedTime, String assertionValue)
throws Exception
{
}
public void testPartialDateNTimeMatchViaIndex(long timeInMillis, String generalizedTime, String assertionValue)
throws Exception
{
Set<ByteString> attrValues = fakeIndex.evaluateAssertionValue(assertValue, FilterType.EXTENSIBLE_MATCH);
}
/** Tests the assertion syntax of the relative time matching rules. */
{
try
{
// An invalid value can't get away without throwing exception.
}
catch (DecodeException e)
{
//invalid values will throw an exception.
}
}
/** Tests the assertion syntax of the partial date and time matching rules. */
{
try
{
}
catch (DecodeException e)
{
//invalid values will throw an exception.
}
}
/** Generates data for testing relative time matching rule assertion syntax. */
{
return new Object[][] {
{"1s",true},
{"1s0d",false},
{"-1d",true},
{"2h",true},
{"+2w",true},
{"0",true},
{"0s",true},
{"0d",true},
{"xyz",false},
{"12w-2d",false},
{"1s2s",false},
{"1d4s5d",false}
};
}
/** Generates the data for testing partial time date and time values. */
{
c.setLenient(false);
c.clear();
sdf.setCalendar(c);
long time1 = c.getTimeInMillis();
long time2 = c.getTimeInMillis();
return new Object[][] {
};
}
/** Generates data for testing partial date and time assertion syntax. */
{
//Get the current time.
cal.setLenient(false);
//Get the date today.
return new Object[][] {
{"20MM30DD1978YY",false},
{"02MM29DD2009YY",false},
{"02MM31DD2010YY",false},
{"-1s",false},
{"02M29D2008Y",true},
{"DDYY",false},
{"02D",true},
{"12M",true},
{"1978Y",true},
{"0MM",false},
{"20MM03DD10MM",false},
{"00s12m13h",true},
{"00s12m14h1M3D1978Y",true},
{"1s",true},
{"12m",true},
{"23h",true},
{"61s",false},
{"60m",false},
{"24h",false},
{second+"s",true},
{minute+"m",true},
{hour+"h",true},
{date+"D",true},
{month+"M",true},
{year+"Y",true},
};
}
{
// Get the current time from the TimeThread. Using the current time from new
// calendar may fail if the time thread using a stale time.
return TestCaseUtils.makeEntries(
"dn: cn=user1,dc=example,dc=com",
"objectclass: person",
"objectclass: testoc",
"cn: user1",
"sn: user1",
"",
"dn: cn=user2,dc=example,dc=com",
"objectclass: person",
"objectclass: testoc",
"cn: user2",
"sn: user2",
"",
"dn: cn=user3,dc=example,dc=com",
"objectclass: person",
"objectclass: testoc",
"cn: user3",
"sn: user3",
"",
"dn: cn=user4,dc=example,dc=com",
"objectclass: person",
"objectclass: testoc",
"cn: user4",
"sn: user4",
"",
"dn: cn=user5,dc=example,dc=com",
"objectclass: person",
"objectclass: testoc",
"cn: user5",
"sn: user5",
"",
"dn: cn=user6,dc=example,dc=com",
"objectclass: person",
"objectclass: testoc2",
"cn: user6",
"sn: user6",
"",
"dn: cn=user7,dc=example,dc=com",
"objectclass: person",
"objectclass: testoc2",
"cn: user7",
"sn: user7",
"",
"dn: cn=user8,dc=example,dc=com",
"objectclass: person",
"objectclass: testoc2",
"cn: user8",
"sn: user8",
);
}
}