Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9297A200B41 for ; Thu, 7 Jul 2016 14:19:35 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 913DC160A68; Thu, 7 Jul 2016 12:19:35 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E0EED160A59 for ; Thu, 7 Jul 2016 14:19:34 +0200 (CEST) Received: (qmail 38641 invoked by uid 500); 7 Jul 2016 12:19:34 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 38630 invoked by uid 99); 7 Jul 2016 12:19:33 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jul 2016 12:19:33 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 871D6E03CE; Thu, 7 Jul 2016 12:19:33 +0000 (UTC) From: neykov To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #236: Adds OSGi classloading/rebind tests Content-Type: text/plain Message-Id: <20160707121933.871D6E03CE@git1-us-west.apache.org> Date: Thu, 7 Jul 2016 12:19:33 +0000 (UTC) archived-at: Thu, 07 Jul 2016 12:19:35 -0000 Github user neykov commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/236#discussion_r69895990 --- Diff: core/src/test/java/org/apache/brooklyn/util/core/ClassLoaderUtilsTest.java --- @@ -0,0 +1,158 @@ +/* + * 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.brooklyn.util.core; + +import static org.testng.Assert.assertEquals; + +import org.apache.brooklyn.api.entity.Entity; +import org.apache.brooklyn.api.mgmt.ManagementContext; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.mgmt.ha.OsgiManager; +import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; +import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; +import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest; +import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; +import org.apache.brooklyn.test.Asserts; +import org.apache.brooklyn.util.core.osgi.Osgis; +import org.apache.brooklyn.util.guava.Maybe; +import org.apache.brooklyn.util.osgi.OsgiTestResources; +import org.dom4j.tree.AbstractEntity; +import org.osgi.framework.Bundle; +import org.osgi.framework.launch.Framework; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class ClassLoaderUtilsTest { + + private LocalManagementContext mgmt; + + private String origWhiteListKey; + + @BeforeMethod(alwaysRun=true) + public void setUp() throws Exception { + origWhiteListKey = System.getProperty(ClassLoaderUtils.WHITE_LIST_KEY); + } + + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + if (origWhiteListKey != null) { + System.setProperty(ClassLoaderUtils.WHITE_LIST_KEY, origWhiteListKey); + } else { + System.clearProperty(ClassLoaderUtils.WHITE_LIST_KEY); + } + if (mgmt != null) { + Entities.destroyAll(mgmt); + } + } + + @Test + public void testLoadClassNotInOsgi() throws Exception { + ClassLoaderUtils clu = new ClassLoaderUtils(getClass()); + assertEquals(clu.loadClass(getClass().getName()), getClass()); + assertEquals(clu.loadClass(Entity.class.getName()), Entity.class); + assertEquals(clu.loadClass(AbstractEntity.class.getName()), AbstractEntity.class); + assertLoadFails(clu, "org.apache.brooklyn.this.name.does.not.Exist"); + } + + @Test + public void testLoadClassInOsgi() throws Exception { + String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; --- End diff -- Same here and following tests. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---