Skip to content

Commit

Permalink
[test] Add some tests for the new architecture
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
  • Loading branch information
sbegaudeau committed Feb 20, 2024
1 parent b6c5bee commit 19b5f53
Show file tree
Hide file tree
Showing 40 changed files with 1,409 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
- [ADR-134] Split IObjectService in multiples sub services
- [ADR-135] Add support for representations in object related services

=== Deprecation warning

- The type `Viewer` may stop being an interface since it does bring some additional complexity without real benefits.
- The field `ChangeKind.PROJECT_RENAMING` will be deleted since it does not mak any sense in Sirius Components.
- The type `RenameProjectSuccessPayload` and `DeletedProjectSuccessPayload` will be replaced by `SuccessPayload`.

=== Breaking changes

- https://github.com/eclipse-sirius/sirius-web/issues/3010[#3010] [forms] Reference widget has been updated.
Expand Down
25 changes: 25 additions & 0 deletions packages/releng/backend/sirius-components-test-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,31 @@
<artifactId>sirius-web-sample-application</artifactId>
<version>2024.1.4</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-web-domain</artifactId>
<version>2024.1.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-web-application</artifactId>
<version>2024.1.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-web-infrastructure</artifactId>
<version>2024.1.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-web-starter</artifactId>
<version>2024.1.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.sirius</groupId>
<artifactId>sirius-web</artifactId>
<version>2024.1.3</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
@MutationDataFetcher(type = "Mutation", field = "createProject")
public class MutationCreateProjectDataFetcher implements IDataFetcherWithFieldCoordinates<IPayload> {

public static final String CREATE_PROJECT_FIELD = "createProject";

private static final String INPUT_ARGUMENT = "input";

private final ObjectMapper objectMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.project.controllers;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Objects;

import org.eclipse.sirius.components.annotations.spring.graphql.MutationDataFetcher;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.web.application.project.dto.DeleteProjectInput;
import org.eclipse.sirius.web.application.project.services.api.IProjectApplicationService;

import graphql.schema.DataFetchingEnvironment;

/**
* Data fetcher for the field Mutation#deleteProject.
*
* @author sbegaudeau
*/
@MutationDataFetcher(type = "Mutation", field = "deleteProject")
public class MutationDeleteProjectDataFetcher implements IDataFetcherWithFieldCoordinates<IPayload> {

private static final String INPUT_ARGUMENT = "input";

private final ObjectMapper objectMapper;

private final IProjectApplicationService projectApplicationService;

public MutationDeleteProjectDataFetcher(ObjectMapper objectMapper, IProjectApplicationService projectApplicationService) {
this.objectMapper = Objects.requireNonNull(objectMapper);
this.projectApplicationService = Objects.requireNonNull(projectApplicationService);
}

@Override
public IPayload get(DataFetchingEnvironment environment) throws Exception {
Object argument = environment.getArgument(INPUT_ARGUMENT);
var input = this.objectMapper.convertValue(argument, DeleteProjectInput.class);
return this.projectApplicationService.deleteProject(input);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.project.controllers;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Objects;

import org.eclipse.sirius.components.annotations.spring.graphql.MutationDataFetcher;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.web.application.project.dto.RenameProjectInput;
import org.eclipse.sirius.web.application.project.services.api.IProjectApplicationService;

import graphql.schema.DataFetchingEnvironment;

/**
* Data fetcher for the field Mutation#renameProject.
*
* @author sbegaudeau
*/
@MutationDataFetcher(type = "Mutation", field = "renameProject")
public class MutationRenameProjectDataFetcher implements IDataFetcherWithFieldCoordinates<IPayload> {

private static final String INPUT_ARGUMENT = "input";

private final ObjectMapper objectMapper;

private final IProjectApplicationService projectApplicationService;

public MutationRenameProjectDataFetcher(ObjectMapper objectMapper, IProjectApplicationService projectApplicationService) {
this.objectMapper = Objects.requireNonNull(objectMapper);
this.projectApplicationService = Objects.requireNonNull(projectApplicationService);
}

@Override
public IPayload get(DataFetchingEnvironment environment) throws Exception {
Object argument = environment.getArgument(INPUT_ARGUMENT);
var input = this.objectMapper.convertValue(argument, RenameProjectInput.class);
return this.projectApplicationService.renameProject(input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author sbegaudeau
*/
@QueryDataFetcher(type = "Viewer", field = "project")
@QueryDataFetcher(type = "DefaultViewer", field = "project")
public class ViewerProjectDataFetcher implements IDataFetcherWithFieldCoordinates<ProjectDTO> {

private static final String PROJECT_ID_ARGUMENT = "projectId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*
* @author sbegaudeau
*/
@QueryDataFetcher(type = "Viewer", field = "project")
@QueryDataFetcher(type = "DefaultViewer", field = "projects")
public class ViewerProjectsDataFetcher implements IDataFetcherWithFieldCoordinates<Connection<ProjectDTO>> {

private static final String PAGE_ARGUMENT = "page";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.project.dto;

import java.util.UUID;

import org.eclipse.sirius.components.core.api.IInput;

import jakarta.validation.constraints.NotNull;

/**
* The input of the delete project mutation.
*
* @author sbegaudeau
*/
public record DeleteProjectInput(@NotNull UUID id, @NotNull UUID projectId) implements IInput {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.project.dto;

import java.util.Objects;
import java.util.UUID;

import org.eclipse.sirius.components.core.api.IPayload;

import jakarta.validation.constraints.NotNull;

/**
* Payload sent when a project is deleted.
*
* @author sbegaudeau
*/
public record DeleteProjectSuccessPayload(@NotNull UUID id) implements IPayload {
public DeleteProjectSuccessPayload {
Objects.requireNonNull(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.project.dto;

import java.util.UUID;

import org.eclipse.sirius.components.core.api.IInput;

import jakarta.validation.constraints.NotNull;

/**
* The input used to rename a project.
*
* @author sbegaudeau
*/
public record RenameProjectInput(
@NotNull UUID id,
@NotNull UUID projectId,
@NotNull String newName) implements IInput {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.project.dto;

import java.util.UUID;

import org.eclipse.sirius.components.core.api.IPayload;

import jakarta.validation.constraints.NotNull;

/**
* Used to indicate that a project has been successfully renamed.
*
* @author sbegaudeau
*/
public record RenameProjectSuccessPayload(@NotNull UUID id) implements IPayload {
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.web.application.project.dto.CreateProjectInput;
import org.eclipse.sirius.web.application.project.dto.CreateProjectSuccessPayload;
import org.eclipse.sirius.web.application.project.dto.DeleteProjectInput;
import org.eclipse.sirius.web.application.project.dto.DeleteProjectSuccessPayload;
import org.eclipse.sirius.web.application.project.dto.ProjectDTO;
import org.eclipse.sirius.web.application.project.dto.RenameProjectInput;
import org.eclipse.sirius.web.application.project.dto.RenameProjectSuccessPayload;
import org.eclipse.sirius.web.application.project.services.api.IProjectApplicationService;
import org.eclipse.sirius.web.application.project.services.api.IProjectMapper;
import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
import org.eclipse.sirius.web.domain.boundedcontexts.project.services.api.IProjectCreationService;
import org.eclipse.sirius.web.domain.boundedcontexts.project.services.api.IProjectDeletionService;
import org.eclipse.sirius.web.domain.boundedcontexts.project.services.api.IProjectSearchService;
import org.eclipse.sirius.web.domain.boundedcontexts.project.services.api.IProjectUpdateService;
import org.eclipse.sirius.web.domain.services.Failure;
import org.eclipse.sirius.web.domain.services.Success;
import org.springframework.data.domain.Page;
Expand All @@ -44,11 +50,17 @@ public class ProjectApplicationService implements IProjectApplicationService {

private final IProjectCreationService projectCreationService;

private final IProjectUpdateService projectUpdateService;

private final IProjectDeletionService projectDeletionService;

private final IProjectMapper projectMapper;

public ProjectApplicationService(IProjectSearchService projectSearchService, IProjectCreationService projectCreationService, IProjectMapper projectMapper) {
public ProjectApplicationService(IProjectSearchService projectSearchService, IProjectCreationService projectCreationService, IProjectUpdateService projectUpdateService, IProjectDeletionService projectDeletionService, IProjectMapper projectMapper) {
this.projectSearchService = Objects.requireNonNull(projectSearchService);
this.projectCreationService = Objects.requireNonNull(projectCreationService);
this.projectUpdateService = Objects.requireNonNull(projectUpdateService);
this.projectDeletionService = Objects.requireNonNull(projectDeletionService);
this.projectMapper = Objects.requireNonNull(projectMapper);
}

Expand Down Expand Up @@ -77,4 +89,32 @@ public IPayload createProject(CreateProjectInput input) {
}
return payload;
}

@Override
@Transactional
public IPayload renameProject(RenameProjectInput input) {
var result = this.projectUpdateService.renameProject(input.projectId(), input.newName());

IPayload payload = null;
if (result instanceof Failure<Void> failure) {
payload = new ErrorPayload(input.id(), failure.message());
} else if (result instanceof Success<Void>) {
payload = new RenameProjectSuccessPayload(input.id());
}
return payload;
}

@Override
@Transactional
public IPayload deleteProject(DeleteProjectInput input) {
var result = this.projectDeletionService.deleteProject(input.projectId());

IPayload payload = null;
if (result instanceof Failure<Void> failure) {
payload = new ErrorPayload(input.id(), failure.message());
} else if (result instanceof Success<Void>) {
payload = new DeleteProjectSuccessPayload(input.id());
}
return payload;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.web.application.project.dto.CreateProjectInput;
import org.eclipse.sirius.web.application.project.dto.DeleteProjectInput;
import org.eclipse.sirius.web.application.project.dto.ProjectDTO;
import org.eclipse.sirius.web.application.project.dto.RenameProjectInput;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

Expand All @@ -32,4 +34,8 @@ public interface IProjectApplicationService {
Page<ProjectDTO> findAll(Pageable pageable);

IPayload createProject(CreateProjectInput input);

IPayload renameProject(RenameProjectInput input);

IPayload deleteProject(DeleteProjectInput input);
}

0 comments on commit 19b5f53

Please sign in to comment.