|
@@ -71,7 +71,7 @@ class BatchSubjectServiceTest {
|
|
|
resp.setAuthorizeLink("https://ur.alipay.com/abc");
|
|
resp.setAuthorizeLink("https://ur.alipay.com/abc");
|
|
|
when(alipayClient.certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class))).thenReturn(resp);
|
|
when(alipayClient.certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class))).thenReturn(resp);
|
|
|
|
|
|
|
|
- Map<String, String> result = service.apply("张三公司", "2088111122223333", 1L);
|
|
|
|
|
|
|
+ Map<String, String> result = service.apply("张三公司", "2088111122223333", "ALIPAY_USER_ID", 1L);
|
|
|
|
|
|
|
|
assertEquals("https://ur.alipay.com/abc", result.get("authorize_link"));
|
|
assertEquals("https://ur.alipay.com/abc", result.get("authorize_link"));
|
|
|
assertEquals("AUTHING", result.get("status"));
|
|
assertEquals("AUTHING", result.get("status"));
|
|
@@ -97,28 +97,98 @@ class BatchSubjectServiceTest {
|
|
|
verify(alipayClientFactory).getClientByProvider(1L, "BATCH_PAY");
|
|
verify(alipayClientFactory).getClientByProvider(1L, "BATCH_PAY");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void apply_usesCustomParticipantIdType() throws AlipayApiException {
|
|
|
|
|
+ AlipayFundAuthorizeUniApplyResponse resp = new AlipayFundAuthorizeUniApplyResponse();
|
|
|
|
|
+ resp.setAuthorizeLink("https://ur.alipay.com/custom");
|
|
|
|
|
+ when(alipayClient.certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class))).thenReturn(resp);
|
|
|
|
|
+
|
|
|
|
|
+ service.apply("张三公司", "18812345678", "ALIPAY_LOGON_ID", 1L);
|
|
|
|
|
+
|
|
|
|
|
+ ArgumentCaptor<AlipayFundAuthorizeUniApplyRequest> cap = ArgumentCaptor.forClass(AlipayFundAuthorizeUniApplyRequest.class);
|
|
|
|
|
+ verify(alipayClient).certificateExecute(cap.capture());
|
|
|
|
|
+ AlipayFundAuthorizeUniApplyModel m = (AlipayFundAuthorizeUniApplyModel) cap.getValue().getBizModel();
|
|
|
|
|
+ assertEquals("ALIPAY_LOGON_ID", m.getPrincipalInfo().getParticipantIdType());
|
|
|
|
|
+
|
|
|
|
|
+ ArgumentCaptor<BatchAuthorizeEntity> ent = ArgumentCaptor.forClass(BatchAuthorizeEntity.class);
|
|
|
|
|
+ verify(batchAuthorizeMapper).insert(ent.capture());
|
|
|
|
|
+ assertEquals("ALIPAY_LOGON_ID", ent.getValue().getParticipantIdType());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void apply_nullParticipantIdType_defaultsToUserId() throws AlipayApiException {
|
|
|
|
|
+ AlipayFundAuthorizeUniApplyResponse resp = new AlipayFundAuthorizeUniApplyResponse();
|
|
|
|
|
+ resp.setAuthorizeLink("https://ur.alipay.com/abc");
|
|
|
|
|
+ when(alipayClient.certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class))).thenReturn(resp);
|
|
|
|
|
+
|
|
|
|
|
+ service.apply("张三公司", "2088111122223333", null, 1L);
|
|
|
|
|
+
|
|
|
|
|
+ ArgumentCaptor<AlipayFundAuthorizeUniApplyRequest> cap = ArgumentCaptor.forClass(AlipayFundAuthorizeUniApplyRequest.class);
|
|
|
|
|
+ verify(alipayClient).certificateExecute(cap.capture());
|
|
|
|
|
+ AlipayFundAuthorizeUniApplyModel m = (AlipayFundAuthorizeUniApplyModel) cap.getValue().getBizModel();
|
|
|
|
|
+ assertEquals("ALIPAY_USER_ID", m.getPrincipalInfo().getParticipantIdType());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void apply_invalidParticipantIdType_throws() throws AlipayApiException {
|
|
|
|
|
+ BusinessException ex = assertThrows(BusinessException.class,
|
|
|
|
|
+ () -> service.apply("张三公司", "2088111122223333", "BOGUS_TYPE", 1L));
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals(400, ex.getCode());
|
|
|
|
|
+ assertTrue(ex.getMessage().contains("主体类型"), ex.getMessage());
|
|
|
|
|
+ verify(alipayClient, never()).certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class));
|
|
|
|
|
+ verify(batchAuthorizeMapper, never()).insert(any());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void rebind_reusesExistingParticipantIdType() throws AlipayApiException {
|
|
|
|
|
+ BatchAuthorizeEntity existing = new BatchAuthorizeEntity();
|
|
|
|
|
+ existing.setId(9L);
|
|
|
|
|
+ existing.setOutBizNo("OLD-2");
|
|
|
|
|
+ existing.setParticipantName("张三公司");
|
|
|
|
|
+ existing.setParticipantId("2088111122223333");
|
|
|
|
|
+ existing.setParticipantIdType("ALIPAY_OPEN_ID");
|
|
|
|
|
+ existing.setServiceProviderId(1L);
|
|
|
|
|
+ existing.setStatus("AUTHING");
|
|
|
|
|
+ when(batchAuthorizeMapper.selectById(9L)).thenReturn(existing);
|
|
|
|
|
+ AlipayFundAuthorizeUniApplyResponse resp = new AlipayFundAuthorizeUniApplyResponse();
|
|
|
|
|
+ resp.setAuthorizeLink("https://ur.alipay.com/new");
|
|
|
|
|
+ when(alipayClient.certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class))).thenReturn(resp);
|
|
|
|
|
+
|
|
|
|
|
+ service.rebind(9L);
|
|
|
|
|
+
|
|
|
|
|
+ ArgumentCaptor<AlipayFundAuthorizeUniApplyRequest> cap = ArgumentCaptor.forClass(AlipayFundAuthorizeUniApplyRequest.class);
|
|
|
|
|
+ verify(alipayClient).certificateExecute(cap.capture());
|
|
|
|
|
+ AlipayFundAuthorizeUniApplyModel m = (AlipayFundAuthorizeUniApplyModel) cap.getValue().getBizModel();
|
|
|
|
|
+ assertEquals("ALIPAY_OPEN_ID", m.getPrincipalInfo().getParticipantIdType());
|
|
|
|
|
+ // 新申请落库沿用原主体类型
|
|
|
|
|
+ ArgumentCaptor<BatchAuthorizeEntity> ent = ArgumentCaptor.forClass(BatchAuthorizeEntity.class);
|
|
|
|
|
+ verify(batchAuthorizeMapper).insert(ent.capture());
|
|
|
|
|
+ assertEquals("ALIPAY_OPEN_ID", ent.getValue().getParticipantIdType());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
void apply_failure_throwsBusinessException() throws AlipayApiException {
|
|
void apply_failure_throwsBusinessException() throws AlipayApiException {
|
|
|
when(alipayClient.certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class)))
|
|
when(alipayClient.certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class)))
|
|
|
.thenThrow(new AlipayApiException("network error"));
|
|
.thenThrow(new AlipayApiException("network error"));
|
|
|
|
|
|
|
|
- assertThrows(BusinessException.class, () -> service.apply("张三公司", "2088111122223333", 1L));
|
|
|
|
|
|
|
+ assertThrows(BusinessException.class, () -> service.apply("张三公司", "2088111122223333", "ALIPAY_USER_ID", 1L));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
void apply_missingParticipantId_throwsBusinessException() {
|
|
void apply_missingParticipantId_throwsBusinessException() {
|
|
|
- assertThrows(BusinessException.class, () -> service.apply("张三公司", " ", 1L));
|
|
|
|
|
- assertThrows(BusinessException.class, () -> service.apply("张三公司", null, 1L));
|
|
|
|
|
|
|
+ assertThrows(BusinessException.class, () -> service.apply("张三公司", " ", "ALIPAY_USER_ID", 1L));
|
|
|
|
|
+ assertThrows(BusinessException.class, () -> service.apply("张三公司", null, "ALIPAY_USER_ID", 1L));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
void apply_missingParticipantName_throwsBusinessException() {
|
|
void apply_missingParticipantName_throwsBusinessException() {
|
|
|
- assertThrows(BusinessException.class, () -> service.apply(" ", "2088111122223333", 1L));
|
|
|
|
|
|
|
+ assertThrows(BusinessException.class, () -> service.apply(" ", "2088111122223333", "ALIPAY_USER_ID", 1L));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
void apply_missingServiceProvider_throwsBusinessException() {
|
|
void apply_missingServiceProvider_throwsBusinessException() {
|
|
|
- assertThrows(BusinessException.class, () -> service.apply("张三公司", "2088111122223333", null));
|
|
|
|
|
|
|
+ assertThrows(BusinessException.class, () -> service.apply("张三公司", "2088111122223333", "ALIPAY_USER_ID", null));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -129,7 +199,7 @@ class BatchSubjectServiceTest {
|
|
|
existing.setStatus("AUTHED");
|
|
existing.setStatus("AUTHED");
|
|
|
when(batchAuthorizeMapper.selectOne(any())).thenReturn(existing);
|
|
when(batchAuthorizeMapper.selectOne(any())).thenReturn(existing);
|
|
|
|
|
|
|
|
- assertThrows(BusinessException.class, () -> service.apply("张三公司", "2088111122223333", 1L));
|
|
|
|
|
|
|
+ assertThrows(BusinessException.class, () -> service.apply("张三公司", "2088111122223333", "ALIPAY_USER_ID", 1L));
|
|
|
|
|
|
|
|
verify(alipayClient, never()).certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class));
|
|
verify(alipayClient, never()).certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class));
|
|
|
verify(batchAuthorizeMapper, never()).insert(any());
|
|
verify(batchAuthorizeMapper, never()).insert(any());
|
|
@@ -149,7 +219,7 @@ class BatchSubjectServiceTest {
|
|
|
resp.setAuthorizeLink("https://ur.alipay.com/new");
|
|
resp.setAuthorizeLink("https://ur.alipay.com/new");
|
|
|
when(alipayClient.certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class))).thenReturn(resp);
|
|
when(alipayClient.certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class))).thenReturn(resp);
|
|
|
|
|
|
|
|
- service.apply("张三公司", "2088111122223333", 1L);
|
|
|
|
|
|
|
+ service.apply("张三公司", "2088111122223333", "ALIPAY_USER_ID", 1L);
|
|
|
|
|
|
|
|
verify(batchAuthorizeMapper).updateById(argThat(e -> "UNBIND".equals(e.getStatus()) && "OLD-1".equals(e.getOutBizNo())));
|
|
verify(batchAuthorizeMapper).updateById(argThat(e -> "UNBIND".equals(e.getStatus()) && "OLD-1".equals(e.getOutBizNo())));
|
|
|
ArgumentCaptor<BatchAuthorizeEntity> ent = ArgumentCaptor.forClass(BatchAuthorizeEntity.class);
|
|
ArgumentCaptor<BatchAuthorizeEntity> ent = ArgumentCaptor.forClass(BatchAuthorizeEntity.class);
|
|
@@ -162,7 +232,7 @@ class BatchSubjectServiceTest {
|
|
|
AlipayFundAuthorizeUniApplyResponse resp = new AlipayFundAuthorizeUniApplyResponse();
|
|
AlipayFundAuthorizeUniApplyResponse resp = new AlipayFundAuthorizeUniApplyResponse();
|
|
|
when(alipayClient.certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class))).thenReturn(resp);
|
|
when(alipayClient.certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class))).thenReturn(resp);
|
|
|
|
|
|
|
|
- Map<String, String> result = service.apply("张三公司", "2088111122223333", 1L);
|
|
|
|
|
|
|
+ Map<String, String> result = service.apply("张三公司", "2088111122223333", "ALIPAY_USER_ID", 1L);
|
|
|
|
|
|
|
|
assertEquals("", result.get("authorize_link"));
|
|
assertEquals("", result.get("authorize_link"));
|
|
|
assertEquals("AUTHING", result.get("status"));
|
|
assertEquals("AUTHING", result.get("status"));
|
|
@@ -271,7 +341,7 @@ class BatchSubjectServiceTest {
|
|
|
doThrow(new org.springframework.dao.DuplicateKeyException("duplicate key")).when(batchAuthorizeMapper).insert(any());
|
|
doThrow(new org.springframework.dao.DuplicateKeyException("duplicate key")).when(batchAuthorizeMapper).insert(any());
|
|
|
|
|
|
|
|
BusinessException ex = assertThrows(BusinessException.class,
|
|
BusinessException ex = assertThrows(BusinessException.class,
|
|
|
- () -> service.apply("张三公司", "2088111122223333", 1L));
|
|
|
|
|
|
|
+ () -> service.apply("张三公司", "2088111122223333", "ALIPAY_USER_ID", 1L));
|
|
|
|
|
|
|
|
assertEquals(400, ex.getCode());
|
|
assertEquals(400, ex.getCode());
|
|
|
assertTrue(ex.getMessage().contains("请勿重复操作"), ex.getMessage());
|
|
assertTrue(ex.getMessage().contains("请勿重复操作"), ex.getMessage());
|
|
@@ -287,7 +357,7 @@ class BatchSubjectServiceTest {
|
|
|
when(batchAuthorizeMapper.selectOne(any())).thenReturn(existing);
|
|
when(batchAuthorizeMapper.selectOne(any())).thenReturn(existing);
|
|
|
|
|
|
|
|
BusinessException ex = assertThrows(BusinessException.class,
|
|
BusinessException ex = assertThrows(BusinessException.class,
|
|
|
- () -> service.apply("张三公司", "2088111122223333", 1L));
|
|
|
|
|
|
|
+ () -> service.apply("张三公司", "2088111122223333", "ALIPAY_USER_ID", 1L));
|
|
|
|
|
|
|
|
assertEquals(400, ex.getCode());
|
|
assertEquals(400, ex.getCode());
|
|
|
assertTrue(ex.getMessage().contains("未完成"), ex.getMessage());
|
|
assertTrue(ex.getMessage().contains("未完成"), ex.getMessage());
|
|
@@ -304,7 +374,7 @@ class BatchSubjectServiceTest {
|
|
|
existing.setCreatedTime(java.time.OffsetDateTime.now());
|
|
existing.setCreatedTime(java.time.OffsetDateTime.now());
|
|
|
when(batchAuthorizeMapper.selectOne(any())).thenReturn(existing);
|
|
when(batchAuthorizeMapper.selectOne(any())).thenReturn(existing);
|
|
|
|
|
|
|
|
- assertThrows(BusinessException.class, () -> service.apply("张三公司", "2088111122223333", 1L));
|
|
|
|
|
|
|
+ assertThrows(BusinessException.class, () -> service.apply("张三公司", "2088111122223333", "ALIPAY_USER_ID", 1L));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -316,7 +386,7 @@ class BatchSubjectServiceTest {
|
|
|
when(batchAuthorizeMapper.selectOne(any())).thenReturn(existing);
|
|
when(batchAuthorizeMapper.selectOne(any())).thenReturn(existing);
|
|
|
|
|
|
|
|
BusinessException ex = assertThrows(BusinessException.class,
|
|
BusinessException ex = assertThrows(BusinessException.class,
|
|
|
- () -> service.apply("张三公司", "2088111122223333", 1L));
|
|
|
|
|
|
|
+ () -> service.apply("张三公司", "2088111122223333", "ALIPAY_USER_ID", 1L));
|
|
|
|
|
|
|
|
assertEquals(400, ex.getCode());
|
|
assertEquals(400, ex.getCode());
|
|
|
verify(alipayClient, never()).certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class));
|
|
verify(alipayClient, never()).certificateExecute(any(AlipayFundAuthorizeUniApplyRequest.class));
|