-
Notifications
You must be signed in to change notification settings - Fork 45
/
RepresentationControllerIntegrationTests.java
136 lines (116 loc) · 6.05 KB
/
RepresentationControllerIntegrationTests.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
/*******************************************************************************
* 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 org.eclipse.sirius.web.AbstractIntegrationTests;
import org.eclipse.sirius.web.TestIdentifiers;
import org.eclipse.sirius.web.services.api.IGraphQLRequestor;
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.transaction.annotation.Transactional;
/**
* Integration tests of the representation controllers.
*
* @author sbegaudeau
*/
@Transactional
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class RepresentationControllerIntegrationTests extends AbstractIntegrationTests {
private static final String GET_REPRESENTATION_METADATA_QUERY = """
query getRepresentationMetadata($editingContextId: ID!, $representationId: ID!) {
viewer {
editingContext(editingContextId: $editingContextId) {
representation(representationId: $representationId) {
id
kind
label
}
}
}
}
""";
private static final String GET_ALL_REPRESENTATION_METADATA_QUERY = """
query getAllRepresentationMetadata($editingContextId: ID!) {
viewer {
editingContext(editingContextId: $editingContextId) {
representations {
edges {
node {
id
label
kind
}
}
pageInfo {
hasPreviousPage
hasNextPage
startCursor
endCursor
count
}
}
}
}
}
""";
@Autowired
private IGraphQLRequestor graphQLRequestor;
@Test
@DisplayName("Given a representation id, when a query is performed, then the representation metadata 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 givenRepresentationIdWhenQueryIsPerformedThenTheRepresentationMetadataAreReturned() {
Map<String, Object> variables = Map.of(
"editingContextId", TestIdentifiers.ECORE_SAMPLE_PROJECT.toString(),
"representationId", TestIdentifiers.EPACKAGE_PORTAL_REPRESENTATION.toString()
);
var result = this.graphQLRequestor.execute(GET_REPRESENTATION_METADATA_QUERY, variables);
String representationId = JsonPath.read(result, "$.data.viewer.editingContext.representation.id");
assertThat(representationId).isEqualTo(TestIdentifiers.EPACKAGE_PORTAL_REPRESENTATION.toString());
String kind = JsonPath.read(result, "$.data.viewer.editingContext.representation.kind");
assertThat(kind).isEqualTo("siriusComponents://representation?type=Portal");
String label = JsonPath.read(result, "$.data.viewer.editingContext.representation.label");
assertThat(label).isEqualTo("Portal");
}
@Test
@DisplayName("Given an editing context id, when a query is performed, then all the representation metadata 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 givenEditingContextIdWhenQueryIsPerformedThenAllTheRepresentationMetadataAreReturned() {
Map<String, Object> variables = Map.of(
"editingContextId", TestIdentifiers.ECORE_SAMPLE_PROJECT.toString()
);
var result = this.graphQLRequestor.execute(GET_ALL_REPRESENTATION_METADATA_QUERY, variables);
boolean hasPreviousPage = JsonPath.read(result, "$.data.viewer.editingContext.representations.pageInfo.hasPreviousPage");
assertThat(hasPreviousPage).isFalse();
boolean hasNextPage = JsonPath.read(result, "$.data.viewer.editingContext.representations.pageInfo.hasNextPage");
assertThat(hasNextPage).isFalse();
String startCursor = JsonPath.read(result, "$.data.viewer.editingContext.representations.pageInfo.startCursor");
assertThat(startCursor).isNotBlank();
String endCursor = JsonPath.read(result, "$.data.viewer.editingContext.representations.pageInfo.endCursor");
assertThat(endCursor).isNotBlank();
int count = JsonPath.read(result, "$.data.viewer.editingContext.representations.pageInfo.count");
assertThat(count).isEqualTo(1);
List<String> representationIds = JsonPath.read(result, "$.data.viewer.editingContext.representations.edges[*].node.id");
assertThat(representationIds).hasSize(1);
var firstRepresentationId = representationIds.get(0);
assertThat(firstRepresentationId).isEqualTo(TestIdentifiers.EPACKAGE_PORTAL_REPRESENTATION.toString());
}
}