Search in sources :

Example 6 with APIManagerFactory

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);
}
Also used : API(org.wso2.carbon.apimgt.core.models.API) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with APIManagerFactory

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);
}
Also used : APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) NotificationDTO(org.wso2.carbon.apimgt.core.template.dto.NotificationDTO) Set(java.util.Set) HashSet(java.util.HashSet) NotificationConfigurations(org.wso2.carbon.apimgt.core.configuration.models.NotificationConfigurations) NotificationExecutor(org.wso2.carbon.apimgt.core.executors.NotificationExecutor) APIMConfigurations(org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) Properties(java.util.Properties) HashSet(java.util.HashSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with APIManagerFactory

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());
}
Also used : Response(org.wso2.msf4j.Response) AccessTokenInfo(org.wso2.carbon.apimgt.core.models.AccessTokenInfo) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) ServiceMethodInfo(org.wso2.msf4j.ServiceMethodInfo) OAuth2Authenticator(org.wso2.carbon.apimgt.rest.api.common.impl.OAuth2Authenticator) Request(org.wso2.msf4j.Request) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with APIManagerFactory

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());
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with APIManagerFactory

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());
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.junit.Test)28 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)28 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)27 Response (javax.ws.rs.core.Response)23 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)17 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)6 ArrayList (java.util.ArrayList)5 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)5 API (org.wso2.carbon.apimgt.core.models.API)5 Request (org.wso2.msf4j.Request)4 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)3 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)3 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)2 ThreatProtectionPolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThreatProtectionPolicyDTO)2 File (java.io.File)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Properties (java.util.Properties)1 Set (java.util.Set)1 APIMConfigurations (org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations)1