Example usage for javax.ejb EJBException getCause

List of usage examples for javax.ejb EJBException getCause

Introduction

In this page you can find the example usage for javax.ejb EJBException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.rhq.enterprise.server.discovery.DiscoveryBossBeanTest.java

@Test(groups = "integration.ejb3")
public void testIgnoreUnignoreAndImportResources() throws Exception {

    // First create an inventory report for a new platform with servers

    InventoryReport inventoryReport = new InventoryReport(agent);

    Resource platform = new Resource(prefix("platform"), prefix("platform"), platformType);
    platform.setUuid(String.valueOf(new Random().nextInt()));
    for (int i = 0; i < 17; i++) {
        String serverString = prefix("server " + String.valueOf(i));
        Resource server = new Resource(serverString, serverString, serverType);
        server.setUuid(String.valueOf(new Random().nextInt()));
        platform.addChildResource(server);
    }// w w  w.  j a v a2s  . c o  m

    inventoryReport.addAddedRoot(platform);

    // Merge this inventory report
    MergeInventoryReportResults mergeResults = discoveryBoss.mergeInventoryReport(serialize(inventoryReport));
    assert mergeResults != null;
    assert checkIgnoredTypes(mergeResults) : "nothing should have been ignored: "
            + mergeResults.getIgnoredResourceTypes();
    PlatformSyncInfo platformSyncInfo = mergeResults.getPlatformSyncInfo();
    assert platformSyncInfo != null;

    // Check merge result
    assertEquals(InventoryStatus.NEW, platformSyncInfo.getPlatform().getInventoryStatus());
    assertEquals(platform.getChildResources().size(), platformSyncInfo.getTopLevelServerIds().size());

    // Collect the resource ids generated for the platform and the servers

    int platformId = platformSyncInfo.getPlatform().getId();
    List<Integer> serverIds = new LinkedList<Integer>();
    for (Integer serverId : platformSyncInfo.getTopLevelServerIds()) {
        serverIds.add(serverId);
    }
    int[] arrayOfServerIds = ArrayUtils.unwrapCollection(serverIds);

    // Now test ignore, unignore and import behavior
    discoveryBoss.importResources(subjectManager.getOverlord(), new int[] { platformId });
    discoveryBoss.ignoreResources(subjectManager.getOverlord(), arrayOfServerIds);

    try {
        discoveryBoss.importResources(subjectManager.getOverlord(), arrayOfServerIds);
        fail("Import resources should fail for ignored resources");
    } catch (EJBException e) {
        assertEquals(String.valueOf(e.getCause()), IllegalArgumentException.class, e.getCause().getClass());
        assertTrue(String.valueOf(e.getCause()),
                e.getCause().getMessage().startsWith("Can only set inventory status to"));
    }

    discoveryBoss.unignoreAndImportResources(subjectManager.getOverlord(), arrayOfServerIds);

    // excursus: take this time to do a side test of the resource criteria filtering on parent inv status
    List<InventoryStatus> committedStatus = new ArrayList<InventoryStatus>(1);
    List<InventoryStatus> ignoredStatus = new ArrayList<InventoryStatus>(1);
    committedStatus.add(InventoryStatus.COMMITTED);
    ignoredStatus.add(InventoryStatus.IGNORED);
    ResourceCriteria criteria = new ResourceCriteria();
    criteria.addFilterParentInventoryStatuses(committedStatus);
    criteria.addFilterId(serverIds.get(0));

    // excursus: look for the server with the given ID but only if the parent is committed (this should return the resource)
    List<Resource> lookup = resourceManager.findResourcesByCriteria(subjectManager.getOverlord(), criteria);
    assert 1 == lookup.size() : lookup;
    assert lookup.get(0).getId() == serverIds.get(0) : lookup;

    // excursus: look for the server with the given ID but only if the parent is ignored (this should return nothing)
    criteria.addFilterParentInventoryStatuses(ignoredStatus);
    lookup = resourceManager.findResourcesByCriteria(subjectManager.getOverlord(), criteria);
    assert lookup.isEmpty() : lookup;
}

From source file:ru.codeinside.gses.manager.ManagerService.java

public Procedure createProcedure(String name, String description, String serviceId, Long code, String login,
        ProcedureType type) {//from   ww w .  j  a  v a  2 s .  c o m
    try {
        if (hasProcedureWithSameRegisterCode(code)) {
            throw new RuntimeException(
                    " ?    ??");
        }
        final Procedure procedure = new Procedure();
        mergeProcedure(procedure, name, description, serviceId, code, type);
        procedure.setCreator(em.find(Employee.class, login));
        em.persist(procedure);
        return procedure;
    } catch (EJBException e) {
        final String message;
        if (e.getMessage() != null) {
            message = e.getMessage();
        } else if (e.getCausedByException() != null) {
            message = e.getCausedByException().getMessage();
        } else {
            message = e.getCause() != null ? e.getCause().getMessage() : e.getClass().toString();
        }
        throw new RuntimeException(message);
    }
}