TestRegReadWritepublic class TestRegReadWrite extends com.sun.midp.i3test.TestCase Test RegistryStore functionality.
Test write and read of ContentHandlerImpl. |
Fields Summary |
---|
private static final int | suiteIdConstant application ID for testing. | private static final String | nameThe name of the GraphicalInstaller. | private static final String | IDTest ID. | private static final String | classnameThe class of the GraphicalInstaller. | private String[] | typesThe types registered. | private String[] | suffixesThe suffixes registered. | private String[] | actionsThe actions registered. | private String[] | enActionNamesThe english action names registered. | private String[] | frActionNamesThe french action names registered. | private String[] | actionmapsThe action name maps to verify. | private String[] | actionlocalesThe locale supported. | private String[] | accessRestrictedThe restricted access. | private String[] | ZERO_STRINGSA zero length array of strings. | private static final javax.microedition.content.ActionNameMap[] | ZERO_ACTIONNAMESEmpty ActionNameMap to return when needed. |
Methods Summary |
---|
void | assertEquals(java.lang.String msg, ContentHandlerImpl expected, ContentHandlerImpl actual)Compare two Content Handlers.
assertEquals("Verify storageId",
expected.storageId, actual.storageId);
assertEquals("Verify classname",
expected.classname, actual.classname);
assertEquals("Verify ID",
expected.ID, actual.ID);
// Verify the dynamic flag
assertTrue("Verify dynamic flag",
expected.registrationMethod == actual.registrationMethod);
| void | assertEquals(java.lang.String msg, java.lang.String[] expected, java.lang.String[] actual)Verify string arrays; asserting members are equals.
assertEquals(msg + " length", expected.length, actual.length);
int len = expected.length;
if (len > actual.length) {
len = actual.length;
}
for (int i = 0; i < len; i++) {
assertEquals(msg + "[" + i + "]", expected[i], actual[i]);
}
// Report errors for any extra actuals
for (int i = len; i < actual.length; i++) {
assertEquals(msg + "[" + i + "]", null, actual[i]);
}
// Report errors for any extra expected
for (int i = len; i < expected.length; i++) {
assertEquals(msg + "[" + i + "]", actual[i], null);
}
| void | assertEquals(java.lang.String msg, javax.microedition.content.ActionNameMap expected, javax.microedition.content.ActionNameMap actual)Verify that two ActionNameMaps are equal.
assertEquals("Verify locale",
expected.getLocale(), actual.getLocale());
int size = expected.size();
assertEquals(msg + " size ", size, actual.size());
if (size == actual.size()) {
for (int i = 0; i < size; i++) {
assertEquals(msg + " action ",
expected.getAction(i),
actual.getAction(i));
assertEquals(msg + " action name",
expected.getActionName(i),
actual.getActionName(i));
}
}
| ContentHandlerImpl | makeFull()Make a contenthandlerImpl with everything set.
ActionNameMap [] actionnames = new ActionNameMap[2];
actionnames[0] =
new ActionNameMap(actions, enActionNames, "en_US");
actionnames[1] =
new ActionNameMap(actions, frActionNames, "fr_CH");
ContentHandlerImpl ch = new ContentHandlerImpl(types, suffixes, actions,
actionnames, "ID-1",
accessRestricted,
"authority");
ch.storageId = 61000;
ch.appname = "Application Name";
ch.version = "1.1.1";
ch.classname = "classname";
ch.registrationMethod = ContentHandlerImpl.REGISTERED_STATIC;
return ch;
| public void | runTests()Run the tests.
test001();
| void | test001()Test that the built-in suite is registered.
boolean b;
ContentHandlerImpl[] chArr;
ContentHandlerImpl chTst;
String[] arr;
String caller = accessRestricted[0];
String badStr = "_";
declare("Verify the write and read of RegistryStore");
ContentHandlerImpl ch = new ContentHandlerImpl(ZERO_STRINGS,
ZERO_STRINGS,
ZERO_STRINGS,
ZERO_ACTIONNAMES,
null,
ZERO_STRINGS,
"");
assertNotNull("Verify handler created", ch);
b = RegistryStore.register(ch);
assertFalse("Verify empty handler is not registered", b);
ActionNameMap[] actionnames = new ActionNameMap[2];
actionnames[0] =
new ActionNameMap(actions, enActionNames, "en_US");
actionnames[1] =
new ActionNameMap(actions, frActionNames, "fr_CH");
ch = new ContentHandlerImpl(types, suffixes, actions, actionnames,
ID, accessRestricted, "authority");
ch.storageId = suiteId;
ch.classname = classname;
ch.appname = name;
// static boolean register(ContentHandlerImpl contentHandler) {
b = RegistryStore.register(ch);
assertTrue("Verify right handler is registered", b);
/**
* @param searchBy:
* <code>BY_TYPE</code>,
* <code>BY_SUFFIX</code>,
* <code>BY_ACTION</code>,
* <code>BY_ID</code>,
* <code>BY_ID_EXACT</code>
* <code>BY_SUITE</code>
*/
// static String[] findHandler(String callerId, int searchBy, String value)
chArr = RegistryStore.findHandler(caller, RegistryStore.FIELD_TYPES,
ch.getType(0));
if (chArr != null && chArr.length == 1) {
assertEquals("Verify handler ID after search by type",
ch.ID, chArr[0].ID);
} else {
fail("Verify search handler by type");
}
chArr = RegistryStore.findHandler(caller, RegistryStore.FIELD_TYPES,
badStr);
assertTrue("Verify empty search results by type",
chArr == null || chArr.length == 0);
// search by partial ID
chArr = RegistryStore.findHandler(caller, RegistryStore.FIELD_ID,
ch.ID + ch.ID.substring(0, 3));
if (chArr != null && chArr.length == 1) {
assertEquals("Verify handler ID after partial search", ch.ID, chArr[0].ID);
} else {
fail("Verify handler ID after search by cut ID");
}
// search by exact ID
chTst = RegistryStore.getHandler(caller, ch.ID, RegistryStore.SEARCH_EXACT);
if (chTst != null) {
assertEquals("Verify handler search by ID exact", ch.ID, chTst.ID);
} else {
fail("Verify handler search by ID exact");
}
// get values
arr = RegistryStore.getValues(caller, RegistryStore.FIELD_TYPES);
assertTrue("Verify getValues by type", arr != null && arr.length >= 2);
// testId
b = testId(ch.ID);
assertFalse("Verify test equal ID", b);
b = testId(ch.ID.substring(0, 3));
assertFalse("Verify test prefixed ID", b);
b = testId(ch.ID+"qqq");
assertFalse("Verify test prefixing ID", b);
b = testId("qqq"+ch.ID);
assertTrue("Verify test good ID", b);
// load handler
ContentHandlerImpl ch2 = RegistryStore.getHandler(null, ch.ID,
RegistryStore.SEARCH_EXACT);
assertNotNull("Verify loadHandler by ID", ch2);
// version and appname are not storable
if (ch2 != null) {
ch2.appname = ch.appname;
ch2.version = ch.version;
assertEquals("Verify loadHandler by ID", ch, ch2);
}
// unregister
b = RegistryStore.unregister(ch.ID);
assertTrue("Verify right handler is unregistered "+
"/CHECK: if JSR 211 database has the correct format!/", b);
| private boolean | testId(java.lang.String ID)
ContentHandlerImpl[] arr =
RegistryStore.findHandler(null, RegistryStore.FIELD_ID, ID);
return arr == null || arr.length == 0;
|
|