OrgExternalService { public String getOrgIdFromOrgExternalIdAndProvider(String externalId, String provider) { Map<String, Object> dbRequestMap = new HashMap<>(); dbRequestMap.put(JsonKey.EXTERNAL_ID, externalId.toLowerCase()); dbRequestMap.put(JsonKey.PROVIDER, provider.toLowerCase()); Response response = getCassandraOperation().getRecordsByCompositeKey( KEYSPACE_NAME, ORG_EXTERNAL_IDENTITY, dbRequestMap); List<Map<String, Object>> orgList = (List<Map<String, Object>>) response.getResult().get(JsonKey.RESPONSE); if (CollectionUtils.isNotEmpty(orgList)) { Map<String, Object> orgExternalMap = orgList.get(0); if (MapUtils.isNotEmpty(orgExternalMap)) { return (String) orgExternalMap.get(JsonKey.ORG_ID); } } return null; }  String getOrgIdFromOrgExternalIdAndProvider(String externalId, String provider);  }
@Test public void testGetOrgIdFromOrgExtIdFailure() { try { Map<String, Object> dbRequestMap = new HashMap<>(); dbRequestMap.put(JsonKey.EXTERNAL_ID, "anyorgextid"); dbRequestMap.put(JsonKey.PROVIDER, "anyprovider"); Response response = new Response(); List<Map<String, Object>> orgList =new ArrayList<>(); Map<String,Object>map=new HashMap<>(); orgList.add(map); response.put(JsonKey.RESPONSE, orgList); when(cassandraOperation.getRecordsByCompositeKey(Util.KEY_SPACE_NAME, ORG_EXTERNAL_IDENTITY, dbRequestMap)).thenReturn(response); String resp = orgExternalService.getOrgIdFromOrgExternalIdAndProvider("anyOrgExtid", "anyprovider"); Assert.assertEquals(null, resp); } catch (Exception e) { Assert.assertTrue(false); } }
@Test public void testGetOrgIdFromOrgExtIdSuccess() { try { Map<String, Object> dbRequestMap = new HashMap<>(); dbRequestMap.put(JsonKey.EXTERNAL_ID, "orgextid"); dbRequestMap.put(JsonKey.PROVIDER, "provider"); Response response = new Response(); List<Map<String, Object>> orgList =new ArrayList<>(); Map<String,Object>map=new HashMap<>(); map.put(JsonKey.ORG_ID,"anyOrgId"); orgList.add(map); response.put(JsonKey.RESPONSE, orgList); when(cassandraOperation.getRecordsByCompositeKey(Util.KEY_SPACE_NAME, ORG_EXTERNAL_IDENTITY, dbRequestMap)).thenReturn(response); String resp = orgExternalService.getOrgIdFromOrgExternalIdAndProvider("OrgExtid", "provider"); Assert.assertEquals("anyOrgId", resp); } catch (Exception e) { Assert.assertTrue(false); } }