ConverterBean implements IConverterManagerLocal { @Override @Asynchronous @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) public void convertCADFileToOBJ(PartIterationKey partIterationKey, BinaryResource cadBinaryResource) { try { Conversion existingConversion = productService.getConversion(partIterationKey); if (existingConversion != null && existingConversion.isPending()) { LOGGER.log(Level.SEVERE, "Conversion already running for part iteration {0}", partIterationKey); return; } if (existingConversion != null) { LOGGER.log(Level.FINE, "Cleaning previous ended conversion"); productService.removeConversion(partIterationKey); } } catch (ApplicationException e) { LOGGER.log(Level.SEVERE, null, e); return; } try { LOGGER.log(Level.FINE, "Creating a new conversion"); productService.createConversion(partIterationKey); } catch (ApplicationException e) { LOGGER.log(Level.SEVERE, null, e); return; } CADConverter selectedConverter = selectConverter(cadBinaryResource); boolean succeed = false; if (selectedConverter != null) { try { succeed = doConversion(cadBinaryResource, selectedConverter, partIterationKey); } catch (StorageException e) { LOGGER.log(Level.WARNING, "Unable to read from storage", e); } catch (IOException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); } catch (ConversionException e) { LOGGER.log(Level.WARNING, "Cannot convert " + cadBinaryResource.getName(), e); } } else { LOGGER.log(Level.WARNING, "No CAD converter able to handle " + cadBinaryResource.getName()); } try { LOGGER.log(Level.FINE, "Conversion ended"); productService.endConversion(partIterationKey, succeed); } catch (ApplicationException e) { LOGGER.log(Level.SEVERE, null, e); } }  @Override @Asynchronous @RolesAllowed({UserGroupMapping.REGULAR_USER_ROLE_ID}) void convertCADFileToOBJ(PartIterationKey partIterationKey, BinaryResource cadBinaryResource);  }
@Test public void testNominalConvert() throws Exception { bean.convertCADFileToOBJ(ipk, cadBinRes); verify(locator).search(CADConverter.class); verify(conv).canConvertToOBJ("dae"); verify(conv).convert(any(URI.class), any(URI.class)); verify(product).saveGeometryInPartIteration(eq(ipk), anyString(), anyInt(), anyLong(), any(double[].class)); verify(storage).getBinaryResourceOutputStream(lod); verify(product, times(2)).saveFileInPartIteration(eq(ipk), anyString(), eq(PartIteration.ATTACHED_FILES_SUBTYPE), anyLong()); verify(storage, times(2)).getBinaryResourceOutputStream(attachedFile); }
@Test public void testNoConverter() throws Exception { when(cadBinRes.getName()).thenReturn("foo.unknown"); bean.convertCADFileToOBJ(ipk, cadBinRes); verify(locator).search(CADConverter.class); verify(conv).canConvertToOBJ("unknown"); verify(conv, never()).convert(any(), any()); verify(product, never()).saveGeometryInPartIteration(any(), anyString(), anyInt(), anyLong(), any()); verify(product, never()).saveFileInPartIteration(any(), anyString(), anyString(), anyLong()); verify(storage, never()).getBinaryResourceOutputStream(any()); }
@Test public void testBrokenConvert() throws Exception { when(conv.convert(any(URI.class), any(URI.class))).thenThrow(new CADConverter.ConversionException("error")); bean.convertCADFileToOBJ(ipk, cadBinRes); verify(conv).canConvertToOBJ("dae"); verify(conv).convert(any(URI.class), any(URI.class)); verify(product, never()).saveGeometryInPartIteration(any(), anyString(), anyInt(), anyLong(), any()); verify(product, never()).saveFileInPartIteration(any(), anyString(), anyString(), anyLong()); verify(storage, never()).getBinaryResourceOutputStream(any()); }