Skip to content

Commit

Permalink
Merge pull request #12 from xm-online/fix-add-profile-channelid-keyre…
Browse files Browse the repository at this point in the history
…solver

Implement profile channel key resolver
  • Loading branch information
amedvedchuk authored Dec 3, 2019
2 parents 5e94999 + e5febc8 commit 23be093
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
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};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.icthh.xm.commons.lep.LogicExtensionPoint;
import com.icthh.xm.commons.lep.spring.LepService;
import com.icthh.xm.tmf.ms.qualification.lep.keyresolver.ProfileKeyResolver;
import com.icthh.xm.tmf.ms.qualification.lep.keyresolver.ProfileChannelKeyResolver;
import com.icthh.xm.tmf.ms.qualification.web.api.PromotionQualificationApiDelegate;
import com.icthh.xm.tmf.ms.qualification.web.api.model.PromotionQualification;
import io.micrometer.core.annotation.Timed;
Expand All @@ -17,7 +17,7 @@
public class PromotionQualificationDelegate implements PromotionQualificationApiDelegate {

@Timed
@LogicExtensionPoint(value = "PromotionQualificationFind", resolver = ProfileKeyResolver.class)
@LogicExtensionPoint(value = "PromotionQualificationFind", resolver = ProfileChannelKeyResolver.class)
@PreAuthorize("hasPermission({'profile': #profile, 'relatedPartyId': #relatedPartyId, 'channelId': #channelId}, 'QUALIFICATION.PROMOTION.GET')")
@Override
public ResponseEntity<PromotionQualification> promotionQualificationFind(String profile,
Expand Down
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());
}
}

0 comments on commit 23be093

Please sign in to comment.