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");
}
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);
}
}
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);
}
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");
}
}
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);
}
Aggregations