use of io.fabric8.deployer.ProjectDeployer in project fabric8 by jboss-fuse.
the class ProjectDeployerTest method setUp.
@Before
public void setUp() throws Exception {
URL.setURLStreamHandlerFactory(new CustomBundleURLStreamHandlerFactory());
basedir = System.getProperty("basedir", ".");
String karafRoot = basedir + "/target/karaf";
System.setProperty("karaf.root", karafRoot);
System.setProperty("karaf.data", karafRoot + "/data");
sfb = new ZKServerFactoryBean();
delete(sfb.getDataDir());
delete(sfb.getDataLogDir());
sfb.setPort(9123);
sfb.afterPropertiesSet();
int zkPort = sfb.getClientPortAddress().getPort();
LOG.info("Connecting to ZK on port: " + zkPort);
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000);
curator = builder.build();
curator.start();
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
// setup a local and remote git repo
File root = new File(basedir + "/target/git").getCanonicalFile();
delete(root);
new File(root, "remote").mkdirs();
remote = Git.init().setDirectory(new File(root, "remote")).setGitDir(new File(root, "remote/.git")).call();
remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath();
new File(root, "local").mkdirs();
git = Git.init().setDirectory(new File(root, "local")).setGitDir(new File(root, "local/.git")).call();
git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
StoredConfig config = git.getRepository().getConfig();
config.setString("remote", "origin", "url", remoteUrl);
config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
config.save();
runtimeProperties = EasyMock.createMock(RuntimeProperties.class);
EasyMock.expect(runtimeProperties.getRuntimeIdentity()).andReturn("root").anyTimes();
EasyMock.expect(runtimeProperties.getHomePath()).andReturn(Paths.get("target")).anyTimes();
EasyMock.expect(runtimeProperties.getDataPath()).andReturn(Paths.get("target/data")).anyTimes();
EasyMock.expect(runtimeProperties.getProperty(EasyMock.eq(SystemProperties.FABRIC_ENVIRONMENT))).andReturn("").anyTimes();
EasyMock.expect(runtimeProperties.removeRuntimeAttribute(DataStoreTemplate.class)).andReturn(null).anyTimes();
EasyMock.replay(runtimeProperties);
FabricGitServiceImpl gitService = new FabricGitServiceImpl();
gitService.bindRuntimeProperties(runtimeProperties);
gitService.activate();
gitService.setGitForTesting(git);
/*
dataStore = new GitDataStoreImpl();
dataStore.bindCurator(curator);
dataStore.bindGitService(gitService);
dataStore.bindRuntimeProperties(runtimeProperties);
dataStore.bindConfigurer(new Configurer() {
@Override
public <T> Map<String, ?> configure(Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
return null;
}
@Override
public <T> Map<String, ?> configure(Dictionary<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
return null;
}
});
Map<String, Object> datastoreProperties = new HashMap<String, Object>();
datastoreProperties.put(GitDataStore.GIT_REMOTE_URL, remoteUrl);
dataStore.activate(datastoreProperties);
*/
fabricService = new FabricServiceImpl();
// fabricService.bindDataStore(dataStore);
fabricService.bindRuntimeProperties(runtimeProperties);
fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("port"));
fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("zk"));
fabricService.bindPlaceholderResolver(new ProfilePropertyPointerResolver());
fabricService.bindPlaceholderResolver(new ChecksumPlaceholderResolver());
fabricService.bindPlaceholderResolver(new VersionPropertyPointerResolver());
fabricService.bindPlaceholderResolver(new EnvPlaceholderResolver());
fabricService.activateComponent();
projectDeployer = new ProjectDeployerImpl();
projectDeployer.bindFabricService(fabricService);
projectDeployer.bindMBeanServer(ManagementFactory.getPlatformMBeanServer());
// dataStore.getDefaultVersion();
String defaultVersion = null;
assertEquals("defaultVersion", "1.0", defaultVersion);
// now lets import some data - using the old non-git file layout...
String importPath = basedir + "/../fabric8-karaf/src/main/resources/distro/fabric/import";
assertFolderExists(importPath);
dataStore.importFromFileSystem(importPath);
assertHasVersion(defaultVersion);
}
use of io.fabric8.deployer.ProjectDeployer in project fabric8 by jboss-fuse.
the class MavenProxyServletSupportTest method testUpload.
private Map<String, String> testUpload(String path, final byte[] contents, String location, String profile, String version, boolean hasLocationHeader) throws Exception {
final String old = System.getProperty("karaf.data");
System.setProperty("karaf.data", new File("target").getCanonicalPath());
FileUtils.deleteDirectory(new File("target/tmp"));
Server server = new Server(0);
server.setHandler(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
});
server.start();
try {
int localPort = ((ServerConnector) server.getConnectors()[0]).getLocalPort();
List<String> remoteRepos = Arrays.asList("http://relevant.not/maven2@id=central");
RuntimeProperties props = new MockRuntimeProperties();
MavenResolver resolver = createResolver("target/tmp", remoteRepos, "http", "localhost", localPort, "fuse", "fuse", null);
MavenUploadProxyServlet servlet = new MavenUploadProxyServlet(resolver, props, projectDeployer, new File("target/upload"), 0);
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
EasyMock.expect(request.getPathInfo()).andReturn(path);
EasyMock.expect(request.getContentType()).andReturn("text/plain").anyTimes();
EasyMock.expect(request.getInputStream()).andReturn(new ServletInputStream() {
private int i;
@Override
public int read() throws IOException {
if (i >= contents.length) {
return -1;
}
return (contents[i++] & 0xFF);
}
@Override
public boolean isReady() {
return false;
}
@Override
public boolean isFinished() {
return false;
}
@Override
public void setReadListener(ReadListener readListener) {
}
});
EasyMock.expect(request.getHeader("X-Location")).andReturn(location);
EasyMock.expect(request.getParameter("profile")).andReturn(profile);
EasyMock.expect(request.getParameter("version")).andReturn(version);
final Map<String, String> headers = new HashMap<>();
HttpServletResponse rm = EasyMock.createMock(HttpServletResponse.class);
HttpServletResponse response = new HttpServletResponseWrapper(rm) {
@Override
public void addHeader(String name, String value) {
headers.put(name, value);
}
};
response.setStatus(EasyMock.anyInt());
EasyMock.expectLastCall().anyTimes();
response.setContentLength(EasyMock.anyInt());
EasyMock.expectLastCall().anyTimes();
response.setContentType((String) EasyMock.anyObject());
EasyMock.expectLastCall().anyTimes();
response.setDateHeader((String) EasyMock.anyObject(), EasyMock.anyLong());
EasyMock.expectLastCall().anyTimes();
response.setHeader((String) EasyMock.anyObject(), (String) EasyMock.anyObject());
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(request, rm);
servlet.start();
servlet.doPut(request, response);
EasyMock.verify(request, rm);
Assert.assertEquals(hasLocationHeader, headers.containsKey("X-Location"));
return headers;
} finally {
server.stop();
if (old != null) {
System.setProperty("karaf.data", old);
}
}
}
use of io.fabric8.deployer.ProjectDeployer in project fabric8 by jboss-fuse.
the class MavenProxyServletSupportTest method testUploadWithMimeMultipartFormData.
@Test
public void testUploadWithMimeMultipartFormData() throws Exception {
new File("target/maven/proxy/tmp/multipart").mkdirs();
System.setProperty("karaf.data", new File("target").getCanonicalPath());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JarOutputStream jas = new JarOutputStream(baos);
addEntry(jas, "META-INF/MANIFEST.MF", "Manifest-Version: 1.0\n".getBytes());
addEntry(jas, "META-INF/maven/io.fabric8/mybundle/pom.properties", "groupId=io.fabric8\nartifactId=mybundle\nversion=1.0\n".getBytes());
jas.close();
byte[] jarBytes = baos.toByteArray();
RuntimeProperties props = new MockRuntimeProperties();
MavenResolver resolver = EasyMock.createMock(MavenResolver.class);
MavenUploadProxyServlet servlet = new MavenUploadProxyServlet(resolver, props, projectDeployer, new File("target/upload"), 0);
servlet.setFileItemFactory(new DiskFileItemFactory(0, new File("target/maven/proxy/tmp/multipart")));
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
FilePart part = new FilePart("file[]", new ByteArrayPartSource("mybundle-1.0.jar", jarBytes));
MultipartRequestEntity entity = new MultipartRequestEntity(new Part[] { part }, new HttpMethodParams());
final ByteArrayOutputStream requestBytes = new ByteArrayOutputStream();
entity.writeRequest(requestBytes);
final byte[] multipartRequestBytes = requestBytes.toByteArray();
EasyMock.expect(request.getPathInfo()).andReturn("/mybundle-1.0.jar");
EasyMock.expect(request.getHeader(MavenProxyServletSupport.LOCATION_HEADER)).andReturn(null);
EasyMock.expect(request.getParameter("profile")).andReturn("my");
EasyMock.expect(request.getParameter("version")).andReturn("1.0");
EasyMock.expect(request.getContentType()).andReturn(entity.getContentType()).anyTimes();
EasyMock.expect(request.getHeader("Content-length")).andReturn(Long.toString(entity.getContentLength())).anyTimes();
EasyMock.expect(request.getContentLength()).andReturn((int) entity.getContentLength()).anyTimes();
EasyMock.expect(request.getCharacterEncoding()).andReturn("ISO-8859-1").anyTimes();
Capture<String> location = EasyMock.newCapture(CaptureType.ALL);
response.setStatus(HttpServletResponse.SC_ACCEPTED);
EasyMock.expect(request.getInputStream()).andReturn(new ServletInputStream() {
private int pos = 0;
@Override
public int read() throws IOException {
return pos >= multipartRequestBytes.length ? -1 : (multipartRequestBytes[pos++] & 0xFF);
}
@Override
public boolean isFinished() {
return false;
}
@Override
public boolean isReady() {
return true;
}
@Override
public void setReadListener(ReadListener readListener) {
}
});
Capture<ProjectRequirements> requirementsCapture = EasyMock.newCapture(CaptureType.FIRST);
EasyMock.expect(projectDeployer.deployProject(EasyMock.capture(requirementsCapture), EasyMock.eq(true))).andReturn(null);
EasyMock.replay(resolver, request, response, projectDeployer);
servlet.doPut(request, response);
FileInputStream fis = new FileInputStream("target/upload/io.fabric8/mybundle/1.0/mybundle-1.0.jar");
ByteArrayOutputStream storedBundleBytes = new ByteArrayOutputStream();
IOUtils.copy(fis, storedBundleBytes);
fis.close();
Assert.assertArrayEquals(jarBytes, storedBundleBytes.toByteArray());
ProjectRequirements pr = requirementsCapture.getValue();
List<String> bundles = pr.getBundles();
assertThat(bundles.size(), equalTo(1));
assertThat(bundles.get(0), equalTo("mvn:io.fabric8/mybundle/1.0"));
assertThat(pr.getProfileId(), equalTo("my"));
assertThat(pr.getVersion(), equalTo("1.0"));
assertThat(pr.getGroupId(), nullValue());
assertThat(pr.getArtifactId(), nullValue());
EasyMock.verify(resolver, request, response, projectDeployer);
}
use of io.fabric8.deployer.ProjectDeployer in project fabric8 by jboss-fuse.
the class MavenProxyServletSupportTest method setUp.
@Before
public void setUp() {
System.out.println(">>>>>>> Running " + testname.getMethodName());
LOG.info(">>>>>>> Running " + testname.getMethodName());
Properties props = new Properties();
props.setProperty("localRepository", System.getProperty("java.io.tmpdir"));
runtimeProperties = EasyMock.createMock(RuntimeProperties.class);
projectDeployer = EasyMock.createMock(ProjectDeployer.class);
}
use of io.fabric8.deployer.ProjectDeployer in project fabric8 by jboss-fuse.
the class MavenProxyServletSupportTest method testStartServlet.
@Test(timeout = 30000)
public void testStartServlet() throws Exception {
String old = System.getProperty("karaf.data");
System.setProperty("karaf.data", new File("target").getCanonicalPath());
try {
MavenResolver resolver = createResolver();
MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtimeProperties, projectDeployer, 5, 0);
servlet.start();
} finally {
if (old != null) {
System.setProperty("karaf.data", old);
}
}
}
Aggregations