use of org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils in project identity-governance by wso2-extensions.
the class MeApiServiceImplTest method testMeResendCodePost.
@Test
public void testMeResendCodePost() throws IdentityRecoveryException {
try {
String carbonHome = Paths.get(System.getProperty("user.dir"), "src", "test", "resources").toString();
System.setProperty(CarbonBaseConstants.CARBON_HOME, carbonHome);
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(USERNAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(-1234);
Mockito.when(resendConfirmationManager.resendConfirmationCode(isNull(), anyString(), anyString(), anyString(), isNull())).thenReturn(notificationResponseBean);
mockedUtils.when(() -> Utils.getUserRecoveryData(any(ResendCodeRequestDTO.class), anyString())).thenReturn(userRecoveryData);
mockedUtils.when(Utils::getResendConfirmationManager).thenReturn(resendConfirmationManager);
Mockito.when(userRecoveryData.getRecoveryScenario()).thenReturn(RecoveryScenarios.getRecoveryScenario("MOBILE_VERIFICATION_ON_UPDATE"));
Mockito.when(userRecoveryData.getRecoveryStep()).thenReturn(RecoverySteps.getRecoveryStep("VERIFY_MOBILE_NUMBER"));
assertEquals(meApiService.meResendCodePost(meResendCodeRequestDTO()).getStatus(), 201);
assertEquals(meApiService.meResendCodePost(meResendCodeRequestDTOWithInvalidScenarioProperty()).getStatus(), 400);
mockedUtils.when(() -> Utils.getUserRecoveryData(any(ResendCodeRequestDTO.class), anyString())).thenReturn(null);
assertEquals(meApiService.meResendCodePost(meResendCodeRequestDTO()).getStatus(), 400);
Mockito.when(userRecoveryData.getRecoveryScenario()).thenReturn(RecoveryScenarios.getRecoveryScenario("ASK_PASSWORD"));
assertEquals(meApiService.meResendCodePost(meResendCodeRequestDTO()).getStatus(), 400);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils in project identity-governance by wso2-extensions.
the class PiInfoApiServiceImplTest method testGetUserById.
@Test
public void testGetUserById() throws Exception {
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
Mockito.when(tenantManager.getTenantId(anyString())).thenReturn(-1234);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
PiInfoApiServiceImpl piInfoApiService = new PiInfoApiServiceImpl();
mockedUtils.when(Utils::getRealmService).thenReturn(realmService);
mockedUtils.when(Utils::getUserInformationService).thenReturn(new MockUserInformationService());
Assert.assertEquals(piInfoApiService.getUserById("ZHVtbXlVc2Vy").getStatus(), 200);
}
use of org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils in project product-is by wso2.
the class OAuth2TokenRevokeAfterCacheTimeOutTestCase method testRevokeTokenAfterCacheTimedOut.
/**
* This tests written for test for token revocation after cache timed out CARBON-15028
* This test needed two APIM nodes with clustering enabled
* During the test one node is use to generate the token and other node use to revoke the token
* After cache timeout new token should issued after it revoked
*
* @throws Exception
*/
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.ALL })
@Test(description = "Revoke token after cache timed out")
public void testRevokeTokenAfterCacheTimedOut() throws Exception {
// Application utils
OAuthConsumerAppDTO appDto = createApplication();
consumerKey = appDto.getOauthConsumerKey();
consumerSecret = appDto.getOauthConsumerSecret();
// request for token
String token = requestAccessToken(consumerKey, consumerSecret, TOKEN_API_ENDPOINT, "admin", "admin");
// Sleep for 1m for cache timeout
Thread.sleep(60 * 1000);
// Revoke access token
revokeAccessToken(consumerKey, consumerSecret, token, REVOKE_TOKEN_API_ENDPOINT);
// Generate new token
String newToken = requestAccessToken(consumerKey, consumerSecret, TOKEN_API_ENDPOINT, "admin", "admin");
Assert.assertNotEquals(token, newToken, "Token revocation failed");
}
use of org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils in project carbon-apimgt by wso2.
the class UtilsTestCase method setup.
@Before
public void setup() {
messageContext = Mockito.mock(Axis2MessageContext.class);
axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext.class);
Mockito.when(axis2MsgCntxt.getProperty(APIMgtGatewayConstants.REQUEST_RECEIVED_TIME)).thenReturn("1506576365");
Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.mockStatic(Axis2Sender.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
PowerMockito.when(serviceReferenceHolder.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
try {
PowerMockito.doNothing().when(Axis2Sender.class, "sendBack", messageContext);
} catch (Exception e) {
e.printStackTrace();
fail("Exception is thrown while setup Utils test cases");
}
headers = Mockito.mock(Map.class);
}
use of org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils in project ballerina by ballerina-lang.
the class IterableCodeDesugar method createForeachVariables.
/* Some Utils methods */
private List<BLangVariable> createForeachVariables(IterableContext ctx, BLangVariable firstOperationArg, BLangFunction funcNode) {
List<BLangVariable> foreachVariables = new ArrayList<>();
if (firstOperationArg.type.tag != TypeTags.TUPLE) {
foreachVariables.add(firstOperationArg);
defineVariable(firstOperationArg, ctx.env.enclPkg.symbol.pkgID, funcNode);
return foreachVariables;
}
final List<BType> tupleTypes = ((BTupleType) firstOperationArg.type).tupleTypes;
int index = 0;
for (BType type : tupleTypes) {
String varName = VAR_FOREACH_VAL + index++;
final BLangVariable variable = ASTBuilderUtil.createVariable(funcNode.pos, varName, type);
foreachVariables.add(variable);
defineVariable(variable, ctx.env.enclPkg.symbol.pkgID, funcNode);
}
return foreachVariables;
}
Aggregations