2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
2011-02-15 22:33:22 +01:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
2011-02-15 22:33:22 +01:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2011-02-15 22:33:22 +01:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
2011-02-15 22:33:22 +01:00
|
|
|
*
|
2020-03-23 15:35:58 +01:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
2011-02-15 22:33:22 +01:00
|
|
|
*/
|
2020-03-23 15:35:58 +01:00
|
|
|
|
2011-02-16 20:17:05 +01:00
|
|
|
package sonia.scm.it;
|
2011-02-15 22:33:22 +01:00
|
|
|
|
|
|
|
|
//~--- non-JDK imports --------------------------------------------------------
|
|
|
|
|
|
2018-08-03 09:28:54 +02:00
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.google.common.io.Resources;
|
2011-02-15 22:33:22 +01:00
|
|
|
import com.sun.jersey.api.client.Client;
|
|
|
|
|
import com.sun.jersey.api.client.ClientResponse;
|
|
|
|
|
import com.sun.jersey.api.client.WebResource;
|
|
|
|
|
import com.sun.jersey.client.apache.ApacheHttpClient;
|
|
|
|
|
import com.sun.jersey.client.apache.config.ApacheHttpClientConfig;
|
|
|
|
|
import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig;
|
2018-08-03 09:28:54 +02:00
|
|
|
import de.otto.edison.hal.HalRepresentation;
|
2018-06-06 10:36:27 +02:00
|
|
|
import sonia.scm.api.rest.JSONContextResolver;
|
|
|
|
|
import sonia.scm.api.rest.ObjectMapperProvider;
|
|
|
|
|
import sonia.scm.repository.Person;
|
|
|
|
|
import sonia.scm.util.IOUtil;
|
2011-02-15 22:33:22 +01:00
|
|
|
|
2011-08-07 13:13:06 +02:00
|
|
|
import java.io.IOException;
|
2018-08-03 09:28:54 +02:00
|
|
|
import java.net.URI;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.nio.charset.Charset;
|
2012-02-25 16:23:45 +01:00
|
|
|
import java.util.ArrayList;
|
2011-02-15 22:33:22 +01:00
|
|
|
import java.util.Collection;
|
|
|
|
|
|
2018-06-06 10:36:27 +02:00
|
|
|
//~--- JDK imports ------------------------------------------------------------
|
2011-02-15 22:33:22 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author Sebastian Sdorra
|
|
|
|
|
*/
|
2013-01-31 10:26:16 +01:00
|
|
|
public final class IntegrationTestUtil
|
2011-02-15 22:33:22 +01:00
|
|
|
{
|
2018-08-07 16:34:26 +02:00
|
|
|
|
2017-01-14 11:48:42 +01:00
|
|
|
public static final Person AUTHOR = new Person("SCM Administrator", "scmadmin@scm-manager.org");
|
2011-02-15 22:33:22 +01:00
|
|
|
|
2011-08-03 17:04:13 +02:00
|
|
|
/** Field description */
|
|
|
|
|
public static final String ADMIN_PASSWORD = "scmadmin";
|
|
|
|
|
|
|
|
|
|
/** Field description */
|
|
|
|
|
public static final String ADMIN_USERNAME = "scmadmin";
|
2018-08-07 16:34:26 +02:00
|
|
|
|
2016-07-25 18:27:47 +02:00
|
|
|
/** scm-manager base url */
|
|
|
|
|
public static final String BASE_URL = "http://localhost:8081/scm/";
|
2018-08-07 16:34:26 +02:00
|
|
|
|
2016-07-25 18:27:47 +02:00
|
|
|
/** scm-manager base url for the rest api */
|
2018-10-01 17:22:03 +02:00
|
|
|
public static final String REST_BASE_URL = BASE_URL.concat("api/v2/");
|
2011-02-16 17:18:00 +01:00
|
|
|
|
2013-01-31 10:26:16 +01:00
|
|
|
//~--- constructors ---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs ...
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
private IntegrationTestUtil() {}
|
|
|
|
|
|
2011-02-15 22:33:22 +01:00
|
|
|
//~--- methods --------------------------------------------------------------
|
|
|
|
|
|
2011-02-19 17:19:47 +01:00
|
|
|
|
2018-08-03 09:28:54 +02:00
|
|
|
public static ScmClient createAdminClient()
|
2011-02-15 22:33:22 +01:00
|
|
|
{
|
2018-08-03 09:28:54 +02:00
|
|
|
return new ScmClient("scmadmin", "scmadmin");
|
2011-02-21 21:20:20 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-15 22:33:22 +01:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2011-02-19 17:19:47 +01:00
|
|
|
public static Client createClient()
|
2011-02-15 22:33:22 +01:00
|
|
|
{
|
2011-02-16 17:18:00 +01:00
|
|
|
DefaultApacheHttpClientConfig config = new DefaultApacheHttpClientConfig();
|
2018-06-06 10:36:27 +02:00
|
|
|
config.getSingletons().add(new JSONContextResolver(new ObjectMapperProvider().get()));
|
2017-06-28 22:03:21 +02:00
|
|
|
config.getProperties().put(ApacheHttpClientConfig.PROPERTY_HANDLE_COOKIES, true);
|
2011-02-15 22:33:22 +01:00
|
|
|
|
|
|
|
|
return ApacheHttpClient.create(config);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-03 09:28:54 +02:00
|
|
|
public static String serialize(Object o) {
|
|
|
|
|
ObjectMapper mapper = new ObjectMapperProvider().get();
|
|
|
|
|
try {
|
|
|
|
|
return mapper.writeValueAsString(o);
|
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-23 17:24:00 +02:00
|
|
|
public static Collection<String[]> createRepositoryTypeParameters() {
|
|
|
|
|
Collection<String[]> params = new ArrayList<>();
|
2012-02-25 16:23:45 +01:00
|
|
|
|
2018-08-24 11:13:24 +02:00
|
|
|
params.add(new String[]{"git"});
|
|
|
|
|
params.add(new String[]{"svn"});
|
2012-02-25 16:23:45 +01:00
|
|
|
|
|
|
|
|
if (IOUtil.search("hg") != null)
|
|
|
|
|
{
|
2018-08-24 11:13:24 +02:00
|
|
|
params.add(new String[]{"hg"});
|
2012-02-25 16:23:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return params;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-03 09:28:54 +02:00
|
|
|
public static URI getLink(HalRepresentation object, String linkName) {
|
|
|
|
|
return URI.create(object.getLinks().getLinkBy("delete").get().getHref());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static WebResource.Builder createResource(ScmClient client, String url) {
|
|
|
|
|
return createResource(client, createResourceUrl(url));
|
|
|
|
|
}
|
|
|
|
|
public static WebResource.Builder createResource(ScmClient client, URI url) {
|
|
|
|
|
return client.resource(url.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ClientResponse post(ScmClient client, String path, String mediaType, Object o) {
|
|
|
|
|
return createResource(client, path)
|
|
|
|
|
.type(mediaType)
|
|
|
|
|
.post(ClientResponse.class, serialize(o));
|
2011-08-03 17:04:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param url
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2018-08-03 09:28:54 +02:00
|
|
|
public static URI createResourceUrl(String url)
|
2011-08-03 17:04:13 +02:00
|
|
|
{
|
2018-08-03 09:28:54 +02:00
|
|
|
return URI.create(REST_BASE_URL).resolve(url);
|
2011-02-15 22:33:22 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-03 09:28:54 +02:00
|
|
|
public static String readJson(String jsonFileName) {
|
|
|
|
|
URL url = Resources.getResource(jsonFileName);
|
|
|
|
|
try {
|
|
|
|
|
return Resources.toString(url, Charset.forName("UTF-8"));
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException("could not read json file " + jsonFileName, e);
|
|
|
|
|
}
|
2011-02-15 22:33:22 +01:00
|
|
|
}
|
|
|
|
|
}
|