new Date());
UserManager userManager = mock(UserManager.class);
when(userManager.getUser("john")).thenReturn(user);
DistributionSpecification aaplOnBloomberg = new DistributionSpecification(
ExternalId.of("BLOOMBERG_BUID", "EQ12345"),
StandardRules.getNoNormalization(),
"LiveData.Bloomberg.Equity.AAPL");
DistributionSpecification aaplOnBloombergWithNormalization = new DistributionSpecification(
ExternalId.of("BLOOMBERG_BUID", "EQ12345"),
new NormalizationRuleSet("MyWeirdNormalizationRule"),
"LiveData.Bloomberg.Equity.AAPL.MyWeirdNormalizationRule");
DistributionSpecification bondOnBloomberg = new DistributionSpecification(
ExternalId.of("BLOOMBERG_BUID", "BOND12345"),
StandardRules.getNoNormalization(),
"LiveData.Bloomberg.Bond.IBMBOND123");
DistributionSpecification bondOnBloombergWithNormalization = new DistributionSpecification(
ExternalId.of("BLOOMBERG_BUID", "BOND12345"),
new NormalizationRuleSet("MyWeirdNormalizationRule"),
"LiveData.Bloomberg.Bond.IBMBOND123.MyWeirdNormalizationRule");
DistributionSpecification fxOnBloomberg = new DistributionSpecification(
ExternalId.of("BLOOMBERG_BUID", "FX12345"),
StandardRules.getNoNormalization(),
"LiveData.Bloomberg.FX.EURUSD");
DistributionSpecification fxOnBloombergWithNormalization = new DistributionSpecification(
ExternalId.of("BLOOMBERG_BUID", "FX12345"),
new NormalizationRuleSet("MyWeirdNormalizationRule"),
"LiveData.Bloomberg.FX.EURUSD.MyWeirdNormalizationRule");
Map<LiveDataSpecification, DistributionSpecification> fixes = new HashMap<LiveDataSpecification, DistributionSpecification>();
fixes.put(aaplOnBloomberg.getFullyQualifiedLiveDataSpecification(), aaplOnBloomberg);
fixes.put(aaplOnBloombergWithNormalization.getFullyQualifiedLiveDataSpecification(), aaplOnBloombergWithNormalization);
fixes.put(bondOnBloomberg.getFullyQualifiedLiveDataSpecification(), bondOnBloomberg);
fixes.put(bondOnBloombergWithNormalization.getFullyQualifiedLiveDataSpecification(), bondOnBloombergWithNormalization);
fixes.put(fxOnBloomberg.getFullyQualifiedLiveDataSpecification(), fxOnBloomberg);
fixes.put(fxOnBloombergWithNormalization.getFullyQualifiedLiveDataSpecification(), fxOnBloombergWithNormalization);
FixedDistributionSpecificationResolver resolver = new FixedDistributionSpecificationResolver(fixes);
LiveDataEntitlementChecker userEntitlementChecker = new UserEntitlementChecker(userManager, resolver);
UserPrincipal john = new UserPrincipal("john", "127.0.0.1");
AssertJUnit.assertTrue(userEntitlementChecker.isEntitled(john, aaplOnBloomberg.getFullyQualifiedLiveDataSpecification()));
AssertJUnit.assertTrue(userEntitlementChecker.isEntitled(john, aaplOnBloombergWithNormalization.getFullyQualifiedLiveDataSpecification()));
AssertJUnit.assertTrue(userEntitlementChecker.isEntitled(john, bondOnBloomberg.getFullyQualifiedLiveDataSpecification()));
AssertJUnit.assertFalse(userEntitlementChecker.isEntitled(john, bondOnBloombergWithNormalization.getFullyQualifiedLiveDataSpecification()));
AssertJUnit.assertFalse(userEntitlementChecker.isEntitled(john, fxOnBloomberg.getFullyQualifiedLiveDataSpecification()));
AssertJUnit.assertFalse(userEntitlementChecker.isEntitled(john, fxOnBloombergWithNormalization.getFullyQualifiedLiveDataSpecification()));
// non-existent user
UserPrincipal mike = new UserPrincipal("mike", "127.0.0.1");
AssertJUnit.assertFalse(userEntitlementChecker.isEntitled(mike, aaplOnBloomberg.getFullyQualifiedLiveDataSpecification()));
AssertJUnit.assertFalse(userEntitlementChecker.isEntitled(mike, fxOnBloomberg.getFullyQualifiedLiveDataSpecification()));