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

[Spring Cleanup] Refactor web.xml to remove Spring dependency #2672

Open
wants to merge 115 commits into
base: feature-spring-cleanup
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
cb73abf
Improve OAuth error logs
rksk Aug 24, 2023
c97e43f
Fix missing claims for federated users for jwt token issuers
sandushi Oct 31, 2024
7620e99
Remove unused imports
sandushi Oct 31, 2024
70a2459
Address PR comments
sandushi Nov 1, 2024
4810b2d
support showAuthFailureReason config in password grant
shanggeeth Nov 19, 2024
7802558
Fix Property "renew_token_without_revoking_existing" not being honored
KD23243 Nov 20, 2024
9196f79
Add default method to get access token type
KD23243 Nov 20, 2024
ed69463
Add configuration to disable multi value support for userinfo response
SujanSanjula96 Nov 20, 2024
9b1c5ec
Remove unwanted line
sandushi Nov 20, 2024
eaba6be
Add unit tests
KD23243 Nov 21, 2024
75d8855
Address review comments
KD23243 Nov 21, 2024
704533b
Remove unnecessary new lines
KD23243 Nov 22, 2024
8ee3092
Merge pull request #2630 from KD23243/renew_token_without_revoking_ex…
kayathiri4 Nov 25, 2024
f4d35de
[WSO2 Release] [Jenkins #5117] [Release 7.0.191] prepare release v7.0…
wso2-jenkins-bot Nov 25, 2024
b0cd3a9
[WSO2 Release] [Jenkins #5117] [Release 7.0.191] prepare for next dev…
wso2-jenkins-bot Nov 25, 2024
b68394e
Merge pull request #2145 from rksk/oauth-error-log-improvement
rksk Nov 28, 2024
9cba152
[WSO2 Release] [Jenkins #5119] [Release 7.0.192] prepare release v7.0…
wso2-jenkins-bot Nov 28, 2024
654bc26
[WSO2 Release] [Jenkins #5119] [Release 7.0.192] prepare for next dev…
wso2-jenkins-bot Nov 28, 2024
2f91b22
Upgrade opensaml version
asha15 Dec 2, 2024
74b2650
Fix unnecessary DB queries when revoking tokens
SujanSanjula96 Dec 3, 2024
dab71d6
Merge pull request #2638 from asha15/master
asha15 Dec 4, 2024
9f2bfd7
[WSO2 Release] [Jenkins #5121] [Release 7.0.193] prepare release v7.0…
wso2-jenkins-bot Dec 4, 2024
b91c38d
[WSO2 Release] [Jenkins #5121] [Release 7.0.193] prepare for next dev…
wso2-jenkins-bot Dec 4, 2024
f4d26b2
implementing the user attribute handlig for implicit flow
indeewari Dec 4, 2024
8f4ba1d
Fixing styling
indeewari Dec 4, 2024
84c11d6
Fix app-id not set in the cache
sadilchamishka Dec 5, 2024
0281c42
Merge pull request #2642 from sadilchamishka/spa-issue
sadilchamishka Dec 5, 2024
0a9904a
Adding the test class to testng file
indeewari Dec 5, 2024
a6f1921
[WSO2 Release] [Jenkins #5123] [Release 7.0.194] prepare release v7.0…
wso2-jenkins-bot Dec 5, 2024
9c32672
[WSO2 Release] [Jenkins #5123] [Release 7.0.194] prepare for next dev…
wso2-jenkins-bot Dec 5, 2024
f9ec15d
Merge pull request #2641 from indeewari/user_attributes_for_access_to…
sadilchamishka Dec 5, 2024
092b94b
[WSO2 Release] [Jenkins #5125] [Release 7.0.195] prepare release v7.0…
wso2-jenkins-bot Dec 5, 2024
6d8ab54
[WSO2 Release] [Jenkins #5125] [Release 7.0.195] prepare for next dev…
wso2-jenkins-bot Dec 5, 2024
305c1c5
[Spring Cleanup] Remove spring dependency in client authn filter (#2635)
lashinijay Dec 12, 2024
4677132
[WSO2 Release] [Jenkins #5127] [Release 7.0.196] prepare release v7.0…
wso2-jenkins-bot Dec 12, 2024
4953794
[WSO2 Release] [Jenkins #5127] [Release 7.0.196] prepare for next dev…
wso2-jenkins-bot Dec 12, 2024
ecf0542
Fix DCR not updating application role audience
ThaminduR Dec 16, 2024
6d7e4e8
Update unit test
ThaminduR Dec 16, 2024
02524b9
Merge pull request #2633 from SujanSanjula96/user-info-1
SujanSanjula96 Dec 16, 2024
b48dacf
[WSO2 Release] [Jenkins #5129] [Release 7.0.197] prepare release v7.0…
wso2-jenkins-bot Dec 16, 2024
2f31dda
[WSO2 Release] [Jenkins #5129] [Release 7.0.197] prepare for next dev…
wso2-jenkins-bot Dec 16, 2024
b221f6a
Add license header
sandushi Dec 17, 2024
e2ebb60
Merge branch 'master' into missing-claim
sandushi Dec 17, 2024
f085dc9
Revert "[Spring Cleanup] Remove spring dependency in client authn fil…
lashinijay Dec 17, 2024
7232788
[WSO2 Release] [Jenkins #5131] [Release 7.0.198] prepare release v7.0…
wso2-jenkins-bot Dec 17, 2024
e9a9049
[WSO2 Release] [Jenkins #5131] [Release 7.0.198] prepare for next dev…
wso2-jenkins-bot Dec 17, 2024
83bfbbb
Add a new test case
sandushi Dec 17, 2024
a0bccb8
Merge remote-tracking branch 'origin/missing-claim' into missing-claim
sandushi Dec 17, 2024
df80a31
Improve unit tests
sandushi Dec 17, 2024
1ee62a0
Merge pull request #2489 from shanggeeth/master
shanggeeth Dec 18, 2024
bdc9bca
[WSO2 Release] [Jenkins #5133] [Release 7.0.199] prepare release v7.0…
wso2-jenkins-bot Dec 18, 2024
64f0341
[WSO2 Release] [Jenkins #5133] [Release 7.0.199] prepare for next dev…
wso2-jenkins-bot Dec 18, 2024
b267c63
Remove Entitlements dependency (#2650)
mpmadhavig Dec 18, 2024
51a77e2
[WSO2 Release] [Jenkins #5135] [Release 7.0.200] prepare release v7.0…
wso2-jenkins-bot Dec 18, 2024
337ae4e
[WSO2 Release] [Jenkins #5135] [Release 7.0.200] prepare for next dev…
wso2-jenkins-bot Dec 18, 2024
e607ea0
Added a comment for test class
sandushi Dec 18, 2024
80fc44d
Merge pull request #2613 from sandushi/missing-claim
sandushi Dec 18, 2024
b6a9885
[WSO2 Release] [Jenkins #5137] [Release 7.0.201] prepare release v7.0…
wso2-jenkins-bot Dec 18, 2024
f40ff1a
[WSO2 Release] [Jenkins #5137] [Release 7.0.201] prepare for next dev…
wso2-jenkins-bot Dec 18, 2024
178bdcc
Fix access token attributes for federated user (#2653)
shashimalcse Dec 18, 2024
87c6060
[WSO2 Release] [Jenkins #5139] [Release 7.0.202] prepare release v7.0…
wso2-jenkins-bot Dec 18, 2024
707373c
[WSO2 Release] [Jenkins #5139] [Release 7.0.202] prepare for next dev…
wso2-jenkins-bot Dec 18, 2024
78442d8
fix application roles (#2654)
shashimalcse Dec 19, 2024
daa0726
[WSO2 Release] [Jenkins #5141] [Release 7.0.203] prepare release v7.0…
wso2-jenkins-bot Dec 19, 2024
6c75b2f
[WSO2 Release] [Jenkins #5141] [Release 7.0.203] prepare for next dev…
wso2-jenkins-bot Dec 19, 2024
a178595
Fix oidc claim mapping in jwt access token attributes (#2655)
shashimalcse Dec 19, 2024
3283412
[WSO2 Release] [Jenkins #5143] [Release 7.0.204] prepare release v7.0…
wso2-jenkins-bot Dec 19, 2024
9095d8d
[WSO2 Release] [Jenkins #5143] [Release 7.0.204] prepare for next dev…
wso2-jenkins-bot Dec 19, 2024
c8efd77
Add unit tests for revoke token flow for app audience role update
SujanSanjula96 Jan 2, 2025
c5d5091
Add wrapper for device code grant request
kayathiri4 Jan 3, 2025
1ced028
Add verification for revokeAccessTokens method invocation
SujanSanjula96 Jan 3, 2025
c14d5ef
Refactor code to remove unnecessary iterations
SujanSanjula96 Dec 3, 2024
71fa07f
Merge pull request #2658 from kayathiri4/add-wrapper
kayathiri4 Jan 6, 2025
a2ea184
[WSO2 Release] [Jenkins #5145] [Release 7.0.205] prepare release v7.0…
wso2-jenkins-bot Jan 6, 2025
8a01652
[WSO2 Release] [Jenkins #5145] [Release 7.0.205] prepare for next dev…
wso2-jenkins-bot Jan 6, 2025
4f536d6
add missing columns for AT Audit table
Thumimku Jan 6, 2025
f1420ad
Allow OAuth2 application management through DCR in sub organizations
ShanChathusanda93 Jan 3, 2025
2302b85
Merge pull request #2578 from ShanChathusanda93/dcr-impr-branch
ShanChathusanda93 Jan 7, 2025
a0d6b69
Merge pull request #2661 from Thumimku/modifyATAuditTable
Thumimku Jan 7, 2025
671b850
[WSO2 Release] [Jenkins #5147] [Release 7.0.206] prepare release v7.0…
wso2-jenkins-bot Jan 7, 2025
ebc90b5
[WSO2 Release] [Jenkins #5147] [Release 7.0.206] prepare for next dev…
wso2-jenkins-bot Jan 7, 2025
b2f607e
Merge commit 'ebc90b5cb3a00100af1560bce70cd7bcfd4474ac' into 591c655f…
wso2-jenkins-bot Jan 7, 2025
3491950
[WSO2 Release] [Jenkins #5148] [Release 7.0.207] prepare release v7.0…
wso2-jenkins-bot Jan 7, 2025
f511999
[WSO2 Release] [Jenkins #5148] [Release 7.0.207] prepare for next dev…
wso2-jenkins-bot Jan 7, 2025
8649c99
Merge pull request #2640 from SujanSanjula96/role-v2-patch-token-revo…
SujanSanjula96 Jan 7, 2025
84ca851
[WSO2 Release] [Jenkins #5150] [Release 7.0.208] prepare release v7.0…
wso2-jenkins-bot Jan 7, 2025
e476cfa
[WSO2 Release] [Jenkins #5150] [Release 7.0.208] prepare for next dev…
wso2-jenkins-bot Jan 7, 2025
8ae348e
Merge pull request #2649 from ThaminduR/fix-21627
ThaminduR Jan 7, 2025
bb5eba7
[WSO2 Release] [Jenkins #5152] [Release 7.0.209] prepare release v7.0…
wso2-jenkins-bot Jan 7, 2025
89c8817
[WSO2 Release] [Jenkins #5152] [Release 7.0.209] prepare for next dev…
wso2-jenkins-bot Jan 7, 2025
be46f12
Fix token not revoked when a user is removed from a role
ThaminduDilshan Jan 7, 2025
fad2923
Revert "Fix DCR PUT request not updating application role audience"
ThaminduR Jan 8, 2025
43298dc
Merge pull request #2667 from wso2-extensions/revert-2649-fix-21627
JeethJJ Jan 8, 2025
4387c65
[WSO2 Release] [Jenkins #5154] [Release 7.0.210] prepare release v7.0…
wso2-jenkins-bot Jan 8, 2025
efceef3
[WSO2 Release] [Jenkins #5154] [Release 7.0.210] prepare for next dev…
wso2-jenkins-bot Jan 8, 2025
4a0382c
update SP Audience DCR
Thumimku Jan 9, 2025
5289eb2
Merge pull request #2665 from ThaminduDilshan/thamindu-revoke-fix
ThaminduDilshan Jan 9, 2025
31d6267
[WSO2 Release] [Jenkins #5156] [Release 7.0.211] prepare release v7.0…
wso2-jenkins-bot Jan 9, 2025
5c971ae
[WSO2 Release] [Jenkins #5156] [Release 7.0.211] prepare for next dev…
wso2-jenkins-bot Jan 9, 2025
7e302b5
Merge pull request #2669 from Thumimku/updateSPAudienceInDCR
Thumimku Jan 9, 2025
916717b
[WSO2 Release] [Jenkins #5158] [Release 7.0.212] prepare release v7.0…
wso2-jenkins-bot Jan 9, 2025
60cf7fa
[WSO2 Release] [Jenkins #5158] [Release 7.0.212] prepare for next dev…
wso2-jenkins-bot Jan 9, 2025
292e1db
[WSO2 Release] [Jenkins #5160] [Release 7.0.213] prepare release v7.0…
wso2-jenkins-bot Jan 10, 2025
f11275f
[WSO2 Release] [Jenkins #5160] [Release 7.0.213] prepare for next dev…
wso2-jenkins-bot Jan 10, 2025
cc43689
[Spring Cleanup] Remove spring dependencies in DCR endpoint (#2631)
lashinijay Dec 12, 2024
d44cfa7
Remove spring dependency in Oauth2 scopes endpoint (#2632)
lashinijay Dec 12, 2024
82690aa
[Spring Cleanup] Remove spring dependency in client attestation filte…
lashinijay Dec 12, 2024
d0be90f
[Spring Cleanup] Remove unused DCR endpoint (#2636)
lashinijay Dec 12, 2024
f46861a
remove scopes webapp as it is no longer used (#2645)
lashinijay Dec 12, 2024
ae1efbd
remove spring dependency from main pom.xml (#2646)
lashinijay Dec 12, 2024
b90c21f
[Spring Cleanup] Remove Spring dependency from oauth component (#2648)
lashinijay Jan 8, 2025
e16a602
[Spring Cleanup] Remove unused feature references (#2668)
lashinijay Jan 9, 2025
c6ccbcc
Revert "remove scopes webapp as it is no longer used (#2645)" (#2671)
lashinijay Jan 10, 2025
5c07d99
Revert "[Spring Cleanup] Remove unused DCR endpoint (#2636)" (#2670)
lashinijay Jan 10, 2025
6c1a5b6
refactor oauth.client.authn.filter component
lashinijay Jan 14, 2025
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
13 changes: 6 additions & 7 deletions components/org.wso2.carbon.identity.api.server.dcr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<parent>
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<version>7.0.191-SNAPSHOT</version>
<version>7.0.214-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.api.server.dcr</artifactId>
<version>7.0.191-SNAPSHOT</version>
<version>7.0.214-SNAPSHOT</version>
<name>WSO2 Carbon - User DCR Rest API</name>
<description>WSO2 Carbon - User DCR Rest API</description>

Expand All @@ -48,11 +48,6 @@
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -151,6 +146,10 @@
<artifactId>jaxp-ri</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.testutil</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

public class RegisterApiServiceFactory {

private final static RegisterApiService service = new RegisterApiServiceImpl();
private static final RegisterApiService SERVICE = new RegisterApiServiceImpl();

public static RegisterApiService getRegisterApi()
{
return service;
return SERVICE;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2017-2024, WSO2 LLC. (http://www.wso2.org).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* WSO2 LLC. 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
Expand All @@ -20,6 +20,7 @@

import org.apache.commons.logging.Log;
import org.slf4j.MDC;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.oauth.dcr.DCRMConstants;
import org.wso2.carbon.identity.oauth.dcr.bean.Application;
import org.wso2.carbon.identity.oauth.dcr.bean.ApplicationRegistrationRequest;
Expand All @@ -44,16 +45,15 @@ public class DCRMUtils {
private static final String NOT_FOUND_STATUS = "NOT_FOUND_";
private static final String FORBIDDEN_STATUS = "FORBIDDEN_";

private static DCRMService oAuth2DCRMService;
private static class OAuth2DCRMServiceHolder {

public static void setOAuth2DCRMService(DCRMService oAuth2DCRMService) {

DCRMUtils.oAuth2DCRMService = oAuth2DCRMService;
private static final DCRMService SERVICE = (DCRMService) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(DCRMService.class, null);
}

public static DCRMService getOAuth2DCRMService() {

return oAuth2DCRMService;
return OAuth2DCRMServiceHolder.SERVICE;
}

public static ApplicationRegistrationRequest getApplicationRegistrationRequest(
Expand Down Expand Up @@ -307,5 +307,4 @@ private static DCRMEndpointException buildDCRMEndpointException(Response.Status
return new DCRMEndpointException(status, errorDTO);
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
import org.wso2.carbon.context.internal.OSGiDataHolder;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
import org.wso2.carbon.identity.common.testng.WithCarbonHome;
import org.wso2.carbon.identity.oauth.dcr.exception.DCRMException;
import org.wso2.carbon.identity.oauth.dcr.internal.DCRDataHolder;
import org.wso2.carbon.identity.oauth.dcr.service.DCRMService;
import org.wso2.carbon.identity.oauth2.dcr.endpoint.TestUtil;
import org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.RegistrationRequestDTO;
import org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.UpdateRequestDTO;
import org.wso2.carbon.identity.oauth2.dcr.endpoint.exceptions.DCRMEndpointException;
import org.wso2.carbon.identity.oauth2.dcr.endpoint.util.DCRMUtils;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -49,11 +49,13 @@

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockConstruction;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;

@WithCarbonHome
@Listeners(MockitoTestNGListener.class)
public class RegisterApiServiceImplExceptionTest {

Expand All @@ -70,13 +72,22 @@ public class RegisterApiServiceImplExceptionTest {
ApplicationManagementService applicationManagementService;

@Mock
DCRMService mockedDCRMService;
PrivilegedCarbonContext privilegedCarbonContext;

MockedConstruction<ServiceTracker> mockedConstruction;
private MockedStatic<PrivilegedCarbonContext> mockedPrivilegedCarbonContext;

@BeforeMethod
public void setUp() throws Exception {

if (mockedPrivilegedCarbonContext != null) {
mockedPrivilegedCarbonContext.close();
}
mockedPrivilegedCarbonContext = mockStatic(PrivilegedCarbonContext.class);
when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
lenient().when(PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getOSGiService(DCRMService.class, null)).thenReturn(mock(DCRMService.class));

// Initializing variables.
registerApiService = new RegisterApiServiceImpl();

Expand Down Expand Up @@ -104,7 +115,6 @@ public void tearDown() {
public void testDeleteApplicationClientException() throws Exception {

try {
DCRMUtils.setOAuth2DCRMService(mockedDCRMService);
registerApiService.deleteApplication("");
} catch (DCRMEndpointException e) {
assertEquals(e.getResponse().getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
Expand All @@ -126,7 +136,6 @@ public void testDeleteApplicationThrowableException() throws DCRMException {
public void testGetApplicationClientException() throws Exception {

try {
DCRMUtils.setOAuth2DCRMService(mockedDCRMService);
registerApiService.getApplication("");
} catch (DCRMEndpointException e) {
assertEquals(e.getResponse().getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
Expand Down Expand Up @@ -155,7 +164,6 @@ public void testRegisterApplicationClientException() throws DCRMException {
registrationRequestDTO.setClientName("Test App");
registrationRequestDTO.setGrantTypes(granttypes);
registrationRequestDTO.setRedirectUris(redirectUris);
DCRMUtils.setOAuth2DCRMService(mockedDCRMService);
dcrDataHolder.when(DCRDataHolder::getInstance).thenReturn(dataHolder);
lenient().when(dataHolder.getApplicationManagementService()).thenReturn(applicationManagementService);

Expand All @@ -180,7 +188,6 @@ public void testRegisterApplicationServerException() throws DCRMException, Ident
registrationRequestDTO.setGrantTypes(granttypes);
registrationRequestDTO.setRedirectUris(redirectUris);

DCRMUtils.setOAuth2DCRMService(mockedDCRMService);
dcrDataHolder.when(DCRDataHolder::getInstance).thenReturn(dataHolder);
lenient().when(dataHolder.getApplicationManagementService()).thenReturn(applicationManagementService);
lenient().when(applicationManagementService.getServiceProvider(any(String.class), any(String.class))).
Expand Down Expand Up @@ -218,7 +225,6 @@ public void testUpdateApplicationClientException() throws DCRMException {
updateRequestDTO.setClientName("Test App");
updateRequestDTO.setGrantTypes(granttypes);
updateRequestDTO.setRedirectUris(redirectUris);
DCRMUtils.setOAuth2DCRMService(mockedDCRMService);
dcrDataHolder.when(DCRDataHolder::getInstance).thenReturn(dataHolder);
lenient().when(dataHolder.getApplicationManagementService()).thenReturn(applicationManagementService);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.mockito.Mock;
import org.mockito.MockedConstruction;
import org.mockito.MockedStatic;
import org.mockito.testng.MockitoTestNGListener;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
Expand All @@ -30,6 +31,7 @@
import org.testng.annotations.Test;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.context.internal.OSGiDataHolder;
import org.wso2.carbon.identity.common.testng.WithCarbonHome;
import org.wso2.carbon.identity.oauth.dcr.bean.Application;
import org.wso2.carbon.identity.oauth.dcr.bean.ApplicationRegistrationRequest;
import org.wso2.carbon.identity.oauth.dcr.bean.ApplicationUpdateRequest;
Expand All @@ -40,7 +42,6 @@
import org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.RegistrationRequestDTO;
import org.wso2.carbon.identity.oauth2.dcr.endpoint.dto.UpdateRequestDTO;
import org.wso2.carbon.identity.oauth2.dcr.endpoint.exceptions.DCRMEndpointException;
import org.wso2.carbon.identity.oauth2.dcr.endpoint.util.DCRMUtils;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -49,11 +50,13 @@

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockConstruction;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

@WithCarbonHome
@Listeners(MockitoTestNGListener.class)
public class RegisterApiServiceImplTest {

Expand All @@ -69,10 +72,20 @@ public class RegisterApiServiceImplTest {
@Mock
private DCRMService dcrmService;

@Mock
PrivilegedCarbonContext privilegedCarbonContext;

MockedConstruction<ServiceTracker> mockedConstruction;
private MockedStatic<PrivilegedCarbonContext> mockedPrivilegedCarbonContext;

@BeforeMethod
public void setUp() throws Exception {

mockedPrivilegedCarbonContext = mockStatic(PrivilegedCarbonContext.class);
lenient().when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
lenient().when(PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getOSGiService(DCRMService.class, null)).thenReturn(mock(DCRMService.class));

//Initializing variables.
registerApiService = new RegisterApiServiceImpl();
validclientId = "N2QqQluzQuL5X6CtM3KZwqzLQhUa";
Expand Down Expand Up @@ -101,16 +114,15 @@ public void tearDown() {

mockedConstruction.close();
PrivilegedCarbonContext.endTenantFlow();
mockedPrivilegedCarbonContext.close();
}

@Test
public void testDeleteApplication() throws Exception {

DCRMUtils.setOAuth2DCRMService(dcrmService);
doNothing().when(dcrmService).deleteApplication(validclientId);
lenient().doNothing().when(dcrmService).deleteApplication(validclientId);
Assert.assertEquals(registerApiService.deleteApplication(validclientId).getStatus(),
Response.Status.NO_CONTENT.getStatusCode());

}

@Test
Expand All @@ -127,8 +139,7 @@ public void testDeleteApplicationServerException() throws Exception {
@Test
public void testGetApplication() throws Exception {

DCRMUtils.setOAuth2DCRMService(dcrmService);
when(dcrmService.getApplication(validclientId)).thenReturn(application);
lenient().when(dcrmService.getApplication(validclientId)).thenReturn(application);
Assert.assertEquals(registerApiService.getApplication(validclientId).getStatus(),
Response.Status.OK.getStatusCode());

Expand All @@ -153,8 +164,7 @@ public void testRegisterApplication() throws Exception {

RegistrationRequestDTO registrationRequestDTO = new RegistrationRequestDTO();
registrationRequestDTO.setClientName("app1");
DCRMUtils.setOAuth2DCRMService(dcrmService);
when(dcrmService.registerApplication(any(ApplicationRegistrationRequest.class)))
lenient().when(dcrmService.registerApplication(any(ApplicationRegistrationRequest.class)))
.thenReturn(application);
Assert.assertEquals(registerApiService.registerApplication(registrationRequestDTO)
.getStatus(), Response.Status.CREATED.getStatusCode());
Expand All @@ -179,8 +189,7 @@ public void testUpdateApplication() throws Exception {
UpdateRequestDTO updateRequestDTO1 = new UpdateRequestDTO();
updateRequestDTO1.setClientName("Client1");
String clientID = "clientID1";
DCRMUtils.setOAuth2DCRMService(dcrmService);
when(dcrmService.updateApplication
lenient().when(dcrmService.updateApplication
(any(ApplicationUpdateRequest.class), anyString()))
.thenReturn(application);
Assert.assertEquals(registerApiService.updateApplication(updateRequestDTO1, clientID)
Expand Down
Loading