@Test public void shouldBeAbletoQueryForExactMatch() throws UnauthorizedException, RemoteRequestException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { if (testLiveBackend == null) return; if (testLiveBackend != null && !testLiveBackend.equals("yes")) { return; } Map<String, String> params = new HashMap<String, String>(); com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote obj = new com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote(); obj.save(); obj.reload(); params.put("requested_on", obj.getRequestedOn().toString()); createdObjects = new ArrayList< com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote>(); createdObjects.add(obj); List<com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote> objects = com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote .query("exact_match", params, null, null); Assert.assertEquals(1, objects.size()); }
@Test public void shouldBeAbletoQueryForAll() throws UnauthorizedException, RemoteRequestException { if (testLiveBackend == null) return; if (testLiveBackend != null && !testLiveBackend.equals("yes")) { return; } createdObjects = new ArrayList< com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote>(); // Create some entities. for (int i = 0; i < MAX_ENTITIES; i++) { com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote obj = new com.anypresence.sdk.citi_mobile_challenge.models .CorporatePaymentsCrossBorderFxQuote(); obj.save(); createdObjects.add(obj); } List<com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote> objects = com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote .query("all"); Assert.assertTrue(objects.size() >= MAX_ENTITIES); // Test limiting result. objects = com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote.query( "all", null, 0, 2); Assert.assertEquals(2, objects.size()); }
@After public void cleanUp() throws RemoteRequestException { if (createdObjects == null) return; for (com.anypresence.sdk.citi_mobile_challenge.models.CorporatePaymentsCrossBorderFxQuote category : createdObjects) { category.delete(); } }
@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."); } }