Search in sources :

Example 16 with APIAdmin

use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.

the class APIAdminImplTest method getTenantConfigException.

@Test
public void getTenantConfigException() throws APIManagementException {
    APIAdmin apiAdmin = new APIAdminImpl();
    Mockito.when(apimConfigService.getTenantConfig("abc.com")).thenThrow(APIManagementException.class);
    try {
        apiAdmin.getTenantConfig("abc.com");
        Assert.fail("Method successfully invoked");
    } catch (APIManagementException e) {
        Assert.assertTrue(true);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Test(org.junit.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with APIAdmin

use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.

the class APIAdminImplTest method getTenantConfigSchemaException.

@Test
public void getTenantConfigSchemaException() throws Exception {
    APIAdmin apiAdmin = new APIAdminImpl();
    PowerMockito.when(APIUtil.class, "retrieveTenantConfigJsonSchema").thenThrow(APIManagementException.class);
    try {
        apiAdmin.getTenantConfigSchema("abc.com");
        Assert.fail("Method successfully invoked");
    } catch (APIManagementException e) {
        Assert.assertTrue(true);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) 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 18 with APIAdmin

use of org.wso2.carbon.apimgt.api.APIAdmin 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 19 with APIAdmin

use of org.wso2.carbon.apimgt.api.APIAdmin 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 20 with APIAdmin

use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.

the class APIAdminImplTest method updateTenantConfigNegative3.

// valid json element missing
@Test
public void updateTenantConfigNegative3() throws Exception {
    String tenantConf = "{\"hello\":\"world\"}";
    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.doThrow(ValidationException.class).when(schema).validate(Mockito.any());
    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)

Aggregations

APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)46 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)39 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)31 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 BeforeTest (org.testng.annotations.BeforeTest)8 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)8 APIUtil (org.wso2.carbon.apimgt.impl.utils.APIUtil)6 ArrayList (java.util.ArrayList)5 Schema (org.everit.json.schema.Schema)5 File (java.io.File)4 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 BotDetectionData (org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData)4 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)4 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)4 GlobalPolicy (org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy)4 Policy (org.wso2.carbon.apimgt.api.model.policy.Policy)4 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)4 Gson (com.google.gson.Gson)3