use of org.wso2.carbon.utils.ConfigurationContextService in project carbon-apimgt by wso2.
the class TestUtils method initConfigurationContextService.
/**
* To initialize the (@link {@link ConfigurationContextService}} for testing.
*
* @return initialized configuration context service.
*/
public static ConfigurationContextService initConfigurationContextService(boolean initAPIMConfigurationService) throws XMLStreamException {
ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
AxisConfiguration axisConfiguration = Mockito.mock(AxisConfiguration.class);
Mockito.doReturn(axisConfiguration).when(configurationContext).getAxisConfiguration();
TransportInDescription transportInDescription = Mockito.mock(TransportInDescription.class);
Mockito.doReturn(transportInDescription).when(axisConfiguration).getTransportIn(Mockito.anyString());
Parameter dynamicSSLProfilesConfigParameter = Mockito.mock(Parameter.class);
Mockito.when(dynamicSSLProfilesConfigParameter.getParameterElement()).thenReturn(getDynamicSSLElement());
Mockito.when(transportInDescription.getParameter("dynamicSSLProfilesConfig")).thenReturn(dynamicSSLProfilesConfigParameter);
TransportOutDescription transportOutDescription = Mockito.mock(TransportOutDescription.class);
Mockito.doReturn(transportOutDescription).when(axisConfiguration).getTransportOut(Mockito.anyString());
Mockito.when(transportOutDescription.getParameter("dynamicSSLProfilesConfig")).thenReturn(dynamicSSLProfilesConfigParameter);
Mockito.doReturn(configurationContext).when(configurationContextService).getServerConfigContext();
if (initAPIMConfigurationService) {
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.doReturn("true").when(apiManagerConfiguration).getFirstProperty(APIConstants.ENABLE_MTLS_FOR_APIS);
Mockito.doReturn(apiManagerConfiguration).when(apiManagerConfigurationService).getAPIManagerConfiguration();
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(apiManagerConfigurationService);
}
ServiceReferenceHolder.setContextService(configurationContextService);
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
System.setProperty("javax.net.ssl.trustStore", ".");
return configurationContextService;
}
use of org.wso2.carbon.utils.ConfigurationContextService in project carbon-apimgt by wso2.
the class APIUtil method getRegistryResourceHTTPPermlink.
/**
* This is to get the registry resource's HTTP permlink path.
* Once this issue is fixed (https://wso2.org/jira/browse/REGISTRY-2110),
* we can remove this method, and get permlink from the resource.
*
* @param path - Registry resource path
* @return {@link String} -HTTP permlink
*/
public static String getRegistryResourceHTTPPermlink(String path) {
String schemeHttp = APIConstants.HTTP_PROTOCOL;
String schemeHttps = APIConstants.HTTPS_PROTOCOL;
ConfigurationContextService contetxservice = ServiceReferenceHolder.getContextService();
// First we will try to generate http permalink and if its disabled then only we will consider https
int port = CarbonUtils.getTransportProxyPort(contetxservice.getServerConfigContext(), schemeHttp);
if (port == -1) {
port = CarbonUtils.getTransportPort(contetxservice.getServerConfigContext(), schemeHttp);
}
// getting https parameters if http is disabled. If proxy port is not present we will go for default port
if (port == -1) {
port = CarbonUtils.getTransportProxyPort(contetxservice.getServerConfigContext(), schemeHttps);
}
if (port == -1) {
port = CarbonUtils.getTransportPort(contetxservice.getServerConfigContext(), schemeHttps);
}
String webContext = ServerConfiguration.getInstance().getFirstProperty("WebContextRoot");
if (webContext == null || "/".equals(webContext)) {
webContext = "";
}
RegistryService registryService = ServiceReferenceHolder.getInstance().getRegistryService();
String version = "";
if (registryService == null) {
log.error("Registry Service has not been set.");
} else if (path != null) {
try {
String[] versions = registryService.getRegistry(CarbonConstants.REGISTRY_SYSTEM_USERNAME, CarbonContext.getThreadLocalCarbonContext().getTenantId()).getVersions(path);
if (versions != null && versions.length > 0) {
version = versions[0].substring(versions[0].lastIndexOf(";version:"));
}
} catch (RegistryException e) {
log.error("An error occurred while determining the latest version of the " + "resource at the given path: " + path, e);
}
}
if (port != -1 && path != null) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
return webContext + ((tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) ? "/" + MultitenantConstants.TENANT_AWARE_URL_PREFIX + "/" + tenantDomain : "") + "/registry/resource" + org.wso2.carbon.registry.app.Utils.encodeRegistryPath(path) + version;
}
return null;
}
use of org.wso2.carbon.utils.ConfigurationContextService in project carbon-apimgt by wso2.
the class TenantLoadMessageSenderTest method testGetClusteringAgent.
@Test
public void testGetClusteringAgent() {
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ConfigurationContextService configurationContextService = PowerMockito.mock(ConfigurationContextService.class);
PowerMockito.when(ServiceReferenceHolder.getContextService()).thenReturn(configurationContextService);
ConfigurationContext serverConfigContext = PowerMockito.mock(ConfigurationContext.class);
PowerMockito.when(ServiceReferenceHolder.getContextService().getServerConfigContext()).thenReturn(serverConfigContext);
AxisConfiguration axisConfiguration = PowerMockito.mock(AxisConfiguration.class);
PowerMockito.when(ServiceReferenceHolder.getContextService().getServerConfigContext().getAxisConfiguration()).thenReturn(axisConfiguration);
ClusteringAgent clusteringAgent = PowerMockito.mock(ClusteringAgent.class);
PowerMockito.when(ServiceReferenceHolder.getContextService().getServerConfigContext().getAxisConfiguration().getClusteringAgent()).thenReturn(clusteringAgent);
tenantLoadMessageSender.getClusteringAgent();
}
use of org.wso2.carbon.utils.ConfigurationContextService in project carbon-business-process by wso2.
the class AttachmentMgtDAOBasicOperationsTest method setUp.
@Override
protected void setUp() throws Exception {
// Setup the MockAttachment-Server
try {
ConfigurationContext context = ConfigurationContextFactory.createConfigurationContextFromFileSystem(AXIS2_XML_FILE_PATH, "axis2.xml");
ConfigurationContextService service = new ConfigurationContextService(context, null);
AttachmentServerHolder.getInstance().setConfigurationContextService(service);
} catch (Exception e) {
}
server = new MockAttachmentServer();
attachmentServerHolder = AttachmentServerHolder.getInstance();
attachmentServerHolder.setAttachmentServer(server);
server.init();
}
use of org.wso2.carbon.utils.ConfigurationContextService in project carbon-apimgt by wso2.
the class UserAwareAPIProviderTest method init.
@Before
public void init() throws Exception {
System.setProperty("carbon.home", "");
apiIdentifier = new APIIdentifier("admin_identifier1_v1.0");
PowerMockito.mockStatic(ApiMgtDAO.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.mockStatic(APIUtil.class);
PowerMockito.mockStatic(RegistryUtils.class);
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
RealmService realmService = Mockito.mock(RealmService.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
userRegistry = Mockito.mock(UserRegistry.class);
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
resource = Mockito.mock(Resource.class, Mockito.CALLS_REAL_METHODS);
Mockito.doReturn(apiManagerConfiguration).when(apiManagerConfigurationService).getAPIManagerConfiguration();
Mockito.doReturn(APIConstants.API_GATEWAY_TYPE_SYNAPSE).when(apiManagerConfiguration).getFirstProperty(APIConstants.API_GATEWAY_TYPE);
Mockito.doReturn("true").when(apiManagerConfiguration).getFirstProperty(APIConstants.API_PUBLISHER_ENABLE_ACCESS_CONTROL_LEVELS);
Mockito.doReturn(userRegistry).when(registryService).getGovernanceUserRegistry(Mockito.anyString(), Mockito.anyInt());
Mockito.doReturn(userRegistry).when(registryService).getGovernanceSystemRegistry();
Mockito.doReturn(userRegistry).when(registryService).getConfigSystemRegistry(Mockito.anyInt());
Mockito.doReturn(userRegistry).when(registryService).getConfigSystemRegistry();
Mockito.doReturn(resource).when(userRegistry).newResource();
Mockito.doReturn(null).when(userRegistry).getUserRealm();
PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
PowerMockito.when(APIUtil.getAPIPath(Mockito.any(APIIdentifier.class))).thenReturn("test");
PowerMockito.when(APIUtil.getArtifactManager(Mockito.any(Registry.class), Mockito.anyString())).thenReturn(artifactManager);
PowerMockito.when(APIUtil.getInternalOrganizationDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)).thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
PowerMockito.doNothing().when(ServiceReferenceHolder.class, "setUserRealm", Mockito.any());
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.when(APIUtil.replaceEmailDomainBack(apiIdentifier.getProviderName())).thenReturn(apiIdentifier.getProviderName());
Mockito.doReturn(realmService).when(serviceReferenceHolder).getRealmService();
Mockito.doReturn(tenantManager).when(realmService).getTenantManager();
Mockito.doReturn(registryService).when(serviceReferenceHolder).getRegistryService();
Mockito.doReturn(apiManagerConfigurationService).when(serviceReferenceHolder).getAPIManagerConfigurationService();
PowerMockito.when(APIUtil.compareRoleList(Mockito.any(String[].class), Mockito.anyString())).thenCallRealMethod();
ConfigurationContextService configurationContextService = TestUtils.initConfigurationContextService(true);
PowerMockito.when(ServiceReferenceHolder.getContextService()).thenReturn(configurationContextService);
userAwareAPIProvider = new UserAwareAPIProvider(ADMIN_ROLE_NAME);
PrivilegedCarbonContext prcontext = Mockito.mock(PrivilegedCarbonContext.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(prcontext);
}
Aggregations