@Test public void testUpdateContext() { String line = "replicate /tomcat-vm as vm-for-tomcat"; ReplicateCommandInstruction instr = new ReplicateCommandInstruction( this.context, line, 1 ); Assert.assertEquals( 0, instr.validate().size()); Assert.assertTrue( this.context.instancePathToComponentName.containsKey( "/tomcat-vm" )); Assert.assertTrue( this.context.instancePathToComponentName.containsKey( "/tomcat-vm/tomcat-server" )); Assert.assertTrue( this.context.instancePathToComponentName.containsKey( "/tomcat-vm/tomcat-server/hello-world" )); int instancesCount = this.context.instancePathToComponentName.size(); instr.updateContext(); Assert.assertEquals( instancesCount + 3, this.context.instancePathToComponentName.size()); Assert.assertTrue( this.context.instancePathToComponentName.containsKey( "/tomcat-vm" )); Assert.assertTrue( this.context.instancePathToComponentName.containsKey( "/tomcat-vm/tomcat-server" )); Assert.assertTrue( this.context.instancePathToComponentName.containsKey( "/tomcat-vm/tomcat-server/hello-world" )); Assert.assertTrue( this.context.instancePathToComponentName.containsKey( "/vm-for-tomcat" )); Assert.assertTrue( this.context.instancePathToComponentName.containsKey( "/vm-for-tomcat/tomcat-server" )); Assert.assertTrue( this.context.instancePathToComponentName.containsKey( "/vm-for-tomcat/tomcat-server/hello-world" )); }
@Override public void updateContext() { String copyInstancePath = "/" + this.replicatedInstancePath.replaceFirst( "/[^/]+$", this.newInstanceName ); Map<String,String> pathToAdd = new HashMap<> (); for( Map.Entry<String,String> entry : this.context.instancePathToComponentName.entrySet()) { if( ! entry.getKey().startsWith( this.replicatedInstancePath + "/" ) && ! entry.getKey().equals( this.replicatedInstancePath )) continue; String updatedPath = entry.getKey().replace( this.replicatedInstancePath, copyInstancePath ); pathToAdd.put( updatedPath, entry.getValue()); } this.context.instancePathToComponentName.putAll( pathToAdd ); }
ReplicateCommandInstruction extends AbstractCommandInstruction { @Override public void updateContext() { String copyInstancePath = "/" + this.replicatedInstancePath.replaceFirst( "/[^/]+$", this.newInstanceName ); Map<String,String> pathToAdd = new HashMap<> (); for( Map.Entry<String,String> entry : this.context.instancePathToComponentName.entrySet()) { if( ! entry.getKey().startsWith( this.replicatedInstancePath + "/" ) && ! entry.getKey().equals( this.replicatedInstancePath )) continue; String updatedPath = entry.getKey().replace( this.replicatedInstancePath, copyInstancePath ); pathToAdd.put( updatedPath, entry.getValue()); } this.context.instancePathToComponentName.putAll( pathToAdd ); } }
ReplicateCommandInstruction extends AbstractCommandInstruction { @Override public void updateContext() { String copyInstancePath = "/" + this.replicatedInstancePath.replaceFirst( "/[^/]+$", this.newInstanceName ); Map<String,String> pathToAdd = new HashMap<> (); for( Map.Entry<String,String> entry : this.context.instancePathToComponentName.entrySet()) { if( ! entry.getKey().startsWith( this.replicatedInstancePath + "/" ) && ! entry.getKey().equals( this.replicatedInstancePath )) continue; String updatedPath = entry.getKey().replace( this.replicatedInstancePath, copyInstancePath ); pathToAdd.put( updatedPath, entry.getValue()); } this.context.instancePathToComponentName.putAll( pathToAdd ); } ReplicateCommandInstruction( Context context, String instruction, int line ); }
ReplicateCommandInstruction extends AbstractCommandInstruction { @Override public void updateContext() { String copyInstancePath = "/" + this.replicatedInstancePath.replaceFirst( "/[^/]+$", this.newInstanceName ); Map<String,String> pathToAdd = new HashMap<> (); for( Map.Entry<String,String> entry : this.context.instancePathToComponentName.entrySet()) { if( ! entry.getKey().startsWith( this.replicatedInstancePath + "/" ) && ! entry.getKey().equals( this.replicatedInstancePath )) continue; String updatedPath = entry.getKey().replace( this.replicatedInstancePath, copyInstancePath ); pathToAdd.put( updatedPath, entry.getValue()); } this.context.instancePathToComponentName.putAll( pathToAdd ); } ReplicateCommandInstruction( Context context, String instruction, int line ); @Override List<ParsingError> doValidate(); @Override void updateContext(); String getNewInstanceName(); String getReplicatedInstancePath(); }
ReplicateCommandInstruction extends AbstractCommandInstruction { @Override public void updateContext() { String copyInstancePath = "/" + this.replicatedInstancePath.replaceFirst( "/[^/]+$", this.newInstanceName ); Map<String,String> pathToAdd = new HashMap<> (); for( Map.Entry<String,String> entry : this.context.instancePathToComponentName.entrySet()) { if( ! entry.getKey().startsWith( this.replicatedInstancePath + "/" ) && ! entry.getKey().equals( this.replicatedInstancePath )) continue; String updatedPath = entry.getKey().replace( this.replicatedInstancePath, copyInstancePath ); pathToAdd.put( updatedPath, entry.getValue()); } this.context.instancePathToComponentName.putAll( pathToAdd ); } ReplicateCommandInstruction( Context context, String instruction, int line ); @Override List<ParsingError> doValidate(); @Override void updateContext(); String getNewInstanceName(); String getReplicatedInstancePath();  }