package com.github.terma.gigaspacesqlconsole.counts;

import com.github.terma.gigaspacesqlconsole.GigaSpaceUtils;
import junit.framework.Assert;
import org.junit.Test;
import org.openspaces.core.GigaSpace;

public class CountsTest {

    @Test
    public void shouldReturnEmptyResultIfNoTypesInSpace() {
        GigaSpaceUtils.getGigaSpace("/./ff");

        CountsRequest countsRequest = new CountsRequest();
        countsRequest.url = "/./ff?";
        final CountsResponse countsResponse = Counts.counts(countsRequest);

        // then only Object default
        Assert.assertEquals(1, countsResponse.counts.size());
    }

    @Test
    public void shouldReturnCountsOfTypes() {
        String url = "/./ff1?";
        final GigaSpace gigaSpace = GigaSpaceUtils.getGigaSpace(url);
        GigaSpaceUtils.registerType(gigaSpace, "com.a");

        GigaSpaceUtils.createDocument(gigaSpace, "com.a");
        GigaSpaceUtils.createDocument(gigaSpace, "com.a");
        GigaSpaceUtils.createDocument(gigaSpace, "com.a");

        CountsRequest countsRequest = new CountsRequest();
        countsRequest.url = url;
        final CountsResponse countsResponse = Counts.counts(countsRequest);

        // then
        Assert.assertEquals(2, countsResponse.counts.size());
        Assert.assertEquals("com.a", countsResponse.counts.get(1).name);
        Assert.assertEquals(3, countsResponse.counts.get(1).count);
    }

}

@@ -200,16 +200,65 @@
 Space;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 public c
@@ -1325,35 +1325,107 @@
     
-Assert.assertEquals(%22com.a%22
+Map%3CString, Integer%3E counts = new HashMap%3C%3E();%0A        counts.put(countsResponse.counts.get(0).name
 , co
@@ -1452,15 +1452,16 @@
 get(
-1).name
+0).count
 );%0A 
@@ -1471,65 +1471,240 @@
     
-Assert.assertEquals(3, countsResponse.counts.get(1).count
+counts.put(countsResponse.counts.get(1).name, countsResponse.counts.get(1).count);%0A        Assert.assertEquals(new HashMap%3CString, Integer%3E() %7B%7B%0A            put(%22com.a%22, 3);%0A            put(%22java.lang.Object%22, 0);%0A        %7D%7D, counts
 );%0A 

Fix unstable tests =)