Skip to content

Commit 433f5cd

Browse files
AdminService tests
1 parent 983760e commit 433f5cd

6 files changed

Lines changed: 496 additions & 682 deletions

File tree

sdm/src/main/java/com/sap/cds/sdm/configuration/Registration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ public void eventHandlers(CdsRuntimeConfigurer configurer) {
7171
persistenceService, sdmService, tokenHandlerInstance, dbQueryInstance));
7272
configurer.eventHandler(
7373
new SDMAttachmentsServiceHandler(
74-
persistenceService, sdmService, documentService, tokenHandlerInstance));
74+
persistenceService,
75+
sdmService,
76+
documentService,
77+
tokenHandlerInstance,
78+
dbQueryInstance));
7579
}
7680

7781
private AttachmentService buildAttachmentService() {

sdm/src/main/java/com/sap/cds/sdm/handler/TokenHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,11 @@ public static String toString(byte[] bytes) {
7070
private static final String CLIENT_ID = "clientid";
7171
private static final String CLIENT_SECRET = "clientsecret";
7272
private static TokenHandler tokenHandlerInstance = new TokenHandler();
73-
private static int i = 0;
7473

7574
public static TokenHandler getTokenHandlerInstance() {
7675
if (tokenHandlerInstance == null) {
7776
tokenHandlerInstance = new TokenHandler();
78-
i++;
7977
}
80-
System.out.println("Number of objects created for token handler: " + i);
8178
return tokenHandlerInstance;
8279
}
8380

sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
public class DBQuery {
1717

1818
private static DBQuery dbQueryInstance = new DBQuery();
19-
private static int i = 0;
2019

2120
private DBQuery() {
2221
// Doesn't do anything
@@ -25,9 +24,7 @@ private DBQuery() {
2524
public static DBQuery getDBQueryInstance() {
2625
if (dbQueryInstance == null) {
2726
dbQueryInstance = new DBQuery();
28-
i++;
2927
}
30-
System.out.println("Number of objects created for db query: " + i);
3128
return dbQueryInstance;
3229
}
3330

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.sap.cds.sdm.service.handler;
22

3-
import static com.sap.cds.sdm.persistence.DBQuery.*;
4-
53
import com.sap.cds.Result;
64
import com.sap.cds.feature.attachments.generated.cds4j.sap.attachments.MediaData;
75
import com.sap.cds.feature.attachments.service.AttachmentService;
@@ -41,16 +39,19 @@ public class SDMAttachmentsServiceHandler implements EventHandler {
4139
private final DocumentUploadService documentService;
4240
private static final Logger logger = LoggerFactory.getLogger(SDMAttachmentsServiceHandler.class);
4341
private final TokenHandler tokenHandler;
42+
private final DBQuery dbQuery;
4443

4544
public SDMAttachmentsServiceHandler(
4645
PersistenceService persistenceService,
4746
SDMService sdmService,
4847
DocumentUploadService documentService,
49-
TokenHandler tokenHandler) {
48+
TokenHandler tokenHandler,
49+
DBQuery dbQuery) {
5050
this.persistenceService = persistenceService;
5151
this.sdmService = sdmService;
5252
this.documentService = documentService;
5353
this.tokenHandler = tokenHandler;
54+
this.dbQuery = dbQuery;
5455
}
5556

5657
@On(event = AttachmentService.EVENT_CREATE_ATTACHMENT)
@@ -77,8 +78,7 @@ public void markAttachmentAsDeleted(AttachmentMarkAsDeletedEventContext context)
7778
String subdomain = contextValues[3];
7879
// check if only attachment exists against the folderId
7980
List<CmisDocument> cmisDocuments =
80-
DBQuery.getDBQueryInstance()
81-
.getAttachmentsForFolder(entity, persistenceService, folderId, context);
81+
dbQuery.getAttachmentsForFolder(entity, persistenceService, folderId, context);
8282
if (cmisDocuments.isEmpty()) {
8383
// deleteFolder API
8484
sdmService.deleteDocument("deleteTree", folderId, userEmail, subdomain);
@@ -165,8 +165,7 @@ private void processEntities(AttachmentCreateEventContext eventContext)
165165
String upID = (String) attachmentIds.get(upIdKey);
166166

167167
Result result =
168-
DBQuery.getDBQueryInstance()
169-
.getAttachmentsForUPID(attachmentDraftEntity, persistenceService, upID, upIdKey);
168+
dbQuery.getAttachmentsForUPID(attachmentDraftEntity, persistenceService, upID, upIdKey);
170169
checkAttachmentConstraints(eventContext, attachmentDraftEntity, upID, upIdKey);
171170

172171
MediaData data = eventContext.getData();
@@ -204,9 +203,8 @@ private void checkAttachmentConstraints(
204203
throws ServiceException {
205204
// Fetch the row count for current repository
206205
Result result =
207-
DBQuery.getDBQueryInstance()
208-
.getAttachmentsForUPIDAndRepository(
209-
attachmentDraftEntity, persistenceService, upID, upIdKey);
206+
dbQuery.getAttachmentsForUPIDAndRepository(
207+
attachmentDraftEntity, persistenceService, upID, upIdKey);
210208
long rowCount = result.rowCount();
211209
String errorMessageCount =
212210
SDMUtils.getAttachmentCountAndMessage(
@@ -305,9 +303,8 @@ private void handleCreateDocumentResult(
305303
throw new ServiceException(SDMConstants.USER_NOT_AUTHORISED_ERROR);
306304
default:
307305
cmisDocument.setObjectId(createResult.get("objectId").toString());
308-
DBQuery.getDBQueryInstance()
309-
.addAttachmentToDraft(
310-
getAttachmentDraftEntity(eventContext), persistenceService, cmisDocument);
306+
dbQuery.addAttachmentToDraft(
307+
getAttachmentDraftEntity(eventContext), persistenceService, cmisDocument);
311308
finalizeContext(eventContext, cmisDocument);
312309
}
313310
}

0 commit comments

Comments
 (0)