<commit_before>package org.nakedobjects.example.ecs;

import org.nakedobjects.object.defaults.value.Date;
import org.nakedobjects.object.defaults.value.TextString;
import org.nakedobjects.object.exploration.AbstractExplorationFixture;
import org.nakedobjects.xat.AcceptanceTestCase;
import org.nakedobjects.xat.TestObject;



public class ECSAcceptanceTest extends AcceptanceTestCase {

    public static void main(java.lang.String[] args) {
        junit.textui.TestRunner.run(ECSAcceptanceTest.class);
    }
    
    public ECSAcceptanceTest(String name) {
        super(name);
    }


     protected void setUpFixtures() {
         addFixture(new AbstractExplorationFixture() {
             public void install() {
                 registerClass(Booking.class);
                 registerClass(City.class);
                 registerClass(Customer.class);
                 registerClass(Location.class);
                 registerClass(CreditCard.class);
                 registerClass(Telephone.class);
                 
                 createCity("Boston");
                 createCity("New York");
                 createCity("Chicago");
                 createCity("Washington");
                 createCity("Philadelphia");
                 
                 setDate(2001, 12, 14);
             }
             
             private void createCity(String name) {
                 City city = (City) createInstance(City.class);
                 city.getName().setValue(name);
             }
         } );
     }
     
    public void testBasicBooking() {
        subtitle("Set up the new booking");
        
        nextStep();

        TestObject booking = getTestClass(Booking.class.getName()).newInstance();

        nextStep("Specify the city that the booking is for");

        TestObject city = getTestClass(City.class.getName()).findInstance("New York");

        booking.associate("City", city);


        //
        nextStep("As this is for a new customer one should be specified rather than looked up");

        TestObject customer = getTestClass(Customer.class.getName()).newInstance();

        booking.associate("Customer", customer);
        customer.fieldEntry("First Name", "Richard");
        customer.fieldEntry("Last Name", "Pawson");


        //
        nextStep("Specify pick up and drop off locations");

        TestObject pickup = city.invokeAction("New Location");

        pickup.fieldEntry("Street Address", "234 E 42nd Street");
        booking.associate("Pick Up", pickup);

        TestObject dropoff = city.invokeAction("New Location");

        dropoff.fieldEntry("Street Address", "JFK Airport, BA Terminal");
        booking.associate("Drop Off", dropoff);


        //
        nextStep("Specify when to pick up.");
        booking.fieldEntry("Date", "+2");
        booking.fieldEntry("Time", "2:30:00 PM");

        booking.assertFieldContains("Date", new Date(2001, 12, 16));
        

        //
        nextStep("Specify the  payment method.");

        TestObject payment = getTestClass(CreditCard.class.getName()).newInstance();

        booking.associate("Payment Method", payment);
        payment.fieldEntry("Name On Card", "<NAME>");
        payment.fieldEntry("Number", "4927834512344535");
        payment.fieldEntry("Expires", "01/04");


        //
        nextStep("Specify other details.");

        TestObject phone = getTestClass(Telephone.class.getName()).newInstance();

        booking.associate("Contact Telephone", phone);
        phone.fieldEntry("Number", "6175551234");


        //
        nextStep("Ask the customer if this is a regular number (e.g. a mobile) and if so, associate it with the customer for future use");
        phone.fieldEntry("Known As", "Mobile");
        customer.associate("Phone Numbers", phone);


        //
        nextStep("Check it is available.");
        booking.invokeAction("Check Availability");
        booking.assertFieldContains("Status", new TextString("Available"));


        //
        nextStep("And then confirm.");
        booking.invokeAction("Confirm");
        booking.assertFieldContains("Status", "Confirmed");


        //
        customer.assertFieldContains("Locations", pickup);
        customer.assertFieldContains("Locations", dropoff);
    }

    public void testReuseBooking() {
        // setup
        testBasicBooking();
        // end of setup
        
        firstStep("Retrieve the customer object.");
        
        TestObject customer = getTestClass(Customer.class.getName()).findInstance("Pawson");

        nextStep("Create a booking for this customer.");

        TestObject booking = customer.invokeAction("New Booking");

        booking.assertFieldContains("Customer", customer);
        nextStep("Retrieve the customer's home and office as the pick-up and drop-off locations.");
        booking.associate("Pick Up", 
                customer.getField("Locations", "234 E 42nd Street, New York"));
        booking.associate("Drop Off", 
                customer.getField("Locations", 
                "JFK Airport, BA Terminal, New York"));
        booking.assertFieldContains("City", "New York");
        nextStep("Use the customer's mobile phone as the contact number for this booking.");

        TestObject mobile = customer.getField("Phone Numbers", "Mobile");

        booking.associate("Contact Telephone", mobile);
        nextStep("Specify when to be picked up.");
        booking.fieldEntry("Date", "2001-12-18");
        booking.fieldEntry("Time", "7:00:00 AM");
        booking.assertFieldContains("Payment Method", 
                                 (TestObject) customer.getField(
                                         "Preferred Payment Method"));


        nextStep("Check it is available");
        booking.invokeAction("Check Availability");
        booking.assertFieldContains("Status", "Available");
        nextStep("And then confrm");
        booking.invokeAction("Confirm");
        booking.assertFieldContains("Status", "Confirmed");
    }
    
    public void testNewMethods() {
//      setup
        testBasicBooking();
        // end of setup<commit_msg>Moved the XAT to a separate source folder.  This way the eploration build can exclude the XATs.<commit_after>package org.nakedobjects.example.ecs;

import org.nakedobjects.object.defaults.value.Date;
import org.nakedobjects.object.defaults.value.TextString;
import org.nakedobjects.object.exploration.AbstractExplorationFixture;
import org.nakedobjects.xat.AcceptanceTestCase;
import org.nakedobjects.xat.TestObject;



public class ECSAcceptanceTest extends AcceptanceTestCase {

    public static void main(java.lang.String[] args) {
        junit.textui.TestRunner.run(ECSAcceptanceTest.class);
    }
    
    public ECSAcceptanceTest(String name) {
        super(name);
    }


     protected void setUpFixtures() {
         addFixture(new AbstractExplorationFixture() {
             public void install() {
                 registerClass(Booking.class);
                 registerClass(City.class);
                 registerClass(Customer.class);
                 registerClass(Location.class);
                 registerClass(CreditCard.class);
                 registerClass(Telephone.class);
                 
                 createCity("Boston");
                 createCity("New York");
                 createCity("Chicago");
                 createCity("Washington");
                 createCity("Philadelphia");
                 
                 setDate(2001, 12, 14);
             }
             
             private void createCity(String name) {
                 City city = (City) createInstance(City.class);
                 city.getName().setValue(name);
             }
         } );
     }
     
    public void testBasicBooking() {
        subtitle("Set up the new booking");
        
        nextStep();

        TestObject booking = getTestClass(Booking.class.getName()).newInstance();

        nextStep("Specify the city that the booking is for");

        TestObject city = getTestClass(City.class.getName()).findInstance("New York");

        booking.associate("City", city);


        //
        nextStep("As this is for a new customer one should be specified rather than looked up");

        TestObject customer = getTestClass(Customer.class.getName()).newInstance();

        booking.associate("Customer", customer);
        customer.fieldEntry("First Name", "Richard");
        customer.fieldEntry("Last Name", "Pawson");


        //
        nextStep("Specify pick up and drop off locations");

        TestObject pickup = city.invokeAction("New Location");

        pickup.fieldEntry("Street Address", "234 E 42nd Street");
        booking.associate("Pick Up", pickup);

        TestObject dropoff = city.invokeAction("New Location");

        dropoff.fieldEntry("Street Address", "JFK Airport, BA Terminal");
        booking.associate("Drop Off", dropoff);


        //
        nextStep("Specify when to pick up.");
        booking.fieldEntry("Date", "+2");
        booking.fieldEntry("Time", "2:30:00 PM");

        booking.assertFieldContains("Date", new Date(2001, 12, 16));
        

        //
        nextStep("Specify the  payment method.");

        TestObject payment = getTestClass(CreditCard.class.getName()).newInstance();

        booking.associate("Payment Method", payment);
        payment.fieldEntry("Name On Card", "<NAME>");
        payment.fieldEntry("Number", "4927834512344535");
        payment.fieldEntry("Expires", "01/04");


        //
        nextStep("Specify other details.");

        TestObject phone = getTestClass(Telephone.class.getName()).newInstance();

        booking.associate("Contact Telephone", phone);
        phone.fieldEntry("Number", "6175551234");


        //
        nextStep("Ask the customer if this is a regular number (e.g. a mobile) and if so, associate it with the customer for future use");
        phone.fieldEntry("Known As", "Mobile");
        customer.associate("Phone Numbers", phone);


        //
        nextStep("Check it is available.");
        booking.invokeAction("Check Availability");
        booking.assertFieldContains("Status", new TextString("Available"));


        //
        nextStep("And then confirm.");
        booking.invokeAction("Confirm");
        booking.assertFieldContains("Status", "Confirmed");


        //
        customer.assertFieldContains("Locations", pickup);
        customer.assertFieldContains("Locations", dropoff);
    }

    public void testReuseBooking() {
        // setup
        testBasicBooking();
        // end of setup
        
        firstStep("Retrieve the customer object.");
        
        TestObject customer = getTestClass(Customer.class.getName()).findInstance("Pawson");

        nextStep("Create a booking for this customer.");

        TestObject booking = customer.invokeAction("New Booking");

        booking.assertFieldContains("Customer", customer);
        nextStep("Retrieve the customer's home and office as the pick-up and drop-off locations.");
        booking.associate("Pick Up", 
                customer.getField("Locations", "234 E 42nd Street, New York"));
        booking.associate("Drop Off", 
                customer.getField("Locations", 
                "JFK Airport, BA Terminal, New York"));
        booking.assertFieldContains("City", "New York");
        nextStep("Use the customer's mobile phone as the contact number for this booking.");

        TestObject mobile = customer.getField("Phone Numbers", "Mobile");

        booking.associate("Contact Telephone", mobile);
        nextStep("Specify when to be picked up.");
        booking.fieldEntry("Date", "2001-12-18");
        booking.fieldEntry("Time", "7:00:00 AM");
        booking.assertFieldContains("Payment Method", 
                                 (TestObject) customer.getField(
                                         "Preferred Payment Method"));


        nextStep("Check it is available");
        booking.invokeAction("Check Availability");
        booking.assertFieldContains("Status", "Available");
        nextStep("And then confrm");
        booking.invokeAction("Confirm");
        booking.assertFieldContains("Status", "Confirmed");
    }
    
    public void testNewMethods() {
       testBasicBooking();
        // end of setup
{'fraction_non_alphanumeric': 0.11806739748274463, 'fraction_numerical': 0.012180267965895249, 'mean_word_length': 2.366867140513942, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4670338', 'n_tokens_mistral': 3247, 'n_tokens_neox': 3036, 'n_words': 726}