package com.balancedpayments;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.HashMap;

import com.balancedpayments.errors.*;
import org.junit.Test;


public class CallbackTest extends BaseTest {

    @Test
    public void testCallbackCreate() throws HTTPError, NotCreated, NoResultsFound, MultipleResultsFound {
        Callback.Collection callbacks = mp.callbacks;
        int total = callbacks.total();
        assertEquals(0, total);

        HashMap<String, Object> callbackPayload = new HashMap<String, Object>();
        callbackPayload.put("url", "http://www.example.com/cb");
        callbackPayload.put("method", "post");

        Callback callback = new Callback(callbackPayload);
        callback.save();

        callback.reload();
        mp.reload();

        assertEquals(mp.callbacks.total(), 1);
        assertEquals("http://www.example.com/cb", callback.url);
        assertEquals("post", callback.method);

        callback.delete();
        mp.reload();

        assertEquals(mp.callbacks.total(), 0);
    }

    @Test
    public void testCallbacksResourceFields() throws HTTPError {
        HashMap<String, Object> payload = new HashMap<String, Object>();
        payload.put("url", "http://www.example.com/callback");
        payload.put("method", "post");

        Callback callback = new Callback(payload);
        callback.save();

        assertNotNull(callback.href);
        assertNotNull(callback.id);
        assertNotNull(callback.links);
        assertNotNull(callback.method);
        assertNotNull(callback.revision);
        assertNotNull(callback.url);
    }
}

@@ -1490,39 +1490,36 @@
 %0A%0A        assert
-NotNull
+True
 (callback.href);
@@ -1520,41 +1520,28 @@
 href
-);%0A        assertNotNull(
+.contains(%22/
 callback
 .id)
@@ -1540,11 +1540,14 @@
 back
-.id
+s/CB%22)
 );%0A 
@@ -1551,39 +1551,36 @@
 ;%0A        assert
-NotNull
+True
 (callback.links)
@@ -1577,13 +1577,25 @@
 ack.
-links
+id.contains(%22CB%22)
 );%0A 
@@ -1599,39 +1599,38 @@
 ;%0A        assert
-NotNull
+Equals
 (callback.method
@@ -1629,16 +1629,24 @@
 k.method
+, %22post%22
 );%0A     
@@ -1646,39 +1646,38 @@
 ;%0A        assert
-NotNull
+Equals
 (callback.revisi
@@ -1678,16 +1678,34 @@
 revision
+.toString(), %221.1%22
 );%0A     
@@ -1713,23 +1713,22 @@
   assert
-NotNull
+Equals
 (callbac
@@ -1728,23 +1728,58 @@
 callback.url
+, %22http://www.example.com/callback%22
 );%0A    %7D%0A%7D%0A

Add specific assertions to callbacks