Java Code Examples for org.testng.collections.Lists#newArrayList()

The following examples show how to use org.testng.collections.Lists#newArrayList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestRunner.java    From qaf with MIT License 6 votes vote down vote up
/**
 * Apply the method interceptor (if applicable) to the list of methods.
 */
private ITestNGMethod[] intercept(ITestNGMethod[] methods) {
  List<IMethodInstance> methodInstances = methodsToMethodInstances(Arrays.asList(methods));

  // add built-in interceptor (PreserveOrderMethodInterceptor or InstanceOrderingMethodInterceptor at the end of the list
  m_methodInterceptors.add(builtinInterceptor);
  for (IMethodInterceptor m_methodInterceptor : m_methodInterceptors) {
    methodInstances = m_methodInterceptor.intercept(methodInstances, this);
  }

  List<ITestNGMethod> result = Lists.newArrayList();
  for (IMethodInstance imi : methodInstances) {
    result.add(imi.getMethod());
  }

  //Since an interceptor is involved, we would need to ensure that the ClassMethodMap object is in sync with the
  //output of the interceptor, else @AfterClass doesn't get executed at all when interceptors are involved.
  //so let's update the current classMethodMap object with the list of methods obtained from the interceptor.
  this.m_classMethodMap = new ClassMethodMap(result, null);

  return result.toArray(new ITestNGMethod[result.size()]);
}
 
Example 2
Source File: TestRunner.java    From qaf with MIT License 6 votes vote down vote up
private List<List<IMethodInstance>> createInstances(List<IMethodInstance> methodInstances) {
    Map<Object, List<IMethodInstance>> map = Maps.newHashMap();
//    MapList<IMethodInstance[], Object> map = new MapList<IMethodInstance[], Object>();
    for (IMethodInstance imi : methodInstances) {
      for (Object o : imi.getInstances()) {
        System.out.println(o);
        List<IMethodInstance> l = map.get(o);
        if (l == null) {
          l = Lists.newArrayList();
          map.put(o, l);
        }
        l.add(imi);
      }
//      for (Object instance : imi.getInstances()) {
//        map.put(imi, instance);
//      }
    }
//    return map.getKeys();
//    System.out.println(map);
    return new ArrayList<List<IMethodInstance>>(map.values());
  }
 
Example 3
Source File: MethodHelper.java    From qaf with MIT License 6 votes vote down vote up
private static List<ITestNGMethod> sortMethods(boolean forTests,
    List<ITestNGMethod> allMethods, IAnnotationFinder finder) {
  List<ITestNGMethod> sl = Lists.newArrayList();
  List<ITestNGMethod> pl = Lists.newArrayList();
  ITestNGMethod[] allMethodsArray = allMethods.toArray(new ITestNGMethod[allMethods.size()]);

  // Fix the method inheritance if these are @Configuration methods to make
  // sure base classes are invoked before child classes if 'before' and the
  // other way around if they are 'after'
  if (!forTests && allMethodsArray.length > 0) {
    ITestNGMethod m = allMethodsArray[0];
    boolean before = m.isBeforeClassConfiguration()
        || m.isBeforeMethodConfiguration() || m.isBeforeSuiteConfiguration()
        || m.isBeforeTestConfiguration();
    MethodInheritance.fixMethodInheritance(allMethodsArray, before);
  }

  topologicalSort(allMethodsArray, sl, pl);

  List<ITestNGMethod> result = Lists.newArrayList();
  result.addAll(sl);
  result.addAll(pl);
  return result;
}
 
Example 4
Source File: DefaultStaticTestData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider
static Object[][] testCasesAll() {
    List<Object[]> result = Lists.newArrayList();
    result.addAll(Arrays.asList(testClasses()));
    result.addAll(Arrays.asList(testInterfaces()));
    return result.toArray(new Object[result.size()][]);
}
 
Example 5
Source File: DefaultStaticTestData.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider
static Object[][] testCasesAll() {
    List<Object[]> result = Lists.newArrayList();
    result.addAll(Arrays.asList(testClasses()));
    result.addAll(Arrays.asList(testInterfaces()));
    return result.toArray(new Object[result.size()][]);
}
 
Example 6
Source File: MethodHelper.java    From qaf with MIT License 5 votes vote down vote up
/**
 * Extracts the unique list of <code>ITestNGMethod</code>s.
 */
public static List<ITestNGMethod> uniqueMethodList(Collection<List<ITestNGMethod>> methods) {
  Set<ITestNGMethod> resultSet = Sets.newHashSet();

  for (List<ITestNGMethod> l : methods) {
    resultSet.addAll(l);
  }

  return Lists.newArrayList(resultSet);
}
 
Example 7
Source File: IntegrationJobFactorySuite.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Config> getWorkerConfigs() {
  Config rawConfig = super.getWorkerConfigs().iterator().next();
  Config workerConfig = ConfigFactory.parseMap(ImmutableMap.of(GobblinClusterConfigurationKeys.TASK_RUNNER_SUITE_BUILDER, "TestJobFactorySuiteBuilder"))
      .withFallback(rawConfig);

  return Lists.newArrayList(workerConfig);
}
 
Example 8
Source File: DefaultStaticTestData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider
static Object[][] testCasesAll() {
    List<Object[]> result = Lists.newArrayList();
    result.addAll(Arrays.asList(testClasses()));
    result.addAll(Arrays.asList(testInterfaces()));
    return result.toArray(new Object[result.size()][]);
}
 
Example 9
Source File: AvroStringFieldEncryptorConverterTest.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testEncryptionOfArray()
    throws SchemaConversionException, DataConversionException, IOException {
  AvroStringFieldEncryptorConverter converter = new AvroStringFieldEncryptorConverter();
  WorkUnitState wuState = new WorkUnitState();

  wuState.getJobState().setProp("converter.fieldsToEncrypt", "favorite_quotes");
  wuState.getJobState().setProp("converter.encrypt.algorithm", "insecure_shift");

  converter.init(wuState);
  GenericRecord inputRecord =
      getRecordFromFile(getClass().getClassLoader().getResource("fieldPickInput_arrays.avro").getPath());
  GenericArray origValues = (GenericArray) inputRecord.get("favorite_quotes");
  for (int i = 0; i < origValues.size(); i++) {
    origValues.set(i, origValues.get(i).toString());
  }

  Schema inputSchema = inputRecord.getSchema();
  Schema outputSchema = converter.convertSchema(inputSchema, wuState);

  Iterable<GenericRecord> recordIt = converter.convertRecord(outputSchema, inputRecord, wuState);
  GenericRecord encryptedRecord = recordIt.iterator().next();

  Assert.assertEquals(outputSchema, inputSchema);

  GenericArray<String> encryptedVals = (GenericArray<String>) encryptedRecord.get("favorite_quotes");
  List<String> decryptedValues = Lists.newArrayList();
  for (String encryptedValue: encryptedVals) {
    InsecureShiftCodec codec = new InsecureShiftCodec(Maps.<String, Object>newHashMap());
    InputStream in =
        codec.decodeInputStream(new ByteArrayInputStream(encryptedValue.getBytes(StandardCharsets.UTF_8)));
    byte[] decryptedValue = new byte[in.available()];
    in.read(decryptedValue);
    decryptedValues.add(new String(decryptedValue, StandardCharsets.UTF_8));
  }

  Assert.assertEquals(decryptedValues, origValues);
}
 
Example 10
Source File: DefaultStaticTestData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider
static Object[][] testCasesAll() {
    List<Object[]> result = Lists.newArrayList();
    result.addAll(Arrays.asList(testClasses()));
    result.addAll(Arrays.asList(testInterfaces()));
    return result.toArray(new Object[result.size()][]);
}
 
Example 11
Source File: DefaultStaticTestData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider
static Object[][] testCasesAll() {
    List<Object[]> result = Lists.newArrayList();
    result.addAll(Arrays.asList(testClasses()));
    result.addAll(Arrays.asList(testInterfaces()));
    return result.toArray(new Object[result.size()][]);
}
 
Example 12
Source File: LongSource.java    From yql-plus with Apache License 2.0 5 votes vote down vote up
@Query
public Iterable<Sample> getSampleIds(long start, long end, boolean increment) {
    List<Sample> samples = Lists.newArrayList();
    if (increment) {         
        samples.add(new Sample(start + 1, end + 1));
    } else {
        samples.add(new Sample(start, end));
    }
    return samples;
}
 
Example 13
Source File: MyTestExecutor.java    From AppiumTestDistribution with GNU General Public License v3.0 5 votes vote down vote up
public boolean runMethodParallel() {
    TestNG testNG = new TestNG();
    List<String> suites = Lists.newArrayList();
    suites.add(getProperty("user.dir") + PARALLEL_XML_LOCATION);
    testNG.setTestSuites(suites);
    testNG.run();
    return testNG.hasFailure();
}
 
Example 14
Source File: ReplicatorTlsTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplicationClient() throws Exception {
    log.info("--- Starting ReplicatorTlsTest::testReplicationClient ---");
    for (BrokerService ns : Lists.newArrayList(ns1, ns2, ns3)) {
        ns.getReplicationClients().forEach((cluster, client) -> {
            assertTrue(((PulsarClientImpl) client).getConfiguration().isUseTls());
            assertEquals(((PulsarClientImpl) client).getConfiguration().getTlsTrustCertsFilePath(),
                    TLS_SERVER_CERT_FILE_PATH);
        });
    }
}
 
Example 15
Source File: DefaultStaticTestData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider
static Object[][] testCasesAll() {
    List<Object[]> result = Lists.newArrayList();
    result.addAll(Arrays.asList(testClasses()));
    result.addAll(Arrays.asList(testInterfaces()));
    return result.toArray(new Object[result.size()][]);
}
 
Example 16
Source File: DefaultStaticTestData.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider
static Object[][] testCasesAll() {
    List<Object[]> result = Lists.newArrayList();
    result.addAll(Arrays.asList(testClasses()));
    result.addAll(Arrays.asList(testInterfaces()));
    return result.toArray(new Object[result.size()][]);
}
 
Example 17
Source File: LongSource.java    From yql-plus with Apache License 2.0 4 votes vote down vote up
@Query
public Iterable<Sample> getSampleIds(Long start, Long end) {
    List<Sample> samples = Lists.newArrayList();
    samples.add(new Sample(start, end));
    return samples;
}
 
Example 18
Source File: TestDistributedAtomicLong.java    From xian with Apache License 2.0 4 votes vote down vote up
@Test
public void     testSimulation() throws Exception
{
    final int           threadQty = 20;
    final int           executionQty = 50;

    final AtomicInteger optimisticTries = new AtomicInteger();
    final AtomicInteger promotedLockTries = new AtomicInteger();
    final AtomicInteger failures = new AtomicInteger();
    final AtomicInteger errors = new AtomicInteger();

    final SummaryStatistics timingStats = new SynchronizedSummaryStatistics();
    List<Future<Void>>      procs = Lists.newArrayList();
    ExecutorService         executorService = Executors.newFixedThreadPool(threadQty);
    for ( int i = 0; i < threadQty; ++i )
    {
        Callable<Void>          proc = new Callable<Void>()
        {
            @Override
            public Void call() throws Exception
            {
                doSimulation(executionQty, timingStats, optimisticTries, promotedLockTries, failures, errors);
                return null;
            }
        };
        procs.add(executorService.submit(proc));
    }

    for ( Future<Void> f : procs )
    {
        f.get();
    }

    System.out.println("OptimisticTries: " + optimisticTries.get());
    System.out.println("PromotedLockTries: " + promotedLockTries.get());
    System.out.println("Failures: " + failures.get());
    System.out.println("Errors: " + errors.get());
    System.out.println();

    System.out.println("Avg time: " + timingStats.getMean());
    System.out.println("Max time: " + timingStats.getMax());
    System.out.println("Min time: " + timingStats.getMin());
    System.out.println("Qty: " + timingStats.getN());

    Assert.assertEquals(errors.get(), 0);
    Assert.assertTrue(optimisticTries.get() > 0);
    Assert.assertTrue(promotedLockTries.get() > 0);
}
 
Example 19
Source File: MethodHelper.java    From qaf with MIT License 4 votes vote down vote up
/**
 * Finds TestNG methods that the specified TestNG method depends upon
 * @param m TestNG method
 * @param methods list of methods to search for depended upon methods
 * @return list of methods that match the criteria
 */
protected static ITestNGMethod[] findDependedUponMethods(ITestNGMethod m,
    ITestNGMethod[] methods)
{
  String canonicalMethodName = calculateMethodCanonicalName(m);
  List<ITestNGMethod> vResult = Lists.newArrayList();
  String regexp = null;
  for (String fullyQualifiedRegexp : m.getMethodsDependedUpon()) {
    boolean foundAtLeastAMethod = false;

    if (null != fullyQualifiedRegexp) {
      // Escapes $ in regexps as it is not meant for end - line matching, but inner class matches.
      regexp = fullyQualifiedRegexp.replace("$", "\\$");
      boolean usePackage = regexp.indexOf('.') != -1;
      Pattern pattern = Pattern.compile(regexp);

      for (ITestNGMethod method : methods) {
        ConstructorOrMethod thisMethod = method.getConstructorOrMethod();
        String thisMethodName = thisMethod.getName();
        String methodName = usePackage ?
            calculateMethodCanonicalName(method)
            : thisMethodName;
        Pair<String, String> cacheKey = Pair.create(regexp, methodName);
        Boolean match = MATCH_CACHE.get(cacheKey);
        if (match == null) {
            match = pattern.matcher(methodName).matches();
            MATCH_CACHE.put(cacheKey, match);
        }
        if (match) {
          vResult.add(method);
          foundAtLeastAMethod = true;
        }
      }
    }

    if (!foundAtLeastAMethod) {
      if (m.ignoreMissingDependencies()) {
        continue;
      }
      if (m.isAlwaysRun()) {
        continue;
      }
      Method maybeReferringTo = findMethodByName(m, regexp);
      if (maybeReferringTo != null) {
        throw new TestNGException(canonicalMethodName + "() is depending on method "
            + maybeReferringTo + ", which is not annotated with @Test or not included.");
      }
      throw new TestNGException(canonicalMethodName
          + "() depends on nonexistent method " + regexp);
    }
  }//end for

  return vResult.toArray(new ITestNGMethod[vResult.size()]);
}
 
Example 20
Source File: MockZKHelixManager.java    From helix with Apache License 2.0 4 votes vote down vote up
@Override
public ZkHelixPropertyStore<ZNRecord> getHelixPropertyStore() {
  // TODO Auto-generated method stub
  return new ZkHelixPropertyStore<>(
      (ZkBaseDataAccessor<ZNRecord>) _accessor.getBaseDataAccessor(), TaskConstants.REBALANCER_CONTEXT_ROOT, Lists.<String>newArrayList());
}