3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program 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 * This program 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.
20 package org.sonar.server.computation.task.projectanalysis.step;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.junit.rules.ExpectedException;
25 import org.mockito.ArgumentCaptor;
26 import org.sonar.api.utils.MessageException;
27 import org.sonar.db.organization.OrganizationDto;
28 import org.sonar.server.computation.task.projectanalysis.analysis.MutableAnalysisMetadataHolderRule;
29 import org.sonar.server.computation.task.projectanalysis.analysis.Organization;
30 import org.sonar.server.organization.BillingValidations;
31 import org.sonar.server.organization.BillingValidations.BillingValidationsException;
32 import org.sonar.server.organization.BillingValidationsProxy;
34 import static org.assertj.core.api.Assertions.assertThat;
35 import static org.mockito.Matchers.any;
36 import static org.mockito.Mockito.doThrow;
37 import static org.mockito.Mockito.mock;
38 import static org.mockito.Mockito.verify;
39 import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
41 public class VerifyBillingStepTest {
44 public ExpectedException expectedException = ExpectedException.none();
46 private OrganizationDto organization = newOrganizationDto();
48 public MutableAnalysisMetadataHolderRule analysisMetadata = new MutableAnalysisMetadataHolderRule()
49 .setOrganization(Organization.from(organization));
51 private BillingValidationsProxy validations = mock(BillingValidationsProxy.class);
54 public void execute_fails_with_MessageException_when_organization_is_not_allowed_to_execute_analysis() {
55 doThrow(new BillingValidationsException("This organization cannot execute project analysis"))
57 .checkOnProjectAnalysis(any(BillingValidations.Organization.class));
59 VerifyBillingStep underTest = new VerifyBillingStep(analysisMetadata, validations);
61 expectedException.expect(MessageException.class);
62 expectedException.expectMessage("This organization cannot execute project analysis");
69 public void execute_does_no_fail_when_organization_is_allowed_to_execute_analysis() {
70 ArgumentCaptor<BillingValidations.Organization> orgCaptor = ArgumentCaptor.forClass(BillingValidations.Organization.class);
72 VerifyBillingStep underTest = new VerifyBillingStep(analysisMetadata, validations);
75 verify(validations).checkOnProjectAnalysis(orgCaptor.capture());
76 BillingValidations.Organization calledOrg = orgCaptor.getValue();
77 assertThat(calledOrg.getKey()).isEqualTo(organization.getKey());