public void testEntityMetaDataWithUrl() throws Exception { final String entityKey = "testEntityMetaDataWithUrl" + Math.random(); Entity entity = Entity.newInstance(entityKey, "testAddEntity"); String url = "http://www.getsocialize.com"; JSONObject metaData = new JSONObject(); metaData.put("url", url); String jsonString = metaData.toString(); entity.setMetaData(jsonString); final CountDownLatch latch = new CountDownLatch(1); // Force no config ConfigUtils.getConfig(getContext()) .setProperty(SocializeConfig.SOCIALIZE_REQUIRE_AUTH, "false"); EntityUtils.saveEntity( TestUtils.getActivity(this), entity, new EntityAddListener() { @Override public void onError(SocializeException error) { error.printStackTrace(); addResult(0, error); latch.countDown(); } @Override public void onCreate(Entity entity) { addResult(0, entity); latch.countDown(); } }); latch.await(20, TimeUnit.SECONDS); Object result = getResult(0); assertNotNull(result); assertTrue("Result is not a entity object", (result instanceof Entity)); Entity entityAfter = (Entity) result; String metaDataAfter = entityAfter.getMetaData(); assertNotNull(metaDataAfter); JSONObject json = new JSONObject(metaDataAfter); String urlAfter = json.getString("url"); assertEquals(url, urlAfter); }
public void testAddEntity() throws Exception { final String entityKey = "testAddEntity" + Math.random(); Entity entity = Entity.newInstance(entityKey, "testAddEntity"); final CountDownLatch latch = new CountDownLatch(1); // Force no config ConfigUtils.getConfig(getContext()) .setProperty(SocializeConfig.SOCIALIZE_REQUIRE_AUTH, "false"); EntityUtils.saveEntity( TestUtils.getActivity(this), entity, new EntityAddListener() { @Override public void onError(SocializeException error) { error.printStackTrace(); addResult(0, error); latch.countDown(); } @Override public void onCreate(Entity entity) { addResult(0, entity); latch.countDown(); } }); latch.await(20, TimeUnit.SECONDS); Object result = getResult(0); assertNotNull(result); assertTrue("Result is not a entity object", (result instanceof Entity)); Entity entityAfter = (Entity) result; assertTrue("Entity ID is not greater than 0", entityAfter.getId() > 0); // Now use the normal UI to retrieve the entity clearResults(); final CountDownLatch latch2 = new CountDownLatch(1); EntityUtils.getEntity( TestUtils.getActivity(this), entityAfter.getId(), new EntityGetListener() { @Override public void onGet(Entity entity) { addResult(0, entity); latch2.countDown(); } @Override public void onError(SocializeException error) { error.printStackTrace(); latch2.countDown(); } }); latch2.await(20, TimeUnit.SECONDS); Entity after = getResult(0); assertNotNull(after); assertEquals(entityAfter.getId(), after.getId()); assertEquals(entityAfter.getKey(), after.getKey()); }