List of usage examples for java.util Collections singletonMap
public static <K, V> Map<K, V> singletonMap(K key, V value)
From source file:com.flipkart.foxtrot.core.datastore.impl.hbase.HBaseDataStoreTest.java
@Test public void testSaveSingleNullId() throws Exception { Document document = new Document(null, System.currentTimeMillis(), mapper.valueToTree(Collections.singletonMap("TEST_NAME", "SINGLE_SAVE_TEST"))); try {/*w w w . j ava 2 s.c o m*/ HBaseDataStore.save(TEST_APP, document); fail(); } catch (DataStoreException ex) { assertEquals(DataStoreException.ErrorCode.STORE_INVALID_REQUEST, ex.getErrorCode()); } }
From source file:io.openshift.booster.BoosterApplicationTest.java
@Test public void testPutWithWrongPayload() { Fruit cherry = fruitRepository.save(new Fruit("Cherry")); given().contentType(ContentType.JSON).body(Collections.singletonMap("id", 0)).when() .put(String.valueOf(cherry.getId())).then().statusCode(422); }
From source file:com.lightboxtechnologies.nsrl.HashLoaderHelperTest.java
protected void writeRowTester(final boolean sha1rowkey) throws Exception { final long timestamp = 1234567890; final ProdData pd = new ProdData(42, "ACME Roadrunner Decapitator", "1.0", "1", "ACME", "Meep", "roadrunner exterminator"); final MfgData md = new MfgData("ACME", "ACME Corporation"); final Hex hex = new Hex(); final byte[] sha1 = (byte[]) hex.decode("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); final byte[] md5 = (byte[]) hex.decode("deadbeefdeadbeefdeadbeefdeadbeef"); final byte[] crc32 = (byte[]) hex.decode("deadbeef"); final byte[] sha1_col = "sha1".getBytes(); final byte[] md5_col = "md5".getBytes(); final byte[] crc32_col = "crc32".getBytes(); final byte[] size_col = "filesize".getBytes(); final byte[] nsrl_col = "NSRL".getBytes(); final byte[] family = HBaseTables.HASH_COLFAM_B; final byte[] key = sha1rowkey ? sha1 : md5; final byte ktype = (byte) (sha1rowkey ? 1 : 0); final HashData hd = new HashData(sha1, md5, crc32, "librrkill.so.1", 123456, pd.code, "ACME_OS", "special"); final ImmutableBytesWritable okey_crc32 = new ImmutableBytesWritable( KeyUtils.makeEntryKey(key, ktype, crc32_col)); final KeyValue kv_crc32 = new KeyValue(key, family, crc32_col, timestamp, crc32); final ImmutableBytesWritable okey_sha1 = new ImmutableBytesWritable( KeyUtils.makeEntryKey(key, ktype, sha1_col)); final KeyValue kv_sha1 = new KeyValue(key, family, sha1_col, timestamp, sha1); final ImmutableBytesWritable okey_md5 = new ImmutableBytesWritable( KeyUtils.makeEntryKey(key, ktype, md5_col)); final KeyValue kv_md5 = new KeyValue(key, family, md5_col, timestamp, md5); final ImmutableBytesWritable okey_size = new ImmutableBytesWritable( KeyUtils.makeEntryKey(key, ktype, size_col)); final KeyValue kv_size = new KeyValue(key, family, size_col, timestamp, Bytes.toBytes(hd.size)); final ImmutableBytesWritable okey_nsrl = new ImmutableBytesWritable( KeyUtils.makeEntryKey(key, ktype, nsrl_col)); final KeyValue kv_nsrl = new KeyValue(key, family, nsrl_col, timestamp, nsrl_col); final byte[] prod_col = (md.name + '/' + pd.name + ' ' + pd.version).getBytes(); final ImmutableBytesWritable okey_prod = new ImmutableBytesWritable( KeyUtils.makeEntryKey(key, ktype, prod_col)); final KeyValue kv_prod = new KeyValue(key, family, prod_col, timestamp, prod_col); final Map<Integer, List<ProdData>> prod = Collections.singletonMap(pd.code, Collections.singletonList(pd)); final Map<String, MfgData> mfg = Collections.singletonMap(md.code, md); final Map<String, OSData> os = null; @SuppressWarnings("unchecked") final HashLoaderMapper.Context ctx = context.mock(HashLoaderMapper.Context.class); context.checking(new Expectations() { {//from w w w. j a va2 s .c o m oneOf(ctx).write(okey_crc32, kv_crc32); if (sha1rowkey) { oneOf(ctx).write(okey_md5, kv_md5); } else { oneOf(ctx).write(okey_sha1, kv_sha1); } oneOf(ctx).write(okey_size, kv_size); oneOf(ctx).write(okey_nsrl, kv_nsrl); oneOf(ctx).write(okey_prod, kv_prod); } }); final HashLoaderHelper hlh = new HashLoaderHelper(prod, mfg, os, timestamp); hlh.writeRow(key, hd, ctx); }
From source file:com.smartitengineering.cms.spi.impl.content.VelocityGeneratorTest.java
@Test public void testVelocityRepGeneration() throws IOException { TypeRepresentationGenerator generator = new VelocityRepresentationGenerator(); final RepresentationTemplate template = mockery.mock(RepresentationTemplate.class); WorkspaceAPIImpl impl = new WorkspaceAPIImpl() { @Override//from w ww. java 2s . co m public RepresentationTemplate getRepresentationTemplate(WorkspaceId id, String name) { return template; } }; impl.setRepresentationGenerators(Collections.singletonMap(TemplateType.VELOCITY, generator)); RepresentationProvider provider = new RepresentationProviderImpl(); final WorkspaceAPI api = impl; registerBeanFactory(api); final Content content = mockery.mock(Content.class); final Field field = mockery.mock(Field.class); final FieldValue value = mockery.mock(FieldValue.class); final Map<String, Field> fieldMap = mockery.mock(Map.class); final ContentType type = mockery.mock(ContentType.class); final Map<String, RepresentationDef> reps = mockery.mock(Map.class, "repMap"); final RepresentationDef def = mockery.mock(RepresentationDef.class); mockery.checking(new Expectations() { { exactly(1).of(template).getTemplateType(); will(returnValue(TemplateType.VELOCITY)); exactly(1).of(template).getTemplate(); will(returnValue(IOUtils.toByteArray( getClass().getClassLoader().getResourceAsStream("scripts/velocity/test-template.vm")))); exactly(1).of(template).getName(); will(returnValue(REP_NAME)); exactly(1).of(value).getValue(); will(returnValue(CONTENT)); exactly(1).of(field).getValue(); will(returnValue(value)); exactly(1).of(fieldMap).get(with(Expectations.<String>anything())); will(returnValue(field)); exactly(1).of(content).getFields(); will(returnValue(fieldMap)); exactly(1).of(content).getContentDefinition(); will(returnValue(type)); final ContentId contentId = mockery.mock(ContentId.class); exactly(2).of(content).getContentId(); will(returnValue(contentId)); final WorkspaceId wId = mockery.mock(WorkspaceId.class); exactly(1).of(contentId).getWorkspaceId(); will(returnValue(wId)); exactly(2).of(type).getRepresentationDefs(); will(returnValue(reps)); exactly(2).of(reps).get(with(REP_NAME)); will(returnValue(def)); exactly(1).of(def).getParameters(); will(returnValue(Collections.emptyMap())); exactly(1).of(def).getMIMEType(); will(returnValue(GroovyGeneratorTest.MIME_TYPE)); final ResourceUri rUri = mockery.mock(ResourceUri.class); exactly(1).of(def).getResourceUri(); will(returnValue(rUri)); exactly(1).of(rUri).getValue(); will(returnValue("iUri")); } }); Representation representation = provider.getRepresentation(REP_NAME, type, content); Assert.assertNotNull(representation); Assert.assertEquals(REP_NAME, representation.getName()); Assert.assertEquals(CONTENT, StringUtils.newStringUtf8(representation.getRepresentation())); Assert.assertEquals(GroovyGeneratorTest.MIME_TYPE, representation.getMimeType()); }
From source file:com.jaspersoft.jasperserver.war.xmla.XmlaRepositoryImpl.java
@Override public Map<String, RolapSchema> getRolapSchemas(RolapConnection connection, String databaseName, String catalogName) {/*from w ww. j ava 2 s . com*/ final RolapSchema schema = connection.getSchema(); return Collections.singletonMap(schema.getName(), schema); }
From source file:com.logsniffer.fields.FieldsMapJsonTest.java
@SuppressWarnings("unchecked") @Test/*from w w w . j av a 2 s .co m*/ public void testDeserializationOfUnknownFields() throws IOException { final FieldsMap map = new FieldsMap(); map.put("fa", new Date(120)); final JSONObject parsedJson = JSONObject.fromObject(mapper.writeValueAsString(map)); parsedJson.element("unknown", Collections.singletonMap("int", 134)); final String jsonStr = parsedJson.toString(); LOGGER.info("Serialized in extended form to: {}", jsonStr); final FieldsMap dMap = mapper.readValue(jsonStr, FieldsMap.class); Assert.assertNull(dMap.get("@types")); Assert.assertEquals(2, dMap.size()); Assert.assertEquals(new Date(120), dMap.get("fa")); Assert.assertTrue(dMap.get("unknown") instanceof Map); Assert.assertEquals(134, ((Map<String, Object>) dMap.get("unknown")).get("int")); }
From source file:ru.mystamps.web.dao.impl.JdbcCategoryDao.java
@Override public long countByName(String name) { return jdbcTemplate.queryForObject(countByNameSql, Collections.singletonMap("name", name), Long.class); }
From source file:io.pivotal.strepsirrhini.chaosloris.web.ApplicationControllerTest.java
@SuppressWarnings("unchecked") @Test/*from w w w . j a v a 2 s.c om*/ public void createDuplicateApplicationId() throws Exception { UUID applicationId = UUID.randomUUID(); when(this.applicationRepository.saveAndFlush(new Application(applicationId))) .thenThrow(DataIntegrityViolationException.class); this.mockMvc .perform(post("/applications").contentType(APPLICATION_JSON) .content(asJson(Collections.singletonMap("applicationId", applicationId.toString())))) .andExpect(status().isBadRequest()); }