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 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);

        assertTrue(content.matches(withPrivateUrlPattern));
    }

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

        String content = builder.buildContentString(icsName);

        assertTrue(content.matches(withoutPrivateUrlPattern));
    }

    @Test
    public void testTextBuildWhenCalendarServiceNotAvailable() {

        String content = builder.buildContentString(notIcs);

        assertTrue(content.matches(serviceNotAvailablePattern));
    }

}

@@ -811,32 +811,105 @@
 stallation.*%22;%0A%0A
+    private String withoutDefaultUrlPattern = %22.*(%5B%5Ecalendar.ics%5D).*$%22;%0A%0A
     private Stri
@@ -1498,24 +1498,62 @@
 ring(ics);%0A%0A
+        System.out.println(content);%0A%0A
         asse
@@ -1591,32 +1591,96 @@
 ateUrlPattern));
+%0A%0A        assertTrue(content.matches(withoutDefaultUrlPattern));
 %0A    %7D%0A%0A    @Tes
@@ -1821,24 +1821,62 @@
 (icsName);%0A%0A
+        System.out.println(content);%0A%0A
         asse
@@ -1917,32 +1917,96 @@
 ateUrlPattern));
+%0A%0A        assertTrue(content.matches(withoutDefaultUrlPattern));
 %0A    %7D%0A%0A    @Tes

add an another regex validation