/**
 * Copyright 2016 Palantir Technologies
 *
 * Licensed under the BSD-3 License (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://opensource.org/licenses/BSD-3-Clause
 *
 * 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 com.palantir.atlasdb.table.description;

import java.io.File;
import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import com.palantir.atlasdb.keyvalue.api.Namespace;

public class SchemaHotspottingTest {

    Schema hotspottingSchema = getHotspottingSchema();

    private static Schema getHotspottingSchema() {
        Schema suffersFromHotspoting = new Schema("SuffersFromHotspoting", "unused", Namespace.DEFAULT_NAMESPACE);
        suffersFromHotspoting.addTableDefinition("HotspottingTable", new TableDefinition() {{
            rowName();
                rowComponent("Hotspotter", ValueType.VAR_STRING);
            noColumns();
        }});
        return suffersFromHotspoting;
    }

    private static Schema getIgnoredHotspottingSchema() {
        Schema ignoredHotspotting = new Schema("IgnoredHotspotting", "valid.package", Namespace.DEFAULT_NAMESPACE);
        ignoredHotspotting.addTableDefinition("IgnoredHotspottingTable", new TableDefinition() {{
            ignoreHotspottingChecks();
            rowName();
                rowComponent("Hotspotter", ValueType.VAR_STRING);
            noColumns();
        }});
        return ignoredHotspotting;
    }

    @Test (expected = IllegalStateException.class)
    public void testHardFailOnValidateOfHotspottingSchema() {
        hotspottingSchema.validate();
    }

    @Test (expected = IllegalStateException.class)
    public void testFailToGenerateHotspottingSchema() throws IOException {
        hotspottingSchema.renderTables(new TemporaryFolder().getRoot());
    }

    @Test
    public void testNoFailureWhenHotspottingIgnored() {
        getIgnoredHotspottingSchema().validate();
    }

    @Test
    public void testSuccessfulGenerationWhenHotspottingIgnored() throws IOException {
        TemporaryFolder temporaryFolder = new TemporaryFolder();
        temporaryFolder.create();

        File srcDir = temporaryFolder.getRoot();
        getIgnoredHotspottingSchema().renderTables(srcDir);

        Assert.assertArrayEquals(srcDir.list(), new String[] {"valid"});

        File validDirectory = srcDir.listFiles()[0];
        Assert.assertArrayEquals(validDirectory.list(), new String[] {"package"});
        Assert.assertArrayEquals(validDirectory.listFiles()[0].list(),
                new String[] {"IgnoredHotspottingTableFactory.java", "IgnoredHotspottingTableTable.java"});
    }
}
@@ -627,24 +627,169 @@
 scription;%0A%0A
+import static org.hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.contains;%0Aimport static org.hamcrest.Matchers.equalTo;%0A%0A
 import java.
@@ -829,33 +829,33 @@
 on;%0A
-%0A
 import 
-org.junit.Assert;
+java.util.Arrays;%0A
 %0Aimp
@@ -2779,32 +2779,32 @@
     
-A
+a
 ssert
-.assertArrayEquals
+That(Arrays.asList
 (src
@@ -2817,32 +2817,37 @@
 st()
+)
 , 
-new String%5B%5D %7B
+contains(equalTo(
 %22valid%22
-%7D
+))
 );%0A%0A
@@ -2911,32 +2911,32 @@
     
-A
+a
 ssert
-.assertArrayEquals
+That(Arrays.asList
 (val
@@ -2957,24 +2957,28 @@
 st()
+)
 , 
-new String%5B%5D %7B
+contains(equalTo(
 %22pac
@@ -2982,17 +2982,18 @@
 package%22
-%7D
+))
 );%0A     
@@ -2999,32 +2999,32 @@
     
-A
+a
 ssert
-.assertArrayEquals
+That(Arrays.asList
 (val
@@ -3060,40 +3060,28 @@
 st()
-,%0A                new String%5B%5D %7B
+), contains(equalTo(
 %22Ign
@@ -3113,18 +3113,27 @@
 ry.java%22
+)
 , 
+equalTo(
 %22Ignored
@@ -3159,17 +3159,18 @@
 le.java%22
-%7D
+))
 );%0A    %7D

Fix test to use proper asserts