/**
* Copyright 2014 Comcast Cable Communications Management, LLC
*
* This file is part of CATS.
*
* CATS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CATS 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 CATS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.comcast.cats.domain.service;
import java.nio.channels.IllegalSelectorException;
import java.util.List;
import junit.framework.Assert;
import org.easymock.EasyMock;
import org.junit.Test;
import com.comcast.cats.domain.HardwarePurpose;
import com.comcast.cats.domain.SettopDesc;
import com.comcast.cats.domain.SettopGroup;
import com.comcast.cats.domain.test.DataProvider;
/**
* Test cases for {@link SettopGroup} id based search APIs in
* {@link SettopDomainService}.
*
* @author subinsugunan
*
*/
public class SettopDomainServiceBasedOnSettopGroupIdTest extends BaseSettopDomainServiceTest
{
@Test( expected = IllegalArgumentException.class )
public void findAllBySettopGroupIdNull()
{
settopDomainService.findAllBySettopGroupId( null );
}
@Test( expected = IllegalArgumentException.class )
public void findAllBySettopGroupIdEmpty()
{
settopDomainService.findAllBySettopGroupId( "" );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test( expected = RuntimeException.class )
public void findAllByInvalidSettopGroupId()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andThrow( new IllegalSelectorException() );
replayAll();
List< SettopDesc > settops = settopDomainService.findAllBySettopGroupId( DataProvider.INVALID_ID );
logResult( settops.size() );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test
public void findAllBySettopGroupId()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andReturn( dataProvider.getSettopDescList() );
replayAll();
List< SettopDesc > settops = settopDomainService.findAllBySettopGroupId( testProperties.getSettopGroupId() );
logResult( settops.size() );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test
public void findAllBySettopGroupIdShallowTrue()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andReturn( dataProvider.getSettopDescList( true ) );
replayAll();
List< SettopDesc > settops = settopDomainService.findAllBySettopGroupId( testProperties.getSettopGroupId(),true );
logResult( settops.size() );
Assert.assertNull( "shallow object contains hardware info",
settops.get( 0 ).getHardwareInterfaceByType( HardwarePurpose.POWER ) );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test
public void findAllBySettopGroupIdShallowFalse()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andReturn( dataProvider.getSettopDescList( false ) );
replayAll();
List< SettopDesc > settops = settopDomainService.findAllBySettopGroupId( testProperties.getSettopGroupId() ,false);
logResult( settops.size() );
Assert.assertNotNull( " object does not contains hardware info",
settops.get( 0 ).getHardwareInterfaceByType( HardwarePurpose.POWER ) );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test
public void findAlleBySettopGroupIdOffset()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andReturn( dataProvider.getSettopDescList() );
replayAll();
List< SettopDesc > settops = settopDomainService.findAllBySettopGroupId( testProperties.getSettopGroupId(),
offset, count );
logResult( settops.size() );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test
public void findAlleBySettopGroupIdOffsetShallowTrue()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andReturn( dataProvider.getSettopDescList( true ) );
replayAll();
List< SettopDesc > settops = settopDomainService.findAllBySettopGroupId( testProperties.getSettopGroupId(),
offset, count,true );
logResult( settops.size() );
Assert.assertNull( "shallow object contains hardware info",
settops.get( 0 ).getHardwareInterfaceByType( HardwarePurpose.POWER ) );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test
public void findAlleBySettopGroupIdOffsetShallowFalse()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andReturn( dataProvider.getSettopDescList( false ) );
replayAll();
List< SettopDesc > settops = settopDomainService.findAllBySettopGroupId( testProperties.getSettopGroupId(),
offset, count,false );
logResult( settops.size() );
Assert.assertNotNull( " object does not contains hardware info",
settops.get( 0 ).getHardwareInterfaceByType( HardwarePurpose.POWER ) );
}
@Test( expected = IllegalArgumentException.class )
public void findAvailableBySettopGroupIdNull()
{
settopDomainService.findAvailableBySettopGroupId( null );
}
@Test( expected = IllegalArgumentException.class )
public void findAvailableBySettopGroupIdEmpty()
{
settopDomainService.findAvailableBySettopGroupId( "" );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test( expected = RuntimeException.class )
public void findAvailableByInvalidSettopGroupId()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andThrow( new IllegalSelectorException() );
replayAll();
List< SettopDesc > settops = settopDomainService.findAllBySettopGroupId( DataProvider.INVALID_ID );
logResult( settops.size() );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test
public void findAvailableBySettopGroupId()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andReturn( dataProvider.getSettopDescList() );
replayAll();
List< SettopDesc > settops = settopDomainService.findAvailableBySettopGroupId( testProperties
.getSettopGroupId() );
logResult( settops.size() );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test
public void findAvailableBySettopGroupIdShallowTrue()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andReturn( dataProvider.getSettopDescList( true ) );
replayAll();
List< SettopDesc > settops = settopDomainService.findAvailableBySettopGroupId( testProperties
.getSettopGroupId(),true );
logResult( settops.size() );
Assert.assertNull( "shallow object contains hardware info",
settops.get( 0 ).getHardwareInterfaceByType( HardwarePurpose.POWER ) );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test
public void findAvailableBySettopGroupIdShallowFalse()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andReturn( dataProvider.getSettopDescList( false ) );
replayAll();
List< SettopDesc > settops = settopDomainService.findAvailableBySettopGroupId( testProperties
.getSettopGroupId(),false );
logResult( settops.size() );
Assert.assertNotNull( " object does not contains hardware info",
settops.get( 0 ).getHardwareInterfaceByType( HardwarePurpose.POWER ) );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test
public void findAvailableBySettopGroupIdOffset()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andReturn( dataProvider.getSettopDescList() );
replayAll();
List< SettopDesc > settops = settopDomainService.findAvailableBySettopGroupId(
testProperties.getSettopGroupId(), offset, count );
logResult( settops.size() );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test
public void findAvailableBySettopGroupIdOffsetShallowTrue()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andReturn( dataProvider.getSettopDescList( true ) );
replayAll();
List< SettopDesc > settops = settopDomainService.findAvailableBySettopGroupId(
testProperties.getSettopGroupId(), offset, count,true );
logResult( settops.size() );
Assert.assertNull( "shallow object contains hardware info",
settops.get( 0 ).getHardwareInterfaceByType( HardwarePurpose.POWER ) );
}
@SuppressWarnings(
{ "rawtypes", "unchecked" } )
@Test
public void findAvailableBySettopGroupIdOffsetShallowFalse()
{
EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) )
.andReturn( dataProvider.getSettopDescList( false ) );
replayAll();
List< SettopDesc > settops = settopDomainService.findAvailableBySettopGroupId(
testProperties.getSettopGroupId(), offset, count,false );
logResult( settops.size() );
Assert.assertNotNull( " object does not contains hardware info",
settops.get( 0 ).getHardwareInterfaceByType( HardwarePurpose.POWER ) );
}
}