This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 8ead72f3d5b00fb6545c6c5eb785ecb3632481c2 Author: Alex Heneveld <[email protected]> AuthorDate: Thu Oct 1 23:25:34 2020 +0100 add JAR with bean and failing test case the problem is that we aren't passing the loader to the bean deserializer, so it isn't looking in the right osgi bundles --- .../brooklyn/CustomTypeConfigYamlOsgiTest.java | 22 ++++++ utils/common/dependencies/osgi/beans/pom.xml | 84 +++++++++++++++++++++ .../org/apache/brooklyn/test/osgi/SampleBean.java | 26 +++++++ .../osgi/beans/src/main/resources/catalog.bom | 24 ++++++ .../brooklyn/util/osgi/OsgiTestResources.java | 6 +- .../brooklyn/osgi/brooklyn-test-osgi-beans.jar | Bin 0 -> 11696 bytes .../brooklyn/osgi/brooklyn-test-osgi-beans.txt | 26 +++++++ 7 files changed, 187 insertions(+), 1 deletion(-) diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlOsgiTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlOsgiTest.java index b118aa1..b71760a 100644 --- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlOsgiTest.java +++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlOsgiTest.java @@ -25,6 +25,8 @@ import org.apache.brooklyn.api.typereg.RegisteredType; import org.apache.brooklyn.config.ConfigKey; import org.apache.brooklyn.core.config.ConfigKeys; import org.apache.brooklyn.core.entity.Dumper; +import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult; +import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; import org.apache.brooklyn.core.resolve.jackson.BeanWithTypePlanTransformer; import org.apache.brooklyn.core.test.entity.TestEntity; import org.apache.brooklyn.core.typereg.BasicBrooklynTypeRegistry; @@ -32,6 +34,9 @@ import org.apache.brooklyn.core.typereg.BasicTypeImplementationPlan; import org.apache.brooklyn.core.typereg.JavaClassNameTypePlanTransformer; import org.apache.brooklyn.core.typereg.RegisteredTypes; import org.apache.brooklyn.test.Asserts; +import org.apache.brooklyn.util.core.ResourceUtils; +import org.apache.brooklyn.util.exceptions.ReferenceWithError; +import org.apache.brooklyn.util.osgi.OsgiTestResources; import org.apache.brooklyn.util.text.Strings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,4 +51,21 @@ public class CustomTypeConfigYamlOsgiTest extends CustomTypeConfigYamlTest { protected boolean disableOsgi() { return false; } + + @Test + public void testLoadBundleBom() throws NoSuchFieldException, IllegalAccessException { + ReferenceWithError<OsgiBundleInstallationResult> result = ((ManagementContextInternal) mgmt()).getOsgiManager().get().install( + new ResourceUtils(getClass()).getResourceFromUrl(OsgiTestResources.BROOKLYN_TEST_OSGI_BEANS_URL)); + + OsgiBundleInstallationResult r = result.getWithError(); + RegisteredType rt = r.getTypesInstalled().stream().filter(rti -> "sampleBean".equals(rti.getId())).findAny() + .orElseThrow(() -> { + throw Asserts.fail("Bean not found; RTs were: " + r.getTypesInstalled()); + }); + Asserts.assertEquals(rt.getKind(), RegisteredTypeKind.BEAN); + + Object b1 = mgmt().getTypeRegistry().create(rt, null, null); + Object b1n = b1.getClass().getField("number").get(b1); + Asserts.assertEquals(b1n, 1); + } } diff --git a/utils/common/dependencies/osgi/beans/pom.xml b/utils/common/dependencies/osgi/beans/pom.xml new file mode 100644 index 0000000..cad4da6 --- /dev/null +++ b/utils/common/dependencies/osgi/beans/pom.xml @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <packaging>jar</packaging> + + <groupId>org.apache.brooklyn.test.resources.osgi</groupId> + <artifactId>brooklyn-test-osgi-beans</artifactId> + <version>0.1.0</version> + + <name>OSGi bundled test beans</name> + + <description> + Simple beans for testing the OSGi functionality + </description> + + <parent> + <groupId>org.apache.brooklyn</groupId> + <artifactId>brooklyn-parent</artifactId> + <version>1.1.0-SNAPSHOT</version><!-- BROOKLYN_VERSION --> + <relativePath>../../../../../../../parent/pom.xml</relativePath> + </parent> + <dependencies> + <dependency> + <groupId>org.apache.brooklyn</groupId> + <artifactId>brooklyn-core</artifactId> + <version>${brooklyn.version}</version> + </dependency> + <dependency> + <groupId>org.apache.brooklyn</groupId> + <artifactId>brooklyn-api</artifactId> + <version>${brooklyn.version}</version> + </dependency> + <dependency> + <groupId>org.apache.brooklyn</groupId> + <artifactId>brooklyn-utils-common</artifactId> + <version>${brooklyn.version}</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <outputDirectory>../../../src/test/resources/brooklyn/osgi</outputDirectory> + <finalName>brooklyn-test-osgi-beans</finalName> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>2.5.3</version> + <configuration> + <instructions> + <Bundle-Version>${project.version}</Bundle-Version> + <Brooklyn-Feature-BuildId>${buildNumber}</Brooklyn-Feature-BuildId> + <Brooklyn-Feature-BuildBranch>${scmBranch}</Brooklyn-Feature-BuildBranch> + </instructions> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/utils/common/dependencies/osgi/beans/src/main/java/org/apache/brooklyn/test/osgi/SampleBean.java b/utils/common/dependencies/osgi/beans/src/main/java/org/apache/brooklyn/test/osgi/SampleBean.java new file mode 100644 index 0000000..725a2a6 --- /dev/null +++ b/utils/common/dependencies/osgi/beans/src/main/java/org/apache/brooklyn/test/osgi/SampleBean.java @@ -0,0 +1,26 @@ +/* + * 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.test.osgi; + +public class SampleBean { + + String word; + int number; + +} diff --git a/utils/common/dependencies/osgi/beans/src/main/resources/catalog.bom b/utils/common/dependencies/osgi/beans/src/main/resources/catalog.bom new file mode 100644 index 0000000..4b7379e --- /dev/null +++ b/utils/common/dependencies/osgi/beans/src/main/resources/catalog.bom @@ -0,0 +1,24 @@ +# 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. + + +brooklyn.catalog: + items: + - id: sampleBean + item: + type: org.apache.brooklyn.test.osgi.SampleBean + number: 1 diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java b/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java index 048e0f5..98d807c 100644 --- a/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java +++ b/utils/common/src/test/java/org/apache/brooklyn/util/osgi/OsgiTestResources.java @@ -112,7 +112,11 @@ public interface OsgiTestResources { public static final String BROOKLYN_TEST_MORE_ENTITIES_V1_URL = "classpath:"+BROOKLYN_TEST_MORE_ENTITIES_V1_PATH; public static final String BROOKLYN_TEST_MORE_ENTITIES_V2_URL = "classpath:"+BROOKLYN_TEST_MORE_ENTITIES_V2_PATH; public static final String BROOKLYN_TEST_MORE_ENTITIES_V2_EVIL_TWIN_URL = "classpath:"+BROOKLYN_TEST_MORE_ENTITIES_V2_EVIL_TWIN_PATH; - + + public static final String BROOKLYN_TEST_OSGI_BEANS_SYMBOLIC_NAME_FINAL_PART = "brooklyn-test-osgi-bean"; + public static final String BROOKLYN_TEST_OSGI_BEANS_PATH = "/brooklyn/osgi/brooklyn-test-osgi-beans.jar"; + public static final String BROOKLYN_TEST_OSGI_BEANS_URL = "classpath:"+OsgiTestResources.BROOKLYN_TEST_OSGI_BEANS_PATH; + public static final String TEST_VERSION = "0.1.0"; } diff --git a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-beans.jar b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-beans.jar new file mode 100644 index 0000000..0f5de20 Binary files /dev/null and b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-beans.jar differ diff --git a/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-beans.txt b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-beans.txt new file mode 100644 index 0000000..1860f11 --- /dev/null +++ b/utils/common/src/test/resources/brooklyn/osgi/brooklyn-test-osgi-beans.txt @@ -0,0 +1,26 @@ +# 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. + +The file brooklyn-test-osgi-beans.jar is for testing a deployment of +an OSGi bundle containing beans. + +The source is in utils/common/dependencies/osgi/beans + +Under Apache conventions, binary files are not part of the source +release. If you are using the source release, you may add this file +by copying it from the master repository, which is accessible on the +web at https://github.com/apache/brooklyn
