ServiceCacheController extends AbstractController { public void initBindings( DataServiceModel model ) { PushDownOptimizationMeta meta = locateServiceCacheMeta( model ); ServiceCache serviceCache = (ServiceCache) meta.getType(); BindingFactory bindingFactory = getBindingFactory(); XulRadio normalModeRadio = getElementById( "regular-type-radio" ); XulRadio streamingRadioButton = getElementById( "streaming-type-radio" ); XulTab serviceCacheTab = getElementById( "service-cache-tab" ); XulCheckbox serviceCacheCheckBox = getElementById( "service-cache-checkbox" ); XulTextbox serviceCacheTextBox = getElementById( "service-cache-ttl" ); bindingFactory.setBindingType( Binding.Type.ONE_WAY ); serviceCacheCheckBox.setChecked( meta.isEnabled() ); serviceCacheTab.setVisible( !model.isStreaming() ); try { serviceCacheTextBox.setValue( serviceCache.getConfiguredTimeToLive() ); } catch ( Exception e ) { getLogChannel().logError( "Unable to set default TTL", e ); } bindingFactory.createBinding( serviceCacheTextBox, "value", serviceCache, "timeToLive" ); bindingFactory.createBinding( serviceCacheCheckBox, "checked", meta, "enabled" ); bindingFactory.createBinding( serviceCacheCheckBox, "checked", serviceCacheTextBox, "disabled", not() ); bindingFactory.createBinding( normalModeRadio, "selected", serviceCacheTab, "visible" ); bindingFactory.createBinding( streamingRadioButton, "!selected", serviceCacheTab, "visible" ); } ServiceCacheController( ServiceCacheFactory factory ); void initBindings( DataServiceModel model );  }
@Test public void testBindingsNonStreaming() throws Exception { testBindingsAux(); controller.initBindings( model ); verify( checkbox ).setChecked( true ); verify( ttl ).setValue( "1200" ); verify( bindingFactory ).createBinding( checkbox, "checked", meta, "enabled" ); verify( bindingFactory ).createBinding( ttl, "value", serviceCache, "timeToLive" ); verify( serviceCacheTab ).setVisible( true ); verify( bindingFactory ).createBinding( streamingTypeRadio, "!selected", serviceCacheTab, "visible" ); verify( bindingFactory ).createBinding( regularTypeRadio, "selected", serviceCacheTab, "visible" ); }
@Test public void testBindingsStreaming() throws Exception { testBindingsAux(); RuntimeException e = new RuntimeException(); when( model.isStreaming() ).thenReturn( true ); controller.initBindings( model ); verify( checkbox ).setChecked( true ); verify( ttl ).setValue( "1200" ); verify( bindingFactory ).createBinding( checkbox, "checked", meta, "enabled" ); verify( bindingFactory ).createBinding( ttl, "value", serviceCache, "timeToLive" ); verify( serviceCacheTab ).setVisible( false ); verify( bindingFactory ).createBinding( streamingTypeRadio, "!selected", serviceCacheTab, "visible" ); verify( bindingFactory ).createBinding( regularTypeRadio, "selected", serviceCacheTab, "visible" ); }
@Test public void testBindingsTtlException() throws Exception { testBindingsAux(); RuntimeException e = new RuntimeException(); doThrow( e ).when( serviceCache ).getConfiguredTimeToLive(); when( model.isStreaming() ).thenReturn( true ); controller.initBindings( model ); verify( log ).logError( "Unable to set default TTL", e ); }