Skip to content
Snippets Groups Projects
Commit 33c7a21f authored by pkupczyk's avatar pkupczyk
Browse files

SSDM-137 : V3 AS API - fully cover existing functionality with system tests -...

SSDM-137 : V3 AS API - fully cover existing functionality with system tests - create js-test for V3 API

SVN: 32183
parent 35f5a6f6
No related branches found
No related tags found
No related merge requests found
Showing
with 223 additions and 590 deletions
......@@ -161,6 +161,50 @@ var createExperimentFetchOptions = function() {
}
}
var createSampleFetchOptions = function() {
return {
"@type" : "SampleFetchOptions",
"sampleType" : {
"@type" : "SampleTypeFetchOptions"
},
"experiment" : {
"@type" : "ExperimentFetchOptions",
"project" : {
"@type" : "ProjectFetchOptions",
"space" : {
"@type" : "SpaceFetchOptions"
}
}
},
"space" : {
"@type" : "SpaceFetchOptions"
},
"properties" : {
"@type" : "PropertyFetchOptions"
},
"tags" : {
"@type" : "TagFetchOptions"
},
"registrator" : {
"@type" : "PersonFetchOptions"
},
"modifier" : {
"@type" : "PersonFetchOptions"
},
"attachments" : {
"@type" : "AttachmentFetchOptions"
}
}
}
test("listExperiments()", function() {
createFacadeAndLogin(function(facade) {
facade.ajaxRequest({
......@@ -186,6 +230,32 @@ test("listExperiments()", function() {
});
});
test("listSamples()", function() {
createFacadeAndLogin(function(facade) {
facade.ajaxRequest({
url : testApiUrl,
data : {
"method" : "listSamples",
"params" : [ facade.sessionToken, [ {
"@type" : "SamplePermId",
"permId" : "20130412140147735-20"
} ], createSampleFetchOptions() ]
},
success : function(samples) {
assertObjectsCount(samples, 1);
var sample = samples[0];
equal(sample.code, "PLATE-1", "Sample code");
equal(sample.sampleType.code, "PLATE", "Type code");
equal(sample.experiment.code, "EXP-1", "Experiment code");
equal(sample.experiment.project.code, "SCREENING-EXAMPLES", "Project code");
equal(sample.space.code, "PLATONIC", "Space code");
facade.close();
}
});
});
});
test("searchExperiments()", function() {
createFacadeAndLogin(function(facade) {
facade.ajaxRequest({
......@@ -217,6 +287,38 @@ test("searchExperiments()", function() {
});
});
test("searchSamples()", function() {
createFacadeAndLogin(function(facade) {
facade.ajaxRequest({
url : testApiUrl,
data : {
"method" : "searchSamples",
"params" : [ facade.sessionToken, {
"@type" : "SampleSearchCriterion",
"criteria" : [ {
"@type" : "CodeSearchCriterion",
"fieldValue" : {
"@type" : "StringEqualToValue",
"value" : "PLATE-1"
}
} ]
}, createSampleFetchOptions() ]
},
success : function(samples) {
assertObjectsCount(samples, 1);
var sample = samples[0];
equal(sample.code, "PLATE-1", "Sample code");
equal(sample.sampleType.code, "PLATE", "Type code");
equal(sample.experiment.code, "EXP-1", "Experiment code");
equal(sample.experiment.project.code, "SCREENING-EXAMPLES", "Project code");
equal(sample.space.code, "PLATONIC", "Space code");
facade.close();
}
});
});
});
test("createExperiments()", function() {
createFacadeAndLogin(function(facade) {
var code = "CREATE_JSON_EXPERIMENT_" + (new Date().getTime());
......@@ -271,6 +373,58 @@ test("createExperiments()", function() {
});
});
test("createSamples()", function() {
createFacadeAndLogin(function(facade) {
var code = "CREATE_JSON_SAMPLE_" + (new Date().getTime());
facade.ajaxRequest({
url : testApiUrl,
data : {
"method" : "createSamples",
"params" : [ facade.sessionToken, [ {
"@type" : "SampleCreation",
"typeId" : {
"@type" : "EntityTypePermId",
"permId" : "UNKNOWN"
},
"code" : code,
"spaceId" : {
"@type" : "SpacePermId",
"permId" : "TEST"
},
"tagIds" : [ {
"@type" : "TagNameId",
"name" : "CREATE_JSON_TAG"
} ]
} ] ]
},
success : function(samplePermIds) {
facade.ajaxRequest({
url : testApiUrl,
data : {
"method" : "listSamples",
"params" : [ facade.sessionToken, [ samplePermIds[0] ], createSampleFetchOptions() ]
},
success : function(samples) {
assertObjectsCount(samples, 1);
var sample = samples[0];
equal(sample.code, code, "Sample code");
equal(sample.sampleType.code, "UNKNOWN", "Type code");
equal(sample.space.code, "TEST", "Space code");
facade.close();
}
});
}
});
});
});
test("updateExperiments()", function() {
createFacadeAndLogin(function(facade) {
var code = "UPDATE_JSON_EXPERIMENT_" + (new Date().getTime());
......@@ -313,7 +467,7 @@ test("updateExperiments()", function() {
} ] ]
},
success : function(experiments) {
success : function() {
facade.ajaxRequest({
url : testApiUrl,
......@@ -338,3 +492,71 @@ test("updateExperiments()", function() {
});
});
});
test("updateSamples()", function() {
createFacadeAndLogin(function(facade) {
var code = "UPDATE_JSON_SAMPLE_" + (new Date().getTime());
facade.ajaxRequest({
url : testApiUrl,
data : {
"method" : "createSamples",
"params" : [ facade.sessionToken, [ {
"@type" : "SampleCreation",
"typeId" : {
"@type" : "EntityTypePermId",
"permId" : "UNKNOWN"
},
"code" : code,
"spaceId" : {
"@type" : "SpacePermId",
"permId" : "PLATONIC"
}
} ] ]
},
success : function(samplePermIds) {
facade.ajaxRequest({
url : testApiUrl,
data : {
"method" : "updateSamples",
"params" : [ facade.sessionToken, [ {
"@type" : "SampleUpdate",
"sampleId" : samplePermIds[0],
"spaceId" : {
"@type" : "SpacePermId",
"permId" : "TEST"
}
} ] ]
},
success : function() {
facade.ajaxRequest({
url : testApiUrl,
data : {
"method" : "listSamples",
"params" : [ facade.sessionToken, [ samplePermIds[0] ], createSampleFetchOptions() ]
},
success : function(samples) {
assertObjectsCount(samples, 1);
var sample = samples[0];
equal(sample.code, code, "Sample code");
equal(sample.sampleType.code, "UNKNOWN", "Type code");
equal(sample.space.code, "TEST", "Space code");
facade.close();
}
});
}
});
}
});
});
});
/*
* Copyright 2014 ETH Zuerich, CISD
*
* 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.
*/
package ch.systemsx.cisd.openbis.systemtest.api.v3;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.JsonNode;
/**
* @author pkupczyk
*/
@Test(enabled = false)
public class ExperimentJsonTest extends AbstractJsonTest
{
@Test(enabled = false)
public void testListExperiments() throws Exception
{
String sessionToken = login();
String fetchOptions = getFileContent("fetchOptions.json");
JsonNode response = sendRequest("listExperiments.json", sessionToken, "200811050951882-1028", fetchOptions);
assertResultCount(response, 1);
JsonNode experimentNode = response.get("result").get(0);
assertEquals("EXP1", experimentNode.get("code").asText());
assertEquals("/CISD/NEMO/EXP1", experimentNode.get("identifier").get("identifier").asText());
assertEquals("200811050951882-1028", experimentNode.get("permId").get("permId").asText());
assertEquals("SIRNA_HCS", experimentNode.get("type").get("code").asText());
assertEquals("NEMO", experimentNode.get("project").get("code").asText());
assertEquals("A simple experiment", experimentNode.get("properties").get("DESCRIPTION").asText());
assertEquals("test", experimentNode.get("registrator").get("userId").asText());
JsonNode attachments = experimentNode.get("attachments");
assertChildrenCount(attachments, 1);
assertEquals("exampleExperiments.txt", attachments.get(0).get("fileName").asText());
assertFalse(experimentNode.get("registrationDate").isNull());
assertFalse(experimentNode.get("modificationDate").isNull());
}
@Test(enabled = false)
public void testCreateExperiments() throws Exception
{
String sessionToken = login();
JsonNode createResponse = sendRequest("createExperiments.json", sessionToken, "NEW_JSON_EXPERIMENT");
assertResultCount(createResponse, 1);
String experimentPermId = createResponse.get("result").get(0).get("permId").asText();
String fetchOptions = getFileContent("fetchOptions.json");
JsonNode listResponse = sendRequest("listExperiments.json", sessionToken, experimentPermId, fetchOptions);
assertResultCount(listResponse, 1);
JsonNode experimentNode = listResponse.get("result").get(0);
assertEquals(experimentPermId, experimentNode.get("permId").get("permId").asText());
assertEquals("NEW_JSON_EXPERIMENT", experimentNode.get("code").asText());
assertEquals("/CISD/NEMO/NEW_JSON_EXPERIMENT", experimentNode.get("identifier").get("identifier").asText());
assertEquals("COMPOUND_HCS", experimentNode.get("type").get("code").asText());
assertEquals("NEMO", experimentNode.get("project").get("code").asText());
assertEquals("hello", experimentNode.get("properties").get("DESCRIPTION").asText());
JsonNode tagsNode = experimentNode.get("tags");
assertChildrenCount(tagsNode, 1);
assertEquals("NEW_JSON_TAG", tagsNode.get(0).get("name").asText());
assertEquals("test", experimentNode.get("registrator").get("userId").asText());
assertFalse(experimentNode.get("modifier").isNull());
assertFalse(experimentNode.get("registrationDate").isNull());
assertFalse(experimentNode.get("modificationDate").isNull());
}
@Test(enabled = false)
public void testUpdateExperiments() throws Exception
{
// updateExperiments method is not yet implemented in the new API
}
@Test(enabled = false)
public void testSearchExperiments() throws Exception
{
String sessionToken = login();
String fetchOptions = getFileContent("fetchOptions.json");
JsonNode response = sendRequest("searchExperiments.json", sessionToken, "EXP1", fetchOptions);
assertResultCount(response, 1);
JsonNode experimentNode = response.get("result").get(0);
assertEquals("EXP1", experimentNode.get("code").asText());
assertEquals("/CISD/NEMO/EXP1", experimentNode.get("identifier").get("identifier").asText());
assertEquals("200811050951882-1028", experimentNode.get("permId").get("permId").asText());
assertEquals("SIRNA_HCS", experimentNode.get("type").get("code").asText());
assertEquals("NEMO", experimentNode.get("project").get("code").asText());
assertEquals("A simple experiment", experimentNode.get("properties").get("DESCRIPTION").asText());
assertEquals("test_role", experimentNode.get("modifier").get("userId").asText());
}
}
{
"method":"createExperiments",
"params":[
"%s",
[
{
"@type" : "ExperimentCreation",
"typeId" : {
"@type" : "EntityTypePermId",
"permId" : "COMPOUND_HCS"
},
"code" : "%s",
"projectId" : {
"@type" : "ProjectIdentifier",
"identifier" : "/CISD/NEMO"
},
"tagIds" : [
{
"@type" : "TagNameId",
"name" : "NEW_JSON_TAG"
}
],
"properties" : {
"DESCRIPTION" : "hello"
}
}
]
],
"id":"1",
"jsonrpc":"2.0"
}
{
"@type" : "ExperimentFetchOptions",
"type" : {
"@type" : "ExperimentTypeFetchOptions"
},
"project" : {
"@type" : "ProjectFetchOptions"
},
"properties" : {
"@type" : "PropertyFetchOptions"
},
"tags" : {
"@type" : "TagFetchOptions"
},
"registrator" : {
"@type" : "PersonFetchOptions"
},
"modifier" : {
"@type" : "PersonFetchOptions"
},
"attachments" : {
"@type" : "AttachmentFetchOptions"
}
}
\ No newline at end of file
{
"method":"listExperiments",
"params":[
"%s",
[
{"@type" : "ExperimentPermId", "permId" : "%s"}
],
%s
],
"id":"1",
"jsonrpc":"2.0"
}
{
"method" : "login",
"params" : [
"test",
"password"
],
"id" : "1",
"jsonrpc" : "2.0"
}
\ No newline at end of file
{
"method":"searchExperiments",
"params":[
"%s",
{
"@type" : "ExperimentSearchCriterion",
"criteria" : [
{
"@type" : "CodeSearchCriterion",
"fieldValue" : {
"@type" : "StringEqualToValue",
"value" : "%s"
}
}
]
},
%s
],
"id":"1",
"jsonrpc":"2.0"
}
{
"method":"updateExperiments",
"params":[
"%s",
[
{
"@type" : "ExperimentUpdate",
"experimentId" : {
"@type" : "ExperimentIdentifer",
"identifier" : "%s"
},
"projectId" : {
"@type" : "ProjectIdentifier",
"identifier" : "/CISD/NOE"
},
"tagsActions" : [
{
"@type" : "AddAction",
"ids" : [
{
"@type" : "TagNameId",
"name" : "NEW_JSON_TAG_2"
}
]
},
{
"@type" : "RemoveAction",
"ids" : [
{
"@type" : "TagNameId",
"name" : "NEW_JSON_TAG"
}
]
}
],
"properties" : {
"DESCRIPTION" : "hello 2"
}
}
]
],
"id":"1",
"jsonrpc":"2.0"
}
/*
* Copyright 2014 ETH Zuerich, CISD
*
* 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.
*/
package ch.systemsx.cisd.openbis.systemtest.api.v3;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.JsonNode;
/**
* @author pkupczyk
*/
@Test(enabled = false)
public class SampleJsonTest extends AbstractJsonTest
{
@Test(enabled = false)
public void testListSamples() throws Exception
{
String sessionToken = login();
String fetchOptions = getFileContent("fetchOptions.json");
JsonNode response = sendRequest("listSamples.json", sessionToken, "200811050919915-8", fetchOptions);
assertResultCount(response, 1);
JsonNode sampleNode = response.get("result").get(0);
assertEquals("CL1", sampleNode.get("code").asText());
assertEquals("CONTROL_LAYOUT", sampleNode.get("sampleType").get("code").asText());
assertEquals("CISD", sampleNode.get("space").get("code").asText());
assertTrue(sampleNode.get("experiment").isNull());
assertTrue(sampleNode.get("container").isNull());
assertEquals("384_WELLS_16X24", sampleNode.get("properties").get("$PLATE_GEOMETRY").asText());
assertEquals("test control layout", sampleNode.get("properties").get("DESCRIPTION").asText());
}
@Test(enabled = false)
public void testCreateSamples() throws Exception
{
String sessionToken = login();
JsonNode createResponse = sendRequest("createSamples.json", sessionToken, "NEW_JSON_SAMPLE");
assertResultCount(createResponse, 1);
String samplePermId = createResponse.get("result").get(0).get("permId").asText();
String fetchOptions = getFileContent("fetchOptions.json");
JsonNode listResponse = sendRequest("listSamples.json", sessionToken, samplePermId, fetchOptions);
assertResultCount(listResponse, 1);
JsonNode sampleNode = listResponse.get("result").get(0);
assertEquals(samplePermId, sampleNode.get("permId").get("permId").asText());
assertEquals("NEW_JSON_SAMPLE", sampleNode.get("code").asText());
assertEquals("CELL_PLATE", sampleNode.get("sampleType").get("code").asText());
assertEquals("CISD", sampleNode.get("space").get("code").asText());
assertEquals("EXP10", sampleNode.get("experiment").get("code").asText());
assertEquals("hello", sampleNode.get("properties").get("COMMENT").asText());
}
@Test(enabled = false)
public void testUpdateSamples() throws Exception
{
String sessionToken = login();
JsonNode createResponse;
createResponse = sendRequest("createSamples.json", sessionToken, "JSON_SAMPLE_TO_UPDATE_CONTAINED");
assertResultCount(createResponse, 1);
createResponse = sendRequest("createSamples.json", sessionToken, "JSON_SAMPLE_TO_UPDATE_CONTAINER");
assertResultCount(createResponse, 1);
createResponse = sendRequest("createSamples.json", sessionToken, "JSON_SAMPLE_TO_UPDATE");
assertResultCount(createResponse, 1);
String samplePermId = createResponse.get("result").get(0).get("permId").asText();
String fetchOptions = getFileContent("fetchOptions.json");
sendRequest("updateSamples.json", sessionToken, "/CISD/JSON_SAMPLE_TO_UPDATE");
JsonNode listResponse = sendRequest("listSamples.json", sessionToken, samplePermId, fetchOptions);
assertResultCount(listResponse, 1);
JsonNode sampleNode = listResponse.get("result").get(0);
assertEquals("JSON_SAMPLE_TO_UPDATE", sampleNode.get("code").asText());
assertEquals("CELL_PLATE", sampleNode.get("sampleType").get("code").asText());
assertEquals("CISD", sampleNode.get("space").get("code").asText());
assertEquals("EXP11", sampleNode.get("experiment").get("code").asText());
assertEquals("JSON_SAMPLE_TO_UPDATE_CONTAINER", sampleNode.get("container").get("code").asText());
JsonNode containedNode = sampleNode.get("contained");
assertTrue(containedNode.has(0));
assertFalse(containedNode.has(1));
assertEquals("JSON_SAMPLE_TO_UPDATE_CONTAINED", containedNode.get(0).get("code").asText());
assertEquals("hello 2", sampleNode.get("properties").get("COMMENT").asText());
}
@Test(enabled = false)
public void testSearchSamples() throws Exception
{
String sessionToken = login();
String fetchOptions = getFileContent("fetchOptions.json");
JsonNode response = sendRequest("searchSamples.json", sessionToken, "PLATE_WELLSEARCH", fetchOptions);
assertResultCount(response, 1);
JsonNode sampleNode = response.get("result").get(0);
assertEquals("PLATE_WELLSEARCH", sampleNode.get("code").asText());
assertEquals("CELL_PLATE", sampleNode.get("sampleType").get("code").asText());
assertEquals("CISD", sampleNode.get("space").get("code").asText());
assertEquals("EXP-WELLS", sampleNode.get("experiment").get("code").asText());
assertTrue(sampleNode.get("container").isNull());
assertEquals("{}", sampleNode.get("properties").toString());
}
}
{
"method":"createSamples",
"params":[
"%s",
[
{
"@type" : "SampleCreation",
"typeId" : {
"@type" : "EntityTypePermId",
"permId" : "CELL_PLATE"
},
"code" : "%s",
"spaceId" : {
"@type" : "SpacePermId",
"permId" : "CISD"
},
"experimentId" : {
"@type" : "ExperimentPermId",
"permId" : "200811050952663-1029"
},
"properties" : {
"COMMENT" : "hello"
}
}
]
],
"id":"1",
"jsonrpc":"2.0"
}
{
"@type" : "SampleFetchOptions",
"sampleType" : {
"@type" : "SampleTypeFetchOptions"
},
"space" : {
"@type" : "SpaceFetchOptions"
},
"experiment" : {
"@type" : "ExperimentFetchOptions"
},
"properties" : {
"@type" : "PropertyFetchOptions"
},
"parents" : {
"@type" : "SampleFetchOptions"
},
"children" : {
"@type" : "SampleFetchOptions"
},
"container" : {
"@type" : "SampleFetchOptions"
},
"contained" : {
"@type" : "SampleFetchOptions"
},
"tags" : {
"@type" : "TagFetchOptions"
},
"registrator" : {
"@type" : "PersonFetchOptions"
},
"modifier" : {
"@type" : "PersonFetchOptions"
},
"attachments" : {
"@type" : "AttachmentFetchOptions"
}
}
\ No newline at end of file
{
"method":"listSamples",
"params":[
"%s",
[
{"@type" : "SamplePermId", "permId" : "%s"}
],
%s
],
"id":"1",
"jsonrpc":"2.0"
}
{
"method" : "login",
"params" : [
"test",
"password"
],
"id" : "1",
"jsonrpc" : "2.0"
}
\ No newline at end of file
{
"method":"searchSamples",
"params":[
"%s",
{
"@type" : "SampleSearchCriterion",
"criteria" : [
{
"@type" : "CodeSearchCriterion",
"fieldValue" : {
"@type" : "StringEqualToValue",
"value" : "%s"
}
}
]
},
%s
],
"id":"1",
"jsonrpc":"2.0"
}
{
"method":"updateSamples",
"params":[
"%s",
[
{
"@type" : "SampleUpdate",
"sampleId" : {
"@type" : "SampleIdentifier",
"identifier" : "%s"
},
"spaceId" : {
"@type" : "SpacePermId",
"permId" : "CISD"
},
"experimentId" : {
"@type" : "ExperimentPermId",
"permId" : "200811050952663-1030"
},
"containerId" : {
"@type" : "SampleIdentifier",
"identifier" : "/CISD/JSON_SAMPLE_TO_UPDATE_CONTAINER"
},
"containedActions" : [
{
"@type" : "AddAction",
"ids" : [
{
"@type" : "SampleIdentifier",
"identifier" : "/CISD/JSON_SAMPLE_TO_UPDATE_CONTAINED"
}
]
}
],
"properties" : {
"COMMENT" : "hello 2"
}
}
]
],
"id":"1",
"jsonrpc":"2.0"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment