package org.devilry.clientapi;

import javax.naming.*;

import org.devilry.core.InvalidNameException;
import org.devilry.core.NoSuchObjectException;
import org.devilry.core.NoSuchUserException;
import org.devilry.core.NodePath;
import org.devilry.core.PathExistsException;
import org.devilry.core.UnauthorizedException;
import org.devilry.core.daointerfaces.AssignmentNodeCommon;
import org.devilry.core.daointerfaces.CourseNodeCommon;
import org.devilry.core.daointerfaces.DeliveryCommon;
import org.devilry.core.daointerfaces.NodeCommon;
import org.devilry.core.daointerfaces.PeriodNodeCommon;
import org.devilry.core.daointerfaces.UserCommon;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

public abstract class StudentAssignmentCommonTest extends UserAssignmentCommonTest {
	
	Student homer;
	Student bart, lisa;
	
	StudentPeriod period;
	StudentPeriod period2;
	
	StudentAssignment assignment;
				
	@Before
	public void setUp() throws NamingException, PathExistsException, UnauthorizedException, InvalidNameException, NoSuchObjectException {
		
		super.setUp();
				
		period = new StudentPeriod(inf1000Spring09, connection);
		period2 = new StudentPeriod(inf1000Fall09, connection);
				
		assignment = new StudentAssignment(assignmentId, connection); 
		// Create some test users
				
		homer = new Student(homerId, connection);
		bart = new Student(bartId, connection);
		lisa = new Student(lisaId, connection);
	}
		
	@Test
	public void getPath() throws NoSuchObjectException, NamingException {
		NodePath path = assignment.getPath();
				
		NodePath check = new NodePath(new String[]{"uio", "matnat", "ifi", "inf1000", "spring2009", "oblig1"});
		assertTrue(path.equals(check));
	}
	
	@Test
	public void getDeliveries() throws NoSuchObjectException, UnauthorizedException, NamingException, PathExistsException, InvalidNameException {
		
		// Add some deliveries
		
		assertEquals(0, assignment.getDeliveries().size());
				
		long deliveryId = delivery.create(assignmentId);
		delivery.addStudent(deliveryId, homerId);
		
		assertEquals(1, assignment.getDeliveries().size());
		assertEquals(deliveryId, assignment.getDeliveries().get(0).deliveryId);
				
		long delivery2Id = delivery.create(assignmentId);
		delivery.addStudent(delivery2Id, homerId);
		
		List<StudentDelivery> deliveries = assignment.getDeliveries();
		
		assertEquals(2, deliveries.size());
		
		for (StudentDelivery d : deliveries) {
			long val = d.deliveryId;
			assertTrue(val == deliveryId || val == delivery2Id);
		}
	}
	
	@Test
	public void getDeadline() throws NoSuchObjectException, NamingException {
		assertEquals(assignmentDeadline.getTime(), assignment.getDeadline());
	}
}

@@ -1428,16 +1428,19 @@
 tion); %0A
+%09%09%0A
 %09%09// Cre
@@ -1459,21 +1459,16 @@
 t users%0A
-%09%09%09%09%0A
 %09%09homer 
@@ -2017,34 +2017,8 @@
 %7B%0A%09%09
-%0A%09%09// Add some deliveries%0A
 %09%09%0A%09
@@ -2169,24 +2169,112 @@
 omerId);%0A%09%09%0A
+%09%09// Not connected to student%0A%09%09long infantDelivery = delivery.create(assignmentId);%0A%09%09%0A
 %09%09assertEqua

Add an assignment not connected to user to the test