|
24 | 24 | import org.eclipse.sw360.datahandler.thrift.*; |
25 | 25 | import org.eclipse.sw360.datahandler.thrift.components.*; |
26 | 26 | import org.eclipse.sw360.datahandler.thrift.projects.Project; |
| 27 | +import org.eclipse.sw360.datahandler.thrift.projects.ProjectProjectRelationship; |
| 28 | +import org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship; |
| 29 | +import org.eclipse.sw360.datahandler.thrift.projects.ProjectType; |
27 | 30 | import org.eclipse.sw360.datahandler.thrift.users.User; |
28 | 31 | import org.eclipse.sw360.datahandler.thrift.users.UserGroup; |
29 | 32 | import org.eclipse.sw360.datahandler.thrift.vendors.Vendor; |
|
34 | 37 | import org.mockito.Mock; |
35 | 38 | import org.mockito.junit.MockitoJUnitRunner; |
36 | 39 |
|
| 40 | +import org.apache.logging.log4j.LogManager; |
| 41 | +import org.apache.logging.log4j.Logger; |
| 42 | + |
| 43 | +import com.google.common.collect.ImmutableMap; |
37 | 44 |
|
38 | 45 | import java.io.BufferedWriter; |
39 | 46 | import java.io.FileWriter; |
|
48 | 55 | @RunWith(MockitoJUnitRunner.class) |
49 | 56 | public class BulkDeleteUtilTest { |
50 | 57 |
|
| 58 | + private static final Logger log = LogManager.getLogger(BulkDeleteUtilTest.class); |
| 59 | + |
51 | 60 | private static final String dbName = DatabaseSettingsTest.COUCH_DB_DATABASE; |
52 | 61 | private static final String attachmentsDbName = DatabaseSettingsTest.COUCH_DB_ATTACHMENTS; |
53 | 62 | private static final String changeLogsDbName = DatabaseSettingsTest.COUCH_DB_CHANGELOGS; |
@@ -154,7 +163,7 @@ public void tearDown() throws Exception { |
154 | 163 | @Test |
155 | 164 | public void testGetAllLinkedReleaseMap() throws Exception { |
156 | 165 | if (!isFeatureEnable()) { |
157 | | - System.out.println("BulkReleaseDeletion is disabled. these test is Skipped."); |
| 166 | + log.warn("BulkReleaseDeletion is disabled. these test is Skipped."); |
158 | 167 | return; |
159 | 168 | } |
160 | 169 |
|
@@ -230,7 +239,7 @@ public void testGetExternalLinkMap() throws Exception { |
230 | 239 | @Test |
231 | 240 | public void testDeleteBulkRelease001() throws Exception { |
232 | 241 | if (!isFeatureEnable()) { |
233 | | - System.out.println("BulkReleaseDeletion is disabled. these test is Skipped."); |
| 242 | + log.warn("BulkReleaseDeletion is disabled. these test is Skipped."); |
234 | 243 | return; |
235 | 244 | } |
236 | 245 |
|
@@ -461,7 +470,7 @@ private void checkBulkOperationNode(BulkOperationNode node, Map<String, Object[] |
461 | 470 | //@Test |
462 | 471 | public void testDeleteBulkRelease002() throws Exception { |
463 | 472 | if (!isFeatureEnable()) { |
464 | | - System.out.println("BulkReleaseDeletion is disabled. these test is Skipped."); |
| 473 | + log.warn("BulkReleaseDeletion is disabled. these test is Skipped."); |
465 | 474 | return; |
466 | 475 | } |
467 | 476 |
|
@@ -517,10 +526,64 @@ public void testDeleteBulkRelease002() throws Exception { |
517 | 526 | } |
518 | 527 | } |
519 | 528 |
|
| 529 | + @Test |
| 530 | + public void testDeleteBulkRelease_ExternalLink001() throws Exception { |
| 531 | + if (!isFeatureEnable()) { |
| 532 | + log.warn("BulkReleaseDeletion is disabled. these test is Skipped."); |
| 533 | + return; |
| 534 | + } |
| 535 | + |
| 536 | + List<String> releaseIdList = new ArrayList<String>(); |
| 537 | + List<String> componentIdList = new ArrayList<String>(); |
| 538 | + |
| 539 | + createTestRecords002(1, 2, releaseIdList, componentIdList); |
| 540 | + String rootReleaseId = releaseIdList.get(0); |
| 541 | + assertEquals(3, releaseIdList.size()); |
| 542 | + assertEquals(3, componentIdList.size()); |
| 543 | + |
| 544 | + Project project = new Project().setId("P1").setName("project1").setVisbility(Visibility.EVERYONE).setProjectType(ProjectType.CUSTOMER); |
| 545 | + project.putToReleaseIdToUsage(rootReleaseId, new ProjectReleaseRelationship(ReleaseRelationship.CONTAINED, MainlineState.OPEN)); |
| 546 | + databaseConnector.add(project); |
| 547 | + |
| 548 | + BulkOperationNode level1Component = bulkDeleteUtil.deleteBulkRelease(rootReleaseId, user1, false); |
| 549 | + assertNotNull(level1Component); |
| 550 | + |
| 551 | + //Check the BulkOperationNode status |
| 552 | + //Object[0] : NodeType, Object[1] : ResultState |
| 553 | + Map<String, Object[]> expectedResults = new HashMap<String, Object[]>(); |
| 554 | + expectedResults.put(releaseIdList.get(0), new Object[]{BulkOperationNodeType.RELEASE, BulkOperationResultState.EXCLUDED}); |
| 555 | + expectedResults.put(releaseIdList.get(1), new Object[]{BulkOperationNodeType.RELEASE, BulkOperationResultState.EXCLUDED}); |
| 556 | + expectedResults.put(releaseIdList.get(2), new Object[]{BulkOperationNodeType.RELEASE, BulkOperationResultState.EXCLUDED}); |
| 557 | + expectedResults.put(componentIdList.get(0), new Object[]{BulkOperationNodeType.COMPONENT, BulkOperationResultState.EXCLUDED}); |
| 558 | + expectedResults.put(componentIdList.get(1), new Object[]{BulkOperationNodeType.COMPONENT, BulkOperationResultState.EXCLUDED}); |
| 559 | + expectedResults.put(componentIdList.get(2), new Object[]{BulkOperationNodeType.COMPONENT, BulkOperationResultState.EXCLUDED}); |
| 560 | + checkBulkOperationNode(level1Component, expectedResults); |
| 561 | + |
| 562 | + //Releases to be undeleted |
| 563 | + for (String releaseId : releaseIdList) { |
| 564 | + assertTrue(this.releaseExists(releaseId)); |
| 565 | + } |
| 566 | + |
| 567 | + //Release links to be undeleted |
| 568 | + Release release0 = databaseConnector.get(Release.class, releaseIdList.get(0)); |
| 569 | + assertEquals(1, release0.getReleaseIdToRelationshipSize()); |
| 570 | + Release release1 = databaseConnector.get(Release.class, releaseIdList.get(1)); |
| 571 | + assertEquals(1, release1.getReleaseIdToRelationshipSize()); |
| 572 | + Release release2 = databaseConnector.get(Release.class, releaseIdList.get(2)); |
| 573 | + assertEquals(0, release2.getReleaseIdToRelationshipSize()); |
| 574 | + |
| 575 | + //Components and links to be undeleted |
| 576 | + for (String componentId : componentIdList) { |
| 577 | + assertTrue(this.componentExists(componentId)); |
| 578 | + Component component = databaseConnector.get(Component.class, componentId); |
| 579 | + assertEquals(1, component.getReleaseIdsSize()); |
| 580 | + } |
| 581 | + } |
| 582 | + |
520 | 583 | @Test |
521 | 584 | public void testDeleteBulkRelease_ConflictError001() throws Exception { |
522 | 585 | if (!isFeatureEnable()) { |
523 | | - System.out.println("BulkReleaseDeletion is disabled. these test is Skipped."); |
| 586 | + log.warn("BulkReleaseDeletion is disabled. these test is Skipped."); |
524 | 587 | return; |
525 | 588 | } |
526 | 589 |
|
@@ -743,7 +806,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List<Release> deletedRe |
743 | 806 | @Test |
744 | 807 | public void testDeleteBulkRelease_ConflictError002() throws Exception { |
745 | 808 | if (!isFeatureEnable()) { |
746 | | - System.out.println("BulkReleaseDeletion is disabled. these test is Skipped."); |
| 809 | + log.warn("BulkReleaseDeletion is disabled. these test is Skipped."); |
747 | 810 | return; |
748 | 811 | } |
749 | 812 |
|
@@ -931,7 +994,7 @@ public void checkDeletedReleaseListInLoop(int loopCount, List<Release> deletedRe |
931 | 994 | @Test |
932 | 995 | public void testDeleteBulkRelease_ConflictError003() throws Exception { |
933 | 996 | if (!isFeatureEnable()) { |
934 | | - System.out.println("BulkReleaseDeletion is disabled. these test is Skipped."); |
| 997 | + log.warn("BulkReleaseDeletion is disabled. these test is Skipped."); |
935 | 998 | return; |
936 | 999 | } |
937 | 1000 |
|
|
0 commit comments