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 } }