//At this points should not be here anymore
foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
assertTrue( foundBundles == null || foundBundles.isEmpty() );
//Get the audit records related to this bundle
PublishAuditStatus status = PublishAuditAPI.getInstance().getPublishAuditStatus( bundleId );
//We will be able to retry failed and successfully bundles
assertEquals( status.getStatus(), PublishAuditStatus.Status.FAILED_TO_PUBLISH ); //Remember, we are expecting this to fail
//Get current status dates
Date initialCreationDate = status.getCreateDate();
Date initialUpdateDate = status.getStatusUpdated();
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++RETRY++++++++++++++++++++++++++++++
//Now we can try the retry
req = ServletTestRunner.localRequest.get();
baseURL = "http://" + req.getServerName() + ":" + req.getServerPort() + "/DotAjaxDirector/com.dotcms.publisher.ajax.RemotePublishAjaxAction/cmd/retry/u/admin@dotcms.com/p/admin";
completeURL = baseURL + "?bundlesIds=" + UtilMethods.encodeURIComponent( bundleId );
//Execute the call
URL retryUrl = new URL( completeURL );
response = IOUtils.toString( retryUrl.openStream(), "UTF-8" );//We can expect something like "Bundle id: <strong>1193e3eb-3ccd-496e-8995-29a9fcc48cbd</strong> added successfully to Publishing Queue."
//Validations
assertNotNull( response );
assertTrue( response.contains( bundleId ) );
assertTrue( response.contains( "added successfully to" ) );
//And should be back to the queue job
foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
assertNotNull( foundBundles );
assertTrue( !foundBundles.isEmpty() );
//Get current status dates
status = PublishAuditAPI.getInstance().getPublishAuditStatus( bundleId );//Get the audit records related to this bundle
Date latestCreationDate = status.getCreateDate();
Date latestUpdateDate = status.getStatusUpdated();
//Validations
assertNotSame( initialCreationDate, latestCreationDate );
assertNotSame( initialUpdateDate, latestUpdateDate );
assertTrue( initialCreationDate.before( latestCreationDate ) );
assertTrue( initialUpdateDate.before( latestUpdateDate ) );
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++SIMULATE AN END POINT++++++++++++++++++++++++
/*
And finally lets try to simulate a end point sending directly an already created bundle file to
the api/bundlePublisher/publish service
*/
//Create a receiving end point
PublishingEndPoint receivingFromEndpoint = new PublishingEndPoint();
receivingFromEndpoint.setServerName( new StringBuilder( "TestReceivingEndPoint" + String.valueOf( new Date().getTime() ) ) );
receivingFromEndpoint.setAddress( req.getServerName() );
receivingFromEndpoint.setPort( String.valueOf( req.getServerPort() ) );
receivingFromEndpoint.setProtocol( "http" );
receivingFromEndpoint.setAuthKey( new StringBuilder( PublicEncryptionFactory.encryptString( "1111" ) ) );
receivingFromEndpoint.setEnabled( true );
receivingFromEndpoint.setSending( true );//TODO: Shouldn't this be false as we are creating this end point to receive bundles from another server..?
receivingFromEndpoint.setGroupId( environment.getId() );
//Save the endpoint.
publisherEndPointAPI.saveEndPoint( receivingFromEndpoint );
//Find the bundle
Bundle bundle = APILocator.getBundleAPI().getBundleById( bundleId );
PublisherConfig basicConfig = new PublisherConfig();
basicConfig.setId( bundleId );
File bundleRoot = BundlerUtil.getBundleRoot( basicConfig );
File bundleFile = new File( bundleRoot + File.separator + ".." + File.separator + bundle.getId() + ".tar.gz" );
//lets wait one minute
Thread.sleep( 60000 );
assertTrue( bundleFile.exists() );
//Rename the bundle file
String newBundleId = UUID.randomUUID().toString();
File newBundleFile = new File( bundleRoot + File.separator + ".." + File.separator + newBundleId + ".tar.gz" );
Boolean success = bundleFile.renameTo( newBundleFile );
assertTrue( success );
assertTrue( newBundleFile.exists() );
//Prepare the post request
ClientConfig cc = new DefaultClientConfig();
Client client = Client.create( cc );
FormDataMultiPart form = new FormDataMultiPart();
form.field( "AUTH_TOKEN", PublicEncryptionFactory.encryptString( (PublicEncryptionFactory.decryptString( receivingFromEndpoint.getAuthKey().toString() )) ) );
form.field( "GROUP_ID", UtilMethods.isSet( receivingFromEndpoint.getGroupId() ) ? receivingFromEndpoint.getGroupId() : receivingFromEndpoint.getId() );
form.field( "BUNDLE_NAME", bundle.getName() );
form.field( "ENDPOINT_ID", receivingFromEndpoint.getId() );
form.bodyPart( new FileDataBodyPart( "bundle", newBundleFile, MediaType.MULTIPART_FORM_DATA_TYPE ) );
//Sending bundle to endpoint
WebResource resource = client.resource( receivingFromEndpoint.toURL() + "/api/bundlePublisher/publish" );
ClientResponse clientResponse = resource.type( MediaType.MULTIPART_FORM_DATA ).post( ClientResponse.class, form );
//Validations
assertEquals( clientResponse.getClientResponseStatus().getStatusCode(), HttpStatus.SC_OK );
//Get current status dates
status = PublishAuditAPI.getInstance().getPublishAuditStatus( newBundleId );//Get the audit records related to this new bundle
Date finalCreationDate = status.getCreateDate();
Date finalUpdateDate = status.getStatusUpdated();
//Validations
assertNotSame( latestCreationDate.getTime(), finalCreationDate.getTime() );
assertNotSame( latestUpdateDate.getTime(), finalUpdateDate.getTime() );
}