Search in sources :

Example 1 with UserServiceAdapter

use of org.candlepin.service.UserServiceAdapter in project candlepin by candlepin.

the class DefaultUserServiceAdapterTest method findByLogin.

@Test
public void findByLogin() {
    User u = mock(User.class);
    UserCurator curator = mock(UserCurator.class);
    RoleCurator roleCurator = mock(RoleCurator.class);
    UserServiceAdapter dusa = new DefaultUserServiceAdapter(curator, roleCurator);
    when(curator.findByLogin(anyString())).thenReturn(u);
    User foo = dusa.findByLogin("foo");
    assertNotNull(foo);
    assertEquals(foo, u);
}
Also used : User(org.candlepin.model.User) UserCurator(org.candlepin.model.UserCurator) UserServiceAdapter(org.candlepin.service.UserServiceAdapter) RoleCurator(org.candlepin.model.RoleCurator) Test(org.junit.Test)

Example 2 with UserServiceAdapter

use of org.candlepin.service.UserServiceAdapter in project candlepin by candlepin.

the class ConsumerResourceTest method testNullPerson.

@Test(expected = NotFoundException.class)
public void testNullPerson() {
    Owner owner = this.createOwner();
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.PERSON));
    ConsumerTypeDTO ctypeDto = this.translator.translate(ctype, ConsumerTypeDTO.class);
    Consumer consumer = this.createConsumer(owner, ctype);
    ConsumerDTO consumerDto = this.translator.translate(consumer, ConsumerDTO.class);
    UserServiceAdapter usa = mock(UserServiceAdapter.class);
    UserPrincipal up = mock(UserPrincipal.class);
    when(up.canAccess(eq(owner), eq(SubResource.CONSUMERS), eq(Access.CREATE))).thenReturn(true);
    // usa.findByLogin() will return null by default no need for a when
    ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, usa, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    cr.create(consumerDto, up, null, owner.getKey(), null, true);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) UserServiceAdapter(org.candlepin.service.UserServiceAdapter) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Aggregations

UserServiceAdapter (org.candlepin.service.UserServiceAdapter)2 Test (org.junit.Test)2 UserPrincipal (org.candlepin.auth.UserPrincipal)1 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)1 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)1 Consumer (org.candlepin.model.Consumer)1 ConsumerType (org.candlepin.model.ConsumerType)1 Owner (org.candlepin.model.Owner)1 RoleCurator (org.candlepin.model.RoleCurator)1 User (org.candlepin.model.User)1 UserCurator (org.candlepin.model.UserCurator)1