Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/485#discussion_r107489495
--- Diff:
rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
---
@@ -487,6 +495,79 @@ public void testAddMissingItem() {
//equivalent to HTTP response 404 text/html
addAddCatalogItemWithInvalidBundleUrl("classpath://missing-jar-file.txt");
}
+
+ @Test
+ public void testOsgiBundleWithBom() throws Exception {
+
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(),
OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
--- End diff --
I tested this - it does work:
```
@Test
public void testOsgiBundleWithBomNotInBrooklynNamespace() throws
Exception {
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(),
OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH);
final String symbolicName =
OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_SYMBOLIC_NAME_FULL;
final String version =
OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_VERSION;
final String bundleUrl =
OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_URL;
final String entityType =
OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_ENTITY;
final String iconPath =
OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_ICON_PATH;
BundleMaker bm = new BundleMaker(manager);
File f = Os.newTempFile("osgi", "jar");
Files.copyFile(ResourceUtils.create(this).getResourceFromUrl(bundleUrl), f);
String bom = Joiner.on("\n").join(
"brooklyn.catalog:",
" id: " + symbolicName,
" version: " + version,
" itemType: entity",
" name: My Catalog App",
" description: My description",
" icon_url: classpath:" + iconPath,
" item:",
" type: " + entityType);
f = bm.copyAdding(f, MutableMap.of(new ZipEntry("catalog.bom"),
(InputStream) new ByteArrayInputStream(bom.getBytes())));
Response response = client().path("/catalog")
.header(HttpHeaders.CONTENT_TYPE, "application/x-zip")
.post(Streams.readFully(new FileInputStream(f)));
assertEquals(response.getStatus(),
Response.Status.CREATED.getStatusCode());
CatalogEntitySummary entityItem =
client().path("/catalog/entities/"+symbolicName + "/" + version)
.get(CatalogEntitySummary.class);
Assert.assertNotNull(entityItem.getPlanYaml());
Assert.assertTrue(entityItem.getPlanYaml().contains(entityType));
assertEquals(entityItem.getId(),
CatalogUtils.getVersionedId(symbolicName, version));
assertEquals(entityItem.getSymbolicName(), symbolicName);
assertEquals(entityItem.getVersion(), version);
// and internally let's check we have libraries
RegisteredType item =
getManagementContext().getTypeRegistry().get(symbolicName, version);
Assert.assertNotNull(item);
Collection<OsgiBundleWithUrl> libs = item.getLibraries();
assertEquals(libs.size(), 1);
OsgiBundleWithUrl lib = Iterables.getOnlyElement(libs);
Assert.assertNull(lib.getUrl());
assertEquals(lib.getSymbolicName(), symbolicName);
assertEquals(lib.getVersion(), version);
// now let's check other things on the item
URI expectedIconUrl = URI.create(getEndpointAddress() +
"/catalog/icon/" + symbolicName + "/" + entityItem.getVersion()).normalize();
assertEquals(entityItem.getName(), "My Catalog App");
assertEquals(entityItem.getDescription(), "My description");
assertEquals(entityItem.getIconUrl(), expectedIconUrl.getPath());
assertEquals(item.getIconUrl(), "classpath:" + iconPath);
// an InterfacesTag should be created for every catalog item
assertEquals(entityItem.getTags().size(), 1);
Object tag = entityItem.getTags().iterator().next();
@SuppressWarnings("unchecked")
List<String> actualInterfaces = ((Map<String, List<String>>)
tag).get("traits");
List<String> expectedInterfaces =
ImmutableList.of(Entity.class.getName(), BrooklynObject.class.getName(),
Identifiable.class.getName(), Configurable.class.getName());
assertTrue(actualInterfaces.containsAll(expectedInterfaces),
"actual="+actualInterfaces);
byte[] iconData = client().path("/catalog/icon/" + symbolicName +
"/" + version).get(byte[].class);
assertEquals(iconData.length, 43);
// Check that the catalog item is useable (i.e. can deploy the
entity)
String appYaml = Joiner.on("\n").join(
"services:",
"- type: " + symbolicName + ":" + version,
" name: myEntityName");
Response appResponse = client().path("/applications")
.header(HttpHeaders.CONTENT_TYPE, "application/x-yaml")
.post(appYaml);
assertEquals(appResponse.getStatus(),
Response.Status.CREATED.getStatusCode());
Entity entity =
Iterables.tryFind(getManagementContext().getEntityManager().getEntities(),
EntityPredicates.displayNameEqualTo("myEntityName")).get();
assertEquals(entity.getEntityType().getName(), entityType);
}
```
The special code is in `CatalogBomScanner`, where it calls
`addLibraryDetails` (e.g. in the `scanForCatalog(bundle)` method).
---
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 [email protected] or file a JIRA ticket
with INFRA.
---