JPAActivityStore implements ActivityStore { public List<ActivityType> query(QuerySpec query) throws Exception { if (LOG.isLoggable(Level.FINEST)) { LOG.finest("Query=" + query); } if (query.getFormat() == null || !query.getFormat().equalsIgnoreCase("jpql")) { throw new IllegalArgumentException(MessageFormat.format(java.util.PropertyResourceBundle .getBundle("activity-store-jpa.Messages").getString("ACTIVITY-STORE-JPA-1"), (query .getFormat() == null ? "" : query.getFormat()))); } if (query.getExpression() == null || !query.getExpression().toLowerCase().startsWith("select ")) { throw new IllegalArgumentException(java.util.PropertyResourceBundle.getBundle( "activity-store-jpa.Messages").getString("ACTIVITY-STORE-JPA-2")); } return (query(query.getExpression())); } JPAActivityStore();  JPAActivityStore(JpaStore jpaStore); void store(final List<ActivityUnit> activities); ActivityUnit getActivityUnit(final String id); @SuppressWarnings("unchecked") java.util.List<ActivityType> getActivityTypes(final Context context, final long from, final long to); List<ActivityType> getActivityTypes(Context context); List<ActivityType> query(QuerySpec query); @SuppressWarnings("unchecked") List<ActivityType> query(final String query); void remove(final ActivityUnit au);  }
@Test public void testQueryUnsupportedFormat() { try { activityStore.query(new QuerySpec() .setFormat("mvel") .setExpression("true")); fail("Should have returned an exception"); } catch (IllegalArgumentException iae) { System.out.println("EXPECTED EXCEPTION="+iae); } catch (Exception e) { fail("Unexpected exception: "+e); } }
@Test public void testQueryNotSelect() { try { activityStore.query(new QuerySpec() .setFormat("jpql") .setExpression("update activities")); fail("Should have returned an exception"); } catch (IllegalArgumentException iae) { System.out.println("EXPECTED EXCEPTION="+iae); } catch (Exception e) { fail("Unexpected exception: "+e); } }