DurationPropertyDefinitionTest.java revision e0e6d30a905e47931a89b7e9063d752a6f28106d
/*
* 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 2008 Sun Microsystems, Inc.
*/
@SuppressWarnings("javadoc")
public class DurationPropertyDefinitionTest extends ConfigTestCase {
@Test
public void testCreateBuilder() {
}
/**
* Creates data for testing string-based limit values
*
* @return data
*/
Object[][] createLongLimitData() {
return new Object[][] {
{ 1L, 1L },
};
}
/**
* Creates data for testing limit values
*
* @return data
*/
Object[][] createIllegalLongLimitData() {
return new Object[][] {
// lower, upper, lower first
{ -1L, 0L, true },
{ 0L, -1L, false },
{ 2L, 1L, true },
{ 2L, 1L, false } };
}
Object[][] createStringLimitData() {
return new Object[][] {
// unit, limit, expected value
{ "ms", "123", 123 },
{ "ms", "123s", 123000 },
{ "s", "123", 123000 },
{ "s", "123s", 123000 },
{ "m", "10", 600000 },
{ "m", "10s", 10000 } };
}
}
}
}
if (isLowerFirst) {
} else {
}
}
@Test
public void testAllowUnlimitedIsTrue() {
builder.setAllowUnlimited(true);
}
public void testAllowUnlimitedIsFalse() {
builder.setAllowUnlimited(false);
}
public void testAllowUnlimitedIsFalseNumValue() {
builder.setAllowUnlimited(false);
}
Object[][] createValidateValueData() {
return new Object[][] {
// low in ms, high in ms, allow unlimited, value in seconds
{ 5000L, 10000L, false, 7L },
{ 5000L, 10000L, false, 5L },
{ 5000L, 10000L, false, 10L },
};
}
}
Object[][] createIllegalValidateValueData() {
return new Object[][] {
// low in ms, high in ms, allow unlimited, value in seconds
{ 5000L, 10000L, false, 1L },
{ 5000L, 10000L, false, 11L },
{ 5000L, 10000L, false, -1L } };
}
NullPointerException.class, PropertyException.class })
}
Object[][] createEncodeValueData() {
return new Object[][] {
{ -1L, "unlimited" },
{ 0L, "0 s" },
{ 1L, "1 s" },
{ 2L, "2 s" },
{ 999L, "999 s" },
{ 1000L, "1000 s" },
{ 1001L, "1001 s" },
{ 1023L, "1023 s" },
{ 1024L, "1024 s" },
{ 1025L, "1025 s" },
{ 1000L * 1000L, "1000000 s" },
};
}
builder.setAllowUnlimited(true);
}
/** Test that accept doesn't throw and exception */
@Test
public void testAccept() {
builder.setAllowUnlimited(true);
return true;
}
@SuppressWarnings("unused")
return false;
}
};
}
/** Make sure toString doesn't barf */
@Test
public void testToString() {
builder.setAllowUnlimited(true);
}
/** Make sure toString doesn't barf */
@Test
public void testToString2() {
}
@Test
public void testCompare() {
builder.setAllowUnlimited(true);
}
@Test
public void testSetDefaultBehaviorProvider() {
builder.setAllowUnlimited(true);
return null;
}
});
}
@Test
public void testSetPropertyOption() {
}
Object[][] createDecodeValueData() {
return new Object[][] {
// syntax tests
{ "unlimited", -1L },
{ "0h", 0L },
{ "0.0h", 0L },
{ "0.00h", 0L },
{ "0 h", 0L },
{ "0.00 h", 0L },
{ "1h", 1L },
{ "1 h", 1L },
{ "0ms", 0L },
{ "1h60m", 2L },
{ "1d10h", 34L },
{ "4d600m", 106L },
// conversion tests
{ "1 d", 24L }, { "2 d", 48L }, { "0.5 d", 12L } };
}
builder.setAllowUnlimited(true);
}
Object[][] createDecodeValueDataIllegal() {
{ "123" }, // no unit
{ "a s" },
{ "1 x" },
{ "0.h" },
{ "0. h" },
{ "1.h" },
{ "1. h" },
{ "1.1 h" }, // too granular
{ "30 m" }, // unit too small violation
{ "60 m" }, // unit too small violation
{ "1 w" }, // unit too big violation
{ "7 w" }, // unit too big violation
{ "1 x" }, { "1 d" }, // upper limit violation
{ "2 h" }, // lower limit violation
{ "-1 h" } // unlimited violation
};
}
builder.setAllowUnlimited(false);
}
}
private DurationPropertyDefinition buildTestDefinition(DurationPropertyDefinition.Builder builder) {
return builder.getInstance();
}
}