Skip to content

Commit 0910de8

Browse files
authored
max limit of root network is four (#814)
* max limit of root network is four --------- Signed-off-by: SOUISSI Maissa (Externe) <[email protected]>
1 parent 97311f5 commit 0910de8

File tree

4 files changed

+391
-9
lines changed

4 files changed

+391
-9
lines changed

src/main/java/org/gridsuite/study/server/service/RootNetworkService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class RootNetworkService {
5353
private final NetworkStoreService networkStoreService;
5454

5555
@Value("${study.max-root-network-by-study}")
56-
private int maximumRootNetworkByStudy = 3;
56+
private int maximumRootNetworkByStudy = 4;
5757

5858
public RootNetworkService(RootNetworkRepository rootNetworkRepository,
5959
RootNetworkRequestRepository rootNetworkRequestRepository,

src/main/resources/config/application.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,4 @@ gridsuite:
223223
base-uri: http://study-config-server/
224224

225225
study:
226-
max-root-network-by-study: 3
226+
max-root-network-by-study: 4

src/test/java/org/gridsuite/study/server/rootnetworks/RootNetworkTest.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.springframework.messaging.Message;
4848
import org.springframework.messaging.support.GenericMessage;
4949
import org.springframework.test.web.servlet.MockMvc;
50+
import org.springframework.test.web.servlet.MvcResult;
5051

5152
import java.util.*;
5253
import java.util.function.Consumer;
@@ -59,6 +60,7 @@
5960
import static org.springframework.http.MediaType.APPLICATION_JSON;
6061
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
6162
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
63+
import static org.gridsuite.study.server.StudyException.Type.MAXIMUM_ROOT_NETWORK_BY_STUDY_REACHED;
6264

6365
@AutoConfigureMockMvc
6466
@SpringBootTest
@@ -266,23 +268,28 @@ void testCreateRootNetworkWithMaximumReached() throws Exception {
266268
// create study with first root network
267269
StudyEntity studyEntity = TestUtils.createDummyStudy(NETWORK_UUID, CASE_UUID, CASE_NAME, CASE_FORMAT, REPORT_UUID);
268270
// create another dummy root networks for the same entity
269-
createDummyRootNetwork(studyEntity, "dummyRootNetwork");
271+
createDummyRootNetwork(studyEntity, "secondRootNetwork");
272+
createDummyRootNetwork(studyEntity, "thirdRootNetwork");
270273

271274
studyRepository.save(studyEntity);
272275

273276
// insert a creation request for the same study entity
274-
rootNetworkService.insertCreationRequest(UUID.randomUUID(), studyEntity.getId(), "rootNetworkName", "rn1", USER_ID);
277+
rootNetworkService.insertCreationRequest(UUID.randomUUID(), studyEntity.getId(), "rootNetworkName4", "rn4", USER_ID);
275278

276279
// request execution - fails since there is already too many root networks + root network creation requests for this study
277280
UUID caseUuid = UUID.randomUUID();
278281
String caseFormat = "newCaseFormat";
279-
mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks?caseUuid={caseUuid}&caseFormat={caseFormat}&name={rootNetworkName}&tag={rootNetworkTag}", studyEntity.getId(), caseUuid, caseFormat, "rootNetworkName", "rn1")
280-
.header("userId", USER_ID)
281-
.header("content-type", "application/json"))
282-
.andExpect(status().isForbidden());
282+
MvcResult result = mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks?caseUuid={caseUuid}&caseFormat={caseFormat}&name={rootNetworkName}&tag={rootNetworkTag}", studyEntity.getId(), caseUuid, caseFormat, "rootNetworkName5", "rn5")
283+
.header("userId", USER_ID)
284+
.header("content-type", "application/json"))
285+
.andExpect(status().isForbidden())
286+
.andReturn();
287+
288+
assertTrue(result.getResponse().getContentAsString().equalsIgnoreCase(MAXIMUM_ROOT_NETWORK_BY_STUDY_REACHED.name()
289+
));
283290

284291
assertEquals(1, rootNetworkRequestRepository.countAllByStudyUuid(studyEntity.getId()));
285-
assertEquals(2, rootNetworkRepository.countAllByStudyId(studyEntity.getId()));
292+
assertEquals(3, rootNetworkRepository.countAllByStudyId(studyEntity.getId()));
286293
}
287294

288295
@Test

0 commit comments

Comments
 (0)