4343import org .json .simple .JSONObject ;
4444import org .json .simple .parser .JSONParser ;
4545import org .json .simple .parser .ParseException ;
46- import org .junit .Rule ;
4746import org .junit .Test ;
4847
4948import com .google .gson .JsonArray ;
5049import com .google .gson .JsonObject ;
5150import com .google .gson .JsonParser ;
52- import com .icegreen .greenmail .configuration .GreenMailConfiguration ;
53- import com .icegreen .greenmail .junit .GreenMailRule ;
54- import com .icegreen .greenmail .util .ServerSetup ;
5551
5652import eu .openanalytics .rdepot .integrationtest .IntegrationTest ;
5753import eu .openanalytics .rdepot .integrationtest .utils .JSONConverter ;
@@ -73,9 +69,7 @@ public SubmissionIntegrationTest() {
7369
7470 private final String PACKAGE_ID_TO_DOWNLOAD = "32" ;
7571 private final String PACKAGE_NAME_TO_DOWNLOAD = "Benchmarking" ;
76- private final String PDF_PATH = "src/integration-test/resources/itestPdf" ;
77-
78- private static final ServerSetup serverSetup = new ServerSetup (3925 , "0.0.0.0" , "smtp" );
72+ private final String PDF_PATH = "src/integration-test/resources/itestPdf" ;
7973
8074 @ Test
8175 public void shouldNotPublishPackageWhenRepositoryIsUnpublished () throws IOException , ParseException {
@@ -238,60 +232,60 @@ public void shouldUploadPackageAndCreateManualByDefault() throws ParseException,
238232 }
239233
240234 //TODO wait to decision about manual - if always create or only on specified conditions
241- // @Test
242- // public void shouldUploadPackageAndNotCreateManual() throws ParseException, IOException {
243- // File packageBag = new File ("src/integration-test/resources/itestPackages/Benchmarking_0.10.tar.gz");
244- //
245- // given()
246- // .header(AUTHORIZATION, BEARER + ADMIN_TOKEN)
247- // .accept("application/json")
248- // .contentType("multipart/form-data")
249- // .multiPart("repository", "testrepo2")
250- // .multiPart("generateManual", "false")
251- // .multiPart(new MultiPartSpecBuilder(Files.readAllBytes(packageBag.toPath()))
252- // .fileName(packageBag.getName())
253- // .mimeType("application/gzip")
254- // .controlName("file")
255- // .build())
256- // .when()
257- // .post(API_PACKAGES_PATH + "/submit")
258- // .then()
259- // .statusCode(200)
260- // .extract();
261- //
262- // FileReader reader = new FileReader(JSON_PATH + "/submission/repositories_after_uploading_package.json");
263- // JsonArray expectedJSON = (JsonArray) JsonParser.parseReader(reader);
264- //
265- // List<Set<JsonObject>> expectedPackages = JSONConverter.convertNewPackagesFromRepo(expectedJSON);
266- //
267- // String data = given()
268- // .header(AUTHORIZATION, BEARER + USER_TOKEN)
269- // .accept(ContentType.JSON)
270- // .when()
271- // .get(API_REPOSITORIES_PATH + "/list")
272- // .then()
273- // .statusCode(200)
274- // .extract()
275- // .asString();
276- //
277- // JsonArray actualJSON = (JsonArray) JsonParser.parseString(data);
278- //
279- // List<Set<JsonObject>> actualPackages = JSONConverter.convertNewPackagesFromRepo(actualJSON);
280- //
281- // given()
282- // .header(AUTHORIZATION, BEARER + ADMIN_TOKEN)
283- // .accept(ContentType.ANY)
284- //
285- // .when()
286- // .get(API_PACKAGES_PATH + "/" + PACKAGE_ID_TO_DOWNLOAD + "/download/" + PACKAGE_NAME_TO_DOWNLOAD + ".pdf")
287- // .then()
288- // .statusCode(404)
289- // .extract()
290- // .asByteArray();
291- //
292- // assertEquals("expected packages: " + expectedPackages + " but was: " + actualPackages, expectedPackages, actualPackages);
293- // assertTrue("expected json: " + expectedJSON + "but was: " + actualJSON, compare(expectedJSON, actualJSON));
294- // }
235+ @ Test
236+ public void shouldUploadPackageAndNotCreateManual () throws ParseException , IOException {
237+ File packageBag = new File ("src/integration-test/resources/itestPackages/Benchmarking_0.10.tar.gz" );
238+
239+ given ()
240+ .header (AUTHORIZATION , BEARER + ADMIN_TOKEN )
241+ .accept ("application/json" )
242+ .contentType ("multipart/form-data" )
243+ .multiPart ("repository" , "testrepo2" )
244+ .multiPart ("generateManual" , "false" )
245+ .multiPart (new MultiPartSpecBuilder (Files .readAllBytes (packageBag .toPath ()))
246+ .fileName (packageBag .getName ())
247+ .mimeType ("application/gzip" )
248+ .controlName ("file" )
249+ .build ())
250+ .when ()
251+ .post (API_PACKAGES_PATH + "/submit" )
252+ .then ()
253+ .statusCode (200 )
254+ .extract ();
255+
256+ FileReader reader = new FileReader (JSON_PATH + "/submission/repositories_after_uploading_package.json" );
257+ JsonArray expectedJSON = (JsonArray ) JsonParser .parseReader (reader );
258+
259+ List <Set <JsonObject >> expectedPackages = JSONConverter .convertNewPackagesFromRepo (expectedJSON );
260+
261+ String data = given ()
262+ .header (AUTHORIZATION , BEARER + USER_TOKEN )
263+ .accept (ContentType .JSON )
264+ .when ()
265+ .get (API_REPOSITORIES_PATH + "/list" )
266+ .then ()
267+ .statusCode (200 )
268+ .extract ()
269+ .asString ();
270+
271+ JsonArray actualJSON = (JsonArray ) JsonParser .parseString (data );
272+
273+ List <Set <JsonObject >> actualPackages = JSONConverter .convertNewPackagesFromRepo (actualJSON );
274+
275+ given ()
276+ .header (AUTHORIZATION , BEARER + ADMIN_TOKEN )
277+ .accept (ContentType .ANY )
278+
279+ .when ()
280+ .get (API_PACKAGES_PATH + "/" + PACKAGE_ID_TO_DOWNLOAD + "/download/" + PACKAGE_NAME_TO_DOWNLOAD + ".pdf" )
281+ .then ()
282+ .statusCode (404 )
283+ .extract ()
284+ .asByteArray ();
285+
286+ assertEquals ("expected packages: " + expectedPackages + " but was: " + actualPackages , expectedPackages , actualPackages );
287+ assertTrue ("expected json: " + expectedJSON + "but was: " + actualJSON , compare (expectedJSON , actualJSON ));
288+ }
295289
296290 @ Test
297291 public void shouldUploadPackageWithReplaceOption () throws IOException , ParseException {
0 commit comments