Example usage for java.util Collection containsAll

List of usage examples for java.util Collection containsAll

Introduction

In this page you can find the example usage for java.util Collection containsAll.

Prototype

boolean containsAll(Collection<?> c);

Source Link

Document

Returns true if this collection contains all of the elements in the specified collection.

Usage

From source file:org.apache.hadoop.hdfs.server.namenode.bookkeeper.metadata.TestBookKeeperJournalMetadataManager.java

@Test
public void testListLedgers() throws Exception {
    Set<EditLogLedgerMetadata> metadata = ImmutableSet.of(
            new EditLogLedgerMetadata(FSConstants.LAYOUT_VERSION, 1, 1, 100),
            new EditLogLedgerMetadata(FSConstants.LAYOUT_VERSION, 2, 101, 200),
            new EditLogLedgerMetadata(FSConstants.LAYOUT_VERSION, 3, 201, -1),
            new EditLogLedgerMetadata(FSConstants.LAYOUT_VERSION - 1, 4, 11, -1),
            new EditLogLedgerMetadata(FSConstants.LAYOUT_VERSION - 1, 5, 2, 10));
    for (EditLogLedgerMetadata e : metadata) {
        String fullLedgerPath = manager.fullyQualifiedPathForLedger(e);
        manager.writeEditLogLedgerMetadata(fullLedgerPath, e);
    }//from w  ww.  j ava 2 s  .  c o  m
    Collection<EditLogLedgerMetadata> allLedgers = manager.listLedgers(true);
    assertTrue("listLedgers(true) returns all ledgers and all ledgers once",
            allLedgers.containsAll(metadata) && metadata.containsAll(allLedgers));

    EditLogLedgerMetadata prev = null;
    for (EditLogLedgerMetadata curr : allLedgers) {
        if (prev != null) {
            assertTrue("List must be ordered by firsTxId", prev.getFirstTxId() <= curr.getFirstTxId());
        }
        prev = curr;
    }

    Collection<EditLogLedgerMetadata> finalizedOnly = manager.listLedgers(false);
    for (EditLogLedgerMetadata e : finalizedOnly) {
        assertFalse("listLedgers(false) does not return in-progress ledgers" + e, e.getLastTxId() == -1);
    }
    TreeSet<EditLogLedgerMetadata> expectedFinalizedOnly = new TreeSet<EditLogLedgerMetadata>();
    for (EditLogLedgerMetadata e : allLedgers) {
        if (e.getLastTxId() != -1) {
            expectedFinalizedOnly.add(e);
        }
    }
    assertTrue("listLedgers(false) returns all finalized ledgers",
            finalizedOnly.containsAll(expectedFinalizedOnly)
                    && expectedFinalizedOnly.containsAll(finalizedOnly));
}

From source file:org.rhq.plugins.jbossas.test.util.JMSConfigurationEditorTest.java

private void assertTestConfig(Configuration configuration, String topicName) {
    Configuration testConfig = createConfiguration(topicName);
    Collection<Property> retreivedProperties = configuration.getProperties();
    Collection<Property> testProperties = testConfig.getProperties();
    assert testProperties.containsAll(retreivedProperties) : "Not sure if this will ever pass";
}

From source file:org.kuali.rice.devtools.jpa.eclipselink.conv.parser.helper.resolver.AbstractJoinColumnResolver.java

private List<Expression> processReferenceField(String enclosingClass, String fieldName, String mappedClass,
        ObjectReferenceDescriptor ord) {
    final List<Expression> joinColumns = new ArrayList<Expression>();
    final Collection<String> fks = ord.getForeignKeyFields();
    if (fks == null || fks.isEmpty()) {
        LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass)
                + " field has a reference descriptor for " + fieldName
                + " but does not have any foreign keys configured");
        return joinColumns;
    }/*from w ww .j a  va 2  s  .c om*/

    final Collection<String> pks = OjbUtil.getPrimaryKeyNames(mappedClass, descriptorRepositories);

    //make sure it isn't a one to one
    if (!(pks.containsAll(fks) && fks.containsAll(pks)) && !pks.isEmpty()) {

        final ClassDescriptor cd = OjbUtil.findClassDescriptor(mappedClass, descriptorRepositories);
        final ClassDescriptor icd = getItemClassDescriptor(enclosingClass, fieldName, mappedClass, ord);
        final FieldDescriptor[] fkDescs = ord.getForeignKeyFieldDescriptors(cd);
        final FieldDescriptor[] pkDescs = icd.getPkFields();

        if (fkDescs.length != pkDescs.length) {
            LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass)
                    + " field has a collection descriptor for " + fieldName
                    + " with an foreign key that is not joined to all of the primary key fields. This is not supported in JPA.");
        }

        for (int i = 0; i < fkDescs.length; i++) {
            joinColumns.add(createJoinColumn(fkDescs[i], pkDescs[i]));
        }
    }
    return joinColumns;
}

From source file:com.netflix.genie.web.security.oauth2.pingfederate.PingFederateJWTTokenServicesUnitTests.java

/**
 * Make sure we can successfully load an authentication.
 *
 * @throws AuthenticationException On error
 * @throws InvalidTokenException   When the token is invalid
 * @throws InvalidJwtException     On invalid JWT token
 * @throws MalformedClaimException A bad claim
 *//*  w  w w  .j av a 2 s .  c  o m*/
@Test
public void canLoadAuthentication()
        throws AuthenticationException, InvalidTokenException, InvalidJwtException, MalformedClaimException {
    final JwtClaims claims = Mockito.mock(JwtClaims.class);
    final String clientId = UUID.randomUUID().toString();
    final String scope1 = "genie_admin";
    final String scope2 = UUID.randomUUID().toString();
    final Set<String> scopes = Sets.newHashSet(scope1, scope2);
    Mockito.when(claims.getClaimValue("client_id", String.class)).thenReturn(clientId);
    Mockito.when(claims.getClaimValue("scope", Collection.class)).thenReturn(scopes);
    Mockito.when(this.jwtConsumer.processToClaims(Mockito.anyString())).thenReturn(claims);

    final OAuth2Authentication authentication = this.tokenServices
            .loadAuthentication(UUID.randomUUID().toString());
    Assert.assertNull(authentication.getUserAuthentication());
    Assert.assertThat(authentication.getPrincipal(), Matchers.is(clientId));

    final Collection<GrantedAuthority> authorities = authentication.getAuthorities();
    Assert.assertThat(authorities.size(), Matchers.is(3));
    Assert.assertTrue(authorities.containsAll(Sets.newHashSet(new SimpleGrantedAuthority("ROLE_ADMIN"),
            new SimpleGrantedAuthority("ROLE_" + scope2.toUpperCase()),
            new SimpleGrantedAuthority("ROLE_USER"))));

    Mockito.verify(this.loadAuthenticationTimer, Mockito.times(1)).record(Mockito.anyLong(),
            Mockito.eq(TimeUnit.NANOSECONDS));
}

From source file:mx.edu.um.mateo.general.utils.SpringSecurityUtils.java

/**
 * Check if the current user has all of the specified roles.
 * /*from w  ww . ja v  a2  s.  com*/
 * @param roles
 *            a comma-delimited list of role names
 * @return <code>true</code> if the user is authenticated and has all the
 *         roles
 */
public boolean ifAllGranted(final String roles) {
    Collection<GrantedAuthority> inferred = findInferredAuthorities(getPrincipalAuthorities());
    return inferred.containsAll(parseAuthoritiesString(roles));
}

From source file:org.fcrepo.apix.jena.impl.LdpContainerRegistryTest.java

@Test
public void listLdpMembersTest() throws Exception {
    final URI member1 = URI.create("test:member1");
    final URI member2 = URI.create("test:member2");
    final URI containerURI = URI.create("test:Container");
    toTest.setContainer(containerURI);//  w  ww. j  a va  2s . c  o  m
    toTest.setRegistryDelegate(registryDelegate);

    final String rdf = String.format("<%s> <%s> <%s> .\n<%s> <%s> <%s> .", containerURI.toString(),
            LDP_CONTAINS, member1.toString(), containerURI.toString(), LDP_CONTAINS, member2.toString());

    when(registryDelegate.get(containerURI))
            .thenReturn(WebResource.of(IOUtils.toInputStream(rdf, "UTF-8"), "application/n-triples"));

    final Collection<URI> members = toTest.list();
    final Collection<URI> expectedMembers = Arrays.asList(member1, member2);

    assertTrue(members.containsAll(expectedMembers));
    assertTrue(expectedMembers.containsAll(members));
}

From source file:com.opengamma.engine.depgraph.DepGraphBasicTest.java

public void incrementalBuild() {
    final DepGraphTestHelper helper = helper();
    helper.addFunctionRequiring2Producing1();
    helper.addFunctionProducing2();//from  w w w  .j  a  va  2 s  . c o m
    DependencyGraphBuilder builder = helper.createBuilder(null);
    builder.setDependencyGraph(new DependencyGraph("DEFAULT"));
    builder.addTarget(helper.getRequirement2());
    final DependencyGraph graph1 = builder.getDependencyGraph();
    assertNotNull(graph1);
    assertEquals(1, graph1.getDependencyNodes().size());
    builder = helper.createBuilder(null);
    builder.setDependencyGraph(graph1);
    builder.addTarget(helper.getRequirement1());
    final DependencyGraph graph2 = builder.getDependencyGraph();
    assertNotNull(graph2);
    final Collection<DependencyNode> graph2Nodes = graph2.getDependencyNodes();
    assertEquals(2, graph2Nodes.size());
    assertTrue(graph2Nodes.containsAll(graph1.getDependencyNodes()));
    builder = helper.createBuilder(null);
    for (DependencyNode node : graph2Nodes) {
        new DependencyNode(ComputationTarget.NULL).addInputNode(node);
        if (node.getOutputValues().contains(helper.getSpec1())) {
            assertEquals(1, node.getDependentNodes().size());
        } else {
            assertEquals(2, node.getDependentNodes().size());
        }
    }
    // graph2 is now a subgraph of a larger graph containing two more nodes
    builder.setDependencyGraph(graph2);
    builder.addTarget(helper.getRequirement2Foo());
    final DependencyGraph graph3 = builder.getDependencyGraph();
    assertNotNull(graph3);
    assertEquals(2, graph3.getDependencyNodes().size());
    assertEquals(graph2.getDependencyNodes(), graph3.getDependencyNodes());
    // the build should have modified the supplied nodes
    for (DependencyNode node : graph2Nodes) {
        if (node.getOutputValues().contains(helper.getSpec1())) {
            assertEquals(0, node.getDependentNodes().size());
        } else {
            assertEquals(1, node.getDependentNodes().size());
        }
    }
}

From source file:mondrian.olap.IdBatchResolverTest.java

private void assertContains(String msg, Collection<String> strings, Collection<String> list) {
    if (!strings.containsAll(list)) {
        List<String> copy = new ArrayList<String>(list);
        copy.removeAll(strings);//from  w w  w .j ava 2 s  .  c o m
        fail(String.format("%s\nMissing: %s", msg, Arrays.toString(copy.toArray())));
    }
}

From source file:ddf.catalog.validation.impl.validator.RelationshipValidator.java

private Optional<ValidationViolation> mustHave(Collection<String> actualValues) {
    boolean isViolated;
    if (targetValues.isEmpty()) {
        isViolated = actualValues.isEmpty();
    } else {//from   w  w  w  .  j a  v  a 2s  .  c  om
        isViolated = !actualValues.containsAll(targetValues);
    }
    return getValidationViolation("must have", isViolated);
}

From source file:org.apache.hadoop.hdfs.server.namenode.TestAvatarStorageSetup.java

private void assertEqualsCol(Collection<URI> obj1, Collection<URI> obj2) {
    assertTrue(obj1.containsAll(obj2));
    assertTrue(obj2.containsAll(obj1));//  w w w  .  j  a  v a2 s  .  c o m
}