@Test
 public void importCreatedShouldEmitSuccessfully() throws Exception {
   Owner owner = new Owner("Import guy");
   eventSinkImpl.emitImportCreated(owner);
   eventSinkImpl.sendEvents();
   verify(mockClientProducer).send(any(ClientMessage.class));
 }
 @Test
 public void rulesDeletedShouldEmitSuccessfully() throws Exception {
   Rules oldRules = new Rules(TestUtil.createRulesBlob(1));
   eventSinkImpl.emitRulesDeleted(oldRules);
   eventSinkImpl.sendEvents();
   verify(mockClientProducer).send(any(ClientMessage.class));
 }
 @Test
 public void emptyKeyShouldEmitSuccessfully() throws Exception {
   ActivationKey key = TestUtil.createActivationKey(new Owner("deadbeef"), null);
   eventSinkImpl.emitActivationKeyCreated(key);
   eventSinkImpl.sendEvents();
   verify(mockClientProducer).send(any(ClientMessage.class));
 }
 @Test
 public void exportCreatedShouldEmitSuccessfully() throws Exception {
   Consumer consumer = TestUtil.createConsumer();
   eventSinkImpl.emitExportCreated(consumer);
   eventSinkImpl.sendEvents();
   verify(mockClientProducer).send(any(ClientMessage.class));
 }
 @Test
 public void poolCreatedShouldEmitSuccessfully() throws Exception {
   Pool pool = TestUtil.createPool(o, TestUtil.createProduct(o));
   eventSinkImpl.emitPoolCreated(pool);
   eventSinkImpl.sendEvents();
   verify(mockClientProducer).send(any(ClientMessage.class));
 }
 @Test
 public void keyWithPoolsShouldEmitSuccessfully() throws Exception {
   ArrayList<Pool> pools = new ArrayList<Pool>();
   pools.add(TestUtil.createPool(o, TestUtil.createProduct(o)));
   pools.add(TestUtil.createPool(o, TestUtil.createProduct(o)));
   ActivationKey key = TestUtil.createActivationKey(new Owner("deadbeef"), pools);
   eventSinkImpl.emitActivationKeyCreated(key);
   eventSinkImpl.sendEvents();
   verify(mockClientProducer).send(any(ClientMessage.class));
 }
 @Test
 public void sendEventShouldSendMessageOnProperEventInput() throws Exception {
   final String content = "Simple String";
   doReturn(content).when(mapper).writeValueAsString(anyObject());
   ArgumentCaptor<ClientMessage> argumentCaptor = ArgumentCaptor.forClass(ClientMessage.class);
   eventSinkImpl.queueEvent(mock(Event.class));
   eventSinkImpl.sendEvents();
   verify(mockClientProducer).send(argumentCaptor.capture());
   assertEquals(content, argumentCaptor.getValue().getBodyBuffer().readString());
 }
  /**
   * @return
   * @throws Exception
   */
  private EventSinkImpl createEventSink(final ClientSessionFactory sessionFactory)
      throws Exception {
    EventSinkImpl sink =
        new EventSinkImpl(eventFilter, factory, mapper, new CandlepinCommonTestConfig()) {

          @Override
          protected ClientSessionFactory createClientSessionFactory() {
            return sessionFactory;
          }
        };
    sink.initialize();
    return sink;
  }
  @Test
  public void sendEventShouldNotFailWhenObjectMapperThrowsException() throws Exception {
    doThrow(new JsonGenerationException("Nothing serious!")).when(mapper).writeValueAsString(any());
    Event event = mock(Event.class);

    eventSinkImpl.queueEvent(event);
    verify(mockClientProducer, never()).send(any(ClientMessage.class));
  }
 @Test
 public void ownerCreatedShouldEmitSuccessfully() throws Exception {
   eventSinkImpl.emitOwnerCreated(o);
   eventSinkImpl.sendEvents();
   verify(mockClientProducer).send(any(ClientMessage.class));
 }