Search in sources :

Example 1 with MessageCollector

use of com.google.idea.blaze.android.MessageCollector in project intellij by bazelbuild.

the class BlazeInstrumentationTestApkBuildStepIntegrationTest method getInstrumentorToTargetPair_separateInstrumentorAndTestTargets.

@Test
public void getInstrumentorToTargetPair_separateInstrumentorAndTestTargets() {
    setupProject();
    MessageCollector messageCollector = new MessageCollector();
    BlazeContext context = BlazeContext.create();
    context.addOutputSink(IssueOutput.class, messageCollector);
    BlazeInstrumentationTestApkBuildStep buildStep = new BlazeInstrumentationTestApkBuildStep(getProject(), Label.create("//java/com/foo/app:instrumentation_test"), ImmutableList.of());
    InstrumentorToTarget pair = buildStep.getInstrumentorToTargetPair(context, BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData());
    assertThat(pair.instrumentor).isEqualTo(Label.create("//java/com/foo/app:test_app"));
    assertThat(pair.target).isEqualTo(Label.create("//java/com/foo/app:app"));
    assertThat(pair.isSelfInstrumentingTest()).isFalse();
    assertThat(messageCollector.getMessages()).isEmpty();
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) MessageCollector(com.google.idea.blaze.android.MessageCollector) BlazeInstrumentationTestApkBuildStep(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep) InstrumentorToTarget(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep.InstrumentorToTarget) Test(org.junit.Test)

Example 2 with MessageCollector

use of com.google.idea.blaze.android.MessageCollector 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 MessageCollector

use of com.google.idea.blaze.android.MessageCollector in project intellij by bazelbuild.

the class BlazeInstrumentationTestApkBuildStepIntegrationTest method getInstrumentorToTargetPair_selfInstrumentingTest.

@Test
public void getInstrumentorToTargetPair_selfInstrumentingTest() {
    setupProject();
    MessageCollector messageCollector = new MessageCollector();
    BlazeContext context = BlazeContext.create();
    context.addOutputSink(IssueOutput.class, messageCollector);
    BlazeInstrumentationTestApkBuildStep buildStep = new BlazeInstrumentationTestApkBuildStep(getProject(), Label.create("//java/com/foo/app:self_instrumenting_test"), ImmutableList.of());
    InstrumentorToTarget pair = buildStep.getInstrumentorToTargetPair(context, BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData());
    assertThat(pair.instrumentor).isEqualTo(Label.create("//java/com/foo/app:test_app_self_instrumenting"));
    assertThat(pair.target).isNull();
    assertThat(pair.isSelfInstrumentingTest()).isTrue();
    assertThat(messageCollector.getMessages()).isEmpty();
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) MessageCollector(com.google.idea.blaze.android.MessageCollector) BlazeInstrumentationTestApkBuildStep(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep) InstrumentorToTarget(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep.InstrumentorToTarget) Test(org.junit.Test)

Example 4 with MessageCollector

use of com.google.idea.blaze.android.MessageCollector 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 5 with MessageCollector

use of com.google.idea.blaze.android.MessageCollector in project intellij by bazelbuild.

the class FullApkBuildStepIntegrationTest method setupTestInfoGatherers.

@Before
public void setupTestInfoGatherers() {
    // Message collector for collecting errors.
    messageCollector = new MessageCollector();
    context = BlazeContext.create();
    context.addOutputSink(IssueOutput.class, messageCollector);
    // Setup interceptor for fake running of blaze commands and capture details.
    externalTaskInterceptor = new ExternalTaskInterceptor();
    registerApplicationService(ExternalTaskProvider.class, externalTaskInterceptor);
}
Also used : MessageCollector(com.google.idea.blaze.android.MessageCollector) Before(org.junit.Before)

Aggregations

MessageCollector (com.google.idea.blaze.android.MessageCollector)8 BlazeInstrumentationTestApkBuildStep (com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep)6 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)6 Test (org.junit.Test)6 AndroidDeployInfo (com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo)3 BlazeAndroidDeployInfo (com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo)3 BlazeApkDeployInfoProtoHelper (com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper)3 DeviceSession (com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession)3 InstrumentorToTarget (com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep.InstrumentorToTarget)3 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)3 Label (com.google.idea.blaze.base.model.primitives.Label)3 File (java.io.File)2 Before (org.junit.Before)2 GetDeployInfoException (com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper.GetDeployInfoException)1 ParsedBepOutput (com.google.idea.blaze.base.command.buildresult.ParsedBepOutput)1 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)1