// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java
// public class Customer extends CustomerAbstract
// {
//     public Customer(Timestamp businessDate, Timestamp processingDate)
//     {
//         super(businessDate, processingDate);
//         // You must not modify this constructor. Mithra calls this internally.
//         // You can call this constructor. You can also add new constructors.
//     }
// 
//     public Customer(Timestamp businessDate)
//     {
//         super(businessDate);
//     }
// }
// 
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java
// public class CustomerAccount extends CustomerAccountAbstract
// {
//     public CustomerAccount(Timestamp businessDate, Timestamp processingDate)
//     {
//         super(businessDate, processingDate);
//         // You must not modify this constructor. Mithra calls this internally.
//         // You can call this constructor. You can also add new constructors.
//     }
// 
//     public CustomerAccount(Timestamp businessDate)
//     {
//         super(businessDate);
//     }
// }
// 
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccountList.java
// public class CustomerAccountList extends CustomerAccountListAbstract
// {
//     public CustomerAccountList()
//     {
//         super();
//     }
// 
//     public CustomerAccountList(int initialSize)
//     {
//         super(initialSize);
//     }
// 
//     public CustomerAccountList(Collection c)
//     {
//         super(c);
//     }
// 
//     public CustomerAccountList(Operation operation)
//     {
//         super(operation);
//     }
// }
// 
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/web/BitemporalBankServer.java
// public class BitemporalBankServer
// {
// 
//     private ResourceConfig config;
// 
//     public BitemporalBankServer(String runtimeConfigXML) throws Exception
//     {
//         this.initReladomo(runtimeConfigXML);
//     }
// 
//     public static void main(String[] args) throws Exception
//     {
//         String runtimeConfigXML = "reladomoxml/bitemporalbankRuntimeConfiguration.xml";
//         new BitemporalBankServer(runtimeConfigXML).start();
//     }
// 
//     protected void initReladomo(String runtimeConfigXML) throws Exception
//     {
//         MithraManager mithraManager = MithraManagerProvider.getMithraManager();
//         mithraManager.setTransactionTimeout(60 * 1000);
//         loadReladomoXML(runtimeConfigXML);
//     }
// 
//     protected void loadReladomoXML(String fileName) throws Exception
//     {
//         InputStream stream = BitemporalBankServer.class.getClassLoader().getResourceAsStream(fileName);
//         if (stream == null)
//         {
//             throw new Exception("Failed to locate " + fileName + " in classpath");
//         }
//         MithraManagerProvider.getMithraManager().readConfiguration(stream);
//         stream.close();
//     }
// 
//     protected void initResources()
//     {
//         this.config = new ResourceConfig(CustomerResource.class);
//         config.register(JacksonFeature.class);
//         config.register(BitemporalBankJacksonObjectMapperProvider.class);
//     }
// 
//     public void start() throws IOException
//     {
//         initResources();
//         URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build();
//         HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);
//         server.start();
//     }
// }


import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import static org.junit.Assert.assertEquals;
import bitemporalbank.domain.Customer;
import bitemporalbank.domain.CustomerAccount;
import bitemporalbank.domain.CustomerAccountList;
import bitemporalbank.serialization.BitemporalBankJacksonObjectMapperProvider;
import bitemporalbank.web.BitemporalBankServer;
import com.gs.fw.common.mithra.test.ConnectionManagerForTests;
import com.gs.fw.common.mithra.test.MithraTestResource;
import com.gs.fw.common.mithra.util.serializer.Serialized;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.junit.Before;
import org.junit.Test;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
/*
Copyright 2016 Goldman Sachs.
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 bitemporalbank.api;




public class BitemporalBankAPITest
{
    private String testRuntimeConfigXML = "testconfig/BitemporalBankTestRuntimeConfiguration.xml";

    @Before
    public void setup() throws Exception
    {
        intializeReladomoForTest();
        initializeApp();
    }

    private void intializeReladomoForTest()
    {
        MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML);
        ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db");
        testResource.createSingleDatabase(connectionManager, "testconfig/BitemporalBankTestData.txt");
        testResource.setUp();
    }

    private void initializeApp() throws Exception
    {
        new BitemporalBankServer(testRuntimeConfigXML).start();
    }

    @Test
    public void testGetCustomer()
    {
        WebTarget target = webTarget("/api/customer/1");
        Response response = target
                .queryParam("businessDate", "2017-01-20")
                .request(MediaType.APPLICATION_JSON_TYPE)
                .get();

        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/Customer.java
// public class Customer extends CustomerAbstract
// {
//     public Customer(Timestamp businessDate, Timestamp processingDate)
//     {
//         super(businessDate, processingDate);
//         // You must not modify this constructor. Mithra calls this internally.
//         // You can call this constructor. You can also add new constructors.
//     }
// 
//     public Customer(Timestamp businessDate)
//     {
//         super(businessDate);
//     }
// }
// 
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccount.java
// public class CustomerAccount extends CustomerAccountAbstract
// {
//     public CustomerAccount(Timestamp businessDate, Timestamp processingDate)
//     {
//         super(businessDate, processingDate);
//         // You must not modify this constructor. Mithra calls this internally.
//         // You can call this constructor. You can also add new constructors.
//     }
// 
//     public CustomerAccount(Timestamp businessDate)
//     {
//         super(businessDate);
//     }
// }
// 
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/domain/CustomerAccountList.java
// public class CustomerAccountList extends CustomerAccountListAbstract
// {
//     public CustomerAccountList()
//     {
//         super();
//     }
// 
//     public CustomerAccountList(int initialSize)
//     {
//         super(initialSize);
//     }
// 
//     public CustomerAccountList(Collection c)
//     {
//         super(c);
//     }
// 
//     public CustomerAccountList(Operation operation)
//     {
//         super(operation);
//     }
// }
// 
// Path: reladomo-tour/tour-examples/bitemporal-bank/src/main/java/bitemporalbank/web/BitemporalBankServer.java
// public class BitemporalBankServer
// {
// 
//     private ResourceConfig config;
// 
//     public BitemporalBankServer(String runtimeConfigXML) throws Exception
//     {
//         this.initReladomo(runtimeConfigXML);
//     }
// 
//     public static void main(String[] args) throws Exception
//     {
//         String runtimeConfigXML = "reladomoxml/bitemporalbankRuntimeConfiguration.xml";
//         new BitemporalBankServer(runtimeConfigXML).start();
//     }
// 
//     protected void initReladomo(String runtimeConfigXML) throws Exception
//     {
//         MithraManager mithraManager = MithraManagerProvider.getMithraManager();
//         mithraManager.setTransactionTimeout(60 * 1000);
//         loadReladomoXML(runtimeConfigXML);
//     }
// 
//     protected void loadReladomoXML(String fileName) throws Exception
//     {
//         InputStream stream = BitemporalBankServer.class.getClassLoader().getResourceAsStream(fileName);
//         if (stream == null)
//         {
//             throw new Exception("Failed to locate " + fileName + " in classpath");
//         }
//         MithraManagerProvider.getMithraManager().readConfiguration(stream);
//         stream.close();
//     }
// 
//     protected void initResources()
//     {
//         this.config = new ResourceConfig(CustomerResource.class);
//         config.register(JacksonFeature.class);
//         config.register(BitemporalBankJacksonObjectMapperProvider.class);
//     }
// 
//     public void start() throws IOException
//     {
//         initResources();
//         URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build();
//         HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);
//         server.start();
//     }
// }


// Path: reladomo-tour/tour-examples/bitemporal-bank/src/test/java/bitemporalbank/api/BitemporalBankAPITest.java
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import static org.junit.Assert.assertEquals;
import bitemporalbank.domain.Customer;
import bitemporalbank.domain.CustomerAccount;
import bitemporalbank.domain.CustomerAccountList;
import bitemporalbank.serialization.BitemporalBankJacksonObjectMapperProvider;
import bitemporalbank.web.BitemporalBankServer;
import com.gs.fw.common.mithra.test.ConnectionManagerForTests;
import com.gs.fw.common.mithra.test.MithraTestResource;
import com.gs.fw.common.mithra.util.serializer.Serialized;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.junit.Before;
import org.junit.Test;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

/*
Copyright 2016 Goldman Sachs.
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 bitemporalbank.api;




public class BitemporalBankAPITest
{
    private String testRuntimeConfigXML = "testconfig/BitemporalBankTestRuntimeConfiguration.xml";

    @Before
    public void setup() throws Exception
    {
        intializeReladomoForTest();
        initializeApp();
    }

    private void intializeReladomoForTest()
    {
        MithraTestResource testResource = new MithraTestResource(testRuntimeConfigXML);
        ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance("test_db");
        testResource.createSingleDatabase(connectionManager, "testconfig/BitemporalBankTestData.txt");
        testResource.setUp();
    }

    private void initializeApp() throws Exception
    {
        new BitemporalBankServer(testRuntimeConfigXML).start();
    }

    @Test
    public void testGetCustomer()
    {
        WebTarget target = webTarget("/api/customer/1");
        Response response = target
                .queryParam("businessDate", "2017-01-20")
                .request(MediaType.APPLICATION_JSON_TYPE)
                .get();

        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        Serialized<Customer> mickeySerialized = response.readEntity(new GenericType<Serialized<Customer>>()