/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.component.yql;

import org.apache.camel.Endpoint;
import org.apache.camel.Producer;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.yql.configuration.YqlConfiguration;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.text.IsEmptyString.emptyString;

public class YqlComponentTest extends CamelTestSupport {

    @Rule
    public final ExpectedException thrown = ExpectedException.none();

    @Override
    protected RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() {
                from("direct:start")
                        .to("yql://query?format=json")
                        .to("mock:result");
            }
        };
    }

    @Test
    public void testCreateProducer() throws Exception {
        // given
        final Endpoint yqlEndpoint = context.getEndpoint("yql://query?format=json");

        // when
        final Producer producer = yqlEndpoint.createProducer();

        // then
        assertNotNull(producer);
        assertTrue(producer instanceof YqlProducer);
    }

    @Test
    public void testConfigurationSetup() {
        // given
        final YqlEndpoint yqlEndpoint = (YqlEndpoint) context.getEndpoint("yql://query?format=xml&callback=yqlCallback&diagnostics=true");

        // when
        final YqlConfiguration yqlConfiguration = yqlEndpoint.getConfiguration();

        // then
        assertNotNull(yqlConfiguration);
        assertEquals("query", yqlConfiguration.getQuery());
        assertEquals("xml", yqlConfiguration.getFormat());
        assertEquals("yqlCallback", yqlConfiguration.getCallback());
        assertTrue(yqlConfiguration.isDiagnostics());
    }

    @Test
    public void testConfigurationSetupDefault() {
        // given
        final YqlEndpoint yqlEndpoint = (YqlEndpoint) context.getEndpoint("yql://query");

        // when
        final YqlConfiguration yqlConfiguration = yqlEndpoint.getConfiguration();

        // then
        assertNotNull(yqlConfiguration);
        assertEquals("query", yqlConfiguration.getQuery());
        assertEquals("json", yqlConfiguration.getFormat());
        assertThat(yqlConfiguration.getCallback(), is(emptyString()));
        assertFalse(yqlConfiguration.isDiagnostics());
    }

    @Test
    public void testCreateConsumer() throws Exception {
        // then
        thrown.expect(UnsupportedOperationException.class);

        // given
        final Endpoint yqlEndpoint = context.getEndpoint("yql://query?format=json");

        // when
        yqlEndpoint.createConsumer(null);
    }
}

@@ -2278,20 +2278,88 @@
 ics=true
+&debug=true&https=false&throwExceptionOnFailure=false&jsonCompat=new
 %22);%0A
-
 %0A       
@@ -2691,24 +2691,72 @@
 allback());%0A
+        assertTrue(yqlConfiguration.isDebug());%0A
         asse
@@ -2789,32 +2789,148 @@
 Diagnostics());%0A
+        assertFalse(yqlConfiguration.isHttps());%0A        assertFalse(yqlConfiguration.isThrowExceptionOnFailure());%0A
     %7D%0A%0A    @Test
@@ -3453,43 +3453,363 @@
 sert
-False(yqlConfiguration.isDiagnostic
+Null(yqlConfiguration.getCrossProduct());%0A        assertFalse(yqlConfiguration.isDiagnostics());%0A        assertFalse(yqlConfiguration.isDebug());%0A        assertNull(yqlConfiguration.getEnv());%0A        assertNull(yqlConfiguration.getJsonCompat());%0A        assertTrue(yqlConfiguration.isThrowExceptionOnFailure());%0A        assertTrue(yqlConfiguration.isHttp
 s())

Improve tests