Return-Path: X-Original-To: apmail-aries-commits-archive@www.apache.org Delivered-To: apmail-aries-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2EF424825 for ; Wed, 15 Jun 2011 14:05:12 +0000 (UTC) Received: (qmail 27524 invoked by uid 500); 15 Jun 2011 14:05:12 -0000 Delivered-To: apmail-aries-commits-archive@aries.apache.org Received: (qmail 26822 invoked by uid 500); 15 Jun 2011 14:05:11 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 26804 invoked by uid 99); 15 Jun 2011 14:05:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Jun 2011 14:05:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Wed, 15 Jun 2011 14:05:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 96AFE2388A3B; Wed, 15 Jun 2011 14:04:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1136053 - in /aries/trunk/application: ./ application-modeller-common-test/ application-modeller-common-test/src/ application-modeller-common-test/src/test/ application-modeller-common-test/src/test/java/ application-modeller-common-test/s... Date: Wed, 15 Jun 2011 14:04:48 -0000 To: commits@aries.apache.org From: mahrwald@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110615140448.96AFE2388A3B@eris.apache.org> Author: mahrwald Date: Wed Jun 15 14:04:47 2011 New Revision: 1136053 URL: http://svn.apache.org/viewvc?rev=1136053&view=rev Log: ARIES-676: Common up tests between modeller projects Added: aries/trunk/application/application-modeller-common-test/ aries/trunk/application/application-modeller-common-test/pom.xml aries/trunk/application/application-modeller-common-test/src/ aries/trunk/application/application-modeller-common-test/src/test/ aries/trunk/application/application-modeller-common-test/src/test/java/ - copied from r1135727, aries/trunk/application/application-modeller/src/test/java/ aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/ModellerTest.java aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/impl/ParserProxyTest.java aries/trunk/application/application-modeller-common-test/src/test/resources/ - copied from r1135727, aries/trunk/application/application-modeller/src/test/resources/ aries/trunk/application/application-modeller-common-test/src/test/resources/test.bundle/ - copied from r1135728, aries/trunk/application/application-modeller-standalone/src/test/resources/test.bundle/ Removed: aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/impl/ParserProxyImplTest.java aries/trunk/application/application-modeller-standalone/src/test/ aries/trunk/application/application-modeller/src/test/java/ aries/trunk/application/application-modeller/src/test/resources/ Modified: aries/trunk/application/application-modeller-standalone/src/main/java/org/apache/aries/application/modelling/standalone/OfflineModellingFactory.java aries/trunk/application/pom.xml Added: aries/trunk/application/application-modeller-common-test/pom.xml URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller-common-test/pom.xml?rev=1136053&view=auto ============================================================================== --- aries/trunk/application/application-modeller-common-test/pom.xml (added) +++ aries/trunk/application/application-modeller-common-test/pom.xml Wed Jun 15 14:04:47 2011 @@ -0,0 +1,134 @@ + + + 4.0.0 + + org.apache.aries + java5-parent + 0.4 + + + + org.apache.aries.application + application-modeller-common-test + jar + Apache Aries Application Modelling tests + 0.3.1-SNAPSHOT + + Modelling utilities for working with Aries Applications (distribution for offline use). + + + + scm:svn:http://svn.apache.org/repos/asf/aries/trunk/application/application-modeller-common-test + scm:svn:https://svn.apache.org/repos/asf/aries/trunk/application/application-modeller-common-test + http://svn.apache.org/viewvc/aries/trunk/application/application-modeller-common-test + + + + + org.apache.aries.application + application-modeller-standalone + 0.3.1-SNAPSHOT + + + junit + junit + test + + + org.apache.aries + org.apache.aries.util + 0.4-SNAPSHOT + test + + + org.osgi + org.osgi.core + 4.2.0 + test + + + org.osgi + org.osgi.compendium + 4.2.0 + test + + + + org.apache.aries.application + org.apache.aries.application.api + 0.3.1-SNAPSHOT + + + org.apache.aries.application + org.apache.aries.application.modeller + 0.3.1-SNAPSHOT + + + org.apache.aries.blueprint + org.apache.aries.blueprint.core + + + + + org.apache.aries.application + org.apache.aries.application.utils + 0.3.1-SNAPSHOT + test + + + org.apache.aries.blueprint + org.apache.aries.blueprint.api + 0.3.2-SNAPSHOT + + + org.apache.aries.blueprint + blueprint-parser + 0.4-SNAPSHOT + + + org.slf4j + slf4j-api + test + + + org.slf4j + slf4j-simple + test + + + org.apache.aries.testsupport + org.apache.aries.testsupport.unit + test + 0.3 + + + org.apache.aries.blueprint + org.apache.aries.blueprint.core + 0.3.2-SNAPSHOT + + + org.apache.aries.proxy + org.apache.aries.proxy.api + + + + + + Added: aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/ModellerTest.java URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/ModellerTest.java?rev=1136053&view=auto ============================================================================== --- aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/ModellerTest.java (added) +++ aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/ModellerTest.java Wed Jun 15 14:04:47 2011 @@ -0,0 +1,92 @@ +package org.apache.aries.application.modelling; + +import java.io.File; +import java.net.URL; +import java.util.Arrays; +import java.util.List; + +import org.apache.aries.application.modelling.ExportedPackage; +import org.apache.aries.application.modelling.ImportedPackage; +import org.apache.aries.application.modelling.ImportedService; +import org.apache.aries.application.modelling.ModelledResource; +import org.apache.aries.application.modelling.ModelledResourceManager; +import org.apache.aries.application.modelling.impl.ModelledResourceManagerImpl; +import org.apache.aries.application.modelling.impl.ModellingManagerImpl; +import org.apache.aries.application.modelling.impl.ParserProxyTest; +import org.apache.aries.application.modelling.standalone.OfflineModellingFactory; +import org.apache.aries.mocks.BundleContextMock; +import org.apache.aries.util.filesystem.FileSystem; +import org.junit.AfterClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import static org.junit.Assert.*; + +@RunWith(Parameterized.class) +public class ModellerTest { + + @Parameters + public static List getDifferentModelledResourceManagers() { + ModelledResourceManagerImpl manager = new ModelledResourceManagerImpl(); + manager.setModellingManager(new ModellingManagerImpl()); + manager.setParserProxy(ParserProxyTest.getMockParserServiceProxy()); + + return Arrays.asList(new Object[][] { + {OfflineModellingFactory.getModelledResourceManager()}, + {manager} + }); + } + + @AfterClass + public static void cleanup() { + BundleContextMock.clear(); + } + + private final ModelledResourceManager sut; + + public ModellerTest(ModelledResourceManager sut) { + this.sut = sut; + } + + @Test + public void testParsingOfBundle() throws Exception { + URL pathToTestBundle = getClass().getClassLoader().getResource("test.bundle"); + + ModelledResource resource = sut.getModelledResource( + "file:///some.uri", + FileSystem.getFSRoot(new File(pathToTestBundle.toURI()))); + + assertNotNull(resource); + + // sanity check that we have parsed the manifest and package imports / exports + + assertEquals("test.bundle", resource.getSymbolicName()); + assertEquals("1.0.0", resource.getVersion()); + assertEquals(1, resource.getExportedPackages().size()); + assertEquals(3, resource.getImportedPackages().size()); + + ImportedPackage pack = resource.getImportedPackages().iterator().next(); + assertEquals("javax.jms", pack.getPackageName()); + assertEquals("1.1.0", pack.getVersionRange()); + + ExportedPackage epack = resource.getExportedPackages().iterator().next(); + assertEquals("wibble", epack.getPackageName()); + assertEquals("1.0.0", epack.getVersion()); + + assertEquals("true", epack.getAttributes().get("directive:")); + + + // sanity check that we have parsed the services + + assertEquals(3, resource.getExportedServices().size()); + assertEquals(1, resource.getImportedServices().size()); + + ImportedService service = resource.getImportedServices().iterator().next(); + assertEquals("foo.bar.MyInjectedService", service.getInterface()); + assertTrue(service.isOptional()); + assertFalse(service.isList()); + assertEquals("anOptionalReference", service.getId()); + } +} Added: aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/impl/ParserProxyTest.java URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/impl/ParserProxyTest.java?rev=1136053&view=auto ============================================================================== --- aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/impl/ParserProxyTest.java (added) +++ aries/trunk/application/application-modeller-common-test/src/test/java/org/apache/aries/application/modelling/impl/ParserProxyTest.java Wed Jun 15 14:04:47 2011 @@ -0,0 +1,244 @@ +/* + * 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 WARRANTIESOR 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.aries.application.modelling.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.aries.application.modelling.ModellingManager; +import org.apache.aries.application.modelling.ParsedServiceElements; +import org.apache.aries.application.modelling.ParserProxy; +import org.apache.aries.application.modelling.WrappedReferenceMetadata; +import org.apache.aries.application.modelling.WrappedServiceMetadata; +import org.apache.aries.application.modelling.standalone.OfflineModellingFactory; +import org.apache.aries.blueprint.container.NamespaceHandlerRegistry; +import org.apache.aries.blueprint.container.ParserServiceImpl; +import org.apache.aries.blueprint.namespace.NamespaceHandlerRegistryImpl; +import org.apache.aries.blueprint.services.ParserService; +import org.apache.aries.mocks.BundleContextMock; +import org.apache.aries.unittest.mocks.Skeleton; +import org.junit.AfterClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.osgi.framework.BundleContext; + +@RunWith(Parameterized.class) +public class ParserProxyTest { + + @Parameters + public static List parserProxies() { + return Arrays.asList(new Object[][] { + {getMockParserServiceProxy()}, + {OfflineModellingFactory.getOfflineParserProxy()}}); + } + + public static ParserProxy getMockParserServiceProxy() { + BundleContext mockCtx = Skeleton.newMock(new BundleContextMock(), BundleContext.class); + NamespaceHandlerRegistry nhri = new NamespaceHandlerRegistryImpl (mockCtx); + + ParserService parserService = new ParserServiceImpl(nhri); + mockCtx.registerService(ParserService.class.getName(), parserService, new Hashtable()); + + ParserProxyImpl parserProxyService = new ParserProxyImpl(); + parserProxyService.setParserService(parserService); + parserProxyService.setBundleContext(mockCtx); + parserProxyService.setModellingManager(new ModellingManagerImpl()); + + return parserProxyService; + } + + @AfterClass + public static void teardown() { + BundleContextMock.clear(); + } + + private final ModellingManager _modellingManager; + private final ParserProxy _parserProxy; + private final File resourceDir; + + public ParserProxyTest(ParserProxy sut) throws IOException { + _parserProxy = sut; + _modellingManager = new ModellingManagerImpl(); + + // make sure paths work in Eclipse as well as Maven + if (new File(".").getCanonicalFile().getName().equals("target")) { + resourceDir = new File("../src/test/resources"); + } else { + resourceDir = new File("src/test/resources"); + } + } + + + @Test + public void basicTest1() throws Exception { + File bpXml = new File (resourceDir, "appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp.xml"); + File bp2Xml = new File (resourceDir, "appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp2.xml"); + List urls = new ArrayList(); + urls.add ((bpXml.toURI()).toURL()); + urls.add ((bp2Xml.toURI()).toURL()); + + List results = _parserProxy.parse(urls); + assertTrue ("Four results expected, not " + results.size(), results.size() == 4); + + Set resultSet = new HashSet(results); + Set expectedResults = getTest1ExpectedResults(); + assertEquals ("Blueprint parsed xml is not as expected: " + resultSet.toString() + " != " + expectedResults, + resultSet, expectedResults); + } + + @Test + public void testParseAllServiceElements() throws Exception { + File bpXml = new File (resourceDir, "appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp.xml"); + File bp2Xml = new File (resourceDir, "appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp2.xml"); + + List services = new ArrayList(); + List references = new ArrayList(); + + FileInputStream fis = new FileInputStream (bpXml); + ParsedServiceElements bpelem = _parserProxy.parseAllServiceElements(fis); + services.addAll(bpelem.getServices()); + references.addAll(bpelem.getReferences()); + + fis = new FileInputStream (bp2Xml); + bpelem = _parserProxy.parseAllServiceElements(fis); + services.addAll(bpelem.getServices()); + references.addAll(bpelem.getReferences()); + + // We expect: + // bp.xml: 3 services and 2 references + // bp2.xml: 3 services and a reference list + // + assertTrue ("Six services expected, not " + services.size(), services.size() == 6); + assertTrue ("Three references expected, not " + references.size(), references.size() == 3); + + Set expectedServices = getTest2ExpectedServices(); + // ServiceResultSet will contain some services with autogenerated names starting '.' so we can't + // use a straight Set.equals(). We could add the autogenerated names to the expected results but instead + // let's test that differsOnlyByName() works + int serviceMatchesFound = 0; + for (WrappedServiceMetadata result : services) { + Iterator it = expectedServices.iterator(); + while (it.hasNext()) { + WrappedServiceMetadata next = it.next(); + if (result.equals(next) || result.identicalOrDiffersOnlyByName(next)) { + serviceMatchesFound++; + it.remove(); + } + } + } + + assertEquals ("Parsed services are wrong: " + expectedServices + " unmatched ", + 6, serviceMatchesFound); + + Set expectedReferences = getTest2ExpectedReferences(); + Set results = new HashSet(references); + assertTrue ("Parsed references are not as we'd expected: " + results.toString() + " != " + expectedReferences, + results.equals(expectedReferences)); + } + + @Test + public void checkMultiValues() throws Exception { + File bpXml = new File (resourceDir, "appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bpMultiValues.xml"); + List services = new ArrayList(); + FileInputStream fis = new FileInputStream (bpXml); + ParsedServiceElements bpelem = _parserProxy.parseAllServiceElements(fis); + services.addAll(bpelem.getServices()); + + assertEquals ("Multi valued service not parsed correctly", services.size(), 1); + + WrappedServiceMetadata wsm = services.get(0); + Map props = wsm.getServiceProperties(); + String [] intents = (String[]) props.get("service.intents"); + + assertEquals ("Service.intents[0] wrong", intents[0], "propagatesTransaction"); + assertEquals ("Service.intents[1] wrong", intents[1], "confidentiality"); + + } + + // model + // + // + // + private Set getTest2ExpectedReferences() throws Exception { + Set expectedResults = new HashSet(); + + expectedResults.add(_modellingManager.getImportedService(false, "foo.bar.MyInjectedService", null, + null, "fromOutside", false)); + expectedResults.add(_modellingManager.getImportedService(true, "foo.bar.MyInjectedService", null, + null, "anotherOptionalReference", false)); + expectedResults.add(_modellingManager.getImportedService(false, "my.logging.service", null, "(&(trace=on)(debug=true))", "refList1", true)); + + return expectedResults; + } + + // Test 2 includes anonymous services: the expected results are a superset of test1 + private Set getTest2ExpectedServices() { + Set expectedResults = getTest1ExpectedResults(); + + expectedResults.add(_modellingManager.getExportedService("", 0, Arrays.asList("foo.bar.AnonService"), null)); + expectedResults.add(_modellingManager.getExportedService("", 0, Arrays.asList("foo.bar.NamedInnerBeanService"), null)); + return expectedResults; + } + + private Set getTest1ExpectedResults() { + Set expectedResults = new HashSet(); + Map props = new HashMap(); + props.put ("priority", "9"); + props.put("volume", "11"); + props.put("osgi.service.blueprint.compname", "myBean"); + expectedResults.add(_modellingManager.getExportedService("myService", 0, Arrays.asList("foo.bar.MyService"), props)); + + props = new HashMap(); + props.put ("priority", "7"); + props.put ("volume", "11"); + props.put ("osgi.service.blueprint.compname", "bean1"); + expectedResults.add(_modellingManager.getExportedService("service1.should.be.exported", 0, Arrays.asList("foo.bar.MyService"), props)); + + props = new HashMap(); + props.put ("customer", "pig"); + props.put ("osgi.service.blueprint.compname", "bean2"); + expectedResults.add(_modellingManager.getExportedService("service2.should.not.be.exported", 0, Arrays.asList("com.acme.Delivery"), props)); + + props = new HashMap(); + props.put ("customer", "pig"); + props.put ("target", "rabbit"); + props.put ("payload", "excessive"); + props.put ("osgi.service.blueprint.compname", "bean3"); + expectedResults.add(_modellingManager.getExportedService("bean3", 0, Arrays.asList("com.acme.Delivery"), props)); + + return expectedResults; + } +} Modified: aries/trunk/application/application-modeller-standalone/src/main/java/org/apache/aries/application/modelling/standalone/OfflineModellingFactory.java URL: http://svn.apache.org/viewvc/aries/trunk/application/application-modeller-standalone/src/main/java/org/apache/aries/application/modelling/standalone/OfflineModellingFactory.java?rev=1136053&r1=1136052&r2=1136053&view=diff ============================================================================== --- aries/trunk/application/application-modeller-standalone/src/main/java/org/apache/aries/application/modelling/standalone/OfflineModellingFactory.java (original) +++ aries/trunk/application/application-modeller-standalone/src/main/java/org/apache/aries/application/modelling/standalone/OfflineModellingFactory.java Wed Jun 15 14:04:47 2011 @@ -11,6 +11,7 @@ import java.util.Set; import javax.xml.validation.Schema; import org.apache.aries.application.modelling.ModelledResourceManager; +import org.apache.aries.application.modelling.ParserProxy; import org.apache.aries.application.modelling.impl.AbstractParserProxy; import org.apache.aries.application.modelling.impl.ModelledResourceManagerImpl; import org.apache.aries.application.modelling.impl.ModellingManagerImpl; @@ -69,25 +70,34 @@ public class OfflineModellingFactory { private static class OfflineParserProxy extends AbstractParserProxy { - private final Parser parser = new Parser(); - protected ComponentDefinitionRegistry parseCDR(List blueprintsToParse) throws Exception { + Parser parser = new Parser(); parser.parse(blueprintsToParse); - return getCDR(); + return getCDR(parser); } protected ComponentDefinitionRegistry parseCDR(InputStream blueprintToParse) throws Exception { + Parser parser = new Parser(); parser.parse(blueprintToParse); - return getCDR(); + return getCDR(parser); } - private ComponentDefinitionRegistry getCDR() { + private ComponentDefinitionRegistry getCDR(Parser parser) { ComponentDefinitionRegistry cdr = new ComponentDefinitionRegistryImpl(); parser.populate(DUMMY_HANDLER_SET, cdr); return cdr; } }; + public static ParserProxy getOfflineParserProxy() { + ModellingManagerImpl modellingManager = new ModellingManagerImpl(); + + OfflineParserProxy parserProxy = new OfflineParserProxy(); + parserProxy.setModellingManager(modellingManager); + + return parserProxy; + } + public static ModelledResourceManager getModelledResourceManager() { ModellingManagerImpl modellingManager = new ModellingManagerImpl(); Modified: aries/trunk/application/pom.xml URL: http://svn.apache.org/viewvc/aries/trunk/application/pom.xml?rev=1136053&r1=1136052&r2=1136053&view=diff ============================================================================== --- aries/trunk/application/pom.xml (original) +++ aries/trunk/application/pom.xml Wed Jun 15 14:04:47 2011 @@ -46,6 +46,7 @@ application-management application-modeller application-modeller-standalone + application-modeller-common-test application-noop-resolver application-obr-resolver application-runtime