Skip to content

Commit

Permalink
SONAR-9551 Persist applications with APP qualifier
Browse files Browse the repository at this point in the history
  • Loading branch information
teryk authored and julienlancelot committed Jul 31, 2017
1 parent 0ce3af0 commit 019fb49
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 46 deletions.
Expand Up @@ -317,7 +317,7 @@ private ComponentDto createForView(Component view) {
ComponentDto res = createBase(view);

res.setScope(Scopes.PROJECT);
res.setQualifier(Qualifiers.VIEW);
res.setQualifier(view.getViewAttributes().getType().getQualifier());
res.setName(view.getName());
res.setDescription(view.getDescription());
res.setLongName(res.name());
Expand Down
Expand Up @@ -37,18 +37,12 @@
public class ViewsComponent implements Component {
private final Type type;
private final String key;
@CheckForNull
private final String uuid;
@CheckForNull
private final String name;
@CheckForNull
private final String description;
private final List<Component> children;
@CheckForNull
private final ProjectViewAttributes projectViewAttributes;
@CheckForNull
private final SubViewAttributes subViewAttributes;
@CheckForNull
private final ViewAttributes viewAttributes;

private ViewsComponent(Type type, String key, @Nullable String uuid, @Nullable String name, @Nullable String description,
Expand Down Expand Up @@ -77,18 +71,12 @@ public static Builder builder(Type type, int key) {
public static final class Builder {
private final Type type;
private final String key;
@CheckForNull
private String uuid;
@CheckForNull
private String name;
@CheckForNull
private String description;
private List<Component> children = new ArrayList<>();
@CheckForNull
private ProjectViewAttributes projectViewAttributes;
@CheckForNull
private SubViewAttributes subViewAttributes;
@CheckForNull
private ViewAttributes viewAttributes;

private Builder(Type type, String key) {
Expand Down
Expand Up @@ -42,6 +42,7 @@
import org.sonar.server.computation.task.projectanalysis.component.ProjectViewAttributes;
import org.sonar.server.computation.task.projectanalysis.component.SubViewAttributes;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
import org.sonar.server.computation.task.projectanalysis.component.ViewAttributes;
import org.sonar.server.computation.task.projectanalysis.component.ViewsComponent;
import org.sonar.server.computation.task.step.ComputationStep;

Expand All @@ -55,6 +56,8 @@
import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.PROJECT_VIEW;
import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.SUBVIEW;
import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.VIEW;
import static org.sonar.server.computation.task.projectanalysis.component.ViewAttributes.Type.APPLICATION;
import static org.sonar.server.computation.task.projectanalysis.component.ViewAttributes.Type.PORTFOLIO;
import static org.sonar.server.computation.task.projectanalysis.component.ViewsComponent.builder;

public class ViewsPersistComponentsStepTest extends BaseStepTest {
Expand Down Expand Up @@ -107,7 +110,7 @@ protected ComputationStep step() {

@Test
public void persist_empty_view() {
treeRootHolder.setRoot(createViewBuilder().build());
treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build());

underTest.execute();

Expand All @@ -122,7 +125,7 @@ public void persist_existing_empty_view() {
// most of the time view already exists since its supposed to be created when config is uploaded
persistComponents(newViewDto(dbTester.organizations().insert()));

treeRootHolder.setRoot(createViewBuilder().build());
treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build());

underTest.execute();

Expand All @@ -137,7 +140,7 @@ public void persist_view_with_projectView() {
persistComponents(project);

treeRootHolder.setRoot(
createViewBuilder()
createViewBuilder(PORTFOLIO)
.addChildren(createProjectView1Builder(project, null).build())
.build());

Expand All @@ -152,10 +155,31 @@ public void persist_view_with_projectView() {
assertDtoIsProjectView1(pv1Dto, viewDto, viewDto, project);
}

@Test
public void persist_application_with_projectView() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert());
persistComponents(project);

treeRootHolder.setRoot(
createViewBuilder(APPLICATION)
.addChildren(createProjectView1Builder(project, null).build())
.build());

underTest.execute();

assertRowsCountInTableProjects(3);

ComponentDto applicationDto = getComponentFromDb(VIEW_KEY);
assertDtoIsApplication(applicationDto);

ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY);
assertDtoIsProjectView1(pv1Dto, applicationDto, applicationDto, project);
}

@Test
public void persist_empty_subview() {
treeRootHolder.setRoot(
createViewBuilder()
createViewBuilder(PORTFOLIO)
.addChildren(
createSubView1Builder(null).build())
.build());
Expand All @@ -174,7 +198,7 @@ public void persist_empty_subview() {
@Test
public void persist_empty_subview_having_original_view_uuid() {
treeRootHolder.setRoot(
createViewBuilder()
createViewBuilder(PORTFOLIO)
.addChildren(
createSubView1Builder("ORIGINAL_UUID").build())
.build());
Expand All @@ -194,7 +218,7 @@ public void persist_existing_empty_subview_under_existing_view() {
persistComponents(ComponentTesting.newSubView(viewDto, SUBVIEW_1_UUID, SUBVIEW_1_KEY).setName(SUBVIEW_1_NAME));

treeRootHolder.setRoot(
createViewBuilder()
createViewBuilder(PORTFOLIO)
.addChildren(
createSubView1Builder(null).build())
.build());
Expand All @@ -212,7 +236,7 @@ public void persist_empty_subview_under_existing_view() {
persistComponents(newViewDto(dbTester.organizations().insert()));

treeRootHolder.setRoot(
createViewBuilder()
createViewBuilder(PORTFOLIO)
.addChildren(
createSubView1Builder(null).build())
.build());
Expand All @@ -231,7 +255,7 @@ public void persist_project_view_under_subview() {
persistComponents(project);

treeRootHolder.setRoot(
createViewBuilder()
createViewBuilder(PORTFOLIO)
.addChildren(
createSubView1Builder(null)
.addChildren(
Expand All @@ -256,7 +280,7 @@ public void update_view_name_and_longName() {
ComponentDto viewDto = newViewDto(dbTester.organizations().insert()).setLongName("another long name").setCreatedAt(now);
persistComponents(viewDto);

treeRootHolder.setRoot(createViewBuilder().build());
treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build());

underTest.execute();

Expand All @@ -283,7 +307,7 @@ public void update_project_view() {
persistComponents(projectView);

treeRootHolder.setRoot(
createViewBuilder()
createViewBuilder(PORTFOLIO)
.addChildren(createProjectView1Builder(project, null).build())
.build());

Expand Down Expand Up @@ -313,7 +337,7 @@ public void update_copy_component_uuid_of_project_view() {
persistComponents(projectView);

treeRootHolder.setRoot(
createViewBuilder()
createViewBuilder(PORTFOLIO)
// Project view in the View is linked to the first project2
.addChildren(createProjectView1Builder(project2, null).build())
.build());
Expand All @@ -337,7 +361,7 @@ public void update_copy_component_uuid_of_sub_view() {
persistComponents(view, subView);

treeRootHolder.setRoot(
createViewBuilder()
createViewBuilder(PORTFOLIO)
.addChildren(
createSubView1Builder("NEW_COPY").build())
.build());
Expand All @@ -356,7 +380,7 @@ public void update_copy_component_uuid_of_sub_view() {
public void persists_new_components_as_public_if_root_does_not_exist_yet_out_of_functional_transaction() {
ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
treeRootHolder.setRoot(
createViewBuilder()
createViewBuilder(PORTFOLIO)
.addChildren(
createSubView1Builder(null)
.addChildren(
Expand All @@ -378,7 +402,7 @@ public void persists_new_components_with_visibility_of_root_in_db_out_of_functio
ComponentDto view = newViewDto(organization).setUuid(VIEW_UUID).setKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate);
dbTester.components().insertComponent(view);
treeRootHolder.setRoot(
createViewBuilder()
createViewBuilder(PORTFOLIO)
.addChildren(
createSubView1Builder(null)
.addChildren(
Expand All @@ -405,7 +429,7 @@ public void persists_existing_components_with_visibility_of_root_in_db_out_of_fu
dbTester.components().insertComponent(subView);
dbTester.components().insertComponent(newProjectCopy("DEFG", project, view).setKey("DIR").setPrivate(isRootPrivate));
treeRootHolder.setRoot(
createViewBuilder()
createViewBuilder(PORTFOLIO)
.addChildren(
createSubView1Builder(null)
.addChildren(
Expand All @@ -421,11 +445,12 @@ public void persists_existing_components_with_visibility_of_root_in_db_out_of_fu
.isEqualTo(isRootPrivate));
}

private static ViewsComponent.Builder createViewBuilder() {
private static ViewsComponent.Builder createViewBuilder(ViewAttributes.Type viewType) {
return builder(VIEW, VIEW_KEY)
.setUuid(VIEW_UUID)
.setName(VIEW_NAME)
.setDescription(VIEW_DESCRIPTION);
.setDescription(VIEW_DESCRIPTION)
.setViewAttributes(new ViewAttributes(viewType));
}

private ViewsComponent.Builder createSubView1Builder(@Nullable String originalViewUuid) {
Expand Down Expand Up @@ -473,23 +498,43 @@ private ComponentDto newSubViewDto(ComponentDto rootView) {
}

/**
* Assertions to verify the DTO created from {@link #createViewBuilder()}
* Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()}
*/
private void assertDtoIsView(ComponentDto dto) {
assertThat(dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
assertThat(dto.name()).isEqualTo(VIEW_NAME);
assertThat(dto.longName()).isEqualTo(VIEW_NAME);
assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION);
assertThat(dto.path()).isNull();
assertThat(dto.uuid()).isEqualTo(VIEW_UUID);
assertThat(dto.projectUuid()).isEqualTo(VIEW_UUID);
assertThat(dto.getRootUuid()).isEqualTo(VIEW_UUID);
assertThat(dto.moduleUuid()).isNull();
assertThat(dto.moduleUuidPath()).isEqualTo("." + dto.uuid() + ".");
assertThat(dto.qualifier()).isEqualTo(Qualifiers.VIEW);
assertThat(dto.scope()).isEqualTo(Scopes.PROJECT);
assertThat(dto.getCopyResourceUuid()).isNull();
assertThat(dto.getCreatedAt()).isEqualTo(now);
}

/**
* Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()}
*/
private void assertDtoIsView(ComponentDto projectDto) {
assertThat(projectDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
assertThat(projectDto.name()).isEqualTo(VIEW_NAME);
assertThat(projectDto.longName()).isEqualTo(VIEW_NAME);
assertThat(projectDto.description()).isEqualTo(VIEW_DESCRIPTION);
assertThat(projectDto.path()).isNull();
assertThat(projectDto.uuid()).isEqualTo(VIEW_UUID);
assertThat(projectDto.projectUuid()).isEqualTo(VIEW_UUID);
assertThat(projectDto.getRootUuid()).isEqualTo(VIEW_UUID);
assertThat(projectDto.moduleUuid()).isNull();
assertThat(projectDto.moduleUuidPath()).isEqualTo("." + projectDto.uuid() + ".");
assertThat(projectDto.qualifier()).isEqualTo(Qualifiers.VIEW);
assertThat(projectDto.scope()).isEqualTo(Scopes.PROJECT);
assertThat(projectDto.getCopyResourceUuid()).isNull();
assertThat(projectDto.getCreatedAt()).isEqualTo(now);
private void assertDtoIsApplication(ComponentDto dto) {
assertThat(dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
assertThat(dto.name()).isEqualTo(VIEW_NAME);
assertThat(dto.longName()).isEqualTo(VIEW_NAME);
assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION);
assertThat(dto.path()).isNull();
assertThat(dto.uuid()).isEqualTo(VIEW_UUID);
assertThat(dto.projectUuid()).isEqualTo(VIEW_UUID);
assertThat(dto.getRootUuid()).isEqualTo(VIEW_UUID);
assertThat(dto.moduleUuid()).isNull();
assertThat(dto.moduleUuidPath()).isEqualTo("." + dto.uuid() + ".");
assertThat(dto.qualifier()).isEqualTo(Qualifiers.APP);
assertThat(dto.scope()).isEqualTo(Scopes.PROJECT);
assertThat(dto.getCopyResourceUuid()).isNull();
assertThat(dto.getCreatedAt()).isEqualTo(now);
}

/**
Expand Down

0 comments on commit 019fb49

Please sign in to comment.