ServletRegistrationComponent implements RestServicesMBean { public void setEnableCors( boolean enableCors ) { this.logger.fine( "CORS is now " + (enableCors ? "enabled" : "disabled") + ". Updating the REST resource." ); this.enableCors = enableCors; if( this.app != null ) this.app.enableCors( enableCors ); if( this.authenticationFilter != null ) this.authenticationFilter.setEnableCors( enableCors ); try { if( this.jerseyServlet != null ) this.jerseyServlet.reload(); } catch( Exception e ) { Utils.logException( this.logger, e ); } } ServletRegistrationComponent( BundleContext bundleContext ); void starting(); void stopping(); void schedulerAppears(); void schedulerDisappears(); void mavenResolverAppears(); void mavenResolverDisappears(); void setHttpService( HttpService httpService ); void setManager( Manager manager ); void setEnableCors( boolean enableCors ); void setEnableAuthentication( boolean enableAuthentication ); void setAuthenticationRealm( String authenticationRealm ); void setSessionPeriod( long sessionPeriod ); void setScheduler( IScheduler scheduler ); void setMavenResolver( MavenResolver mavenResolver ); @Override int getCurrentWebSocketClientsCount(); @Override long getWebSocketConnectionErrorsCount(); @Override long getRestRequestsWithAuthFailureCount(); @Override long getRestRequestsCount(); @Override boolean isAuthenticationRequired(); @Override boolean isCorsEnabled(); @Override void reset(); static final String REST_CONTEXT; static final String WEBSOCKET_CONTEXT; final AtomicLong restRequestsCount; final AtomicLong restRequestsWithAuthFailureCount; static final AtomicLong WS_CONNECTION_ERRORS_COUNT; }
@Test public void testSetEnableCors() throws Exception { this.register.setEnableCors( true ); this.register.setEnableCors( false ); this.register.app = Mockito.spy( new RestApplication( this.manager )); this.register.jerseyServlet = Mockito.mock( ServletContainer.class ); this.register.setEnableCors( true ); Mockito.verify( this.register.app, Mockito.times( 1 )).enableCors( true ); Mockito.verify( this.register.jerseyServlet, Mockito.only()).reload(); Mockito.reset( this.register.app ); Mockito.reset( this.register.jerseyServlet ); this.register.setEnableCors( false ); Mockito.verify( this.register.app, Mockito.times( 1 )).enableCors( false ); Mockito.verify( this.register.jerseyServlet, Mockito.only()).reload(); this.register.stopping(); this.register.setEnableCors( true ); Assert.assertTrue( this.register.isCorsEnabled()); this.register.setEnableCors( false ); Assert.assertFalse( this.register.isCorsEnabled()); }