diff --git a/src/main/java/run/halo/app/extension/DefaultExtensionClient.java b/src/main/java/run/halo/app/extension/DefaultExtensionClient.java index cb6fca518..d6b0f3033 100644 --- a/src/main/java/run/halo/app/extension/DefaultExtensionClient.java +++ b/src/main/java/run/halo/app/extension/DefaultExtensionClient.java @@ -105,8 +105,10 @@ public class DefaultExtensionClient implements ExtensionClient { @Override public void delete(E extension) { + extension.getMetadata().setDeletionTimestamp(Instant.now()); var extensionStore = converter.convertTo(extension); - var deleteStore = storeClient.delete(extensionStore.getName(), extensionStore.getVersion()); + var deleteStore = storeClient.update(extensionStore.getName(), extensionStore.getVersion(), + extensionStore.getData()); Extension deleteExt = converter.convertFrom(extension.getClass(), deleteStore); watchers.onDelete(deleteExt); } diff --git a/src/main/java/run/halo/app/extension/ExtensionRouterFunctionFactory.java b/src/main/java/run/halo/app/extension/ExtensionRouterFunctionFactory.java index da1b0f7c6..f35d49729 100644 --- a/src/main/java/run/halo/app/extension/ExtensionRouterFunctionFactory.java +++ b/src/main/java/run/halo/app/extension/ExtensionRouterFunctionFactory.java @@ -6,7 +6,6 @@ import static org.springdoc.core.fn.builders.requestbody.Builder.requestBodyBuil import io.swagger.v3.oas.annotations.enums.ParameterIn; import java.net.URI; -import java.time.Instant; import java.util.Objects; import net.bytebuddy.ByteBuddy; import net.bytebuddy.description.type.TypeDescription; @@ -299,10 +298,7 @@ public class ExtensionRouterFunctionFactory { String name = request.pathVariable("name"); return getExtension(name) .flatMap(extension -> - Mono.fromRunnable(() -> { - extension.getMetadata().setDeletionTimestamp(Instant.now()); - client.update(extension); - }).thenReturn(extension)) + Mono.fromRunnable(() -> client.delete(extension)).thenReturn(extension)) .flatMap(extension -> this.getExtension(name)) .flatMap(extension -> ServerResponse .ok() diff --git a/src/test/java/run/halo/app/config/ExtensionConfigurationTest.java b/src/test/java/run/halo/app/config/ExtensionConfigurationTest.java index b55f9bdc2..b3a222165 100644 --- a/src/test/java/run/halo/app/config/ExtensionConfigurationTest.java +++ b/src/test/java/run/halo/app/config/ExtensionConfigurationTest.java @@ -29,6 +29,7 @@ import run.halo.app.extension.FakeExtension; import run.halo.app.extension.Metadata; import run.halo.app.extension.Scheme; import run.halo.app.extension.SchemeManager; +import run.halo.app.extension.store.ExtensionStoreRepository; @SpringBootTest @AutoConfigureWebTestClient @@ -59,6 +60,11 @@ class ExtensionConfigurationTest { schemeManager.register(FakeExtension.class); } + @AfterEach + void cleanUp(@Autowired ExtensionStoreRepository repository) { + repository.deleteAll(); + } + @Test @WithMockUser void shouldReturnNotFoundWhenSchemeNotRegistered() { @@ -130,12 +136,6 @@ class ExtensionConfigurationTest { .getResponseBody(); } - @AfterEach - void cleanUp() { - FakeExtension fakeToDelete = getFakeExtension(createdFake.getMetadata().getName()); - extClient.delete(fakeToDelete); - } - @Test @WithMockUser void shouldDeleteExtensionWhenSchemeRegistered() { diff --git a/src/test/java/run/halo/app/extension/DefaultExtensionClientTest.java b/src/test/java/run/halo/app/extension/DefaultExtensionClientTest.java index fc3a61644..2dbf8f46c 100644 --- a/src/test/java/run/halo/app/extension/DefaultExtensionClientTest.java +++ b/src/test/java/run/halo/app/extension/DefaultExtensionClientTest.java @@ -12,6 +12,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -340,13 +341,14 @@ class DefaultExtensionClientTest { var fake = createFakeExtension("fake", 2L); when(converter.convertTo(any())).thenReturn( createExtensionStore("/registry/fake.halo.run/fakes/fake")); - when(storeClient.delete(any(), any())).thenReturn( + when(storeClient.update(any(), any(), any())).thenReturn( createExtensionStore("/registry/fake.halo.run/fakes/fake")); client.delete(fake); verify(converter, times(1)).convertTo(any()); - verify(storeClient, times(1)).delete(any(), any()); + verify(storeClient, times(1)).update(any(), any(), any()); + verify(storeClient, never()).delete(any(), any()); } @Nested diff --git a/src/test/java/run/halo/app/extension/ExtensionDeleteHandlerTest.java b/src/test/java/run/halo/app/extension/ExtensionDeleteHandlerTest.java index 3ed44a878..7bef5099d 100644 --- a/src/test/java/run/halo/app/extension/ExtensionDeleteHandlerTest.java +++ b/src/test/java/run/halo/app/extension/ExtensionDeleteHandlerTest.java @@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.doNothing; @@ -57,7 +56,7 @@ class ExtensionDeleteHandlerTest { .pathVariable("name", "my-fake") .body(Mono.just(unstructured)); when(client.fetch(eq(FakeExtension.class), eq("my-fake"))).thenReturn(Optional.of(fake)); - doNothing().when(client).update(any()); + doNothing().when(client).delete(any()); var scheme = Scheme.buildFromType(FakeExtension.class); var deleteHandler = new ExtensionDeleteHandler(scheme, client); @@ -72,9 +71,8 @@ class ExtensionDeleteHandlerTest { }) .verifyComplete(); verify(client, times(2)).fetch(eq(FakeExtension.class), eq("my-fake")); - verify(client, times(1)).update( - argThat(fakeToDelete -> fakeToDelete.getMetadata().getDeletionTimestamp() != null)); - verify(client, times(0)).delete(any()); + verify(client, times(1)).delete(any()); + verify(client, times(0)).update(any()); } @Test