use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIKeyValidationServiceTest method Init.
@Before
public void Init() throws Exception {
System.setProperty(CARBON_HOME, "");
privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
metricService = Mockito.mock(MetricService.class);
org.wso2.carbon.metrics.manager.ServiceReferenceHolder serviceReferenceHolder1 = Mockito.mock(org.wso2.carbon.metrics.manager.ServiceReferenceHolder.class);
Timer timer = Mockito.mock(Timer.class);
Timer.Context timerContext = Mockito.mock(Timer.Context.class);
MessageContext messageContext = Mockito.mock(MessageContext.class);
OperationContext operationContext = Mockito.mock(OperationContext.class);
MessageContext responseMessageContext = Mockito.mock(MessageContext.class);
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PowerMockito.mockStatic(ApiMgtDAO.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.mockStatic(org.wso2.carbon.metrics.manager.ServiceReferenceHolder.class);
PowerMockito.mockStatic(APIKeyMgtUtil.class);
PowerMockito.mockStatic(MessageContext.class);
PowerMockito.mockStatic(APIKeyMgtDataHolder.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
PowerMockito.when(privilegedCarbonContext.getUsername()).thenReturn(USER_NAME);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
PowerMockito.when(MessageContext.getCurrentMessageContext()).thenReturn(messageContext);
PowerMockito.when(APIKeyMgtDataHolder.isJwtGenerationEnabled()).thenReturn(true);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_KEY_MANGER_VALIDATIONHANDLER_CLASS_NAME)).thenReturn(API_KEY_MANGER_VALIDATION_HANDLER_CLASS_NAME);
Mockito.when(org.wso2.carbon.metrics.manager.ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder1);
Mockito.when(serviceReferenceHolder1.getMetricService()).thenReturn(metricService);
Mockito.when(timer.start()).thenReturn(timerContext);
Mockito.when(metricService.timer(Mockito.anyString(), Mockito.any(org.wso2.carbon.metrics.manager.Level.class))).thenReturn(timer);
Mockito.when(messageContext.getOperationContext()).thenReturn(operationContext);
Mockito.when(operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE)).thenReturn(responseMessageContext);
Map headers = new HashMap();
headers.put("activityID", "1s2f2g4g5");
Mockito.when(messageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS)).thenReturn(headers);
String cacheKey = APIUtil.getAccessTokenCacheKey(ACCESS_TOKEN, API_CONTEXT, API_VERSION, "/*", "GET", REQUIRED_AUTHENTICATION_LEVEL);
APIKeyValidationInfoDTO infoDTO = new APIKeyValidationInfoDTO();
infoDTO.setApiPublisher(USER_NAME);
infoDTO.setEndUserName(USER_NAME);
PowerMockito.when(APIKeyMgtUtil.getFromKeyManagerCache(cacheKey)).thenReturn(infoDTO);
}
use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class InboundWebsocketProcessorUtilTest method init.
@Before
public void init() {
System.setProperty("carbon.home", "jhkjn");
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
PowerMockito.mockStatic(ThrottleDataPublisher.class);
dataPublisher = Mockito.mock(DataPublisher.class);
ThrottleDataPublisher throttleDataPublisher = Mockito.mock(ThrottleDataPublisher.class);
Mockito.when(serviceReferenceHolder.getThrottleDataPublisher()).thenReturn(throttleDataPublisher);
PowerMockito.when(ThrottleDataPublisher.getDataPublisher()).thenReturn(dataPublisher);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
PowerMockito.when(serviceReferenceHolder.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
PowerMockito.mockStatic(WebsocketUtil.class);
}
use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIMgtGoogleAnalyticsUtilsTestCase method testPublishGATrackingData.
@Test
public void testPublishGATrackingData() {
APIMgtGoogleAnalyticsUtils apiMgtGoogleAnalyticsUtils = new APIMgtGoogleAnalyticsUtils();
GoogleAnalyticsData.DataBuilder dataBuilder = Mockito.mock(GoogleAnalyticsData.DataBuilder.class);
// test when gaConfig == null
apiMgtGoogleAnalyticsUtils.publishGATrackingData(dataBuilder, "abc", "567r637r6");
// test when gaConfig != null
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry userRegistry = Mockito.mock(UserRegistry.class);
Resource resource = Mockito.mock(Resource.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
try {
Mockito.when(resource.getContentStream()).thenReturn(new ByteArrayInputStream(Charset.forName("UTF-16").encode("<GoogleAnalyticsTracking>\n" + "\t<!--Enable/Disable Google Analytics Tracking -->\n" + "\t<Enabled>false</Enabled>\n" + "\n" + "\t<!-- Google Analytics Tracking ID -->\n" + "\t<TrackingID>UA-XXXXXXXX-X</TrackingID>\n" + "\n" + "</GoogleAnalyticsTracking>").array()));
Mockito.when(userRegistry.get("/apimgt/statistics/ga-config.xml")).thenReturn(resource);
} catch (RegistryException e) {
fail("RegistryException is thrown when tesing .");
e.printStackTrace();
}
try {
Mockito.when(registryService.getGovernanceSystemRegistry()).thenReturn(userRegistry);
} catch (RegistryException e) {
fail("RegistryException is thrown.");
}
apiMgtGoogleAnalyticsUtils.init("abc.com");
// test when gaconfig.enabled=false
apiMgtGoogleAnalyticsUtils.publishGATrackingData(dataBuilder, "ishara", "jhgy");
// test when gaconfig.enabled=true annonymous
try {
Mockito.when(resource.getContentStream()).thenReturn(new ByteArrayInputStream(Charset.forName("UTF-16").encode("<GoogleAnalyticsTracking>\n" + "\t<!--Enable/Disable Google Analytics Tracking -->\n" + "\t<Enabled>true</Enabled>\n" + "\n" + "\t<!-- Google Analytics Tracking ID -->\n" + "\t<TrackingID>UA-XXXXXXXX-X</TrackingID>\n" + "\n" + "</GoogleAnalyticsTracking>").array()));
apiMgtGoogleAnalyticsUtils.init("abc.com");
GoogleAnalyticsData.DataBuilder dataBuilder1 = Mockito.mock(GoogleAnalyticsData.DataBuilder.class);
Mockito.when(dataBuilder.setProtocolVersion("1")).thenReturn(dataBuilder);
Mockito.when(dataBuilder.setTrackingId("UA-XXXXXXXX-X")).thenReturn(dataBuilder);
Mockito.when(dataBuilder.setClientId("0x05a823c101178dd5")).thenReturn(dataBuilder);
Mockito.when(dataBuilder.setHitType("pageview")).thenReturn(dataBuilder);
GoogleAnalyticsData data = Mockito.mock(GoogleAnalyticsData.class);
Mockito.when(dataBuilder.build()).thenReturn(data);
PowerMockito.mockStatic(GoogleAnalyticsDataPublisher.class);
PowerMockito.when(GoogleAnalyticsDataPublisher.buildPayloadString(data)).thenReturn("payload");
} catch (RegistryException e) {
fail(e.getMessage());
}
apiMgtGoogleAnalyticsUtils.publishGATrackingData(dataBuilder, "ishara", "Autorization ishara");
}
use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class GatewayUtilsTestCase method setup.
@Before
public void setup() {
System.setProperty("carbon.home", "jhkjn");
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.mockStatic(RegistryServiceHolder.class);
PowerMockito.mockStatic(SubscriptionDataHolder.class);
PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
RegistryServiceHolder registryServiceHolder = Mockito.mock(RegistryServiceHolder.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
userRegistry = Mockito.mock(UserRegistry.class);
resource = Mockito.mock(Resource.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
PowerMockito.when(RegistryServiceHolder.getInstance()).thenReturn(registryServiceHolder);
Mockito.when(registryServiceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(privilegedCarbonContext.getTenantId()).thenReturn(tenantID);
Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn("carbon.super");
try {
Mockito.when(registryService.getConfigSystemRegistry(tenantID)).thenReturn(userRegistry);
} catch (RegistryException e) {
fail("Error while mocking registryService.getConfigSystemRegistry");
}
try {
Mockito.when(userRegistry.get(path)).thenReturn(resource);
} catch (RegistryException e) {
fail("Error while mocking userRegistry.get(path)");
}
}
use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIUtilTest method testGetTokenEndpointsByType.
@Test
public void testGetTokenEndpointsByType() throws Exception {
System.setProperty("carbon.home", APIUtilTest.class.getResource("/").getFile());
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Environment environment = new Environment();
environment.setType("production");
environment.setName("Production");
environment.setDefault(true);
environment.setApiGatewayEndpoint("http://localhost:8280,https://localhost:8243");
Map<String, Environment> environmentMap = new HashMap<String, Environment>();
environmentMap.put("Production", environment);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(apiManagerConfiguration.getApiGatewayEnvironments()).thenReturn(environmentMap);
ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
PowerMockito.mockStatic(ApiMgtDAO.class);
Mockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
Mockito.when(apiMgtDAO.getAllEnvironments(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)).thenReturn(new ArrayList<org.wso2.carbon.apimgt.api.model.Environment>());
String tokenEndpointType = APIUtil.getTokenEndpointsByType("production", "61416403c40f086ad2dc5eef");
Assert.assertEquals("https://localhost:8243", tokenEndpointType);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
Aggregations