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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations