Classes

Document Sample
Classes Powered By Docstoc
					Exercises
Sample Application

     Foreign Cash Exchange
Overview




           2
Exercises Overview




                     3
        Exercise 13

   Homework: For the example scenario "Foreign
    Cash Exchange" develop an UML class diagram
       See description on next slides or in chapter 2
       Work in groups of two (or three)
   Explain your solution to the class
   Discuss the presented solution




                                                         4
       Description Foreign Cash Exchange

Object Types      Description

Branches of the   Name, Location, Opening Hours, Phone Number,
bank              Provided Currencies with actual Amounts
ATMs              Location, Status, Brand, Type , Serial Number
                  Provided Currencies with actual Amounts
Persons           Name, Date of Birth, Email, List of Phone Numbers
                  (Number, Type), List of Addresses (State, City, Street
                  or PO Box, ZIP, Type)

Employees of      Like Persons, additionally
bank              Task, Salary, SSN, Branch, Supervisor, …
                  Relation: Employees advise Customers
Addresses         State, City, Street or PO Box, ZIP, Type

                                                                           5
     Description Foreign Cash Exchange (cont.)

Object Types       Description

Customers of the   Customers can be Persons or Companies
bank               Customer Nr, CostomerSince, Credit Rating
Persons as         Like Persons and Customers
Customers
Companies as       Like Customers, additionally
Customers          Address, Set of Representatives (Persons)
Accounts           Account Nr, Account Type, Currency, Actual Amount,
                   Start Date, End Date, List of Interest Rates, List of
                   Transactions



                                                                           6
     Description Foreign Cash Exchange (cont.)

Object Types      Description

Currency Orders   Date and Time Stamp, Supplied Currency, Supplied
                  Amount, Requested Currency, Requested Amount,
                  Exchange Rate, Fee
Different Types of Payment as Cash, Credit Card, or Account
Curr. Orders
Account Payment Like Currency Order, additionally Account

Credit Card       Like Currency Order, additionally
Payment           Card Nr, Card Organization, Expiration Date
Prepared          Like Currency Order, additionally
Payment           Requestor Name, Requestor Email, Order Nr
                                                                     7
Branch and ATM Class Model


FCE.Branch                 FCE.ATM
Name                       Brand
Address    ATMs    0..*    Type
Phone                      SerialNr
Opens      1      Branch
                           Address
Closes                     CurrencyBalances




                                              8
        How To: Create a Unit Test Class

   Create new class that extends
    %UnitTest.TestCase.
       Each class represents a test case.
   Add methods named Test*.
       Write test code.
       Use macros to make assertions.
   Add additional methods not named Test* for
    control or other purposes.



                                                 9
     How To: Create a Unit Test Class (cont.)

   Write set up and tear down methods when
    necessary.

             Method                 Purpose
     OnBeforeAllTests()   Run before all tests.
     OnAfterAllTests()    Run after all tests.
     OnBeforeOneTest()    Run before each test.
     OnAfterOneTest()     Run after each test.




                                                  10
        How To: Create a Unit Test Class (cont.)

   Compile class.
   Optionally, export class (or classes) as XML file to
    subfolder of root testing folder.
       Each subfolder of root testing folder represents a test
        suite.
       Allows test classes to be loaded, compiled, run, and
        deleted in another namespace.




                                                                  11
        How To: Run Unit Tests

   Run tests using %UnitTest.Manager class.
    do ##class(%UnitTest.Manager).RunTest(TestSpec,
      Qualifiers)

   To run one test case (without XML file):
       Arguments:
            TestSpec = "TestSuiteFolder:TestCaseClass"
            Qualifiers = "/noload/norecursive"
       Without XML file, TestSuiteFolder is “organizational”
        only; used to navigate test results in browser.
            Convention: same as TestCaseClass.



                                                                12
        How To: Run Unit Tests (cont.)

   Run tests using %UnitTest.Manager class.
    do ##class(%UnitTest.Manager).RunTest(TestSpec,
      Qualifiers)

   To load an XML file, compile all its classes, run all
    tests, and delete all classes:
       Argument:
            TestSpec = "TestSuiteFolder"
       Before running test, must also specify root folder for unit
        testing.
         set ^UnitTestRoot = "PathToContainingFolder"




                                                                      13
     ObjectScript Macros

   Macro: named piece of ObjectScript code, usually
    defined at top of method.
    #define sum x+y

   Macro may take arguments (%* variables).
    #define sumplusextra(%extra) x+y+%extra

   When writing method, use macro by preceding
    name with $$$.
    set x=4, y=5, s=$$$sum, b=$$$sumplusextra(6)

   Compiler replaces macro with code.
    set x=4, y=5, s=x+y, b=x+y+6



                                                       14
     Include (INC) files

   File containing several #define statements. For
    example, helper.inc:
    #define sum x+y
    #define sumplusextra(%extra) x+y+%extra
   Including file in class definitions provides all
    macros.
   Use IncludeCode attribute of class, or enter above
    Class statement.
    include helper
   Include file may contain #include statements to
    include other files.

                                                         15
    Unit Testing Macros

Macro     $$$AssertEquals(value1, value2,
          message)
Asserts   value1=value2
Macro     $$$AssertNotEquals(value1, value2,
          message)
Asserts   value1'=value2
Macro     $$$AssertStatusOK(status, message)
Asserts   status is OK
Macro     $$$AssertStatusNotOK(status,
          message)
Asserts   status is not OK
                                               16
    Unit Testing Macros (cont.)

Macro     $$$AssertTrue(condition, message)
Asserts   condition is true
Macro     $$$AssertNotTrue(condition, message)
Asserts   condition is false




                                                 17
    Exercise 14

Description: As class …
 define specification for class Branch

 create unit test class for initial FCE application

 define OOP unit tests for Branch (demonstration)



In your team …
 define specification for class ATM

 define OOP unit tests for ATM




                                                       18

				
DOCUMENT INFO