mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-16 10:16:16 +01:00
Remove direct dependency to UriInfo
This commit is contained in:
@@ -4,7 +4,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
@@ -37,7 +36,7 @@ public class LinkBuilderTest {
|
||||
}
|
||||
}
|
||||
|
||||
private UriInfo uriInfo = mock(UriInfo.class);
|
||||
private ScmPathInfo uriInfo = mock(ScmPathInfo.class);
|
||||
|
||||
@Test
|
||||
public void shouldBuildSimplePath() {
|
||||
@@ -94,6 +93,6 @@ public class LinkBuilderTest {
|
||||
|
||||
@Before
|
||||
public void setBaseUri() throws URISyntaxException {
|
||||
when(uriInfo.getBaseUri()).thenReturn(new URI("http://example.com/"));
|
||||
when(uriInfo.getApiRestUri()).thenReturn(new URI("http://example.com/"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import sonia.scm.user.UserManager;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
@@ -40,7 +39,7 @@ public class MeResourceTest {
|
||||
|
||||
private final ResourceLinks resourceLinks = ResourceLinksMock.createMock(URI.create("/"));
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
private ScmPathInfo uriInfo;
|
||||
@Mock
|
||||
private UriInfoStore uriInfoStore;
|
||||
|
||||
@@ -62,7 +61,7 @@ public class MeResourceTest {
|
||||
userToDtoMapper.setResourceLinks(resourceLinks);
|
||||
MeResource meResource = new MeResource(userToDtoMapper, userManager);
|
||||
dispatcher.getRegistry().addSingletonResource(meResource);
|
||||
when(uriInfo.getBaseUri()).thenReturn(URI.create("/"));
|
||||
when(uriInfo.getApiRestUri()).thenReturn(URI.create("/"));
|
||||
when(uriInfoStore.get()).thenReturn(uriInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import sonia.scm.repository.api.RepositoryServiceFactory;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -73,7 +72,7 @@ public class RepositoryRootResourceTest {
|
||||
@Mock
|
||||
private UriInfoStore uriInfoStore;
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
private ScmPathInfo uriInfo;
|
||||
|
||||
|
||||
private final URI baseUri = URI.create("/");
|
||||
@@ -93,7 +92,7 @@ public class RepositoryRootResourceTest {
|
||||
RepositoryRootResource repositoryRootResource = new RepositoryRootResource(MockProvider.of(repositoryResource), MockProvider.of(repositoryCollectionResource));
|
||||
when(serviceFactory.create(any(Repository.class))).thenReturn(service);
|
||||
when(uriInfoStore.get()).thenReturn(uriInfo);
|
||||
when(uriInfo.getBaseUri()).thenReturn(URI.create("/x/y"));
|
||||
when(uriInfo.getApiRestUri()).thenReturn(URI.create("/x/y"));
|
||||
dispatcher = createDispatcher(repositoryRootResource);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import sonia.scm.repository.api.RepositoryService;
|
||||
import sonia.scm.repository.api.RepositoryServiceFactory;
|
||||
import sonia.scm.repository.api.ScmProtocol;
|
||||
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
@@ -51,7 +50,7 @@ public class RepositoryToRepositoryDtoMapperTest {
|
||||
@Mock
|
||||
private UriInfoStore uriInfoStore;
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
private ScmPathInfo uriInfo;
|
||||
|
||||
@InjectMocks
|
||||
private RepositoryToRepositoryDtoMapperImpl mapper;
|
||||
@@ -63,7 +62,7 @@ public class RepositoryToRepositoryDtoMapperTest {
|
||||
when(repositoryService.isSupported(any(Command.class))).thenReturn(true);
|
||||
when(repositoryService.getSupportedProtocols()).thenReturn(emptySet());
|
||||
when(uriInfoStore.get()).thenReturn(uriInfo);
|
||||
when(uriInfo.getBaseUri()).thenReturn(URI.create("/x/y"));
|
||||
when(uriInfo.getApiRestUri()).thenReturn(URI.create("/x/y"));
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -10,8 +9,8 @@ public class ResourceLinksMock {
|
||||
public static ResourceLinks createMock(URI baseUri) {
|
||||
ResourceLinks resourceLinks = mock(ResourceLinks.class);
|
||||
|
||||
UriInfo uriInfo = mock(UriInfo.class);
|
||||
when(uriInfo.getBaseUri()).thenReturn(baseUri);
|
||||
ScmPathInfo uriInfo = mock(ScmPathInfo.class);
|
||||
when(uriInfo.getApiRestUri()).thenReturn(baseUri);
|
||||
|
||||
when(resourceLinks.user()).thenReturn(new ResourceLinks.UserLinks(uriInfo));
|
||||
when(resourceLinks.userCollection()).thenReturn(new ResourceLinks.UserCollectionLinks(uriInfo));
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -20,7 +19,7 @@ public class ResourceLinksTest {
|
||||
@Mock
|
||||
private UriInfoStore uriInfoStore;
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
private ScmPathInfo uriInfo;
|
||||
|
||||
@InjectMocks
|
||||
private ResourceLinks resourceLinks;
|
||||
@@ -178,6 +177,6 @@ public class ResourceLinksTest {
|
||||
public void initUriInfo() {
|
||||
initMocks(this);
|
||||
when(uriInfoStore.get()).thenReturn(uriInfo);
|
||||
when(uriInfo.getBaseUri()).thenReturn(URI.create(BASE_URL));
|
||||
when(uriInfo.getApiRestUri()).thenReturn(URI.create(BASE_URL));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,19 +4,26 @@ import org.junit.Test;
|
||||
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class UriInfoStoreTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnSetInfo() {
|
||||
URI someUri = URI.create("/anything");
|
||||
|
||||
UriInfo uriInfo = mock(UriInfo.class);
|
||||
UriInfoStore uriInfoStore = new UriInfoStore();
|
||||
|
||||
when(uriInfo.getBaseUri()).thenReturn(someUri);
|
||||
|
||||
uriInfoStore.set(uriInfo);
|
||||
|
||||
assertSame(uriInfo, uriInfoStore.get());
|
||||
assertSame(someUri, uriInfoStore.get().getApiRestUri());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
|
||||
Reference in New Issue
Block a user