use of org.wso2.carbon.apimgt.core.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ApiStoreSdkGenerationManagerTestCase method testGenerateSdkForApiIncorrectSwagger.
@Test(expected = NullPointerException.class)
public void testGenerateSdkForApiIncorrectSwagger() throws APIManagementException, ApiStoreSdkGenerationException {
String apiId = UUID.randomUUID().toString();
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
Mockito.when(instance.getAPIConsumer(USER)).thenReturn(apiStore);
API api = SampleTestObjectCreator.createDefaultAPI().build();
Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
Mockito.when(apiStore.getApiSwaggerDefinition(apiId)).thenReturn(null);
ApiStoreSdkGenerationManager sdkGenerationManager = new ApiStoreSdkGenerationManager();
sdkGenerationManager.generateSdkForApi(apiId, LANGUAGE, USER);
}
use of org.wso2.carbon.apimgt.core.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class NotificationTestCase method testNotificationExecutor.
@Test
public void testNotificationExecutor() throws Exception {
Properties properties = Mockito.mock(Properties.class);
NotificationDTO notificationDTO = Mockito.mock(NotificationDTO.class);
Mockito.when(notificationDTO.getTitle()).thenReturn("Title");
Mockito.when(notificationDTO.getType()).thenReturn("ApiNewVersion");
Mockito.when(notificationDTO.getMessage()).thenReturn("Message");
Mockito.when(notificationDTO.getProperties()).thenReturn(properties);
APIMConfigurations apimConfigurations = Mockito.mock(APIMConfigurations.class);
NotificationConfigurations notificationConfigurations = Mockito.mock(NotificationConfigurations.class);
PowerMockito.mockStatic(APIMConfigurations.class);
PowerMockito.when(apimConfigurations.getNotificationConfigurations()).thenReturn(notificationConfigurations);
APIManagerFactory apiManagerFactory = Mockito.mock(APIManagerFactory.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
Set subscriber = new HashSet();
subscriber.add("User");
Mockito.when((Set<String>) notificationDTO.getProperty(NotifierConstants.SUBSCRIBERS_PER_API)).thenReturn(subscriber);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(apiManagerFactory);
PowerMockito.when(apiManagerFactory.getIdentityProvider()).thenReturn(identityProvider);
PowerMockito.when(identityProvider.getIdOfUser("User")).thenReturn("1111");
PowerMockito.when(identityProvider.getEmailOfUser("1111")).thenReturn("admin@gmail.com");
new NotificationExecutor().sendAsyncNotifications(notificationDTO);
}
use of org.wso2.carbon.apimgt.core.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class OAuth2AuthenticatorTestCase method testOauthAuthenticate.
@Test
public void testOauthAuthenticate() throws Exception {
HTTPCarbonMessage carbonMessage = Mockito.mock(HTTPCarbonMessage.class);
Request requestObj = new Request(carbonMessage);
Response responseObj = Mockito.mock(Response.class);
ServiceMethodInfo serviceMethodInfoObj = Mockito.mock(ServiceMethodInfo.class);
final String authorizationHttpHeader = "Bearer 7d33e3cd-60f0-3484-9651-cc31f2e09fb4";
final String accessToken = "7d33e3cd-60f0-3484-9651-cc31f2e09fb4";
Mockito.when(requestObj.getHeader(RestApiConstants.AUTHORIZATION_HTTP_HEADER)).thenReturn(authorizationHttpHeader);
AccessTokenInfo accessTokenInfo = new AccessTokenInfo();
accessTokenInfo.setTokenValid(true);
accessTokenInfo.setEndUserName("admin@carbon.super");
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getIdentityProvider()).thenReturn(identityProvider);
Mockito.when(identityProvider.getTokenMetaData(accessToken)).thenReturn(accessTokenInfo);
when((String) requestObj.getProperty(APIConstants.REQUEST_URL)).thenReturn("/api/am/publisher/");
OAuth2Authenticator oAuth2Authenticator = new OAuth2Authenticator();
oAuth2Authenticator.authenticate(requestObj, responseObj, serviceMethodInfoObj);
Assert.assertEquals(0, responseObj.getStatusCode());
}
use of org.wso2.carbon.apimgt.core.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method apisApiIdGatewayConfigExceptionTestCase.
@Test
public void apisApiIdGatewayConfigExceptionTestCase() throws Exception {
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
String apiID = UUID.randomUUID().toString();
String message = "Error while retrieving gateway config of API " + apiID;
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
APIManagementException apiManagementException = new APIManagementException(message, ExceptionCodes.GATEWAY_EXCEPTION);
Mockito.when(instance.getAPIMgtAdminService()).thenThrow(apiManagementException);
Response response = apisApiService.apisApiIdGatewayConfigGet(apiID, null, getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
use of org.wso2.carbon.apimgt.core.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method apisApiIdGatewayConfigGetTestCase.
@Test
public void apisApiIdGatewayConfigGetTestCase() throws Exception {
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
String apiID = UUID.randomUUID().toString();
String gatewayConfig = "package deployment.org.wso2.apim;\n" + "import ballerina.net.http;\n" + "\n" + "@http:BasePath(\"/aaa1\")\n" + "service aaa1_1489666767745 {\n" + "\n" + " @http:GET\n" + " @http:Path(\"/*\")\n" + " resource get_star_ (message m) {\n" + " http:ClientConnector productionEndpoint = create http:ClientConnector(getUrlFromKey" + "(\"aaa1_1.0.0__ep\"));\n http:ClientConnector sandboxEndpoint = create http:ClientConnector" + "(getUrlFromKey(\"aaa1_1.0.0__ep\"));\n message response;\n string endpointType;\n string " + "productionType;\n \n \n endpointType = \"production\";\n productionType = \"production\";\n" + "\n if (endpointType == productionType) {\n" + " response = http:ClientConnector.execute(productionEndpoint, \"get\", \"\", m);\n" + " } else {\n" + " response = http:ClientConnector.execute(sandboxEndpoint, \"get\", \"\", m);\n" + " }\n" + "\n" + " reply response;\n" + " }\n" + "}";
Mockito.when(adminService.getAPIGatewayServiceConfig(apiID)).thenReturn(gatewayConfig);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(adminService);
Response response = apisApiService.apisApiIdGatewayConfigGet(apiID, null, getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
}
Aggregations