Package org.mule.module.db.internal.domain.query

Examples of org.mule.module.db.internal.domain.query.QueryTemplate


    {
        DbConnectionFactory dbConnectionFactory = mock(DbConnectionFactory.class);

        for (QueryType type : QueryType.values())
        {
            QueryTemplate queryTemplate = new QueryTemplate("UNUSED SQL TEXT", type, Collections.<QueryParam>emptyList());

            if (type != QueryType.SELECT && type != QueryType.STORE_PROCEDURE_CALL)
            {
                try
                {
View Full Code Here


    {
        DbConnectionFactory dbConnectionFactory = mock(DbConnectionFactory.class);

        for (QueryType type : QueryType.values())
        {
            QueryTemplate queryTemplate = new QueryTemplate("UNUSED SQL TEXT", type, Collections.<QueryParam>emptyList());

            if (type != QueryType.UPDATE && type != QueryType.STORE_PROCEDURE_CALL)
            {
                try
                {
View Full Code Here

    @Test
    public void configuresSimpleQuery() throws Exception
    {
        Object queryTemplateBean = muleContext.getRegistry().get("simple");
        assertTrue(queryTemplateBean instanceof QueryTemplate);
        QueryTemplate queryTemplate = (QueryTemplate) queryTemplateBean;
        assertEquals(QueryType.SELECT, queryTemplate.getType());
        assertEquals(0, queryTemplate.getInputParams().size());
    }
View Full Code Here

    @Test
    public void configuresParameterizedQuery() throws Exception
    {
        Object queryTemplateBean = muleContext.getRegistry().get("parameterized");
        assertTrue(queryTemplateBean instanceof QueryTemplate);
        QueryTemplate queryTemplate = (QueryTemplate) queryTemplateBean;
        assertEquals(QueryType.SELECT, queryTemplate.getType());
        assertEquals(1, queryTemplate.getInputParams().size());

        InputQueryParam inputSqlParam = queryTemplate.getInputParams().get(0);
        assertEquals(UnknownDbType.getInstance(), inputSqlParam.getType());
    }
View Full Code Here

    public static final String OVERRIDDEN_PARAM_VALUE = "10";

    @Test
    public void createsQueryWithNoParams() throws Exception
    {
        QueryTemplate queryTemplate = new QueryTemplate(QUERY, QueryType.SELECT, Collections.<QueryParam>emptyList());

        QueryTemplateParser queryParser = mock(QueryTemplateParser.class);
        when(queryParser.parse(QUERY)).thenReturn(queryTemplate);

        ParameterizedQueryTemplateFactoryBean factoryBean = new ParameterizedQueryTemplateFactoryBean(QUERY, Collections.EMPTY_LIST, queryParser);

        QueryTemplate createdQueryTemplate = factoryBean.getObject();

        assertThat(createdQueryTemplate.getSqlText(), equalTo(QUERY));
        assertThat(createdQueryTemplate.getType(), equalTo(QueryType.SELECT));
        assertThat(createdQueryTemplate.getParams(), is(empty()));
    }
View Full Code Here

    @Test
    public void createsQueryWithDefaultParams() throws Exception
    {
        List<QueryParam> defaultParams = Collections.<QueryParam>singletonList(new DefaultInputQueryParam(1, JdbcTypes.INTEGER_DB_TYPE, TEMPLATE_PARAM_VALUE, POSITION_PARAM_NAME));
        QueryTemplate queryTemplate = new QueryTemplate(PARSED_PARAMETERIZED_QUERY, QueryType.SELECT, defaultParams);

        QueryTemplateParser queryParser = mock(QueryTemplateParser.class);
        when(queryParser.parse(PARAMETERIZED_QUERY)).thenReturn(queryTemplate);

        ParameterizedQueryTemplateFactoryBean factoryBean = new ParameterizedQueryTemplateFactoryBean(PARAMETERIZED_QUERY, Collections.EMPTY_LIST, queryParser);

        QueryTemplate createdQueryTemplate = factoryBean.getObject();

        assertThat(createdQueryTemplate.getSqlText(), equalTo(PARSED_PARAMETERIZED_QUERY));
        assertThat(createdQueryTemplate.getType(), equalTo(QueryType.SELECT));
        assertThat(createdQueryTemplate.getParams().size(), equalTo(1));
        InputQueryParam inputQueryParam = createdQueryTemplate.getInputParams().get(0);
        assertThat(inputQueryParam.getValue(), IsEqual.<Object>equalTo(TEMPLATE_PARAM_VALUE));
    }
View Full Code Here

    }

    @Test
    public void createsQueryWithOverriddenParams() throws Exception
    {
        QueryTemplate createdQueryTemplate = doOverriddenParamTest(JdbcTypes.INTEGER_DB_TYPE, new DefaultInputQueryParam(1, JdbcTypes.INTEGER_DB_TYPE, OVERRIDDEN_PARAM_VALUE, POSITION_PARAM_NAME));

        assertThat(createdQueryTemplate.getSqlText(), equalTo(PARSED_PARAMETERIZED_QUERY));
        assertThat(createdQueryTemplate.getType(), equalTo(QueryType.SELECT));
        assertThat(createdQueryTemplate.getParams().size(), equalTo(1));
        InputQueryParam inputQueryParam = createdQueryTemplate.getInputParams().get(0);
        assertThat(inputQueryParam.getValue(), IsEqual.<Object>equalTo(OVERRIDDEN_PARAM_VALUE));
    }
View Full Code Here

    private void doInputParamOverrideTest(DbType templateParamType, DbType overriddenParamType, DbType expectedParamType) throws Exception
    {
        QueryParam overriddenParam = new DefaultInputQueryParam(2, overriddenParamType, OVERRIDDEN_PARAM_VALUE, POSITION_PARAM_NAME);

        QueryTemplate createdQueryTemplate = doOverriddenParamTest(templateParamType, overriddenParam);

        assertThat(createdQueryTemplate.getParams().size(), equalTo(1));
        InputQueryParam inputQueryParam = createdQueryTemplate.getInputParams().get(0);
        assertThat(inputQueryParam.getIndex(), equalTo(1));
        assertThat(inputQueryParam.getType(), equalTo(expectedParamType));
        assertThat(inputQueryParam.getName(), equalTo(POSITION_PARAM_NAME));
        assertThat(inputQueryParam.getValue(), IsEqual.<Object>equalTo(OVERRIDDEN_PARAM_VALUE));
    }
View Full Code Here

    private void doInOutParamOverrideTest(DbType templateParamType, DbType overriddenParamType, DbType expectedParamType) throws Exception
    {
        QueryParam overriddenParam = new DefaultInOutQueryParam(2, overriddenParamType, POSITION_PARAM_NAME, OVERRIDDEN_PARAM_VALUE);

        QueryTemplate createdQueryTemplate = doOverriddenParamTest(templateParamType, overriddenParam);

        assertThat(createdQueryTemplate.getParams().size(), equalTo(1));
        InOutQueryParam queryParam = (InOutQueryParam) createdQueryTemplate.getParams().get(0);
        assertThat(queryParam.getIndex(), equalTo(1));
        assertThat(queryParam.getType(), equalTo(expectedParamType));
        assertThat(queryParam.getName(), equalTo(POSITION_PARAM_NAME));
        assertThat(queryParam.getValue(), IsEqual.<Object>equalTo(OVERRIDDEN_PARAM_VALUE));
    }
View Full Code Here

    }

    @Test
    public void usesCustomType() throws Exception
    {
        QueryTemplate parameterizedQueryTemplate = muleContext.getRegistry().lookupObject("parameterizedQuery");
        QueryParam queryParam = parameterizedQueryTemplate.getParams().get(0);

        assertThat(queryParam.getType().getName(), equalTo("CUSTOM_TYPE1"));
    }
View Full Code Here

TOP

Related Classes of org.mule.module.db.internal.domain.query.QueryTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.