/*
 * Copyright 1999-2015 dangdang.com.
 * <p>
 * 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.
 * </p>
 */

package com.dangdang.ddframe.job.lite.api.strategy.impl;

import com.dangdang.ddframe.job.lite.api.strategy.JobShardingResult;
import com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategyOption;
import com.dangdang.ddframe.job.lite.api.strategy.JobShardingUnit;
import org.junit.Ignore;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public final class RotateServerByNameJobShardingStrategyTest {
    
    private RotateServerByNameJobShardingStrategy rotateServerByNameJobShardingStrategy = new RotateServerByNameJobShardingStrategy();
    
    @Test
    @Ignore
    public void assertSharding1() {
        Collection<JobShardingResult> expected = Arrays.asList(
                new JobShardingResult(new JobShardingUnit("host0", "test_job_instance_id"), Collections.<Integer>emptyList()),
                new JobShardingResult(new JobShardingUnit("host1", "test_job_instance_id"), Collections.singletonList(0)),
                new JobShardingResult(new JobShardingUnit("host2", "test_job_instance_id"), Collections.singletonList(1)));
        assertThat(rotateServerByNameJobShardingStrategy.sharding(Arrays.asList(
                new JobShardingUnit("host1", "test_job_instance_id"), new JobShardingUnit("host2", "test_job_instance_id"), new JobShardingUnit("host0", "test_job_instance_id")), 
                new JobShardingStrategyOption("1", 2)), is(expected));
    }
    
    @Test
    @Ignore
    public void assertSharding2() {
        Collection<JobShardingResult> expected = Arrays.asList(
                new JobShardingResult(new JobShardingUnit("host0", "test_job_instance_id"), Collections.singletonList(1)),
                new JobShardingResult(new JobShardingUnit("host1", "test_job_instance_id"), Collections.<Integer>emptyList()),
                new JobShardingResult(new JobShardingUnit("host2", "test_job_instance_id"), Collections.singletonList(0)));
        assertThat(rotateServerByNameJobShardingStrategy.sharding(Arrays.asList(
                new JobShardingUnit("host0", "test_job_instance_id"), new JobShardingUnit("host1", "test_job_instance_id"), new JobShardingUnit("host2", "test_job_instance_id")),
                new JobShardingStrategyOption("2", 2)), is(expected));
    }
    
    @Test
    public void assertSharding3() {
        Collection<JobShardingResult> expected = Arrays.asList(
                new JobShardingResult(new JobShardingUnit("host0", "test_job_instance_id"), Collections.singletonList(0)),
                new JobShardingResult(new JobShardingUnit("host1", "test_job_instance_id"), Collections.singletonList(1)),
                new JobShardingResult(new JobShardingUnit("host2", "test_job_instance_id"), Collections.<Integer>emptyList()));
        assertThat(rotateServerByNameJobShardingStrategy.sharding(Arrays.asList(
                new JobShardingUnit("host0", "test_job_instance_id"), new JobShardingUnit("host1", "test_job_instance_id"), new JobShardingUnit("host2", "test_job_instance_id")),
                new JobShardingStrategyOption("3", 2)), is(expected));
    }
}

@@ -883,33 +883,8 @@
 it;%0A
-import org.junit.Ignore;%0A
 impo
@@ -1290,36 +1290,24 @@
  %0A    @Test%0A
-    @Ignore%0A
     public v
@@ -1449,33 +1449,33 @@
 ardingUnit(%22host
-0
+1
 %22, %22test_job_ins
@@ -1498,35 +1498,31 @@
 ections.
-%3CInteger%3Eempty
+singleton
 List(
+0
 )),%0A    
@@ -1572,33 +1572,33 @@
 ardingUnit(%22host
-1
+2
 %22, %22test_job_ins
@@ -1627,33 +1627,33 @@
 s.singletonList(
-0
+1
 )),%0A            
@@ -1695,33 +1695,33 @@
 ardingUnit(%22host
-2
+0
 %22, %22test_job_ins
@@ -1744,31 +1744,35 @@
 ections.
-singleton
+%3CInteger%3Eempty
 List(
-1
 )));%0A   
@@ -1856,32 +1856,86 @@
 %0A               
+ new JobShardingUnit(%22host0%22, %22test_job_instance_id%22),
  new JobSharding
@@ -2005,62 +2005,8 @@
 t2%22,
- %22test_job_instance_id%22), new JobShardingUnit(%22host0%22,
  %22te
@@ -2125,20 +2125,8 @@
 est%0A
-    @Ignore%0A
     
@@ -2213,32 +2213,155 @@
  Arrays.asList(%0A
+                new JobShardingResult(new JobShardingUnit(%22host2%22, %22test_job_instance_id%22), Collections.singletonList(0)),%0A
                 
@@ -2596,131 +2596,8 @@
 t())
-,%0A                new JobShardingResult(new JobShardingUnit(%22host2%22, %22test_job_instance_id%22), Collections.singletonList(0))
 );%0A 

fix test case