Search in sources :

Example 1 with CARBON_HOME

use of org.wso2.carbon.utils.ServerConstants.CARBON_HOME in project carbon-business-process by wso2.

the class BPELServerImpl method initDataSource.

/**
 * Initialize the data source.
 *
 * @throws BPELEngineException If error occured while initializing datasource
 */
private void initDataSource() throws BPELEngineException {
    db = new Database(odeConfigurationProperties);
    db.setTransactionManager(transactionManager);
    if (System.getProperty("setup") != null) {
        BPELDatabaseCreator bpelDBCreator;
        try {
            bpelDBCreator = new BPELDatabaseCreator(db.<DataSource>lookupInJndi(odeConfigurationProperties.getDbDataSource()));
        } catch (Exception e) {
            String errMsg = "Error creating BPELDatabaseCreator";
            log.error(errMsg, e);
            throw new BPELEngineException(errMsg, e);
        }
        if (!bpelDBCreator.isDatabaseStructureCreated("SELECT * FROM ODE_SCHEMA_VERSION")) {
            try {
                // TODO rename following method
                bpelDBCreator.createRegistryDatabase();
            } catch (Exception e) {
                String errMsg = "Error creating BPEL database";
                log.error(errMsg, e);
                throw new BPELEngineException(errMsg, e);
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("BPEL database already exists. Using the old database.");
            }
        }
    }
    // In carbon, embedded H2 database for ODE is located at CARBON_HOME/repository/database
    String dbRoot = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "database";
    File dbRootDir = new File(dbRoot);
    if (dbRootDir.exists() && dbRootDir.isDirectory()) {
        db.setWorkRoot(dbRootDir);
    } else {
        db.setWorkRoot(null);
    }
    try {
        db.start();
    } catch (Exception e) {
        String errMsg = "Error starting database connections, check the database configuration!";
        log.error(errMsg, e);
        throw new BPELEngineException(errMsg, e);
    }
}
Also used : Database(org.apache.ode.il.dbutil.Database) BPELDatabaseCreator(org.wso2.carbon.bpel.core.ode.integration.utils.BPELDatabaseCreator) File(java.io.File) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanRegistrationException(javax.management.MBeanRegistrationException) BpelEngineException(org.apache.ode.bpel.iapi.BpelEngineException) DataSource(javax.sql.DataSource)

Example 2 with CARBON_HOME

use of org.wso2.carbon.utils.ServerConstants.CARBON_HOME in project carbon-apimgt by wso2.

the class AbstractAPIManagerTestCase method init.

@Before
public void init() {
    System.setProperty(CARBON_HOME, "");
    privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
    PowerMockito.mockStatic(GovernanceUtils.class);
    paginationContext = Mockito.mock(PaginationContext.class);
    PowerMockito.mockStatic(PaginationContext.class);
    PowerMockito.when(PaginationContext.getInstance()).thenReturn(paginationContext);
    apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
    scopesDAO = Mockito.mock(ScopesDAO.class);
    registry = Mockito.mock(Registry.class);
    genericArtifactManager = Mockito.mock(GenericArtifactManager.class);
    registryService = Mockito.mock(RegistryService.class);
    tenantManager = Mockito.mock(TenantManager.class);
    graphQLSchemaDefinition = Mockito.mock(GraphQLSchemaDefinition.class);
    keyManager = Mockito.mock(KeyManager.class);
    apiPersistenceInstance = Mockito.mock(APIPersistence.class);
    PowerMockito.mockStatic(KeyManagerHolder.class);
    KeyManagerDto keyManagerDto = new KeyManagerDto();
    keyManagerDto.setName("default");
    keyManagerDto.setKeyManager(keyManager);
    keyManagerDto.setIssuer("https://localhost");
    Map<String, KeyManagerDto> tenantKeyManagerDtoMap = new HashMap<>();
    tenantKeyManagerDtoMap.put("default", keyManagerDto);
    PowerMockito.when(KeyManagerHolder.getTenantKeyManagers("carbon.super")).thenReturn(tenantKeyManagerDtoMap);
}
Also used : GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) HashMap(java.util.HashMap) PaginationContext(org.wso2.carbon.registry.core.pagination.PaginationContext) ScopesDAO(org.wso2.carbon.apimgt.impl.dao.ScopesDAO) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) KeyManagerDto(org.wso2.carbon.apimgt.impl.dto.KeyManagerDto) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) GraphQLSchemaDefinition(org.wso2.carbon.apimgt.impl.definitions.GraphQLSchemaDefinition) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager) APIPersistence(org.wso2.carbon.apimgt.persistence.APIPersistence) Before(org.junit.Before)

Example 3 with CARBON_HOME

use of org.wso2.carbon.utils.ServerConstants.CARBON_HOME in project carbon-apimgt by wso2.

the class APIConsumerImplTest method testGetTagsWithAttributes.

@Test
public void testGetTagsWithAttributes() throws Exception {
    Registry userRegistry = Mockito.mock(Registry.class);
    APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(apiMgtDAO, apiPersistenceInstance);
    System.setProperty(CARBON_HOME, "");
    PowerMockito.mockStatic(GovernanceUtils.class);
    UserRegistry userRegistry1 = Mockito.mock(UserRegistry.class);
    Mockito.when(registryService.getGovernanceUserRegistry(Mockito.anyString(), Mockito.anyInt())).thenReturn(userRegistry1);
    Mockito.when(registryService.getGovernanceSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry1);
    List<TermData> list = new ArrayList<TermData>();
    TermData termData = new TermData("testTerm", 10);
    list.add(termData);
    Mockito.when(GovernanceUtils.getTermDataList(Mockito.anyMap(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(list);
    ResourceDO resourceDO = Mockito.mock(ResourceDO.class);
    Resource resource = new ResourceImpl("dw", resourceDO);
    resource.setContent("testContent");
    Mockito.when(userRegistry1.resourceExists(Mockito.anyString())).thenReturn(true);
    Mockito.when(userRegistry1.get(Mockito.anyString())).thenReturn(resource);
    assertNotNull(apiConsumer.getTagsWithAttributes("testDomain"));
}
Also used : ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) ResourceDO(org.wso2.carbon.registry.core.jdbc.dataobjects.ResourceDO) TermData(org.wso2.carbon.registry.common.TermData) ArrayList(java.util.ArrayList) Resource(org.wso2.carbon.registry.core.Resource) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with CARBON_HOME

use of org.wso2.carbon.utils.ServerConstants.CARBON_HOME 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);
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) ServiceReferenceHolder(org.wso2.carbon.apimgt.keymgt.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) HashMap(java.util.HashMap) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) MetricService(org.wso2.carbon.metrics.manager.MetricService) Timer(org.wso2.carbon.metrics.manager.Timer) MessageContext(org.apache.axis2.context.MessageContext) HashMap(java.util.HashMap) Map(java.util.Map) APIKeyValidationInfoDTO(org.wso2.carbon.apimgt.impl.dto.APIKeyValidationInfoDTO) Before(org.junit.Before)

Example 5 with CARBON_HOME

use of org.wso2.carbon.utils.ServerConstants.CARBON_HOME in project carbon-apimgt by wso2.

the class WorkflowExecutorFactoryTest method init.

@Before
public void init() {
    System.setProperty(CARBON_HOME, "");
    carbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(carbonContext);
    PowerMockito.when(carbonContext.getTenantDomain()).thenReturn(tenantDomain);
    PowerMockito.when(carbonContext.getTenantId()).thenReturn(tenantID);
    cache = Mockito.mock(Cache.class);
    CacheManager cacheManager = Mockito.mock(CacheManager.class);
    PowerMockito.mockStatic(Caching.class);
    Mockito.when(Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER)).thenReturn(cacheManager);
    Mockito.when(cacheManager.getCache(APIConstants.WORKFLOW_CACHE_NAME)).thenReturn(cache);
    tenantWorkflowConfigHolder = Mockito.mock(TenantWorkflowConfigHolder.class);
    workflowExecutorFactory = WorkflowExecutorFactory.getInstance();
}
Also used : CacheManager(javax.cache.CacheManager) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) Cache(javax.cache.Cache) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)13 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)5 Before (org.junit.Before)4 API (org.wso2.carbon.apimgt.api.model.API)4 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)4 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)4 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)4 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)4 DevPortalAPI (org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI)4 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)4 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)4 Registry (org.wso2.carbon.registry.core.Registry)4 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)4 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)4 TreeMap (java.util.TreeMap)3 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Tier (org.wso2.carbon.apimgt.api.model.Tier)3