/**
 * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
 *
 * 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 io.gravitee.am.gateway.handler.vertx.endpoint;

import io.gravitee.am.gateway.handler.auth.idp.IdentityProviderManager;
import io.gravitee.am.gateway.handler.oauth2.client.ClientService;
import io.gravitee.am.gateway.handler.vertx.RxWebTestBase;
import io.gravitee.am.gateway.handler.vertx.handler.ExceptionHandler;
import io.gravitee.am.gateway.handler.vertx.handler.login.endpoint.LoginEndpointHandler;
import io.gravitee.am.model.Domain;
import io.gravitee.common.http.HttpStatusCode;
import io.reactivex.Maybe;
import io.vertx.core.http.HttpMethod;
import io.vertx.reactivex.ext.web.templ.ThymeleafTemplateEngine;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;

/**
 * @author Titouan COMPIEGNE (titouan.compiegne at graviteesource.com)
 * @author GraviteeSource Team
 */
@RunWith(MockitoJUnitRunner.class)
public class LoginEndpointHandlerTest extends RxWebTestBase {

    @InjectMocks
    private LoginEndpointHandler loginEndpointHandler = new LoginEndpointHandler();

    @Mock
    private ThymeleafTemplateEngine engine;

    @Mock
    private Domain domain;

    @Mock
    private ClientService clientService;

    @Mock
    private IdentityProviderManager identityProviderManager;

    @Override
    public void setUp() throws Exception {
        super.setUp();

        router.route(HttpMethod.GET, "/login").handler(loginEndpointHandler);
        router.route().failureHandler(new ExceptionHandler());
    }

    @Test
    public void shouldNotInvokeLoginEndpoint_noClientParameter() throws Exception {
        testRequest(
                HttpMethod.GET, "/login",
                HttpStatusCode.BAD_REQUEST_400, "Bad Request");
    }

    @Test
    public void shouldNotInvokeLoginEndpoint_noClient() throws Exception {
        when(clientService.findByClientId(anyString())).thenReturn(Maybe.empty());

        testRequest(
                HttpMethod.GET, "/login?client_id=test",
                HttpStatusCode.NOT_FOUND_404, "Not Found");
    }

}

@@ -684,80 +684,8 @@
 t;%0A%0A
-import io.gravitee.am.gateway.handler.auth.idp.IdentityProviderManager;%0A
 impo
@@ -991,20 +991,77 @@
 .am.
-model.Domain
+gateway.handler.vertx.handler.login.endpoint.LoginRequestParseHandler
 ;%0Aim
@@ -1174,73 +1174,8 @@
 od;%0A
-import io.vertx.reactivex.ext.web.templ.ThymeleafTemplateEngine;%0A
 impo
@@ -1754,200 +1754,35 @@
 ate 
-ThymeleafTemplateEngine engine;%0A%0A    @Mock%0A    private Domain domain;%0A%0A    @Mock%0A    private ClientService clientService;%0A%0A    @Mock%0A    private IdentityProviderManager identityProviderManager
+ClientService clientService
 ;%0A%0A 
@@ -1907,16 +1907,103 @@
 /login%22)
+%0A                .handler(new LoginRequestParseHandler(clientService))%0A                
 .handler
@@ -2606,33 +2606,37 @@
 ode.
-NOT_FOUND_404, %22Not Found
+BAD_REQUEST_400, %22Bad Request
 %22);%0A

fix ut