Search in sources :

Example 16 with GlobalSessionObject

use of com.hp.oo.sdk.content.plugin.GlobalSessionObject in project cs-actions by CloudSlang.

the class SQLQueryTest method executeSuccess.

@Test
public void executeSuccess() throws Exception {
    final String aKey = "akey";
    final GlobalSessionObject<Map<String, Object>> globalSessionObject = new GlobalSessionObject<>();
    final Map<String, Object> stringMap = new HashMap<>();
    stringMap.put(aKey, aKey);
    globalSessionObject.setResource(new SQLSessionResource(stringMap));
    mockStatic(SQLInputsUtils.class);
    when(SQLInputsUtils.getSqlKey(any(SQLInputs.class))).thenReturn(aKey);
    when(SQLInputsUtils.getOrDefaultGlobalSessionObj(any(GlobalSessionObject.class))).thenReturn(globalSessionObject);
    final Map<String, String> resultMap = sqlQuery.execute("1", MSSQL_DB_TYPE, "username", "Password", "someInstance", "123", "db", AUTH_SQL, EMPTY, EMPTY, "something", "true", EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, FALSE, globalSessionObject);
    verifyStatic();
    assertThat(resultMap.get(RETURN_CODE), is(NO_MORE));
    assertThat(resultMap.get(RETURN_RESULT), is(DBResponseNames.NO_MORE));
}
Also used : GlobalSessionObject(com.hp.oo.sdk.content.plugin.GlobalSessionObject) HashMap(java.util.HashMap) GlobalSessionObject(com.hp.oo.sdk.content.plugin.GlobalSessionObject) SQLInputs(io.cloudslang.content.database.utils.SQLInputs) HashMap(java.util.HashMap) Map(java.util.Map) SQLSessionResource(io.cloudslang.content.database.utils.SQLSessionResource) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with GlobalSessionObject

use of com.hp.oo.sdk.content.plugin.GlobalSessionObject in project cs-actions by CloudSlang.

the class ConnectionManagerBuilderTest method buildConnectionManagerNewConnectionManager.

@Test
public void buildConnectionManagerNewConnectionManager() {
    PoolingHttpClientConnectionManager connectionManager = new ConnectionManagerBuilder().setConnectionManagerMapKey("key1", "key2").setSslsf(sslConnectionSocketFactoryMock).setConnectionPoolHolder(new GlobalSessionObject()).buildConnectionManager();
    assertNotNull(connectionManager);
}
Also used : GlobalSessionObject(com.hp.oo.sdk.content.plugin.GlobalSessionObject) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Test(org.junit.Test)

Example 18 with GlobalSessionObject

use of com.hp.oo.sdk.content.plugin.GlobalSessionObject in project cs-actions by CloudSlang.

the class CounterProcessor method init.

public void init(String to, String from, String by, boolean reset, GlobalSessionObject<Map<String, Object>> session) throws CounterImplException {
    /*
         * If the session resource is not ini
         */
    if (session.get() == null) {
        session.setResource(new CounterSessionResource(new HashMap<String, Object>()));
    }
    Map<String, Object> sessionMap = session.get();
    try {
        start = Long.parseLong(from.trim());
        end = Long.parseLong(to.trim());
        if (by == null || by.length() == 0)
            increment = 1;
        else
            try {
                increment = Integer.parseInt(by);
            } catch (Exception e) {
                increment = 1;
            }
    } catch (Exception e) {
        throw new CounterImplException("Start or end is not a long integer, or by is not an integer.\nfrom: " + from + "\nto: " + to + "\nby:" + by);
    }
    try {
        index = (Integer) sessionMap.get(INDEX);
    } catch (Exception e) {
        index = 0;
    }
    if (index == 0 && initialized(session)) {
        sessionMap.put(INDEX, 0);
    }
    // ok, now push data into context
    if (!initialized(session)) {
        sessionMap.put(INDEX, 0);
    }
    // pull data from context
    this.index = (Integer) sessionMap.get(INDEX);
}
Also used : HashMap(java.util.HashMap) GlobalSessionObject(com.hp.oo.sdk.content.plugin.GlobalSessionObject) CounterImplException(io.cloudslang.content.hashicorp.terraform.exceptions.CounterImplException) CounterImplException(io.cloudslang.content.hashicorp.terraform.exceptions.CounterImplException)

Example 19 with GlobalSessionObject

use of com.hp.oo.sdk.content.plugin.GlobalSessionObject in project cs-actions by CloudSlang.

the class IteratorProcessor method init.

public void init(String list, String delim, GlobalSessionObject<Map<String, Object>> session) throws IteratorProcessorException {
    if (session.get() == null) {
        session.setResource(new IteratorSessionResource(new HashMap<String, Object>()));
    }
    Map<String, Object> sessionMap = session.get();
    if (list != null && delim != null) {
        if (delim.length() == 0) {
            throw new IteratorProcessorException("delimiter has null or 0 length");
        }
        // Get array list value
        try {
            splitList = (String[]) sessionMap.get(TEXT_ARRAYLIST);
        } catch (Exception e) {
            splitList = new String[0];
        }
        // Get String list value
        String stringList;
        try {
            stringList = (String) sessionMap.get(TEXT_STRINGLIST);
        } catch (Exception e) {
            stringList = "";
        }
        // Get index value
        try {
            index = (Integer) sessionMap.get(TEXT_INDEX);
        } catch (Exception e) {
            index = 0;
        }
        if (splitList == null) {
            splitList = new String[0];
        }
        if (stringList == null) {
            stringList = "";
        }
        if (index == 0 && initialized(session)) {
            if (list.indexOf(stringList) != 0) {
                stringList = "";
                splitList = new String[0];
            }
            sessionMap.put(TEXT_ARRAYLIST, splitList);
            sessionMap.put(TEXT_INDEX, 0);
        }
        if (!initialized(session) || !stringList.equals(list)) {
            String lastIn = list;
            int index = list.indexOf(stringList);
            if (index == 0) {
                if (list.length() == 0) {
                    throw new IteratorProcessorException("list has null or 0 length");
                }
                splitList = ListProcessor.toArray(list, delim);
            } else {
                if (initialized(session) && list.startsWith(delim)) {
                    list = list.substring(1, list.length());
                }
                String[] listarray = ListProcessor.toArray(list, delim);
                splitList = combine(this.splitList, listarray);
            }
            if (list == "" && splitList.length == 0) {
                throw new IteratorProcessorException("list has null or zero length");
            }
            // ok, now push data into context
            if (!initialized(session)) {
                sessionMap.put(TEXT_INDEX, 0);
            }
            sessionMap.put(TEXT_ARRAYLIST, splitList);
            sessionMap.put(TEXT_STRINGLIST, lastIn);
        }
    }
    // pull data from context
    splitList = (String[]) sessionMap.get(TEXT_ARRAYLIST);
    index = (Integer) sessionMap.get(TEXT_INDEX);
}
Also used : HashMap(java.util.HashMap) GlobalSessionObject(com.hp.oo.sdk.content.plugin.GlobalSessionObject) IteratorSessionResource(com.hp.oo.sdk.content.plugin.IteratorSessionResource) IteratorProcessorException(io.cloudslang.content.exceptions.IteratorProcessorException) IteratorProcessorException(io.cloudslang.content.exceptions.IteratorProcessorException)

Example 20 with GlobalSessionObject

use of com.hp.oo.sdk.content.plugin.GlobalSessionObject in project cs-actions by CloudSlang.

the class SFTPTest method testSaveToCache.

@Test
public void testSaveToCache() {
    SFTPService sftpService = new SFTPService();
    String sessionId = "sessionId";
    boolean savedToCache = sftpService.saveToCache(globalSessionObjectMock, sftpCopierMock, sessionId);
    assertFalse(savedToCache);
    when(sftpCopierMock.saveToCache(globalSessionObjectMock, sessionId)).thenReturn(true);
    savedToCache = sftpService.saveToCache(globalSessionObjectMock, sftpCopierMock, sessionId);
    assertTrue(savedToCache);
    final GlobalSessionObject<Map<String, SFTPConnection>> sessionParam = new GlobalSessionObject<>();
    when(sftpCopierMock.saveToCache(sessionParam, sessionId)).thenReturn(true);
    savedToCache = sftpService.saveToCache(sessionParam, sftpCopierMock, sessionId);
    assertEquals(sessionParam.getName(), "sshSessions:default-id");
    assertTrue(savedToCache);
}
Also used : GlobalSessionObject(com.hp.oo.sdk.content.plugin.GlobalSessionObject) Map(java.util.Map) SFTPService(io.cloudslang.content.rft.services.SFTPService) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

GlobalSessionObject (com.hp.oo.sdk.content.plugin.GlobalSessionObject)21 HashMap (java.util.HashMap)16 Map (java.util.Map)10 Test (org.junit.Test)8 SerializableSessionObject (com.hp.oo.sdk.content.plugin.SerializableSessionObject)6 SQLInputs (io.cloudslang.content.database.utils.SQLInputs)6 SQLSessionResource (io.cloudslang.content.database.utils.SQLSessionResource)6 Action (com.hp.oo.sdk.content.annotations.Action)5 SQLUtils.getRowsFromGlobalSessionMap (io.cloudslang.content.database.utils.SQLUtils.getRowsFromGlobalSessionMap)3 OutputUtilities.getFailureResultsMap (io.cloudslang.content.utils.OutputUtilities.getFailureResultsMap)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 OutputUtilities.getSuccessResultsMap (io.cloudslang.content.utils.OutputUtilities.getSuccessResultsMap)2 Value (io.cloudslang.lang.entities.bindings.values.Value)2 RunEnvironment (io.cloudslang.lang.runtime.env.RunEnvironment)2 NonSerializableObject (io.cloudslang.lang.runtime.steps.ContentTestActions.NonSerializableObject)2 Output (com.hp.oo.sdk.content.annotations.Output)1 Param (com.hp.oo.sdk.content.annotations.Param)1 Response (com.hp.oo.sdk.content.annotations.Response)1 MatchType (com.hp.oo.sdk.content.plugin.ActionMetadata.MatchType)1 ResponseType (com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType)1