use of org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder in project carbon-apimgt by wso2.
the class GatewayUtilsTestCase method testGetAPIasNull.
@Test
public void testGetAPIasNull() {
MessageContext messageContext = Mockito.mock(MessageContext.class);
SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
Mockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
Mockito.when(subscriptionDataHolder.getTenantSubscriptionStore("carbon.super")).thenReturn(subscriptionDataStore);
Mockito.when(messageContext.getProperty(RESTConstants.REST_API_CONTEXT)).thenReturn("/abc1");
Mockito.when(messageContext.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION)).thenReturn("1.0.0");
Assert.assertNull(GatewayUtils.getAPI(messageContext));
Assert.assertNull(GatewayUtils.getAPINameFromContextAndVersion(messageContext));
Assert.assertNull(GatewayUtils.getApiProviderFromContextAndVersion(messageContext));
Mockito.verify(messageContext, Mockito.times(0)).setProperty(Mockito.anyString(), Mockito.any());
Mockito.verify(messageContext, Mockito.times(6)).getProperty(APIMgtGatewayConstants.API_OBJECT);
Mockito.verify(messageContext, Mockito.times(3)).getProperty(RESTConstants.REST_API_CONTEXT);
Mockito.verify(messageContext, Mockito.times(3)).getProperty(RESTConstants.SYNAPSE_REST_API_VERSION);
Mockito.verify(subscriptionDataStore, Mockito.times(3)).getApiByContextAndVersion("/abc1", "1.0.0");
}
use of org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder in project carbon-apimgt by wso2.
the class UtilsTest method getSelectedAPI.
@Test
public void getSelectedAPI() {
SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
Mockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
Mockito.when(subscriptionDataHolder.getTenantSubscriptionStore("carbon.super")).thenReturn(subscriptionDataStore);
Mockito.when(subscriptionDataStore.getAllAPIsByContextList()).thenReturn(apiMap());
Map<String, API> selectedAPIList = Utils.getSelectedAPIList("/api1/cde?c=y", "carbon.super");
Assert.assertEquals(selectedAPIList.size(), 1);
Assert.assertEquals(selectedAPIList.keySet().iterator().next(), "/api1");
}
use of org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder in project carbon-apimgt by wso2.
the class TokenGenTest method setUp.
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(CarbonUtils.class);
PowerMockito.mockStatic(SubscriptionDataHolder.class);
ServerConfiguration serverConfiguration = Mockito.mock(ServerConfiguration.class);
Mockito.when(serverConfiguration.getFirstProperty(APIConstants.PORT_OFFSET_CONFIG)).thenReturn("2");
PowerMockito.when(CarbonUtils.getServerConfiguration()).thenReturn(serverConfiguration);
String dbConfigPath = System.getProperty("APIManagerDBConfigurationPath");
APIManagerConfiguration config = new APIManagerConfiguration();
config.load(dbConfigPath);
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(new APIManagerConfigurationServiceImpl(config));
SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
PowerMockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
PowerMockito.when(SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)).thenReturn(subscriptionDataStore);
Application application = new Application();
application.setId(1);
application.setName("app2");
application.setUUID(UUID.randomUUID().toString());
application.addAttribute("abc", "cde");
Mockito.when(subscriptionDataStore.getApplicationById(1)).thenReturn(application);
}
use of org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder in project carbon-apimgt by wso2.
the class GatewayUtilsTestCase method testGetAPI.
@Test
public void testGetAPI() {
API api = new API();
api.setApiName("api1");
api.setApiVersion("1.0.0");
api.setApiProvider("admin");
MessageContext messageContext = Mockito.mock(MessageContext.class);
SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
Mockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
Mockito.when(subscriptionDataHolder.getTenantSubscriptionStore("carbon.super")).thenReturn(subscriptionDataStore);
Mockito.when(subscriptionDataStore.getApiByContextAndVersion("/abc", "1.0.0")).thenReturn(api);
Mockito.when(messageContext.getProperty(RESTConstants.REST_API_CONTEXT)).thenReturn("/abc");
Mockito.when(messageContext.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION)).thenReturn("1.0.0");
Assert.assertEquals(GatewayUtils.getAPI(messageContext), api);
Assert.assertEquals(GatewayUtils.getAPINameFromContextAndVersion(messageContext), "api1");
Assert.assertEquals(GatewayUtils.getApiProviderFromContextAndVersion(messageContext), "admin");
Mockito.verify(messageContext, Mockito.times(6)).getProperty(APIMgtGatewayConstants.API_OBJECT);
Mockito.verify(messageContext, Mockito.times(3)).getProperty(RESTConstants.REST_API_CONTEXT);
Mockito.verify(messageContext, Mockito.times(3)).getProperty(RESTConstants.SYNAPSE_REST_API_VERSION);
Mockito.verify(subscriptionDataStore, Mockito.times(3)).getApiByContextAndVersion("/abc", "1.0.0");
}
use of org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder in project carbon-apimgt by wso2.
the class GatewayUtilsTestCase method testGetAPIasNullWhenTenantSubscriptionStoreNull.
@Test
public void testGetAPIasNullWhenTenantSubscriptionStoreNull() {
MessageContext messageContext = Mockito.mock(MessageContext.class);
SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
Mockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
Mockito.when(subscriptionDataHolder.getTenantSubscriptionStore("carbon.super")).thenReturn(null);
Mockito.when(messageContext.getProperty(RESTConstants.REST_API_CONTEXT)).thenReturn("/abc1");
Mockito.when(messageContext.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION)).thenReturn("1.0.0");
Assert.assertNull(GatewayUtils.getAPI(messageContext));
Assert.assertNull(GatewayUtils.getStatus(messageContext));
Mockito.verify(messageContext, Mockito.times(0)).setProperty(Mockito.anyString(), Mockito.any());
Mockito.verify(messageContext, Mockito.times(4)).getProperty(APIMgtGatewayConstants.API_OBJECT);
Mockito.verify(messageContext, Mockito.times(2)).getProperty(RESTConstants.REST_API_CONTEXT);
Mockito.verify(messageContext, Mockito.times(2)).getProperty(RESTConstants.SYNAPSE_REST_API_VERSION);
Mockito.verify(subscriptionDataStore, Mockito.times(0)).getApiByContextAndVersion("/abc1", "1.0.0");
}
Aggregations