Search in sources :

Example 1 with ComponentRepository

use of com.axway.ats.agent.core.ComponentRepository in project ats-framework by Axway.

the class EnvironmentConfigurator method apply.

@Override
public void apply() throws ConfigurationException {
    for (Properties dbProperties : dbPropertiesList) {
        int dbConfigurationIndex = -1;
        if (dbProperties.get(DB_CONFIGURATION_INDEX) != null) {
            dbConfigurationIndex = (Integer) dbProperties.get(DB_CONFIGURATION_INDEX);
        }
        ComponentRepository componentRepository = ComponentRepository.getInstance();
        ComponentEnvironment componentEnvironment;
        try {
            componentEnvironment = componentRepository.getComponentEnvironment(component);
        } catch (NoSuchComponentException nsce) {
            throw new ConfigurationException("Error changing environment configuration. CAUSE: " + nsce.getMessage());
        }
        int foundDbConfigurationIndex = 0;
        for (EnvironmentUnit environmentUnit : componentEnvironment.getEnvironmentUnits()) {
            if (environmentUnit instanceof DatabaseEnvironmentUnit) {
                if (foundDbConfigurationIndex == dbConfigurationIndex) {
                    DatabaseEnvironmentUnit dbEnvironmentUnit = (DatabaseEnvironmentUnit) environmentUnit;
                    DbConnection dbConnection = dbEnvironmentUnit.getDbConnection();
                    // the database port is kept in a list of custom properties
                    Map<String, Object> customProperties = dbConnection.getCustomProperties();
                    // get the new configuration properties
                    String newDbHost = chooseNewProperty(dbProperties.getProperty(DB_HOST), dbConnection.getHost());
                    String newDbName = chooseNewProperty(dbProperties.getProperty(DB_NAME), dbConnection.getDb());
                    String newDbUserName = chooseNewProperty(dbProperties.getProperty(DB_USER_NAME), dbConnection.getUser());
                    String newDbUserPassword = chooseNewProperty(dbProperties.getProperty(DB_USER_PASSWORD), dbConnection.getPassword());
                    Object newDbPort = chooseDbPort(dbProperties.get(DB_PORT), customProperties.get(DbKeys.PORT_KEY));
                    // create a new connection object
                    customProperties.put(DbKeys.PORT_KEY, newDbPort);
                    DbConnection newDbConnection = DatabaseProviderFactory.createDbConnection(dbConnection.getDbType(), newDbHost, newDbName, newDbUserName, newDbUserPassword, customProperties);
                    // apply the changes
                    dbEnvironmentUnit.setDbConnection(newDbConnection);
                    log.info("Database configuration for index " + dbConfigurationIndex + " is changed. DbConnection: " + newDbConnection.getDescription());
                    return;
                } else {
                    // still searching the exact database configuration
                    foundDbConfigurationIndex++;
                }
            }
        }
        throw new ConfigurationException("Database configuration with index " + dbConfigurationIndex + " is not available");
    }
}
Also used : ComponentEnvironment(com.axway.ats.agent.core.ComponentEnvironment) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) DatabaseEnvironmentUnit(com.axway.ats.environment.database.DatabaseEnvironmentUnit) EnvironmentUnit(com.axway.ats.environment.EnvironmentUnit) ComponentRepository(com.axway.ats.agent.core.ComponentRepository) Properties(java.util.Properties) NoSuchComponentException(com.axway.ats.agent.core.exceptions.NoSuchComponentException) DbConnection(com.axway.ats.core.dbaccess.DbConnection)

Example 2 with ComponentRepository

use of com.axway.ats.agent.core.ComponentRepository in project ats-framework by Axway.

the class Test_ActionMethodEnumArguments method setUpTest_ActionHandler.

@BeforeClass
public static void setUpTest_ActionHandler() throws AgentException {
    Component component = new Component(TEST_COMPONENT_NAME);
    ComponentActionMap actionMap = new ComponentActionMap(TEST_COMPONENT_NAME);
    actionMap.registerActionClass(ActionClassEnumArguments.class);
    component.setActionMap(actionMap);
    ComponentRepository componentRepository = ComponentRepository.getInstance();
    componentRepository.clear();
    componentRepository.putComponent(component);
}
Also used : ComponentActionMap(com.axway.ats.agent.core.ComponentActionMap) ComponentRepository(com.axway.ats.agent.core.ComponentRepository) Component(com.axway.ats.agent.core.Component) BeforeClass(org.junit.BeforeClass)

Example 3 with ComponentRepository

use of com.axway.ats.agent.core.ComponentRepository in project ats-framework by Axway.

the class Test_ActionMethodValidation method setUpTest_ActionHandler.

@BeforeClass
public static void setUpTest_ActionHandler() throws AgentException {
    Component component = new Component(TEST_COMPONENT_NAME);
    ComponentActionMap actionMap = new ComponentActionMap(TEST_COMPONENT_NAME);
    actionMap.registerActionClass(ActionClassForValidation.class);
    component.setActionMap(actionMap);
    ComponentRepository componentRepository = ComponentRepository.getInstance();
    componentRepository.clear();
    componentRepository.putComponent(component);
}
Also used : ComponentActionMap(com.axway.ats.agent.core.ComponentActionMap) ComponentRepository(com.axway.ats.agent.core.ComponentRepository) Component(com.axway.ats.agent.core.Component) BeforeClass(org.junit.BeforeClass)

Example 4 with ComponentRepository

use of com.axway.ats.agent.core.ComponentRepository in project ats-framework by Axway.

the class DisabledTest_RampUpLoaderMultipleInvocations method setUpTest_ActionInvoker.

@BeforeClass
public static void setUpTest_ActionInvoker() throws AgentException {
    Component component = new Component(TEST_COMPONENT_NAME);
    ComponentActionMap actionMap = new ComponentActionMap(TEST_COMPONENT_NAME);
    actionMap.registerActionClass(LoadTestActionClass.class);
    component.setActionMap(actionMap);
    ComponentRepository componentRepository = ComponentRepository.getInstance();
    componentRepository.clear();
    componentRepository.putComponent(component);
}
Also used : ComponentActionMap(com.axway.ats.agent.core.ComponentActionMap) ComponentRepository(com.axway.ats.agent.core.ComponentRepository) Component(com.axway.ats.agent.core.Component) BeforeClass(org.junit.BeforeClass)

Example 5 with ComponentRepository

use of com.axway.ats.agent.core.ComponentRepository in project ats-framework by Axway.

the class Test_LocalExecutor method setUpTest_LocalExecutor.

@BeforeClass
public static void setUpTest_LocalExecutor() throws AgentException {
    Component component = new Component(TEST_COMPONENT_NAME);
    ComponentActionMap actionMap = new ComponentActionMap(TEST_COMPONENT_NAME);
    actionMap.registerActionClass(ActionClassOne.class);
    component.setActionMap(actionMap);
    ComponentRepository componentRepository = ComponentRepository.getInstance();
    componentRepository.clear();
    componentRepository.putComponent(component);
}
Also used : ComponentActionMap(com.axway.ats.agent.core.ComponentActionMap) ComponentRepository(com.axway.ats.agent.core.ComponentRepository) Component(com.axway.ats.agent.core.Component) BeforeClass(org.junit.BeforeClass)

Aggregations

ComponentRepository (com.axway.ats.agent.core.ComponentRepository)10 Component (com.axway.ats.agent.core.Component)7 ComponentActionMap (com.axway.ats.agent.core.ComponentActionMap)7 BeforeClass (org.junit.BeforeClass)7 ComponentEnvironment (com.axway.ats.agent.core.ComponentEnvironment)1 ActionRequest (com.axway.ats.agent.core.action.ActionRequest)1 NoSuchComponentException (com.axway.ats.agent.core.exceptions.NoSuchComponentException)1 DbConnection (com.axway.ats.core.dbaccess.DbConnection)1 EnvironmentUnit (com.axway.ats.environment.EnvironmentUnit)1 DatabaseEnvironmentUnit (com.axway.ats.environment.database.DatabaseEnvironmentUnit)1 Properties (java.util.Properties)1 After (org.junit.After)1 Before (org.junit.Before)1