22
33import com .testmonitor .api .Connector ;
44import com .testmonitor .parsers .TestCaseFolderParser ;
5+ import com .testmonitor .parsers .TestCaseParser ;
56import com .testmonitor .resources .Project ;
7+ import com .testmonitor .resources .TestCase ;
68import com .testmonitor .resources .TestCaseFolder ;
79import org .apache .hc .core5 .http .NameValuePair ;
810import org .apache .hc .core5 .http .message .BasicNameValuePair ;
@@ -93,7 +95,7 @@ public TestCaseFolder get(Integer id) throws IOException, URISyntaxException {
9395 /**
9496 * Create a test case folder
9597 *
96- * @param testCaseFolder The test case your want to create
98+ * @param testCaseFolder The name of the test case folder
9799 *
98100 * @return The created test case folder
99101 */
@@ -110,7 +112,7 @@ public TestCaseFolder create(TestCaseFolder testCaseFolder) throws IOException {
110112 /**
111113 * Create a test case folder
112114 *
113- * @param name The test case folder name you want to create
115+ * @param name The name of the test case folder
114116 *
115117 * @return The created test case folder
116118 */
@@ -123,14 +125,14 @@ public TestCaseFolder create(String name) throws IOException {
123125 }
124126
125127 /**
126- * Create a test case subfolder
128+ * Create a test case folder
127129 *
128130 * @param name The name of the test case folder
129131 * @param parent The parent folder
130132 *
131133 * @return The created test case folder
132134 */
133- public TestCaseFolder createSubfolder (String name , TestCaseFolder parent ) throws IOException {
135+ public TestCaseFolder create (String name , TestCaseFolder parent ) throws IOException {
134136 TestCaseFolder testCaseFolder = new TestCaseFolder ();
135137
136138 testCaseFolder
@@ -142,14 +144,14 @@ public TestCaseFolder createSubfolder(String name, TestCaseFolder parent) throws
142144 }
143145
144146 /**
145- * Create a test case subfolder
147+ * Create a test case folder
146148 *
147149 * @param child The name of the test case folder
148150 * @param parent The parent folder
149151 *
150152 * @return The created test case folder
151153 */
152- public TestCaseFolder createSubfolder (TestCaseFolder child , TestCaseFolder parent ) throws IOException {
154+ public TestCaseFolder create (TestCaseFolder child , TestCaseFolder parent ) throws IOException {
153155 return this .create (child .setParent (parent ));
154156 }
155157
@@ -200,6 +202,87 @@ public TestCaseFolder clone(TestCaseFolder source, String name) throws IOExcepti
200202 return this .clone (source , name , true , true );
201203 }
202204
205+ /**
206+ * Find a test case folder using the provided name or create a new one.
207+ *
208+ * @param name The provided name and parent folder
209+ *
210+ * @return A test case folder matching the name or a new test case folder
211+ */
212+ public TestCaseFolder findOrCreate (String name ) throws IOException , URISyntaxException {
213+ ArrayList <TestCaseFolder > testCaseFolders = this .findByName (name );
214+
215+ if (testCaseFolders .size () > 0 ) {
216+ return testCaseFolders .get (0 );
217+ }
218+
219+ return this .create (name );
220+ }
221+
222+ /**
223+ * Find a test case folder using the provided name and parent folder or create a new one.
224+ *
225+ * @param name The name of the test case folder
226+ * @param parent The parent folder
227+ *
228+ * @return A test case folder matching the name or a new test case folder
229+ */
230+ public TestCaseFolder findOrCreate (String name , TestCaseFolder parent ) throws IOException , URISyntaxException {
231+ ArrayList <TestCaseFolder > testCaseFolders = this .findByName (name , parent );
232+
233+ if (testCaseFolders .size () > 0 ) {
234+ return testCaseFolders .get (0 );
235+ }
236+
237+ return this .create (name , parent );
238+ }
239+
240+ /**
241+ * Find a test case folder using the provided name.
242+ *
243+ * @param name The name of the test case folder
244+ *
245+ * @return Test case folders matching the provided name.
246+ */
247+ public ArrayList <TestCaseFolder > findByName (String name ) throws IOException , URISyntaxException {
248+ List <NameValuePair > params = new ArrayList <>();
249+
250+ params .add (new BasicNameValuePair ("project_id" , this .projectId .toString ()));
251+ params .add (new BasicNameValuePair ("filter[name]" , name ));
252+
253+ return TestCaseFolderParser .parse (this .connector .get ("test-case/folders" , params ));
254+ }
255+
256+ /**
257+ * Find a test case folder using the provided name and parent folder id
258+ *
259+ * @param name The name of the test case folder
260+ * @param parentId The id of the parent folder
261+ *
262+ * @return Test case folders matching the provided name.
263+ */
264+ public ArrayList <TestCaseFolder > findByName (String name , Integer parentId ) throws IOException , URISyntaxException {
265+ List <NameValuePair > params = new ArrayList <>();
266+
267+ params .add (new BasicNameValuePair ("project_id" , this .projectId .toString ()));
268+ params .add (new BasicNameValuePair ("parent_id" , parentId .toString ()));
269+ params .add (new BasicNameValuePair ("filter[name]" , name ));
270+
271+ return TestCaseFolderParser .parse (this .connector .get ("test-case/folders" , params ));
272+ }
273+
274+ /**
275+ * Find a test case folder using the provided name and parent folder
276+ *
277+ * @param name The name of the test case folder
278+ * @param parent The parent folder
279+ *
280+ * @return Test case folders matching the provided name.
281+ */
282+ public ArrayList <TestCaseFolder > findByName (String name , TestCaseFolder parent ) throws IOException , URISyntaxException {
283+ return this .findByName (name , parent .getId ());
284+ }
285+
203286 /**
204287 * Update a test case folder.
205288 *
0 commit comments