List of usage examples for org.apache.commons.collections CollectionUtils isEqualCollection
public static boolean isEqualCollection(final Collection a, final Collection b)
From source file:ome.services.blitz.test.utests.FilePathRestrictionsTest.java
/** * Test that two complex sets of rules combined as expected. * (On a rainy day this test could be broken up into several smaller tests.) *///from w w w . j a va 2 s.c om @Test public void testCombineRules() { /* these variables define the X set of rules to combine */ final SetMultimap<Integer, Integer> transformationMatrixX = HashMultimap.create(); final Set<String> unsafePrefixesX = new HashSet<String>(); final Set<String> unsafeSuffixesX = new HashSet<String>(); final Set<String> unsafeNamesX = new HashSet<String>(); final Set<Character> safeCharactersX = new HashSet<Character>(); /* these variables define the Y set of rules to combine */ final SetMultimap<Integer, Integer> transformationMatrixY = HashMultimap.create(); final Set<String> unsafePrefixesY = new HashSet<String>(); final Set<String> unsafeSuffixesY = new HashSet<String>(); final Set<String> unsafeNamesY = new HashSet<String>(); final Set<Character> safeCharactersY = new HashSet<Character>(); /* these variables define the expected result of combining X and Y */ final SetMultimap<Integer, Integer> transformationMatrixXY = HashMultimap.create(); final Set<String> unsafePrefixesXY = new HashSet<String>(); final Set<String> unsafeSuffixesXY = new HashSet<String>(); final Set<String> unsafeNamesXY = new HashSet<String>(); final Set<Character> safeCharactersXY = new HashSet<Character>(); /* automatically map control characters to the safe characters; * we will remove and replace any that are to be tested specially */ for (int codePoint = 0; codePoint < 0x100; codePoint++) { if (Character.getType(codePoint) == Character.CONTROL) { transformationMatrixXY.put(codePoint, 65); } } /* choose four control characters and remove them from the transformation matrix */ final Iterator<Integer> controlCodePointIterator = transformationMatrixXY.keySet().iterator(); final int controlCharacterP = controlCodePointIterator.next(); final int controlCharacterQ = controlCodePointIterator.next(); final int controlCharacterR = controlCodePointIterator.next(); final int controlCharacterS = controlCodePointIterator.next(); transformationMatrixXY.removeAll(controlCharacterP); transformationMatrixXY.removeAll(controlCharacterQ); transformationMatrixXY.removeAll(controlCharacterR); transformationMatrixXY.removeAll(controlCharacterS); /* set up test case for combining control character mappings */ transformationMatrixX.put(controlCharacterP, 65); transformationMatrixX.put(controlCharacterP, 67); transformationMatrixX.put(controlCharacterQ, 65); transformationMatrixX.put(controlCharacterQ, 66); transformationMatrixX.put(controlCharacterR, 66); transformationMatrixY.put(controlCharacterQ, 66); transformationMatrixY.put(controlCharacterR, 66); transformationMatrixY.put(controlCharacterS, 68); transformationMatrixXY.put(controlCharacterP, 65); transformationMatrixXY.put(controlCharacterP, 67); transformationMatrixXY.put(controlCharacterQ, 66); transformationMatrixXY.put(controlCharacterR, 66); transformationMatrixXY.put(controlCharacterS, 68); /* choose four non-control characters and remove them from the transformation matrix */ int[] normalCodePoints = new int[4]; int index = 0; int codePoint = 0; while (index < normalCodePoints.length) { if (Character.getType(codePoint) != Character.CONTROL) { normalCodePoints[index++] = codePoint; transformationMatrixXY.removeAll(codePoint); } codePoint++; } int normalCharacterP = normalCodePoints[0]; int normalCharacterQ = normalCodePoints[1]; int normalCharacterR = normalCodePoints[2]; int normalCharacterS = normalCodePoints[3]; /* set up test case for combining non-control character mappings */ transformationMatrixX.put(normalCharacterP, 65); transformationMatrixX.put(normalCharacterP, 67); transformationMatrixX.put(normalCharacterQ, 65); transformationMatrixX.put(normalCharacterQ, 66); transformationMatrixX.put(normalCharacterR, 66); transformationMatrixY.put(normalCharacterQ, 66); transformationMatrixY.put(normalCharacterR, 66); transformationMatrixY.put(normalCharacterS, 68); transformationMatrixXY.put(normalCharacterP, 65); transformationMatrixXY.put(normalCharacterP, 67); transformationMatrixXY.put(normalCharacterQ, 66); transformationMatrixXY.put(normalCharacterR, 66); transformationMatrixXY.put(normalCharacterS, 68); /* set up test cases for combining proscribed strings */ unsafePrefixesX.add("XP"); unsafePrefixesX.add("YP"); unsafePrefixesY.add("YP"); unsafePrefixesY.add("ZP"); unsafePrefixesXY.add("XP"); unsafePrefixesXY.add("YP"); unsafePrefixesXY.add("ZP"); unsafeSuffixesX.add("XS"); unsafeSuffixesX.add("YS"); unsafeSuffixesY.add("YS"); unsafeSuffixesY.add("ZS"); unsafeSuffixesXY.add("XS"); unsafeSuffixesXY.add("YS"); unsafeSuffixesXY.add("ZS"); unsafeNamesX.add("XN"); unsafeNamesX.add("YN"); unsafeNamesY.add("YN"); unsafeNamesY.add("ZN"); unsafeNamesXY.add("XN"); unsafeNamesXY.add("YN"); unsafeNamesXY.add("ZN"); /* set up test case for combining safe characters */ safeCharactersX.add('A'); safeCharactersX.add('B'); safeCharactersY.add('A'); safeCharactersXY.add('A'); /* perform the combination */ final FilePathRestrictions rulesX = new FilePathRestrictions(transformationMatrixX, unsafePrefixesX, unsafeSuffixesX, unsafeNamesX, safeCharactersX); final FilePathRestrictions rulesY = new FilePathRestrictions(transformationMatrixY, unsafePrefixesY, unsafeSuffixesY, unsafeNamesY, safeCharactersY); final FilePathRestrictions rulesXY = FilePathRestrictions.combineFilePathRestrictions(rulesX, rulesY); /* test that the combination is as expected in all respects */ Assert.assertTrue(CollectionUtils.isEqualCollection(rulesXY.safeCharacters, safeCharactersXY)); Assert.assertTrue(CollectionUtils.isEqualCollection(rulesXY.unsafePrefixes, unsafePrefixesXY)); Assert.assertTrue(CollectionUtils.isEqualCollection(rulesXY.unsafeSuffixes, unsafeSuffixesXY)); Assert.assertTrue(CollectionUtils.isEqualCollection(rulesXY.unsafeNames, unsafeNamesXY)); assertEqualMultimaps(rulesXY.transformationMatrix, transformationMatrixXY); /* given a mapping choice, prefer the safe character */ Assert.assertEquals((int) rulesXY.transformationMap.get(controlCharacterP), 65); Assert.assertEquals((int) rulesXY.transformationMap.get(normalCharacterP), 65); }
From source file:omero.cmd.fs.OriginalMetadataRequestTest.java
/** * Test that pre-FS original_metadata.txt files are parsed as expected, * including selection of which "=" to split at, and non-ASCII characters. * @throws FileNotFoundException if the test INI-style file is not accessible *///from w ww . j av a 2 s .com @Test public void testMetadataParsing() throws FileNotFoundException { final OriginalMetadataRequestI request = new OriginalMetadataRequestI(null); request.init(new Helper(request, new Status(), null, null, null)); request.parseOriginalMetadataTxt(ResourceUtils.getFile("classpath:original_metadata.txt")); request.buildResponse(0, null); final OriginalMetadataResponse response = (OriginalMetadataResponse) request.getResponse(); final Map<String, String> actualGlobalMetadata = new HashMap<String, String>(); for (final Entry<String, RType> keyValue : response.globalMetadata.entrySet()) { actualGlobalMetadata.put(keyValue.getKey(), ((RString) keyValue.getValue()).getValue()); } Assert.assertTrue(CollectionUtils.isEqualCollection(expectedGlobalMetadata.entrySet(), actualGlobalMetadata.entrySet())); final Map<String, String> actualSeriesMetadata = new HashMap<String, String>(); for (final Entry<String, RType> keyValue : response.seriesMetadata.entrySet()) { actualSeriesMetadata.put(keyValue.getKey(), ((RString) keyValue.getValue()).getValue()); } Assert.assertTrue(CollectionUtils.isEqualCollection(expectedSeriesMetadata.entrySet(), actualSeriesMetadata.entrySet())); }
From source file:omero.cmd.graphs.GraphUtil.java
/** * Test if the maps have the same contents, regardless of ordering. * {@code null} arguments are taken as being empty maps. * @param map1 the first map//w w w . j a v a2 s . c o m * @param map2 the second map * @return if the two maps have the same contents */ private static <K, V> boolean isEqualMaps(Map<K, V> map1, Map<K, V> map2) { if (map1 == null) { map1 = Collections.emptyMap(); } if (map2 == null) { map2 = Collections.emptyMap(); } return CollectionUtils.isEqualCollection(map1.entrySet(), map2.entrySet()); }
From source file:org.apache.ambari.server.controller.internal.ClusterResourceProviderTest.java
@SuppressWarnings("unchecked") @Test/*from w ww . ja v a2 s . co m*/ public void testBlueprintPropertyUpdaters() throws Exception { final Map<String, String> singleHostProperty1 = Collections.singletonMap("dfs.http.address", "localhost:50070"); final Map<String, String> singleHostProperty2 = Collections.singletonMap("hive.metastore.uris", "prefix.localhost.suffix"); final Map<String, String> multiHostProperty1 = Collections.singletonMap("hbase.zookeeper.quorum", "localhost"); final Map<String, String> multiHostProperty2 = Collections.singletonMap("storm.zookeeper.servers", "['localhost']"); final Map<String, String> mProperty = Collections.singletonMap("namenode_heapsize", "1025"); final Map<String, String> databaseProperty = Collections.singletonMap("javax.jdo.option.ConnectionURL", "localhost:12345"); final HostGroup hostGroup1 = createNiceMock(HostGroup.class); final HostGroup hostGroup2 = createNiceMock(HostGroup.class); expect(hostGroup1.getComponents()).andReturn(new ArrayList<String>() { { add("NAMENODE"); add("HBASE_MASTER"); add("HIVE_SERVER"); add("ZOOKEEPER_SERVER"); } }).anyTimes(); expect(hostGroup1.getHostInfo()).andReturn(Collections.singletonList("h1")).anyTimes(); expect(hostGroup2.getComponents()).andReturn(Collections.singletonList("ZOOKEEPER_SERVER")).anyTimes(); expect(hostGroup2.getHostInfo()).andReturn(Collections.singletonList("h2")).anyTimes(); Map<String, HostGroup> hostGroups = new HashMap<String, HostGroup>() { { put("host_group_1", hostGroup1); put("host_group_2", hostGroup2); } }; AmbariManagementController managementController = createNiceMock(AmbariManagementController.class); ClusterResourceProvider resourceProvider = createMockBuilder(ClusterResourceProvider.class) .withConstructor(Set.class, Map.class, AmbariManagementController.class) .withArgs(new HashSet<String>(), new HashMap<Resource.Type, String>(), managementController) .createMock(); replay(managementController, resourceProvider, hostGroup1, hostGroup2); Map<String, Map<String, String>> mapConfigurations; Field configField = ClusterResourceProvider.class.getDeclaredField("mapClusterConfigurations"); configField.setAccessible(true); mapConfigurations = (Map<String, Map<String, String>>) configField.get(resourceProvider); Map<String, PropertyUpdater> propertyUpdaterMap; Field f = ClusterResourceProvider.class.getDeclaredField("propertyUpdaters"); f.setAccessible(true); propertyUpdaterMap = (Map<String, PropertyUpdater>) f.get(resourceProvider); Assert.assertNotNull(propertyUpdaterMap); String newValue; Map.Entry<String, String> entry = singleHostProperty1.entrySet().iterator().next(); newValue = propertyUpdaterMap.get(entry.getKey()).update(hostGroups, entry.getValue()); Assert.assertEquals("h1:50070", newValue); entry = singleHostProperty2.entrySet().iterator().next(); newValue = propertyUpdaterMap.get(entry.getKey()).update(hostGroups, entry.getValue()); Assert.assertEquals("prefix.h1.suffix", newValue); entry = multiHostProperty1.entrySet().iterator().next(); newValue = propertyUpdaterMap.get(entry.getKey()).update(hostGroups, entry.getValue()); Assert.assertTrue(CollectionUtils.isEqualCollection(Arrays.asList("h1,h2".split(",")), Arrays.asList(newValue.split(",")))); entry = multiHostProperty2.entrySet().iterator().next(); newValue = propertyUpdaterMap.get(entry.getKey()).update(hostGroups, entry.getValue()); // no ordering guarantee Assert.assertTrue(newValue.equals("['h1','h2']") || newValue.equals("['h2','h1']")); entry = mProperty.entrySet().iterator().next(); newValue = propertyUpdaterMap.get(entry.getKey()).update(hostGroups, entry.getValue()); Assert.assertEquals("1025m", newValue); Map<String, String> configs = new HashMap<String, String>(); configs.put("hive_database", "External MySQL Database"); mapConfigurations.put("global", configs); entry = databaseProperty.entrySet().iterator().next(); newValue = propertyUpdaterMap.get(entry.getKey()).update(hostGroups, entry.getValue()); Assert.assertEquals("localhost:12345", newValue); verify(managementController, resourceProvider, hostGroup1, hostGroup2); }
From source file:org.apache.blur.slur.SolrLookingBlurServerTest.java
@Test public void basicFullTextQuery() throws Exception { String table = "basicFullTextQuery"; SolrServer server = TestTableCreator.newTable(table).withRowCount(1).withRecordsPerRow(2) .withRecordColumns("fam.value", "fam.mvf", "fam.mvf").create(); SolrQuery query = new SolrQuery("value0-0"); QueryResponse response = server.query(query); assertEquals("We should get our doc back.", 1l, response.getResults().getNumFound()); SolrDocument docResult = response.getResults().get(0); assertEquals("0", docResult.getFieldValue("recordid")); assertEquals("value0-0", docResult.getFieldValue("fam.value")); Collection<Object> mvfVals = docResult.getFieldValues("fam.mvf"); assertTrue("We should get all our values back[" + mvfVals + "]", CollectionUtils.isEqualCollection(mvfVals, Lists.newArrayList("value0-0", "value0-0"))); removeTable(table);/*from w w w .j a v a 2 s. c o m*/ }
From source file:org.apache.eagle.alert.coordination.model.PolicyWorkerQueue.java
@Override public boolean equals(Object other) { if (this == other) { return true; }//from www. j av a 2 s . com if (!(other instanceof PolicyWorkerQueue)) { return false; } PolicyWorkerQueue that = (PolicyWorkerQueue) other; return Objects.equals(partition, that.partition) && CollectionUtils.isEqualCollection(workers, that.workers); }
From source file:org.apache.eagle.alert.coordination.model.StreamRepartitionStrategy.java
public boolean equals(Object obj) { if (!(obj instanceof StreamRepartitionStrategy)) { return false; }/*from ww w .j av a2 s. c o m*/ StreamRepartitionStrategy o = (StreamRepartitionStrategy) obj; return partition.equals(o.partition) && CollectionUtils.isEqualCollection(totalTargetBoltIds, o.totalTargetBoltIds); }
From source file:org.apache.eagle.alert.coordination.model.StreamRouterSpec.java
@Override public boolean equals(Object other) { if (this == other) { return true; }/*w w w . ja va2 s . c om*/ if (!(other instanceof StreamRouterSpec)) { return false; } StreamRouterSpec that = (StreamRouterSpec) other; return Objects.equals(streamId, that.streamId) && Objects.equals(partition, that.partition) && CollectionUtils.isEqualCollection(targetQueue, that.targetQueue); }
From source file:org.apache.eagle.alert.engine.coordinator.PolicyDefinition.java
@Override public boolean equals(Object that) { if (that == this) { return true; }/*from w w w. j a v a 2 s. c om*/ if (!(that instanceof PolicyDefinition)) { return false; } PolicyDefinition another = (PolicyDefinition) that; if (Objects.equals(another.name, this.name) && Objects.equals(another.description, this.description) && CollectionUtils.isEqualCollection(another.inputStreams, this.inputStreams) && CollectionUtils.isEqualCollection(another.outputStreams, this.outputStreams) && (another.definition != null && another.definition.equals(this.definition)) && Objects.equals(this.definition, another.definition) && CollectionUtils.isEqualCollection(another.partitionSpec, this.partitionSpec) && another.policyStatus.equals(this.policyStatus) && another.parallelismHint == this.parallelismHint && Objects.equals(another.alertDefinition, alertDefinition)) { return true; } return false; }
From source file:org.apache.eagle.alert.engine.coordinator.PublishPartition.java
@Override public boolean equals(Object obj) { return obj instanceof PublishPartition && Objects.equal(this.streamId, ((PublishPartition) obj).getStreamId()) && Objects.equal(this.policyId, ((PublishPartition) obj).getPolicyId()) && Objects.equal(this.publishId, ((PublishPartition) obj).getPublishId()) && CollectionUtils.isEqualCollection(this.columns, ((PublishPartition) obj).getColumns()) && CollectionUtils.isEqualCollection(this.columnValues, ((PublishPartition) obj).getColumnValues()); }