RepositoryPackageService repoPackageService = getRepositoryPackageService();
long before = System.currentTimeMillis();
Thread.sleep( 20 );
FileManagerUtils uploadHelper = getFileManagerUtils();
PackageItem pkg = repo.createPackage( "testGetBinaryPackageServlet",
"" );
DroolsHeader.updateDroolsHeader( "import java.util.List",
pkg );
pkg.updateCompiledPackage( new ByteArrayInputStream( "foo".getBytes() ) );
pkg.checkin( "" );
assertTrue( before < uploadHelper.getLastModified( pkg.getName(),
"LATEST" ) );
repoPackageService.createPackageSnapshot( pkg.getName(),
"SNAPPY 1",
false,
"" );
ByteArrayOutputStream out = new ByteArrayOutputStream();
String fileName = uploadHelper.loadBinaryPackage( pkg.getName(),
Snapshot.LATEST_SNAPSHOT,
true,
out );
assertEquals( "testGetBinaryPackageServlet.pkg",
fileName );
byte[] file = out.toByteArray();
assertNotNull( file );
assertEquals( "foo",
new String( file ) );
out = new ByteArrayOutputStream();
String drlName = uploadHelper.loadSourcePackage( pkg.getName(),
Snapshot.LATEST_SNAPSHOT,
true,
out );
String drl = new String( out.toByteArray() );
assertEquals( pkg.getName() + ".drl",
drlName );
assertNotNull( drl );
assertTrue( drl.indexOf( "import java.util.List" ) > -1 );
out = new ByteArrayOutputStream();
fileName = uploadHelper.loadBinaryPackage( pkg.getName(),
"SNAPPY 1",
false,
out );
assertEquals( "testGetBinaryPackageServlet_SNAPPY+1.pkg",
fileName );
file = out.toByteArray();
assertNotNull( file );
assertEquals( "foo",
new String( file ) );
out = new ByteArrayOutputStream();
fileName = uploadHelper.loadSourcePackage( pkg.getName(),
"SNAPPY 1",
false,
out );
assertEquals( "testGetBinaryPackageServlet_SNAPPY+1.drl",
fileName );
drl = new String( out.toByteArray() );
assertTrue( drl.indexOf( "import java.util.List" ) > -1 );
Thread.sleep( 100 );
repoPackageService.createPackageSnapshot( pkg.getName(),
"SNAPX",
false,
"" );
long lastMod = uploadHelper.getLastModified( pkg.getName(),
"SNAPPY 1" );
assertTrue( pkg.getLastModified().getTimeInMillis() < lastMod );
Thread.sleep( 100 );
repoPackageService.createPackageSnapshot( pkg.getName(),
"SNAPX",
true,
"yeah" );
long lastMod2 = uploadHelper.getLastModified( pkg.getName(),
"SNAPX" );
assertTrue( lastMod < lastMod2 );
}