Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d98ff4f
extensions: add sync functionality
shwstppr Oct 7, 2025
d7d9a4a
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Oct 10, 2025
4a535bd
more tests
shwstppr Oct 10, 2025
0337e34
missing file
shwstppr Oct 10, 2025
c91a970
fix line endings
shwstppr Oct 10, 2025
d384fb2
Merge branch 'main' into feature-sync-ext
shwstppr Oct 10, 2025
ecbdcd6
do not use mockConstruction
shwstppr Oct 10, 2025
2c70e03
changes
shwstppr Oct 11, 2025
2be9d96
changes for download extension
shwstppr Oct 12, 2025
40b013d
fix lint and rat check
shwstppr Oct 13, 2025
2da3004
add more tests
shwstppr Oct 13, 2025
fdfcfe6
fix lint
shwstppr Oct 13, 2025
942f36e
handle when share context is disabled
shwstppr Oct 14, 2025
f923de8
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Oct 26, 2025
5525242
changes for download via ssvm/secondary store
shwstppr Oct 29, 2025
865c6fd
allow cleanup of archives on sec store
shwstppr Oct 30, 2025
6276cd6
allow share context for lacal maven run, refactor
shwstppr Nov 2, 2025
c6b677b
refactor
shwstppr Nov 2, 2025
480fa9d
add tests
shwstppr Nov 3, 2025
0f5f3da
more tests and refactor
shwstppr Nov 3, 2025
2332c9c
log fix
shwstppr Nov 3, 2025
5b09704
Merge branch 'main' into feature-sync-ext
DaanHoogland Dec 22, 2025
de78f5b
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Dec 29, 2025
02c87ea
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Jan 28, 2026
5220a3e
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Jan 29, 2026
35903ed
fix build
shwstppr Jan 29, 2026
1998867
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Jan 31, 2026
07e70f2
secondary-storage: delete temp directory while deleting entity download
shwstppr Jan 31, 2026
21419d1
fix
shwstppr Jan 31, 2026
6941097
refactor
shwstppr Feb 6, 2026
6519e55
address copilot comments
shwstppr Feb 6, 2026
e895355
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Apr 11, 2026
49d9b76
Merge remote-tracking branch 'apache/main' into feature-sync-ext
shwstppr Apr 14, 2026
23360ac
address comment
shwstppr Apr 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add more tests
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
  • Loading branch information
shwstppr committed Oct 13, 2025
commit 2da3004286255c6951784d10adbd3ca94bd0fa74
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ public String prepareExternalPayload(String extensionName, Map<String, Object> d
}

@Override
public void deleteExtensionPayload(String extensionName, String payloadFileName) {
logger.trace("Deleting payload file: {} for extension: {}", payloadFileName, extensionName);
FileUtil.deletePath(payloadFileName);
public void deleteExtensionPayload(String extensionName, String payloadFilePath) {
logger.trace("Deleting payload file: {} for extension: {}", payloadFilePath, extensionName);
FileUtil.deletePath(payloadFilePath);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ protected boolean packArchiveForSync(Extension extension, Path extensionRootPath
Files.copy(p, dest, StandardCopyOption.COPY_ATTRIBUTES);
}
}
logger.debug("Packing files for {} from: {} to archive: {}", extension, sourceDir,
logger.debug("Packing files for sync for {} from: {} to archive: {}", extension, sourceDir,
archivePath.toAbsolutePath());
boolean result = ArchiveUtil.packPath(ArchiveUtil.ArchiveFormat.TGZ, sourceDir, archivePath, 60);

Expand All @@ -286,7 +286,7 @@ protected boolean packArchiveForDownload(Extension extension, Path extensionRoot
throws IOException {
Files.createDirectories(archivePath.getParent());
FileUtil.deletePath(archivePath.toAbsolutePath().toString());
logger.debug("Packing files for {} from: {} to archive: {}", extension, extensionRootPath,
logger.debug("Packing files for download for {} from: {} to archive: {}", extension, extensionRootPath,
archivePath.toAbsolutePath());

return ArchiveUtil.packPath(ArchiveUtil.ArchiveFormat.ZIP, extensionRootPath, archivePath, 60);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
import org.apache.cloudstack.extension.ExtensionCustomAction;
import org.apache.cloudstack.framework.extensions.manager.ExtensionsManager;
import org.apache.commons.collections.MapUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;

Expand All @@ -51,15 +52,11 @@
@RunWith(MockitoJUnitRunner.class)
public class AddCustomActionCmdTest {

private AddCustomActionCmd cmd;
@Mock
private ExtensionsManager extensionsManager;

@Before
public void setUp() throws Exception {
cmd = new AddCustomActionCmd();
extensionsManager = mock(ExtensionsManager.class);
cmd.extensionsManager = extensionsManager;
}
@InjectMocks
private AddCustomActionCmd cmd = new AddCustomActionCmd();

private void setField(String fieldName, Object value) {
ReflectionTestUtils.setField(cmd, fieldName, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@

import org.apache.commons.collections.MapUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class CreateExtensionCmdTest {
@InjectMocks
CreateExtensionCmd cmd = new CreateExtensionCmd();

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.framework.extensions.manager.ExtensionsManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class DeleteCustomActionCmdTest {

private DeleteCustomActionCmd cmd;
@Mock
private ExtensionsManager extensionsManager;

@Before
public void setUp() throws Exception {
cmd = Mockito.spy(new DeleteCustomActionCmd());
extensionsManager = Mockito.mock(ExtensionsManager.class);
java.lang.reflect.Field field = DeleteCustomActionCmd.class.getDeclaredField("extensionsManager");
field.setAccessible(true);
field.set(cmd, extensionsManager);
}
@Spy
@InjectMocks
private DeleteCustomActionCmd cmd;

@Test
public void getIdReturnsNullWhenUnset() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,24 @@
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.framework.extensions.manager.ExtensionsManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;

@RunWith(MockitoJUnitRunner.class)
public class DeleteExtensionCmdTest {

private DeleteExtensionCmd cmd;
@Mock
private ExtensionsManager extensionsManager;

@Before
public void setUp() {
cmd = Mockito.spy(new DeleteExtensionCmd());
extensionsManager = Mockito.mock(ExtensionsManager.class);
cmd.extensionsManager = extensionsManager;
}
@Spy
@InjectMocks
private DeleteExtensionCmd cmd;

@Test
public void getIdReturnsNullWhenUnset() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.framework.extensions.api;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.framework.extensions.api.response.DownloadExtensionResponse;
import org.apache.cloudstack.framework.extensions.manager.ExtensionsManager;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;

import com.cloud.event.EventTypes;
import com.cloud.user.Account;

@RunWith(MockitoJUnitRunner.class)
public class DownloadExtensionCmdTest {

@Mock
private ExtensionsManager extensionsManager;

@Spy
@InjectMocks
private DownloadExtensionCmd cmd;

@Test
public void getIdReturnsExpected() {
ReflectionTestUtils.setField(cmd, "id", 123L);
assertEquals(Long.valueOf(123L), cmd.getId());
}

@Test
public void getManagementServerIdReturnsExpected() {
ReflectionTestUtils.setField(cmd, "managementServerId", 123L);
assertEquals(Long.valueOf(123L), cmd.getManagementServerId());
}

@Test
public void executeSetsResponseObjectWhenDownloadSucceeds() {
DownloadExtensionResponse response = mock(DownloadExtensionResponse.class);
when(extensionsManager.downloadExtension(any(DownloadExtensionCmd.class))).thenReturn(response);
cmd.execute();
verify(cmd).setResponseObject(response);
}

@Test
public void executeThrowsExceptionWhenDownloadFails() {
when(extensionsManager.downloadExtension(cmd)).thenReturn(null);
ServerApiException exception = assertThrows(ServerApiException.class, cmd::execute);
assertEquals(ApiErrorCode.INTERNAL_ERROR, exception.getErrorCode());
assertEquals("Failed to download extension", exception.getDescription());
}

@Test
public void getEntityOwnerIdReturnsSystemAccount() {
assertEquals(Account.ACCOUNT_ID_SYSTEM, cmd.getEntityOwnerId());
}

@Test
public void getApiResourceTypeReturnsExtension() {
assertEquals(ApiCommandResourceType.Extension, cmd.getApiResourceType());
}

@Test
public void getEventTypeReturnsCorrectEventType() {
assertEquals(EventTypes.EVENT_EXTENSION_DOWNLOAD, cmd.getEventType());
}

@Test
public void getEventDescriptionReturnsCorrectDescription() {
Long id = 123L;
ReflectionTestUtils.setField(cmd, "id", id);
assertEquals("Download extension: 123", cmd.getEventDescription());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,24 @@
import org.apache.cloudstack.api.response.ExtensionCustomActionResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.framework.extensions.manager.ExtensionsManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;

@RunWith(MockitoJUnitRunner.class)
public class ListCustomActionCmdTest {

private ListCustomActionCmd cmd;
@Mock
private ExtensionsManager extensionsManager;

@Before
public void setUp() {
cmd = new ListCustomActionCmd();
extensionsManager = mock(ExtensionsManager.class);
ReflectionTestUtils.setField(cmd, "extensionsManager", extensionsManager);
}
@Spy
@InjectMocks
private ListCustomActionCmd cmd;

private void setField(String fieldName, Object value) {
ReflectionTestUtils.setField(cmd, fieldName, value);
Expand Down Expand Up @@ -140,14 +142,10 @@ public void isEnabledReturnsFalseWhenSetFalse() {
@Test
public void executeSetsListResponse() {
List<ExtensionCustomActionResponse> responses = Arrays.asList(mock(ExtensionCustomActionResponse.class));
when(extensionsManager.listCustomActions(cmd)).thenReturn(responses);

ListCustomActionCmd spyCmd = Mockito.spy(cmd);
doNothing().when(spyCmd).setResponseObject(any());

spyCmd.execute();

verify(extensionsManager).listCustomActions(spyCmd);
verify(spyCmd).setResponseObject(any(ListResponse.class));
when(extensionsManager.listCustomActions(any(ListCustomActionCmd.class))).thenReturn(responses);
doNothing().when(cmd).setResponseObject(any());
cmd.execute();
verify(extensionsManager).listCustomActions(cmd);
verify(cmd).setResponseObject(any(ListResponse.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,41 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;

import org.apache.cloudstack.api.ApiConstants;
import org.junit.Before;
import org.apache.cloudstack.api.response.ExtensionResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.framework.extensions.manager.ExtensionsManager;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;

import com.cloud.exception.InvalidParameterValueException;

@RunWith(MockitoJUnitRunner.class)
public class ListExtensionsCmdTest {

private ListExtensionsCmd cmd;

@Before
public void setUp() {
cmd = new ListExtensionsCmd();
}
@Mock
private ExtensionsManager extensionsManager;

@Spy
@InjectMocks
private ListExtensionsCmd cmd;

private void setPrivateField(String fieldName, Object value) {
ReflectionTestUtils.setField(cmd, fieldName, value);
Expand Down Expand Up @@ -89,4 +103,14 @@ public void testGetDetailsWithInvalidValueThrowsException() {
setPrivateField("details", detailsList);
cmd.getDetails();
}

@Test
public void executeSetsListResponse() {
List<ExtensionResponse> responses = Arrays.asList(mock(ExtensionResponse.class));
when(extensionsManager.listExtensions(any(ListExtensionsCmd.class))).thenReturn(responses);
doNothing().when(cmd).setResponseObject(any());
cmd.execute();
verify(extensionsManager).listExtensions(cmd);
verify(cmd).setResponseObject(any(ListResponse.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@
import org.apache.cloudstack.api.response.ExtensionResponse;
import org.apache.cloudstack.extension.Extension;
import org.apache.cloudstack.framework.extensions.manager.ExtensionsManager;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;

@RunWith(MockitoJUnitRunner.class)
public class RegisterExtensionCmdTest {

private RegisterExtensionCmd cmd;
@Mock
private ExtensionsManager extensionsManager;

@Before
public void setUp() {
cmd = Mockito.spy(new RegisterExtensionCmd());
extensionsManager = mock(ExtensionsManager.class);
ReflectionTestUtils.setField(cmd, "extensionsManager", extensionsManager);
}
@Spy
@InjectMocks
private RegisterExtensionCmd cmd;

@Test
public void extensionIdReturnsNullWhenUnset() {
Expand Down
Loading
Loading