/* Copyright (c) 2014-2017 Julien Rialland <julien.rialland@gmail.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.github.jrialland.ajpclient;

import io.netty.channel.Channel;

import java.net.ConnectException;
import java.net.UnknownHostException;
import java.nio.channels.UnresolvedAddressException;
import java.util.concurrent.TimeUnit;

import org.junit.Assert;
import org.junit.Test;

import com.github.jrialland.ajpclient.CPing;
import com.github.jrialland.ajpclient.pool.Channels;

public class TestCPing extends AbstractTomcatTest {

	public TestCPing() {
		super(AbstractTomcatTest.Protocol.Ajp);
	}

	@Test
	public void testCping() throws Exception {

		final boolean pong = new CPing(2, TimeUnit.SECONDS).execute("localhost", getPort());
		Assert.assertTrue(pong);
	}

	public void testUnknownHost() throws Exception {
		try {
		    final Channel channel = Channels.connect("unknownHost", getPort());
		    new CPing(2, TimeUnit.SECONDS).execute(channel);
		    Assert.fail("an exception should have been raised");
		} catch(UnresolvedAddressException|UnknownHostException e) {
		  
		} catch(Exception e) {
		  Assert.fail("bad exception type");
		}
	}

	@Test(expected = ConnectException.class)
	public void testWrongPort() throws Exception {
		final Channel channel = Channels.connect("localhost", getPort() + 1);
		new CPing(2, TimeUnit.SECONDS).execute(channel);
	}

}

@@ -66,17 +66,16 @@
 .com%3E%0A *
- 
 %0A * Lice
@@ -618,17 +618,16 @@
 ense.%0A *
- 
 %0A */%0Apac
@@ -668,42 +668,8 @@
 t;%0A%0A
-import io.netty.channel.Channel;%0A%0A
 impo
@@ -680,22 +680,21 @@
 ava.net.
-Connec
+Socke
 tExcepti
@@ -873,22 +873,23 @@
 nit.
-Test;%0A
+Ignore;
 %0Aimport 
 com.
@@ -888,45 +888,24 @@
 ort 
-com.github.jrialland.ajpclient.CPing;
+org.junit.Test;%0A
 %0Aimp
@@ -953,16 +953,49 @@
 hannels;
+%0Aimport io.netty.channel.Channel;
 %0A%0Apublic
@@ -1160,17 +1160,16 @@
 ption %7B%0A
-%0A
 %09%09final 
@@ -1278,16 +1278,32 @@
 g);%0A%09%7D%0A%0A
+%09@Ignore%0A%09@Test%0A
 %09public 
@@ -1702,14 +1702,13 @@
 d = 
-Connec
+Socke
 tExc

Use actual expected exception in test.