Java Code Examples for org.testng.annotations.Factory

The following are top voted examples for showing how to use org.testng.annotations.Factory. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: test-data-supplier   File: DataSupplierMetaData.java   View source code 6 votes vote down vote up
private Tuple2<Class<?>, String> getFactoryAnnotationMetaData() {
    val constructor = testMethod.getConstructorOrMethod().getConstructor();
    val method = testMethod.getConstructorOrMethod().getMethod();

    val factoryAnnotation = nonNull(method)
            ? ofNullable(method.getDeclaredAnnotation(Factory.class))
            : ofNullable(constructor.getDeclaredAnnotation(Factory.class));

    val dataProviderClass = factoryAnnotation
            .map(fa -> (Class) fa.dataProviderClass())
            .filter(cl -> cl != Object.class)
            .orElseGet(() -> testMethod.getConstructorOrMethod().getDeclaringClass());

    val dataProviderMethod = factoryAnnotation.map(Factory::dataProvider).orElse("");

    return Tuple.of(dataProviderClass, dataProviderMethod);
}
 
Example 2
Project: qaf   File: ScenarioFactory.java   View source code 6 votes vote down vote up
@Factory
public Object[] getTestsFromFile(ITestContext context) {

	if (null != context) {
		includeGroups = Arrays.asList(context.getIncludedGroups());
		excludeGroups = Arrays.asList(context.getExcludedGroups());
	}

	String sanariosloc = MetaDataScanner.getParameter(context, "scenario.file.loc");
	if (StringUtil.isNotBlank(sanariosloc)) {
		ConfigurationManager.getBundle().setProperty("scenario.file.loc", sanariosloc);
	}

	System.out.printf("include groups %s\n exclude groups: %s Scanarios location: %s \n", includeGroups,
			excludeGroups, sanariosloc);
	logger.info("scenario.file.loc"
			+ ConfigurationManager.getBundle().getStringArray("scenario.file.loc", "./scenarios"));
	for (String fileName : ConfigurationManager.getBundle().getStringArray("scenario.file.loc", "./scenarios")) {
		process(fileName);
	}

	logger.info("total test found: " + scenarios.size());
	return scenarios.toArray(new Object[scenarios.size()]);

}
 
Example 3
Project: tempto   File: ConventionBasedTestFactory.java   View source code 6 votes vote down vote up
@Factory
public Object[] createTestCases()
{
    LOGGER.debug("Loading file based test cases");
    try {
        Optional<Path> productTestsPath = getConventionsTestsPath(TESTCASES_PATH_PART);
        if (!productTestsPath.isPresent()) {
            LOGGER.info("No convention tests cases");
            return NO_TEST_CASES;
        }

        factories = setupFactories();
        return createTestsForRootPath(productTestsPath.get());
    }
    catch (Exception e) {
        LOGGER.error("Could not create file test", e);
        throw new RuntimeException("Could not create test cases", e);
    }
}
 
Example 4
Project: hub-cf   File: ServiceBrokerTestFactory.java   View source code 5 votes vote down vote up
@Factory
@Test
public Object[] tests() {
    return new Object[] {
            new BindingInstanceTest(),
            new BindingProvisionRequestTest(),
            new BindingProvisionResponseTest(),
            new HubCredentialsTest(),
            new HubLoginTest(),
            new HubProjectParametersTest(),
            new BindResourceTest(),
            new BindingInstanceServiceTest(),
            new PhoneHomeParametersTest(),
    };
}
 
Example 5
Project: openjdk-jdk10   File: ScriptTest.java   View source code 5 votes vote down vote up
/**
 * Creates a test factory for the set of .js source tests.
 *
 * @return a Object[] of test objects.
 * @throws Exception upon failure
 */
@SuppressWarnings("static-method")
@Factory
public Object[] suite() throws Exception {
    Locale.setDefault(new Locale(""));

    final List<ITest> tests = new ArrayList<>();
    final Set<String> orphans = new TreeSet<>();

    final TestFactory<ITest> testFactory = new TestFactory<ITest>() {
        @Override
        public ITest createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) {
            return new ScriptRunnable(framework, testFile, engineOptions, testOptions,  scriptArguments);
        }

        @Override
        public void log(final String msg) {
            org.testng.Reporter.log(msg, true);
        }
    };

    TestFinder.findAllTests(tests, orphans, testFactory);

    if (System.getProperty(TEST_JS_INCLUDES) == null) {
        tests.add(new OrphanTestFinder(orphans));
    }

    return tests.toArray();
}
 
Example 6
Project: dockerfile-image-update   File: TestCollector.java   View source code 5 votes vote down vote up
@Factory
public Object[] runAllTests() throws IOException, IllegalAccessException, InstantiationException {
    // Any new test file, add it to this list
    // TODO: Can use reflection to automatically add these
    List<Object> tests = new ArrayList<>();

    Set<ClassPath.ClassInfo> allClasses = new TreeSet<>(Comparator.comparing(ClassPath.ClassInfo::getName));

    ClassPath classpath = ClassPath.from(TestCollector.class.getClassLoader());
    allClasses.addAll(classpath.getTopLevelClasses("com.salesforce.dockerfileimageupdate.itest.tests"));
    for (ClassPath.ClassInfo classinfo : allClasses) {
        tests.add(classinfo.load().newInstance());
    }
    return tests.toArray();
}
 
Example 7
Project: openjdk9   File: ScriptTest.java   View source code 5 votes vote down vote up
/**
 * Creates a test factory for the set of .js source tests.
 *
 * @return a Object[] of test objects.
 * @throws Exception upon failure
 */
@SuppressWarnings("static-method")
@Factory
public Object[] suite() throws Exception {
    Locale.setDefault(new Locale(""));

    final List<ITest> tests = new ArrayList<>();
    final Set<String> orphans = new TreeSet<>();

    final TestFactory<ITest> testFactory = new TestFactory<ITest>() {
        @Override
        public ITest createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) {
            return new ScriptRunnable(framework, testFile, engineOptions, testOptions,  scriptArguments);
        }

        @Override
        public void log(final String msg) {
            org.testng.Reporter.log(msg, true);
        }
    };

    TestFinder.findAllTests(tests, orphans, testFactory);

    if (System.getProperty(TEST_JS_INCLUDES) == null) {
        tests.add(new OrphanTestFinder(orphans));
    }

    return tests.toArray();
}
 
Example 8
Project: kaziranga   File: ScriptTest.java   View source code 5 votes vote down vote up
/**
 * Creates a test factory for the set of .js source tests.
 *
 * @return a Object[] of test objects.
 * @throws Exception upon failure
 */
@SuppressWarnings("static-method")
@Factory
public Object[] suite() throws Exception {
    Locale.setDefault(new Locale(""));

    final List<ITest> tests = new ArrayList<>();
    final Set<String> orphans = new TreeSet<>();

    final TestFactory<ITest> testFactory = new TestFactory<ITest>() {
        @Override
        public ITest createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) {
            return new ScriptRunnable(framework, testFile, engineOptions, testOptions,  scriptArguments);
        }

        @Override
        public void log(final String msg) {
            org.testng.Reporter.log(msg, true);
        }
    };

    TestFinder.findAllTests(tests, orphans, testFactory);

    if (System.getProperty(TEST_JS_INCLUDES) == null) {
        tests.add(new OrphanTestFinder(orphans));
    }

    return tests.toArray();
}
 
Example 9
Project: kotlogram   File: TLApiTest.java   View source code 5 votes vote down vote up
@Factory
public Object[] generateTestSuite() {
    AbsTLApiTest.init();
    ArrayList<TLApiTest> list = new ArrayList<>();
    for (Class<? extends TLObject> clazz : constructorList) {
        list.add(new TLApiTest(clazz));
    }
    return list.toArray();
}
 
Example 10
Project: kotlogram   File: TLApiDumpTest.java   View source code 5 votes vote down vote up
@Factory
public Object[] generateTestSuite() throws IOException, DecoderException {
    ArrayList<TLApiDumpTest> list = new ArrayList<>();
    for (File file : DumpUtils.loadAll()) {
        list.add(new TLApiDumpTest(file));
    }
    return list.toArray();
}
 
Example 11
Project: cloudkeeper   File: ITS3StagingArea.java   View source code 5 votes vote down vote up
@Factory
public Object[] contractTests() {
    setup();

    ProviderImpl provider = new ProviderImpl();
    return new Object[] {
        new StagingAreaContract(provider),
        new RemoteStagingAreaContract(provider, instanceProvider)
    };
}
 
Example 12
Project: cloudkeeper   File: MapStagingAreaTest.java   View source code 5 votes vote down vote up
@Factory
public Object[] contractTests() {
    return new Object[] {
        new StagingAreaContract(
            (identifier, runtimeContext, executionTrace) -> new MapStagingArea(runtimeContext, executionTrace)
        )
    };
}
 
Example 13
Project: cloudkeeper   File: MutableAnnotationTypeDeclarationTest.java   View source code 5 votes vote down vote up
@Factory
public Object[] contracts() {
    return new Object[] {
        new MutableLocatableContract(MutableAnnotationTypeDeclaration.class),
        new XmlRootElementContract(MutableAnnotationTypeDeclaration.fromClass(MemoryRequirements.class))
    };
}
 
Example 14
Project: cloudkeeper   File: MutableModuleTest.java   View source code 5 votes vote down vote up
@Factory
public Object[] contracts() {
    List<Object> contractsList = new ArrayList<>();
    contractsList.addAll(Arrays.asList(MutableLocatableContract.contractsFor(MutableCompositeModule.class,
        MutableInputModule.class, MutableLoopModule.class, MutableProxyModule.class)));
    contractsList.add(new XmlRootElementContract(
        new MutableInputModule()
            .setRaw(
                new MutableSerializationRoot()
                    .setDeclaration("test.FooSerialization")
                    .setEntries(Arrays.<MutableSerializationNode<?>>asList(
                        new MutableSerializationRoot()
                            .setKey(SimpleName.identifier("a"))
                            .setDeclaration("test.BarSerialization")
                            .setEntries(Collections.<MutableSerializationNode<?>>singletonList(
                                new MutableSerializedString()
                                    .setString("Hello")
                            )),
                        new MutableByteSequence()
                            .setKey(SimpleName.identifier("c"))
                            .setArray("World".getBytes()),
                        new MutableSerializationRoot()
                            .setKey(Index.index(4))
                            .setDeclaration("test.BazSerialization")
                            .setEntries(Collections.<MutableSerializationNode<?>>singletonList(
                                new MutableSerializationRoot()
                                    .setKey(SimpleName.identifier("e"))
                                    .setEntries(Collections.<MutableSerializationNode<?>>singletonList(
                                        new MutableByteSequence()
                                            .setKey(SimpleName.identifier("f"))
                                            .setArray("!".getBytes())
                                    ))
                            ))
                    ))
            )
    ));
    return contractsList.toArray();
}
 
Example 15
Project: cloudkeeper   File: MutableExecutableTest.java   View source code 5 votes vote down vote up
@Factory
public Object[] contracts() {
    List<Object> contractsList = new ArrayList<>();
    contractsList.addAll(Arrays.asList(MutableLocatableContract.contractsFor(MutableExecutable.class)));
    contractsList.add(new XmlRootElementContract(
        new MutableExecutable()
            .setModule(
                new MutableCompositeModule()
                    .setModules(Arrays.<MutableModule<?>>asList(
                        new MutableInputModule()
                            .setSimpleName("zero")
                            .setOutPortType(new MutableDeclaredType().setDeclaration(Integer.class.getName()))
                            .setRaw(
                                new MutableSerializationRoot()
                                    .setDeclaration(IntegerMarshaler.class.getName())
                                    .setEntries(Collections.<MutableSerializationNode<?>>singletonList(
                                        new MutableSerializedString().setString("0")
                                    ))
                            ),
                        new MutableProxyModule()
                            .setSimpleName("sum")
                            .setDeclaration("test.Sum")
                    ))
                    .setConnections(Collections.<MutableConnection<?>>singletonList(
                        new MutableSiblingConnection()
                            .setFromModule("zero").setFromPort(BareInputModule.OUT_PORT_NAME)
                            .setToModule("sum").setToPort("num1")
                    ))
            )
            .setBundleIdentifiers(Collections.singletonList(
                URI.create("x-maven:xyz.cloudkeeper.examples.bundles:simple:ckbundle.zip:1.0.0-SNAPSHOT")
            ))
    ));
    return contractsList.toArray();
}
 
Example 16
Project: cloudkeeper   File: ByteSequencesTest.java   View source code 5 votes vote down vote up
@Factory
public Object[] byteSequences() {
    return new Object[] {
        new ByteSequenceContract("arrayBacked", new ByteSequenceProvider() {
            @Override
            public ByteSequence getByteSequence(byte[] content) {
                return ByteSequences.arrayBacked(content);
            }
        })
    };
}
 
Example 17
Project: cloudkeeper   File: PrefetchingModuleConnectorProviderTest.java   View source code 5 votes vote down vote up
@Factory
public Object[] contractTests() throws IOException {
    setup();
    assert tempDir != null && executorService != null;

    ModuleConnectorProvider moduleConnectorProvider = new PrefetchingModuleConnectorProvider(tempDir);
    return new Object[] {
        new ModuleConnectorProviderContract(
            moduleConnectorProvider,
            (identifier, runtimeContext, executionTrace) -> new MapStagingArea(runtimeContext, executionTrace),
            WAIT_DURATION_MILLIS
        )
    };
}
 
Example 18
Project: cloudkeeper   File: SimpleExecutorTest.java   View source code 5 votes vote down vote up
@Factory
public Object[] contractTests() throws IOException {
    setup();

    long awaitDurationMillis = 1000;
    return new Object[] {
        new ModuleExecutorContract(
            simpleExecutor,
            (identifier, runtimeContext, executionTrace) -> new MapStagingArea(runtimeContext, executionTrace),
            awaitDurationMillis
        )
    };
}
 
Example 19
Project: cloudkeeper   File: CloudKeeperTypesTest.java   View source code 5 votes vote down vote up
@Factory
public Object[] createTests() {
    Provider provider = new Provider();
    return new Object[] {
        new AbstractTypesContract(provider)
    };
}
 
Example 20
Project: cloudkeeper   File: ITMavenRuntimeContextProvider.java   View source code 5 votes vote down vote up
@Factory
public Object[] contractTests() throws Exception {
    setup();

    return new Object[] {
        new RuntimeContextProviderContract(
            () -> new MavenRuntimeContextFactory.Builder(
                executorService,
                aetherRepository.getRepositorySystem(),
                aetherRepository.getRepositorySystemSession()
            ).build()
        )
    };
}
 
Example 21
Project: cloudkeeper   File: ITFileStagingArea.java   View source code 5 votes vote down vote up
@Factory
public Object[] contractTests() {
    ProviderImpl stagingAreaProvider = new ProviderImpl();
    return new Object[] {
        new StagingAreaContract(stagingAreaProvider),
        new RemoteStagingAreaContract(stagingAreaProvider, instanceProvider)
    };
}
 
Example 22
Project: lookaside_java-1.8.0-openjdk   File: ScriptTest.java   View source code 5 votes vote down vote up
/**
 * Creates a test factory for the set of .js source tests.
 *
 * @return a Object[] of test objects.
 * @throws Exception upon failure
 */
@SuppressWarnings("static-method")
@Factory
public Object[] suite() throws Exception {
    Locale.setDefault(new Locale(""));

    final List<ITest> tests = new ArrayList<>();
    final Set<String> orphans = new TreeSet<>();

    final TestFactory<ITest> testFactory = new TestFactory<ITest>() {
        @Override
        public ITest createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) {
            return new ScriptRunnable(framework, testFile, engineOptions, testOptions,  scriptArguments);
        }

        @Override
        public void log(final String msg) {
            org.testng.Reporter.log(msg, true);
        }
    };

    TestFinder.findAllTests(tests, orphans, testFactory);

    if (System.getProperty(TEST_JS_INCLUDES) == null) {
        tests.add(new OrphanTestFinder(orphans));
    }

    return tests.toArray();
}
 
Example 23
Project: correctanswers-java   File: SwapperNGTestGenerator.java   View source code 5 votes vote down vote up
/**
 * Test instance factory method.
 *
 * @return Object[] test instances, each with a different {@link Swapper} to test.
 */
@Factory
public Object[] generateTests()
{
    final Object[] tests =
    {
        new SwapperNGTest(new XorSwapper()),
        new SwapperNGTest(new PlusSwapper()),
        new SwapperNGTest(new TimesSwapper()),
    };
    return tests;
}
 
Example 24
Project: jdk8u_nashorn   File: ScriptTest.java   View source code 5 votes vote down vote up
/**
 * Creates a test factory for the set of .js source tests.
 *
 * @return a Object[] of test objects.
 * @throws Exception upon failure
 */
@SuppressWarnings("static-method")
@Factory
public Object[] suite() throws Exception {
    Locale.setDefault(new Locale(""));

    final List<ITest> tests = new ArrayList<>();
    final Set<String> orphans = new TreeSet<>();

    final TestFactory<ITest> testFactory = new TestFactory<ITest>() {
        @Override
        public ITest createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) {
            return new ScriptRunnable(framework, testFile, engineOptions, testOptions,  scriptArguments);
        }

        @Override
        public void log(final String msg) {
            org.testng.Reporter.log(msg, true);
        }
    };

    TestFinder.findAllTests(tests, orphans, testFactory);

    if (System.getProperty(TEST_JS_INCLUDES) == null) {
        tests.add(new OrphanTestFinder(orphans));
    }

    return tests.toArray();
}
 
Example 25
Project: JDI   File: ButtonTests.java   View source code 5 votes vote down vote up
@Factory
public Object[] textTests() {
    return new Object[]{
            new TextTests("Button", METALS_AND_COLORS_PAGE, () -> nestedMetalsAndColorsView.calculateButton,
                    "Calculate", "cul", ".*lcu.*")
    };
}
 
Example 26
Project: JDI   File: DatePickerTests.java   View source code 5 votes vote down vote up
@Factory
public Object[] textTests() {
    return new Object[]{
            new TextFieldTests("DatePicker", DATES_PAGE_FILLED,
                    () -> dates.datepicker,
                    nowTime("MM/dd/yyyy"),
                    nowTime("MM/dd/yyyy"),
                    "09/09/1945",
                    "1945",
                    "([0-9]{2}[\\/]{1}){2}[0-9]{4}")
    };
}
 
Example 27
Project: jlibs   File: SequenceTestFactory.java   View source code 5 votes vote down vote up
@Factory
@SuppressWarnings({"unchecked"})
public static SequenceTest[] createTests(){
    Sequence sequences[] = new Sequence[]{
        new TOCSequence(1, 10),
        new IterableSequence(System.getProperties().entrySet()),
        new ArraySequence(System.getProperties().entrySet().toArray()),
    };

    SequenceTest tests[] = new SequenceTest[sequences.length];
    for(int i=0; i<sequences.length; i++)
        tests[i] = new SequenceTest(sequences[i]);

    return tests;
}
 
Example 28
Project: JDI   File: TextAreaTests.java   View source code 5 votes vote down vote up
@Factory
public Object[] textTests() {
    return new Object[]{
            new TextFieldTests("ITextArea", CONTACT_PAGE_FILLED,
                    this::textItem, "text123", "text123",
                    DEFAULT.description, "pti", ".escriptio.")
    };
}
 
Example 29
Project: infobip-open-jdk-8   File: ScriptTest.java   View source code 5 votes vote down vote up
/**
 * Creates a test factory for the set of .js source tests.
 *
 * @return a Object[] of test objects.
 * @throws Exception upon failure
 */
@SuppressWarnings("static-method")
@Factory
public Object[] suite() throws Exception {
    Locale.setDefault(new Locale(""));

    final List<ITest> tests = new ArrayList<>();
    final Set<String> orphans = new TreeSet<>();

    final TestFactory<ITest> testFactory = new TestFactory<ITest>() {
        @Override
        public ITest createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) {
            return new ScriptRunnable(framework, testFile, engineOptions, testOptions,  scriptArguments);
        }

        @Override
        public void log(final String msg) {
            org.testng.Reporter.log(msg, true);
        }
    };

    TestFinder.findAllTests(tests, orphans, testFactory);

    if (System.getProperty(TEST_JS_INCLUDES) == null) {
        tests.add(new OrphanTestFinder(orphans));
    }

    return tests.toArray();
}
 
Example 30
Project: diqube   File: AbstractCacheDoubleDiqlExecutionTest.java   View source code 5 votes vote down vote up
@Factory
public Object[] cacheDoubleTests() {
  // execute all tests again. In the second run, execute each test twice on a single bean context.
  try {
    return CacheDoubleTestUtil.createTestObjects(this);
  } catch (Throwable t) {
    throw new RuntimeException("Exception while factorying for class " + this.getClass().getName(), t);
  }
}
 
Example 31
Project: sqoop-on-spark   File: TestLoader.java   View source code 5 votes vote down vote up
@Factory(dataProvider="test-hdfs-loader")
public TestLoader(ToFormat outputFormat,
                  ToCompression compression)
    throws Exception {
  this.outputDirectory = INPUT_ROOT + getClass().getSimpleName();
  this.outputFormat = outputFormat;
  this.compression = compression;
  this.loader = new HdfsLoader();
}
 
Example 32
Project: sqoop-on-spark   File: TestExtractor.java   View source code 5 votes vote down vote up
@Factory(dataProvider="test-hdfs-extractor")
public TestExtractor(ToFormat outputFileType,
                     Class<? extends CompressionCodec> compressionClass)
    throws Exception {
  this.inputDirectory = INPUT_ROOT + getClass().getSimpleName();
  this.outputFileType = outputFileType;
  this.compressionClass = compressionClass;
  this.extractor = new HdfsExtractor();
}
 
Example 33
Project: JDI   File: TextBoxTests.java   View source code 5 votes vote down vote up
@Factory
public Object[] textTests() {
    return new Object[]{
            new TextFieldTests("ITextArea", Preconditions.CONTACT_PAGE_FILLED, textFieldSupplier, "text123",
                    "text123", "Description", "pti", ".escriptio.")
    };
}
 
Example 34
Project: Reer   File: TestFactory.java   View source code 4 votes vote down vote up
@Factory(dataProvider = "data")
public TestFactory(String data) {
    this.data = data;
}
 
Example 35
Project: azure-documentdb-rxjava   File: DocumentQueryTest.java   View source code 4 votes vote down vote up
@Factory(dataProvider = "clientBuilders")
public DocumentQueryTest(AsyncDocumentClient.Builder clientBuilder) {
    this.clientBuilder = clientBuilder;
}
 
Example 36
Project: azure-documentdb-rxjava   File: DatabaseCrudTest.java   View source code 4 votes vote down vote up
@Factory(dataProvider = "clientBuilders")
public DatabaseCrudTest(AsyncDocumentClient.Builder clientBuilder) {
    this.clientBuilder = clientBuilder;
}
 
Example 37
Project: azure-documentdb-rxjava   File: DocumentCrudTest.java   View source code 4 votes vote down vote up
@Factory(dataProvider = "clientBuilders")
public DocumentCrudTest(AsyncDocumentClient.Builder clientBuilder) {
    this.clientBuilder = clientBuilder;
}
 
Example 38
Project: azure-documentdb-rxjava   File: StoredProcedureCrudTest.java   View source code 4 votes vote down vote up
@Factory(dataProvider = "clientBuilders")
public StoredProcedureCrudTest(AsyncDocumentClient.Builder clientBuilder) {
    this.clientBuilder = clientBuilder;
}
 
Example 39
Project: TestNG-Foundation   File: ConstructorFactory.java   View source code 4 votes vote down vote up
@Factory(dataProvider = "ints")
public ConstructorFactory(final int i) {
    // not important
}
 
Example 40
Project: TestNG-Foundation   File: ListenerChainTestFactory.java   View source code 4 votes vote down vote up
@Factory
public Object[] createInstances() {
    return new Object[] { new FactoryProduct() }; 
}