package org.socialfarm.camarilla;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author vpathak
 */
public class OrderTest {
    
    public OrderTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }
    
    @Before
    public void setUp() {
    }
    
    @After
    public void tearDown() {
    }

    /**
     * Test of hasExpired method, of class Order.
     */
    @Test
    public void testHasExpired() {
        System.out.println("hasExpired");
        Order instance = null;
        boolean expResult = false;
        boolean result = instance.hasExpired();
        assertEquals(expResult, result);
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
    }
}

@@ -159,16 +159,109 @@
 t.Test;%0A
+%0Aimport javax.json.Json;%0Aimport javax.json.JsonObject;%0Aimport javax.json.JsonObjectBuilder;%0A%0A
 import s
@@ -342,20 +342,69 @@
 rTest %7B%0A
+%0A
     
+JsonObjectBuilder job ;%0A%0A    JsonObject order ;%0A
 %0A    pub
@@ -638,127 +638,732 @@
     
-%7D%0A    %0A    @After%0A    public void tearDown() %7B%0A    %7D%0A%0A    /**%0A     * Test of hasExpired method, of class Order.%0A     */
+    job = Json.createObjectBuilder();%0A        order = job.add(%22testField%22, %22TestValue%22).build();%0A        System.out.println( %22created %22 + order.toString() ) ;%0A    %7D%0A    %0A    @After%0A    public void tearDown() %7B%0A    %7D%0A%0A    //------------------------- test expiresAt ------------------------------------%0A    @Test%0A    public void testexpiresAtMustExist() %7B%0A        Order instance = null;%0A        try %7B%0A            instance = new Order(order.toString());%0A        %7D catch (CamarillaException e) %7B%0A            //e.printStackTrace();%0A            System.out.println( %22expiredAt missing prevents order from being created - OK %22 ) ;%0A            return;%0A        %7D%0A        fail( %22mus not create order if expiresAt is missing%22 );%0A    %7D%0A%0A
 %0A   
@@ -1393,155 +1393,592 @@
 test
-HasE
+e
 xpire
-d() %7B%0A        System.out.println(%22hasExpired%22);%0A        Order instance = null;%0A        boolean expResult = false;%0A        boolean result =
+sAtWorks() throws InterruptedException %7B%0A        final long expiresAt = 2000 + System.currentTimeMillis() ;%0A        order = job.add(%22expiresAt%22 , expiresAt ).add( %22itemName%22 , %22testItem%22 ).build() ;%0A%0A        Order instance = null;%0A        try %7B%0A            instance = new Order(order.toString());%0A        %7D catch (CamarillaException e) %7B%0A            e.printStackTrace();%0A            fail(%22must be able to create if expiredAt is present%22) ;%0A        %7D%0A%0A        while( System.currentTimeMillis() %3C expiresAt ) %7B%0A            assertFalse(%22instance does not expire when it shouldnt %22,
  ins
@@ -1995,16 +1995,17 @@
 xpired()
+)
 ;%0A      
@@ -2010,169 +2010,872 @@
     
-assertEquals(expResult, result)
+    System.out.println( %22tested hasExpired() works OK %22 ) ;%0A            Thread.sleep(1000);%0A        %7D%0A%0A        assertTrue( %22instance expires when it should %22 , instance.hasExpired() );%0A        System.out.println( %22tested hasExpired() works OK %22 ) 
 ;%0A    
+%7D%0A%0A%0A
     //
- TODO review the generated test code and remove the default call to fail.%0A        fail(%22The test case is a prototype.%22
+------------- item name tests --------------------------------%0A    @Test%0A    public void testitemNameMustExist() %7B%0A        final long expiresAt = 2000 + System.currentTimeMillis() ;%0A        order = job.add(%22expiresAt%22 , expiresAt ).build() ;%0A%0A        Order instance = null;%0A        try %7B%0A            instance = new Order(order.toString());%0A        %7D catch (CamarillaException e) %7B%0A            //e.printStackTrace();%0A            System.out.println( %22itemName missing prevents order from being created - OK %22 ) ;%0A            return;%0A        %7D%0A        fail( %22mus not create order if itemName is missing%22 
 );%0A 
@@ -2879,10 +2879,12 @@
 ;%0A    %7D%0A
+%0A%0A
 %7D%0A

order tests