mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 06:55:47 +01:00
merge with 2.0.0-m3
This commit is contained in:
@@ -82,7 +82,7 @@ public class BranchRootResourceTest extends RepositoryTestBase {
|
||||
|
||||
|
||||
@InjectMocks
|
||||
private ChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||
private DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||
|
||||
private final Subject subject = mock(Subject.class);
|
||||
private final ThreadState subjectThreadState = new SubjectThreadState(subject);
|
||||
|
||||
@@ -24,12 +24,12 @@ class BranchToBranchDtoMapperTest {
|
||||
|
||||
@Test
|
||||
void shouldAppendLinks() {
|
||||
LinkEnricherRegistry registry = new LinkEnricherRegistry();
|
||||
HalEnricherRegistry registry = new HalEnricherRegistry();
|
||||
registry.register(Branch.class, (ctx, appender) -> {
|
||||
NamespaceAndName namespaceAndName = ctx.oneRequireByType(NamespaceAndName.class);
|
||||
Branch branch = ctx.oneRequireByType(Branch.class);
|
||||
|
||||
appender.appendOne("ka", "http://" + namespaceAndName.logString() + "/" + branch.getName());
|
||||
appender.appendLink("ka", "http://" + namespaceAndName.logString() + "/" + branch.getName());
|
||||
});
|
||||
mapper.setRegistry(registry);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ChangesetCollectionToDtoMapperTest {
|
||||
|
||||
public static final Repository REPOSITORY = new Repository("", "git", "space", "name");
|
||||
public static final Changeset CHANGESET = new Changeset();
|
||||
private final ChangesetToChangesetDtoMapper changesetToChangesetDtoMapper = mock(ChangesetToChangesetDtoMapper.class);
|
||||
private final DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper = mock(DefaultChangesetToChangesetDtoMapperImpl.class);
|
||||
|
||||
private final ChangesetCollectionToDtoMapper changesetCollectionToDtoMapper = new ChangesetCollectionToDtoMapper(changesetToChangesetDtoMapper, ResourceLinksMock.createMock(URI.create("/")));
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ChangesetRootResourceTest extends RepositoryTestBase {
|
||||
private ChangesetCollectionToDtoMapper changesetCollectionToDtoMapper;
|
||||
|
||||
@InjectMocks
|
||||
private ChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||
private DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||
|
||||
private ChangesetRootResource changesetRootResource;
|
||||
|
||||
|
||||
@@ -93,11 +93,7 @@ public class ConfigResourceTest {
|
||||
@Test
|
||||
@SubjectAware(username = "readWrite")
|
||||
public void shouldUpdateConfig() throws URISyntaxException, IOException {
|
||||
URL url = Resources.getResource("sonia/scm/api/v2/config-test-update.json");
|
||||
byte[] configJson = Resources.toByteArray(url);
|
||||
MockHttpRequest request = MockHttpRequest.put("/" + ConfigResource.CONFIG_PATH_V2)
|
||||
.contentType(VndMediaType.CONFIG)
|
||||
.content(configJson);
|
||||
MockHttpRequest request = post("sonia/scm/api/v2/config-test-update.json");
|
||||
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response);
|
||||
@@ -114,11 +110,7 @@ public class ConfigResourceTest {
|
||||
@Test
|
||||
@SubjectAware(username = "readOnly")
|
||||
public void shouldNotUpdateConfigWhenNotAuthorized() throws URISyntaxException, IOException {
|
||||
URL url = Resources.getResource("sonia/scm/api/v2/config-test-update.json");
|
||||
byte[] configJson = Resources.toByteArray(url);
|
||||
MockHttpRequest request = MockHttpRequest.put("/" + ConfigResource.CONFIG_PATH_V2)
|
||||
.contentType(VndMediaType.CONFIG)
|
||||
.content(configJson);
|
||||
MockHttpRequest request = post("sonia/scm/api/v2/config-test-update.json");
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
|
||||
thrown.expectMessage("Subject does not have permission [configuration:write:global]");
|
||||
@@ -126,6 +118,36 @@ public class ConfigResourceTest {
|
||||
dispatcher.invoke(request, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readWrite")
|
||||
public void shouldFailForEmptyAdminUsers() throws URISyntaxException, IOException {
|
||||
MockHttpRequest request = post("sonia/scm/api/v2/config-test-empty-admin-user.json");
|
||||
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response);
|
||||
|
||||
assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readWrite")
|
||||
public void shouldFailForEmptyAdminGroups() throws URISyntaxException, IOException {
|
||||
MockHttpRequest request = post("sonia/scm/api/v2/config-test-empty-admin-group.json");
|
||||
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response);
|
||||
|
||||
assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
|
||||
}
|
||||
|
||||
private MockHttpRequest post(String resourceName) throws IOException, URISyntaxException {
|
||||
URL url = Resources.getResource(resourceName);
|
||||
byte[] configJson = Resources.toByteArray(url);
|
||||
return MockHttpRequest.put("/" + ConfigResource.CONFIG_PATH_V2)
|
||||
.contentType(VndMediaType.CONFIG)
|
||||
.content(configJson);
|
||||
}
|
||||
|
||||
private static ScmConfiguration createConfiguration() {
|
||||
ScmConfiguration scmConfiguration = new ScmConfiguration();
|
||||
scmConfiguration.setProxyPassword("heartOfGold");
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.Embedded;
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import de.otto.edison.hal.Link;
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.otto.edison.hal.Embedded.embeddedBuilder;
|
||||
import static de.otto.edison.hal.Links.linkingTo;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class EdisonHalAppenderTest {
|
||||
|
||||
private Links.Builder linksBuilder;
|
||||
private Embedded.Builder embeddedBuilder;
|
||||
private EdisonHalAppender appender;
|
||||
|
||||
@BeforeEach
|
||||
void prepare() {
|
||||
linksBuilder = linkingTo();
|
||||
embeddedBuilder = embeddedBuilder();
|
||||
appender = new EdisonHalAppender(linksBuilder, embeddedBuilder);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAppendOneLink() {
|
||||
appender.appendLink("self", "https://scm.hitchhiker.com");
|
||||
|
||||
Links links = linksBuilder.build();
|
||||
assertThat(links.getLinkBy("self").get().getHref()).isEqualTo("https://scm.hitchhiker.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAppendMultipleLinks() {
|
||||
appender.linkArrayBuilder("items")
|
||||
.append("one", "http://one")
|
||||
.append("two", "http://two")
|
||||
.build();
|
||||
|
||||
List<Link> items = linksBuilder.build().getLinksBy("items");
|
||||
assertThat(items).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAppendEmbedded() {
|
||||
HalRepresentation one = new HalRepresentation();
|
||||
appender.appendEmbedded("one", one);
|
||||
|
||||
HalRepresentation two = new HalRepresentation();
|
||||
appender.appendEmbedded("two", new HalRepresentation());
|
||||
|
||||
Embedded embedded = embeddedBuilder.build();
|
||||
assertThat(embedded.getItemsBy("one")).containsOnly(one);
|
||||
assertThat(embedded.getItemsBy("two")).containsOnly(two);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.Link;
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.otto.edison.hal.Links.linkingTo;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class EdisonLinkAppenderTest {
|
||||
|
||||
private Links.Builder builder;
|
||||
private EdisonLinkAppender appender;
|
||||
|
||||
@BeforeEach
|
||||
void prepare() {
|
||||
builder = linkingTo();
|
||||
appender = new EdisonLinkAppender(builder);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAppendOneLink() {
|
||||
appender.appendOne("self", "https://scm.hitchhiker.com");
|
||||
|
||||
Links links = builder.build();
|
||||
assertThat(links.getLinkBy("self").get().getHref()).isEqualTo("https://scm.hitchhiker.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAppendMultipleLinks() {
|
||||
appender.arrayBuilder("items")
|
||||
.append("one", "http://one")
|
||||
.append("two", "http://two")
|
||||
.build();
|
||||
|
||||
List<Link> items = builder.build().getLinksBy("items");
|
||||
assertThat(items).hasSize(2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class FileHistoryResourceTest extends RepositoryTestBase {
|
||||
private FileHistoryCollectionToDtoMapper fileHistoryCollectionToDtoMapper;
|
||||
|
||||
@InjectMocks
|
||||
private ChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||
private DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||
|
||||
private FileHistoryRootResource fileHistoryRootResource;
|
||||
|
||||
|
||||
@@ -73,13 +73,13 @@ public class FileObjectToFileObjectDtoMapperTest {
|
||||
|
||||
@Test
|
||||
public void shouldAppendLinks() {
|
||||
LinkEnricherRegistry registry = new LinkEnricherRegistry();
|
||||
HalEnricherRegistry registry = new HalEnricherRegistry();
|
||||
registry.register(FileObject.class, (ctx, appender) -> {
|
||||
NamespaceAndName repository = ctx.oneRequireByType(NamespaceAndName.class);
|
||||
FileObject fo = ctx.oneRequireByType(FileObject.class);
|
||||
String rev = ctx.oneRequireByType(String.class);
|
||||
|
||||
appender.appendOne("hog", "http://" + repository.logString() + "/" + fo.getName() + "/" + rev);
|
||||
appender.appendLink("hog", "http://" + repository.logString() + "/" + fo.getName() + "/" + rev);
|
||||
});
|
||||
mapper.setRegistry(registry);
|
||||
|
||||
|
||||
@@ -90,10 +90,10 @@ public class GroupToGroupDtoMapperTest {
|
||||
|
||||
@Test
|
||||
public void shouldAppendLinks() {
|
||||
LinkEnricherRegistry registry = new LinkEnricherRegistry();
|
||||
HalEnricherRegistry registry = new HalEnricherRegistry();
|
||||
registry.register(Group.class, (ctx, appender) -> {
|
||||
Group group = ctx.oneRequireByType(Group.class);
|
||||
appender.appendOne("some", "http://" + group.getName());
|
||||
appender.appendLink("some", "http://" + group.getName());
|
||||
});
|
||||
mapper.setRegistry(registry);
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Java6Assertions.assertThat;
|
||||
|
||||
class HalEnricherAutoRegistrationTest {
|
||||
|
||||
@Test
|
||||
void shouldRegisterAllAvailableLinkEnrichers() {
|
||||
HalEnricher one = new One();
|
||||
HalEnricher two = new Two();
|
||||
HalEnricher three = new Three();
|
||||
HalEnricher four = new Four();
|
||||
Set<HalEnricher> enrichers = ImmutableSet.of(one, two, three, four);
|
||||
|
||||
HalEnricherRegistry registry = new HalEnricherRegistry();
|
||||
|
||||
LinkEnricherAutoRegistration autoRegistration = new LinkEnricherAutoRegistration(registry, enrichers);
|
||||
autoRegistration.contextInitialized(null);
|
||||
|
||||
assertThat(registry.allByType(String.class)).containsOnly(one, two);
|
||||
assertThat(registry.allByType(Integer.class)).containsOnly(three);
|
||||
}
|
||||
|
||||
@Enrich(String.class)
|
||||
public static class One implements HalEnricher {
|
||||
|
||||
@Override
|
||||
public void enrich(HalEnricherContext context, HalAppender appender) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Enrich(String.class)
|
||||
public static class Two implements HalEnricher {
|
||||
|
||||
@Override
|
||||
public void enrich(HalEnricherContext context, HalAppender appender) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Enrich(Integer.class)
|
||||
public static class Three implements HalEnricher {
|
||||
|
||||
@Override
|
||||
public void enrich(HalEnricherContext context, HalAppender appender) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class Four implements HalEnricher {
|
||||
|
||||
@Override
|
||||
public void enrich(HalEnricherContext context, HalAppender appender) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class IncomingRootResourceTest extends RepositoryTestBase {
|
||||
private IncomingChangesetCollectionToDtoMapper incomingChangesetCollectionToDtoMapper;
|
||||
|
||||
@InjectMocks
|
||||
private ChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||
private DefaultChangesetToChangesetDtoMapperImpl changesetToChangesetDtoMapper;
|
||||
|
||||
private IncomingRootResource incomingRootResource;
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Java6Assertions.assertThat;
|
||||
|
||||
class LinkEnricherAutoRegistrationTest {
|
||||
|
||||
@Test
|
||||
void shouldRegisterAllAvailableLinkEnrichers() {
|
||||
LinkEnricher one = new One();
|
||||
LinkEnricher two = new Two();
|
||||
LinkEnricher three = new Three();
|
||||
LinkEnricher four = new Four();
|
||||
Set<LinkEnricher> enrichers = ImmutableSet.of(one, two, three, four);
|
||||
|
||||
LinkEnricherRegistry registry = new LinkEnricherRegistry();
|
||||
|
||||
LinkEnricherAutoRegistration autoRegistration = new LinkEnricherAutoRegistration(registry, enrichers);
|
||||
autoRegistration.contextInitialized(null);
|
||||
|
||||
assertThat(registry.allByType(String.class)).containsOnly(one, two);
|
||||
assertThat(registry.allByType(Integer.class)).containsOnly(three);
|
||||
}
|
||||
|
||||
@Enrich(String.class)
|
||||
public static class One implements LinkEnricher {
|
||||
|
||||
@Override
|
||||
public void enrich(LinkEnricherContext context, LinkAppender appender) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Enrich(String.class)
|
||||
public static class Two implements LinkEnricher {
|
||||
|
||||
@Override
|
||||
public void enrich(LinkEnricherContext context, LinkAppender appender) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Enrich(Integer.class)
|
||||
public static class Three implements LinkEnricher {
|
||||
|
||||
@Override
|
||||
public void enrich(LinkEnricherContext context, LinkAppender appender) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class Four implements LinkEnricher {
|
||||
|
||||
@Override
|
||||
public void enrich(LinkEnricherContext context, LinkAppender appender) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -169,12 +169,12 @@ class MeDtoFactoryTest {
|
||||
void shouldAppendLinks() {
|
||||
prepareSubject(UserTestData.createTrillian());
|
||||
|
||||
LinkEnricherRegistry registry = new LinkEnricherRegistry();
|
||||
HalEnricherRegistry registry = new HalEnricherRegistry();
|
||||
meDtoFactory.setRegistry(registry);
|
||||
|
||||
registry.register(Me.class, (ctx, appender) -> {
|
||||
User user = ctx.oneRequireByType(User.class);
|
||||
appender.appendOne("profile", "http://hitchhiker.com/users/" + user.getName());
|
||||
appender.appendLink("profile", "http://hitchhiker.com/users/" + user.getName());
|
||||
});
|
||||
|
||||
MeDto dto = meDtoFactory.create();
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class NoBlankStringsValidatorTest {
|
||||
|
||||
@Test
|
||||
void shouldAcceptNonEmptyElements() {
|
||||
assertTrue(new NoBlankStringsValidator().isValid(Arrays.asList("not", "empty"), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailForEmptyElements() {
|
||||
assertFalse(new NoBlankStringsValidator().isValid(Arrays.asList("one", "", "three"), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldAcceptEmptyList() {
|
||||
assertTrue(new NoBlankStringsValidator().isValid(emptySet(), null));
|
||||
}
|
||||
}
|
||||
@@ -211,10 +211,10 @@ public class RepositoryToRepositoryDtoMapperTest {
|
||||
|
||||
@Test
|
||||
public void shouldAppendLinks() {
|
||||
LinkEnricherRegistry registry = new LinkEnricherRegistry();
|
||||
HalEnricherRegistry registry = new HalEnricherRegistry();
|
||||
registry.register(Repository.class, (ctx, appender) -> {
|
||||
Repository repository = ctx.oneRequireByType(Repository.class);
|
||||
appender.appendOne("id", "http://" + repository.getId());
|
||||
appender.appendLink("id", "http://" + repository.getId());
|
||||
});
|
||||
mapper.setRegistry(registry);
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ class TagToTagDtoMapperTest {
|
||||
|
||||
@Test
|
||||
void shouldAppendLinks() {
|
||||
LinkEnricherRegistry registry = new LinkEnricherRegistry();
|
||||
HalEnricherRegistry registry = new HalEnricherRegistry();
|
||||
registry.register(Tag.class, (ctx, appender) -> {
|
||||
NamespaceAndName repository = ctx.oneRequireByType(NamespaceAndName.class);
|
||||
Tag tag = ctx.oneRequireByType(Tag.class);
|
||||
appender.appendOne("yo", "http://" + repository.logString() + "/" + tag.getName());
|
||||
appender.appendLink("yo", "http://" + repository.logString() + "/" + tag.getName());
|
||||
});
|
||||
mapper.setRegistry(registry);
|
||||
|
||||
|
||||
@@ -155,8 +155,8 @@ public class UserToUserDtoMapperTest {
|
||||
public void shouldAppendLink() {
|
||||
User trillian = UserTestData.createTrillian();
|
||||
|
||||
LinkEnricherRegistry registry = new LinkEnricherRegistry();
|
||||
registry.register(User.class, (ctx, appender) -> appender.appendOne("sample", "http://" + ctx.oneByType(User.class).get().getName()));
|
||||
HalEnricherRegistry registry = new HalEnricherRegistry();
|
||||
registry.register(User.class, (ctx, appender) -> appender.appendLink("sample", "http://" + ctx.oneByType(User.class).get().getName()));
|
||||
mapper.setRegistry(registry);
|
||||
|
||||
UserDto userDto = mapper.map(trillian);
|
||||
|
||||
@@ -136,10 +136,13 @@ public class GitLfsITCase {
|
||||
}
|
||||
|
||||
private void createUser(User user) {
|
||||
UserDto dto = new UserToUserDtoMapperImpl(){
|
||||
@Override
|
||||
protected void appendLinks(User user, UserDto target) {}
|
||||
}.map(user);
|
||||
UserDto dto = new UserDto();
|
||||
dto.setName(user.getName());
|
||||
dto.setMail(user.getMail());
|
||||
dto.setDisplayName(user.getDisplayName());
|
||||
dto.setType(user.getType());
|
||||
dto.setActive(user.isActive());
|
||||
dto.setAdmin(user.isAdmin());
|
||||
dto.setPassword(user.getPassword());
|
||||
createResource(adminClient, "users")
|
||||
.accept("*/*")
|
||||
|
||||
@@ -2,8 +2,6 @@ package sonia.scm.web.i18n;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.sdorra.shiro.ShiroRule;
|
||||
import com.github.sdorra.shiro.SubjectAware;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -40,12 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
@SubjectAware(configuration = "classpath:sonia/scm/shiro-001.ini")
|
||||
public class I18nServletTest {
|
||||
|
||||
@Rule
|
||||
public ShiroRule shiro = new ShiroRule();
|
||||
|
||||
private static final String GIT_PLUGIN_JSON = json(
|
||||
"{",
|
||||
"'scm-git-plugin': {",
|
||||
@@ -86,15 +80,15 @@ public class I18nServletTest {
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Mock
|
||||
PluginLoader pluginLoader;
|
||||
private PluginLoader pluginLoader;
|
||||
|
||||
@Mock
|
||||
CacheManager cacheManager;
|
||||
private CacheManager cacheManager;
|
||||
|
||||
@Mock
|
||||
ClassLoader classLoader;
|
||||
private ClassLoader classLoader;
|
||||
|
||||
I18nServlet servlet;
|
||||
private I18nServlet servlet;
|
||||
|
||||
@Mock
|
||||
private Cache cache;
|
||||
@@ -104,9 +98,9 @@ public class I18nServletTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void init() throws IOException {
|
||||
resources = Collections.enumeration(Lists.newArrayList(
|
||||
createFileFromString(SVN_PLUGIN_JSON).toURL(),
|
||||
createFileFromString(GIT_PLUGIN_JSON).toURL(),
|
||||
createFileFromString(HG_PLUGIN_JSON).toURL()
|
||||
createFileFromString(SVN_PLUGIN_JSON).toURI().toURL(),
|
||||
createFileFromString(GIT_PLUGIN_JSON).toURI().toURL(),
|
||||
createFileFromString(HG_PLUGIN_JSON).toURI().toURL()
|
||||
));
|
||||
when(pluginLoader.getUberClassLoader()).thenReturn(classLoader);
|
||||
when(cacheManager.getCache(I18nServlet.CACHE_NAME)).thenReturn(cache);
|
||||
@@ -192,6 +186,8 @@ public class I18nServletTest {
|
||||
assertJson(json);
|
||||
verify(cache).get(path);
|
||||
verify(cache).put(eq(path), any());
|
||||
|
||||
verifyHeaders(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -219,6 +215,8 @@ public class I18nServletTest {
|
||||
verify(cache, never()).put(eq(path), any());
|
||||
verify(cache).get(path);
|
||||
assertJson(json);
|
||||
|
||||
verifyHeaders(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -232,11 +230,16 @@ public class I18nServletTest {
|
||||
assertJson(jsonNodeOptional.orElse(null));
|
||||
}
|
||||
|
||||
private void verifyHeaders(HttpServletResponse response) {
|
||||
verify(response).setCharacterEncoding("UTF-8");
|
||||
verify(response).setContentType("application/json");
|
||||
}
|
||||
|
||||
public void assertJson(JsonNode actual) throws IOException {
|
||||
assertJson(actual.toString());
|
||||
}
|
||||
|
||||
public void assertJson(String actual) throws IOException {
|
||||
private void assertJson(String actual) throws IOException {
|
||||
assertThat(actual)
|
||||
.isNotEmpty()
|
||||
.contains(StringUtils.deleteWhitespace(GIT_PLUGIN_JSON.substring(1, GIT_PLUGIN_JSON.length() - 1)))
|
||||
@@ -244,7 +247,7 @@ public class I18nServletTest {
|
||||
.contains(StringUtils.deleteWhitespace(SVN_PLUGIN_JSON.substring(1, SVN_PLUGIN_JSON.length() - 1)));
|
||||
}
|
||||
|
||||
public File createFileFromString(String json) throws IOException {
|
||||
private File createFileFromString(String json) throws IOException {
|
||||
File file = temporaryFolder.newFile();
|
||||
Files.write(json.getBytes(Charsets.UTF_8), file);
|
||||
return file;
|
||||
|
||||
Reference in New Issue
Block a user