@Test(groups = "integration.ejb3")
public void testManuallyAddResource() throws Exception {
InventoryReport inventoryReport = new InventoryReport(agent);
Resource platform = new Resource(prefix("alpha"), prefix("platform"), platformType);
Resource server = new Resource(prefix("bravo"), prefix("server"), serverType);
platform.addChildResource(server);
Resource service2 = new Resource(prefix("delta"), prefix("service 2"), serviceType2);
server.addChildResource(service2);
platform.setUuid(String.valueOf(new Random().nextInt()));
server.setUuid(String.valueOf(new Random().nextInt()));
service2.setUuid(String.valueOf(new Random().nextInt()));
inventoryReport.addAddedRoot(platform);
MergeInventoryReportResults results = discoveryBoss.mergeInventoryReport(serialize(inventoryReport));
assert results != null;
assert checkIgnoredTypes(results) : "nothing should have been ignored in this test";
assertNotNull(results.getPlatformSyncInfo());
assertNotNull(results.getPlatformSyncInfo().getTopLevelServerIds());
assertTrue(!results.getPlatformSyncInfo().getTopLevelServerIds().isEmpty());
Integer resourceId = results.getPlatformSyncInfo().getTopLevelServerIds().iterator().next();
Collection<ResourceSyncInfo> syncInfos = discoveryBoss.getResourceSyncInfo(resourceId);
assert syncInfos != null;
assert !syncInfos.isEmpty();
Resource resource1 = discoveryBoss.manuallyAddResource(subjectManager.getOverlord(), serviceType2.getId(),
resourceId, new Configuration());
try {
Resource resource2 = discoveryBoss.manuallyAddResource(subjectManager.getOverlord(), serviceType2.getId(),
resourceId, new Configuration());
fail("Manually adding a singleton that already existed succeeded: " + resource2);
} catch (EJBException e) {
assertEquals(String.valueOf(e.getCause()), RuntimeException.class, e.getCause().getClass());
assertTrue(String.valueOf(e.getCause()), e.getCause().getMessage().contains("singleton"));