List of usage examples for java.util List containsAll
boolean containsAll(Collection<?> c);
From source file:org.apache.atlas.service.DefaultMetadataServiceTest.java
@Test public void testDeleteEntities() throws Exception { // Create a table entity, with 3 composite column entities Referenceable dbEntity = createDBEntity(); String dbGuid = TestUtils.createInstance(metadataService, dbEntity); Referenceable table1Entity = createTableEntity(dbGuid); Referenceable col1 = createColumnEntity(); Referenceable col2 = createColumnEntity(); Referenceable col3 = createColumnEntity(); table1Entity.set(COLUMNS_ATTR_NAME, ImmutableList.of(col1, col2, col3)); TestUtils.createInstance(metadataService, table1Entity); // Retrieve the table entities from the repository, // to get their guids and the composite column guids. String entityJson = metadataService.getEntityDefinition(TestUtils.TABLE_TYPE, NAME, (String) table1Entity.get(NAME)); Assert.assertNotNull(entityJson);//from www . j a v a2 s . c o m table1Entity = InstanceSerialization.fromJsonReferenceable(entityJson, true); List<IReferenceableInstance> table1Columns = (List<IReferenceableInstance>) table1Entity .get(COLUMNS_ATTR_NAME); // Register an EntityChangeListener to verify the notification mechanism // is working for deleteEntities(). EntitiesChangeListener listener = new EntitiesChangeListener(); metadataService.registerListener(listener); //Delete one column String columnId = table1Columns.get(0).getId()._getId(); AtlasClient.EntityResult entityResult = deleteEntities(columnId); //column is deleted and table is updated assertEquals(entityResult.getDeletedEntities().get(0), columnId); assertEquals(entityResult.getUpdateEntities().get(0), table1Entity.getId()._getId()); //verify listener was called for updates and deletes assertEquals(entityResult.getDeletedEntities(), listener.getDeletedEntities()); assertEquals(entityResult.getUpdateEntities(), listener.getUpdatedEntities()); // Delete the table entities. The deletion should cascade // to their composite columns. entityResult = deleteEntities(table1Entity.getId()._getId()); // Verify that deleteEntities() response has guids for tables and their composite columns. Assert.assertTrue(entityResult.getDeletedEntities().contains(table1Entity.getId()._getId())); Assert.assertTrue(entityResult.getDeletedEntities().contains(table1Columns.get(1).getId()._getId())); Assert.assertTrue(entityResult.getDeletedEntities().contains(table1Columns.get(2).getId()._getId())); // Verify that tables and their composite columns have been deleted from the repository. assertEntityDeleted(TABLE_TYPE, NAME, table1Entity.get(NAME)); assertEntityDeleted(COLUMN_TYPE, NAME, col2.get(NAME)); assertEntityDeleted(COLUMN_TYPE, NAME, col3.get(NAME)); // Verify that the listener was notified about the deleted entities. List<String> deletedEntitiesFromListener = listener.getDeletedEntities(); Assert.assertNotNull(deletedEntitiesFromListener); assertEquals(deletedEntitiesFromListener.size(), entityResult.getDeletedEntities().size()); Assert.assertTrue(deletedEntitiesFromListener.containsAll(entityResult.getDeletedEntities())); }
From source file:org.opendaylight.genius.itm.impl.ItmUtils.java
public static VtepConfigSchema validateForUpdateVtepSchema(String schemaName, List<BigInteger> lstDpnsForAdd, List<BigInteger> lstDpnsForDelete, IITMProvider itmProvider) { Preconditions.checkArgument(StringUtils.isNotBlank(schemaName)); if ((lstDpnsForAdd == null || lstDpnsForAdd.isEmpty()) && (lstDpnsForDelete == null || lstDpnsForDelete.isEmpty())) { Preconditions.checkArgument(false, "DPN ID list for add | delete is null or empty in schema " + schemaName); }/* w w w . ja va2s.c om*/ VtepConfigSchema schema = itmProvider.getVtepConfigSchema(schemaName); if (schema == null) { Preconditions.checkArgument(false, "Specified VTEP Schema [" + schemaName + "] doesn't exists!"); } List<BigInteger> existingDpnIds = getDpnIdList(schema.getDpnIds()); if (isNotEmpty(lstDpnsForAdd)) { // if (isNotEmpty(existingDpnIds)) { List<BigInteger> lstAlreadyExistingDpns = new ArrayList<>(existingDpnIds); lstAlreadyExistingDpns.retainAll(lstDpnsForAdd); Preconditions.checkArgument(lstAlreadyExistingDpns.isEmpty(), "DPN ID's " + lstAlreadyExistingDpns + " already exists in VTEP schema [" + schemaName + "]"); // } if (schema.getTunnelType().equals(TunnelTypeGre.class)) { validateForSingleGreTep(schema.getSchemaName(), lstDpnsForAdd, itmProvider.getAllVtepConfigSchemas()); } } if (isNotEmpty(lstDpnsForDelete)) { if (existingDpnIds == null || existingDpnIds.isEmpty()) { String builder = "DPN ID's " + lstDpnsForDelete + " specified for delete from VTEP schema [" + schemaName + "] are not configured in the schema."; Preconditions.checkArgument(false, builder); } else if (!existingDpnIds.containsAll(lstDpnsForDelete)) { List<BigInteger> lstConflictingDpns = new ArrayList<>(lstDpnsForDelete); lstConflictingDpns.removeAll(existingDpnIds); String builder = "DPN ID's " + lstConflictingDpns + " specified for delete from VTEP schema [" + schemaName + "] are not configured in the schema."; Preconditions.checkArgument(false, builder); } } return schema; }
From source file:org.talend.dataprofiler.core.ui.editor.composite.AnalysisColumnTreeViewer.java
@Override public boolean canDrop(IRepositoryNode metadataRepositoryNode) { IRepositoryViewObject metadataRepObject = metadataRepositoryNode.getObject(); ConnectionItem connItem = (ConnectionItem) metadataRepObject.getProperty().getItem(); // MOD qiongli 2010-8-19,bug 14436:could not come from diffrent connection Connection tdProvider = connItem.getConnection(); if (tdProvider == null) { return false; } else if (this.getAnalysis().getContext().getConnection() != null && !ResourceHelper.areSame(tdProvider, this.getAnalysis().getContext().getConnection())) { return false; }/*from w w w. ja v a2 s . co m*/ // MOD mzhao, 2010-07-23 bug 14014: If the editor is dirty, save it firstly before drag and drop an elements. if (masterPage.isDirty()) { masterPage.doSave(new NullProgressMonitor()); return false; } List<ModelElement> existModelElements = new ArrayList<ModelElement>(); for (ModelElementIndicator modelElementIndicator : this.getAllTheElementIndicator()) { ModelElement me = RepositoryNodeHelper .getModelElementFromRepositoryNode(modelElementIndicator.getModelElementRepositoryNode()); existModelElements.add(me); } // MOD mzhao 9848 2010-01-14, allowing to drag and drop table. if (metadataRepObject instanceof MetadataTableRepositoryObject) { MetadataTableRepositoryObject tableRepObject = (MetadataTableRepositoryObject) metadataRepObject; return !existModelElements.containsAll(ColumnSetHelper.getColumns((TdTable) tableRepObject.getTable())); } if (metadataRepObject instanceof MetadataColumnRepositoryObject) { if (existModelElements.contains(((MetadataColumnRepositoryObject) metadataRepObject).getTdColumn())) { return false; } } if (metadataRepObject instanceof MetadataXmlElementTypeRepositoryObject) { return !metadataRepositoryNode.hasChildren(); } return true; }
From source file:com.thoughtworks.go.config.CachedGoConfigIntegrationTest.java
@Test public void shouldFailWhenTryingToAddPipelineWithTheSameNameAsAnotherPipelineDefinedRemotely_EntitySave() throws Exception { assertThat(configWatchList.getCurrentConfigRepos().size()).isEqualTo(1); repoConfigDataSource.onCheckoutComplete(configRepo.getMaterialConfig(), externalConfigRepo, latestModification);//from w w w . j a v a 2 s. c o m assertThat(cachedGoConfig.currentConfig().hasPipelineNamed(new CaseInsensitiveString("pipe1"))).isTrue(); PipelineConfig dupPipelineConfig = PipelineMother.twoBuildPlansWithResourcesAndSvnMaterialsAtUrl("pipe1", "ut", "www.spring.com"); try { goConfigDao.updateConfig( new CreatePipelineConfigCommand(goConfigService, dupPipelineConfig, Username.ANONYMOUS, new DefaultLocalizedOperationResult(), "default", externalArtifactsService), Username.ANONYMOUS); fail("Should have thrown"); } catch (RuntimeException ex) { PipelineConfig pipe1 = goConfigService.pipelineConfigNamed(new CaseInsensitiveString("pipe1")); String errorMessage = dupPipelineConfig.errors().on(PipelineConfig.NAME); assertThat(errorMessage).contains( "You have defined multiple pipelines named 'pipe1'. Pipeline names must be unique. Source(s):"); Matcher matcher = Pattern.compile("^.*\\[(.*),\\s(.*)\\].*$").matcher(errorMessage); assertThat(matcher.matches()).isTrue(); assertThat(matcher.groupCount()).isEqualTo(2); List<String> expectedSources = asList(dupPipelineConfig.getOriginDisplayName(), pipe1.getOriginDisplayName()); List<String> actualSources = new ArrayList<>(); for (int i = 1; i <= matcher.groupCount(); i++) { actualSources.add(matcher.group(i)); } assertThat(actualSources.size()).isEqualTo(expectedSources.size()); assertThat(actualSources.containsAll(expectedSources)).isTrue(); } }
From source file:com.thoughtworks.go.config.CachedGoConfigIntegrationTest.java
@Test public void shouldFailWhenTryingToAddPipelineWithTheSameNameAsAnotherPipelineDefinedRemotely_FullConfigSave() throws Exception { assertThat(configWatchList.getCurrentConfigRepos().size()).isEqualTo(1); repoConfigDataSource.onCheckoutComplete(configRepo.getMaterialConfig(), externalConfigRepo, latestModification);/*www .jav a2 s . c o m*/ assertThat(cachedGoConfig.currentConfig().hasPipelineNamed(new CaseInsensitiveString("pipe1"))).isTrue(); final PipelineConfig dupPipelineConfig = PipelineMother .twoBuildPlansWithResourcesAndSvnMaterialsAtUrl("pipe1", "ut", "www.spring.com"); try { goConfigDao.updateConfig(new UpdateConfigCommand() { @Override public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception { cruiseConfig.getGroups().first().add(dupPipelineConfig); return cruiseConfig; } }); fail("Should have thrown"); } catch (RuntimeException ex) { String errorMessage = ex.getMessage(); assertThat(errorMessage).contains( "You have defined multiple pipelines named 'pipe1'. Pipeline names must be unique. Source(s):"); Matcher matcher = Pattern.compile("^.*\\[(.*),\\s(.*)\\].*$", Pattern.DOTALL | Pattern.MULTILINE) .matcher(errorMessage); assertThat(matcher.matches()).isTrue(); assertThat(matcher.groupCount()).isEqualTo(2); PipelineConfig pipe1 = goConfigService.pipelineConfigNamed(new CaseInsensitiveString("pipe1")); List<String> expectedSources = asList(dupPipelineConfig.getOriginDisplayName(), pipe1.getOriginDisplayName()); List<String> actualSources = new ArrayList<>(); for (int i = 1; i <= matcher.groupCount(); i++) { actualSources.add(matcher.group(i)); } assertThat(actualSources.size()).isEqualTo(expectedSources.size()); assertThat(actualSources.containsAll(expectedSources)).isTrue(); } }
From source file:org.apache.kylin.cube.model.CubeDesc.java
public Map<Array<TblColRef>, List<DeriveInfo>> getHostToDerivedInfo(List<TblColRef> rowCols, Collection<TblColRef> wantedCols) { Map<Array<TblColRef>, List<DeriveInfo>> result = new HashMap<Array<TblColRef>, List<DeriveInfo>>(); for (Entry<Array<TblColRef>, List<DeriveInfo>> entry : hostToDerivedMap.entrySet()) { Array<TblColRef> hostCols = entry.getKey(); boolean hostOnRow = rowCols.containsAll(Arrays.asList(hostCols.data)); if (!hostOnRow) continue; List<DeriveInfo> wantedInfo = new ArrayList<DeriveInfo>(); for (DeriveInfo info : entry.getValue()) { if (wantedCols == null || Collections.disjoint(wantedCols, Arrays.asList(info.columns)) == false) // has any wanted columns? wantedInfo.add(info);//from w w w . java 2s. co m } if (wantedInfo.size() > 0) result.put(hostCols, wantedInfo); } return result; }
From source file:org.apache.lens.ml.algo.spark.TableTrainingSpec.java
/** * Validate.//from ww w .j a v a2 s . c o m * * @return true, if successful */ boolean validate() { List<HCatFieldSchema> columns; try { HCatInputFormat.setInput(conf, database == null ? "default" : database, table, partitionFilter); HCatSchema tableSchema = HCatInputFormat.getTableSchema(conf); columns = tableSchema.getFields(); } catch (IOException exc) { LOG.error("Error getting table info " + toString(), exc); return false; } LOG.info(table + " columns " + columns.toString()); boolean valid = false; if (columns != null && !columns.isEmpty()) { // Check labeled column List<String> columnNames = new ArrayList<String>(); for (HCatFieldSchema col : columns) { columnNames.add(col.getName()); } // Need at least one feature column and one label column valid = columnNames.contains(labelColumn) && columnNames.size() > 1; if (valid) { labelPos = columnNames.indexOf(labelColumn); // Check feature columns if (featureColumns == null || featureColumns.isEmpty()) { // feature columns are not provided, so all columns except label column are feature columns featurePositions = new int[columnNames.size() - 1]; int p = 0; for (int i = 0; i < columnNames.size(); i++) { if (i == labelPos) { continue; } featurePositions[p++] = i; } columnNames.remove(labelPos); featureColumns = columnNames; } else { // Feature columns were provided, verify all feature columns are present in the table valid = columnNames.containsAll(featureColumns); if (valid) { // Get feature positions featurePositions = new int[featureColumns.size()]; for (int i = 0; i < featureColumns.size(); i++) { featurePositions[i] = columnNames.indexOf(featureColumns.get(i)); } } } numFeatures = featureColumns.size(); } } return valid; }
From source file:com.pinterest.deployservice.db.DBDAOTest.java
@Test public void testEnvDAO() throws Exception { // Test insert EnvironBean envBean = genDefaultEnvBean("env-1", "s-1", "prod", "deploy-1"); environDAO.insert(envBean);/* w w w. ja va 2 s . c o m*/ // Test getById EnvironBean envBean2 = environDAO.getById(envBean.getEnv_id()); assertTrue(EqualsBuilder.reflectionEquals(envBean, envBean2)); // Test getByStage EnvironBean envBean22 = environDAO.getByStage("s-1", "prod"); assertTrue(EqualsBuilder.reflectionEquals(envBean, envBean22)); // Test Watcher Column assertTrue(envBean2.getWatch_recipients().equals("watcher")); // Test update EnvironBean envBean3 = new EnvironBean(); envBean3.setAdv_config_id("config_id_2"); envBean2.setAdv_config_id("config_id_2"); environDAO.update("env-1", envBean3); EnvironBean envBean4 = environDAO.getById("env-1"); assertTrue(EqualsBuilder.reflectionEquals(envBean2, envBean4)); // Test getByName return 2 envs after add another env envBean = genDefaultEnvBean("env-2", "s-1", "whatever", "deploy-1"); environDAO.insert(envBean); List<EnvironBean> envBeans = environDAO.getByName("s-1"); assertEquals(envBeans.size(), 2); assertEquals(groupDAO.getCapacityHosts("env-1").size(), 0); assertEquals(groupDAO.getCapacityGroups("env-1").size(), 0); assertEquals(environDAO.getOverrideHosts("env-1", "s-1", "prod").size(), 0); assertEquals(environDAO.countTotalCapacity("env-1", "s-1", "prod"), 0); // Add 2 hosts capacity to env-1, host1 & host2 groupDAO.addHostCapacity("env-1", "host1"); groupDAO.addHostCapacity("env-1", "host2"); // Add 2 groups capacity to env-1, group1 & group2 groupDAO.addGroupCapacity("env-1", "group1"); groupDAO.addGroupCapacity("env-1", "group2"); // env-1 : host1, host2, group1, group2, empty groups though assertEquals(groupDAO.getCapacityHosts("env-1").size(), 2); assertEquals(groupDAO.getCapacityGroups("env-1").size(), 2); assertEquals(environDAO.getOverrideHosts("env-1", "s-1", "prod").size(), 0); assertEquals(environDAO.countTotalCapacity("env-1", "s-1", "prod"), 2); ArrayList<String> groupNames = new ArrayList<>(); groupNames.add("group1"); assertEquals(environDAO.getEnvsByGroups(groupNames).size(), 1); groupNames.add("group-lo"); assertEquals(environDAO.getEnvsByGroups(groupNames).size(), 1); // Test remove Host capacity and remove host capacity groupDAO.removeHostCapacity("env-1", "host2"); groupDAO.removeGroupCapacity("env-1", "group2"); // now env-1 associate with only : host1, group1 assertEquals(groupDAO.getCapacityHosts("env-1").size(), 1); assertEquals(groupDAO.getCapacityGroups("env-1").size(), 1); assertEquals(environDAO.getOverrideHosts("env-1", "s-1", "prod").size(), 0); assertEquals(environDAO.countTotalCapacity("env-1", "s-1", "prod"), 1); // Added 2 hosts to group1 and group2 Set<String> groups = new HashSet<>(Arrays.asList("group1", "group2")); hostDAO.insertOrUpdate("host-1", "1.1.1.1", "id-123434", HostState.ACTIVE.toString(), groups); hostDAO.insertOrUpdate("host-2", "1.1.1.2", "id-123435", HostState.ACTIVE.toString(), groups); // Total capacity for env-1 should be 3, host1, host-1(group1), host-2(group2) assertEquals(environDAO.getOverrideHosts("env-1", "s-1", "prod").size(), 0); assertEquals(environDAO.countTotalCapacity("env-1", "s-1", "prod"), 3); List<String> totalHosts = environDAO.getTotalCapacityHosts("env-1", "s-1", "prod"); assertEquals(totalHosts.size(), 3); assertTrue(totalHosts.containsAll(Arrays.asList("host-1", "host-2", "host1"))); // Now, override host-1 with env2 groupDAO.addHostCapacity("env-2", "host-1"); // override hosts should be 1, host-1 // Total capacity for env1 should be 2, host1, host-2 assertEquals(environDAO.getOverrideHosts("env-1", "s-1", "prod").size(), 1); assertEquals(environDAO.countTotalCapacity("env-1", "s-1", "prod"), 2); List<String> totalHosts2 = environDAO.getTotalCapacityHosts("env-1", "s-1", "prod"); assertEquals(totalHosts2.size(), 2); assertFalse(totalHosts2.contains("hosts-1")); // ineffective override (noise), add host-2 override on env-1 // override hosts should be 1, host-1 // Total capacity for env1 still is 2, host1, host-2 groupDAO.addHostCapacity("env-1", "host-2"); // noise assertEquals(environDAO.getOverrideHosts("env-1", "s-1", "prod").size(), 1); assertEquals(environDAO.countTotalCapacity("env-1", "s-1", "prod"), 2); List<String> totalHosts3 = environDAO.getTotalCapacityHosts("env-1", "s-1", "prod"); assertEquals(totalHosts3.size(), 2); assertTrue(totalHosts3.containsAll(Arrays.asList("host-2", "host1"))); // env-1 : host1, group1 // env-2 : host-1, List<EnvironBean> envs = environDAO.getEnvsByHost("host-1"); assertEquals(envs.size(), 1); assertEquals(envs.get(0).getEnv_name(), "s-1"); assertEquals(envs.get(0).getStage_name(), "whatever"); envs = environDAO.getEnvsByGroups(groups); assertEquals(envs.size(), 1); environDAO.delete("env-1"); environDAO.delete("env-2"); envBean = environDAO.getById("env-1"); assertEquals(envBean, null); }
From source file:grakn.core.graql.reasoner.query.AtomicQueryUnificationIT.java
/** * checks the correctness and uniqueness of an EXACT unifier required to unify child query with parent * @param parentString parent query string * @param childString child query string * @param checkInverse flag specifying whether the inverse equality u^{-1}=u(parent, child) of the unifier u(child, parent) should be checked * @param ignoreTypes flag specifying whether the types should be disregarded and only role players checked for containment * @param checkEquality if true the parent and child answers will be checked for equality, otherwise they are checked for containment of child answers in parent */// w w w .ja v a2 s.co m private void unificationWithResultChecks(String parentString, String childString, boolean checkInverse, boolean checkEquality, boolean ignoreTypes, UnifierType unifierType, TransactionOLTP tx) { ReasonerAtomicQuery child = ReasonerQueries.atomic(conjunction(childString), tx); ReasonerAtomicQuery parent = ReasonerQueries.atomic(conjunction(parentString), tx); Unifier unifier = unification(childString, parentString, true, unifierType, tx).getUnifier(); List<ConceptMap> childAnswers = tx.execute(child.getQuery(), false); List<ConceptMap> unifiedAnswers = childAnswers.stream().map(unifier::apply).filter(a -> !a.isEmpty()) .collect(Collectors.toList()); List<ConceptMap> parentAnswers = tx.execute(parent.getQuery(), false); if (checkInverse) { Unifier inverse = parent.getMultiUnifier(child, unifierType).getUnifier(); assertEquals(unifier.inverse(), inverse); assertEquals(unifier, inverse.inverse()); } assertTrue(!childAnswers.isEmpty()); assertTrue(!unifiedAnswers.isEmpty()); assertTrue(!parentAnswers.isEmpty()); Set<Variable> parentNonTypeVariables = Sets.difference(parent.getAtom().getVarNames(), Sets.newHashSet(parent.getAtom().getPredicateVariable())); if (!checkEquality) { if (!ignoreTypes) { assertTrue(parentAnswers.containsAll(unifiedAnswers)); } else { List<ConceptMap> projectedParentAnswers = parentAnswers.stream() .map(ans -> ans.project(parentNonTypeVariables)).collect(Collectors.toList()); List<ConceptMap> projectedUnified = unifiedAnswers.stream() .map(ans -> ans.project(parentNonTypeVariables)).collect(Collectors.toList()); assertTrue(projectedParentAnswers.containsAll(projectedUnified)); } } else { Unifier inverse = unifier.inverse(); if (!ignoreTypes) { assertCollectionsNonTriviallyEqual(parentAnswers, unifiedAnswers); List<ConceptMap> parentToChild = parentAnswers.stream().map(inverse::apply) .collect(Collectors.toList()); assertCollectionsNonTriviallyEqual(parentToChild, childAnswers); } else { Set<Variable> childNonTypeVariables = Sets.difference(child.getAtom().getVarNames(), Sets.newHashSet(child.getAtom().getPredicateVariable())); List<ConceptMap> projectedParentAnswers = parentAnswers.stream() .map(ans -> ans.project(parentNonTypeVariables)).collect(Collectors.toList()); List<ConceptMap> projectedUnified = unifiedAnswers.stream() .map(ans -> ans.project(parentNonTypeVariables)).collect(Collectors.toList()); List<ConceptMap> projectedChild = childAnswers.stream() .map(ans -> ans.project(childNonTypeVariables)).collect(Collectors.toList()); assertCollectionsNonTriviallyEqual(projectedParentAnswers, projectedUnified); List<ConceptMap> projectedParentToChild = projectedParentAnswers.stream().map(inverse::apply) .map(ans -> ans.project(childNonTypeVariables)).collect(Collectors.toList()); assertCollectionsNonTriviallyEqual(projectedParentToChild, projectedChild); } } }