Search in sources :

Example 11 with ConsumerTypeDTO

use of org.candlepin.dto.manifest.v1.ConsumerTypeDTO in project candlepin by candlepin.

the class ConsumerResourceTest method testCreateConsumerShouldFailOnMaxLengthOfName.

@Test
public void testCreateConsumerShouldFailOnMaxLengthOfName() {
    thrown.expect(BadRequestException.class);
    thrown.expectMessage(String.format("Name of the consumer " + "should be shorter than %d characters.", Consumer.MAX_LENGTH_OF_CONSUMER_NAME + 1));
    Owner owner = this.createOwner();
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SYSTEM));
    ConsumerTypeDTO ctypeDto = this.translator.translate(ctype, ConsumerTypeDTO.class);
    Consumer consumer = this.createConsumer(owner, ctype);
    consumer.setName(RandomStringUtils.randomAlphanumeric(Consumer.MAX_LENGTH_OF_CONSUMER_NAME + 1));
    ConsumerDTO consumerDto = this.translator.translate(consumer, ConsumerDTO.class);
    UserPrincipal up = mock(UserPrincipal.class);
    ConsumerResource consumerResource = createConsumerResource(mockOwnerCurator);
    when(up.canAccess(eq(owner), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
    consumerResource.create(consumerDto, up, null, owner.getKey(), null, false);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 12 with ConsumerTypeDTO

use of org.candlepin.dto.manifest.v1.ConsumerTypeDTO in project candlepin by candlepin.

the class ConsumerTypeResourceTest method testCreateType.

@Test
public void testCreateType() {
    String label = "test_label";
    ConsumerType existing = this.consumerTypeCurator.lookupByLabel(label);
    // Verify it doesn't exist already
    assertNull(existing);
    ConsumerTypeDTO dto = new ConsumerTypeDTO();
    dto.setLabel(label);
    dto.setManifest(true);
    // Create the type with our DTO
    ConsumerTypeDTO output = this.consumerTypeResource.create(dto);
    assertNotNull(output);
    assertEquals(dto.getLabel(), output.getLabel());
    assertEquals(dto.isManifest(), output.isManifest());
    // Flush & clear DB state
    this.consumerTypeCurator.flush();
    this.consumerTypeCurator.clear();
    // Ensure the type actually hit the DB
    existing = this.consumerTypeCurator.lookupByLabel(label);
    assertNotNull(existing);
    assertEquals(dto.getLabel(), existing.getLabel());
    assertEquals(dto.isManifest(), existing.isManifest());
}
Also used : ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Example 13 with ConsumerTypeDTO

use of org.candlepin.dto.manifest.v1.ConsumerTypeDTO in project candlepin by candlepin.

the class ConsumerTypeResourceTest method testUpdateTypeUpdatesLabelButNotManifest.

@Test
public void testUpdateTypeUpdatesLabelButNotManifest() {
    String label = "updated_label";
    boolean manifest = this.testType.isManifest();
    ConsumerTypeDTO dto = new ConsumerTypeDTO();
    dto.setId(this.testType.getId());
    dto.setLabel(label);
    // Update the type with our DTO
    ConsumerTypeDTO output = this.consumerTypeResource.update(dto);
    assertNotNull(output);
    assertEquals(dto.getLabel(), output.getLabel());
    assertEquals(manifest, output.isManifest());
    // Flush & clear DB state
    this.consumerTypeCurator.flush();
    this.consumerTypeCurator.clear();
    // Ensure the update actually hit the DB
    ConsumerType existing = this.consumerTypeCurator.lookupByLabel(label);
    assertNotNull(existing);
    assertEquals(dto.getLabel(), existing.getLabel());
    assertEquals(manifest, existing.isManifest());
}
Also used : ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Example 14 with ConsumerTypeDTO

use of org.candlepin.dto.manifest.v1.ConsumerTypeDTO in project candlepin by candlepin.

the class ConsumerTypeResourceTest method testRetrieveType.

@Test
public void testRetrieveType() {
    ConsumerTypeDTO output = this.consumerTypeResource.getConsumerType(this.testType.getId());
    assertNotNull(output);
    assertEquals(this.testType.getLabel(), output.getLabel());
    assertEquals(this.testType.isManifest(), output.isManifest());
}
Also used : ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Example 15 with ConsumerTypeDTO

use of org.candlepin.dto.manifest.v1.ConsumerTypeDTO in project candlepin by candlepin.

the class ConsumerResourceTest method testCreatePersonConsumerWithActivationKey.

@Test(expected = BadRequestException.class)
public void testCreatePersonConsumerWithActivationKey() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.PERSON));
    ConsumerTypeDTO ctypeDto = this.translator.translate(ctype, ConsumerTypeDTO.class);
    Owner owner = this.createOwner();
    Consumer consumer = this.createConsumer(owner, ctype);
    ConsumerDTO consumerDto = this.translator.translate(consumer, ConsumerDTO.class);
    ActivationKey ak = mock(ActivationKey.class);
    NoAuthPrincipal nap = mock(NoAuthPrincipal.class);
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    ConsumerContentOverrideCurator ccoc = mock(ConsumerContentOverrideCurator.class);
    when(ak.getId()).thenReturn("testKey");
    when(akc.lookupForOwner(eq(owner.getKey()), eq(owner))).thenReturn(ak);
    ConsumerResource cr = new ConsumerResource(null, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, akc, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    cr.create(consumerDto, nap, null, owner.getKey(), "testKey", true);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerContentOverrideCurator(org.candlepin.model.ConsumerContentOverrideCurator) ConsumerType(org.candlepin.model.ConsumerType) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)14 ConsumerType (org.candlepin.model.ConsumerType)13 Owner (org.candlepin.model.Owner)11 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)7 ConsumerTypeDTO (org.candlepin.dto.manifest.v1.ConsumerTypeDTO)7 ConsumerDTO (org.candlepin.dto.manifest.v1.ConsumerDTO)6 OwnerDTO (org.candlepin.dto.manifest.v1.OwnerDTO)6 UserPrincipal (org.candlepin.auth.UserPrincipal)5 CertificateSerial (org.candlepin.model.CertificateSerial)3 Consumer (org.candlepin.model.Consumer)3 IdentityCertificate (org.candlepin.model.IdentityCertificate)3 UpstreamConsumer (org.candlepin.model.UpstreamConsumer)3 File (java.io.File)2 Date (java.util.Date)2 Access (org.candlepin.auth.Access)2 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)2 SubResource (org.candlepin.auth.SubResource)2 CandlepinCommonTestConfig (org.candlepin.config.CandlepinCommonTestConfig)2 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)2