Skip to content

Commit

Permalink
remove spring dependencies in dcr endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lashinijay committed Nov 19, 2024
1 parent dc41ff9 commit 4d534df
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 100 deletions.
5 changes: 0 additions & 5 deletions components/org.wso2.carbon.identity.api.server.dcr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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,17 @@ 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 DCRMService oAuthDCRMService = (DCRMService) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(DCRMService.class, null);

public static void setOAuth2DCRMService(DCRMService oAuth2DCRMService) {
public static void setOAuth2DCRMService(DCRMService oAuthDCRMService) {

DCRMUtils.oAuth2DCRMService = oAuth2DCRMService;
DCRMUtils.oAuthDCRMService = oAuthDCRMService;
}

public static DCRMService getOAuth2DCRMService() {

return oAuth2DCRMService;
return oAuthDCRMService;
}

public static ApplicationRegistrationRequest getApplicationRegistrationRequest(
Expand Down Expand Up @@ -307,5 +309,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
@@ -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 Down Expand Up @@ -40,7 +40,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 Down Expand Up @@ -72,6 +71,9 @@ public class RegisterApiServiceImplExceptionTest {
@Mock
DCRMService mockedDCRMService;

@Mock
PrivilegedCarbonContext mockedPrivilegedCarbonContext;

MockedConstruction<ServiceTracker> mockedConstruction;

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

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

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

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

DCRMUtils.setOAuth2DCRMService(mockedDCRMService);
// mockPrivilegedCarbonContext();
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 +220,7 @@ public void testUpdateApplicationClientException() throws DCRMException {
updateRequestDTO.setClientName("Test App");
updateRequestDTO.setGrantTypes(granttypes);
updateRequestDTO.setRedirectUris(redirectUris);
DCRMUtils.setOAuth2DCRMService(mockedDCRMService);
// mockPrivilegedCarbonContext();
dcrDataHolder.when(DCRDataHolder::getInstance).thenReturn(dataHolder);
lenient().when(dataHolder.getApplicationManagementService()).thenReturn(applicationManagementService);

Expand All @@ -242,4 +244,15 @@ public void testUpdateApplicationThrowableException() throws DCRMException {
assertEquals(e.getResponse().getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}

// private void mockPrivilegedCarbonContext() {
//
// try (MockedStatic<PrivilegedCarbonContext> privilegedCarbonContext =
// mockStatic(PrivilegedCarbonContext.class)) {
// privilegedCarbonContext.when(PrivilegedCarbonContext::getThreadLocalCarbonContext)
// .thenReturn(mockedPrivilegedCarbonContext);
// lenient().when(mockedPrivilegedCarbonContext.getOSGiService(DCRMService.class, null)).
// thenReturn(mockedDCRMService);
// }
// }
}

0 comments on commit 4d534df

Please sign in to comment.