diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/api/v2/resources/GitConfigResourceTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/api/v2/resources/GitConfigResourceTest.java index 46e47bbf38..7535e43db5 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/api/v2/resources/GitConfigResourceTest.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/api/v2/resources/GitConfigResourceTest.java @@ -1,5 +1,7 @@ package sonia.scm.api.v2.resources; +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; @@ -16,10 +18,10 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import sonia.scm.repository.GitConfig; import sonia.scm.repository.GitRepositoryHandler; -import sonia.scm.store.ConfigurationStoreFactory; import javax.servlet.http.HttpServletResponse; import java.io.File; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -52,38 +54,39 @@ public class GitConfigResourceTest { private GitConfigToGitConfigDtoMapperImpl configToDtoMapper; @Mock - ConfigurationStoreFactory storeFactory; - - @InjectMocks private GitRepositoryHandler repositoryHandler; @Before public void prepareEnvironment() { GitConfig gitConfig = createConfiguration(); - repositoryHandler.setConfig(gitConfig); + when(repositoryHandler.getConfig()).thenReturn(gitConfig); GitConfigResource gitConfigResource = new GitConfigResource(dtoToConfigMapper, configToDtoMapper, repositoryHandler); dispatcher.getRegistry().addSingletonResource(gitConfigResource); when(uriInfoStore.get().getBaseUri()).thenReturn(baseUri); } @Test - public void shouldGetGitConfig() throws URISyntaxException { + public void shouldGetGitConfig() throws URISyntaxException, IOException { MockHttpRequest request = MockHttpRequest.get("/" + GitConfigResource.GIT_CONFIG_PATH_V2); MockHttpResponse response = new MockHttpResponse(); dispatcher.invoke(request, response); assertEquals(HttpServletResponse.SC_OK, response.getStatus()); - assertTrue(response.getContentAsString().contains("\"disabled\":false")); - //assertTrue(response.getContentAsString().contains("\"repository-directory\":\"repository/directory\"")); - //assertTrue(response.getContentAsString().contains("\"gc-expression\":\"valid Git GC Cron Expression\"")); - assertTrue(response.getContentAsString().contains("\"self\":{\"href\":\"/v2/config/git")); - assertTrue(response.getContentAsString().contains("\"update\":{\"href\":\"/v2/config/git")); + + String responseString = response.getContentAsString(); + ObjectNode responseJson = new ObjectMapper().readValue(responseString, ObjectNode.class); + + assertTrue(responseString.contains("\"disabled\":false")); + assertTrue(responseJson.get("repositoryDirectory").asText().endsWith("repository/directory")); + assertTrue(responseString.contains("\"gcExpression\":\"valid Git GC Cron Expression\"")); + assertTrue(responseString.contains("\"self\":{\"href\":\"/v2/config/git")); + assertTrue(responseString.contains("\"update\":{\"href\":\"/v2/config/git")); } - // TODO negative tests + // TODO update & negative tests private GitConfig createConfiguration() { GitConfig config = new GitConfig(); - //config.setGcExpression("valid Git GC Cron Expression"); + config.setGcExpression("valid Git GC Cron Expression"); config.setDisabled(false); config.setRepositoryDirectory(new File("repository/directory")); return config;