diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/CodeGenerationTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/CodeGenerationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..6fbcc453e50b71b30a3e9f7470fba1991e2c961b --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/CodeGenerationTest.java @@ -0,0 +1,130 @@ +/* + * Copyright 2012 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; + +import static org.testng.AssertJUnit.assertEquals; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory; + +/** + * Tests various service methode which generates new unique IDs. + * + * @author Franz-Josef Elmer + */ +@Test(groups = "system test") +public class CodeGenerationTest extends SystemTestCase +{ + @BeforeMethod + public void setSequences() + { + simpleJdbcTemplate.queryForLong("select setval('code_seq', 8)"); + simpleJdbcTemplate.queryForLong("select setval('experiment_code_seq', 100)"); + simpleJdbcTemplate.queryForLong("select setval('sample_code_seq', 200)"); + } + + @Test + public void testCommonClientServiceGenerateCodeForExperimentsAndSamples() + { + logIntoCommonClientService(); + + assertEquals("E-101", commonClientService.generateCode("E-", EntityKind.EXPERIMENT)); + assertEquals("E-102", commonClientService.generateCode("E-", EntityKind.EXPERIMENT)); + assertEquals("S-201", commonClientService.generateCode("S-", EntityKind.SAMPLE)); + assertEquals("S-202", commonClientService.generateCode("S-", EntityKind.SAMPLE)); + } + + @Test + public void testGenericServerGenerateCodes() + { + assertEquals("[E-101, E-102]", + genericServer.generateCodes(systemSessionToken, "E-", EntityKind.EXPERIMENT, 2) + .toString()); + assertEquals("[S-201, S-202, S-203]", + genericServer.generateCodes(systemSessionToken, "S-", EntityKind.SAMPLE, 3) + .toString()); + assertEquals("[DS-9, DS-10]", + genericServer.generateCodes(systemSessionToken, "DS-", EntityKind.DATA_SET, 2) + .toString()); + assertEquals("[M-11, M-12]", + genericServer.generateCodes(systemSessionToken, "M-", EntityKind.MATERIAL, 2) + .toString()); + } + + @Test + public void testETLServiceDrawANewUniqueID() + { + assertEquals(9, etlService.drawANewUniqueID(systemSessionToken)); + assertEquals(201, etlService.drawANewUniqueID(systemSessionToken, EntityKind.SAMPLE)); + } + + @Test + public void testETLServiceGenerateCodes() + { + assertEquals("[E-101, E-102]", + etlService.generateCodes(systemSessionToken, "E-", EntityKind.EXPERIMENT, 2) + .toString()); + } + + @Test + public void testAutomaticCreationOfSampleCodesInBatchSampleRegistration() + { + String sessionID = logIntoCommonClientService().getSessionID(); + uploadFile("testAutomaticCreationOfSampleCodesInBatchSampleRegistration.txt", + "experiment\tCOMMENT\n" + "/CISD/NEMO/EXP1\tA\n" + "/CISD/NEMO/EXP1\tB\n"); + SampleType sampleType = new SampleType(); + sampleType.setGeneratedCodePrefix("SAMPLE-"); + sampleType.setCode("CELL_PLATE"); + + genericClientService.registerSamples(sampleType, SESSION_KEY, "/CISD", false); + + Experiment experiment = + commonServer.getExperimentInfo(sessionID, + ExperimentIdentifierFactory.parse("/CISD/NEMO/EXP1")); + List<Sample> samples = + commonServer.listSamples(sessionID, + ListSampleCriteria.createForExperiment(new TechId(experiment))); + Collections.sort(samples, new Comparator<Sample>() + { + @Override + public int compare(Sample s1, Sample s2) + { + return s1.getCode().compareTo(s2.getCode()); + } + }); + StringBuilder builder = new StringBuilder(); + for (Sample sample : samples) + { + builder.append(sample.getIdentifier()).append(":").append(sample.getProperties()); + builder.append("\n"); + } + assertEquals("/CISD/SAMPLE-201:[COMMENT: A]\n" + "/CISD/SAMPLE-202:[COMMENT: B]\n", + builder.toString()); + } +} diff --git a/openbis/sourceTest/sql/postgresql/119/020=database_version_logs.tsv b/openbis/sourceTest/sql/postgresql/119/020=database_version_logs.tsv index 665568243e37d3b0f46518dd3987b28e183bb64c..259f5187e95362b43697a61b5e8f282da11b7404 100644 --- a/openbis/sourceTest/sql/postgresql/119/020=database_version_logs.tsv +++ b/openbis/sourceTest/sql/postgresql/119/020=database_version_logs.tsv @@ -92,4 +92,4 @@ 116 source/sql/postgresql/migration/migration-115-116.sql SUCCESS 2012-08-17 11:08:17.132 \\x2d2d204d6967726174696f6e2066726f6d2031313520746f203131360a2d2d20496e74656e74696f6e616c6c79206c65667420656d707479202d206d6967726174696f6e20697320706572666f726d656420696e207375622070726f6a6563742073637265656e696e670a \N 117 source/sql/postgresql/migration/migration-116-117.sql SUCCESS 2012-08-17 11:08:17.138 \\x2d2d204d6967726174696f6e2066726f6d2031313620746f203131370a \N 118 source/sql/postgresql/migration/migration-117-118.sql SUCCESS 2012-08-17 11:08:17.146 \\x2d2d204d6967726174696f6e2066726f6d2031313720746f203131380a2d2d200a2d2d204372656174652061206e6577207363726970742074797065202d20656e7469747920747970652076616c69646174696f6e0a2d2d20616464206e6577206669656c642076616c69646174696f6e5f7363726970745f696420746f20616c6c20656e746974792074797065207461626c65730a2d2d0a0a414c54455220444f4d41494e205343524950545f545950452044524f5020434f4e53545241494e54207363726970745f747970655f636865636b3b0a414c54455220444f4d41494e205343524950545f545950452041444420434845434b202856414c554520494e20282744594e414d49435f50524f5045525459272c20274d414e414745445f50524f5045525459272c2027454e544954595f545950455f56414c49444154494f4e2729293b0a0a414c544552205441424c4520444154415f5345545f54595045532041444420434f4c554d4e2056414c49444154494f4e5f5343524950545f494420544543485f49443b0a414c544552205441424c4520444154415f5345545f54595045532041444420434f4e53545241494e5420445354595f5343524950545f464b20464f524549474e204b4559202856414c49444154494f4e5f5343524950545f494429205245464552454e4345532053435249505453284944293b0a0a414c544552205441424c45204558504552494d454e545f54595045532041444420434f4c554d4e2056414c49444154494f4e5f5343524950545f494420544543485f49443b0a414c544552205441424c45204558504552494d454e545f54595045532041444420434f4e53545241494e5420455854595f5343524950545f464b20464f524549474e204b4559202856414c49444154494f4e5f5343524950545f494429205245464552454e4345532053435249505453284944293b0a0a414c544552205441424c45204d4154455249414c5f54595045532041444420434f4c554d4e2056414c49444154494f4e5f5343524950545f494420544543485f49443b0a414c544552205441424c45204d4154455249414c5f54595045532041444420434f4e53545241494e54204d4154595f5343524950545f464b20464f524549474e204b4559202856414c49444154494f4e5f5343524950545f494429205245464552454e4345532053435249505453284944293b0a0a414c544552205441424c452053414d504c455f54595045532041444420434f4c554d4e2056414c49444154494f4e5f5343524950545f494420544543485f49443b0a414c544552205441424c452053414d504c455f54595045532041444420434f4e53545241494e5420534154595f5343524950545f464b20464f524549474e204b4559202856414c49444154494f4e5f5343524950545f494429205245464552454e4345532053435249505453284944293b0a \N -119 source/sql/postgresql/migration/migration-118-119.sql SUCCESS 2012-08-20 09:15:28.85 \\x2d2d204d6967726174696f6e2066726f6d2031313820746f203131390a2d2d200a0a2d2d20457874656e642053616d706c6520547970650a2d2d0a0a414c544552205441424c452053414d504c455f54595045532041444420434f4c554d4e2053484f575f504152454e545f4d4554414441544120424f4f4c45414e5f43484152204e4f54204e554c4c2044454641554c54202746273b0a \N +119 source/sql/postgresql/migration/migration-118-119.sql SUCCESS 2012-08-21 15:15:43.909 \\x2d2d204d6967726174696f6e2066726f6d2031313820746f203131390a2d2d200a0a2d2d20457874656e642053616d706c6520547970650a2d2d0a0a414c544552205441424c452053414d504c455f54595045532041444420434f4c554d4e2053484f575f504152454e545f4d4554414441544120424f4f4c45414e5f43484152204e4f54204e554c4c2044454641554c54202746273b0a0a2d2d204e65772073657175656e63657220666f722073616d706c6520616e64206578706572696d656e7420636f6465730a2d2d0a0a4352454154452053455155454e4345204558504552494d454e545f434f44455f5345513b200a53454c4543542073657476616c28274558504552494d454e545f434f44455f534551272c206e65787476616c2827434f44455f5345512729293b0a4352454154452053455155454e43452053414d504c455f434f44455f5345513b200a53454c4543542073657476616c282753414d504c455f434f44455f534551272c206e65787476616c2827434f44455f5345512729293b0a4752414e542053454c454354204f4e2053455155454e4345204558504552494d454e545f434f44455f53455120544f2047524f5550204f50454e4249535f524541444f4e4c593b0a4752414e542053454c454354204f4e2053455155454e43452053414d504c455f434f44455f53455120544f2047524f5550204f50454e4249535f524541444f4e4c593b0a0a0a \N diff --git a/openbis/sourceTest/sql/postgresql/119/schema-119.sql b/openbis/sourceTest/sql/postgresql/119/schema-119.sql index 9c083bd6dddeb67287c136081d0a30a010540d79..e73a326bae188c2774f1cc12b121519ad4cbd64f 100644 --- a/openbis/sourceTest/sql/postgresql/119/schema-119.sql +++ b/openbis/sourceTest/sql/postgresql/119/schema-119.sql @@ -495,10 +495,7 @@ CREATE SEQUENCE code_seq NO MINVALUE NO MAXVALUE CACHE 1; -CREATE SEQUENCE EXPERIMENT_CODE_SEQ; -CREATE SEQUENCE SAMPLE_CODE_SEQ; - -SELECT pg_catalog.setval('code_seq', 7, false); +SELECT pg_catalog.setval('code_seq', 8, true); CREATE TABLE controlled_vocabularies ( id tech_id NOT NULL, code code NOT NULL, @@ -812,6 +809,13 @@ CREATE TABLE events ( identifiers text_value NOT NULL, CONSTRAINT evnt_et_enum_ck CHECK (((entity_type)::text = ANY (ARRAY[('ATTACHMENT'::character varying)::text, ('DATASET'::character varying)::text, ('EXPERIMENT'::character varying)::text, ('SPACE'::character varying)::text, ('MATERIAL'::character varying)::text, ('PROJECT'::character varying)::text, ('PROPERTY_TYPE'::character varying)::text, ('SAMPLE'::character varying)::text, ('VOCABULARY'::character varying)::text, ('AUTHORIZATION_GROUP'::character varying)::text]))) ); +CREATE SEQUENCE experiment_code_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +SELECT pg_catalog.setval('experiment_code_seq', 7, true); CREATE TABLE experiment_properties_history ( id tech_id NOT NULL, expe_id tech_id NOT NULL, @@ -1257,6 +1261,13 @@ CREATE TABLE role_assignments ( CONSTRAINT roas_ag_pers_arc_ck CHECK ((((ag_id_grantee IS NOT NULL) AND (pers_id_grantee IS NULL)) OR ((ag_id_grantee IS NULL) AND (pers_id_grantee IS NOT NULL)))), CONSTRAINT roas_dbin_space_arc_ck CHECK ((((dbin_id IS NOT NULL) AND (space_id IS NULL)) OR ((dbin_id IS NULL) AND (space_id IS NOT NULL)))) ); +CREATE SEQUENCE sample_code_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +SELECT pg_catalog.setval('sample_code_seq', 8, true); CREATE TABLE sample_properties_history ( id tech_id NOT NULL, samp_id tech_id NOT NULL,