Example usage for java.util EnumSet allOf

List of usage examples for java.util EnumSet allOf

Introduction

In this page you can find the example usage for java.util EnumSet allOf.

Prototype

public static <E extends Enum<E>> EnumSet<E> allOf(Class<E> elementType) 

Source Link

Document

Creates an enum set containing all of the elements in the specified element type.

Usage

From source file:org.apache.accumulo.proxy.SimpleTest.java

@Test(timeout = 10000)
public void security() throws Exception {
    client.createLocalUser(creds, "user", s2bb(secret));
    ByteBuffer badLogin = client.login("user", properties);
    client.dropLocalUser(creds, "user");
    final String table = makeTableName();
    client.createTable(creds, table, false, TimeType.MILLIS);

    final IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(),
            Collections.singletonMap("sleepTime", "200"));

    try {//w w w  . j a  v  a 2s  .  c om
        client.addConstraint(badLogin, table, NumericValueConstraint.class.getName());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.addSplits(badLogin, table, Collections.singleton(s2bb("1")));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.clearLocatorCache(badLogin, table);
        fail("exception not thrown");
    } catch (TException ex) {
    }
    try {
        client.compactTable(badLogin, table, null, null, null, true, false);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.cancelCompaction(badLogin, table);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.createTable(badLogin, table, false, TimeType.MILLIS);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.deleteTable(badLogin, table);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.deleteRows(badLogin, table, null, null);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.tableExists(badLogin, table);
        fail("exception not thrown");
    } catch (TException ex) {
    }
    try {
        client.flushTable(badLogin, table, null, null, false);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getLocalityGroups(badLogin, table);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getMaxRow(badLogin, table, Collections.<ByteBuffer>emptySet(), null, false, null, false);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getTableProperties(badLogin, table);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.listSplits(badLogin, table, 10000);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.listTables(badLogin);
        fail("exception not thrown");
    } catch (TException ex) {
    }
    try {
        client.listConstraints(badLogin, table);
        fail("exception not thrown");
    } catch (TException ex) {
    }
    try {
        client.mergeTablets(badLogin, table, null, null);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.offlineTable(badLogin, table);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.onlineTable(badLogin, table);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.removeConstraint(badLogin, table, 0);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.removeTableProperty(badLogin, table, Property.TABLE_FILE_MAX.getKey());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.renameTable(badLogin, table, "someTableName");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        Map<String, Set<String>> groups = new HashMap<String, Set<String>>();
        groups.put("group1", Collections.singleton("cf1"));
        groups.put("group2", Collections.singleton("cf2"));
        client.setLocalityGroups(badLogin, table, groups);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.setTableProperty(badLogin, table, Property.TABLE_FILE_MAX.getKey(), "0");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.tableIdMap(badLogin);
        fail("exception not thrown");
    } catch (TException ex) {
    }
    try {
        client.getSiteConfiguration(badLogin);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getSystemConfiguration(badLogin);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getTabletServers(badLogin);
        fail("exception not thrown");
    } catch (TException ex) {
    }
    try {
        client.getActiveScans(badLogin, "fake");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getActiveCompactions(badLogin, "fakse");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.removeProperty(badLogin, "table.split.threshold");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.setProperty(badLogin, "table.split.threshold", "500M");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.testClassLoad(badLogin, DevNull.class.getName(), SortedKeyValueIterator.class.getName());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.authenticateUser(badLogin, "root", s2pp(secret));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        HashSet<ByteBuffer> auths = new HashSet<ByteBuffer>(Arrays.asList(s2bb("A"), s2bb("B")));
        client.changeUserAuthorizations(badLogin, "stooge", auths);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.changeLocalUserPassword(badLogin, "stooge", s2bb(""));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.createLocalUser(badLogin, "stooge", s2bb("password"));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.dropLocalUser(badLogin, "stooge");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getUserAuthorizations(badLogin, "stooge");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.grantSystemPermission(badLogin, "stooge", SystemPermission.CREATE_TABLE);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.grantTablePermission(badLogin, "root", table, TablePermission.WRITE);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.hasSystemPermission(badLogin, "stooge", SystemPermission.CREATE_TABLE);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.hasTablePermission(badLogin, "root", table, TablePermission.WRITE);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.listLocalUsers(badLogin);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.revokeSystemPermission(badLogin, "stooge", SystemPermission.CREATE_TABLE);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.revokeTablePermission(badLogin, "root", table, TablePermission.ALTER_TABLE);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.createScanner(badLogin, table, new ScanOptions());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.createBatchScanner(badLogin, table, new BatchScanOptions());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.updateAndFlush(badLogin, table, new HashMap<ByteBuffer, List<ColumnUpdate>>());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.createWriter(badLogin, table, new WriterOptions());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.attachIterator(badLogin, "slow", setting, EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.checkIteratorConflicts(badLogin, table, setting, EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        final String TABLE_TEST = makeTableName();
        client.cloneTable(badLogin, table, TABLE_TEST, false, null, null);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.exportTable(badLogin, table, "/tmp");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.importTable(badLogin, "testify", "/tmp");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getIteratorSetting(badLogin, table, "foo", IteratorScope.SCAN);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.listIterators(badLogin, table);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.removeIterator(badLogin, table, "name", EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.splitRangeByTablets(badLogin, table, client.getRowRange(ByteBuffer.wrap("row".getBytes())), 10);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        File newFolder = folder.newFolder();
        client.importDirectory(badLogin, table, "/tmp", newFolder.getAbsolutePath(), true);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.pingTabletServer(badLogin, "fake");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.login("badUser", properties);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.testTableClassLoad(badLogin, table, VersioningIterator.class.getName(),
                SortedKeyValueIterator.class.getName());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.createConditionalWriter(badLogin, table, new ConditionalWriterOptions());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
}

From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java

private void peaksDataInitializations() {
    String classElements[] = _ecurveclass.getName().split("\\.");
    elutionTableLabel.setText("<html><body><center>Elution Data<br><font size='-1'>("
            + classElements[classElements.length - 1] + ")</font></center></body></html>");
    elutionTableLabel.setHorizontalAlignment(JLabel.CENTER);
    elutionTableLabel.setHorizontalTextPosition(JLabel.CENTER);

    if (transDefHeader == null || transDefHeader.getAQUApairs() == null
            || transDefHeader.getAQUApairs().size() == 0) {
        buttonFindMate.setVisible(false);
    } else {// w  ww.j  a v a  2  s .c om
        buttonFindMate.setVisible(true);
    }
    peaksScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    peaksScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    peaksTable = new JTable(new PeaksTableModel());
    //peaksTable.setPreferredScrollableViewportSize(new Dimension(500, 700));
    peaksTable.setSelectionModel(new peaksTableSelectionModel());
    peaksTable.setAutoscrolls(true);
    peaksTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    int totalTableRows = 1;
    for (MRMTransition curTrans : _mrmTransitions)
        totalTableRows += (1 + curTrans.getDaughters().size());
    ((PeaksTableModel) (peaksTable.getModel())).data = new Object[totalTableRows
            - 1][peaksData.values().length];
    for (peaksData pd : EnumSet.allOf(peaksData.class)) {
        peaksTable.getColumnModel().getColumn(pd.colno).setPreferredWidth(pd.colWidth);
    }
    peaksTable.doLayout();
    ((DefaultCellEditor) peaksTable.getDefaultEditor(peaksData.Accept.colClass)).setClickCountToStart(1);
    int i = 0;
    for (MRMTransition curTrans : _mrmTransitions) {
        curTrans.setGraphData(makeParentSeries(curTrans));
        int curPrecursorIndex = i;
        curTrans.setTableRow(curPrecursorIndex);
        for (peaksData pd : EnumSet.allOf(peaksData.class)) {
            ((PeaksTableModel) (peaksTable.getModel())).data[i][pd.colno] = null;
            pd.makeVisible(true);
        }

        ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Accept.colno] = null;
        ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Precursor.colno] = curTrans;
        for (MRMDaughter d : curTrans.getDaughters().values()) {
            i++;
            d.setGraphData(d.makeDaughterSeries());
            d.setContinDaughterData(d.makeDaughterSeries(d, true));
            d.setElutionDataTableRow(i);
            ElutionCurveStrategy bes = ElutionCurveStrategy.getInstance(curTrans, d, _ecurveclass);
            bes.calculateParentElutionCurves(null);
            bes.calculateDaughterElutionCurves(null);
            bes.calculateBestCurves();
            d.calculateQuality();
            curTrans.getElutionCurves().put(d, bes);

            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Accept.colno] = new Boolean(
                    !Utils.allYsAre0(d));
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Peptide.colno] = "";
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Precursor.colno] = curTrans;
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Daughter.colno] = d;
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.CoStart.colno] = null;
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.CoEnd.colno] = null;
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.CoDelta.colno] = null;
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.AUC.colno] = null;
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.MaxPeak.colno] = null;
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.MidTime.colno] = null;
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Quality.colno] = null;
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Label.colno] = "";
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Code.colno] = null;
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.LHRatio.colno] = null;
            ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Comment.colno] = "";
            if (transDefHeader != null && transDefHeader.getDToTD() != null
                    && transDefHeader.getDToTD().get(d) != null) {
                TransitionDefinition td = transDefHeader.getDToTD().get(d);
                ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Peptide.colno] = td.getPeptide();
                ((PeaksTableModel) (peaksTable
                        .getModel())).data[curPrecursorIndex][peaksData.Peptide.colno] = td.getPeptide();
                ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Code.colno] = new Integer(
                        td.getAQUAcode());
            }
            ElutionCurve bestPrecursorCurve = bes.getBestParentCurve();
            if (bestPrecursorCurve == null || bestPrecursorCurve.getMinElutionTimeSecs() <= 0.0) {
                ((PeaksTableModel) (peaksTable
                        .getModel())).data[curPrecursorIndex][peaksData.AUC.colno] = new Float(-1);
                ((PeaksTableModel) (peaksTable
                        .getModel())).data[curPrecursorIndex][peaksData.MaxPeak.colno] = new Float(-1);
                ((PeaksTableModel) (peaksTable
                        .getModel())).data[curPrecursorIndex][peaksData.Quality.colno] = new Float(-1);
                ((PeaksTableModel) (peaksTable
                        .getModel())).data[curPrecursorIndex][peaksData.MidTime.colno] = new Float(-1);

            } else {
                ((PeaksTableModel) (peaksTable
                        .getModel())).data[curPrecursorIndex][peaksData.AUC.colno] = new Float(
                                bestPrecursorCurve.getAUC());
                ((PeaksTableModel) (peaksTable
                        .getModel())).data[curPrecursorIndex][peaksData.MaxPeak.colno] = new Float(
                                bestPrecursorCurve.getHighestPointY());
                ((PeaksTableModel) (peaksTable
                        .getModel())).data[curPrecursorIndex][peaksData.Quality.colno] = new Float(
                                curTrans.getQuality());
            }

            ElutionCurve bestDaughterCurve = bes.getBestDaughterCurve();
            if (bestDaughterCurve == null || bestDaughterCurve.getMinElutionTimeSecs() <= 0.0) {
                ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Accept.colno] = new Boolean(
                        false);
                ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.AUC.colno] = new Float(-1);
                ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.MaxPeak.colno] = new Float(-1);
                ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Quality.colno] = new Float(-1);
                ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.MidTime.colno] = new Float(-1);

            } else {
                ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.AUC.colno] = new Float(
                        bestDaughterCurve.getAUC());
                ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.MaxPeak.colno] = new Float(
                        bestDaughterCurve.getHighestPointY());
                d.setBestElutionCurve(bestDaughterCurve);
                ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Quality.colno] = new Float(
                        d.getQuality());
                if (_minPeakCutoff > 0 && bestDaughterCurve.getHighestPointY() < _minPeakCutoff)
                    ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Accept.colno] = new Boolean(
                            false);
                if (_minAreaCutoff > 0 && bestDaughterCurve.getAUC() < _minAreaCutoff)
                    ((PeaksTableModel) (peaksTable.getModel())).data[i][peaksData.Accept.colno] = new Boolean(
                            false);
            }
        }
        curTrans.setElutionRegionStart(curTrans.calculateMinOfAllBestDaughterCurves());
        curTrans.setElutionRegionEnd(curTrans.calculateMaxOfAllBestDaughterCurves());
        curTrans.calcMaxYofAllDaughters();
        for (int j = curPrecursorIndex; j <= i; j++) {
            ((PeaksTableModel) (peaksTable.getModel())).data[j][peaksData.CoStart.colno] = new Float(
                    curTrans.getElutionRegionStart());
            ((PeaksTableModel) (peaksTable.getModel())).data[j][peaksData.CoEnd.colno] = new Float(
                    curTrans.getElutionRegionEnd());
            ((PeaksTableModel) (peaksTable.getModel())).data[j][peaksData.CoDelta.colno] = new Float(
                    curTrans.getElutionRegionEnd() - curTrans.getElutionRegionStart());
            ((PeaksTableModel) (peaksTable.getModel())).data[j][peaksData.MidTime.colno] = new Float(
                    curTrans.getCalcXatMaxYAllDaughters());
        }
        i++;
    }

    peaksTable.setDefaultRenderer(MRMTransition.class, new MRMTransitionTableRenderer(false));
    peaksTable.setDefaultRenderer(MRMDaughter.class, new MRMDaughterTableRenderer(false));
    peaksTable.setDefaultRenderer(Number.class, new MRMNumberTableRenderer());
    peaksTable.setDefaultRenderer(Integer.class, new MRMNumberTableRenderer());
    peaksTable.setDefaultRenderer(Boolean.class, new MRMBooleanRenderer());
    peaksTable.getColumnModel().getColumn(peaksData.CoStart.colno).setCellEditor(new NumberTableCellEditor());
    peaksTable.getColumnModel().getColumn(peaksData.CoEnd.colno).setCellEditor(new NumberTableCellEditor());
    peaksTable.getColumnModel().getColumn(peaksData.Code.colno).setCellEditor(new NumberTableCellEditor());
    peaksTable.getColumnModel().getColumn(peaksData.LHRatio.colno).setCellEditor(new NumberTableCellEditor());

    peaksScrollPane.getViewport().setView(peaksTable);

    if (transDefHeader == null) {
        peaksData.Peptide.makeVisible(false);
        peaksData.Label.makeVisible(false);
        peaksData.LHRatio.makeVisible(false);
        peaksData.Code.makeVisible(false);
    } else {
        if (transDefHeader.getAQUApairs() == null || transDefHeader.getAQUApairs().isEmpty()) {
            peaksData.Label.makeVisible(false);
            peaksData.LHRatio.makeVisible(false);
            peaksData.Code.makeVisible(false);
        }
    }

    //  "Quality" column, currently unused, is invisible unless one or more of its
    //  values is not -1          
    peaksData.Quality.makeVisible(!Utils.qualColIsEmpty());

    peaksScrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent ae) {
            if (!ae.getValueIsAdjusting()) {
                peaksTable.repaint();
            }
        }
    });
    peaksTable.getModel().addTableModelListener(new peaksTableListener());
    _ptmlsl = new PeaksTableListSelectionListener();
    peaksTable.getSelectionModel().addListSelectionListener(_ptmlsl);

}

From source file:org.apache.accumulo.proxy.SimpleProxyIT.java

@Test(timeout = 10000)
public void security() throws Exception {
    client.createLocalUser(creds, "user", s2bb(secret));
    ByteBuffer badLogin = client.login("user", properties);
    client.dropLocalUser(creds, "user");
    final String table = makeTableName();
    client.createTable(creds, table, false, TimeType.MILLIS);

    final IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(),
            Collections.singletonMap("sleepTime", "200"));

    try {//www . ja v a 2s.  c  o  m
        client.addConstraint(badLogin, table, NumericValueConstraint.class.getName());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.addSplits(badLogin, table, Collections.singleton(s2bb("1")));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.clearLocatorCache(badLogin, table);
        fail("exception not thrown");
    } catch (TException ex) {
    }
    try {
        client.compactTable(badLogin, table, null, null, null, true, false);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.cancelCompaction(badLogin, table);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.createTable(badLogin, table, false, TimeType.MILLIS);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.deleteTable(badLogin, table);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.deleteRows(badLogin, table, null, null);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.tableExists(badLogin, table);
        fail("exception not thrown");
    } catch (TException ex) {
    }
    try {
        client.flushTable(badLogin, table, null, null, false);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getLocalityGroups(badLogin, table);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getMaxRow(badLogin, table, Collections.<ByteBuffer>emptySet(), null, false, null, false);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getTableProperties(badLogin, table);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.listSplits(badLogin, table, 10000);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.listTables(badLogin);
        fail("exception not thrown");
    } catch (TException ex) {
    }
    try {
        client.listConstraints(badLogin, table);
        fail("exception not thrown");
    } catch (TException ex) {
    }
    try {
        client.mergeTablets(badLogin, table, null, null);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.offlineTable(badLogin, table, false);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.onlineTable(badLogin, table, false);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.removeConstraint(badLogin, table, 0);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.removeTableProperty(badLogin, table, Property.TABLE_FILE_MAX.getKey());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.renameTable(badLogin, table, "someTableName");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        Map<String, Set<String>> groups = new HashMap<String, Set<String>>();
        groups.put("group1", Collections.singleton("cf1"));
        groups.put("group2", Collections.singleton("cf2"));
        client.setLocalityGroups(badLogin, table, groups);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.setTableProperty(badLogin, table, Property.TABLE_FILE_MAX.getKey(), "0");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.tableIdMap(badLogin);
        fail("exception not thrown");
    } catch (TException ex) {
    }
    try {
        client.getSiteConfiguration(badLogin);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getSystemConfiguration(badLogin);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getTabletServers(badLogin);
        fail("exception not thrown");
    } catch (TException ex) {
    }
    try {
        client.getActiveScans(badLogin, "fake");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getActiveCompactions(badLogin, "fakse");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.removeProperty(badLogin, "table.split.threshold");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.setProperty(badLogin, "table.split.threshold", "500M");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.testClassLoad(badLogin, DevNull.class.getName(), SortedKeyValueIterator.class.getName());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.authenticateUser(badLogin, "root", s2pp(secret));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        HashSet<ByteBuffer> auths = new HashSet<ByteBuffer>(Arrays.asList(s2bb("A"), s2bb("B")));
        client.changeUserAuthorizations(badLogin, "stooge", auths);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.changeLocalUserPassword(badLogin, "stooge", s2bb(""));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.createLocalUser(badLogin, "stooge", s2bb("password"));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.dropLocalUser(badLogin, "stooge");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getUserAuthorizations(badLogin, "stooge");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.grantSystemPermission(badLogin, "stooge", SystemPermission.CREATE_TABLE);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.grantTablePermission(badLogin, "root", table, TablePermission.WRITE);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.hasSystemPermission(badLogin, "stooge", SystemPermission.CREATE_TABLE);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.hasTablePermission(badLogin, "root", table, TablePermission.WRITE);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.listLocalUsers(badLogin);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.revokeSystemPermission(badLogin, "stooge", SystemPermission.CREATE_TABLE);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.revokeTablePermission(badLogin, "root", table, TablePermission.ALTER_TABLE);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.createScanner(badLogin, table, new ScanOptions());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.createBatchScanner(badLogin, table, new BatchScanOptions());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.updateAndFlush(badLogin, table, new HashMap<ByteBuffer, List<ColumnUpdate>>());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.createWriter(badLogin, table, new WriterOptions());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.attachIterator(badLogin, "slow", setting, EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.checkIteratorConflicts(badLogin, table, setting, EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        final String TABLE_TEST = makeTableName();
        client.cloneTable(badLogin, table, TABLE_TEST, false, null, null);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.exportTable(badLogin, table, "/tmp");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.importTable(badLogin, "testify", "/tmp");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.getIteratorSetting(badLogin, table, "foo", IteratorScope.SCAN);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.listIterators(badLogin, table);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.removeIterator(badLogin, table, "name", EnumSet.allOf(IteratorScope.class));
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.splitRangeByTablets(badLogin, table, client.getRowRange(ByteBuffer.wrap("row".getBytes())), 10);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        File importDir = tempFolder.newFolder("importDir");
        File failuresDir = tempFolder.newFolder("failuresDir");
        client.importDirectory(badLogin, table, importDir.getAbsolutePath(), failuresDir.getAbsolutePath(),
                true);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.pingTabletServer(badLogin, "fake");
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.login("badUser", properties);
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.testTableClassLoad(badLogin, table, VersioningIterator.class.getName(),
                SortedKeyValueIterator.class.getName());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
    try {
        client.createConditionalWriter(badLogin, table, new ConditionalWriterOptions());
        fail("exception not thrown");
    } catch (AccumuloSecurityException ex) {
    }
}

From source file:org.apache.hadoop.yarn.server.timeline.RollingLevelDBTimelineStore.java

/**
 * Read entity from a db iterator. If no information is found in the specified
 * fields for this entity, return null./* ww w.  ja v  a2 s.co  m*/
 */
private static TimelineEntity getEntity(String entityId, String entityType, Long startTime,
        EnumSet<Field> fields, DBIterator iterator, byte[] prefix, int prefixlen) throws IOException {
    if (fields == null) {
        fields = EnumSet.allOf(Field.class);
    }

    TimelineEntity entity = new TimelineEntity();
    boolean events = false;
    boolean lastEvent = false;
    if (fields.contains(Field.EVENTS)) {
        events = true;
    } else if (fields.contains(Field.LAST_EVENT_ONLY)) {
        lastEvent = true;
    } else {
        entity.setEvents(null);
    }
    boolean relatedEntities = false;
    if (fields.contains(Field.RELATED_ENTITIES)) {
        relatedEntities = true;
    } else {
        entity.setRelatedEntities(null);
    }
    boolean primaryFilters = false;
    if (fields.contains(Field.PRIMARY_FILTERS)) {
        primaryFilters = true;
    } else {
        entity.setPrimaryFilters(null);
    }
    boolean otherInfo = false;
    if (fields.contains(Field.OTHER_INFO)) {
        otherInfo = true;
    } else {
        entity.setOtherInfo(null);
    }

    // iterate through the entity's entry, parsing information if it is part
    // of a requested field
    for (; iterator.hasNext(); iterator.next()) {
        byte[] key = iterator.peekNext().getKey();
        if (!prefixMatches(prefix, prefixlen, key)) {
            break;
        }
        if (key.length == prefixlen) {
            continue;
        }
        if (key[prefixlen] == PRIMARY_FILTERS_COLUMN[0]) {
            if (primaryFilters) {
                addPrimaryFilter(entity, key, prefixlen + PRIMARY_FILTERS_COLUMN.length);
            }
        } else if (key[prefixlen] == OTHER_INFO_COLUMN[0]) {
            if (otherInfo) {
                Object o = null;
                String keyStr = parseRemainingKey(key, prefixlen + OTHER_INFO_COLUMN.length);
                try {
                    o = fstConf.asObject(iterator.peekNext().getValue());
                    entity.addOtherInfo(keyStr, o);
                } catch (Exception ignore) {
                    try {
                        // Fall back to 2.24 parser
                        o = fstConf224.asObject(iterator.peekNext().getValue());
                        entity.addOtherInfo(keyStr, o);
                    } catch (Exception e) {
                        LOG.warn("Error while decoding " + entityId + ":otherInfo:" + keyStr, e);
                    }
                }
            }
        } else if (key[prefixlen] == RELATED_ENTITIES_COLUMN[0]) {
            if (relatedEntities) {
                addRelatedEntity(entity, key, prefixlen + RELATED_ENTITIES_COLUMN.length);
            }
        } else if (key[prefixlen] == EVENTS_COLUMN[0]) {
            if (events || (lastEvent && entity.getEvents().size() == 0)) {
                TimelineEvent event = getEntityEvent(null, key, prefixlen + EVENTS_COLUMN.length,
                        iterator.peekNext().getValue());
                if (event != null) {
                    entity.addEvent(event);
                }
            }
        } else if (key[prefixlen] == DOMAIN_ID_COLUMN[0]) {
            byte[] v = iterator.peekNext().getValue();
            String domainId = new String(v, UTF_8);
            entity.setDomainId(domainId);
        } else {
            LOG.warn(String.format("Found unexpected column for entity %s of " + "type %s (0x%02x)", entityId,
                    entityType, key[prefixlen]));
        }
    }

    entity.setEntityId(entityId);
    entity.setEntityType(entityType);
    entity.setStartTime(startTime);

    return entity;
}

From source file:org.anarres.cpp.Main.java

public static Result preprocess(String[] args, String source) throws Exception {

    OptionParser parser = new OptionParser();
    OptionSpec<?> helpOption = parser.accepts("help", "Displays command-line help.").forHelp();
    OptionSpec<?> debugOption = parser.acceptsAll(Arrays.asList("debug"), "Enables debug output.");

    OptionSpec<String> defineOption = parser
            .acceptsAll(Arrays.asList("define", "D"), "Defines the given macro.").withRequiredArg()
            .ofType(String.class).describedAs("name[=definition]");
    OptionSpec<String> undefineOption = parser
            .acceptsAll(Arrays.asList("undefine", "U"),
                    "Undefines the given macro, previously either builtin or defined using -D.")
            .withRequiredArg().describedAs("name");
    OptionSpec<File> includeOption = parser
            .accepts("include",
                    "Process file as if \"#"
                            + "include \"file\"\" appeared as the first line of the primary source file.")
            .withRequiredArg().ofType(File.class).describedAs("file");
    OptionSpec<File> incdirOption = parser
            .acceptsAll(Arrays.asList("incdir", "I"),
                    "Adds the directory dir to the list of directories to be searched for header files.")
            .withRequiredArg().ofType(File.class).describedAs("dir");
    OptionSpec<File> iquoteOption = parser.acceptsAll(Arrays.asList("iquote"),
            "Adds the directory dir to the list of directories to be searched for header files included using \"\".")
            .withRequiredArg().ofType(File.class).describedAs("dir");
    OptionSpec<String> warningOption = parser
            .acceptsAll(Arrays.asList("warning", "W"),
                    "Enables the named warning class (" + getWarnings() + ").")
            .withRequiredArg().ofType(String.class).describedAs("warning");
    OptionSpec<Void> noWarningOption = parser.acceptsAll(Arrays.asList("no-warnings", "w"),
            "Disables ALL warnings.");
    OptionSpec<File> inputsOption = parser.nonOptions().ofType(File.class).describedAs("Files to process.");

    OptionSet options = parser.parse(args);

    if (options.has(helpOption)) {
        parser.printHelpOn(System.out);
        return null;
    }/*ww  w  .j av  a 2s  .  com*/

    Preprocessor pp = new Preprocessor();
    pp.addFeature(Feature.DIGRAPHS);
    pp.addFeature(Feature.TRIGRAPHS);
    pp.addFeature(Feature.PRAGMA_ONCE);
    //pp.addFeature(Feature.LINEMARKERS);
    pp.addWarning(Warning.IMPORT);
    pp.setListener(new DefaultPreprocessorListener());
    pp.addMacro("__JCPP__");
    pp.getSystemIncludePath().add("/usr/local/include");
    pp.getSystemIncludePath().add("/usr/include");
    pp.getFrameworksPath().add("/System/Library/Frameworks");
    pp.getFrameworksPath().add("/Library/Frameworks");
    pp.getFrameworksPath().add("/Local/Library/Frameworks");

    if (options.has(debugOption))
        pp.addFeature(Feature.DEBUG);

    if (options.has(noWarningOption))
        pp.getWarnings().clear();

    for (String warning : options.valuesOf(warningOption)) {
        warning = warning.toUpperCase();
        warning = warning.replace('-', '_');
        if (warning.equals("ALL"))
            pp.addWarnings(EnumSet.allOf(Warning.class));
        else
            pp.addWarning(Enum.valueOf(Warning.class, warning));
    }

    for (String arg : options.valuesOf(defineOption)) {
        int idx = arg.indexOf('=');
        if (idx == -1)
            pp.addMacro(arg);
        else
            pp.addMacro(arg.substring(0, idx), arg.substring(idx + 1));
    }
    for (String arg : options.valuesOf(undefineOption)) {
        pp.getMacros().remove(arg);
    }

    for (File dir : options.valuesOf(incdirOption))
        pp.getSystemIncludePath().add(dir.getAbsolutePath());
    for (File dir : options.valuesOf(iquoteOption))
        pp.getQuoteIncludePath().add(dir.getAbsolutePath());
    for (File file : options.valuesOf(includeOption))
        // Comply exactly with spec.
        pp.addInput(new StringLexerSource("#" + "include \"" + file + "\"\n"));

    List<File> inputs = options.valuesOf(inputsOption);
    if (inputs.isEmpty()) {
        pp.addInput(new StringLexerSource(source, true));
        //pp.addInput(new InputLexerSource(System.in));
    } else {
        for (File input : inputs)
            pp.addInput(new FileLexerSource(input));
    }

    if (pp.getFeature(Feature.DEBUG)) {
        LOG.info("#" + "include \"...\" search starts here:");
        for (String dir : pp.getQuoteIncludePath())
            LOG.info("  " + dir);
        LOG.info("#" + "include <...> search starts here:");
        for (String dir : pp.getSystemIncludePath())
            LOG.info("  " + dir);
        LOG.info("End of search list.");
    }

    try {
        Result result = new Result();
        result.preprocessor = pp;
        pp.collector = new ActionCollectorImpl(pp, pp.inputs);
        for (;;) {
            TokenS tok = pp.token();
            if (tok == null)
                break;
            if (tok.token.getType() == Token.EOF)
                break;
            result.produced.add(tok);
        }
        result.original = ((ActionCollectorImpl) pp.collector).original;
        result.actions = ((ActionCollectorImpl) pp.collector).actions;
        pp.collector = new ActionCollector();
        return result;
    } catch (Exception e) {
        StringBuilder buf = new StringBuilder("Preprocessor failed:\n");
        Source s = pp.getSource();
        while (s != null) {
            buf.append(" -> ").append(s).append("\n");
            s = s.getParent();
        }
        LOG.error(buf.toString(), e);
    }
    return null;
}

From source file:net.sf.eclipsecs.core.config.meta.MetadataFactory.java

@SuppressWarnings("unchecked")
private static void processProperties(Element moduleElement, RuleMetadata moduleMetadata,
        ResourceBundle metadataBundle) throws CheckstylePluginException {

    List<Element> propertyElements = moduleElement.elements(XMLTags.PROPERTY_METADATA_TAG);
    for (Element propertyEl : propertyElements) {

        ConfigPropertyType type = ConfigPropertyType.valueOf(propertyEl.attributeValue(XMLTags.DATATYPE_TAG));

        String name = propertyEl.attributeValue(XMLTags.NAME_TAG).trim();
        String defaultValue = StringUtils.trim(propertyEl.attributeValue(XMLTags.DEFAULT_VALUE_TAG));
        String overrideDefaultValue = StringUtils
                .trim(propertyEl.attributeValue(XMLTags.DEFAULT_VALUE_OVERRIDE_TAG));

        ConfigPropertyMetadata property = new ConfigPropertyMetadata(type, name, defaultValue,
                overrideDefaultValue);//from  www.  j  a va  2  s .c om

        moduleMetadata.getPropertyMetadata().add(property);

        // get description
        String description = propertyEl.elementTextTrim(XMLTags.DESCRIPTION_TAG);
        description = localize(description, metadataBundle);
        property.setDescription(description);

        // get property enumeration values
        Element enumEl = propertyEl.element(XMLTags.ENUMERATION_TAG);
        if (enumEl != null) {
            String optionProvider = enumEl.attributeValue(XMLTags.OPTION_PROVIDER);
            if (optionProvider != null) {

                try {
                    Class<?> providerClass = CheckstylePlugin.getDefault().getAddonExtensionClassLoader()
                            .loadClass(optionProvider);

                    if (IOptionProvider.class.isAssignableFrom(providerClass)) {

                        IOptionProvider provider = (IOptionProvider) providerClass.newInstance();
                        property.getPropertyEnumeration().addAll(provider.getOptions());
                    } else if (Enum.class.isAssignableFrom(providerClass)) {

                        EnumSet<?> values = EnumSet.allOf((Class<Enum>) providerClass);
                        for (Enum e : values) {
                            property.getPropertyEnumeration().add(e.name().toLowerCase());
                        }
                    }
                } catch (ClassNotFoundException e) {
                    CheckstylePluginException.rethrow(e);
                } catch (InstantiationException e) {
                    CheckstylePluginException.rethrow(e);
                } catch (IllegalAccessException e) {
                    CheckstylePluginException.rethrow(e);
                }
            }

            // get explicit enumeration option values
            for (Element optionEl : (List<Element>) enumEl.elements(XMLTags.PROPERTY_VALUE_OPTIONS_TAG)) {
                property.getPropertyEnumeration().add(optionEl.attributeValue(XMLTags.VALUE_TAG));
            }
        }
    }
}

From source file:org.carrot2.workbench.core.ui.SearchEditor.java

/**
 * Restore global state shared among editors. 
 *//*from w  ww. j  a v a  2 s .c  om*/
private static SearchEditorMemento restoreGlobalState() {
    SearchEditorMemento memento = SimpleXmlMemento.fromPreferenceStore(SearchEditorMemento.class,
            GLOBAL_MEMENTO_KEY);

    if (memento == null) {
        memento = new SearchEditorMemento();
        memento.sectionsExpansionState = Maps.newHashMap();
    }

    final IPreferenceStore prefStore = WorkbenchCorePlugin.getDefault().getPreferenceStore();
    final Map<PanelName, PanelState> panels = Maps.newEnumMap(PanelName.class);
    for (PanelName n : EnumSet.allOf(PanelName.class)) {
        final PanelState s = new PanelState();
        s.visibility = prefStore.getBoolean(n.prefKeyVisibility);
        s.weight = prefStore.getInt(n.prefKeyWeight);
        panels.put(n, s);
    }
    memento.panels = panels;

    return memento;
}

From source file:org.apache.hadoop.tools.distcp2.mapred.TestCopyMapper.java

@Test
public void testFailCopyWithAccessControlException() {
    try {//from www . ja  va 2 s  . c  o m
        deleteState();
        createSourceData();

        UserGroupInformation tmpUser = UserGroupInformation.createRemoteUser("guest");

        final CopyMapper copyMapper = new CopyMapper();

        final StubContext stubContext = tmpUser.doAs(new PrivilegedAction<StubContext>() {
            @Override
            public StubContext run() {
                try {
                    return new StubContext(getConfiguration(), null, 0);
                } catch (Exception e) {
                    LOG.error("Exception encountered ", e);
                    throw new RuntimeException(e);
                }
            }
        });

        EnumSet<DistCpOptions.FileAttribute> preserveStatus = EnumSet.allOf(DistCpOptions.FileAttribute.class);

        final Mapper<Text, FileStatus, Text, Text>.Context context = stubContext.getContext();

        context.getConfiguration().set(DistCpConstants.CONF_LABEL_PRESERVE_STATUS,
                DistCpUtils.packAttributes(preserveStatus));

        touchFile(SOURCE_PATH + "/src/file");
        OutputStream out = cluster.getFileSystem().create(new Path(TARGET_PATH + "/src/file"));
        out.write("hello world".getBytes());
        out.close();
        cluster.getFileSystem().setPermission(new Path(SOURCE_PATH + "/src/file"),
                new FsPermission(FsAction.READ, FsAction.READ, FsAction.READ));
        cluster.getFileSystem().setPermission(new Path(TARGET_PATH + "/src/file"),
                new FsPermission(FsAction.READ, FsAction.READ, FsAction.READ));

        final FileSystem tmpFS = tmpUser.doAs(new PrivilegedAction<FileSystem>() {
            @Override
            public FileSystem run() {
                try {
                    return FileSystem.get(configuration);
                } catch (IOException e) {
                    LOG.error("Exception encountered ", e);
                    Assert.fail("Test failed: " + e.getMessage());
                    throw new RuntimeException("Test ought to fail here");
                }
            }
        });

        tmpUser.doAs(new PrivilegedAction<Integer>() {
            @Override
            public Integer run() {
                try {
                    copyMapper.setup(context);
                    copyMapper.map(new Text("/src/file"),
                            tmpFS.getFileStatus(new Path(SOURCE_PATH + "/src/file")), context);
                    Assert.fail("Didn't expect the file to be copied");
                } catch (AccessControlException ignore) {
                } catch (Exception e) {
                    if (e.getCause() == null || !(e.getCause() instanceof AccessControlException)) {
                        throw new RuntimeException(e);
                    }
                }
                return null;
            }
        });
    } catch (Exception e) {
        LOG.error("Exception encountered ", e);
        Assert.fail("Test failed: " + e.getMessage());
    }
}

From source file:org.silverpeas.migration.jcr.service.SimpleDocumentServiceTest.java

/**
 * Test of listWysiwygByForeignId method, of class DocumentRepository.
 *//*from  w  w w  .j av a2  s  .c  om*/
@Test
public void listWysiwygByForeignId() throws Exception {
    new JcrSimpleDocumentServiceTest() {
        @Override
        public void run() throws Exception {
            Set<String> createdIds = new HashSet<String>();
            // No WYSIWYG content exists
            List<String> wysiwygFIdLangFilenames = extractForeignIdLanguageFilenames(
                    getSimpleDocumentService().listWysiwygByForeignId(instanceId, ""));
            assertThat(wysiwygFIdLangFilenames, notNullValue());
            assertThat(wysiwygFIdLangFilenames, hasSize(0));

            // Creating an FR "attachment" content.
            String createdUuid = createAttachmentForTest(
                    defaultDocumentBuilder("fId_1").setDocumentType(attachment), defaultFRContentBuilder(),
                    "fId_1_fr").getId();
            createdIds.add(createdUuid);
            SimpleDocument enDocument = getDocumentById(createdUuid, "en");
            assertThat(enDocument, notNullValue());
            assertThat(enDocument.getAttachment(), nullValue());
            SimpleDocument frDocument = getDocumentById(createdUuid, "fr");
            assertThat(frDocument, notNullValue());
            assertThat(frDocument.getAttachment(), notNullValue());
            assertThat(frDocument.getDocumentType(), is(attachment));
            wysiwygFIdLangFilenames = extractForeignIdLanguageFilenames(
                    getSimpleDocumentService().listWysiwygByForeignId(instanceId, "fId_1"));
            assertThat(wysiwygFIdLangFilenames, hasSize(0));

            // Updating attachment with EN content.
            setEnData(frDocument);
            updateAttachmentForTest(frDocument, "en", "fId_1_en");
            createdIds.add(frDocument.getId());

            // Vrifying the attachment exists into both of tested languages.
            enDocument = getDocumentById(createdUuid, "en");
            assertThat(enDocument, notNullValue());
            assertThat(enDocument.getAttachment(), notNullValue());
            assertThat(enDocument.getDocumentType(), is(attachment));
            checkEnglishSimpleDocument(enDocument);
            frDocument = getDocumentById(createdUuid, "fr");
            assertThat(frDocument, notNullValue());
            assertThat(frDocument.getAttachment(), notNullValue());
            assertThat(frDocument.getDocumentType(), is(attachment));
            checkFrenchSimpleDocument(frDocument);

            // No WYSIWYG : that is what it is expected
            wysiwygFIdLangFilenames = extractForeignIdLanguageFilenames(
                    getSimpleDocumentService().listWysiwygByForeignId(instanceId, "fId_1"));
            assertThat(wysiwygFIdLangFilenames, hasSize(0));

            // Adding several documents, but no WYSIWYG
            Set<DocumentType> documentTypes = EnumSet.allOf(DocumentType.class);
            documentTypes.remove(DocumentType.wysiwyg);
            int id = 2;
            for (DocumentType documentType : documentTypes) {
                createdIds.add(createAttachmentForTest(
                        defaultDocumentBuilder("fId_" + id).setDocumentType(documentType),
                        defaultFRContentBuilder().setFilename("fId_" + id + "_wysiwyg_en.txt"),
                        "fId_" + id + "_fr").getId());
                id++;
            }

            // No WYSIWYG : that is what it is expected
            wysiwygFIdLangFilenames = extractForeignIdLanguageFilenames(
                    getSimpleDocumentService().listWysiwygByForeignId(instanceId, "fId_1"));
            assertThat(wysiwygFIdLangFilenames, hasSize(0));

            // Number of expected created documents
            int nbDocuments = 1 + (DocumentType.values().length - 1);
            assertThat(createdIds.size(), is(nbDocuments));

            // Adding the first WYSIWYG EN content
            SimpleDocument createdDocument = createAttachmentForTest(
                    defaultDocumentBuilder("fId_26").setDocumentType(wysiwyg), defaultENContentBuilder(),
                    "fId_26_en");
            createdIds.add(createdDocument.getId());

            // One wrong WYSIWYG base name
            wysiwygFIdLangFilenames = extractForeignIdLanguageFilenames(
                    getSimpleDocumentService().listWysiwygByForeignId(instanceId, "fId_26"));
            assertThat(wysiwygFIdLangFilenames, hasSize(1));
            assertThat(wysiwygFIdLangFilenames, contains("fId_26|en|test.pdf"));

            // Updating wysiwyg file name
            createdDocument.setFilename("fId_26_wysiwyg_en.txt");
            updateAttachmentForTest(createdDocument);

            // One WYSIWYG base name
            wysiwygFIdLangFilenames = extractForeignIdLanguageFilenames(
                    getSimpleDocumentService().listWysiwygByForeignId(instanceId, "fId_26"));
            assertThat(wysiwygFIdLangFilenames, hasSize(1));
            assertThat(wysiwygFIdLangFilenames, contains("fId_26|en|fId_26_wysiwyg_en.txt"));

            // Adding the FR content to the first WYSIWYG document
            enDocument = getDocumentById(createdDocument.getId(), "en");
            setFrData(enDocument);
            enDocument.setFilename("fId_26_wysiwyg_fr.txt");
            updateAttachmentForTest(enDocument, "fr", "fId_26_fr");
            createdIds.add(enDocument.getId());

            // One WYSIWYG on one Component
            wysiwygFIdLangFilenames = extractForeignIdLanguageFilenames(
                    getSimpleDocumentService().listWysiwygByForeignId(instanceId, "fId_26"));
            assertThat(wysiwygFIdLangFilenames, hasSize(2));
            assertThat(wysiwygFIdLangFilenames,
                    containsInAnyOrder("fId_26|fr|fId_26_wysiwyg_fr.txt", "fId_26|en|fId_26_wysiwyg_en.txt"));

            // Adding the second WYSIWYG document (on same component)
            SimpleDocument secondCreatedDocument = createAttachmentForTest(
                    defaultDocumentBuilder("fId_27").setDocumentType(wysiwyg),
                    defaultFRContentBuilder().setFilename("fId_27_wysiwyg_fr.txt"), "fId_27_fr");
            createdIds.add(secondCreatedDocument.getId());

            // Two WYSIWYG on one Component
            wysiwygFIdLangFilenames = extractForeignIdLanguageFilenames(
                    getSimpleDocumentService().listWysiwygByForeignId(instanceId, "fId_27"));
            assertThat(wysiwygFIdLangFilenames, hasSize(1));
            assertThat(wysiwygFIdLangFilenames, contains("fId_27|fr|fId_27_wysiwyg_fr.txt"));

            // Updating wysiwyg file name
            setEnData(secondCreatedDocument);
            secondCreatedDocument.setFilename(secondCreatedDocument.getFilename());
            updateAttachmentForTest(secondCreatedDocument, "en", "fId_27_en");

            // Two WYSIWYG (each one in two languages) on one Component
            wysiwygFIdLangFilenames = extractForeignIdLanguageFilenames(
                    getSimpleDocumentService().listWysiwygByForeignId(instanceId, "fId_27"));
            assertThat(wysiwygFIdLangFilenames, hasSize(2));
            assertThat(wysiwygFIdLangFilenames,
                    contains("fId_27|fr|fId_27_wysiwyg_fr.txt", "fId_27|en|fId_27_wysiwyg_fr.txt"));

            assertThat(createdIds, hasSize(nbDocuments + 2));
        }
    }.execute();
}

From source file:org.silverpeas.migration.jcr.service.repository.DocumentRepositoryTest.java

/**
 * Test of listWysiwygFileNames method, of class DocumentRepository.
 *//* w  ww  .  j  a v  a2 s . c  o m*/
@Test
public void listWysiwygFileNames() throws Exception {
    new JcrDocumentRepositoryTest() {
        @Override
        public void run(final Session session) throws Exception {
            Set<String> createdIds = new HashSet<String>();
            // No WYSIWYG content exists
            Set<String> wysiwygFilenames = getDocumentRepository().listWysiwygFileNames(session, instanceId);
            assertThat(wysiwygFilenames, notNullValue());
            assertThat(wysiwygFilenames, hasSize(0));

            // Creating an FR "attachment" content.
            String createdUuid = createAttachmentForTest(
                    defaultDocumentBuilder("fId_1").setDocumentType(attachment), defaultFRContentBuilder(),
                    "fId_1_fr").getId();
            createdIds.add(createdUuid);
            SimpleDocument enDocument = getDocumentById(createdUuid, "en");
            assertThat(enDocument, notNullValue());
            assertThat(enDocument.getAttachment(), nullValue());
            SimpleDocument frDocument = getDocumentById(createdUuid, "fr");
            assertThat(frDocument, notNullValue());
            assertThat(frDocument.getAttachment(), notNullValue());
            assertThat(frDocument.getDocumentType(), is(attachment));

            // Updating attachment with EN content.
            setEnData(frDocument);
            updateAttachmentForTest(frDocument, "en", "fId_1_en");
            createdIds.add(frDocument.getId());

            // Vrifying the attachment exists into both of tested languages.
            enDocument = getDocumentById(createdUuid, "en");
            assertThat(enDocument, notNullValue());
            assertThat(enDocument.getAttachment(), notNullValue());
            assertThat(enDocument.getDocumentType(), is(attachment));
            checkEnglishSimpleDocument(enDocument);
            frDocument = getDocumentById(createdUuid, "fr");
            assertThat(frDocument, notNullValue());
            assertThat(frDocument.getAttachment(), notNullValue());
            assertThat(frDocument.getDocumentType(), is(attachment));
            checkFrenchSimpleDocument(frDocument);

            // No WYSIWYG : that is what it is expected
            wysiwygFilenames = getDocumentRepository().listWysiwygFileNames(session, instanceId);
            assertThat(wysiwygFilenames, hasSize(0));

            // Adding several documents, but no WYSIWYG
            Set<DocumentType> documentTypes = EnumSet.allOf(DocumentType.class);
            documentTypes.remove(DocumentType.wysiwyg);
            int id = 2;
            for (DocumentType documentType : documentTypes) {
                createdIds.add(createAttachmentForTest(
                        defaultDocumentBuilder("fId_" + id).setDocumentType(documentType),
                        defaultFRContentBuilder().setFilename("fId_" + id + "_wysiwyg_en.txt"),
                        "fId_" + id + "_fr").getId());
                id++;
            }

            // No WYSIWYG : that is what it is expected
            wysiwygFilenames = getDocumentRepository().listWysiwygFileNames(session, instanceId);
            assertThat(wysiwygFilenames, hasSize(0));

            // Number of expected created documents
            int nbDocuments = 1 + (DocumentType.values().length - 1);
            assertThat(createdIds.size(), is(nbDocuments));

            // Adding the first WYSIWYG EN content
            SimpleDocument createdDocument = createAttachmentForTest(
                    defaultDocumentBuilder("fId_26").setDocumentType(wysiwyg), defaultENContentBuilder(),
                    "fId_26_en");
            createdIds.add(createdDocument.getId());

            // One wrong WYSIWYG base name
            wysiwygFilenames = getDocumentRepository().listWysiwygFileNames(session, instanceId);
            assertThat(wysiwygFilenames, hasSize(0));

            // Updating wysiwyg file name
            createdDocument.setFilename("fId_26_wysiwyg_en.txt");
            updateAttachmentForTest(createdDocument);

            // One WYSIWYG base name
            wysiwygFilenames = getDocumentRepository().listWysiwygFileNames(session, instanceId);
            assertThat(wysiwygFilenames, hasSize(1));
            assertThat(wysiwygFilenames, contains("fId_26_wysiwyg"));

            // Adding the FR content to the first WYSIWYG document
            enDocument = getDocumentById(createdDocument.getId(), "en");
            setFrData(enDocument);
            enDocument.setFilename("fId_26_wysiwyg_fr.txt");
            updateAttachmentForTest(enDocument, "fr", "fId_26_fr");
            createdIds.add(enDocument.getId());

            // One WYSIWYG on one Component
            wysiwygFilenames = getDocumentRepository().listWysiwygFileNames(session, instanceId);
            assertThat(wysiwygFilenames, hasSize(1));
            assertThat(wysiwygFilenames, contains("fId_26_wysiwyg"));

            // Adding the second WYSIWYG document (on same component)
            createdUuid = createAttachmentForTest(defaultDocumentBuilder("fId_27").setDocumentType(wysiwyg),
                    defaultFRContentBuilder().setFilename("fId_27_wysiwyg_fr.txt"), "fId_27_fr").getId();
            createdIds.add(createdUuid);

            // Two WYSIWYG on one Component
            wysiwygFilenames = getDocumentRepository().listWysiwygFileNames(session, instanceId);
            assertThat(wysiwygFilenames, hasSize(2));
            assertThat(wysiwygFilenames, containsInAnyOrder("fId_26_wysiwyg", "fId_27_wysiwyg"));

            assertThat(createdIds, hasSize(nbDocuments + 2));
        }
    }.execute();
}