Example usage for java.util Collections singletonMap

List of usage examples for java.util Collections singletonMap

Introduction

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

Prototype

public static <K, V> Map<K, V> singletonMap(K key, V value) 

Source Link

Document

Returns an immutable map, mapping only the specified key to the specified value.

Usage

From source file:net.javacrumbs.springws.test.helper.DummyEndpoint.java

private boolean shoulReturnError(Source request) {
    XPathExpressionEvaluator evaluator = new XPathExpressionEvaluator();
    Document document = DefaultXmlUtil.getInstance().loadDocument(request);
    SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
    namespaceContext.setBindings(Collections.singletonMap("ns", "http://www.example.org/schema"));
    return "true"
            .equals(evaluator.evaluateExpression(document, "//ns:number='not-number'", null, namespaceContext));
}

From source file:ru.mystamps.web.dao.impl.JdbcStampsCatalogDao.java

public List<String> add(Set<String> catalogNumbers) {
    Validate.validState(!"".equals(addCatalogNumberSql), "Query must be non empty");

    List<String> inserted = new ArrayList<>();
    for (String number : catalogNumbers) {
        int affected = jdbcTemplate.update(addCatalogNumberSql, Collections.singletonMap("code", number));
        if (affected > 0) {
            inserted.add(number);/*from w  w  w .  ja  v  a 2  s.com*/
        }
    }

    return inserted;
}

From source file:br.com.thiaguten.persistence.demo.jpa.UserDAOImpl.java

@Override
public List<User> findByName(String name) {
    String jpql = "SELECT u FROM User u WHERE UPPER(u.name) LIKE :name";
    Map<String, String> namedParams = Collections.singletonMap("name", "%" + name.toUpperCase() + "%"); // like IGNORECASE and matchmode ANYWHERE
    List<User> results = persistenceProvider.findByQueryAndNamedParams(getPersistenceClass(), jpql,
            namedParams);/*from   ww w.  j  a  v  a  2 s . c  om*/
    if (results.isEmpty()) {
        return Collections.emptyList();
    } else {
        return Collections.unmodifiableList(results);
    }
}

From source file:org.cloudfoundry.identity.uaa.login.ProfileControllerTests.java

public void testPostForUpdate() {
    controller.setLinks(Collections.singletonMap("foo", "http://example.com"));
    Mockito.when(restTemplate.getForObject(approvalsUri, Set.class))
            .thenReturn(Collections.singleton(Collections.singletonMap("clientId", "foo")));
    Model model = new ExtendedModelMap();
    controller.post(Collections.singleton("read"), "", null, "foo", model);
    assertTrue(model.containsAttribute("links"));
    assertTrue(model.containsAttribute("approvals"));
}

From source file:com.graphaware.reco.neo4j.filter.CypherBlacklistBuilder.java

/**
 * {@inheritDoc}/*from w ww.  j a va2 s.  co m*/
 */
@Override
public final Set<Node> buildBlacklist(Node input) {
    notNull(input);

    Set<Node> excluded = new HashSet<>();

    ResourceIterator<Node> it = executionEngine
            .execute(query, Collections.singletonMap("id", (Object) input.getId())).columnAs("blacklist");

    while (it.hasNext()) {
        excluded.add(it.next());
    }

    return excluded;
}

From source file:edu.sampleu.bookstore.kew.BookTypeQualifierResolver.java

public List<Map<String, String>> resolve(RouteContext context) {
    List<Map<String, String>> qualifiers = new ArrayList<Map<String, String>>();
    MaintenanceDocument doc = (MaintenanceDocument) getDocument(context);
    Maintainable maint = doc.getNewMaintainableObject();
    Book book = (Book) maint.getDataObject();
    if (StringUtils.isNotEmpty(book.getTypeCode())) {
        qualifiers.add(Collections.singletonMap(BookstoreKimAttributes.BOOK_TYPE_CODE, book.getTypeCode()));
        decorateWithCommonQualifiers(qualifiers, context, null);
    } else {/*  w  w w  .  j av a 2s  .c  o  m*/
        Map<String, String> basicQualifier = new HashMap<String, String>();
        qualifiers.add(basicQualifier);
    }
    return qualifiers;
}

From source file:example.helloworld.CubbyholeAuthenticationTests.java

/**
 * Write some data to Vault before Vault can be used as {@link VaultPropertySource}.
 *//*from  ww  w . j  av a2s .com*/
@BeforeClass
public static void beforeClass() {

    VaultOperations vaultOperations = new VaultTestConfiguration().vaultTemplate();
    vaultOperations.write("secret/myapp/configuration", Collections.singletonMap("configuration.key", "value"));

    VaultResponse response = vaultOperations.doWithSession(new RestOperationsCallback<VaultResponse>() {

        @Override
        public VaultResponse doWithRestOperations(RestOperations restOperations) {

            HttpHeaders headers = new HttpHeaders();
            headers.add("X-Vault-Wrap-TTL", "10m");

            return restOperations.postForObject("auth/token/create", new HttpEntity<Object>(headers),
                    VaultResponse.class);
        }
    });

    // Response Wrapping requires Vault 0.6.0+
    Map<String, String> wrapInfo = response.getWrapInfo();
    initialToken = VaultToken.of(wrapInfo.get("token"));
}

From source file:net.javacrumbs.springws.test.validator.XPathRequestValidatorTest.java

@Test
public void testValidationFailsOnFirst() throws IOException {
    WebServiceMessage message = getValidMessage();
    String expression1 = "//ns:number = 0";
    Map<String, String> expressionMap = Collections.singletonMap(expression1, ERROR_MESSAGE + "1");

    AbstractExpressionProcessor validator = new XPathRequestValidator();
    ExpressionResolver resolver = createMock(ExpressionResolver.class);
    validator.setExpressionResolver(resolver);

    validator.setExceptionMapping(expressionMap);
    expect(resolver.resolveExpression(eq(expression1), (URI) anyObject(), (Document) anyObject()))
            .andReturn("true");

    replay(resolver);//  ww  w .  j ava  2s.  c om

    try {
        validator.processRequest(null, messageFactory, message);
        fail("Exception expected");
    } catch (WsTestException e) {
        assertEquals(ERROR_MESSAGE + "1", e.getMessage());
    }
    verify(resolver);
}

From source file:nl.conspect.legacy.user.web.LoginController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String username = ServletRequestUtils.getStringParameter(request, "j_username");
    String password = ServletRequestUtils.getStringParameter(request, "j_password");

    User user = userService.login(username, password);
    if (user != null) {
        WebUtils.setSessionAttribute(request, "currentUser", user);
        return new ModelAndView("account");
    }/*from w ww.j av a 2 s  .c  om*/
    return new ModelAndView("index", Collections.singletonMap("msg", "Wrong username/password combination."));
}

From source file:org.elasticsearch.xpack.core.rollup.RollupRestTestStateCleaner.java

private void waitForPendingTasks() throws Exception {
    ESTestCase.assertBusy(() -> {//  ww  w  .  ja  va  2s . co  m
        try {
            Response response = adminClient.performRequest("GET", "/_cat/tasks",
                    Collections.singletonMap("detailed", "true"));
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                try (BufferedReader responseReader = new BufferedReader(
                        new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8))) {
                    int activeTasks = 0;
                    String line;
                    StringBuilder tasksListString = new StringBuilder();
                    while ((line = responseReader.readLine()) != null) {

                        // We only care about Rollup jobs, otherwise this fails too easily due to unrelated tasks
                        if (line.startsWith(RollupJob.NAME) == true) {
                            activeTasks++;
                            tasksListString.append(line);
                            tasksListString.append('\n');
                        }
                    }
                    assertEquals(activeTasks + " active tasks found:\n" + tasksListString, 0, activeTasks);
                }
            }
        } catch (IOException e) {
            throw new AssertionError("Error getting active tasks list", e);
        }
    });
}