TransactionManager tx = getTransactionManager();
try {
tx.begin();
EntityManager entityManager = getEntityManager();
ContentManagerLocal contentManager = LookupUtil.getContentManager();
ContentSourceManagerLocal contentSourceManager = LookupUtil.getContentSourceManager();
RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
ResourceTypeManagerLocal resourceTypeManager = LookupUtil.getResourceTypeManager();
SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
Subject overlord = subjectManager.getOverlord();
// protect if it aleady exists due to a failed run
contentSourceType = contentSourceManager.getContentSourceType("testType");
if (null == contentSourceType) {
// Create a sample content source type that will be used in this test
contentSourceType = new ContentSourceType("testType");
entityManager.persist(contentSourceType);
entityManager.flush();
}
// protect if it aleady exists due to a failed run
ContentSource cs1 = contentSourceManager.getContentSourceByNameAndType(overlord, "contentSource1",
"testType");
if (null == cs1) {
// A repo sync will query all providers for that repo, so add multiple providers
cs1 = new ContentSource("contentSource1", contentSourceType);
cs1.setDownloadMode(DownloadMode.DATABASE);
cs1 = contentSourceManager.simpleCreateContentSource(overlord, cs1);
}
ContentSource cs2 = contentSourceManager.getContentSourceByNameAndType(overlord, "contentSource2",
"testType");
if (null == cs2) {
cs2 = new ContentSource("contentSource2", contentSourceType);
cs2.setDownloadMode(DownloadMode.DATABASE);
cs2 = contentSourceManager.simpleCreateContentSource(overlord, cs2);
}
pluginService.associateContentProvider(cs1, contentProvider1);
pluginService.associateContentProvider(cs2, contentProvider2);
repoContentSources.add(cs1);
repoContentSources.add(cs2);
// Create the package type packages will be created against
resourceType = resourceTypeManager.getResourceTypeByNameAndPlugin(TestContentProvider.RESOURCE_TYPE_NAME,
TestContentProvider.RESOURCE_TYPE_PLUGIN_NAME);
if (null == resourceType) {
resourceType = new ResourceType(TestContentProvider.RESOURCE_TYPE_NAME,
TestContentProvider.RESOURCE_TYPE_PLUGIN_NAME, ResourceCategory.PLATFORM, null);
entityManager.persist(resourceType);
entityManager.flush();
}
List<PackageType> packageTypes = contentManager.findPackageTypes(overlord,
TestContentProvider.RESOURCE_TYPE_NAME, TestContentProvider.RESOURCE_TYPE_PLUGIN_NAME);
if (!packageTypes.isEmpty()) {
packageType = packageTypes.get(0);
} else {
packageType = new PackageType(TestContentProvider.PACKAGE_TYPE_NAME, resourceType);