/*
 * Copyright 2015-2016 Dark Phoenixs (Open-Source Organization).
 *
 * 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.darkphoenixs.pool.socket;

import java.net.Socket;
import java.util.Properties;

import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.junit.Test;

public class SocketConnectionFactoryTest {

	@Test
	public void test_0() throws Exception {

		SocketConnectionFactory factory = new SocketConnectionFactory(
				SocketConfig.DEFAULT_HOST, SocketConfig.DEFAULT_PORT,
				SocketConfig.DEFAULT_BUFFERSIZE,
				SocketConfig.DEFAULT_BUFFERSIZE, SocketConfig.DEFAULT_TIMEOUT,
				SocketConfig.DEFAULT_TIMEOUT, 1, true, true, new String[] {
						"0", "1", "2" });

		try {
			factory.createConnection();
		} catch (Exception e) {
		}

		try {
			factory.makeObject();
		} catch (Exception e) {
		}

		factory.activateObject(new DefaultPooledObject<Socket>(new Socket()));
		try {
			factory.activateObject(new DefaultPooledObject<Socket>(null));
		} catch (Exception e) {
		}

		factory.validateObject(new DefaultPooledObject<Socket>(new Socket()));
		try {
			factory.validateObject(new DefaultPooledObject<Socket>(null));
		} catch (Exception e) {
		}

		factory.passivateObject(new DefaultPooledObject<Socket>(new Socket()));
		try {
			factory.passivateObject(new DefaultPooledObject<Socket>(null));
		} catch (Exception e) {
		}

		factory.destroyObject(new DefaultPooledObject<Socket>(new Socket()));
		try {
			factory.destroyObject(new DefaultPooledObject<Socket>(null));
		} catch (Exception e) {
		}
	}

	@Test
	public void test_1() throws Exception {

		Properties pro = new Properties();

		try {
			new SocketConnectionFactory(pro);
		} catch (Exception e) {
			// TODO: handle exception
		}

		pro.setProperty(SocketConfig.ADDRESS_PROPERTY,
				SocketConfig.DEFAULT_HOST + ":" + SocketConfig.DEFAULT_PORT);
		pro.setProperty(SocketConfig.RECE_BUFFERSIZE_PROPERTY,
				SocketConfig.DEFAULT_BUFFERSIZE + "");
		pro.setProperty(SocketConfig.SEND_BUFFERSIZE_PROPERTY,
				SocketConfig.DEFAULT_BUFFERSIZE + "");
		pro.setProperty(SocketConfig.CONN_TIMEOUT_PROPERTY,
				SocketConfig.DEFAULT_TIMEOUT + "");
		pro.setProperty(SocketConfig.SO_TIMEOUT_PROPERTY,
				SocketConfig.DEFAULT_TIMEOUT + "");
		pro.setProperty(SocketConfig.LINGER_PROPERTY,
				SocketConfig.DEFAULT_LINGER + "");
		pro.setProperty(SocketConfig.KEEPALIVE_PROPERTY,
				SocketConfig.DEFAULT_KEEPALIVE + "");
		pro.setProperty(SocketConfig.TCPNODELAY_PROPERTY,
				SocketConfig.TCPNODELAY_PROPERTY + "");
		
		new SocketConnectionFactory(pro);
	}
}

@@ -676,24 +676,84 @@
 .socket;%0D%0A%0D%0A
+import java.io.IOException;%0D%0Aimport java.net.ServerSocket;%0D%0A
 import java.
@@ -757,32 +757,32 @@
 va.net.Socket;%0D%0A
-
 import java.util
@@ -924,24 +924,395 @@
 ryTest %7B%0D%0A%0D%0A
+%09static %7B%0D%0A%09%09%0D%0A%09%09Thread th = new Thread(new Runnable() %7B%0D%0A%09%09%09%0D%0A%09%09%09private ServerSocket serverSocket;%0D%0A%0D%0A%09%09%09@Override%0D%0A%09%09%09public void run() %7B%0D%0A%09%09%09%09%0D%0A%09%09%09%09try %7B%0D%0A%09%09%09%09%09serverSocket = new ServerSocket(1234);%0D%0A%09%09%09%09%09%0D%0A%09%09%09%09%09serverSocket.accept();%0D%0A%09%09%09%09%09%0D%0A%09%09%09%09%7D catch (IOException e) %7B%0D%0A%09%09%09%09%09e.printStackTrace();%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D%0D%0A%09%09%7D);%0D%0A%09%09%0D%0A%09%09th.setDaemon(true);%0D%0A%09%09th.start();%0D%0A%09%7D%0D%0A
 %09@Test%0D%0A%09pub
@@ -2728,38 +2728,8 @@
  %7B%0D%0A
-%09%09%09// TODO: handle exception%0D%0A
 %09%09%7D%0D
@@ -3520,26 +3520,24 @@
 RTY + %22%22);%0D%0A
-%09%09
 %0D%0A%09%09new Sock
@@ -3559,19 +3559,281 @@
 tory(pro);%0D%0A
+%0D%0A%09%09Properties pro2 = new Properties();%0D%0A%09%09pro2.setProperty(SocketConfig.ADDRESS_PROPERTY,%0D%0A%09%09%09%09SocketConfig.DEFAULT_HOST + %22:%22 + SocketConfig.DEFAULT_PORT);%0D%0A%0D%0A%09%09try %7B%0D%0A%09%09%09new SocketConnectionFactory(pro2).createConnection();%0D%0A%09%09%7D catch (Exception e) %7B%0D%0A%09%09%7D%0D%0A%0D%0A
 %09%7D%0D%0A%7D%0D%0A

fix testcase