/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.ignite.testframework.test;

import java.util.concurrent.atomic.AtomicInteger;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.testframework.configvariations.ConfigVariationsTestSuiteBuilder;
import org.apache.ignite.testframework.junits.IgniteConfigVariationsAbstractTest;

/**
 *
 */
public class ConfigVariationsTestSuiteBuilderTest extends TestCase {
    /**
     * @throws Exception If failed.
     */
    public void testDefaults() throws Exception {
        TestSuite dfltSuite = new ConfigVariationsTestSuiteBuilder("testSuite", OneTestCase.class).build();

        assertEquals(4, dfltSuite.countTestCases());

        TestSuite dfltCacheSuite = new ConfigVariationsTestSuiteBuilder("testSuite", OneTestCase.class)
            .withBasicCacheParams().build();

        assertEquals(4 * 12, dfltCacheSuite.countTestCases());

        // With clients.
        dfltSuite = new ConfigVariationsTestSuiteBuilder("testSuite", OneTestCase.class)
            .testedNodesCount(2).withClients().build();

        assertEquals(4 * 2, dfltSuite.countTestCases());

        dfltCacheSuite = new ConfigVariationsTestSuiteBuilder("testSuite", OneTestCase.class)
            .withBasicCacheParams().testedNodesCount(3).withClients().build();

        assertEquals(4 * 12 * 3, dfltCacheSuite.countTestCases());
    }

    /**
     * @throws Exception If failed.
     */
    @SuppressWarnings("serial")
    public void testIgniteConfigFilter() throws Exception {
        TestSuite dfltSuite = new ConfigVariationsTestSuiteBuilder("testSuite", OneTestCase.class).build();

        final AtomicInteger cnt = new AtomicInteger();

        TestSuite filteredSuite = new ConfigVariationsTestSuiteBuilder("testSuite", OneTestCase.class)
            .withIgniteConfigFilters(new IgnitePredicate<IgniteConfiguration>() {
                @Override public boolean apply(IgniteConfiguration configuration) {
                    return cnt.getAndIncrement() % 2 == 0;
                }
            })
            .build();

        assertEquals(dfltSuite.countTestCases() / 2, filteredSuite.countTestCases());
    }

    /**
     * @throws Exception If failed.
     */
    @SuppressWarnings("serial")
    public void testCacheConfigFilter() throws Exception {
        TestSuite dfltSuite = new ConfigVariationsTestSuiteBuilder("testSuite", OneTestCase.class)
            .withBasicCacheParams()
            .build();

        final AtomicInteger cnt = new AtomicInteger();

        TestSuite filteredSuite = new ConfigVariationsTestSuiteBuilder("testSuite", OneTestCase.class)
            .withBasicCacheParams()
            .withCacheConfigFilters(new IgnitePredicate<CacheConfiguration>() {
                @Override public boolean apply(CacheConfiguration configuration) {
                    return cnt.getAndIncrement() % 2 == 0;
                }
            })
            .build();

        assertEquals(dfltSuite.countTestCases() / 2, filteredSuite.countTestCases());
    }

    /**
     *
     */
    private static class OneTestCase extends IgniteConfigVariationsAbstractTest {
        /**
         * @throws Exception If failed.
         */
        public void test1() throws Exception {
            // No-op.
        }
    }
}

@@ -1558,35 +1558,32 @@
 testSuite%22, 
-OneTestCase
+NoopTest
 .class).buil
@@ -1723,35 +1723,32 @@
 testSuite%22, 
-OneTestCase
+NoopTest
 .class)%0A    
@@ -1944,35 +1944,32 @@
 testSuite%22, 
-OneTestCase
+NoopTest
 .class)%0A    
@@ -2150,35 +2150,32 @@
 testSuite%22, 
-OneTestCase
+NoopTest
 .class)%0A    
@@ -2544,35 +2544,32 @@
 testSuite%22, 
-OneTestCase
+NoopTest
 .class).buil
@@ -2710,35 +2710,32 @@
 testSuite%22, 
-OneTestCase
+NoopTest
 .class)%0A    
@@ -3323,35 +3323,32 @@
 testSuite%22, 
-OneTestCase
+NoopTest
 .class)%0A    
@@ -3542,27 +3542,24 @@
 Suite%22, 
-OneTestCase
+NoopTest
 .class)%0A
@@ -4017,19 +4017,16 @@
 ass 
-OneTestCase
+NoopTest
  ext

fix JCache TCK tests