package com.imadcn.system.test.idworker;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

import com.alibaba.fastjson.JSON;
import com.imadcn.framework.idworker.generator.IdGenerator;
import com.imadcn.system.test.spring.AbstractZookeeperJUnit4SpringContextTests;

@ContextConfiguration(locations = "classpath:META-INF/idworker-ctx.xml")
public final class SpringIdWorkerTest extends AbstractZookeeperJUnit4SpringContextTests {

	@Autowired
	private IdGenerator idGenerator;

	@Test
	public void testGetId() {
		Object object = idGenerator.nextId();
		print(object);
	}
	
	@Test
	public void testBatchGetId() {
		Object object = idGenerator.nextId(20);
		print(object);
	}
	
	@Test
	public void testWithInvalidParam() {
		try {
			Object object = idGenerator.nextId(0);
			print(object);
		} catch (Exception e) {
			print(e);
		}
		
		try {
			Object object = idGenerator.nextId(-1);
			print(object);
		} catch (Exception e) {
			print(e);
		}
		
		
		try {
			Object object = idGenerator.nextId(100_001);
			print(object);
		} catch (Exception e) {
			print(e);
		}
		
	}

	public void print(Object object) {
		String json = JSON.toJSONString(object);
		System.out.println(json);
		logger.info(json);
	}

}

@@ -265,18 +265,25 @@
 nerator.
-Id
+Snowflake
 Generato
@@ -551,18 +551,25 @@
 private 
-Id
+Snowflake
 Generato
@@ -1182,16 +1182,152 @@
 %09%7D%0A%09%09%0A%09%7D
+%0A%09%0A%09@Test%0A%09public void testClose() throws Exception %7B%0A%09%09Object object = idGenerator.nextId();%0A%09%09print(object);%0A%09%09idGenerator.close();%0A%09%7D
 %0A%0A%09publi

update test case