@@ -0,0 +1,3060 @@
+/*%0A * %0A * %0A * Copyright (C) 2007 SIPfoundry Inc.%0A * Licensed by SIPfoundry under the LGPL license.%0A * %0A * Copyright (C) 2007 Pingtel Corp.%0A * Licensed to SIPfoundry under a Contributor Agreement.%0A * %0A * $%0A */%0Apackage org.sipfoundry.sipxconfig.service;%0A%0Aimport junit.framework.TestCase;%0A%0Aimport org.easymock.classextension.EasyMock;%0Aimport org.easymock.classextension.IMocksControl;%0Aimport org.sipfoundry.sipxconfig.device.ModelSource;%0A%0Apublic class AddServiceTaskTest extends TestCase %7B%0A%0A    public void testAddService() %7B%0A        ServiceDescriptor turkeyDesctriptor = new ServiceDescriptor(%22bird%22, %22turkey%22);%0A        IMocksControl serviceSourceControl = EasyMock.createControl();%0A        ModelSource%3CServiceDescriptor%3E serviceSource = serviceSourceControl.createMock(ModelSource.class);%0A        serviceSource.getModel(%22turkey%22);%0A        serviceSourceControl.andReturn(turkeyDesctriptor).anyTimes();%0A        serviceSourceControl.replay();%0A        %0A        ConfiguredService turkey = new UnmanagedService();%0A        turkey.setDescriptor(turkeyDesctriptor);%0A        %0A        IMocksControl serviceManagerControl = EasyMock.createStrictControl();%0A        ServiceManager serviceManager = serviceManagerControl.createMock(ServiceManager.class);%0A%0A        %0A        // already a service%0A        serviceManager.getServiceByName(%22Thanksgiving%22);%0A        serviceManagerControl.andReturn(turkey);%0A        serviceManagerControl.replay();%0A        AddServiceTask task = new AddServiceTask();%0A        task.setServiceManager(serviceManager);%0A        task.setServicesSource(serviceSource);%0A        try %7B%0A            task.addService(%22Thanksgiving%22, %22chicken%22, %221.1.1.1%22);%0A            fail();%0A        %7D catch (IllegalArgumentException expected) %7B            %0A        %7D        %0A        serviceManagerControl.verify();%0A        %0A%0A        // update service%0A        serviceManagerControl.reset();%0A        serviceManager.getServiceByName(%22Thanksgiving%22);%0A        serviceManagerControl.andReturn(turkey);%0A        serviceManager.saveService(turkey);%0A        serviceManagerControl.replay();        %0A        turkey.setName(%22Thanksgiving%22);%0A        task.addService(%22Thanksgiving%22, %22turkey%22, %221.1.1.1%22);%0A        serviceManagerControl.verify();%0A        %0A        // add a service%0A        serviceManagerControl.reset();%0A        serviceManager.getServiceByName(%22Thanksgiving%22);%0A        serviceManagerControl.andReturn(null);%0A        serviceManager.newService(turkeyDesctriptor);%0A        serviceManagerControl.andReturn(turkey);%0A        serviceManager.saveService(turkey);        %0A        serviceManagerControl.replay();            %0A        turkey.setName(%22Thanksgiving%22);%0A        task.addService(%22Thanksgiving%22, %22turkey%22, %221.1.1.1%22);        %0A        serviceManagerControl.verify();%0A    %7D%0A%0A    public void testAssertArgument() %7B%0A        AddServiceTask.assertArgument(new String%5B%5D %7B%22x%22%7D, 0, %22x%22);%0A        try %7B%0A            AddServiceTask.assertArgument(new String%5B0%5D, 0, %22x%22);%0A            fail();%0A        %7D catch (IllegalArgumentException expected) %7B%0A            assertTrue(true);%0A        %7D%0A    %7D%0A%7D%0A

Add forgotten unit test for adding a new service task