use of org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder in project carbon-apimgt by wso2.
the class GatewayUtilsTestCase method testGetAPIFromProperty.
@Test
public void testGetAPIFromProperty() {
API api = Mockito.mock(API.class);
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");
Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.API_OBJECT)).thenReturn(api);
Assert.assertEquals(GatewayUtils.getAPI(messageContext), api);
Mockito.verify(messageContext, Mockito.times(1)).getProperty(APIMgtGatewayConstants.API_OBJECT);
Mockito.verify(messageContext, Mockito.times(0)).getProperty(RESTConstants.REST_API_CONTEXT);
Mockito.verify(messageContext, Mockito.times(0)).getProperty(RESTConstants.SYNAPSE_REST_API_VERSION);
Mockito.verify(subscriptionDataStore, Mockito.times(0)).getApiByContextAndVersion("/abc", "1.0.0");
}
Aggregations