mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
Adds test for HgConfigPackageResource, its DTO and mappers.
This commit is contained in:
@@ -6,17 +6,18 @@ import javax.inject.Inject;
|
||||
|
||||
public class HgConfigPackageCollectionToDtoMapper extends CollectionToDtoMapper<HgPackage, HgConfigPackageDto> {
|
||||
|
||||
static final String COLLECTION_NAME = "packages";
|
||||
private UriInfoStore uriInfoStore;
|
||||
|
||||
@Inject
|
||||
public HgConfigPackageCollectionToDtoMapper(HgConfigPackageToDtoMapper mapper, UriInfoStore uriInfoStore) {
|
||||
super("packages", mapper);
|
||||
super(COLLECTION_NAME, mapper);
|
||||
this.uriInfoStore = uriInfoStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String createSelfLink() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), HgConfigResource.class);
|
||||
return linkBuilder.method("get").parameters().href();
|
||||
return linkBuilder.method("getPackagesResource").parameters().href();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import de.otto.edison.hal.Links;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@@ -13,7 +12,7 @@ import sonia.scm.repository.HgConfig;
|
||||
public class HgConfigPackageDto extends HalRepresentation {
|
||||
|
||||
private String arch;
|
||||
private HgConfig hgConfigTemplate;
|
||||
private HgConfigDto hgConfigTemplate;
|
||||
private String hgVersion;
|
||||
private String id;
|
||||
private String platform;
|
||||
|
||||
@@ -61,7 +61,7 @@ public class HgConfigPackageResource {
|
||||
/**
|
||||
* Installs a mercurial package
|
||||
*
|
||||
* @param id Identifier of the package to install
|
||||
* @param pkgId Identifier of the package to install
|
||||
*/
|
||||
@PUT
|
||||
@Path("{pkgId}")
|
||||
@@ -73,22 +73,19 @@ public class HgConfigPackageResource {
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
public Response installPackage(@PathParam("pkgId") String id) {
|
||||
public Response installPackage(@PathParam("pkgId") String pkgId) {
|
||||
Response response;
|
||||
|
||||
ConfigurationPermissions.write(HgConfig.PERMISSION).check();
|
||||
|
||||
HgPackage pkg = pkgReader.getPackage(id);
|
||||
HgPackage pkg = pkgReader.getPackage(pkgId);
|
||||
|
||||
if (pkg != null) {
|
||||
if (HgInstallerFactory.createInstaller().installPackage(client, handler,
|
||||
SCMContext.getContext().getBaseDirectory(), pkg)) {
|
||||
response = Response.noContent().build();
|
||||
} else {
|
||||
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
// First path parm cannot be null (leaving it results in 405)
|
||||
if (HgInstallerFactory.createInstaller()
|
||||
.installPackage(client, handler, SCMContext.getContext().getBaseDirectory(), pkg)) {
|
||||
response = Response.noContent().build();
|
||||
} else {
|
||||
response = Response.status(Response.Status.NOT_FOUND).build();
|
||||
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
@@ -1,28 +1,20 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.Mapping;
|
||||
import sonia.scm.installer.HgPackage;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static de.otto.edison.hal.Links.linkingTo;
|
||||
|
||||
@Mapper
|
||||
public abstract class HgConfigPackageToDtoMapper extends BaseMapper<HgPackage, HgConfigPackageDto> {
|
||||
@Inject
|
||||
private UriInfoStore uriInfoStore;
|
||||
|
||||
@AfterMapping
|
||||
void appendLinks(@MappingTarget HgConfigPackageDto target) {
|
||||
Links.Builder linksBuilder = linkingTo().self(self());
|
||||
target.add(linksBuilder.build());
|
||||
}
|
||||
@Override
|
||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||
@Mapping(target = "hgConfigTemplate.attributes", ignore = true) // Also not for nested DTOs
|
||||
public abstract HgConfigPackageDto map(HgPackage modelObject);
|
||||
|
||||
private String self() {
|
||||
LinkBuilder linkBuilder = new LinkBuilder(uriInfoStore.get(), HgConfigPackageResource.class);
|
||||
return linkBuilder.method("get").parameters().href();
|
||||
}
|
||||
// Don't add links because ConfigPackages don't have their own ressource
|
||||
}
|
||||
|
||||
@@ -162,6 +162,7 @@ public class HgPackageInstaller implements Runnable
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error("could not downlaod file ".concat(pkg.getUrl()), ex);
|
||||
file = null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import sonia.scm.installer.HgPackage;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static sonia.scm.api.v2.resources.HgConfigPackageCollectionToDtoMapper.COLLECTION_NAME;
|
||||
import static sonia.scm.api.v2.resources.HgConfigTests.assertEqualsPackage;
|
||||
import static sonia.scm.api.v2.resources.HgConfigTests.createPackage;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HgConfigPackageCollectionToDtoMapperTest {
|
||||
|
||||
private URI baseUri = URI.create("http://example.com/base/");
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
|
||||
@InjectMocks
|
||||
private HgConfigPackageToDtoMapperImpl hgConfigPackageToDtoMapper;
|
||||
|
||||
private HgConfigPackageCollectionToDtoMapper mapper;
|
||||
|
||||
private URI expectedBaseUri;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
expectedBaseUri = baseUri.resolve(HgConfigResource.HG_CONFIG_PATH_V2 + "/packages");
|
||||
mapper = new HgConfigPackageCollectionToDtoMapper(hgConfigPackageToDtoMapper, uriInfoStore);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapFields() {
|
||||
Collection<HgPackage> hgPackages = createPackages();
|
||||
|
||||
HalRepresentation dto = mapper.map(hgPackages);
|
||||
|
||||
List<HalRepresentation> itemsBy = dto.getEmbedded().getItemsBy(COLLECTION_NAME);
|
||||
assertThat(itemsBy).hasSize(2);
|
||||
|
||||
HgConfigPackageDto hgPackageDto1 = assertAndGetAsDto(itemsBy.get(0));
|
||||
assertEqualsPackage(hgPackageDto1);
|
||||
|
||||
HgConfigPackageDto hgPackageDto2 = assertAndGetAsDto(itemsBy.get(1));
|
||||
assertTrue(hgPackageDto2.getLinks().isEmpty());
|
||||
// Just verify a random field
|
||||
assertThat(hgPackageDto2.getId()).isNull();
|
||||
|
||||
assertEquals(expectedBaseUri.toString(), dto.getLinks().getLinkBy("self").get().getHref());
|
||||
}
|
||||
|
||||
private HgConfigPackageDto assertAndGetAsDto(HalRepresentation halRepresentation) {
|
||||
assertThat(halRepresentation).isInstanceOf(HgConfigPackageDto.class);
|
||||
return (HgConfigPackageDto) halRepresentation;
|
||||
}
|
||||
|
||||
private Collection<HgPackage> createPackages() {
|
||||
return Arrays.asList(createPackage(), new HgPackage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.github.sdorra.shiro.ShiroRule;
|
||||
import com.github.sdorra.shiro.SubjectAware;
|
||||
import org.jboss.resteasy.core.Dispatcher;
|
||||
import org.jboss.resteasy.mock.MockDispatcherFactory;
|
||||
import org.jboss.resteasy.mock.MockHttpRequest;
|
||||
import org.jboss.resteasy.mock.MockHttpResponse;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import sonia.scm.installer.HgPackage;
|
||||
import sonia.scm.installer.HgPackageReader;
|
||||
import sonia.scm.net.ahc.AdvancedHttpClient;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
|
||||
import javax.inject.Provider;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static sonia.scm.api.v2.resources.HgConfigTests.createPackage;
|
||||
|
||||
@SubjectAware(
|
||||
configuration = "classpath:sonia/scm/configuration/shiro.ini",
|
||||
password = "secret"
|
||||
)
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HgConfigPackageResourceTest {
|
||||
|
||||
public static final String URI = "/" + HgConfigResource.HG_CONFIG_PATH_V2 + "/packages";
|
||||
@Rule
|
||||
public ShiroRule shiro = new ShiroRule();
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder= new TemporaryFolder();
|
||||
|
||||
private Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
|
||||
|
||||
private final URI baseUri = java.net.URI.create("/");
|
||||
|
||||
@InjectMocks
|
||||
private HgConfigPackageToDtoMapperImpl hgConfigPackageToDtoMapper;
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
|
||||
@Mock
|
||||
private HgRepositoryHandler repositoryHandler;
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private HgPackageReader hgPackageReader;
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private AdvancedHttpClient advancedHttpClient;
|
||||
|
||||
@Mock
|
||||
private Provider<HgConfigPackageResource> hgConfigPackageResourceProvider;
|
||||
|
||||
@Mock
|
||||
private HgPackage hgPackage;
|
||||
|
||||
@Before
|
||||
public void prepareEnvironment() {
|
||||
setupResources();
|
||||
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
|
||||
when(hgPackageReader.getPackages().getPackages()).thenReturn(createPackages());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readOnly")
|
||||
public void shouldGetPackages() throws Exception {
|
||||
MockHttpResponse response = get();
|
||||
|
||||
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
|
||||
|
||||
String responseString = response.getContentAsString();
|
||||
ObjectNode responseJson = new ObjectMapper().readValue(responseString, ObjectNode.class);
|
||||
|
||||
|
||||
JsonNode embedded = responseJson.get("_embedded");
|
||||
assertThat(embedded).isNotNull();
|
||||
|
||||
JsonNode packages = embedded.get("packages");
|
||||
assertThat(packages).isNotNull();
|
||||
assertThat(packages).hasSize(2);
|
||||
|
||||
JsonNode package1 = packages.get(0);
|
||||
assertThat(package1.get("_links")).isNull();
|
||||
|
||||
JsonNode hgConfigTemplate = package1.get("hgConfigTemplate");
|
||||
assertThat(hgConfigTemplate).isNotNull();
|
||||
assertThat(hgConfigTemplate.get("_links")).isNull();
|
||||
|
||||
assertThat(responseString).contains("\"_links\":{\"self\":{\"href\":\"/v2/config/hg/packages");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "writeOnly")
|
||||
public void shouldGetPackagesOnlyWhenAuthorized() throws Exception {
|
||||
thrown.expectMessage("Subject does not have permission [configuration:read:hg]");
|
||||
|
||||
get();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "writeOnly")
|
||||
public void shouldInstallPackage() throws Exception {
|
||||
String packgeId = "ourPackage";
|
||||
String url = "http://url";
|
||||
|
||||
setupPackageInstallation(packgeId, url);
|
||||
when(advancedHttpClient.get(url).request().contentAsStream())
|
||||
.thenReturn(new ByteArrayInputStream("mockedFile".getBytes()));
|
||||
|
||||
MockHttpResponse response = put(packgeId);
|
||||
assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "writeOnly")
|
||||
public void shouldHandleFailingInstallation() throws Exception {
|
||||
String packgeId = "ourPackage";
|
||||
String url = "http://url";
|
||||
|
||||
setupPackageInstallation(packgeId, url);
|
||||
when(advancedHttpClient.get(url).request().contentAsStream())
|
||||
.thenThrow(new IOException("mocked Exception"));
|
||||
|
||||
MockHttpResponse response = put(packgeId);
|
||||
assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "writeOnly")
|
||||
public void shouldHandleMissingPackageId() throws Exception {
|
||||
|
||||
MockHttpResponse response = put(null);
|
||||
assertEquals(HttpServletResponse.SC_METHOD_NOT_ALLOWED, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readOnly")
|
||||
public void shouldInstallPackageOnlyWhenAuthorized() throws Exception {
|
||||
thrown.expectMessage("Subject does not have permission [configuration:write:hg]");
|
||||
|
||||
put("don-t-care");
|
||||
}
|
||||
|
||||
private List<HgPackage> createPackages() {
|
||||
return Arrays.asList(createPackage(), new HgPackage());
|
||||
}
|
||||
|
||||
private MockHttpResponse get() throws URISyntaxException {
|
||||
MockHttpRequest request = MockHttpRequest.get(URI);
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response);
|
||||
return response;
|
||||
}
|
||||
|
||||
private MockHttpResponse put(String pckgId) throws URISyntaxException {
|
||||
String packgeIdParam = "";
|
||||
if (pckgId != null) {
|
||||
packgeIdParam = "/" + pckgId;
|
||||
}
|
||||
MockHttpRequest request = MockHttpRequest.put(URI + packgeIdParam);
|
||||
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response);
|
||||
return response;
|
||||
}
|
||||
|
||||
private void setupResources() {
|
||||
HgConfigPackageCollectionToDtoMapper mapper =
|
||||
new HgConfigPackageCollectionToDtoMapper(hgConfigPackageToDtoMapper, uriInfoStore);
|
||||
|
||||
HgConfigPackageResource hgConfigPackageResource =
|
||||
new HgConfigPackageResource(hgPackageReader, advancedHttpClient, repositoryHandler, mapper);
|
||||
|
||||
when(hgConfigPackageResourceProvider.get()).thenReturn(hgConfigPackageResource);
|
||||
dispatcher.getRegistry().addSingletonResource(
|
||||
new HgConfigResource(null, null, null,
|
||||
hgConfigPackageResourceProvider, null, null));
|
||||
}
|
||||
|
||||
private void setupPackageInstallation(String packgeId, String url) throws IOException {
|
||||
when(hgPackage.getId()).thenReturn(packgeId);
|
||||
when(hgPackageReader.getPackage(packgeId)).thenReturn(hgPackage);
|
||||
when(repositoryHandler.getConfig()).thenReturn(new HgConfig());
|
||||
when(hgPackage.getHgConfigTemplate()).thenReturn(new HgConfig());
|
||||
when(hgPackage.getUrl()).thenReturn(url);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import sonia.scm.installer.HgPackage;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static sonia.scm.api.v2.resources.HgConfigTests.assertEqualsPackage;
|
||||
import static sonia.scm.api.v2.resources.HgConfigTests.createPackage;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HgConfigPackageToDtoMapperTest {
|
||||
|
||||
private URI baseUri = URI.create("http://example.com/base/");
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private UriInfoStore uriInfoStore;
|
||||
|
||||
@InjectMocks
|
||||
private HgConfigPackageToDtoMapperImpl mapper;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapFields() {
|
||||
HgPackage hgPackage = createPackage();
|
||||
|
||||
HgConfigPackageDto dto = mapper.map(hgPackage);
|
||||
|
||||
assertEqualsPackage(dto);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import sonia.scm.installer.HgPackage;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
class HgConfigTests {
|
||||
|
||||
private HgConfigTests() {
|
||||
}
|
||||
|
||||
static HgConfig createConfiguration() {
|
||||
HgConfig config = new HgConfig();
|
||||
config.setDisabled(true);
|
||||
config.setRepositoryDirectory(new File("repository/directory"));
|
||||
|
||||
config.setEncoding("ABC");
|
||||
config.setHgBinary("/etc/hg");
|
||||
config.setPythonBinary("/py");
|
||||
config.setPythonPath("/etc/");
|
||||
config.setShowRevisionInId(true);
|
||||
config.setUseOptimizedBytecode(true);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
static void assertEqualsConfiguration(HgConfigDto dto) {
|
||||
assertTrue(dto.isDisabled());
|
||||
assertEquals("repository/directory", dto.getRepositoryDirectory().getPath());
|
||||
|
||||
assertEquals("ABC", dto.getEncoding());
|
||||
assertEquals("/etc/hg", dto.getHgBinary());
|
||||
assertEquals("/py", dto.getPythonBinary());
|
||||
assertEquals("/etc/", dto.getPythonPath());
|
||||
assertTrue(dto.isShowRevisionInId());
|
||||
assertTrue(dto.isUseOptimizedBytecode());
|
||||
}
|
||||
|
||||
static HgPackage createPackage() {
|
||||
HgPackage hgPackage= new HgPackage();
|
||||
hgPackage.setArch("arch");
|
||||
hgPackage.setId("1");
|
||||
hgPackage.setHgVersion("2");
|
||||
hgPackage.setPlatform("someOs");
|
||||
hgPackage.setPythonVersion("3");
|
||||
hgPackage.setSize(4);
|
||||
hgPackage.setUrl("https://package");
|
||||
hgPackage.setHgConfigTemplate(createConfiguration());
|
||||
return hgPackage;
|
||||
}
|
||||
|
||||
static void assertEqualsPackage(HgConfigPackageDto dto) {
|
||||
assertEquals("arch", dto.getArch());
|
||||
assertEquals("1", dto.getId());
|
||||
assertEquals("2", dto.getHgVersion());
|
||||
assertEquals("someOs", dto.getPlatform());
|
||||
assertEquals("3", dto.getPythonVersion());
|
||||
assertEquals(4, dto.getSize());
|
||||
assertEquals("https://package", dto.getUrl());
|
||||
|
||||
assertEqualsConfiguration(dto.getHgConfigTemplate());
|
||||
assertTrue(dto.getHgConfigTemplate().getLinks().isEmpty());
|
||||
|
||||
assertTrue(dto.getLinks().isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,14 +14,14 @@ import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static sonia.scm.api.v2.resources.HgConfigTests.assertEqualsConfiguration;
|
||||
import static sonia.scm.api.v2.resources.HgConfigTests.createConfiguration;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HgConfigToHgConfigDtoMapperTest {
|
||||
@@ -59,15 +59,7 @@ public class HgConfigToHgConfigDtoMapperTest {
|
||||
when(subject.isPermitted("configuration:write:hg")).thenReturn(true);
|
||||
HgConfigDto dto = mapper.map(config);
|
||||
|
||||
assertTrue(dto.isDisabled());
|
||||
assertEquals("repository/directory", dto.getRepositoryDirectory().getPath());
|
||||
|
||||
assertEquals("ABC", dto.getEncoding());
|
||||
assertEquals("/etc/hg", dto.getHgBinary());
|
||||
assertEquals("/py", dto.getPythonBinary());
|
||||
assertEquals("/etc/", dto.getPythonPath());
|
||||
assertTrue(dto.isShowRevisionInId());
|
||||
assertTrue(dto.isUseOptimizedBytecode());
|
||||
assertEqualsConfiguration(dto);
|
||||
|
||||
assertEquals(expectedBaseUri.toString(), dto.getLinks().getLinkBy("self").get().getHref());
|
||||
assertEquals(expectedBaseUri.toString(), dto.getLinks().getLinkBy("update").get().getHref());
|
||||
@@ -83,20 +75,4 @@ public class HgConfigToHgConfigDtoMapperTest {
|
||||
assertEquals(expectedBaseUri.toString(), dto.getLinks().getLinkBy("self").get().getHref());
|
||||
assertFalse(dto.getLinks().hasLink("update"));
|
||||
}
|
||||
|
||||
private HgConfig createConfiguration() {
|
||||
HgConfig config = new HgConfig();
|
||||
config.setDisabled(true);
|
||||
config.setRepositoryDirectory(new File("repository/directory"));
|
||||
|
||||
config.setEncoding("ABC");
|
||||
config.setHgBinary("/etc/hg");
|
||||
config.setPythonBinary("/py");
|
||||
config.setPythonPath("/etc/");
|
||||
config.setShowRevisionInId(true);
|
||||
config.setUseOptimizedBytecode(true);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user