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


The following commit(s) were added to refs/heads/master by this push:
     new c4b69bb  fixes and more tests for previous multi-part change
c4b69bb is described below

commit c4b69bbc2be335d0520a1c00ea2c33954c88ff82
Author: Alex Heneveld <[email protected]>
AuthorDate: Wed Jul 28 13:17:07 2021 +0100

    fixes and more tests for previous multi-part change
    
    more test coverage, fix path param on the unique app id tag
---
 .../apache/brooklyn/rest/api/ApplicationApi.java   |  8 ++---
 .../rest/BrooklynRestApiLauncherTestFixture.java   |  5 ++++
 .../brooklyn/rest/api/ApplicationApiTest.java      | 35 ++++++++++++++++++++++
 3 files changed, 44 insertions(+), 4 deletions(-)

diff --git 
a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ApplicationApi.java 
b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ApplicationApi.java
index 4a62c6e..c19b28e 100644
--- 
a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ApplicationApi.java
+++ 
b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ApplicationApi.java
@@ -212,12 +212,12 @@ public interface ApplicationApi {
             @ApiParam(name = "plan", value = "Plan", required = true)
             @Multipart("plan") String yaml,
             @ApiParam(name = "format", value = "Format eg broolyn-camp", 
required = false)
-            @Multipart("format") String format,
+            @Multipart(value = "format", required = false) String format,
             @ApiParam(name = "application", value = "Application id", required 
= true)
-            @Multipart("application") String appId);
+            @PathParam("application") String appId);
 
 
-    /** @deprecated since 1.1 use {@link #createWithFormat(byte[], String)} 
instead */
+    /** @deprecated since 1.1 use {@link #createWithFormatMultipart(String, 
String)} instead */
     @Deprecated
     @POST
     @Consumes("application/deprecated-yaml-app-spec")
@@ -271,7 +271,7 @@ public interface ApplicationApi {
             @ApiParam(name = "plan", value = "Application plan to deploy", 
required = true)
             @Multipart("plan") String plan,
             @ApiParam(name = "format", value = "Type plan format e.g. 
brooklyn-camp", required = false)
-            @Multipart("format") String format);
+            @Multipart(value = "format", required = false) String format);
 
     @Beta
     @POST
diff --git 
a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncherTestFixture.java
 
b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncherTestFixture.java
index 1ec89a4..cda7f25 100644
--- 
a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncherTestFixture.java
+++ 
b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/BrooklynRestApiLauncherTestFixture.java
@@ -113,6 +113,11 @@ public abstract class BrooklynRestApiLauncherTestFixture {
         return HttpTool.httpPost(newClient(user), uri, headers, body);
     }
 
+    protected HttpToolResponse httpPut(String user, String path, byte[] body, 
Map<String, String> headers) throws Exception {
+        final URI uri = URI.create(getBaseUriRest()).resolve(path);
+        return HttpTool.httpPut(newClient(user), uri, headers, body);
+    }
+
     protected void assertHealthyStatusCode(HttpToolResponse response) {
         
assertTrue(HttpAsserts.isHealthyStatusCode(response.getResponseCode()), 
"code="+response.getResponseCode()+"; reason="+response.getReasonPhrase());
     }
diff --git 
a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/api/ApplicationApiTest.java
 
b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/api/ApplicationApiTest.java
index 433ce1d..218a9f4 100644
--- 
a/rest/rest-server/src/test/java/org/apache/brooklyn/rest/api/ApplicationApiTest.java
+++ 
b/rest/rest-server/src/test/java/org/apache/brooklyn/rest/api/ApplicationApiTest.java
@@ -45,10 +45,45 @@ public class ApplicationApiTest extends 
BrooklynRestApiLauncherTestFixture {
         assertPostMultiPart("admin", "/v1/applications", body.getBytes(), 
headers);
     }
 
+
+    @Test(groups = "Integration")
+    public void testMultipartFormWithoutOptionalFormat() throws Exception {
+        useServerForTest(newServer());
+        String body = "------WebKitFormBoundaryaQhM7RFMi4ZiXOj2\n\r" +
+                "Content-Disposition: form-data; name=\"plan\"\n\r\n\r" +
+                "services:\n\r" +
+                "- type: org.apache.brooklyn.entity.stock.BasicEntity\n\r" +
+                "  brooklyn.config:\n\r" +
+                "    example: $brooklyn:formatString(\"%s\", 
\"vault\")\n\r\n\r\n\r" +
+                "------WebKitFormBoundaryaQhM7RFMi4ZiXOj2--\n\r";
+        ImmutableMap<String, String> headers = ImmutableMap.of("Content-Type", 
"multipart/form-data; boundary=----WebKitFormBoundaryaQhM7RFMi4ZiXOj2");
+        assertPostMultiPart("admin", "/v1/applications", body.getBytes(), 
headers);
+    }
+
+
+    @Test(groups = "Integration")
+    public void testMultipartFormWithAppIdWithoutOptionalFormat() throws 
Exception {
+        useServerForTest(newServer());
+        String body = "------WebKitFormBoundaryaQhM7RFMi4ZiXOj2\n\r" +
+                "Content-Disposition: form-data; name=\"plan\"\n\r\n\r" +
+                "services:\n\r" +
+                "- type: org.apache.brooklyn.entity.stock.BasicEntity\n\r" +
+                "  brooklyn.config:\n\r" +
+                "    example: $brooklyn:formatString(\"%s\", 
\"vault\")\n\r\n\r\n\r" +
+                "------WebKitFormBoundaryaQhM7RFMi4ZiXOj2--\n\r";
+        ImmutableMap<String, String> headers = ImmutableMap.of("Content-Type", 
"multipart/form-data; boundary=----WebKitFormBoundaryaQhM7RFMi4ZiXOj2");
+        assertPutMultiPart("admin", 
"/v1/applications/sample0unique0request0id0min10chars0letters0or0numbers", 
body.getBytes(), headers);
+    }
+
     public void assertPostMultiPart(String user, String path, byte[] body, 
Map<String, String> headers) throws Exception {
         HttpToolResponse response = httpPost(user, path, body, headers);
         assertHealthyStatusCode(response);
     }
 
+    public void assertPutMultiPart(String user, String path, byte[] body, 
Map<String, String> headers) throws Exception {
+        HttpToolResponse response = httpPut(user, path, body, headers);
+        assertHealthyStatusCode(response);
+    }
+
 
 }
\ No newline at end of file

Reply via email to