Triggering Class Which Extends PTransforms one After One? - java

I have 2 classes which extend PTransform, called CompositeCall2 and CompositeCall.
I have to call CompositeCall first and then, after completion of the work done in CompositeCall, I have to call CompositeCall2 in my dataflow program. I am making template of my dataflow job so parallel processing is going on which makes my work difficult.
Code.:Tester.java
package Testing2;
import java.util.List;
import org.apache.beam.runners.dataflow.DataflowRunner;
import org.apache.beam.runners.dataflow.options.DataflowPipelineOptions;
import org.apache.beam.runners.direct.DirectRunner;
import org.apache.beam.sdk.Pipeline;
import org.apache.beam.sdk.io.TextIO;
import org.apache.beam.sdk.options.Description;
import org.apache.beam.sdk.options.PipelineOptions;
import org.apache.beam.sdk.options.PipelineOptionsFactory;
import org.apache.beam.sdk.options.Validation;
import org.apache.beam.sdk.options.ValueProvider;
import org.apache.beam.sdk.transforms.Create;
import org.apache.beam.sdk.transforms.View;
import org.apache.beam.sdk.values.PCollection;
import org.apache.beam.sdk.values.PCollectionView;
import org.apache.beam.sdk.values.PDone;
import com.google.api.services.bigquery.model.TableRow;
public class Tester {
public interface FileData extends PipelineOptions {
#Description("name Of the File")
#Validation.Required
ValueProvider<String> getInputFile();
void setInputFile(ValueProvider<String> value);
#Description("Path Of File From Where We need To Read Data")
#Validation.Required
ValueProvider<String> getOutputFile();
void setOutputFile(ValueProvider<String> value);
}
public static void main(String[] args) throws InterruptedException {
DataflowPipelineOptions options=PipelineOptionsFactory.as(DataflowPipelineOptions.class);
options.setProject("testing1-180111");
options.setTempLocation("gs://kishan-bucket/staging");
options.setTemplateLocation("gs://kiss-bucket/templates/Test1");
options.setRunner(DataflowRunner.class);
Pipeline p = Pipeline.create(options);
PDone dta = p.begin().apply("Creating File",Create.of("Kishan")).apply(new CompositeCall(p));
p.apply("Creating File",Create.of("Kishan")).apply(new CompositeCall2(p));
p.run().waitUntilFinish();
}
}
This is the way I am calling.
Both classes are doing the same work, just printing data in a file and writing that data.
package Testing2;
import java.util.List;
import org.apache.beam.sdk.Pipeline;
import org.apache.beam.sdk.io.TextIO;
import org.apache.beam.sdk.transforms.DoFn;
import org.apache.beam.sdk.transforms.PTransform;
import org.apache.beam.sdk.transforms.ParDo;
import org.apache.beam.sdk.values.PCollection;
import org.apache.beam.sdk.values.PCollectionView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CompositeCall2 extends PTransform <PCollection<String>,PCollection<String>> {
private static final long serialVersionUID = 1L;
static Pipeline p;
public CompositeCall2(Pipeline p1) {
this.p = p1;
}
private static final Logger LOG = LoggerFactory.getLogger(CompositeCall2.class);
#Override
public PCollection<String> expand(PCollection<String> input) {
PCollection<String> data;
input.apply(ParDo.of(new testing())).apply(TextIO.write().to("gs://kiss-bucket/test1.txt"));
LOG.info("Enter Second Stage Called");
return input;
}
static class testing extends DoFn<String,String>{
#ProcessElement
public void processElement(ProcessContext c) throws InterruptedException{
LOG.info("Enter Second Stage");
c.output("Data Is"+c.element());
}
}
}
How can I synchronize the flow so that after one transformation another transform runs?

This a bit old but I came across it today and thought I might share for others that are having a similar issue - there is a Wait.on transform allows you to wait for a prior transform to complete before applying a later operation.

Related

Error: While resolving module, the Haste package was found. the module could not be found within the package

I am trying the new arch of react native. I have enabled it in my gradle.properties file. This error is for android only and I have not tried iOS yet.
I am following the exact sample of Calculator mentioned over here.
I get an error saying
error: Error: While resolving module `rtn-calculator/js/NativeCalculator.js`, the Haste package `rtn-calculator` was found. However the module `js/NativeCalculator.js` could not be found within the package. Indeed, none of these files exist:
* `/Users/transformhub/Desktop/rnapp/RTNCalculator/js/NativeCalculator.js(.native|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`
* `/Users/transformhub/Desktop/rnapp/RTNCalculator/js/NativeCalculator.js/index(.native|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`
at resolveHasteName (/Users/transformhub/Desktop/rnapp/node_modules/metro-resolver/src/resolve.js:173:9)
at Object.resolve (/Users/transformhub/Desktop/rnapp/node_modules/metro-resolver/src/resolve.js:63:20)
at ModuleResolver.resolveDependency (/Users/transformhub/Desktop/rnapp/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:111:31)
at DependencyGraph.resolveDependency (/Users/transformhub/Desktop/rnapp/node_modules/metro/src/node-haste/DependencyGraph.js:260:43)
at Object.resolve (/Users/transformhub/Desktop/rnapp/node_modules/metro/src/lib/transformHelpers.js:177:21)
at Graph._resolveDependencies (/Users/transformhub/Desktop/rnapp/node_modules/metro/src/DeltaBundler/Graph.js:432:35)
at Graph._processModule (/Users/transformhub/Desktop/rnapp/node_modules/metro/src/DeltaBundler/Graph.js:218:38)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Graph._addDependency (/Users/transformhub/Desktop/rnapp/node_modules/metro/src/DeltaBundler/Graph.js:314:20)
at async Promise.all (index 2)
The complete repo is here
Below is sample code
NativeCalculator.ts
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
import {TurboModuleRegistry} from 'react-native';
export interface Spec extends TurboModule {
add(a: number, b: number): Promise<number>;
}
export default TurboModuleRegistry.get<Spec>('RTNCalculator') as Spec | null;
package com.rtncalculator;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.model.ReactModuleInfo;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.facebook.react.TurboReactPackage;
import java.util.Collections;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
public class CalculatorPackage extends TurboReactPackage {
#Nullable
#Override
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
if (name.equals(CalculatorModule.NAME)) {
return new CalculatorModule(reactContext);
} else {
return null;
}
}
#Override
public ReactModuleInfoProvider getReactModuleInfoProvider() {
return () -> {
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
moduleInfos.put(
CalculatorModule.NAME,
new ReactModuleInfo(
CalculatorModule.NAME,
CalculatorModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
true // isTurboModule
));
return moduleInfos;
};
}
}
package com.rtncalculator;
import androidx.annotation.NonNull;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import java.util.Map;
import java.util.HashMap;
import com.rtncalculator.NativeCalculatorSpec;
public class CalculatorModule extends NativeCalculatorSpec {
public static String NAME = "RTNCalculator";
CalculatorModule(ReactApplicationContext context) {
super(context);
}
#Override
#NonNull
public String getName() {
return NAME;
}
#Override
public void add(double a, double b, Promise promise) {
promise.resolve(a + b);
}
}
This is a react native issue introduced in 0.70 and was resolved in 0.71. Check here for more details

PowerMock #PrepareForTest throws exception for a class containing a sorted call [JAVA 8]

I have a class(TempClass) containing a map that uses a static method of another class(UtilClass) to generate a list using this map.
For mocking the static method(can't avoid using the static method), I'm using Powermockito. However, I'm getting this exception when I try to run the test.
javassist version used: 3.18.1-GA
java.lang.IllegalStateException: Failed to transform class with name fk.retail.ip.nodes.compute.iwit.utils.temp.UtilClass. Reason: javassist.bytecode.InterfaceMethodrefInfo cannot be cast to javassist.bytecode.MethodrefInfo
it disappears when I remove a sorted call from the static method
I know it can be resolved by dependency changes mentioned here. But I don't want to change the dependency. My question is more around why is this happening?
This is a simplified example of a code that I'm using.
TempClass.java
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;
public class TempClass {
public void execute(){
List<Integer> integerList1 = Lists.newArrayList();
List<Integer> integerList2 = Lists.newArrayList();
integerList1.add(10);
integerList1.add(1);
integerList1.add(4);
integerList2.add(10);
integerList2.add(20);
integerList2.add(30);
Map<String, List<Integer>> stringListMap = Maps.newHashMap();
stringListMap.put("AA", integerList1);
stringListMap.put("AB", integerList2);
List<Integer> sortedList = UtilClass.getSomeList(stringListMap);
}
}
UtilClass.java
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class UtilClass {
public static List<Integer> getSomeList(Map<String, List<Integer>> inputs) {
return inputs.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.map(Map.Entry::getValue)
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
}
TempClassTest.java
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
#RunWith(PowerMockRunner.class)
#PrepareForTest({
UtilClass.class
})
public class TempClassTest {
#Test
public void dummy(){
Assert.assertEquals(1, 1);
}
}
The exception disappears and the test runs fine when I remove the sorted call from the method.
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class UtilClass {
public static List<Integer> getSomeList(Map<String, List<Integer>> inputs) {
return inputs.entrySet().stream()
.map(Map.Entry::getValue)
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
}

Integration testing for events in the Jersey container listener

I have an application based on Jersey JAX-RS. I need to refactor the event handler and therefore also write a test for it.
I'm trying to do this with the JerseyTest Framework. I created a configuration to extend ResourceConfig, but when I use the target () call the handler is not called.
I will present the situation using code.
Here is an example Resource class:
package com.my.page;
import org.glassfish.hk2.api.messaging.Topic;
import com.my.core.entity.Link;
import com.my.core.location.LinkHitLocationFactory;
import com.my.core.service.LinkService;
import com.my.core.service.link.LinkFinder;
import com.my.core.service.link.LinkFinderFactory;
import com.my.event.LinkHitEvent;
import com.my.exception.FragmentNotFoundException;
import javax.annotation.security.PermitAll;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
#PermitAll
#Path("/")
public class LinkResource {
#Inject
private LinkService linkService;
#Inject
private Topic<LinkHitEvent> linkHitPublisher;
#Inject
private LinkFinderFactory linkFinderFactory;
#Inject
private LinkHitLocationFactory linkHitLocationFactory;
#GET
#Path("/{fragment:[^ ]{1,32}}")
public Response redirect(
#PathParam("fragment") String fragment,
#HeaderParam("Range") String range,
#HeaderParam("User-Agent") String userAgent,
#Context HttpHeaders headers) throws Exception {
LinkFinder linkFinder = linkFinderFactory.getLinkFinder(fragment);
Link link = linkFinder.getLink(fragment);
if (link.isExpired()) {
throw new FragmentNotFoundException(fragment);
}
linkService.insertHit();
linkHitPublisher.publish(new LinkHitEvent(link));
return handlerFactory.getHandler(link).handleGet(link, range).build();
}
}
Event test:
package com.my.page;
import org.glassfish.hk2.extras.events.internal.TopicDistributionModule;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import pl.comvision.hk2.events.ThreadedEventDistributorService;
import com.my.client.CallbackTargetBuilder;
import com.my.core.entity.Link;
import com.my.core.mapper.LinkMapper;
import com.my.core.service.LinkService;
import com.my.page.resource.LinkResource;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Response;
import static javax.ws.rs.core.Response.Status.TEMPORARY_REDIRECT;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
#RunWith(MockitoJUnitRunner.class)
public class CallbackEventTest extends JerseyTest {
#Mock
private LinkMapper linkMapper;
#Mock
private LinkService linkService;
private CallbackTargetBuilder callbackTargetBuilder;
private final String callbackUrl = "";
#Override
protected Application configure() {
this.callbackTargetBuilder = spy(new CallbackTargetBuilder(this.callbackUrl));
ResourceConfig config = new ResourceConfig(LinkResource.class);
config.register(new TopicDistributionModule());
config.register(new AbstractBinder() {
#Override
protected void configure() {
addActiveDescriptor(ThreadedEventDistributorService.class).setRanking(100);
}
});
config.register(new EventsContainerListener(CallbackEventHandler.class));
config.register(new AbstractBinder() {
#Override
protected void configure() {
bind(linkMapper).to(LinkMapper.class);
bind(linkService).to(LinkService.class);
bind(mock(LinkService.class)).to(LinkService.class);
bind("").to(String.class).named("varPath");
bind("127.0.0.1").to(String.class).named("requestIP");
bind(callbackTargetBuilder).to(CallbackTargetBuilder.class);
}
});
return config;
}
#Test
public void publish_event() {
Link link = mock(Link.class);
when(link.getUrl()).thenReturn("example");
when(link.getName()).thenReturn("test");
when(linkMapper.getByName(anyString())).thenReturn(link);
Response response = target("/testY").property("jersey.config.client.followRedirects", false).request().get();
assertEquals(TEMPORARY_REDIRECT.getStatusCode(), response.getStatus());
verify(callbackTargetBuilder).build();
}
}
For testing purposes, I only injected callbackTargetBuilder into the handler, and called the build method on it to verify the call:
package com.my.page;
import org.glassfish.hk2.api.messaging.MessageReceiver;
import org.glassfish.hk2.api.messaging.SubscribeTo;
import org.jvnet.hk2.annotations.Service;
import com.my.client.CallbackTargetBuilder;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
#Service
#Singleton
#MessageReceiver
public class CallbackEventHandler {
#Named("callbackUrl")
private String url;
#Inject
private CallbackTargetBuilder callbackTargetBuilder;
#MessageReceiver
public void handle(#SubscribeTo LinkHitEvent event) {
Form form = new Form();
form.param("id", event.getLink().getId().toString());
form.param("name", event.getLink().getName());
callbackTargetBuilder.build();
Client client = ClientBuilder.newClient();
client.target(url).request().post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
}
}
Edit:
I tried to register dependencies differently, but it does not bring satisfactory results. Each time verification fails:
verify (callbackTargetBuilder) .build ();
Looking for information I found that I can configure the DeploymentContext, but I don't know if this is the right direction.
Edit the second:
A quick test shows that I may have some more basic problem with mocking. Because the call:
verify (linkService) .insertHit (anyObject ());
It also fails.
I will write only for posterity that the above code is correct. The problem was a lot of small bugs in the tested code and how to mock it.

Stubbing static methods in Mockito 2 throws InvalidUseOfMatchersException

I have a class where I'm using Powermock + Mockito to suppress a static method in a utility class. It works fine with Powermock 1.6.2 and Mockito 1.10.19, but I've been tasked with moving to Java 10 (JRE: we're still compiling with Java 8) and so I've moved to Powermock 2 (currently in beta) and Mockito 2.16.1. Now, I consistently get org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Misplaced or misused argument matcher detected here.
A simple example, MyMockito.java:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.lang.reflect.Method;
import static org.mockito.Mockito.any;
import static org.powermock.api.mockito.PowerMockito.spy;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.powermock.api.support.membermodification.MemberMatcher.method;
import static org.powermock.api.support.membermodification.MemberModifier.suppress;
#RunWith(PowerMockRunner.class)
#PrepareForTest(StringMeasurer.class)
public class MyMockito {
#Test
public void testSuppressMethod() throws Exception {
spy(StringMeasurer.class);
Method measure = method(StringMeasurer.class, "measure", String.class);
suppress(measure);
when(StringMeasurer.class, measure)
.withArguments(any(String.class))
.thenReturn(10);
System.out.println(StringMeasurer.measure("Hello"));
}
And StringMeasurer.java:
public class StringMeasurer {
private StringMeasurer() {}
public static int measure(String s) {
return s.length();
}
}
}
I'm assuming that either there have been some changes to how matchers can be used to match arguments in stubbed static methods, or else this should never have worked and somehow got through in Mockito 2 (or possibly this is a bug in the Powermock beta). Can anyone provide me some insight into what I'm doing wrong?
Working solution for PowerMock 2.0.0-beta.5:
import static org.mockito.ArgumentMatchers.any;
import static org.powermock.api.mockito.PowerMockito.when;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
#RunWith(PowerMockRunner.class)
#PrepareForTest(StringMeasurer.class)
public class MyMockito {
#Test
public void testSuppressMethod() throws Exception {
PowerMockito.mockStatic(StringMeasurer.class);
when(StringMeasurer.measure(any(String.class))).thenReturn(10);
System.out.println(StringMeasurer.measure("Hello"));
}
}
More details can be found in the official PowerMock documentation: Mocking Static Method
The question uses the PowerMockito.spy() method, which is required for partial mocking, although the example given only has one static method, so that's not necessary here. Here's a working solution that uses partial mocking for an extended example:
MyMockito.java:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.lang.reflect.Method;
import java.util.List;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Mockito.*;
import static org.powermock.api.support.membermodification.MemberMatcher.method;
import static org.powermock.api.mockito.PowerMockito.doReturn;
import static org.powermock.api.mockito.PowerMockito.spy;
#RunWith(PowerMockRunner.class)
#PrepareForTest(StringMeasurer.class)
public class MyMockito {
#Test
public void testSuppressMethod() throws Exception {
spy(StringMeasurer.class);
Method measure = method(StringMeasurer.class, "measure", String.class);
doReturn(10).when(StringMeasurer.class, measure)
.withArguments(any(String.class));
System.out.println(StringMeasurer.measure("Hello"));
List<String> dummy = StringMeasurer.dummy(5);
assertEquals(5, dummy.size());
dummy.forEach(System.out::println);
}
}
And StringMeasurer.java:
import java.util.ArrayList;
import java.util.List;
public class StringMeasurer {
private StringMeasurer() {}
public static int measure(String s) {
return s.length();
}
public static List<String> dummy(int size) {
List<String> list = new ArrayList<>();
for (int i = 0; i < size; i++) {
list.add("" + i);
}
return list;
}
}
Note that, in this case, the accepted solution would mock the StringMeasurer.dummy() method as well, returning an empty list, and the test would fail on the assertEquals().

java TestNG calling methods with #Parameters inside #DataProvider

I'm trying to get data using #DataProvider, which returns Object[][], in which I'm pasting value by calling another method. This method, in its turn, using #Parameters to get value from XML.
The problem is that I'm getting NullPointerException, because in #DataProvider calling required method with #Parameters by passing value null, hoping that #Parameters will change this value to appropriate one from XML.
At the same time, I cannot call method by not passing any arguments to it.
Code:
Class TestSuite
package blablabla.mainPackage;
import blablabla.framework.*;
import java.io.IOException;
import java.util.ArrayList;
import org.testng.annotations.Test;
public class TestSuite extends Config {
FilesOperations fOps = new FilesOperations();
List<String> fileNames = new ArrayList<String>();
#Test(groups = {"positive"},
dataProvider = "getRandomFileName",
priority = 1)
public void createFileRandom(String fileName) throws IOException {
fOps.createFile(fileName, tempPath);
fileNames.add(fileName);
}
}
Class Config
package blablabla.mainPackage;
import blablabla.framework.*;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;
public class Config extends DataProviders{
public static Path tempPath;
DirectoriesOperations dirOps = new DirectoriesOperations();
#BeforeSuite(alwaysRun = true)
#Parameters({"path"})
public void tearUp(String path) throws IOException {
tempPath = dirOps.createTempDir(Paths.get(path));
}
#AfterSuite(alwaysRun = true, enabled = true)
public void tearDown() throws IOException {
dirOps.deleteTempDirOnExit(tempPath);
}
}
Class DataProviders
package blablabla.framework;
import java.io.IOException;
import org.testng.annotations.DataProvider;
public class DataProviders {
FilesOperations fOps = new FilesOperations();
HelpFunctions hf = new HelpFunctions();
ParametrizedFunctions pf = new ParametrizedFunctions();
#DataProvider(name = "getRandomFileName")
public Object[][] getRandomFileName() {
return new Object[][]{new Object[]{pf.generateRandomFileNameWithExtension(null)}};
}
}
Class ParametrizedFunctions
package blablabla.framework;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.testng.annotations.Parameters;
public class ParametrizedFunctions {
FilesOperations fOps = new FilesOperations();
HelpFunctions hf = new HelpFunctions();
#Parameters({"extensionsArray"})
public String generateRandomFileNameWithExtension(String extensionsArray) {
return fOps.getFileName(hf.stringToArray(extensionsArray), null);
}
}
Here, #Parameters({"extensionsArray"}) does't provide a value from XML file. It just takes null, that was passed as an argument for calling method generateRandomFileNameWithExtension(). And, at the same time, I cannot call this method from #DataProvider without passing any argument to method called.
Hope for your suggestions.
I found the solution. The best way to pass parameter from XML into #DataProvider is passing ITestContext context as the argument to the #DataProvider method, and then, get required parameter using:
context.getCurrentXmlTest().getParameter("parameterName");
Full code of #DataProvider:
#DataProvider(name = "getRandomFileName")
public Object[][] getRandomFileName(ITestContext context) {
String extensionsArray = context.getCurrentXmlTest().getParameter("extensionsArray");
return new Object[][]{new Object[]{pf.generateRandomFileNameWithExtension(extensionsArray)}};
}
Thanks all for your suggestions.

Categories

Resources