@Test public void testTransform() { final JSONObject request = new JSONObject(); final String personName1 = "personName1"; final String personName2 = "personName2"; final JSONObject personObj1 = new JSONObject(); personObj1.accumulate("type", "PERSON"); personObj1.accumulate("name", personName1); final JSONObject personObj2 = new JSONObject(); personObj2.accumulate("type", "PERSON"); personObj2.accumulate("name", personName2); JSONArray recipientArr = new JSONArray(); recipientArr.add(personObj1); recipientArr.add(personObj2); request.accumulate(key, recipientArr); final Long personId1 = 4L; final Long personId2 = 5L; final ArrayList<String> expectedAccountIds = new ArrayList<String>(); expectedAccountIds.add(personName1); expectedAccountIds.add(personName2); final List<Long> ids = new ArrayList<Long>(); ids.add(personId1); ids.add(personId2); context.checking(new Expectations() { { oneOf(getPeopleIdsByAccountIdsMapper).execute(with(expectedAccountIds)); will(returnValue(ids)); } }); List<Long> results = (List<Long>) sut.transform(request, 0L); Assert.assertEquals(2, results.size()); Assert.assertEquals(personId1, results.get(0)); Assert.assertEquals(personId2, results.get(1)); context.assertIsSatisfied(); }
public Serializable transform(final JSONObject request, final Long userEntityId) { JSONArray entities = request.getJSONArray(reqKey); List<String> accountIds = new ArrayList<String>(); for (int i = 0; i < entities.size(); i++) { JSONObject req = entities.getJSONObject(i); EntityType type = EntityType.valueOf(req.getString("type")); switch (type) { case PERSON: accountIds.add(req.getString("name")); break; default: throw new IllegalArgumentException("Unhandled type."); } } return new ArrayList<Long>(getPeopleIdsByAccountIdsMapper.execute(accountIds)); }
MultiUserPersistenceRequestTransformer implements PersistenceDataSourceRequestTransformer { public Serializable transform(final JSONObject request, final Long userEntityId) { JSONArray entities = request.getJSONArray(reqKey); List<String> accountIds = new ArrayList<String>(); for (int i = 0; i < entities.size(); i++) { JSONObject req = entities.getJSONObject(i); EntityType type = EntityType.valueOf(req.getString("type")); switch (type) { case PERSON: accountIds.add(req.getString("name")); break; default: throw new IllegalArgumentException("Unhandled type."); } } return new ArrayList<Long>(getPeopleIdsByAccountIdsMapper.execute(accountIds)); } }
MultiUserPersistenceRequestTransformer implements PersistenceDataSourceRequestTransformer { public Serializable transform(final JSONObject request, final Long userEntityId) { JSONArray entities = request.getJSONArray(reqKey); List<String> accountIds = new ArrayList<String>(); for (int i = 0; i < entities.size(); i++) { JSONObject req = entities.getJSONObject(i); EntityType type = EntityType.valueOf(req.getString("type")); switch (type) { case PERSON: accountIds.add(req.getString("name")); break; default: throw new IllegalArgumentException("Unhandled type."); } } return new ArrayList<Long>(getPeopleIdsByAccountIdsMapper.execute(accountIds)); } MultiUserPersistenceRequestTransformer(
            final DomainMapper<List<String>, List<Long>> inGetPeopleIdsByAccountIdsMapper, final String inReqKey); }
MultiUserPersistenceRequestTransformer implements PersistenceDataSourceRequestTransformer { public Serializable transform(final JSONObject request, final Long userEntityId) { JSONArray entities = request.getJSONArray(reqKey); List<String> accountIds = new ArrayList<String>(); for (int i = 0; i < entities.size(); i++) { JSONObject req = entities.getJSONObject(i); EntityType type = EntityType.valueOf(req.getString("type")); switch (type) { case PERSON: accountIds.add(req.getString("name")); break; default: throw new IllegalArgumentException("Unhandled type."); } } return new ArrayList<Long>(getPeopleIdsByAccountIdsMapper.execute(accountIds)); } MultiUserPersistenceRequestTransformer(
            final DomainMapper<List<String>, List<Long>> inGetPeopleIdsByAccountIdsMapper, final String inReqKey); Serializable transform(final JSONObject request, final Long userEntityId); }
MultiUserPersistenceRequestTransformer implements PersistenceDataSourceRequestTransformer { public Serializable transform(final JSONObject request, final Long userEntityId) { JSONArray entities = request.getJSONArray(reqKey); List<String> accountIds = new ArrayList<String>(); for (int i = 0; i < entities.size(); i++) { JSONObject req = entities.getJSONObject(i); EntityType type = EntityType.valueOf(req.getString("type")); switch (type) { case PERSON: accountIds.add(req.getString("name")); break; default: throw new IllegalArgumentException("Unhandled type."); } } return new ArrayList<Long>(getPeopleIdsByAccountIdsMapper.execute(accountIds)); } MultiUserPersistenceRequestTransformer(
            final DomainMapper<List<String>, List<Long>> inGetPeopleIdsByAccountIdsMapper, final String inReqKey); Serializable transform(final JSONObject request, final Long userEntityId);  }