/*
Copyright 2006 - 2010 Under Dusken
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 no.dusken.aranea.service;
import no.dusken.aranea.model.Issue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import static junit.framework.Assert.*;
/**
* @author Erlend Hamnaberg<erlenha@underdusken.no>
* @author Marvin B. Lillehaug <lillehau@underdusken.no>
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/META-INF/integrationTest.xml"})
@TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true)
@Transactional
public class TestIssueServiceImpl {
@Autowired
private IssueService issueService;
private Issue issue;
@Before
public void onSetup(){
issue = new Issue();
issue.setIssue(1);
Calendar from = new GregorianCalendar(2007, 01, 1);
Calendar to = new GregorianCalendar(2007, 05, 1);
issue.setFromDate(from);
issue.setToDate(to);
issue.setTimeCreated(to);
issue.setDescription("#UD 01");
issue = issueService.saveOrUpdate(issue);
Issue issue2 = new Issue();
issue2.setIssue(1);
Calendar from2 = new GregorianCalendar(2007, 05, 1);
Calendar to2 = new GregorianCalendar(2007, 11, 11);
issue2.setFromDate(from2);
issue2.setToDate(to2);
issue2.setTimeCreated(to);
issue2.setDescription("#UD 01");
issue2 = issueService.saveOrUpdate(issue2);
}
@Test
public void testGetEntity() {
Issue iss = issueService.getEntity(issue.getID());
assertNotNull(iss);
}
@Test
public void testGetCurrentIssue() {
Issue iss = issueService.getCurrentIssue();
assertNotNull(iss);
}
@Test
public void testGetIssues() {
List<Issue> list = issueService.getIssues();
assertEquals(list.size(), 2);
}
@Test
public void testGetIssuesYear() {
List<Issue> list = issueService.getIssues(2007);
assertEquals(list.size(), 2);
}
@Test
public void testGetOldestIssue() {
Issue iss = issueService.getOldestIssue();
assertEquals(iss, issue);
}
@Test
public void testNotPublished(){
List issues = issueService.getPublishedIssues(5);
assertEquals(2, issues.size());
}
@Test
public void testPublished(){
Issue issue2 = new Issue();
issue2.setIssue(3);
Calendar from = new GregorianCalendar();
Calendar to = new GregorianCalendar();
from.add(Calendar.YEAR, 1);
to.add(Calendar.YEAR, 1);
issue2.setFromDate(from);
issue2.setToDate(to);
issue2.setTimeCreated(to);
issue2.setDescription("#UD 01");
issue2 = issueService.saveOrUpdate(issue2);
List issues = issueService.getPublishedIssues(5);
assertEquals(2, issues.size());
assertFalse("Should not contain issue 3", issues.contains(issue2));
}
}