acre.require('/test/lib').enable(this);

var qa_app = "//metadata.qatests.apps.freebase.dev";

test('metadata file loading',function() {
    var md = acre.get_metadata(qa_app);

    ok(md.ttl === 1, "ttl wasn't set");

    ok(md.mounts.metadata, "mount missing");

    ok(md.handlers.custom, "custom handler missing");
    ok(md.extensions.cst, "cst extension missing");
    ok(md.extensions.html, "lost html extension");
    var file = md.files["not_custom.html"];
    ok(file.handler === 'custom', "handler wasn't set");
});

test('mount points',function() {
    var metadata_file = acre.require(qa_app + '/metadata/mount_file');
    ok(metadata_file.body == 'success', "couldn't find mount_file at metadata mount point");

    acre.mount(qa_app, "inline");
    var inline_file = acre.require('inline/mount_file');
    ok(inline_file.body == 'success', "couldn't find mount_file at inline mount point");
});

test('custom handler triggering',function() {
    var ext_file = acre.require('//metadata.qatests.apps.freebase.dev/custom');
    ok(ext_file.body == 'success', "extension-triggered handler didn't work");

    var md_file = acre.require('//metadata.qatests.apps.freebase.dev/not_custom');
    ok(md_file.body == 'success', "metadata-triggered handler didn't work");
});

test('require with metadata',function() {
    var md = {
        "extensions" : {
            "cst" : {
                "handler" : "passthrough"
            }
        },
        "files" : {
            "not_custom.html": {
                "handler": "passthrough"
            },
            "not_custom2.html": {
                "handler": "custom"
            }
        }
    };
    var file1 = acre.require('//metadata.qatests.apps.freebase.dev/custom.cst', md);
    ok(file1.body == 'fail', "metadata argument didn't override extension map");

    var file2 = acre.require('//metadata.qatests.apps.freebase.dev/not_custom2.html', md);
    ok(file2.body == 'success', "metadata argument didn't override default handler");

    var file3 = acre.require('//metadata.qatests.apps.freebase.dev/not_custom.html', md);
    ok(file3.body == 'fail', "metadata argument didn't override in-app metadata");

});

acre.test.report();
@@ -196,27 +196,24 @@
  1, %22ttl was
-n't
  set%22);%0A%0A   
@@ -243,23 +243,23 @@
  %22mount 
-missing
+present
 %22);%0A%0A   
@@ -298,23 +298,23 @@
 handler 
-missing
+present
 %22);%0A    
@@ -354,15 +354,15 @@
 ion 
-missing
+present
 %22);%0A
@@ -393,13 +393,8 @@
 l, %22
-lost 
 html
@@ -403,16 +403,24 @@
 xtension
+ present
 %22);%0A    
@@ -494,16 +494,23 @@
 stom', %22
+custom 
 handler 
@@ -512,19 +512,16 @@
 dler was
-n't
  set%22);%0A
@@ -666,35 +666,27 @@
 'success', %22
-c
+f
 ou
-ldn't fi
 nd mount_fil
@@ -849,19 +849,11 @@
 ', %22
-c
+f
 ou
-ldn't fi
 nd m
@@ -1058,47 +1058,38 @@
 ', %22
-extension-triggered handler didn't work
+handler triggered by extension
 %22);%0A
@@ -1211,17 +1211,16 @@
 ', %22
-metadata-
+handler 
 trig
@@ -1229,27 +1229,19 @@
 red 
-handler didn't work
+by metadata
 %22);%0A
@@ -1759,29 +1759,22 @@
 rgument 
-didn't 
 overr
-i
+o
 de exten
@@ -1928,29 +1928,22 @@
 rgument 
-didn't 
 overr
-i
+o
 de defau
@@ -2099,21 +2099,14 @@
 ent 
-didn't 
 overr
-i
+o
 de i

messages were backwards