Search in sources :

Example 21 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessTest method testOnBreakpointListChangedSetsErrorMessageAndUpdatesBreakpointPresentation.

public void testOnBreakpointListChangedSetsErrorMessageAndUpdatesBreakpointPresentation() throws Exception {
    // override the default XBreakpointManager implementation with mock to use Mockito.verify()
    XBreakpointManager breakpointManager = mock(XBreakpointManager.class);
    XDebuggerManager debuggerManager = mock(XDebuggerManager.class);
    when(debuggerManager.getBreakpointManager()).thenReturn(breakpointManager);
    ((ProjectImpl) getProject()).registerComponentInstance(XDebuggerManager.class, debuggerManager);
    ArrayList<Breakpoint> breakpoints = new ArrayList<Breakpoint>();
    Breakpoint breakpoint = new Breakpoint();
    breakpoint.setId("breakpointId").setIsFinalState(Boolean.TRUE).setStatus(new StatusMessage().setIsError(Boolean.TRUE));
    breakpoints.add(breakpoint);
    CloudDebugProcessState processState = mock(CloudDebugProcessState.class);
    when(processState.getCurrentServerBreakpointList()).thenReturn(ContainerUtil.immutableList(breakpoints));
    XLineBreakpointImpl xLineBreakpointImpl = mock(XLineBreakpointImpl.class);
    CloudLineBreakpoint cloudLineBreakpoint = mockCloudLineBreakpoint("mock error message", xLineBreakpointImpl);
    when(xLineBreakpointImpl.getUserData(com.intellij.debugger.ui.breakpoints.Breakpoint.DATA_KEY)).thenReturn(cloudLineBreakpoint);
    CloudBreakpointHandler breakpointHandler = mock(CloudBreakpointHandler.class);
    when(breakpointHandler.getEnabledXBreakpoint(breakpoint)).thenReturn(xLineBreakpointImpl);
    process.setBreakpointHandler(breakpointHandler);
    process.initialize(processState);
    process.onBreakpointListChanged(mock(CloudDebugProcessState.class));
    verify(cloudLineBreakpoint).setErrorMessage(eq("General error"));
    verify(cloudLineBreakpoint).getXBreakpoint();
    verify(cloudLineBreakpoint).getSetIcon(Matchers.anyBoolean());
    verify(cloudLineBreakpoint).getErrorMessage();
    verify(breakpointManager).updateBreakpointPresentation(same(xLineBreakpointImpl), any(Icon.class), eq("General error"));
    process.getStateController().stopBackgroundListening();
}
Also used : Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) XLineBreakpointImpl(com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) ProjectImpl(com.intellij.openapi.project.impl.ProjectImpl) ArrayList(java.util.ArrayList) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) Icon(javax.swing.Icon) StatusMessage(com.google.api.services.clouddebugger.v2.model.StatusMessage)

Example 22 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugHistoricalSnapshotsTest method testOnBreakpointListChanged_twoBreakPoints.

@Test
public void testOnBreakpointListChanged_twoBreakPoints() throws InterruptedException {
    CloudDebugHistoricalSnapshots snapshots = new CloudDebugHistoricalSnapshots(handler);
    Breakpoint bp1 = new Breakpoint();
    bp1.setId("bp1");
    bp1.setFinalTime("2015-08-22T05:23:34.123Z");
    bp1.setIsFinalState(true);
    SourceLocation location = new SourceLocation();
    location.setPath("foo/bar/baz");
    location.setLine(12);
    bp1.setLocation(location);
    Breakpoint bp2 = new Breakpoint();
    bp2.setId("bp2");
    bp2.setFinalTime("2016-08-22T05:23:34.123Z");
    bp2.setIsFinalState(true);
    SourceLocation location2 = new SourceLocation();
    location2.setPath("foo/bar/baz");
    location2.setLine(14);
    bp2.setLocation(location);
    List<Breakpoint> breakpoints1 = new ArrayList<Breakpoint>();
    breakpoints1.add(bp1);
    List<Breakpoint> breakpoints2 = new ArrayList<Breakpoint>();
    breakpoints2.add(bp1);
    breakpoints2.add(bp2);
    CloudBreakpointHandler breakpointHandler = Mockito.mock(CloudBreakpointHandler.class);
    Mockito.when(mockProcess.getBreakpointHandler()).thenReturn(breakpointHandler);
    Assert.assertEquals(-1, snapshots.table.getSelectedRow());
    // BP1
    Mockito.when(mockProcess.getCurrentBreakpointList()).thenReturn(breakpoints1);
    Mockito.when(mockProcess.getCurrentSnapshot()).thenReturn(bp1);
    runModelSetter(snapshots);
    Assert.assertEquals(0, snapshots.table.getSelectedRow());
    // BP2
    Mockito.when(mockProcess.getCurrentBreakpointList()).thenReturn(breakpoints2);
    Mockito.when(mockProcess.getCurrentSnapshot()).thenReturn(bp2);
    runModelSetter(snapshots);
    Assert.assertEquals(1, snapshots.table.getSelectedRow());
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) CloudBreakpointHandler(com.google.cloud.tools.intellij.debugger.CloudBreakpointHandler) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 23 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessStateTest method createMockClient.

private Debugger createMockClient(final List<Breakpoint> returnedBreakpoints) throws IOException {
    Debugger client = Mockito.mock(Debugger.class);
    Debugger.Debuggees debuggees = Mockito.mock(Debugger.Debuggees.class);
    Debugger.Debuggees.Breakpoints breakpoints = Mockito.mock(Debugger.Debuggees.Breakpoints.class);
    Debugger.Debuggees.Breakpoints.List list = Mockito.mock(Debugger.Debuggees.Breakpoints.List.class);
    when(client.debuggees()).thenReturn(debuggees);
    when(debuggees.breakpoints()).thenReturn(breakpoints);
    when(breakpoints.list(DEBUGEE_ID)).thenReturn(list);
    when(list.setIncludeInactive(Boolean.TRUE)).thenReturn(list);
    when(list.setActionValue("CAPTURE")).thenReturn(list);
    when(list.setStripResults(Boolean.TRUE)).thenReturn(list);
    when(list.setWaitToken(null)).thenReturn(list);
    when(list.setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger())).thenReturn(list);
    when(list.execute()).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ListBreakpointsResponse response = new ListBreakpointsResponse();
            List<Breakpoint> copy = new ArrayList<Breakpoint>(returnedBreakpoints);
            response.setBreakpoints(copy);
            return response;
        }
    });
    return client;
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) ListBreakpointsResponse(com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) List(java.util.List)

Example 24 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessStateTest method testFirstSync.

public void testFirstSync() throws IOException {
    List<Breakpoint> returnedBreakpoints = new ArrayList<Breakpoint>();
    returnedBreakpoints.add(createBreakpoint("bp1", Boolean.TRUE, 1000, "com/google/ex1.java", 15, null, null));
    returnedBreakpoints.add(createBreakpoint("bp2", Boolean.TRUE, 2000, "com/google/ex1.java", 15, null, null));
    returnedBreakpoints.add(createBreakpoint("bp3", Boolean.TRUE, 2200, "com/google/ex1.java", 15, Boolean.TRUE, "foo!"));
    returnedBreakpoints.add(createBreakpoint("bp4", Boolean.FALSE, 0, "com/google/ex2.java", 12, null, null));
    returnedBreakpoints.add(createBreakpoint("bp5", Boolean.FALSE, 0, "com/google/ex1.java", 15, null, null));
    returnedBreakpoints.add(createBreakpoint("bp6", null, 0, "com/google/ex1.java", 16, null, null));
    returnedBreakpoints.add(createBreakpoint("bp7", Boolean.FALSE, 0, "com/google/ex1.java", 17, null, null));
    returnedBreakpoints.add(createBreakpoint("bp8", Boolean.FALSE, 0, "com/google/ex3.java", 18, null, null));
    Debugger client = createMockClient(returnedBreakpoints);
    CloudDebugProcessState state = new CloudDebugProcessState(USER, DEBUGEE_ID, PROJECT_NAME, PROJECT_NUMBER, null);
    assertEquals(USER, state.getUserEmail());
    // Danger: static global state
    CloudDebuggerClient.setClient(state.getUserEmail() + 120000, client);
    CloudDebugProcessStateController controller = new CloudDebugProcessStateController();
    controller.initialize(state);
    verify(client.debuggees().breakpoints().list(DEBUGEE_ID), times(1)).setIncludeInactive(Boolean.TRUE);
    List<Breakpoint> currentList = state.getCurrentServerBreakpointList();
    assertNotEmpty(currentList);
    // verifies the sort order...
    assertTrue(verifyList(currentList, "bp5", "bp6", "bp7", "bp4", "bp8", "bp3", "bp2", "bp1"));
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) ArrayList(java.util.ArrayList)

Example 25 with Breakpoint

use of com.google.api.services.clouddebugger.v2.model.Breakpoint in project google-cloud-intellij by GoogleCloudPlatform.

the class DoUpdateIdeWithBreakpointTest method runUpdateIdeWithBreakpoint.

@Test
public void runUpdateIdeWithBreakpoint() throws Exception {
    when(virtualFile.getUrl()).thenReturn(MOCK_FILE_URL);
    when(xLineBreakpoint.getUserData(com.intellij.debugger.ui.breakpoints.Breakpoint.DATA_KEY)).thenReturn(cloudLineBreakpoint);
    when(xLineBreakpoint.getProperties()).thenReturn(cloudLineBreakpointProperties);
    when(breakpointManager.addLineBreakpoint(any(CloudLineBreakpointType.class), anyString(), anyInt(), eq(cloudLineBreakpointProperties))).thenReturn(xLineBreakpoint);
    Breakpoint serverBreakpoint = new Breakpoint();
    serverBreakpoint.setId("mock-breakpoint-id").setCondition(MOCK_BREAKPOINT_CONDITION).setExpressions(Lists.newArrayList(MOCK_BREAKPOINT_EXPRESSION));
    HashMap<String, XBreakpoint> ideBreakpoints = new HashMap<>();
    int line = 1;
    new DoUpdateIdeWithBreakpoint(breakpointManager, virtualFile, line, cloudLineBreakpointProperties, serverBreakpoint, ideBreakpoints, cloudDebugProcess).run();
    verify(breakpointManager).addLineBreakpoint(any(), eq(MOCK_FILE_URL), eq(line), eq(cloudLineBreakpointProperties));
    verify(xLineBreakpoint).putUserData(keyArgumentCaptor.capture(), eq("mock-breakpoint-id"));
    assertThat(keyArgumentCaptor.getValue().toString()).isEqualTo(// CloudBreakpointHandler.CLOUD_ID
    "CloudId");
    assertThat(ideBreakpoints.get("mock-breakpoint-id")).isEqualTo(xLineBreakpoint);
    verify(xLineBreakpoint).setCondition(eq(MOCK_BREAKPOINT_CONDITION));
    assertThat(cloudLineBreakpointProperties.getWatchExpressions()).hasLength(1);
    assertThat(cloudLineBreakpointProperties.getWatchExpressions()[0]).isEqualTo(MOCK_BREAKPOINT_EXPRESSION);
    assertFalse(cloudLineBreakpointProperties.isCreatedByServer());
    verify(cloudDebugProcess).updateBreakpointPresentation(cloudLineBreakpoint);
}
Also used : Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) HashMap(com.intellij.util.containers.HashMap) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Test(org.junit.Test)

Aggregations

Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)27 CloudLineBreakpoint (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)11 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)11 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)10 SourceLocation (com.google.api.services.clouddebugger.v2.model.SourceLocation)8 Debugger (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger)7 ArrayList (java.util.ArrayList)7 XBreakpointManager (com.intellij.xdebugger.breakpoints.XBreakpointManager)4 IOException (java.io.IOException)4 ListBreakpointsResponse (com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse)3 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 XLineBreakpointImpl (com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl)3 Test (org.junit.Test)3 StatusMessage (com.google.api.services.clouddebugger.v2.model.StatusMessage)2 CloudBreakpointHandler (com.google.cloud.tools.intellij.debugger.CloudBreakpointHandler)2 SetBreakpointHandler (com.google.cloud.tools.intellij.debugger.CloudDebugProcessStateController.SetBreakpointHandler)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 XDebuggerManager (com.intellij.xdebugger.XDebuggerManager)2