Example usage for java.util Collections singleton

List of usage examples for java.util Collections singleton

Introduction

In this page you can find the example usage for java.util Collections singleton.

Prototype

public static <T> Set<T> singleton(T o) 

Source Link

Document

Returns an immutable set containing only the specified object.

Usage

From source file:com.dickthedeployer.dick.web.service.WorkerServiceTest.java

private Build prepareBuild() {
    Namespace namespace = namespaceDao.save(new Namespace.Builder().withName("test-namespace").build());
    final Project project = new Project.Builder().withRef("master").withName(UUID.randomUUID().toString())
            .withRepository(UUID.randomUUID().toString()).withNamespace(namespace)
            .withEnvironmentVariables(Collections
                    .singleton(new com.dickthedeployer.dick.web.domain.EnvironmentVariable("BARKEY", "bar")))
            .build();//from w  w  w.  j av  a2 s.c  o m
    projectDao.save(project);
    Build build = new Build.Builder().withSha("somesha").withProject(project)
            .withEnvironmentVariables(asList(new EnvironmentVariable("FOOKEY", "foo"))).build();
    buildDao.save(build);
    return build;
}

From source file:org.sakuli.services.forwarder.database.DatabaseResultServiceImplTest.java

@Test
public void testSaveResultsInDatabaseWithTestcases() throws Exception {

    Integer tcPrimaryKey = 22;//from  ww w.j  av a 2 s. com
    TestCase tc1 = mock(TestCase.class);
    TestCaseStep tcs1 = mock(TestCaseStep.class);
    when(tc1.getDbPrimaryKey()).thenReturn(tcPrimaryKey);
    SortedSet<TestCaseStep> tcStepList = new TreeSet<>(Collections.singleton(tcs1));
    when(tc1.getStepsAsSortedSet()).thenReturn(tcStepList);

    TestCase tc2 = mock(TestCase.class);
    when(tc2.getSteps()).thenReturn(new ArrayList<>());

    Map<String, TestCase> testCaseMap = new HashMap<>();
    testCaseMap.put("1", tc1);
    testCaseMap.put("2", tc2);

    testSuite = new TestSuite();
    testSuite.setTestCases(testCaseMap);
    ReflectionTestUtils.setField(testling, "testSuite", testSuite);

    testling.saveAllResults();

    verify(daoTestSuite).saveTestSuiteResult();
    verify(daoTestSuite).saveTestSuiteToSahiJobs();
    verify(daoTestCase).saveTestCaseResult(tc1);
    verify(daoTestCase).saveTestCaseResult(tc2);
    verify(daoTestCase, times(2)).saveTestCaseResult(any(TestCase.class));
    verify(daoTestCaseStep).saveTestCaseSteps(tcStepList, tcPrimaryKey);
    verify(daoTestCaseStep).saveTestCaseSteps(any(SortedSet.class), anyInt());
}

From source file:com.jgoetsch.ib.handlers.SingleHandlerManager.java

public Collection<EWrapper> getHandlers(String eventName, int objectId) {
    EWrapper handler, noObjectHandler;//from w  ww. ja  va  2 s.co m
    synchronized (this) {
        handler = handlerMap.get(eventName, objectId);
        noObjectHandler = handlerMap.get(eventName, 0);
    }
    if (handler != null && noObjectHandler != null && handler != noObjectHandler)
        return Arrays.asList(handler, noObjectHandler);
    else if (handler != null)
        return Collections.singleton(handler);
    else if (noObjectHandler != null)
        return Collections.singleton(noObjectHandler);
    else
        return Collections.emptySet();
}

From source file:edu.pitt.dbmi.ccd.db.service.DataFileService.java

public List<DataFile> findByUserAccount(UserAccount userAccount) {
    return dataFileRepository.findByUserAccounts(Collections.singleton(userAccount));
}

From source file:org.cloudfoundry.identity.uaa.oauth.UaaUserApprovalHandlerTests.java

@Test
public void testAutoApproveByScope() {
    BaseClientDetails client = new BaseClientDetails("client", "none", "read,write", "authorization_code",
            "uaa.none");
    Mockito.when(clientDetailsService.loadClientByClientId("client")).thenReturn(client);
    client.setAdditionalInformation(Collections.singletonMap("autoapprove", Collections.singleton("read")));
    assertTrue(handler.isApproved(authorizationRequest, userAuthentication));
    client.setAdditionalInformation(Collections.singletonMap("autoapprove", Collections.singleton("write")));
    assertFalse(handler.isApproved(authorizationRequest, userAuthentication));
}

From source file:org.gvnix.addon.jpa.addon.JpaOperationsImpl.java

public void setup() {
    // Get add-on configuration file
    Element configuration = XmlUtils.getConfiguration(getClass());

    // Install the add-on repository needed
    List<Element> repos = XmlUtils.findElements("/configuration/gvnix/repositories/repository", configuration);
    for (Element repo : repos) {
        getProjectOperations().addRepositories(getProjectOperations().getFocusedModuleName(),
                Collections.singleton(new Repository(repo)));
    }//from w  w w. j a  v  a 2s  .com

    // Install properties
    List<Element> properties = XmlUtils.findElements("/configuration/gvnix/properties/*", configuration);
    for (Element property : properties) {
        getProjectOperations().addProperty(getProjectOperations().getFocusedModuleName(),
                new Property(property));
    }

    // Install dependencies
    List<Element> depens = XmlUtils.findElements("/configuration/gvnix/dependencies/dependency", configuration);

    DependenciesVersionManager.manageDependencyVersion(getMetadataService(), getProjectOperations(), depens);
}

From source file:org.kamranzafar.xmpp.template.XmppAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    //Authentication and BOSH pre-binding
    BoshConnectionConfiguration boshConfiguration = BoshConnectionConfiguration.builder()
            .hostname(xmppConfig.getHost()).port(xmppConfig.getPort()).file(xmppConfig.getHttpBind()).wait(60)
            .build();/*www  . j a v a 2  s .  com*/

    XmppClient xmppClient = new XmppClient(xmppConfig.getHost(), boshConfiguration);

    try {
        xmppClient.connect(new Jid((String) authentication.getPrincipal()));
        xmppClient.login((String) authentication.getPrincipal(), (String) authentication.getCredentials());

        rocks.xmpp.extensions.httpbind.BoshConnection boshConnection = (rocks.xmpp.extensions.httpbind.BoshConnection) xmppClient
                .getActiveConnection();

        String sessionId = boshConnection.getSessionId();

        // Detaches the BOSH session, without terminating it.
        long rid = boshConnection.detach();
        //            System.out.println("JID: " + xmppClient.getConnectedResource());
        //            System.out.println("SID: " + sessionId);
        //            System.out.println("RID: " + rid);

        XmppUser xmppUser = new XmppUser();
        xmppUser.setUsername((String) authentication.getPrincipal());
        xmppUser.setJid(xmppClient.getConnectedResource().toString());
        xmppUser.setSid(sessionId);
        xmppUser.setRid(rid);

        Collection<? extends GrantedAuthority> authorities = Collections
                .singleton(new SimpleGrantedAuthority("ROLE_USER"));

        return new UsernamePasswordAuthenticationToken(xmppUser, authentication.getCredentials(), authorities);
    } catch (XmppException e) {
        e.printStackTrace();
        throw new XmppAuthenticationException(e.getMessage(), e);
    }
}

From source file:hr.fer.zemris.vhdllab.service.extractor.testbench.TestbenchMetadataExtractor.java

@Override
protected Set<String> doExtractDependencies(String data) throws DependencyExtractionException {
    Testbench tb;//from  ww  w  . ja v a2s . co  m
    try {
        tb = TestbenchParser.parseXml(data);
    } catch (UniformTestbenchParserException e) {
        throw new DependencyExtractionException(e);
    }
    return Collections.singleton(tb.getSourceName());
}

From source file:org.neo4j.save.config.SingleLabelBasedNodeTypeRepresentationStrategy.java

private Set<String> getAllHierarchyLabelsForType(StoredEntityType type) {
    return Collections.singleton(type.getAlias().toString());
}

From source file:com.hp.autonomy.hod.sso.HodAuthenticationTest.java

@Test
public void serializesAndDeserializes() throws IOException, ClassNotFoundException {
    final HodAuthentication<EntityType.Combined> authentication = new HodAuthentication<>(
            new TokenProxy<>(EntityType.Combined.INSTANCE, TokenType.Simple.INSTANCE),
            Collections.singleton(GRANTED_AUTHORITY), PRINCIPAL);

    final HodAuthentication<EntityType.Combined> outputAuthentication = writeAndReadObject(authentication);
    assertThat(outputAuthentication, is(authentication));
}