use of com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep in project intellij by bazelbuild.
the class MobileInstallBuildStepIntegrationTest method deployInfoBuiltCorrectly_withAdbTunnelSetup.
@Test
public void deployInfoBuiltCorrectly_withAdbTunnelSetup() throws Exception {
// 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);
// Setup mock AdbTunnelConfigurator for testing device port flags.
AdbTunnelConfigurator tunnelConfigurator = mock(AdbTunnelConfigurator.class);
when(tunnelConfigurator.isActive()).thenReturn(true);
when(tunnelConfigurator.getAdbServerPort()).thenReturn(12345);
registerExtension(AdbTunnelConfiguratorProvider.EP_NAME, providerCxt -> tunnelConfigurator);
// Perform
MobileInstallBuildStep buildStep = new MobileInstallBuildStep(getProject(), buildTarget, blazeFlags, execFlags, helper);
buildStep.build(context, new DeviceSession(null, deviceFutures, null));
// Verify
assertThat(buildStep.getDeployInfo()).isNotNull();
assertThat(buildStep.getDeployInfo()).isEqualTo(mockDeployInfo);
assertThat(externalTaskInterceptor.context).isEqualTo(context);
assertThat(externalTaskInterceptor.command).containsAllIn(blazeFlags);
assertThat(externalTaskInterceptor.command).containsAllIn(execFlags);
assertThat(externalTaskInterceptor.command).contains("--nolaunch_app");
assertThat(externalTaskInterceptor.command).contains("--device");
assertThat(externalTaskInterceptor.command).contains("serial-number:tcp:12345");
assertThat(externalTaskInterceptor.command).contains(buildTarget.toString());
}
use of com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep in project intellij by bazelbuild.
the class MobileInstallBuildStepIntegrationTest method blazeCommandFailed.
@Test
public void blazeCommandFailed() throws Exception {
// Return a non-zero value to indicate blaze command run failure.
registerApplicationService(ExternalTaskProvider.class, builder -> scopes -> 1337);
// 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, ImmutableList.of(), ImmutableList.of(), helper);
buildStep.build(context, new DeviceSession(null, deviceFutures, null));
// Verify
assertThat(context.hasErrors()).isTrue();
assertThat(messageCollector.getMessages()).contains("Blaze build failed. See Blaze Console for details.");
}
use of com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep in project intellij by bazelbuild.
the class MobileInstallBuildStepIntegrationTest method exceptionDuringDeployInfoExtraction.
@Test
public void exceptionDuringDeployInfoExtraction() throws Exception {
// Make blaze command invocation always pass.
registerApplicationService(ExternalTaskProvider.class, builder -> scopes -> 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();
BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
when(helper.readDeployInfoProtoForTarget(eq(buildTarget), any(BuildResultHelper.class), any())).thenReturn(fakeProto);
when(helper.extractDeployInfoAndInvalidateManifests(any(), any(), any())).thenThrow(new GetDeployInfoException("Fake Exception"));
// Perform
MobileInstallBuildStep buildStep = new MobileInstallBuildStep(getProject(), buildTarget, ImmutableList.of(), ImmutableList.of(), helper);
buildStep.build(context, new DeviceSession(null, deviceFutures, null));
// Verify
assertThat(context.hasErrors()).isTrue();
assertThat(messageCollector.getMessages()).contains("Could not read apk deploy info from build: Fake Exception");
}
Aggregations