You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2017/11/21 17:08:17 UTC
[2/8] brooklyn-server git commit: CatalogResourceTest: add more tests
CatalogResourceTest: add more tests
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b5753501
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b5753501
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b5753501
Branch: refs/heads/master
Commit: b5753501752ee52f27cc481858532825234278f6
Parents: d33abf5
Author: Aled Sage <al...@gmail.com>
Authored: Thu Nov 16 15:33:30 2017 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Nov 16 15:33:30 2017 +0000
----------------------------------------------------------------------
.../rest/resources/CatalogResourceTest.java | 83 ++++++++++++++++++++
1 file changed, 83 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b5753501/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
index 7de540d..090b108 100644
--- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
@@ -96,6 +96,7 @@ import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
+import com.google.gson.Gson;
@Test( // by using a different suite name we disallow interleaving other tests between the methods of this test class, which wrecks the test fixtures
suiteName = "CatalogResourceTest")
@@ -663,6 +664,88 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
}
@Test
+ public void testArchiveWithBundleAndVersion() throws Exception {
+ String version = "0.1.0";
+ String itemSymbolicName = "my-entity";
+
+ File f = createZip(ImmutableMap.<String, String>of("catalog.bom", Joiner.on("\n").join(
+ "brooklyn.catalog:",
+ " bundle: org.apache.brooklyn.test",
+ " version: " + version,
+ " itemType: entity",
+ " id: " + itemSymbolicName,
+ " name: My Catalog App",
+ " description: My description",
+ " item:",
+ " type: org.apache.brooklyn.core.test.entity.TestEntity")));
+
+ 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());
+
+ CatalogSummaryAsserts.newInstance(CatalogItemType.ENTITY, itemSymbolicName, version)
+ .planYamlPredicate(StringPredicates.containsLiteral("org.apache.brooklyn.core.test.entity.TestEntity"))
+ .name("My Catalog App")
+ .description("My description")
+ .expectedInterfaces(Reflections.getAllInterfaces(TestEntity.class))
+ .applyAsserts(() -> client());
+
+ RegisteredTypeAsserts.newInstance(itemSymbolicName, version)
+ .libraryNames(new VersionedName("org.apache.brooklyn.test", version))
+ .libraryUrls((String)null)
+ .applyAsserts(getManagementContext().getTypeRegistry());
+ }
+
+ @Test
+ public void testInstallSameArchiveTwice() throws Exception {
+ String version = "0.1.0";
+ String itemSymbolicName = "my-entity";
+
+ File f = createZip(ImmutableMap.<String, String>of("catalog.bom", Joiner.on("\n").join(
+ "brooklyn.catalog:",
+ " bundle: org.apache.brooklyn.test",
+ " version: " + version,
+ " itemType: entity",
+ " id: " + itemSymbolicName,
+ " name: My Catalog App",
+ " item:",
+ " type: org.apache.brooklyn.core.test.entity.TestEntity")));
+
+ // Deploy first time
+ 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());
+
+ RegisteredTypeAsserts.newInstance(itemSymbolicName, version)
+ .libraryNames(new VersionedName("org.apache.brooklyn.test", version))
+ .applyAsserts(getManagementContext().getTypeRegistry());
+
+ // Deploy again
+ // Aled had expected a 200, but getting a 400 - assert existing behaviour.
+ // Also assert that type is still there
+ Response response2 = client().path("/catalog")
+ .header(HttpHeaders.CONTENT_TYPE, "application/x-zip")
+ .post(Streams.readFully(new FileInputStream(f)));
+ String response2Body = response2.readEntity(String.class);
+
+ Map<?,?> response2Map = new Gson().fromJson(response2Body, Map.class);
+ String response2Message = (String) response2Map.get("message");
+ String response2Code = (String) ((Map<?,?>)response2Map.get("data")).get("code");
+
+ assertEquals(response2.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
+ assertTrue(response2Code.equals("IGNORING_BUNDLE_AREADY_INSTALLED"), "body="+response2Body);
+ assertTrue(response2Message.toLowerCase().contains("bundle org.apache.brooklyn.test:0.1.0 already installed"), "body="+response2Body);
+
+ RegisteredTypeAsserts.newInstance(itemSymbolicName, version)
+ .libraryNames(new VersionedName("org.apache.brooklyn.test", version))
+ .applyAsserts(getManagementContext().getTypeRegistry());
+ }
+
+ @Test
public void testJarWithoutMatchingBundle() throws Exception {
String name = "My Catalog App";
String bundle = "org.apache.brooklyn.test";