Search in sources :

Example 11 with PermissionBlueprint

use of org.candlepin.model.PermissionBlueprint in project candlepin by candlepin.

the class ConsumerResourceCreationTest method init.

@Before
public void init() throws Exception {
    this.i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    this.modelTranslator = new StandardTranslator(this.consumerTypeCurator, this.environmentCurator, this.ownerCurator);
    testMigration = new GuestMigration(consumerCurator);
    migrationProvider = Providers.of(testMigration);
    this.config = initConfig();
    this.resource = new ConsumerResource(this.consumerCurator, this.consumerTypeCurator, null, this.subscriptionService, this.ownerService, null, this.idCertService, null, this.i18n, this.sink, null, null, null, this.userService, null, null, this.ownerCurator, this.activationKeyCurator, null, this.complianceRules, this.deletedConsumerCurator, null, null, this.config, null, null, null, this.consumerBindUtil, null, null, new FactValidator(this.config, this.i18n), null, consumerEnricher, migrationProvider, modelTranslator);
    this.system = this.initConsumerType();
    this.mockConsumerType(this.system);
    this.systemDto = this.modelTranslator.translate(this.system, ConsumerTypeDTO.class);
    owner = new Owner("test_owner");
    owner.setId(TestUtil.randomString());
    user = new User(USER, "");
    PermissionBlueprint p = new PermissionBlueprint(PermissionType.OWNER, owner, Access.ALL);
    role = new Role();
    role.addPermission(p);
    role.addUser(user);
    when(consumerCurator.create(any(Consumer.class))).thenAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return invocation.getArguments()[0];
        }
    });
    when(consumerCurator.create(any(Consumer.class), any(Boolean.class))).thenAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return invocation.getArguments()[0];
        }
    });
    when(userService.findByLogin(USER)).thenReturn(user);
    IdentityCertificate cert = new IdentityCertificate();
    cert.setKey("testKey");
    cert.setCert("testCert");
    cert.setId("testId");
    cert.setSerial(new CertificateSerial(new Date()));
    when(idCertService.generateIdentityCert(any(Consumer.class))).thenReturn(cert);
    when(ownerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    when(complianceRules.getStatus(any(Consumer.class), any(Date.class), any(Boolean.class), any(Boolean.class))).thenReturn(new ComplianceStatus(new Date()));
}
Also used : FactValidator(org.candlepin.util.FactValidator) Owner(org.candlepin.model.Owner) User(org.candlepin.model.User) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) CertificateSerial(org.candlepin.model.CertificateSerial) StandardTranslator(org.candlepin.dto.StandardTranslator) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Date(java.util.Date) Role(org.candlepin.model.Role) GuestMigration(org.candlepin.resource.util.GuestMigration) Answer(org.mockito.stubbing.Answer) Consumer(org.candlepin.model.Consumer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PermissionBlueprint(org.candlepin.model.PermissionBlueprint) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) IdentityCertificate(org.candlepin.model.IdentityCertificate) Before(org.junit.Before)

Aggregations

PermissionBlueprint (org.candlepin.model.PermissionBlueprint)11 Role (org.candlepin.model.Role)9 Owner (org.candlepin.model.Owner)6 User (org.candlepin.model.User)6 HashSet (java.util.HashSet)4 Test (org.junit.Test)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 LinkedList (java.util.LinkedList)2 Produces (javax.ws.rs.Produces)2 Principal (org.candlepin.auth.Principal)2 UserPrincipal (org.candlepin.auth.UserPrincipal)2 OwnerPermission (org.candlepin.auth.permissions.OwnerPermission)2 Permission (org.candlepin.auth.permissions.Permission)2 UsernameConsumersPermission (org.candlepin.auth.permissions.UsernameConsumersPermission)2 NotFoundException (org.candlepin.common.exceptions.NotFoundException)2 Consumer (org.candlepin.model.Consumer)2 ConsumerType (org.candlepin.model.ConsumerType)2 Transactional (com.google.inject.persist.Transactional)1 Date (java.util.Date)1