Search in sources :

Example 41 with ConsumerDTO

use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.

the class ConsumerResourceTest method testValidateShareConsumerRequiresRecipientFact.

@Test
public void testValidateShareConsumerRequiresRecipientFact() {
    ConsumerType share = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SHARE));
    ConsumerTypeDTO shareDto = this.translator.translate(share, ConsumerTypeDTO.class);
    OwnerDTO ownerDto = new OwnerDTO().setDisplayName("Test Owner");
    ConsumerDTO c = createConsumerDTO("test-consumer", "test-user", ownerDto, shareDto);
    ConsumerResource consumerResource = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, i18n, null, null, null, null, null, mockPoolManager, null, mockOwnerCurator, null, null, null, null, null, null, new CandlepinCommonTestConfig(), null, null, null, consumerBindUtil, null, null, factValidator, null, consumerEnricher, migrationProvider, translator);
    UserPrincipal uap = mock(UserPrincipal.class);
    when(uap.canAccess(any(Object.class), any(SubResource.class), any(Access.class))).thenReturn(Boolean.TRUE);
    Owner o = mock(Owner.class);
    when(mockOwnerCurator.lookupByKey(any(String.class))).thenReturn(o);
    c.setFact("foo", "bar");
    thrown.expect(BadRequestException.class);
    thrown.expectMessage("must specify a recipient org");
    consumerResource.create(c, uap, "test-user", "test-owner", null, false);
}
Also used : SubResource(org.candlepin.auth.SubResource) Owner(org.candlepin.model.Owner) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Access(org.candlepin.auth.Access) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 42 with ConsumerDTO

use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.

the class OwnerResourceTest method consumerCannotListConsumersFromAnotherOwner.

@Test
public void consumerCannotListConsumersFromAnotherOwner() {
    Consumer c = createConsumer(owner);
    Owner owner2 = ownerCurator.create(new Owner("Owner2"));
    Consumer c2 = createConsumer(owner2);
    List<String> uuids = new ArrayList<>();
    uuids.add(c.getUuid());
    uuids.add(c2.getUuid());
    setupPrincipal(owner, Access.ALL);
    securityInterceptor.enable();
    CandlepinQuery<ConsumerDTO> result = ownerResource.listConsumers(owner.getKey(), null, null, uuids, null, null, null, null, null, null);
    assertNotNull(result);
    List<ConsumerDTO> consumers = result.list();
    assertEquals(1, consumers.size());
}
Also used : Owner(org.candlepin.model.Owner) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) UpstreamConsumerDTO(org.candlepin.dto.api.v1.UpstreamConsumerDTO) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 43 with ConsumerDTO

use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.

the class OwnerResourceTest method consumerCanListMultipleConsumers.

@Test
public void consumerCanListMultipleConsumers() {
    Consumer c = createConsumer(owner);
    Consumer c2 = createConsumer(owner);
    List<String> uuids = new ArrayList<>();
    uuids.add(c.getUuid());
    uuids.add(c2.getUuid());
    setupPrincipal(owner, Access.ALL);
    securityInterceptor.enable();
    CandlepinQuery<ConsumerDTO> result = ownerResource.listConsumers(owner.getKey(), null, null, uuids, null, null, null, null, null, null);
    assertNotNull(result);
    List<ConsumerDTO> consumers = result.list();
    assertEquals(2, consumers.size());
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) UpstreamConsumerDTO(org.candlepin.dto.api.v1.UpstreamConsumerDTO) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 44 with ConsumerDTO

use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.

the class OwnerResourceTest method consumerCanListConsumersByIdWhenOtherParametersPresent.

@Test
public void consumerCanListConsumersByIdWhenOtherParametersPresent() {
    Consumer c = createConsumer(owner);
    List<String> uuids = new ArrayList<>();
    uuids.add(c.getUuid());
    setupPrincipal(owner, Access.ALL);
    securityInterceptor.enable();
    Set<String> types = new HashSet<>();
    types.add("type");
    consumerTypeCurator.create(new ConsumerType("type"));
    CandlepinQuery<ConsumerDTO> result = ownerResource.listConsumers(owner.getKey(), "username", types, uuids, null, null, null, null, null, new PageRequest());
    assertNotNull(result);
    List<ConsumerDTO> consumers = result.list();
    assertEquals(0, consumers.size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) UpstreamConsumerDTO(org.candlepin.dto.api.v1.UpstreamConsumerDTO) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 45 with ConsumerDTO

use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.

the class EntitlementImporterTest method init.

@Before
public void init() {
    this.owner = new Owner();
    this.translator = new StandardTranslator(mockConsumerTypeCurator, mockEnvironmentCurator, ownerCurator);
    i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    this.importer = new EntitlementImporter(certSerialCurator, cdnCurator, i18n, mockProductCurator, ec, translator);
    ConsumerType ctype = TestUtil.createConsumerType();
    ctype.setId("test-ctype");
    consumer = TestUtil.createConsumer(ctype, owner);
    consumerDTO = this.translator.translate(consumer, ConsumerDTO.class);
    consumerDTO.setUrlWeb("");
    consumerDTO.setUrlApi("");
    when(this.mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    when(this.mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    cert = createEntitlementCertificate("my-test-key", "my-cert");
    cert.setId("test-id");
    reader = mock(Reader.class);
    meta = new Meta();
    meta.setCdnLabel("test-cdn");
    testCdn = new Cdn("test-cdn", "Test CDN", "https://test.url.com");
    when(cdnCurator.lookupByLabel("test-cdn")).thenReturn(testCdn);
}
Also used : Owner(org.candlepin.model.Owner) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) Reader(java.io.Reader) ConsumerType(org.candlepin.model.ConsumerType) Cdn(org.candlepin.model.Cdn) StandardTranslator(org.candlepin.dto.StandardTranslator) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)70 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)64 Consumer (org.candlepin.model.Consumer)37 UserPrincipal (org.candlepin.auth.UserPrincipal)19 Owner (org.candlepin.model.Owner)19 ConsumerType (org.candlepin.model.ConsumerType)16 HashSet (java.util.HashSet)15 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)15 Principal (org.candlepin.auth.Principal)14 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)13 TrustedUserPrincipal (org.candlepin.auth.TrustedUserPrincipal)12 Set (java.util.Set)10 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 TestUtil.createConsumerDTO (org.candlepin.test.TestUtil.createConsumerDTO)8 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)7 ConsumerTypeDTO (org.candlepin.dto.manifest.v1.ConsumerTypeDTO)7 OwnerDTO (org.candlepin.dto.manifest.v1.OwnerDTO)7 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)7 Entitlement (org.candlepin.model.Entitlement)5