Java源码示例:javax.ejb.EJBAccessException
示例1
@Test
public void testToResponse_EJBAccessException() {
Exception e = new EJBAccessException("Caller unauthorized");
StackTraceElement[] traceArr = new StackTraceElement[1];
traceArr[0] = new StackTraceElement("dummyClass", "dummyMethod", null, 0);
e.setStackTrace(traceArr);
Response response = rem.toResponse(e);
MultivaluedMap<String,Object> responseMap = response.getHeaders();
Assert.assertEquals(403, response.getStatus());
Assert.assertEquals(6, responseMap.size());
Assert.assertEquals(Lists.newArrayList(true), responseMap.get(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
Assert.assertEquals(Lists.newArrayList("*"), responseMap.get(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
Assert.assertEquals(Lists.newArrayList(864000), responseMap.get(HttpHeaders.ACCESS_CONTROL_MAX_AGE));
Assert.assertEquals(Lists.newArrayList("403-1"), responseMap.get(Constants.ERROR_CODE));
Assert.assertEquals(Lists.newArrayList("null/null"), responseMap.get(Constants.RESPONSE_ORIGIN));
Assert.assertEquals(Lists.newArrayList("X-SSL-ClientCert-Subject, X-ProxiedEntitiesChain, X-ProxiedIssuersChain, Accept, Accept-Encoding"),
responseMap.get(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS));
}
示例2
@Test
public void testToResponse_EJBAccessException2() {
Exception e = new EJBAccessException("Caller is legit");
StackTraceElement[] traceArr = new StackTraceElement[1];
traceArr[0] = new StackTraceElement("dummyClass", "dummyMethod", null, 0);
e.setStackTrace(traceArr);
Response response = rem.toResponse(e);
MultivaluedMap<String,Object> responseMap = response.getHeaders();
Assert.assertEquals(500, response.getStatus());
Assert.assertEquals(6, responseMap.size());
Assert.assertEquals(Lists.newArrayList(true), responseMap.get(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
Assert.assertEquals(Lists.newArrayList("*"), responseMap.get(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
Assert.assertEquals(Lists.newArrayList(864000), responseMap.get(HttpHeaders.ACCESS_CONTROL_MAX_AGE));
Assert.assertEquals(Lists.newArrayList("500-1"), responseMap.get(Constants.ERROR_CODE));
Assert.assertEquals(Lists.newArrayList("null/null"), responseMap.get(Constants.RESPONSE_ORIGIN));
Assert.assertEquals(Lists.newArrayList("X-SSL-ClientCert-Subject, X-ProxiedEntitiesChain, X-ProxiedIssuersChain, Accept, Accept-Encoding"),
responseMap.get(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS));
}
示例3
@Test
public void saveAllVats_asBroker() throws Exception {
// given
container.login(givenBroker().getKey(),
UserRoleType.BROKER_MANAGER.name());
// when
try {
vatService.saveAllVats(new VOVatRate(),
new ArrayList<VOCountryVatRate>(),
new ArrayList<VOOrganizationVatRate>());
fail("EJBException expected as operation must fail due to not allowed role!");
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例4
@Test
public void updateCustomerDiscount_asReseller() throws Exception {
// given
container.login(givenReseller().getKey(),
UserRoleType.RESELLER_MANAGER.name());
// when
try {
as.updateCustomerDiscount(new VOOrganization());
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例5
@Test
public void updateCustomerDiscount_asBroker() throws Exception {
// given
container.login(givenBroker().getKey(),
UserRoleType.BROKER_MANAGER.name());
// when
try {
as.updateCustomerDiscount(new VOOrganization());
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例6
@Test
public void saveDefaultVat_asBroker() throws Exception {
// given
container.login(givenBroker().getKey(),
UserRoleType.BROKER_MANAGER.name());
// when
try {
vatService.saveDefaultVat(new VOVatRate());
fail("EJBException expected as operation must fail due to not allowed role!");
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例7
@Test
public void getServicePaymentConfiguration_asBroker() throws Exception {
// given
container.login(givenBroker().getKey(),
UserRoleType.BROKER_MANAGER.name());
try {
// when
as.getServicePaymentConfiguration();
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例8
@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);
}
}
示例9
@Test
public void getPartnerRevenueShareForService_invalidRole()
throws Exception {
setupWithContainer();
// given
container.login(mpOwnerUserKey, UserRoleType.TECHNOLOGY_MANAGER.name());
// when
try {
pricingService.getPartnerRevenueShareForService(
new POServiceForPricing());
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例10
@Test
public void getPricingForMarketplace_invalidRole() throws Exception {
// given
container.login(givenTechProvider().getKey(),
UserRoleType.TECHNOLOGY_MANAGER.name());
// when
try {
pricingService.getPricingForMarketplace(OPEN_MP_ID);
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例11
@Test
public void getPartnerRevenueSharesForMarketplace_invalidRole()
throws Exception {
// given
container.login(mpOwnerUserKey, UserRoleType.TECHNOLOGY_MANAGER.name());
// when
try {
pricingService.getPartnerRevenueSharesForMarketplace(MARKETPLACEID);
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例12
@Test
public void getMarketplaceRevenueShares_invalidRole() throws Exception {
// given
container.login(mpOwnerUserKey, UserRoleType.TECHNOLOGY_MANAGER.name());
// when
try {
pricingService.getMarketplaceRevenueShares(MARKETPLACEID);
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例13
@Test
public void saveCountryVats_asReseller() throws Exception {
// given
container.login(givenReseller().getKey(),
UserRoleType.RESELLER_MANAGER.name());
// when
try {
vatService.saveCountryVats(new ArrayList<VOCountryVatRate>());
fail("EJBException expected as operation must fail due to not allowed role!");
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例14
@Test
public void saveOrganizationVats_asReseller() throws Exception {
// given
container.login(givenReseller().getKey(),
UserRoleType.RESELLER_MANAGER.name());
// when
try {
vatService.saveOrganizationVats(
new ArrayList<VOOrganizationVatRate>());
fail("EJBException expected as operation must fail due to not allowed role!");
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例15
@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);
}
}
示例16
@Test
public void getResellerOrganizations_asReseller() throws Exception {
// given
container.login(givenReseller().getKey(),
UserRoleType.RESELLER_MANAGER.name());
try {
// when
publishService.getResellers(0L);
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例17
@Test(expected = EJBAccessException.class)
public void getSubscriptionsForOrgSize_NotAuthorized() throws Exception {
runTX(new Callable<Void>() {
@Override
public Void call() throws Exception {
container.login(String.valueOf(admin.getKey()));
try {
service.getSubscriptionsForOrgSize(
new HashSet<SubscriptionStatus>(), new Pagination());
} catch (EJBException e) {
throw e.getCausedByException();
}
return null;
}
});
}
示例18
@Test(expected = EJBAccessException.class)
public void getAvailableReportsForOrgAdmin_NotAuthorized()
throws Exception {
runTX(new Callable<Void>() {
@Override
public Void call() throws Exception {
container.login(String.valueOf(supplierUserA.getKey()),
UserRoleType.SUBSCRIPTION_MANAGER.name());
try {
reportService
.getAvailableReportsForOrgAdmin(ReportType.ALL);
} catch (EJBException e) {
throw e.getCausedByException();
}
return null;
}
});
}
示例19
@Test
public void savePriceModelForSubscription_asReseller() throws Exception {
// given
container.login(1L, UserRoleType.RESELLER_MANAGER.name());
// when
try {
sps.savePriceModelForSubscription(new VOServiceDetails(),
new VOPriceModel());
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例20
@Test
public void savePriceModelForCustomer_asBroker() throws Exception {
// given
container.login(1L, UserRoleType.BROKER_MANAGER.name());
// when
try {
sps.savePriceModelForCustomer(new VOServiceDetails(),
new VOPriceModel(), new VOOrganization());
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例21
@Test
public void savePriceModelForCustomer_asReseller() throws Exception {
// given
container.login(1L, UserRoleType.RESELLER_MANAGER.name());
// when
try {
sps.savePriceModelForCustomer(new VOServiceDetails(),
new VOPriceModel(), new VOOrganization());
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例22
@Test
public void updateService_asBroker() throws Exception {
// given
container.login(1L, UserRoleType.BROKER_MANAGER.name());
// when
try {
sps.updateService(new VOServiceDetails(), null);
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例23
@Test
public void saveOrganizationVats_asBroker() throws Exception {
// given
container.login(givenBroker().getKey(),
UserRoleType.BROKER_MANAGER.name());
// when
try {
vatService.saveOrganizationVats(
new ArrayList<VOOrganizationVatRate>());
fail("EJBException expected as operation must fail due to not allowed role!");
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例24
@Test(expected = EJBAccessException.class)
public void availableServices_invalidRole() throws Throwable {
// given
String invalidRole = UserRoleType.ORGANIZATION_ADMIN.name();
container.login(mpOwnerUserKey, invalidRole);
// when
try {
landingpageServiceLocal.availableServices(MARKETPLACEID);
} catch (EJBException e) {
throw e.getCause();
}
// then
fail();
}
示例25
@Test(expected = EJBAccessException.class)
public void resetLandingpage_invalidRole() throws Throwable {
// given
String invalidRole = UserRoleType.ORGANIZATION_ADMIN.name();
container.login(mpOwnerUserKey, invalidRole);
// when
try {
landingpageServiceLocal.resetLandingpage(MARKETPLACEID);
} catch (EJBException e) {
throw e.getCause();
}
// then
fail();
}
示例26
@Test(expected = EJBAccessException.class)
public void loadPublicLandingpageConfig_invalidRole() throws Throwable {
// given
String invalidRole = UserRoleType.ORGANIZATION_ADMIN.name();
container.login(mpOwnerUserKey, invalidRole);
// when loading, then throw exception
try {
landingpageServiceLocal.loadPublicLandingpageConfig(MARKETPLACEID);
} catch (EJBException e) {
throw e.getCause();
}
}
示例27
private void checkAllowed() {
if (rolesAllowed.length == 0) {
return;
}
for (String r : rolesAllowed) {
if (sessionContext.isCallerInRole(r)) {
return;
}
}
throw new EJBAccessException("Allowed roles are: "
+ Arrays.asList(rolesAllowed));
}
示例28
public static Matcher<EJBException> isAccessDenied() {
return new BaseMatcher<EJBException>() {
@Override
public boolean matches(Object exception) {
return ((EJBException) exception).getCausedByException() instanceof EJBAccessException;
}
@Override
public void describeTo(Description description) {
description
.appendText("exception is not an EJBAccessException");
}
};
}
示例29
@Test
public void getTemplateServices_InvalidRole() {
// given
container.login(mpOwnerUserKey, UserRoleType.SERVICE_MANAGER.name());
try {
// when
pricingService.getTemplateServices();
fail();
} catch (EJBException e) {
// then
assertTrue(e.getCausedByException() instanceof EJBAccessException);
}
}
示例30
@Test
public void savePartnerRevenueSharesForServices_InvalidRole()
throws Exception {
// given
container.login(mpOwnerUserKey, ROLE_SERVICE_MANAGER);
// when
try {
pricingService.savePartnerRevenueSharesForServices(null);
fail();
} catch (EJBException ex) {
// then
assertTrue(ex.getCause() instanceof EJBAccessException);
}
}