package de.is24.infrastructure.gridfs.http.web.controller; import de.is24.infrastructure.gridfs.http.web.boot.AbstractContainerAndMongoDBStarter; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.junit.Before; import org.junit.Test; 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.web.RepoTestUtils.uploadRpm; import static javax.servlet.http.HttpServletResponse.SC_CREATED; import static javax.servlet.http.HttpServletResponse.SC_OK; import static org.apache.http.util.EntityUtils.consume; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; public class MetadataControllerIT extends AbstractContainerAndMongoDBStarter { private String repoUrl; private String reponame; @Before public void setUp() throws Exception { reponame = uniqueRepoName(); repoUrl = deploymentURL + "/repo/" + reponame; uploadRpm(repoUrl, RPM_FILE.getPath()); } @Test public void generateMetadata() throws Exception { HttpPost post = new HttpPost(repoUrl + "/repodata"); HttpResponse response = httpClient.execute(post); consume(response.getEntity()); assertThat(response.getStatusLine().getStatusCode(), is(SC_CREATED)); downloadFile("repomd.xml"); downloadFile("repomd.xml.asc"); } private void downloadFile(String filename) throws Exception { String uri = repoUrl + "/repodata/" + filename; HttpGet get = new HttpGet(uri); HttpResponse response = httpClient.execute(get); consume(response.getEntity()); assertThat("URL: " + uri + " returned wrong status.", response.getStatusLine().getStatusCode(), is(SC_OK)); } }