/**
 * Copyright 2007-2016, Kaazing Corporation. All rights reserved.
 *
 * Licensed 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.kaazing.gateway.service.http.proxy;

import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.kaazing.gateway.server.test.GatewayRule;
import org.kaazing.gateway.server.test.config.GatewayConfiguration;
import org.kaazing.gateway.server.test.config.builder.GatewayConfigurationBuilder;
import org.kaazing.gateway.util.feature.EarlyAccessFeatures;
import org.kaazing.k3po.junit.annotation.Specification;
import org.kaazing.k3po.junit.rules.K3poRule;


import static org.kaazing.test.util.ITUtil.createRuleChain;

public class HttpProxyNegativeCasesIT {

    private final K3poRule robot = new K3poRule();

    private final GatewayRule gateway = new GatewayRule() {{
        // @formatter:off
        GatewayConfiguration configuration =
                new GatewayConfigurationBuilder()
                    .property(EarlyAccessFeatures.HTTP_PROXY_SERVICE.getPropertyName(), "true")
                    .service()
                        .accept("http://localhost:8110")
                        .connect("http://localhost:8080")
                        .type("http.proxy")
                    .done()
                .done();
        // @formatter:on
        init(configuration);
    }};

    @Rule
    public TestRule chain = createRuleChain(gateway, robot);

    @Specification("http.proxy.http.1.0.request")
    @Test
    public void sendHttp_1_0_Request() throws Exception {
        robot.finish();
    }

    @Specification("http.proxy.http.2.0.request")
    @Test
    public void sendHttp_2_0_Request() throws Exception {
        robot.finish();
    }

    @Ignore("https://github.com/kaazing/tickets/issues/664")
    @Specification("http.proxy.content.without.content.length.header")
    @Test
    public void sendContentWithoutContentLengthHeader() throws Exception {
        robot.finish();
    }

    @Ignore("https://github.com/kaazing/tickets/issues/631")
    @Specification("http.proxy.payload.no.match.content.length.smaller")
    @Test
    public void sendPayloadWithContentLengthSmaller() throws Exception {
        robot.finish();
    }

    @Specification("http.proxy.payload.no.match.content.length.bigger")
    @Test
    public void sendPayloadWithContentLengthBigger() throws Exception {
        robot.finish();
    }

    @Specification("http.proxy.no.method.is.send")
    @Test
    public void noMethodIsSend() throws Exception {
        robot.finish();
    }

    @Specification("http.proxy.send.made.up.method")
    @Test
    public void sendMadeUpMethod() throws Exception {
        robot.finish();
    }

    @Specification("http.proxy.multiple.half.complete.requests")
    @Test
    public void sendMultipleHalfCompleteRequests() throws Exception {
        robot.finish();
    }

}

@@ -671,16 +671,93 @@
 proxy;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0A
 import o
@@ -842,24 +842,100 @@
 t.rules.
-Test
 Rule
+Chain;%0Aimport org.junit.rules.TestRule;%0Aimport org.junit.runners.model.Statement
 ;%0Aimport
@@ -1298,23 +1298,59 @@
 le;%0A
-%0A%0A
 import 
-static
+org.kaazing.test.util.MemoryAppender;%0Aimport
  org
@@ -1372,30 +1372,28 @@
 til.
-ITUtil.createRuleChain
+MethodExecutionTrace
 ;%0A%0Ap
@@ -1482,16 +1482,343 @@
 oRule();
+%0A    private List%3CString%3E expectedPatterns;%0A%0A    private TestRule checkLogMessageRule = (base, description) -%3E new Statement() %7B%0A        @Override%0A        public void evaluate() throws Throwable %7B%0A            base.evaluate();%0A            MemoryAppender.assertMessagesLogged(expectedPatterns, null, null, true);%0A        %7D%0A    %7D;
 %0A%0A    pr
@@ -2437,14 +2437,8 @@
 n = 
-create
 Rule
@@ -2446,16 +2446,103 @@
 hain
+.outerRule(new MethodExecutionTrace()).around(robot).around(checkLogMessageRule).around
 (gateway
 , ro
@@ -2541,15 +2541,8 @@
 eway
-, robot
 );%0A%0A
@@ -2675,32 +2675,236 @@
 robot.finish();%0A
+        expectedPatterns = new ArrayList%3CString%3E(Arrays.asList(new String%5B%5D %7B%0A                %22http.proxy service .*. received an HTTP 1.0 request. HTTP 1.0 is not explicitly supported.%22%0A            %7D));%0A
     %7D%0A%0A    @Spec

Modify test: sendHttp_1_0_Request, in order to validate the changes.