provisionizer is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

/cmdline-testsrctestgroovycomlackeyproviscmdline
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.lackey.provis.cmdline;
/*
 *
 *     Copyright 2009. Build Lackey Labs. All Rights Reserved.
 *
 *
 *       Licensed under the Apache License, Version 2.0 (the "License");
 *       you may not use this file except in compliance with the
 *       License. You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *       Unless required by applicable law or agreed to in writing, software
 *       distributed under the License is distributed on an "AS IS" BASIS,
 *       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 *       See the License for the specific language governing permissions
 *       and limitations under the License.
 *
 * Author: cbedford
 * Date: Feb 11, 2009
 * Time: 9:30:12 PM
 */


import org.testng.annotations.*

import org.slf4j.*
import com.lackey.provis.util.ClassLoaderUtils
import com.lackey.provis.util.FileAndDirUtils
import com.lackey.provis.metadata.DepotInfo
import com.lackey.provis.util.Xmlify

public class TestCliAdminCreateSession {
  private static Logger logger = LoggerFactory.getLogger(TestCliAdminCreateSession.class.name)

  private final String defaultLocalDepotPath = "defaultLocalDepotPath"

  // TODO - figure out how to factor out the stuff below so there is one copy --
  // the original was copy/pasted from AbstractDepotTest
  //
  public final static File base = ClassLoaderUtils.getTestFixturesRootDir(
          TestCliAdminCreateSession .class)
  public final static String VALIDATE_CLONE_DIR = "validateCloneOfPrototypeToLocal"
  public final static File validateCloneDir = new File(base, VALIDATE_CLONE_DIR)
  public final static String PROTOTYPE_DEPOT = "prototypeDepotDir"

  @Test (enabled = true)
  public void testInvalidInputHandlingAndCreationOfDepotMetadata() {
    // Prepare testable reader and writer for use in constructing session
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter pwriter = new PrintWriter(baos)
    File newDepotDir = FileAndDirUtils.getDeleteOnExitTmpDir()
    StringReader reader = getStringReaderFromCannedInputs(newDepotDir)

    // Create and run session
    CliAdminCreateSession session = new CliAdminCreateSession(reader, pwriter)
    session.run()

    // Verify metadata was written correctly
    final File depotInfoFile = new File(newDepotDir, DepotInfo.DEPOT_INFO_FILE_NAME)
    DepotInfo info = Xmlify.deserializeFromFile(depotInfoFile)
    assert info.defaultLocalDepotPath.contains(defaultLocalDepotPath)
    assert info.prototypeDepotPath.contains(newDepotDir.canonicalPath)
    assert info.sizeInBytes > 0
    assert info.numFiles == 7

    // Verify output stream has expected content
    pwriter.close();
    String written = baos.toString()
    println "WRITTEN >> \n$written"
    assert written =~ /(?ms)is not a readable directory.*is not a valid JDK directory/
    assert written.contains("")
  }

  private StringReader getStringReaderFromCannedInputs(File newDepotDir) {
    File jdkDir =  new File(validateCloneDir,  PROTOTYPE_DEPOT + "/v1/unix/jdks/jdk1.5")
    assert  jdkDir.exists()

    String inputs = """
          /tmp/-non-existent-dir-as-opposed-to-next-dir-which-is-readable-but-not-jdk
          /
          $jdkDir.canonicalPath
          $newDepotDir.canonicalPath
          $defaultLocalDepotPath
"""

    StringReader reader = new StringReader(inputs)
    return reader
  }
}

Ajax-loader Loading, please wait...