Search in sources :

Example 1 with Rules

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

the class RulesExporterTest method testMetaExporter.

@Test
public void testMetaExporter() throws IOException {
    RulesCurator rulesCurator = mock(RulesCurator.class);
    when(rulesCurator.getRules()).thenReturn(new Rules(FAKE_RULES));
    RulesExporter exporter = new RulesExporter(rulesCurator);
    StringWriter writer = new StringWriter();
    exporter.export(writer);
    assertEquals(FAKE_RULES, writer.toString());
}
Also used : RulesCurator(org.candlepin.model.RulesCurator) StringWriter(java.io.StringWriter) Rules(org.candlepin.model.Rules) Test(org.junit.Test)

Example 2 with Rules

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

the class InstalledProductStatusCalculatorTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    translator = new StandardTranslator(this.consumerTypeCurator, this.environmentCurator, this.ownerCurator);
    // Load the default production rules:
    InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
    Rules rules = new Rules(Util.readFile(is));
    Locale locale = new Locale("en_US");
    when(rulesCuratorMock.getUpdated()).thenReturn(new Date());
    when(rulesCuratorMock.getRules()).thenReturn(rules);
    when(cacheProvider.get()).thenReturn(cache);
    this.provider = new JsRunnerProvider(rulesCuratorMock, cacheProvider);
    i18n = I18nFactory.getI18n(getClass(), "org.candlepin.i18n.Messages", locale, I18nFactory.FALLBACK);
    RulesObjectMapper objectMapper = new RulesObjectMapper(new ProductCachedSerializationModule(productCurator));
    this.complianceRules = new ComplianceRules(provider.get(), this.entCurator, new StatusReasonMessageGenerator(i18n), eventSink, this.consumerCurator, this.consumerTypeCurator, objectMapper, translator);
    this.consumerEnricher = new ConsumerEnricher(this.complianceRules, this.ownerProductCurator);
}
Also used : Locale(java.util.Locale) ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) InputStream(java.io.InputStream) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) StatusReasonMessageGenerator(org.candlepin.policy.js.compliance.StatusReasonMessageGenerator) ComplianceRules(org.candlepin.policy.js.compliance.ComplianceRules) StandardTranslator(org.candlepin.dto.StandardTranslator) Rules(org.candlepin.model.Rules) ComplianceRules(org.candlepin.policy.js.compliance.ComplianceRules) Date(java.util.Date) Before(org.junit.Before)

Example 3 with Rules

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

the class StatusResourceTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    CandlepinModeChange mockModeChange = new CandlepinModeChange(new Date(), Mode.NORMAL, Reason.STARTUP);
    CandlepinQuery mockCPQuery = mock(CandlepinQuery.class);
    when(mockCPQuery.list()).thenReturn(new ArrayList<Rules>());
    when(rulesCurator.listAll()).thenReturn(mockCPQuery);
    when(rulesCurator.getRules()).thenReturn(new Rules("// Version: 2.0\nBLAH"));
    when(mockedStatusCache.getStatus()).thenReturn(null);
    when(candlepinCache.getStatusCache()).thenReturn(mockedStatusCache);
    when(modeManager.getLastCandlepinModeChange()).thenReturn(mockModeChange);
}
Also used : CandlepinQuery(org.candlepin.model.CandlepinQuery) CandlepinModeChange(org.candlepin.model.CandlepinModeChange) Rules(org.candlepin.model.Rules) Date(java.util.Date) Before(org.junit.Before)

Example 4 with Rules

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

the class ExporterTest method exportConsumer.

@Test
public void exportConsumer() throws ExportCreationException, IOException {
    config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
    config.setProperty(ConfigProperties.PREFIX_WEBURL, "localhost:8443/weburl");
    config.setProperty(ConfigProperties.PREFIX_APIURL, "localhost:8443/apiurl");
    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);
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
    ctype.setId("test-ctype");
    KeyPair keyPair = createKeyPair();
    when(consumer.getKeyPair()).thenReturn(keyPair);
    when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
    when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
    when(consumer.getUuid()).thenReturn("8auuid");
    when(consumer.getName()).thenReturn("consumer_name");
    when(consumer.getContentAccessMode()).thenReturn("access_mode");
    when(consumer.getTypeId()).thenReturn(ctype.getId());
    when(ctc.getConsumerType(eq(consumer))).thenReturn(ctype);
    when(ctc.find(eq(ctype.getId()))).thenReturn(ctype);
    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(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);
    verifyContent(export, "export/consumer.json", new VerifyConsumer("consumer.json"));
}
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 5 with Rules

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

the class ExporterTest method exportDistributorVersions.

@Test
public void exportDistributorVersions() throws ExportCreationException, IOException {
    config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
    config.setProperty(ConfigProperties.PREFIX_WEBURL, "localhost:8443/weburl");
    config.setProperty(ConfigProperties.PREFIX_APIURL, "localhost:8443/apiurl");
    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");
    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);
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
    ctype.setId("test-ctype");
    KeyPair keyPair = createKeyPair();
    when(consumer.getKeyPair()).thenReturn(keyPair);
    when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
    when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
    when(consumer.getUuid()).thenReturn("8auuid");
    when(consumer.getName()).thenReturn("consumer_name");
    when(consumer.getTypeId()).thenReturn(ctype.getId());
    when(ctc.getConsumerType(eq(consumer))).thenReturn(ctype);
    when(ctc.find(eq(ctype.getId()))).thenReturn(ctype);
    DistributorVersion dv = new DistributorVersion("test-dist-ver");
    Set<DistributorVersionCapability> dvcSet = new HashSet<>();
    dvcSet.add(new DistributorVersionCapability(dv, "capability-1"));
    dvcSet.add(new DistributorVersionCapability(dv, "capability-2"));
    dvcSet.add(new DistributorVersionCapability(dv, "capability-3"));
    dv.setCapabilities(dvcSet);
    List<DistributorVersion> dvList = new ArrayList<>();
    dvList.add(dv);
    when(dvc.findAll()).thenReturn(dvList);
    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);
    when(ctc.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);
    verifyContent(export, "export/distributor_version/test-dist-ver.json", new VerifyDistributorVersion("test-dist-ver.json"));
}
Also used : KeyPair(org.candlepin.model.KeyPair) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) 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) DistributorVersionCapability(org.candlepin.model.DistributorVersionCapability) ConsumerType(org.candlepin.model.ConsumerType) File(java.io.File) Principal(org.candlepin.auth.Principal) IdentityCertificate(org.candlepin.model.IdentityCertificate) DistributorVersion(org.candlepin.model.DistributorVersion) HashSet(java.util.HashSet) MockResultIterator(org.candlepin.test.MockResultIterator) Test(org.junit.Test)

Aggregations

Rules (org.candlepin.model.Rules)34 InputStream (java.io.InputStream)18 Date (java.util.Date)18 Test (org.junit.Test)15 Before (org.junit.Before)14 ProductCachedSerializationModule (org.candlepin.jackson.ProductCachedSerializationModule)9 Consumer (org.candlepin.model.Consumer)9 JsRunnerProvider (org.candlepin.policy.js.JsRunnerProvider)9 RulesObjectMapper (org.candlepin.policy.js.RulesObjectMapper)9 CandlepinQuery (org.candlepin.model.CandlepinQuery)8 ConsumerType (org.candlepin.model.ConsumerType)8 File (java.io.File)7 StandardTranslator (org.candlepin.dto.StandardTranslator)7 ExportRules (org.candlepin.policy.js.export.ExportRules)7 FileInputStream (java.io.FileInputStream)6 ZipInputStream (java.util.zip.ZipInputStream)6 Principal (org.candlepin.auth.Principal)6 CertificateSerial (org.candlepin.model.CertificateSerial)6 IdentityCertificate (org.candlepin.model.IdentityCertificate)6 MockResultIterator (org.candlepin.test.MockResultIterator)6