Skip to content

Commit 658d676

Browse files
committed
spotless & UTs
1 parent 39a38fa commit 658d676

8 files changed

Lines changed: 75 additions & 140 deletions

File tree

sdm/src/main/java/com/sap/cds/sdm/constants/SDMErrorMessages.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ public static String buildErrorMessage(
140140
public static String nameConstraintMessage(List<String> invalidFileNames) {
141141
// if only 1 restricted character is there in file, so different error will throw
142142
if (invalidFileNames.size() == 1) {
143-
return String.format(SDMUtils.getErrorMessage("SINGLE_RESTRICTED_CHARACTER_IN_FILE"), invalidFileNames.iterator().next());
143+
return String.format(
144+
SDMUtils.getErrorMessage("SINGLE_RESTRICTED_CHARACTER_IN_FILE"),
145+
invalidFileNames.iterator().next());
144146
}
145147
StringBuilder prefix = new StringBuilder();
146148
prefix.append(SDMUtils.getErrorMessage("RESTRICTED_CHARACTERS_IN_MULTIPLE_FILES"));

sdm/src/main/java/com/sap/cds/sdm/service/SDMService.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.sap.cds.sdm.model.SDMCredentials;
88
import com.sap.cds.services.ServiceException;
99
import com.sap.cds.services.persistence.PersistenceService;
10-
import com.sap.cds.services.EventContext;
1110
import java.io.IOException;
1211
import java.util.List;
1312
import java.util.Map;
@@ -30,12 +29,9 @@ public String getFolderIdByPath(
3029
String parentId, String repositoryId, SDMCredentials sdmCredentials, boolean isSystemUser)
3130
throws IOException;
3231

33-
public RepoValue checkRepositoryType(
34-
String repositoryId, String tenant)
35-
throws IOException;
32+
public RepoValue checkRepositoryType(String repositoryId, String tenant) throws IOException;
3633

37-
public JSONObject getRepositoryInfo(
38-
SDMCredentials sdmCredentials) throws IOException;
34+
public JSONObject getRepositoryInfo(SDMCredentials sdmCredentials) throws IOException;
3935

4036
public int deleteDocument(String cmisaction, String objectId, String user) throws IOException;
4137

sdm/src/main/java/com/sap/cds/sdm/service/SDMServiceImpl.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.sap.cds.services.environment.CdsProperties;
2020
import com.sap.cds.services.persistence.PersistenceService;
2121
import com.sap.cloud.environment.servicebinding.api.ServiceBinding;
22-
import com.sap.cds.services.EventContext;
2322
import java.io.ByteArrayInputStream;
2423
import java.io.IOException;
2524
import java.io.InputStream;
@@ -549,8 +548,7 @@ else if (responseCode == 403) {
549548
}
550549

551550
@Override
552-
public RepoValue checkRepositoryType(
553-
String repositoryId, String tenant) {
551+
public RepoValue checkRepositoryType(String repositoryId, String tenant) {
554552
RepoKey repoKey = new RepoKey();
555553
repoKey.setSubdomain(tenant);
556554
repoKey.setRepoId(repositoryId);
@@ -570,8 +568,7 @@ public RepoValue checkRepositoryType(
570568
}
571569

572570
@Override
573-
public JSONObject getRepositoryInfo(
574-
SDMCredentials sdmCredentials) {
571+
public JSONObject getRepositoryInfo(SDMCredentials sdmCredentials) {
575572
String repositoryId = SDMConstants.REPOSITORY_ID;
576573
var httpClient = tokenHandler.getHttpClient(binding, connectionPool, null, TECHNICAL_USER_FLOW);
577574

sdm/src/main/java/com/sap/cds/sdm/service/handler/SDMAttachmentsServiceHandler.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ private void validateRepository(AttachmentCreateEventContext eventContext)
144144
throws ServiceException, IOException {
145145
String repositoryId = SDMConstants.REPOSITORY_ID;
146146
RepoValue repoValue =
147-
sdmService.checkRepositoryType(
148-
repositoryId, eventContext.getUserInfo().getTenant());
147+
sdmService.checkRepositoryType(repositoryId, eventContext.getUserInfo().getTenant());
149148
if (repoValue.getVersionEnabled()) {
150149
throw new ServiceException(SDMUtils.getErrorMessage("VERSIONED_REPO_ERROR"));
151150
}
@@ -204,10 +203,7 @@ private void checkAttachmentConstraints(
204203
}
205204
}
206205

207-
private void validateFileName(
208-
String filename,
209-
Result result,
210-
Map<String, Object> attachmentIds)
206+
private void validateFileName(String filename, Result result, Map<String, Object> attachmentIds)
211207
throws ServiceException {
212208
if (filename == null || filename.isBlank()) {
213209
throw new ServiceException(SDMUtils.getErrorMessage("FILENAME_WHITESPACE_ERROR_MESSAGE"));

sdm/src/main/java/com/sap/cds/sdm/service/handler/SDMServiceGenericHandler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,7 @@ public void openAttachment(AttachmentReadContext context) throws Exception {
373373
private void validateRepository(EventContext eventContext) throws ServiceException, IOException {
374374
String repositoryId = SDMConstants.REPOSITORY_ID;
375375
RepoValue repoValue =
376-
sdmService.checkRepositoryType(
377-
repositoryId, eventContext.getUserInfo().getTenant());
376+
sdmService.checkRepositoryType(repositoryId, eventContext.getUserInfo().getTenant());
378377
if (repoValue.getVersionEnabled()) {
379378
throw new ServiceException(SDMUtils.getErrorMessage("VERSIONED_REPO_ERROR"));
380379
}
@@ -508,8 +507,7 @@ private void checkAttachmentConstraints(
508507
}
509508
}
510509

511-
private void validateLinkName(String filename, Result result)
512-
throws ServiceException {
510+
private void validateLinkName(String filename, Result result) throws ServiceException {
513511
if (filename == null || filename.isBlank()) {
514512
throw new ServiceException(SDMUtils.getErrorMessage("FILENAME_WHITESPACE_ERROR_MESSAGE"));
515513
}

sdm/src/test/java/unit/com/sap/cds/sdm/service/SDMServiceImplTest.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void testGetRepositoryInfo() throws IOException {
119119
when(mockParameterInfo.getLocale()).thenReturn(java.util.Locale.ENGLISH);
120120
com.sap.cds.sdm.service.SDMService sdmService =
121121
new SDMServiceImpl(binding, connectionPool, tokenHandler);
122-
JSONObject json = sdmService.getRepositoryInfo(sdmCredentials, mockEventContext);
122+
JSONObject json = sdmService.getRepositoryInfo(sdmCredentials);
123123

124124
JSONObject fetchedRepoInfo = json.getJSONObject(REPO_ID);
125125
JSONObject fetchedCapabilities = fetchedRepoInfo.getJSONObject("capabilities");
@@ -155,7 +155,7 @@ public void testGetRepositoryInfoFail() throws IOException {
155155
when(mockEventContext.getCdsRuntime()).thenReturn(mockCdsRuntime);
156156
when(mockCdsRuntime.getLocalizedMessage(anyString(), any(), any()))
157157
.thenReturn(SDMErrorMessages.REPOSITORY_ERROR);
158-
sdmService.getRepositoryInfo(sdmCredentials, mockEventContext);
158+
sdmService.getRepositoryInfo(sdmCredentials);
159159
});
160160
assertEquals("Failed to get repository info.", exception.getMessage());
161161
}
@@ -188,8 +188,7 @@ public void testGetRepositoryInfoThrowsServiceExceptionOnHttpClientError() throw
188188
.thenReturn("REPOSITORY_ERROR");
189189
ServiceException exception =
190190
assertThrows(
191-
ServiceException.class,
192-
() -> sdmServiceImpl.getRepositoryInfo(mockSdmCredentials, mockEventContext));
191+
ServiceException.class, () -> sdmServiceImpl.getRepositoryInfo(mockSdmCredentials));
193192

194193
assertEquals("Failed to get repository info.", exception.getMessage());
195194
}
@@ -245,9 +244,7 @@ public void testCheckRepositoryTypeNoCacheVersioned() throws IOException {
245244
InputStream inputStream = new ByteArrayInputStream(mockRepoData.toString().getBytes());
246245
when(entity.getContent()).thenReturn(inputStream);
247246

248-
RepoValue repoValue =
249-
spySDMService.checkRepositoryType(
250-
repositoryId, tenant, mock(com.sap.cds.services.EventContext.class));
247+
RepoValue repoValue = spySDMService.checkRepositoryType(repositoryId, tenant);
251248
assertEquals(true, repoValue.getVersionEnabled());
252249
assertEquals(false, repoValue.getVirusScanEnabled());
253250
}
@@ -307,9 +304,7 @@ public void testCheckRepositoryTypeNoCacheNonVersioned() throws IOException {
307304
InputStream inputStream = new ByteArrayInputStream(mockRepoData.toString().getBytes());
308305
when(entity.getContent()).thenReturn(inputStream);
309306

310-
RepoValue repoValue =
311-
spySDMService.checkRepositoryType(
312-
repositoryId, tenant, mock(com.sap.cds.services.EventContext.class));
307+
RepoValue repoValue = spySDMService.checkRepositoryType(repositoryId, tenant);
313308
assertEquals(false, repoValue.getVersionEnabled());
314309
assertEquals(false, repoValue.getVirusScanEnabled());
315310
}
@@ -333,9 +328,7 @@ public void testCheckRepositoryTypeCacheNonVersioned() throws IOException {
333328
repoValue.setDisableVirusScannerForLargeFile(false);
334329
Mockito.when(mockCache.get(repoKey)).thenReturn(repoValue);
335330
cacheConfigMockedStatic.when(CacheConfig::getRepoCache).thenReturn(mockCache);
336-
repoValue =
337-
spySDMService.checkRepositoryType(
338-
repositoryId, tenant, mock(com.sap.cds.services.EventContext.class));
331+
repoValue = spySDMService.checkRepositoryType(repositoryId, tenant);
339332
assertEquals(false, repoValue.getVersionEnabled());
340333
assertEquals(false, repoValue.getVirusScanEnabled());
341334
assertEquals(false, repoValue.getDisableVirusScannerForLargeFile());

0 commit comments

Comments
 (0)