@Test void testWritePackageSheet() { String entityType1Id = "e1"; EntityType entityType1 = mock(EntityType.class); String entityType2Id = "e2"; EntityType entityType2 = mock(EntityType.class); String pack1Id = "parentParentPack_parentPack_pack1"; Package pack1 = mock(Package.class); doReturn(pack1Id).when(pack1).get(PackageMetadata.ID); String parentPackId = "parentParentPack_parentPack"; Package parentPack = when(mock(Package.class).getId()).thenReturn(parentPackId).getMock(); doReturn(parentPackId).when(parentPack).get(PackageMetadata.ID); doReturn(parentPackId).when(parentPack).getIdValue(); String parentParentPackId = "parentParentPack"; Package parentParentPack = when(mock(Package.class).getId()).thenReturn(parentParentPackId).getMock(); doReturn(parentParentPackId).when(parentParentPack).get(PackageMetadata.ID); doReturn(parentParentPackId).when(parentParentPack).getIdValue(); String pack2Id = "pack2"; Package pack2 = mock(Package.class); doReturn(pack2Id).when(pack2).get(PackageMetadata.ID); String entityPackId = "entityParentPack_entityPack"; Package entityPack1 = when(mock(Package.class).getId()).thenReturn(entityPackId).getMock(); doReturn(entityPackId).when(entityPack1).get(PackageMetadata.ID); doReturn(entityPackId).when(entityPack1).getIdValue(); String entityParentPackId = "entityParentPack"; Package entityParentPack1 = when(mock(Package.class).getId()).thenReturn(entityParentPackId).getMock(); doReturn(entityParentPackId).when(entityParentPack1).get(PackageMetadata.ID); doReturn(entityParentPackId).when(entityParentPack1).getIdValue(); when(pack1.getParent()).thenReturn(parentPack); when(parentPack.getParent()).thenReturn(parentParentPack); when(pack2.getParent()).thenReturn(null); when(entityPack1.getParent()).thenReturn(entityParentPack1); when(entityType1.getPackage()).thenReturn(entityPack1); when(entityType2.getPackage()).thenReturn(null); Map<String, EntityType> entityTypes = new HashMap<>(); entityTypes.put(entityType1Id, entityType1); entityTypes.put(entityType2Id, entityType2); Map<String, Package> packages = new HashMap<>(); packages.put(pack1Id, pack1); packages.put(pack2Id, pack2); doReturn("Finished").when(contextMessageSource).getMessage("emx_export_metadata_message"); XlsxWriter writer = mock(XlsxWriter.class); Progress progress = mock(Progress.class); List<Object> expectedRow1 = newArrayList( "parentParentPack_parentPack_pack1", null, null, "parentParentPack_parentPack", ""); List<Object> expectedRow2 = newArrayList("parentParentPack_parentPack", null, null, "parentParentPack", ""); List<Object> expectedRow3 = newArrayList("parentParentPack", null, null, null, ""); List<Object> expectedRow4 = newArrayList("entityParentPack_entityPack", null, null, "entityParentPack", ""); List<Object> expectedRow5 = newArrayList("entityParentPack", null, null, null, ""); List<Object> expectedRow6 = newArrayList("pack2", null, null, null, ""); List<List<Object>> expected = newArrayList( expectedRow4, expectedRow6, expectedRow2, expectedRow1, expectedRow5, expectedRow3); service.writePackageSheet(packages, entityTypes, writer, progress); verify(writer).createSheet(EMX_PACKAGES, newArrayList(PACKAGE_ATTRS.keySet())); @SuppressWarnings("unchecked") ArgumentCaptor<Stream<List<Object>>> captor = ArgumentCaptor.forClass(Stream.class); verify(writer).writeRows(captor.capture(), eq("packages")); List<List<Object>> actual = captor.getValue().collect(Collectors.toList()); assertTrue(actual.containsAll(expected)); verify(progress).status("Finished"); }
void writePackageSheet( Map<String, Package> packages, Map<String, EntityType> entityTypes, XlsxWriter writer, Progress progress) { if (!writer.hasSheet(EMX_PACKAGES)) { writer.createSheet(EMX_PACKAGES, newArrayList(PACKAGE_ATTRS.keySet())); } addEntityPackages(entityTypes.values(), packages); addParentPackages(packages); writer.writeRows(packages.values().stream().map(PackageMapper::map), EMX_PACKAGES); progress.status(contextMessageSource.getMessage("emx_export_metadata_message")); progress.increment(1); }
EmxExportServiceImpl implements EmxExportService { void writePackageSheet( Map<String, Package> packages, Map<String, EntityType> entityTypes, XlsxWriter writer, Progress progress) { if (!writer.hasSheet(EMX_PACKAGES)) { writer.createSheet(EMX_PACKAGES, newArrayList(PACKAGE_ATTRS.keySet())); } addEntityPackages(entityTypes.values(), packages); addParentPackages(packages); writer.writeRows(packages.values().stream().map(PackageMapper::map), EMX_PACKAGES); progress.status(contextMessageSource.getMessage("emx_export_metadata_message")); progress.increment(1); } }
EmxExportServiceImpl implements EmxExportService { void writePackageSheet( Map<String, Package> packages, Map<String, EntityType> entityTypes, XlsxWriter writer, Progress progress) { if (!writer.hasSheet(EMX_PACKAGES)) { writer.createSheet(EMX_PACKAGES, newArrayList(PACKAGE_ATTRS.keySet())); } addEntityPackages(entityTypes.values(), packages); addParentPackages(packages); writer.writeRows(packages.values().stream().map(PackageMapper::map), EMX_PACKAGES); progress.status(contextMessageSource.getMessage("emx_export_metadata_message")); progress.increment(1); } EmxExportServiceImpl(DataService dataService, ContextMessageSource contextMessageSource); }
EmxExportServiceImpl implements EmxExportService { void writePackageSheet( Map<String, Package> packages, Map<String, EntityType> entityTypes, XlsxWriter writer, Progress progress) { if (!writer.hasSheet(EMX_PACKAGES)) { writer.createSheet(EMX_PACKAGES, newArrayList(PACKAGE_ATTRS.keySet())); } addEntityPackages(entityTypes.values(), packages); addParentPackages(packages); writer.writeRows(packages.values().stream().map(PackageMapper::map), EMX_PACKAGES); progress.status(contextMessageSource.getMessage("emx_export_metadata_message")); progress.increment(1); } EmxExportServiceImpl(DataService dataService, ContextMessageSource contextMessageSource); @Override @Transactional(readOnly = true, isolation = Isolation.SERIALIZABLE) void export(
      List<EntityType> entityTypes,
      List<Package> packages,
      Path downloadFilePath,
      Progress progress); }
EmxExportServiceImpl implements EmxExportService { void writePackageSheet( Map<String, Package> packages, Map<String, EntityType> entityTypes, XlsxWriter writer, Progress progress) { if (!writer.hasSheet(EMX_PACKAGES)) { writer.createSheet(EMX_PACKAGES, newArrayList(PACKAGE_ATTRS.keySet())); } addEntityPackages(entityTypes.values(), packages); addParentPackages(packages); writer.writeRows(packages.values().stream().map(PackageMapper::map), EMX_PACKAGES); progress.status(contextMessageSource.getMessage("emx_export_metadata_message")); progress.increment(1); } EmxExportServiceImpl(DataService dataService, ContextMessageSource contextMessageSource); @Override @Transactional(readOnly = true, isolation = Isolation.SERIALIZABLE) void export(
      List<EntityType> entityTypes,
      List<Package> packages,
      Path downloadFilePath,
      Progress progress);  }