Adding non-string properties using Sling Testing Tools

Adding non-string properties using Sling Testing Tools

Recently, I was creating integration test following this article. Everything was working out nicely but then I couldn't figure out how to create anything other than a String data type in the JCR. I was specifically trying to create a Date data type. I found a nice document about the sling post servlet and Date properties. This showed the proper format for Date String but all the examples where for HTML forms. I tried formatting the Date Strings accordingly but still only Strings where being saved.

With help from Center of Excellence, he pointed out that I needed to use @TypeHint. After reviewing, I still ran into the issue of only form examples. So I just followed the examples but attempted to apply them toward the Map I was using. It worked!

How to add non-String properties to nodes using Sling Testing Tools


	SimpleDateFormat sdf = 
			new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

	Map<String,Object> propertiesMap = new HashMap<String,Object>() {
		private static final long serialVersionUID = 1L;
		{
			put(JcrConstants.JCR_PRIMARYTYPE, "nt:unstructured");
			put("mk:lastDownload", 
					sdf.format(lastDownload.getTime()));
			put("mk:lastDownload@TypeHint","Date");
			put("mk:assetType", MK_ASSETTYPE_1);
		}
	};		
	slingClient.createNode(
				damAssetPath,
				propertiesMap
			});

So all we have to do is add the data type name as one property then add another with the @TypeHint and the data type.

Share this post

0 Comments

comments powered by Disqus