Skip to content

Commit 42d5000

Browse files
committed
- split ILLEGAL_PARAMETER to ILLEGAL_MESSAGE_NAME_LENGTH & ILLEGAL_MESSAGE_CONTENT_LENGTH
1 parent 5431c85 commit 42d5000

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

sampling-message-proto/src/main/proto/service.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ enum StatusCode {
8686
SUCCESS = 1;
8787
CONFLICT = 2;
8888
NOT_FOUND = 3;
89-
ILLEGAL_PARAMETER = 4;
90-
MESSAGE_COUNT_EXCEEDED = 5;
89+
ILLEGAL_MESSAGE_NAME_LENGTH = 4;
90+
ILLEGAL_MESSAGE_CONTENT_LENGTH = 5;
91+
MESSAGE_COUNT_EXCEEDED = 6;
9192
}

sampling-message-server/src/it/java/de/dhbw/ravensburg/verteiltesysteme/server/SamplingMessageServerIT.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,15 @@ public void exceedMaxMessageNameLengthAtCreation() {
286286
final String tooLongMsgName = String.join("", Collections.nCopies(maxSamplingMessageNameLength + 1, "x"));
287287
SamplingMessageGrpcService.CreateSamplingMessageRequest createSamplingMessageRequest = createSamplingMessageRequest(tooLongMsgName, 120);
288288
SamplingMessageGrpcService.CreateSamplingMessageResponse createSamplingMessageResponse = this.samplingMessageBlockingStub.createSamplingMessage(createSamplingMessageRequest);
289-
Assert.assertEquals(createSamplingMessageResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_PARAMETER);
289+
Assert.assertEquals(createSamplingMessageResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_MESSAGE_NAME_LENGTH);
290290
}
291291

292292
@Test
293293
public void exceedMaxMessageNameLengthAtGetingStatus() {
294294
final String tooLongMsgName = String.join("", Collections.nCopies(maxSamplingMessageNameLength + 1, "x"));
295295
SamplingMessageGrpcService.GetSamplingMessageStatusRequest getSamplingMessageStatusRequest = getSamplingMessageStatusRequest(tooLongMsgName);
296296
SamplingMessageGrpcService.GetSamplingMessageStatusResponse getSamplingMessageStatusResponse = this.samplingMessageBlockingStub.getSamplingMessageStatus(getSamplingMessageStatusRequest);
297-
Assert.assertEquals(getSamplingMessageStatusResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_PARAMETER);
297+
Assert.assertEquals(getSamplingMessageStatusResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_MESSAGE_NAME_LENGTH);
298298
Assert.assertFalse(getSamplingMessageStatusResponse.getMessageIsEmpty());
299299
Assert.assertFalse(getSamplingMessageStatusResponse.getMessageIsValid());
300300
}
@@ -304,7 +304,7 @@ public void exceedMaxMessageNameLengthAtRading() {
304304
final String tooLongMsgName = String.join("", Collections.nCopies(maxSamplingMessageNameLength + 1, "x"));
305305
SamplingMessageGrpcService.ReadSamplingMessageRequest readSamplingMessageRequest = readSamplingMessageRequest(tooLongMsgName);
306306
SamplingMessageGrpcService.ReadSamplingMessageResponse readSamplingMessageResponse = this.samplingMessageBlockingStub.readSamplingMessage(readSamplingMessageRequest);
307-
Assert.assertEquals(readSamplingMessageResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_PARAMETER);
307+
Assert.assertEquals(readSamplingMessageResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_MESSAGE_NAME_LENGTH);
308308
Assert.assertFalse(readSamplingMessageResponse.getMessageIsValid());
309309
}
310310

@@ -313,7 +313,7 @@ public void exceedMaxMessageNameLengthAtClearing() {
313313
final String tooLongMsgName = String.join("", Collections.nCopies(maxSamplingMessageNameLength + 1, "x"));
314314
SamplingMessageGrpcService.ClearSamplingMessageRequest clearSamplingMessageRequest = clearSamplingMessageRequest(tooLongMsgName);
315315
SamplingMessageGrpcService.ClearSamplingMessageResponse clearSamplingMessageResponse = this.samplingMessageBlockingStub.clearSamplingMessage(clearSamplingMessageRequest);
316-
Assert.assertEquals(clearSamplingMessageResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_PARAMETER);
316+
Assert.assertEquals(clearSamplingMessageResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_MESSAGE_NAME_LENGTH);
317317
}
318318

319319
@Test
@@ -322,15 +322,15 @@ public void exceedMaxMessageNameLengthAtWriting() {
322322
final String msgContent = "random";
323323
SamplingMessageGrpcService.WriteSamplingMessageRequest writeSamplingMessageRequest = writeSamplingMessageRequest(tooLongMsgName, msgContent);
324324
SamplingMessageGrpcService.WriteSamplingMessageResponse writeSamplingMessageResponse = this.samplingMessageBlockingStub.writeSamplingMessage(writeSamplingMessageRequest);
325-
Assert.assertEquals(writeSamplingMessageResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_PARAMETER);
325+
Assert.assertEquals(writeSamplingMessageResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_MESSAGE_NAME_LENGTH);
326326
}
327327

328328
@Test
329329
public void exceedMaxMessageNameLengthAtDeleting() {
330330
final String tooLongMsgName = String.join("", Collections.nCopies(maxSamplingMessageNameLength + 1, "x"));
331331
SamplingMessageGrpcService.DeleteSamplingMessageRequest deleteSamplingMessageRequest = deleteSamplingMessageRequest(tooLongMsgName);
332332
SamplingMessageGrpcService.DeleteSamplingMessageResponse deleteSamplingMessageResponse = this.samplingMessageBlockingStub.deleteSamplingMessage(deleteSamplingMessageRequest);
333-
Assert.assertEquals(deleteSamplingMessageResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_PARAMETER);
333+
Assert.assertEquals(deleteSamplingMessageResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_MESSAGE_NAME_LENGTH);
334334
}
335335

336336

@@ -345,7 +345,7 @@ public void exceedMaxMessageContentLength() {
345345

346346
SamplingMessageGrpcService.WriteSamplingMessageRequest writeSamplingMessageRequest = writeSamplingMessageRequest(msgName, tooLongMsgContent);
347347
SamplingMessageGrpcService.WriteSamplingMessageResponse writeSamplingMessageResponse = this.samplingMessageBlockingStub.writeSamplingMessage(writeSamplingMessageRequest);
348-
Assert.assertEquals(writeSamplingMessageResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_PARAMETER);
348+
Assert.assertEquals(writeSamplingMessageResponse.getStatusCode(), SamplingMessageGrpcService.StatusCode.ILLEGAL_MESSAGE_CONTENT_LENGTH);
349349

350350
}
351351

sampling-message-server/src/main/java/de/dhbw/ravensburg/verteiltesysteme/server/rpc/RpcService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ private static SamplingMessageGrpcService.StatusCode fromServiceResultStatus(fin
4040
return SamplingMessageGrpcService.StatusCode.NOT_FOUND;
4141
case ALREADY_EXISTS:
4242
return SamplingMessageGrpcService.StatusCode.CONFLICT;
43-
case ILLEGAL_PARAMETER:
44-
return SamplingMessageGrpcService.StatusCode.ILLEGAL_PARAMETER;
43+
case ILLEGAL_MESSAGE_NAME_LENGTH:
44+
return SamplingMessageGrpcService.StatusCode.ILLEGAL_MESSAGE_NAME_LENGTH;
45+
case ILLEGAL_MESSAGE_CONTENT_LENGTH:
46+
return SamplingMessageGrpcService.StatusCode.ILLEGAL_MESSAGE_CONTENT_LENGTH;
4547
case MSG_COUNT_EXCEEDED:
4648
return SamplingMessageGrpcService.StatusCode.MESSAGE_COUNT_EXCEEDED;
4749
default:

sampling-message-server/src/main/java/de/dhbw/ravensburg/verteiltesysteme/server/service/SamplingMessageServiceImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public ServiceResult createSamplingMessage(@NonNull final String messageName, @N
3131

3232
if (inputValidator.isInvalidMessageName(messageName)) {
3333
log.info(String.format("Invalid messageName provided: %s", messageName));
34-
return new ServiceResult(ServiceResult.Status.ILLEGAL_PARAMETER);
34+
return new ServiceResult(ServiceResult.Status.ILLEGAL_MESSAGE_NAME_LENGTH);
3535
}
3636

3737
final long totalMessageCount = databaseAccessObject.getTotalMessageCount();
@@ -70,11 +70,11 @@ public ServiceResult writeSamplingMessage(@NonNull final String messageName, @No
7070

7171
if (inputValidator.isInvalidMessageName(messageName)) {
7272
log.info(String.format("Invalid messageName provided: %s", messageName));
73-
return new ServiceResult(ServiceResult.Status.ILLEGAL_PARAMETER);
73+
return new ServiceResult(ServiceResult.Status.ILLEGAL_MESSAGE_NAME_LENGTH);
7474
}
7575
if (inputValidator.isInvalidMessageContent(messageContent)) {
7676
log.info(String.format("Invalid messageContent provided: %s", messageContent));
77-
return new ServiceResult(ServiceResult.Status.ILLEGAL_PARAMETER);
77+
return new ServiceResult(ServiceResult.Status.ILLEGAL_MESSAGE_CONTENT_LENGTH);
7878
}
7979

8080
final ServiceResult serviceResult;
@@ -100,7 +100,7 @@ public ServiceResult clearSamplingMessage(@NonNull final String messageName) {
100100

101101
if (inputValidator.isInvalidMessageName(messageName)) {
102102
log.info(String.format("Invalid messageName provided: %s", messageName));
103-
return new ServiceResult(ServiceResult.Status.ILLEGAL_PARAMETER);
103+
return new ServiceResult(ServiceResult.Status.ILLEGAL_MESSAGE_NAME_LENGTH);
104104
}
105105

106106
final ServiceResult serviceResult;
@@ -129,7 +129,7 @@ public ServiceResult<SamplingMessage> readSamplingMessage(@NonNull final String
129129

130130
if (inputValidator.isInvalidMessageName(messageName)) {
131131
log.info(String.format("Invalid messageName provided: %s", messageName));
132-
return new ServiceResult<>(Optional.empty(), ServiceResult.Status.ILLEGAL_PARAMETER);
132+
return new ServiceResult<>(Optional.empty(), ServiceResult.Status.ILLEGAL_MESSAGE_NAME_LENGTH);
133133
}
134134

135135
final ServiceResult<SamplingMessage> serviceResult;
@@ -160,7 +160,7 @@ public ServiceResult<SamplingMessageStatus> getSamplingMessageStatus(@NonNull fi
160160

161161
if (inputValidator.isInvalidMessageName(messageName)) {
162162
log.info(String.format("Invalid messageName provided: %s", messageName));
163-
return new ServiceResult<>(Optional.empty(), ServiceResult.Status.ILLEGAL_PARAMETER);
163+
return new ServiceResult<>(Optional.empty(), ServiceResult.Status.ILLEGAL_MESSAGE_NAME_LENGTH);
164164
}
165165

166166
final ServiceResult<SamplingMessageStatus> serviceResult;
@@ -192,7 +192,7 @@ public ServiceResult deleteSamplingMessage(@NonNull final String messageName) {
192192

193193
if (inputValidator.isInvalidMessageName(messageName)) {
194194
log.info(String.format("Invalid messageName provided: %s", messageName));
195-
return new ServiceResult<>(Optional.empty(), ServiceResult.Status.ILLEGAL_PARAMETER);
195+
return new ServiceResult<>(Optional.empty(), ServiceResult.Status.ILLEGAL_MESSAGE_NAME_LENGTH);
196196
}
197197
final ServiceResult serviceResult;
198198
if (databaseAccessObject.deleteSamplingMessage(messageName)) {

sampling-message-server/src/main/java/de/dhbw/ravensburg/verteiltesysteme/server/service/ServiceResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public ServiceResult(Optional<T> resultItem, Status status) {
1919
}
2020

2121
public enum Status {
22-
SUCCESS, NOT_FOUND, ALREADY_EXISTS, MSG_COUNT_EXCEEDED, ILLEGAL_PARAMETER
22+
SUCCESS, NOT_FOUND, ALREADY_EXISTS, MSG_COUNT_EXCEEDED, ILLEGAL_MESSAGE_NAME_LENGTH, ILLEGAL_MESSAGE_CONTENT_LENGTH
2323
}
2424

2525
@Override

0 commit comments

Comments
 (0)