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:com.whizzosoftware.hobson.dto.task.HobsonTaskDTOTest.java

@Test
public void testToJSON() {
    HobsonTaskDTO dto = new HobsonTaskDTO.Builder("taskLink").name("My Task").description("Task Desc")
            .conditions(Collections.singletonList(new PropertyContainerDTO.Builder("conditionclass1")
                    .containerClass(new PropertyContainerClassDTO.Builder("conditionClassLink").build())
                    .values(Collections.singletonMap("foo", (Object) "bar")).build()))
            .actionSet(new PropertyContainerSetDTO.Builder("actionSetLink")
                    .containers(Collections.singletonList(new PropertyContainerDTO.Builder("pc1").build()))
                    .build())//from   w  w  w .j a  v  a2s  .  c  om
            .build();

    JSONObject json = dto.toJSON();
    assertEquals("taskLink", json.getString("@id"));
    assertEquals("My Task", json.getString("name"));

    assertTrue(json.has("conditions"));
    JSONArray jcs = json.getJSONArray("conditions");
    assertEquals(1, jcs.length());
    JSONObject jct = jcs.getJSONObject(0);
    assertTrue(jct.has("cclass"));
    assertEquals("conditionClassLink", jct.getJSONObject("cclass").getString("@id"));
    assertTrue(jct.has("values"));

    assertTrue(json.has("actionSet"));
    JSONObject jas = json.getJSONObject("actionSet");
    assertTrue(jas.has("@id"));
    assertEquals("actionSetLink", jas.getString("@id"));
    assertTrue(jas.has("actions"));
}

From source file:org.apereo.openlrs.services.StatementServiceTest.java

@Before
public void setup() {
    actor = new XApiActor();
    actor.setMbox("mailto:test@test.com");
    verb = new XApiVerb();
    verb.setId("http://example.com/verb");
    verb.setDisplay(Collections.singletonMap("en-US", "verb"));
    object = new XApiObject();
    object.setId("http://example.com/object");
}

From source file:com.yahoo.elide.core.exceptions.HttpStatusException.java

public Pair<Integer, JsonNode> getVerboseErrorResponse() {
    Map<String, List<String>> errors = Collections.singletonMap("errors",
            Collections.singletonList(getVerboseMessage()));
    return buildResponse(errors);
}

From source file:com.gm.wine.dao.NoticeHibernateDao.java

/**
 * {@inheritDoc}/*from  w w  w .j  a v  a2  s  . c om*/
 * 
 * @since 2012-11-25
 * @see com.gm.machine.api.AdvertDao#batchDelete(java.util.List)
 */
@Override
public void batchDelete(List<Long> ids) {
    String hql = "delete from Notice where id in(:ids)";
    Map<String, List<Long>> values = Collections.singletonMap("ids", ids);
    super.batchExecute(hql, values);

}

From source file:org.hsweb.web.mybatis.user.UserMapperTest.java

@Test
public void testQuery() {
    User user = new User();
    user.setId("test");
    user.setUsername("admin");
    user.setName("test");
    Pager.doPaging(0, 20);/*from   w  w  w  . j a v  a 2 s.c  om*/
    Query.forList(userMapper::select, new QueryParam()).sql("username is not null").or()
            .sql("username=#{username}", Collections.singletonMap("username", "root")).fromBean(user)
            .$like$("username").list();
}

From source file:org.brutusin.rpc.websocket.WebsocketFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    if (isDisabled || httpRequest.getRequestURI() == null
            || !(httpRequest.getRequestURI().substring(httpRequest.getContextPath().length())
                    .startsWith(RpcConfig.getInstance().getPath() + "/wskt"))) {
        chain.doFilter(request, response);
        return;/* w w w  . j av  a  2 s . co m*/
    }
    final Map<String, String[]> fakedParams = Collections.singletonMap("requestId",
            new String[] { String.valueOf(counter.getAndIncrement()) });
    HttpServletRequestWrapper wrappedRequest = new HttpServletRequestWrapper(httpRequest) {
        @Override
        public Map<String, String[]> getParameterMap() {
            return fakedParams;
        }
    };
    /*
     * current request is needed for getEndpointInstance(). In glassfish getEndpointInstance() is executed out this filter chain, 
     * but inside whole request-response cycle (controlled by the overall listener that sets and removes GlobalThreadLocal)
     */
    if (GlobalThreadLocal.get() == null) {
        throw new AssertionError();
    }
    Object securityContext;
    if (ClassUtils.isPresent("org.springframework.security.core.context.SecurityContextHolder",
            RpcWebInitializer.class.getClassLoader())) {
        securityContext = SecurityContextHolder.getContext();
    } else {
        securityContext = null;
    }
    GlobalThreadLocal.set(new GlobalThreadLocal(wrappedRequest, securityContext)); // override current request with the one with faked params and security context
    chain.doFilter(wrappedRequest, response);
}

From source file:com.gm.bamboo.dao.BaseDataHibernateDao.java

/**
 * {@inheritDoc}/*ww w .ja va  2 s  .co  m*/
 * 
 * @since 2012-7-25
 * @see com.gm.bamboo.api.BaseDataDao#batchDelete(java.util.List)
 */
@Override
public void batchDelete(List<Long> ids) {
    String hql = "delete from BaseData where id in(:ids)";
    Map<String, List<Long>> values = Collections.singletonMap("ids", ids);
    super.batchExecute(hql, values);

}

From source file:com.gm.bamboo.dao.AdvertHibernateDao.java

/**
 * {@inheritDoc}/*from   w w w  .  j  av  a 2 s.  com*/
 * 
 * @since 2012-7-25
 * @see com.gm.bamboo.api.BaseDataDao#batchDelete(java.util.List)
 */
@Override
public void batchDelete(List<Long> ids) {
    String hql = "delete from Advert where id in(:ids)";
    Map<String, List<Long>> values = Collections.singletonMap("ids", ids);
    super.batchExecute(hql, values);

}

From source file:com.gm.machine.dao.PostHibernateDao.java

/**
 * {@inheritDoc}//from  w ww .  ja  va2s  . co m
 * 
 * @since 2012-11-25
 * @see com.gm.machine.api.AdvertDao#batchDelete(java.util.List)
 */
@Override
public void batchDelete(List<Long> ids) {
    String hql = "delete from Post where id in(:ids)";
    Map<String, List<Long>> values = Collections.singletonMap("ids", ids);
    super.batchExecute(hql, values);

}

From source file:org.terasoluna.gfw.common.date.jodatime.JdbcFixedJodaTimeDateFactoryTest.java

/**
 * normal case 1. <br>/*from  w  w w . j  av  a  2  s.  co m*/
 * use prepared table.
 */
@Test
public void testNewDateTime01() throws Exception {
    // crate table
    jdbcTemplate.getJdbcOperations().execute("CREATE TABLE system_date(now timestamp NOT NULL)");
    jdbcTemplate.update("INSERT INTO system_date(now) VALUES (:now)",
            Collections.singletonMap("now", new DateTime(2012, 9, 11, 2, 25, 15, 100).toDate()));

    JdbcFixedJodaTimeDateFactory dateFactory = new JdbcFixedJodaTimeDateFactory();
    dateFactory.setDataSource(dataSource);
    dateFactory.setCurrentTimestampQuery("SELECT now FROM system_date");

    DateTime now = dateFactory.newDateTime();
    assertThat(now.getYear(), is(2012));
    assertThat(now.getMonthOfYear(), is(9));
    assertThat(now.getDayOfMonth(), is(11));
    assertThat(now.getHourOfDay(), is(2));
    assertThat(now.getMinuteOfHour(), is(25));
    assertThat(now.getSecondOfMinute(), is(15));
    assertThat(now.getMillisOfSecond(), is(100));

    // drop table
    jdbcTemplate.getJdbcOperations().execute("DROP TABLE system_date");
}