assert contentResource != null : "Could not load test-scheduler.properties as package content";
InputStream packageInputStream = contentResource.openStream();
// Test
CreateResourceHistory history1 = resourceFactoryManager.createResource(overlord, parentResource.getId(),
contentBackedChildResourceType.getId(), "newResource", null, packageName, packageVersion, architectureId,
deploymentTimeConfiguration, packageInputStream);
// Verify
try {
getTransactionManager().begin();
Resource parent = em.find(Resource.class, parentResource.getId());
List<CreateResourceHistory> historyList = parent.getCreateChildResourceRequests();
assert historyList.size() == 1 : "Incorrect number of children found. Expected: 1, Found: "
+ historyList.size();
CreateResourceHistory historyItem = historyList.get(0);
assert historyItem.getStatus() == CreateResourceStatus.SUCCESS : "Incorrect status for history item. Expected: Success, Found: "
+ historyItem.getStatus();
assert historyItem.getNewResourceKey().equals("mockResourceKey") : "Incorrect resource key for history item. Expected: mockResourceKey, Found: "
+ historyItem.getNewResourceKey();
assert historyItem.getErrorMessage() == null : "Error message found for successful call";
} finally {
getTransactionManager().rollback();
}
// Invoke the same callbacks the plugin container would to actually commit the new Resource to inventory.
resourceFactoryManager.completeCreateResource(new CreateResourceResponse(history1.getId(), "newResource",
"key", CreateResourceStatus.SUCCESS, null, new Configuration()));
Resource resource = new Resource(2000000);
resource.setUuid(UUID.randomUUID().toString());
resource.setResourceType(contentBackedChildResourceType);
long randomLong = UUID.randomUUID().getLeastSignificantBits();
resource.setResourceKey(String.valueOf("key-" + randomLong));
resource.setName("name-" + randomLong);
resource.setParentResource(parentResource);
discoveryBoss.addResource(resource, overlord.getId());
// Now try to create another Resource of the same singleton type - this should fail.
try {
CreateResourceHistory history2 = resourceFactoryManager.createResource(overlord, parentResource.getId(),
contentBackedChildResourceType.getId(), "newResource2", null, packageName, packageVersion,
architectureId, deploymentTimeConfiguration, packageInputStream);
fail("Creating a singleton that already existed succeeded: " + history2);
} catch (EJBException e) {
assertEquals(String.valueOf(e.getCause()), RuntimeException.class, e.getCause().getClass());