Search in sources :

Example 21 with ConsumerType

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

the class ExporterTest method exportIdentityCertificate.

@Test
public void exportIdentityCertificate() throws Exception {
    config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
    Rules mrules = mock(Rules.class);
    Consumer consumer = mock(Consumer.class);
    Principal principal = mock(Principal.class);
    when(mrules.getRules()).thenReturn("foobar");
    when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
    when(rc.getRules()).thenReturn(mrules);
    when(pprov.get()).thenReturn(principal);
    when(principal.getUsername()).thenReturn("testUser");
    // specific to this test
    IdentityCertificate idcert = new IdentityCertificate();
    idcert.setSerial(new CertificateSerial(10L, new Date()));
    idcert.setKey("euh0876puhapodifbvj094");
    idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
    idcert.setCreated(new Date());
    idcert.setUpdated(new Date());
    when(consumer.getIdCert()).thenReturn(idcert);
    KeyPair keyPair = createKeyPair();
    when(consumer.getKeyPair()).thenReturn(keyPair);
    when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
    when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    when(cqmock.iterator()).thenReturn(Arrays.asList(new ConsumerType("system")).iterator());
    when(ctc.listAll()).thenReturn(cqmock);
    CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class);
    when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator()));
    when(emptyIteratorMock.iterator()).thenReturn(Arrays.asList().iterator());
    when(cdnc.listAll()).thenReturn(emptyIteratorMock);
    // FINALLY test this badboy
    Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator);
    File export = e.getFullExport(consumer);
    // VERIFY
    assertNotNull(export);
    assertTrue(export.exists());
    verifyContent(export, "export/upstream_consumer/10.pem", new VerifyIdentityCert("10.pem"));
}
Also used : KeyPair(org.candlepin.model.KeyPair) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CertificateSerial(org.candlepin.model.CertificateSerial) CandlepinQuery(org.candlepin.model.CandlepinQuery) Rules(org.candlepin.model.Rules) ExportRules(org.candlepin.policy.js.export.ExportRules) Date(java.util.Date) Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType) File(java.io.File) Principal(org.candlepin.auth.Principal) IdentityCertificate(org.candlepin.model.IdentityCertificate) MockResultIterator(org.candlepin.test.MockResultIterator) Test(org.junit.Test)

Example 22 with ConsumerType

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

the class DatabaseTestFixture method createConsumerType.

protected ConsumerType createConsumerType(String label, boolean manifest) {
    ConsumerType ctype = new ConsumerType(label);
    ctype.setManifest(manifest);
    return this.consumerTypeCurator.create(ctype);
}
Also used : ConsumerType(org.candlepin.model.ConsumerType)

Example 23 with ConsumerType

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

the class DatabaseTestFixture method createDistributor.

protected Consumer createDistributor(Owner owner) {
    ConsumerType type = this.createConsumerType(true);
    Consumer consumer = new Consumer("test-distributor", "test-user", owner, type);
    return this.consumerCurator.create(consumer);
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType)

Example 24 with ConsumerType

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

the class ConsumerTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public ConsumerDTO populate(ModelTranslator translator, Consumer source, ConsumerDTO dest) {
    if (source == null) {
        throw new IllegalArgumentException("source is null");
    }
    if (dest == null) {
        throw new IllegalArgumentException("destination is null");
    }
    dest.setUuid(source.getUuid()).setName(source.getName()).setContentAccessMode(source.getContentAccessMode());
    // Process nested objects if we have a ModelTranslator to use to the translation...
    if (translator != null) {
        if (source.getOwnerId() != null) {
            Owner owner = this.ownerCurator.findOwnerById(source.getOwnerId());
            dest.setOwner(owner != null ? translator.translate(owner, OwnerDTO.class) : null);
        }
        // Temporary measure to maintain API compatibility
        if (source.getTypeId() != null) {
            ConsumerType ctype = this.consumerTypeCurator.getConsumerType(source);
            dest.setType(translator.translate(ctype, ConsumerTypeDTO.class));
        } else {
            dest.setType(null);
        }
    } else {
        dest.setOwner(null);
        dest.setType(null);
    }
    return dest;
}
Also used : Owner(org.candlepin.model.Owner) ConsumerType(org.candlepin.model.ConsumerType)

Example 25 with ConsumerType

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

the class ConsumerTypeTranslatorTest method initSourceObject.

@Override
public ConsumerType initSourceObject() {
    ConsumerType type = new ConsumerType();
    type.setId("test_id");
    type.setLabel("type_label");
    type.setManifest(true);
    return type;
}
Also used : ConsumerType(org.candlepin.model.ConsumerType)

Aggregations

ConsumerType (org.candlepin.model.ConsumerType)169 Consumer (org.candlepin.model.Consumer)92 Test (org.junit.Test)71 Owner (org.candlepin.model.Owner)53 Pool (org.candlepin.model.Pool)47 Entitlement (org.candlepin.model.Entitlement)33 ArrayList (java.util.ArrayList)29 Date (java.util.Date)27 HashMap (java.util.HashMap)24 HashSet (java.util.HashSet)24 ValidationResult (org.candlepin.policy.ValidationResult)22 ApiOperation (io.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Before (org.junit.Before)20 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)18 LinkedList (java.util.LinkedList)16 BadRequestException (org.candlepin.common.exceptions.BadRequestException)16 DeletedConsumer (org.candlepin.model.DeletedConsumer)16 Matchers.anyString (org.mockito.Matchers.anyString)16