Search in sources :

Example 1 with WorkerThread

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

the class RemoteServiceTest method testStartAlarmHbThread.

/**
 * Test starting the service with the ALARM_HB_THREAD Intent.
 *
 * @throws Exception Issue setting up the service.
 */
@MediumTest
public final void testStartAlarmHbThread() throws Exception {
    /**
     * Setup test preconditions (i.e. WorkerThread not running). *
     */
    final TestStatus testStatus = new TestStatus();
    setupService();
    RemoteService remoteService = getService();
    remoteService.registerCpuWakeupListener(new IWakeupListener() {

        @Override
        public void notifyOfWakeupAlarm() {
            /*
                 * Test that the dummy mWakeListener.notifyOfWakeupAlarm() has
                 * been called, otherwise the test must fail.
                 */
            testStatus.setPass(true);
        }
    });
    /**
     * Perform test (i.e. trigger ALARM_HB_THREAD). *
     */
    Intent alarmWorkerThreadIntent = new Intent(getContext(), RemoteService.class);
    alarmWorkerThreadIntent.putExtra(RemoteService.ALARM_KEY, IWakeupListener.ALARM_HB_THREAD);
    startService(alarmWorkerThreadIntent);
    /**
     * Test if notifyOfWakeupAlarm() was called. *
     */
    assertTrue("Expecting the notifyOfWakeupAlarm() dummy method to have " + "been called", testStatus.isPass());
}
Also used : TestStatus(com.vodafone360.people.tests.testutils.TestStatus) RemoteService(com.vodafone360.people.service.RemoteService) IWakeupListener(com.vodafone360.people.service.transport.IWakeupListener) Intent(android.content.Intent) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 2 with WorkerThread

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

the class RemoteServiceTest method testStartAlarmWorkerThread.

/**
 * Test starting the service with the ALARM_WORKER_THREAD Intent.
 *
 * @throws Exception Issue setting up framework.
 */
@MediumTest
public final void testStartAlarmWorkerThread() 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", true);
    FrameworkUtils.set(remoteService, "mWorkerThread", null);
    /**
     * Perform test (i.e. trigger ALARM_WORKER_THREAD). *
     */
    Intent alarmWorkerThreadIntent = new Intent(getContext(), RemoteService.class);
    alarmWorkerThreadIntent.putExtra(RemoteService.ALARM_KEY, WorkerThread.ALARM_WORKER_THREAD);
    remoteService.onStart(alarmWorkerThreadIntent, -1);
    /**
     * Test if the kickWorkerThread() was called. *
     */
    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 3 with WorkerThread

use of com.vodafone360.people.service.WorkerThread 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 4 with WorkerThread

use of com.vodafone360.people.service.WorkerThread 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)

Aggregations

Intent (android.content.Intent)4 MediumTest (android.test.suitebuilder.annotation.MediumTest)4 RemoteService (com.vodafone360.people.service.RemoteService)4 WorkerThread (com.vodafone360.people.service.WorkerThread)2 IWakeupListener (com.vodafone360.people.service.transport.IWakeupListener)1 TestStatus (com.vodafone360.people.tests.testutils.TestStatus)1