/*
 * Copyright (c) 2013-2015 Cinchapi Inc.
 *
 * 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.cinchapi.concourse;

import java.util.Set;

import org.cinchapi.concourse.util.TestData;
import org.junit.Assert;
import org.junit.Test;

import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;

/**
 * Unit tests that check the operational correctness of the Set API methods.
 * 
 * @author Jeff Nelson
 */
public class SetTest extends ConcourseIntegrationTest {

    @Test
    public void testSetInEmptyKey() {
        String key = TestData.getString();
        Object value = TestData.getObject();
        long record = TestData.getLong();
        client.set(key, value, record);
        Assert.assertEquals(value, client.get(key, record));
    }
    
    @Test
    public void testSetInPopulatedKey(){
        int count = TestData.getScaleCount();
        String key = TestData.getString();
        Object value = TestData.getObject();
        long record = TestData.getLong();
        for(int i = 0; i < count; i++){
            client.add(key, count, record);
        }
        client.set(key, value, record);
        Assert.assertEquals(value, client.get(key, record));
        Assert.assertEquals(1, client.select(key, record).size());  
    }
    
    @Test
    public void testSetValueThatAlreadyExists(){
        Set<Object> values = Sets.newHashSet();
        String key = TestData.getString();
        long record = TestData.getLong();
        for(int i = 0; i < TestData.getScaleCount(); i++){
            values.add(TestData.getObject());
        }
        Object value = Iterables.getFirst(values, TestData.getObject());
        for(Object v : values){
            value = TestData.getInt() % 4 == 0 ? v : value;
            client.add(key, v, record);
        }
        Assert.assertTrue(client.verify(key, value, record));
        client.set(key, value, record);
        Assert.assertEquals(value, client.get(key, record));
        Assert.assertEquals(1, client.select(key, record).size());
    }

}

/*
 * Copyright (c) 2013-2015 Cinchapi Inc.
 *
 * 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.cinchapi.concourse;

import java.util.Set;

import org.cinchapi.concourse.util.TestData;
import org.junit.Assert;
import org.junit.Test;

import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;

/**
 * Unit tests that check the operational correctness of the Set API methods.
 * 
 * @author Jeff Nelson
 */
public class SetTest extends ConcourseIntegrationTest {

    @Test
    public void testSetInEmptyKey() {
        String key = TestData.getSimpleString();
        Object value = TestData.getObject();
        long record = TestData.getLong();
        client.set(key, value, record);
        Assert.assertEquals(value, client.get(key, record));
    }
    
    @Test
    public void testSetInPopulatedKey(){
        int count = TestData.getScaleCount();
        String key = TestData.getSimpleString();
        Object value = TestData.getObject();
        long record = TestData.getLong();
        for(int i = 0; i < count; i++){
            client.add(key, count, record);
        }
        client.set(key, value, record);
        Assert.assertEquals(value, client.get(key, record));
        Assert.assertEquals(1, client.select(key, record).size());  
    }
    
    @Test
    public void testSetValueThatAlreadyExists(){
        Set<Object> values = Sets.newHashSet();
        String key = TestData.getSimpleString();
        long record = TestData.getLong();
        for(int i = 0; i < TestData.getScaleCount(); i++){
            values.add(TestData.getObject());
        }
        Object value = Iterables.getFirst(values, TestData.getObject());
        for(Object v : values){
            value = TestData.getInt() % 4 == 0 ? v : value;
            client.add(key, v, record);
        }
        Assert.assertTrue(client.verify(key, value, record));
        client.set(key, value, record);
        Assert.assertEquals(value, client.get(key, record));
        Assert.assertEquals(1, client.select(key, record).size());
    }

}

fix unit test so it doesn't fail