diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2018-06-22 16:08:28 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2018-06-29 09:10:14 +0200 |
commit | 697e8d18e6a8b9dca3e345fa355c4b6228e89bdc (patch) | |
tree | 4a02e5b723379f032261e921564e7656219c3063 /server/sonar-server-common | |
parent | 525ed917b32bfd43f2517c03d500d7a557240ce0 (diff) | |
download | sonarqube-697e8d18e6a8b9dca3e345fa355c4b6228e89bdc.tar.gz sonarqube-697e8d18e6a8b9dca3e345fa355c4b6228e89bdc.zip |
create module sonar-ce-common
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r-- | server/sonar-server-common/build.gradle | 47 | ||||
-rw-r--r-- | server/sonar-server-common/src/test/java/org/sonar/server/organization/TestDefaultOrganizationProvider.java | 95 |
2 files changed, 128 insertions, 14 deletions
diff --git a/server/sonar-server-common/build.gradle b/server/sonar-server-common/build.gradle index 94fa4862ee7..6e189c3febf 100644 --- a/server/sonar-server-common/build.gradle +++ b/server/sonar-server-common/build.gradle @@ -1,23 +1,42 @@ +description = 'Code shared between the Web Server and the Compute Engine' + sonarqube { - properties { - property 'sonar.projectName', "${projectTitle} :: Server :: Common" - } + properties { + property 'sonar.projectName', "${projectTitle} :: Server :: Common" + } +} + +configurations { + tests } dependencies { - // please keep the list grouped by configuration and ordered by name + // please keep the list grouped by configuration and ordered by name + + compile 'com.google.guava:guava' + compile 'org.slf4j:slf4j-api' + compile project(':sonar-core') + compile project(':server:sonar-db-dao') - compile 'com.google.guava:guava' - compile 'org.slf4j:slf4j-api' + compileOnly project(path: ':sonar-plugin-api') + compileOnly project(path: ':server:sonar-process') - compile project(':sonar-core') - compileOnly project(path: ':sonar-plugin-api') + compileOnly 'com.google.code.findbugs:jsr305' - compileOnly 'com.google.code.findbugs:jsr305' + testCompile 'com.google.code.findbugs:jsr305' + testCompile 'com.h2database:h2' + testCompile 'com.tngtech.java:junit-dataprovider' + testCompile 'junit:junit' + testCompile 'org.assertj:assertj-core' + testCompile 'org.mockito:mockito-core' + testCompile project(':server:sonar-db-testing') +} + +task testJar(type: Jar) { + classifier = 'tests' + from sourceSets.test.output +} - testCompile 'com.google.code.findbugs:jsr305' - testCompile 'com.tngtech.java:junit-dataprovider' - testCompile 'junit:junit' - testCompile 'org.assertj:assertj-core' - testCompile 'org.mockito:mockito-core' +artifacts { + tests testJar } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/organization/TestDefaultOrganizationProvider.java b/server/sonar-server-common/src/test/java/org/sonar/server/organization/TestDefaultOrganizationProvider.java new file mode 100644 index 00000000000..10092482447 --- /dev/null +++ b/server/sonar-server-common/src/test/java/org/sonar/server/organization/TestDefaultOrganizationProvider.java @@ -0,0 +1,95 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.organization; + +import java.util.Date; +import org.sonar.db.DbTester; +import org.sonar.db.organization.OrganizationDto; + +public class TestDefaultOrganizationProvider implements DefaultOrganizationProvider { + + private final DefaultOrganizationProvider delegate; + + private TestDefaultOrganizationProvider(DefaultOrganizationProvider delegate) { + this.delegate = delegate; + } + + public static TestDefaultOrganizationProvider from(DbTester dbTester) { + return new TestDefaultOrganizationProvider(new DbTesterDefaultOrganizationProvider(dbTester)); + } + + public static TestDefaultOrganizationProvider fromUuid(String uuid) { + long createdAt = new Date().getTime(); + return new TestDefaultOrganizationProvider( + new ImmutableDefaultOrganizationProvider( + DefaultOrganization.newBuilder() + .setUuid(uuid) + .setKey("key_" + uuid) + .setName("name_" + uuid) + .setCreatedAt(createdAt) + .setUpdatedAt(createdAt) + .build())); + } + + @Override + public DefaultOrganization get() { + return delegate.get(); + } + + private static final class ImmutableDefaultOrganizationProvider implements DefaultOrganizationProvider { + private final DefaultOrganization defaultOrganization; + + private ImmutableDefaultOrganizationProvider(DefaultOrganization defaultOrganization) { + this.defaultOrganization = defaultOrganization; + } + + @Override + public DefaultOrganization get() { + return defaultOrganization; + } + } + + private static final class DbTesterDefaultOrganizationProvider implements DefaultOrganizationProvider { + private final DbTester dbTester; + private DefaultOrganization defaultOrganization = null; + + private DbTesterDefaultOrganizationProvider(DbTester dbTester) { + this.dbTester = dbTester; + } + + @Override + public DefaultOrganization get() { + if (defaultOrganization == null) { + defaultOrganization = toDefaultOrganization(dbTester.getDefaultOrganization()); + } + return defaultOrganization; + } + + private static DefaultOrganization toDefaultOrganization(OrganizationDto organizationDto) { + return DefaultOrganization.newBuilder() + .setUuid(organizationDto.getUuid()) + .setKey(organizationDto.getKey()) + .setName(organizationDto.getName()) + .setCreatedAt(organizationDto.getCreatedAt()) + .setUpdatedAt(organizationDto.getUpdatedAt()) + .build(); + } + } +} |