feat(appconfig): implement UpdateApplication (#7209)

* feat(appconfig): implement UpdateApplication

* fix: address AppConfig update review findings

* fix: incorporate AppConfig maintainer feedback

---------

Co-authored-by: Ovidiu (Ovi) <462561+ovidiubute@users.noreply.github.com>
This commit is contained in:
Ovidiu (Ovi)andOvidiu authored and GitHub committed 2026-11-02 07:41:06 -04:00
1 parent 42bc856258
commit 1b87483483
6 files changed
+155 -2

No files matched your search

@@ -748,6 +748,40 @@ class AppConfigTest {
}
}
}
@Test
@Order(59)
@DisplayName("UpdateApplication preserves fields omitted by the SDK request")
void updateApplication() {
String applicationId = appConfig.createApplication(CreateApplicationRequest.builder()
.name(TestFixtures.uniqueName("update-app"))
.description("original")
.build()).id();
try {
UpdateApplicationResponse renamed = appConfig.updateApplication(UpdateApplicationRequest.builder()
.applicationId(applicationId)
.name("updated-app")
.build());
assertThat(renamed.name()).isEqualTo("updated-app");
assertThat(renamed.description()).isEqualTo("original");
UpdateApplicationResponse described = appConfig.updateApplication(UpdateApplicationRequest.builder()
.applicationId(applicationId)
.description("updated")
.build());
assertThat(described.name()).isEqualTo("updated-app");
assertThat(described.description()).isEqualTo("updated");
GetApplicationResponse retrieved = appConfig.getApplication(GetApplicationRequest.builder()
.applicationId(applicationId)
.build());
assertThat(retrieved.name()).isEqualTo("updated-app");
assertThat(retrieved.description()).isEqualTo("updated");
} finally {
appConfig.deleteApplication(DeleteApplicationRequest.builder().applicationId(applicationId).build());
}
}
@Test
@DisplayName("A non-hosted profile without a type stays untyped")
void nonHostedProfileWithoutTypeStaysUntyped() {
+1
View File
@@ -11,6 +11,7 @@ The management plane allows you to create and manage applications, environments,
- `CreateApplication`
- `GetApplication`
- `ListApplications`
- `UpdateApplication`
- `DeleteApplication`
- `CreateEnvironment`
- `GetEnvironment`
@@ -17,6 +17,7 @@ import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
import jakarta.ws.rs.PATCH;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
@@ -64,6 +65,14 @@ public class AppConfigController {
return Response.ok(service.getApplication(id)).build();
}
@PATCH
@Path("/applications/{id}")
public Response updateApplication(@PathParam("id") String id, String body) throws IOException {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
return Response.ok(service.updateApplication(id, request)).build();
}
@GET
@Path("/applications")
public Response listApplications() {
@@ -122,11 +122,25 @@ public class AppConfigService {
applicationStore.get(applicationId).ifPresent(application -> applicationStore.delete(applicationId));
}
/** Updates only the application fields present in an UpdateApplication request. */
public synchronized Application updateApplication(String applicationIdentifier, Map<String, Object> request) {
if (request.containsKey("Name") && !(request.get("Name") instanceof String)) {
throw new AwsException("BadRequestException", "Name must be a string", 400);
}
if (request.containsKey("Description") && !(request.get("Description") instanceof String)) {
throw new AwsException("BadRequestException", "Description must be a string", 400);
}
Application app = resolveApplication(applicationIdentifier);
String name = request.containsKey("Name") ? (String) request.get("Name") : app.getName();
String description = request.containsKey("Description")
? (String) request.get("Description") : app.getDescription();
return updateApplication(app.getId(), name, description);
}
/**
* Sets the name and description of the application whose ID is {@code applicationId}, as a
* CloudFormation update of {@code AWS::AppConfig::Application} does: both are written, so a null
* description clears it. Floci serves no UpdateApplication route; the CloudFormation provisioner
* is the only caller.
* description clears it.
*/
public synchronized Application updateApplication(String applicationId, String name, String description) {
Application app = copy(requireApplicationById(applicationId));
@@ -1154,6 +1154,72 @@ class AppConfigIntegrationTest {
.body("values.promo._variants[0].name", equalTo("uk"));
}
@Test @Order(56)
void updateApplicationPreservesOmittedFields() {
String applicationId = given()
.contentType(ContentType.JSON)
.body("{\"Name\":\"update-app\",\"Description\":\"original\"}")
.when().post("/applications")
.then().statusCode(201)
.extract().path("Id");
given()
.contentType(ContentType.JSON)
.body("{\"Name\":\"updated-app\"}")
.when().patch("/applications/" + applicationId)
.then().statusCode(200)
.body("Id", equalTo(applicationId))
.body("Name", equalTo("updated-app"))
.body("Description", equalTo("original"));
given()
.contentType(ContentType.JSON)
.body("{\"Description\":\"updated\"}")
.when().patch("/applications/updated-app")
.then().statusCode(200)
.body("Id", equalTo(applicationId))
.body("Name", equalTo("updated-app"))
.body("Description", equalTo("updated"));
given()
.when().delete("/applications/" + applicationId)
.then().statusCode(204);
}
@Test @Order(57)
void updateApplicationRejectsNonStringFieldsWithoutChangingTheApplication() {
String applicationId = given()
.contentType(ContentType.JSON)
.body("{\"Name\":\"validation-app\",\"Description\":\"original\"}")
.when().post("/applications")
.then().statusCode(201)
.extract().path("Id");
given()
.contentType(ContentType.JSON)
.body("{\"Name\":123}")
.when().patch("/applications/" + applicationId)
.then().statusCode(400)
.body("__type", equalTo("BadRequestException"));
given()
.contentType(ContentType.JSON)
.body("{\"Name\":\"should-not-stick\",\"Description\":false}")
.when().patch("/applications/" + applicationId)
.then().statusCode(400)
.body("__type", equalTo("BadRequestException"));
given()
.when().get("/applications/" + applicationId)
.then().statusCode(200)
.body("Name", equalTo("validation-app"))
.body("Description", equalTo("original"));
given()
.when().delete("/applications/" + applicationId)
.then().statusCode(204);
}
/** Polls a new session on a feature flag profile with variants, deployed on first use. */
private static ValidatableResponse getLatestVariantFlagsAccepting(String accept) {
if (variantFlagsSessionBody == null) {
@@ -93,6 +93,8 @@ class AppConfigServiceTest {
Application application = new Application();
application.setId("app");
application.setName("orders");
application.setDescription("Order processing");
applicationStore.put("app", application);
when(applicationStore.get("app")).thenReturn(Optional.of(application));
Environment environment = new Environment();
@@ -107,6 +109,33 @@ class AppConfigServiceTest {
service = new AppConfigService(storageFactory, mock(EmulatorConfig.class));
}
@Test
void updateApplicationPreservesOmittedFields() {
Application updated = service.updateApplication("app", Map.of("Name", "orders-v2"));
assertEquals("orders-v2", updated.getName());
assertEquals("Order processing", updated.getDescription());
verify(applicationStore).put("app", updated);
}
@Test
void updateApplicationRejectsNonStringFieldsWithoutWriting() {
clearInvocations(applicationStore);
AwsException nameError = assertThrows(AwsException.class,
() -> service.updateApplication("app", Map.of("Name", 123)));
AwsException descriptionError = assertThrows(AwsException.class,
() -> service.updateApplication("app", Map.of("Name", "renamed", "Description", false)));
assertEquals("BadRequestException", nameError.getErrorCode());
assertEquals(400, nameError.getHttpStatus());
assertEquals("BadRequestException", descriptionError.getErrorCode());
assertEquals(400, descriptionError.getHttpStatus());
assertEquals("orders", service.getApplication("app").getName());
assertEquals("Order processing", service.getApplication("app").getDescription());
verify(applicationStore, never()).put(anyString(), any(Application.class));
}
@Test
void onlyHostedProfilesReceiveTheOmittedTypeDefault() {
assertEquals("AWS.Freeform", service.createConfigurationProfile("app",