JPASituationStore extends AbstractSituationStore implements SituationStore { @SuppressWarnings("unchecked") public List<Situation> getSituations(final SituationsQuery sitQuery) { boolean isOpen=sitQuery.getResolutionState() != null && sitQuery.getResolutionState().equalsIgnoreCase(ResolutionState.OPEN.name()); final String queryString = createQuery("SELECT sit from Situation sit ", sitQuery); List<Situation> situations = _jpaStore.withJpa(new JpaWork<List<Situation>>() { public List<Situation> perform(Session s) { Query query = s.createQuery(queryString); return query.list(); } }); if (isOpen) { sitQuery.setResolutionState(ResolutionState.UNRESOLVED.name()); final String queryString2 = createQuery("SELECT sit from Situation sit ", sitQuery); List<Situation> situations2 = _jpaStore.withJpa(new JpaWork<List<Situation>>() { public List<Situation> perform(Session s) { Query query = s.createQuery(queryString2); return query.list(); } }); if (situations2 != null) { if (situations != null) { situations.addAll(situations2); } else { situations = situations2; } } } if (LOG.isLoggable(Level.FINEST)) { LOG.finest("Situations="+situations); } return (situations); } JPASituationStore();  JPASituationStore(JpaStore jpaStore); @SuppressWarnings("unchecked") List<Situation> getSituations(final SituationsQuery sitQuery); void assignSituation(final String situationId, final String userName); void unassignSituation(final String situationId); void updateResolutionState(final String situationId, final ResolutionState resolutionState); @Override void recordSuccessfulResubmit(final String situationId, final String userName); @Override void recordResubmitFailure(final String situationId, final String errorMessage, final String userName);  }
@Test public void getSituationsByOpenResolutionState() throws Exception { Situation unresolvedSituation = new Situation(); unresolvedSituation.setId("unresolvedSituation"); unresolvedSituation.setTimestamp(System.currentTimeMillis()); persist(unresolvedSituation); Situation openSituation = new Situation(); openSituation.setId("inprogressSituation"); openSituation.setTimestamp(System.currentTimeMillis()); openSituation.getSituationProperties().put("resolutionState", ResolutionState.IN_PROGRESS.name()); persist(openSituation); Situation closedSituation = new Situation(); closedSituation.setId("closedSituation"); closedSituation.setTimestamp(System.currentTimeMillis()); closedSituation.getSituationProperties().put("resolutionState", ResolutionState.RESOLVED.name()); persist(closedSituation); SituationsQuery sitQuery = new SituationsQuery(); sitQuery.setResolutionState(ResolutionState.OPEN.name()); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(2 == situations.size()); Assert.assertTrue(situations.contains(unresolvedSituation)); Assert.assertTrue(situations.contains(openSituation)); }
@Test public void findByEqualsHostText() throws Exception { Situation situation = new Situation(); situation.setId(name.getMethodName()); situation.setSubject(name.getMethodName()); situation.setTimestamp(System.currentTimeMillis()); situation.getSituationProperties().put(SituationStore.HOST_PROPERTY, name.getMethodName()); persist(situation); SituationsQuery sitQuery = new SituationsQuery(); Properties properties = new Properties(); properties.setProperty("host", name.getMethodName()); sitQuery.setProperties(properties); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(1 == situations.size()); Assert.assertEquals(situation.getId(), situations.get(0).getId()); }
@Test public void findLikeHostText() throws Exception { Situation situation = new Situation(); situation.setId(name.getMethodName()); situation.setSubject(name.getMethodName()); situation.setTimestamp(System.currentTimeMillis()); situation.getSituationProperties().put(SituationStore.HOST_PROPERTY, name.getMethodName()); persist(situation); SituationsQuery sitQuery = new SituationsQuery(); Properties properties = new Properties(); properties.setProperty("host", name.getMethodName().substring(3)); sitQuery.setProperties(properties); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(1 == situations.size()); Assert.assertEquals(situation.getId(), situations.get(0).getId()); }
@Test public void findEqualsSubjectText() throws Exception { Situation situation = new Situation(); situation.setId(name.getMethodName()); situation.setSubject(name.getMethodName()); situation.setTimestamp(System.currentTimeMillis()); persist(situation); SituationsQuery sitQuery = new SituationsQuery(); sitQuery.setSubject(name.getMethodName()); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(1 == situations.size()); Assert.assertEquals(situation.getId(), situations.get(0).getId()); }
@Test public void findLikeSubjectText() throws Exception { Situation situation = new Situation(); situation.setId(name.getMethodName()); situation.setSubject(name.getMethodName()); situation.setTimestamp(System.currentTimeMillis()); persist(situation); SituationsQuery sitQuery = new SituationsQuery(); sitQuery.setSubject(name.getMethodName().substring(3)); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(1 == situations.size()); Assert.assertEquals(situation.getId(), situations.get(0).getId()); }
@Test public void findIgnoreCaseSubjectText() throws Exception { Situation situation = new Situation(); situation.setId(name.getMethodName()); situation.setSubject(name.getMethodName().toUpperCase()); situation.setTimestamp(System.currentTimeMillis()); persist(situation); SituationsQuery sitQuery = new SituationsQuery(); sitQuery.setSubject(name.getMethodName().substring(3).toLowerCase()); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(1 == situations.size()); Assert.assertEquals(situation.getId(), situations.get(0).getId()); }
@Test public void findEqualsDescriptionText() throws Exception { Situation situation = new Situation(); situation.setId(name.getMethodName()); situation.setDescription(name.getMethodName()); situation.setTimestamp(System.currentTimeMillis()); persist(situation); SituationsQuery sitQuery = new SituationsQuery(); sitQuery.setDescription(name.getMethodName()); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(1 == situations.size()); Assert.assertEquals(situation.getId(), situations.get(0).getId()); }
@Test public void findEndsWithDescriptionText() throws Exception { Situation situation = new Situation(); situation.setId(name.getMethodName()); situation.setDescription(name.getMethodName()); situation.setTimestamp(System.currentTimeMillis()); persist(situation); SituationsQuery sitQuery = new SituationsQuery(); sitQuery.setDescription(name.getMethodName().substring(5)); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(1 == situations.size()); Assert.assertEquals(situation.getId(), situations.get(0).getId()); }
@Test public void findStartsWithDescriptionText() throws Exception { Situation situation = new Situation(); situation.setId(name.getMethodName()); situation.setDescription(name.getMethodName()); situation.setTimestamp(System.currentTimeMillis()); persist(situation); SituationsQuery sitQuery = new SituationsQuery(); sitQuery.setDescription(name.getMethodName().substring(0, 5)); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(1 == situations.size()); Assert.assertEquals(situation.getId(), situations.get(0).getId()); }
@Test public void findIgnoreCaseDescriptionText() throws Exception { Situation situation = new Situation(); situation.setId(name.getMethodName()); situation.setDescription(name.getMethodName().toLowerCase()); situation.setTimestamp(System.currentTimeMillis()); persist(situation); SituationsQuery sitQuery = new SituationsQuery(); sitQuery.setDescription(name.getMethodName().substring(5).toUpperCase()); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(1 == situations.size()); Assert.assertEquals(situation.getId(), situations.get(0).getId()); }
@Test public void findDescriptionTextNegative() throws Exception { Situation situation = new Situation(); situation.setId(name.getMethodName()); situation.setDescription(name.getMethodName().toLowerCase()); situation.setTimestamp(System.currentTimeMillis()); persist(situation); SituationsQuery sitQuery = new SituationsQuery(); sitQuery.setDescription("other"); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(situations.isEmpty()); }
@Test public void findSituationBySeverity() throws Exception { Situation situation1 = new Situation(); situation1.setId(name.getMethodName()+"1"); situation1.setDescription(name.getMethodName().toLowerCase()); situation1.setTimestamp(System.currentTimeMillis()); situation1.setSeverity(Severity.Critical); persist(situation1); Situation situation2 = new Situation(); situation2.setId(name.getMethodName()+"2"); situation2.setDescription(name.getMethodName().toLowerCase()); situation2.setTimestamp(System.currentTimeMillis()); situation2.setSeverity(Severity.Low); persist(situation2); SituationsQuery sitQuery = new SituationsQuery(); sitQuery.setSeverity(Severity.Low); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(situations.size()==1); Assert.assertTrue(situations.get(0).getId().equals(name.getMethodName()+"2")); }
@Test public void getSituationsByUnresolvedResolutionState() throws Exception { Situation unresolvedSituation = new Situation(); unresolvedSituation.setId("unresolvedSituation"); unresolvedSituation.setTimestamp(System.currentTimeMillis()); persist(unresolvedSituation); SituationsQuery sitQuery = new SituationsQuery(); sitQuery.setResolutionState(ResolutionState.UNRESOLVED.name()); java.util.List<Situation> situations = _situationStore.getSituations(sitQuery); Assert.assertNotNull(situations); Assert.assertTrue(1 == situations.size()); Assert.assertEquals(unresolvedSituation.getId(), situations.get(0).getId()); }
@Test public void deleteSituation() throws Exception { Situation situation = new Situation(); situation.setId("deleteSituation"); situation.setDescription("deleteSituation"); situation.setTimestamp(System.currentTimeMillis()); situation.setSituationProperties(Collections.singletonMap("1", "1")); situation.setContext(Sets.newHashSet(new Context(Context.Type.Conversation, "1"))); situation.setActivityTypeIds(Sets.newHashSet(new ActivityTypeId("1", 0))); persist(situation); SituationsQuery situationQuery = new SituationsQuery(); situationQuery.setDescription(situation.getDescription()); _situationStore.delete(situationQuery); List<Situation> situations = _situationStore.getSituations(situationQuery); assertTrue(situations.isEmpty()); }