Example usage for org.apache.commons.collections CollectionUtils isEqualCollection

List of usage examples for org.apache.commons.collections CollectionUtils isEqualCollection

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils isEqualCollection.

Prototype

public static boolean isEqualCollection(final Collection a, final Collection b) 

Source Link

Document

Returns true iff the given Collection s contain exactly the same elements with exactly the same cardinalities.

Usage

From source file:ai.grakn.graql.internal.reasoner.AtomicTest.java

@Test
public void testTypeInference_singleGuard() {
    GraknGraph graph = typeInferenceSet.graph();
    String patternString = "{$x isa entity1; ($x, $y);}";
    String patternString2 = "{$x isa subEntity1; ($x, $y);}";
    ReasonerAtomicQuery query = ReasonerQueries.atomic(conjunction(patternString, graph), graph);
    ReasonerAtomicQuery query2 = ReasonerQueries.atomic(conjunction(patternString2, graph), graph);
    RelationAtom atom = (RelationAtom) query.getAtom();
    RelationAtom atom2 = (RelationAtom) query2.getAtom();

    List<RelationType> possibleTypes = Lists.newArrayList(graph.getOntologyConcept(Label.of("relation1")),
            graph.getOntologyConcept(Label.of("relation3")));
    List<RelationType> relationTypes = atom.inferPossibleRelationTypes(new QueryAnswer());
    List<RelationType> relationTypes2 = atom2.inferPossibleRelationTypes(new QueryAnswer());

    assertTrue(CollectionUtils.isEqualCollection(relationTypes, possibleTypes));
    assertTrue(CollectionUtils.isEqualCollection(relationTypes2, possibleTypes));

    assertEquals(atom.getOntologyConcept(), null);
    assertEquals(atom2.getOntologyConcept(), null);
}

From source file:ai.grakn.graql.internal.reasoner.AtomicTest.java

@Test
public void testTypeInference_singleRole() {
    GraknGraph graph = typeInferenceSet.graph();
    String patternString = "{(role2: $x, $y);}";
    ReasonerAtomicQuery query = ReasonerQueries.atomic(conjunction(patternString, graph), graph);
    RelationAtom atom = (RelationAtom) query.getAtom();

    List<RelationType> possibleTypes = Lists.newArrayList(graph.getOntologyConcept(Label.of("relation1")),
            graph.getOntologyConcept(Label.of("relation2")), graph.getOntologyConcept(Label.of("relation3")));

    List<RelationType> relationTypes = atom.inferPossibleRelationTypes(new QueryAnswer());
    assertTrue(CollectionUtils.isEqualCollection(relationTypes, possibleTypes));
    assertEquals(atom.getOntologyConcept(), null);
}

From source file:com.vmware.photon.controller.common.xenon.XenonRestClientTest.java

private void checkDocumentsRetrievedInAll(int numDocuments, ImmutableMap<String, String> queryTerms,
        boolean expandContent, boolean broadCast,
        Collection<ExampleService.ExampleServiceState> expectedDocuments) throws Throwable {

    Integer iterations = 60;// w ww.j  av a2s.c  om
    if (broadCast) {
        iterations = 1;
    }

    ServiceDocumentQueryResult queryResult = null;
    Set<String> expectedDocumentNames = null;
    Set<String> actualDocumentNames = null;

    for (int i = 0; i < iterations; i++) {
        queryResult = xenonRestClient.queryDocuments(ExampleService.ExampleServiceState.class, queryTerms,
                Optional.absent(), expandContent, broadCast);

        expectedDocumentNames = expectedDocuments.stream().map(d -> d.name).collect(Collectors.toSet());
        actualDocumentNames = queryResult.documents.values().stream()
                .map(d -> Utils.fromJson(d, ExampleService.ExampleServiceState.class).name)
                .collect(Collectors.toSet());

        if (queryResult.documentLinks.size() == numDocuments) {
            break;
        }

        Thread.sleep(1000L);
    }

    assertThat(queryResult.documentLinks.size(), is(numDocuments));
    assertThat(queryResult.documents.size(), is(numDocuments));
    assertThat(CollectionUtils.isEqualCollection(expectedDocumentNames, actualDocumentNames), is(true));
    assertNull(queryResult.nextPageLink);
    assertNull(queryResult.prevPageLink);
}

From source file:ai.grakn.graql.internal.reasoner.AtomicTest.java

@Test
public void testTypeInference_singleRole_singleGuard() {
    GraknGraph graph = typeInferenceSet.graph();
    String patternString = "{(role2: $x, $y); $y isa entity1;}";
    String patternString2 = "{(role2: $x, $y); $y isa subEntity1;}";
    ReasonerAtomicQuery query = ReasonerQueries.atomic(conjunction(patternString, graph), graph);
    ReasonerAtomicQuery query2 = ReasonerQueries.atomic(conjunction(patternString2, graph), graph);
    RelationAtom atom = (RelationAtom) query.getAtom();
    RelationAtom atom2 = (RelationAtom) query2.getAtom();

    List<RelationType> possibleTypes = Lists.newArrayList(graph.getOntologyConcept(Label.of("relation1")),
            graph.getOntologyConcept(Label.of("relation3")));
    List<RelationType> relationTypes = atom.inferPossibleRelationTypes(new QueryAnswer());
    List<RelationType> relationTypes2 = atom2.inferPossibleRelationTypes(new QueryAnswer());

    assertTrue(CollectionUtils.isEqualCollection(relationTypes, possibleTypes));
    assertTrue(CollectionUtils.isEqualCollection(relationTypes2, possibleTypes));

    assertEquals(atom.getOntologyConcept(), null);
    assertEquals(atom2.getOntologyConcept(), null);
}

From source file:com.vmware.photon.controller.common.xenon.XenonRestClientTest.java

private void checkDocumentsRetrievedPageByPage(int numDocuments, int pageSize,
        ImmutableMap<String, String> queryTerms, boolean expandContent, boolean broadCast,
        Collection<ExampleService.ExampleServiceState> expectedDocuments) throws Throwable {

    Integer iterations = 60;//from   w w w  .j  av  a 2s .c  o m
    if (broadCast) {
        iterations = 1;
    }

    Set<String> expectedDocumentNames = null;
    Set<String> actualDocumentNames = null;

    for (int i = 0; i < iterations; i++) {
        ServiceDocumentQueryResult queryResult = xenonRestClient.queryDocuments(
                ExampleService.ExampleServiceState.class, queryTerms, Optional.of(pageSize), expandContent,
                broadCast);

        assertNotNull(queryResult.documents);
        assertNull(queryResult.prevPageLink);

        actualDocumentNames = new HashSet<>();
        actualDocumentNames.addAll(queryResult.documents.values().stream()
                .map(d -> Utils.fromJson(d, ExampleService.ExampleServiceState.class).name)
                .collect(Collectors.toSet()));

        expectedDocumentNames = expectedDocuments.stream().map(d -> d.name).collect(Collectors.toSet());

        while (queryResult.nextPageLink != null) {
            queryResult = xenonRestClient.queryDocumentPage(queryResult.nextPageLink);

            actualDocumentNames.addAll(queryResult.documents.values().stream()
                    .map(d -> Utils.fromJson(d, ExampleService.ExampleServiceState.class).name)
                    .collect(Collectors.toSet()));
        }

        if (actualDocumentNames.size() == numDocuments) {
            break;
        }

        Thread.sleep(1000L);
    }

    assertThat(actualDocumentNames.size(), is(numDocuments));
    assertThat(CollectionUtils.isEqualCollection(expectedDocumentNames, actualDocumentNames), is(true));
}

From source file:ProvenanceServiceTestReal.java

@Test
public void test4GetConvertedUrisFromIds() throws Exception {
    ProvenanceService.Client client = pool.getClient(APP_NAME, SERVICE_NAME, ProvenanceService.Client.class);

    try {/*from   ww w .j a  v a2s  .co  m*/
        Set<Long> docIds = new HashSet<Long>();
        for (int i = 0; i < DOCUMENT_COUNT; i++) {
            docIds.add(documentIds[i]);
        }

        Set<Long> fakeIds = new HashSet<Long>();
        for (int i = 0; i < 5; i++) {
            fakeIds.add(999999999999L + i);
        }

        Set<Long> allIds = new HashSet<>(docIds);
        allIds.addAll(fakeIds);

        ConversionResult result = client.getDocumentConvertedUrisFromIds(securityToken, allIds);
        assertEquals(fakeIds.size(), result.getIdsNotFoundSize());
        assertTrue(CollectionUtils.isEqualCollection(docIds, result.getConvertedUris()));
    } finally {
        pool.returnToPool(client);
    }
}

From source file:ProvenanceServiceTestReal.java

@Test
public void test4GetConvertedUrisFromUris() throws Exception {
    ProvenanceService.Client client = pool.getClient(APP_NAME, SERVICE_NAME, ProvenanceService.Client.class);

    try {/*from  w w  w .j  a va2s. c  om*/
        Set<String> uris = new HashSet<String>();
        for (int i = 0; i < DOCUMENT_COUNT; i++) {
            uris.add(DOCUMENT_URI + "parent/" + i);
        }
        for (int i = 0; i < 5; i++) {
            uris.add("test://uri_not_exists/" + i);
        }

        ConversionResult result = client.getDocumentConvertedUrisFromUris(securityToken, uris);
        assertEquals(5, result.getUrisNotFound().size());

        List<Long> expectedIds = new ArrayList<Long>();
        for (int i = 0; i < DOCUMENT_COUNT; i++) {
            expectedIds.add(documentIds[i]);
        }
        assertTrue(CollectionUtils.isEqualCollection(expectedIds, result.getConvertedUris()));
    } finally {
        pool.returnToPool(client);
    }
}

From source file:ProvenanceServiceTest.java

@Test
public void test4GetConvertedUrisFromIds() throws Exception {
    ProvenanceService.Client client = pool.getClient(APP_NAME, SERVICE_NAME, ProvenanceService.Client.class);

    try {/*from ww w  .  java2 s  .c o m*/
        Set<Long> docIds = new HashSet<>();
        for (int i = 0; i < DOCUMENT_COUNT; i++) {
            docIds.add(documentIds[i]);
        }

        Set<Long> fakeIds = new HashSet<Long>();
        for (int i = 0; i < 5; i++) {
            fakeIds.add(999999999999L + i);
        }

        Set<Long> allIds = new HashSet<>(docIds);
        allIds.addAll(fakeIds);

        ConversionResult result = client.getDocumentConvertedUrisFromIds(securityToken, allIds);
        assertEquals(fakeIds.size(), result.getIdsNotFoundSize());
        assertTrue(CollectionUtils.isEqualCollection(docIds, result.getConvertedUris()));
    } finally {
        pool.returnToPool(client);
    }
}

From source file:ome.services.blitz.test.utests.FilePathNamingValidatorTest.java

/**
 * Test that file path naming validation flags the correct proscriptions.
 * @throws FilePathNamingException unexpected
 *///from  www  .j a  v  a2  s . c  o  m
@Test
public void testInvalidFilePath() throws FilePathNamingException {
    final String illegalFilePath = "C:/Foo1./nUl.txt/coM5/$bar/.<>.";
    final Set<Integer> illegalCodePoints = new HashSet<Integer>();
    final Set<String> illegalPrefixes = new HashSet<String>();
    final Set<String> illegalSuffixes = new HashSet<String>();
    final Set<String> illegalNames = new HashSet<String>();

    illegalCodePoints.add(0x3A); // :
    illegalCodePoints.add(0x3C); // [
    illegalCodePoints.add(0x3E); // ]

    illegalPrefixes.add("NUL.");
    illegalPrefixes.add("$");
    illegalPrefixes.add(".");
    illegalSuffixes.add(".");
    illegalNames.add("COM5");

    final FilePathNamingValidator validator = new FilePathNamingValidator(this.conservativeRules);
    try {
        validator.validateFilePathNaming(illegalFilePath);
        Assert.fail("illegal file path passed name validation");
    } catch (FilePathNamingException fpne) {
        Assert.assertEquals(fpne.illegalFilePath, illegalFilePath);
        Assert.assertTrue(CollectionUtils.isEqualCollection(fpne.illegalCodePoints, illegalCodePoints));
        Assert.assertTrue(CollectionUtils.isEqualCollection(fpne.illegalPrefixes, illegalPrefixes));
        Assert.assertTrue(CollectionUtils.isEqualCollection(fpne.illegalSuffixes, illegalSuffixes));
        Assert.assertTrue(CollectionUtils.isEqualCollection(fpne.illegalNames, illegalNames));
    }
}

From source file:ome.services.blitz.test.utests.FilePathRestrictionsTest.java

/**
 * Assert that an actual multimap is as expected regardless of order.
 * @param actual the actual value//from w ww. j a  va2  s  .  c  o m
 * @param expected the expected value
 */
private void assertEqualMultimaps(Multimap<Integer, Integer> actual, Multimap<Integer, Integer> expected) {
    Assert.assertTrue(CollectionUtils.isEqualCollection(actual.keySet(), expected.keySet()));
    for (final Integer key : expected.keySet()) {
        Assert.assertTrue(CollectionUtils.isEqualCollection(actual.get(key), expected.get(key)));
    }
}