Skip to content

Commit

Permalink
Add testcase fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
JeethJJ committed Oct 16, 2024
1 parent 964c6d3 commit 390d2fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@ public ApplicationBasicInfo[] getApplicationBasicInfo(String filter, int offset,

List<String> filterValues = filterData.getFilterValues();
String filterString = filterData.getFilterString();
String excludeSystemPortalsQueryString = populateSystemPortalsExcludeQuery(excludeSystemPortals);
String excludeSystemPortalsQueryString = populateSystemPortalsExcludeQuery(excludeSystemPortals, true);

String databaseProductName = connection.getMetaData().getDatabaseProductName();
if (databaseProductName.contains("MySQL")
Expand Down Expand Up @@ -2184,16 +2184,19 @@ public ApplicationBasicInfo[] getApplicationBasicInfo(String filter, int offset,
/**
* Get query to exclude system portals if excludeSystemPortals is true.
*
* @param excludeSystemPortals Exclude system portals.
* @return
* @param excludeSystemPortals Exclude system portals.
* @param useTableNameInQuery Use the table name in query.
* @return String Query to exclude system portals.
*/
private String populateSystemPortalsExcludeQuery(Boolean excludeSystemPortals) {
private String populateSystemPortalsExcludeQuery(Boolean excludeSystemPortals, Boolean useTableNameInQuery) {

if (excludeSystemPortals) {
String excludeSystemPortalsQuery = useTableNameInQuery ?
ApplicationMgtDBQueries.EXCLUDE_SYSTEM_PORTALS_BY_TABLE_NAME_AND_NAME :
ApplicationMgtDBQueries.EXCLUDE_SYSTEM_PORTALS_BY_NAME;
Set<String> systemPortals = getSystemPortalsFromConfiguration(SYSTEM_PORTALS);
return systemPortals.isEmpty() ? "" :
String.format(ApplicationMgtDBQueries.EXCLUDE_SYSTEM_PORTALS_BY_NAME,
systemPortals.stream()
String.format(excludeSystemPortalsQuery, systemPortals.stream()
.map(s -> "'" + s + "'")
.collect(Collectors.joining(", ")));
} else {
Expand Down Expand Up @@ -4061,7 +4064,7 @@ public int getCountOfApplications(String filter, Boolean excludeSystemPortals)

FilterData filterData = getFilterDataForDBQuery(filter);
String filterString = filterData.getFilterString();
String excludeSystemPortalsQueryString = populateSystemPortalsExcludeQuery(excludeSystemPortals);
String excludeSystemPortalsQueryString = populateSystemPortalsExcludeQuery(excludeSystemPortals, true);

try {
String filterValueResolvedForSQL;
Expand Down Expand Up @@ -4223,7 +4226,7 @@ public ApplicationBasicInfo[] getApplicationBasicInfo(int offset, int limit, Boo
ResultSet appNameResultSet = null;
String sqlQuery;
ArrayList<ApplicationBasicInfo> appInfo = new ArrayList<ApplicationBasicInfo>();
String excludeSystemPortalsQueryString = populateSystemPortalsExcludeQuery(excludeSystemPortals);
String excludeSystemPortalsQueryString = populateSystemPortalsExcludeQuery(excludeSystemPortals, false);

try {
String databaseProductName = connection.getMetaData().getDatabaseProductName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ public class ApplicationMgtDBQueries {
"THUMBPRINTS, IS_FIDO_TRUSTED FROM SP_TRUSTED_APPS WHERE SP_ID = ? AND TENANT_ID = ?";
public static final String LOAD_TRUSTED_APPS_BY_PLATFORM_TYPE = "SELECT APP_IDENTIFIER, THUMBPRINTS, " +
"IS_FIDO_TRUSTED FROM SP_TRUSTED_APPS WHERE PLATFORM_TYPE = ?";
public static final String EXCLUDE_SYSTEM_PORTALS_BY_NAME = "AND SP_APP.APP_NAME NOT IN (%s)";
public static final String EXCLUDE_SYSTEM_PORTALS_BY_TABLE_NAME_AND_NAME = "AND SP_APP.APP_NAME NOT IN (%s)";
public static final String EXCLUDE_SYSTEM_PORTALS_BY_NAME = "AND APP_NAME NOT IN (%s)";

// DELETE queries
public static final String REMOVE_APP_FROM_APPMGT_APP = "DELETE FROM SP_APP WHERE APP_NAME = ? AND TENANT_ID = ?";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.PlatformType;
import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.TEMPLATE_ID_SP_PROPERTY_NAME;
import static org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.TEMPLATE_VERSION_SP_PROPERTY_NAME;
import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.APPLICATION_NAME_CONFIG_ELEMENT;
import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.PORTAL_NAME_CONFIG_ELEMENT;
import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.SYSTEM_PORTALS;
import static org.wso2.carbon.identity.application.mgt.ApplicationConstants.TRUSTED_APP_CONSENT_REQUIRED_PROPERTY;
import static org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
Expand Down Expand Up @@ -505,7 +505,7 @@ private void setupExcludeSystemPortalsEnv() throws IdentityApplicationManagement
OMElement mockPortalsOMElement = mock(OMElement.class);

when(mockConfigParser.getConfigElement(SYSTEM_PORTALS)).thenReturn(mockOMElement);
when(mockOMElement.getChildrenWithLocalName(APPLICATION_NAME_CONFIG_ELEMENT)).thenReturn(portals);
when(mockOMElement.getChildrenWithLocalName(PORTAL_NAME_CONFIG_ELEMENT)).thenReturn(portals);
when(portals.hasNext()).thenReturn(true).thenReturn(false);
when(portals.next()).thenReturn(mockPortalsOMElement);
when(mockPortalsOMElement.getText()).thenReturn(APPLICATION_NAME_3);
Expand Down

0 comments on commit 390d2fe

Please sign in to comment.