Skip to content

Commit dd4833a

Browse files
committed
Merge pull request #66 from antelder/CLI-FindAndDelete
Cli find and delete
2 parents 29309cc + ffaaed1 commit dd4833a

13 files changed

Lines changed: 1164 additions & 47 deletions

File tree

cli-client/findbugs.exclude.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<FindBugsFilter>
2+
<!-- See http://findbugs.sourceforge.net/manual/filter.html for details
3+
of the syntax of this file -->
4+
5+
<Match>
6+
<Bug pattern="DM_DEFAULT_ENCODING" />
7+
<Class name="com.ibm.ws.lars.upload.cli.Main" />
8+
</Match>
9+
10+
11+
</FindBugsFilter>
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2015 IBM Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
17+
package com.ibm.ws.lars.upload.cli;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertTrue;
21+
22+
import java.io.IOException;
23+
import java.util.Arrays;
24+
import java.util.regex.Matcher;
25+
import java.util.regex.Pattern;
26+
27+
import org.junit.Before;
28+
import org.junit.Rule;
29+
import org.junit.Test;
30+
31+
import com.ibm.ws.lars.testutils.FatUtils;
32+
import com.ibm.ws.lars.testutils.TestProcess;
33+
import com.ibm.ws.lars.testutils.fixtures.RepositoryFixture;
34+
import com.ibm.ws.repository.connections.RepositoryConnectionList;
35+
import com.ibm.ws.repository.connections.RestRepositoryConnection;
36+
import com.ibm.ws.repository.exceptions.RepositoryBackendException;
37+
38+
/**
39+
* Test the find actions of the command line client
40+
*/
41+
public class FindAndDeleteFatTest {
42+
43+
@Rule
44+
public RepositoryFixture repoServer = FatUtils.FAT_REPO;
45+
46+
private RestRepositoryConnection repoConnection;
47+
48+
@Before
49+
public void setUp() {
50+
repoConnection = (RestRepositoryConnection) repoServer.getAdminConnection();
51+
}
52+
53+
@Test
54+
public void testDelete() throws IOException, RepositoryBackendException {
55+
RepositoryConnectionList connectionList = new RepositoryConnectionList(repoConnection);
56+
57+
String esaPath = "resources/com.ibm.websphere.appserver.adminCenter-1.0.esa";
58+
TestProcess tp = new TestProcess(Arrays.asList(FatUtils.SCRIPT,
59+
"upload",
60+
"--url=" + FatUtils.SERVER_URL,
61+
"--username=" + repoConnection.getUserId(),
62+
"--password=" + repoConnection.getPassword(),
63+
esaPath));
64+
tp.run();
65+
tp.assertReturnCode(0);
66+
assertEquals("Incorrect resource count", 1, connectionList.getAllResources().size());
67+
assertEquals("Incorrect feature count", 1, connectionList.getAllFeatures().size());
68+
tp.assertOutputContains("done");
69+
70+
// Add another asset
71+
String esa2Path = "resources/userFeature.esa";
72+
TestProcess upload2 = new TestProcess(Arrays.asList(FatUtils.SCRIPT,
73+
"upload",
74+
"--url=" + FatUtils.SERVER_URL, esa2Path,
75+
"--username=" + repoConnection.getUserId(),
76+
"--password=" + repoConnection.getPassword()));
77+
upload2.run();
78+
upload2.assertReturnCode(0);
79+
assertEquals("Incorrect resource count", 2, connectionList.getAllResources().size());
80+
assertEquals("Incorrect feature count", 2, connectionList.getAllFeatures().size());
81+
upload2.assertOutputContains("done");
82+
83+
// List assets, should now show 2 assets
84+
TestProcess list2Process = new TestProcess(Arrays.asList(FatUtils.SCRIPT,
85+
"listAll",
86+
"--url=" + FatUtils.SERVER_URL,
87+
"--username=" + repoConnection.getUserId(),
88+
"--password=" + repoConnection.getPassword()));
89+
list2Process.run();
90+
String list2output = list2Process.getOutput();
91+
int lineCount2 = FatUtils.countLines(list2output);
92+
93+
assertEquals("Output had the wrong number of lines\n" + list2output, 4, lineCount2);
94+
findFeatureId(list2output, "Admin Center");
95+
list2Process.assertReturnCode(0);
96+
97+
// Delete asset
98+
TestProcess deleteProcess = new TestProcess(Arrays.asList(FatUtils.SCRIPT,
99+
"findAndDelete",
100+
"--noPrompts",
101+
"admin",
102+
"--url=" + FatUtils.SERVER_URL,
103+
"--username=" + repoConnection.getUserId(),
104+
"--password=" + repoConnection.getPassword()));
105+
deleteProcess.run();
106+
String deleteOutput = deleteProcess.getOutput();
107+
int lineCount = FatUtils.countLines(deleteOutput);
108+
109+
assertEquals("Output had the wrong number of lines\n" + deleteOutput, 1, lineCount);
110+
assertTrue("Asset not deleted\n" + deleteOutput + "\n" + list2output, deleteOutput.contains("Deleted asset "));
111+
deleteProcess.assertReturnCode(0);
112+
113+
// List assets, should now show 1 assets
114+
TestProcess list3Process = new TestProcess(Arrays.asList(FatUtils.SCRIPT,
115+
"listAll",
116+
"--url=" + FatUtils.SERVER_URL,
117+
"--username=" + repoConnection.getUserId(),
118+
"--password=" + repoConnection.getPassword()));
119+
list3Process.run();
120+
String list3output = list3Process.getOutput();
121+
int lineCount3 = FatUtils.countLines(list3output);
122+
123+
assertEquals("Output had the wrong number of lines\n" + list3output, 3, lineCount3);
124+
findFeatureId(list3output, "com.ibm.ws.test.userFeature");
125+
list3Process.assertReturnCode(0);
126+
127+
}
128+
129+
@Test
130+
public void testDeleteWithPrompts() throws IOException, RepositoryBackendException {
131+
RepositoryConnectionList connectionList = new RepositoryConnectionList(repoConnection);
132+
133+
String esaPath = "resources/com.ibm.websphere.appserver.adminCenter-1.0.esa";
134+
TestProcess tp = new TestProcess(Arrays.asList(FatUtils.SCRIPT,
135+
"upload",
136+
"--url=" + FatUtils.SERVER_URL,
137+
"--username=" + repoConnection.getUserId(),
138+
"--password=" + repoConnection.getPassword(),
139+
esaPath));
140+
tp.run();
141+
tp.assertReturnCode(0);
142+
assertEquals("Incorrect resource count", 1, connectionList.getAllResources().size());
143+
assertEquals("Incorrect feature count", 1, connectionList.getAllFeatures().size());
144+
tp.assertOutputContains("done");
145+
146+
// Add another asset
147+
String esa2Path = "resources/userFeature.esa";
148+
TestProcess upload2 = new TestProcess(Arrays.asList(FatUtils.SCRIPT,
149+
"upload",
150+
"--url=" + FatUtils.SERVER_URL, esa2Path,
151+
"--username=" + repoConnection.getUserId(),
152+
"--password=" + repoConnection.getPassword()));
153+
upload2.run();
154+
upload2.assertReturnCode(0);
155+
assertEquals("Incorrect resource count", 2, connectionList.getAllResources().size());
156+
assertEquals("Incorrect feature count", 2, connectionList.getAllFeatures().size());
157+
upload2.assertOutputContains("done");
158+
159+
// List assets, should now show 2 assets
160+
TestProcess list2Process = new TestProcess(Arrays.asList(FatUtils.SCRIPT,
161+
"listAll",
162+
"--url=" + FatUtils.SERVER_URL,
163+
"--username=" + repoConnection.getUserId(),
164+
"--password=" + repoConnection.getPassword()));
165+
list2Process.run();
166+
String list2output = list2Process.getOutput();
167+
int lineCount2 = FatUtils.countLines(list2output);
168+
169+
assertEquals("Output had the wrong number of lines\n" + list2output, 4, lineCount2);
170+
findFeatureId(list2output, "Admin Center");
171+
list2Process.assertReturnCode(0);
172+
173+
// Delete asset but answer "n" to the deletion prompt
174+
TestProcess deleteProcess = new TestProcess(Arrays.asList(FatUtils.SCRIPT,
175+
"findAndDelete",
176+
"admin",
177+
"--url=" + FatUtils.SERVER_URL,
178+
"--username=" + repoConnection.getUserId(),
179+
"--password=" + repoConnection.getPassword()), "n" + System.lineSeparator());
180+
181+
deleteProcess.run();
182+
183+
String deleteOutput = deleteProcess.getOutput();
184+
int lineCount = FatUtils.countLines(deleteOutput);
185+
186+
assertEquals("Output had the wrong number of lines\n" + deleteOutput, 1, lineCount);
187+
assertTrue("No delete prompt\n" + deleteOutput + "\n" + list2output, deleteOutput.contains("Delete asset "));
188+
deleteProcess.assertReturnCode(0);
189+
190+
// List assets, should still show 2 assets
191+
TestProcess list3Process = new TestProcess(Arrays.asList(FatUtils.SCRIPT,
192+
"listAll",
193+
"--url=" + FatUtils.SERVER_URL,
194+
"--username=" + repoConnection.getUserId(),
195+
"--password=" + repoConnection.getPassword()));
196+
list3Process.run();
197+
String list3output = list3Process.getOutput();
198+
int lineCount3 = FatUtils.countLines(list3output);
199+
200+
assertEquals("Output had the wrong number of lines\n" + list3output, 4, lineCount3);
201+
findFeatureId(list3output, "com.ibm.ws.test.userFeature");
202+
findFeatureId(list2output, "Admin Center");
203+
list3Process.assertReturnCode(0);
204+
205+
// Delete asset answering "y" to the deletion prompt
206+
TestProcess deleteProcess2 = new TestProcess(Arrays.asList(FatUtils.SCRIPT,
207+
"findAndDelete",
208+
"admin",
209+
"--url=" + FatUtils.SERVER_URL,
210+
"--username=" + repoConnection.getUserId(),
211+
"--password=" + repoConnection.getPassword()), "y" + System.lineSeparator());
212+
213+
deleteProcess2.run();
214+
215+
String delete2Output = deleteProcess2.getOutput();
216+
int lineCount4 = FatUtils.countLines(delete2Output);
217+
218+
assertEquals("Output had the wrong number of lines\n" + delete2Output, 2, lineCount4);
219+
assertTrue("No delete prompt\n" + delete2Output + "\n" + delete2Output, delete2Output.contains("Delete asset "));
220+
assertTrue("Asset not deleted\n" + delete2Output + "\n" + delete2Output, delete2Output.contains("Deleted asset "));
221+
deleteProcess.assertReturnCode(0);
222+
223+
// List assets, should now show 1 asset
224+
TestProcess list4Process = new TestProcess(Arrays.asList(FatUtils.SCRIPT,
225+
"listAll",
226+
"--url=" + FatUtils.SERVER_URL,
227+
"--username=" + repoConnection.getUserId(),
228+
"--password=" + repoConnection.getPassword()));
229+
list4Process.run();
230+
String list4output = list4Process.getOutput();
231+
int lineCount5 = FatUtils.countLines(list4output);
232+
233+
assertEquals("Output had the wrong number of lines\n" + list4output, 3, lineCount5);
234+
findFeatureId(list3output, "com.ibm.ws.test.userFeature");
235+
list3Process.assertReturnCode(0);
236+
}
237+
238+
/**
239+
* Finds the id of a feature from the output of the list command, or fails the test if it can't
240+
* be found. Output from the list command looks something like:
241+
*
242+
* Listing all assets in the repository:<br>
243+
* Asset ID | Asset Type | Liberty Version | Asset Name<br>
244+
* 54be3a90469ba2513fea88e7 | Feature | 8.5.5.5 | Admin Center (adminCenter-1.0)
245+
*
246+
* where the version may be blank
247+
*
248+
* @param output - output of the list command
249+
* @param name - name of the feature to find
250+
* @return
251+
*/
252+
private static String findFeatureId(String output, String name) {
253+
254+
String regex = "(\\w+)\\s+\\|\\s+Feature\\s+\\|.+\\|\\s+" + name;
255+
Pattern idPattern = Pattern.compile(regex);
256+
Matcher idMatcher = idPattern.matcher(output);
257+
boolean result = idMatcher.find();
258+
assertTrue("Can't find id for feature " + name + " in output:\n" + output, result);
259+
String id = idMatcher.group(1);
260+
return id;
261+
}
262+
263+
}

0 commit comments

Comments
 (0)