|
|
@@ -44,7 +44,7 @@ class OmgPaymentCreateServiceTest {
|
|
|
when(attempts.selectOrderForUpdate("DD-1")).thenReturn(order);
|
|
|
|
|
|
OmgPaymentBusinessException error = assertThrows(OmgPaymentBusinessException.class,
|
|
|
- () -> service.create(5L, "DD-1"));
|
|
|
+ () -> service.create(5L, "DD-1", OmgPaymentMethod.CREDIT));
|
|
|
|
|
|
assertEquals(expected, error.getCode());
|
|
|
verify(attempts, never()).createCreated(anyString(), anyString(), anyLong(), anyString(), anyInt(),
|
|
|
@@ -57,7 +57,7 @@ class OmgPaymentCreateServiceTest {
|
|
|
when(attempts.selectOrderForUpdate("DD-1")).thenReturn(payableOrder());
|
|
|
when(attempts.selectActiveCreatedByDdIdForUpdate("DD-1")).thenReturn(new OmgPaymentAttempt());
|
|
|
OmgPaymentBusinessException error = assertThrows(OmgPaymentBusinessException.class,
|
|
|
- () -> service.create(5L, "DD-1"));
|
|
|
+ () -> service.create(5L, "DD-1", OmgPaymentMethod.CREDIT));
|
|
|
assertEquals(PAYMENT_ATTEMPT_EXISTS, error.getCode());
|
|
|
verifyNoInteractions(generator, formFactory, credentials);
|
|
|
}
|
|
|
@@ -74,12 +74,14 @@ class OmgPaymentCreateServiceTest {
|
|
|
when(credentials.getEnabledCredential(77L)).thenReturn(credential());
|
|
|
when(attempts.supersedeCreated(8L)).thenReturn(1);
|
|
|
when(generator.generate()).thenReturn("OMG12345678901234567");
|
|
|
- when(formFactory.create(anyString(), anyInt(), anyString(), anyString(), anyString(), anyString()))
|
|
|
+ when(formFactory.create(anyString(), anyInt(), anyString(), anyString(), anyString(), anyString(),
|
|
|
+ any(OmgPaymentMethod.class)))
|
|
|
.thenReturn(new OmgPaymentForm("stage", Map.of()));
|
|
|
when(attempts.createCreated(anyString(), anyString(), anyLong(), anyString(), anyInt(),
|
|
|
anyString(), anyString())).thenReturn(created);
|
|
|
|
|
|
- OmgPaymentCreateOutcome outcome = service.replaceActiveForRetry(5L, "DD-1", "OMGOLD");
|
|
|
+ OmgPaymentCreateOutcome outcome = service.replaceActiveForRetry(5L, "DD-1", "OMGOLD",
|
|
|
+ OmgPaymentMethod.CREDIT);
|
|
|
|
|
|
assertEquals(9L, outcome.attemptId());
|
|
|
var orderOfCalls = inOrder(attempts, credentials, generator, formFactory);
|
|
|
@@ -89,7 +91,7 @@ class OmgPaymentCreateServiceTest {
|
|
|
orderOfCalls.verify(attempts).supersedeCreated(8L);
|
|
|
orderOfCalls.verify(generator).generate();
|
|
|
orderOfCalls.verify(formFactory).create("DD-1", 100, "1000031", "KEY", "IV",
|
|
|
- "OMG12345678901234567");
|
|
|
+ "OMG12345678901234567", OmgPaymentMethod.CREDIT);
|
|
|
orderOfCalls.verify(attempts).createCreated("DD-1", "OMG12345678901234567", 77L,
|
|
|
"1000031", 100, "KEY", "IV");
|
|
|
}
|
|
|
@@ -103,7 +105,7 @@ class OmgPaymentCreateServiceTest {
|
|
|
when(attempts.selectActiveCreatedByDdIdForUpdate("DD-1")).thenReturn(current);
|
|
|
|
|
|
OmgPaymentBusinessException error = assertThrows(OmgPaymentBusinessException.class,
|
|
|
- () -> service.replaceActiveForRetry(5L, "DD-1", "OMGOLD"));
|
|
|
+ () -> service.replaceActiveForRetry(5L, "DD-1", "OMGOLD", OmgPaymentMethod.CREDIT));
|
|
|
|
|
|
assertEquals(PAYMENT_RETRY_NOT_AVAILABLE, error.getCode());
|
|
|
verifyNoInteractions(credentials, generator, formFactory);
|
|
|
@@ -119,12 +121,13 @@ class OmgPaymentCreateServiceTest {
|
|
|
when(attempts.selectOrderForUpdate("DD-1")).thenReturn(order);
|
|
|
when(credentials.getEnabledCredential(77L)).thenReturn(credential);
|
|
|
when(generator.generate()).thenReturn("OMG12345678901234567");
|
|
|
- when(formFactory.create(anyString(), anyInt(), anyString(), anyString(), anyString(), anyString()))
|
|
|
+ when(formFactory.create(anyString(), anyInt(), anyString(), anyString(), anyString(), anyString(),
|
|
|
+ any(OmgPaymentMethod.class)))
|
|
|
.thenReturn(new OmgPaymentForm(OmgPaymentFormFactory.STAGE_GATEWAY_URL, Map.of("CheckMacValue", "A".repeat(64))));
|
|
|
when(attempts.createCreated(anyString(), anyString(), anyLong(), anyString(), anyInt(),
|
|
|
anyString(), anyString())).thenReturn(attempt);
|
|
|
|
|
|
- OmgPaymentCreateOutcome outcome = service.create(5L, "DD-1");
|
|
|
+ OmgPaymentCreateOutcome outcome = service.create(5L, "DD-1", OmgPaymentMethod.CREDIT);
|
|
|
|
|
|
assertEquals(9L, outcome.attemptId());
|
|
|
assertEquals("CREATED", outcome.response().status());
|
|
|
@@ -136,7 +139,7 @@ class OmgPaymentCreateServiceTest {
|
|
|
orderOfCalls.verify(credentials).getEnabledCredential(77L);
|
|
|
orderOfCalls.verify(generator).generate();
|
|
|
orderOfCalls.verify(formFactory).create("DD-1", 100, "1000031", "KEY", "IV",
|
|
|
- "OMG12345678901234567");
|
|
|
+ "OMG12345678901234567", OmgPaymentMethod.CREDIT);
|
|
|
orderOfCalls.verify(attempts).createCreated("DD-1", "OMG12345678901234567", 77L, "1000031", 100,
|
|
|
"KEY", "IV");
|
|
|
}
|
|
|
@@ -146,7 +149,8 @@ class OmgPaymentCreateServiceTest {
|
|
|
when(attempts.selectOrderForUpdate("DD-1")).thenReturn(payableOrder());
|
|
|
when(credentials.getEnabledCredential(77L)).thenReturn(credential());
|
|
|
when(generator.generate()).thenReturn("OMG12345678901234567");
|
|
|
- when(formFactory.create(anyString(), anyInt(), anyString(), anyString(), anyString(), anyString()))
|
|
|
+ when(formFactory.create(anyString(), anyInt(), anyString(), anyString(), anyString(), anyString(),
|
|
|
+ any(OmgPaymentMethod.class)))
|
|
|
.thenReturn(new OmgPaymentForm("stage", Map.of()));
|
|
|
when(attempts.createCreated(anyString(), anyString(), anyLong(), anyString(), anyInt(),
|
|
|
anyString(), anyString()))
|
|
|
@@ -154,7 +158,7 @@ class OmgPaymentCreateServiceTest {
|
|
|
when(attempts.selectActiveCreatedByDdIdForUpdate("DD-1")).thenReturn(null, new OmgPaymentAttempt());
|
|
|
|
|
|
OmgPaymentBusinessException error = assertThrows(OmgPaymentBusinessException.class,
|
|
|
- () -> service.create(5L, "DD-1"));
|
|
|
+ () -> service.create(5L, "DD-1", OmgPaymentMethod.CREDIT));
|
|
|
assertEquals(PAYMENT_ATTEMPT_EXISTS, error.getCode());
|
|
|
verify(generator, times(1)).generate();
|
|
|
}
|
|
|
@@ -164,7 +168,8 @@ class OmgPaymentCreateServiceTest {
|
|
|
when(attempts.selectOrderForUpdate("DD-1")).thenReturn(payableOrder());
|
|
|
when(credentials.getEnabledCredential(77L)).thenReturn(credential());
|
|
|
when(generator.generate()).thenReturn("OMG11111111111111111", "OMG22222222222222222");
|
|
|
- when(formFactory.create(anyString(), anyInt(), anyString(), anyString(), anyString(), anyString()))
|
|
|
+ when(formFactory.create(anyString(), anyInt(), anyString(), anyString(), anyString(), anyString(),
|
|
|
+ any(OmgPaymentMethod.class)))
|
|
|
.thenReturn(new OmgPaymentForm("stage", Map.of()));
|
|
|
OmgPaymentAttempt inserted = new OmgPaymentAttempt();
|
|
|
inserted.setId(11L);
|
|
|
@@ -174,9 +179,10 @@ class OmgPaymentCreateServiceTest {
|
|
|
when(attempts.selectByMerchantTradeNoForUpdate("OMG11111111111111111"))
|
|
|
.thenReturn(new OmgPaymentAttempt());
|
|
|
|
|
|
- assertEquals(11L, service.create(5L, "DD-1").attemptId());
|
|
|
+ assertEquals(11L, service.create(5L, "DD-1", OmgPaymentMethod.CREDIT).attemptId());
|
|
|
verify(generator, times(2)).generate();
|
|
|
- verify(formFactory, times(2)).create(anyString(), anyInt(), anyString(), anyString(), anyString(), anyString());
|
|
|
+ verify(formFactory, times(2)).create(anyString(), anyInt(), anyString(), anyString(), anyString(), anyString(),
|
|
|
+ eq(OmgPaymentMethod.CREDIT));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -185,7 +191,8 @@ class OmgPaymentCreateServiceTest {
|
|
|
when(credentials.getEnabledCredential(77L)).thenReturn(credential());
|
|
|
when(generator.generate()).thenReturn("OMG11111111111111111", "OMG22222222222222222",
|
|
|
"OMG33333333333333333");
|
|
|
- when(formFactory.create(anyString(), anyInt(), anyString(), anyString(), anyString(), anyString()))
|
|
|
+ when(formFactory.create(anyString(), anyInt(), anyString(), anyString(), anyString(), anyString(),
|
|
|
+ any(OmgPaymentMethod.class)))
|
|
|
.thenReturn(new OmgPaymentForm("stage", Map.of()));
|
|
|
when(attempts.createCreated(anyString(), anyString(), anyLong(), anyString(), anyInt(),
|
|
|
anyString(), anyString()))
|
|
|
@@ -193,7 +200,7 @@ class OmgPaymentCreateServiceTest {
|
|
|
when(attempts.selectByMerchantTradeNoForUpdate(anyString())).thenReturn(new OmgPaymentAttempt());
|
|
|
|
|
|
OmgPaymentBusinessException error = assertThrows(OmgPaymentBusinessException.class,
|
|
|
- () -> service.create(5L, "DD-1"));
|
|
|
+ () -> service.create(5L, "DD-1", OmgPaymentMethod.CREDIT));
|
|
|
assertEquals(PAYMENT_CREATION_FAILED, error.getCode());
|
|
|
verify(generator, times(3)).generate();
|
|
|
}
|
|
|
@@ -233,7 +240,7 @@ class OmgPaymentCreateServiceTest {
|
|
|
when(credentials.getEnabledCredential(77L)).thenReturn(null);
|
|
|
|
|
|
OmgPaymentBusinessException error = assertThrows(OmgPaymentBusinessException.class,
|
|
|
- () -> service.create(5L, "DD-1"));
|
|
|
+ () -> service.create(5L, "DD-1", OmgPaymentMethod.CREDIT));
|
|
|
|
|
|
assertEquals(STORE_CREDENTIAL_UNAVAILABLE, error.getCode());
|
|
|
verifyNoInteractions(generator, formFactory);
|
|
|
@@ -241,6 +248,15 @@ class OmgPaymentCreateServiceTest {
|
|
|
anyString(), anyString());
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void rejectsNullPaymentMethodBeforeAnyDependencyInteraction() {
|
|
|
+ OmgPaymentBusinessException error = assertThrows(OmgPaymentBusinessException.class,
|
|
|
+ () -> service.create(5L, "DD-1", null));
|
|
|
+
|
|
|
+ assertEquals(PAYMENT_METHOD_INVALID, error.getCode());
|
|
|
+ verifyNoInteractions(attempts, credentials, generator, formFactory);
|
|
|
+ }
|
|
|
+
|
|
|
private static OmgPaymentOrderSnapshot payableOrder() {
|
|
|
OmgPaymentOrderSnapshot order = new OmgPaymentOrderSnapshot();
|
|
|
order.setDdId("DD-1");
|