use of com.thoughtworks.go.util.URLService in project gocd by gocd.
the class AgentUpgradeServiceTest method setUp.
@Before
public void setUp() throws Exception {
systemEnvironment = mock(SystemEnvironment.class);
urlService = mock(URLService.class);
GoAgentServerHttpClient httpClient = mock(GoAgentServerHttpClient.class);
jvmExitter = mock(AgentUpgradeService.JvmExitter.class);
agentUpgradeService = spy(new AgentUpgradeService(urlService, httpClient, systemEnvironment, jvmExitter));
httpMethod = mock(HttpGet.class);
doReturn(httpMethod).when(agentUpgradeService).getAgentLatestStatusGetMethod();
closeableHttpResponse = mock(CloseableHttpResponse.class);
when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
when(httpClient.execute(httpMethod)).thenReturn(closeableHttpResponse);
}
use of com.thoughtworks.go.util.URLService in project gocd by gocd.
the class DownloadFileCommandExecutor method execute.
@Override
public boolean execute(BuildCommand command, BuildSession buildSession) {
URLService urlService = new URLService();
String url = urlService.prefixPartialUrl(command.getStringArg("url"));
String dest = command.getStringArg("dest");
String src = command.getStringArg("src");
File artifact = buildSession.resolveRelativeDir(command.getWorkingDirectory(), dest);
FileHandler handler = new FileHandler(artifact, src);
String checksumUrl = null;
ChecksumFileHandler checksumFileHandler = null;
if (command.hasArg("checksumUrl")) {
checksumUrl = new URLService().prefixPartialUrl(command.getStringArg("checksumUrl"));
File checksumFile;
if (command.hasArg("checksumFile")) {
checksumFile = buildSession.resolveRelativeDir(command.getWorkingDirectory(), command.getStringArg("checksumFile"));
} else {
checksumFile = TempFiles.createUniqueFile("checksum");
}
checksumFileHandler = new ChecksumFileHandler(checksumFile);
}
boolean fileExist = artifact.exists();
if (LOG.isDebugEnabled()) {
LOG.debug("Requesting the file [" + artifact.getAbsolutePath() + "], exist? [" + fileExist + "]");
}
if (fileExist && artifact.isFile()) {
try {
url += "?sha1=" + java.net.URLEncoder.encode(StringUtil.sha1Digest(artifact), "UTF-8");
} catch (UnsupportedEncodingException e) {
LOG.error("Download error", e);
return false;
}
}
buildSession.download(handler, url, checksumFileHandler, checksumUrl);
return true;
}
use of com.thoughtworks.go.util.URLService in project gocd by gocd.
the class FetchArtifactBuilderTest method setUp.
@Before
public void setUp() throws Exception {
File folder = TestFileUtil.createTempFolder("log");
File consolelog = new File(folder, "console.log");
folder.mkdirs();
consolelog.createNewFile();
zip = new ZipUtil().zip(folder, TestFileUtil.createUniqueTempFile(folder.getName()), Deflater.NO_COMPRESSION);
toClean.add(folder);
toClean.add(zip);
dest = new File("dest");
dest.mkdirs();
toClean.add(dest);
clock = new TestingClock();
publisher = new StubGoPublisher();
checksumFileHandler = mock(ChecksumFileHandler.class);
urlService = mock(URLService.class);
downloadAction = mock(DownloadAction.class);
}
use of com.thoughtworks.go.util.URLService in project gocd by gocd.
the class DownloadDirCommandExecutor method execute.
@Override
public boolean execute(BuildCommand command, BuildSession buildSession) {
URLService urlService = new URLService();
String url = urlService.prefixPartialUrl(command.getStringArg("url"));
String dest = command.getStringArg("dest");
String src = command.getStringArg("src");
String checksumUrl = null;
ChecksumFileHandler checksumFileHandler = null;
if (command.hasArg("checksumUrl")) {
checksumUrl = new URLService().prefixPartialUrl(command.getStringArg("checksumUrl"));
File checksumFile;
if (command.hasArg("checksumFile")) {
checksumFile = buildSession.resolveRelativeDir(command.getWorkingDirectory(), command.getStringArg("checksumFile"));
} else {
checksumFile = TempFiles.createUniqueFile("checksum");
}
checksumFileHandler = new ChecksumFileHandler(checksumFile);
}
DirHandler handler = new DirHandler(src, buildSession.resolveRelativeDir(command.getWorkingDirectory(), dest));
buildSession.download(handler, url, checksumFileHandler, checksumUrl);
return true;
}
use of com.thoughtworks.go.util.URLService in project gocd by gocd.
the class BuildWorkArtifactUploadingTest method shouldReportUploadFailuresWhenTheyHappen.
@Test
public void shouldReportUploadFailuresWhenTheyHappen() throws Exception {
ArtifactPlans artifactPlans = new ArtifactPlans();
artifactPlans.add(new ArtifactPlan("**/*.png", "mypic"));
BuildAssignment buildAssigment = createAssignment(artifactPlans, new String[] { "logs/pic/pass.png", "logs/pic-1/pass.png" });
BuildWork work = new BuildWork(buildAssigment);
GoArtifactsManipulatorStub manipulator = new GoArtifactsManipulatorStub(new ArrayList<>(), new ArrayList<>(), new HttpServiceStub(), new URLService(), new ZipUtilThatRunsOutOfMemory());
AgentIdentifier agentIdentifier = new AgentIdentifier("somename", "127.0.0.1", AGENT_UUID);
work.doWork(agentIdentifier, new FakeBuildRepositoryRemote(), manipulator, environmentVariableContext, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension);
List<UploadEntry> entries = manipulator.uploadEntries();
assertThat(entries.isEmpty(), is(true));
assertThat(manipulator.consoleOut(), containsString("Failed to upload [**/*.png]"));
}
Aggregations