WidgetImpl w = new WidgetImpl();
w.setId(WIDGET_ID);
w.setType(Constants.WIDGET_TYPE);
w.setUrl(VALID_GADGET_URL);
Region region = new RegionImpl(REGION_ID);
RegionWidget rw = new RegionWidgetImpl();
rw.setId(REGION_WIDGET_ID);
rw.setCollapsed(VALID_COLLAPSED);
rw.setWidget(w);
rw.setRegion(region);
rw.setHideChrome(VALID_HIDE_CHROME);
rw.setLocked(VALID_LOCKED);
rw.setPreferences(Arrays.asList((RegionWidgetPreference)new RegionWidgetPreferenceImpl( 1L, "color", "blue"),
new RegionWidgetPreferenceImpl(1L, "speed", "fast"),
new RegionWidgetPreferenceImpl( 1L, null, null)));
final String markup =
"<script>rave.registerWidget(" + REGION_ID + ", {type: 'OpenSocial'," +
" regionWidgetId: " + REGION_WIDGET_ID + "," +
" widgetUrl: '" + VALID_GADGET_URL +"', " +
" securityToken: '" + VALID_SECURITY_TOKEN + "', " +
" metadata: " + VALID_METADATA + "," +
" userPrefs: {\"speed\":\"fast\",\"color\":\"blue\"}," +
" collapsed: " + VALID_COLLAPSED + ", " +
" widgetId: " + WIDGET_ID + "," +
" locked: " + VALID_LOCKED + "," +
" hideChrome: " + VALID_HIDE_CHROME +
"});</script>";
expect(securityTokenService.getEncryptedSecurityToken(rw)).andReturn(VALID_SECURITY_TOKEN);
replay(securityTokenService);
String key = OpenSocialWidgetRenderer.REGISTER_WIDGET_KEY+"-"+rw.getId();
scriptManager.registerScriptBlock(key, markup, ScriptLocation.AFTER_RAVE, RenderScope.CURRENT_REQUEST, renderContext);
expectLastCall();
replay(scriptManager);
String result = renderer.render(rw, renderContext);
assertThat(result, is(equalTo("<!-- RegionWidget " + rw.getId() + " placeholder -->")));
verify(scriptManager);
}