public void setup() { APSDKSetup.setDBStoreType(DBStoreType.IN_MEMORY); com.anypresence.rails_droid.RemoteRailsConfig.DEBUG = true; if (context == null) { context = Robolectric.buildActivity(MyActivity.class).attach().create().get(); APSetup.setBaseUrl("http://localhost"); APSetup.setup(); Config.TEST_MODE = true; APSetup.setupOrm(context); } }
@BeforeClass public static void init() throws InterruptedException, RemoteRequestException { testLiveBackend = System.getProperty("testLiveBackend"); if (testLiveBackend == null) return; if (testLiveBackend != null && !testLiveBackend.equals("yes")) { return; } APSetup.setBaseUrl("http://localhost"); APSetup.setup(); Config.getInstance().setStrictQueryFieldCheck(false); // Login first before creating entities. AuthManagerFactory.getInstance() .authenticateUser( USERNAME, PASSWORD, new FutureCallback<String>() { @Override public void onSuccess(String result) { System.out.println("The user has been authenticated."); lock.countDown(); } @Override public void onFailure(Throwable err) { err.printStackTrace(); } }); // Wait for latch to be free before continuing as the authentication was done asynchronously. if (!lock.await(5000, TimeUnit.MILLISECONDS)) { Assert.fail( "Unable to run the tests because we can't authenticate. Please check the errors and make sure that the user " + USERNAME + " exists."); } List<com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote> objects = com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote .query("all"); if (!objects.isEmpty()) { Assert.fail("Unable to run test as there are data for CorporatePaymentsCrossBorderFxQuote."); } }
@Test public void shouldBeAbleDeleteFromCache() throws com.anypresence.sdk.acl.UnauthorizedException, RemoteRequestException, InterruptedException, ClassNotFoundException { APSetup.setBaseUrl("http://localhost"); APSetup.setup(); Config.getInstance().setStrictQueryFieldCheck(false); APSDKSetup.setDBStoreType(DBStoreType.IN_MEMORY); Config.DEBUG_MODE = true; RemoteRailsConfig.getInstance().setInlineMode(true); lock = new CountDownLatch(1); IRestClient client = getTestRestClient(); RestClientFactory.registerJSONRestClientImplementation(client); com.anypresence.sdk.citi_mobile_challenge.models.RetailBankingLogin.queryInBackground( "all", null, new APFutureCallback< List<com.anypresence.sdk.citi_mobile_challenge.models.RetailBankingLogin>>() { @Override public void finished( List<com.anypresence.sdk.citi_mobile_challenge.models.RetailBankingLogin> arg0, Throwable ex) { objects = arg0; lock.countDown(); } }); lock.await(); Assert.assertTrue(objects.size() == 2); // Delete one object in cache objects.get(0).deleteInCache(); Assert.assertTrue( com.anypresence.sdk.citi_mobile_challenge.models.RetailBankingLogin.loadAllInCache().size() == 1); // Delete all objects in the cache com.anypresence.sdk.APObject.deleteAllInCache(); Assert.assertTrue( com.anypresence.sdk.citi_mobile_challenge.models.RetailBankingLogin.loadAllInCache().size() == 0); }