Skip to content
This repository has been archived by the owner on Nov 13, 2019. It is now read-only.

Commit

Permalink
add test for RHEL version url rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
heroldus committed Nov 4, 2014
1 parent 497ffe6 commit c53ab33
Showing 1 changed file with 14 additions and 10 deletions.
Expand Up @@ -9,10 +9,13 @@
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;

import static de.is24.infrastructure.gridfs.http.utils.RepositoryUtils.uniqueRepoName;
import static de.is24.infrastructure.gridfs.http.utils.RpmUtils.RPM_FILE;
import static de.is24.infrastructure.gridfs.http.utils.RpmUtils.RPM_FILE_SIZE;
import static de.is24.infrastructure.gridfs.http.web.RepoTestUtils.uploadRpm;
import static java.lang.String.format;
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import static javax.servlet.http.HttpServletResponse.SC_OK;
Expand All @@ -25,6 +28,7 @@


public class FileControllerIT extends AbstractContainerAndMongoDBStarter {
private static final int[] RHEL_VERSION_NUMBERS = {5, 6, 7};
private String repoUrl;
private String repoName;

Expand Down Expand Up @@ -106,26 +110,26 @@ public void returnBadRequestRangeForStartGreaterEnd() throws Exception {

@Test
public void hasDownloadedWholeFile() throws Exception {
HttpGet get = new HttpGet(repoUrl + "/noarch/test-artifact-1.2-1.noarch.rpm");

HttpResponse response = httpClient.execute(get);
assertThat(response.getStatusLine().getStatusCode(), is(SC_OK));
assertThat(response.getEntity().getContentLength(), is((long) RPM_FILE_SIZE));
assertThat(response.getFirstHeader("Content-Length").getValue(), is(Integer.toString(RPM_FILE_SIZE)));
assertThat(response.getFirstHeader("Content-Type").getValue(), is("application/x-rpm"));
checkRpmDownload(repoUrl);
}

@Test
public void downloadFileWithRewriteRule() throws Exception {
String repoPrefix = deploymentURL + "/repo/" + uniqueRepoName();
uploadRpm(repoPrefix + "-rhel-6X-test", RPM_FILE.getPath());

HttpGet get = new HttpGet(repoPrefix + "-rhel-6.5-test/noarch/test-artifact-1.2-1.noarch.rpm");
for (int rhelVersionNumber : RHEL_VERSION_NUMBERS) {
uploadRpm(format("%s-rhel-%dX-test", repoPrefix, rhelVersionNumber), RPM_FILE.getPath());
checkRpmDownload(format("%s-rhel-%d-test", repoPrefix, rhelVersionNumber));
checkRpmDownload(format("%s-rhel-%d.5-test", repoPrefix, rhelVersionNumber));
}
}

public void checkRpmDownload(String repo) throws IOException {
HttpGet get = new HttpGet(repo + "/noarch/test-artifact-1.2-1.noarch.rpm");
HttpResponse response = httpClient.execute(get);
assertThat(response.getStatusLine().getStatusCode(), is(SC_OK));
assertThat(response.getEntity().getContentLength(), is((long) RPM_FILE_SIZE));
assertThat(response.getFirstHeader("Content-Length").getValue(), is(Integer.toString(RPM_FILE_SIZE)));
assertThat(response.getFirstHeader("Content-Type").getValue(), is("application/x-rpm"));
consume(response.getEntity());
}
}

0 comments on commit c53ab33

Please sign in to comment.