001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)TestArchiveUpload.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.management.repository;
030:
031: import com.sun.jbi.management.system.ScaffoldEnvironmentContext;
032: import com.sun.jbi.management.system.ManagementContext;
033:
034: import java.io.File;
035: import java.io.FileInputStream;
036:
037: public class TestArchiveUpload extends junit.framework.TestCase {
038: private static final String JBI_ROOT_PATH = "/bld";
039:
040: private static final String COMPONENT_ARCHIVE_PATH = "/testdata/component.zip";
041:
042: private static final String COMPONENT_ARCHIVE_NAME = "SunSequencingEngine";
043:
044: private ManagementContext mCtx;
045: private String mJbiRoot;
046: private ArchiveUpload mUploader;
047:
048: public TestArchiveUpload(String aTestName) throws Exception {
049: super (aTestName);
050:
051: String srcroot = System.getProperty("junit.srcroot");
052: String manage = "/runtime/manage"; // open-esb build
053: String blddir = "/bld/test-classes"; // open-esb build
054:
055: java.io.File f = new java.io.File(srcroot + manage);
056: if (!f.exists()) {
057: manage = "/shasta/manage"; // mainline/whitney build
058: blddir = "/bld/regress"; // mainline/whitney build
059: }
060:
061: mJbiRoot = srcroot + manage + JBI_ROOT_PATH;
062:
063: ScaffoldEnvironmentContext envCtx = new ScaffoldEnvironmentContext();
064: envCtx.setJbiInstanceRoot(mJbiRoot);
065: envCtx.setAppServerInstanceRoot(mJbiRoot);
066: mJbiRoot = srcroot + manage + blddir;
067: mCtx = new ManagementContext(envCtx);
068: mCtx.setRepository(new Repository(mCtx));
069:
070: mUploader = new ArchiveUpload(mCtx);
071: }
072:
073: public void setUp() throws Exception {
074: super .setUp();
075:
076: mCtx.getRepository().purge();
077: }
078:
079: public void tearDown() throws Exception {
080: }
081:
082: public void testUploadArchive() throws Exception {
083: Object upId;
084: FileInputStream fis;
085: byte[] buf;
086: int count;
087: File archive;
088:
089: buf = new byte[4096];
090: fis = new FileInputStream(mJbiRoot + COMPONENT_ARCHIVE_PATH);
091: upId = mUploader.initiateUpload("component.zip");
092:
093: while ((count = fis.read(buf)) != -1) {
094: if (buf.length != count) {
095: byte[] tmp = new byte[count];
096: System.arraycopy(buf, 0, tmp, 0, count);
097: buf = tmp;
098: }
099: mUploader.uploadBytes(upId, buf);
100: }
101:
102: assertNotNull(mUploader.getArchiveFilePath(upId));
103: mUploader.terminateUpload(upId, System.currentTimeMillis());
104:
105: archive = new File(mUploader.getArchiveFilePath(upId));
106: assertTrue(mUploader.removeArchive(upId));
107: }
108: }
|