@Test( expected = UnauthorizedActionException.class ) public void testReplaceApplicationBindings_failure_inexistingApplication() throws Exception { TestApplication app1 = new TestApplication(); app1.setDirectory( this.folder.newFolder()); app1.getTemplate().setExternalExportsPrefix( "prefix1" ); ManagedApplication ma1 = new ManagedApplication( app1 ); TestManagerWrapper.addManagedApplication( this.mngr, ma1 ); Assert.assertEquals( 0, ma1.getApplication().getApplicationBindings().size()); Mockito.verifyZeroInteractions( this.messagingMngr ); this.mngr.replaceApplicationBindings( ma1, "prefix1", new HashSet<>( Arrays.asList( "inexisting" ))); }
@Override public void replaceApplicationBindings( ManagedApplication ma, String externalExportPrefix, Set<String> applicationNames ) throws UnauthorizedActionException, IOException { for( String applicationName : applicationNames ) { Application app = findApplicationByName( applicationName ); if( app == null ) throw new UnauthorizedActionException( "Application " + applicationName + " does not exist." ); if( ! externalExportPrefix.equals( app.getTemplate().getExternalExportsPrefix())) throw new UnauthorizedActionException( "Application " + applicationName + "'s template does not have " + externalExportPrefix + " as external exports prefix." ); } boolean notify = ma.getApplication().replaceApplicationBindings( externalExportPrefix, applicationNames ); if( notify ) { ConfigurationUtils.saveApplicationBindings( ma.getApplication()); for( String applicationName : applicationNames ) { this.logger.fine( "External prefix " + externalExportPrefix + " is now bound to application " + applicationName + " in " + ma.getName() + "." ); } for( Instance inst : InstanceHelpers.findAllScopedInstances( ma.getApplication())) { MsgCmdChangeBinding msg = new MsgCmdChangeBinding( externalExportPrefix, ma.getApplication().getApplicationBindings().get( externalExportPrefix )); this.messagingMngr.sendMessageSafely( ma, inst, msg ); } } }
ApplicationMngrImpl implements IApplicationMngr { @Override public void replaceApplicationBindings( ManagedApplication ma, String externalExportPrefix, Set<String> applicationNames ) throws UnauthorizedActionException, IOException { for( String applicationName : applicationNames ) { Application app = findApplicationByName( applicationName ); if( app == null ) throw new UnauthorizedActionException( "Application " + applicationName + " does not exist." ); if( ! externalExportPrefix.equals( app.getTemplate().getExternalExportsPrefix())) throw new UnauthorizedActionException( "Application " + applicationName + "'s template does not have " + externalExportPrefix + " as external exports prefix." ); } boolean notify = ma.getApplication().replaceApplicationBindings( externalExportPrefix, applicationNames ); if( notify ) { ConfigurationUtils.saveApplicationBindings( ma.getApplication()); for( String applicationName : applicationNames ) { this.logger.fine( "External prefix " + externalExportPrefix + " is now bound to application " + applicationName + " in " + ma.getName() + "." ); } for( Instance inst : InstanceHelpers.findAllScopedInstances( ma.getApplication())) { MsgCmdChangeBinding msg = new MsgCmdChangeBinding( externalExportPrefix, ma.getApplication().getApplicationBindings().get( externalExportPrefix )); this.messagingMngr.sendMessageSafely( ma, inst, msg ); } } } }
ApplicationMngrImpl implements IApplicationMngr { @Override public void replaceApplicationBindings( ManagedApplication ma, String externalExportPrefix, Set<String> applicationNames ) throws UnauthorizedActionException, IOException { for( String applicationName : applicationNames ) { Application app = findApplicationByName( applicationName ); if( app == null ) throw new UnauthorizedActionException( "Application " + applicationName + " does not exist." ); if( ! externalExportPrefix.equals( app.getTemplate().getExternalExportsPrefix())) throw new UnauthorizedActionException( "Application " + applicationName + "'s template does not have " + externalExportPrefix + " as external exports prefix." ); } boolean notify = ma.getApplication().replaceApplicationBindings( externalExportPrefix, applicationNames ); if( notify ) { ConfigurationUtils.saveApplicationBindings( ma.getApplication()); for( String applicationName : applicationNames ) { this.logger.fine( "External prefix " + externalExportPrefix + " is now bound to application " + applicationName + " in " + ma.getName() + "." ); } for( Instance inst : InstanceHelpers.findAllScopedInstances( ma.getApplication())) { MsgCmdChangeBinding msg = new MsgCmdChangeBinding( externalExportPrefix, ma.getApplication().getApplicationBindings().get( externalExportPrefix )); this.messagingMngr.sendMessageSafely( ma, inst, msg ); } } } ApplicationMngrImpl(
			INotificationMngr notificationMngr,
			IConfigurationMngr configurationMngr,
			ITargetsMngr targetsMngr,
			IMessagingMngr messagingMngr,
			IRandomMngr randomMngr,
			IAutonomicMngr autonomicMngr ); }
ApplicationMngrImpl implements IApplicationMngr { @Override public void replaceApplicationBindings( ManagedApplication ma, String externalExportPrefix, Set<String> applicationNames ) throws UnauthorizedActionException, IOException { for( String applicationName : applicationNames ) { Application app = findApplicationByName( applicationName ); if( app == null ) throw new UnauthorizedActionException( "Application " + applicationName + " does not exist." ); if( ! externalExportPrefix.equals( app.getTemplate().getExternalExportsPrefix())) throw new UnauthorizedActionException( "Application " + applicationName + "'s template does not have " + externalExportPrefix + " as external exports prefix." ); } boolean notify = ma.getApplication().replaceApplicationBindings( externalExportPrefix, applicationNames ); if( notify ) { ConfigurationUtils.saveApplicationBindings( ma.getApplication()); for( String applicationName : applicationNames ) { this.logger.fine( "External prefix " + externalExportPrefix + " is now bound to application " + applicationName + " in " + ma.getName() + "." ); } for( Instance inst : InstanceHelpers.findAllScopedInstances( ma.getApplication())) { MsgCmdChangeBinding msg = new MsgCmdChangeBinding( externalExportPrefix, ma.getApplication().getApplicationBindings().get( externalExportPrefix )); this.messagingMngr.sendMessageSafely( ma, inst, msg ); } } } ApplicationMngrImpl(
			INotificationMngr notificationMngr,
			IConfigurationMngr configurationMngr,
			ITargetsMngr targetsMngr,
			IMessagingMngr messagingMngr,
			IRandomMngr randomMngr,
			IAutonomicMngr autonomicMngr ); void setApplicationTemplateMngr( IApplicationTemplateMngr applicationTemplateMngr ); @Override Application findApplicationByName( String applicationName ); @Override ManagedApplication findManagedApplicationByName( String applicationName ); @Override Collection<ManagedApplication> getManagedApplications(); @Override ManagedApplication createApplication( String name, String description, String tplName, String tplQualifier ); @Override ManagedApplication createApplication( String name, String description, ApplicationTemplate tpl ); @Override void updateApplication( ManagedApplication ma, String newDesc ); @Override void deleteApplication( ManagedApplication ma ); @Override void restoreApplications(); @Override boolean isTemplateUsed( ApplicationTemplate tpl ); @Override void bindOrUnbindApplication( ManagedApplication ma, String externalExportPrefix, String applicationName, boolean bind ); @Override void replaceApplicationBindings( ManagedApplication ma, String externalExportPrefix, Set<String> applicationNames ); }
ApplicationMngrImpl implements IApplicationMngr { @Override public void replaceApplicationBindings( ManagedApplication ma, String externalExportPrefix, Set<String> applicationNames ) throws UnauthorizedActionException, IOException { for( String applicationName : applicationNames ) { Application app = findApplicationByName( applicationName ); if( app == null ) throw new UnauthorizedActionException( "Application " + applicationName + " does not exist." ); if( ! externalExportPrefix.equals( app.getTemplate().getExternalExportsPrefix())) throw new UnauthorizedActionException( "Application " + applicationName + "'s template does not have " + externalExportPrefix + " as external exports prefix." ); } boolean notify = ma.getApplication().replaceApplicationBindings( externalExportPrefix, applicationNames ); if( notify ) { ConfigurationUtils.saveApplicationBindings( ma.getApplication()); for( String applicationName : applicationNames ) { this.logger.fine( "External prefix " + externalExportPrefix + " is now bound to application " + applicationName + " in " + ma.getName() + "." ); } for( Instance inst : InstanceHelpers.findAllScopedInstances( ma.getApplication())) { MsgCmdChangeBinding msg = new MsgCmdChangeBinding( externalExportPrefix, ma.getApplication().getApplicationBindings().get( externalExportPrefix )); this.messagingMngr.sendMessageSafely( ma, inst, msg ); } } } ApplicationMngrImpl(
			INotificationMngr notificationMngr,
			IConfigurationMngr configurationMngr,
			ITargetsMngr targetsMngr,
			IMessagingMngr messagingMngr,
			IRandomMngr randomMngr,
			IAutonomicMngr autonomicMngr ); void setApplicationTemplateMngr( IApplicationTemplateMngr applicationTemplateMngr ); @Override Application findApplicationByName( String applicationName ); @Override ManagedApplication findManagedApplicationByName( String applicationName ); @Override Collection<ManagedApplication> getManagedApplications(); @Override ManagedApplication createApplication( String name, String description, String tplName, String tplQualifier ); @Override ManagedApplication createApplication( String name, String description, ApplicationTemplate tpl ); @Override void updateApplication( ManagedApplication ma, String newDesc ); @Override void deleteApplication( ManagedApplication ma ); @Override void restoreApplications(); @Override boolean isTemplateUsed( ApplicationTemplate tpl ); @Override void bindOrUnbindApplication( ManagedApplication ma, String externalExportPrefix, String applicationName, boolean bind ); @Override void replaceApplicationBindings( ManagedApplication ma, String externalExportPrefix, Set<String> applicationNames );  }