/**
  * Checks the list of event listeners for a single {@link
  * com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.EventListener} that points to a
  * {@link GerritTrigger} and checks if that is configured for the project pattern.
  *
  * @param gerritProjectPattern the pattern to check
  * @throws Exception if so
  */
 private void assertEventListenerWithSomeOtherProjectSet(String gerritProjectPattern)
     throws Exception {
   Collection<GerritEventListener> eventListeners = getGerritEventListeners();
   boolean found = false;
   for (GerritEventListener listener : eventListeners) {
     if (listener
         .getClass()
         .getName()
         .equals("com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.EventListener")) {
       found = true;
       GerritTrigger trigger = Whitebox.invokeMethod(listener, "getTrigger");
       assertNotNull("No Trigger for EventListener", trigger);
       assertSame(Whitebox.getInternalState(trigger, "job"), j.jenkins.getItem("testProj"));
       List<GerritProject> projectList = trigger.getGerritProjects();
       assertEquals(2, projectList.size());
       boolean foundSomeOtherProject = false;
       for (GerritProject project : projectList) {
         if (gerritProjectPattern.equals(project.getPattern())) {
           foundSomeOtherProject = true;
         }
       }
       assertTrue("Could not find " + gerritProjectPattern, foundSomeOtherProject);
     }
   }
   assertTrue("No EventListener", found);
 }
예제 #2
0
 /**
  * Tests the {@link SwiftUnderFileSystem#stripPrefixIfPresent(String)} method.
  *
  * @throws Exception when the Whitebox fails
  */
 @Test
 public void stripPrefixIfPresentTest() throws Exception {
   String[] inputs =
       new String[] {
         "swift://" + mMockContainerName,
         mMockContainerPrefix,
         mMockContainerPrefix + "file",
         mMockContainerPrefix + "dir/file",
         "swift://test-container-wrong/dir/file",
         "dir/file",
         "/dir/file",
       };
   String[] results =
       new String[] {
         "swift://" + mMockContainerName,
         "",
         "file",
         "dir/file",
         "swift://test-container-wrong/dir/file",
         "dir/file",
         "/dir/file",
       };
   for (int i = 0; i < inputs.length; i++) {
     Assert.assertEquals(
         results[i],
         Whitebox.invokeMethod(mMockSwiftUnderFileSystem, "stripPrefixIfPresent", inputs[i]));
   }
 }
예제 #3
0
  /**
   * Tests the {@link SwiftUnderFileSystem#makeQualifiedPath(String)} method.
   *
   * @throws Exception when the Whitebox fails
   */
  @Test
  public void makeQualifiedPathTest() throws Exception {
    String input1 = "a/b";
    String input2 = "/a/b";
    String input3 = "a/b/";
    String input4 = "/a/b/";
    String result1 = Whitebox.invokeMethod(mMockSwiftUnderFileSystem, "makeQualifiedPath", input1);
    String result2 = Whitebox.invokeMethod(mMockSwiftUnderFileSystem, "makeQualifiedPath", input2);
    String result3 = Whitebox.invokeMethod(mMockSwiftUnderFileSystem, "makeQualifiedPath", input3);
    String result4 = Whitebox.invokeMethod(mMockSwiftUnderFileSystem, "makeQualifiedPath", input4);

    Assert.assertEquals(result1, "a/b/");
    Assert.assertEquals(result2, "a/b/");
    Assert.assertEquals(result3, "a/b/");
    Assert.assertEquals(result4, "a/b/");
  }
예제 #4
0
  /**
   * Tests the {@link SwiftUnderFileSystem#stripFolderSuffixIfPresent(String)} method.
   *
   * @throws Exception when the Whitebox fails
   */
  @Test
  public void stripFolderSuffixIfPresentTest() throws Exception {
    String input1 = mMockContainerPrefix;
    String input2 = mMockContainerPrefix + "dir/file";
    String input3 = mMockContainerPrefix + "dir_$folder$";
    String result1 =
        Whitebox.invokeMethod(mMockSwiftUnderFileSystem, "stripFolderSuffixIfPresent", input1);
    String result2 =
        Whitebox.invokeMethod(mMockSwiftUnderFileSystem, "stripFolderSuffixIfPresent", input2);
    String result3 =
        Whitebox.invokeMethod(mMockSwiftUnderFileSystem, "stripFolderSuffixIfPresent", input3);

    Assert.assertEquals(mMockContainerPrefix, result1);
    Assert.assertEquals(mMockContainerPrefix + "dir/file", result2);
    Assert.assertEquals(mMockContainerPrefix + "dir", result3);
  }
  /**
   * userProfile != null tnContext != null
   *
   * @throws Exception
   */
  public void testAddBusinessSpecificData() throws Exception {
    MISReportor misr = new MISReportor();

    Map<Long, String> map = new HashMap<Long, String>();
    map.put(new Long(0), "0");
    map.put(new Long(1), "1");

    StringBuilder recordString = new StringBuilder("string");

    String delimiter = Character.toString((char) 1);

    Whitebox.invokeMethod(misr, "addBusinessSpecificData", map, recordString);

    assertEquals("string0=0" + delimiter + "1=1" + delimiter, recordString.toString());
  }