use of org.wso2.carbon.apimgt.impl.APIAdminImpl 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);
}
}
use of org.wso2.carbon.apimgt.impl.APIAdminImpl 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);
}
}
use of org.wso2.carbon.apimgt.impl.APIAdminImpl 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);
}
use of org.wso2.carbon.apimgt.impl.APIAdminImpl 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");
}
}
use of org.wso2.carbon.apimgt.impl.APIAdminImpl 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");
}
}
Aggregations