Search in sources :

Example 76 with ConsumerDTO

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

the class ConsumerResourceUpdateTest method testUpdateConsumerClearsGuestListWhenRequestGuestListIsEmptyButNotNull.

@Test
public void testUpdateConsumerClearsGuestListWhenRequestGuestListIsEmptyButNotNull() {
    String uuid = "TEST_CONSUMER";
    String[] guests = new String[] { "Guest 1", "Guest 2" };
    Consumer existing = createConsumerWithGuests(createOwner(), guests);
    existing.setUuid(uuid);
    when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(existing);
    ConsumerDTO updated = new ConsumerDTO();
    updated.setGuestIds(new ArrayList<>());
    this.resource.updateConsumer(existing.getUuid(), updated, principal);
    assertTrue(existing.getGuestIds().isEmpty());
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Test(org.junit.Test)

Example 77 with ConsumerDTO

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

the class ConsumerResourceUpdateTest method consumerCapabilityUpdate.

@Test
public void consumerCapabilityUpdate() {
    ConsumerType ct = new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN);
    this.mockConsumerType(ct);
    Consumer c = getFakeConsumer();
    Set<ConsumerCapability> caps = new HashSet<>();
    ConsumerCapability cca = new ConsumerCapability(c, "capability_a");
    ConsumerCapability ccb = new ConsumerCapability(c, "capability_b");
    ConsumerCapability ccc = new ConsumerCapability(c, "capability_c");
    caps.add(cca);
    caps.add(ccb);
    caps.add(ccc);
    c.setCapabilities(caps);
    c.setType(ct);
    assertEquals(3, c.getCapabilities().size());
    // no capability list in update object does not change existing
    // also shows that setCapabilites can accept null and not error
    ConsumerDTO updated = new ConsumerDTO();
    updated.setCapabilities(null);
    resource.updateConsumer(c.getUuid(), updated, principal);
    assertEquals(3, c.getCapabilities().size());
    // empty capability list in update object does change existing
    updated = new ConsumerDTO();
    updated.setCapabilities(new HashSet<>());
    resource.updateConsumer(c.getUuid(), updated, principal);
    assertEquals(0, c.getCapabilities().size());
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerCapability(org.candlepin.model.ConsumerCapability) ConsumerType(org.candlepin.model.ConsumerType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 78 with ConsumerDTO

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

the class ConsumerResourceUpdateTest method nothingChanged.

@Test
public void nothingChanged() throws Exception {
    ConsumerDTO consumer = getFakeConsumerDTO();
    this.resource.updateConsumer(consumer.getUuid(), consumer, principal);
    verify(sink, never()).queueEvent((Event) any());
}
Also used : ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Test(org.junit.Test)

Example 79 with ConsumerDTO

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

the class ConsumerResourceUpdateTest method testUpdatesOnContentTagChanges.

@Test
public void testUpdatesOnContentTagChanges() {
    HashSet<String> originalTags = new HashSet<>(Arrays.asList(new String[] { "hello", "world" }));
    HashSet<String> changedTags = new HashSet<>(Arrays.asList(new String[] { "x", "y" }));
    ConsumerDTO c = getFakeConsumerDTO();
    c.setContentTags(originalTags);
    ConsumerDTO incoming = new ConsumerDTO();
    incoming.setContentTags(changedTags);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    resource.updateConsumer(c.getUuid(), incoming, principal);
    verify(consumerCurator, times(1)).update(consumerCaptor.capture());
    Consumer mergedConsumer = consumerCaptor.getValue();
    assertEquals(changedTags, mergedConsumer.getContentTags());
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) HashSet(java.util.HashSet) Test(org.junit.Test)

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