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);
// Make sure the mock is configured to return a success
this.contentAgentService.setResponseReturnStatus(ContentResponseResult.SUCCESS);
this.contentAgentService.setThrowError(false);
this.contentAgentService.setReturnIndividualResponses(true);
this.contentAgentService.setDeployPackageSteps(stepResults);
String notes = "Test deploy notes";
// 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() == 1 : "Incorrect number of installed packages attached to request. Expected: 1, 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() == 1 : "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();
}
} 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() == 2 : "Incorrect number of history entries on request. Expected: 2, 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();