Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 38444 invoked from network); 14 Jul 2009 11:40:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Jul 2009 11:40:22 -0000 Received: (qmail 74966 invoked by uid 500); 14 Jul 2009 11:39:12 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 74225 invoked by uid 500); 14 Jul 2009 11:39:10 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 73113 invoked by uid 99); 14 Jul 2009 11:36:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Jul 2009 11:36:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Jul 2009 11:36:05 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6EFA023888E2; Tue, 14 Jul 2009 11:35:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r793858 - in /sling/trunk/contrib/commons/classloader: ./ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/sling/ src/test/java/org/apache/sling/commons/ src/test/java/org/apache/sling/commons/c... Date: Tue, 14 Jul 2009 11:35:45 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090714113545.6EFA023888E2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Tue Jul 14 11:35:44 2009 New Revision: 793858 URL: http://svn.apache.org/viewvc?rev=793858&view=rev Log: Add simple junit test for dynamic class loading through package admin. Added: sling/trunk/contrib/commons/classloader/src/test/ sling/trunk/contrib/commons/classloader/src/test/java/ sling/trunk/contrib/commons/classloader/src/test/java/org/ sling/trunk/contrib/commons/classloader/src/test/java/org/apache/ sling/trunk/contrib/commons/classloader/src/test/java/org/apache/sling/ sling/trunk/contrib/commons/classloader/src/test/java/org/apache/sling/commons/ sling/trunk/contrib/commons/classloader/src/test/java/org/apache/sling/commons/classloader/ sling/trunk/contrib/commons/classloader/src/test/java/org/apache/sling/commons/classloader/impl/ sling/trunk/contrib/commons/classloader/src/test/java/org/apache/sling/commons/classloader/impl/ClassLoadingTest.java (with props) Modified: sling/trunk/contrib/commons/classloader/pom.xml Modified: sling/trunk/contrib/commons/classloader/pom.xml URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/classloader/pom.xml?rev=793858&r1=793857&r2=793858&view=diff ============================================================================== --- sling/trunk/contrib/commons/classloader/pom.xml (original) +++ sling/trunk/contrib/commons/classloader/pom.xml Tue Jul 14 11:35:44 2009 @@ -94,5 +94,14 @@ org.slf4j slf4j-api + + + junit + junit + + + org.jmock + jmock-junit4 + Added: sling/trunk/contrib/commons/classloader/src/test/java/org/apache/sling/commons/classloader/impl/ClassLoadingTest.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/commons/classloader/src/test/java/org/apache/sling/commons/classloader/impl/ClassLoadingTest.java?rev=793858&view=auto ============================================================================== --- sling/trunk/contrib/commons/classloader/src/test/java/org/apache/sling/commons/classloader/impl/ClassLoadingTest.java (added) +++ sling/trunk/contrib/commons/classloader/src/test/java/org/apache/sling/commons/classloader/impl/ClassLoadingTest.java Tue Jul 14 11:35:44 2009 @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.commons.classloader.impl; + +import junit.framework.Assert; + +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.jmock.Sequence; +import org.jmock.integration.junit4.JUnit4Mockery; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceListener; +import org.osgi.service.packageadmin.ExportedPackage; +import org.osgi.service.packageadmin.PackageAdmin; + +/** + * Simple test for the dynamic class loader. + */ +public class ClassLoadingTest { + + protected Mockery context; + + public ClassLoadingTest() { + this.context = new JUnit4Mockery(); + } + + /** + * This method tests the dynamic class loading through the package admin. + * The returned class changes from map to array list. + */ + @Test public void testLoading() throws Exception { + final Sequence sequence = this.context.sequence("load-sequence"); + final BundleContext bundleContext = this.context.mock(BundleContext.class); + final PackageAdmin packageAdmin = this.context.mock(PackageAdmin.class); + final ExportedPackage ep = this.context.mock(ExportedPackage.class); + final Bundle bundle = this.context.mock(Bundle.class); + this.context.checking(new Expectations() {{ + allowing(bundleContext).createFilter(with(any(String.class))); + will(returnValue(null)); + allowing(bundleContext).addServiceListener(with(any(ServiceListener.class)), with(any(String.class))); + allowing(bundleContext).removeServiceListener(with(any(ServiceListener.class))); + allowing(bundleContext).getServiceReferences(with(any(String.class)), with(any(String.class))); + will(returnValue(null)); + allowing(packageAdmin).getExportedPackage("org.apache.sling.test"); + will(returnValue(ep)); + allowing(ep).getExportingBundle(); + will(returnValue(bundle)); + one(bundle).loadClass("org.apache.sling.test.A"); inSequence(sequence); + will(returnValue(java.util.Map.class)); + one(bundle).loadClass("org.apache.sling.test.A"); inSequence(sequence); + will(returnValue(java.util.Map.class)); + one(bundle).loadClass("org.apache.sling.test.A"); inSequence(sequence); + will(returnValue(java.util.ArrayList.class)); + }}); + DynamicClassLoaderManagerImpl manager = new DynamicClassLoaderManagerImpl(bundleContext, packageAdmin); + final ClassLoader cl = manager.getDynamicClassLoader(); + final Class c1 = cl.loadClass("org.apache.sling.test.A"); + Assert.assertEquals("java.util.Map", c1.getName()); + final Class c2 = cl.loadClass("org.apache.sling.test.A"); + Assert.assertEquals("java.util.Map", c2.getName()); + final Class c3 = cl.loadClass("org.apache.sling.test.A"); + Assert.assertEquals("java.util.ArrayList", c3.getName()); + } +} Propchange: sling/trunk/contrib/commons/classloader/src/test/java/org/apache/sling/commons/classloader/impl/ClassLoadingTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/trunk/contrib/commons/classloader/src/test/java/org/apache/sling/commons/classloader/impl/ClassLoadingTest.java ------------------------------------------------------------------------------ svn:keywords = author date id revision rev url Propchange: sling/trunk/contrib/commons/classloader/src/test/java/org/apache/sling/commons/classloader/impl/ClassLoadingTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain