11package io .hyperfoil .tools .qdup .cmd .impl ;
22
3+ import io .hyperfoil .tools .qdup .Host ;
34import io .hyperfoil .tools .qdup .Run ;
4- import io .hyperfoil .tools .qdup .cmd .Cmd ;
5- import io .hyperfoil .tools .qdup .cmd .Dispatcher ;
6- import io .hyperfoil .tools .qdup .cmd .Script ;
5+ import io .hyperfoil .tools .qdup .SecretFilter ;
6+ import io .hyperfoil .tools .qdup .cmd .*;
77import io .hyperfoil .tools .qdup .config .RunConfig ;
88import io .hyperfoil .tools .qdup .config .RunConfigBuilder ;
99import io .hyperfoil .tools .qdup .config .yaml .Parser ;
10+ import io .hyperfoil .tools .qdup .shell .AbstractShell ;
11+ import io .hyperfoil .tools .yaup .time .SystemTimer ;
1012import org .junit .Test ;
1113import io .hyperfoil .tools .qdup .SshTestBase ;
1214
1315import java .io .File ;
1416import java .io .IOException ;
1517import java .nio .file .Files ;
18+ import java .nio .file .Paths ;
19+ import java .util .Arrays ;
1620import java .util .HashMap ;
21+ import java .util .concurrent .ScheduledThreadPoolExecutor ;
1722import java .util .stream .Collectors ;
1823
19- import static org .junit .Assert .assertFalse ;
20- import static org .junit .Assert .assertTrue ;
24+ import static org .junit .Assert .*;
2125
2226public class UploadTest extends SshTestBase {
2327
@@ -49,7 +53,6 @@ public void uploadFile(){
4953
5054 assertFalse ("unexpected errors:\n " +config .getErrorStrings ().stream ().collect (Collectors .joining ("\n " )),config .hasErrors ());
5155
52-
5356 Dispatcher dispatcher = new Dispatcher ();
5457 Run run = new Run (tmpDir .toString (),config ,dispatcher );
5558 run .run ();
@@ -62,4 +65,87 @@ public void uploadFile(){
6265 e .printStackTrace ();
6366 }
6467 }
68+
69+ @ Test
70+ public void return_remote_path_new_name () throws IOException {
71+ String wrote = "bizbuz" ;
72+ File source = Files .createTempFile ("qdup" ,"upload.txt" ).toFile ();
73+ Files .write (source .toPath (),wrote .getBytes ());
74+ File runFolder = Files .createTempDirectory ("qdup" ).toFile ();
75+
76+ Upload upload = new Upload (source .getPath (),"/tmp/found.txt" );
77+
78+ AbstractShell shell = AbstractShell .getShell (
79+ Host .parse (Host .LOCAL ),
80+ new ScheduledThreadPoolExecutor (2 ),
81+ new SecretFilter (),
82+ false
83+ );
84+ Run run = new Run (runFolder .getPath (),new RunConfigBuilder ().buildConfig (),new Dispatcher ());
85+ ScriptContext scriptContext = new ScriptContext (shell ,run .getConfig ().getState (),run ,new SystemTimer ("download" ),upload ,true );
86+ SpyContext spyContext = new SpyContext (scriptContext ,run .getConfig ().getState (), run .getCoordinator ());
87+ upload .run ("" ,spyContext );
88+
89+ assertNotNull ("upload should call next" ,spyContext .getNext ());
90+ String response = spyContext .getNext ();
91+ assertEquals ("response should match the destination" ,"/tmp/found.txt" ,response );
92+ String readContent = Files .readString (Paths .get (response ));
93+ assertEquals (wrote ,readContent );
94+ }
95+
96+ @ Test
97+ public void return_remote_path_target_folder () throws IOException {
98+ String wrote = "bizbuz" ;
99+ File source = Files .createTempFile ("qdup." ,".upload.txt" ).toFile ();
100+ Files .write (source .toPath (),wrote .getBytes ());
101+ File runFolder = Files .createTempDirectory ("qdup_" ).toFile ();
102+
103+ File tempFolder = Files .createTempDirectory ("qdup_" ).toFile ();
104+ //tempFolder.mkdirs();
105+ Upload upload = new Upload (source .getPath (),tempFolder .getAbsolutePath ()+File .separator );
106+
107+ AbstractShell shell = AbstractShell .getShell (
108+ Host .parse (Host .LOCAL ),
109+ new ScheduledThreadPoolExecutor (2 ),
110+ new SecretFilter (),
111+ false
112+ );
113+ Run run = new Run (runFolder .getPath (),new RunConfigBuilder ().buildConfig (),new Dispatcher ());
114+ ScriptContext scriptContext = new ScriptContext (shell ,run .getConfig ().getState (),run ,new SystemTimer ("download" ),upload ,true );
115+ SpyContext spyContext = new SpyContext (scriptContext ,run .getConfig ().getState (), run .getCoordinator ());
116+ upload .run ("" ,spyContext );
117+
118+ assertNotNull ("upload should call next" ,spyContext .getNext ());
119+ String response = spyContext .getNext ();
120+ assertTrue ("response should end with source name" ,response .endsWith (source .getName ()));
121+ String readContent = Files .readString (Paths .get (response ));
122+ assertEquals (wrote ,readContent );
123+ }
124+
125+ @ Test
126+ public void return_remote_path_target_file () throws IOException {
127+ String wrote = "bizbuz" ;
128+ File source = Files .createTempFile ("qdup." ,".upload.txt" ).toFile ();
129+ Files .write (source .toPath (),wrote .getBytes ());
130+ File runFolder = Files .createTempDirectory ("qdup_" ).toFile ();
131+
132+ Upload upload = new Upload (source .getPath (),"/tmp/renamed.txt" );
133+ AbstractShell shell = AbstractShell .getShell (
134+ Host .parse (Host .LOCAL ),
135+ new ScheduledThreadPoolExecutor (2 ),
136+ new SecretFilter (),
137+ false
138+ );
139+ Run run = new Run (runFolder .getPath (),new RunConfigBuilder ().buildConfig (),new Dispatcher ());
140+ ScriptContext scriptContext = new ScriptContext (shell ,run .getConfig ().getState (),run ,new SystemTimer ("download" ),upload ,true );
141+ SpyContext spyContext = new SpyContext (scriptContext ,run .getConfig ().getState (), run .getCoordinator ());
142+ upload .run ("" ,spyContext );
143+
144+ assertNotNull ("upload should call next" ,spyContext .getNext ());
145+ String response = spyContext .getNext ();
146+ assertEquals ("response should be the specified path" ,"/tmp/renamed.txt" ,response );
147+ String readContent = Files .readString (Paths .get (response ));
148+ assertEquals (wrote ,readContent );
149+ }
150+
65151}
0 commit comments