use of javax.naming.CompositeName in project uPortal by Jasig.
the class JpaBaseAggregationDaoTest method testBaseAggregationLifecycle.
@Test
public final void testBaseAggregationLifecycle() throws Exception {
final IEntityGroup entityGroupA = mock(IEntityGroup.class);
when(entityGroupA.getServiceName()).thenReturn(new CompositeName("local"));
when(entityGroupA.getName()).thenReturn("Group A");
when(compositeGroupService.findGroup("local.0")).thenReturn(entityGroupA);
final IEntityGroup entityGroupB = mock(IEntityGroup.class);
when(entityGroupB.getServiceName()).thenReturn(new CompositeName("local"));
when(entityGroupB.getName()).thenReturn("Group B");
when(compositeGroupService.findGroup("local.1")).thenReturn(entityGroupB);
final DateTime instant = // just a random time
new DateTime(1326734644000l, DateTimeZone.UTC);
// Create required date and time dimensions
populateDateTimeDimensions(instant.minusHours(2), instant.plusHours(2), null);
// Create aggregations
final Map<K, T> createdAggrs = this.executeInTransaction(new Callable<Map<K, T>>() {
@Override
public Map<K, T> call() throws Exception {
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1");
final AggregationIntervalInfo fiveMinuteInfo = aggregationIntervalHelper.getIntervalInfo(AggregationInterval.FIVE_MINUTE, instant);
final AggregationIntervalInfo hourInfo = aggregationIntervalHelper.getIntervalInfo(AggregationInterval.HOUR, instant);
final Map<K, T> fiveMinGroupA = createAggregations(fiveMinuteInfo, groupA);
final Map<K, T> fiveMinGroupB = createAggregations(fiveMinuteInfo, groupB);
final Map<K, T> hourGroupA = createAggregations(hourInfo, groupA);
final Map<K, T> aggrs = new HashMap<K, T>(fiveMinGroupA);
aggrs.putAll(fiveMinGroupB);
aggrs.putAll(hourGroupA);
return aggrs;
}
});
// Verify aggregations were created
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregationIntervalInfo fiveMinuteInfo = aggregationIntervalHelper.getIntervalInfo(AggregationInterval.FIVE_MINUTE, instant);
final AggregationIntervalInfo hourInfo = aggregationIntervalHelper.getIntervalInfo(AggregationInterval.HOUR, instant);
final Map<K, T> fiveMinGroup = getAggregationDao().getAggregationsForInterval(fiveMinuteInfo.getDateDimension(), fiveMinuteInfo.getTimeDimension(), fiveMinuteInfo.getAggregationInterval());
final Map<K, T> hourGroup = getAggregationDao().getAggregationsForInterval(hourInfo.getDateDimension(), hourInfo.getTimeDimension(), hourInfo.getAggregationInterval());
final Map<K, T> foundAggrs = new HashMap<K, T>(fiveMinGroup);
foundAggrs.putAll(hourGroup);
assertEquals("Aggregations not created as expected", createdAggrs, foundAggrs);
}
});
// Update Aggregations
final Map<K, T> updatedAggrs = this.executeInTransaction(new Callable<Map<K, T>>() {
@Override
public Map<K, T> call() throws Exception {
final Random r = new Random(0);
final AggregationIntervalInfo fiveMinuteInfo = aggregationIntervalHelper.getIntervalInfo(AggregationInterval.FIVE_MINUTE, instant);
final AggregationIntervalInfo hourInfo = aggregationIntervalHelper.getIntervalInfo(AggregationInterval.HOUR, instant);
final Map<K, T> fiveMinGroup = getAggregationDao().getAggregationsForInterval(fiveMinuteInfo.getDateDimension(), fiveMinuteInfo.getTimeDimension(), fiveMinuteInfo.getAggregationInterval());
final Map<K, T> hourGroup = getAggregationDao().getAggregationsForInterval(hourInfo.getDateDimension(), hourInfo.getTimeDimension(), hourInfo.getAggregationInterval());
final Map<K, T> updatedAggrs = new HashMap<K, T>();
for (final Entry<K, T> aggrEntry : fiveMinGroup.entrySet()) {
final T aggr = aggrEntry.getValue();
updateAggregation(fiveMinuteInfo, aggr, r);
getAggregationDao().updateAggregation(aggr);
updatedAggrs.put(aggrEntry.getKey(), aggr);
}
for (final Entry<K, T> aggrEntry : hourGroup.entrySet()) {
final T aggr = aggrEntry.getValue();
updateAggregation(hourInfo, aggr, r);
getAggregationDao().updateAggregation(aggr);
updatedAggrs.put(aggrEntry.getKey(), aggr);
}
return updatedAggrs;
}
});
// Verify aggregations were updated
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregationIntervalInfo fiveMinuteInfo = aggregationIntervalHelper.getIntervalInfo(AggregationInterval.FIVE_MINUTE, instant);
final AggregationIntervalInfo hourInfo = aggregationIntervalHelper.getIntervalInfo(AggregationInterval.HOUR, instant);
final Map<K, T> fiveMinGroup = getAggregationDao().getAggregationsForInterval(fiveMinuteInfo.getDateDimension(), fiveMinuteInfo.getTimeDimension(), fiveMinuteInfo.getAggregationInterval());
final Map<K, T> hourGroup = getAggregationDao().getAggregationsForInterval(hourInfo.getDateDimension(), hourInfo.getTimeDimension(), hourInfo.getAggregationInterval());
final Map<K, T> foundAggrs = new HashMap<K, T>(fiveMinGroup);
foundAggrs.putAll(hourGroup);
assertEquals("Aggregations not updated as expected", updatedAggrs, foundAggrs);
}
});
// Complete intervals
final Map<K, T> completeAggrs = this.executeInTransaction(new Callable<Map<K, T>>() {
@Override
public Map<K, T> call() throws Exception {
final AggregationIntervalInfo fiveMinuteInfo = aggregationIntervalHelper.getIntervalInfo(AggregationInterval.FIVE_MINUTE, instant);
final AggregationIntervalInfo hourInfo = aggregationIntervalHelper.getIntervalInfo(AggregationInterval.HOUR, instant);
final Map<K, T> fiveMinGroup = getAggregationDao().getAggregationsForInterval(fiveMinuteInfo.getDateDimension(), fiveMinuteInfo.getTimeDimension(), fiveMinuteInfo.getAggregationInterval());
final Map<K, T> hourGroup = getAggregationDao().getAggregationsForInterval(hourInfo.getDateDimension(), hourInfo.getTimeDimension(), hourInfo.getAggregationInterval());
final Map<K, T> completeAggrs = new HashMap<K, T>();
for (final Entry<K, T> aggrEntry : fiveMinGroup.entrySet()) {
final T aggr = aggrEntry.getValue();
aggr.intervalComplete(5);
getAggregationDao().updateAggregation(aggr);
completeAggrs.put(aggrEntry.getKey(), aggr);
}
for (final Entry<K, T> aggrEntry : hourGroup.entrySet()) {
final T aggr = aggrEntry.getValue();
aggr.intervalComplete(60);
getAggregationDao().updateAggregation(aggr);
completeAggrs.put(aggrEntry.getKey(), aggr);
}
return completeAggrs;
}
});
// Verify aggregations were completed
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final AggregationIntervalInfo fiveMinuteInfo = aggregationIntervalHelper.getIntervalInfo(AggregationInterval.FIVE_MINUTE, instant);
final AggregationIntervalInfo hourInfo = aggregationIntervalHelper.getIntervalInfo(AggregationInterval.HOUR, instant);
final Map<K, T> fiveMinGroup = getAggregationDao().getAggregationsForInterval(fiveMinuteInfo.getDateDimension(), fiveMinuteInfo.getTimeDimension(), fiveMinuteInfo.getAggregationInterval());
final Map<K, T> hourGroup = getAggregationDao().getAggregationsForInterval(hourInfo.getDateDimension(), hourInfo.getTimeDimension(), hourInfo.getAggregationInterval());
final Map<K, T> foundAggrs = new HashMap<K, T>(fiveMinGroup);
foundAggrs.putAll(hourGroup);
assertEquals("Aggregations not completed as expected", completeAggrs, foundAggrs);
}
});
}
use of javax.naming.CompositeName in project uPortal by Jasig.
the class JpaEventSessionDaoTest method testEventSessionDao.
@Test
public void testEventSessionDao() throws Exception {
final IEntityGroup everyoneGroup = mock(IEntityGroup.class);
when(everyoneGroup.getServiceName()).thenReturn(new CompositeName("local"));
when(everyoneGroup.getName()).thenReturn("Everyone");
when(compositeGroupService.findGroup("local.0")).thenReturn(everyoneGroup);
final IEntityGroup adminGroup = mock(IEntityGroup.class);
when(adminGroup.getServiceName()).thenReturn(new CompositeName("local"));
when(adminGroup.getName()).thenReturn("Admins");
when(compositeGroupService.findGroup("local.1")).thenReturn(adminGroup);
final IPerson person = mock(IPerson.class);
//
// Example event session "1234567890_abcdefg";
final int EVENT_SESSION_LENGTH = 17;
final int EVENT_SESSION_HYPHEN_LENGTH = 10;
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
DateTime timeStamp = null;
for (int i = 0; i <= 100; i++) {
String sessionId = UUID.randomUUID().toString().replaceAll("[\\s\\-()]", "").substring(0, EVENT_SESSION_LENGTH - 1);
sessionId = sessionId.substring(0, 10) + "_" + sessionId.substring(EVENT_SESSION_HYPHEN_LENGTH, sessionId.length());
LoginEvent loginEvent = TestEventFactory.newLoginEvent(this, "testServer", sessionId, person, ImmutableSet.<String>of("local.0", "local.1"), Collections.<String, List<String>>emptyMap());
final EventSession eventSession = eventSessionDao.getEventSession(loginEvent);
assertNotNull(eventSession);
assertEquals(sessionId, eventSession.getEventSessionId());
final Set<AggregatedGroupMapping> groupMappings = eventSession.getGroupMappings();
assertEquals(2, groupMappings.size());
timeStamp = loginEvent.getTimestampAsDate();
}
eventSessionDao.purgeEventSessionsBefore(timeStamp.plusYears(1));
}
});
}
use of javax.naming.CompositeName in project jdk8u_jdk by JetBrains.
the class DirContextStringPair method getTargetContext.
protected DirContextNamePair getTargetContext(Name name) throws NamingException {
if (cpe.getResolvedObj() == null)
throw (NamingException) cpe.fillInStackTrace();
Context ctx = NamingManager.getContext(cpe.getResolvedObj(), cpe.getAltName(), cpe.getAltNameCtx(), env);
if (ctx == null)
throw (NamingException) cpe.fillInStackTrace();
if (ctx instanceof DirContext)
return new DirContextNamePair((DirContext) ctx, name);
if (ctx instanceof Resolver) {
Resolver res = (Resolver) ctx;
ResolveResult rr = res.resolveToClass(name, DirContext.class);
// Reached a DirContext; return result.
DirContext dctx = (DirContext) rr.getResolvedObj();
return (new DirContextNamePair(dctx, rr.getRemainingName()));
}
// Resolve all the way using lookup(). This may allow the operation
// to succeed if it doesn't require the penultimate context.
Object ultimate = ctx.lookup(name);
if (ultimate instanceof DirContext) {
return (new DirContextNamePair((DirContext) ultimate, new CompositeName()));
}
throw (NamingException) cpe.fillInStackTrace();
}
use of javax.naming.CompositeName in project kernel by exoplatform.
the class InitialContextTest method testCompositeNameUsing.
public void testCompositeNameUsing() throws Exception {
Name name = new CompositeName("java:comp/env/jdbc/jcr");
Enumeration en = name.getAll();
while (en.hasMoreElements()) {
en.nextElement();
}
InitialContext ctx = new InitialContext();
ctx.bind(name, "foo");
assertEquals("foo", ctx.lookup(name));
try {
ctx.bind(name, "foo2");
fail("A NameAlreadyBoundException is expected here");
} catch (NameAlreadyBoundException e) {
// expected exception
}
assertEquals("foo", ctx.lookup(name));
assertEquals("foo", ctx.lookup("java:comp/env/jdbc/jcr"));
ctx.unbind(name);
try {
ctx.lookup(name);
fail("A NameNotFoundException is expected here");
} catch (NameNotFoundException e) {
// expected exception
}
}
use of javax.naming.CompositeName in project tomee by apache.
the class IvmContext method federate.
protected Object federate(final String compositName) throws NamingException {
final ObjectFactory[] factories = getFederatedFactories();
for (final ObjectFactory factory : factories) {
try {
final CompositeName name = new CompositeName(compositName);
final Object obj = factory.getObjectInstance(null, name, null, null);
if (obj instanceof Context) {
return ((Context) obj).lookup(compositName);
} else if (obj != null) {
return obj;
}
} catch (final Exception doNothing) {
// no-op
}
}
throw new NameNotFoundException("Name \"" + compositName + "\" not found.");
}
Aggregations