View Javadoc

1   /*
2    * Copyright 2012 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package test.de.smartics.ci.config.load;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.equalTo;
20  import static org.hamcrest.Matchers.is;
21  
22  import java.io.File;
23  import java.io.FileNotFoundException;
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  import org.junit.Before;
28  import org.junit.Test;
29  import org.xml.sax.InputSource;
30  
31  import de.smartics.ci.config.load.LoaderPlan;
32  import de.smartics.ci.config.load.LoaderPlanLoader;
33  import de.smartics.ci.config.load.LocationManager;
34  import de.smartics.ci.config.maven.MavenConfig;
35  import de.smartics.ci.config.projects.Project;
36  import de.smartics.ci.config.test.MavenConfigBuilder;
37  import de.smartics.testdoc.annotations.Uut;
38  import de.smartics.util.test.io.FileTestUtils;
39  
40  /**
41   * Tests {@link LoaderPlanLoader}.
42   */
43  public class LoaderPlanLoaderTest
44  {
45    // ********************************* Fields *********************************
46  
47    // --- constants ------------------------------------------------------------
48  
49    // --- members --------------------------------------------------------------
50  
51    @Uut
52    private LoaderPlanLoader uut;
53  
54    private LocationManager locationManager;
55  
56    private MavenConfig mavenConfig;
57  
58    // ****************************** Inner Classes *****************************
59  
60    // ********************************* Methods ********************************
61  
62    // --- prepare --------------------------------------------------------------
63  
64    @Before
65    public void setUp()
66    {
67      locationManager = new LocationManager();
68      final File projectDir =
69          FileTestUtils.getFileFromRelativeResource(Project.class,
70              Project.SINGLE_PROJECT_USING_POM_DEFAULTS);
71      locationManager.addLocation(projectDir);
72  
73      mavenConfig = MavenConfigBuilder.a().build();
74      uut = new LoaderPlanLoader(mavenConfig);
75    }
76  
77    // --- helper ---------------------------------------------------------------
78  
79    // --- tests ----------------------------------------------------------------
80  
81    @Test
82    public void loadsMultipleLoaderInformationFromOneConfigurationFile()
83      throws FileNotFoundException
84    {
85      final InputSource inputSource = locationManager.open("ci-config.xml");
86      final List<LoaderPlan> plans = uut.load(inputSource);
87  
88      final List<LoaderPlan> expectedPlans = new ArrayList<LoaderPlan>(2);
89      final LoaderPlan plan1 = new LoaderPlan("deploy", mavenConfig);
90      plan1.addConfigurationName("hudson-config-root");
91      plan1.addConfigurationName("hudson-config-deploy");
92      plan1.addConfigurationName("hudson-config");
93      expectedPlans.add(plan1);
94      final LoaderPlan plan2 = new LoaderPlan("site", mavenConfig);
95      plan2.addConfigurationName("hudson-config-root");
96      plan2.addConfigurationName("hudson-config-site");
97      plan2.addConfigurationName("hudson-config");
98      expectedPlans.add(plan2);
99  
100     assertThat(plans, is(equalTo(expectedPlans)));
101   }
102 }