Search in sources :

Example 11 with ProductCachedSerializationModule

use of org.candlepin.jackson.ProductCachedSerializationModule in project candlepin by candlepin.

the class ActivationKeyRulesTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    Locale locale = new Locale("en_US");
    i18n = I18nFactory.getI18n(getClass(), "org.candlepin.i18n.Messages", locale, I18nFactory.FALLBACK);
    // Load the default production rules:
    InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
    Rules rules = new Rules(Util.readFile(is));
    when(rulesCuratorMock.getUpdated()).thenReturn(new Date());
    when(rulesCuratorMock.getRules()).thenReturn(rules);
    when(cacheProvider.get()).thenReturn(cache);
    provider = new JsRunnerProvider(rulesCuratorMock, cacheProvider);
    ProductCurator productCurator = mock(ProductCurator.class);
    translator = new StandardTranslator(mockConsumerTypeCurator, environmentCurator, mockOwnerCurator);
    actKeyRules = new ActivationKeyRules(provider.get(), i18n, new RulesObjectMapper(new ProductCachedSerializationModule(productCurator)), translator);
}
Also used : Locale(java.util.Locale) ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) InputStream(java.io.InputStream) ProductCurator(org.candlepin.model.ProductCurator) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) Rules(org.candlepin.model.Rules) StandardTranslator(org.candlepin.dto.StandardTranslator) Date(java.util.Date) Before(org.junit.Before)

Example 12 with ProductCachedSerializationModule

use of org.candlepin.jackson.ProductCachedSerializationModule in project candlepin by candlepin.

the class RulesObjectMapperTest method begin.

@Before
public void begin() {
    context = new HashMap<>();
    owner = new Owner("test");
    ProductCurator productCurator = Mockito.mock(ProductCurator.class);
    objMapper = new RulesObjectMapper(new ProductCachedSerializationModule(productCurator));
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) Owner(org.candlepin.model.Owner) ProductCurator(org.candlepin.model.ProductCurator) Before(org.junit.Before)

Example 13 with ProductCachedSerializationModule

use of org.candlepin.jackson.ProductCachedSerializationModule in project candlepin by candlepin.

the class ComplianceRulesTest method additivePropertiesCanStillDeserialize.

/*
     * Make sure additive properties coming back from the javascript do not break when
     * we deserialize.
     */
@Test
public void additivePropertiesCanStillDeserialize() {
    JsRunner mockRunner = mock(JsRunner.class);
    compliance = new ComplianceRules(mockRunner, entCurator, new StatusReasonMessageGenerator(i18n), eventSink, consumerCurator, consumerTypeCurator, new RulesObjectMapper(new ProductCachedSerializationModule(productCurator)), translator);
    when(mockRunner.runJsFunction(any(Class.class), eq("get_status"), any(JsContext.class))).thenReturn("{\"unknown\": \"thing\"}");
    Consumer c = mockConsumerWithTwoProductsAndNoEntitlements();
    // Nothing to assert here, we just need to see this return without error.
    compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) Consumer(org.candlepin.model.Consumer) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) JsContext(org.candlepin.policy.js.JsContext) JsRunner(org.candlepin.policy.js.JsRunner) Test(org.junit.Test)

Example 14 with ProductCachedSerializationModule

use of org.candlepin.jackson.ProductCachedSerializationModule in project candlepin by candlepin.

the class AutobindRulesTest method createEnforcer.

@Before
public void createEnforcer() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(config.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
    InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
    Rules rules = new Rules(Util.readFile(is));
    when(rulesCurator.getRules()).thenReturn(rules);
    when(rulesCurator.getUpdated()).thenReturn(TestDateUtil.date(2010, 1, 1));
    when(cacheProvider.get()).thenReturn(cache);
    JsRunner jsRules = new JsRunnerProvider(rulesCurator, cacheProvider).get();
    translator = new StandardTranslator(consumerTypeCurator, environmentCurator, mockOwnerCurator);
    autobindRules = new AutobindRules(jsRules, mockProductCurator, consumerTypeCurator, mockOwnerCurator, new RulesObjectMapper(new ProductCachedSerializationModule(mockProductCurator)), translator);
    owner = new Owner();
    owner.setId(TestUtil.randomString());
    when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
    ctype.setId("test-ctype");
    consumer = new Consumer("test consumer", "test user", owner, ctype);
    when(consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    when(consumerTypeCurator.lookupByLabel(eq(ctype.getLabel()))).thenReturn(ctype);
    when(consumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
    compliance = new ComplianceStatus();
    activeGuestAttrs = new HashMap<>();
    activeGuestAttrs.put("virtWhoType", "libvirt");
    activeGuestAttrs.put("active", "1");
}
Also used : Owner(org.candlepin.model.Owner) AutobindRules(org.candlepin.policy.js.autobind.AutobindRules) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) InputStream(java.io.InputStream) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) JsRunner(org.candlepin.policy.js.JsRunner) Rules(org.candlepin.model.Rules) AutobindRules(org.candlepin.policy.js.autobind.AutobindRules) StandardTranslator(org.candlepin.dto.StandardTranslator) ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) Consumer(org.candlepin.model.Consumer) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) ConsumerType(org.candlepin.model.ConsumerType) Before(org.junit.Before)

Example 15 with ProductCachedSerializationModule

use of org.candlepin.jackson.ProductCachedSerializationModule in project candlepin by candlepin.

the class JsonProviderTest method serializedDateDoesNotIncludeMilliseconds.

// This tests to see that the ObjectMapper serializes Date objects to the proper format
@Test
public void serializedDateDoesNotIncludeMilliseconds() throws JsonProcessingException {
    // will be initialized to when it was allocated with millisecond precision
    Date now = new Date();
    SimpleDateFormat iso8601WithoutMilliseconds = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    iso8601WithoutMilliseconds.setTimeZone(TimeZone.getTimeZone("UTC"));
    String expectedDate = "\"" + iso8601WithoutMilliseconds.format(now) + "\"";
    JsonProvider provider = new JsonProvider(config, new ProductCachedSerializationModule(productCurator));
    ObjectMapper mapper = provider.locateMapper(Object.class, MediaType.APPLICATION_JSON_TYPE);
    String serializedDate = mapper.writeValueAsString(now);
    assertTrue(serializedDate.equals(expectedDate));
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ProductCachedSerializationModule (org.candlepin.jackson.ProductCachedSerializationModule)26 Test (org.junit.Test)13 Before (org.junit.Before)12 PoolManager (org.candlepin.controller.PoolManager)10 Pool (org.candlepin.model.Pool)10 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)10 ActivationKeyCurator (org.candlepin.model.activationkeys.ActivationKeyCurator)10 ActivationKeyPool (org.candlepin.model.activationkeys.ActivationKeyPool)10 RulesObjectMapper (org.candlepin.policy.js.RulesObjectMapper)10 StandardTranslator (org.candlepin.dto.StandardTranslator)9 Rules (org.candlepin.model.Rules)9 JsRunnerProvider (org.candlepin.policy.js.JsRunnerProvider)9 InputStream (java.io.InputStream)8 Date (java.util.Date)7 Owner (org.candlepin.model.Owner)5 ProductCurator (org.candlepin.model.ProductCurator)5 JsRunner (org.candlepin.policy.js.JsRunner)4 Locale (java.util.Locale)3 Consumer (org.candlepin.model.Consumer)3 HashSet (java.util.HashSet)2