List of usage examples for java.util Collections singleton
public static <T> Set<T> singleton(T o)
From source file:com.vmware.photon.controller.model.adapters.vsphere.TestVSphereProvisionWithStaticIpTask.java
@Test public void deployByCloningWithCustomization() throws Throwable { this.nicDescription = new NetworkInterfaceDescription(); this.nicDescription.assignment = IpAssignment.STATIC; this.nicDescription.address = "10.0.0.2"; this.subnet = new SubnetState(); this.subnet.dnsSearchDomains = Collections.singleton("local"); this.subnet.name = "my-subnet"; this.subnet.gatewayAddress = "10.0.0.1"; this.subnet.dnsServerAddresses = Collections.singleton("8.8.8.8"); this.subnet.domain = "local"; this.subnet.subnetCIDR = "10.0.0.0/24"; // Create a resource pool where the VM will be housed this.resourcePool = createResourcePool(); this.auth = createAuth(); this.computeHostDescription = createComputeHostDescription(); this.computeHost = createComputeHost(); // enumerate all resources hoping to find the template doRefresh();/*from ww w . j a v a2s . co m*/ snapshotFactoryState("networks", NetworkService.class); // find the template by vm name // template must have vm-tools and cloud-config installed ComputeState template = findTemplate(); this.network = fetchServiceState(NetworkState.class, findPortGroup(networkId)); // create instance by cloning ComputeDescription vmDescription = createVmDescription(); ComputeState vm = createVmState(vmDescription, template.documentSelfLink); // kick off a provision task to do the actual VM creation ProvisionComputeTaskState outTask = createProvisionTask(vm); awaitTaskEnd(outTask); vm = getComputeState(vm); if (!isMock()) { assertEquals(vm.address, this.nicDescription.address); } deleteVmAndWait(vm); }
From source file:com.opengamma.bbg.BloombergSecuritySource.java
@Override public ManageableSecurity getSingle(ExternalIdBundle bundle) { ArgumentChecker.notNull(bundle, "bundle"); Validate.isTrue(bundle.size() > 0, "Cannot load security for empty identifiers"); Map<ExternalIdBundle, ManageableSecurity> securities = _bloombergBulkSecurityLoader .loadSecurity(Collections.singleton(bundle)); if (securities.size() == 1) { return securities.get(bundle); } else {/*from w ww .j a va 2s . c om*/ s_logger.warn("Bloomberg return security={} for id={}", securities.values(), bundle); return null; } }
From source file:com.haulmont.cuba.web.gui.components.WebLabel.java
@Override public void setDatasource(Datasource datasource, String property) { this.datasource = datasource; resolveMetaPropertyPath(datasource.getMetaClass(), property); switch (metaProperty.getType()) { case ASSOCIATION: component.setConverter(new StringToEntityConverter() { @Override/* w w w . j a v a 2s . c o m*/ public Formatter getFormatter() { return WebLabel.this.formatter; } }); break; case DATATYPE: component.setConverter(new StringToDatatypeConverter(metaProperty.getRange().asDatatype()) { @Override public Formatter getFormatter() { return WebLabel.this.formatter; } }); break; case ENUM: //noinspection unchecked component.setConverter(new StringToEnumConverter((Class<Enum>) metaProperty.getJavaType()) { @Override public Formatter getFormatter() { return WebLabel.this.formatter; } }); break; default: component.setConverter(new StringToDatatypeConverter(Datatypes.getNN(String.class)) { @Override public Formatter getFormatter() { return WebLabel.this.formatter; } }); break; } final ItemWrapper wrapper = createDatasourceWrapper(datasource, Collections.singleton(metaPropertyPath)); component.setPropertyDataSource(wrapper.getItemProperty(metaPropertyPath)); }
From source file:com.google.gerrit.util.http.testutil.FakeHttpServletRequest.java
@Override public Enumeration<Locale> getLocales() { return Collections.enumeration(Collections.singleton(Locale.US)); }
From source file:io.lavagna.service.UserServiceTest.java
@Test public void createUserWithPermissions() { projectService.create("test", "TEST", "desc"); Project project = projectService.findByShortName("TEST"); Set<Permission> permissions = EnumSet.of(Permission.READ, Permission.CREATE_FILE); permissionService.createRole(new Role("A")); permissionService.updatePermissionsToRole(new Role("A"), permissions); UserToCreate userToCreate = new UserToCreate(); userToCreate.setUsername("test"); userToCreate.setProvider("demo"); userToCreate.setEnabled(true);// w ww .j ava 2s. c om userToCreate.setRoles(Arrays.asList("A")); userService.createUser(userToCreate); int userId = userRepository.findUserByName("demo", "test").getId(); permissionService.createRoleInProjectId(new Role("ROLE_PROJ"), project.getId()); permissionService.assignRoleToUsersInProjectId(new Role("ROLE_PROJ"), Collections.singleton(userId), project.getId()); permissionService.updatePermissionsToRoleInProjectId(new Role("ROLE_PROJ"), permissions, project.getId()); UserWithPermission uwp = userService.findUserWithPermission(userId); Assert.assertEquals(uwp.getBasePermissions().keySet(), permissions); Assert.assertEquals(uwp.getPermissionsForProject().get("TEST").keySet(), permissions); }
From source file:be.fgov.kszbcss.rhq.websphere.WebSphereServerPlugin.java
/** * auto inventory resources in two phases * // w w w . ja v a 2s . c om * The sweep phase uninventories all resources which are tagged as 'unconfigured' for a certain time. The mark phase * checks for all unavailable resources if they're still configured and adds the 'unconfigured' tag if so. * * @param invocation * job context */ public void autoUninventory(ScheduledJobInvocationContext invocation) { try { Subject user = LookupUtil.getSubjectManager().getOverlord(); TagManagerLocal tagManager = LookupUtil.getTagManager(); ResourceManagerLocal resourceManager = LookupUtil.getResourceManager(); int uninventoryDelay = Integer .parseInt(invocation.getJobDefinition().getCallbackData().getProperty("uninventoryDelay")); // addTags either creates a new tag or returns an existing tag Tag unconfiguredTag = tagManager .addTags(user, Collections.singleton(new Tag("websphere", null, "unconfigured"))).iterator() .next(); // Resources to check LinkedList<Resource> resources = new LinkedList<Resource>(); // Sweep - search resources that can be uninventoried ResourceCriteria resourceCriteria = new ResourceCriteria(); resourceCriteria.addFilterCurrentAvailability(AvailabilityType.DISABLED); resourceCriteria.addFilterTag(unconfiguredTag); resourceCriteria.fetchTags(true); resourceCriteria.setPageControl(PageControl.getUnlimitedInstance()); PageList<Resource> resourcePageList = resourceManager.findResourcesByCriteria(user, resourceCriteria); for (Resource resource : resourcePageList) { ResourceAvailabilitySummary availability = resourceManager.getAvailabilitySummary(user, resource.getId()); if ((System.currentTimeMillis() - availability.getLastChange().getTime()) / 60000 > uninventoryDelay) { LOG.debug("Removing unconfigured tag from resource " + resource.getName() + " (" + resource.getId() + ") to work around an issue in RHQ 4.5.1"); Set<Tag> tags = resource.getTags(); tags.remove(unconfiguredTag); tagManager.updateResourceTags(user, resource.getId(), tags); LOG.info("About to uninventory " + resource.getName() + " (" + resource.getId() + ")"); resourceManager.uninventoryResources(user, new int[] { resource.getId() }); } else { LOG.debug("Resource " + resource.getName() + " (" + resource.getId() + ") is tagged as unconfigured; force configuration check"); resources.add(resource); } } // Search for WebSphere resources that are down and check if they have been unconfigured // AvailabilityType.MISSING results seems to have been converted to DOWN at this point resourceCriteria = new ResourceCriteria(); resourceCriteria.addFilterCurrentAvailability(AvailabilityType.DOWN); resourceCriteria.addFilterPluginName("WebSphere"); resourceCriteria.fetchParentResource(true); resourceCriteria.fetchTags(true); resourceCriteria.setPageControl(PageControl.getUnlimitedInstance()); resourcePageList = resourceManager.findResourcesByCriteria(user, resourceCriteria); for (Resource resource : resourcePageList) { if (!resourcePageList.contains(resource.getParentResource())) { resources.add(resource); } } // check and mark - for all resources that were already marked as unconfigured and for the unavailable resources checkAndMarkUnconfiguredResources(resources, unconfiguredTag); } catch (RuntimeException e) { // need to catch all exceptions here because letting the exception pass will unschedule the job forevermore LOG.error("Exception during autoUninventory of resources", e); } }
From source file:com.hp.autonomy.frontend.find.hod.search.FindHodDocumentServiceTest.java
@Test public void invalidIndexName() throws HodErrorException { final ResourceIdentifier goodIndex = testUtils.getDatabases().get(0); final ResourceIdentifier badIndex = new ResourceIdentifier("bad", "bad"); when(cacheManager.getCache(CacheNames.DATABASES)).thenReturn(cache); final HodError invalidIndexError = new HodError.Builder().setErrorCode(HodErrorCode.INDEX_NAME_INVALID) .build();//from w w w. j a va 2 s . c om final HodSearchResult result = new HodSearchResult.Builder().setIndex(goodIndex.getName()).build(); final Documents<HodSearchResult> mockedResults = new Documents<>(Collections.singletonList(result), 1, null, null, null, null); when(queryTextIndexService.queryTextIndexWithText(anyString(), any(QueryRequestBuilder.class))) .thenThrow(new HodErrorException(invalidIndexError, HttpStatus.INTERNAL_SERVER_ERROR.value())) .thenReturn(mockedResults); final Database goodDatabase = new Database.Builder().setName(goodIndex.getName()) .setDomain(goodIndex.getDomain()).build(); when(databasesService.getDatabases(any(HodDatabasesRequest.class))) .thenReturn(Collections.singleton(goodDatabase)); final QueryRestrictions<ResourceIdentifier> queryRestrictions = new HodQueryRestrictions.Builder() .setQueryText("*").setDatabases(Arrays.asList(goodIndex, badIndex)).setAnyLanguage(true).build(); final SearchRequest<ResourceIdentifier> searchRequest = new SearchRequest.Builder<ResourceIdentifier>() .setQueryRestrictions(queryRestrictions).setStart(1).setMaxResults(30).setSummary("concept") .setSummaryCharacters(250).setSort(null).setHighlight(true).setAutoCorrect(false) .setQueryType(SearchRequest.QueryType.MODIFIED).build(); final Documents<HodSearchResult> results = documentsService.queryTextIndex(searchRequest); assertThat(results.getDocuments(), hasSize(1)); assertNotNull(results.getWarnings()); assertThat(results.getWarnings().getInvalidDatabases(), hasSize(1)); assertEquals(badIndex, results.getWarnings().getInvalidDatabases().iterator().next()); verify(cache).clear(); }
From source file:com.orange.cepheus.cep.controller.AdminControllerValidationTest.java
@Test public void configurationValidationTypeInAttr() throws Exception { Configuration configuration = getBasicConf(); Attribute testAttr = new Attribute(null, "t"); configuration.getEventTypeIns().get(0).setAttributes(Collections.singleton(testAttr)); checkValidationError(configuration); testAttr.setName(""); checkValidationError(configuration); testAttr.setName("name"); testAttr.setType(null);/* w ww. j av a 2s . com*/ checkValidationError(configuration); testAttr.setType(""); checkValidationError(configuration); }
From source file:io.relution.jenkins.awssqs.SQSTrigger.java
@Override public Collection<? extends Action> getProjectActions() { return Collections.singleton(new SQSTriggerPollingAction()); }