TestLandmarkStorepublic class TestLandmarkStore extends com.sun.midp.i3test.TestCase Tests for LandmarkStore implementation. |
Methods Summary |
---|
void | Test1()Body of the test 1.
This test creates and removes landmark stores
String[] listStores = null;
try {
listStores = LandmarkStore.listLandmarkStores();
assertTrue("No exceptions", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
if ((listStores != null) && (listStores.length > 0)) {
// remove all previous stores
for (int i = 0; i < listStores.length; i++) {
try {
LandmarkStore.deleteLandmarkStore(listStores[i]);
} catch (Throwable e) {
fail("" +e +" was caused");
}
}
}
// create and delete a new store
String testStoreName = "Name1";
try {
LandmarkStore.createLandmarkStore(testStoreName);
listStores = LandmarkStore.listLandmarkStores();
if (listStores != null) {
assertEquals("Wrong length of ListStores",
listStores.length, 1);
assertTrue("Wrong name was saved in ListStores",
listStores[0].equals(testStoreName));
} else { // Landmark store wasn't create
fail("Landmark store wasn't create");
}
// delete Landmark store
LandmarkStore.deleteLandmarkStore(listStores[0]);
// check the list
listStores = LandmarkStore.listLandmarkStores();
assertTrue("ListStores is not empty",
listStores == null);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// try to create a landmark store with null name
try {
LandmarkStore.createLandmarkStore(null);
fail("No exception was caused");
} catch (java.lang.NullPointerException e) {
assertTrue("NullPointerException was caused", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// try to create twice a landmark store with same name
try {
LandmarkStore.createLandmarkStore(testStoreName);
} catch (Throwable e) {
fail("" +e +" was caused");
}
try {
LandmarkStore.createLandmarkStore(testStoreName);
fail("No exception was caused");
} catch (java.lang.IllegalArgumentException e) {
assertTrue("IllegalArgumentException was caused", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// try to delete a landmark store with null name
try {
LandmarkStore.deleteLandmarkStore(null);
fail("No exception was caused");
} catch (java.lang.NullPointerException e) {
assertTrue("NullPointerException was caused", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// remove created landmark store
deleteLandStore(testStoreName);
| void | Test2()Body of the test 2.
Add and remove categories to landmark store
String landmarkStoreName = "StoreName";
String categoryName1 = "Category1";
String categoryName2 = "Category2";
LandmarkStore store = null;
// create a new landmark store
store = createLandStore(landmarkStoreName);
// Test the method "addCategory"
// Name of category is null - NullPointerException
try {
store.addCategory(null);
fail("No exception was caused");
} catch (java.lang.NullPointerException e) {
assertTrue("NullPointerException was caused", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// Category is already exsists - IllegalArgumentException
try {
store.addCategory(categoryName1);
assertTrue("OK", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
try {
store.addCategory(categoryName1);
fail("No exception was caused");
} catch (java.lang.IllegalArgumentException e) {
assertTrue("IllegalArgumentException was caused", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// Test the method "deleteCategory"
// Name of category is null - NullPointerException
try {
store.deleteCategory(null);
fail("No exception was caused");
} catch (java.lang.NullPointerException e) {
assertTrue("NullPointerException was caused", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// delete category
try {
store.deleteCategory(categoryName1);
assertTrue("OK", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// check the category list
Enumeration enumCat = null;
try {
enumCat = store.getCategories();
} catch (Throwable e) {
fail("" +e +" was caused");
}
// Category list should be empty
if (enumCat.hasMoreElements()) {
fail("Categories list is not empty");
} else { // OK
assertTrue("OK", true);
}
try {
store.addCategory(categoryName1);
store.addCategory(categoryName2);
} catch (Throwable e) {
fail("" +e +" was caused");
}
try {
enumCat = store.getCategories();
} catch (Throwable e) {
fail("" +e +" was caused");
}
// Category list should consists of 2 categories
try {
enumCat = store.getCategories();
if (!enumCat.hasMoreElements()) {
fail("Categories list is empty");
}
Object currName = enumCat.nextElement();
if (categoryName1.equals(currName)) {
assertTrue("OK", true);
} else {
fail("Wrong category name: \"" + (String)currName +
"\" on place \"" + categoryName1 + "\"");
}
if (!enumCat.hasMoreElements()) {
fail("Categories list is too small");
}
currName = enumCat.nextElement();
if (categoryName2.equals(currName)) {
assertTrue("OK", true);
} else {
fail("Wrong category name: \"" + (String)currName +
"\" on place \"" + categoryName2 + "\"");
}
} catch (Throwable e) {
fail("" +e +" was caused");
}
// delete all categories
try {
store.deleteCategory(categoryName1);
store.deleteCategory(categoryName2);
assertTrue("OK", true);
} catch (Throwable e) {
fail("Exception was caused");
}
// remove created landmark store
deleteLandStore(landmarkStoreName);
| void | Test3()Body of the test 3.
Add and remove landmarks to landmark store
String landmarkStoreName = "StoreName";
LandmarkStore store = null;
String categoryName1 = "Category1";
String categoryName2 = "Category2";
QualifiedCoordinates testCoord = new QualifiedCoordinates(
1, 2, 3f, 4f, 5f);
AddressInfo testAddr = new AddressInfo();
testAddr.setField(AddressInfo.EXTENSION, "EXTENSION");
testAddr.setField(AddressInfo.STREET, "STREET");
testAddr.setField(AddressInfo.POSTAL_CODE, "POSTAL_CODE");
testAddr.setField(AddressInfo.CITY, "CITY");
testAddr.setField(AddressInfo.COUNTY, "COUNTY");
testAddr.setField(AddressInfo.STATE, "STATE");
testAddr.setField(AddressInfo.COUNTRY, "COUNTRY");
testAddr.setField(AddressInfo.COUNTRY_CODE, "COUNTRY_CODE");
testAddr.setField(AddressInfo.DISTRICT, "DISTRICT");
testAddr.setField(AddressInfo.BUILDING_NAME, "BUILDING_NAME");
testAddr.setField(AddressInfo.BUILDING_FLOOR, "BUILDING_FLOOR");
testAddr.setField(AddressInfo.BUILDING_ROOM, "BUILDING_ROOM");
testAddr.setField(AddressInfo.BUILDING_ZONE, "BUILDING_ZONE");
testAddr.setField(AddressInfo.CROSSING1, "CROSSING1");
testAddr.setField(AddressInfo.CROSSING2, "CROSSING2");
testAddr.setField(AddressInfo.URL, "URL");
testAddr.setField(AddressInfo.PHONE_NUMBER, "PHONE_NUMBER");
Landmark testLandmark = new Landmark("Name", "testDescr",
testCoord, testAddr);
// create a new landmark store
store = createLandStore(landmarkStoreName);
addCategory(categoryName1, store);
// try to add a landmark with wrong category name
try {
// categoryName2 was not added to store
store.addLandmark(testLandmark, categoryName2);
fail("No exception was caused");
} catch (java.lang.IllegalArgumentException e) {
assertTrue("IllegalArgumentException was caused", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// try to add a null landmark
try {
store.addLandmark(null, categoryName1);
fail("No exception was caused");
} catch (java.lang.NullPointerException e) {
assertTrue("NullPointerException was caused", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// add a landmark
try {
store.addLandmark(testLandmark, categoryName1);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// get the list of landmarks
Enumeration enumLandmarks = null;
try {
enumLandmarks = store.getLandmarks();
} catch (Throwable e) {
fail("" +e +" was caused");
}
if ((enumLandmarks == null) ||
(!enumLandmarks.hasMoreElements())) { // no landmarks
fail("Landmarks enumeration is empty");
}
Landmark testLandmark1 = (Landmark)enumLandmarks.nextElement();
if ((testLandmark1 == null) || (enumLandmarks.hasMoreElements())) {
// wrong number of landmarks
fail("Landmarks enumeration contains wrong number of elements");
}
AddressInfo testAddr1 = testLandmark1.getAddressInfo();
if (!compareAddrInfo(testAddr, testAddr1)) {
fail("Address info wasn't stored correctly");
}
QualifiedCoordinates testCoord1 =
testLandmark1.getQualifiedCoordinates();
if (!compareQualiCoord(testCoord, testCoord1)) {
fail("Qualified coordinates weren't stored correctly");
}
if (!(testLandmark.getName().equals(testLandmark1.getName()))) {
fail("Landmark namewasn't stored correctly");
}
if (!(testLandmark.getName().equals(testLandmark1.getName()))) {
fail("Landmark name wasn't stored correctly");
}
if (!(testLandmark.getDescription().equals(
testLandmark1.getDescription()))) {
fail("Landmark description wasn't stored correctly");
}
// get landmarks by the category
try {
addCategory(categoryName2, store);
Landmark testLandmark2 = new Landmark("Name2", "testDescr2",
testCoord, testAddr);
store.addLandmark(testLandmark2, categoryName2);
enumLandmarks = store.getLandmarks(categoryName1, null);
if ((enumLandmarks == null) ||
(!enumLandmarks.hasMoreElements())) { // no landmarks
fail("Landmarks enumeration is empty");
}
if (!((Landmark)enumLandmarks.nextElement()).getName().
equals("Name")) {
fail("Category filter doesn't work");
}
enumLandmarks = store.getLandmarks(categoryName2, null);
if ((enumLandmarks == null) ||
(!enumLandmarks.hasMoreElements())) { // no landmarks
fail("Landmarks enumeration is empty");
}
if (!((Landmark)enumLandmarks.nextElement()).getName().
equals("Name2")) {
fail("Category filter doesn't work");
}
enumLandmarks = store.getLandmarks(null, "Name");
if ((enumLandmarks == null) ||
(!enumLandmarks.hasMoreElements())) { // no landmarks
fail("Landmarks enumeration is empty");
}
if (!((Landmark)enumLandmarks.nextElement()).getName().
equals("Name")) {
fail("Name filter doesn't work");
}
enumLandmarks = store.getLandmarks(null, "Name2");
if ((enumLandmarks == null) ||
(!enumLandmarks.hasMoreElements())) { // no landmarks
fail("Landmarks enumeration is empty");
}
if (!((Landmark)enumLandmarks.nextElement()).getName().
equals("Name2")) {
fail("Name filter doesn't work");
}
} catch (Throwable e) {
fail("" +e +" was caused");
}
// remove landmark from the category with null parameters
try {
store.removeLandmarkFromCategory(null, categoryName1);
fail("No exception was caused");
} catch (java.lang.NullPointerException e) {
assertTrue("NullPointerException was caused", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
try {
store.removeLandmarkFromCategory(testLandmark, null);
fail("No exception was caused");
} catch (java.lang.NullPointerException e) {
assertTrue("NullPointerException was caused", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// remove landmark from the category
try {
enumLandmarks = store.getLandmarks(categoryName1, null);
store.removeLandmarkFromCategory(
(Landmark)enumLandmarks.nextElement(),
categoryName1);
// should return null
enumLandmarks = store.getLandmarks(categoryName1, null);
if (!(enumLandmarks == null)) {
fail("Enumeration should be null");
}
} catch (Throwable e) {
fail("" +e +" was caused");
}
// update landmark with null parameter
try {
store.updateLandmark(null);
fail("No exception was caused");
} catch (java.lang.NullPointerException e) {
assertTrue("NullPointerException was caused", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// update landmark that is not belong to storage
Landmark testLandmark3 = new Landmark("Name3", "testDescr3",
testCoord, testAddr);
try {
store.updateLandmark(testLandmark3);
fail("No exception was caused");
} catch (LandmarkException e) {
assertTrue("LandmarkException was caused", true);
} catch (Throwable e) {
fail("" +e +" was caused");
}
// change landmark name and update landmark
try {
enumLandmarks = store.getLandmarks(null, "Name2");
testLandmark3 = (Landmark)enumLandmarks.nextElement();
testLandmark3.setName("Name3");
store.updateLandmark(testLandmark3);
enumLandmarks = store.getLandmarks(null, "Name3");
if (enumLandmarks == null) {
fail("Landmark name wasn't changed");
}
} catch (Throwable e) {
fail("" +e +" was caused");
}
// remove created landmark store
deleteLandStore(landmarkStoreName);
| private void | addCategory(java.lang.String category, javax.microedition.location.LandmarkStore store)Add a category to landmark store.
try {
store.addCategory(category);
} catch (Throwable e) {
fail("" +e +" was caused");
}
| private boolean | compareAddrInfo(javax.microedition.location.AddressInfo addr1, javax.microedition.location.AddressInfo addr2)Compare two adress info objects.
return
addr1.getField(AddressInfo.EXTENSION).equals(
addr2.getField(AddressInfo.EXTENSION)) &&
addr1.getField(AddressInfo.STREET).equals(
addr2.getField(AddressInfo.STREET)) &&
addr1.getField(AddressInfo.POSTAL_CODE).equals(
addr2.getField(AddressInfo.POSTAL_CODE)) &&
addr1.getField(AddressInfo.CITY).equals(
addr2.getField(AddressInfo.CITY)) &&
addr1.getField(AddressInfo.COUNTY).equals(
addr2.getField(AddressInfo.COUNTY)) &&
addr1.getField(AddressInfo.STATE).equals(
addr2.getField(AddressInfo.STATE)) &&
addr1.getField(AddressInfo.COUNTRY).equals(
addr2.getField(AddressInfo.COUNTRY)) &&
addr1.getField(AddressInfo.COUNTRY_CODE).equals(
addr2.getField(AddressInfo.COUNTRY_CODE)) &&
addr1.getField(AddressInfo.BUILDING_NAME).equals(
addr2.getField(AddressInfo.BUILDING_NAME)) &&
addr1.getField(AddressInfo.DISTRICT).equals(
addr2.getField(AddressInfo.DISTRICT)) &&
addr1.getField(AddressInfo.BUILDING_FLOOR).equals(
addr2.getField(AddressInfo.BUILDING_FLOOR)) &&
addr1.getField(AddressInfo.BUILDING_ROOM).equals(
addr2.getField(AddressInfo.BUILDING_ROOM)) &&
addr1.getField(AddressInfo.BUILDING_ZONE).equals(
addr2.getField(AddressInfo.BUILDING_ZONE)) &&
addr1.getField(AddressInfo.CROSSING1).equals(
addr2.getField(AddressInfo.CROSSING1)) &&
addr1.getField(AddressInfo.CROSSING2).equals(
addr2.getField(AddressInfo.CROSSING2)) &&
addr1.getField(AddressInfo.URL).equals(
addr2.getField(AddressInfo.URL)) &&
addr1.getField(AddressInfo.PHONE_NUMBER).equals(
addr2.getField(AddressInfo.PHONE_NUMBER));
| private boolean | compareQualiCoord(javax.microedition.location.QualifiedCoordinates qualifCoord1, javax.microedition.location.QualifiedCoordinates qualifCoord2)Compare two qualified coordinates objects.
return
(qualifCoord1.getHorizontalAccuracy() ==
qualifCoord2.getHorizontalAccuracy()) &&
(qualifCoord1.getVerticalAccuracy() ==
qualifCoord2.getVerticalAccuracy()) &&
(qualifCoord1.getLatitude() ==
qualifCoord2.getLatitude()) &&
(qualifCoord1.getLongitude() ==
qualifCoord2.getLongitude()) &&
(qualifCoord1.getAltitude() ==
qualifCoord2.getAltitude());
| private javax.microedition.location.LandmarkStore | createLandStore(java.lang.String name)Create the landmark store.
LandmarkStore store = null;
try {
LandmarkStore.createLandmarkStore(name);
store = LandmarkStore.getInstance(name);
} catch (Throwable e) {
fail("" +e +" was caused");
}
return store;
| private void | deleteCategory(java.lang.String category, javax.microedition.location.LandmarkStore store)Delete a category from landmark store.
try {
store.deleteCategory(category);
} catch (Throwable e) {
fail("" +e +" was caused");
}
| private void | deleteLandStore(java.lang.String name)Delete the landmark store.
LandmarkStore store = null;
try {
LandmarkStore.deleteLandmarkStore(name);
} catch (Throwable e) {
fail("" +e +" was caused");
}
| public void | runTests()Tests execute
declare("Create/delete landmark store");
Test1();
declare("Add/remove categories");
Test2();
declare("Add/remove landmarks");
Test3();
|
|