RTGovSituationsProvider implements SituationsProvider, ActiveChangeListener { protected MessageBean getMessage(Situation situation) throws UiException { MessageBean ret=null; for (ActivityTypeId id : situation.getActivityTypeIds()) { try { ActivityType at=null; ActivityUnit au=_activityStore.getActivityUnit(id.getUnitId()); if (au != null && id.getUnitIndex() < au.getActivityTypes().size()) { at = au.getActivityTypes().get(id.getUnitIndex()); } if (at instanceof RPCActivityType && ((RPCActivityType)at).isRequest() && ((RPCActivityType)at).getContent() != null) { ret = new MessageBean(); ret.setContent(((RPCActivityType)at).getContent()); configureHeaders(ret, at); ret.setPrincipal(((RPCActivityType)at).getPrincipal()); if (ret.getPrincipal() == null && au.getOrigin() != null) { ret.setPrincipal(au.getOrigin().getPrincipal()); } break; } } catch (Exception e) { throw new UiException("Failed to get message for activity type id '"+id+"'", e); } } return (ret); } RTGovSituationsProvider(); @PostConstruct void init(); String getName(); void addSituationEventListener(SituationEventListener l); void removeSituationEventListener(SituationEventListener l); java.util.List<SituationSummaryBean> search(SituationsFilterBean filters); @Override SituationBean getSituation(String situationId); @Override void resubmit(String situationId, MessageBean message, String username); @Override BatchRetryResult resubmit(SituationsFilterBean situationsFilterBean, String username); @Override java.util.List<SituationSummaryBean> getResubmitFailures(String situationId); @Override void export(SituationsFilterBean situationsFilterBean, OutputStream outputStream); @Override void inserted(Object key, Object value); @Override void updated(Object key, Object value); @Override void removed(Object key, Object value); @Override void assign(String situationId, final String userName); @Override void unassign(String situationId); @Override void updateResolutionState(String situationId, final ResolutionState resolutionState); @Override int delete(SituationsFilterBean situationsFilterBean);  }
@Test public void testGetMessage() { RTGovSituationsProvider provider=new RTGovSituationsProvider(); ActivityStore acts=new MemActivityStore(); provider.setActivityStore(acts); ActivityUnit au=new ActivityUnit(); au.setId(TEST_AU); RequestReceived rr=new RequestReceived(); au.getActivityTypes().add(rr); rr.setContent(TEST_CONTENT); java.util.List<ActivityUnit> aulist=new java.util.ArrayList<ActivityUnit>(); aulist.add(au); try { acts.store(aulist); } catch (Exception e) { fail("Failed to store: "+e.getMessage()); } provider.setSituations(new ActiveList("Test")); provider.init(); Situation sit=new Situation(); sit.getActivityTypeIds().add(new ActivityTypeId(TEST_AU, 0)); try { MessageBean mb=provider.getMessage(sit); if (mb == null) { fail("Message not returned"); } if (mb.getContent() == null) { fail("Message has no content"); } if (!mb.getContent().equals(TEST_CONTENT)) { fail("Content is incorrect: "+mb.getContent()); } } catch (Exception e) { e.printStackTrace(); fail("Get message failed: "+e.getMessage()); } }