/* * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jetbrains.buildServer.usageStatistics.impl.providers; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Map; import jetbrains.buildServer.groups.UserGroupManager; import jetbrains.buildServer.serverSide.BuildAgentManager; import jetbrains.buildServer.serverSide.impl.BaseServerTestCase; import jetbrains.buildServer.usageStatistics.UsageStatisticsProvider; import jetbrains.buildServer.usageStatistics.UsageStatisticsPublisher; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.testng.annotations.Test; @Test public class UsageStatisticsProvidersTest extends BaseServerTestCase { public void provider_should_not_fail_on_publishing_statistics() { final UsageStatisticsPublisher publisher = new UsageStatisticsPublisher() { public void publishStatistic(@NotNull final String id, @Nullable final Object value) { // do nothing } }; for (final BaseUsageStatisticsProvider provider : getAllProviders()) { provider.setIdFormat(""); provider.setGroupName(""); provider.accept(publisher); } } public void static_server_usage_statistics_provider_test() { final StaticServerUsageStatisticsProvider provider = myServer.getSingletonService(StaticServerUsageStatisticsProvider.class); provider.setIdFormat("%s"); final Map statistics = collectStatisticsByProvider(provider); assertEquals(myServer.getProjectManager().getNumberOfProjects(), statistics.get("projectNumber")); assertEquals(myServer.getProjectManager().getArchivedProjects().size(), statistics.get("archivedProjectNumber")); assertEquals(myServer.getProjectManager().getNumberOfBuildTypes(), statistics.get("buildTypeNumber")); final BuildAgentManager buildAgentManager = myServer.getBuildAgentManager(); assertEquals(buildAgentManager.getRegisteredAgents(true).size(), statistics.get("allRegisteredAgentNumber")); assertEquals(buildAgentManager.getRegisteredAgents(false).size(), statistics.get("authorizedRegisteredAgentNumber")); assertEquals(myServer.getVcsManager().getAllRegisteredVcsRoots().size(), statistics.get("vcsRootNumber")); assertEquals(myServer.getUserModel().getNumberOfRegisteredUsers(), statistics.get("userNumber")); final UserGroupManager userGroupManager = myServer.getSingletonService(UserGroupManager.class); assertEquals(userGroupManager.getUserGroups().size(), statistics.get("userGroupNumber")); } private Collection getAllProviders() { return Arrays.asList( myServer.getSingletonService(AgentsJavaUsageStatisticsProvider.class), myServer.getSingletonService(ServerLoadUsageStatisticsProvider.class), myServer.getSingletonService(IDEUsageStatisticsProvider.class), myServer.getSingletonService(NotificatorUsageStatisticsProvider.class), myServer.getSingletonService(RunnerUsageStatisticsProvider.class), myServer.getSingletonService(ServerConfigurationUsageStatisticsProvider.class), myServer.getSingletonService(StaticServerUsageStatisticsProvider.class), myServer.getSingletonService(TriggerUsageStatisticsProvider.class), myServer.getSingletonService(VCSUsageStatisticsProvider.class) // myServer.getSingletonService(WebPagesUsageStatisticsProvider.class) ); } private Map collectStatisticsByProvider(@NotNull final UsageStatisticsProvider provider) { final Map statistics = new HashMap(); provider.accept(new UsageStatisticsPublisher() { public void publishStatistic(@NotNull final String id, @Nullable final Object value) { statistics.put(id, value); } }); return statistics; } }