/*
 * Copyright 2012 Sebastian.
 *
 * 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.aegee.runanddine.pathfinder;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.aegee.runanddine.AbstractDbEnabledTest;
import org.aegee.runanddine.registration.GroupRegistration;
import org.aegee.runanddine.registration.SingleRegistration;
import org.junit.Test;

/**
 * 
 * @author Sebastian
 */
public class OptGroupTest extends AbstractDbEnabledTest
{
	int runAndDineId = 1;

	OptGroup og1, og2;

	SingleRegistration sr1, sr2;

	GroupRegistration gr;

	public OptGroupTest()
	{
		// OptGroup out of two SingleRegistrations
		sr1 = new SingleRegistration();
		sr1.setFirstName("ralf");
		sr1.setLastName("ralle");
		sr1.setEmail("email1");
		sr1.setVegetarian(true);
		sr1.setAllergies("a1");
		sr1.setPhone("p1");
		sr2 = new SingleRegistration();
		sr2.setFirstName("marko");
		sr2.setLastName("mondschein");
		sr2.setEmail("email2");
		sr2.setVegetarian(false);
		sr2.setAllergies("a2");
		sr2.setPhone("p2");
		og1 = new OptGroup(sr1, sr2);
		og1.setRunAndDineId(runAndDineId);
		// OptGroup out of one GroupRegistration
		gr = new GroupRegistration();
		gr.setFirstName1("andy");
		gr.setLastName1("aal");
		gr.setEmail1("email3");
		;
		gr.setVegetarian1(false);
		gr.setAllergies1("a3");
		gr.setPhone1("p3");
		gr.setFirstName2("karl");
		gr.setLastName2("klar");
		gr.setEmail2("email4");
		gr.setVegetarian2(true);
		gr.setAllergies2("a4");
		gr.setPhone2("p4");
		og2 = new OptGroup(gr);
		og2.setRunAndDineId(runAndDineId);
	}

	/**
	 * Test of getRunAndDineId method, of class OptGroup.
	 */
	@Test
	public void testGetRunAndDineId()
	{
		assertEquals(og1.getRunAndDineId(), runAndDineId);
	}

	/**
	 * Test of isGroupRegistration method, of class OptGroup.
	 */
	@Test
	public void testIsGroupRegistration()
	{
		assertTrue(!og1.isGroupRegistration());
		assertTrue(og2.isGroupRegistration());
	}

	/**
	 * Test of getGroupRegistration method, of class OptGroup.
	 */
	@Test
	public void testGetGroupRegistration()
	{
		assertEquals(og1.getGroupRegistration(), null);
		assertEquals(og2.getGroupRegistration(), gr);
	}

	/**
	 * Test of getFirstName1 method, of class OptGroup.
	 */
	@Test
	public void testGetFirstName1()
	{
		assertEquals(og1.getFirstName1(), "ralf");
		assertEquals(og2.getFirstName1(), "andy");
	}

	/**
	 * Test of getFirstName2 method, of class OptGroup.
	 */
	@Test
	public void testGetFirstName2()
	{
		assertEquals(og1.getFirstName2(), "marko");
		assertEquals(og2.getFirstName2(), "karl");
	}

	/**
	 * Test of getLastName1 method, of class OptGroup.
	 */
	@Test
	public void testGetLastName1()
	{
		assertEquals(og1.getLastName1(), "ralle");
		assertEquals(og2.getLastName1(), "aal");
	}

	/**
	 * Test of getLastName2 method, of class OptGroup.
	 */
	@Test
	public void testGetLastName2()
	{
		assertEquals(og1.getLastName2(), "mondschein");
		assertEquals(og2.getLastName2(), "klar");
	}

	/**
	 * Test of getEmail1 method, of class OptGroup.
	 */
	@Test
	public void testGetEmail1()
	{
		assertEquals(og1.getEmail1(), "email1");
		assertEquals(og2.getEmail1(), "email3");
	}

	/**
	 * Test of getEmail2 method, of class OptGroup.
	 */
	@Test
	public void testGetEmail2()
	{
		assertEquals(og1.getEmail2(), "email2");
		assertEquals(og2.getEmail2(), "email4");
	}

	/**
	 * Test of isVegetarian1 method, of class OptGroup.
	 */
	@Test
	public void testIsVegetarian1()
	{
		assertTrue(og1.isVegetarian1());
		assertTrue(!og2.isVegetarian1());
	}

	/**
	 * Test of isVegetarian2 method, of class OptGroup.
	 */
	@Test
	public void testIsVegetarian2()
	{
		assertTrue(!og1.isVegetarian2());
		assertTrue(og2.isVegetarian2());
	}

	/**
	 * Test of getAllergies1 method, of class OptGroup.
	 */
	@Test
	public void testGetAllergies1()
	{
		assertEquals(og1.getAllergies1(), "a1");
		assertEquals(og2.getAllergies1(), "a3");
	}

	/**
	 * Test of getAllergies2 method, of class OptGroup.
	 */
	@Test
	public void testGetAllergies2()
	{
		assertEquals(og1.getAllergies2(), "a2");
		assertEquals(og2.getAllergies2(), "a4");
	}

	/**
	 * Test of getAllSingleGroups method, of class OptGroup.
	 */
	@Test
	public void testGetAllSingleGroups()
	{
		OptGroupManager ogm = OptGroupManager.getInstance();
		ogm.save(og1);
		ogm.save(og2);

		List<OptGroup> ogl = OptGroup.getAllSingleGroups(runAndDineId);

		assertTrue(ogl.contains(og1));
		assertTrue(!ogl.contains(og2));

		ogm.delete(og1);
		ogm.delete(og2);
	}

	/**
	 * Test of getPhone1 method, of class OptGroup.
	 */
	@Test
	public void testGetPhone1()
	{
		assertEquals(og1.getPhone1(), "p1");
		assertEquals(og2.getPhone1(), "p3");
	}

	/**
	 * Test of getPhone2 method, of class OptGroup.
	 */
	@Test
	public void testGetPhone2()
	{
		assertEquals(og1.getPhone2(), "p2");
		assertEquals(og2.getPhone2(), "p4");
	}
}
