2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2014 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 package org.sonar.server.permission.ws;
23 import java.util.List;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.sonar.api.config.Settings;
28 import org.sonar.api.resources.Qualifiers;
29 import org.sonar.api.resources.ResourceType;
30 import org.sonar.api.resources.ResourceTypes;
32 import static java.util.Arrays.asList;
33 import static org.assertj.core.api.Assertions.assertThat;
34 import static org.mockito.Mockito.mock;
35 import static org.mockito.Mockito.when;
36 import static org.sonar.server.permission.DefaultPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY;
37 import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty;
39 public class DefaultPermissionTemplateFinderTest {
41 ResourceTypes resourceTypes = mock(ResourceTypes.class);
42 Settings settings = new Settings();
44 DefaultPermissionTemplateFinder underTest;
48 underTest = new DefaultPermissionTemplateFinder(settings, resourceTypes);
50 .setProperty(DEFAULT_TEMPLATE_PROPERTY, "default-template-uuid")
51 .setProperty(defaultRootQualifierTemplateProperty(Qualifiers.PROJECT), "default-project-template-uuid")
52 .setProperty(defaultRootQualifierTemplateProperty("DEV"), "default-dev-template-uuid")
53 .setProperty(defaultRootQualifierTemplateProperty(Qualifiers.VIEW), "default-view-template-uuid");
54 when(resourceTypes.getRoots()).thenReturn(rootResourceTypes());
58 public void get_default_template_uuids_in_settings() {
59 Set<String> result = underTest.getDefaultTemplateUuids();
61 assertThat(result).containsOnly("default-project-template-uuid", "default-view-template-uuid", "default-dev-template-uuid");
65 public void get_default_template_uuid_if_no_property() {
66 settings = new Settings();
67 settings.setProperty(DEFAULT_TEMPLATE_PROPERTY, "default-template-uuid");
68 underTest = new DefaultPermissionTemplateFinder(settings, resourceTypes);
70 Set<String> result = underTest.getDefaultTemplateUuids();
72 assertThat(result).containsOnly("default-template-uuid");
75 private static List<ResourceType> rootResourceTypes() {
76 ResourceType project = ResourceType.builder(Qualifiers.PROJECT).build();
77 ResourceType view = ResourceType.builder(Qualifiers.VIEW).build();
78 ResourceType dev = ResourceType.builder("DEV").build();
80 return asList(project, view, dev);