3 * Copyright (C) 2009-2022 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.ce.task.projectexport.steps;
22 import com.sonarsource.governance.projectdump.protobuf.ProjectDump;
23 import org.junit.Test;
24 import org.sonar.api.SonarEdition;
25 import org.sonar.api.SonarQubeSide;
26 import org.sonar.api.internal.SonarRuntimeImpl;
27 import org.sonar.api.utils.System2;
28 import org.sonar.api.utils.Version;
29 import org.sonar.ce.task.step.TestComputationStepContext;
30 import org.sonar.db.project.ProjectDto;
32 import static org.assertj.core.api.Assertions.assertThat;
33 import static org.mockito.Mockito.spy;
34 import static org.mockito.Mockito.when;
36 public class WriteMetadataStepTest {
38 private static final String PROJECT_KEY = "project_key";
39 private static final String PROJECT_UUID = "project_uuid";
40 private static final long NOW = 123L;
42 System2 system2 = spy(System2.INSTANCE);
43 FakeDumpWriter dumpWriter = new FakeDumpWriter();
44 MutableProjectHolderImpl projectHolder = new MutableProjectHolderImpl();
45 Version sqVersion = Version.create(6, 0);
46 WriteMetadataStep underTest = new WriteMetadataStep(system2, dumpWriter, projectHolder,
47 SonarRuntimeImpl.forSonarQube(sqVersion, SonarQubeSide.SERVER, SonarEdition.COMMUNITY));
50 public void write_metadata() {
51 when(system2.now()).thenReturn(NOW);
52 ProjectDto dto = new ProjectDto().setKey(PROJECT_KEY).setUuid(PROJECT_UUID);
53 projectHolder.setProjectDto(dto);
54 underTest.execute(new TestComputationStepContext());
56 ProjectDump.Metadata metadata = dumpWriter.getMetadata();
57 assertThat(metadata.getProjectKey()).isEqualTo(PROJECT_KEY);
58 assertThat(metadata.getProjectUuid()).isEqualTo(PROJECT_UUID);
59 assertThat(metadata.getSonarqubeVersion()).isEqualTo(sqVersion.toString());
60 assertThat(metadata.getDumpDate()).isEqualTo(NOW);
64 public void getDescription_is_defined() {
65 assertThat(underTest.getDescription()).isNotEmpty();