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();