/*
 * Sonar ESQL Plugin
 * Copyright (C) 2013-2017 Thomas Pohl and EXXETA AG
 * http://www.exxeta.com
 *
 * 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 com.exxeta.iss.sonar.esql.api.tree;

import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;

import org.junit.Test;

import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind;
import com.exxeta.iss.sonar.esql.tree.impl.statement.DeclareHandlerStatementTreeImpl;
import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest;

public class DeclareHandlerStatementTest extends EsqlTreeModelTest<DeclareHandlerStatementTreeImpl> {

	@Test
	public void declareHandlerStatement() {
		assertThat(Kind.DECLARE_HANDLER_STATEMENT)
				.matches("DECLARE EXIT HANDLER FOR SQLSTATE VALUE 'U11222' SET a = 1;")
				.matches("DECLARE EXIT HANDLER FOR SQLSTATE VALUE 'U11222', SQLSTATE VALUE 'U11223' SET a = 2;");

	}

	@Test
	public void modelTest() throws Exception {
		DeclareHandlerStatementTreeImpl tree = parse(
				"DECLARE EXIT HANDLER FOR SQLSTATE VALUE 'U11222', SQLSTATE VALUE 'U11223' SET a = 2;",
				Kind.DECLARE_HANDLER_STATEMENT);

		assertNotNull(tree);
		assertNotNull(tree.declareKeyword());
		assertNotNull(tree.handlerType());
		assertNotNull(tree.forKeyword());
		assertNotNull(tree.handlerKeyword());
		assertNotNull(tree.sqlStates());
		assertNotNull(tree.statement());
	}

}

@@ -818,16 +818,59 @@
 NotNull;
+%0Aimport static org.junit.Assert.assertNull;
 %0A%0Aimport
@@ -940,16 +940,82 @@
 e.Kind;%0A
+import com.exxeta.iss.sonar.esql.api.tree.statement.SqlStateTree;%0A
 import c
@@ -2005,14 +2005,494 @@
 ent());%0A
+%09%09%0A%09%09SqlStateTree sqlState = tree.sqlStates().get(0);%0A%09%09assertNotNull(sqlState);%0A%09%09%0A%09%09%0A%09%09assertNotNull(sqlState.sqlstateKeyword());%0A%09%09assertNull(sqlState.likeKeyword());%0A%09%09assertNull(sqlState.likeText());%0A%09%09assertNull(sqlState.escapeKeyword());%0A%09%09assertNull(sqlState.escapeText());%0A%09%09assertNotNull(sqlState.valueKeyword()); %0A%09%09assertNotNull(sqlState.valueText());%0A%09%09%0A%09%09tree = parse(%0A%09%09%09%09%22DECLARE EXIT HANDLER FOR SQLSTATE LIKE'%25' SET a = 2;%22,%0A%09%09%09%09Kind.DECLARE_HANDLER_STATEMENT);%0A
 %09%7D%0A%0A%7D%0A

Improve DeclareHandlerStatementTest