use of org.springframework.integration.jpa.support.JpaParameter in project spring-integration by spring-projects.
the class ExpressionEvaluatingParameterSourceFactoryTests method testMapInputWithMappedExpressionResolveStatic.
@Test
public void testMapInputWithMappedExpressionResolveStatic() {
List<JpaParameter> parameters = new ArrayList<JpaParameter>();
parameters.add(new JpaParameter("spam", null, "#staticParameters['foo'].toUpperCase()"));
parameters.add(new JpaParameter("foo", "bar", null));
factory.setParameters(parameters);
ParameterSource source = factory.createParameterSource(Collections.singletonMap("crap", "bucket"));
assertTrue(source.hasValue("spam"));
assertEquals("BAR", source.getValue("spam"));
}
use of org.springframework.integration.jpa.support.JpaParameter in project spring-integration by spring-projects.
the class JpaMessageHandlerParserTests method testProcedureParametersAreSet.
@SuppressWarnings("unchecked")
@Test
public void testProcedureParametersAreSet() throws Exception {
setUp("JpaMessageHandlerParserTestsWithEmFactory.xml", getClass());
final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class);
final List<JpaParameter> jpaParameters = TestUtils.getPropertyValue(jpaExecutor, "jpaParameters", List.class);
assertTrue(jpaParameters.size() == 3);
JpaParameter parameter1 = jpaParameters.get(0);
JpaParameter parameter2 = jpaParameters.get(1);
JpaParameter parameter3 = jpaParameters.get(2);
assertEquals("firstName", parameter1.getName());
assertEquals("firstaName", parameter2.getName());
assertEquals("updatedDateTime", parameter3.getName());
assertEquals("kenny", parameter1.getValue());
assertEquals("cartman", parameter2.getValue());
assertNull(parameter3.getValue());
assertNull(parameter1.getExpression());
assertNull(parameter2.getExpression());
assertEquals("new java.util.Date()", parameter3.getExpression());
}
use of org.springframework.integration.jpa.support.JpaParameter in project spring-integration by spring-projects.
the class JpaMessageHandlerParserTests method testJpaMessageHandlerParser.
@Test
public void testJpaMessageHandlerParser() throws Exception {
setUp("JpaMessageHandlerParserTests.xml", getClass());
final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class);
assertEquals("target", inputChannel.getComponentName());
final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class);
assertNotNull(jpaExecutor);
final String query = TestUtils.getPropertyValue(jpaExecutor, "jpaQuery", String.class);
assertEquals("from Student", query);
final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class);
assertNotNull(jpaOperations);
final PersistMode persistMode = TestUtils.getPropertyValue(jpaExecutor, "persistMode", PersistMode.class);
assertEquals(PersistMode.PERSIST, persistMode);
@SuppressWarnings("unchecked") List<JpaParameter> jpaParameters = TestUtils.getPropertyValue(jpaExecutor, "jpaParameters", List.class);
assertNotNull(jpaParameters);
assertTrue(jpaParameters.size() == 3);
assertEquals(Integer.valueOf(10), TestUtils.getPropertyValue(jpaExecutor, "flushSize", Integer.class));
assertTrue(TestUtils.getPropertyValue(jpaExecutor, "clearOnFlush", Boolean.class));
}
use of org.springframework.integration.jpa.support.JpaParameter in project spring-integration by spring-projects.
the class ExpressionEvaluatingParameterSourceUtils method convertStaticParameters.
/**
* Utility method that converts a Collection of {@link JpaParameter} to
* a Map containing only static parameters.
*
* @param jpaParameters Must not be null.
* @return Map containing only the static parameters. Will never be null.
*/
public static Map<String, Object> convertStaticParameters(Collection<JpaParameter> jpaParameters) {
Assert.notNull(jpaParameters, "The Collection of jpaParameters must not be null.");
for (JpaParameter parameter : jpaParameters) {
Assert.notNull(parameter, "'jpaParameters' must not contain null values.");
}
final Map<String, Object> staticParameters = new HashMap<String, Object>();
for (JpaParameter parameter : jpaParameters) {
if (parameter.getValue() != null) {
staticParameters.put(parameter.getName(), parameter.getValue());
}
}
return staticParameters;
}
use of org.springframework.integration.jpa.support.JpaParameter in project spring-integration by spring-projects.
the class JpaExecutorTests method getJpaExecutorForMessageAsParamSource.
private JpaExecutor getJpaExecutorForMessageAsParamSource(String query) {
JpaExecutor executor = new JpaExecutor(entityManager);
ExpressionEvaluatingParameterSourceFactory factory = new ExpressionEvaluatingParameterSourceFactory(mock(BeanFactory.class));
factory.setParameters(Collections.singletonList(new JpaParameter("firstName", null, "payload['firstName']")));
executor.setParameterSourceFactory(factory);
executor.setJpaQuery(query);
executor.setExpectSingleResult(true);
executor.setUsePayloadAsParameterSource(false);
executor.afterPropertiesSet();
return executor;
}
Aggregations