@Test(enabled = TESTS_ENABLED) @SuppressWarnings("unchecked") public void synchronizeRepo() throws Exception { // Test // -------------------------------------------- boolean completed = pluginService.getContentProviderManager().synchronizeRepo(repoToSync.getId()); assert completed; // Verify // -------------------------------------------- // Make sure the proper calls were made into the provider assert contentProvider1.getLogSynchronizePackagesRepos().size() == 1 : "Expected: 1, Found: " + contentProvider1.getLogSynchronizePackagesRepos().size(); // Need to add in distro packages being syncced assert contentProvider1.getLogGetInputStreamLocations().size() == TestContentProvider.PACKAGE_COUNT_FOR_BITS : "Expected: " + TestContentProvider.PACKAGE_COUNT_FOR_BITS + ", Found: " + contentProvider1.getLogGetInputStreamLocations().size(); // Make sure all of the packages were added TransactionManager tx = getTransactionManager(); tx.begin(); EntityManager entityManager = getEntityManager(); Query query = entityManager.createNamedQuery(PackageVersion.QUERY_FIND_BY_REPO_ID); query.setParameter("repoId", repoToSync.getId()); List<PackageVersion> repoPackages = query.getResultList(); assert repoPackages.size() == TestContentProvider.PACKAGES.size() : "Expected: " + TestContentProvider.PACKAGES.size() + ", Found: " + repoPackages.size(); // Make sure all of the distributions were added query = entityManager.createNamedQuery(RepoDistribution.QUERY_FIND_BY_REPO_ID); query.setParameter("repoId", repoToSync.getId()); List<RepoDistribution> repoDistributions = query.getResultList(); assert repoDistributions.size() == TestContentProvider.DISTRIBUTIONS.size() : "Expected: " + TestContentProvider.DISTRIBUTIONS.size() + ", Found: " + repoDistributions.size(); // Make sure each distribution has the correct files associated int distro1FileCount = countDistroFiles(entityManager, TestContentProvider.DISTRIBUTION_1_LABEL); assert distro1FileCount == 2 : "Expected: 2, Found: " + distro1FileCount; int distro2FileCount = countDistroFiles(entityManager, TestContentProvider.DISTRIBUTION_2_LABEL); assert distro2FileCount == 1 : "Expected: 1, Found: " + distro1FileCount; tx.rollback(); }
@AfterMethod public void tearDownAfterMethod() throws Exception { try { TransactionManager tx = getTransactionManager(); tx.begin(); EntityManager entityManager = getEntityManager(); Query query; ContentSourceManagerLocal contentSourceManagerLocal = LookupUtil.getContentSourceManager(); RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal(); DistributionManagerLocal distroManager = LookupUtil.getDistributionManagerLocal(); SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager(); Subject overlord = subjectManager.getOverlord(); // Delete all distributions distroManager.deleteDistributionMappingsForRepo(overlord, repoToSync.getId()); for (String distroLabel : TestContentProvider.DISTRIBUTIONS.keySet()) { Distribution distro = distroManager.getDistributionByLabel(distroLabel); if (distro != null) { // Delete the files query = entityManager.createNamedQuery(DistributionFile.DELETE_BY_DIST_ID); query.setParameter("distId", distro.getId()); query.executeUpdate(); // Delete the actual distro distroManager.deleteDistributionByDistId(overlord, distro.getId()); } } // Delete all package version <-> content source mappings for (ContentSource source : repoContentSources) { contentSourceManagerLocal.deleteContentSource(overlord, source.getId()); } repoContentSources.clear(); // Delete the repo repoManager.deleteRepo(overlord, repoToSync.getId()); // Delete any packages that were created for (ContentProviderPackageDetails details : TestContentProvider.PACKAGES.values()) { String packageName = details.getContentProviderPackageDetailsKey().getName(); query = entityManager.createNamedQuery(Package.QUERY_FIND_BY_NAME_PKG_TYPE_ID); query.setParameter("name", packageName); query.setParameter("packageTypeId", packageType.getId()); Package p = (Package) query.getSingleResult(); entityManager.remove(p); } // Delete the package type packageType = entityManager.find(PackageType.class, packageType.getId()); entityManager.remove(packageType); resourceType = entityManager.find(ResourceType.class, resourceType.getId()); entityManager.remove(resourceType); // Delete the content source type contentSourceType = entityManager.find(ContentSourceType.class, contentSourceType.getId()); entityManager.remove(contentSourceType); tx.commit(); // Cleanup providers between tests contentProvider1.reset(); contentProvider2.reset(); } finally { // Plugin service teardown unprepareServerPluginService(); unprepareScheduler(); } }