@Test public void testCollectionContainingObjectAnnotatedWithCerealClass() throws CerealException { StringWrapperContainer container = new StringWrapperContainer(); container.setWrappers(Arrays.asList(new StringWrapper("kp"), new StringWrapper(null))); Map<String, Set<StringWrapper>> wrapperMap = new HashMap<String, Set<StringWrapper>>(); wrapperMap.put("1", Sets.newHashSet(Arrays.asList(new StringWrapper("mp")))); Map<String, Set<String>> wrapperMap2 = new HashMap<String, Set<String>>(); wrapperMap2.put("y", Sets.newHashSet(Arrays.asList("x"))); container.setWrapperMap(wrapperMap); container.setWrapperMapNoSubtype(wrapperMap2); JsonCerealEngine engine = new JsonCerealEngine(); CerealSettings settings = new CerealSettings(); settings.setIncludeClassName(false); engine.setSettings(settings); String cereal = engine.writeToString(container); StringWrapperContainer decereal = engine.readFromString(cereal, StringWrapperContainer.class); Collection<StringWrapper> wrappers = new ArrayList<StringWrapper>(decereal.getWrappers()); wrappers.addAll(decereal.getWrapperMap().get("1")); Assert.assertEquals(wrappers.size(), 3); for (Object obj : wrappers) { Assert.assertEquals(obj.getClass(), StringWrapper.class); } Assert.assertEquals(decereal, container); }
/** A Method that returns all the Methods that are annotated with @DataProvider * in a given package. Should be moved to htsjdk and used from there * * @param packageName the package under which to look for classes and methods * @return an iterator to collection of Object[]'s consisting of {Method method, Class clazz} pair. * where method has the @DataProviderAnnotation and is a member of clazz. */ public static Iterator<Object[]> getDataProviders(final String packageName) { List<Object[]> data = new ArrayList<>(); final ClassFinder classFinder = new ClassFinder(); classFinder.find(packageName, Object.class); for (final Class<?> testClass : classFinder.getClasses()) { if (Modifier.isAbstract(testClass.getModifiers()) || Modifier.isInterface(testClass.getModifiers())) continue; Set<Method> methodSet = Sets.newHashSet(); methodSet.addAll(Arrays.asList(testClass.getDeclaredMethods())); methodSet.addAll(Arrays.asList(testClass.getMethods())); for (final Method method : methodSet) { if (method.isAnnotationPresent(DataProvider.class)) { data.add(new Object[]{method, testClass}); } } } return data.iterator(); }
@Test public void test500ScriptingUsers() throws Exception { final String TEST_NAME = "test500ScriptingUsers"; TestUtil.displayTestTile(this, TEST_NAME); // GIVEN Task task = createTask(DOT_CLASS + TEST_NAME); OperationResult result = task.getResult(); PrismProperty<ScriptingExpressionType> expression = parseAnyData(SCRIPTING_USERS_FILE); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(expression.getAnyValue().getValue(), task, result); // THEN dumpOutput(output, result); result.computeStatus(); TestUtil.assertSuccess(result); PipelineData data = output.getFinalOutput(); assertEquals("Unexpected # of items in output", 5, data.getData().size()); Set<String> realOids = new HashSet<>(); for (PipelineItem item : data.getData()) { PrismValue value = item.getValue(); PrismObject<UserType> user = ((PrismObjectValue<UserType>) value).asPrismObject(); assertEquals("Description not set", "Test", user.asObjectable().getDescription()); realOids.add(user.getOid()); assertSuccess(item.getResult()); } assertEquals("Unexpected OIDs in output", Sets.newHashSet(Arrays.asList(USER_ADMINISTRATOR_OID, USER_JACK_OID, USER_BARBOSSA_OID, USER_GUYBRUSH_OID, USER_ELAINE_OID)), realOids); }
/** * 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); }
private Set<ManageableTrade> extractTrades(PositionMaster positionMaster) { Set<ManageableTrade> tradeSet = Sets.newHashSet(); for (ManageablePosition p : positionMaster.search(new PositionSearchRequest()).getPositions()) { tradeSet.addAll(p.getTrades()); } return tradeSet; }
@Test public void test500ScriptingUsers() throws Exception { final String TEST_NAME = "test500ScriptingUsers"; TestUtil.displayTestTitle(this, TEST_NAME); // GIVEN Task task = createTask(DOT_CLASS + TEST_NAME); OperationResult result = task.getResult(); PrismProperty<ScriptingExpressionType> expression = parseAnyData(SCRIPTING_USERS_FILE); // WHEN ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(expression.getAnyValue().getValue(), task, result); // THEN dumpOutput(output, result); result.computeStatus(); TestUtil.assertSuccess(result); PipelineData data = output.getFinalOutput(); assertEquals("Unexpected # of items in output", 5, data.getData().size()); Set<String> realOids = new HashSet<>(); for (PipelineItem item : data.getData()) { PrismValue value = item.getValue(); PrismObject<UserType> user = ((PrismObjectValue<UserType>) value).asPrismObject(); assertEquals("Description not set", "Test", user.asObjectable().getDescription()); realOids.add(user.getOid()); assertSuccess(item.getResult()); } assertEquals("Unexpected OIDs in output", Sets.newHashSet(Arrays.asList(USER_ADMINISTRATOR_OID, USER_JACK_OID, USER_BARBOSSA_OID, USER_GUYBRUSH_OID, USER_ELAINE_OID)), realOids); }
@Test public void basicTest() throws IOException { final Set<String> headersOfInterest = Sets.newHashSet(Arrays.asList("name", "learning_SAMPLE_0")); final List<SimpleAnnotatedGenomicRegion> simpleAnnotatedGenomicRegions = SimpleAnnotatedGenomicRegion.readAnnotatedRegions(TEST_FILE, headersOfInterest); Assert.assertEquals(simpleAnnotatedGenomicRegions.size(), 15); Assert.assertTrue(simpleAnnotatedGenomicRegions.stream() .mapToInt(s -> s.getAnnotations().entrySet().size()) .allMatch(i -> i == headersOfInterest.size())); Assert.assertTrue(simpleAnnotatedGenomicRegions.stream().allMatch(s -> s.getAnnotations().keySet().containsAll(headersOfInterest))); // Grab the first 15 and test values List<SimpleAnnotatedGenomicRegion> gtRegions = Arrays.asList( new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 30365, 30503), ImmutableSortedMap.of("name", "target_1_None", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 69088, 70010), ImmutableSortedMap.of("name", "target_2_None", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 367656, 368599), ImmutableSortedMap.of("name", "target_3_None", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 621093, 622036), ImmutableSortedMap.of("name", "target_4_None", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 861319, 861395), ImmutableSortedMap.of("name", "target_5_SAMD11", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 865532, 865718), ImmutableSortedMap.of("name", "target_6_SAMD11", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 866416, 866471), ImmutableSortedMap.of("name", "target_7_SAMD11", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 871149, 871278), ImmutableSortedMap.of("name", "target_8_SAMD11", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 874417, 874511), ImmutableSortedMap.of("name", "target_9_SAMD11", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 874652, 874842), ImmutableSortedMap.of("name", "target_10_SAMD11", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 876521, 876688), ImmutableSortedMap.of("name", "target_11_SAMD11", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 877513, 877633), ImmutableSortedMap.of("name", "target_12_SAMD11", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 877787, 877870), ImmutableSortedMap.of("name", "target_13_SAMD11", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 877936, 878440), ImmutableSortedMap.of("name", "target_14_SAMD11", "learning_SAMPLE_0", "2")), new SimpleAnnotatedGenomicRegion(new SimpleInterval("1", 878630, 878759), ImmutableSortedMap.of("name", "target_15_SAMD11", "learning_SAMPLE_0", "2")) ); Assert.assertEquals(simpleAnnotatedGenomicRegions.subList(0, gtRegions.size()), gtRegions); }
private void writeAllToBuffer(XMLStringBuffer xmlBuffer, ISuiteResult suiteResult) { xmlBuffer.push(XMLReporterConfig.TAG_TEST, getSuiteResultAttributes(suiteResult)); Set<ITestResult> testResults = Sets.newHashSet(); ITestContext testContext = suiteResult.getTestContext(); addAllTestResults(testResults, testContext.getPassedTests()); addAllTestResults(testResults, testContext.getFailedTests()); addAllTestResults(testResults, testContext.getSkippedTests()); addAllTestResults(testResults, testContext.getPassedConfigurations()); addAllTestResults(testResults, testContext.getSkippedConfigurations()); addAllTestResults(testResults, testContext.getFailedConfigurations()); addAllTestResults(testResults, testContext.getFailedButWithinSuccessPercentageTests()); addTestResults(xmlBuffer, testResults); xmlBuffer.pop(); }
@Test public void testSelectQueriesWithAllSelectionPolicies(){ QueryContext q1 = mock(QueryContext.class); QueryContext q2 = mock(QueryContext.class); QueryContext q3 = mock(QueryContext.class); /* eligibleQueriesSet1, eligibleQueriesSet2, eligibleQueriesSet3 have q1 in common */ Set<QueryContext> eligibleQueriesSet1 = Sets.newHashSet(Arrays.asList(q1, q2)); Set<QueryContext> eligibleQueriesSet2 = Sets.newHashSet(Arrays.asList(q1, q3)); Set<QueryContext> eligibleQueriesSet3 = Sets.newHashSet(Arrays.asList(q1, q2)); FinishedLensQuery mockFinishedQuery = mock(FinishedLensQuery.class); EstimatedImmutableQueryCollection mockWaitingQueries = mock(EstimatedImmutableQueryCollection.class); WaitingQueriesSelectionPolicy policy1 = mock(WaitingQueriesSelectionPolicy.class); WaitingQueriesSelectionPolicy policy2 = mock(WaitingQueriesSelectionPolicy.class); WaitingQueriesSelectionPolicy driverSelectionPolicy = mock(WaitingQueriesSelectionPolicy.class); when(mockFinishedQuery.getDriverSelectionPolicies()).thenReturn(ImmutableSet.of(driverSelectionPolicy)); /* selection policy1 will return eligibleQueriesSet1 */ when(policy1.selectQueries(mockFinishedQuery, mockWaitingQueries)).thenReturn(eligibleQueriesSet1); /* selection policy2 will return eligibleQueriesSet2 */ when(policy2.selectQueries(mockFinishedQuery, mockWaitingQueries)).thenReturn(eligibleQueriesSet2); /* driver selection policy will return eligibleQueriesSet3 */ when(driverSelectionPolicy.selectQueries(mockFinishedQuery, mockWaitingQueries)).thenReturn(eligibleQueriesSet3); WaitingQueriesSelector selector = new UnioningWaitingQueriesSelector(ImmutableSet.of(policy1, policy2)); /* selector should return only eligibleQuery1, as this is the only common eligible waiting query returned * by both selection policies */ Set<QueryContext> actualEligibleQueries = selector.selectQueries(mockFinishedQuery, mockWaitingQueries); Set<QueryContext> expectedEligibleQueries = Sets.newHashSet(Arrays.asList(q1, q2, q3)); assertEquals(actualEligibleQueries, expectedEligibleQueries); }
@Test public void loadUserByUsername_SuperUser() { UserDetails user = userDetailsService.loadUserByUsername("admin"); Set<String> authorities = Sets.newHashSet(Collections2.transform(user.getAuthorities(), (Function<GrantedAuthority, String>) GrantedAuthority::getAuthority)); assertTrue(authorities.contains(SecurityUtils.AUTHORITY_SU)); assertEquals(authorities.size(), 1); }
@Test public void loadUserByUsername_NonSuperUser() { UserDetails user = userDetailsService.loadUserByUsername("user"); Set<String> authorities = Sets.newHashSet(Collections2.transform(user.getAuthorities(), (Function<GrantedAuthority, String>) GrantedAuthority::getAuthority)); assertEquals(authorities.size(), 0); }
private void initListeners() { // // Find all the listener factories and collect all the listeners requested in a // @Listeners annotation. // Set<Class<? extends ITestNGListener>> listenerClasses = Sets.newHashSet(); Class<? extends ITestNGListenerFactory> listenerFactoryClass = null; for (IClass cls : getTestClasses()) { Class<?> realClass = cls.getRealClass(); ListenerHolder listenerHolder = findAllListeners(realClass); if (listenerFactoryClass == null) { listenerFactoryClass = listenerHolder.listenerFactoryClass; } listenerClasses.addAll(listenerHolder.listenerClasses); } // // Now we have all the listeners collected from @Listeners and at most one // listener factory collected from a class implementing ITestNGListenerFactory. // Instantiate all the requested listeners. // ITestNGListenerFactory listenerFactory = null; // If we found a test listener factory, instantiate it. try { if (m_testClassFinder != null) { IClass ic = m_testClassFinder.getIClass(listenerFactoryClass); if (ic != null) { listenerFactory = (ITestNGListenerFactory) ic.getInstances(false)[0]; } } if (listenerFactory == null) { listenerFactory = listenerFactoryClass != null ? listenerFactoryClass.newInstance() : null; } } catch(Exception ex) { throw new TestNGException("Couldn't instantiate the ITestNGListenerFactory: " + ex); } // Instantiate all the listeners for (Class<? extends ITestNGListener> c : listenerClasses) { if (IClassListener.class.isAssignableFrom(c) && m_classListeners.containsKey(c)) { continue; } ITestNGListener listener = listenerFactory != null ? listenerFactory.createListener(c) : null; if (listener == null) { listener = ClassHelper.newInstance(c); } addListener(listener); } }
@Test public void testPrepareAllSelectionPoliciesWithNoDriverSelectionPolicy() { WaitingQueriesSelectionPolicy p1 = mock(WaitingQueriesSelectionPolicy.class); WaitingQueriesSelectionPolicy p2 = mock(WaitingQueriesSelectionPolicy.class); final ImmutableSet<WaitingQueriesSelectionPolicy> emptySet = ImmutableSet.copyOf( Sets.<WaitingQueriesSelectionPolicy>newHashSet()); FinishedLensQuery mockFinishedQuery = mock(FinishedLensQuery.class); when(mockFinishedQuery.getDriverSelectionPolicies()).thenReturn(emptySet); UnioningWaitingQueriesSelector selector = new UnioningWaitingQueriesSelector(ImmutableSet.of(p1, p2)); assertEquals(selector.prepareAllSelectionPolicies(mockFinishedQuery), ImmutableSet.of(p1, p2)); }
@Test public void testSelectQueriesWithNoSelectionPolicies(){ FinishedLensQuery mockFinishedQuery = mock(FinishedLensQuery.class); EstimatedImmutableQueryCollection mockWaitingQueries = mock(EstimatedImmutableQueryCollection.class); Set<WaitingQueriesSelectionPolicy> emptySetOfPolicies = Sets.newHashSet(); when(mockFinishedQuery.getDriverSelectionPolicies()).thenReturn(ImmutableSet.copyOf(emptySetOfPolicies)); WaitingQueriesSelector selector = new UnioningWaitingQueriesSelector(ImmutableSet.copyOf(emptySetOfPolicies)); /* selector should return an empty set as no selection policy is available */ Set<QueryContext> actualEligibleQueries = selector.selectQueries(mockFinishedQuery, mockWaitingQueries); assertTrue(actualEligibleQueries.isEmpty()); }