Subversion Repositories DevTools

Rev

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