-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from xm-online/fix-add-profile-channelid-keyre…
…solver Implement profile channel key resolver
- Loading branch information
Showing
3 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...ain/java/com/icthh/xm/tmf/ms/qualification/lep/keyresolver/ProfileChannelKeyResolver.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,22 @@ | ||
package com.icthh.xm.tmf.ms.qualification.lep.keyresolver; | ||
|
||
import com.icthh.xm.commons.lep.AppendLepKeyResolver; | ||
import com.icthh.xm.lep.api.LepManagerService; | ||
import com.icthh.xm.lep.api.LepMethod; | ||
import com.icthh.xm.lep.api.commons.SeparatorSegmentedLepKey; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ProfileChannelKeyResolver extends AppendLepKeyResolver { | ||
|
||
@Override | ||
protected String[] getAppendSegments(SeparatorSegmentedLepKey baseKey, | ||
LepMethod method, | ||
LepManagerService managerService) { | ||
String profile = getRequiredParam(method, "profile", String.class); | ||
String translatedProfile = translateToLepConvention(profile); | ||
String channel = getRequiredParam(method, "channelId", String.class); | ||
String translatedChannel = translateToLepConvention(channel); | ||
return new String[]{translatedProfile, translatedChannel}; | ||
} | ||
} |
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
70 changes: 70 additions & 0 deletions
70
...java/com/icthh/xm/tmf/ms/qualification/lep/keyresolver/ProfileChannelKeyResolverTest.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,70 @@ | ||
package com.icthh.xm.tmf.ms.qualification.lep.keyresolver; | ||
|
||
import com.icthh.xm.commons.lep.XmLepConstants; | ||
import com.icthh.xm.commons.lep.spring.LepServiceHandler; | ||
import com.icthh.xm.lep.api.*; | ||
import com.icthh.xm.lep.core.CoreLepManager; | ||
import com.icthh.xm.tmf.ms.qualification.web.rest.PromotionQualificationDelegate; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Captor; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.context.ApplicationContext; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ProfileChannelKeyResolverTest { | ||
|
||
@InjectMocks | ||
private LepServiceHandler lepServiceHandler; | ||
|
||
@Mock | ||
private ApplicationContext applicationContext; | ||
|
||
@Mock | ||
private CoreLepManager lepManager; | ||
|
||
@Captor | ||
private ArgumentCaptor<LepKey> baseLepKey; | ||
|
||
@Captor | ||
private ArgumentCaptor<LepKeyResolver> keyResolver; | ||
|
||
@Captor | ||
private ArgumentCaptor<LepMethod> lepMethod; | ||
|
||
@Captor | ||
private ArgumentCaptor<Version> version; | ||
|
||
@Test | ||
public void testResolveLepKeyByProfileAndChannelId() throws Throwable { | ||
|
||
Method method = PromotionQualificationDelegate.class.getMethod("promotionQualificationFind", String.class, | ||
String.class, String.class); | ||
|
||
when(applicationContext.getBean(LepManager.class)).thenReturn(lepManager); | ||
|
||
ProfileChannelKeyResolver resolver = new ProfileChannelKeyResolver(); | ||
when(applicationContext.getBean(ProfileChannelKeyResolver.class)).thenReturn(resolver); | ||
|
||
lepServiceHandler.onMethodInvoke(PromotionQualificationDelegate.class, | ||
new PromotionQualificationDelegate(), method, new Object[]{"RTM", "relatedPartyId_12345", "CRM"}); | ||
|
||
verify(lepManager) | ||
.processLep(baseLepKey.capture(), version.capture(), keyResolver.capture(), lepMethod.capture()); | ||
|
||
LepKey resolvedKey = resolver.resolve(baseLepKey.getValue(), lepMethod.getValue(), null); | ||
|
||
assertEquals( | ||
String.join(XmLepConstants.EXTENSION_KEY_SEPARATOR, | ||
"service", "PromotionQualificationFind", "RTM", "CRM"), resolvedKey.getId()); | ||
} | ||
} |