/*
 * Copyright 2002-2007 the original author or authors.
 * 
 * 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.
 */
package org.springframework.osgi.iandt.io;

import java.net.URL;
import java.util.Enumeration;

import org.springframework.util.ObjectUtils;

/**
 * Low level access API used for discovering the underlying platform
 * capabilities since there are subtle yet major differences between each
 * implementation.
 * 
 * @author Costin Leau
 * 
 */
public class RawIoTest extends BaseIoTest {

	/*
	 * (non-Javadoc)
	 * @see org.springframework.osgi.iandt.io.BaseIoTest#onSetUp()
	 */
	protected void onSetUp() throws Exception {
	}

	// don't use any extra bundles - just the test jar
	protected String[] getBundles() {
		return null;
	}

	public void testGetResourceOnMetaInf() throws Exception {
		URL url = bundle.getResource("/META-INF");
		System.out.println(url);
		assertNotNull(url);
	}

	// fails on Felix & KF
	public void testGetResourceOnRoot() throws Exception {
		URL url = bundle.getResource("/");
		System.out.println(url);
		assertNotNull(url);
	}

	// fails on Felix & KF
	public void testGetResourceSOnRoot() throws Exception {
		Enumeration enm = bundle.getResources("/");
		Object[] res = copyEnumeration(enm);
		assertEquals("root folder not validated" + ObjectUtils.nullSafeToString(res), 3, res.length);
	}

	// fails on KF
	public void testFindEntriesOnFolders() throws Exception {
		Enumeration enm = bundle.findEntries("/", null, false);
		// should get 3 entries - META-INF/, org/ and log4j.properties

		Object[] res = copyEnumeration(enm);
		assertEquals("folders ignored; found " + ObjectUtils.nullSafeToString(res), 3, res.length);
	}

	public void testFindEntriesOnSubFolders() throws Exception {
		Enumeration enm = bundle.findEntries("/META-INF", null, false);
		Object[] res = copyEnumeration(enm);
		// should get 1 entry - META-INF/
		assertEquals("folders ignored; found "+ ObjectUtils.nullSafeToString(res), 1, res.length);
	}

	// Valid jars do not have entries for root folder / - in fact it doesn't
	// even exist
	// fails on KF
	public void testGetEntryOnRoot() throws Exception {
		URL url = bundle.getEntry("/");
		assertNotNull(url);
	}

	// get folders
	public void testGetEntriesShouldReturnFoldersOnRoot() throws Exception {
		Enumeration enm = bundle.getEntryPaths("/");
		Object[] res = copyEnumeration(enm);
		assertEquals("folders ignored; found " + ObjectUtils.nullSafeToString(res), 3, res.length);
	}

	public void testGetFolderEntry() throws Exception {
		URL url = bundle.getEntry("META-INF/");
		assertNotNull(url);
	}

	public void testGetFolderEntries() throws Exception {
		Enumeration enm = bundle.getEntryPaths("META-INF/");
		Object[] res = copyEnumeration(enm);
		assertEquals("folders ignored; found " + ObjectUtils.nullSafeToString(res), 1, res.length);
	}

	/*
	 * (non-Javadoc)
	 * @see org.springframework.test.ConditionalTestCase#isDisabledInThisEnvironment(java.lang.String)
	 */
	protected boolean isDisabledInThisEnvironment(String testMethodName) {
		return (!(isEquinox() ));
		//|| isMBS()
	}

}

@@ -1041,155 +1041,8 @@
 %0D%0A%0D%0A
-%09/*%0D%0A%09 * (non-Javadoc)%0D%0A%09 * @see org.springframework.osgi.iandt.io.BaseIoTest#onSetUp()%0D%0A%09 */%0D%0A%09protected void onSetUp() throws Exception %7B%0D%0A%09%7D%0D%0A%0D%0A
 %09// 
@@ -1730,33 +1730,33 @@
 eToString(res), 
-3
+1
 , res.length);%0D%0A

fix NPE