List of usage examples for java.util EnumSet of
public static <E extends Enum<E>> EnumSet<E> of(E e)
From source file:com.couchbase.touchdb.testapp.tests.Attachments.java
@SuppressWarnings("unchecked") public void testAttachments() throws Exception { TDBlobStore attachments = database.getAttachments(); Assert.assertEquals(0, attachments.count()); Assert.assertEquals(new HashSet<Object>(), attachments.allKeys()); TDStatus status = new TDStatus(); Map<String, Object> rev1Properties = new HashMap<String, Object>(); rev1Properties.put("foo", 1); rev1Properties.put("bar", false); TDRevision rev1 = database.putRevision(new TDRevision(rev1Properties), null, false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); byte[] attach1 = "This is the body of attach1".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1), rev1.getSequence(), "attach", "text/plain", rev1.getGeneration()); Assert.assertEquals(TDStatus.CREATED, status.getCode()); TDAttachment attachment = database.getAttachmentForSequence(rev1.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment.getContentType()); byte[] data = IOUtils.toByteArray(attachment.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); Map<String, Object> innerDict = new HashMap<String, Object>(); innerDict.put("content_type", "text/plain"); innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE="); innerDict.put("length", 27); innerDict.put("stub", true); innerDict.put("revpos", 1); Map<String, Object> attachmentDict = new HashMap<String, Object>(); attachmentDict.put("attach", innerDict); Map<String, Object> attachmentDictForSequence = database .getAttachmentsDictForSequenceWithContent(rev1.getSequence(), false); Assert.assertEquals(attachmentDict, attachmentDictForSequence); TDRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(TDDatabase.TDContentOptions.class)); Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Check the attachment dict, with attachments included: innerDict.remove("stub"); innerDict.put("data", Base64.encodeBytes(attach1)); attachmentDictForSequence = database.getAttachmentsDictForSequenceWithContent(rev1.getSequence(), true); Assert.assertEquals(attachmentDict, attachmentDictForSequence); gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.of(TDDatabase.TDContentOptions.TDIncludeAttachments)); gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Add a second revision that doesn't update the attachment: Map<String, Object> rev2Properties = new HashMap<String, Object>(); rev2Properties.put("_id", rev1.getDocId()); rev2Properties.put("foo", 2); rev2Properties.put("bazz", false); TDRevision rev2 = database.putRevision(new TDRevision(rev2Properties), rev1.getRevId(), false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); status = database.copyAttachmentNamedFromSequenceToSequence("attach", rev1.getSequence(), rev2.getSequence());/*from w ww . j av a2 s .c om*/ Assert.assertEquals(TDStatus.OK, status.getCode()); // Add a third revision of the same document: Map<String, Object> rev3Properties = new HashMap<String, Object>(); rev3Properties.put("_id", rev2.getDocId()); rev3Properties.put("foo", 2); rev3Properties.put("bazz", false); TDRevision rev3 = database.putRevision(new TDRevision(rev3Properties), rev2.getRevId(), false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); byte[] attach2 = "<html>And this is attach2</html>".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach2), rev3.getSequence(), "attach", "text/html", rev2.getGeneration()); Assert.assertEquals(TDStatus.CREATED, status.getCode()); // Check the 2nd revision's attachment: TDAttachment attachment2 = database.getAttachmentForSequence(rev2.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment2.getContentType()); data = IOUtils.toByteArray(attachment2.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); // Check the 3rd revision's attachment: TDAttachment attachment3 = database.getAttachmentForSequence(rev3.getSequence(), "attach", status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals("text/html", attachment3.getContentType()); data = IOUtils.toByteArray(attachment3.getContentStream()); Assert.assertTrue(Arrays.equals(attach2, data)); // Examine the attachment store: Assert.assertEquals(2, attachments.count()); Set<TDBlobKey> expected = new HashSet<TDBlobKey>(); expected.add(TDBlobStore.keyForBlob(attach1)); expected.add(TDBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected, attachments.allKeys()); status = database.compact(); // This clears the body of the first revision Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals(1, attachments.count()); Set<TDBlobKey> expected2 = new HashSet<TDBlobKey>(); expected2.add(TDBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected2, attachments.allKeys()); }
From source file:io.springagora.store.AppInitializer.java
/** * Web Application.// w w w . jav a2 s . c o m * * @param container * {@code ServletContext}. Representation of the context that is serving * the JEE application. Servlets, filters and listeners are registered * via this interface. */ private void initializeWebApplication(ServletContext container) { AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(WebConfig.class); DispatcherServlet webDispatcher = new DispatcherServlet(dispatcherContext); ServletRegistration.Dynamic servletReg = container.addServlet(dispatcherWebName, webDispatcher); servletReg.setLoadOnStartup(1); servletReg.addMapping(URL_PATTERN_WEB); HiddenHttpMethodFilter filter = new HiddenHttpMethodFilter(); FilterRegistration.Dynamic filterReg = container.addFilter("Hidden HTTP Method Filter", filter); filterReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, dispatcherWebName); }
From source file:ch.cyberduck.core.cryptomator.CopyWorkerTest.java
@Test public void testCopyFile() throws Exception { final Host host = new Host(new DAVProtocol(), "test.cyberduck.ch", new Credentials(System.getProperties().getProperty("webdav.user"), System.getProperties().getProperty("webdav.password"))); host.setDefaultPath("/dav/basic"); final DAVSession session = new DAVSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path home = new DefaultHomeFinderService(session).find(); final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); final Path source = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); final Path target = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator); session.withRegistry(registry);/*from w ww . j a v a 2 s.c o m*/ final byte[] content = RandomUtils.nextBytes(40500); final TransferStatus status = new TransferStatus(); new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new DAVDeleteFeature(session), cryptomator).pre( Transfer.Type.upload, Collections.singletonMap(source, status), new DisabledConnectionCallback()); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), new CryptoWriteFeature<>(session, new DAVWriteFeature(session), cryptomator).write(source, status.length(content.length), new DisabledConnectionCallback())); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source)); final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new TestSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback()); worker.run(session); assertTrue(new CryptoFindFeature(session, new DAVFindFeature(session), cryptomator).find(source)); assertTrue(new CryptoFindFeature(session, new DAVFindFeature(session), cryptomator).find(target)); final ByteArrayOutputStream out = new ByteArrayOutputStream(content.length); assertEquals(content.length, IOUtils.copy( new CryptoReadFeature(session, new DAVReadFeature(session), cryptomator).read(target, new TransferStatus().length(content.length), new DisabledConnectionCallback()), out)); assertArrayEquals(content, out.toByteArray()); new DeleteWorker(new DisabledLoginCallback(), Collections.singletonList(vault), PathCache.empty(), new DisabledProgressListener()).run(session); session.close(); }
From source file:com.netflix.spinnaker.front50.model.AzureStorageService.java
@Override public <T extends Timestamped> Collection<T> loadObjectsWithPrefix(ObjectType objectType, String prefix, int maxResults) { Set<T> blobs = new HashSet<>(); String key = buildKeyPath(objectType.group, prefix, ""); try {/* www .j a va 2 s . c o m*/ ResultContinuation token = null; EnumSet<BlobListingDetails> listDetails = EnumSet.of(BlobListingDetails.METADATA); do { ResultSegment<ListBlobItem> result = blobContainer.listBlobsSegmented(key, true, listDetails, maxResults, token, null, null); token = result.getContinuationToken(); for (ListBlobItem item : result.getResults()) { blobs.add(deserialize((CloudBlockBlob) item, (Class<T>) objectType.clazz)); } } while (token != null); } catch (IOException e) { throw new IllegalStateException("Unable to deserialize object(s) (key: " + key + ")", e); } catch (StorageException se) { logStorageException(se, key); } catch (Exception e) { log.error("Failed to retrieve objects with prefix {}: {}", key, e.getMessage()); } return blobs; }
From source file:com.couchbase.cblite.testapp.tests.Attachments.java
@SuppressWarnings("unchecked") public void testAttachments() throws Exception { CBLBlobStore attachments = database.getAttachments(); Assert.assertEquals(0, attachments.count()); Assert.assertEquals(new HashSet<Object>(), attachments.allKeys()); CBLStatus status = new CBLStatus(); Map<String, Object> rev1Properties = new HashMap<String, Object>(); rev1Properties.put("foo", 1); rev1Properties.put("bar", false); CBLRevision rev1 = database.putRevision(new CBLRevision(rev1Properties), null, false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); byte[] attach1 = "This is the body of attach1".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach1), rev1.getSequence(), "attach", "text/plain", rev1.getGeneration()); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); CBLAttachment attachment = database.getAttachmentForSequence(rev1.getSequence(), "attach", status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment.getContentType()); byte[] data = IOUtils.toByteArray(attachment.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); Map<String, Object> innerDict = new HashMap<String, Object>(); innerDict.put("content_type", "text/plain"); innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE="); innerDict.put("length", 27); innerDict.put("stub", true); innerDict.put("revpos", 1); Map<String, Object> attachmentDict = new HashMap<String, Object>(); attachmentDict.put("attach", innerDict); Map<String, Object> attachmentDictForSequence = database .getAttachmentsDictForSequenceWithContent(rev1.getSequence(), false); Assert.assertEquals(attachmentDict, attachmentDictForSequence); CBLRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(CBLDatabase.TDContentOptions.class)); Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Check the attachment dict, with attachments included: innerDict.remove("stub"); innerDict.put("data", Base64.encodeBytes(attach1)); attachmentDictForSequence = database.getAttachmentsDictForSequenceWithContent(rev1.getSequence(), true); Assert.assertEquals(attachmentDict, attachmentDictForSequence); gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.of(CBLDatabase.TDContentOptions.TDIncludeAttachments)); gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Assert.assertEquals(attachmentDict, gotAttachmentDict); // Add a second revision that doesn't update the attachment: Map<String, Object> rev2Properties = new HashMap<String, Object>(); rev2Properties.put("_id", rev1.getDocId()); rev2Properties.put("foo", 2); rev2Properties.put("bazz", false); CBLRevision rev2 = database.putRevision(new CBLRevision(rev2Properties), rev1.getRevId(), false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); status = database.copyAttachmentNamedFromSequenceToSequence("attach", rev1.getSequence(), rev2.getSequence());//from w w w.j a va2s. c o m Assert.assertEquals(CBLStatus.OK, status.getCode()); // Add a third revision of the same document: Map<String, Object> rev3Properties = new HashMap<String, Object>(); rev3Properties.put("_id", rev2.getDocId()); rev3Properties.put("foo", 2); rev3Properties.put("bazz", false); CBLRevision rev3 = database.putRevision(new CBLRevision(rev3Properties), rev2.getRevId(), false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); byte[] attach2 = "<html>And this is attach2</html>".getBytes(); status = database.insertAttachmentForSequenceWithNameAndType(new ByteArrayInputStream(attach2), rev3.getSequence(), "attach", "text/html", rev2.getGeneration()); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); // Check the 2nd revision's attachment: CBLAttachment attachment2 = database.getAttachmentForSequence(rev2.getSequence(), "attach", status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals("text/plain", attachment2.getContentType()); data = IOUtils.toByteArray(attachment2.getContentStream()); Assert.assertTrue(Arrays.equals(attach1, data)); // Check the 3rd revision's attachment: CBLAttachment attachment3 = database.getAttachmentForSequence(rev3.getSequence(), "attach", status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals("text/html", attachment3.getContentType()); data = IOUtils.toByteArray(attachment3.getContentStream()); Assert.assertTrue(Arrays.equals(attach2, data)); // Examine the attachment store: Assert.assertEquals(2, attachments.count()); Set<CBLBlobKey> expected = new HashSet<CBLBlobKey>(); expected.add(CBLBlobStore.keyForBlob(attach1)); expected.add(CBLBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected, attachments.allKeys()); status = database.compact(); // This clears the body of the first revision Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals(1, attachments.count()); Set<CBLBlobKey> expected2 = new HashSet<CBLBlobKey>(); expected2.add(CBLBlobStore.keyForBlob(attach2)); Assert.assertEquals(expected2, attachments.allKeys()); }
From source file:de.blizzy.documentr.access.UserStore.java
private void createInitialRoles(User adminUser) throws IOException { saveRole(new Role("Administrator", EnumSet.of(Permission.ADMIN)), adminUser); //$NON-NLS-1$ saveRole(new Role("Editor", EnumSet.of(Permission.EDIT_BRANCH, Permission.EDIT_PAGE)), adminUser); //$NON-NLS-1$ saveRole(new Role("Reader", EnumSet.of(Permission.VIEW)), adminUser); //$NON-NLS-1$ Set<RoleGrantedAuthority> authorities = Collections .singleton(new RoleGrantedAuthority(GrantedAuthorityTarget.APPLICATION, "Administrator")); //$NON-NLS-1$ saveUserAuthorities(adminUser.getLoginName(), authorities, adminUser); authorities = Collections.singleton(new RoleGrantedAuthority(GrantedAuthorityTarget.APPLICATION, "Reader")); //$NON-NLS-1$ saveUserAuthorities(ANONYMOUS_USER_LOGIN_NAME, authorities, adminUser); }
From source file:eu.itesla_project.histodb.client.impl.OfflineDbImpl.java
@Override public OfflineWorkflowCreationParameters getParameters(String workflowId) { Matcher m = ID_PATTERN.matcher(workflowId); if (!m.matches()) { throw new IllegalArgumentException("Unexpected workflow id"); }//from w w w . j ava 2 s.c om return new OfflineWorkflowCreationParameters(EnumSet.of(Country.FR), new DateTime(Long.parseLong(m.group(1))), new Interval(new DateTime(Long.parseLong(m.group(2))), new DateTime(Long.parseLong(m.group(3)))), false, false); }
From source file:ch.cyberduck.core.dropbox.DropboxWriteFeatureTest.java
@Test public void testWriteAppendChunks() throws Exception { final DropboxWriteFeature write = new DropboxWriteFeature(session, 44000L); final TransferStatus status = new TransferStatus(); final byte[] content = RandomUtils.nextBytes(290000); status.setLength(content.length);/*from ww w .j a v a 2 s .co m*/ final Path test = new Path(new DefaultHomeFinderService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final OutputStream out = write.write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out); assertTrue(new DropboxFindFeature(session).find(test)); assertEquals(content.length, session.list(test.getParent(), new DisabledListProgressListener()).get(test) .attributes().getSize()); assertEquals(content.length, write.append(test, status.getLength(), PathCache.empty()).size, 0L); { final InputStream in = new DropboxReadFeature(session).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback()); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length); new StreamCopier(status, status).transfer(in, buffer); in.close(); assertArrayEquals(content, buffer.toByteArray()); } { final byte[] buffer = new byte[content.length - 1]; final InputStream in = new DropboxReadFeature(session).read(test, new TransferStatus().length(content.length).append(true).skip(1L), new DisabledConnectionCallback()); IOUtils.readFully(in, buffer); in.close(); final byte[] reference = new byte[content.length - 1]; System.arraycopy(content, 1, reference, 0, content.length - 1); assertArrayEquals(reference, buffer); } new DropboxDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
From source file:org.apache.hadoop.gateway.svcregfunc.impl.ServiceRegistryFunctionsTest.java
public void setUp(String username, Map<String, String> initParams) throws Exception { ServiceRegistry mockServiceRegistry = EasyMock.createNiceMock(ServiceRegistry.class); EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "NAMENODE")) .andReturn("test-nn-scheme://test-nn-host:411").anyTimes(); EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "JOBTRACKER")) .andReturn("test-jt-scheme://test-jt-host:511").anyTimes(); GatewayServices mockGatewayServices = EasyMock.createNiceMock(GatewayServices.class); EasyMock.expect(mockGatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE)) .andReturn(mockServiceRegistry).anyTimes(); EasyMock.replay(mockServiceRegistry, mockGatewayServices); String descriptorUrl = getTestResource("rewrite.xml").toExternalForm(); Log.setLog(new NoOpLogger()); server = new ServletTester(); server.setContextPath("/"); server.getContext().addEventListener(new UrlRewriteServletContextListener()); server.getContext().setInitParameter(UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl);/* w w w . ja v a2s .c o m*/ server.getContext().setAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE, "test-cluster"); server.getContext().setAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE, mockGatewayServices); FilterHolder setupFilter = server.addFilter(SetupFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); setupFilter.setFilter(new SetupFilter(username)); FilterHolder rewriteFilter = server.addFilter(UrlRewriteServletFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); if (initParams != null) { for (Map.Entry<String, String> entry : initParams.entrySet()) { rewriteFilter.setInitParameter(entry.getKey(), entry.getValue()); } } rewriteFilter.setFilter(new UrlRewriteServletFilter()); interactions = new ArrayQueue<MockInteraction>(); ServletHolder servlet = server.addServlet(MockServlet.class, "/"); servlet.setServlet(new MockServlet("mock-servlet", interactions)); server.start(); interaction = new MockInteraction(); request = HttpTester.newRequest(); response = null; }
From source file:com.neurotec.samples.panels.EnrollFromScanner.java
private void startCapturing() { lblInfo.setText(""); if (FingersTools.getInstance().getClient().getFingerScanner() == null) { JOptionPane.showMessageDialog(this, "Please select scanner from the list.", "No scanner selected", JOptionPane.PLAIN_MESSAGE); return;//www .ja v a 2s .c o m } // Create a finger. NFinger finger = new NFinger(); // Set Manual capturing mode if automatic isn't selected. if (!cbAutomatic.isSelected()) { finger.setCaptureOptions(EnumSet.of(NBiometricCaptureOption.MANUAL)); } // Add finger to subject and finger view. subject = new NSubject(); subject.getFingers().add(finger); view.setFinger(finger); view.setShownImage(ShownImage.ORIGINAL); // Begin capturing. NBiometricTask task = FingersTools.getInstance().getClient() .createTask(EnumSet.of(NBiometricOperation.CAPTURE, NBiometricOperation.CREATE_TEMPLATE), subject); FingersTools.getInstance().getClient().performTask(task, null, captureCompletionHandler); scanning = true; updateControls(); }