@Test
  public void testPopulateServicePackagesInfo() throws Exception {
    Capture<AmbariManagementController> controllerCapture = EasyMock.newCapture();
    Injector injector = createStrictMock(Injector.class);
    MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class);

    ServiceInfo serviceInfo = createNiceMock(ServiceInfo.class);
    Map<String, String> hostParams = new HashMap<>();
    String osFamily = "testOSFamily";

    Map<String, ServiceOsSpecific> osSpecifics = new HashMap<>();

    ServiceOsSpecific.Package package1 = new ServiceOsSpecific.Package();
    package1.setName("testrpm1");
    ServiceOsSpecific.Package package2 = new ServiceOsSpecific.Package();
    package2.setName("testrpm2");
    ServiceOsSpecific.Package package3 = new ServiceOsSpecific.Package();
    package3.setName("testrpm3");

    List<ServiceOsSpecific.Package> packageList1 = new ArrayList<>();
    packageList1.add(package1);
    List<ServiceOsSpecific.Package> packageList2 = new ArrayList<>();
    packageList2.add(package2);
    packageList2.add(package3);

    ServiceOsSpecific osSpecific1 = new ServiceOsSpecific("testOSFamily");
    osSpecific1.addPackages(packageList1);
    ServiceOsSpecific osSpecific2 = new ServiceOsSpecific("testOSFamily1,testOSFamily,testOSFamily2");
    osSpecific2.addPackages(packageList2);

    osSpecifics.put("testOSFamily", osSpecific1);
    osSpecifics.put("testOSFamily1,testOSFamily,testOSFamily2", osSpecific2);

    expect(serviceInfo.getOsSpecifics()).andReturn(osSpecifics);
    constructorInit(injector, controllerCapture, null, maintHelper, createNiceMock(KerberosHelper.class),
        null, null);

    OsFamily osFamilyMock = createNiceMock(OsFamily.class);

    EasyMock.expect(osFamilyMock.isVersionedOsFamilyExtendedByVersionedFamily("testOSFamily", "testOSFamily")).andReturn(true).times(3);
    replay(maintHelper, injector, clusters, serviceInfo, osFamilyMock);

    AmbariManagementControllerImplTest.NestedTestClass nestedTestClass = this.new NestedTestClass(null, clusters,
        injector, osFamilyMock);

    ServiceOsSpecific serviceOsSpecific = nestedTestClass.populateServicePackagesInfo(serviceInfo, hostParams, osFamily);

    assertEquals(3, serviceOsSpecific.getPackages().size());
  }
Ensure that RollbackException is thrown outside the updateClusters method
when a unique constraint violation occurs.
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java