Example usage for java.util Set containsAll

List of usage examples for java.util Set containsAll

Introduction

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

Prototype

boolean containsAll(Collection<?> c);

Source Link

Document

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

Usage

From source file:com.comcast.cdn.traffic_control.traffic_router.core.external.StatsTest.java

@Test
public void itGetsApplicationStats() throws Exception {
    HttpGet httpGet = new HttpGet("http://localhost:3333/crs/stats");

    CloseableHttpResponse httpResponse = null;

    try {/*from   ww  w. ja v a  2 s  .  c  om*/

        httpResponse = httpClient.execute(httpGet);
        String responseContent = EntityUtils.toString(httpResponse.getEntity());

        ObjectMapper objectMapper = new ObjectMapper();

        Map<String, Object> data = objectMapper.readValue(responseContent,
                new TypeReference<HashMap<String, Object>>() {
                });

        assertThat(data.keySet(), containsInAnyOrder("app", "stats"));

        Map<String, Object> appData = (Map<String, Object>) data.get("app");
        assertThat(appData.keySet(),
                containsInAnyOrder("buildTimestamp", "name", "deploy-dir", "git-revision", "version"));

        Map<String, Object> statsData = (Map<String, Object>) data.get("stats");
        assertThat(statsData.keySet(),
                containsInAnyOrder("dnsMap", "httpMap", "totalDnsCount", "totalHttpCount", "totalDsMissCount",
                        "appStartTime", "averageDnsTime", "averageHttpTime", "updateTracker"));

        Map<String, Object> dnsStats = (Map<String, Object>) statsData.get("dnsMap");
        Map<String, Object> cacheDnsStats = (Map<String, Object>) dnsStats.values().iterator().next();
        assertThat(cacheDnsStats.keySet(),
                containsInAnyOrder("czCount", "geoCount", "missCount", "dsrCount", "errCount", "deepCzCount",
                        "staticRouteCount", "fedCount", "regionalDeniedCount", "regionalAlternateCount"));

        Map<String, Object> httpStats = (Map<String, Object>) statsData.get("httpMap");
        Map<String, Object> cacheHttpStats = (Map<String, Object>) httpStats.values().iterator().next();
        assertThat(cacheHttpStats.keySet(),
                containsInAnyOrder("czCount", "geoCount", "missCount", "dsrCount", "errCount", "deepCzCount",
                        "staticRouteCount", "fedCount", "regionalDeniedCount", "regionalAlternateCount"));

        Map<String, Object> updateTracker = (Map<String, Object>) statsData.get("updateTracker");
        Set<String> keys = updateTracker.keySet();
        List<String> expectedStats = Arrays.asList("lastCacheStateCheck", "lastCacheStateChange",
                "lastConfigCheck", "lastConfigChange");

        if (!keys.containsAll(expectedStats)) {

            StringJoiner joiner = new StringJoiner(",");
            for (String stat : expectedStats) {
                joiner.add(stat);
            }

            fail("Missing at least one of the following keys '" + joiner.toString() + "'");
        }

    } finally {
        if (httpResponse != null)
            httpResponse.close();
    }
}

From source file:org.apache.taverna.commandline.data.InputsHandler.java

public void checkProvidedInputs(Map<String, InputWorkflowPort> portMap, CommandLineOptions options)
        throws InputMismatchException, IOException {
    if (options.hasInputBundle()) {
        try (Bundle inputBundle = openInputBundle(options)) {
            Path inputs = DataBundles.getInputs(inputBundle);
            Set<String> expected = portMap.keySet();
            Set<String> provided = DataBundles.getPorts(inputs).keySet();
            if (!provided.containsAll(expected)) {
                throw new InputMismatchException("Missing inputs", expected, provided);
            }//from ww w.  j  av  a2s.  co m
        }
        // inputFiles/values ignored if input bundle is provided
        return;
    }

    // we dont check for the document
    Set<String> providedInputNames = new HashSet<String>();
    for (int i = 0; i < options.getInputFiles().length; i += 2) {
        // If it already contains a value for the input port, e.g
        // two inputs are provided for the same port
        if (providedInputNames.contains(options.getInputFiles()[i])) {
            throw new InputMismatchException("Two input values were provided for the same input port "
                    + options.getInputFiles()[i] + ".", null, null);
        }
        providedInputNames.add(options.getInputFiles()[i]);
    }

    for (int i = 0; i < options.getInputValues().length; i += 2) {
        // If it already contains a value for the input port, e.g
        // two inputs are provided for the same port
        if (providedInputNames.contains(options.getInputValues()[i])) {
            throw new InputMismatchException("Two input values were provided for the same input port "
                    + options.getInputValues()[i] + ".", null, null);
        }
        providedInputNames.add(options.getInputValues()[i]);
    }

    if (portMap.size() * 2 != (options.getInputFiles().length + options.getInputValues().length)) {
        throw new InputMismatchException(
                "The number of inputs provided does not match the number of input ports.", portMap.keySet(),
                providedInputNames);
    }

    for (String portName : portMap.keySet()) {
        if (!providedInputNames.contains(portName)) {
            throw new InputMismatchException(
                    "The provided inputs does not contain an input for the port '" + portName + "'",
                    portMap.keySet(), providedInputNames);
        }
    }
}

From source file:org.mitre.uma.service.impl.TestDefaultPermissionService.java

@Before
public void prepare() {
    rs1 = new ResourceSet();
    rs1.setName(rs1Name);//  w  w w.  j a va 2s . c o m
    rs1.setOwner(rs1Owner);
    rs1.setId(rs1Id);
    rs1.setScopes(scopes1);

    rs2 = new ResourceSet();
    rs2.setName(rs2Name);
    rs2.setOwner(rs2Owner);
    rs2.setId(rs2Id);
    rs2.setScopes(scopes2);

    // have the repository just pass the argument through
    when(permissionRepository.save(Matchers.any(PermissionTicket.class)))
            .then(AdditionalAnswers.returnsFirstArg());

    when(scopeService.scopesMatch(anySetOf(String.class), anySetOf(String.class))).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            @SuppressWarnings("unchecked")
            Set<String> expected = (Set<String>) arguments[0];
            @SuppressWarnings("unchecked")
            Set<String> actual = (Set<String>) arguments[1];

            return expected.containsAll(actual);
        }
    });

}

From source file:at.ac.univie.isc.asio.security.HttpMethodRestrictionFilter.java

@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse response,
        final FilterChain chain) throws IOException, ServletException {
    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    final Authentication authentication = org.springframework.security.core.context.SecurityContextHolder
            .getContext().getAuthentication();
    if (authentication != null && HttpMethod.GET.name().equalsIgnoreCase(request.getMethod())) {
        logger.debug("applying " + RESTRICTION + " to " + authentication);
        Set<GrantedAuthority> restricted = RESTRICTION.mapAuthorities(authentication.getAuthorities());
        if (restricted.isEmpty()) { // anonymous and remember me tokens require at least one authority
            restricted = Collections.<GrantedAuthority>singleton(Role.NONE);
        }// w w  w.  java  2 s . c om
        if (!restricted.containsAll(authentication.getAuthorities())) {
            final AbstractAuthenticationToken replacement = copy(authentication, restricted);
            replacement.setDetails(authentication.getDetails());
            logger.debug("injecting " + replacement);
            org.springframework.security.core.context.SecurityContextHolder.getContext()
                    .setAuthentication(replacement);
        } else {
            logger.debug("skip restricting " + authentication + " as it contains no restricted authorities");
        }
    } else {
        logger.debug("skip restricting " + authentication + " on HTTP method " + request.getMethod());
    }
    chain.doFilter(request, response);
}

From source file:com.baidu.rigel.biplatform.tesseract.isservice.search.service.impl.SearchIndexServiceImpl.java

/**
 * /* w w  w.  ja v  a  2  s . c  om*/
 * ???
 * @param idxMeta ?
 * @param query 
 * @return boolean
 */
private boolean indexMetaContains(IndexMeta idxMeta, QueryRequest query) {
    boolean result = false;
    if (idxMeta == null || query == null) {
        return result;
    }
    Set<String> idxSelect = idxMeta.getSelectList(false);

    if (!CollectionUtils.isEmpty(idxSelect) && idxSelect.containsAll(query.getSelect().getQueryProperties())) {
        for (QueryMeasure qm : query.getSelect().getQueryMeasures()) {
            if (!idxSelect.contains(qm.getProperties())) {
                result = false;
                break;
            } else {
                result = true;
            }
        }

        if (query.getWhere() != null && query.getWhere().getAndList() != null && result) {
            for (Expression ex : query.getWhere().getAndList()) {
                if (!idxSelect.contains(ex.getProperties())) {
                    result = false;
                    break;
                } else {
                    result = true;
                }
            }
        }

    }
    return result;

}

From source file:org.fcrepo.apix.routing.impl.ServiceDocumentGeneratorTest.java

@Test
public void endpointURITest() {
    when(binding.getExtensionsFor(RESOURCE_URI)).thenReturn(Arrays.asList(EXPOSING_EXTENSION_RESOURCE_SCOPED,
            EXPOSING_EXTENSION_UNREGISTERED, EXPOSING_EXTENSION_REPOSITORY_SCOPED, INTERCEPTING_EXTENSION));

    final Model doc = parse(toTest.getServiceDocumentFor(RESOURCE_URI, routing, "text/turtle"));

    final String sparql = "CONSTRUCT { ?endpoint <test:/endpointFor> ?serviceInstance . } WHERE { "
            + String.format("?serviceInstance <%s> <%s> . ", RDF_TYPE, CLASS_SERVICE_INSTANCE)
            + String.format("?serviceInstance <%s> ?endpoint . ", PROP_HAS_ENDPOINT) + "}";

    final Set<URI> canonicalEndpoints = subjectsOf(query(sparql, doc));

    assertEquals(3, canonicalEndpoints.size());

    assertTrue(canonicalEndpoints.containsAll(Arrays.asList(REPOSITORY_SCOPE_ENDPOINT_URI,
            RESOURCE_SCOPE_ENDPOINT_URI, UNREGISTERED_ENDPOINT_URI)));
}

From source file:org.fcrepo.apix.routing.impl.ServiceDocumentGeneratorTest.java

@Test
public void serviceInstanceOfTest() {
    when(binding.getExtensionsFor(RESOURCE_URI)).thenReturn(Arrays.asList(EXPOSING_EXTENSION_RESOURCE_SCOPED,
            EXPOSING_EXTENSION_UNREGISTERED, EXPOSING_EXTENSION_REPOSITORY_SCOPED, INTERCEPTING_EXTENSION));

    final Model doc = parse(toTest.getServiceDocumentFor(RESOURCE_URI, routing, "text/turtle"));

    final String sparql = "CONSTRUCT { ?service <test:/isPresentFromInstance> ?serviceInstance . } WHERE { "
            + String.format("?serviceInstance <%s> <%s> . ", RDF_TYPE, CLASS_SERVICE_INSTANCE)
            + String.format("?serviceInstance <%s> ?service . ", PROP_IS_SERVICE_INSTANCE_OF) + "}";

    final Set<URI> servicesFromInstances = subjectsOf(query(sparql, doc));

    assertEquals(3, servicesFromInstances.size());

    assertTrue(servicesFromInstances.containsAll(
            Arrays.asList(REPOSITORY_SCOPE_SERVICE_URI, RESOURCE_SCOPE_SERVICE_URI, UNREGISTERED_SERVICE_URI)));

}

From source file:org.fcrepo.apix.routing.impl.ServiceDocumentGeneratorTest.java

@Test
public void functionOfTest() throws Exception {
    when(binding.getExtensionsFor(RESOURCE_URI)).thenReturn(Arrays.asList(EXPOSING_EXTENSION_RESOURCE_SCOPED,
            EXPOSING_EXTENSION_UNREGISTERED, EXPOSING_EXTENSION_REPOSITORY_SCOPED));

    final Model doc = parse(toTest.getServiceDocumentFor(RESOURCE_URI, routing, "text/turtle"));

    final String sparql = "CONSTRUCT { ?service <test:/rel> ?serviceInstance . } WHERE { "
            + String.format("?serviceInstance <%s> <%s> . ", PROP_IS_FUNCTION_OF, RESOURCE_URI)
            + String.format("?serviceInstance <%s> ?service . ", PROP_IS_SERVICE_INSTANCE_OF) + "}";

    final Set<URI> matchingServices = subjectsOf(query(sparql, doc));

    assertEquals(2, matchingServices.size());
    assertTrue(//  w  ww.  ja v  a 2  s  .  c  o  m
            matchingServices.containsAll(Arrays.asList(RESOURCE_SCOPE_SERVICE_URI, UNREGISTERED_SERVICE_URI)));

}

From source file:biz.netcentric.cq.tools.actool.validators.impl.AceBeanValidatorImpl.java

@Override
public boolean validateRestrictions(final AceBean tmpAceBean, final AccessControlManager aclManager)
        throws InvalidRepGlobException, InvalidRestrictionsException {
    boolean valid = true;

    final List<Restriction> restrictions = tmpAceBean.getRestrictions();
    if (restrictions.isEmpty()) {
        return true;
    }//from   w  w w .j av  a 2 s  .  com

    final String principal = tmpAceBean.getPrincipalName();

    final Set<String> restrictionNamesFromAceBean = new HashSet<String>();
    for (Restriction restriction : restrictions) {
        restrictionNamesFromAceBean.add(restriction.getName());
    }

    final Set<String> allowedRestrictionNames = getSupportedRestrictions(aclManager);

    if (!allowedRestrictionNames.containsAll(restrictionNamesFromAceBean)) {
        restrictionNamesFromAceBean.removeAll(allowedRestrictionNames);
        valid = false;
        final String errorMessage = getBeanDescription(this.currentBeanCounter, principal)
                + ",  this repository doesn't support following restriction(s): " + restrictionNamesFromAceBean;
        throw new InvalidRestrictionsException(errorMessage);
    }

    return valid;
}

From source file:org.marketcetera.photon.internal.marketdata.DataFlowManager.java

@Override
public final synchronized void setSourceFeed(final IMarketDataFeed feed) {
    /*//from   ww w. ja va  2 s.  co  m
     * This method restarts all modules even if the feed has not changed, in
     * case anything went wrong the previous time.
     */
    ModuleURN module = feed == null ? null : feed.getURN();
    if (mSourceModule != null) {
        for (ModuleURN subscriber : mSubscribers.values()) {
            stopModule(subscriber, false);
        }
    }
    for (K key : mItems.keySet()) {
        resetItem(key);
    }
    mSourceModule = null;
    if (feed != null) {
        Set<Capability> capabilities = feed.getCapabilities();
        if (capabilities.containsAll(mRequiredCapabilities)) {
            mSourceModule = module;
            for (ModuleURN subscriber : mSubscribers.values()) {
                startModule(subscriber);
            }
        } else {
            Messages.DATA_FLOW_MANAGER_CAPABILITY_UNSUPPORTED.info(this, feed.getName(), capabilities,
                    mRequiredCapabilities);
        }
    }
}