use of com.google.idea.blaze.android.run.runner.FullApkBuildStep 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());
}
use of com.google.idea.blaze.android.run.runner.FullApkBuildStep in project intellij by bazelbuild.
the class FullApkBuildStepIntegrationTest method build_completesSuccessfully.
@Test
public void build_completesSuccessfully() throws Exception {
// 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);
}
use of com.google.idea.blaze.android.run.runner.FullApkBuildStep in project intellij by bazelbuild.
the class FullApkBuildStepIntegrationTest method build_withBlazeCommandFailure_shouldFail.
@Test
public void build_withBlazeCommandFailure_shouldFail() throws Exception {
// 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.
AndroidDeployInfo fakeProto = AndroidDeployInfo.newBuilder().build();
BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
when(mockDeployInfo.getApksToDeploy()).thenReturn(ImmutableList.of());
BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
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, 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.");
}
use of com.google.idea.blaze.android.run.runner.FullApkBuildStep in project intellij by bazelbuild.
the class FullApkBuildStepIntegrationTest method build_withRemoteApk.
@Test
public void build_withRemoteApk() 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);
// 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()).doesNotContain(apkFile);
assertThat(getOnlyElement(buildStep.getDeployInfo().getApksToDeploy()).getPath()).contains("localcopy");
assertThat(externalTaskInterceptor.command).contains(buildTarget.toString());
assertThat(externalTaskInterceptor.command).contains("--output_groups=+android_deploy_info");
assertThat(externalTaskInterceptor.command).containsAllIn(blazeFlags);
verify(mockDownloader, times(1)).download(any(), any());
}
use of com.google.idea.blaze.android.run.runner.FullApkBuildStep in project intellij by bazelbuild.
the class FullApkBuildStepIntegrationTest method build_withNullExecRoot_shouldFail.
@Test
public void build_withNullExecRoot_shouldFail() throws Exception {
// Return null execroot
when(mockBuildResultHelper.getBuildOutput()).thenReturn(new ParsedBepOutput(null, null, null, null, 0, BuildResult.SUCCESS));
// Return fake deploy info proto and mocked deploy info data object.
AndroidDeployInfo fakeProto = AndroidDeployInfo.newBuilder().build();
BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
when(mockDeployInfo.getApksToDeploy()).thenReturn(ImmutableList.of());
BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
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(context.hasErrors()).isTrue();
assertThat(messageCollector.getMessages()).contains("Could not locate execroot!");
}
Aggregations