Skip to content

Commit 6685bad

Browse files
committed
DMP-5252-ARM-5-2-Upgrade
Added no sonar to fix sonar complaint of duplicate code
1 parent d07286c commit 6685bad

File tree

4 files changed

+445
-4
lines changed

4 files changed

+445
-4
lines changed

src/integrationTest/java/uk/gov/hmcts/darts/arm/service/ArmRpoReplayServiceIntTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class ArmRpoReplayServiceIntTest extends PostgresIntegrationBase {
3838
@Autowired
3939
private ArmRpoReplayService armRpoReplayService;
4040

41-
4241
@BeforeEach
4342
void setUp() {
4443
UserAccountEntity userAccountEntity = dartsDatabase.getUserAccountStub().getIntegrationTestUserAccountEntity();
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
package uk.gov.hmcts.darts.arm.service.impl;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.test.context.TestPropertySource;
8+
import org.springframework.test.context.bean.override.mockito.MockitoBean;
9+
import uk.gov.hmcts.darts.arm.client.ArmRpoClient;
10+
import uk.gov.hmcts.darts.arm.client.ArmTokenClient;
11+
import uk.gov.hmcts.darts.arm.client.model.ArmTokenRequest;
12+
import uk.gov.hmcts.darts.arm.client.model.ArmTokenResponse;
13+
import uk.gov.hmcts.darts.arm.client.model.AvailableEntitlementProfile;
14+
import uk.gov.hmcts.darts.arm.client.model.rpo.ArmAsyncSearchResponse;
15+
import uk.gov.hmcts.darts.arm.client.model.rpo.EmptyRpoRequest;
16+
import uk.gov.hmcts.darts.arm.client.model.rpo.IndexesByMatterIdResponse;
17+
import uk.gov.hmcts.darts.arm.client.model.rpo.MasterIndexFieldByRecordClassSchemaResponse;
18+
import uk.gov.hmcts.darts.arm.client.model.rpo.ProfileEntitlementResponse;
19+
import uk.gov.hmcts.darts.arm.client.model.rpo.RecordManagementMatterResponse;
20+
import uk.gov.hmcts.darts.arm.client.model.rpo.SaveBackgroundSearchResponse;
21+
import uk.gov.hmcts.darts.arm.client.model.rpo.StorageAccountResponse;
22+
import uk.gov.hmcts.darts.authorisation.component.UserIdentity;
23+
import uk.gov.hmcts.darts.common.entity.ArmRpoExecutionDetailEntity;
24+
import uk.gov.hmcts.darts.common.entity.UserAccountEntity;
25+
import uk.gov.hmcts.darts.testutils.PostgresIntegrationBase;
26+
27+
import java.time.Duration;
28+
import java.time.temporal.ChronoUnit;
29+
import java.util.List;
30+
31+
import static org.junit.jupiter.api.Assertions.assertNotNull;
32+
import static org.mockito.ArgumentMatchers.any;
33+
import static org.mockito.ArgumentMatchers.anyString;
34+
import static org.mockito.Mockito.lenient;
35+
import static org.mockito.Mockito.when;
36+
37+
@TestPropertySource(properties = {
38+
"darts.storage.arm-api.enable-arm-v5-2-upgrade=false"
39+
})
40+
class TriggerArmRpoSearchServiceImplIntTest extends PostgresIntegrationBase {
41+
42+
@MockitoBean
43+
private UserIdentity userIdentity;
44+
@MockitoBean
45+
private ArmRpoClient armRpoClient;
46+
@MockitoBean
47+
private ArmTokenClient armTokenClient;
48+
49+
@Autowired
50+
private TriggerArmRpoSearchServiceImpl triggerArmRpoSearchServiceImpl;
51+
52+
@BeforeEach
53+
void setUp() {
54+
UserAccountEntity userAccountEntity = dartsDatabase.getUserAccountStub().getIntegrationTestUserAccountEntity();
55+
lenient().when(userIdentity.getUserAccount()).thenReturn(userAccountEntity);
56+
57+
ArmTokenRequest armTokenRequest = ArmTokenRequest.builder()
58+
.username("some-username")
59+
.password("some-password")
60+
.build();
61+
ArmTokenResponse armTokenResponse = getArmTokenResponse();
62+
String bearerToken = String.format("Bearer %s", armTokenResponse.getAccessToken());
63+
when(armTokenClient.getToken(armTokenRequest))
64+
.thenReturn(armTokenResponse);
65+
EmptyRpoRequest emptyRpoRequest = EmptyRpoRequest.builder().build();
66+
when(armTokenClient.availableEntitlementProfiles(bearerToken, emptyRpoRequest))
67+
.thenReturn(getAvailableEntitlementProfile());
68+
when(armTokenClient.selectEntitlementProfile(bearerToken, "some-profile-id", emptyRpoRequest))
69+
.thenReturn(armTokenResponse);
70+
}
71+
72+
@Test
73+
void triggerArmRpoSearch_shouldCompleteSuccessfully() {
74+
75+
// given
76+
RecordManagementMatterResponse recordManagementMatterResponse = getRecordManagementMatterResponse();
77+
when(armRpoClient.getRecordManagementMatter(anyString(), any()))
78+
.thenReturn(recordManagementMatterResponse);
79+
when(armRpoClient.getIndexesByMatterId(anyString(), any()))
80+
.thenReturn(getIndexesByMatterIdResponse());
81+
when(armRpoClient.getStorageAccounts(anyString(), any()))
82+
.thenReturn(getStorageAccounts());
83+
when(armRpoClient.getProfileEntitlementResponse(anyString(), any()))
84+
.thenReturn(getProfileEntitlementResponse());
85+
when(armRpoClient.getMasterIndexFieldByRecordClassSchema(anyString(), any()))
86+
.thenReturn(getMasterIndexFieldByRecordClassSchemaResponse("propertyName1", "propertyName2"));
87+
when(armRpoClient.addAsyncSearch(anyString(), any()))
88+
.thenReturn(getAsyncSearchResponse());
89+
when(armRpoClient.saveBackgroundSearch(anyString(), any()))
90+
.thenReturn(getSaveBackgroundSearchResponse());
91+
92+
// when
93+
triggerArmRpoSearchServiceImpl.triggerArmRpoSearch(Duration.of(1, ChronoUnit.SECONDS));
94+
95+
// then
96+
ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity = dartsPersistence.getArmRpoExecutionDetailRepository()
97+
.findLatestByCreatedDateTimeDesc().orElseThrow();
98+
99+
assertNotNull(armRpoExecutionDetailEntity.getId());
100+
101+
}
102+
103+
private SaveBackgroundSearchResponse getSaveBackgroundSearchResponse() {
104+
SaveBackgroundSearchResponse saveBackgroundSearchResponse = new SaveBackgroundSearchResponse();
105+
saveBackgroundSearchResponse.setStatus(200);
106+
saveBackgroundSearchResponse.setIsError(false);
107+
return saveBackgroundSearchResponse;
108+
}
109+
110+
private ArmAsyncSearchResponse getAsyncSearchResponse() {
111+
ArmAsyncSearchResponse response = new ArmAsyncSearchResponse();
112+
response.setStatus(200);
113+
response.setIsError(false);
114+
response.setSearchId("SEARCH_ID");
115+
return response;
116+
}
117+
118+
private @NotNull MasterIndexFieldByRecordClassSchemaResponse getMasterIndexFieldByRecordClassSchemaResponse(String propertyName1,
119+
String propertyName2) {
120+
MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField masterIndexField1 = getMasterIndexField1(propertyName1);
121+
122+
MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField masterIndexField2 = getMasterIndexField2(propertyName2);
123+
124+
MasterIndexFieldByRecordClassSchemaResponse response = new MasterIndexFieldByRecordClassSchemaResponse();
125+
response.setMasterIndexFields(List.of(masterIndexField1, masterIndexField2));
126+
return response;
127+
}
128+
129+
private static MasterIndexFieldByRecordClassSchemaResponse.@NotNull MasterIndexField getMasterIndexField2(String propertyName2) {
130+
MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField masterIndexField2 = new MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField();
131+
masterIndexField2.setMasterIndexFieldId("2");
132+
masterIndexField2.setDisplayName("displayName");
133+
masterIndexField2.setPropertyName(propertyName2);
134+
masterIndexField2.setPropertyType("propertyType");
135+
masterIndexField2.setIsMasked(false);
136+
return masterIndexField2;
137+
}
138+
139+
private static MasterIndexFieldByRecordClassSchemaResponse.@NotNull MasterIndexField getMasterIndexField1(String propertyName1) {
140+
MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField masterIndexField1 = new MasterIndexFieldByRecordClassSchemaResponse.MasterIndexField();
141+
masterIndexField1.setMasterIndexFieldId("1");
142+
masterIndexField1.setDisplayName("displayName");
143+
masterIndexField1.setPropertyName(propertyName1);
144+
masterIndexField1.setPropertyType("propertyType");
145+
masterIndexField1.setIsMasked(true);
146+
return masterIndexField1;
147+
}
148+
149+
private ProfileEntitlementResponse getProfileEntitlementResponse() {
150+
ProfileEntitlementResponse.ProfileEntitlement profileEntitlement = new ProfileEntitlementResponse.ProfileEntitlement();
151+
profileEntitlement.setName("ENTITLEMENT_NAME");
152+
profileEntitlement.setEntitlementId("ENTITLEMENT_ID");
153+
154+
ProfileEntitlementResponse profileEntitlementResponse = new ProfileEntitlementResponse();
155+
profileEntitlementResponse.setStatus(200);
156+
profileEntitlementResponse.setIsError(false);
157+
profileEntitlementResponse.setEntitlements(List.of(profileEntitlement));
158+
return profileEntitlementResponse;
159+
}
160+
161+
private StorageAccountResponse getStorageAccounts() {
162+
StorageAccountResponse.DataDetails dataDetails1 = new StorageAccountResponse.DataDetails();
163+
dataDetails1.setId("indexId1");
164+
dataDetails1.setName("unexpectedAccountName");
165+
166+
StorageAccountResponse.DataDetails dataDetails2 = new StorageAccountResponse.DataDetails();
167+
dataDetails2.setId("indexId2");
168+
dataDetails2.setName("some-account-name");
169+
170+
StorageAccountResponse storageAccountResponse = new StorageAccountResponse();
171+
storageAccountResponse.setStatus(200);
172+
storageAccountResponse.setIsError(false);
173+
storageAccountResponse.setDataDetails(List.of(dataDetails1, dataDetails2));
174+
return storageAccountResponse;
175+
}
176+
177+
private IndexesByMatterIdResponse getIndexesByMatterIdResponse() {
178+
IndexesByMatterIdResponse response = new IndexesByMatterIdResponse();
179+
response.setStatus(200);
180+
response.setIsError(false);
181+
182+
IndexesByMatterIdResponse.Index index = new IndexesByMatterIdResponse.Index();
183+
IndexesByMatterIdResponse.IndexDetails indexDetails = new IndexesByMatterIdResponse.IndexDetails();
184+
indexDetails.setIndexId("indexId");
185+
index.setIndexDetails(indexDetails);
186+
response.setIndexes(List.of(index));
187+
return response;
188+
}
189+
190+
private RecordManagementMatterResponse getRecordManagementMatterResponse() {
191+
RecordManagementMatterResponse response = new RecordManagementMatterResponse();
192+
response.setStatus(200);
193+
response.setIsError(false);
194+
response.setRecordManagementMatter(new RecordManagementMatterResponse.RecordManagementMatter());
195+
response.getRecordManagementMatter().setMatterId("some-matter-id");
196+
return response;
197+
}
198+
199+
private AvailableEntitlementProfile getAvailableEntitlementProfile() {
200+
List<AvailableEntitlementProfile.Profiles> profiles = List.of(AvailableEntitlementProfile.Profiles.builder()
201+
.profileName("some-profile-name")
202+
.profileId("some-profile-id")
203+
.build());
204+
205+
return AvailableEntitlementProfile.builder()
206+
.profiles(profiles)
207+
.isError(false)
208+
.build();
209+
}
210+
211+
private ArmTokenResponse getArmTokenResponse() {
212+
return ArmTokenResponse.builder()
213+
.accessToken("some-token")
214+
.tokenType("Bearer")
215+
.expiresIn("3600")
216+
.build();
217+
}
218+
219+
}

0 commit comments

Comments
 (0)