Example usage for java.util List containsAll

List of usage examples for java.util List containsAll

Introduction

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

Prototype

boolean containsAll(Collection<?> c);

Source Link

Document

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

Usage

From source file:eu.freme.eservices.epublishing.webservice.EPubTest.java

@Ignore
@Test/*from   www .  jav  a  2 s  .  c om*/
public void TestAlice() throws IOException {
    String title = "Alice in Utopia";
    String author = "Joske Vermeulen";
    String author2 = "Marieke Vermalen";
    String description = "Dit is een heel mooi boekske.";

    File zippedHTMLFile = new File("src/test/resources/alice.zip");
    System.out.println("Converting " + zippedHTMLFile + " to EPUB format.");

    Metadata metadata = new Metadata();
    ArrayList<String> titles = new ArrayList<>();
    ArrayList<String> authors = new ArrayList<>();
    ArrayList<String> descriptions = new ArrayList<>();
    titles.add(title);
    authors.add(author);
    authors.add(author2);
    metadata.setTitles(titles);
    //metadata.setAuthors(authors);
    descriptions.add(description);
    metadata.setDescriptions(descriptions);
    Identifier id = new Identifier(null, "urn:ean:1234-7956-1356-1123");
    metadata.setIdentifier(id);

    Gson gson = new Gson();

    // create body part containing the ePub file
    FileDataBodyPart ePubFilePart = new FileDataBodyPart("htmlZip", zippedHTMLFile);

    // the form, to which parameters and binary content can be added
    FormDataMultiPart multiPart = new FormDataMultiPart();
    multiPart.bodyPart(ePubFilePart); // add ePub
    multiPart.field("metadata", gson.toJson(metadata));
    System.out.println(gson.toJson(metadata));

    // now send it to the service
    Response response = target.path("e-publishing/html").request("application/epub+zip")
            .post(Entity.entity(multiPart, multiPart.getMediaType()));
    InputStream in = response.readEntity(InputStream.class);

    // write it to a (temporary) file
    File ePubFile = File.createTempFile("alice", ".epub");
    System.out.println("Writing result to " + ePubFile);
    IOUtils.copy(in, new FileOutputStream(ePubFile));

    //read file and perform checks
    EpubReader r = new EpubReader();
    Book b = r.readEpub(new FileInputStream(ePubFile));
    List<String> bookTitles = b.getMetadata().getTitles();
    List<CreatorContributor> bookAuthors = b.getMetadata().getAuthors();
    List<String> bookAuthorsNames = new ArrayList<>();

    for (CreatorContributor a : bookAuthors) {
        bookAuthorsNames.add(a.getFirstname() + " " + a.getLastname());
    }

    Assert.assertTrue(bookTitles.containsAll(titles));
    Assert.assertTrue(titles.containsAll(bookTitles));
    System.out.println(bookAuthorsNames);
    Assert.assertTrue(bookAuthorsNames.containsAll(authors));
    Assert.assertTrue(authors.containsAll(bookAuthorsNames));
}

From source file:hsa.awp.rule.facade.RuleFacadeTest.java

@Test
@Transactional/*from  w w w .  jav a 2 s. c om*/
public void testFindAllRules() {
    // create some rules
    List<Rule> rules = generateRules(10);
    for (Rule rule : rules) {
        // save the rule
        facade.saveRule(rule);
    }

    // try to find all rules again
    List<Rule> found = facade.findAllRules();
    assertEquals(10, found.size());
    assertTrue("has to contain all rules", rules.containsAll(found));
}

From source file:org.glite.slcs.struts.action.AddAccessControlRuleAction.java

protected ActionForward executeAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    // cancel clicked on addRule.jsp?
    if (isCancelled(request)) {
        LOG.debug("cancelled");
        return mapping.findForward("admin.go.listRules");
    }/*from ww w .j av  a 2s . c  om*/

    if (isAddRuleAction(request)) {
        LOG.info("new rule");
        AccessControlRuleForm ruleForm = (AccessControlRuleForm) form;
        AccessControlRuleBean ruleBean = newRule(ruleForm, request);
        request.setAttribute("ruleBean", ruleBean);
        // forward/send response
        return mapping.findForward("admin.page.addRule");
    } else if (isAddRuleAttributeAction(request)) {
        LOG.info("adding rule attribute");
        AccessControlRuleForm ruleForm = (AccessControlRuleForm) form;
        AccessControlRuleBean ruleBean = addRuleAttribute(ruleForm, request);
        request.setAttribute("ruleBean", ruleBean);
        // forward/send response
        return mapping.findForward("admin.page.addRule");
    } else if (isDeleteRuleAttributeAction(request)) {
        LOG.debug("delete rule attribute");
        AccessControlRuleForm ruleForm = (AccessControlRuleForm) form;
        AccessControlRuleBean ruleBean = deleteRuleAttribute(ruleForm, request);
        request.setAttribute("ruleBean", ruleBean);
        // forward/send response
        return mapping.findForward("admin.page.addRule");
    } else if (isSaveRuleAction(request)) {
        LOG.info("save rule");
        // read rule group and attributes from form
        AccessControlRuleForm ruleForm = (AccessControlRuleForm) form;
        GroupManager groupManager = GroupManagerFactory.getInstance();
        List userAttributes = getUserAttributes(request);
        List ruleAttributes = getValidRuleAttributes(ruleForm);
        String ruleGroup = ruleForm.getGroup();
        if (groupManager.inGroup(ruleGroup, userAttributes)) {
            // TODO: check group ACL rule constraint
            Group group = groupManager.getGroup(ruleGroup);
            List attributesContraint = group.getRuleConstraints();
            if (ruleAttributes.containsAll(attributesContraint)) {
                AccessControlRule rule = new AccessControlRule(ruleGroup);
                rule.setAttributes(ruleAttributes);
                LOG.info("save rule: " + rule);
                AccessControlListEditor editor = AccessControlListEditorFactory.getInstance();
                editor.addAccessControlRule(rule);
                return mapping.findForward("admin.go.listRules");
            } else {
                // use ActionMessage for error...
                LOG.warn("rule does not contain the mandatory attributes constraint: " + attributesContraint);
                ActionMessages messages = new ActionMessages();
                StringBuffer messageText = new StringBuffer();
                messageText.append("<ul>");
                Iterator attributes = attributesContraint.iterator();
                while (attributes.hasNext()) {
                    Attribute attribute = (Attribute) attributes.next();
                    messageText.append("<li>").append(attribute.getDisplayName());
                    messageText.append(" = ").append(attribute.getValue());
                    messageText.append("</li>");
                }
                messageText.append("</ul>");
                ActionMessage warn = new ActionMessage("rule.error.save.constraint.missing", ruleGroup,
                        messageText);
                messages.add(ActionMessages.GLOBAL_MESSAGE, warn);
                saveErrors(request, messages);
                AccessControlRuleBean ruleBean = new AccessControlRuleBean();
                List userGroupNames = groupManager.getGroupNames(userAttributes);
                ruleBean.setUserGroups(userGroupNames);
                ruleBean.setGroup(ruleGroup);
                ruleBean.setAttributes(ruleAttributes);
                // add a new empty attributes
                ruleBean.addEmptyAttribute();
                request.setAttribute("ruleBean", ruleBean);
                // forward/send response
                return mapping.findForward("admin.page.addRule");
            }
        } else {
            // use ActionMessage for error...
            LOG.error("User: " + userAttributes + " is not a member of group: " + ruleGroup);
            ActionMessages messages = new ActionMessages();
            ActionMessage error = new ActionMessage("user.error.notmember", userAttributes, ruleGroup);
            messages.add(ActionMessages.GLOBAL_MESSAGE, error);
            saveErrors(request, messages);
        }

    }
    LOG.warn("Unknown action");
    return mapping.findForward("admin.go.home");
}

From source file:org.glite.slcs.struts.action.CreateAccessControlRuleAction.java

protected ActionForward executeAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    // cancel clicked on addRule.jsp?
    if (isCancelled(request)) {
        LOG.debug("cancelled");
        return mapping.findForward("admin.go.home");
    }/*  ww  w  . ja va 2  s  .c om*/

    if (isCreateRuleAction(request)) {
        LOG.info("new rule");
        AccessControlRuleForm ruleForm = (AccessControlRuleForm) form;
        AccessControlRuleBean ruleBean = createRuleBean(ruleForm, request);
        request.setAttribute("ruleBean", ruleBean);
        // forward/send response
        return mapping.findForward("admin.page.createRule");
    }

    if (isChangeRuleGroupAction(request)) {
        LOG.info("change rule group");
        AccessControlRuleForm ruleForm = (AccessControlRuleForm) form;
        AccessControlRuleBean ruleBean = createRuleBean(ruleForm, request);

        // TODO add already existing attributes defined in form

        request.setAttribute("ruleBean", ruleBean);
        // forward/send response
        return mapping.findForward("admin.page.createRule");
    }

    if (isAddRuleAttributeAction(request)) {
        LOG.info("adding rule attribute");
        AccessControlRuleForm ruleForm = (AccessControlRuleForm) form;
        AccessControlRuleBean ruleBean = addRuleAttribute(ruleForm, request);
        request.setAttribute("ruleBean", ruleBean);
        // forward/send response
        return mapping.findForward("admin.page.createRule");
    }

    if (isDeleteRuleAttributeAction(request)) {
        LOG.debug("delete rule attribute");
        AccessControlRuleForm ruleForm = (AccessControlRuleForm) form;
        AccessControlRuleBean ruleBean = deleteRuleAttribute(ruleForm, request);
        request.setAttribute("ruleBean", ruleBean);
        // forward/send response
        return mapping.findForward("admin.page.createRule");
    }

    if (isSaveRuleAction(request)) {
        LOG.info("save rule");
        // read rule group and attributes from form
        AccessControlRuleForm ruleForm = (AccessControlRuleForm) form;
        GroupManager groupManager = GroupManagerFactory.getInstance();
        List userAttributes = getUserAttributes(request);
        String ruleGroup = ruleForm.getGroupName();

        if (groupManager.inGroup(ruleGroup, userAttributes) || groupManager.isAdministrator(userAttributes)) {
            // check group ACL rule constraint
            List ruleAttributes = getValidRuleAttributes(ruleForm);
            Group group = groupManager.getGroup(ruleGroup);
            List attributesContraint = group.getRuleAttributesConstraint();

            // TODO: check if rule contains constraint but not only the constrained attribute

            if (ruleAttributes.containsAll(attributesContraint)) {
                AccessControlRule rule = new AccessControlRule(ruleGroup);
                rule.setAttributes(ruleAttributes);
                LOG.info("save rule: " + rule);
                AccessControlListEditor editor = AccessControlListEditorFactory.getInstance();
                editor.addAccessControlRule(rule);
                return mapping.findForward("admin.go.listRules");
            } else {
                // use ActionMessage for error...
                LOG.warn("rule does not contain all the mandatory attributes: " + attributesContraint);
                ActionMessages messages = new ActionMessages();
                StringBuffer messageText = new StringBuffer();
                Iterator attributes = attributesContraint.iterator();
                while (attributes.hasNext()) {
                    Attribute attribute = (Attribute) attributes.next();
                    messageText.append(attribute.getDisplayName());
                    messageText.append(" = ").append(attribute.getValue());
                }
                ActionMessage warn = new ActionMessage("rule.error.save.constraint.missing", ruleGroup,
                        messageText);
                messages.add(ActionMessages.GLOBAL_MESSAGE, warn);
                saveErrors(request, messages);
                // set the rule bean again
                List userGroupNames = null;
                if (groupManager.isAdministrator(userAttributes)) {
                    userGroupNames = groupManager.getGroupNames();
                } else {
                    userGroupNames = groupManager.getGroupNames(userAttributes);
                }
                AccessControlRuleBean ruleBean = new AccessControlRuleBean();
                ruleBean.setUserGroupNames(userGroupNames);
                ruleBean.setGroupName(ruleGroup);
                ruleBean.addAttributes(ruleAttributes);
                ruleBean.addConstrainedAttributes(attributesContraint);
                ruleBean.updateAttributesDiplayName();
                request.setAttribute("ruleBean", ruleBean);
                // forward/send response
                return mapping.findForward("admin.page.createRule");
            }
        } else {
            // use ActionMessage for error...
            LOG.error("User: " + userAttributes + " is not a member of group: " + ruleGroup);
            ActionMessages messages = new ActionMessages();
            ActionMessage error = new ActionMessage("user.error.notmember", userAttributes, ruleGroup);
            messages.add(ActionMessages.GLOBAL_MESSAGE, error);
            saveErrors(request, messages);
        }

    } // save rule

    LOG.info("default action: new rule");
    AccessControlRuleForm ruleForm = (AccessControlRuleForm) form;
    AccessControlRuleBean ruleBean = createRuleBean(ruleForm, request);
    request.setAttribute("ruleBean", ruleBean);
    // forward/send response
    return mapping.findForward("admin.page.createRule");

}

From source file:org.finra.dm.core.ArgumentParserTest.java

@Test
public void testAddArgument() {
    Option opt1 = new Option("a", "some_flag", false, "Some flag parameter");
    Option opt2 = new Option("b", "some_parameter", true, "Some parameter with an argument");

    List<String> optionsIn = Arrays.asList(optionToString(opt1), optionToString(opt2));

    ArgumentParser argParser = new ArgumentParser("");

    argParser.addArgument(opt1, true);//  w  ww.j ava 2  s  . co  m
    argParser.addArgument(opt2.getOpt(), opt2.getLongOpt(), opt2.hasArg(), opt2.getDescription(), false);

    Collection resultOptions = argParser.getConfiguredOptions();

    List<String> optionsOut = new ArrayList<>();

    for (Object obj : resultOptions) {
        assertTrue(obj instanceof Option);
        optionsOut.add(optionToString((Option) obj));
    }

    optionsOut.containsAll(optionsIn);
    optionsIn.containsAll(optionsOut);
}

From source file:org.apache.geode.internal.util.CollectionUtilsJUnitTest.java

@Test
public void testFindAll() {
    final List<Integer> numbers = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9);

    // accept all even numbers
    final List<Integer> matches = CollectionUtils.findAll(numbers, number -> (number % 2 == 0));

    assertNotNull(matches);/* w ww.  j a v a 2 s .com*/
    assertFalse(matches.isEmpty());
    assertTrue(matches.containsAll(Arrays.asList(0, 2, 4, 6, 8)));
}

From source file:com.splicemachine.derby.utils.SpliceAdminIT.java

@Test
@Category(SlowTest.class)
public void testGetConglomerateIDsAllInSchema() throws Exception {
    String TABLE_NAME = "ZONING1";
    SpliceUnitTest.MyWatcher tableWatcher = new SpliceUnitTest.MyWatcher(TABLE_NAME, CLASS_NAME,
            "(PARCELID INTEGER UNIQUE NOT NULL, ADDRESS VARCHAR(15), BOARDDEC VARCHAR(11), EXSZONE VARCHAR(8), PRPZONE VARCHAR(8), HEARDATE DATE)");
    tableDAO.drop(CLASS_NAME, TABLE_NAME);
    tableWatcher.create(Description.createSuiteDescription(CLASS_NAME, "testGetConglomerateIDsAllInSchema"));
    List<Map> tableCluster = TestUtils.tableLookupByNumberNoPrint(methodWatcher);

    List<Long> actualConglomIDs = new ArrayList<Long>();
    long[] conglomids = methodWatcher.getOrCreateConnection().getConglomNumbers(CLASS_NAME, null);
    Assert.assertTrue(conglomids.length > 0);
    for (long conglomID : conglomids) {
        actualConglomIDs.add(conglomID);
    }/*from   w  ww. j a v  a  2 s . c om*/
    List<Long> expectedConglomIDs = new ArrayList<Long>();
    for (Map m : tableCluster) {
        expectedConglomIDs.add((Long) m.get("CONGLOMERATENUMBER"));
    }
    Assert.assertTrue("Expected: " + expectedConglomIDs + " got: " + actualConglomIDs,
            expectedConglomIDs.containsAll(actualConglomIDs));
}

From source file:eu.freme.eservices.epublishing.webservice.EPubTest.java

@Ignore
@Test/*from   w  w  w  .  j  a v  a  2s.  co m*/
public void TestSections() throws IOException {
    String title = "Alice in Utopia";
    String author = "Joske Vermeulen";

    File zippedHTMLFile = new File("src/test/resources/alice.zip");
    System.out.println("Converting " + zippedHTMLFile + " to EPUB format.");

    Metadata metadata = new Metadata();
    ArrayList<String> titles = new ArrayList<>();
    ArrayList<String> authors = new ArrayList<>();
    ArrayList<Section> toc = new ArrayList<>();
    titles.add(title);
    authors.add(author);
    metadata.setTitles(titles);
    //metadata.setAuthors(authors);
    toc.add(new Section("Chapter 1", "01.xhtml"));
    toc.add(new Section("Chapter 2", "02.xhtml"));
    metadata.setTableOfContents(toc);

    Gson gson = new Gson();

    // create body part containing the ePub file
    FileDataBodyPart ePubFilePart = new FileDataBodyPart("htmlZip", zippedHTMLFile);

    // the form, to which parameters and binary content can be added
    FormDataMultiPart multiPart = new FormDataMultiPart();
    multiPart.bodyPart(ePubFilePart); // add ePub
    multiPart.field("metadata", gson.toJson(metadata));

    // now send it to the service
    Response response = target.path("e-publishing/html").request("application/epub+zip")
            .post(Entity.entity(multiPart, multiPart.getMediaType()));
    InputStream in = response.readEntity(InputStream.class);

    // write it to a (temporary) file
    File ePubFile = File.createTempFile("alice", ".epub");
    System.out.println("Writing result to " + ePubFile);
    IOUtils.copy(in, new FileOutputStream(ePubFile));

    //read file and perform checks
    EpubReader r = new EpubReader();
    Book b = r.readEpub(new FileInputStream(ePubFile));
    List<String> bookTitles = b.getMetadata().getTitles();
    List<CreatorContributor> bookAuthors = b.getMetadata().getAuthors();
    List<String> bookAuthorsNames = new ArrayList<>();

    for (CreatorContributor a : bookAuthors) {
        bookAuthorsNames.add(a.getFirstname() + " " + a.getLastname());
    }

    Assert.assertTrue("All titles are in the EPUB.", bookTitles.containsAll(titles));
    Assert.assertTrue("All EPUB titles are in the given titles.", titles.containsAll(bookTitles));
    System.out.println(bookAuthorsNames);
    Assert.assertTrue("All authors are in the EPUB.", bookAuthorsNames.containsAll(authors));
    Assert.assertTrue("All EPUB authors are in the given authors.", authors.containsAll(bookAuthorsNames));
}

From source file:fi.vm.sade.organisaatio.auth.PermissionChecker.java

public void checkSaveOrganisation(OrganisaatioDTO organisaatio, boolean update) {
    final OrganisaatioContext authContext = OrganisaatioContext.get(organisaatio);

    if (update) {
        final Organisaatio current = organisaatioDAO.findByOid(organisaatio.getOid());

        if (!Objects.equal(current.getNimi(), mkt2entity.apply(organisaatio.getNimi()))) {
            LOG.info("Nimi muuttunut");

            // name changed
            checkPermission(permissionService.userCanEditName(authContext));
        }/*from ww w. j ava  2  s  . c  o m*/
        if (OrganisaatioUtil.isSameDay(organisaatio.getAlkuPvm(), current.getAlkuPvm()) == false) {
            LOG.info("Alkupivmr muuttunut: " + current.getAlkuPvm() + " -> "
                    + organisaatio.getAlkuPvm());

            // date(s) changed
            checkPermission(permissionService.userCanEditDates(authContext));
        }
        if (OrganisaatioUtil.isSameDay(organisaatio.getLakkautusPvm(), current.getLakkautusPvm()) == false) {
            LOG.info("Lakkautuspivmr muuttunut: " + current.getLakkautusPvm() + " -> "
                    + organisaatio.getLakkautusPvm());

            // date(s) changed
            checkPermission(permissionService.userCanEditDates(authContext));
        }
        if (!(Objects.equal(organisaatio.getAlkuPvm(), current.getAlkuPvm())
                && Objects.equal(organisaatio.getLakkautusPvm(), current.getLakkautusPvm()))) {
            // date(s) changed
            checkPermission(permissionService.userCanEditDates(authContext));
        }
        // TODO organisation type
        List<String> stringTyypit = Lists.newArrayList(Iterables.transform(organisaatio.getTyypit(),

                new Function<OrganisaatioTyyppi, String>() {
                    public String apply(OrganisaatioTyyppi input) {
                        return input.value();

                    }
                }));
        if (!(stringTyypit.size() == current.getTyypit().size()
                && stringTyypit.containsAll(current.getTyypit()))) {
            ///XXX what then?
        }
        checkPermission(permissionService.userCanUpdateOrganisation(authContext));
    } else {
        checkPermission(permissionService
                .userCanCreateOrganisation(OrganisaatioContext.get(organisaatio.getParentOid())));
        //TODO types
    }
}

From source file:org.keycloak.testsuite.console.authentication.FlowsTest.java

@Test
public void actionsTest() {
    //rest: add or copy flow to test navigation (browser)
    flowsPage.selectFlowOption(Flows.FlowOption.BROWSER);
    flowsPage.clickCopy();/*from w  w  w  .j ava 2s. co  m*/
    modalDialog.ok();

    flowsPage.table().performAction("Cookie", FlowsTable.Action.DELETE);
    modalDialog.confirmDeletion();
    assertAlertSuccess();
    flowsPage.table().performAction("Kerberos", FlowsTable.Action.DELETE);
    modalDialog.confirmDeletion();
    assertAlertSuccess();
    flowsPage.table().performAction("Copy Of Browser Forms", FlowsTable.Action.ADD_FLOW);
    createFlowPage.form().setValues("nestedFlow", "testDesc", CreateFlowForm.FlowType.FORM);
    assertAlertSuccess();
    flowsPage.table().performAction("Copy Of Browser Forms", FlowsTable.Action.ADD_EXECUTION);
    createExecutionPage.form().selectProviderOption(CreateExecutionForm.ProviderOption.RESET_PASSWORD);
    createExecutionPage.form().save();
    assertAlertSuccess();

    //UI
    List<String> expectedOrder = new ArrayList<>();
    Collections.addAll(expectedOrder, "Identity Provider Redirector", "Copy Of Browser Forms",
            "Username Password Form", "OTP Form", "NestedFlow", "Reset Password");

    assertEquals(6, flowsPage.table().getFlowsAliasesWithRequirements().size());
    assertTrue(expectedOrder.containsAll(flowsPage.table().getFlowsAliasesWithRequirements().keySet()));

    //REST
    assertEquals("identity-provider-redirector",
            getLastFlowFromREST().getAuthenticationExecutions().get(0).getAuthenticator());
    String tmpFlowAlias = getLastFlowFromREST().getAuthenticationExecutions().get(1).getFlowAlias();
    assertEquals("Copy of browser forms", tmpFlowAlias);
    assertEquals("Username Password Form",
            testRealmResource().flows().getExecutions(tmpFlowAlias).get(0).getDisplayName());
    assertEquals("nestedFlow", testRealmResource().flows().getExecutions(tmpFlowAlias).get(2).getDisplayName());
}