Context { public Instance resolveInstance( String instancePath ) { Instance instance = null; String componentName = this.instancePathToComponentName.get( instancePath ); if( componentName != null ) { String instanceName = InstanceHelpers.findInstanceName( instancePath ); Component component; if( DefineVariableCommandInstruction.FAKE_COMPONENT_NAME.equals( componentName )) component = new Component( DefineVariableCommandInstruction.FAKE_COMPONENT_NAME ); else component = ComponentHelpers.findComponent( this.app, componentName ); if( ! Utils.isEmptyOrWhitespaces( instanceName ) && component != null ) instance = new Instance( instanceName ).component( component ); else this.logger.warning( "Instance's component of " + instancePath + " could not be resolved." ); } return instance; } Context( AbstractApplication app, File commandFile ); boolean instanceExists( String instancePath ); Instance resolveInstance( String instancePath ); final Map<String,String> instancePathToComponentName; final Map<String,String> variables; final Set<String> disabledVariables; }
@Test public void testResolveInstance() { Assert.assertEquals( "vm", this.context.resolveInstance( "/tomcat-vm" ).getComponent().getName()); Assert.assertEquals( "tomcat", this.context.resolveInstance( "/tomcat-vm/tomcat-server" ).getComponent().getName()); Assert.assertNull( this.context.resolveInstance( "/tomcat-vm/invalid" )); this.context.instancePathToComponentName.put( "not a path", "whatever" ); Assert.assertNull( this.context.resolveInstance( "not a path" )); Assert.assertNull( this.context.resolveInstance( "" )); this.context.instancePathToComponentName.put( "", "vm" ); Assert.assertNull( this.context.resolveInstance( "" )); }