ConfiguratorOnCreation implements MachineConfigurator { Map<String,String> prepareConfiguration( TargetHandlerParameters parameters, SSHClient ssh, File tmpDir ) throws IOException { String userData = UserDataHelpers.writeUserDataAsString( parameters.getMessagingProperties(), parameters.getDomain(), parameters.getApplicationName(), parameters.getScopedInstancePath()); File userdataFile = new File(tmpDir, USER_DATA_FILE); Utils.writeStringInto(userData, userdataFile); this.logger.fine( "Uploading user data as a file..." ); String agentConfigDir = Utils.getValue( parameters.getTargetProperties(), SCP_AGENT_CONFIG_DIR, DEFAULT_SCP_AGENT_CONFIG_DIR ); ssh.newSCPFileTransfer().upload( new FileSystemFile(userdataFile), agentConfigDir); Map<String,String> keyToNewValue = new HashMap<> (); File remoteAgentConfig = new File(agentConfigDir, userdataFile.getName()); keyToNewValue.put( AGENT_APPLICATION_NAME, "" ); keyToNewValue.put( AGENT_SCOPED_INSTANCE_PATH, "" ); keyToNewValue.put( AGENT_DOMAIN, "" ); keyToNewValue.put( AGENT_PARAMETERS, remoteAgentConfig.toURI().toURL().toString()); return keyToNewValue; } ConfiguratorOnCreation(
			TargetHandlerParameters parameters,
			String ip,
			String machineId,
			EmbeddedHandler embedded ); @Override void close(); @Override boolean configure(); @Override Instance getScopedInstance();  }
@Test public void testPrepareConfiguration() throws Exception { File tmpDir = this.folder.newFolder(); TargetHandlerParameters parameters = new TargetHandlerParameters() .targetProperties( new HashMap<String,String>( 0 )); SSHClient ssh = Mockito.mock( SSHClient.class ); SCPFileTransfer scp = Mockito.mock( SCPFileTransfer.class ); Mockito.when( ssh.newSCPFileTransfer()).thenReturn( scp ); EmbeddedHandler embedded = new EmbeddedHandler(); embedded.karafData = this.folder.newFolder().getAbsolutePath(); ConfiguratorOnCreation configurator = new ConfiguratorOnCreation( parameters, "ip", "machineId", embedded ); Map<String,String> keyToNewValue = configurator.prepareConfiguration( parameters, ssh, tmpDir ); Mockito.verify( scp ).upload( Mockito.any( LocalSourceFile.class ), Mockito.anyString()); configurator.close(); Assert.assertEquals( 4, keyToNewValue.size()); Assert.assertEquals( "", keyToNewValue.get( AGENT_APPLICATION_NAME )); Assert.assertEquals( "", keyToNewValue.get( AGENT_SCOPED_INSTANCE_PATH )); Assert.assertEquals( "", keyToNewValue.get( AGENT_DOMAIN )); Assert.assertEquals( "file:" + DEFAULT_SCP_AGENT_CONFIG_DIR + "/" + USER_DATA_FILE, keyToNewValue.get( AGENT_PARAMETERS )); }