Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6914 dpurdie 1
package com.erggroup.buildtool.utf;
2
 
3
import java.sql.SQLException;
4
import java.util.Iterator;
5
import java.util.ListIterator;
6
import java.util.ArrayList;
7
 
8
import com.erggroup.buildtool.escrow.ESCROWBuild;
9
import com.erggroup.buildtool.ripple.BuildStandard;
10
import com.erggroup.buildtool.ripple.Package;
11
import com.erggroup.buildtool.ripple.ReleaseManager;
12
import com.erggroup.buildtool.ripple.RippleEngine;
13
 
14
import org.apache.log4j.Logger;
15
import org.apache.log4j.xml.DOMConfigurator;
16
import org.junit.Test;
17
import org.junit.runner.JUnitCore;
18
 
19
import static org.junit.Assert.*;
20
 
21
public class ESCROWBuildTestCase
22
{
23
    private static final Logger mLogger = Logger.getLogger(DaemonBuildTestCase.class);
24
    ReleaseManager              releaseManager = null;
25
    RippleEngine                rippleEngine   = null;
26
 
27
    /**
28
     * constructor
29
     */
30
    public ESCROWBuildTestCase()
31
    {
32
        mLogger.debug("ESCROWBuildTestCase");
33
        setUpEscrow();
34
    }
35
 
36
    /**
37
     * Test Case main line
38
     */
39
    public static void main(String[] args)
40
    {
41
        DOMConfigurator.configure("utf.xml");
42
        mLogger.debug("main");
43
        JUnitCore.main("com.erggroup.buildtool.utf.ESCROWBuildTestCase");
44
    }
45
 
46
    /** Subclass and override key methods so that the test can control
47
     *  the data being used
48
     */
49
    public class myReleaseManager extends ReleaseManagerUtf
50
	{
51
 
52
        public myReleaseManager(final String connectionString, final String username, final String password)
53
		{
54
			super(connectionString, username, password);
55
		}
56
 
57
		public String queryBaselineName(int baseline) throws SQLException, Exception
58
		{
59
			return "TIMBUKTU (TIM) > R7 7.9";
60
		}
61
 
62
		public void queryPackageVersions(RippleEngine rippleEngine, ArrayList<Package> packageCollection,
63
				int baseline) throws SQLException, Exception
64
		{
65
			/* prod_id pkg_name                pkg_version  v_ext pkg_vcs_tag
66
	         * 8       NotInAnyWayReproducible 1.0.0.tim    .tim  NA                                  NA
67
	         * 10      SolarisCentricProduct   1.0.0000.tim .tim  SolarisCentricProduct_1.0.0000.tim  \vob\SolarisCentricProduct
68
	         * 11      LinuxCentricProduct     1.0.0000.tim .tim  LinuxCentricProduct_1.0.0000.tim    \vob\LinuxCentricProduct
69
	         * 12      Win32CentricProduct     1.0.0000.tim .tim  Win32CentricProduct_1.0.0000.tim    \vob\Win32CentricProduct
70
	         * 13      GenericProduct          1.0.0000.tim .tim  GenericProduct_1.0.0000.tim         \vob\ToBeMovedFromHere
71
	         */
72
	         Package p = new Package(1, 8, "NotInAnyWayReproducible", "1.0.0.tim", ".tim", "NotInAnyWayReproducible.1.0.0.tim", "CC::NA::NA", 'x');
73
	         packageCollection.add(p);
74
	         p = new Package(2, 10, "SolarisCentricProduct", "1.0.0000.tim", ".tim", "SolarisCentricProduct.1.0.0000.tim", "CC::/vob/SolarisCentricProduct::SolarisCentricProduct_1.0.0000.tim", 'x');
75
	         packageCollection.add(p);
76
	         p = new Package(3, 11, "LinuxCentricProduct", "1.0.0000.tim", ".tim", "LinuxCentricProduct.1.0.0000.tim", "CC::/vob/LinuxCentricProduct::LinuxCentricProduct_1.0.0000.tim", 'x');
77
	         packageCollection.add(p);
78
	         p = new Package(4, 12, "Win32CentricProduct", "1.0.0000.tim", ".tim", "Win32CentricProduct.1.0.0000.tim", "CC::/vob/Win32CentricProduct::Win32CentricProduct_1.0.0000.tim", 'x');
79
	         packageCollection.add(p);
80
	         p = new Package(5, 13, "GenericProduct", "1.0.0000.tim", ".tim", "GenericProduct.1.0.0000.tim", "CC::/vob/ToBeMovedFromHere::GenericProduct_1.0.0000.tim", 'x');
81
	         packageCollection.add(p);
82
 
83
	        /* the above products have the following dependencies which will be discovered in traverseDependencies
84
	         * pv_id   pkg_name, dpv.pkg_version, dpv.v_ext, dpv.pkg_vcs_tag
85
	         * 7     CotsWithFunnyVersion         hoopla2_x.cots   .cots CotsWithFunnyVersion_hoopla2_x.cots \vob\CotsWithFunnyVersion
86
	         * 9     CommonDependency             1.0.0000.tim     .tim  CommonDependency_1.0.0000.tim       \vob\CommonDependency
87
	         * 14    AdvisoryDependency           1.0.0000.tim     .tim  AdvisoryDependency_1.0.0000.tim     \vob\AdvisoryDependency
88
	         * the above packages have the following build info
89
	         * pv_id bm_name bsa_name
90
	         * 7     Solaris Debug
91
	         * 9     Linux   Debug
92
	         * 9     Solaris Debug
93
	         * 9     Win32   Production
94
	         * 10    Solaris Java 1.4
95
	         * 11    Linux   Production and Debug
96
	         * 12    Win32   Java 1.6
97
	         * 13    Generic Java 1.4
98
	         * 14    Linux   Debug
99
	         */
100
 
101
	           // use a ListIterator as it allows traverseDependencies to modify the packageCollection
102
	           for (ListIterator<Package> it = packageCollection.listIterator(); it.hasNext(); )
103
	           {
104
	             p = it.next();
105
	             traverseDependencies(packageCollection, p, false, it);
106
	           }
107
 
108
	           for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
109
	           {
110
	             p = it.next();
111
	             queryBuildInfo(rippleEngine, p);
112
	           }
113
 
114
 
115
		}
116
 
117
		  /**called only in escrow mode
118
		   * if checkCollection is true, checks the pv_id is in the packageCollection
119
		   * if checkCollection is false, or the pv_id is not in the collection
120
		   * 1 traverses the pv_id package dependencies
121
		   *   select dpv.pv_id, p.pkg_name, dpv.pkg_version, dpv.v_ext
122
		   *   from release_manager.package_versions pv, release_manager.package_dependencies pd, release_manager.package_versions dpv, release_manager.packages p
123
		   *   where pv.pv_id = <pv_id> and pd.pv_id=pv.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id
124
		   *   order by pv.pv_id;
125
		   * 2 for each dpv.pv_id in the resultset
126
		   *     call traverseDependencies( packageCollection, dpv.pv_id, true )
127
		   *     if the pv_id is not in the collection, add it
128
		   *   
129
		   */
130
		public void traverseDependencies(ArrayList<Package> packageCollection, Package pkg, 
131
		                                     boolean checkCollection, 
132
		                                     ListIterator<Package> listIterator) throws SQLException, Exception
133
		  {
134
		    mLogger.debug("traverseDependencies " + checkCollection);
135
		    boolean pvIdInCollection = false;
136
 
137
		    if ( checkCollection )
138
		    {
139
		      for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
140
		      {
141
		        Package p = it.next();
142
 
143
		        if ( p.mId == pkg.mId )
144
		        {
145
		          pvIdInCollection = true;
146
		          break;
147
		        }
148
		      }
149
		    }
150
 
151
		    if ( !pvIdInCollection )
152
		    {
153
		      ArrayList<Package> resultset = new ArrayList<Package>();
154
 
155
 
156
		         /* 7      CotsWithFunnyVersion
157
		          * 8      NotInAnyWayReproducible
158
		          * 9      CommonDependency 
159
	             * 10      SolarisCentricProduct
160
	             * 11      LinuxCentricProduct
161
	             * 13      GenericProduct
162
	             * 14      AdvisoryDependency         
163
	             */
164
		        if ( pkg.mId == 8 || pkg.mId == 10 || pkg.mId == 13 )
165
		        {
166
		          Package p = new Package(1, 9, "CommonDependency", "1.0.0000.tim", ".tim", "CommonDependency.1.0.0000.tim", "CC::/vob/CommonDependency::CommonDependency_1.0.0000.tim", 'x');
167
		          resultset.add(p);
168
		          pkg.mDependencyCollection.add(p.mAlias);
169
		        }
170
		        else if ( pkg.mId == 9 )
171
		        {
172
		          Package p = new Package(2, 7, "CotsWithFunnyVersion", "hoopla2_x.cots", ".cots", "CotsWithFunnyVersion.hoopla2_x.cots", "CC::/vob/CotsWithFunnyVersion::CotsWithFunnyVersion_hoopla2_x.cots", 'x');
173
		          resultset.add(p);
174
		          pkg.mDependencyCollection.add(p.mAlias);
175
		        }
176
		        else if ( pkg.mId == 11 )
177
		        {
178
		          Package p = new Package(3, 14, "AdvisoryDependency", "1.0.0000.tim", ".tim", "AdvisoryDependency.1.0.0000.tim", "CC::/vob/AdvisoryDependency::AdvisoryDependency_1.0.0000.tim", 'x');
179
		          resultset.add(p);
180
		          pkg.mDependencyCollection.add(p.mAlias);
181
		        }
182
 
183
 
184
		      for (Iterator<Package> it = resultset.iterator(); it.hasNext(); )
185
		      {
186
		        Package r = it.next();
187
		        traverseDependencies(packageCollection, r, true, listIterator);
188
 
189
		        pvIdInCollection = false;
190
 
191
		        for (Iterator<Package> it2 = packageCollection.iterator(); it2.hasNext(); )
192
		        {
193
		          Package p = it2.next();
194
 
195
		          if ( p.mId == r.mId )
196
		          {
197
		            pvIdInCollection = true;
198
		            break;
199
		          }
200
		        }
201
 
202
		        if (!pvIdInCollection)
203
		        {
204
		          // insert the Package immediately before the next Package returned by next
205
		          // this does not change the next Package (if any) to be returned by next
206
		          listIterator.add(r);
207
		        }
208
 
209
		      }
210
		    }
211
		  }
212
 
213
		/**called only in escrow mode to add build info to the Package
214
		   * select bm.bm_name, bsa.bsa_name
215
		   * from release_manager.package_versions pv, release_manager.package_build_info pbi, release_manager.build_machines bm, release_manager.build_standards_addendum bsa
216
		   * where pv.pv_id = <p.pv_id> and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id
217
		   * order by pv.pv_id;
218
		   */
219
		  private void queryBuildInfo(RippleEngine rippleEngine, Package p) throws SQLException, Exception
220
		  {
221
		    mLogger.debug("queryBuildInfo");
222
 
223
		      mLogger.info("queryBuildInfo !mUseDatabase");
224
 
225
		      if (p.mId == 7)
226
		      {
227
		        BuildStandard bs = new BuildStandard(rippleEngine,"Solaris", "Debug");
228
		        p.mBuildStandardCollection.add(bs);
229
		      }
230
		      else if (p.mId == 9)
231
		      {
232
		        BuildStandard bs = new BuildStandard(rippleEngine, "Linux", "Debug");
233
		        p.mBuildStandardCollection.add(bs);
234
		        bs = new BuildStandard(rippleEngine, "Solaris", "Debug");
235
		        p.mBuildStandardCollection.add(bs);
236
		        bs = new BuildStandard(rippleEngine, "Win32", "Production");
237
		        p.mBuildStandardCollection.add(bs);
238
		      }
239
		      else if (p.mId == 10)
240
		      {
241
		        BuildStandard bs = new BuildStandard(rippleEngine, "Solaris", "Java 1.4");
242
		        p.mBuildStandardCollection.add(bs);
243
		      }
244
		      else if (p.mId == 11)
245
		      {
246
		        BuildStandard bs = new BuildStandard(rippleEngine, "Linux", "Production and Debug");
247
		        p.mBuildStandardCollection.add(bs);
248
		      }
249
		      else if (p.mId == 12)
250
		      {
251
		        BuildStandard bs = new BuildStandard(rippleEngine, "Win32", "Java 1.6");
252
		        p.mBuildStandardCollection.add(bs);
253
		      }
254
		      else if (p.mId == 13)
255
		      {
256
		        BuildStandard bs = new BuildStandard(rippleEngine, "Generic", "Java 1.4");
257
		        p.mBuildStandardCollection.add(bs);
258
		      }
259
		      else if (p.mId == 14)
260
		      {
261
		        BuildStandard bs = new BuildStandard(rippleEngine, "Linux", "Debug");
262
		        p.mBuildStandardCollection.add(bs);
263
		      }
264
 
265
		    }
266
 
267
		}
268
 
269
 
270
    /** Setup and Run the Escrow
271
     *  The tests will be the results of the escrow run
272
     */
273
    public void setUpEscrow()
274
    {
275
       mLogger.debug("TestESCROWBuild");
276
 
277
 
278
        //	Construct a Release Manager and Ripple Builder
279
        //	Run the Escrow Engine
280
        //
281
        DOMConfigurator.configure("work/abtd.xml");
282
        releaseManager = new myReleaseManager("not used", "not used", "not used");
283
        myReleaseManager.mUseDatabase = false;
284
        rippleEngine = new RippleEngine(releaseManager, 99999, false);
285
        ESCROWBuild.generateEscrowFiles(rippleEngine, "build");	
286
    }
287
 
288
    @Test
289
    public void TestEscrowBuildFiles()
290
    {
291
        //	Examine the results
292
        //
293
        boolean rv1 = Utilities.checkBuildfiles("build1.xml");
294
        boolean rv2 = Utilities.checkBuildfiles("build2.xml");
295
        boolean rv3 = Utilities.checkBuildfiles("build3.xml");
296
 
297
        //  Test assertions - after all files have been processed
298
        //
299
        assertTrue(rv1);
300
        assertTrue(rv2);
301
        assertTrue(rv3);
302
    }
303
 
304
    @Test
305
    public void TestEscrowDataFiles()
306
    {
307
        // Examine the other escrow files
308
        boolean rv4 = Utilities.checkBuildfiles("escrow_set_up");
309
        boolean rv5 = Utilities.checkBuildfiles("raw_data.csv");
310
 
311
        assertTrue(rv4);
312
        assertTrue(rv5);
313
    }
314
 
315
 
316
}