package org.kie.services.remote.rest;

import static org.junit.Assert.*;

import java.util.regex.Pattern;

import javax.ws.rs.Path;

import org.junit.Test;

public class DeploymentIdRegexTest {

    @Test
    public void regextTest() {
        Path pathAnno = DeploymentResource.class.getAnnotation(Path.class);
        String path = pathAnno.value();
        path = path.replace("/deployment/{deploymentId: ", "");
        String regex = path.substring(0, path.length()-1);

        String test = "a:b:c";
        assertTrue(test, Pattern.matches(regex, test));
        test = "a:b:c:d";
        assertTrue(test, Pattern.matches(regex, test));
        
        test = "g:a:v:kbase:ksess:";
        assertFalse(test, Pattern.matches(regex, test));
        test = "g:a:v:kbase:ksess:a:";
        assertFalse(test, Pattern.matches(regex, test));
        test = "g:a:v:kbase:kse ss";
        assertFalse(test, Pattern.matches(regex, test));
        test = "g:a :v:kbase:kse ss";
        assertFalse(test, Pattern.matches(regex, test));
        
        test = "g:a:v:kbase";
        assertTrue(test, Pattern.matches(regex, test));
        test = "g:a:v:kbase:";
        assertTrue(test, Pattern.matches(regex, test));
        test = "g:a:v::ksess";
        assertTrue(test, Pattern.matches(regex, test));
        test = "g:a:v::";
        assertTrue(test, Pattern.matches(regex, test));

        String all = "g:a:v:kbase:ksess";
        assertTrue(test, Pattern.matches(regex, all));
        String[] groups = all.split(":");
        assertEquals(5, groups.length);
    }

}

@@ -219,13 +219,527 @@
 id r
+untimeRegexTest() %7B%0A        Path pathAnno = RuntimeResource.class.getAnnotation(Path.class);%0A        String path = pathAnno.value();%0A        path = path.replace(%22/runtime/%7BdeploymentId: %22, %22%22);%0A        String regex = path.substring(0, path.length()-1);%0A%0A        String test = %22group.subgroup:artifact-id:1.0%22;%0A        assertTrue(test, Pattern.matches(regex, test));%0A        test = %22group.sub_group:artifact_id:v1.0.0.Final%22;%0A        assertTrue(test, Pattern.matches(regex, test));%0A    %7D%0A%0A    @Test%0A    public void r
 egex
-t
 Test
@@ -2070,16 +2070,236 @@
 length);
+%0A%0A        test = %22group.subgroup:artifact-id:1.0%22;%0A        assertTrue(test, Pattern.matches(regex, test));%0A        test = %22group.sub_group:artifact_id:1.0.0.Final%22;%0A        assertTrue(test, Pattern.matches(regex, test));
 %0A    %7D%0A%0A

add some realistic tests for deployment ID regular expressions