@Test
  public void hypervisorCheckInUpdatesGuestIdsWhenHostConsumerExists() throws Exception {
    Owner owner = new Owner("admin");

    Map<String, List<GuestId>> hostGuestMap = new HashMap<String, List<GuestId>>();
    hostGuestMap.put("test-host", Arrays.asList(new GuestId("GUEST_B")));

    Owner o = new Owner();
    o.setId("owner-id");
    Consumer existing = new Consumer();
    existing.setUuid("test-host");
    existing.setOwner(o);
    existing.addGuestId(new GuestId("GUEST_A"));

    when(consumerCurator.findByUuid(eq("test-host"))).thenReturn(existing);

    HypervisorCheckInResult result =
        hypervisorResource.hypervisorCheckIn(hostGuestMap, principal, owner.getKey());
    Set<Consumer> updated = result.getUpdated();
    assertEquals(1, updated.size());

    Consumer c1 = updated.iterator().next();
    assertEquals("test-host", c1.getUuid());
    assertEquals(1, c1.getGuestIds().size());
    assertEquals("GUEST_B", c1.getGuestIds().get(0).getGuestId());
  }
  @Test
  public void testcheckForGuestsMigration() {
    ConsumerResource cr =
        Mockito.spy(
            new ConsumerResource(
                mockedConsumerCurator,
                null,
                null,
                null,
                null,
                null,
                null,
                i18n,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                new CandlepinCommonTestConfig(),
                null,
                null,
                null,
                null,
                productCurator,
                null));
    List<GuestId> startGuests = new ArrayList<GuestId>();
    List<GuestId> updatedGuests = new ArrayList<GuestId>();
    VirtConsumerMap guestConsumerMap = new VirtConsumerMap();
    Owner o = mock(Owner.class);
    Consumer host = new Consumer();

    Consumer cOne = new Consumer();
    cOne.setFact("virt.is_guest", "true");
    cOne.setFact("virt.uuid", cOne.getUuid() + "-vuuid");
    cOne.setOwner(o);
    GuestId one = new GuestId(cOne.getFact("virt.uuid"));
    startGuests.add(one);
    guestConsumerMap.add(cOne.getFact("virt.uuid"), cOne);

    Consumer cTwo = new Consumer();
    cTwo.setFact("virt.is_guest", "true");
    cTwo.setFact("virt.uuid", cTwo.getUuid() + "-vuuid");
    cTwo.setOwner(o);
    GuestId two = new GuestId(cTwo.getFact("virt.uuid"));
    startGuests.add(two);
    updatedGuests.add(two);
    guestConsumerMap.add(cTwo.getFact("virt.uuid"), cTwo);

    Consumer cThree = new Consumer();
    cThree.setFact("virt.is_guest", "true");
    cThree.setFact("virt.uuid", cThree.getUuid() + "-vuuid");
    cThree.setOwner(o);
    GuestId three = new GuestId(cThree.getFact("virt.uuid"));
    updatedGuests.add(three);
    guestConsumerMap.add(cThree.getFact("virt.uuid"), cThree);

    cr.checkForGuestsMigration(host, startGuests, updatedGuests, guestConsumerMap);
    verify(cr).checkForGuestMigration(host, cOne);
    verify(cr).checkForGuestMigration(host, cTwo);
    verify(cr).checkForGuestMigration(host, cThree);
  }