use of org.candlepin.common.exceptions.ForbiddenException in project candlepin by candlepin.
the class ConsumerBindUtilTest method registerPassWhenAutobindDisabledForOwnerAndKeyHasAutobindEnabled.
@Test
public void registerPassWhenAutobindDisabledForOwnerAndKeyHasAutobindEnabled() throws Exception {
List<ActivationKey> keys = new ArrayList<>();
ActivationKey key1 = new ActivationKey("key1", owner);
key1.setAutoAttach(true);
keys.add(key1);
Product prod1 = TestUtil.createProduct();
Pool pool1 = TestUtil.createPool(owner, prod1, 5);
pool1.setId("pool1");
key1.addPool(pool1, 10L);
Consumer consumer = new Consumer("sys.example.com", null, null, system);
when(entitler.bindByPoolQuantity(eq(consumer), eq(pool1.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
consumerBindUtil.handleActivationKeys(consumer, keys, true);
}
use of org.candlepin.common.exceptions.ForbiddenException in project candlepin by candlepin.
the class ManifestManagerTest method verifyConsumerIsDistributorBeforeGeneratingManifest.
@Test
public void verifyConsumerIsDistributorBeforeGeneratingManifest() throws Exception {
Consumer consumer = this.createMockConsumer(false);
ConsumerType ctype = consumerTypeCurator.getConsumerType(consumer);
Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
String webAppPrefix = "webapp-prefix";
String apiUrl = "api-url";
Map<String, String> extData = new HashMap<>();
when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
try {
manager.generateManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
fail("Expected ForbiddenException not thrown");
} catch (Exception e) {
assertTrue(e instanceof ForbiddenException);
String expectedMsg = String.format("Unit %s cannot be exported. A manifest cannot be made for " + "units of type \"%s\".", consumer.getUuid(), ctype.getLabel());
assertEquals(e.getMessage(), expectedMsg);
}
}
use of org.candlepin.common.exceptions.ForbiddenException in project candlepin by candlepin.
the class ManifestManagerTest method verifyConsumerIsDistributorBeforeSchedulingManifestGeneration.
@Test
public void verifyConsumerIsDistributorBeforeSchedulingManifestGeneration() throws Exception {
Owner owner = TestUtil.createOwner();
Consumer consumer = this.createMockConsumer(owner, false);
ConsumerType ctype = consumerTypeCurator.getConsumerType(consumer);
Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
String webAppPrefix = "webapp-prefix";
String apiUrl = "api-url";
Map<String, String> extData = new HashMap<>();
when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
try {
manager.generateManifestAsync(consumer.getUuid(), owner.getKey(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
fail("Expected ForbiddenException not thrown");
} catch (Exception e) {
assertTrue(e instanceof ForbiddenException);
String expectedMsg = String.format("Unit %s cannot be exported. A manifest cannot be made for " + "units of type \"%s\".", consumer.getUuid(), ctype.getLabel());
assertEquals(e.getMessage(), expectedMsg);
}
}
use of org.candlepin.common.exceptions.ForbiddenException in project candlepin by candlepin.
the class OwnerContentResourceTest method deleteLockedContent.
@Test(expected = ForbiddenException.class)
public void deleteLockedContent() {
Owner owner = this.createOwner("test_owner");
Content content = this.createContent("test_content", "test_content", owner);
content.setLocked(true);
this.contentCurator.merge(content);
Environment environment = this.createEnvironment(owner, "test_env", "test_env", null, null, Arrays.asList(content));
assertNotNull(this.ownerContentCurator.getContentById(owner, content.getId()));
try {
this.ownerContentResource.remove(owner.getKey(), content.getId());
} catch (ForbiddenException e) {
assertNotNull(this.ownerContentCurator.getContentById(owner, content.getId()));
this.environmentCurator.evict(environment);
environment = this.environmentCurator.find(environment.getId());
assertEquals(1, environment.getEnvironmentContent().size());
throw e;
}
}
use of org.candlepin.common.exceptions.ForbiddenException in project candlepin by candlepin.
the class EntitlerJobTest method handleException.
@Test(expected = JobExecutionException.class)
public void handleException() throws JobExecutionException, EntitlementRefusedException {
PoolIdAndQuantity[] pQs = new PoolIdAndQuantity[1];
pQs[0] = new PoolIdAndQuantity("pool10", 1);
JobDetail detail = EntitlerJob.bindByPoolAndQuantities(consumer, owner.getKey(), pQs);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
Class<HashMap<String, Integer>> className = (Class<HashMap<String, Integer>>) (Class) Map.class;
ArgumentCaptor<HashMap<String, Integer>> pqMapCaptor = ArgumentCaptor.forClass(className);
when(e.bindByPoolQuantities(eq(consumerUuid), pqMapCaptor.capture())).thenThrow(new ForbiddenException("job should fail"));
EntitlerJob job = new EntitlerJob(e, null, null, null);
injector.injectMembers(job);
job.execute(ctx);
}
Aggregations