001/*
002 *   Copyright (C) Christian Schulte, 2005-206
003 *   All rights reserved.
004 *
005 *   Redistribution and use in source and binary forms, with or without
006 *   modification, are permitted provided that the following conditions
007 *   are met:
008 *
009 *     o Redistributions of source code must retain the above copyright
010 *       notice, this list of conditions and the following disclaimer.
011 *
012 *     o Redistributions in binary form must reproduce the above copyright
013 *       notice, this list of conditions and the following disclaimer in
014 *       the documentation and/or other materials provided with the
015 *       distribution.
016 *
017 *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
018 *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
019 *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
020 *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
021 *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
022 *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
023 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
024 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
026 *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027 *
028 *   $JOMC: ServicesTest.java 4613 2012-09-22 10:07:08Z schulte $
029 *
030 */
031package org.jomc.modlet.test;
032
033import org.jomc.modlet.Service;
034import org.jomc.modlet.Services;
035import org.junit.Test;
036import static org.junit.Assert.assertEquals;
037import static org.junit.Assert.assertNotNull;
038import static org.junit.Assert.fail;
039
040/**
041 * Test cases for class {@code org.jomc.modlet.Services}.
042 *
043 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.0
044 * @version $JOMC: ServicesTest.java 4613 2012-09-22 10:07:08Z schulte $
045 */
046public class ServicesTest
047{
048
049    /** Creates a new {@code ServicesTest} instance. */
050    public ServicesTest()
051    {
052        super();
053    }
054
055    @Test
056    public final void testGetServices() throws Exception
057    {
058        final Services services = new Services();
059
060        try
061        {
062            services.getServices( (String) null );
063            fail( "Expected NullPointerException not thrown." );
064        }
065        catch ( final NullPointerException e )
066        {
067            assertNotNull( e.getMessage() );
068            System.out.println( e );
069        }
070
071        try
072        {
073            services.getServices( (Class) null );
074            fail( "Expected NullPointerException not thrown." );
075        }
076        catch ( final NullPointerException e )
077        {
078            assertNotNull( e.getMessage() );
079            System.out.println( e );
080        }
081
082        final Service s1 = new Service();
083        s1.setOrdinal( 1000 );
084        s1.setIdentifier( this.getClass().getName() );
085        s1.setClazz( "Service 1" );
086
087        final Service s2 = new Service();
088        s2.setOrdinal( 500 );
089        s2.setIdentifier( this.getClass().getName() );
090        s2.setClazz( "Service 2" );
091
092        services.getService().add( s1 );
093        services.getService().add( s2 );
094
095        assertNotNull( services.getServices( this.getClass() ) );
096        assertEquals( 2, services.getServices( this.getClass() ).size() );
097        assertEquals( "Service 2", services.getServices( this.getClass() ).get( 0 ).getClazz() );
098        assertEquals( "Service 1", services.getServices( this.getClass() ).get( 1 ).getClazz() );
099
100        assertNotNull( services.getServices( this.getClass().getName() ) );
101        assertEquals( 2, services.getServices( this.getClass().getName() ).size() );
102        assertEquals( "Service 2", services.getServices( this.getClass().getName() ).get( 0 ).getClazz() );
103        assertEquals( "Service 1", services.getServices( this.getClass().getName() ).get( 1 ).getClazz() );
104    }
105
106}