How to use ListMap class of org.powermock.core package

Best Powermock code snippet using org.powermock.core.ListMap

Source:MonitorServiceImplTestSetUp.java Github

copy

Full Screen

1package com.firstrain.frapi.service.impl;2import com.firstrain.common.db.jpa.PersistenceProvider;3import com.firstrain.common.db.jpa.Transaction;4import com.firstrain.db.api.GroupsDbAPI;5import com.firstrain.db.api.TagsDbAPI;6import com.firstrain.db.api.ItemsDbAPI;7import com.firstrain.db.api.TagsItemsMapDbAPI;8import com.firstrain.db.api.SearchMapDbAPI;9import com.firstrain.db.api.EmailSearchScheduleMapDbAPI;10import com.firstrain.db.api.EmailUserSearchDbAPI;11import com.firstrain.db.api.UserGroupMapDbAPI;12import com.firstrain.db.api.EmailScheduleDbAPI;13import com.firstrain.db.obj.TagsInfo;14import com.firstrain.db.obj.EmailUserSearch;15import com.firstrain.db.obj.Tags;16import com.firstrain.db.obj.EmailSchedule;17import com.firstrain.db.obj.Users;18import com.firstrain.db.obj.Groups;19import com.firstrain.db.obj.BaseItem;20import com.firstrain.db.obj.ShareWith;21import com.firstrain.db.obj.Items;22import com.firstrain.db.obj.SearchMap;23import com.firstrain.db.obj.UserGroupMap;24import com.firstrain.db.obj.TagItemsMap;25import com.firstrain.db.obj.EmailSearchScheduleMap;26import com.firstrain.frapi.domain.User;27import com.firstrain.frapi.obj.MonitorWizardFilters;28import com.firstrain.frapi.pojo.EnterprisePref;29import com.firstrain.frapi.pojo.Entity;30import com.firstrain.frapi.repository.EntityBaseServiceRepository;31import com.firstrain.frapi.repository.impl.EntityBaseServiceRepositoryImpl;32import com.firstrain.frapi.repository.impl.GroupServiceRepositoryImpl;33import com.firstrain.frapi.repository.impl.MonitorServiceRepositoryImpl;34import com.firstrain.frapi.repository.impl.UserServiceRepositoryImpl;35import com.firstrain.frapi.util.ConvertUtil;36import com.firstrain.frapi.util.MonitorOrderingUtils;37import com.firstrain.frapi.util.ServicesAPIUtil;38import com.firstrain.obj.IEntityInfo;39import com.firstrain.obj.IEntityInfoCache;40import com.firstrain.utils.FR_ArrayUtils;41import com.firstrain.utils.JSONUtility;42import com.firstrain.utils.object.PerfMonitor;43import com.google.common.collect.Sets;44import org.junit.Before;45import org.junit.Rule;46import org.junit.rules.ErrorCollector;47import org.junit.runner.RunWith;48import org.mockito.ArgumentCaptor;49import org.mockito.Captor;50import org.mockito.Mock;51import org.mockito.InjectMocks;52import org.powermock.core.classloader.annotations.PrepareForTest;53import org.powermock.modules.junit4.PowerMockRunner;54import java.util.Collections;55import java.util.List;56import java.util.Collection;57import java.util.ArrayList;58import java.util.Map;59import java.util.Arrays;60import java.util.HashMap;61import static com.firstrain.frapi.util.DefaultEnums.Status.ACTIVE;62import static org.mockito.Matchers.any;63import static org.mockito.Matchers.anyListOf;64import static org.mockito.Matchers.anyInt;65import static org.mockito.Matchers.anyString;66import static org.mockito.Matchers.anyLong;67import static org.mockito.Matchers.eq;68import static org.mockito.Matchers.anyList;69import static org.powermock.api.mockito.PowerMockito.mockStatic;70import static org.powermock.api.mockito.PowerMockito.when;71import static org.powermock.api.mockito.PowerMockito.doReturn;72import static org.powermock.api.mockito.PowerMockito.spy;73import static org.powermock.reflect.Whitebox.setInternalState;74@RunWith(PowerMockRunner.class)75@PrepareForTest({76 MonitorServiceImpl.class,77 GroupsDbAPI.class,78 TagsDbAPI.class,79 ItemsDbAPI.class,80 PersistenceProvider.class,81 JSONUtility.class,82 TagsItemsMapDbAPI.class,83 SearchMapDbAPI.class,84 EmailSearchScheduleMapDbAPI.class,85 EmailUserSearchDbAPI.class,86 EmailScheduleDbAPI.class,87 UserGroupMapDbAPI.class,88 FR_ArrayUtils.class,89 PerfMonitor.class,90 MonitorOrderingUtils.class91})92public abstract class MonitorServiceImplTestSetUp {93 private static final long TAGS_EMAIL_ID = 111L;94 static final int TAGS_ORDER = 374;95 static final long REFERS_TO = 987;96 static final String TOKEN_ENTRY_SECTOR = "TOKEN ENTRY SECTOR";97 static final String SEARCH_TOKEN = "SEARCH TOKEN";98 static final long DOC_GROUP_ID = 648L;99 static final String ADV_KEYWORDS = "keyword1,keyword2";100 static final String FILTER_STRING_VALUE = "FILTER";101 static final String EXCEPTION = "MESSAGE";102 static final int ENT_COMPANY_ID = 99;103 static final long OWNED_BY = 88L;104 static final long MONITOR_ID = 554L;105 static final long ITEMS_ID = 67L;106 static final String USER_COMPANY = "user_company";107 static final String LAST_NAME = "lastName";108 static final long FR_MONITOR_ID = 98L;109 static final String FIRST_NAME = "firstname";110 static final String USER_DOMAIN = "userDOmain";111 static final String OWNER_TYPE = "ADMIN";112 static final String USER_NAME_VALUE = "usernamevalue";113 static final String USER_ID = "68790";114 static final long GROUP_ID = 88L;115 static final long PARENT_GROUP_ID = 1L;116 static final long FR_USER_ID = 12L;117 static final int RESULT_SIZE = 546;118 static final String ITEMS_DATA = "q=items_data&fq45&q=2352";119 static final long MAIL_SEARCH_ID = 12L;120 static final long SEARCH_TAG_ID = 456L;121 static final long UI_SEARCH_ID = 99L;122 static final long SEARCH_ID = 123L;123 static final String TAG_NAME = "tag";124 static final int SEARCHES_PER_MONITOR = -1;125 static final String CLUSTER_IDS_CSV = "345";126 static final String ENT_NAME = "ent";127 static final int VOL_RECENT_WEEK = 1;128 static final String COMP_LOGO_URL = "logo";129 static final String TICKER = "ticker";130 static final int ONE_DAY_DOC_COUNT = 23;131 static final String DNB_COMPANY_ID = "67uiq0";132 static final String MATCHED_TYPE = "1";133 static final short RELEVANCE_SCORE = 300;134 static final long ITEMS_TAG_ID = 890L;135 static final long SCHEDULE_ID = 34L;136 static final long TEMPLATE_ID = 56L;137 static final long SCHEDULE_USER_ID = 875L;138 static final String ADVANCED_FILTERS = "filter";139 static final String MONITOR_ENTITY = "entity: value";140 static final String EMAIL = "stringEmail";141 static final long EMAIL_USER_SEARCH_ID = 6392L;142 static final long TAGS_ID = 766L;143 private static final String KEYWORD_STRING = "keyword";144 final MonitorServiceRepositoryImpl monitorServiceRepository = spy(new MonitorServiceRepositoryImpl());145 final GroupServiceRepositoryImpl groupServiceRepository = spy(new GroupServiceRepositoryImpl());146 final UserServiceRepositoryImpl userServiceRepository = spy(new UserServiceRepositoryImpl());147 final ConvertUtil convertUtil = spy(new ConvertUtil());148 final ServicesAPIUtil servicesAPIUtil = spy(new ServicesAPIUtil());149 final EntityBaseServiceRepository entityBaseServiceRepository = spy(new EntityBaseServiceRepositoryImpl());150 @InjectMocks151 final MonitorServiceImpl monitorService = spy(new MonitorServiceImpl());152 @Mock153 IEntityInfoCache entityInfoCache;154 @Mock155 IEntityInfo iEntityInfo;156 @Mock157 Transaction transaction;158 @Captor159 ArgumentCaptor<Tags> tagsArgumentCaptor;160 @Captor161 ArgumentCaptor<List<TagsInfo>> tagCaptor;162 @Captor163 ArgumentCaptor<List<Long>> listLongArgumentCaptor;164 @Captor165 ArgumentCaptor<List<Entity>> entListArgumentCaptor;166 @Captor167 ArgumentCaptor<List<String>> strListArgumentCaptor;168 @Captor169 ArgumentCaptor<MonitorWizardFilters> monitorWizardFiltersArgumentCaptor;170 EmailUserSearch emailUserSearch;171 EnterprisePref enterprisePrefFinal;172 MonitorWizardFilters monitorWizardFiltersFinal;173 List<String> stringList;174 @Rule175 public final ErrorCollector errorCollector = new ErrorCollector();176 @Before177 public void setUp() throws Exception {178 mockStatic(GroupsDbAPI.class, TagsDbAPI.class,179 ItemsDbAPI.class, PersistenceProvider.class,180 JSONUtility.class, TagsItemsMapDbAPI.class,181 SearchMapDbAPI.class, EmailSearchScheduleMapDbAPI.class,182 EmailUserSearchDbAPI.class, EmailScheduleDbAPI.class,183 UserGroupMapDbAPI.class, PerfMonitor.class);184 stringList = new ArrayList<>();185 stringList.add("OR");186 monitorWizardFiltersFinal = new MonitorWizardFilters();187 enterprisePrefFinal = new EnterprisePref();188 emailUserSearch = new EmailUserSearch();189 emailUserSearch.setId(EMAIL_USER_SEARCH_ID);190 when(entityInfoCache.searchTokenToEntity(anyString())).thenReturn(iEntityInfo);191 when(entityBaseServiceRepository.getEntityInfoCache()).thenReturn(entityInfoCache);192 setInternalState(servicesAPIUtil, "entityBaseServiceRepository", entityBaseServiceRepository);193 setInternalState(monitorServiceRepository, "servicesAPIUtil", servicesAPIUtil);194 setInternalState(monitorServiceRepository, "convertUtil", convertUtil);195 when(GroupsDbAPI.getAllParentGroupIdsByGroupId(anyString(), anyLong(), anyLong()))196 .thenReturn(Sets.newHashSet(GROUP_ID));197 when(TagsDbAPI.addTag(any(Transaction.class), anyString(), any(Tags.TagType.class)198 , anyString(), anyLong(), any(BaseItem.RefersToType.class), anyLong(), any(BaseItem.OwnedByType.class)199 , anyLong(), any(Tags.SearchOrderType.class), any(ShareWith.class)))200 .thenReturn(createTags());201 when(TagsDbAPI.getTagsByOwner(anyString(), any(BaseItem.OwnedByType.class), anyLong()))202 .thenReturn(null).thenReturn(Collections.singletonList(createTags()));203 when(TagsDbAPI.getTagById(any(Transaction.class), anyLong()))204 .thenReturn(null).thenReturn(createTags());205 when(GroupsDbAPI.getGroupByIds(anyString(), any(Collection.class)))206 .thenReturn(Collections.singletonList(createGroups()));207 when(ItemsDbAPI.getItemsByTagId(anyString(), anyLong(), any(Items.Type.class), anyInt(), anyInt()))208 .thenReturn(null).209 thenReturn(Arrays.asList(createItems(), createItems()));210 when(PersistenceProvider.newTxn(anyString())).thenReturn(transaction);211 when(SearchMapDbAPI.getSearchMapByUISearchIDAndTagID(anyString(), anyLong(), anyLong()))212 .thenReturn(createSearchMap());213 when(TagsItemsMapDbAPI.getTagsItemsMapByTagID(anyString(), anyLong()))214 .thenReturn(null).thenReturn(Collections.singletonList(createTagItemsMap()));215 when(ItemsDbAPI.addItem(any(Transaction.class), anyString(), anyString(), any(Items.Type.class), anyLong()216 , anyInt(), anyLong(), any(BaseItem.RefersToType.class), anyLong(), any(BaseItem.OwnedByType.class)217 , anyInt())).thenReturn(createItems());218 when(EmailScheduleDbAPI.fetchEmailScheduleById(any(Transaction.class), anyLong()))219 .thenReturn(createEmailSchedule());220 when(EmailUserSearchDbAPI.fetchEmailUserSearchById(any(Transaction.class), anyLong()))221 .thenReturn(emailUserSearch);222 when(EmailSearchScheduleMapDbAPI223 .fetchSearchScheduleMapByScheduleIdSearchStatus(anyLong()))224 .thenReturn(Collections.singletonList(createEmailSearchScheduleMap()));225 when(JSONUtility.deserialize(anyString(), eq(MonitorWizardFilters.class)))226 .thenReturn(createWizardFilters());227 when(transaction.fetch(anyLong(), eq(Tags.class))).thenReturn(createTags());228 when(transaction.fetch(anyLong(), eq(EmailUserSearch.class))).thenReturn(emailUserSearch);229 doReturn(entityInfoCache).when(monitorServiceRepository).getEntityInfoCache();230 when(PerfMonitor.currentTime()).thenReturn(PARENT_GROUP_ID);231 }232 static Users createUsers() {233 Users users = new Users();234 users.setFirstName(FIRST_NAME);235 users.setId(FR_USER_ID);236 return users;237 }238 static User createUser() {239 User user = new User();240 user.setDomain(USER_DOMAIN);241 user.setFirstName(FIRST_NAME);242 user.setFrMonitorId(FR_MONITOR_ID);243 user.setOwnedBy(OWNED_BY);244 user.setLastName(LAST_NAME);245 user.setUserCompany(USER_COMPANY);246 user.setUserId(USER_ID);247 user.setUserName(USER_NAME_VALUE);248 user.setEmail(EMAIL);249 return user;250 }251 static UserGroupMap createUserGroupMap(UserGroupMap.MembershipType type) {252 UserGroupMap userGroupMap = new UserGroupMap();253 userGroupMap.setOwnedByType(BaseItem.OwnedByType.USER);254 userGroupMap.setUserId(Long.parseLong(USER_ID));255 userGroupMap.setMembershipType(type);256 userGroupMap.setGroupId(GROUP_ID);257 userGroupMap.setFlags(BaseItem.FLAGS.ACTIVE);258 return userGroupMap;259 }260 static Tags createTags() {261 Tags tagsLocal = new Tags();262 tagsLocal.setEmailId(TAGS_EMAIL_ID);263 tagsLocal.setOrder(TAGS_ORDER);264 tagsLocal.setRefersTo(REFERS_TO);265 tagsLocal.setRefersToType(BaseItem.RefersToType.DOCUMENT);266 tagsLocal.setSearchOrderType(Tags.SearchOrderType.CUSTOM);267 tagsLocal.setFilterString(FILTER_STRING_VALUE);268 tagsLocal.setTagType(Tags.TagType.COMPETITION_REGION);269 tagsLocal.setOwnedBy(FR_USER_ID);270 tagsLocal.setOwnedByType(BaseItem.OwnedByType.GROUP);271 tagsLocal.setTagName(TAG_NAME);272 tagsLocal.setId(TAGS_ID);273 return tagsLocal;274 }275 static Groups createGroups() {276 Groups groups = new Groups();277 groups.setId(GROUP_ID);278 groups.setGroupType(Groups.GroupType.FIRSTRAIN);279 groups.setParentGroupId(PARENT_GROUP_ID);280 groups.setGroupName(USER_NAME_VALUE);281 return groups;282 }283 static Items createItems() {284 Items items = new Items();285 items.setResultSize(RESULT_SIZE);286 items.setDocGroupId(DOC_GROUP_ID);287 items.setData(ITEMS_DATA);288 items.setId(-1L);289 items.setName(ENT_NAME);290 return items;291 }292 static MonitorWizardFilters createWizardFilters() {293 MonitorWizardFilters monitorWizardFilters = new MonitorWizardFilters();294 MonitorWizardFilters.Advanced advanced = new MonitorWizardFilters.Advanced();295 advanced.keywords = ADV_KEYWORDS;296 advanced.advancedFilters = Collections.singletonList(ADVANCED_FILTERS);297 monitorWizardFilters.advanced = advanced;298 return monitorWizardFilters;299 }300 static SearchMap createSearchMap() {301 SearchMap searchMap = new SearchMap();302 searchMap.setId(SEARCH_ID);303 searchMap.setUiSearchID(UI_SEARCH_ID);304 searchMap.setTagID(SEARCH_TAG_ID);305 searchMap.setMailSearchID(MAIL_SEARCH_ID);306 return searchMap;307 }308 static Entity createEntity() {309 Entity entityFinal = new Entity();310 entityFinal.setId(CLUSTER_IDS_CSV);311 entityFinal.setName(ENT_NAME);312 entityFinal.setCompanyId(ENT_COMPANY_ID);313 entityFinal.setVolumeRecentWeek(VOL_RECENT_WEEK);314 entityFinal.setStatus(ACTIVE);315 entityFinal.setCompanyLogoUrl(COMP_LOGO_URL);316 entityFinal.setHasTweet(true);317 entityFinal.setSearchToken(SEARCH_TOKEN);318 entityFinal.setAdditionalMatchQualifier(true);319 entityFinal.setTicker(TICKER);320 entityFinal.setAdded(true);321 entityFinal.setMatchedType(MATCHED_TYPE);322 entityFinal.setRelevanceScore(RELEVANCE_SCORE);323 entityFinal.setDnbEntityId(DNB_COMPANY_ID);324 entityFinal.setSelected(true);325 entityFinal.setOneDayDocCount(ONE_DAY_DOC_COUNT);326 return entityFinal;327 }328 static TagItemsMap createTagItemsMap() {329 TagItemsMap itemsMap = new TagItemsMap();330 itemsMap.setTagId(ITEMS_TAG_ID);331 itemsMap.setItemType(TagItemsMap.ItemType.ITEM);332 itemsMap.setId(ITEMS_ID);333 return itemsMap;334 }335 static EmailSchedule createEmailSchedule() {336 EmailSchedule emailSchedule = new EmailSchedule();337 emailSchedule.setUserId(SCHEDULE_USER_ID);338 emailSchedule.setTemplateID(TEMPLATE_ID);339 emailSchedule.setId(SCHEDULE_ID);340 return emailSchedule;341 }342 EmailSearchScheduleMap createEmailSearchScheduleMap() {343 EmailSearchScheduleMap searchScheduleMap = new EmailSearchScheduleMap();344 searchScheduleMap.setEmailSchedule(createEmailSchedule());345 searchScheduleMap.setEmailUserSearch(emailUserSearch);346 return searchScheduleMap;347 }348 void setTags() throws Exception {349 Tags tags = createTags();350 tags.setOwnedBy(FR_USER_ID);351 tags.setFlags(BaseItem.FLAGS.ACTIVE);352 User user = createUser();353 user.setUserId(String.valueOf(FR_USER_ID));354 when(UserGroupMapDbAPI.getUserGroupMapByUserId(anyString(), anyLong()))355 .thenReturn(Collections.singletonList(createUserGroupMap(UserGroupMap.MembershipType.ADMIN)));356 doReturn(tags).when(monitorServiceRepository).getTagById(anyLong());357 doReturn(null).when(monitorServiceRepository).getTagsByOwnerAndTagName(anyLong(),358 any(BaseItem.OwnedByType.class), anyString());359 Users users = createUsers();360 doReturn(users).when(userServiceRepository).getUserById(anyLong());361 List<Entity> entities = Collections.singletonList(createEntity());362 doReturn(entities).when(monitorServiceRepository).validateTokensUsingEntityCache(anyList(), anyList());363 doReturn(KEYWORD_STRING).when(servicesAPIUtil).prepareFq(anyListOf(String.class));364 }365 void setRemoveTags() throws Exception {366 Tags tags = createTags();367 tags.setFlags(BaseItem.FLAGS.ACTIVE);368 User user = createUser();369 user.setOwnedBy(FR_USER_ID);370 when(UserGroupMapDbAPI.getUserGroupMapByUserId(anyString(), anyLong()))371 .thenReturn(Collections.singletonList(createUserGroupMap(UserGroupMap.MembershipType.ADMIN)));372 doReturn(tags).when(monitorServiceRepository).getTagById(anyLong());373 }374 void setMonitorOwner() {375 UserGroupMap groupMap = createUserGroupMap(UserGroupMap.MembershipType.ADMIN);376 doReturn(Collections.singletonList(groupMap))377 .when(userServiceRepository).getUserGroupMapByUserId(anyLong());378 }379 void initRemoveEntities() throws Exception {380 when(JSONUtility.deserialize(anyString(), eq(MonitorWizardFilters.class)))381 .thenReturn(createWizardFilters());382 when(entityInfoCache.searchTokenToEntity(anyString())).thenReturn(null);383 doReturn(entityInfoCache).when(monitorServiceRepository).getEntityInfoCache();384 Map<String, List<String>> listMap = new HashMap();385 listMap.put("q", Arrays.asList("12: 12", "13: 14"));386 listMap.put("z", Arrays.asList("12: 12", "13: 14"));387 doReturn(listMap).when(servicesAPIUtil).prepareQueryMap(anyString());388 }389 void initAddEntities() throws Exception {390 when(JSONUtility.deserialize(anyString(), eq(MonitorWizardFilters.class)))391 .thenReturn(createWizardFilters());392 when(entityInfoCache.searchTokenToEntity(anyString())).thenReturn(null);393 doReturn(entityInfoCache).when(monitorServiceRepository).getEntityInfoCache();394 Map<String, List<String>> listMap = new HashMap();395 listMap.put("q", Arrays.asList("12: 12", "13: 14"));396 listMap.put("z", Arrays.asList("12: 12", "13: 14"));397 doReturn(listMap).when(servicesAPIUtil).prepareQueryMap(anyString());398 List<Entity> entities = Collections.singletonList(createEntity());399 doReturn(entities).when(monitorServiceRepository).validateTokensUsingEntityCache(anyList(), anyList());400 enterprisePrefFinal.setSearchesPerMonitor(SEARCHES_PER_MONITOR);401 }402 void initCategory() throws Exception {403 initAddEntities();404 Entity entityNew = new Entity();405 entityNew.setId("-1L");406 entityNew.setSearchToken(SEARCH_TOKEN);407 doReturn(Collections.singletonMap(SEARCH_TOKEN, entityNew)).when(monitorService,408 "getEntitiesMap", anyList(), anyList(), any(MonitorWizardFilters.class));409 }410 void initAddFilters() {411 when(entityInfoCache.searchTokenToEntity(anyString())).thenReturn(null);412 doReturn(entityInfoCache).when(monitorServiceRepository).getEntityInfoCache();413 Map<String, List<String>> listMap = new HashMap();414 listMap.put("q", Arrays.asList("12: 12", "13: 14"));415 listMap.put("z", Arrays.asList("12: 12", "13: 14"));416 doReturn(listMap).when(servicesAPIUtil).prepareQueryMap(anyString());417 List<Entity> entities = Collections.singletonList(createEntity());418 doReturn(entities).when(monitorServiceRepository).validateTokensUsingEntityCache(anyList(), anyList());419 }420 void initRemoveFilters() {421 when(entityInfoCache.searchTokenToEntity(anyString())).thenReturn(null);422 doReturn(entityInfoCache).when(monitorServiceRepository).getEntityInfoCache();423 Map<String, List<String>> listMap = new HashMap();424 listMap.put("q", Arrays.asList("12: 12", "13: 14"));425 listMap.put("z", Arrays.asList("12: 12", "13: 14"));426 doReturn(listMap).when(servicesAPIUtil).prepareQueryMap(anyString());427 List<Entity> entities = Collections.singletonList(createEntity());428 doReturn(entities).when(monitorServiceRepository).validateTokensUsingEntityCache(anyList(), anyList());429 }430}...

Full Screen

Full Screen

Source:TenantMigrationActorTest.java Github

copy

Full Screen

1package org.sunbird.actor.user;2import static akka.testkit.JavaTestKit.duration;3import static org.junit.Assert.assertEquals;4import static org.junit.Assert.assertTrue;5import static org.powermock.api.mockito.PowerMockito.mock;6import static org.powermock.api.mockito.PowerMockito.when;7import akka.actor.ActorRef;8import akka.actor.ActorSystem;9import akka.actor.Props;10import akka.dispatch.Futures;11import akka.testkit.javadsl.TestKit;12import java.util.*;13import org.junit.Assert;14import org.junit.Before;15import org.junit.Test;16import org.junit.runner.RunWith;17import org.mockito.Mockito;18import org.powermock.api.mockito.PowerMockito;19import org.powermock.core.classloader.annotations.PowerMockIgnore;20import org.powermock.core.classloader.annotations.PrepareForTest;21import org.powermock.modules.junit4.PowerMockRunner;22import org.sunbird.cassandra.CassandraOperation;23import org.sunbird.cassandraimpl.CassandraOperationImpl;24import org.sunbird.common.Constants;25import org.sunbird.common.ElasticSearchRestHighImpl;26import org.sunbird.common.factory.EsClientFactory;27import org.sunbird.common.inf.ElasticSearchService;28import org.sunbird.dao.user.UserLookupDao;29import org.sunbird.dao.user.UserOrgDao;30import org.sunbird.dao.user.impl.UserLookupDaoImpl;31import org.sunbird.dao.user.impl.UserOrgDaoImpl;32import org.sunbird.exception.ProjectCommonException;33import org.sunbird.exception.ResponseCode;34import org.sunbird.helper.ServiceFactory;35import org.sunbird.keys.JsonKey;36import org.sunbird.operations.ActorOperations;37import org.sunbird.request.Request;38import org.sunbird.request.RequestContext;39import org.sunbird.response.Response;40import org.sunbird.util.DataCacheHandler;41import org.sunbird.util.ProjectUtil;42import scala.concurrent.Promise;43@RunWith(PowerMockRunner.class)44@PrepareForTest({45 ServiceFactory.class,46 CassandraOperationImpl.class,47 DataCacheHandler.class,48 UserLookupDao.class,49 UserLookupDaoImpl.class,50 EsClientFactory.class,51 ElasticSearchRestHighImpl.class,52 UserOrgDao.class,53 UserOrgDaoImpl.class54})55@PowerMockIgnore({56 "javax.management.*",57 "javax.net.ssl.*",58 "javax.security.*",59 "jdk.internal.reflect.*",60 "javax.crypto.*"61})62public class TenantMigrationActorTest {63 Props props = Props.create(TenantMigrationActor.class);64 ActorSystem system = ActorSystem.create("system");65 private static CassandraOperation cassandraOperation = null;66 private static ElasticSearchService esService;67 private static Response response;68 @Before69 public void beforeEachTest() throws Exception {70 PowerMockito.mockStatic(ServiceFactory.class);71 PowerMockito.mockStatic(UserLookupDaoImpl.class);72 PowerMockito.mockStatic(EsClientFactory.class);73 esService = mock(ElasticSearchRestHighImpl.class);74 when(EsClientFactory.getInstance(Mockito.anyString())).thenReturn(esService);75 Promise<Map<String, Object>> promise = Futures.promise();76 promise.success(getListOrgResponse());77 when(esService.search(Mockito.any(), Mockito.anyString(), Mockito.any()))78 .thenReturn(promise.future());79 UserLookupDao userLookupDao = PowerMockito.mock(UserLookupDao.class);80 PowerMockito.when(UserLookupDaoImpl.getInstance()).thenReturn(userLookupDao);81 cassandraOperation = mock(CassandraOperationImpl.class);82 response = new Response();83 Map<String, Object> responseMap = new HashMap<>();84 responseMap.put(Constants.RESPONSE, Arrays.asList(getFeedMap()));85 response.getResult().putAll(responseMap);86 response.put(Constants.RESPONSE, Arrays.asList(getFeedMap()));87 PowerMockito.when(ServiceFactory.getInstance()).thenReturn(cassandraOperation);88 PowerMockito.when(89 cassandraOperation.getRecordsByProperties(90 Mockito.anyString(),91 Mockito.anyString(),92 Mockito.anyMap(),93 Mockito.any(RequestContext.class)))94 .thenReturn(response);95 Response upsertResponse = new Response();96 Map<String, Object> responseMap2 = new HashMap<>();97 responseMap2.put(Constants.RESPONSE, Constants.SUCCESS);98 upsertResponse.getResult().putAll(responseMap2);99 PowerMockito.when(100 cassandraOperation.upsertRecord(101 Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(RequestContext.class)))102 .thenReturn(upsertResponse);103 Response response = new Response();104 response.put(JsonKey.RESPONSE, JsonKey.SUCCESS);105 when(cassandraOperation.insertRecord(106 Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any()))107 .thenReturn(response);108 PowerMockito.when(109 userLookupDao.insertExternalIdIntoUserLookup(110 Mockito.anyList(), Mockito.anyString(), Mockito.any()))111 .thenReturn(response);112 List<Map<String, Object>> listMap = new ArrayList<>();113 Map<String, Object> orgs = new HashMap<>();114 orgs.put(JsonKey.USER_ID, "anyUserId");115 orgs.put(JsonKey.ORGANISATION_ID, "anyRootOrgId");116 listMap.add(orgs);117 Map<String, Object> userDetails1 = new HashMap<>();118 userDetails1.put(JsonKey.ROOT_ORG_ID, "anyRootOrgId");119 userDetails1.put(JsonKey.ORGANISATIONS, listMap);120 Response response1 = new Response();121 List<Map<String, Object>> list1 = new ArrayList<>();122 list1.add(userDetails1);123 response1.getResult().put(JsonKey.RESPONSE, list1);124 Map<String, Object> userDetails2 = new HashMap<>();125 userDetails2.put(JsonKey.ROOT_ORG_ID, "anyRootOrgId");126 userDetails2.put(JsonKey.ORGANISATIONS, listMap);127 Response response2 = new Response();128 List<Map<String, Object>> list2 = new ArrayList<>();129 list2.add(userDetails2);130 response2.getResult().put(JsonKey.RESPONSE, list2);131 PowerMockito.when(132 cassandraOperation.getRecordById(133 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any()))134 .thenReturn(response1)135 .thenReturn(response2);136 PowerMockito.when(137 cassandraOperation.getRecordById(138 Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any()))139 .thenReturn(getSelfDeclarationResponse())140 .thenReturn(getSelfDeclarationResponse());141 PowerMockito.when(142 cassandraOperation.updateRecord(143 Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any()))144 .thenReturn(response);145 PowerMockito.when(146 cassandraOperation.upsertRecord(147 Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any()))148 .thenReturn(response);149 Response updateResponse = new Response();150 updateResponse.getResult().put(JsonKey.RESPONSE, "FAILED");151 PowerMockito.when(152 cassandraOperation.updateRecord(153 Mockito.any(), Mockito.any(), Mockito.anyMap(), Mockito.anyMap(), Mockito.any()))154 .thenReturn(updateResponse);155 when(cassandraOperation.getRecordsByCompositeKey(156 Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any()))157 .thenReturn(getOrgFromCassandra())158 .thenReturn(getOrgFromCassandra());159 }160 public static Response getEsResponse() {161 Response response = new Response();162 Map<String, Object> map = new HashMap<>();163 map.put("anyString", new Object());164 response.put(JsonKey.RESPONSE, map);165 return response;166 }167 public static Map<String, Object> getEsResponseMap() {168 Map<String, Object> map = new HashMap<>();169 map.put(JsonKey.IS_TENANT, true);170 map.put(JsonKey.ID, "rootOrgId");171 map.put(JsonKey.CHANNEL, "anyChannel");172 return map;173 }174 public static Map<String, Object> getListOrgResponse() {175 Map<String, Object> map = new HashMap<>();176 map.put(JsonKey.ID, "anyRootOrgId");177 map.put(JsonKey.HASHTAGID, "anyRootOrgId");178 map.put(JsonKey.STATUS, 1);179 map.put(JsonKey.CHANNEL, "anyProvider");180 Map<String, Object> response = new HashMap<>();181 List<Map<String, Object>> content = new ArrayList<>();182 content.add(map);183 response.put(JsonKey.CONTENT, content);184 return response;185 }186 public Request getFailureMigrateReq(ActorOperations actorOperation, String action) {187 Request reqObj = new Request();188 Map reqMap = new HashMap<>();189 reqMap.put(JsonKey.USER_ID, "WrongUserId");190 reqMap.put(JsonKey.USER_EXT_ID, "WrongAnyUserExtId");191 reqMap.put(JsonKey.CHANNEL, "anyChannel");192 reqMap.put(JsonKey.ACTION, action);193 reqMap.put(JsonKey.FEED_ID, "anyFeedId");194 reqObj.setRequest(reqMap);195 reqObj.setOperation(actorOperation.getValue());196 return reqObj;197 }198 public boolean testScenario(Request reqObj, ResponseCode errorCode, Props props) {199 TestKit probe = new TestKit(system);200 ActorRef subject = system.actorOf(props);201 subject.tell(reqObj, probe.getRef());202 if (errorCode == null) {203 Response res = probe.expectMsgClass(duration("100 second"), Response.class);204 return null != res && res.getResponseCode() == ResponseCode.OK;205 } else {206 ProjectCommonException res =207 probe.expectMsgClass(duration("100 second"), ProjectCommonException.class);208 return res.getResponseCode().name().equals(errorCode.name())209 || res.getErrorResponseCode() == errorCode.getResponseCode();210 }211 }212 public Request getMigrateReq(ActorOperations actorOperation) {213 Request reqObj = new Request();214 Map reqMap = new HashMap<>();215 reqMap.put(JsonKey.USER_ID, "anyUserId");216 reqMap.put(JsonKey.USER_EXT_ID, "anyUserExtId");217 reqMap.put(JsonKey.CHANNEL, "anyChannel");218 reqMap.put(JsonKey.FEED_ID, "anyFeedId");219 reqMap.put(JsonKey.FORCE_MIGRATION, true);220 reqMap.put(JsonKey.NOTIFY_USER_MIGRATION, true);221 reqMap.put(JsonKey.SOFT_DELETE_PREVIOUS_ORG, true);222 reqObj.setRequest(reqMap);223 reqObj.setOperation(actorOperation.getValue());224 return reqObj;225 }226 private static Map<String, Object> getFeedMap() {227 Map<String, Object> fMap = new HashMap<>();228 fMap.put(JsonKey.ID, "123-456-7890");229 fMap.put(JsonKey.USER_ID, "123-456-789");230 fMap.put(JsonKey.CATEGORY, "category");231 return fMap;232 }233 @Test234 public void testUserMigration() {235 try {236 PowerMockito.mockStatic(DataCacheHandler.class);237 Map<String, String> dataCache = new HashMap<>();238 dataCache.put(JsonKey.CUSTODIAN_ORG_ID, "anyRootOrgId");239 when(DataCacheHandler.getConfigSettings()).thenReturn(dataCache);240 boolean result =241 testScenario(getMigrateReq(ActorOperations.USER_TENANT_MIGRATE), null, props);242 } catch (ProjectCommonException e) {243 assertEquals(ResponseCode.CLIENT_ERROR.getResponseCode(), e.getErrorResponseCode());244 }245 }246 @Test247 public void testUserSelfDeclarationMigrationWithValidatedStatus() {248 PowerMockito.mockStatic(DataCacheHandler.class);249 Map<String, String> dataCache = new HashMap<>();250 dataCache.put(JsonKey.CUSTODIAN_ORG_ID, "anyRootOrgId");251 when(DataCacheHandler.getConfigSettings()).thenReturn(dataCache);252 boolean result =253 testScenario(254 getSelfDeclaredMigrateReq(ActorOperations.USER_SELF_DECLARED_TENANT_MIGRATE),255 ResponseCode.errorUserMigrationFailed,256 props);257 assertTrue(result);258 }259 @Test260 public void testWithInvalidRequest() {261 TestKit probe = new TestKit(system);262 ActorRef subject = system.actorOf(props);263 Request request = new Request();264 request.setOperation("invalidOperation");265 subject.tell(request, probe.getRef());266 ProjectCommonException exception =267 probe.expectMsgClass(duration("10 second"), ProjectCommonException.class);268 Assert.assertNotNull(exception);269 }270 public Map<String, Object> getOrgandLocation() {271 Map<String, Object> map = new HashMap<>();272 map.put(JsonKey.ORG_ID, "anyOrgId");273 // map.put(JsonKey.LOCATION_IDS, new ArrayList<String>(Arrays.asList("anyLocationId")));274 return map;275 }276 public static Response getOrgFromCassandra() {277 Response response = new Response();278 List<Map<String, Object>> list = new ArrayList<>();279 Map<String, Object> map = new HashMap<>();280 map.put(JsonKey.ORG_ID, "anyRootOrgId");281 // map.put(JsonKey.LOCATION_IDS, new ArrayList<String>(Arrays.asList("anyLocationId")));282 map.put("template", "anyTemplate");283 list.add(map);284 response.put(Constants.RESPONSE, list);285 return response;286 }287 // @Test288 public void testUserSelfDeclarationMigrationWithValidatedStatuswithError() {289 Response updateResponse = new Response();290 updateResponse.getResult().put(JsonKey.RESPONSE, "FAILED");291 PowerMockito.when(292 cassandraOperation.updateRecord(293 Mockito.any(), Mockito.any(), Mockito.anyMap(), Mockito.anyMap(), Mockito.any()))294 .thenReturn(updateResponse);295 List<Map<String, Object>> listMap = new ArrayList<>();296 listMap.add(new HashMap<>());297 Map<String, Object> userDetails = new HashMap<>();298 userDetails.put(JsonKey.ROOT_ORG_ID, "");299 userDetails.put(JsonKey.ORGANISATIONS, listMap);300 boolean result =301 testScenario(302 getSelfDeclaredMigrateReq(ActorOperations.USER_SELF_DECLARED_TENANT_MIGRATE),303 ResponseCode.parameterMismatch,304 props);305 assert (result);306 }307 public Request getSelfDeclaredMigrateReq(ActorOperations actorOperation) {308 Request reqObj = new Request();309 Map<String, Object> requestMap = new HashMap();310 Map<String, String> externalIdMap = new HashMap();311 List<Map<String, String>> externalIdLst = new ArrayList();312 requestMap.put(JsonKey.USER_ID, "anyUserID");313 requestMap.put(JsonKey.CHANNEL, "anyChannel");314 requestMap.put(JsonKey.ROOT_ORG_ID, "anyRootOrgId");315 externalIdMap.put(JsonKey.ID, "anyID");316 externalIdMap.put(JsonKey.ID_TYPE, "anyIDtype");317 externalIdMap.put(JsonKey.PROVIDER, "anyProvider");318 externalIdLst.add(externalIdMap);319 requestMap.put(JsonKey.EXTERNAL_IDS, externalIdLst);320 requestMap.put(JsonKey.ORG_EXTERNAL_ID, "anyOrgId");321 requestMap.put(JsonKey.STATUS, ProjectUtil.Status.ACTIVE.getValue());322 reqObj.setRequest(requestMap);323 reqObj.setOperation(actorOperation.getValue());324 return reqObj;325 }326 private static Response getSelfDeclarationResponse() {327 Response response = new Response();328 Map<String, Object> responseMap = new HashMap<>();329 responseMap.put(JsonKey.ORG_ID, "anyOrgID");330 responseMap.put(JsonKey.PERSONA, "anyPersona");331 responseMap.put(Constants.RESPONSE, Arrays.asList(responseMap));332 response.getResult().putAll(responseMap);333 return response;334 }335}...

Full Screen

Full Screen

Source:TenantMigrationServiceImplTest.java Github

copy

Full Screen

1package org.sunbird.service.user.impl;2import static org.junit.Assert.assertTrue;3import static org.mockito.Mockito.when;4import static org.powermock.api.mockito.PowerMockito.mock;5import static org.powermock.api.mockito.PowerMockito.whenNew;6import java.util.*;7import org.junit.Before;8import org.junit.Test;9import org.junit.runner.RunWith;10import org.mockito.Mockito;11import org.powermock.api.mockito.PowerMockito;12import org.powermock.core.classloader.annotations.PowerMockIgnore;13import org.powermock.core.classloader.annotations.PrepareForTest;14import org.powermock.modules.junit4.PowerMockRunner;15import org.sunbird.cassandra.CassandraOperation;16import org.sunbird.cassandraimpl.CassandraOperationImpl;17import org.sunbird.exception.ProjectCommonException;18import org.sunbird.exception.ResponseCode;19import org.sunbird.helper.ServiceFactory;20import org.sunbird.keys.JsonKey;21import org.sunbird.request.Request;22import org.sunbird.request.RequestContext;23import org.sunbird.response.Response;24import org.sunbird.service.organisation.OrgExternalService;25import org.sunbird.service.organisation.OrgService;26import org.sunbird.service.organisation.impl.OrgExternalServiceImpl;27import org.sunbird.service.organisation.impl.OrgServiceImpl;28import org.sunbird.service.user.TenantMigrationService;29import org.sunbird.service.user.UserService;30import org.sunbird.util.DataCacheHandler;31@RunWith(PowerMockRunner.class)32@PrepareForTest({33 ServiceFactory.class,34 CassandraOperationImpl.class,35 UserServiceImpl.class,36 UserService.class,37 OrgServiceImpl.class,38 OrgService.class,39 OrgExternalService.class,40 DataCacheHandler.class41})42@PowerMockIgnore({43 "javax.management.*",44 "javax.net.ssl.*",45 "javax.security.*",46 "jdk.internal.reflect.*",47 "javax.crypto.*"48})49public class TenantMigrationServiceImplTest {50 private CassandraOperation cassandraOperation = null;51 private static OrgExternalServiceImpl orgExternalService;52 @Before53 public void beforeEachTest() throws Exception {54 PowerMockito.mockStatic(ServiceFactory.class);55 PowerMockito.mockStatic(UserServiceImpl.class);56 PowerMockito.mockStatic(OrgServiceImpl.class);57 PowerMockito.mockStatic(OrgExternalServiceImpl.class);58 cassandraOperation = mock(CassandraOperationImpl.class);59 PowerMockito.when(ServiceFactory.getInstance()).thenReturn(cassandraOperation);60 Response updateResponse = new Response();61 updateResponse.getResult().put(JsonKey.RESPONSE, "SUCCESS");62 UserService userService = mock(UserServiceImpl.class);63 PowerMockito.when(UserServiceImpl.getInstance()).thenReturn(userService);64 OrgService orgService = mock(OrgServiceImpl.class);65 PowerMockito.when(OrgServiceImpl.getInstance()).thenReturn(orgService);66 when(orgService.getOrgById(Mockito.anyString(), Mockito.any(RequestContext.class)))67 .thenReturn(getOrgandLocation());68 orgExternalService = PowerMockito.mock(OrgExternalServiceImpl.class);69 whenNew(OrgExternalServiceImpl.class).withNoArguments().thenReturn(orgExternalService);70 when(orgExternalService.getOrgIdFromOrgExternalIdAndProvider(71 Mockito.anyString(), Mockito.anyString(), Mockito.any(RequestContext.class)))72 .thenReturn("anyRootOrgId");73 PowerMockito.when(74 cassandraOperation.updateRecord(75 Mockito.any(), Mockito.any(), Mockito.anyMap(), Mockito.any()))76 .thenReturn(updateResponse);77 PowerMockito.when(78 cassandraOperation.getRecordsByCompositeKey(79 Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.any()))80 .thenReturn(getRecordsByProperty(true));81 PowerMockito.mockStatic(DataCacheHandler.class);82 Map<String, String> dataCache = new HashMap<>();83 dataCache.put(JsonKey.CUSTODIAN_ORG_ID, "anyRootOrgId");84 PowerMockito.when(DataCacheHandler.getConfigSettings()).thenReturn(dataCache);85 }86 @Test87 public void migrateUser() {88 List<Map<String, Object>> listMap = new ArrayList<>();89 listMap.add(new HashMap<String, Object>());90 Map<String, Object> userDetails = new HashMap<>();91 userDetails.put(JsonKey.ROOT_ORG_ID, "");92 userDetails.put(JsonKey.ORGANISATIONS, listMap);93 TenantMigrationService tenantMigrationService = TenantMigrationServiceImpl.getInstance();94 tenantMigrationService.migrateUser(userDetails, new RequestContext());95 }96 @Test97 public void validateChannelAndGetRootOrgId() {98 List<Map<String, Object>> listMap = new ArrayList<>();99 listMap.add(new HashMap<String, Object>());100 Map<String, Object> userDetails = new HashMap<>();101 userDetails.put(JsonKey.ROOT_ORG_ID, "");102 userDetails.put(JsonKey.ORGANISATIONS, listMap);103 TenantMigrationService tenantMigrationService = TenantMigrationServiceImpl.getInstance();104 tenantMigrationService.validateChannelAndGetRootOrgId(getSelfDeclaredMigrateReq());105 }106 @Test107 public void validateUserCustodianOrgId() {108 TenantMigrationService tenantMigrationService = TenantMigrationServiceImpl.getInstance();109 tenantMigrationService.validateUserCustodianOrgId("anyRootOrgId");110 }111 @Test112 public void validateInvalidUserCustodianOrgId() {113 PowerMockito.mockStatic(DataCacheHandler.class);114 Map<String, String> dataCache = new HashMap<>();115 dataCache.put(JsonKey.CUSTODIAN_ORG_ID, "newRootOrgId");116 PowerMockito.when(DataCacheHandler.getConfigSettings()).thenReturn(dataCache);117 TenantMigrationService tenantMigrationService = TenantMigrationServiceImpl.getInstance();118 try {119 tenantMigrationService.validateUserCustodianOrgId("anyRootOrgId");120 } catch (ProjectCommonException pe) {121 assertTrue(pe.getResponseCode() == ResponseCode.parameterMismatch);122 }123 }124 @Test125 public void validateOrgExternalIdOrOrgIdAndGetOrgId() {126 List<Map<String, Object>> listMap = new ArrayList<>();127 listMap.add(new HashMap<String, Object>());128 Map<String, Object> userDetails = new HashMap<>();129 userDetails.put(JsonKey.ROOT_ORG_ID, "");130 userDetails.put(JsonKey.ORGANISATIONS, listMap);131 TenantMigrationService tenantMigrationService = TenantMigrationServiceImpl.getInstance();132 tenantMigrationService.validateOrgExternalIdOrOrgIdAndGetOrgId(133 getSelfDeclaredMigrateReq().getRequest(), new RequestContext());134 }135 @Test136 public void deactivateUserFromKC() {137 List<Map<String, Object>> listMap = new ArrayList<>();138 listMap.add(new HashMap<String, Object>());139 Map<String, Object> userDetails = new HashMap<>();140 userDetails.put(JsonKey.ROOT_ORG_ID, "");141 userDetails.put(JsonKey.ORGANISATIONS, listMap);142 TenantMigrationService tenantMigrationService = TenantMigrationServiceImpl.getInstance();143 tenantMigrationService.deactivateUserFromKC("anyUserID", new RequestContext());144 }145 @Test146 public void updateUserOrg() {147 List<Map<String, Object>> listMap = new ArrayList<>();148 listMap.add(new HashMap<String, Object>());149 Map<String, Object> userDetails = new HashMap<>();150 userDetails.put(JsonKey.ROOT_ORG_ID, "");151 userDetails.put(JsonKey.ORGANISATIONS, listMap);152 TenantMigrationService tenantMigrationService = TenantMigrationServiceImpl.getInstance();153 tenantMigrationService.updateUserOrg(getSelfDeclaredMigrateReq(), listMap);154 }155 @Test156 public void updateUserOrgSoftDelete() {157 List<Map<String, Object>> listMap = new ArrayList<>();158 listMap.add(new HashMap<String, Object>());159 Map<String, Object> userDetails = new HashMap<>();160 userDetails.put(JsonKey.ROOT_ORG_ID, "");161 userDetails.put(JsonKey.ORGANISATIONS, listMap);162 TenantMigrationService tenantMigrationService = TenantMigrationServiceImpl.getInstance();163 Request reqObj = new Request();164 Map<String, Object> requestMap = new HashMap();165 requestMap.put(JsonKey.USER_ID, "anyUserID");166 requestMap.put(JsonKey.CHANNEL, "anyChannel");167 requestMap.put(JsonKey.ROOT_ORG_ID, "anyRootOrgId");168 requestMap.put(JsonKey.SOFT_DELETE_PREVIOUS_ORG, true);169 reqObj.setRequest(requestMap);170 tenantMigrationService.updateUserOrg(reqObj, listMap);171 }172 public Request getSelfDeclaredMigrateReq() {173 Request reqObj = new Request();174 Map<String, Object> requestMap = new HashMap();175 Map<String, String> externalIdMap = new HashMap();176 List<Map<String, String>> externalIdLst = new ArrayList();177 requestMap.put(JsonKey.USER_ID, "anyUserID");178 requestMap.put(JsonKey.CHANNEL, "anyChannel");179 requestMap.put(JsonKey.ROOT_ORG_ID, "anyRootOrgId");180 externalIdMap.put(JsonKey.ID, "anyID");181 externalIdMap.put(JsonKey.ID_TYPE, "anyIDtype");182 externalIdMap.put(JsonKey.PROVIDER, "anyProvider");183 externalIdLst.add(externalIdMap);184 requestMap.put(JsonKey.EXTERNAL_IDS, externalIdLst);185 requestMap.put(JsonKey.ORG_EXTERNAL_ID, "anyOrgId");186 reqObj.setRequest(requestMap);187 return reqObj;188 }189 public Map<String, Object> getOrgandLocation() {190 Map<String, Object> map = new HashMap<>();191 map.put(JsonKey.ORG_ID, "anyOrgId");192 map.put(JsonKey.LOCATION_IDS, new ArrayList<String>(Arrays.asList("anyLocationId")));193 return map;194 }195 private Response getRecordsByProperty(boolean empty) {196 Response res = new Response();197 List<Map<String, Object>> list = new ArrayList<>();198 if (empty) {199 Map<String, Object> map = new HashMap<>();200 map.put(JsonKey.ID, "orgId");201 map.put(JsonKey.ORG_ID, "orgId");202 map.put(JsonKey.IS_DELETED, true);203 map.put(JsonKey.CHANNEL, "channel1");204 map.put(JsonKey.IS_TENANT, true);205 list.add(map);206 }207 res.put(JsonKey.RESPONSE, list);208 return res;209 }210}...

Full Screen

Full Screen

ListMap

Using AI Code Generation

copy

Full Screen

1import org.powermock.core.classloader.annotations.PrepareForTest;2import org.powermock.modules.junit4.PowerMockRunner;3import org.powermock.reflect.Whitebox;4import org.junit.Before;5import org.junit.Test;6import org.junit.runner.RunWith;7import static org.junit.Assert.assertEquals;8import static org.powermock.api.mockito.PowerMockito.*;9import java.util.List;10import java.util.Map;11import java.util.ArrayList;12import java.util.HashMap;13import java.util.Iterator;14@RunWith(PowerMockRunner.class)15@PrepareForTest({ListMap.class})16public class ListMapTest {17 private ListMap listMap;18 private List<String> list;19 private Map<String, String> map;20 public void setup() {21 listMap = new ListMap();22 list = new ArrayList<String>();23 map = new HashMap<String, String>();24 }25 public void testListMap() {26 list.add("test");27 map.put("test", "test");28 listMap.setList(list);29 listMap.setMap(map);30 assertEquals(list, listMap.getList());31 assertEquals(map, listMap.getMap());32 }33 public void testListMap2() {34 list.add("test");35 map.put("test", "test");36 listMap.setList(list);37 listMap.setMap(map);38 assertEquals(list, listMap.getList());39 assertEquals(map, listMap.getMap());40 }41 public void testListMap3() {42 list.add("test");43 map.put("test", "test");44 listMap.setList(list);45 listMap.setMap(map);46 assertEquals(list, listMap.getList());47 assertEquals(map, listMap.getMap());48 }49 public void testListMap4() {50 list.add("test");51 map.put("test", "test");52 listMap.setList(list);53 listMap.setMap(map);54 assertEquals(list, listMap.getList());55 assertEquals(map, listMap.getMap());56 }57 public void testListMap5() {58 list.add("test");59 map.put("test", "test");60 listMap.setList(list);61 listMap.setMap(map);62 assertEquals(list, listMap.getList());63 assertEquals(map, listMap.getMap());64 }65}

Full Screen

Full Screen

ListMap

Using AI Code Generation

copy

Full Screen

1import org.powermock.core.classloader.annotations.PrepareForTest;2import org.powermock.modules.junit4.PowerMockRunner;3import org.powermock.reflect.Whitebox;4import org.junit.Test;5import org.junit.runner.RunWith;6import static org.junit.Assert.*;7import java.util.*;8import java.lang.reflect.Field;9import java.lang.reflect.Method;10@RunWith(PowerMockRunner.class)11@PrepareForTest(ListMap.class)12public class ListMapTest {13 public void testListMap() throws Exception {14 ListMap listMap = new ListMap();15 List list = new ArrayList();16 list.add(1);17 list.add(2);18 list.add(3);19 list.add(4);20 list.add(5);21 list.add(6);22 list.add(7);23 list.add(8);24 list.add(9);25 list.add(10);26 list.add(11);27 list.add(12);28 list.add(13);29 list.add(14);30 list.add(15);31 list.add(16);32 list.add(17);33 list.add(18);34 list.add(19);35 list.add(20);36 list.add(21);37 list.add(22);38 list.add(23);39 list.add(24);40 list.add(25);41 list.add(26);42 list.add(27);43 list.add(28);44 list.add(29);45 list.add(30);46 list.add(31);47 list.add(32);48 list.add(33);49 list.add(34);50 list.add(35);51 list.add(36);52 list.add(37);53 list.add(38);54 list.add(39);55 list.add(40);56 list.add(41);57 list.add(42);58 list.add(43);59 list.add(44);60 list.add(45);61 list.add(46);62 list.add(47);63 list.add(48);64 list.add(49);65 list.add(50);66 list.add(51);67 list.add(52);68 list.add(53);69 list.add(54);70 list.add(55);71 list.add(56);72 list.add(57);73 list.add(58);74 list.add(59);75 list.add(60);76 list.add(61);77 list.add(62);78 list.add(63);

Full Screen

Full Screen

ListMap

Using AI Code Generation

copy

Full Screen

1package org.powermock.core;2import java.util.ArrayList;3import java.util.Collection;4import java.util.HashMap;5import java.util.List;6import java.util.Map;7import java.util.Set;8import java.util.Map.Entry;9public class ListMap<K, V> implements Map<K, V> {10 private final Map<K, List<V>> map = new HashMap<K, List<V>>();11 public void clear() {12 map.clear();13 }14 public boolean containsKey(Object key) {15 return map.containsKey(key);16 }17 public boolean containsValue(Object value) {18 for (List<V> list : map.values()) {19 if (list.contains(value)) {20 return true;21 }22 }23 return false;24 }25 public Set<Entry<K, V>> entrySet() {26 throw new UnsupportedOperationException();27 }28 public V get(Object key) {29 List<V> list = map.get(key);30 return list == null ? null : list.get(0);31 }32 public boolean isEmpty() {33 return map.isEmpty();34 }35 public Set<K> keySet() {36 return map.keySet();37 }38 public V put(K key, V value) {39 List<V> list = map.get(key);40 if (list == null) {41 list = new ArrayList<V>();42 map.put(key, list);43 }44 list.add(value);45 return value;46 }47 public void putAll(Map<? extends K, ? extends V> t) {48 for (Entry<? extends K, ? extends V> entry : t.entrySet()) {49 put(entry.getKey(), entry.getValue());50 }51 }52 public V remove(Object key) {53 List<V> list = map.get(key);54 if (list == null) {55 return null;56 }57 V value = list.remove(0);58 if (list.isEmpty()) {59 map.remove(key);60 }61 return value;62 }63 public int size() {64 int size = 0;65 for (List<V> list : map.values()) {66 size += list.size();67 }68 return size;69 }70 public Collection<V> values() {71 List<V> values = new ArrayList<V>();72 for (List<V> list : map.values()) {73 values.addAll(list);74 }75 return values;76 }77}

Full Screen

Full Screen

ListMap

Using AI Code Generation

copy

Full Screen

1package org.powermock.core;2import java.util.*;3{4 private Map map;5 public ListMap()6 {7 map = new HashMap();8 }9 public void add(String key, Object value)10 {11 List list = (List)map.get(key);12 if(list == null)13 {14 list = new ArrayList();15 map.put(key, list);16 }17 list.add(value);18 }19 public List get(String key)20 {21 return (List)map.get(key);22 }23}24package org.powermock.core;25import java.util.*;26{27 private Map map;28 public ListMap()29 {30 map = new HashMap();31 }32 public void add(String key, Object value)33 {34 List list = (List)map.get(key);35 if(list == null)36 {37 list = new ArrayList();38 map.put(key, list);39 }40 list.add(value);41 }42 public List get(String key)43 {44 return (List)map.get(key);45 }46}47package org.powermock.core;48import java.util.*;49{50 private Map map;51 public ListMap()52 {53 map = new HashMap();54 }55 public void add(String key, Object value)56 {57 List list = (List)map.get(key);58 if(list == null)59 {60 list = new ArrayList();61 map.put(key, list);62 }63 list.add(value);64 }65 public List get(String key)66 {67 return (List)map.get(key);68 }69}70package org.powermock.core;71import java.util.*;72{73 private Map map;74 public ListMap()75 {76 map = new HashMap();77 }78 public void add(String key, Object value)79 {80 List list = (List)map.get(key);81 if(list == null)82 {83 list = new ArrayList();84 map.put(key, list);85 }86 list.add(value);87 }88 public List get(String key)89 {90 return (List)map.get

Full Screen

Full Screen

ListMap

Using AI Code Generation

copy

Full Screen

1import org.powermock.core.ListMap;2import java.util.*;3{4 public static void main(String args[])5 {6 ListMap<Integer, String> lmap = new ListMap<Integer, String>();7 lmap.put(1, "one");8 lmap.put(2, "two");9 lmap.put(3, "three");10 lmap.put(4, "four");11 lmap.put(5, "five");12 lmap.put(6, "six");13 lmap.put(7, "seven");14 lmap.put(8, "eight");15 lmap.put(9, "nine");16 lmap.put(10, "ten");17 System.out.println("ListMap: " + lmap);18 System.out.println("Size: " + lmap.size());19 System.out.println("Contains key 9? " + lmap.containsKey(9));20 System.out.println("Contains key 12? " + lmap.containsKey(12));21 System.out.println("Contains value 'nine'? " + lmap.containsValue("nine"));22 System.out.println("Contains value 'twelve'? " + lmap.containsValue("twelve"));23 System.out.println("Get value for key 4: " + lmap.get(4));24 System.out.println("Get value for key 11: " + lmap.get(11));25 System.out.println("Remove key 5: " + lmap.remove(5));26 System.out.println("ListMap: " + lmap);27 System.out.println("Size: " + lmap.size());28 System.out.println("Remove key 11: " + lmap.remove(11));29 System.out.println("ListMap: " + lmap);30 System.out.println("Size: " + lmap.size());31 System.out.println("Remove key 1: " + lmap.remove(1));32 System.out.println("ListMap: " + lmap);33 System.out.println("Size: " + lmap.size());34 System.out.println("Remove key 10: " + lmap.remove(10));35 System.out.println("ListMap: " + lmap);36 System.out.println("Size: " + lmap.size());37 System.out.println("Remove key 10: " + lmap.remove(10));38 System.out.println("ListMap: " + lmap);39 System.out.println("

Full Screen

Full Screen

ListMap

Using AI Code Generation

copy

Full Screen

1package org.powermock.core;2import java.util.Map;3import java.util.List;4import java.util.HashMap;5import java.util.ArrayList;6import java.util.LinkedList;7import java.util.Set;8import java.util.HashSet;9import java.util.TreeMap;10import java.util.TreeSet;11import java.util.Collections;12import java.util.Collection;13import java.util.Iterator;14import java.util.Properties;15public class ListMap extends HashMap {16 public ListMap() {17 super();18 }19 public ListMap(int initialCapacity) {20 super(initialCapacity);21 }22 public ListMap(int initialCapacity, float loadFactor) {23 super(initialCapacity, loadFactor);24 }25 public ListMap(Map t) {26 super(t);27 }28 public ListMap(Properties properties) {29 super();30 Iterator keys = properties.keySet().iterator();31 while (keys.hasNext()) {32 String key = (String) keys.next();33 String value = properties.getProperty(key);34 add(key, value);35 }36 }37 public void add(Object key, Object value) {38 List values = (List) get(key);39 if (values == null) {40 values = new ArrayList();41 put(key, values);42 }43 values.add(value);44 }45 public void add(Object key, int index, Object value) {46 List values = (List) get(key);47 if (values == null) {48 values = new ArrayList();49 put(key, values);50 }51 values.add(index, value);52 }53 public void addAll(Object key, Collection values) {54 List currentValues = (List) get(key);55 if (currentValues == null) {56 currentValues = new ArrayList();57 put(key, currentValues);58 }59 currentValues.addAll(values);60 }61 public void addAll(Map map) {62 Iterator keys = map.keySet().iterator();63 while (keys.hasNext()) {64 Object key = keys.next();65 Object value = map.get(key);66 if (value instanceof Collection) {67 addAll(key, (Collection) value);68 } else {69 add(key, value);70 }71 }72 }73 public void addAll(ListMap map) {74 addAll((Map) map);75 }76 public Object removeFirst(Object key) {77 List values = (List) get(key);78 if (values == null || values.size() == 0) {79 return null;80 }

Full Screen

Full Screen

ListMap

Using AI Code Generation

copy

Full Screen

1package org.powermock.core;2import java.util.Map;3import java.util.HashMap;4import java.util.Iterator;5{6 private Map listMap;7 public ListMap()8 {9 listMap = new HashMap();10 }11 public void put(Object key, Object value)12 {13 super.put(key, value);14 listMap.put(key, value);15 }16 public void putAll(Map map)17 {18 super.putAll(map);19 listMap.putAll(map);20 }21 public Object remove(Object key)22 {23 Object value = super.remove(key);24 listMap.remove(key);25 return value;26 }27 public Iterator iterator()28 {29 return listMap.values().iterator();30 }31}32package org.powermock.core;33import java.util.Map;34import java.util.HashMap;35import java.util.Iterator;36{37 private Map listMap;38 public ListMap()39 {40 listMap = new HashMap();41 }42 public void put(Object key, Object value)43 {44 super.put(key, value);45 listMap.put(key, value);46 }47 public void putAll(Map map)48 {49 super.putAll(map);50 listMap.putAll(map);51 }52 public Object remove(Object key)53 {54 Object value = super.remove(key);55 listMap.remove(key);56 return value;57 }58 public Iterator iterator()59 {60 return listMap.values().iterator();61 }62}63package org.powermock.core;64import java.util.Map;65import java.util.HashMap;66import java.util.Iterator;67{68 private Map listMap;69 public ListMap()70 {71 listMap = new HashMap();72 }73 public void put(Object key, Object value)74 {75 super.put(key, value);76 listMap.put(key, value);77 }78 public void putAll(Map map)79 {80 super.putAll(map);81 listMap.putAll(map);82 }83 public Object remove(Object key)84 {85 Object value = super.remove(key);86 listMap.remove(key);87 return value;88 }89 public Iterator iterator()90 {91 return listMap.values().iterator();92 }93}94 {95 list = new ArrayList();96 map.put(key, list);97 }98 list.add(value);99 }100 public List get(String key)101 {102 return (List)map.get(key);103 }104}105package org.powermock.core;106import java.util.*;107{108 private Map map;109 public ListMap()110 {111 map = new HashMap();112 }113 public void add(String key, Object value)114 {115 List list = (List)map.get(key);116 if(list == null)117 {118 list = new ArrayList();119 map.put(key, list);120 }121 list.add(value);122 }123 public List get(String key)124 {125 return (List)map.get(key);126 }127}128package org.powermock.core;129import java.util.*;130{131 private Map map;132 public ListMap()133 {134 map = new HashMap();135 }136 public void add(String key, Object value)137 {138 List list = (List)map.get(key);139 if(list == null)140 {141 list = new ArrayList();142 map.put(key, list);143 }144 list.add(value);145 }146 public List get(String key)147 {148 return (List)map.get

Full Screen

Full Screen

ListMap

Using AI Code Generation

copy

Full Screen

1import org.powermock.core.ListMap;2import java.util.*;3{4 public static void main(String args[])5 {6 ListMap<Integer, String> lmap = new ListMap<Integer, String>();7 lmap.put(1, "one");8 lmap.put(2, "two");9 lmap.put(3, "three");10 lmap.put(4, "four");11 lmap.put(5, "five");12 lmap.put(6, "six");13 lmap.put(7, "seven");14 lmap.put(8, "eight");15 lmap.put(9, "nine");16 lmap.put(10, "ten");17 System.out.println("ListMap: " + lmap);18 System.out.println("Size: " + lmap.size());19 System.out.println("Contains key 9? " + lmap.containsKey(9));20 System.out.println("Contains key 12? " + lmap.containsKey(12));21 System.out.println("Contains value 'nine'? " + lmap.containsValue("nine"));22 System.out.println("Contains value 'twelve'? " + lmap.containsValue("twelve"));23 System.out.println("Get value for key 4: " + lmap.get(4));24 System.out.println("Get value for key 11: " + lmap.get(11));25 System.out.println("Remove key 5: " + lmap.remove(5));26 System.out.println("ListMap: " + lmap);27 System.out.println("Size: " + lmap.size());28 System.out.println("Remove key 11: " + lmap.remove(11));29 System.out.println("ListMap: " + lmap);30 System.out.println("Size: " + lmap.size());31 System.out.println("Remove key 1: " + lmap.remove(1));32 System.out.println("ListMap: " + lmap);33 System.out.println("Size: " + lmap.size());34 System.out.println("Remove key 10: " + lmap.remove(10));35 System.out.println("ListMap: " + lmap);36 System.out.println("Size: " + lmap.size());37 System.out.println("Remove key 10: " + lmap.remove(10));38 System.out.println("ListMap: " + lmap);39 System.out.println("

Full Screen

Full Screen

ListMap

Using AI Code Generation

copy

Full Screen

1package org.powermock.core;2import java.util.ArrayList;3import java.util.Collection;4import java.util.HashMap;5import java.util.List;6import java.util.Map;7import java.util.Set;8import java.util.Map.Entry;9public class ListMap<K, V> implements Map<K, V> {10 private final Map<K, List<V>> map = new HashMap<K, List<V>>();11 public void clear() {12 map.clear();13 }14 public boolean containsKey(Object key) {15 return map.containsKey(key);16 }17 public boolean containsValue(Object value) {18 for (List<V> list : map.values()) {19 if (list.contains(value)) {20 return true;21 }22 }23 return false;24 }25 public Set<Entry<K, V>> entrySet() {26 throw new UnsupportedOperationException();27 }28 public V get(Object key) {29 List<V> list = map.get(key);30 return list == null ? null : list.get(0);31 }32 public boolean isEmpty() {33 return map.isEmpty();34 }35 public Set<K> keySet() {36 return map.keySet();37 }38 public V put(K key, V value) {39 List<V> list = map.get(key);40 if (list == null) {41 list = new ArrayList<V>();42 map.put(key, list);43 }44 list.add(value);45 return value;46 }47 public void putAll(Map<? extends K, ? extends V> t) {48 for (Entry<? extends K, ? extends V> entry : t.entrySet()) {49 put(entry.getKey(), entry.getValue());50 }51 }52 public V remove(Object key) {53 List<V> list = map.get(key);54 if (list == null) {55 return null;56 }57 V value = list.remove(0);58 if (list.isEmpty()) {59 map.remove(key);60 }61 return value;62 }63 public int size() {64 int size = 0;65 for (List<V> list : map.values()) {66 size += list.size();67 }68 return size;69 }70 public Collection<V> values() {71 List<V> values = new ArrayList<V>();72 for (List<V> list : map.values()) {73 values.addAll(list);74 }75 return values;76 }77}

Full Screen

Full Screen

ListMap

Using AI Code Generation

copy

Full Screen

1import org.powermock.core.ListMap;2import java.util.*;3{4 public static void main(String args[])5 {6 ListMap<Integer, String> lmap = new ListMap<Integer, String>();7 lmap.put(1, "one");8 lmap.put(2, "two");9 lmap.put(3, "three");10 lmap.put(4, "four");11 lmap.put(5, "five");12 lmap.put(6, "six");13 lmap.put(7, "seven");14 lmap.put(8, "eight");15 lmap.put(9, "nine");16 lmap.put(10, "ten");17 System.out.println("ListMap: " + lmap);18 System.out.println("Size: " + lmap.size());19 System.out.println("Contains key 9? " + lmap.containsKey(9));20 System.out.println("Contains key 12? " + lmap.containsKey(12));21 System.out.println("Contains value 'nine'? " + lmap.containsValue("nine"));22 System.out.println("Contains value 'twelve'? " + lmap.containsValue("twelve"));23 System.out.println("Get value for key 4: " + lmap.get(4));24 System.out.println("Get value for key 11: " + lmap.get(11));25 System.out.println("Remove key 5: " + lmap.remove(5));26 System.out.println("ListMap: " + lmap);27 System.out.println("Size: " + lmap.size());28 System.out.println("Remove key 11: " + lmap.remove(11));29 System.out.println("ListMap: " + lmap);30 System.out.println("Size: " + lmap.size());31 System.out.println("Remove key 1: " + lmap.remove(1));32 System.out.println("ListMap: " + lmap);33 System.out.println("Size: " + lmap.size());34 System.out.println("Remove key 10: " + lmap.remove(10));35 System.out.println("ListMap: " + lmap);36 System.out.println("Size: " + lmap.size());37 System.out.println("Remove key 10: " + lmap.remove(10));38 System.out.println("ListMap: " + lmap);39 System.out.println("

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Powermock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful