Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.kie.remote.services.rest;
  
  import static org.kie.remote.services.rest.DeployResourceBase.*;
  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.assertFalse;
  import static org.junit.Assert.assertTrue;
  
  
 import  javax.ws.rs.Path;
 
 import  org.jbpm.kie.services.impl.KModuleDeploymentUnit;
 import  org.jbpm.services.api.model.DeploymentUnit;
 import  org.junit.Test;
 
 public class DeploymentIdTest extends DeploymentResourceImpl {
 
     @Test
     public void sameRegexUsedEverywhereTest() {
         Path pathAnno = RuntimeResourceImpl.class.getAnnotation(Path.class);
         String path = pathAnno.value();
         path = path.replace("/runtime/{deploymentId: """);
         String runRegex = path.substring(0, path.length()-1);
 
         pathAnno = DeploymentResourceImpl.class.getAnnotation(Path.class);
         path = pathAnno.value();
         path = path.replace("/deployment/{deploymentId: """);
         String depRegex = path.substring(0, path.length()-1);
         
         assertEquals("DeploymentResource deploymentId regex does not match RuntimeResource's"depRegexrunRegex);
     }
 
     @Test
     public void deploymentIdRegexTest() {
         Path pathAnno = DeploymentResourceImpl.class.getAnnotation(Path.class);
         String path = pathAnno.value();
         path = path.replace("/deployment/{deploymentId: """);
         String regex = path.substring(0, path.length()-1);
 
         // Test : groups
         String test = "a:b:c";
         assertTrue(test, Pattern.matches(regextest));
         test = "a:b:c:d";
         assertTrue(test, Pattern.matches(regextest));
         
         test = "g:a:v:kbase:ksess:";
         assertFalse(test, Pattern.matches(regextest));
         test = "g:a:v:kbase:ksess:a:";
         assertFalse(test, Pattern.matches(regextest));
         test = "g:a:v:kbase:kse ss";
         assertFalse(test, Pattern.matches(regextest));
         test = "g:a :v:kbase:kse ss";
         assertFalse(test, Pattern.matches(regextest));
         
         test = "g:a:v:kbase";
         assertTrue(test, Pattern.matches(regextest));
         test = "g:a:v:kbase:";
         assertTrue(test, Pattern.matches(regextest));
         test = "g:a:v::ksess";
         assertTrue(test, Pattern.matches(regextest));
         test = "g:a:v::";
         assertTrue(test, Pattern.matches(regextest));
 
         String all = "g:a:v:kbase:ksess";
         assertTrue(test, Pattern.matches(regexall));
         String[] groups = all.split(":");
         assertEquals(5, groups.length);
 
         // Test use of "-", "." and "_"
         test = "group.subgroup:artifact-id:1.0";
         assertTrue(test, Pattern.matches(regextest));
         test = "group.sub_group:artifact_id:1.0.0.Final";
         assertTrue(test, Pattern.matches(regextest));
         
         test = "group.subgroup:artifact-id:1.0";
         assertTrue(test, Pattern.matches(regextest));
         test = "group.sub_group:artifact_id:v1.0.0.Final";
         assertTrue(test, Pattern.matches(regextest));
        
         // Test other
         test = "::v:kbase";
         assertFalse(test, Pattern.matches(regextest));
         test = "::v";
         assertFalse(test, Pattern.matches(regextest));
         test = "$:#:v";
         assertFalse(test, Pattern.matches(regextest));
         
         // Test: process def id's url doesn't match
         test = "processes";
         assertFalse(test, Pattern.matches(regextest));
     }
 
     @Test
     public void parseDeploymentIdTest() { 
         // Test : groups
         {
         String [] test = { "a""b""c" };
         KModuleDeploymentUnit depUnit = createDeploymentUnit(join(test":"), null);
         checkDepUnit(depUnittest); 
        }
       
        {
        String [] test = { "g""a""v""kbase""ksess" };
        KModuleDeploymentUnit depUnit = createDeploymentUnit(join(test":"), null);
        checkDepUnit(depUnittest); 
        }
        
        { 
        String [] test = { "g""a""v""kbase" };
        KModuleDeploymentUnit depUnit = createDeploymentUnit(join(test":"), null);
        checkDepUnit(depUnittest); 
        }
        {
        String [] test = { "group.sub_group""artifact_id""1.0.0.Final" };
        KModuleDeploymentUnit depUnit = createDeploymentUnit(join(test":"), null);
        checkDepUnit(depUnittest); 
        }
    }
    
    private String join(String [] strArrString sep) { 
      StringBuilder builder = new StringBuilder();
      ifstrArr.length > 0 ) { 
         builder.append(strArr[0]);
         forint i = 1; i < strArr.length; ++i ) { 
            builder.appendsep + strArr[i]);
         }
      }
      return builder.toString();
    }
    
    private void checkDepUnit(DeploymentUnit depUnitString [] test) {
       String [] depUnitArr = depUnit.getIdentifier().split(":");
       assertEquals"size/# components"test.lengthdepUnitArr.length);
       forint i = 0; i < depUnitArr.length; ++i ) { 
           assertEquals(test[i], depUnitArr[i]);
       }
    }
New to GrepCode? Check out our FAQ X