Search in sources :

Example 6 with SyncService

use of com.android.ddmlib.SyncService in project VideoOptimzer by attdevsupport.

the class AndroidImplTest method pullTraceFilesFromDevice_returnIsFalse.

@Test
public void pullTraceFilesFromDevice_returnIsFalse() throws TimeoutException, AdbCommandRejectedException, IOException, SyncException {
    IDevice device = mock(IDevice.class);
    SyncService syncServ = mock(SyncService.class);
    when(device.getSyncService()).thenReturn(syncServ);
    when(filereader.createFile(any(String.class), any(String.class))).thenReturn(folder.newFile("cpu"));
    doThrow(SyncException.class).when(syncServ).pullFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
    assertFalse(androidImpl.pullTraceFilesFromDevice(device, " ", " "));
    doThrow(TimeoutException.class).when(syncServ).pullFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
    assertFalse(androidImpl.pullTraceFilesFromDevice(device, " ", " "));
    doThrow(IOException.class).when(syncServ).pullFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
    assertFalse(androidImpl.pullTraceFilesFromDevice(device, " ", " "));
}
Also used : ISyncProgressMonitor(com.android.ddmlib.SyncService.ISyncProgressMonitor) IDevice(com.android.ddmlib.IDevice) SyncService(com.android.ddmlib.SyncService) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Example 7 with SyncService

use of com.android.ddmlib.SyncService in project VideoOptimzer by attdevsupport.

the class AndroidImplTest method pushFile_ServiceHasReturn.

@Test
public void pushFile_ServiceHasReturn() throws SyncException, IOException, TimeoutException {
    IDevice device = mock(IDevice.class);
    SyncService service = mock(SyncService.class);
    try {
        when(device.getSyncService()).thenReturn(service);
    } catch (AdbCommandRejectedException e) {
        e.printStackTrace();
    }
    doNothing().when(service).pushFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
    assertTrue(androidImpl.pushFile(device, "", ""));
    doThrow(SyncException.class).when(service).pushFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
    assertFalse(androidImpl.pushFile(device, "", ""));
    doThrow(TimeoutException.class).when(service).pushFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
    assertFalse(androidImpl.pushFile(device, "", ""));
    doThrow(IOException.class).when(service).pushFile(any(String.class), any(String.class), any(ISyncProgressMonitor.class));
    assertFalse(androidImpl.pushFile(device, "", ""));
}
Also used : ISyncProgressMonitor(com.android.ddmlib.SyncService.ISyncProgressMonitor) AdbCommandRejectedException(com.android.ddmlib.AdbCommandRejectedException) IDevice(com.android.ddmlib.IDevice) SyncService(com.android.ddmlib.SyncService) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Example 8 with SyncService

use of com.android.ddmlib.SyncService in project android by JetBrains.

the class AndroidDbUtil method downloadDatabase.

public static boolean downloadDatabase(@NotNull IDevice device, @NotNull String packageName, @NotNull String dbName, boolean external, @NotNull File localDbFile, @NotNull final ProgressIndicator progressIndicator, @NotNull AndroidDbErrorReporter errorReporter) {
    try {
        final MyShellOutputReceiver receiver = new MyShellOutputReceiver(progressIndicator, device);
        device.executeShellCommand(getRunAsPrefix(packageName, external) + "cat " + getDatabaseRemoteFilePath(packageName, dbName, external) + " >" + TEMP_REMOTE_DB_PATH, receiver, DB_COPYING_TIMEOUT_SEC, TimeUnit.SECONDS);
        final String output = receiver.getOutput();
        if (!output.isEmpty()) {
            errorReporter.reportError(output);
            return false;
        }
        progressIndicator.checkCanceled();
        final File parent = localDbFile.getParentFile();
        if (!parent.exists()) {
            if (!parent.mkdirs()) {
                errorReporter.reportError("cannot create directory '" + parent.getPath() + "'");
                return false;
            }
        }
        final SyncService syncService = device.getSyncService();
        try {
            syncService.pullFile(TEMP_REMOTE_DB_PATH, localDbFile.getPath(), new MySyncProgressMonitor(progressIndicator));
        } finally {
            syncService.close();
        }
    } catch (Exception e) {
        errorReporter.reportError(e);
        return false;
    }
    return true;
}
Also used : SyncService(com.android.ddmlib.SyncService)

Example 9 with SyncService

use of com.android.ddmlib.SyncService in project android by JetBrains.

the class AndroidDbUtil method uploadDatabase.

public static boolean uploadDatabase(@NotNull IDevice device, @NotNull String packageName, @NotNull String dbName, boolean external, @NotNull String localDbPath, @NotNull final ProgressIndicator progressIndicator, @NotNull AndroidDbErrorReporter errorReporter) {
    try {
        final SyncService syncService = device.getSyncService();
        try {
            syncService.pushFile(localDbPath, TEMP_REMOTE_DB_PATH, new MySyncProgressMonitor(progressIndicator));
        } finally {
            syncService.close();
        }
        final String remoteDbPath = getDatabaseRemoteFilePath(packageName, dbName, external);
        final String remoteDbDirPath = remoteDbPath.substring(0, remoteDbPath.lastIndexOf('/'));
        MyShellOutputReceiver outputReceiver = new MyShellOutputReceiver(progressIndicator, device);
        device.executeShellCommand(getRunAsPrefix(packageName, external) + "mkdir " + remoteDbDirPath, outputReceiver, DB_COPYING_TIMEOUT_SEC, TimeUnit.SECONDS);
        String output = outputReceiver.getOutput();
        if (!output.isEmpty() && !output.startsWith("mkdir failed")) {
            errorReporter.reportError(output);
            return false;
        }
        // recreating is needed for Genymotion emulator (IDEA-114732)
        if (!external && !recreateRemoteFile(device, packageName, remoteDbPath, errorReporter, progressIndicator)) {
            return false;
        }
        outputReceiver = new MyShellOutputReceiver(progressIndicator, device);
        device.executeShellCommand(getRunAsPrefix(packageName, external) + "cat " + TEMP_REMOTE_DB_PATH + " >" + remoteDbPath, outputReceiver, DB_COPYING_TIMEOUT_SEC, TimeUnit.SECONDS);
        output = outputReceiver.getOutput();
        if (!output.isEmpty()) {
            errorReporter.reportError(output);
            return false;
        }
        progressIndicator.checkCanceled();
    } catch (Exception e) {
        errorReporter.reportError(e);
        return false;
    }
    return true;
}
Also used : SyncService(com.android.ddmlib.SyncService)

Example 10 with SyncService

use of com.android.ddmlib.SyncService in project VideoOptimzer by attdevsupport.

the class AdbServiceImplTest method fail_pullFile.

@SuppressWarnings("rawtypes")
@Test
public void fail_pullFile() throws Exception {
    SyncService syncservice = Mockito.mock(SyncService.class);
    // Mockito.doNothing().when(syncservice).pullFile(Mockito.anyString(), Mockito.anyString(), (ISyncProgressMonitor) Mockito.any());
    Mockito.doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            throw new IOException("its Mocking!");
        }
    }).when(syncservice).pullFile(Mockito.anyString(), Mockito.anyString(), (ISyncProgressMonitor) Mockito.any());
    boolean success = adbService.pullFile(syncservice, "remote", "file", "local");
    assertTrue(!success);
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IOException(java.io.IOException) SyncService(com.android.ddmlib.SyncService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Aggregations

SyncService (com.android.ddmlib.SyncService)18 Test (org.junit.Test)10 IOException (java.io.IOException)9 IDevice (com.android.ddmlib.IDevice)8 TimeoutException (com.android.ddmlib.TimeoutException)8 BaseTest (com.att.aro.core.BaseTest)7 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)6 ISyncProgressMonitor (com.android.ddmlib.SyncService.ISyncProgressMonitor)6 StatusResult (com.att.aro.core.datacollector.pojo.StatusResult)5 SyncException (com.android.ddmlib.SyncException)4 File (java.io.File)3 Date (java.util.Date)3 Ignore (org.junit.Ignore)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 FileEntry (com.android.ddmlib.FileListingService.FileEntry)1 IVideoImageSubscriber (com.att.aro.core.datacollector.IVideoImageSubscriber)1 IVideoCapture (com.att.aro.core.video.IVideoCapture)1 InputStream (java.io.InputStream)1 Hashtable (java.util.Hashtable)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1