-
Notifications
You must be signed in to change notification settings - Fork 45
/
ProjectTemplateControllerIntegrationTests.java
159 lines (134 loc) · 7.09 KB
/
ProjectTemplateControllerIntegrationTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*******************************************************************************
* 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.controllers;
import static org.assertj.core.api.Assertions.assertThat;
import com.jayway.jsonpath.JsonPath;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessor;
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry;
import org.eclipse.sirius.components.core.api.IEditingContextSearchService;
import org.eclipse.sirius.components.emf.services.api.IEMFEditingContext;
import org.eclipse.sirius.web.AbstractIntegrationTests;
import org.eclipse.sirius.web.application.project.dto.CreateProjectFromTemplateInput;
import org.eclipse.sirius.web.application.project.dto.CreateProjectFromTemplateSuccessPayload;
import org.eclipse.sirius.web.application.studio.services.StudioProjectTemplateProvider;
import org.eclipse.sirius.web.services.api.IGraphQLRequestor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
import org.springframework.test.context.transaction.TestTransaction;
import org.springframework.transaction.annotation.Transactional;
/**
* Integration tests of the project templates controllers.
*
* @author sbegaudeau
*/
@Transactional
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "sirius.web.enabled=*" })
public class ProjectTemplateControllerIntegrationTests extends AbstractIntegrationTests {
private static final String GET_PROJECT_TEMPLATES_QUERY = """
query getProjectTemplates($page: Int!, $limit: Int!) {
viewer {
projectTemplates(page: $page, limit: $limit) {
edges {
node {
id
label
imageURL
}
}
pageInfo {
hasPreviousPage
hasNextPage
startCursor
endCursor
count
}
}
}
}
""";
private static final String CREATE_PROJECT_FROM_TEMPLATE_MUTATION = """
mutation createProjectFromTemplate($input: CreateProjectFromTemplateInput!) {
createProjectFromTemplate(input: $input) {
__typename
... on CreateProjectFromTemplateSuccessPayload {
project {
id
}
representationToOpen {
id
}
}
}
}
""";
@Autowired
private IGraphQLRequestor graphQLRequestor;
@Autowired
private IEditingContextSearchService editingContextSearchService;
@Autowired
private IEditingContextEventProcessorRegistry editingContextEventProcessorRegistry;
@BeforeEach
public void beforeEach() {
this.editingContextEventProcessorRegistry.getEditingContextEventProcessors().stream()
.map(IEditingContextEventProcessor::getEditingContextId)
.forEach(this.editingContextEventProcessorRegistry::disposeEditingContextEventProcessor);
}
@Test
@DisplayName("Given a set of project templates, when a query is performed, then the project templates are returned")
@Sql(scripts = {"/scripts/initialize.sql"}, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = {"/scripts/cleanup.sql"}, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void givenSetOfProjectTemplatesWhenQueryIsPerformedThenTheProjectTemplatesAreReturned() {
Map<String, Object> variables = Map.of("page", 0, "limit", 2);
var result = this.graphQLRequestor.execute(GET_PROJECT_TEMPLATES_QUERY, variables);
boolean hasPreviousPage = JsonPath.read(result, "$.data.viewer.projectTemplates.pageInfo.hasPreviousPage");
assertThat(hasPreviousPage).isFalse();
boolean hasNextPage = JsonPath.read(result, "$.data.viewer.projectTemplates.pageInfo.hasNextPage");
assertThat(hasNextPage).isFalse();
String startCursor = JsonPath.read(result, "$.data.viewer.projectTemplates.pageInfo.startCursor");
assertThat(startCursor).isNotBlank();
String endCursor = JsonPath.read(result, "$.data.viewer.projectTemplates.pageInfo.endCursor");
assertThat(endCursor).isNotBlank();
int count = JsonPath.read(result, "$.data.viewer.projectTemplates.pageInfo.count");
assertThat(count).isGreaterThan(0);
List<String> projectTemplateIds = JsonPath.read(result, "$.data.viewer.projectTemplates.edges[*].node.id");
assertThat(projectTemplateIds).hasSizeGreaterThan(0);
}
@Test
@DisplayName("Given a project to create from a template, when the mutation is performed, then the project is created")
@Sql(scripts = {"/scripts/initialize.sql"}, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = {"/scripts/cleanup.sql"}, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void givenProjectToCreateFromTemplateWhenMutationIsPerformedThenTheProjectIsCreated() {
TestTransaction.flagForCommit();
TestTransaction.end();
var input = new CreateProjectFromTemplateInput(UUID.randomUUID(), StudioProjectTemplateProvider.STUDIO_TEMPLATE_ID);
var result = this.graphQLRequestor.execute(CREATE_PROJECT_FROM_TEMPLATE_MUTATION, input);
String typename = JsonPath.read(result, "$.data.createProjectFromTemplate.__typename");
assertThat(typename).isEqualTo(CreateProjectFromTemplateSuccessPayload.class.getSimpleName());
String projectId = JsonPath.read(result, "$.data.createProjectFromTemplate.project.id");
assertThat(projectId).isNotBlank();
var optionalEditingContext = this.editingContextSearchService.findById(projectId);
assertThat(optionalEditingContext).isPresent();
var editingContext = optionalEditingContext.get();
assertThat(editingContext).isInstanceOf(IEMFEditingContext.class);
var emfEditingContext = (IEMFEditingContext) editingContext;
assertThat(emfEditingContext.getDomain().getResourceSet().getResources()).hasSize(3);
}
}