Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test for discoverable shared applications flow #412

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo;
import org.wso2.carbon.identity.application.common.model.ServiceProvider;
import org.wso2.carbon.identity.application.common.model.ServiceProviderProperty;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
Expand All @@ -32,8 +33,10 @@
import org.wso2.carbon.identity.organization.management.application.model.MainApplicationDO;
import org.wso2.carbon.identity.organization.management.application.model.SharedApplicationDO;
import org.wso2.carbon.identity.organization.management.service.OrganizationManager;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -45,6 +48,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.wso2.carbon.identity.organization.management.application.constant.OrgApplicationMgtConstants.IS_FRAGMENT_APP;

/**
Expand Down Expand Up @@ -272,4 +276,38 @@ public void testGetChildAppIdsWithInvalidParentAppId() throws Exception {

Assert.assertEquals(resolvedChildAppIdMap, Collections.emptyMap());
}

@Test
public void testGetDiscoverableSharedApplicationBasicInfo() throws OrganizationManagementException {

String tenantDomain = "abc.com";
String rootOrgId = "root-org-id";

ApplicationBasicInfo app1 = new ApplicationBasicInfo();
app1.setApplicationName("App1");
app1.setDescription("Description1");
ApplicationBasicInfo app2 = new ApplicationBasicInfo();
app2.setApplicationName("App2");
app2.setDescription("Description2");
List<ApplicationBasicInfo> expectedApps = Arrays.asList(app1, app2);
when(organizationManager.getPrimaryOrganizationId(tenantDomain)).thenReturn(rootOrgId);
when(orgApplicationMgtDAO.getDiscoverableSharedApplicationBasicInfo(10, 0, "*",
"ASC", "dummyName", tenantDomain, rootOrgId)).thenReturn(expectedApps);
List<ApplicationBasicInfo> actualApps = orgApplicationManager.getDiscoverableSharedApplicationBasicInfo(
10, 0, "*", "ASC", "dummyName", tenantDomain);
assertEquals(expectedApps, actualApps);
}

@Test
public void testGetCountOfDiscoverableSharedApplications() throws OrganizationManagementException {

int expectedCount = 5;

when(organizationManager.getPrimaryOrganizationId("dummyTenant")).thenReturn("rootOrg123");
when(orgApplicationMgtDAO.getCountOfDiscoverableSharedApplications("*", "dummyTenant",
"rootOrg123")).thenReturn(5);

int actualCount = orgApplicationManager.getCountOfDiscoverableSharedApplications("*", "dummyTenant");
assertEquals(expectedCount, actualCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
import org.wso2.carbon.identity.organization.management.service.OrganizationManager;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;

import java.lang.reflect.Method;
import java.util.Optional;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.assertEquals;
Expand Down Expand Up @@ -90,6 +92,8 @@ public void setUp() {
OrgApplicationMgtDataHolder.getInstance().setOrganizationManager(organizationManager);
OrgApplicationMgtDataHolder.getInstance().setOrgApplicationMgtDAO(orgApplicationMgtDAO);
OrgApplicationMgtDataHolder.getInstance().setApplicationManagementService(applicationManagementService);
mockedUtilities = Mockito.mockStatic(IdentityTenantUtil.class, Mockito.withSettings()
.defaultAnswer(Mockito.CALLS_REAL_METHODS));
}

@DataProvider(name = "subOrganizationMetaData")
Expand Down Expand Up @@ -214,10 +218,21 @@ private ServiceProviderProperty mockServiceProviderProperty(String name, String
return property;
}

@Test
public void testInheritDiscoverabilityProperty() throws Exception {

ServiceProvider mainApplication = mock(ServiceProvider.class);
when(mainApplication.isDiscoverable()).thenReturn(true);
when(serviceProvider.isDiscoverable()).thenReturn(false);
Method method = fragmentApplicationMgtListener.getClass()
.getDeclaredMethod("inheritDiscoverabilityProperty", ServiceProvider.class, ServiceProvider.class);
method.setAccessible(true);
method.invoke(fragmentApplicationMgtListener, mainApplication, serviceProvider);
verify(serviceProvider).setDiscoverable(true);
}

private void mockUtils(String requestInitiatedDomain) {

mockedUtilities = Mockito.mockStatic(IdentityTenantUtil.class, Mockito.withSettings()
.defaultAnswer(Mockito.CALLS_REAL_METHODS));
mockedUtilities.when(() -> IdentityTenantUtil.getTenantDomainFromContext()).thenReturn(requestInitiatedDomain);
}

Expand Down
Loading