List of usage examples for java.util EnumSet allOf
public static <E extends Enum<E>> EnumSet<E> allOf(Class<E> elementType)
From source file:org.silverpeas.migration.jcr.service.repository.DocumentRepositoryTest.java
/** * Test of listWysiwygAttachmentsByBasename method, of class DocumentRepository. *//*from w ww. j a v a 2 s . com*/ @Test public void listWysiwygAttachmentsByBasename() throws Exception { new JcrDocumentRepositoryTest() { @Override public void run(final Session session) throws Exception { Set<String> createdIds = new HashSet<String>(); // No WYSIWYG content exists List<String> wysiwygLangFilenames = extractForeignIdLanguageFilenames( getDocumentRepository().listWysiwygAttachmentsByBasename(session, instanceId, "")); assertThat(wysiwygLangFilenames, notNullValue()); assertThat(wysiwygLangFilenames, 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 wysiwygLangFilenames = extractForeignIdLanguageFilenames( getDocumentRepository().listWysiwygAttachmentsByBasename(session, instanceId, "")); assertThat(wysiwygLangFilenames, 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 wysiwygLangFilenames = extractForeignIdLanguageFilenames( getDocumentRepository().listWysiwygAttachmentsByBasename(session, instanceId, "")); assertThat(wysiwygLangFilenames, 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 wysiwygLangFilenames = extractForeignIdLanguageFilenames( getDocumentRepository().listWysiwygAttachmentsByBasename(session, instanceId, "")); assertThat(wysiwygLangFilenames, hasSize(0)); // Updating wysiwyg file name createdDocument.setFilename("fId_26_wysiwyg_en.txt"); updateAttachmentForTest(createdDocument); // One WYSIWYG base name wysiwygLangFilenames = extractForeignIdLanguageFilenames( getDocumentRepository().listWysiwygAttachmentsByBasename(session, instanceId, "")); assertThat(wysiwygLangFilenames, hasSize(1)); assertThat(wysiwygLangFilenames, contains("fId_26|en|fId_26_wysiwyg_en.txt")); wysiwygLangFilenames = extractForeignIdLanguageFilenames(getDocumentRepository() .listWysiwygAttachmentsByBasename(session, instanceId, "fId_26_wysiwyg")); assertThat(wysiwygLangFilenames, hasSize(1)); assertThat(wysiwygLangFilenames, contains("fId_26|en|fId_26_wysiwyg_en.txt")); wysiwygLangFilenames = extractForeignIdLanguageFilenames(getDocumentRepository() .listWysiwygAttachmentsByBasename(session, instanceId, "wrong_fId_26_wysiwyg")); assertThat(wysiwygLangFilenames, hasSize(0)); // 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 wysiwygLangFilenames = extractForeignIdLanguageFilenames( getDocumentRepository().listWysiwygAttachmentsByBasename(session, instanceId, "")); assertThat(wysiwygLangFilenames, hasSize(2)); assertThat(wysiwygLangFilenames, containsInAnyOrder("fId_26|en|fId_26_wysiwyg_en.txt", "fId_26|fr|fId_26_wysiwyg_fr.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 wysiwygLangFilenames = extractForeignIdLanguageFilenames( getDocumentRepository().listWysiwygAttachmentsByBasename(session, instanceId, "")); assertThat(wysiwygLangFilenames, hasSize(3)); assertThat(wysiwygLangFilenames, containsInAnyOrder("fId_26|en|fId_26_wysiwyg_en.txt", "fId_26|fr|fId_26_wysiwyg_fr.txt", "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 wysiwygLangFilenames = extractForeignIdLanguageFilenames( getDocumentRepository().listWysiwygAttachmentsByBasename(session, instanceId, "")); assertThat(wysiwygLangFilenames, hasSize(4)); assertThat(wysiwygLangFilenames, containsInAnyOrder("fId_26|en|fId_26_wysiwyg_en.txt", "fId_26|fr|fId_26_wysiwyg_fr.txt", "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.apache.ode.bpel.engine.ProcessAndInstanceManagementImpl.java
public Collection<Long> delete(String filter) { final InstanceFilter instanceFilter = new InstanceFilter(filter); final List<Long> ret = new LinkedList<Long>(); if (garbage(filter)) { return ret; }//from w w w. j a v a 2 s .c om try { _db.exec(new BpelDatabase.Callable<Object>() { public Object run(BpelDAOConnection conn) { Collection<ProcessInstanceDAO> instances = conn.instanceQuery(instanceFilter); for (ProcessInstanceDAO instance : instances) { ProcessConf proc = _store.getProcessConfiguration(instance.getProcess().getProcessId()); if (proc == null) throw new ProcessNotFoundException( "ProcessNotFound:" + instance.getProcess().getProcessId()); // delete the instance and all related data instance.delete(EnumSet.allOf(CLEANUP_CATEGORY.class)); ret.add(instance.getInstanceId()); } return null; } }); } catch (Exception e) { __log.error("Exception during instance deletion", e); throw new ProcessingException("Exception during instance deletion: " + e.toString()); } return ret; }
From source file:org.apache.hadoop.yarn.api.TestPBImplRecords.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private static Object genTypeValue(Type type) { Object ret = typeValueCache.get(type); if (ret != null) { return ret; }//from ww w. j a va 2s . c o m // only use positive primitive values if (type.equals(boolean.class)) { return rand.nextBoolean(); } else if (type.equals(byte.class)) { return bytes[rand.nextInt(4)]; } else if (type.equals(int.class)) { return rand.nextInt(1000000); } else if (type.equals(long.class)) { return Long.valueOf(rand.nextInt(1000000)); } else if (type.equals(float.class)) { return rand.nextFloat(); } else if (type.equals(double.class)) { return rand.nextDouble(); } else if (type.equals(String.class)) { return String.format("%c%c%c", 'a' + rand.nextInt(26), 'a' + rand.nextInt(26), 'a' + rand.nextInt(26)); } else if (type instanceof Class) { Class clazz = (Class) type; if (clazz.isArray()) { Class compClass = clazz.getComponentType(); if (compClass != null) { ret = Array.newInstance(compClass, 2); Array.set(ret, 0, genTypeValue(compClass)); Array.set(ret, 1, genTypeValue(compClass)); } } else if (clazz.isEnum()) { Object[] values = clazz.getEnumConstants(); ret = values[rand.nextInt(values.length)]; } else if (clazz.equals(ByteBuffer.class)) { // return new ByteBuffer every time // to prevent potential side effects ByteBuffer buff = ByteBuffer.allocate(4); rand.nextBytes(buff.array()); return buff; } } else if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) type; Type rawType = pt.getRawType(); Type[] params = pt.getActualTypeArguments(); // only support EnumSet<T>, List<T>, Set<T>, Map<K,V> if (rawType.equals(EnumSet.class)) { if (params[0] instanceof Class) { Class c = (Class) (params[0]); return EnumSet.allOf(c); } } if (rawType.equals(List.class)) { ret = Lists.newArrayList(genTypeValue(params[0])); } else if (rawType.equals(Set.class)) { ret = Sets.newHashSet(genTypeValue(params[0])); } else if (rawType.equals(Map.class)) { Map<Object, Object> map = Maps.newHashMap(); map.put(genTypeValue(params[0]), genTypeValue(params[1])); ret = map; } } if (ret == null) { throw new IllegalArgumentException("type " + type + " is not supported"); } typeValueCache.put(type, ret); return ret; }
From source file:org.apache.accumulo.test.proxy.SimpleProxyBase.java
@Test(expected = AccumuloSecurityException.class, timeout = 5000) public void attachIteratorLoginFailure() throws Exception { client.attachIterator(badLogin, "slow", setting, EnumSet.allOf(IteratorScope.class)); }
From source file:org.carrot2.workbench.core.ui.SearchEditor.java
/** * Create internal panels and hook up listener infrastructure. *///w w w. j a v a 2 s . co m private void createControls(SashForm parent) { /* * Create and add panels in order of their declaration in the enum type. */ this.panels = Maps.newEnumMap(PanelName.class); int index = 0; for (final PanelName s : EnumSet.allOf(PanelName.class)) { final Section section; switch (s) { case CLUSTERS: section = createClustersPart(parent, getSite()); break; case DOCUMENTS: section = createDocumentsPart(parent, getSite()); break; case ATTRIBUTES: section = createAttributesPart(parent, getSite()); break; default: throw new RuntimeException("Unknown section: " + s); } final PanelReference sr = new PanelReference(section, index++); panels.put(s, sr); } /* * Set up selection event forwarding. */ this.selectionProvider = new SearchEditorSelectionProvider(this); this.getSite().setSelectionProvider(selectionProvider); final ClusterTree tree = (ClusterTree) panels.get(PanelName.CLUSTERS).section.getClient(); /* Link bidirectional selection synchronization. */ new ClusterTreeSelectionAdapter(selectionProvider, tree); /* * Set up an event callback making editor dirty when attributes change. */ this.getSearchResult().getInput().addAttributeListener(new AttributeListenerAdapter() { public void valueChanged(AttributeEvent event) { setDirty(true); } }); /* * Set up an event callback to spawn auto-update jobs on changes to attributes. */ resources.registerAttributeChangeListener(this.getSearchResult().getInput(), autoUpdateListener); /* * Set up an event callback to restart processing after auto-update is enabled and * the editor is dirty. */ resources.registerPropertyChangeListener(WorkbenchCorePlugin.getDefault().getPreferenceStore(), autoUpdateListener2); /* * Install a synchronization agent between the current selection in the editor and * the document list panel. */ final DocumentList documentList = (DocumentList) panels.get(PanelName.DOCUMENTS).section.getClient(); new DocumentListSelectionAdapter(selectionProvider, documentList, this); /* * Restore state information. */ restoreState(); }
From source file:org.apache.accumulo.test.proxy.SimpleProxyBase.java
@Test(expected = AccumuloSecurityException.class, timeout = 5000) public void checkIteratorLoginFailure() throws Exception { client.checkIteratorConflicts(badLogin, tableName, setting, EnumSet.allOf(IteratorScope.class)); }
From source file:org.silverpeas.migration.jcr.service.SimpleDocumentServiceTest.java
/** * Test of listWysiwygByInstanceId method, of class DocumentRepository. */// w w w .j a va 2s . co m @Test public void listWysiwygByInstanceId() 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().listWysiwygByInstanceId(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().listWysiwygByInstanceId(instanceId)); 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().listWysiwygByInstanceId(instanceId)); 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().listWysiwygByInstanceId(instanceId)); 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().listWysiwygByInstanceId(instanceId)); 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().listWysiwygByInstanceId(instanceId)); 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().listWysiwygByInstanceId(instanceId)); 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().listWysiwygByInstanceId(instanceId)); assertThat(wysiwygFIdLangFilenames, hasSize(3)); assertThat(wysiwygFIdLangFilenames, containsInAnyOrder("fId_26|fr|fId_26_wysiwyg_fr.txt", "fId_26|en|fId_26_wysiwyg_en.txt", "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().listWysiwygByInstanceId(instanceId)); assertThat(wysiwygFIdLangFilenames, hasSize(4)); assertThat(wysiwygFIdLangFilenames, containsInAnyOrder("fId_26|fr|fId_26_wysiwyg_fr.txt", "fId_26|en|fId_26_wysiwyg_en.txt", "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.apache.hadoop.yarn.server.resourcemanager.webapp.TestRMWebServicesNodes.java
@Test public void testQueryAll() throws Exception { WebResource r = resource();//from ww w. j av a 2 s .co m getRunningRMNode("h1", 1234, 5120); // add h2 node in NEW state getNewRMNode("h2", 1235, 5121); // add lost node RMNode nm3 = getRunningRMNode("h3", 1236, 5122); sendLostEvent(nm3); ClientResponse response = r.path("ws").path("v1").path("cluster").path("nodes") .queryParam("states", Joiner.on(',').join(EnumSet.allOf(NodeState.class))) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); JSONObject nodes = json.getJSONObject("nodes"); assertEquals("incorrect number of elements", 1, nodes.length()); JSONArray nodeArray = nodes.getJSONArray("node"); assertEquals("incorrect number of elements", 3, nodeArray.length()); }
From source file:org.kuali.kfs.module.tem.document.TravelReimbursementDocument.java
/** * This method returns total expense amount minus the non-reimbursable. Overridden to remove manually adjusted per diem if it exists * * @return/* www .j ava2s . co m*/ */ @Override public KualiDecimal getApprovedAmount() { KualiDecimal total = KualiDecimal.ZERO; for (ExpenseType expense : EnumSet.allOf(ExpenseType.class)) { KualiDecimal expenseAmount = getTravelExpenseService().getExpenseServiceByType(expense) .getAllExpenseTotal(this, false); if (expenseAmount == null) { expenseAmount = KualiDecimal.ZERO; } total = expenseAmount.add(total); if (expense.equals(ExpenseType.perDiem) && getPerDiemAdjustment() != null && getPerDiemAdjustment().isPositive() && expenseAmount.isPositive()) { total = total.subtract(getPerDiemAdjustment()); } } return total; }
From source file:org.apache.accumulo.test.proxy.SimpleProxyBase.java
@Test(expected = AccumuloSecurityException.class, timeout = 5000) public void removeIteratorLoginFailure() throws Exception { client.removeIterator(badLogin, tableName, "name", EnumSet.allOf(IteratorScope.class)); }