package edu.msu.nscl.olog.api;

import static org.junit.Assert.*;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import edu.msu.nscl.olog.api.OlogClientImpl.OlogClientBuilder;
import static edu.msu.nscl.olog.api.LogBuilder.*;
import static edu.msu.nscl.olog.api.PropertyBuilder.*;
import static edu.msu.nscl.olog.api.TagBuilder.*;
import static edu.msu.nscl.olog.api.LogbookBuilder.*;

public class ErrorIT {

	private static LogbookBuilder validLogbook = logbook("Valid Logbook");
	private static TagBuilder validTag = tag("Valid Tag");
	private static PropertyBuilder validProperty = property("Valid Property")
			.attribute("Valid Attribute");
	private static LogBuilder validLog = log().description(
			"Valid Log Entry for error condition tests.").appendToLogbook(
			validLogbook);

	private static LogbookBuilder inValidLogbook = logbook("InValid Logbook");
	private static TagBuilder inValidTag = tag("InValid Tag");
	private static PropertyBuilder inValidProperty = property("InValid Property");

	private static OlogClient client;

	@BeforeClass
	public static void setup() {
		try {
			client = OlogClientBuilder.serviceURL()
					.withHTTPAuthentication(true).create();
			client.set(validTag);
			client.set(validLogbook.owner("test"));
			client.set(validProperty);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@AfterClass
	public static void tearDown() {
		client.deleteTag(validTag.build().getName());
		client.deleteLogbook(validLogbook.build().getName());
		client.deleteProperty(validProperty.build().getName());
	}

	@Test(expected = OlogException.class)
	public void setLogWithInvalidLogbook() {
		LogBuilder log = log().description("log with invalid logbook")
				.level("Info").appendToLogbook(inValidLogbook);
		client.set(log);
	}

	@Test(expected = OlogException.class)
	public void setLogWithInvalidTag() {
		LogBuilder log = log().description("log with invalid tag")
				.level("Info").appendTag(inValidTag);
		client.set(log);
	}

	@Test(expected = OlogException.class)
	public void setLogWithInvalidProperty() {
		LogBuilder log = log().description("log with invalid property")
				.level("Info").appendProperty(inValidProperty);
		client.set(log);
	}

	@Test(expected = OlogException.class)
	public void setLogWithInvalidAttribute() {
		LogBuilder log = log()
				.description("log with invalid attribute")
				.level("Info")
				.appendProperty(validProperty.attribute("invalidAttribute", ""));
		client.set(log);
	}

	@Test
	public void setTagOnInvalidLog() {

	}

	@Test
	public void setInvalidTagOnLog() {

	}

}

@@ -1663,32 +1663,410 @@
 Name());%0D%0A%09%7D%0D%0A%0D%0A
+%09@Test(expected = OlogException.class)%0D%0A%09public void setLogWithNoLogbook() %7B%0D%0A%09%09LogBuilder log = log().description(%22log with no logbook%22).level(%22Info%22);%0D%0A%09%09client.set(log);%0D%0A%09%7D%0D%0A%0D%0A%09@Test(expected = OlogException.class)%0D%0A%09public void setLogWithNoLevel() %7B%0D%0A%09%09LogBuilder log = log().description(%22log with no level%22)%0D%0A%09%09%09%09.appendToLogbook(validLogbook);%0D%0A%09%09client.set(log);%0D%0A%09%7D%0D%0A%0D%0A
 %09@Test(expected 
@@ -2124,32 +2124,32 @@
 lidLogbook() %7B%0D%0A
-
 %09%09LogBuilder log
@@ -2428,32 +2428,68 @@
 %09%09.level(%22Info%22)
+.appendToLogbook(validLogbook)%0D%0A%09%09%09%09
 .appendTag(inVal
@@ -2688,24 +2688,60 @@
 evel(%22Info%22)
+.appendToLogbook(validLogbook)%0D%0A%09%09%09%09
 .appendPrope
@@ -2944,24 +2944,24 @@
 ttribute%22)%0D%0A
-
 %09%09%09%09.level(%22
@@ -2964,24 +2964,60 @@
 el(%22Info%22)%0D%0A
+%09%09%09%09.appendToLogbook(validLogbook)%0D%0A
 %09%09%09%09.appendP

add the required logbook and level, add test for log entries without logbook or level