public void testQueryWithCustomIdPolicy() { setupCustomIdentifierPolicy("___", "PREFIX", "SUFFIX", "UpperCase"); Flight f1 = new Flight(); f1.setOrigin("BOS"); f1.setDest("MIA"); f1.setMe(2); f1.setYou(4); f1.setName("Harold"); f1.setFlightNumber(400); pm.makePersistent(f1); Flight f2 = new Flight(); f2.setOrigin("BOS"); f2.setDest("MIA"); f2.setMe(2); f2.setYou(4); f2.setName("Harold2"); f2.setFlightNumber(401); pm.makePersistent(f2); Query q = pm.newQuery( "select from " + Flight.class.getName() + " where flightNumber > 300 " + " order by flightNumber desc"); @SuppressWarnings("unchecked") List<Flight> result = (List<Flight>) q.execute(); assertEquals(2, result.size()); assertEquals(f2, result.get(0)); assertEquals(f1, result.get(1)); q = pm.newQuery( "select from " + Flight.class.getName() + " where name == \"Harold\" " + " order by name desc"); @SuppressWarnings("unchecked") List<Flight> result2 = (List<Flight>) q.execute(); assertEquals(1, result2.size()); assertEquals(f1, result2.get(0)); }
public void testInsertWithCustomIdPolicy() throws EntityNotFoundException { setupCustomIdentifierPolicy("___", "PREFIX", "SUFFIX", "UpperCase"); Flight f1 = new Flight(); f1.setOrigin("BOS"); f1.setDest("MIA"); f1.setMe(2); f1.setYou(4); f1.setName("Harold"); f1.setFlightNumber(400); pm.makePersistent(f1); Entity entity = ds.get(KeyFactory.stringToKey(f1.getId())); assertNotNull(entity); assertEquals( "PREFIX" + Flight.class.getSimpleName().toUpperCase() + "SUFFIX", entity.getKind()); assertEquals("Harold", entity.getProperty("NAME")); // column name isn't generated if explicitly set assertEquals(400L, entity.getProperty("flight_number")); }