mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-06 23:58:46 +02:00
do not create config.xml during unit test
This commit is contained in:
@@ -21,9 +21,10 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -45,6 +46,7 @@ import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* RESTful Web Service Resource to manage the configuration.
|
||||
@@ -61,6 +63,8 @@ public class ConfigResource {
|
||||
private final ScmConfiguration configuration;
|
||||
private final NamespaceStrategyValidator namespaceStrategyValidator;
|
||||
|
||||
private Consumer<ScmConfiguration> store = (config) -> ScmConfigurationUtil.getInstance().store(config);
|
||||
|
||||
@Inject
|
||||
public ConfigResource(ConfigDtoToScmConfigurationMapper dtoToConfigMapper,
|
||||
ScmConfigurationToConfigDtoMapper configToDtoMapper,
|
||||
@@ -71,6 +75,11 @@ public class ConfigResource {
|
||||
this.namespaceStrategyValidator = namespaceStrategyValidator;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setStore(Consumer<ScmConfiguration> store) {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the global scm config.
|
||||
*/
|
||||
@@ -137,7 +146,7 @@ public class ConfigResource {
|
||||
ScmConfiguration config = dtoToConfigMapper.map(configDto);
|
||||
synchronized (ScmConfiguration.class) {
|
||||
configuration.load(config);
|
||||
ScmConfigurationUtil.getInstance().store(configuration);
|
||||
store.accept(configuration);
|
||||
}
|
||||
|
||||
return Response.noContent().build();
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.github.sdorra.shiro.ShiroRule;
|
||||
@@ -89,6 +89,7 @@ public class ConfigResourceTest {
|
||||
initMocks(this);
|
||||
|
||||
ConfigResource configResource = new ConfigResource(dtoToConfigMapper, configToDtoMapper, createConfiguration(), namespaceStrategyValidator);
|
||||
configResource.setStore(config -> {});
|
||||
|
||||
dispatcher.addSingletonResource(configResource);
|
||||
}
|
||||
@@ -128,7 +129,9 @@ public class ConfigResourceTest {
|
||||
|
||||
request = MockHttpRequest.get("/" + ConfigResource.CONFIG_PATH_V2);
|
||||
response = new MockHttpResponse();
|
||||
dispatcher.invoke(request, response); assertEquals(HttpServletResponse.SC_OK, response.getStatus());
|
||||
dispatcher.invoke(request, response);
|
||||
|
||||
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
|
||||
assertTrue(response.getContentAsString().contains("\"proxyPassword\":\"newPassword\""));
|
||||
assertTrue(response.getContentAsString().contains("\"self\":{\"href\":\"/v2/config"));
|
||||
assertTrue("link not found", response.getContentAsString().contains("\"update\":{\"href\":\"/v2/config"));
|
||||
@@ -146,8 +149,6 @@ public class ConfigResourceTest {
|
||||
assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@SubjectAware(username = "readWrite")
|
||||
public void shouldValidateNamespaceStrategy() throws URISyntaxException {
|
||||
|
||||
Reference in New Issue
Block a user