1   /*
2    * Copyright (C) 2010 Atlassian
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.atlassian.jira.rest.client;
18  
19  import com.atlassian.jira.rest.client.auth.BasicHttpAuthenticationHandler;
20  import com.atlassian.jira.rest.client.domain.BasicUser;
21  import com.atlassian.jira.rest.client.internal.ServerVersionConstants;
22  import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClient;
23  import com.atlassian.jira.webtests.util.LocalTestEnvironmentData;
24  
25  import javax.ws.rs.core.UriBuilder;
26  import java.net.URI;
27  import java.net.URISyntaxException;
28  
29  public class IntegrationTestUtil {
30  	public static final BasicUser USER_ADMIN;
31      public static final BasicUser USER1;
32      public static final BasicUser USER2;
33  	public static final BasicUser USER_SLASH;
34  
35  	public static final boolean TESTING_JIRA_5_OR_NEWER;
36  	public static final int START_PROGRESS_TRANSITION_ID = 4;
37  	public static final int STOP_PROGRESS_TRANSITION_ID = 301;
38  	public static final String NUMERIC_CUSTOMFIELD_ID = "customfield_10000";
39  	public static final String NUMERIC_CUSTOMFIELD_TYPE = "com.atlassian.jira.plugin.system.customfieldtypes:float";
40  	public static final String NUMERIC_CUSTOMFIELD_TYPE_V5 = "number";
41  	private static final LocalTestEnvironmentData environmentData = new LocalTestEnvironmentData();
42  	private static final String URI_INTERFIX_FOR_USER;
43  
44  
45  	static {
46          try {
47  			JerseyJiraRestClient client = new JerseyJiraRestClient(environmentData.getBaseUrl().toURI(), new BasicHttpAuthenticationHandler("admin", "admin"));
48  			TESTING_JIRA_5_OR_NEWER = client.getMetadataClient().getServerInfo(new NullProgressMonitor()).getBuildNumber() > ServerVersionConstants.BN_JIRA_5;
49  			// remove it when https://jdog.atlassian.com/browse/JRADEV-7691 is fixed
50  			URI_INTERFIX_FOR_USER = TESTING_JIRA_5_OR_NEWER ? "2" : "latest";
51  
52              USER1 = new BasicUser(getUserUri("wseliga"), "wseliga", "Wojciech Seliga");
53              USER2 = new BasicUser(getUserUri("user"), "user", "My Test User");
54  			USER_SLASH = new BasicUser(getUserUri("a/user/with/slash"), "a/user/with/slash", "A User with / in its username");
55              USER_ADMIN = new BasicUser(getUserUri("admin"), "admin", "Administrator");
56          } catch (URISyntaxException e) {
57              throw new RuntimeException(e);
58          }
59  
60      }
61  
62  	private static URI getUserUri(String username) throws URISyntaxException {
63  		return UriBuilder.fromUri(environmentData.getBaseUrl().toURI()).path("/rest/api/" +
64  				URI_INTERFIX_FOR_USER + "/user").queryParam("username", username).build();
65  	}
66  
67      public static URI concat(URI uri, String path) {
68          return UriBuilder.fromUri(uri).path(path).build();
69      }
70  
71  }