package org.ow2.proactive_grid_cloud_portal.scheduler.client;

import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ow2.proactive_grid_cloud_portal.scheduler.client.CalendarInfoWindow.CalendarInfoContentBuilder;

import com.google.gwtmockito.GwtMockitoTestRunner;


@RunWith(GwtMockitoTestRunner.class)
public class CalendarInfoWindowTest {

    private CalendarInfoContentBuilder builder;

    private static final String ics = "private-121345679.ics/";

    private static final String notIcs = "<!DOCTYPE html><html lang=\"en\"><head>    <meta charset=\"utf-8\">";

    private String withPrivateUrlPattern = ".*ProActive Scheduling & Orchestration.*" + ics +
        ".*Regenerate.*Delete.*See calendar Documentation and Installation.*";

    private String withoutDefaultUrlPattern = "^(?!.*calendar.ics).*";

    private String withoutPrivateUrlPattern = ".*ProActive Scheduling & Orchestration.*Create.*See calendar Documentation and Installation.*";

    private String serviceNotAvailablePattern = ".*ProActive Scheduling & Orchestration.*Oops, Calendar Service is not available.*administrator.*";

    @Before
    public void setUp() throws Exception {
        CalendarInfoWindow window = new CalendarInfoWindow("7.18.0");
        builder = window.new CalendarInfoContentBuilder("7.18.0");
    }

    @Test
    public void testTextBuildWithPrivateUrl() {

        String content = builder.buildContentString(ics);

        System.out.println(content);

        assertTrue(content.matches(withPrivateUrlPattern));

        assertTrue(content.matches(withoutDefaultUrlPattern));
    }

    @Test
    public void testTextBuildWithoutPrivateUrl() {
        String icsName = "";

        String content = builder.buildContentString(icsName);

        System.out.println(content);

        assertTrue(content.matches(withoutPrivateUrlPattern));

        assertTrue(content.matches(withoutDefaultUrlPattern));
    }

    @Test
    public void testTextBuildWhenCalendarServiceNotAvailable() {

        String content = builder.buildContentString(notIcs);

        System.out.println(content);

        assertTrue(content.matches(serviceNotAvailablePattern));

        assertTrue(content.matches(withoutDefaultUrlPattern));
    }

}

@@ -1505,46 +1505,8 @@
 );%0A%0A
-        System.out.println(content);%0A%0A
     
@@ -1553,32 +1553,32 @@
 teUrlPattern));%0A
+
 %0A        assertT
@@ -1790,46 +1790,8 @@
 );%0A%0A
-        System.out.println(content);%0A%0A
     
@@ -1992,24 +1992,24 @@
 ilable() %7B%0A%0A
+
         Stri
@@ -2062,46 +2062,8 @@
 );%0A%0A
-        System.out.println(content);%0A%0A
     

remove systout