private Import getImportEntity(final EntityManager rootEm, final FileImport fileImport) { try { Results importJobResults = rootEm.getSourceEntities(fileImport, IMPORT_FILE_INCLUDES_CONNECTION, null, Level.ALL_PROPERTIES); List<Entity> importEntities = importJobResults.getEntities(); final Import importEntity = (Import) importEntities.get(0).toTypedEntity(); return importEntity; } catch (Exception e) { throw new RuntimeException("Unable to import entity"); } }
Identifier.fromUUID( UUID.fromString( identifierString ) ) ); if ( entity != null ) { user = ( User ) entity.toTypedEntity(); if (logger.isTraceEnabled()) { logger.trace("Found user {} as a UUID", identifierString); Entity entity = getUserEntityByIdentifier( applicationId, identifier ); if ( entity != null ) { user = ( User ) entity.toTypedEntity(); if (logger.isTraceEnabled()) { logger.trace("Found user {} as an {}", identifierString, identifier.getType());
user = ( User ) r.getEntity().toTypedEntity(); Map<String, Object> properties = new LinkedHashMap<String, Object>();
user = ( User ) r.getEntity().toTypedEntity(); Map<String, Object> properties = new LinkedHashMap<String, Object>();
Event event = ( Event ) entity.toTypedEntity(); for ( String prop_name : properties.keySet() ) { Object propertyValue = properties.get( prop_name );
@Ignore( "Pending https://issues.apache.org/jira/browse/USERGRID-1120. ") // needs to have elasticsearch refreshes implemented @Test public void testIncrementAndDecrement() throws Exception { logger.info( "CounterIT.testIncrementAndDecrement" ); EntityManager em = app.getEntityManager(); assertNotNull( em ); final UUID applicationId = em.getApplicationId(); Map<String, Long> counters = em.getEntityCounters( applicationId ); assertEquals( null, counters.get( "application.collection.users" ) ); UUID uuid = UUIDUtils.newTimeUUID(); // UUID.(); Map<String, Object> userProperties = new HashMap<String, Object>(); userProperties.put( "name", "test-name" ); userProperties.put( "username", "test-username" ); userProperties.put( "email", "test-email" ); User user = ( User ) em.create( uuid, "user", userProperties ).toTypedEntity(); logger.debug( "user={}", user ); em.refreshIndex(); counters = em.getEntityCounters( applicationId ); assertEquals( new Long( 1 ), counters.get( "application.collection.users" ) ); em.delete( user ); em.refreshIndex(); counters = em.getEntityCounters( applicationId ); assertEquals( new Long( 0 ), counters.get( "application.collection.users" ) ); }
@Ignore("Pending https://issues.apache.org/jira/browse/USERGRID-1113. Mock doesn't work") @Test public void goodAPNsCreation() throws Exception { app.clear(); app.put("provider", "apple"); app.put("environment", "development"); InputStream fis = getClass().getClassLoader().getResourceAsStream( "pushtest_dev_recent.p12"); byte[] certBytes = IOUtils.toByteArray(fis); app.put("p12Certificate", certBytes); fis.close(); Notifier notifier = (Notifier) app .testRequest(ServiceAction.POST, 1, false, new Object[] { "notifiers" }).getEntity() .toTypedEntity(); assertEquals(app.get("provider"), notifier.getProvider()); assertEquals(app.get("environment"), notifier.getEnvironment()); assertArrayEquals(notifier.getP12Certificate(), certBytes); }
notifier = (Notifier) app .testRequest(ServiceAction.PUT, 1, "notifiers", notifier.getUuid()).getEntity() .toTypedEntity();
@Test public void createGoogleNotifierWithBadAPIKey() throws Exception { final String badKey = API_KEY + "bad"; // create notifier with bad API key app.clear(); app.put("name", "gcm_bad_key"); app.put("provider", PROVIDER); app.put("environment", "development"); app.put("apiKey", badKey); try { notifier = (Notifier) app .testRequest(ServiceAction.POST, 1, "notifiers").getEntity() .toTypedEntity(); } catch (InvalidRequestException e) { assertEquals(Constants.ERROR_INVALID_REGISTRATION, e.getDescription()); } }
app.put("p12Certificate", certBytes); app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity().toTypedEntity(); String key = "gcm" + NOTIFIER_ID_POSTFIX; notification = (Notification)results.getEntitiesMap().get(notification.getUuid()).toTypedEntity(); assertEquals(0, notification.getDeviceProcessedCount()); assertNotNull(entity); notification = (Notification) entity.toTypedEntity(); checkReceipts(notification, 0);
@Test public void emptyPushNotification() throws Exception { app.clear(); app.put("name", "foo"); app.put("provider", PROVIDER); app.put("environment", "development"); app.put("apiKey", API_KEY); Notifier n = (Notifier) app .testRequest(ServiceAction.POST, 1, "notifiers").getEntity() .toTypedEntity(); app.clear(); String payload = "Hello, World!"; Map<String, String> payloads = new HashMap<String, String>(1); payloads.put("foo", payload); app.put("payloads", payloads); app.put("debug", true); app.put("queued", System.currentTimeMillis()); Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications") .getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); // perform push // notification = notificationWaitForComplete(notification); checkReceipts(notification, 0); }
setup.getEntityIndex().refresh(app.getId()); final Notification notification = (Notification) entity.toTypedEntity();
@Before public void before() throws Exception { // create gcm notifier // app.clear(); app.put("name", "gcm"); app.put("provider", PROVIDER); app.put("environment", "development"); app.put("apiKey", API_KEY); notifier = (Notifier) app .testRequest(ServiceAction.POST, 1, "notifiers").getEntity() .toTypedEntity(); String key = notifier.getName() + NOTIFIER_ID_POSTFIX; // create devices // app.clear(); app.put(key, PUSH_TOKEN); Entity e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity(); app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid()); device1 = app.getEntityManager().get(e.getUuid(), Device.class); assertEquals(device1.getProperty(key), PUSH_TOKEN); app.put(key, PUSH_TOKEN); e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity(); device2 = app.getEntityManager().get(e.getUuid(), Device.class); ns = getNotificationService(); listener = new QueueListener(ns.getServiceManagerFactory(), ns.getEntityManagerFactory(), new Properties()); listener.start(); }