/**
 * Copyright 2008-2009 DRIVER PROJECT (Bielefeld University)
 * Original author: Marek Imialek <marek.imialek at uni-bielefeld.de>
 *
 * 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 eu.dnetlib.data.sts.das.lls;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileWriter;
import java.util.Iterator;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;

import eu.dnetlib.data.sts.constants.DepotServiceConstants;
import eu.dnetlib.data.sts.ds.lls.sdo.SimpleDigitalObject;
import eu.dnetlib.data.sts.ds.lls.sdo.SimpleDigitalObject.ObjectContentType;
import eu.dnetlib.data.sts.lls.LLSAccessFacade;
import eu.dnetlib.data.sts.lls.LLSStoreFacade;
import eu.dnetlib.data.sts.utils.SpringUtils;

/**
 * The Class LLSStoreFacadeTest.
 * 
 * @author <a href="mailto:marek.imialek at uni-bielefeld.de">Marek Imialek</a>
 */
public class LLSAccessFacadeTest {
	
	/** The ctx. */
	ApplicationContext ctx;

	/** The lls store facade. */
	private LLSStoreFacade llsStoreFacade;
	
	
	private LLSAccessFacade llsAccessFacade;
	
	/**
	 * Sets the up.
	 * 
	 */
	@Before 
	public void setUp() {
		this.ctx = SpringUtils
				.getSpringContext(SpringUtils.DEFAULT_JUNIT_RESOURCE_DAS);
	
		this.llsStoreFacade = (LLSStoreFacade) this.ctx
			.getBean("ossStorage");
		this.llsAccessFacade = (LLSAccessFacade) this.ctx
			.getBean("ossAccess");
		
	}
	
	/**
	 * Test searching objects uri.
	 * 
	 * @throws Exception the exception
	 */
	@Test
	public void testSearchObjectsUris  () throws Exception {
		
		String dummyObjectPath = "/tmp/dummyObject";
		String dummyObjectPath2 = "/tmp/dummyObject2";
		File file = new File(dummyObjectPath);
		File file2 = new File(dummyObjectPath2);
		String storeDataStructId = "testSearchObjectsUris";
		String newStoreDataStructId = null;
		
		try {
			if (!file.exists())
				assertTrue("Can not create file " +
						"required for testing: "  +
						dummyObjectPath,file.createNewFile());
			
		    BufferedWriter out = new BufferedWriter(
		    		new FileWriter(dummyObjectPath));
		    out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<GGGGGGGGG><juhb> hvgvgc gfgc  gg g </juhb></GGGGGGGGG>");
		    out.close();
		    
		    if (!file2.exists())
				assertTrue("Can not create file " +
						"required for testing: "  +
						dummyObjectPath,file2.createNewFile());
			
		    BufferedWriter out2 = new BufferedWriter(
		    		new FileWriter(dummyObjectPath2));
		    out2.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<ROOT><mytag> I am the second object </mytag></ROOT>");
		    out2.close();
			
			newStoreDataStructId = 
				llsStoreFacade.createStoreDataStructure(storeDataStructId);
			assertNotNull(newStoreDataStructId);
			System.out.println("The Store Data Structure identifier:" 
					+ newStoreDataStructId);
			
			/*Store first object */
			SimpleDigitalObject sdo = new SimpleDigitalObject();
			sdo.setDataStructureType(DepotServiceConstants.
					STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS);
			
			sdo.setObjectContentType(ObjectContentType.PATH);
			sdo.setObjectLocation(dummyObjectPath);
			sdo.setObjectMimeType("application/xml");
			sdo.setObjectName(file.getName());
			sdo.setObjectExtension("xml");
			String objectId = 
				llsStoreFacade.storeObject(storeDataStructId, sdo);
			assertNotNull(objectId);
			
			/*Store second object */
			sdo.setObjectContentType(ObjectContentType.PATH);
			sdo.setObjectLocation(dummyObjectPath2);
			sdo.setObjectName(file2.getName());
			String objectId2 = 
				llsStoreFacade.storeObject(storeDataStructId, sdo);
			assertNotNull(objectId2);
		
			LLSLookUpResponse searchingResponse = llsAccessFacade.searchObjects(
					newStoreDataStructId, 
					DepotServiceConstants.STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS,1,
					50,true);
			
			if (searchingResponse != null) { 
			
				Iterator<String> objects = 
					searchingResponse.getResponseResults().iterator();
			
				if (objects != null)
					while (objects.hasNext())
						System.out.println("OBJECT URI: " + objects.next());
				else
					throw new Exception("Null result returned from storage");
			}
			
		} catch(Exception e) {
			throw new Exception("Nested Exception: " +e);
		} finally {
			//file.delete();
			//llsStoreFacade.removeStoreDataStructure(storeDataStructId);
		}		
	}
	
	/**
	 * Test searching objects.
	 * 
	 * @throws Exception the exception
	 */
	@Test
	public void testSearchObjects() throws Exception {
		

		String dummyObjectPath = "/tmp/dummyObject";
		String dummyObjectPath2 = "/tmp/dummyObject2";
		File file = new File(dummyObjectPath);
		File file2 = new File(dummyObjectPath2);
		String storeDataStructId = "testSearchObjects";
		String newStoreDataStructId = null;
		
		try {
			if (!file.exists())
				assertTrue("Can not create file " +
						"required for testing: "  +
						dummyObjectPath,file.createNewFile());
			
		    BufferedWriter out = new BufferedWriter(
		    		new FileWriter(dummyObjectPath));
		    out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<GGGGGGGGG><juhb> hvgvgc gfgc  gg g </juhb></GGGGGGGGG>");
		    out.close();
		    
		    if (!file2.exists())
				assertTrue("Can not create file " +
						"required for testing: "  +
						dummyObjectPath,file2.createNewFile());
			
		    BufferedWriter out2 = new BufferedWriter(
		    		new FileWriter(dummyObjectPath2));
		    out2.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<ROOT><mytag> I am the second object </mytag></ROOT>");
		    out2.close();
			
			newStoreDataStructId = 
				llsStoreFacade.createStoreDataStructure(storeDataStructId);
			assertNotNull(newStoreDataStructId);
			System.out.println("The Store Data Structure identifier:" 
					+ newStoreDataStructId);
			
			/*Store first object */
			SimpleDigitalObject sdo = new SimpleDigitalObject();
			sdo.setDataStructureType(DepotServiceConstants.
					STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS);	
			sdo.setObjectContentType(ObjectContentType.PATH);
			sdo.setObjectLocation(dummyObjectPath);
			sdo.setObjectMimeType("application/xml");
			sdo.setObjectName(file.getName());
			sdo.setObjectExtension("xml");
			String objectId = 
				llsStoreFacade.storeObject(storeDataStructId, sdo);
			assertNotNull(objectId);
			
			/*Store second object */
			sdo.setObjectContentType(ObjectContentType.PATH);
			sdo.setObjectLocation(dummyObjectPath2);
			sdo.setObjectName(file2.getName());
			String objectId2 = 
				llsStoreFacade.storeObject(storeDataStructId, sdo);
			assertNotNull(objectId2);
			
			LLSLookUpResponse searchingResponse = llsAccessFacade.searchObjects(
					newStoreDataStructId, 
					DepotServiceConstants.STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS,
					1, 50, false);
			
			if (searchingResponse != null) { 
				Iterator<String> objects = 
					searchingResponse.getResponseResults().iterator();
			
				if (objects != null)
					while (objects.hasNext())
						System.out.println("OBJECT: " + objects.next());
				else
					throw new Exception("Null result returned from storage");
			}	
			
		} catch(Exception e) {
			throw new Exception("Nested Exception: " +e);
		} finally {
			//file.delete();
			//llsStoreFacade.removeStoreDataStructure(storeDataStructId);
		}		
	}
	
	/**
	 * Test searching SDO objects.
	 * 
	 * @throws Exception the exception
	 */
	@Test
	public void testSearchSDOObjects() throws Exception {
		

		String dummyObjectPath = "/tmp/dummyObject";
		String dummyObjectPath2 = "/tmp/dummyObject2";
		File file = new File(dummyObjectPath);
		File file2 = new File(dummyObjectPath2);
		String storeDataStructId = "testSearchSDOObjects";
		String newStoreDataStructId = null;
		
		try {
			if (!file.exists())
				assertTrue("Can not create file " +
						"required for testing: "  +
						dummyObjectPath,file.createNewFile());
			
		    BufferedWriter out = new BufferedWriter(
		    		new FileWriter(dummyObjectPath));
		    out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<GGGGGGGGG><juhb> hvgvgc gfgc  gg g </juhb></GGGGGGGGG>");
		    out.close();
		    
		    if (!file2.exists())
				assertTrue("Can not create file " +
						"required for testing: "  +
						dummyObjectPath,file2.createNewFile());
			
		    BufferedWriter out2 = new BufferedWriter(
		    		new FileWriter(dummyObjectPath2));
		    out2.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<ROOT><mytag> I am the second object </mytag></ROOT>");
		    out2.close();
			
			newStoreDataStructId = 
				llsStoreFacade.createStoreDataStructure(storeDataStructId);
			assertNotNull(newStoreDataStructId);
			System.out.println("The Store Data Structure identifier:" 
					+ newStoreDataStructId);
			
			/*Store first object */
			SimpleDigitalObject sdo = new SimpleDigitalObject();
			sdo.setDataStructureType(DepotServiceConstants.
					STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS);	
			sdo.setObjectContentType(ObjectContentType.PATH);
			sdo.setObjectLocation(dummyObjectPath);
			sdo.setObjectMimeType("application/xml");
			sdo.setObjectName(file.getName());
			sdo.setObjectExtension("xml");
			String objectId = 
				llsStoreFacade.storeObject(storeDataStructId, sdo);
			assertNotNull(objectId);
			
			/*Store second object */
			sdo.setObjectContentType(ObjectContentType.PATH);
			sdo.setObjectLocation(dummyObjectPath2);
			sdo.setObjectName(file2.getName());
			String objectId2 = 
				llsStoreFacade.storeObject(storeDataStructId, sdo);
			assertNotNull(objectId2);
			
			LLSLookUpResponse searchingResponse = llsAccessFacade.searchObjects(
					newStoreDataStructId, 
					DepotServiceConstants.STORE_DATA_STRUCTURE_SUBTYPE_SDOS,
					1, 50, false);
			
			if (searchingResponse != null) { 
				Iterator<String> objects = 
					searchingResponse.getResponseResults().iterator();
			
				if (objects != null)
					while (objects.hasNext())
						System.out.println("OBJECT URI: " + objects.next());
				else
					throw new Exception("Null result returned from storage");
			}
			
		} catch(Exception e) {
			throw new Exception("Nested Exception: " +e);
		} finally {
			//file.delete();
			//llsStoreFacade.removeStoreDataStructure(storeDataStructId);
		}		
	}
	
	
	@Test
	public void testSearchObjectsUrisByTags  () throws Exception {
		
		String dummyObjectPath = "/tmp/dummyObject";
		String dummyObjectPath2 = "/tmp/dummyObject2";
		File file = new File(dummyObjectPath);
		File file2 = new File(dummyObjectPath2);
		String storeDataStructId = "testSearchObjectsUris";
		String newStoreDataStructId = null;
		
		try {
			if (!file.exists())
				assertTrue("Can not create file " +
						"required for testing: "  +
						dummyObjectPath,file.createNewFile());
			
		    BufferedWriter out = new BufferedWriter(
		    		new FileWriter(dummyObjectPath));
		    out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<GGGGGGGGG><juhb> hvgvgc gfgc  gg g </juhb></GGGGGGGGG>");
		    out.close();
		    
		    if (!file2.exists())
				assertTrue("Can not create file " +
						"required for testing: "  +
						dummyObjectPath,file2.createNewFile());
			
		    BufferedWriter out2 = new BufferedWriter(
		    		new FileWriter(dummyObjectPath2));
		    out2.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<ROOT><mytag> I am the second object </mytag></ROOT>");
		    out2.close();
			
			newStoreDataStructId = 
				llsStoreFacade.createStoreDataStructure(storeDataStructId);
			assertNotNull(newStoreDataStructId);
			System.out.println("The Store Data Structure identifier:" 
					+ newStoreDataStructId);
			System.out.println("1");
			/*Store first object */
			SimpleDigitalObject sdo = new SimpleDigitalObject();
			sdo.setDataStructureType(DepotServiceConstants.
					STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS);	
			sdo.setObjectContentType(ObjectContentType.PATH);
			sdo.setObjectLocation(dummyObjectPath);
			sdo.setObjectMimeType("application/xml");
			sdo.setObjectName(file.getName());
			sdo.setObjectExtension("xml");
			String objectId = 
				llsStoreFacade.storeObject(storeDataStructId, sdo);
			assertNotNull(objectId);
			System.out.println("2");
			/*Store second object */
			sdo.setObjectContentType(ObjectContentType.PATH);
			sdo.setObjectLocation(dummyObjectPath2);
			sdo.setObjectName(file2.getName());
			String objectId2 = 
				llsStoreFacade.storeObject(storeDataStructId, sdo);
			assertNotNull(objectId2);
			System.out.println("3");
			String [] tagsForSearching = {newStoreDataStructId+"-"+
					DepotServiceConstants.
					STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS};
			System.out.println("4");
			
			Thread.sleep(1000);
			LLSLookUpResponse searchingResponse = llsAccessFacade.searchObjectsByTags(
					tagsForSearching, 1, 50, true);
			System.out.println("5");
			Iterator<String> objects = 
				searchingResponse.getResponseResults().iterator();
			
			if (objects != null)
				while (objects.hasNext())
					System.out.println("OBJECT URI: " + objects.next());
			else
				throw new Exception("Null result returned from storage");

			
		} catch(Exception e) {
			throw new Exception("Nested Exception: " +e);
		} finally {
			//file.delete();
			//llsStoreFacade.removeStoreDataStructure(storeDataStructId);
		}		
	}
	
	/**
	 * Test searching objects.
	 * 
	 * @throws Exception the exception
	 */
	@Test
	public void testSearchObjectsByTags() throws Exception {
		

		String dummyObjectPath = "/tmp/dummyObject";
		String dummyObjectPath2 = "/tmp/dummyObject2";
		File file = new File(dummyObjectPath);
		File file2 = new File(dummyObjectPath2);
		String storeDataStructId = "testSearchObjects";
		String newStoreDataStructId = null;
		
		try {
			if (!file.exists())
				assertTrue("Can not create file " +
						"required for testing: "  +
						dummyObjectPath,file.createNewFile());
			
		    BufferedWriter out = new BufferedWriter(
		    		new FileWriter(dummyObjectPath));
		    out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<GGGGGGGGG><juhb> hvgvgc gfgc  gg g </juhb></GGGGGGGGG>");
		    out.close();
		    
		    if (!file2.exists())
				assertTrue("Can not create file " +
						"required for testing: "  +
						dummyObjectPath,file2.createNewFile());
			
		    BufferedWriter out2 = new BufferedWriter(
		    		new FileWriter(dummyObjectPath2));
		    out2.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<ROOT><mytag> I am the second object </mytag></ROOT>");
		    out2.close();
			
			newStoreDataStructId = 
				llsStoreFacade.createStoreDataStructure(storeDataStructId);
			assertNotNull(newStoreDataStructId);
			System.out.println("The Store Data Structure identifier:" 
					+ newStoreDataStructId);
			
			/*Store first object */
			SimpleDigitalObject sdo = new SimpleDigitalObject();
			sdo.setDataStructureType(DepotServiceConstants.
					STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS);	
			sdo.setObjectContentType(ObjectContentType.PATH);
			sdo.setObjectLocation(dummyObjectPath);
			sdo.setObjectMimeType("application/xml");
			sdo.setObjectName(file.getName());
			sdo.setObjectExtension("xml");
			String objectId = 
				llsStoreFacade.storeObject(storeDataStructId, sdo);
			assertNotNull(objectId);
			
			/*Store second object */
			sdo.setObjectContentType(ObjectContentType.PATH);
			sdo.setObjectLocation(dummyObjectPath2);
			sdo.setObjectName(file2.getName());
			String objectId2 = 
				llsStoreFacade.storeObject(storeDataStructId, sdo);
			assertNotNull(objectId2);
			
			String [] tagsForSearching = {newStoreDataStructId+"-"+
					DepotServiceConstants.
					STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS};
			
			
			LLSLookUpResponse searchingResponse = llsAccessFacade.searchObjectsByTags(
					tagsForSearching, 1, 50, false);
			
			Iterator<String> objects = 
				searchingResponse.getResponseResults().iterator();
			
			if (objects != null)
				while (objects.hasNext())
					System.out.println("OBJECT: " + objects.next());
			else
				throw new Exception("Null result returned from storage");

			
		} catch(Exception e) {
			throw new Exception("Nested Exception: " +e);
		} finally {
			//file.delete();
			//llsStoreFacade.removeStoreDataStructure(storeDataStructId);
		}		
	}
	
	/**
	 * Test searching SDO objects.
	 * 
	 * @throws Exception the exception
	 */
	@Test
	public void testSearchSDOObjectsByTags() throws Exception {
		

		String dummyObjectPath = "/tmp/dummyObject";
		String dummyObjectPath2 = "/tmp/dummyObject2";
		File file = new File(dummyObjectPath);
		File file2 = new File(dummyObjectPath2);
		String storeDataStructId = "testSearchSDOObjects";
		String newStoreDataStructId = null;
		
		try {
			if (!file.exists())
				assertTrue("Can not create file " +
						"required for testing: "  +
						dummyObjectPath,file.createNewFile());
			
		    BufferedWriter out = new BufferedWriter(
		    		new FileWriter(dummyObjectPath));
		    out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<GGGGGGGGG><juhb> hvgvgc gfgc  gg g </juhb></GGGGGGGGG>");
		    out.close();
		    
		    if (!file2.exists())
				assertTrue("Can not create file " +
						"required for testing: "  +
						dummyObjectPath,file2.createNewFile());
			
		    BufferedWriter out2 = new BufferedWriter(
		    		new FileWriter(dummyObjectPath2));
		    out2.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
				"<ROOT><mytag> I am the second object </mytag></ROOT>");
		    out2.close();
			
			newStoreDataStructId = 
				llsStoreFacade.createStoreDataStructure(storeDataStructId);
			assertNotNull(newStoreDataStructId);
			System.out.println("The Store Data Structure identifier:" 
					+ newStoreDataStructId);
			
			/*Store first object */
			SimpleDigitalObject sdo = new SimpleDigitalObject();
			sdo.setDataStructureType(DepotServiceConstants.
					STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS);	
			sdo.setObjectContentType(ObjectContentType.PATH);
			sdo.setObjectLocation(dummyObjectPath);
			sdo.setObjectMimeType("application/xml");
			sdo.setObjectName(file.getName());
			sdo.setObjectExtension("xml");
			String objectId = 
				llsStoreFacade.storeObject(storeDataStructId, sdo);
			assertNotNull(objectId);
			
			/*Store second object */
			sdo.setObjectContentType(ObjectContentType.PATH);
			sdo.setObjectLocation(dummyObjectPath2);
			sdo.setObjectName(file2.getName());
			String objectId2 = 
				llsStoreFacade.storeObject(storeDataStructId, sdo);
			assertNotNull(objectId2);
			
			String [] tagsForSearching = {newStoreDataStructId+"-"+
					DepotServiceConstants.
					STORE_DATA_STRUCTURE_SUBTYPE_SDOS};
			LLSLookUpResponse searchingResponse = llsAccessFacade.searchObjectsByTags(
					tagsForSearching, 1, 50, false);
			
			Iterator<String> objects = 
				searchingResponse.getResponseResults().iterator();
			
			if (objects != null)
				while (objects.hasNext())
					System.out.println("OBJECT URI: " + objects.next());
			else
				throw new Exception("Null result returned from storage");

			
		} catch(Exception e) {
			throw new Exception("Nested Exception: " +e);
		} finally {
			//file.delete();
			//llsStoreFacade.removeStoreDataStructure(storeDataStructId);
		}		
	}
	
	@Test
	public void testGetObjectUrl() throws Exception{
		
		String storeDataStructId = "getSingleObjectTestStructure";
		String objectName = "dummyObject77";
		
		storeDataStructId = 
			llsStoreFacade.createStoreDataStructure(storeDataStructId);
		assertNotNull("Store Data Structure not created",storeDataStructId);
		
		SimpleDigitalObject sdo = new SimpleDigitalObject();
		sdo.setDataStructureType(DepotServiceConstants.
				STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS);
		sdo.setObjectContentType(ObjectContentType.DATA);
		sdo.setObjectContent(new ByteArrayInputStream(
				"I am a content of dummyObject!".getBytes()));
		sdo.setObjectName(objectName);
		sdo.setObjectId(objectName);
		sdo.setObjectExtension("xml");
		sdo.setObjectTags(new String[] {"xml",DepotServiceConstants.
				STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS});
		
		String objectId = 
			llsStoreFacade.storeObject(storeDataStructId, sdo);
		assertNotNull(objectId);
		
		String objectURL = 
			llsAccessFacade.getObjectUrl(storeDataStructId, objectName);
		assertNotNull(objectURL);
		System.out.println("object URL:" + objectURL);
	}
	
	@Test
	public void testGetObjectSDO() throws Exception{
		
		String storeDataStructId = "getSingleObjectTestStructure111";
		String objectName = "dummyObject771";
		
		storeDataStructId = 
			llsStoreFacade.createStoreDataStructure(storeDataStructId);
		assertNotNull("Store Data Structure not created",storeDataStructId);
		
		SimpleDigitalObject sdo = new SimpleDigitalObject();
		sdo.setDataStructureType(DepotServiceConstants.
				STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS);
		
		sdo.setObjectContentType(ObjectContentType.DATA);
		sdo.setObjectContent(new ByteArrayInputStream(
				"I am a content of dummyObject!".getBytes()));
		sdo.setObjectName(objectName);
		sdo.setObjectId(objectName);
		sdo.setObjectExtension("xml");
		sdo.setObjectTags(new String[] {"xml",DepotServiceConstants.
				STORE_DATA_STRUCTURE_SUBTYPE_OBJECTS});
		
		String objectId = 
			llsStoreFacade.storeObject(storeDataStructId, sdo);
		assertNotNull(objectId);
		
		String objectURL = 
			llsAccessFacade.getObjectSDO(storeDataStructId, objectName);
		assertNotNull(objectURL);
		System.out.println("object SDO:" + objectURL);	
	}
	
	/**
	 * Deletes all files and subdirectories under specified directory.
	 * 
	 * @param directoryToBeRemoved the directory to be removed
	 * 
	 * @return boolean
	 */
	public boolean deleteDirectory(File directoryToBeRemoved) {

		if (directoryToBeRemoved.isDirectory()) {

			String[] children = directoryToBeRemoved.list();

			for (int i = 0; i < children.length; i++) {
				boolean success = deleteDirectory
					(new File(directoryToBeRemoved, children[i]));
				if (!success)
					return false;
			}
		}

		return directoryToBeRemoved.delete();
	}
	

}
