类javax.ejb.EJBException源码实例Demo

下面列出了怎么用javax.ejb.EJBException的API类实例代码及写法,或者点击链接到github查看源代码。

@Test(expected = EJBAccessException.class)
public void getRevenueShareData_invalidRoleTechnologyManager()
        throws Exception {
    // given no revenue share result entries. Login with invalid user role
    container.login(brokerUser.getKey(), ROLE_TECHNOLOGY_MANAGER);

    // when
    try {
        bs.getRevenueShareData(Long.valueOf(PERIOD_START_MONTH1),
                Long.valueOf(PERIOD_END_MONTH1),
                BillingSharesResultType.BROKER);
        fail();
    } catch (EJBException e) {
        throw (EJBAccessException) e.getCause();
    }
}
 
@Test
public void createMarketingProductForExternal() throws Exception {
    VOTechnicalService tp = createTechnicalProduct(svcProv);
    svcProv.deleteTechnicalService(tp);
    tp.setAccessType(ServiceAccessType.EXTERNAL);
    tp.setKey(0);
    tp = svcProv.createTechnicalService(tp);
    VOServiceDetails product = new VOServiceDetails();
    product.setServiceId("test");
    OrganizationReference ref = createOrgRef(provider.getKey());
    createMarketingPermission(tp.getKey(), ref.getKey());
    try {
        VOServiceDetails svc = svcProv.createService(tp, product, null);
        validateCopiedProductPaymentConfiguration(svc.getKey(),
                ENABLED_PAYMENTTYPES);

        // is price model created and not chargeable?
        assertFalse(svc.getPriceModel().isChargeable());
        assertTrue(svc.getPriceModel().getKey() > 0L);
    } catch (EJBException e) {
        throw e.getCausedByException();
    }
}
 
源代码3 项目: development   文件: MarketplaceToOrganizationIT.java
@Test(expected = NonUniqueBusinessKeyException.class)
public void testAdd_Duplicate() throws Exception {
    try {
        runTX(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                doTestAdd();
                return null;
            }
        });
        runTX(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                doTestAdd();
                return null;
            }
        });
    } catch (EJBException e) {
        throw e.getCausedByException();
    }
}
 
@Test
public void getBrokerOrganizations_asReseller() throws Exception {
    // given
    container.login(givenReseller().getKey(),
            UserRoleType.RESELLER_MANAGER.name());

    try {
        // when
        publishService.getBrokers(0L);
        fail();
    } catch (EJBException e) {

        // then
        assertTrue(e.getCausedByException() instanceof EJBAccessException);
    }
}
 
@Test(expected = ValidationException.class)
public void publishService_MultipleGlobalMPs() throws Exception {
    // currently, each service instance can only be published to exactly one
    // MP; this might change in the future
    container.login(supplier1Key, ROLE_SERVICE_MANAGER);
    final Marketplace mpglobal2 = runTX(new Callable<Marketplace>() {
        @Override
        public Marketplace call() throws Exception {
            return Marketplaces.createMarketplace(mpOwner, "GLOBAL_MP2",
                    false, mgr);
        }
    });

    VOCatalogEntry voCESvc1_3 = createCatalogEntry(p1_1.getKey(), mpglobal2);

    try {
        marketplaceService.publishService(new VOService(),
                Arrays.asList(voCESvc1_2, voCESvc1_3));
    } catch (EJBException e) {
        throw e.getCausedByException();
    }
}
 
@Test(expected = SaaSSystemException.class)
public void testCreateMarketingProductImageTypeInvalid() throws Exception {
    VOTechnicalService tp = createTechnicalProduct(svcProv);
    VOServiceDetails product = new VOServiceDetails();
    product.setServiceId("test");
    VOImageResource imageResource = new VOImageResource();
    byte[] content = BaseAdmUmTest.getFileAsByteArray(
            ServiceProvisioningServiceBeanIT.class, "icon1.png");
    imageResource.setBuffer(content);
    imageResource.setContentType("image/png");
    imageResource.setImageType(ImageType.SHOP_LOGO_LEFT);
    try {
        container.login(supplierUserKey, ROLE_SERVICE_MANAGER);
        svcProv.createService(tp, product, imageResource);
    } catch (EJBException e) {
        throw e.getCausedByException();
    }
}
 
源代码7 项目: development   文件: PlatformUserIT.java
/**
 * <b>Testcase:</b> Try to insert two Users with the same login for the same
 * organization<br>
 * <b>ExpectedResult:</b> SaasNonUniqueBusinessKeyException
 * 
 * @throws Throwable
 */
@Test(expected = NonUniqueBusinessKeyException.class)
public void testViolateUniqueConstraintSameOrganizationInOneTX()
        throws Throwable {
    try {
        runTX(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                doTestViolateUniqueConstraintInOneTX();
                return null;
            }
        });
    } catch (EJBException e) {
        throw e.getCause();
    }
}
 
@Test(expected = SaaSSystemException.class)
public void testCreateMarketingProductImageTypeNull() throws Exception {
    VOTechnicalService tp = createTechnicalProduct(svcProv);
    VOServiceDetails product = new VOServiceDetails();
    product.setServiceId("test");
    VOImageResource imageResource = new VOImageResource();
    byte[] content = BaseAdmUmTest.getFileAsByteArray(
            ServiceProvisioningServiceBeanIT.class, "icon1.png");
    imageResource.setBuffer(content);
    imageResource.setContentType("image/png");
    try {
        container.login(supplierUserKey, ROLE_SERVICE_MANAGER);
        svcProv.createService(tp, product, imageResource);
    } catch (EJBException e) {
        throw e.getCausedByException();
    }
}
 
源代码9 项目: development   文件: ProductClassBridgeIT.java
@Test
public void test2() throws Throwable {
    try {
        runTX(new Callable<Void>() {
            public Void call() throws Exception {
                Product product = createProductAndExpectedFields();
                expectedFields.clear();
                productKey = createAndPublishPartnerCopy(product).getKey();
                // Bug 9784
                // The ID of the marketplace where the partner publishes
                // must be written in the index.
                expectedFields.put(ProductClassBridge.MP_ID,
                        RESELLER_MP.toLowerCase());
                return null;
            }
        });
        runTX(new Callable<Void>() {
            public Void call() throws Exception {
                verifyIndexedFieldsForProduct(productKey);
                return null;
            }
        });
    } catch (EJBException e) {
        throw e.getCause();
    }
}
 
@Test
public void getDefaultPaymentConfiguration_asBroker() throws Exception {
    // given
    container.login(givenBroker().getKey(),
            UserRoleType.BROKER_MANAGER.name());

    try {
        // when
        as.getDefaultPaymentConfiguration();
        fail();
    } catch (EJBException e) {

        // then
        assertTrue(e.getCausedByException() instanceof EJBAccessException);
    }
}
 
@Test
public void getDefaultServicePaymentConfiguration_asBroker()
        throws Exception {
    // given
    container.login(givenBroker().getKey(),
            UserRoleType.BROKER_MANAGER.name());

    try {
        // when
        as.getDefaultServicePaymentConfiguration();
        fail();
    } catch (EJBException e) {

        // then
        assertTrue(e.getCausedByException() instanceof EJBAccessException);
    }
}
 
源代码12 项目: development   文件: ExceptionHandler.java
/**
 * Convert a EJBException into FacesMessage which is presented to the user.
 * 
 * @param ex
 *            the EJBException to be analyzed
 */
public static void execute(EJBException ex) {
    if (ex != null && ex.getCause() instanceof Exception
            && ex.getCausedByException() instanceof AccessException) {
        handleOrganizationAuthoritiesException();
    } else if (ex != null && isInvalidUserSession(ex)) {
        HttpServletRequest request = JSFUtils.getRequest();
        request.getSession().removeAttribute(Constants.SESS_ATTR_USER);
        request.getSession().invalidate();
        handleInvalidSession();
    } else if (ex != null && isConnectionException(ex)) {
        handleMissingConnect(BaseBean.ERROR_DATABASE_NOT_AVAILABLE);
    } else {
        throw new FacesException(ex);
    }
}
 
源代码13 项目: development   文件: DataServiceBeanIT.java
@Test
public void testGetCurrentUserNonExisting() throws Exception {
    container.login("1000");
    try {
        runTX(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                mgr.getCurrentUser();
                return null;
            }
        });
        Assert.fail(
                "Call must fail, as no dataset is present in the database for this user!");
    } catch (EJBException e) {
        Assert.assertTrue(
                e.getCausedByException() instanceof InvalidUserSession);
        Assert.assertNotNull(e.getCausedByException().getCause());
    }
}
 
@Test
public void getPartnerRevenueShareForAllStatesService_invalidRole()
        throws Exception {
    setupWithContainer();
    // given
    container.login(mpOwnerUserKey, UserRoleType.TECHNOLOGY_MANAGER.name());

    // when
    try {
        pricingService.getPartnerRevenueShareForAllStatesService(
                new POServiceForPricing());
        fail();
    } catch (EJBException e) {

        // then
        assertTrue(e.getCausedByException() instanceof EJBAccessException);
    }
}
 
源代码15 项目: development   文件: APPTimerServiceBean.java
/**
 * Convert given exception into a well designed platform exception.
 * 
 * @param ex
 *            the exception
 * @return the converted platform exception
 */
private APPlatformException getPlatformException(Throwable ex) {
    if (ex instanceof EJBException) {
        if (ex.getCause() != null) {
            ex = ex.getCause();
        } else if (((EJBException) ex).getCausedByException() != null) {
            ex = ((EJBException) ex).getCausedByException();
        }
    }

    if (ex instanceof APPlatformException) {
        return (APPlatformException) ex;
    }

    String causeMessage = (ex.getMessage() != null) ? ex.getMessage()
            : ex.getClass().getName();
    return new APPlatformException(causeMessage, ex);
}
 
源代码16 项目: development   文件: ProductToPaymentTypeIT.java
@Test
public void testAdd() throws Exception {
    try {
        runTX(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                doTestAdd();
                return null;
            }
        });

        runTX(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                doTestAddCheck();
                return null;
            }
        });
    } catch (EJBException e) {
        throw e.getCausedByException();
    }
}
 
源代码17 项目: development   文件: TimerServiceBean2Test.java
@Test(expected = ValidationException.class)
public void initTimers_nextExpirationDateNegative_userCount()
        throws ValidationException {
    // given
    tss = new TimerServiceStub() {
        @Override
        public Timer createTimer(Date arg0, Serializable arg1)
                throws IllegalArgumentException, IllegalStateException,
                EJBException {
            initTimer((TimerType) arg1, arg0);
            getTimers().add(timer);
            return null;
        }
    };
    when(ctx.getTimerService()).thenReturn(tss);
    cfs.setConfigurationSetting(ConfigurationKey.TIMER_INTERVAL_USER_COUNT,
            "9223372036854775807");
    // when
    tm.initTimers();

}
 
源代码18 项目: development   文件: AuthorizationFilter.java
private void handleServletException(HttpServletRequest httpRequest,
        HttpServletResponse httpResponse, ServletException e)
        throws IOException, ServletException {
    EJBException ejbEx = ExceptionHandler.getEJBException(e);
    if (ejbEx != null && ejbEx.getCause() instanceof Exception
            && ejbEx.getCausedByException() instanceof AccessException) {
        String forwardErrorPage;
        if (BesServletRequestReader.isMarketplaceRequest(httpRequest)) {
            forwardErrorPage = Marketplace.MARKETPLACE_ROOT
                    + Constants.INSUFFICIENT_AUTHORITIES_URI;
        } else {
            forwardErrorPage = Constants.INSUFFICIENT_AUTHORITIES_URI;
        }
        JSFUtils.sendRedirect(httpResponse, httpRequest.getContextPath()
                + forwardErrorPage);
    } else {
        // make sure we do not catch exceptions cause by
        // ViewExpiredException here, they'll be handled directly in the
        // doFilter()
        throw e;
    }
}
 
源代码19 项目: development   文件: ParameterDefinitionIT.java
@Test
public void modify() throws Throwable {
    try {
        runTX(new Callable<Void>() {
            public Void call() throws Exception {
                doTestAdd();
                return null;
            }
        });
        runTX(new Callable<Void>() {
            public Void call() throws Exception {
                doTestModify();
                return null;
            }
        });
        runTX(new Callable<Void>() {
            public Void call() throws Exception {
                doTestModifyCheck();
                return null;
            }
        });
    } catch (EJBException e) {
        throw e.getCause();
    }
}
 
源代码20 项目: development   文件: ModifiedUdaIT.java
/**
 * <b>Testcase:</b> Add new ModifiedUda objects <br>
 * <b>ExpectedResult:</b>
 * <ul>
 * <li>All objects can be retrieved from DB and are identical to provided
 * ModifiedUda objects</li>
 * <li>A history object is created for each ModifiedUda stored</li>
 * <li>History objects are created for CascadeAudit-annotated associated
 * objects</li>
 * </ul>
 * 
 * @throws Throwable
 */
@Test
public void testAdd() throws Throwable {
    try {
        runTX(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                doTestAdd();
                return null;
            }
        });
        runTX(new Callable<Void>() {
            @Override
            public Void call() {
                doTestAddCheck();
                return null;
            }
        });
    } catch (EJBException e) {
        throw e.getCause();
    }
}
 
源代码21 项目: development   文件: TechProviderSupplierIT.java
/**
 * Login with wrong role. SupplierServiceManger3. Exception expected.
 * 
 * @throws Exception
 */
@Test(expected = EJBAccessException.class)
public void testWrongRoleSupplierServiceManger() throws Exception {
    loginSupplierServiceManger(3);
    try {
        sps.getInstanceIdsForSellers(new ArrayList<String>());
    } catch (EJBException e) {
        throw e.getCausedByException();
    }
}
 
源代码22 项目: development   文件: EventServiceBeanIT.java
@Test
public void testRecordEventForInstance() throws Exception {

    event = new VOGatheredEvent();
    event.setActor(ACTOR);
    event.setOccurrenceTime(TIMESTAMP);
    event.setEventId(PlatformEventIdentifier.USER_LOGIN_TO_SERVICE);
    event.setMultiplier(MULTIPLIER);
    event.setUniqueId(UNIQUEID);

    evMgmt.recordEventForInstance(technicalProductId, instanceId, event);
    GatheredEvent savedEvent = readEvent(ACTOR, TIMESTAMP, SUBSCRIPTION_KEY,
            EventType.SERVICE_EVENT);
    testSavedEvent(TIMESTAMP, MULTIPLIER, UNIQUEID, savedEvent,
            EventType.SERVICE_EVENT);

    runTX(new Callable<Void>() {
        @Override
        public Void call() throws Exception {

            Subscription subscription = Subscriptions.createSubscription(
                    mgr, customerId, productId, "SUBSCRIPTION_2", supplier);
            subscription.setProductInstanceId(instanceId);
            return null;
        }
    });
    try {
        evMgmt.recordEventForInstance(technicalProductId, instanceId,
                event);
        Assert.fail("recordEvent() must faile!");
    } catch (EJBException e) {
        Assert.assertEquals(NonUniqueResultException.class,
                e.getCause().getCause().getClass());
    }
}
 
源代码23 项目: development   文件: EventServiceBeanIT.java
@Test(expected = EJBAccessException.class)
public void testRecordEventForSubscriptionWrongOrganization()
        throws Exception {

    runTX(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            // login as another technology provider
            Organization provider = Organizations.createOrganization(mgr,
                    OrganizationRoleType.TECHNOLOGY_PROVIDER);
            PlatformUser user = Organizations.createUserForOrg(mgr,
                    provider, true, "admin");
            container.login(user.getKey());
            return null;
        }
    });

    final VOGatheredEvent evt = new VOGatheredEvent();
    evt.setActor(ACTOR);
    evt.setOccurrenceTime(TIMESTAMP);
    evt.setEventId(PlatformEventIdentifier.USER_LOGIN_TO_SERVICE);
    evt.setMultiplier(MULTIPLIER);
    try {
        evMgmt.recordEventForSubscription(SUBSCRIPTION_KEY, evt);
    } catch (EJBException e) {
        throw e.getCausedByException();
    }
}
 
源代码24 项目: datawave   文件: CachedResultsBean.java
@PostConstruct
public void init() {
    // create the template table in the database if it does not exist.
    
    if (cachedResultsConfiguration.getDefaultPageSize() > cachedResultsConfiguration.getMaxPageSize()) {
        throw new EJBException("The default page size " + cachedResultsConfiguration.getDefaultPageSize() + " has been set larger than the max page size "
                        + cachedResultsConfiguration.getMaxPageSize());
    }
    
    try {
        importFileUrl = new File(System.getProperty("jboss.home.dir"), IMPORT_FILE).toURI().toURL();
        log.info("import.sh: " + importFileUrl);
    } catch (MalformedURLException e) {
        log.error("Error getting import.sh", e);
        importFileUrl = null;
    }
    
    CachedRunningQuery.setDatasource(ds);
    CachedRunningQuery.setQueryFactory(queryFactory);
    CachedRunningQuery.setResponseObjectFactory(responseObjectFactory);
    
    String template = null;
    try (Connection con = ds.getConnection(); Statement s = con.createStatement()) {
        template = cachedResultsConfiguration.getParameters().get("TEMPLATE_TABLE");
        s.execute(template);
    } catch (SQLException sqle) {
        log.error(sqle.getMessage(), sqle);
        throw new EJBException("Unable to create template table with statement: " + template, sqle);
    }
}
 
源代码25 项目: development   文件: CategoryToCatalogEntryIT.java
@Test
public void testDelete() throws Throwable {
    try {
        runTX(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                doTestDeletePrepare();
                return null;
            }
        });
        runTX(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                doTestDelete();
                return null;
            }
        });
        runTX(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                doTestDeleteCheck();
                return null;
            }
        });
    } catch (EJBException e) {
        throw e.getCause();
    }
}
 
源代码26 项目: development   文件: UserManagementServiceBeanIT.java
@Test(expected = EJBAccessException.class)
public void clearPlatformSettings_OrganizationAdmin() throws Exception {
    container.login(1, ROLE_ORGANIZATION_ADMIN);
    try {
        ums.clearPlatformSettings();
    } catch (EJBException e) {
        throw e.getCausedByException();
    }
}
 
源代码27 项目: solace-integration-guides   文件: XAConsumerMDB.java
public void onMessage(Message message) {
    String msg = message.toString();

    System.out.println(Thread.currentThread().getName() + " - XAConsumerMDB: received message: " + msg);

    try {
        // Send reply message
        sb.sendMessage();
    } catch (JMSException e) {
        throw new EJBException("Error while sending reply message", e);
    }

    System.out.println("Completed processing!");

}
 
源代码28 项目: development   文件: TimerServiceStub.java
@Override
public Timer createIntervalTimer(long arg0, long arg1, TimerConfig arg2)
        throws IllegalArgumentException, IllegalStateException,
        EJBException {

    return null;
}
 
/**
 * delete is only allowed for Role PLATFORM_OPERATOR if the user doesn't
 * have this role EJBAccessException is thrown
 * 
 * @throws Exception
 */
@Test(expected = EJBAccessException.class)
public void deleteMarketplace_RequiresPlatformOperatorRole()
        throws Exception {

    container.login(this.supplier3Key, ROLE_ORGANIZATION_ADMIN);

    try {
        marketplaceService.deleteMarketplace("");
    } catch (EJBException e) {
        throw e.getCausedByException();
    }
}
 
@Test
public void testDirectCall(){

    try{
        //this does not return a boolean, but rather throw an exception
        ejb.createFailDirect();
        fail();
    }catch (EJBException e){
        //expected
    }
}