package com.skogsrud.halvard.dynamodb.spike;

import com.almworks.sqlite4java.SQLite;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.local.main.ServerRunner;
import com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer;
import com.amazonaws.services.dynamodbv2.model.ListTablesResult;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.net.ServerSocket;

public class DynamoDbTest {
    private static String port;
    private static DynamoDBProxyServer server;

    @BeforeClass
    public static void beforeAll() throws Exception {
        // Aweful! https://code.google.com/p/sqlite4java/wiki/UsingWithMaven
        SQLite.setLibraryPath("target/lib");
//        SQLite.setLibraryPath(System.getenv("HOME") + "/.m2/repository/com/almworks/sqlite4java/libsqlite4java-osx/1.0.392");
        port = String.valueOf(findOpenPort());
        server = ServerRunner.createServerFromCommandLineArgs(new String[]{"-inMemory", "-port", port});
        server.start();
    }

    @AfterClass
    public static void afterAll() throws Exception {
        server.stop();
    }

    @Test
    public void test() throws Exception {
        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        client.setEndpoint("http://localhost:" + port);
        ListTablesResult listTablesResult = client.listTables();
        System.out.println("listTablesResult = " + listTablesResult);
    }

    public static int findOpenPort() throws IOException {
        try (ServerSocket socket = new ServerSocket(0)) {
            return socket.getLocalPort();
        }
    }
}

@@ -681,247 +681,29 @@
     
-// Aweful! https://code.google.com/p/sqlite4java/wiki/UsingWithMaven%0A        SQLite.setLibraryPath(%22target/lib%22);%0A//        SQLite.setLibraryPath(System.getenv(%22HOME%22) + %22/.m2/repository/com/almworks/sqlite4java/libsqlite4java-osx/1.0.392%22
+configureEnvironment(
 );%0A 
@@ -1295,24 +1295,1038 @@
 lt);%0A    %7D%0A%0A
+    private static void configureEnvironment() %7B%0A        setUpDummyAwsCredentials();%0A        /**%0A         * This is ugly! We have to tell SQLite4Java where the native sqlite libraries are located.%0A         * Our pom.xml file ensures they are copied from your local maven repository (~/.m2/repository)%0A         * to target/lib on compilation.%0A         * See this site for further details: https://code.google.com/p/sqlite4java/wiki/UsingWithMaven%0A         */%0A        SQLite.setLibraryPath(%22target/lib%22);%0A//        SQLite.setLibraryPath(System.getenv(%22HOME%22) + %22/.m2/repository/com/almworks/sqlite4java/libsqlite4java-osx/1.0.392%22);%0A    %7D%0A%0A    /**%0A     * The AWS SDK requires credentials to be set up, even if we only talk to DynamoDB Local.%0A     */%0A    private static void setUpDummyAwsCredentials() %7B%0A        System.setProperty(%22aws.accessKeyId%22, %22dummyAccessKeyId%22);%0A        System.setProperty(%22aws.secretKey%22, %22dummySecretKey%22);%0A    %7D%0A%0A    /**%0A     * Allows the test to be run on an arbitrary free port.%0A     */%0A
     public s

Fix AWS credentials problem