use of org.apache.http.nio.entity.NFileEntity in project fabric8 by jboss-fuse.
the class FabricMavenProxyTest method testUpload.
@Test
public void testUpload() throws Exception {
String featureLocation = System.getProperty("feature.location");
System.out.println("Testing with feature from:" + featureLocation);
System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
// System.out.println(executeCommand("shell:info"));
// System.out.println(executeCommand("fabric:info"));
// System.out.println(executeCommand("fabric:profile-list"));
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
try {
Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 2).withName("maven").withProfiles("fabric").waitForProvisioning(10 * 60 * 1000L).assertProvisioningResult().build();
try {
List<String> uploadUrls = new ArrayList<String>();
ServiceProxy<CuratorFramework> curatorProxy = ServiceProxy.createServiceProxy(bundleContext, CuratorFramework.class);
try {
CuratorFramework curator = curatorProxy.getService();
List<String> children = ZooKeeperUtils.getChildren(curator, ZkPath.MAVEN_PROXY.getPath("upload"));
for (String child : children) {
String uploadeUrl = ZooKeeperUtils.getSubstitutedPath(curator, ZkPath.MAVEN_PROXY.getPath("upload") + "/" + child);
uploadUrls.add(uploadeUrl);
}
} finally {
curatorProxy.close();
}
// Pick a random maven proxy from the list.
Random random = new Random();
int index = random.nextInt(uploadUrls.size());
String targetUrl = uploadUrls.get(index);
String uploadUrl = targetUrl + "itest/itest/1.0/itest-1.0-features.xml";
System.out.println("Using URI: " + uploadUrl);
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "admin"));
CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
HttpPut put = new HttpPut(uploadUrl);
NFileEntity entity = new NFileEntity(new File(featureLocation), ContentType.TEXT_XML);
put.setEntity(entity);
HttpResponse response = client.execute(put);
System.out.println("Response:" + response.getStatusLine());
Assert.assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 202);
System.out.println(executeCommand("fabric:profile-edit --repository mvn:itest/itest/1.0/xml/features default"));
System.out.println(executeCommand("fabric:profile-edit --feature example-cbr default"));
Provision.containerStatus(containers, PROVISION_TIMEOUT);
} finally {
ContainerBuilder.destroy(containers);
}
} finally {
fabricProxy.close();
}
}
Aggregations