protected void tearDown() { if (iSession != null) { try { iSession.destroySession(); } catch (StorageException se) { // No can do System.out.println("TearDown failed: " + se.toString()); } } }
/** * Test constructor with name and value. 2. Test with Name and Value. 3. Test Name null throws * StorageException 4. Test Name "" throws StorageException 5. Test value null. It is allowed * value. 6. Test value "". 7. Test one len name and value. 8. Test value null, type STRING is * allowed. */ public void testNameValueConstructor() { StorageAttribute sa = new StorageAttribute("N/A", "N/A"); // 2. Test with Name and Value try { String name = "AttrName"; String value = "AttrValue"; sa = new StorageAttribute(name, value); assertTrue(name.equals(sa.getName())); assertTrue(value.equals(sa.getValue())); // Default value is set if not defined. assertTrue(sa.getType() == StorageAttribute.STRING_TYPE); } catch (StorageException se) { assertTrue("Attribute creation failed: " + se.getMessage(), false); } // 3. Test null name try { String name = null; String value = "AttrValue"; sa = new StorageAttribute(name, value); assertTrue("Null name does not throw exception", false); } catch (StorageException se) { // PASSED } // 4. Test empty name try { String name = ""; String value = "AttrValue"; sa = new StorageAttribute(name, value); assertTrue("Empty name does not throw exception", false); } catch (StorageException se) { // PASSED } // 5. Test null value. try { String name = "AttrName"; String value = null; sa = new StorageAttribute(name, value); } catch (StorageException se) { assertTrue("SE thrown when null value: " + se.toString(), false); } catch (Throwable t) { assertTrue("Wrong exp thrown: " + t.toString(), false); } // 6. Test empty value try { String name = "AttrName"; String value = ""; sa = new StorageAttribute(name, value); assertTrue(name.equals(sa.getName())); assertTrue(sa.getValue() == ""); assertTrue(sa.getType() == StorageAttribute.STRING_TYPE); } catch (StorageException se) { assertTrue("Attribute creation failed: " + se.getMessage(), false); } // 7. Test one len arguments try { String name = "A"; String value = "V"; sa = new StorageAttribute(name, value); assertTrue(name.equals(sa.getName())); assertTrue(value.equals(sa.getValue())); // Default value is set if not defined. assertTrue(sa.getType() == StorageAttribute.STRING_TYPE); } catch (StorageException se) { assertTrue("Attribute creation failed: " + se.getMessage(), false); } // 8. Test value null, type STRING throws StorageException. try { String name = "A"; String value = null; sa = new StorageAttribute(name, value); } catch (StorageException se) { assertTrue("SE thrown when null value: " + se.toString(), false); } catch (Throwable t) { assertTrue("Wrong exception thrown: " + t.toString(), false); } }