Skip to content

Commit

Permalink
Addressed comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Jan 24, 2025
1 parent e00f179 commit 6a309ee
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.wso2.carbon.identity.action.execution;

import org.wso2.carbon.identity.action.execution.impl.DefaultResponseData;
import org.wso2.carbon.identity.action.execution.model.ActionType;
import org.wso2.carbon.identity.action.execution.model.ResponseData;

Expand All @@ -39,5 +40,8 @@ public interface ActionInvocationResponseClassProvider {
*
* @return The extended ResponseData class.
*/
Class<? extends ResponseData> getSuccessResponseDataClass();
default Class<? extends ResponseData> getSuccessResponseDataClass() {

return DefaultResponseData.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ private ActionExecutionStatus<Success> processSuccessResponse(Action action,
validatePerformableOperations(actionRequest, successResponse.getOperations(), action);
ActionInvocationSuccessResponse.Builder successResponseBuilder =
new ActionInvocationSuccessResponse.Builder().actionStatus(ActionInvocationResponse.Status.SUCCESS)
.operations(allowedPerformableOperations);
.operations(allowedPerformableOperations)
.responseData(successResponse.getData());
return actionExecutionResponseProcessor.processSuccessResponse(eventContext,
actionRequest.getEvent(), successResponseBuilder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
package org.wso2.carbon.identity.action.execution.impl;

import org.wso2.carbon.identity.action.execution.ActionInvocationResponseClassProvider;
import org.wso2.carbon.identity.action.execution.DefaultActionInvocationResponseClassProvider;
import org.wso2.carbon.identity.action.execution.model.ActionType;
import org.wso2.carbon.identity.action.execution.model.ResponseData;

import java.util.HashMap;
import java.util.Map;

/**
* This class defines the classes for extended implementations of action invocation responses for
* This class manages ActionInvocationResponseClassProvider implementations that extends action invocation responses for
* different action types.
* The ActionInvocationResponseClassFactory is the component that is responsible for providing the classes
* defined by the downstream component based on the action type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
* under the License.
*/

package org.wso2.carbon.identity.action.execution;
package org.wso2.carbon.identity.action.execution.impl;

import org.wso2.carbon.identity.action.execution.ActionInvocationResponseClassProvider;
import org.wso2.carbon.identity.action.execution.model.ActionType;
import org.wso2.carbon.identity.action.execution.model.DefaultResponseData;
import org.wso2.carbon.identity.action.execution.model.ResponseData;

/**
* Default implementation of the ActionInvocationResponseClassProvider. The downStream components need to extend
Expand All @@ -37,17 +36,7 @@ public static DefaultActionInvocationResponseClassProvider getInstance() {
@Override
public ActionType getSupportedActionType() {

throw new UnsupportedOperationException("This method should not called for default implementation.");
}

/**
* Get the default ResponseData class for action invocation success response.
*
* @return The default ResponseData class.
*/
@Override
public Class<? extends ResponseData> getSuccessResponseDataClass() {

return DefaultResponseData.class;
throw new UnsupportedOperationException(
"This method is not allowed for DefaultActionInvocationResponseClassProvider.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* under the License.
*/

package org.wso2.carbon.identity.action.execution.model;
package org.wso2.carbon.identity.action.execution.impl;

import org.wso2.carbon.identity.action.execution.model.ResponseData;

/**
* Default ResponseData implementation, which can be used when there are no extended ResponseData class for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
* under the License.
*/

package org.wso2.carbon.identity.action.execution.model;
package org.wso2.carbon.identity.action.execution.impl;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.wso2.carbon.identity.action.execution.impl.ActionInvocationResponseClassFactory;
import org.wso2.carbon.identity.action.execution.model.ActionType;
import org.wso2.carbon.identity.action.execution.model.ResponseData;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import org.wso2.carbon.identity.action.execution.impl.ResponseDataDeserializer;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.wso2.carbon.identity.action.execution.exception.ActionInvocationException;
import org.wso2.carbon.identity.action.execution.impl.ResponseDataDeserializer;
import org.wso2.carbon.identity.action.execution.model.ActionExecutionStatus;
import org.wso2.carbon.identity.action.execution.model.ActionInvocationErrorResponse;
import org.wso2.carbon.identity.action.execution.model.ActionInvocationFailureResponse;
Expand All @@ -44,7 +45,6 @@
import org.wso2.carbon.identity.action.execution.model.ActionInvocationSuccessResponse;
import org.wso2.carbon.identity.action.execution.model.ActionType;
import org.wso2.carbon.identity.action.execution.model.ResponseData;
import org.wso2.carbon.identity.action.execution.model.ResponseDataDeserializer;

import java.io.IOException;
import java.net.SocketTimeoutException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.wso2.carbon.identity.action.execution.model.Operation;
import org.wso2.carbon.identity.action.execution.model.Organization;
import org.wso2.carbon.identity.action.execution.model.Param;
import org.wso2.carbon.identity.action.execution.model.PerformableOperation;
import org.wso2.carbon.identity.action.execution.model.Request;
import org.wso2.carbon.identity.action.execution.model.SuccessStatus;
import org.wso2.carbon.identity.action.execution.model.Tenant;
Expand Down Expand Up @@ -447,9 +448,13 @@ public void testActionExecuteSuccessWhenNoRuleConfiguredInAction() throws Except
.getActionExecutionResponseProcessor(any()))
.thenReturn(actionExecutionResponseProcessor);

requestFilter.when(() -> RequestFilter.getFilteredHeaders(any(), any())).thenReturn(new ArrayList<Header>());
requestFilter.when(() -> RequestFilter.getFilteredParams(any(), any())).thenReturn(new ArrayList<Param>());

ActionExecutionRequest actionExecutionRequest = createActionExecutionRequest(actionType);
when(actionExecutionRequestBuilder.getSupportedActionType()).thenReturn(actionType);
when(actionExecutionRequestBuilder.buildActionExecutionRequest(eventContext)).thenReturn(
mock(ActionExecutionRequest.class));
actionExecutionRequest);

ActionInvocationResponse actionInvocationResponse =
createSuccessActionInvocationResponse();
Expand Down Expand Up @@ -491,9 +496,13 @@ public void testActionExecuteSuccessWhenRuleConfiguredInActionIsSatisfied() thro
.getActionExecutionResponseProcessor(any()))
.thenReturn(actionExecutionResponseProcessor);

requestFilter.when(() -> RequestFilter.getFilteredHeaders(any(), any())).thenReturn(new ArrayList<Header>());
requestFilter.when(() -> RequestFilter.getFilteredParams(any(), any())).thenReturn(new ArrayList<Param>());

ActionExecutionRequest actionExecutionRequest = createActionExecutionRequest(actionType);
when(actionExecutionRequestBuilder.getSupportedActionType()).thenReturn(actionType);
when(actionExecutionRequestBuilder.buildActionExecutionRequest(eventContext)).thenReturn(
mock(ActionExecutionRequest.class));
actionExecutionRequest);

ActionInvocationResponse actionInvocationResponse = createSuccessActionInvocationResponse();
when(apiClient.callAPI(any(), any(), any(), any())).thenReturn(actionInvocationResponse);
Expand Down Expand Up @@ -675,9 +684,14 @@ private String getJSONRequestPayload(ActionExecutionRequest actionExecutionReque

private ActionInvocationResponse createSuccessActionInvocationResponse() throws Exception {

PerformableOperation performableOp = new PerformableOperation();
performableOp.setOp(Operation.ADD);
performableOp.setPath("/accessToken/claims/-");
performableOp.setValue("testValue");

ActionInvocationSuccessResponse successResponse = mock(ActionInvocationSuccessResponse.class);
when(successResponse.getActionStatus()).thenReturn(ActionInvocationResponse.Status.SUCCESS);
when(successResponse.getOperations()).thenReturn(Collections.emptyList());
when(successResponse.getOperations()).thenReturn(new ArrayList<>(Collections.singletonList(performableOp)));

ActionInvocationResponse actionInvocationResponse = mock(ActionInvocationResponse.class);
setField(actionInvocationResponse, "actionStatus", ActionInvocationResponse.Status.SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.testng.annotations.Test;
import org.wso2.carbon.identity.action.execution.model.ActionType;
import org.wso2.carbon.identity.action.execution.model.DefaultResponseData;
import org.wso2.carbon.identity.action.execution.model.ResponseData;
import org.wso2.carbon.identity.action.execution.util.TestActionInvocationResponseClassProvider;
import org.wso2.carbon.identity.action.execution.util.UserData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ public void testCallAPIUnacceptableContentTypeForSuccessResponse()
@DataProvider(name = "unacceptableSuccessResponsePayloads")
public String[] unacceptableSuccessResponsePayloads() {

return new String[]{"{}", "", "success", "{\"actionStatus\":\"ERROR\"}, " +
"{\"actionStatus\": \"FAILED\"}"};
return new String[]{"{}", "", "success", "{\"actionStatus\":\"ERROR\"}, " + "{\"actionStatus\": \"FAILED\"}"};
}

@Test(dataProvider = "unacceptableSuccessResponsePayloads")
Expand Down Expand Up @@ -472,10 +471,9 @@ public void testCallAPIRetryOnTimeoutAndReceiveSuccessResponse() throws Exceptio
}

@Test
public void testCallAPIRetryOnTimeoutAndReceiveSuccessResponseWithExtendedResponseData() throws Exception {
public void testReceiveSuccessResponseWithExtendedResponseData() throws Exception {

when(httpClient.execute(any(HttpPost.class))).thenThrow(new ConnectTimeoutException("Timeout"))
.thenReturn(httpResponse);
when(httpClient.execute(any(HttpPost.class))).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(statusLine);
when(statusLine.getStatusCode()).thenReturn(200);

Expand All @@ -494,7 +492,6 @@ public void testCallAPIRetryOnTimeoutAndReceiveSuccessResponseWithExtendedRespon

assertNotNull(response);
assertTrue(response.isSuccess());
verify(httpClient, times(2)).execute(any(HttpPost.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package org.wso2.carbon.identity.action.execution.util;

import org.wso2.carbon.identity.action.execution.DefaultActionInvocationResponseClassProvider;
import org.wso2.carbon.identity.action.execution.impl.DefaultActionInvocationResponseClassProvider;
import org.wso2.carbon.identity.action.execution.model.ActionType;
import org.wso2.carbon.identity.action.execution.model.ResponseData;

Expand Down

0 comments on commit 6a309ee

Please sign in to comment.