@Test
 public void updateNonExistingCustomer() {
   final int nonExistingId = getNonExistingCustomerId();
   final String newFirstname = "Douglas";
   final String newLastname = "MacArthur";
   final Customer customer = new Customer(nonExistingId, newFirstname, newLastname);
   impl.updateCustomer(customer);
   assertNull(impl.getCustomerById(nonExistingId));
   final Customer existingCustomer = impl.getCustomerById(CUSTOMER.getId());
   assertEquals(CUSTOMER.getFirstName(), existingCustomer.getFirstName());
   assertEquals(CUSTOMER.getLastName(), existingCustomer.getLastName());
 }
 @RequestMapping(value = "/customers/{id}", method = RequestMethod.PUT)
 ResponseEntity<Resource<Customer>> put(@PathVariable Long id, @RequestBody Customer c) {
   Customer customer =
       this.customerRepository.save(new Customer(id, c.getFirstName(), c.getLastName()));
   Resource<Customer> customerResource = this.customerResourceAssembler.toResource(customer);
   URI selfLink = URI.create(ServletUriComponentsBuilder.fromCurrentRequest().toUriString());
   return ResponseEntity.created(selfLink).body(customerResource);
 }
  public void testGeneratedCustomer() {
    CreateTestCustomerClass testObjectCreator = new CreateTestCustomerClass();
    Customer customer =
        testObjectCreator
            .createParam1Customer_au_com_dw_testdatacapturej_explanation_ExplanationTest_joinPointParamForCustomer();

    assertTrue("John".equals(customer.getFirstName()));
    assertTrue("Smith".equals(customer.getSurName()));
  }
 @Test
 public void updateExistingCustomer() {
   final String newFirstname = "Bernard";
   final String newLastname = "Montgomery";
   final Customer customer = new Customer(CUSTOMER.getId(), newFirstname, newLastname);
   impl.updateCustomer(customer);
   final Customer cust = impl.getCustomerById(CUSTOMER.getId());
   assertEquals(newFirstname, cust.getFirstName());
   assertEquals(newLastname, cust.getLastName());
 }
  @RequestMapping(value = "/customers", method = RequestMethod.POST)
  ResponseEntity<Resource<Customer>> post(@RequestBody Customer c) {

    Customer customer =
        this.customerRepository.save(new Customer(c.getFirstName(), c.getLastName()));
    URI uri =
        MvcUriComponentsBuilder.fromController(getClass())
            .path("/customers/{id}")
            .buildAndExpand(customer.getId())
            .toUri();
    return ResponseEntity.created(uri).body(this.customerResourceAssembler.toResource(customer));
  }
  @Test
  public void updateCustomerFromTransparentRedirect() {
    CustomerRequest request = new CustomerRequest().firstName("John").lastName("Doe");
    Customer customer = gateway.customer().create(request).getTarget();

    CustomerRequest updateRequest = new CustomerRequest().firstName("Jane");
    CustomerRequest trParams = new CustomerRequest().customerId(customer.getId()).lastName("Dough");
    String queryString =
        TestHelper.simulateFormPostForTR(
            gateway, trParams, updateRequest, gateway.transparentRedirect().url());

    Result<Customer> result = gateway.transparentRedirect().confirmCustomer(queryString);

    assertTrue(result.isSuccess());
    Customer updatedCustomer = gateway.customer().find(customer.getId());
    assertEquals("Jane", updatedCustomer.getFirstName());
    assertEquals("Dough", updatedCustomer.getLastName());
  }
  public static void main(String[] args) throws Exception {
    HashMap map = new HashMap();
    // map.put("hibernate.show_sql", "true");
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("titan", map);
    EntityManager entityManager = factory.createEntityManager();
    entityManager.getTransaction().begin();
    try {
      System.out.println("Initialize DB");
      InitializeDB.initialize(entityManager);
      System.out.println();
      System.out.println();

      System.out.println("Find Bill Burke by named parameter");
      Customer cust = findCustomerByNamedParameter(entityManager, "Bill", "Burke");
      System.out.println("Bill Burke's cust id: " + cust.getId());
      System.out.println();
      System.out.println();

      System.out.println("Find Gavin King by indexed parameter");
      cust = findCustomerByIndexedParameter(entityManager, "Gavin", "King");
      System.out.println("Gavin King's cust id: " + cust.getId());
      System.out.println();
      System.out.println();

      System.out.println("Output all customers via paging");
      List results;
      int first = 0;
      int max = 2;
      do {
        results = getCustomers(entityManager, max, first);
        Iterator it = results.iterator();
        while (it.hasNext()) {
          Customer c = (Customer) it.next();
          System.out.println(c.getFirstName() + " " + c.getLastName());
        }
        entityManager.clear();
        first = first + results.size();
      } while (results.size() > 0);
    } finally {
      entityManager.getTransaction().commit();
      entityManager.close();
      factory.close();
    }
  }
 public void setCustomerID(int customerID) {
   CustomerID = customerID;
   lblAddCustomer.setText("Edit Customer");
   Customer customer = CustomerBL.GetCustomer(GetPU(), customerID);
   if (customer != null) {
     txtFirstName.setText(customer.getFirstName());
     txtLastName.setText(customer.getLastName());
     txtUsername.setText(customer.getUsername());
     txtUsername.setEditable(false);
     txtPassword.setText("");
     txtEmail.setText(customer.getEmail());
     txtPhone.setText(customer.getPhone());
     txtStreet1.setText(customer.getAddr_Street1());
     txtStreet2.setText(customer.getAddr_Street2());
     txtCity.setText(customer.getAddr_City());
     txtState.setText(customer.getAddr_State());
     txtZipcode.setText(customer.getAddr_Zipcode());
     txtCountry.setText(customer.getAddr_Country());
     chkActive.setSelected(customer.isIsActive());
   }
 }
示例#9
0
  public static void main(String[] args) {
    try {
      Context jndiContext = getInitialContext();
      Object ref = jndiContext.lookup("TravelAgentBean/remote");
      TravelAgentRemote dao = (TravelAgentRemote) ref;

      CustomerPK pk = new CustomerPK("Burke", 9999999);
      Customer cust = new Customer();
      cust.setPk(pk);
      cust.setFirstName("Bill");

      dao.createCustomer(cust);

      cust = dao.findCustomer("Burke", 9999999);
      System.out.println(cust.getFirstName());
      System.out.println(cust.getLastName());
      System.out.println(cust.getSsn());
    } catch (javax.naming.NamingException ne) {
      ne.printStackTrace();
    }
  }
 public void testSetTextValueByXPath() {
   Customer customer = new Customer();
   xmlContext.setValueByXPath(
       customer, "personal-info/first-name/text()", null, CONTROL_CUSTOMER_FIRST_NAME);
   assertEquals(CONTROL_CUSTOMER_FIRST_NAME, customer.getFirstName());
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_edit_customer);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    String[] data = {"owner", "rent"};
    String status;
    spinner = (Spinner) findViewById(R.id.spinner);
    toDayDate = new SimpleDateFormat("dd-MM-yyyy").format(new Date());

    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner = (Spinner) findViewById(R.id.spinner);
    spinner.setAdapter(adapter);
    spinner.setPrompt("Title");
    spinner.setSelection(0);
    spinner.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
              mPosition = 0;
            }
            if (position == 1) {
              mPosition = 1;
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {}
        });

    mApartmentNumberEditText = (EditText) findViewById(R.id.ApartmentNumberEditText);
    mFirstNameEditText = (EditText) findViewById(R.id.FirstNameEditText);
    mLastNameEditText = (EditText) findViewById(R.id.LastNameEditText);
    mEmailEditText = (EditText) findViewById(R.id.EmailEditText);
    mPhoneHomeEditText = (EditText) findViewById(R.id.PhoneHomeEditText);
    mPhoneMobileEditText = (EditText) findViewById(R.id.PhoneMobileEditText);
    mMonthlyPaymentNumberEditText = (EditText) findViewById(R.id.MonthlyPaymentNumberEditText);
    mPreviousBalanceEditText = (EditText) findViewById(R.id.PreviousBalanceEditText);
    mDateEditText = (EditText) findViewById(R.id.DateEditText);

    Intent intent = getIntent();
    mDbOpenHelperCustomer = new DbOpenHelperCustomer(this);

    int customerId = intent.getIntExtra("ID", -1);
    if (customerId > -1) {
      mCustomer = mDbOpenHelperCustomer.getCustomerById(customerId);
      if (mCustomer != null) {
        Log.d("MyLog", "som");
        edit = true;
        mApartmentNumberEditText.setText(mCustomer.getApartmentNumber());
        mFirstNameEditText.setText(mCustomer.getFirstName());
        mLastNameEditText.setText(mCustomer.getLastName());
        mEmailEditText.setText(mCustomer.getEmail());
        mPhoneHomeEditText.setText(mCustomer.getPhoneHome());
        mPhoneMobileEditText.setText(mCustomer.getPhoneMobil());
        mMonthlyPaymentNumberEditText.setText(mCustomer.getMonthlyPayment());
        mPreviousBalanceEditText.setText(mCustomer.getPreviousBalance());
        spinner.setSelection(mCustomer.getCustomerStatus());
        mPosition = mCustomer.getCustomerStatus();
        mDateEditText.setText(mCustomer.getDate());
      }
    }

    Button actionButton = (Button) findViewById(R.id.actionButton);
    if (edit) {
      actionButton.setText("Update");
      apartment = mCustomer.getApartmentNumber();
    } else {
      actionButton.setText("Create");
      mDateEditText.setText(toDayDate);
    }
    actionButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {

            if (!edit) {
              if (!mDbOpenHelperCustomer.idExist(mApartmentNumberEditText.getText().toString())) {
                Toast.makeText(getApplication(), "Already taken ", Toast.LENGTH_SHORT).show();
                return;
              }
            }

            if (edit) {
              if (!apartment.equals(mApartmentNumberEditText.getText().toString())) {
                List<Customer> customers = mDbOpenHelperCustomer.getCustomers();
                for (Customer customer : customers) {
                  if (customer
                      .getApartmentNumber()
                      .equals(mApartmentNumberEditText.getText().toString())) {

                    Toast.makeText(getApplication(), "Already taken ", Toast.LENGTH_SHORT).show();
                    return;
                  }
                }
              }
            }

            if (TextUtils.isEmpty(mApartmentNumberEditText.getText().toString())) {
              Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT)
                  .show();
              return;
            }
            if (TextUtils.isEmpty(mFirstNameEditText.getText().toString())) {
              Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT)
                  .show();
              return;
            }
            if (TextUtils.isEmpty(mLastNameEditText.getText().toString())) {
              Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT)
                  .show();
              return;
            }
            if (TextUtils.isEmpty(mEmailEditText.getText().toString())) {
              Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT)
                  .show();
              return;
            }
            if (TextUtils.isEmpty(mPhoneHomeEditText.getText().toString())) {
              Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT)
                  .show();
              return;
            }
            if (TextUtils.isEmpty(mPhoneMobileEditText.getText().toString())) {
              Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT)
                  .show();
              return;
            }
            if (TextUtils.isEmpty(mMonthlyPaymentNumberEditText.getText().toString())) {
              Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT)
                  .show();
              return;
            }
            if (TextUtils.isEmpty(mPreviousBalanceEditText.getText().toString())) {
              Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT)
                  .show();
              return;
            }
            //                if (TextUtils.isEmpty(mCustomerStatusEditText.getText().toString())) {
            //                    Toast.makeText(getApplication(), "All fields must be complete ",
            // Toast.LENGTH_SHORT).show();
            //                    return;
            //                }
            if (TextUtils.isEmpty(mDateEditText.getText().toString())) {
              Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT)
                  .show();
              return;
            }

            if (!edit) {
              Log.d("MyLog", "new");
              mCustomer =
                  new Customer(
                      mApartmentNumberEditText.getText().toString(),
                      mFirstNameEditText.getText().toString(),
                      mLastNameEditText.getText().toString(),
                      mEmailEditText.getText().toString(),
                      mPhoneHomeEditText.getText().toString(),
                      mPhoneMobileEditText.getText().toString(),
                      mMonthlyPaymentNumberEditText.getText().toString(),
                      mPreviousBalanceEditText.getText().toString(),
                      mPosition,
                      mDateEditText.getText().toString());
              mDbOpenHelperCustomer.saveCustomer(mCustomer);
            } else {
              Log.d("MyLog", "Back");
              mCustomer.setApartmentNumber(mApartmentNumberEditText.getText().toString());
              mCustomer.setFirstName(mFirstNameEditText.getText().toString());
              mCustomer.setLastName(mLastNameEditText.getText().toString());
              mCustomer.setEmail(mEmailEditText.getText().toString());
              mCustomer.setPhoneHome(mPhoneHomeEditText.getText().toString());
              mCustomer.setPhoneMobil(mPhoneMobileEditText.getText().toString());
              mCustomer.setMonthlyPayment(mMonthlyPaymentNumberEditText.getText().toString());
              mCustomer.setPreviousBalance(mPreviousBalanceEditText.getText().toString());
              mCustomer.setCustomerStatus(mPosition);
              mCustomer.setDate(mDateEditText.getText().toString());
              mDbOpenHelperCustomer.updateCustomer(mCustomer);
            }
            finish();
          }
        });
  }
示例#12
0
 public String toString() {
   return "Order id for " + customer.getFirstName();
 }
示例#13
0
 public final String getCustomerFullName() {
   return customer.getFirstName() + " " + customer.getLastName();
 }