@SuppressWarnings("unchecked") @Test void testDeleteResourcesPackages() { Package packageA = mock(Package.class); Package packageB = mock(Package.class); doReturn(Stream.of(packageA, packageB)) .when(dataService) .findAll(eq(PACKAGE), any(Stream.class), eq(Package.class)); Progress progress = mock(Progress.class); resourceDeleteServiceImpl.delete( asList( ResourceIdentifier.builder().setType(ResourceType.PACKAGE).setId("pA").build(), ResourceIdentifier.builder().setType(ResourceType.PACKAGE).setId("pB").build()), progress); @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Package>> packageCaptor = ArgumentCaptor.forClass(Stream.class); verify(dataService).delete(eq(PACKAGE), packageCaptor.capture()); assertEquals( new HashSet<>(asList(packageA, packageB)), packageCaptor.getValue().collect(toSet())); verifyNoMoreInteractions(dataService); }
@Override public Void delete(List<ResourceIdentifier> resources, Progress progress) { progress.status(contextMessageSource.getMessage("progress-delete-started")); Set<Object> packageIds = new LinkedHashSet<>(); Set<Object> entityTypeIds = new LinkedHashSet<>(); resources.forEach( resource -> { switch (resource.getType()) { case PACKAGE: packageIds.add(resource.getId()); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: entityTypeIds.add(resource.getId()); break; default: throw new UnexpectedEnumException(resource.getType()); } }); if (!entityTypeIds.isEmpty()) { deleteEntityTypes(entityTypeIds); } if (!packageIds.isEmpty()) { deletePackages(packageIds); } progress.status(contextMessageSource.getMessage("progress-delete-success")); return null; }
ResourceDeleteServiceImpl implements ResourceDeleteService { @Override public Void delete(List<ResourceIdentifier> resources, Progress progress) { progress.status(contextMessageSource.getMessage("progress-delete-started")); Set<Object> packageIds = new LinkedHashSet<>(); Set<Object> entityTypeIds = new LinkedHashSet<>(); resources.forEach( resource -> { switch (resource.getType()) { case PACKAGE: packageIds.add(resource.getId()); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: entityTypeIds.add(resource.getId()); break; default: throw new UnexpectedEnumException(resource.getType()); } }); if (!entityTypeIds.isEmpty()) { deleteEntityTypes(entityTypeIds); } if (!packageIds.isEmpty()) { deletePackages(packageIds); } progress.status(contextMessageSource.getMessage("progress-delete-success")); return null; } }
ResourceDeleteServiceImpl implements ResourceDeleteService { @Override public Void delete(List<ResourceIdentifier> resources, Progress progress) { progress.status(contextMessageSource.getMessage("progress-delete-started")); Set<Object> packageIds = new LinkedHashSet<>(); Set<Object> entityTypeIds = new LinkedHashSet<>(); resources.forEach( resource -> { switch (resource.getType()) { case PACKAGE: packageIds.add(resource.getId()); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: entityTypeIds.add(resource.getId()); break; default: throw new UnexpectedEnumException(resource.getType()); } }); if (!entityTypeIds.isEmpty()) { deleteEntityTypes(entityTypeIds); } if (!packageIds.isEmpty()) { deletePackages(packageIds); } progress.status(contextMessageSource.getMessage("progress-delete-success")); return null; } ResourceDeleteServiceImpl(DataService dataService, ContextMessageSource contextMessageSource); }
ResourceDeleteServiceImpl implements ResourceDeleteService { @Override public Void delete(List<ResourceIdentifier> resources, Progress progress) { progress.status(contextMessageSource.getMessage("progress-delete-started")); Set<Object> packageIds = new LinkedHashSet<>(); Set<Object> entityTypeIds = new LinkedHashSet<>(); resources.forEach( resource -> { switch (resource.getType()) { case PACKAGE: packageIds.add(resource.getId()); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: entityTypeIds.add(resource.getId()); break; default: throw new UnexpectedEnumException(resource.getType()); } }); if (!entityTypeIds.isEmpty()) { deleteEntityTypes(entityTypeIds); } if (!packageIds.isEmpty()) { deletePackages(packageIds); } progress.status(contextMessageSource.getMessage("progress-delete-success")); return null; } ResourceDeleteServiceImpl(DataService dataService, ContextMessageSource contextMessageSource); @Override Void delete(List<ResourceIdentifier> resources, Progress progress); }
ResourceDeleteServiceImpl implements ResourceDeleteService { @Override public Void delete(List<ResourceIdentifier> resources, Progress progress) { progress.status(contextMessageSource.getMessage("progress-delete-started")); Set<Object> packageIds = new LinkedHashSet<>(); Set<Object> entityTypeIds = new LinkedHashSet<>(); resources.forEach( resource -> { switch (resource.getType()) { case PACKAGE: packageIds.add(resource.getId()); break; case ENTITY_TYPE: case ENTITY_TYPE_ABSTRACT: entityTypeIds.add(resource.getId()); break; default: throw new UnexpectedEnumException(resource.getType()); } }); if (!entityTypeIds.isEmpty()) { deleteEntityTypes(entityTypeIds); } if (!packageIds.isEmpty()) { deletePackages(packageIds); } progress.status(contextMessageSource.getMessage("progress-delete-success")); return null; } ResourceDeleteServiceImpl(DataService dataService, ContextMessageSource contextMessageSource); @Override Void delete(List<ResourceIdentifier> resources, Progress progress);  }