Search in sources :

Example 1 with DeviceSession

use of com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession in project intellij by bazelbuild.

the class BlazeInstrumentationTestApkBuildStepIntegrationTest method deployInfoBuiltCorrectly_selfInstrumentingTest.

@Test
public void deployInfoBuiltCorrectly_selfInstrumentingTest() throws GetDeployInfoException, ApkProvisionException {
    setupProject();
    Label testTarget = Label.create("//java/com/foo/app:self_instrumenting_test");
    Label instrumentorTarget = Label.create("//java/com/foo/app:test_app_self_instrumenting");
    BlazeContext context = BlazeContext.create();
    ImmutableList<String> blazeFlags = ImmutableList.of("some_blaze_flag", "some_other_flag");
    // Setup interceptor for fake running of blaze commands and capture details.
    ExternalTaskInterceptor externalTaskInterceptor = new ExternalTaskInterceptor();
    registerApplicationService(ExternalTaskProvider.class, externalTaskInterceptor);
    // Return fake deploy info proto and mocked deploy info data object.
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    AndroidDeployInfo fakeInstrumentorProto = AndroidDeployInfo.newBuilder().build();
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    when(helper.readDeployInfoProtoForTarget(eq(instrumentorTarget), any(BuildResultHelper.class), any())).thenReturn(fakeInstrumentorProto);
    when(helper.extractDeployInfoAndInvalidateManifests(eq(getProject()), eq(new File(getExecRoot())), eq(fakeInstrumentorProto))).thenReturn(mockDeployInfo);
    // Perform
    BlazeInstrumentationTestApkBuildStep buildStep = new BlazeInstrumentationTestApkBuildStep(getProject(), testTarget, blazeFlags, helper);
    buildStep.build(context, new DeviceSession(null, null, null));
    // Verify
    assertThat(buildStep.getDeployInfo()).isNotNull();
    assertThat(buildStep.getDeployInfo()).isEqualTo(mockDeployInfo);
    assertThat(externalTaskInterceptor.context).isEqualTo(context);
    assertThat(externalTaskInterceptor.command).contains(instrumentorTarget.toString());
    assertThat(externalTaskInterceptor.command).contains("--output_groups=+android_deploy_info");
    assertThat(externalTaskInterceptor.command).containsAllIn(blazeFlags);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) DeviceSession(com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) BlazeInstrumentationTestApkBuildStep(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep) File(java.io.File) Test(org.junit.Test)

Example 2 with DeviceSession

use of com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession in project intellij by bazelbuild.

the class BlazeInstrumentationTestApkBuildStepIntegrationTest method exceptionDuringDeployInfoExtraction.

@Test
public void exceptionDuringDeployInfoExtraction() throws GetDeployInfoException {
    setupProject();
    Label testTarget = Label.create("//java/com/foo/app:instrumentation_test");
    Label instrumentorTarget = Label.create("//java/com/foo/app:test_app");
    Label appTarget = Label.create("//java/com/foo/app:app");
    MessageCollector messageCollector = new MessageCollector();
    BlazeContext context = BlazeContext.create();
    context.addOutputSink(IssueOutput.class, messageCollector);
    // Make blaze command invocation always pass.
    registerApplicationService(ExternalTaskProvider.class, builder -> scopes -> 0);
    // Return fake deploy info proto and mocked deploy info data object.
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    AndroidDeployInfo fakeInstrumentorProto = AndroidDeployInfo.newBuilder().build();
    AndroidDeployInfo fakeAppProto = AndroidDeployInfo.newBuilder().build();
    when(helper.readDeployInfoProtoForTarget(eq(instrumentorTarget), any(BuildResultHelper.class), any())).thenReturn(fakeInstrumentorProto);
    when(helper.readDeployInfoProtoForTarget(eq(appTarget), any(BuildResultHelper.class), any())).thenReturn(fakeAppProto);
    when(helper.extractInstrumentationTestDeployInfoAndInvalidateManifests(any(), any(), any(), any())).thenThrow(new GetDeployInfoException("Fake Exception"));
    // Perform
    BlazeInstrumentationTestApkBuildStep buildStep = new BlazeInstrumentationTestApkBuildStep(getProject(), testTarget, ImmutableList.of(), helper);
    buildStep.build(context, new DeviceSession(null, null, null));
    // Verify
    assertThat(context.hasErrors()).isTrue();
    assertThat(messageCollector.getMessages()).contains("Could not read apk deploy info from build: Fake Exception");
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) DeviceSession(com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession) GetDeployInfoException(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper.GetDeployInfoException) MessageCollector(com.google.idea.blaze.android.MessageCollector) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeInstrumentationTestApkBuildStep(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep) Test(org.junit.Test)

Example 3 with DeviceSession

use of com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession in project intellij by bazelbuild.

the class BlazeInstrumentationTestApkBuildStepIntegrationTest method blazeCommandFailed.

@Test
public void blazeCommandFailed() throws GetDeployInfoException {
    setupProject();
    Label testTarget = Label.create("//java/com/foo/app:instrumentation_test");
    Label instrumentorTarget = Label.create("//java/com/foo/app:test_app");
    Label appTarget = Label.create("//java/com/foo/app:app");
    MessageCollector messageCollector = new MessageCollector();
    BlazeContext context = BlazeContext.create();
    context.addOutputSink(IssueOutput.class, messageCollector);
    // Return a non-zero value to indicate blaze command run failure.
    registerApplicationService(ExternalTaskProvider.class, builder -> scopes -> 1337);
    // Return fake deploy info proto and mocked deploy info data object.
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    AndroidDeployInfo fakeInstrumentorProto = AndroidDeployInfo.newBuilder().build();
    AndroidDeployInfo fakeAppProto = AndroidDeployInfo.newBuilder().build();
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    when(helper.readDeployInfoProtoForTarget(eq(instrumentorTarget), any(BuildResultHelper.class), any())).thenReturn(fakeInstrumentorProto);
    when(helper.readDeployInfoProtoForTarget(eq(appTarget), any(BuildResultHelper.class), any())).thenReturn(fakeAppProto);
    when(helper.extractInstrumentationTestDeployInfoAndInvalidateManifests(eq(getProject()), eq(new File(getExecRoot())), eq(fakeInstrumentorProto), eq(fakeAppProto))).thenReturn(mockDeployInfo);
    // Perform
    BlazeInstrumentationTestApkBuildStep buildStep = new BlazeInstrumentationTestApkBuildStep(getProject(), testTarget, ImmutableList.of(), helper);
    buildStep.build(context, new DeviceSession(null, null, null));
    // Verify
    assertThat(context.hasErrors()).isTrue();
    assertThat(messageCollector.getMessages()).contains("Blaze build failed. See Blaze Console for details.");
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) DeviceSession(com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession) MessageCollector(com.google.idea.blaze.android.MessageCollector) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) BlazeInstrumentationTestApkBuildStep(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep) File(java.io.File) Test(org.junit.Test)

Example 4 with DeviceSession

use of com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession in project intellij by bazelbuild.

the class FullApkBuildStepIntegrationTest method build_withRemoteApkButDisabledRemoteApkFetching.

@Test
public void build_withRemoteApkButDisabledRemoteApkFetching() throws Exception {
    // Setup remote APK downloader for ensuring the download method is called
    RemoteApkDownloader mockDownloader = mock(RemoteApkDownloader.class);
    when(mockDownloader.canDownload(any())).thenReturn(true);
    registerExtension(RemoteApkDownloader.EP_NAME, mockDownloader);
    // Disable remote APK fetching
    MockExperimentService mockExperimentService = new MockExperimentService();
    mockExperimentService.setExperiment(FullApkBuildStep.FETCH_REMOTE_APKS, false);
    ServiceHelper.registerApplicationComponent(ExperimentService.class, mockExperimentService, getTestRootDisposable());
    // Return fake deploy info proto and mocked deploy info data object.
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    File apkFile = new File("/path/to/apk");
    when(mockDeployInfo.getApksToDeploy()).thenReturn(ImmutableList.of(apkFile));
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    AndroidDeployInfo fakeProto = AndroidDeployInfo.newBuilder().build();
    when(helper.readDeployInfoProtoForTarget(eq(buildTarget), any(BuildResultHelper.class), any())).thenReturn(fakeProto);
    when(helper.extractDeployInfoAndInvalidateManifests(eq(getProject()), eq(new File(getExecRoot())), eq(fakeProto))).thenReturn(mockDeployInfo);
    // Perform
    FullApkBuildStep buildStep = new FullApkBuildStep(getProject(), buildTarget, blazeFlags, helper);
    buildStep.build(context, new DeviceSession(null, null, null));
    // Verify
    assertThat(buildStep.getDeployInfo()).isNotNull();
    assertThat(buildStep.getDeployInfo().getApksToDeploy()).containsExactly(apkFile);
    assertThat(externalTaskInterceptor.command).contains(buildTarget.toString());
    assertThat(externalTaskInterceptor.command).contains("--output_groups=+android_deploy_info");
    assertThat(externalTaskInterceptor.command).containsAllIn(blazeFlags);
    verify(mockDownloader, times(0)).download(any(), any());
}
Also used : MockExperimentService(com.google.idea.common.experiments.MockExperimentService) FullApkBuildStep(com.google.idea.blaze.android.run.runner.FullApkBuildStep) AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) DeviceSession(com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) RemoteApkDownloader(com.google.idea.blaze.android.run.RemoteApkDownloader) File(java.io.File) Test(org.junit.Test)

Example 5 with DeviceSession

use of com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession in project intellij by bazelbuild.

the class MobileInstallBuildStepIntegrationTest method nullExecRoot.

@Test
public void nullExecRoot() throws Exception {
    // Return null execroot
    when(mockBuildResultHelper.getBuildOutput()).thenReturn(new ParsedBepOutput(null, null, null, null, 0, BuildResult.SUCCESS, 0));
    // Mobile-install build step requires only one device be active.  DeviceFutures class is final,
    // so we have to make one with a stub AndroidDevice.
    DeviceFutures deviceFutures = new DeviceFutures(ImmutableList.of(new FakeDevice()));
    // Return fake deploy info proto and mocked deploy info data object.
    AndroidDeployInfo fakeProto = AndroidDeployInfo.newBuilder().build();
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    when(helper.readDeployInfoProtoForTarget(eq(buildTarget), any(BuildResultHelper.class), any())).thenReturn(fakeProto);
    when(helper.extractDeployInfoAndInvalidateManifests(getProject(), new File(getExecRoot()), fakeProto)).thenReturn(mockDeployInfo);
    // Perform
    MobileInstallBuildStep buildStep = new MobileInstallBuildStep(getProject(), buildTarget, blazeFlags, execFlags, helper);
    buildStep.build(context, new DeviceSession(null, deviceFutures, null));
    // Verify
    assertThat(context.hasErrors()).isTrue();
    assertThat(messageCollector.getMessages()).contains("Could not locate execroot!");
}
Also used : AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) DeviceSession(com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession) MobileInstallBuildStep(com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) DeviceFutures(com.android.tools.idea.run.DeviceFutures) ParsedBepOutput(com.google.idea.blaze.base.command.buildresult.ParsedBepOutput) File(java.io.File) Test(org.junit.Test)

Aggregations

AndroidDeployInfo (com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo)19 BlazeAndroidDeployInfo (com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo)19 BlazeApkDeployInfoProtoHelper (com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper)19 DeviceSession (com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession)19 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)19 Test (org.junit.Test)19 File (java.io.File)16 DeviceFutures (com.android.tools.idea.run.DeviceFutures)8 MobileInstallBuildStep (com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep)8 FullApkBuildStep (com.google.idea.blaze.android.run.runner.FullApkBuildStep)6 BlazeInstrumentationTestApkBuildStep (com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep)5 Label (com.google.idea.blaze.base.model.primitives.Label)5 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)5 MessageCollector (com.google.idea.blaze.android.MessageCollector)3 AdbTunnelConfigurator (com.google.idea.blaze.android.run.binary.mobileinstall.AdbTunnelConfigurator)3 GetDeployInfoException (com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper.GetDeployInfoException)3 ParsedBepOutput (com.google.idea.blaze.base.command.buildresult.ParsedBepOutput)3 RemoteApkDownloader (com.google.idea.blaze.android.run.RemoteApkDownloader)2 MockExperimentService (com.google.idea.common.experiments.MockExperimentService)1