-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add runtime Launch attributes update example
- Loading branch information
Showing
5 changed files
with
60 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...a/com/epam/reportportal/example/testng/logback/extension/RuntimeLaunchAttributesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.epam.reportportal.example.testng.logback.extension; | ||
|
||
import com.epam.reportportal.listeners.ListenerParameters; | ||
import com.epam.reportportal.service.ReportPortal; | ||
import com.epam.reportportal.testng.BaseTestNGListener; | ||
import com.epam.reportportal.testng.ITestNGService; | ||
import com.epam.reportportal.testng.TestNGService; | ||
import com.epam.reportportal.utils.MemoizingSupplier; | ||
import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; | ||
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.function.Supplier; | ||
|
||
import static java.util.Optional.ofNullable; | ||
|
||
/** | ||
* Test class to demonstrate how to add runtime attributes to a Launch. | ||
*/ | ||
@Listeners({ RuntimeLaunchAttributesTest.ExtendedListener.class }) | ||
public class RuntimeLaunchAttributesTest { | ||
private static final Set<ItemAttributesRQ> RUNTIME_ATTRIBUTES = Collections.newSetFromMap(new ConcurrentHashMap<>()); | ||
|
||
@Test | ||
public void testRuntimeLaunchAttributes() { | ||
System.out.println("Test stub to demonstrate runtime launch attributes."); | ||
// Add runtime attributes | ||
RUNTIME_ATTRIBUTES.add(new ItemAttributesRQ("runtime1", "value1")); | ||
} | ||
|
||
public static class ExtendedListener extends BaseTestNGListener { | ||
public static final Supplier<ITestNGService> SERVICE = new MemoizingSupplier<>(() -> new TestNGService(ReportPortal.builder() | ||
.build()) { | ||
@Override | ||
protected FinishExecutionRQ buildFinishLaunchRq(ListenerParameters parameters) { | ||
FinishExecutionRQ rq = super.buildFinishLaunchRq(parameters); | ||
Set<ItemAttributesRQ> attributes = ofNullable(rq.getAttributes()).orElseGet(HashSet::new); | ||
attributes.addAll(RUNTIME_ATTRIBUTES); | ||
rq.setAttributes(attributes); | ||
return rq; | ||
} | ||
}); | ||
|
||
public ExtendedListener() { | ||
super(SERVICE.get()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters