@Test
  public void testRepositoryResolvedWhenVersionsMatch() throws Exception {
    String version = "2.4.0.0";

    Host host = createMock(Host.class);
    expect(host.getHostId()).andReturn(1L).anyTimes();

    expect(sch.getVersion()).andReturn(version);
    expect(sch.getHost()).andReturn(host).anyTimes();
    expect(componentInfo.isVersionAdvertised()).andReturn(true).once();

    RepositoryVersionDAO dao = createNiceMock(RepositoryVersionDAO.class);
    RepositoryVersionEntity entity = createNiceMock(RepositoryVersionEntity.class);
    expect(entity.getVersion()).andReturn(version).once();
    expect(entity.isResolved()).andReturn(false).once();

    // when the version gets reported back, we set this repo to resolved
    entity.setResolved(true);
    expectLastCall().once();

    expect(dao.findByPK(1L)).andReturn(entity).once();
    expect(dao.merge(entity)).andReturn(entity).once();

    replayAll();

    String newVersion = version;

    HostComponentVersionAdvertisedEvent event = new HostComponentVersionAdvertisedEvent(cluster, sch, newVersion, 1L);

    // !!! avoid injector for test class
    Field field = StackVersionListener.class.getDeclaredField("repositoryVersionDAO");
    field.setAccessible(true);
    field.set(listener, dao);

    listener.onAmbariEvent(event);

    verifyAll();
  }
Tests that if a component advertises a version and the repository already
matches, that we ensure that it is marked as resolved.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java