NamedNativeQueryProcessor { <T> void processClass(Class<T> cls) { final NamedNativeQueries queries = cls.getAnnotation(NamedNativeQueries.class); if (queries != null) { for (NamedNativeQuery q : queries.value()) { processQuery(q); } } final NamedNativeQuery nq = cls.getAnnotation(NamedNativeQuery.class); if (nq != null) { processQuery(nq); } }    }
@Test void processesSingleQueryDeclaredOnClass() { processor.processClass(SingleQuery.class); final String query = queryManager().getQuery(SingleQuery.class.getSimpleName() + "." + SELECT_NAME); assertNotNull(query); assertEquals(SELECT_QUERY, query); }
@Test void processesNamedNativeQueriesDeclaredOnClass() { processor.processClass(MultipleQueries.class); final String select = queryManager().getQuery(MultipleQueries.class.getSimpleName() + "." + SELECT_NAME); assertEquals(SELECT_QUERY, select); final String ask = queryManager().getQuery(MultipleQueries.class.getSimpleName() + "." + ASK_NAME); assertEquals(ASK_QUERY, ask); }
@Test void doesNothingForClassWithoutNamedNativeQueries() throws Exception { processor.processClass(OWLClassA.class); final Field queriesField = NamedQueryManager.class.getDeclaredField("queryMap"); queriesField.setAccessible(true); final Map<?, ?> queryMap = (Map<?, ?>) queriesField.get(queryManager()); assertTrue(queryMap.isEmpty()); }
@Test void processesClassWithCombinationOfNamedNativeQueriesAndNamedNativeQuery() { processor.processClass(QueryCombination.class); final String select = queryManager().getQuery(QueryCombination.class.getSimpleName() + "." + SELECT_NAME); assertEquals(SELECT_QUERY, select); final String ask = queryManager().getQuery(QueryCombination.class.getSimpleName() + "." + ASK_NAME); assertEquals(ASK_QUERY, ask); }