package org.saiku.web.rest.servlet;

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

import java.util.List;

import org.junit.Test;
import org.saiku.service.olap.OlapDiscoverService;
import org.saiku.web.rest.objects.CubeRestPojo;
import org.springframework.beans.factory.annotation.Autowired;

import com.sun.jersey.api.client.WebResource;

import edu.emory.mathcs.backport.java.util.Collections;

//@RunWith(MockitoJUnitRunner.class)
public class DataSourceInterfaceTest extends AbstractServiceTest {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    @Autowired
    protected OlapDiscoverService olapDiscoverService = null;


//    @Mock
//    private TimberlineEmployeeService mockTimberlineEmployeeService;
//    
//    @InjectMocks
//    private EmployeeCreatedEventHandler handler = new EmployeeCreatedEventHandler();

   

	@Test
    public void testCheckDefaultConnection()
    {
	    DataSourceServlet dsi = new DataSourceServlet();
        dsi.setOlapDiscoverService(olapDiscoverService);
        List<CubeRestPojo> cubes = dsi.getCubes();
        assertEquals(cubes.size(),2);
        Collections.sort(cubes);
        CubeRestPojo cube = cubes.get(0);
        System.out.println(cube);
        assertEquals(cube.getCatalog(), "SampleData");
        assertEquals(cube.getConnectionName(), "TestConnection1");
        assertEquals(cube.getSchema(),"Quadrant Analysis");
        assertEquals(cube.getCubeName(), "SampleData");

        cube = cubes.get(1);
        System.out.println(cube);
        assertEquals(cube.getCatalog(), "SteelWheels");
        assertEquals(cube.getConnectionName(), "TestConnection1");
        assertEquals(cube.getCubeName(),"SteelWheels");
        assertEquals(cube.getSchema(), "SteelWheelsSales");

    }
    
    @Test
    public void testApplicationWadl() {
        WebResource webResouce = resource();
        String applicationWadl = webResouce.path("application.wadl").get(String.class);
        System.out.println(applicationWadl);
        assertTrue("Something wrong. Returned wadl length is not > 0",
                applicationWadl.length() > 0);
    }
    @Test
    public void testConvertDataSourcesToJson(){
     
        /*
            WebResource webResource = resource();
            String responseMsg = webResource.path("saiku").path("session").get(String.class);
            assertEquals("HELLO", responseMsg);*/
        
    }
    


    
	@Test
    public void testGetHtmlSucceeds()
    {
   /* ClientResponse response = callGet( path, MediaType.TEXT_HTML_TYPE );
    validateResponse( 200, MediaType.TEXT_HTML_TYPE, response );
    assertTrue( response.getEntity( String.class ).contains( "<td>Name</td><td>FE_Demo</td>" ) );*/
    }

    @Test
    public void testGetDefaultsToJson()
    {
   /* ClientResponse response = callGet( path, MediaType.WILDCARD_TYPE );
    validateResponse( 200, MediaType.APPLICATION_JSON_TYPE, response );*/
    }

    @Test
    public void testPutFails()
    {
    /*ClientResponse response = callPut( path, validJson, MediaType.APPLICATION_JSON_TYPE );
    assertEquals( 405, response.getStatus() );*/
    }



}

@@ -187,88 +187,83 @@
 iku.
-service.olap.OlapDiscoverService;%0Aimport org.saiku.web.rest.objects.CubeRestPojo
+olap.dto.SaikuConnection;%0Aimport org.saiku.service.olap.OlapDiscoverService
 ;%0Aim
@@ -375,65 +375,8 @@
 e;%0A%0A
-import edu.emory.mathcs.backport.java.util.Collections;%0A%0A
 //@R
@@ -998,24 +998,335 @@
 erService);%0A
+        List%3CSaikuConnection%3E connections = dsi.getConnections();%0A        assertEquals(connections.size(),1);%0A        SaikuConnection con = connections.get(0);%0A        System.out.println(con);%0A        assertEquals(con.getName(), %22TestConnection1%22);%0A        assertEquals(con.getCatalogs().size(), 2);%0A        %0A//
         List
@@ -1360,24 +1360,26 @@
 getCubes();%0A
+//
         asse
@@ -1400,24 +1400,26 @@
 .size(),2);%0A
+//
         Coll
@@ -1435,24 +1435,26 @@
 ort(cubes);%0A
+//
         Cube
@@ -1475,32 +1475,34 @@
 = cubes.get(0);%0A
+//
         System.o
@@ -1511,32 +1511,34 @@
 .println(cube);%0A
+//
         assertEq
@@ -1572,24 +1572,26 @@
 mpleData%22);%0A
+//
         asse
@@ -1637,32 +1637,34 @@
 tConnection1%22);%0A
+//
         assertEq
@@ -1703,24 +1703,26 @@
 Analysis%22);%0A
+//
         asse
@@ -1761,25 +1761,29 @@
 mpleData%22);%0A
-%0A
+//%0A//
         cube
@@ -1795,24 +1795,26 @@
 bes.get(1);%0A
+//
         Syst
@@ -1831,24 +1831,26 @@
 ntln(cube);%0A
+//
         asse
@@ -1885,32 +1885,34 @@
 %22SteelWheels%22);%0A
+//
         assertEq
@@ -1954,32 +1954,34 @@
 tConnection1%22);%0A
+//
         assertEq
@@ -2016,24 +2016,26 @@
 elWheels%22);%0A
+//
         asse

fix connection test