Search in sources :

Example 46 with CompositeName

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);
        }
    });
}
Also used : CompositeName(javax.naming.CompositeName) DateTime(org.joda.time.DateTime) CallableWithoutResult(org.apereo.portal.concurrency.CallableWithoutResult) IEntityGroup(org.apereo.portal.groups.IEntityGroup) AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) Entry(java.util.Map.Entry) Random(java.util.Random) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Test(org.junit.Test) BaseAggrEventsJpaDaoTest(org.apereo.portal.test.BaseAggrEventsJpaDaoTest)

Example 47 with CompositeName

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));
        }
    });
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IPerson(org.apereo.portal.security.IPerson) ImmutableSet(com.google.common.collect.ImmutableSet) CompositeName(javax.naming.CompositeName) LoginEvent(org.apereo.portal.events.LoginEvent) DateTime(org.joda.time.DateTime) CallableWithoutResult(org.apereo.portal.concurrency.CallableWithoutResult) Test(org.junit.Test) BaseAggrEventsJpaDaoTest(org.apereo.portal.test.BaseAggrEventsJpaDaoTest)

Example 48 with CompositeName

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();
}
Also used : DirContext(javax.naming.directory.DirContext) Context(javax.naming.Context) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) DirContext(javax.naming.directory.DirContext)

Example 49 with CompositeName

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
    }
}
Also used : NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) Enumeration(java.util.Enumeration) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) InitialContext(javax.naming.InitialContext) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 50 with CompositeName

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.");
}
Also used : Context(javax.naming.Context) ObjectFactory(javax.naming.spi.ObjectFactory) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) FileNotFoundException(java.io.FileNotFoundException) ObjectStreamException(java.io.ObjectStreamException) OperationNotSupportedException(javax.naming.OperationNotSupportedException)

Aggregations

CompositeName (javax.naming.CompositeName)124 Test (org.junit.Test)69 Name (javax.naming.Name)43 NameNotFoundException (javax.naming.NameNotFoundException)27 NamingException (javax.naming.NamingException)25 Reference (javax.naming.Reference)19 Context (javax.naming.Context)18 InvalidNameException (javax.naming.InvalidNameException)13 NotContextException (javax.naming.NotContextException)12 ServiceName (org.jboss.msc.service.ServiceName)11 Test (org.junit.jupiter.api.Test)10 JndiPermission (org.wildfly.naming.java.permission.JndiPermission)10 Hashtable (java.util.Hashtable)9 Binding (javax.naming.Binding)8 LinkRef (javax.naming.LinkRef)8 OperationNotSupportedException (javax.naming.OperationNotSupportedException)8 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)7 IEntityGroup (org.apereo.portal.groups.IEntityGroup)7 BaseAggrEventsJpaDaoTest (org.apereo.portal.test.BaseAggrEventsJpaDaoTest)7 StringRefAddr (javax.naming.StringRefAddr)5