You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by dr...@apache.org on 2017/04/14 12:11:02 UTC

[3/4] brooklyn-server git commit: Make the version process case-insensitive and add test for it

Make the version process case-insensitive and add test for it


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/361a0fd4
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/361a0fd4
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/361a0fd4

Branch: refs/heads/master
Commit: 361a0fd47377d012d8b484dc925b4da3695887d3
Parents: 6ad3b5c
Author: Thomas Bouron <th...@cloudsoftcorp.com>
Authored: Fri Apr 14 10:50:12 2017 +0100
Committer: Thomas Bouron <th...@cloudsoftcorp.com>
Committed: Fri Apr 14 10:50:12 2017 +0100

----------------------------------------------------------------------
 .../rest/resources/CatalogResource.java         | 35 ++++++--------
 .../rest/resources/CatalogResourceTest.java     | 49 +++++++++-----------
 2 files changed, 35 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/361a0fd4/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
index 713cdb9..bc75ce5 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
@@ -114,6 +114,13 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
         };
     };
 
+    private String processVersion(String version) {
+        if (version != null && LATEST.equals(version.toLowerCase())) {
+            version = null;
+        }
+        return version;
+    }
+
     static Set<String> missingIcons = MutableSet.of();
 
     @Override
@@ -333,9 +340,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
                 Entitlements.getEntitlementContext().user());
         }
 
-        if (LATEST.equals(version)) {
-            version = null;
-        }
+        version = processVersion(version);
         
         RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, version);
         if (item == null) {
@@ -354,9 +359,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
                 Entitlements.getEntitlementContext().user());
         }
 
-        if (LATEST.equals(version)) {
-            version = null;
-        }
+        version = processVersion(version);
         
         RegisteredType item = mgmt().getTypeRegistry().get(policyId, version);
         if (item == null) {
@@ -375,9 +378,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
                 Entitlements.getEntitlementContext().user());
         }
 
-        if (LATEST.equals(version)) {
-            version = null;
-        }
+        version = processVersion(version);
         
         RegisteredType item = mgmt().getTypeRegistry().get(locationId, version);
         if (item == null) {
@@ -435,9 +436,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
                 Entitlements.getEntitlementContext().user());
         }
 
-        if (LATEST.equals(version)) {
-            version = null;
-        }
+        version = processVersion(version);
 
         //TODO These casts are not pretty, we could just provide separate get methods for the different types?
         //Or we could provide asEntity/asPolicy cast methods on the CataloItem doing a safety check internally
@@ -498,9 +497,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
                 Entitlements.getEntitlementContext().user());
         }
 
-        if (LATEST.equals(version)) {
-            version = null;
-        }
+        version = processVersion(version);
 
         @SuppressWarnings("unchecked")
         CatalogItem<? extends Policy, PolicySpec<?>> result =
@@ -548,9 +545,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
                 Entitlements.getEntitlementContext().user());
         }
 
-        if (LATEST.equals(version)) {
-            version = null;
-        }
+        version = processVersion(version);
 
         @SuppressWarnings("unchecked")
         CatalogItem<? extends Location, LocationSpec<?>> result =
@@ -601,9 +596,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
                 Entitlements.getEntitlementContext().user());
         }
 
-        if (LATEST.equals(version)) {
-            version = null;
-        }
+        version = processVersion(version);
         
         return getCatalogItemIcon(mgmt().getTypeRegistry().get(itemId, version));
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/361a0fd4/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 ac2d2d9..500508e 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
@@ -890,6 +890,19 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         assertEquals(application.getVersion(), TEST_LASTEST_VERSION);
     }
 
+    @Test(dependsOnMethods = {"testGetOnlyLatestApplication"})
+    public void testGetOnlyLatestDifferentCases() {
+        String symbolicName = "latest.catalog.application.id";
+
+        CatalogItemSummary application = client().path("/catalog/applications/" + symbolicName + "/LaTeSt")
+                .get(CatalogItemSummary.class);
+        assertEquals(application.getVersion(), TEST_LASTEST_VERSION);
+
+        application = client().path("/catalog/applications/" + symbolicName + "/LATEST")
+                .get(CatalogItemSummary.class);
+        assertEquals(application.getVersion(), TEST_LASTEST_VERSION);
+    }
+
     @Test
     public void testGetOnlyLatestEntity() {
         String symbolicName = "latest.catalog.entity.id";
@@ -932,14 +945,9 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         assertEquals(application.getVersion(), TEST_LASTEST_VERSION);
     }
 
-    @Test
+    @Test(dependsOnMethods = {"testGetOnlyLatestApplication", "testGetOnlyLatestDifferentCases"})
     public void testDeleteOnlyLatestApplication() throws IOException {
-        String symbolicName = "latest.catalog.application.delete.id";
-        String itemType = "template";
-        String serviceType = "org.apache.brooklyn.core.test.entity.TestEntity";
-
-        addTestCatalogItem(symbolicName, itemType, TEST_VERSION, serviceType);
-        addTestCatalogItem(symbolicName, itemType, TEST_LASTEST_VERSION, serviceType);
+        String symbolicName = "latest.catalog.application.id";
 
         Response deleteResponse = client().path("/catalog/applications/" + symbolicName + "/latest").delete();
         assertEquals(deleteResponse.getStatus(), HttpStatus.NO_CONTENT_204);
@@ -950,14 +958,9 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         assertEquals(applications.get(0).getVersion(), TEST_VERSION);
     }
 
-    @Test
+    @Test(dependsOnMethods = {"testGetOnlyLatestEntity"})
     public void testDeleteOnlyLatestEntity() throws IOException {
-        String symbolicName = "latest.catalog.entity.delete.id";
-        String itemType = "entity";
-        String serviceType = "org.apache.brooklyn.core.test.entity.TestEntity";
-
-        addTestCatalogItem(symbolicName, itemType, TEST_VERSION, serviceType);
-        addTestCatalogItem(symbolicName, itemType, TEST_LASTEST_VERSION, serviceType);
+        String symbolicName = "latest.catalog.entity.id";
 
         Response deleteResponse = client().path("/catalog/entities/" + symbolicName + "/latest").delete();
         assertEquals(deleteResponse.getStatus(), HttpStatus.NO_CONTENT_204);
@@ -968,14 +971,9 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         assertEquals(applications.get(0).getVersion(), TEST_VERSION);
     }
 
-    @Test
+    @Test(dependsOnMethods = {"testGetOnlyLatestPolicy"})
     public void testDeleteOnlyLatestPolicy() throws IOException {
-        String symbolicName = "latest.catalog.policy.delete.id";
-        String itemType = "policy";
-        String serviceType = "org.apache.brooklyn.policy.autoscaling.AutoScalerPolicy";
-
-        addTestCatalogItem(symbolicName, itemType, TEST_VERSION, serviceType);
-        addTestCatalogItem(symbolicName, itemType, TEST_LASTEST_VERSION, serviceType);
+        String symbolicName = "latest.catalog.policy.id";
 
         Response deleteResponse = client().path("/catalog/policies/" + symbolicName + "/latest").delete();
         assertEquals(deleteResponse.getStatus(), HttpStatus.NO_CONTENT_204);
@@ -986,14 +984,9 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         assertEquals(applications.get(0).getVersion(), TEST_VERSION);
     }
 
-    @Test
+    @Test(dependsOnMethods = {"testGetOnlyLatestLocation"})
     public void testDeleteOnlyLatestLocation() throws IOException {
-        String symbolicName = "latest.catalog.location.delete.id";
-        String itemType = "location";
-        String serviceType = "localhost";
-
-        addTestCatalogItem(symbolicName, itemType, TEST_VERSION, serviceType);
-        addTestCatalogItem(symbolicName, itemType, TEST_LASTEST_VERSION, serviceType);
+        String symbolicName = "latest.catalog.location.id";
 
         Response deleteResponse = client().path("/catalog/locations/" + symbolicName + "/latest").delete();
         assertEquals(deleteResponse.getStatus(), HttpStatus.NO_CONTENT_204);