View Javadoc

1   package org.apache.continuum.release.distributed.manager;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.continuum.dao.BuildResultDao;
23  import org.apache.maven.continuum.model.project.BuildResult;
24  import org.codehaus.plexus.spring.PlexusInSpringTestCase;
25  import org.jmock.Expectations;
26  import org.jmock.Mockery;
27  import org.jmock.integration.junit3.JUnit3Mockery;
28  import org.jmock.lib.legacy.ClassImposteriser;
29  
30  /**
31   * DefaultDistributedReleaseManagerTest
32   */
33  public class DefaultDistributedReleaseManagerTest
34      extends PlexusInSpringTestCase
35  {
36      private DefaultDistributedReleaseManager distributedReleaseManager;
37  
38      private BuildResultDao buildResultDao;
39  
40      private BuildResult buildResult;
41  
42      private Mockery context;
43  
44      @Override
45      protected void setUp()
46          throws Exception
47      {
48          super.setUp();
49  
50          context = new JUnit3Mockery();
51          context.setImposteriser( ClassImposteriser.INSTANCE );
52  
53          distributedReleaseManager = new DefaultDistributedReleaseManager();
54  
55          buildResultDao = context.mock( BuildResultDao.class );
56          distributedReleaseManager.setBuildResultDao( buildResultDao );
57      }
58  
59      public void testGetDefaultBuildagent()
60          throws Exception
61      {
62          String defaultBuildagentUrl = "http://localhost:8181/continuum-buildagent/xmlrpc";
63  
64          buildResult = new BuildResult();
65          buildResult.setBuildUrl( defaultBuildagentUrl );
66  
67          contextBuildResultDaoExpectations();
68  
69          String returnedBuildagent = distributedReleaseManager.getDefaultBuildagent( 0 );
70  
71          assertNotNull( returnedBuildagent );
72          assertEquals( returnedBuildagent, defaultBuildagentUrl );
73  
74          context.assertIsSatisfied();
75      }
76  
77      public void testGetDefaultBuildagentNullBuildResult()
78          throws Exception
79      {
80          buildResult = null;
81  
82          contextBuildResultDaoExpectations();
83  
84          String returnedBuildagent = distributedReleaseManager.getDefaultBuildagent( 0 );
85  
86          assertNull( returnedBuildagent );
87  
88          context.assertIsSatisfied();
89      }
90  
91      private void contextBuildResultDaoExpectations()
92          throws Exception
93      {
94          context.checking( new Expectations()
95          {
96              {
97                  one( buildResultDao ).getLatestBuildResultForProject( 0 );
98                  will( returnValue( buildResult ) );
99              }
100         } );
101     }
102 }