forked from IQSS/dataverse
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds initial arquillian integration testing support
- Loading branch information
Showing
7 changed files
with
338 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
src/test/java/edu/harvard/iq/dataverse/batch/launcher/ImportLauncherIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package edu.harvard.iq.dataverse.batch.launcher; | ||
|
||
|
||
import com.jayway.restassured.http.ContentType; | ||
import com.jayway.restassured.path.json.JsonPath; | ||
import com.jayway.restassured.response.Response; | ||
import edu.harvard.iq.dataverse.api.UtilIT; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.importer.ZipImporter; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.*; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.logging.Logger; | ||
|
||
import static com.jayway.restassured.RestAssured.given; | ||
import static com.jayway.restassured.RestAssured.with; | ||
import static junit.framework.Assert.assertEquals; | ||
|
||
/** | ||
* Created by bmckinney on 3/30/16. | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class ImportLauncherIT { | ||
|
||
private static final Logger logger = Logger.getLogger(ImportLauncherIT.class.getCanonicalName()); | ||
|
||
private static final String PRIVILEGED_USER = "src/test/resources/json/user-privileged.json"; | ||
private static final String GUEST_USER = "src/test/resources/json/user-guest.json"; | ||
private static final String TEST_DATAVERSE = "src/test/resources/json/complete-dataverse.json"; | ||
private static final String TEST_DATASET = "src/test/resources/json/test-dataset.json"; | ||
|
||
private static final String BUILT_IN_USER_KEY = "burrito"; | ||
private static final String USERNAME_KEY = "userName"; | ||
private static final String API_TOKEN_HTTP_HEADER = "X-Dataverse-key"; | ||
|
||
private String dsid; | ||
private String dvAlias; | ||
private String privilegedUserToken; | ||
private String privilegedUserName; | ||
private String guestUserName; | ||
|
||
@Deployment | ||
public static WebArchive createDeployment() { | ||
|
||
WebArchive war = ShrinkWrap.create(ZipImporter.class, "test-dataverse.war") | ||
.importFrom(new File("target/dataverse-4.2.4.war")) | ||
.as(WebArchive.class); | ||
war.delete("WEB-INF/classes/META-INF/persistence.xml"); | ||
war.addAsResource(new File("src/test/resources/glassfish/test-persistence.xml"), "META-INF/persistence.xml"); | ||
return war; | ||
|
||
} | ||
|
||
@Before | ||
public void before() throws Exception{ | ||
|
||
Response response; | ||
|
||
// BuiltinUsers.KEY | ||
response = given().body(BUILT_IN_USER_KEY).put("api/admin/settings/:BuiltinUsers.KEY"); | ||
response.prettyPrint(); | ||
|
||
// SUPER USER | ||
response = given() | ||
.body(new String(Files.readAllBytes(Paths.get(PRIVILEGED_USER)))) | ||
.contentType(ContentType.JSON) | ||
.post("/api/builtin-users?key=" + BUILT_IN_USER_KEY); | ||
response.prettyPrint(); | ||
privilegedUserName = JsonPath.from(response.asString()).getString("data.user.userName"); | ||
privilegedUserToken = JsonPath.from(response.asString()).getString("data.apiToken"); | ||
Response superUser = given().post("/api/admin/superuser/pete"); | ||
superUser.prettyPrint(); | ||
|
||
// DATAVERSE | ||
response = given() | ||
.body(Files.readAllBytes(Paths.get(TEST_DATAVERSE))) | ||
.contentType(ContentType.JSON) | ||
.when().post("/api/dataverses/:root?key=" + privilegedUserToken); | ||
response.prettyPrint(); | ||
String dataverseId = JsonPath.from(response.asString()).getString("data.id"); | ||
dvAlias = JsonPath.from(response.asString()).getString("data.alias"); | ||
|
||
// DATASET | ||
response = given() | ||
.header(API_TOKEN_HTTP_HEADER, privilegedUserToken) | ||
.body(Files.readAllBytes(Paths.get(TEST_DATASET))) | ||
.contentType("application/json") | ||
.post("/api/dataverses/" + dvAlias + "/datasets"); | ||
response.prettyPrint(); | ||
dsid = JsonPath.from(response.asString()).getString("data.id"); | ||
|
||
// GUEST USER | ||
response = given() | ||
.body(new String(Files.readAllBytes(Paths.get(GUEST_USER)))) | ||
.contentType(ContentType.JSON) | ||
.post("/api/builtin-users?key=" + BUILT_IN_USER_KEY); | ||
response.prettyPrint(); | ||
guestUserName = JsonPath.from(response.asString()).getString("data.user.userName"); | ||
|
||
} | ||
|
||
@After | ||
public void after() { | ||
|
||
Response resp; | ||
|
||
resp = given().delete("/api/datasets/" + dsid + "?key=" + privilegedUserToken ); | ||
resp.prettyPrint(); | ||
|
||
resp = given().delete("/api/dataverses/" + dvAlias + "?key=" + privilegedUserToken); | ||
resp.prettyPrint(); | ||
|
||
resp = given().delete("/api/admin/authenticatedUsers/" + privilegedUserName + "/"); | ||
resp.prettyPrint(); | ||
|
||
resp = given().delete("/api/admin/authenticatedUsers/" + guestUserName + "/"); | ||
resp.prettyPrint(); | ||
|
||
} | ||
|
||
@RunAsClient | ||
@Test | ||
public void should_return_execution_id() { | ||
ImportLauncher importLauncher = new ImportLauncher(); | ||
//javax.ws.rs.core.Response response = importLauncher.getFilesystemImport("doi:10.5072/FK2/NSMTIE","12345678"); | ||
//System.out.println(response.getStatus()); | ||
//System.out.println("Response: " + response.toString()); | ||
|
||
//Assert.fail("Not yet implemented."); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<arquillian xmlns="http://jboss.org/schema/arquillian" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation=" | ||
http://jboss.org/schema/arquillian | ||
http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> | ||
<engine> | ||
<property name="deploymentExportPath">target/deployments</property> | ||
</engine> | ||
<extension qualifier="webdriver"> | ||
<property name="browser">chrome</property> | ||
</extension> | ||
<container qualifier="glassfish" default="true"> | ||
<configuration> | ||
<property name="glassFishHome">/usr/local/glassfish4</property> | ||
<property name="adminHost">localhost</property> | ||
<property name="adminPort">4848</property> | ||
<property name="adminUser">admin</property> | ||
<property name="adminPassword"></property> | ||
<property name="outputToConsole">true</property> | ||
<property name="allowConnectingToRunningServer">true</property> | ||
</configuration> | ||
</container> | ||
</arquillian> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> | ||
<persistence-unit name="VDCNet-ejbPU" transaction-type="JTA"> | ||
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> | ||
<jta-data-source>jdbc/VDCNetDS</jta-data-source> | ||
<properties> | ||
<property name="eclipselink.ddl-generation" value="none"/> | ||
<property name="eclipselink.logging.level.sql" value="FINE"/> | ||
<property name="eclipselink.logging.parameters" value="true"/> | ||
<property name="eclipselink.cache.shared.default" value="false"/> | ||
<property name="eclipselink.id-validation" value="NULL"/> | ||
</properties> | ||
</persistence-unit> | ||
</persistence> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"datasetVersion": { | ||
"metadataBlocks": { | ||
"citation": { | ||
"fields": [ | ||
{ | ||
"value": "Darwin's Finches", | ||
"typeClass": "primitive", | ||
"multiple": false, | ||
"typeName": "title" | ||
}, | ||
{ | ||
"value": [ | ||
{ | ||
"authorName": { | ||
"value": "Finch, Fiona", | ||
"typeClass": "primitive", | ||
"multiple": false, | ||
"typeName": "authorName" | ||
}, | ||
"authorAffiliation": { | ||
"value": "Birds Inc.", | ||
"typeClass": "primitive", | ||
"multiple": false, | ||
"typeName": "authorAffiliation" | ||
} | ||
} | ||
], | ||
"typeClass": "compound", | ||
"multiple": true, | ||
"typeName": "author" | ||
}, | ||
{ | ||
"value": [ | ||
{ "datasetContactEmail" : { | ||
"typeClass": "primitive", | ||
"multiple": false, | ||
"typeName": "datasetContactEmail", | ||
"value" : "finch@mailinator.com" | ||
} | ||
}], | ||
"typeClass": "compound", | ||
"multiple": true, | ||
"typeName": "datasetContact" | ||
}, | ||
{ | ||
"value": [ { | ||
"dsDescriptionValue":{ | ||
"value": "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds.", | ||
"multiple":false, | ||
"typeClass": "primitive", | ||
"typeName": "dsDescriptionValue" | ||
}}], | ||
"typeClass": "compound", | ||
"multiple": true, | ||
"typeName": "dsDescription" | ||
}, | ||
{ | ||
"value": [ | ||
"Medicine, Health and Life Sciences" | ||
], | ||
"typeClass": "controlledVocabulary", | ||
"multiple": true, | ||
"typeName": "subject" | ||
} | ||
], | ||
"displayName": "Citation Metadata" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"firstName":"Gabbi", | ||
"lastName":"Guest", | ||
"userName":"gabbi", | ||
"affiliation":"low", | ||
"position":"A Guest", | ||
"email":"gabbi@malinator.com", | ||
"phone":"(888) 888-8888" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"firstName":"Pete", | ||
"lastName":"Privileged", | ||
"userName":"pete", | ||
"affiliation":"Top", | ||
"position":"The Boss", | ||
"email":"pete@malinator.com", | ||
"phone":"(888) 888-8888" | ||
} |