List of usage examples for java.util Collections singleton
public static <T> Set<T> singleton(T o)
From source file:com.dangdang.ddframe.rdb.common.sql.base.AbstractSQLTest.java
private static BasicDataSource buildDataSource(final String dbName, final DatabaseType type) { DataBaseEnvironment dbEnv = new DataBaseEnvironment(type); BasicDataSource result = new BasicDataSource(); result.setDriverClassName(dbEnv.getDriverClassName()); result.setUrl(dbEnv.getURL(dbName)); result.setUsername(dbEnv.getUsername()); result.setPassword(dbEnv.getPassword()); result.setMaxActive(1000);// w ww .j a v a2s . c o m if (DatabaseType.Oracle == dbEnv.getDatabaseType()) { result.setConnectionInitSqls(Collections.singleton("ALTER SESSION SET CURRENT_SCHEMA = " + dbName)); } return result; }
From source file:com.codecrate.shard.transfer.pcgen.PcgenDatasetImporter.java
private Collection<File> findDatasets(File root) { if (isDataset(root)) { return Collections.singleton(root); }/*from w w w.j a v a 2 s . com*/ Collection<File> results = new TreeSet<File>(); File[] files = root.listFiles(); if (null != files) { for (int i = 0; i < files.length; i++) { File child = files[i]; if (child.isDirectory()) { results.addAll(findDatasets(child)); } } } return results; }
From source file:ch.cyberduck.core.irods.IRODSReadFeatureTest.java
@Test(expected = NotfoundException.class) public void testReadNotFound() 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)); new IRODSReadFeature(session).read(test, new TransferStatus(), new DisabledConnectionCallback()); }
From source file:com.yahoo.elide.jsonapi.JsonApiTest.java
@Test public void writeSingleIncluded() throws JsonProcessingException { Parent parent = new Parent(); Child child = new Child(); parent.setId(123L);//w ww .j a va2 s . c o m child.setId(2); parent.setFirstName("bob"); parent.setChildren(Collections.singleton(child)); child.setParents(Collections.singleton(parent)); child.setFriends(new HashSet<>()); PersistentResource<Parent> pRec = new PersistentResource<>(parent, userScope); JsonApiDocument jsonApiDocument = new JsonApiDocument(); jsonApiDocument.setData(new Data<>(pRec.toResource())); jsonApiDocument.addIncluded(new PersistentResource<>(pRec, child, userScope).toResource()); String expected = "{\"data\":{\"type\":\"parent\",\"id\":\"123\",\"attributes\":{\"firstName\":\"bob\"},\"relationships\":{\"children\":{\"data\":[{\"type\":\"child\",\"id\":\"2\"}]},\"spouses\":{\"data\":[]}}},\"included\":[{\"type\":\"child\",\"id\":\"2\",\"attributes\":{\"name\":null},\"relationships\":{\"friends\":{\"data\":[]},\"parents\":{\"data\":[{\"type\":\"parent\",\"id\":\"123\"}]}}}]}"; String doc = mapper.writeJsonApiDocument(jsonApiDocument); assertEquals(doc, expected); }
From source file:org.apache.ambari.server.controller.metrics.timeline.AMSReportPropertyProviderTest.java
@Test public void testPopulateResources() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider(SINGLE_HOST_METRICS_FILE_PATH); injectCacheEntryFactoryWithStreamProvider(streamProvider); TestMetricHostProvider metricHostProvider = new TestMetricHostProvider(); ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class); Map<String, Map<String, PropertyInfo>> propertyIds = PropertyHelper .getMetricPropertyIds(Resource.Type.Cluster); AMSReportPropertyProvider propertyProvider = new AMSReportPropertyProvider(propertyIds, streamProvider, sslConfiguration, cacheProvider, metricHostProvider, CLUSTER_NAME_PROPERTY_ID); String propertyId = PropertyHelper.getPropertyId("metrics/cpu", "User"); Resource resource = new ResourceImpl(Resource.Type.Cluster); resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1"); Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>(); temporalInfoMap.put(propertyId, new TemporalInfoImpl(1416445244800L, 1416448936474L, 1L)); Request request = PropertyHelper.getReadRequest(Collections.singleton(propertyId), temporalInfoMap); Set<Resource> resources = propertyProvider.populateResources(Collections.singleton(resource), request, null);//from w w w .j a v a 2s. c o m Assert.assertEquals(1, resources.size()); Resource res = resources.iterator().next(); Map<String, Object> properties = PropertyHelper.getProperties(resources.iterator().next()); Assert.assertNotNull(properties); URIBuilder uriBuilder = AMSPropertyProvider.getAMSUriBuilder("localhost", 6188, false); uriBuilder.addParameter("metricNames", "cpu_user"); uriBuilder.addParameter("appId", "HOST"); uriBuilder.addParameter("startTime", "1416445244800"); uriBuilder.addParameter("endTime", "1416448936474"); Assert.assertEquals(uriBuilder.toString(), streamProvider.getLastSpec()); Number[][] val = (Number[][]) res.getPropertyValue("metrics/cpu/User"); Assert.assertEquals(111, val.length); }
From source file:com.thomasjensen.sercoll.SerializableUnmodifiableHashMapUTest.java
@Test public void testUnsupportedOps() { final SerializableMap<String, String> mapUnderTest = buildNewTestMap(); try {//from ww w . j a va 2s . c o m mapUnderTest.clear(); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { mapUnderTest.put("D", "value"); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { mapUnderTest.putAll(new HashMap<String, String>()); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { mapUnderTest.remove("A"); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { mapUnderTest.keySet().remove("B"); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { mapUnderTest.keySet().add("E"); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { mapUnderTest.keySet().clear(); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { mapUnderTest.keySet().removeAll(Collections.singleton("A")); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { mapUnderTest.keySet().addAll(Arrays.asList("E", "F")); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { mapUnderTest.keySet().retainAll(Collections.singleton("A")); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { mapUnderTest.values().remove("B"); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } Map.Entry<String, String> entry1 = mapUnderTest.entrySet().iterator().next(); Assert.assertNotNull(entry1); try { mapUnderTest.entrySet().remove(entry1); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { entry1.setValue("poison"); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { mapUnderTest.entrySet().clear(); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } try { Iterator<Entry<String, String>> iter = mapUnderTest.entrySet().iterator(); Assert.assertNotNull(iter.next()); iter.remove(); Assert.fail("expected exception was not thrown"); } catch (UnsupportedOperationException e) { // expected } }
From source file:com.mirth.connect.server.api.servlets.ChannelStatusServlet.java
@Override @CheckAuthorizedChannelId/*from w w w . ja v a 2 s .c o m*/ public void stopChannel(String channelId, boolean returnErrors) { ErrorTaskHandler handler = new ErrorTaskHandler(); engineController.stopChannels(Collections.singleton(channelId), handler); if (returnErrors && handler.isErrored()) { throw new MirthApiException(handler.getError()); } }
From source file:org.hupo.psi.mi.psicquic.ws.IndexBasedPsicquicService.java
private String createQuery(String fieldName, DbRef dbRef) { return createQuery(fieldName, Collections.singleton(dbRef), null); }
From source file:com.evolveum.midpoint.web.page.admin.server.PageTaskController.java
public void deleteSyncTokenPerformed(AjaxRequestTarget target) { LOGGER.debug("Deleting sync token."); OperationResult result = new OperationResult(PageTaskEdit.OPERATION_DELETE_SYNC_TOKEN); Task operationTask = parentPage.createSimpleTask(PageTaskEdit.OPERATION_DELETE_SYNC_TOKEN); try {/*w ww.j a v a 2 s .c om*/ final TaskDto taskDto = parentPage.getTaskDto(); final PrismProperty property = taskDto.getExtensionProperty(SchemaConstants.SYNC_TOKEN); if (property == null) { result.recordWarning("Token is not present in this task."); // should be treated by isVisible } else { final ObjectDelta<? extends ObjectType> delta = (ObjectDelta<? extends ObjectType>) DeltaBuilder .deltaFor(TaskType.class, parentPage.getPrismContext()) .item(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.SYNC_TOKEN), property.getDefinition()) .replace().asObjectDelta(parentPage.getTaskDto().getOid()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Deleting sync token:\n{}", delta.debugDump()); } parentPage.getModelService().executeChanges(Collections.singleton(delta), null, operationTask, result); result.recomputeStatus(); } } catch (Exception ex) { result.recomputeStatus(); result.recordFatalError("Couldn't delete sync token from the task.", ex); LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete sync token from the task.", ex); } afterStateChangingOperation(target, result); }