// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java
// public class Customer extends CustomerAbstract
// {
//     public Customer()
//     {
//         super();
//         // You must not modify this constructor. Mithra calls this internally.
//         // You can call this constructor. You can also add new constructors.
//     }
// 
//     public Customer(int customerId, String firstName, String lastName)
//     {
//         super();
//         this.setCustomerId(customerId);
//         this.setFirstName(firstName);
//         this.setLastName(lastName);
//     }
// }
// 
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccount.java
// public class CustomerAccount extends CustomerAccountAbstract
// {
//     public CustomerAccount()
//     {
//         super();
//         // You must not modify this constructor. Mithra calls this internally.
//         // You can call this constructor. You can also add new constructors.
//     }
// }
// 
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/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/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java
// public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper>
// {
//     final ObjectMapper defaultObjectMapper;
// 
//     public SimpleBankJacksonObjectMapperProvider()
//     {
//         defaultObjectMapper = new ObjectMapper();
//         defaultObjectMapper.registerModule(new JacksonReladomoModule());
//     }
// 
//     @Override
//     public ObjectMapper getContext(Class<?> type)
//     {
//         return defaultObjectMapper;
//     }
// }
// 
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java
// public class SimpleBankServer
// {
//     private ResourceConfig config;
// 
//     public SimpleBankServer(String runtimeConfigXML) throws Exception
//     {
//         this.initReladomo(runtimeConfigXML);
//     }
// 
//     protected void initReladomo(String runtimeConfigXML) throws Exception
//     {
//         MithraManager mithraManager = MithraManagerProvider.getMithraManager();
//         mithraManager.setTransactionTimeout(60 * 1000);
//         InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML);
//         MithraManagerProvider.getMithraManager().readConfiguration(stream);
//         stream.close();
//     }
// 
//     private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception
//     {
//         InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName);
//         if (stream == null)
//         {
//             throw new Exception("Failed to locate " + fileName + " in classpath");
//         }
//         return stream;
//     }
// 
//     protected void initResources()
//     {
//         this.config = new ResourceConfig(CustomerResource.class);
//         config.register(JacksonFeature.class);
//         config.register(SimpleBankJacksonObjectMapperProvider.class);
//     }
// 
//     public void start() throws IOException
//     {
//         initResources();
//         URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build();
//         HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);
//         server.start();
//     }
// 
//     public static void main(String[] args) throws Exception
//     {
//         String runtimeConfigXML = "reladomoxml/SimpleBankRuntimeConfiguration.xml";
//         new SimpleBankServer(runtimeConfigXML).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 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 simplebank.domain.Customer;
import simplebank.domain.CustomerAccount;
import simplebank.domain.CustomerAccountList;
import simplebank.serialization.SimpleBankJacksonObjectMapperProvider;
import simplebank.web.SimpleBankServer;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
    @Test
    public void testGetCustomer()
    {
        WebTarget target = webTarget("/api/customer/1");
        Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get();

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

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

        Customer mickey = mickeySerialized.getWrapped();
        assertEquals(1, mickey.getCustomerId());
        assertEquals("mickey", mickey.getFirstName());
        assertEquals("mouse", mickey.getLastName());

        CustomerAccountList mickeysAccounts = mickey.getAccounts();
        assertEquals(1, mickeysAccounts.size());
        CustomerAccount clubhouseAccount = mickeysAccounts.get(0);
        assertEquals(100, clubhouseAccount.getAccountId());
        assertEquals("mickey mouse club", clubhouseAccount.getAccountName());
        assertEquals("savings", clubhouseAccount.getAccountType());
        assertEquals(5000, clubhouseAccount.getBalance(), 0);
    }

    private WebTarget webTarget(String path)
    {
        Client client = ClientBuilder.newClient();
        client.register(JacksonFeature.class);
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/Customer.java
// public class Customer extends CustomerAbstract
// {
//     public Customer()
//     {
//         super();
//         // You must not modify this constructor. Mithra calls this internally.
//         // You can call this constructor. You can also add new constructors.
//     }
// 
//     public Customer(int customerId, String firstName, String lastName)
//     {
//         super();
//         this.setCustomerId(customerId);
//         this.setFirstName(firstName);
//         this.setLastName(lastName);
//     }
// }
// 
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/domain/CustomerAccount.java
// public class CustomerAccount extends CustomerAccountAbstract
// {
//     public CustomerAccount()
//     {
//         super();
//         // You must not modify this constructor. Mithra calls this internally.
//         // You can call this constructor. You can also add new constructors.
//     }
// }
// 
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/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/simple-bank/src/main/java/simplebank/serialization/SimpleBankJacksonObjectMapperProvider.java
// public class SimpleBankJacksonObjectMapperProvider implements ContextResolver<ObjectMapper>
// {
//     final ObjectMapper defaultObjectMapper;
// 
//     public SimpleBankJacksonObjectMapperProvider()
//     {
//         defaultObjectMapper = new ObjectMapper();
//         defaultObjectMapper.registerModule(new JacksonReladomoModule());
//     }
// 
//     @Override
//     public ObjectMapper getContext(Class<?> type)
//     {
//         return defaultObjectMapper;
//     }
// }
// 
// Path: reladomo-tour/tour-examples/simple-bank/src/main/java/simplebank/web/SimpleBankServer.java
// public class SimpleBankServer
// {
//     private ResourceConfig config;
// 
//     public SimpleBankServer(String runtimeConfigXML) throws Exception
//     {
//         this.initReladomo(runtimeConfigXML);
//     }
// 
//     protected void initReladomo(String runtimeConfigXML) throws Exception
//     {
//         MithraManager mithraManager = MithraManagerProvider.getMithraManager();
//         mithraManager.setTransactionTimeout(60 * 1000);
//         InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML);
//         MithraManagerProvider.getMithraManager().readConfiguration(stream);
//         stream.close();
//     }
// 
//     private InputStream loadReladomoXMLFromClasspath(String fileName) throws Exception
//     {
//         InputStream stream = SimpleBankServer.class.getClassLoader().getResourceAsStream(fileName);
//         if (stream == null)
//         {
//             throw new Exception("Failed to locate " + fileName + " in classpath");
//         }
//         return stream;
//     }
// 
//     protected void initResources()
//     {
//         this.config = new ResourceConfig(CustomerResource.class);
//         config.register(JacksonFeature.class);
//         config.register(SimpleBankJacksonObjectMapperProvider.class);
//     }
// 
//     public void start() throws IOException
//     {
//         initResources();
//         URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build();
//         HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config);
//         server.start();
//     }
// 
//     public static void main(String[] args) throws Exception
//     {
//         String runtimeConfigXML = "reladomoxml/SimpleBankRuntimeConfiguration.xml";
//         new SimpleBankServer(runtimeConfigXML).start();
//     }
// }


// Path: reladomo-tour/tour-examples/simple-bank/src/test/java/simplebank/api/SimpleBankAPITest.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 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 simplebank.domain.Customer;
import simplebank.domain.CustomerAccount;
import simplebank.domain.CustomerAccountList;
import simplebank.serialization.SimpleBankJacksonObjectMapperProvider;
import simplebank.web.SimpleBankServer;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

    @Test
    public void testGetCustomer()
    {
        WebTarget target = webTarget("/api/customer/1");
        Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get();

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

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

        Customer mickey = mickeySerialized.getWrapped();
        assertEquals(1, mickey.getCustomerId());
        assertEquals("mickey", mickey.getFirstName());
        assertEquals("mouse", mickey.getLastName());

        CustomerAccountList mickeysAccounts = mickey.getAccounts();
        assertEquals(1, mickeysAccounts.size());
        CustomerAccount clubhouseAccount = mickeysAccounts.get(0);
        assertEquals(100, clubhouseAccount.getAccountId());
        assertEquals("mickey mouse club", clubhouseAccount.getAccountName());
        assertEquals("savings", clubhouseAccount.getAccountType());
        assertEquals(5000, clubhouseAccount.getBalance(), 0);
    }

    private WebTarget webTarget(String path)
    {
        Client client = ClientBuilder.newClient();
        client.register(JacksonFeature.class);
        client.register(SimpleBankJacksonObjectMapperProvider.class);