-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix #807: Fix error handling for FCM errors * - add test
- Loading branch information
Showing
2 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
powerauth-push-server/src/test/java/io/getlime/push/service/PushSendingWorkerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2024 Wultra s.r.o. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.getlime.push.service; | ||
|
||
import com.google.firebase.messaging.MessagingErrorCode; | ||
import com.wultra.core.rest.client.base.RestClientException; | ||
import io.getlime.push.configuration.PushServiceConfiguration; | ||
import io.getlime.push.errorhandling.exceptions.FcmMissingTokenException; | ||
import io.getlime.push.model.entity.PushMessageAttributes; | ||
import io.getlime.push.model.entity.PushMessageBody; | ||
import io.getlime.push.model.enumeration.Priority; | ||
import io.getlime.push.service.fcm.FcmClient; | ||
import io.getlime.push.service.fcm.FcmModelConverter; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* Tests of {@link PushSendingWorker} | ||
* | ||
* @author Jan Dusil, [email protected] | ||
*/ | ||
@SpringBootTest | ||
@ActiveProfiles("test") | ||
class PushSendingWorkerTest { | ||
|
||
@Mock | ||
private FcmClient fcmClient; | ||
|
||
@Mock | ||
private PushSendingCallback callback; | ||
|
||
@Mock | ||
private PushServiceConfiguration pushServiceConfiguration; | ||
|
||
@Mock | ||
private FcmModelConverter fcmModelConverter; | ||
|
||
@InjectMocks | ||
private PushSendingWorker tested; | ||
|
||
@Test | ||
void testSendMessageToAndroidError() throws FcmMissingTokenException { | ||
final RestClientException simulatedException = new RestClientException("Simulated INVALID_ARGUMENT error"); | ||
when(fcmModelConverter.convertExceptionToErrorCode(simulatedException)).thenReturn(MessagingErrorCode.INVALID_ARGUMENT); | ||
doAnswer(invocation -> { | ||
final Consumer<Throwable> onError = invocation.getArgument(3); | ||
onError.accept(simulatedException); | ||
return null; | ||
}).when(fcmClient).exchange(any(), anyBoolean(), any(), any()); | ||
|
||
tested.sendMessageToAndroid(fcmClient, new PushMessageBody(), new PushMessageAttributes(), Priority.HIGH, "dummyToken", callback); | ||
verify(callback).didFinishSendingMessage(PushSendingCallback.Result.FAILED_DELETE); | ||
} | ||
|
||
} | ||
|