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" );