GuestIdCurator extends AbstractHibernateCurator<GuestId> { public GuestId findByConsumerAndId(Consumer consumer, String guestId) { return (GuestId) this.currentSession().createCriteria(GuestId.class) .add(Restrictions.eq("consumer", consumer)) .add(Restrictions.eq("guestIdLower", guestId.toLowerCase())) .setMaxResults(1) .uniqueResult(); } GuestIdCurator(); CandlepinQuery<GuestId> listByConsumer(Consumer consumer); GuestId findByConsumerAndId(Consumer consumer, String guestId); GuestId findByGuestIdAndOrg(String guestUuid, String ownerId);  }
@Test public void findByConsumerAndIdDoesntExist() { Consumer consumer = new Consumer("testConsumer", "testUser", owner, ct); consumer.addGuestId(new GuestId("1")); consumerCurator.create(consumer); GuestId result = curator.findByConsumerAndId(consumer, "2"); assertNull(result); }
@Test public void findByConsumerAndIdOtherConsumer() { Consumer consumer = new Consumer("testConsumer", "testUser", owner, ct); consumer.addGuestId(new GuestId("1")); consumerCurator.create(consumer); Consumer other = new Consumer("testConsumer2", "testUser2", owner, ct); other.addGuestId(new GuestId("2")); consumerCurator.create(other); GuestId result = curator.findByConsumerAndId(consumer, "2"); assertNull(result); }
@Test public void findByConsumerAndId() { Consumer consumer = new Consumer("testConsumer", "testUser", owner, ct); consumer.addGuestId(new GuestId("1")); consumerCurator.create(consumer); GuestId result = curator.findByConsumerAndId(consumer, "1"); assertEquals(new GuestId("1"), result); }
@Test public void findByConsumerAndIdCaseInsensitive() { String guestId = "GuEsTiD"; Consumer consumer = new Consumer("testConsumer", "testUser", owner, ct); consumer.addGuestId(new GuestId(guestId)); consumerCurator.create(consumer); GuestId result = curator.findByConsumerAndId(consumer, guestId.toUpperCase()); assertEquals(new GuestId(guestId), result); }