@Test public void testGetPublicMethods() throws Exception { PojoRest model = new PojoRest(new AddressBook().init()); assertTrue(SimpleJsonSerializer.DEFAULT.toString(model.getPublicMethods("0")).contains("'toString'")); assertTrue(SimpleJsonSerializer.DEFAULT.toString(model.getPublicMethods("0/addresses/0/state")).contains("'toString'")); assertNull(model.getPublicMethods("1")); }
@Test public void testGetClassMeta() throws Exception { PojoRest model = new PojoRest(new AddressBook().init()); assertEquals("Person", model.getClassMeta("0").getInnerClass().getSimpleName()); assertEquals("String", model.getClassMeta("0/addresses/0/state").getInnerClass().getSimpleName()); assertNull(model.getClassMeta("1")); assertNull(model.getClassMeta("0/addresses/1/state")); } }
@Test public void testRootLocked() throws Exception { PojoRest model = new PojoRest(new AddressBook()).setRootLocked(); try { model.put("", new AddressBook()); fail(); } catch (PojoRestException e) { assertEquals("Cannot overwrite root object", e.getLocalizedMessage()); } try { model.put(null, new AddressBook()); fail(); } catch (PojoRestException e) { assertEquals("Cannot overwrite root object", e.getLocalizedMessage()); } try { model.put("/", new AddressBook()); fail(); } catch (PojoRestException e) { assertEquals("Cannot overwrite root object", e.getLocalizedMessage()); } }
@Test public void testInvokeMethod() throws Exception { PojoRest model = new PojoRest(new AddressBook().init()); assertEquals("Person(name=Bill Clinton,age=65)", model.invokeMethod("0", "toString", "")); model = new PojoRest(new AddressBook().init(), JsonParser.DEFAULT); assertEquals("Person(name=Bill Clinton,age=65)", model.invokeMethod("0", "toString", "")); assertEquals("NY", model.invokeMethod("0/addresses/0/state", "toString", "")); assertNull(model.invokeMethod("1", "toString", "")); }
@Test public void testGetRootObject() throws Exception { PojoRest model = new PojoRest(new AddressBook()); assertTrue(model.getRootObject() instanceof AddressBook); model.put("", "foobar"); assertTrue(model.getRootObject() instanceof String); model.put("", null); assertNull(model.getRootObject()); }
@Test public void testConstructors() throws Exception { PojoRest model = new PojoRest(new AddressBook(), JsonParser.DEFAULT); // Try adding a person to the address book. Person billClinton = new Person("Bill Clinton", 65, new Address("55W. 125th Street", "New York", "NY", 10027, true) ); model.post("/", billClinton); // Make sure we get the original person back. billClinton = (Person)model.get("/0"); }
@Test public void testAddressBook() { PojoRest model; model = new PojoRest(new AddressBook()); // Try adding a person to the address book. Person billClinton = new Person("Bill Clinton", 65, new Address("55W. 125th Street", "New York", "NY", 10027, true) ); model.post("/", billClinton); // Make sure we get the original person back. billClinton = (Person)model.get("/0"); }