List of usage examples for java.util Collections singleton
public static <T> Set<T> singleton(T o)
From source file:com.googlecode.spring.appengine.objectify.converter.OfyEntityClassConverter.java
@Override public Set<ConvertiblePair> getConvertibleTypes() { return Collections.singleton(new ConvertiblePair(Object.class, Object.class)); }
From source file:io.lavagna.service.UserService.java
@Transactional(readOnly = false) public void createUser(UserToCreate userToCreate) { requireNonNull(userToCreate);// ww w . ja v a 2s . c o m requireNonNull(userToCreate.getProvider()); requireNonNull(userToCreate.getUsername()); if (trimToNull(userToCreate.getPassword()) != null) { userToCreate.setPassword(hashPassword(userToCreate.getPassword())); } userRepository.createUser(userToCreate.getProvider(), userToCreate.getUsername(), userToCreate.getPassword(), userToCreate.getEmail(), userToCreate.getDisplayName(), userToCreate.getEnabled()); if (userToCreate.getRoles() == null) { return; } User u = userRepository.findUserByName(userToCreate.getProvider(), userToCreate.getUsername()); Set<Integer> userId = Collections.singleton(u.getId()); for (String r : userToCreate.getRoles()) { permissionService.assignRoleToUsers(new Role(r), userId); } }
From source file:com.cloudbees.jenkins.support.impl.NetworkInterfaces.java
@NonNull @Override public Set<Permission> getRequiredPermissions() { return Collections.singleton(Jenkins.ADMINISTER); }
From source file:ch.cyberduck.core.irods.IRODSReadFeatureTest.java
@Test public void testRead() throws Exception { final ProtocolFactory factory = new ProtocolFactory( new HashSet<>(Collections.singleton(new IRODSProtocol()))); final Profile profile = new ProfilePlistReader(factory) .read(new Local("../profiles/iRODS (iPlant Collaborative).cyberduckprofile")); final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials(System.getProperties().getProperty("irods.key"), System.getProperties().getProperty("irods.secret"))); final IRODSSession session = new IRODSSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path test = new Path(new IRODSHomeFinderService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); assertFalse(session.getFeature(Find.class).find(test)); final byte[] content = RandomUtils.nextBytes(2048); final TransferStatus status = new TransferStatus(); status.setLength(content.length);//from w w w.ja va2 s . c o m status.setAppend(false); final OutputStream out = new IRODSWriteFeature(session).write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out); out.close(); assertTrue(session.getFeature(Find.class).find(test)); final InputStream in = new IRODSReadFeature(session).read(test, status, new DisabledConnectionCallback()); assertNotNull(in); in.close(); session.getFeature(Delete.class).delete(Arrays.asList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); assertFalse(session.getFeature(Find.class).find(test)); session.close(); }
From source file:com.xtructure.xsim.impl.TestAbstractStandardXComponent.java
@Test public void testRetrieveForeignData() { final AbstractStandardXComponent component = new MockComponent(COMPONENT_ID, Collections.singleton(SOURCE_ID), Collections.singleton(TARGET_ID)); final XBorder border = new MockBorder((MockComponent) component); component.addBorder(border);// ww w. j a v a2 s . co m component.retrieveForeignData(); }
From source file:com.mirth.connect.server.api.servlets.CodeTemplateServlet.java
@Override public CodeTemplateLibrary getCodeTemplateLibrary(String libraryId, boolean includeCodeTemplates) { try {// w ww . j ava 2 s . c o m List<CodeTemplateLibrary> libraries = codeTemplateController .getLibraries(Collections.singleton(libraryId), includeCodeTemplates); if (CollectionUtils.isEmpty(libraries)) { throw new MirthApiException(Status.NOT_FOUND); } return libraries.iterator().next(); } catch (ControllerException e) { throw new MirthApiException(e); } }
From source file:com.redhat.red.offliner.ftest.FoloRecordAvoidedDownloadFTest.java
/** * In general, we should only have one test method per functional test. This allows for the best parallelism when we * execute the tests, especially if the setup takes some time. * * @throws Exception In case anything (anything at all) goes wrong! *///from w ww . j a v a 2 s. co m @Test public void run() throws Exception { // We only need one repo server. TestRepositoryServer server = newRepositoryServer(); // Generate some test content byte[] content = contentGenerator.newBinaryContent(1024); TrackedContentEntryDTO dto = contentGenerator.newRemoteContentEntry(new StoreKey(StoreType.remote, "test"), "jar", server.getBaseUri(), content); TrackedContentDTO record = new TrackedContentDTO(new TrackingKey("test-record"), Collections.emptySet(), Collections.singleton(dto)); String path = dto.getPath(); // Register the generated content by writing it to the path within the repo server's dir structure. // This way when the path is requested it can be downloaded instead of returning a 404. server.registerContent(path, content); server.registerContent(path + Main.SHA_SUFFIX, sha1Hex(content)); server.registerContent(path + Main.MD5_SUFFIX, md5Hex(content)); // Write the plaintext file we'll use as input. File foloRecord = temporaryFolder.newFile("folo." + getClass().getSimpleName() + ".json"); FileUtils.write(foloRecord, objectMapper.writeValueAsString(record)); Options opts = new Options(); opts.setBaseUrls(Collections.singletonList(server.getBaseUri())); // Capture the downloads here so we can verify the content. File downloads = temporaryFolder.newFolder(); opts.setDownloads(downloads); opts.setLocations(Collections.singletonList(foloRecord.getAbsolutePath())); Main firstMain = run(opts); assertThat("Wrong number of downloads logged. Should have been 3 with checksum files included.", firstMain.getDownloaded(), equalTo(3)); //re-run to test the function of avoiding re-downloading existing files Main secondMain = run(opts); assertThat("Wrong number of downloads logged. Should have been 0.", secondMain.getDownloaded(), equalTo(0)); assertThat("Wrong number of avoided downloads logged. Should have been 1", secondMain.getAvoided(), equalTo(3)); assertThat("Errors should be empty!", secondMain.getErrors().isEmpty(), equalTo(true)); }
From source file:zipkin.autoconfigure.metrics.PrometheusMetricsAutoConfigurationTest.java
@Test public void detectsGauges() throws Exception { PublicMetrics publicMetrics = () -> Collections.singleton(new Metric<Number>("gauge_mem.free", 1024)); ResponseEntity<String> response = responseForMetrics(publicMetrics); String body = response.getBody(); assertThat(body, equalTo("#TYPE mem_free gauge\n" + "#HELP mem_free mem_free\n" + "mem_free 1024.0\n")); }
From source file:com.mauersu.util.redis.DefaultSetOperations.java
public Set<V> difference(K key, K otherKey) { return difference(key, Collections.singleton(otherKey)); }