public static PrintJob createTestPrintJob(PrintFileProcessor processor) throws InappropriateDeviceException, Exception { PrintJob printJob = Mockito.mock(PrintJob.class); Printer printer = Mockito.mock(Printer.class); PrinterConfiguration printerConfiguration = Mockito.mock(PrinterConfiguration.class); SlicingProfile slicingProfile = Mockito.mock(SlicingProfile.class); InkConfig inkConfiguration = Mockito.mock(InkConfig.class); eGENERICGCodeControl gCode = Mockito.mock(eGENERICGCodeControl.class); SerialCommunicationsPort serialPort = Mockito.mock(SerialCommunicationsPort.class); MonitorDriverConfig monitorConfig = Mockito.mock(MonitorDriverConfig.class); MachineConfig machine = Mockito.mock(MachineConfig.class); Mockito.when(printJob.getJobFile()).thenReturn(new File("jobname.txt")); Mockito.when(printJob.getPrinter()).thenReturn(printer); Mockito.when(printer.getPrinterFirmwareSerialPort()).thenReturn(serialPort); Mockito.when(printJob.getPrintFileProcessor()).thenReturn(processor); Mockito.when(printer.getConfiguration()).thenReturn(printerConfiguration); Mockito.when(printer.waitForPauseIfRequired()).thenReturn(true); Mockito.when(printer.isPrintActive()).thenReturn(true); Mockito.when(printerConfiguration.getSlicingProfile()).thenReturn(slicingProfile); Mockito.when(slicingProfile.getSelectedInkConfig()).thenReturn(inkConfiguration); Mockito.when(slicingProfile.getDirection()).thenReturn(BuildDirection.Bottom_Up); Mockito.when(printer.getGCodeControl()).thenReturn(gCode); Mockito.when(slicingProfile.getgCodeLift()).thenReturn("Lift z"); Mockito.doCallRealMethod() .when(gCode) .executeGCodeWithTemplating(Mockito.any(PrintJob.class), Mockito.anyString()); Mockito.when(printer.getConfiguration().getMachineConfig()).thenReturn(machine); Mockito.when(printer.getConfiguration().getMachineConfig().getMonitorDriverConfig()) .thenReturn(monitorConfig); return printJob; }
PrinterConfiguration createTemplatePrinter( String printername, String displayId, String comport, double physicalProjectionMMX, double physicalProjectionMMY, double buildHeightMMZ) { PrinterConfiguration currentConfiguration = new PrinterConfiguration(printername, printername); ComPortSettings settings = new ComPortSettings(); settings.setPortName(comport); settings.setDatabits(8); settings.setHandshake("None"); settings.setStopbits("One"); settings.setParity("None"); settings.setSpeed(115200); MotorsDriverConfig motors = new MotorsDriverConfig(); motors.setComPortSettings(settings); MonitorDriverConfig monitor = new MonitorDriverConfig(); MachineConfig machineConfig = new MachineConfig(); machineConfig.setMotorsDriverConfig(motors); machineConfig.setMonitorDriverConfig(monitor); machineConfig.setOSMonitorID(displayId); machineConfig.setName(printername); machineConfig.setPlatformXSize(physicalProjectionMMX); machineConfig.setPlatformYSize(physicalProjectionMMY); machineConfig.setPlatformZSize(buildHeightMMZ); SlicingProfile slicingProfile = new SlicingProfile(); slicingProfile.setLiftDistance(5.0); slicingProfile.setLiftFeedRate(50); slicingProfile.setDirection(BuildDirection.Bottom_Up); try { GraphicsDevice device = DisplayManager.Instance().getDisplayDevice(DisplayManager.LAST_AVAILABLE_DISPLAY); monitor.setDLP_X_Res(device.getDefaultConfiguration().getBounds().getWidth()); monitor.setDLP_Y_Res(device.getDefaultConfiguration().getBounds().getHeight()); machineConfig.setxRenderSize((int) monitor.getDLP_X_Res()); machineConfig.setyRenderSize((int) monitor.getDLP_Y_Res()); slicingProfile.setxResolution((int) monitor.getDLP_X_Res()); slicingProfile.setyResolution((int) monitor.getDLP_Y_Res()); } catch (InappropriateDeviceException e) { e.printStackTrace(); throw new IllegalArgumentException("Couldn't get screen device"); } InkConfig ink = new InkConfig(); ink.setName("Default"); ink.setNumberOfFirstLayers(3); ink.setResinPriceL(65.0); ink.setSliceHeight(0.1); ink.setFirstLayerExposureTime(5000); ink.setExposureTime(1000); List<InkConfig> configs = new ArrayList<InkConfig>(); configs.add(ink); slicingProfile.setInkConfigs(configs); slicingProfile.setSelectedInkConfigName("Default"); slicingProfile.setDotsPermmX(monitor.getDLP_X_Res() / physicalProjectionMMX); slicingProfile.setDotsPermmY(monitor.getDLP_Y_Res() / physicalProjectionMMY); slicingProfile.setFlipX(false); slicingProfile.setFlipY(true); currentConfiguration.setSlicingProfile(slicingProfile); currentConfiguration.setMachineConfig(machineConfig); currentConfiguration.setName(printername); return currentConfiguration; }