@@ -69,40 +69,49 @@ public List<ZephyrTestCaseDTO> getTestCase(final int startAt, final ProjectConfF
6969 queryBuilder .append (QUERY_PARAM ).append (PROJECT_KEY );
7070 queryBuilder .append (projectConfig .getProjectKey ());
7171 queryBuilder .append (INVERTED_COMMA );
72- if (ObjectUtils .isNotEmpty (projectConfig .getProcessorToolConnection ().getProjectComponent ())) {
73- queryBuilder .append (AND );
74- queryBuilder .append (COMPONENT ).append (projectConfig .getProcessorToolConnection ().getProjectComponent ());
75- queryBuilder .append (INVERTED_COMMA );
76- }
72+ buildQuery (projectConfig , queryBuilder );
7773
7874 log .info ("ZEPHYR query executed {} ...." , queryBuilder );
79- if (StringUtils .isNotBlank (queryBuilder )) {
80- ResponseEntity <ZephyrTestCaseDTO []> response = null ;
81- try {
82- if (!toolInfo .isBearerToken ()) {
83- response = makeRestCall (queryBuilder .toString (), ZephyrTestCaseDTO [].class , HttpMethod .GET ,
84- zephyrUtil .getCredentialsAsBase64String (toolInfo .getUsername (), toolInfo .getPassword ()));
85- } else {
86- response = restTemplate .exchange (queryBuilder .toString (), HttpMethod .GET ,
87- zephyrUtil .buildBearerHeader (toolInfo .getPatOAuthToken ()), ZephyrTestCaseDTO [].class );
88- }
89- if (response .getStatusCode () == HttpStatus .OK && Objects .nonNull (response .getBody ())) {
90- testCaseList = Arrays .asList (response .getBody ());
91- } else {
92- String statusCode = response .getStatusCode ().toString ();
93- log .error ("Error while fetching projects from {}. with status {}" , queryBuilder , statusCode );
94- throw new RestClientException ("Got different status code: " + statusCode + " : " + response .getBody ());
95- }
96- } catch (Exception exception ) {
97- isClientException (toolInfo , exception );
98- log .error ("Error while fetching projects from {}" , exception .getMessage ());
99- throw new RestClientException ("Error while fetching projects from {}" , exception );
75+ testCaseList = getTestCaseList (testCaseList , toolInfo , queryBuilder );
76+ }
77+ return testCaseList ;
78+ }
79+
80+ private List <ZephyrTestCaseDTO > getTestCaseList (List <ZephyrTestCaseDTO > testCaseList , ProcessorToolConnection toolInfo , StringBuilder queryBuilder ) {
81+ if (StringUtils .isNotBlank (queryBuilder )) {
82+ ResponseEntity <ZephyrTestCaseDTO []> response = null ;
83+ try {
84+ if (!toolInfo .isBearerToken ()) {
85+ response = makeRestCall (queryBuilder .toString (), ZephyrTestCaseDTO [].class , HttpMethod .GET ,
86+ zephyrUtil .getCredentialsAsBase64String (toolInfo .getUsername (), toolInfo .getPassword ()));
87+ } else {
88+ response = restTemplate .exchange (queryBuilder .toString (), HttpMethod .GET ,
89+ zephyrUtil .buildBearerHeader (toolInfo .getPatOAuthToken ()), ZephyrTestCaseDTO [].class );
10090 }
91+ if (response .getStatusCode () == HttpStatus .OK && Objects .nonNull (response .getBody ())) {
92+ testCaseList = Arrays .asList (response .getBody ());
93+ } else {
94+ String statusCode = response .getStatusCode ().toString ();
95+ log .error ("Error while fetching projects from {}. with status {}" , queryBuilder , statusCode );
96+ throw new RestClientException ("Got different status code: " + statusCode + " : " + response .getBody ());
97+ }
98+ } catch (Exception exception ) {
99+ isClientException (toolInfo , exception );
100+ log .error ("Error while fetching projects from {}" , exception .getMessage ());
101+ throw new RestClientException ("Error while fetching projects from {}" , exception );
101102 }
102103 }
103104 return testCaseList ;
104105 }
105106
107+ private static void buildQuery (ProjectConfFieldMapping projectConfig , StringBuilder queryBuilder ) {
108+ if (ObjectUtils .isNotEmpty (projectConfig .getProcessorToolConnection ().getProjectComponent ())) {
109+ queryBuilder .append (AND );
110+ queryBuilder .append (COMPONENT ).append (projectConfig .getProcessorToolConnection ().getProjectComponent ());
111+ queryBuilder .append (INVERTED_COMMA );
112+ }
113+ }
114+
106115 /**
107116 * REST client to make a REST call to the Zephyr cloud
108117 *
0 commit comments