Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
/*
*
/** <pre>
Copyright 2016 ResearchSpace

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</pre>
*/
package com.researchspace.dataverse.http;

import static org.junit.Assert.assertTrue;

import java.net.URL;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
Expand All @@ -26,75 +36,58 @@
import com.researchspace.dataverse.spring.config.DataverseSpringConfig;

import lombok.extern.slf4j.Slf4j;
/** <pre>
Copyright 2016 ResearchSpace

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</pre>
*/
/**
* Integration tests.
*/
@TestPropertySource(locations = "classpath:/test.properties")
@ContextConfiguration(classes = { DataverseSpringConfig.class })
@Slf4j
public class AbstractIntegrationTest extends AbstractJUnit4SpringContextTests {

DatasetOperations datasetOps;
DataverseOperations dataverseOps;
MetadataOperations metadataOPs;
InfoOperations infoOps;
SearchOperations searchOps;
@Autowired
DataverseAPI dataverseAPI;
@Value("#{systemProperties['dataverseAlias']}")
protected String dataverseAlias;
@Value("#{systemProperties['dataverseApiKey']}")
protected String apiKey;
@Value("#{systemProperties['dataverseServerURL']}")
protected String serverURL;

// defaults from test.properties
@Value("${dataverseAlias}")
protected String dataverseAliasdefault;
@Value("${dataverseServerURL}")
protected String serverURLDevault;
DatasetOperations datasetOps;
DataverseOperations dataverseOps;
MetadataOperations metadataOPs;
InfoOperations infoOps;
SearchOperations searchOps;
@Autowired
DataverseAPI dataverseAPI;
@Value("#{systemProperties['dataverseAlias']}")
protected String dataverseAlias;
@Value("#{systemProperties['dataverseApiKey']}")
protected String apiKey;
@Value("#{systemProperties['dataverseServerURL']}")
protected String serverURL;

protected static final String ERROR_MSG = "ERROR";
// defaults from test.properties
@Value("${dataverseAlias}")
protected String dataverseAliasdefault;
@Value("${dataverseServerURL}")
protected String serverURLDevault;

public void setUp() throws Exception {
validateServerCredentials();
log.info("serverURL: [{}], apiKey: [{}], dataverseId=[{}]", serverURL, apiKey, dataverseAlias);
URL uri = new URL(serverURL);
DataverseConfig cfg = new DataverseConfig(uri, apiKey, dataverseAlias);
dataverseAPI.configure(cfg);
datasetOps = dataverseAPI.getDatasetOperations();
dataverseOps = dataverseAPI.getDataverseOperations();
metadataOPs = dataverseAPI.getMetadataOperations();
infoOps = dataverseAPI.getInfoOperations();
searchOps = dataverseAPI.getSearchOperations();
}
protected static final String ERROR_MSG = "ERROR";

private void validateServerCredentials() {
Validate.notEmpty(apiKey, "ApiKey must be set via command line -DdataverseApiKey option");
dataverseAlias = (StringUtils.isEmpty(dataverseAlias)) ? dataverseAliasdefault : dataverseAlias;
serverURL = (StringUtils.isEmpty(serverURL)) ? serverURLDevault : serverURL;
Validate.notEmpty(dataverseAlias,
"Dataverse alias must be set via command line -DdataverseAlias option or in test.properties");
Validate.notEmpty(serverURL,
"Dataverse server URL must be set via command line -DdataverseServerURL option or in test.properties)");
}
public void setUp() throws Exception {
validateServerCredentials();
log.info("serverURL: [{}], apiKey: [{}], dataverseId=[{}]", serverURL, apiKey, dataverseAlias);
final URL uri = new URL(serverURL);
final DataverseConfig cfg = new DataverseConfig(uri, apiKey, dataverseAlias);
dataverseAPI.configure(cfg);
datasetOps = dataverseAPI.getDatasetOperations();
dataverseOps = dataverseAPI.getDataverseOperations();
metadataOPs = dataverseAPI.getMetadataOperations();
infoOps = dataverseAPI.getInfoOperations();
searchOps = dataverseAPI.getSearchOperations();
}

@Test
public void test() {
assertTrue(1 == 1);// stop complaints about no methods
}
private void validateServerCredentials() {
Validate.notEmpty(apiKey, "ApiKey must be set via command line -DdataverseApiKey option");
dataverseAlias = StringUtils.isEmpty(dataverseAlias) ? dataverseAliasdefault : dataverseAlias;
serverURL = StringUtils.isEmpty(serverURL) ? serverURLDevault : serverURL;
Validate.notEmpty(dataverseAlias,
"Dataverse alias must be set via command line -DdataverseAlias option or in test.properties");
Validate.notEmpty(serverURL,
"Dataverse server URL must be set via command line -DdataverseServerURL option or in test.properties)");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
/*
*
/** <pre>
Copyright 2016 ResearchSpace

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</pre>
*/
package com.researchspace.dataverse.http;

Expand All @@ -12,13 +25,11 @@
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import com.researchspace.dataverse.entities.Dataset;
Expand All @@ -31,79 +42,63 @@
import com.researchspace.dataverse.entities.Version;
import com.researchspace.dataverse.entities.facade.DatasetFacade;


/** <pre>
Copyright 2016 ResearchSpace

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</pre>
*/

/**
* Dataset operations tests.
*/
public class DatasetOperationsTest extends AbstractIntegrationTest {

@Before
public void setup() throws Exception {
super.setUp();
}

File exampleDatasetJson = new File("src/integration-test/resources/dataset-create-new-all-default-fields.json");
@Test
public void testListDatasets() {
List<DataverseObject> results = dataverseOps.getDataverseContents(dataverseAlias);
assertTrue(results.size() > 0);

}

@Test
public void testPostSampleDataset() throws IOException, InterruptedException, URISyntaxException {
String toPost = FileUtils.readFileToString(exampleDatasetJson);
Identifier datasetId = dataverseOps.createDataset(toPost, dataverseAlias);
assertNotNull(datasetId.getId());

}

@Test
public void testPostGetDeleteDataset() throws IOException, InterruptedException, URISyntaxException {
DatasetFacade facade = createFacade();
//create a new, unpublished Dataverse
String newAlias = RandomStringUtils.randomAlphabetic(10);
DataversePost toCreate = DataverseOperationsTest.createADataverse(newAlias);
DataversePost newDV = dataverseOps.createNewDataverse(dataverseAlias, toCreate).getData();

// create Dataset in child dataverse
Identifier datasetId = dataverseOps.createDataset(facade, newDV.getAlias());
assertNotNull(datasetId.getId());
Dataset ds = datasetOps.getDataset(datasetId);
String doiId = ds.getDoiId().get();
datasetOps.uploadFile(doiId, getTestFile());

//publishing will fail, as parent DV is not published
DataverseResponse<PublishedDataset> response = datasetOps.publishDataset (datasetId, Version.MAJOR);
assertNull(response.getData());
assertNotNull(response.getMessage());

facade.setTitle("Updated title2");
datasetOps.updateDataset(facade, datasetId);
List<DatasetVersion> versions = datasetOps.getDatasetVersions(datasetId);
assertEquals(1, versions.size()); // published and draft
assertEquals("DRAFT", versions.get(0).getVersionState());
String msg = datasetOps.deleteDataset(datasetId).getMessage();
dataverseOps.deleteDataverse(newAlias);
assertNotNull(msg);

}

private File getTestFile() {
return new File("src/integration-test/resources/ResizablePng.zip");
}

@Before
public void setup() throws Exception {
super.setUp();
}

File exampleDatasetJson = new File("src/integration-test/resources/dataset-create-new-all-default-fields.json");
@Test
public void testListDatasets() {
final List<DataverseObject> results = dataverseOps.getDataverseContents(dataverseAlias);
assertTrue(results.size() > 0);
}

@Test
public void testPostSampleDataset() throws IOException, InterruptedException, URISyntaxException {
final String toPost = FileUtils.readFileToString(exampleDatasetJson);
final Identifier datasetId = dataverseOps.createDataset(toPost, dataverseAlias);
assertNotNull(datasetId.getId());

}

@Test
public void testPostGetDeleteDataset() throws IOException, InterruptedException, URISyntaxException {
final DatasetFacade facade = createFacade();
//create a new, unpublished Dataverse
final String newAlias = RandomStringUtils.randomAlphabetic(10);
final DataversePost toCreate = DataverseOperationsTest.createADataverse(newAlias);
final DataversePost newDV = dataverseOps.createNewDataverse(dataverseAlias, toCreate).getData();

// create Dataset in child dataverse
final Identifier datasetId = dataverseOps.createDataset(facade, newDV.getAlias());
assertNotNull(datasetId.getId());
final Dataset ds = datasetOps.getDataset(datasetId);
final String doiId = ds.getDoiId().get();
datasetOps.uploadFile(doiId, getTestFile());

//publishing will fail, as parent DV is not published
final DataverseResponse<PublishedDataset> response = datasetOps.publishDataset (datasetId, Version.MAJOR);
assertNull(response.getData());
assertNotNull(response.getMessage());

facade.setTitle("Updated title2");
datasetOps.updateDataset(facade, datasetId);
final List<DatasetVersion> versions = datasetOps.getDatasetVersions(datasetId);
assertEquals(1, versions.size()); // published and draft
assertEquals("DRAFT", versions.get(0).getVersionState());
final String msg = datasetOps.deleteDataset(datasetId).getMessage();
dataverseOps.deleteDataverse(newAlias);
assertNotNull(msg);

}

private File getTestFile() {
return new File("src/integration-test/resources/ResizablePng.zip");
}
}
Loading