private Collection<Instance> replicateInstancesFrom( Instance rootInstance ) { Collection<Instance> newRootInstances = new ArrayList<> (); // Begin with the duplicates of the deepest instances. List<Instance> orderedInstances = InstanceHelpers.buildHierarchicalList( rootInstance ); Collections.reverse( orderedInstances ); for( Instance instance : orderedInstances ) { String countAsString = instance.data.remove( INST_COUNT ); Integer count = 1; try { count = Integer.parseInt( countAsString ); } catch( NumberFormatException e ) { // ignore, the validator for the parsing model should handle this } if( count <= 1 ) continue; String format = "%0" + String.valueOf( count ).length() + "d"; for( int i=2; i<=count; i++ ) { Instance copy = InstanceHelpers.replicateInstance( instance ); copy.name( copy.getName() + String.format( format, i )); if( instance.getParent() != null ) InstanceHelpers.insertChild( instance.getParent(), copy ); else newRootInstances.add( copy ); } // Update the first one instance.name( instance.getName() + String.format( format, 1 )); } return newRootInstances; }
copy.name( current.getName()); copy.component( current.getComponent()); copy.channels.addAll( current.channels );
@Test public void testChain() { Instance inst = new Instance().name( "ins" ).status( InstanceStatus.DEPLOYING ).component( null ).parent( null ); Assert.assertEquals( 0, inst.channels.size()); Assert.assertEquals( "ins", inst.getName()); Assert.assertEquals( InstanceStatus.DEPLOYING, inst.getStatus()); Assert.assertNull( inst.getComponent()); Assert.assertNull( inst.getParent()); Assert.assertEquals( 1, inst.channel( "woo" ).channels.size()); Assert.assertEquals( 2, inst.channel( "yeah" ).channels.size()); Assert.assertEquals( 2, inst.channel( "woo" ).channels.size()); }
@Test public void testCrap() { Instance inst = new Instance(); Assert.assertNull( inst.toString()); Assert.assertNotNull( inst.name( "azerty" ).toString()); Component comp = new Component(); Assert.assertNull( comp.toString()); Assert.assertNotNull( comp.name( "azerty" ).toString()); Application app = new Application( new ApplicationTemplate()); Assert.assertNull( app.toString()); Assert.assertNotNull( app.name( "azerty" ).toString()); Assert.assertTrue( 0 < PreferenceKeyCategory.values().length ); } }