Search in sources :

Example 6 with RemoteService

use of com.vodafone360.people.service.RemoteService in project 360-Engine-for-Android by 360.

the class RemoteServiceTest method testSetAlarm.

/**
     * Test setAlarm() from RemoteService.
     */
@MediumTest
public final void testSetAlarm() {
    /** Setup test preconditions (i.e. remoteService running). **/
    startService(new Intent(getContext(), RemoteService.class));
    RemoteService remoteService = getService();
    /** Set an alarm that will never go off. **/
    remoteService.setAlarm(true, System.currentTimeMillis() + 10000);
    /** Cancel alarm before it goes off. **/
    remoteService.setAlarm(false, System.currentTimeMillis() + 10000);
    /** Set alarm that will go off now. **/
    remoteService.setAlarm(true, 0);
    /** Allow RemoteService to be created. **/
    pause(1000);
/**
         * Warning: Unable to test if the alarm actually goes off, as the
         * AlarmManager creates a new apparently unreachable instance of the
         * RemoteService.
         */
}
Also used : RemoteService(com.vodafone360.people.service.RemoteService) Intent(android.content.Intent) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 7 with RemoteService

use of com.vodafone360.people.service.RemoteService in project 360-Engine-for-Android by 360.

the class RemoteServiceTest method testSignalConnectionManager.

/**
     * Test signalConnectionManager() from RemoteService.
     *
     * @throws Exception Any kind of mapping exception
     */
@MediumTest
public final void testSignalConnectionManager() throws Exception {
    /** Setup test preconditions (i.e. remoteService running). **/
    startService(new Intent(getContext(), RemoteService.class));
    RemoteService remoteService = getService();
    assertNotNull("RemoteService should not be NULL", remoteService);
    assertTrue("Expected mIsConnected to be TRUE", (Boolean) FrameworkUtils.get(remoteService, "mIsConnected"));
    assertNotNull("Expected mDecoder to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder"));
    assertNotNull("Expected mConnection to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mConnection"));
    assertTrue("Expected mDecoder to be running", ((DecoderThread) FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder")).getIsRunning());
    assertEquals("Expected mConnection to be AuthenticationManager class", AuthenticationManager.class, FrameworkUtils.get(ConnectionManager.getInstance(), "mConnection").getClass());
    /** Perform test (i.e. disconnect). **/
    remoteService.signalConnectionManager(false);
    /**
         * Test if signalConnectionManager() called
         * ConnectionManager.disconnect() and set mIsConnected to false.
         */
    assertFalse("Expecting mIsConnected to be FALSE", (Boolean) FrameworkUtils.get(remoteService, "mIsConnected"));
    assertNotNull("Expected mDecoder not to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder"));
    assertNotNull("Expected mConnection not to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mConnection"));
    assertFalse("Expected mDecoder not to be running", ((DecoderThread) FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder")).getIsRunning());
    FrameworkUtils.set(remoteService, "mWorkerThread", null);
    /** Perform second test (i.e. connect). **/
    remoteService.signalConnectionManager(true);
    /**
         * Test if signalConnectionManager() called
         * ConnectionManager.connect(), kickWorkerThread() and set mIsConnected
         * to true.
         */
    assertTrue("Expecting mIsConnected to be TRUE", (Boolean) FrameworkUtils.get(remoteService, "mIsConnected"));
    assertNotNull("Expected mDecoder not to be NULL", FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder"));
    assertTrue("Expected mDecoder to be running", ((DecoderThread) FrameworkUtils.get(ConnectionManager.getInstance(), "mDecoder")).getIsRunning());
    assertNotNull("Expecting workerThread not to be NULL", FrameworkUtils.get(remoteService, "mWorkerThread"));
}
Also used : RemoteService(com.vodafone360.people.service.RemoteService) Intent(android.content.Intent) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 8 with RemoteService

use of com.vodafone360.people.service.RemoteService in project 360-Engine-for-Android by 360.

the class RemoteServiceTest method testGetNetworkAgent.

/**
     * Test getNetworkAgent() from RemoteService.
     */
@MediumTest
public final void testGetNetworkAgent() {
    /** Setup test preconditions (i.e. remoteService running). **/
    startService(new Intent(getContext(), RemoteService.class));
    RemoteService remoteService = getService();
    assertNotNull("RemoteService should not be NULL", remoteService);
    /** Perform test (i.e. disconnect). **/
    NetworkAgent networkAgent = remoteService.getNetworkAgent();
    /** Test NetworkAgent object. **/
    assertNotNull("NetworkAgent should not be NULL", networkAgent);
    assertEquals("NetworkAgent RoamingDeviceSetting should be FALSE", false, networkAgent.getRoamingDeviceSetting());
    assertEquals("NetworkAgent RoamingNotificationType should be ROAMING_DIALOG_GLOBAL_OFF", NetworkAgent.ROAMING_DIALOG_GLOBAL_OFF, networkAgent.getRoamingNotificationType());
    assertEquals("NetworkAgent AgentState should be CONNECTED", AgentState.CONNECTED, NetworkAgent.getAgentState());
}
Also used : NetworkAgent(com.vodafone360.people.service.agent.NetworkAgent) RemoteService(com.vodafone360.people.service.RemoteService) Intent(android.content.Intent) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 9 with RemoteService

use of com.vodafone360.people.service.RemoteService in project 360-Engine-for-Android by 360.

the class RemoteServiceTest method testKickWorkerThread.

/**
     * Test kickWorkerThread() from RemoteService.
     *
     * @throws Exception Issue setting up framework.
     */
@MediumTest
public final void testKickWorkerThread() throws Exception {
    /** Setup test preconditions (i.e. WorkerThread not running). **/
    startService(new Intent(getContext(), RemoteService.class));
    RemoteService remoteService = getService();
    assertNotNull("RemoteService should not be NULL", remoteService);
    FrameworkUtils.set(remoteService, "mIsStarted", false);
    FrameworkUtils.set(remoteService, "mWorkerThread", null);
    /** Perform test (i.e. trigger ALARM_WORKER_THREAD). **/
    remoteService.kickWorkerThread();
    /**
         * Test if kickWorkerThread() returned because mIsStarted was FALSE.
         */
    WorkerThread workerThread = (WorkerThread) FrameworkUtils.get(remoteService, "mWorkerThread");
    assertNull("Expecting workerThread to be NULL", workerThread);
    /** Setup test preconditions (i.e. WorkerThread not running). **/
    FrameworkUtils.set(remoteService, "mIsStarted", true);
    FrameworkUtils.set(remoteService, "mWorkerThread", null);
    /** Perform test (i.e. trigger ALARM_WORKER_THREAD). **/
    remoteService.kickWorkerThread();
    /** Test if kickWorkerThread() created a new WorkerThread. **/
    workerThread = (WorkerThread) FrameworkUtils.get(remoteService, "mWorkerThread");
    assertNotNull("Expecting workerThread not to be NULL", workerThread);
    assertTrue("Expecting workerThread to be alive", workerThread.isAlive());
}
Also used : WorkerThread(com.vodafone360.people.service.WorkerThread) RemoteService(com.vodafone360.people.service.RemoteService) Intent(android.content.Intent) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 10 with RemoteService

use of com.vodafone360.people.service.RemoteService in project 360-Engine-for-Android by 360.

the class NetworkAgent method onConnectionStateChanged.

/**
     * Contains the main logic that determines the agent state for network
     * access
     */
private void onConnectionStateChanged() {
    if (mContext != null) {
        MainApplication app = (MainApplication) ((RemoteService) mContext).getApplication();
        if ((app.getInternetAvail() == InternetAvail.MANUAL_CONNECT)) {
            LogUtils.logV("NetworkAgent.onConnectionStateChanged()" + " Internet allowed only in manual mode");
            sDisconnectReason = AgentDisconnectReason.DATA_SETTING_SET_TO_MANUAL_CONNECTION;
            setNewState(AgentState.DISCONNECTED);
            return;
        }
    }
    if (!mNetworkWorking) {
        LogUtils.logV("NetworkAgent.onConnectionStateChanged() Network is not working");
        sDisconnectReason = AgentDisconnectReason.NO_WORKING_NETWORK;
        setNewState(AgentState.DISCONNECTED);
        return;
    }
    if (mIsRoaming && !mDataRoaming && !mWifiNetworkAvailable) {
        LogUtils.logV("NetworkAgent.onConnectionStateChanged() " + "Connect while roaming not allowed");
        sDisconnectReason = AgentDisconnectReason.DATA_ROAMING_DISABLED;
        setNewState(AgentState.DISCONNECTED);
        return;
    }
    if (mIsInBackground && !mBackgroundData) {
        LogUtils.logV("NetworkAgent.onConnectionStateChanged() Background connection not allowed");
        sDisconnectReason = AgentDisconnectReason.BACKGROUND_CONNECTION_DISABLED;
        setNewState(AgentState.DISCONNECTED);
        return;
    }
    if (!mInternetConnected) {
        LogUtils.logV("NetworkAgent.onConnectionStateChanged() No internet connection");
        sDisconnectReason = AgentDisconnectReason.NO_INTERNET_CONNECTION;
        // If 2g call is started, notify contact sync engine to pause.
        if (mNetworkInfo != null && VOICE_CALL_STARTED_2G_STRING.equals(mNetworkInfo.getReason())) {
            EngineManager.getInstance().getContactSyncEngine().pauseSync();
        }
        setNewState(AgentState.DISCONNECTED);
        return;
    }
    // If 2g voice call is finished, set resume state
    if (mNetworkInfo != null && VOICE_CALL_ENDED_2G_STRING.equals(mNetworkInfo.getReason())) {
        mIsResumeSync = true;
    }
    if (mWifiNetworkAvailable) {
        LogUtils.logV("NetworkAgent.onConnectionStateChanged() WIFI connected");
    } else {
        LogUtils.logV("NetworkAgent.onConnectionStateChanged() Cellular connected");
    }
    LogUtils.logV("NetworkAgent.onConnectionStateChanged() Connection available");
    setNewState(AgentState.CONNECTED);
}
Also used : MainApplication(com.vodafone360.people.MainApplication)

Aggregations

Intent (android.content.Intent)8 MediumTest (android.test.suitebuilder.annotation.MediumTest)8 RemoteService (com.vodafone360.people.service.RemoteService)8 MainApplication (com.vodafone360.people.MainApplication)2 WorkerThread (com.vodafone360.people.service.WorkerThread)2 NetworkAgent (com.vodafone360.people.service.agent.NetworkAgent)2 ApplicationCache (com.vodafone360.people.ApplicationCache)1 UiAgent (com.vodafone360.people.service.agent.UiAgent)1 IPeopleService (com.vodafone360.people.service.interfaces.IPeopleService)1 IWorkerThreadControl (com.vodafone360.people.service.interfaces.IWorkerThreadControl)1 IWakeupListener (com.vodafone360.people.service.transport.IWakeupListener)1 UserDataProtection (com.vodafone360.people.service.utils.UserDataProtection)1 TestStatus (com.vodafone360.people.tests.testutils.TestStatus)1