Use namespace and name instead of id in repository hooks

This commit is contained in:
René Pfeuffer
2018-08-06 11:11:44 +02:00
parent e60bea5f08
commit 83005bebf4
6 changed files with 49 additions and 164 deletions

View File

@@ -32,6 +32,7 @@ package sonia.scm.it;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.sun.jersey.api.client.WebResource;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
@@ -42,6 +43,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import sonia.scm.api.v2.resources.RepositoryDto;
import sonia.scm.debug.DebugHookData;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.Person;
import sonia.scm.repository.client.api.ClientCommand;
@@ -52,6 +54,12 @@ import java.io.File;
import java.io.IOException;
import java.util.Collection;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.core.AllOf.allOf;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static sonia.scm.it.IntegrationTestUtil.createResource;
import static sonia.scm.it.IntegrationTestUtil.readJson;
import static sonia.scm.it.RepositoryITUtil.createRepository;
import static sonia.scm.it.RepositoryITUtil.deleteRepository;
@@ -129,10 +137,10 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase
Thread.sleep(WAIT_TIME);
// check debug servlet for pushed commit
// WebResource wr = createResource(client, "debug/" + repository.getId() + "/post-receive/last");
// DebugHookData data = wr.get(DebugHookData.class);
// assertNotNull(data);
// assertThat(data.getChangesets(), contains(changeset.getId()));
WebResource.Builder wr = createResource(client, "../debug/" + repository.getNamespace() + "/" + repository.getName() + "/post-receive/last");
DebugHookData data = wr.get(DebugHookData.class);
assertNotNull(data);
assertThat(data.getChangesets(), contains(changeset.getId()));
}
/**
@@ -164,15 +172,15 @@ public class RepositoryHookITCase extends AbstractAdminITCaseBase
Thread.sleep(WAIT_TIME);
// check debug servlet that only one commit is present
// WebResource wr = createResource(client, "debug/" + repository.getId() + "/post-receive/last");
// DebugHookData data = wr.get(DebugHookData.class);
// assertNotNull(data);
// assertThat(data.getChangesets(), allOf(
// contains(b.getId()),
// not(
// contains(a.getId())
// )
// ));
WebResource.Builder wr = createResource(client, "../debug/" + repository.getNamespace() + "/" + repository.getName() + "/post-receive/last");
DebugHookData data = wr.get(DebugHookData.class);
assertNotNull(data);
assertThat(data.getChangesets(), allOf(
contains(b.getId()),
not(
contains(a.getId())
)
));
}
private Changeset commit(String message) throws IOException {

View File

@@ -1,119 +0,0 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.it;
//~--- non-JDK imports --------------------------------------------------------
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.junit.Ignore;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryTestData;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static sonia.scm.it.IntegrationTestUtil.createAdminClient;
import static sonia.scm.it.IntegrationTestUtil.createResource;
//~--- JDK imports ------------------------------------------------------------
/**
*
* @author Sebastian Sdorra
*/
@Ignore()
public class RepositoryHttpCacheITCase extends HttpCacheITCaseBase<Repository>
{
/**
* Method description
*
*
* @return
*/
@Override
protected Repository createSampleItem()
{
Repository repository = RepositoryTestData.createHeartOfGold("git");
ScmClient client = createAdminClient();
WebResource.Builder resource = createResource(client, "repositories");
ClientResponse response = resource.post(ClientResponse.class, repository);
assertNotNull(response);
assertEquals(201, response.getStatus());
String location = response.getHeaders().get("Location").get(0);
assertNotNull(location);
response = client.resource(location).get(ClientResponse.class);
assertNotNull(response);
assertEquals(200, response.getStatus());
repository = response.getEntity(Repository.class);
assertNotNull(repository);
assertNotNull(repository.getId());
return repository;
}
/**
* Method description
*
*
* @param item
*/
@Override
protected void destroy(Repository item)
{
ScmClient client = createAdminClient();
WebResource.Builder resource = createResource(client,
"repositories/".concat(item.getId()));
ClientResponse response = resource.delete(ClientResponse.class);
assertNotNull(response);
assertEquals(204, response.getStatus());
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
protected String getCollectionUrlPart()
{
return "repositories";
}
}

View File

@@ -76,6 +76,7 @@ public final class RepositoryITUtil
assertNotNull(other);
assertNotNull(other.getType());
assertNotNull(other.getNamespace());
assertNotNull(other.getCreationDate());
return other;