Github user tbouron commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/485#discussion_r106941722
  
    --- 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);
    +        final String symbolicName = 
OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FULL;
    +        final String version = 
OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_VERSION;
    +        final String bundleUrl = 
OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL;
    +        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:/org/apache/brooklyn/test/osgi/entities/icon.gif",
    +                "  item:",
    +                "    type: 
org.apache.brooklyn.core.test.entity.TestEntity");
    +        
    +        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("org.apache.brooklyn.core.test.entity.TestEntity"));
    +
    +        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(), 
"org.apache.brooklyn.test.resources.osgi.brooklyn-test-osgi-entities");
    +        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:/org/apache/brooklyn/test/osgi/entities/icon.gif");
    +
    +        // 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<Class<?>> expectedInterfaces = 
Reflections.getAllInterfaces(TestEntity.class);
    +        assertEquals(actualInterfaces.size(), expectedInterfaces.size());
    +        for (Class<?> expectedInterface : expectedInterfaces) {
    +            
assertTrue(actualInterfaces.contains(expectedInterface.getName()));
    +        }
    +
    +        byte[] iconData = client().path("/catalog/icon/" + symbolicName + 
"/" + version).get(byte[].class);
    +        assertEquals(iconData.length, 43);
    +    }
    --- End diff --
    
    It would be worth to create more simple tests for:
    - `version` mismatch
    - `symbolicName` mismatch
    - `symbolicName` and/or `version` missing
    - uploading a zip, i.e. no manifest file


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to