Subject overlord = subjectManager.getOverlord();
Set<ResourcePackageDetails> installUs = new HashSet<ResourcePackageDetails>(2);
// Package 1, Version 2 with configuration values
PackageVersion packageVersion1 = package1.getVersions().get(0);
Configuration deploymentConfiguration1 = new Configuration();
deploymentConfiguration1.put(new PropertySimple("property1", "value1"));
PackageDetailsKey key1 = new PackageDetailsKey(package1.getName(), packageVersion1.getVersion(), package1
.getPackageType().getName(), packageVersion1.getArchitecture().getName());
ResourcePackageDetails packageDetails1 = new ResourcePackageDetails(key1);
packageDetails1.setDeploymentTimeConfiguration(deploymentConfiguration1);
installUs.add(packageDetails1);
// Package 2, Version 1 (intentionally older version) with no configuration values
PackageVersion packageVersion2 = package2.getVersions().get(0);
PackageDetailsKey key2 = new PackageDetailsKey(package2.getName(), packageVersion2.getVersion(), package2
.getPackageType().getName(), packageVersion2.getArchitecture().getName());
ResourcePackageDetails packageDetails2 = new ResourcePackageDetails(key2);
installUs.add(packageDetails2);
// Make sure the mock is configured to return a success
this.contentAgentService.setResponseReturnStatus(ContentResponseResult.SUCCESS);
this.contentAgentService.setThrowError(false);
this.contentAgentService.setReturnIndividualResponses(true);
String notes = "Test package deployment";
// Test --------------------------------------------
// Perform the deploy while locking the agent service. This allows us to check the state after the request
// is sent to the agent but before the agent has replied.
synchronized (responseLock) {
contentManager.deployPackages(overlord, resource1.getId(), installUs, notes);
// Check to see if the request and installed package were created and have the right status
getTransactionManager().begin();
try {
// Content request
Query query = em.createNamedQuery(ContentServiceRequest.QUERY_FIND_BY_RESOURCE);
query.setParameter("resourceId", resource1.getId());
List<?> results = query.getResultList();
assert results.size() == 1 : "Incorrect number of content service requests. Expected: 1, Found: "
+ results.size();
ContentServiceRequest request = (ContentServiceRequest) results.get(0);
assert request.getContentRequestType() == ContentRequestType.DEPLOY : "Request type incorrect. Expected: DEPLOY, Found: "
+ request.getContentRequestType();
assert request.getStatus() == ContentRequestStatus.IN_PROGRESS : "Request status incorrect. Expected: IN_PROGRESS, Found: "
+ request.getStatus();
assert request.getInstalledPackageHistory().size() == 2 : "Incorrect number of installed packages attached to request. Expected: 2, Found: "
+ request.getInstalledPackageHistory().size();
assert request.getNotes() != null : "Null notes found";
assert request.getNotes().equals(notes) : "Incorrect notes found: " + request.getNotes();
// Verify a history entry has been added for each package in the request
Set<InstalledPackageHistory> history = request.getInstalledPackageHistory();
assert history.size() == 2 : "Incorrect number of history entries on request. Expected: 2, Found: "
+ history.size();
for (InstalledPackageHistory historyEntry : history) {
assert historyEntry.getStatus() == InstalledPackageHistoryStatus.BEING_INSTALLED : "Incorrect state on history entity. Expected: BEING_INSTALLED, Found: "
+ historyEntry.getStatus();
}
// Ensure the installed package has not been added to the resource yet
// Package 1, Version 2
query = em.createNamedQuery(InstalledPackage.QUERY_FIND_BY_RESOURCE_ID_AND_PKG_VER_ID);
query.setParameter("resourceId", resource1.getId());
query.setParameter("packageVersionId", packageVersion1.getId());
results = query.getResultList();
assert results.size() == 0 : "Incorrect number of installed packages for package 1, version 2. Expected: 0, Found: "
+ results.size();
// Check status of audit trail
query = em.createNamedQuery(InstalledPackageHistory.QUERY_FIND_BY_CSR_ID_AND_PKG_VER_ID);
query.setParameter("contentServiceRequestId", request.getId());
query.setParameter("packageVersionId", packageVersion1.getId());
results = query.getResultList();
assert results.size() == 1 : "Incorrect number of audit trail entries. Expected: 1, Found: "
+ results.size();
InstalledPackageHistory historyEntity = (InstalledPackageHistory) results.get(0);
assert historyEntity.getStatus() == InstalledPackageHistoryStatus.BEING_INSTALLED : "Incorrect status on first entity. Expected: BEING_INSTALLED, Found: "
+ historyEntity.getStatus();
// Package 2, Version 1
query = em.createNamedQuery(InstalledPackage.QUERY_FIND_BY_RESOURCE_ID_AND_PKG_VER_ID);
query.setParameter("resourceId", resource1.getId());
query.setParameter("packageVersionId", packageVersion2.getId());
results = query.getResultList();
assert results.size() == 0 : "Incorrect number of installed packages for package 2, version 1. Expected: 0, Found: "
+ results.size();
// Check status of audit trail
query = em.createNamedQuery(InstalledPackageHistory.QUERY_FIND_BY_CSR_ID_AND_PKG_VER_ID);
query.setParameter("contentServiceRequestId", request.getId());
query.setParameter("packageVersionId", packageVersion2.getId());
results = query.getResultList();
assert results.size() == 1 : "Incorrect number of audit trail entries. Expected: 1, Found: "
+ results.size();
historyEntity = (InstalledPackageHistory) results.get(0);
assert historyEntity.getStatus() == InstalledPackageHistoryStatus.BEING_INSTALLED : "Incorrect status on second entity. Expected: BEING_INSTALLED, Found: "
+ historyEntity.getStatus();
} finally {
responseLock.notifyAll();
getTransactionManager().rollback();
}
}
// Verify --------------------------------------------
// Give the agent service a second to make sure it finishes out its call
Thread.sleep(1000);
getTransactionManager().begin();
try {
// Content request
Query query = em.createNamedQuery(ContentServiceRequest.QUERY_FIND_BY_RESOURCE);
query.setParameter("resourceId", resource1.getId());
List<?> results = query.getResultList();
assert results.size() == 1 : "Incorrect number of content service requests. Expected: 1, Found: "
+ results.size();
ContentServiceRequest request = (ContentServiceRequest) results.get(0);
assert request.getStatus() == ContentRequestStatus.SUCCESS : "Request status incorrect. Expected: SUCCESS, Found: "
+ request.getStatus();
// Verify a history entry has been added for the completion of the request per package
Set<InstalledPackageHistory> history = request.getInstalledPackageHistory();
assert history.size() == 4 : "Incorrect number of history entries on request. Expected: 4, Found: "
+ history.size();
// Check for Package 1
query = em.createNamedQuery(InstalledPackageHistory.QUERY_FIND_BY_CSR_ID_AND_PKG_VER_ID);
query.setParameter("contentServiceRequestId", request.getId());
query.setParameter("packageVersionId", packageVersion1.getId());
results = query.getResultList();
assert results.size() == 2 : "Incorrect number of history entries. Expected: 2, Found: " + results.size();
InstalledPackageHistory historyEntity = (InstalledPackageHistory) results.get(0);
assert historyEntity.getStatus() == InstalledPackageHistoryStatus.INSTALLED : "Incorrect status on first entity. Expected: INSTALLED, Found: "
+ historyEntity.getStatus();
historyEntity = (InstalledPackageHistory) results.get(1);
assert historyEntity.getStatus() == InstalledPackageHistoryStatus.BEING_INSTALLED : "Incorrect status on first entity. Expected: BEING_INSTALLED, Found: "
+ historyEntity.getStatus();
// Check for Package 2
query = em.createNamedQuery(InstalledPackageHistory.QUERY_FIND_BY_CSR_ID_AND_PKG_VER_ID);
query.setParameter("contentServiceRequestId", request.getId());
query.setParameter("packageVersionId", packageVersion2.getId());
results = query.getResultList();
assert results.size() == 2 : "Incorrect number of history entries. Expected: 2, Found: " + results.size();
historyEntity = (InstalledPackageHistory) results.get(0);
assert historyEntity.getStatus() == InstalledPackageHistoryStatus.INSTALLED : "Incorrect status on first entity. Expected: INSTALLED, Found: "
+ historyEntity.getStatus();
historyEntity = (InstalledPackageHistory) results.get(1);
assert historyEntity.getStatus() == InstalledPackageHistoryStatus.BEING_INSTALLED : "Incorrect status on first entity. Expected: BEING_INSTALLED, Found: "
+ historyEntity.getStatus();
// Add a few tests for the new Criteria Search feature
PackageVersionCriteria criteria = new PackageVersionCriteria();
criteria.addFilterResourceId(resource1.getId());
PageList<PackageVersion> pageList = contentManager.findPackageVersionsByCriteria(overlord, criteria);
assertNotNull(pageList);
ArrayList<PackageVersion> pvs = pageList.getValues();
assertEquals(2, pvs.size());
PackageVersion pv0 = pvs.get(0);
criteria.addFilterPackageTypeId(pv0.getGeneralPackage().getPackageType().getId());
pageList = contentManager.findPackageVersionsByCriteria(overlord, criteria);
assertNotNull(pageList);
pvs = pageList.getValues();
assertEquals(1, pvs.size());
assertEquals(pv0.getId(), pvs.get(0).getId());
// there is no repo assignment, any valid ID should eliminate all PVs
criteria.addFilterRepoId(38465);
pageList = contentManager.findPackageVersionsByCriteria(overlord, criteria);
assertNotNull(pageList);