@Test public void collectItemScenarios_should_recursively_call_and_correctly_set_request_name_and_severity() { final Request request = new Request(); ItemWithScripts[] items = new ItemWithScripts[] { new ItemWithScripts() .withName("root") .withChildren(new ItemWithScripts[] { new ItemWithScripts() .withName("folder") .withSubFolder(true) .withEvents(new Event[] { new Event() .withListen(Listen.TEST) .withScript(new Script() .withExec(new String[] { "pm.test('Folder assertion')" }) ) }) .withChildren(new ItemWithScripts[] { new ItemWithScripts() .withName("request") .withRequest(request) .withEvents(new Event[] { new Event() .withListen(Listen.TEST) .withScript(new Script() .withExec(new String[] { "pm.test('Item assertion')" }) ) }) }) }) }; Source source = new Source(); AtomicInteger requestPosition = new AtomicInteger(5); doReturn("severity").when(postmanService).getSeverity(eq("root")); doReturn("folder-severity").when(postmanService).getSeverity(eq("root-without-severity"), eq("folder")); doReturn("").when(postmanService).getSeverity(eq("root-without-severity"), eq("folder-without-severity"), eq("request")); doReturn("root-without-severity").when(postmanService).removeSeverityTag(eq("root")); doReturn("folder-without-severity").when(postmanService).removeSeverityTag(eq("folder")); doReturn("request-without-severity").when(postmanService).removeSeverityTag(eq("request")); final Assertion[] expectedJoinedAssertions = { new Assertion().withName("Item assertion"), new Assertion().withName("Folder assertion") }; doReturn("content").when(postmanService) .buildScenarioContent(request, null, expectedJoinedAssertions, null, true); List<Scenario> scenarios = cut.collectItemScenarios(items, source, requestPosition, null, Collections.emptyList()); assertThat(scenarios).hasSize(1); assertThat(scenarios.get(0).getSource()).isSameAs(source); assertThat(scenarios.get(0).getSeverity()).isEqualTo("folder-severity"); assertThat(scenarios.get(0).getName()) .isEqualTo("root-without-severity \u25b6 folder-without-severity \u25b6 request-without-severity"); assertThat(scenarios.get(0).getLine()).isEqualTo(6); assertThat(scenarios.get(0).getContent()).isEqualTo("content"); }
List<Scenario> collectItemScenarios(ItemWithScripts[] items, Source source, AtomicInteger requestPosition, String parentSeverity, List<Assertion> parentAssertions, String... parentFolders) { List<Scenario> scenarios = new ArrayList<>(); if (items != null) { for (ItemWithScripts item : items) { boolean isRootFolder = (parentFolders.length == 0); boolean isFolder = isRootFolder || item.isSubFolder(); String severity = postmanService.getSeverity(ArrayUtils.addAll(parentFolders, item.getName())); if (StringUtils.isEmpty(severity)) { severity = parentSeverity; } String nameWithoutTag = postmanService.removeSeverityTag(item.getName()); String[] path = ArrayUtils.addAll(parentFolders, nameWithoutTag); List<Assertion> assertions = ListUtils.union(extractAssertions(item), parentAssertions); if (isFolder) { scenarios.addAll(collectItemScenarios(item.getChildren(), source, requestPosition, severity, assertions, path)); } else { scenarios.add(toScenario(item, source, requestPosition, severity, assertions, path)); } } } return scenarios; }
PostmanScenarioIndexerService { List<Scenario> collectItemScenarios(ItemWithScripts[] items, Source source, AtomicInteger requestPosition, String parentSeverity, List<Assertion> parentAssertions, String... parentFolders) { List<Scenario> scenarios = new ArrayList<>(); if (items != null) { for (ItemWithScripts item : items) { boolean isRootFolder = (parentFolders.length == 0); boolean isFolder = isRootFolder || item.isSubFolder(); String severity = postmanService.getSeverity(ArrayUtils.addAll(parentFolders, item.getName())); if (StringUtils.isEmpty(severity)) { severity = parentSeverity; } String nameWithoutTag = postmanService.removeSeverityTag(item.getName()); String[] path = ArrayUtils.addAll(parentFolders, nameWithoutTag); List<Assertion> assertions = ListUtils.union(extractAssertions(item), parentAssertions); if (isFolder) { scenarios.addAll(collectItemScenarios(item.getChildren(), source, requestPosition, severity, assertions, path)); } else { scenarios.add(toScenario(item, source, requestPosition, severity, assertions, path)); } } } return scenarios; } }
PostmanScenarioIndexerService { List<Scenario> collectItemScenarios(ItemWithScripts[] items, Source source, AtomicInteger requestPosition, String parentSeverity, List<Assertion> parentAssertions, String... parentFolders) { List<Scenario> scenarios = new ArrayList<>(); if (items != null) { for (ItemWithScripts item : items) { boolean isRootFolder = (parentFolders.length == 0); boolean isFolder = isRootFolder || item.isSubFolder(); String severity = postmanService.getSeverity(ArrayUtils.addAll(parentFolders, item.getName())); if (StringUtils.isEmpty(severity)) { severity = parentSeverity; } String nameWithoutTag = postmanService.removeSeverityTag(item.getName()); String[] path = ArrayUtils.addAll(parentFolders, nameWithoutTag); List<Assertion> assertions = ListUtils.union(extractAssertions(item), parentAssertions); if (isFolder) { scenarios.addAll(collectItemScenarios(item.getChildren(), source, requestPosition, severity, assertions, path)); } else { scenarios.add(toScenario(item, source, requestPosition, severity, assertions, path)); } } } return scenarios; }  }
PostmanScenarioIndexerService { List<Scenario> collectItemScenarios(ItemWithScripts[] items, Source source, AtomicInteger requestPosition, String parentSeverity, List<Assertion> parentAssertions, String... parentFolders) { List<Scenario> scenarios = new ArrayList<>(); if (items != null) { for (ItemWithScripts item : items) { boolean isRootFolder = (parentFolders.length == 0); boolean isFolder = isRootFolder || item.isSubFolder(); String severity = postmanService.getSeverity(ArrayUtils.addAll(parentFolders, item.getName())); if (StringUtils.isEmpty(severity)) { severity = parentSeverity; } String nameWithoutTag = postmanService.removeSeverityTag(item.getName()); String[] path = ArrayUtils.addAll(parentFolders, nameWithoutTag); List<Assertion> assertions = ListUtils.union(extractAssertions(item), parentAssertions); if (isFolder) { scenarios.addAll(collectItemScenarios(item.getChildren(), source, requestPosition, severity, assertions, path)); } else { scenarios.add(toScenario(item, source, requestPosition, severity, assertions, path)); } } } return scenarios; }  List<Scenario> extractScenarios(Source source, File zipFile); }
PostmanScenarioIndexerService { List<Scenario> collectItemScenarios(ItemWithScripts[] items, Source source, AtomicInteger requestPosition, String parentSeverity, List<Assertion> parentAssertions, String... parentFolders) { List<Scenario> scenarios = new ArrayList<>(); if (items != null) { for (ItemWithScripts item : items) { boolean isRootFolder = (parentFolders.length == 0); boolean isFolder = isRootFolder || item.isSubFolder(); String severity = postmanService.getSeverity(ArrayUtils.addAll(parentFolders, item.getName())); if (StringUtils.isEmpty(severity)) { severity = parentSeverity; } String nameWithoutTag = postmanService.removeSeverityTag(item.getName()); String[] path = ArrayUtils.addAll(parentFolders, nameWithoutTag); List<Assertion> assertions = ListUtils.union(extractAssertions(item), parentAssertions); if (isFolder) { scenarios.addAll(collectItemScenarios(item.getChildren(), source, requestPosition, severity, assertions, path)); } else { scenarios.add(toScenario(item, source, requestPosition, severity, assertions, path)); } } } return scenarios; }  List<Scenario> extractScenarios(Source source, File zipFile);  }