use of com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep 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!");
}
use of com.google.idea.blaze.android.run.binary.mobileinstall.MobileInstallBuildStep in project intellij by bazelbuild.
the class MobileInstallBuildStepIntegrationTest method deployInfoBuiltCorrectly_withInactiveAdbTunnelSetup.
@Test
public void deployInfoBuiltCorrectly_withInactiveAdbTunnelSetup() 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(false);
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");
// workaround for inconsistent stateful AndroidDebugBridge class.
assertThat(externalTaskInterceptor.command).containsAnyOf("serial-number", "serial-number:tcp:0");
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 deployInfoBuiltCorrectly.
@Test
public void deployInfoBuiltCorrectly() 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);
// 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).containsAnyOf("serial-number", "serial-number:tcp:0");
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 deployInfoBuiltCorrectly_withNullAdbTunnelSetup.
@Test
public void deployInfoBuiltCorrectly_withNullAdbTunnelSetup() 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 -> null);
// 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");
// workaround for inconsistent stateful AndroidDebugBridge class.
assertThat(externalTaskInterceptor.command).containsAnyOf("serial-number", "serial-number:tcp:0");
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 moreThanOneDevice.
@Test
public void moreThanOneDevice() 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(), 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("Only one device can be used with mobile-install.");
}
Aggregations