

package com.google.appengine.tck.datastore;

import static org.junit.Assert.assertTrue;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.Query;

import org.jboss.arquillian.junit.Arquillian;
import org.junit.runner.RunWith;

/**
 * datastore statistics test.
 * http://code.google.com/appengine/docs/java/datastore/stats.html
 *  
 * @author hchen@google.com (Hannah Chen)
 */
@RunWith(Arquillian.class)
public class StatsTest extends DatastoreTestBase {
  private static final String[] stats = {"Total__", "Kind__", "Kind_IsRootEntity__", 
    "Kind_NotRootEntity__", "PropertyType__", "PropertyType_Kind__", "PropertyName_Kind__",
    "PropertyType_PropertyName_Kind__"};

//  @Test
//  public void testStatics() {
//    if (!TestContextHelper.get().getReq().getServerName().endsWith("localhost")) {
//      // __Stat_Namespace__ is used to list all aggregated namespaces.
//      checkCount("__Stat_Namespace__");
//      for (int i = 0; i < stats.length; i++) {
//        // check stats that are empty namespace.
//        checkCount("__Stat_" + stats[i]);
//        // check stats that are namespace specific.
//        checkCount("__Stat_Ns_" + stats[i]);
//      }
//    }
//  }

  private void checkCount(String statsKind) {
    FetchOptions fo = FetchOptions.Builder.withDefaults();
    Query query = new Query(statsKind);
    assertTrue(datastoreService.prepare(query).countEntities(fo) > 0);
    for (Entity readRec : datastoreService.prepare(query).asIterable()) {
      assertTrue((Long) readRec.getProperty("count") > 0);
    }
  }
}

@@ -44,52 +44,8 @@
 e;%0A%0A
-import static org.junit.Assert.assertTrue;%0A%0A
 impo
@@ -90,16 +90,16 @@
 Entity;%0A
+
 import c
@@ -195,17 +195,16 @@
 .Query;%0A
-%0A
 import o
@@ -241,16 +241,39 @@
 illian;%0A
+import org.junit.Test;%0A
 import o
@@ -298,16 +298,60 @@
 nWith;%0A%0A
+import static org.junit.Assert.assertTrue;%0A%0A
 /**%0A * d
@@ -445,18 +445,16 @@
 .html%0A *
-  
 %0A * @aut
@@ -570,16 +570,18 @@
 tBase %7B%0A
+  
   privat
@@ -660,14 +660,21 @@
 __%22,
- 
 %0A
+     
     
+   
 %22Kin
@@ -753,24 +753,32 @@
 me_Kind__%22,%0A
+        
     %22Propert
@@ -807,16 +807,121 @@
 d__%22%7D;%0A%0A
+    @Test%0A    public void testDummy() %7B%0A        // TODO -- remove once some real test is in place%0A    %7D%0A%0A
 //  @Tes
@@ -1424,16 +1424,18 @@
 %0A//  %7D%0A%0A
+  
   privat
@@ -1468,24 +1468,28 @@
 tatsKind) %7B%0A
+    
     FetchOpt
@@ -1539,16 +1539,20 @@
 ();%0A    
+  
+  
 Query qu
@@ -1579,16 +1579,20 @@
 sKind);%0A
+    
     asse
@@ -1654,24 +1654,28 @@
 ) %3E 0);%0A    
+ 
+   
 for (Entity 
@@ -1728,24 +1728,30 @@
 erable()) %7B%0A
+      
       assert
@@ -1801,16 +1801,22 @@
 0);%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

Add dummy test.