Application extends AbstractApplication implements Serializable { public boolean replaceApplicationBindings( String externalExportPrefix, Set<String> applicationNames ) { boolean changed = false; Set<String> oldApplicationNames = this.applicationBindings.remove( externalExportPrefix ); if( oldApplicationNames == null ) { changed = ! applicationNames.isEmpty(); } else if( oldApplicationNames.size() != applicationNames.size()) { changed = true; } else { oldApplicationNames.removeAll( applicationNames ); changed = ! oldApplicationNames.isEmpty(); } if( ! applicationNames.isEmpty()) this.applicationBindings.put( externalExportPrefix, applicationNames ); return changed; } Application( ApplicationTemplate template );  Application( String name, ApplicationTemplate template ); ApplicationTemplate getTemplate(); @Override Graphs getGraphs(); Map<String,String> getExternalExports(); @Override boolean equals( Object obj ); @Override int hashCode(); Application name( String name ); Application description( String description ); Application directory( File directory ); void removeAssociationWithTemplate(); void bindWithApplication( String externalExportPrefix, String applicationName ); boolean unbindFromApplication( String externalExportPrefix, String applicationName ); boolean replaceApplicationBindings( String externalExportPrefix, Set<String> applicationNames ); Map<String,Set<String>> getApplicationBindings();  }
@Test public void testReplaceApplicationBindings() { TestApplication app = new TestApplication(); Assert.assertEquals( 0, app.getApplicationBindings().size()); app.bindWithApplication( "p1", "app1" ); Assert.assertEquals( 1, app.getApplicationBindings().size()); Assert.assertEquals( 1, app.getApplicationBindings().get( "p1" ).size()); Assert.assertTrue( app.getApplicationBindings().get( "p1" ).contains( "app1" )); Assert.assertTrue( app.replaceApplicationBindings( "p1", new HashSet<>( Arrays.asList( "app1", "app2", "app3" )))); Assert.assertEquals( 3, app.getApplicationBindings().get( "p1" ).size()); Assert.assertFalse( app.replaceApplicationBindings( "p1", new HashSet<>( Arrays.asList( "app1", "app2", "app3" )))); Assert.assertEquals( 1, app.getApplicationBindings().size()); Assert.assertEquals( 3, app.getApplicationBindings().get( "p1" ).size()); Assert.assertTrue( app.getApplicationBindings().get( "p1" ).contains( "app1" )); Assert.assertTrue( app.getApplicationBindings().get( "p1" ).contains( "app2" )); Assert.assertTrue( app.getApplicationBindings().get( "p1" ).contains( "app3" )); Assert.assertTrue( app.replaceApplicationBindings( "p1", new HashSet<>( Arrays.asList( "app2", "app3" )))); Assert.assertFalse( app.replaceApplicationBindings( "p1", new HashSet<>( Arrays.asList( "app2", "app3" )))); Assert.assertEquals( 1, app.getApplicationBindings().size()); Assert.assertEquals( 2, app.getApplicationBindings().get( "p1" ).size()); Assert.assertFalse( app.getApplicationBindings().get( "p1" ).contains( "app1" )); Assert.assertTrue( app.getApplicationBindings().get( "p1" ).contains( "app2" )); Assert.assertTrue( app.getApplicationBindings().get( "p1" ).contains( "app3" )); Assert.assertTrue( app.replaceApplicationBindings( "p2", new HashSet<>( Arrays.asList( "app1", "app2", "app3" )))); Assert.assertFalse( app.replaceApplicationBindings( "p2", new HashSet<>( Arrays.asList( "app1", "app2", "app3" )))); Assert.assertEquals( 2, app.getApplicationBindings().size()); Assert.assertEquals( 2, app.getApplicationBindings().get( "p1" ).size()); Assert.assertFalse( app.getApplicationBindings().get( "p1" ).contains( "app1" )); Assert.assertTrue( app.getApplicationBindings().get( "p1" ).contains( "app2" )); Assert.assertTrue( app.getApplicationBindings().get( "p1" ).contains( "app3" )); Assert.assertEquals( 3, app.getApplicationBindings().get( "p2" ).size()); Assert.assertTrue( app.getApplicationBindings().get( "p2" ).contains( "app1" )); Assert.assertTrue( app.getApplicationBindings().get( "p2" ).contains( "app2" )); Assert.assertTrue( app.getApplicationBindings().get( "p2" ).contains( "app3" )); Assert.assertTrue( app.replaceApplicationBindings( "p1", new HashSet<String>( 0 ))); Assert.assertFalse( app.replaceApplicationBindings( "p1", new HashSet<String>( 0 ))); Assert.assertEquals( 1, app.getApplicationBindings().size()); Assert.assertNull( app.getApplicationBindings().get( "p1" )); Assert.assertEquals( 3, app.getApplicationBindings().get( "p2" ).size()); Assert.assertTrue( app.getApplicationBindings().get( "p2" ).contains( "app1" )); Assert.assertTrue( app.getApplicationBindings().get( "p2" ).contains( "app2" )); Assert.assertTrue( app.getApplicationBindings().get( "p2" ).contains( "app3" )); Assert.assertTrue( app.replaceApplicationBindings( "p2", new HashSet<>( Arrays.asList( "app4", "app5", "app6" )))); Assert.assertFalse( app.replaceApplicationBindings( "p2", new HashSet<>( Arrays.asList( "app4", "app5", "app6" )))); Assert.assertEquals( 1, app.getApplicationBindings().size()); Assert.assertNull( app.getApplicationBindings().get( "p1" )); Assert.assertEquals( 3, app.getApplicationBindings().get( "p2" ).size()); Assert.assertTrue( app.getApplicationBindings().get( "p2" ).contains( "app4" )); Assert.assertTrue( app.getApplicationBindings().get( "p2" ).contains( "app5" )); Assert.assertTrue( app.getApplicationBindings().get( "p2" ).contains( "app6" )); }