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();
}
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());
}
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;
}
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"));
}
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);
}
Aggregations