|
| 1 | +package com.aventstack.extentreports.model.context; |
| 2 | + |
| 3 | +import java.util.Set; |
| 4 | +import java.util.stream.IntStream; |
| 5 | + |
| 6 | +import org.testng.Assert; |
| 7 | +import org.testng.annotations.BeforeMethod; |
| 8 | +import org.testng.annotations.Test; |
| 9 | + |
| 10 | +import com.aventstack.extentreports.ExtentReports; |
| 11 | +import com.aventstack.extentreports.model.Author; |
| 12 | +import com.aventstack.extentreports.model.Category; |
| 13 | +import com.aventstack.extentreports.model.Device; |
| 14 | +import com.aventstack.extentreports.model.NamedAttribute; |
| 15 | + |
| 16 | +public class NamedAttributeContextManagerTest { |
| 17 | + |
| 18 | + private final String[] tags = new String[] { "tag1", "tag2", "tag3", "tag4" }; |
| 19 | + |
| 20 | + private ExtentReports _extent; |
| 21 | + |
| 22 | + @BeforeMethod |
| 23 | + public void beforeMethod() { |
| 24 | + _extent = new ExtentReports(); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * This test checks if the context only tracks tag uniqueness across N number of |
| 29 | + * tests |
| 30 | + * |
| 31 | + * Issue details: |
| 32 | + * https://github.com/extent-framework/extentreports-java/issues/282 |
| 33 | + */ |
| 34 | + @Test |
| 35 | + public void concurrentlyAssignedTags() { |
| 36 | + IntStream.range(1, 100).parallel().forEach(x -> { |
| 37 | + _extent.createTest("Test" + x).assignCategory(tags).pass(""); |
| 38 | + }); |
| 39 | + final Set<NamedAttributeContext<Category>> set = _extent.getReport().getCategoryCtx().getSet(); |
| 40 | + verifyContentAssert(set); |
| 41 | + } |
| 42 | + |
| 43 | + private <T extends NamedAttribute> void verifyContentAssert(final Set<NamedAttributeContext<T>> set) { |
| 44 | + final String[] runtimeTags = set.stream().map(x -> x.getAttr().getName()).toArray(String[]::new); |
| 45 | + Assert.assertEqualsNoOrder(tags, runtimeTags); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void concurrentlyAssignedUsers() { |
| 50 | + IntStream.range(1, 100).parallel().forEach(x -> { |
| 51 | + _extent.createTest("Test" + x).assignAuthor(tags).pass(""); |
| 52 | + }); |
| 53 | + final Set<NamedAttributeContext<Author>> set = _extent.getReport().getAuthorCtx().getSet(); |
| 54 | + verifyContentAssert(set); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void concurrentlyAssignedDevices() { |
| 59 | + IntStream.range(1, 100).parallel().forEach(x -> { |
| 60 | + _extent.createTest("Test" + x).assignDevice(tags).pass(""); |
| 61 | + }); |
| 62 | + final Set<NamedAttributeContext<Device>> set = _extent.getReport().getDeviceCtx().getSet(); |
| 63 | + verifyContentAssert(set); |
| 64 | + } |
| 65 | +} |
0 commit comments