Search in sources :

Example 1 with APIMConfigService

use of org.wso2.carbon.apimgt.impl.config.APIMConfigService in project carbon-apimgt by wso2.

the class APIAdminImplTest method getTenantConfig.

@Test
public void getTenantConfig() throws APIManagementException {
    APIAdmin apiAdmin = new APIAdminImpl();
    Mockito.when(apimConfigService.getTenantConfig("abc.com")).thenReturn("abcde");
    Assert.assertEquals(apiAdmin.getTenantConfig("abc.com"), "abcde");
    Mockito.verify(apimConfigService, Mockito.times(1)).getTenantConfig("abc.com");
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Test(org.junit.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with APIMConfigService

use of org.wso2.carbon.apimgt.impl.config.APIMConfigService in project carbon-apimgt by wso2.

the class APIAdminImplTest method updateTenantConfigNegative1.

// Schema not present
@Test
public void updateTenantConfigNegative1() throws Exception {
    File siteConfFile = new File(Thread.currentThread().getContextClassLoader().getResource("tenant-conf.json").getFile());
    String tenantConf = FileUtils.readFileToString(siteConfFile);
    PowerMockito.doNothing().when(APIUtil.class, "validateRestAPIScopes", tenantConf);
    Schema schema = Mockito.mock(Schema.class);
    PowerMockito.when(APIUtil.class, "retrieveTenantConfigJsonSchema").thenReturn(null);
    APIAdmin apiAdmin = new APIAdminImpl();
    Mockito.doNothing().when(apimConfigService).updateTenantConfig("abc.com", tenantConf);
    try {
        apiAdmin.updateTenantConfig("abc.com", tenantConf);
        Assert.fail("Method successfully invoked");
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "tenant-config validation failure");
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.INTERNAL_ERROR);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Schema(org.everit.json.schema.Schema) APIUtil(org.wso2.carbon.apimgt.impl.utils.APIUtil) File(java.io.File) Test(org.junit.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with APIMConfigService

use of org.wso2.carbon.apimgt.impl.config.APIMConfigService in project carbon-apimgt by wso2.

the class APIAdminImplTest method updateTenantConfig.

@Test
public void updateTenantConfig() throws Exception {
    File siteConfFile = new File(Thread.currentThread().getContextClassLoader().getResource("tenant-conf.json").getFile());
    String tenantConf = FileUtils.readFileToString(siteConfFile);
    PowerMockito.doNothing().when(APIUtil.class, "validateRestAPIScopes", tenantConf);
    Schema schema = Mockito.mock(Schema.class);
    PowerMockito.when(APIUtil.class, "retrieveTenantConfigJsonSchema").thenReturn(schema);
    Mockito.doNothing().when(schema).validate(Mockito.any());
    APIAdmin apiAdmin = new APIAdminImpl();
    Mockito.doNothing().when(apimConfigService).updateTenantConfig("abc.com", tenantConf);
    apiAdmin.updateTenantConfig("abc.com", tenantConf);
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Schema(org.everit.json.schema.Schema) APIUtil(org.wso2.carbon.apimgt.impl.utils.APIUtil) File(java.io.File) Test(org.junit.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with APIMConfigService

use of org.wso2.carbon.apimgt.impl.config.APIMConfigService in project carbon-apimgt by wso2.

the class APIAdminImplTest method updateTenantConfigNegative2.

// invalid json
@Test
public void updateTenantConfigNegative2() throws Exception {
    String tenantConf = "{\"hello\"";
    PowerMockito.doNothing().when(APIUtil.class, "validateRestAPIScopes", tenantConf);
    APIAdmin apiAdmin = new APIAdminImpl();
    Schema schema = Mockito.mock(Schema.class);
    PowerMockito.when(APIUtil.class, "retrieveTenantConfigJsonSchema").thenReturn(schema);
    Mockito.doNothing().when(apimConfigService).updateTenantConfig("abc.com", tenantConf);
    try {
        apiAdmin.updateTenantConfig("abc.com", tenantConf);
        Assert.fail("Method successfully invoked");
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "tenant-config validation failure");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Schema(org.everit.json.schema.Schema) APIUtil(org.wso2.carbon.apimgt.impl.utils.APIUtil) Test(org.junit.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with APIMConfigService

use of org.wso2.carbon.apimgt.impl.config.APIMConfigService in project carbon-apimgt by wso2.

the class APIAdminImplTest method setup.

@Before
public void setup() {
    PowerMockito.mockStatic(APIUtil.class);
    PowerMockito.mockStatic(ApiMgtDAO.class);
    ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
    PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
    apimConfigService = Mockito.mock(APIMConfigService.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) APIMConfigService(org.wso2.carbon.apimgt.impl.config.APIMConfigService) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 APIMConfigService (org.wso2.carbon.apimgt.impl.config.APIMConfigService)13 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)13 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)8 File (java.io.File)7 RealmService (org.wso2.carbon.user.core.service.RealmService)7 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)7 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)6 BeforeTest (org.testng.annotations.BeforeTest)5 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)5 Schema (org.everit.json.schema.Schema)4 Matchers.anyString (org.mockito.Matchers.anyString)4 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 Tier (org.wso2.carbon.apimgt.api.model.Tier)4 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)4 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)4 ApiMgtDAOMockCreator (org.wso2.carbon.apimgt.impl.ApiMgtDAOMockCreator)4 APIUtil (org.wso2.carbon.apimgt.impl.utils.APIUtil)4 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)4