/**
 * A CCNx library test.
 *
 * Copyright (C) 2008, 2009 Palo Alto Research Center, Inc.
 *
 * This work is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the
 * Free Software Foundation. 
 * This work is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details. You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

package org.ccnx.ccn.test.profiles.security.access.group;

import junit.framework.Assert;

import org.ccnx.ccn.CCNHandle;
import org.ccnx.ccn.impl.support.DataUtils;
import org.ccnx.ccn.io.CCNFileInputStream;
import org.ccnx.ccn.io.RepositoryFileOutputStream;
import org.ccnx.ccn.profiles.security.access.group.ACL;
import org.ccnx.ccn.protocol.ContentName;
import org.junit.BeforeClass;
import org.junit.Test;

public class GroupAccessControlTestRepo {
	static ContentName acName;
	static ContentName fileName;
	static byte content[] = "the network is built around me".getBytes();

	/**
	 * Create a new root of an access controlled namespace in the repo
	 * and write a file out there
	 */
	@BeforeClass
	public static void createAC() throws Exception {
		// mark the namespace as under access control
		ACL acl = new ACL();
		acName = ContentName.fromNative("/parc.com/ac_repo");
	//	NamespaceManager.Root.create(acName, acl, SaveType.REPOSITORY, CCNHandle.getHandle());

		// create a file in the namespace under access control
		fileName = ContentName.fromNative(acName, "/test.txt");
		CCNHandle h = CCNHandle.getHandle();
		RepositoryFileOutputStream os = new RepositoryFileOutputStream(fileName, h);
		os.write(content);
		os.close();
		h.close();
	}

	@Test
	public void read() throws Exception {
		CCNFileInputStream is = new CCNFileInputStream(fileName);
		byte received[] = new byte[content.length];
		Assert.assertEquals(is.read(received), content.length);
		Assert.assertTrue(DataUtils.arrayEquals(content, received));
	}
}

/**
 * A CCNx library test.
 *
 * Copyright (C) 2008, 2009 Palo Alto Research Center, Inc.
 *
 * This work is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the
 * Free Software Foundation. 
 * This work is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details. You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

package org.ccnx.ccn.test.profiles.security.access.group;

import junit.framework.Assert;

import org.ccnx.ccn.CCNHandle;
import org.ccnx.ccn.impl.support.DataUtils;
import org.ccnx.ccn.io.CCNFileInputStream;
import org.ccnx.ccn.io.RepositoryFileOutputStream;
import org.ccnx.ccn.profiles.security.access.group.ACL;
import org.ccnx.ccn.protocol.ContentName;
import org.junit.BeforeClass;
import org.junit.Test;

public class GroupAccessControlTestRepo {
	static ContentName acName;
	static ContentName fileName;
	static byte content[] = "the network is built around me".getBytes();

	/**
	 * Create a new root of an access controlled namespace in the repo
	 * and write a file out there
	 */
	@BeforeClass
	public static void createAC() throws Exception {
		// mark the namespace as under access control
    //  ACL acl = new ACL();
		acName = ContentName.fromNative("/parc.com/ac_repo");
	//	NamespaceManager.Root.create(acName, acl, SaveType.REPOSITORY, CCNHandle.getHandle());

		// create a file in the namespace under access control
		fileName = ContentName.fromNative(acName, "/test.txt");
		CCNHandle h = CCNHandle.getHandle();
		RepositoryFileOutputStream os = new RepositoryFileOutputStream(fileName, h);
		os.write(content);
		os.close();
		h.close();
	}

	@Test
	public void read() throws Exception {
		CCNFileInputStream is = new CCNFileInputStream(fileName);
		byte received[] = new byte[content.length];
		Assert.assertEquals(is.read(received), content.length);
		Assert.assertTrue(DataUtils.arrayEquals(content, received));
	}
}

Fix warning for declared but not used variable acl, resulting from the use being commented out in GroupAccessControlTestRepo.java