/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 test.sdo21.tests.api.Sequence; import org.junit.After; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; import commonj.sdo.DataObject; import commonj.sdo.Sequence; import commonj.sdo.Type; import commonj.sdo.helper.DataFactory; import commonj.sdo.helper.TypeHelper; import test.sdo21.framework.CTSTestCase; /** * Set of tests for Sequence APIs. */ public class SequenceTest extends CTSTestCase { @Before public void setUp() throws Exception { super.setUp(); } @After public void tearDown() throws Exception { super.tearDown(); } /** * Test to ensure that once an isMany=false property within a sequenced type * retains an existing position in the sequence following an update. *@see SDO Spec Jira 242 */ @Test public void testSeqWhenIsManyFalseAndValueUpdated() { DataFactory df = getScope().getDataFactory(); TypeHelper th = getScope().getTypeHelper(); Type stringType = th.getType("commonj.sdo", "String"); DataObject typeModel = df.create("commonj.sdo", "Type"); typeModel.set("name", "name"); typeModel.set("uri", "example.org"); typeModel.set("sequenced", true); DataObject property1 = typeModel.createDataObject("property"); property1.set("name", "givenname"); property1.set("type", stringType); DataObject property2 = typeModel.createDataObject("property"); property2.set("name", "familyname"); property2.set("type", stringType); th.define(typeModel); DataObject aName = df.create("example.org", "name"); aName.set("familyname", "Smith"); aName.set("givenname", "John"); Sequence seq = aName.getSequence(); // System.out.println(getScope().getXMLHelper().save(aName, "example./org", "aName")); assertEquals(seq.getValue(0), "Smith"); assertEquals(seq.getValue(1), "John"); aName.set("familyname", "Jones"); // System.out.println(getScope().getXMLHelper().save(aName, "example./org", "aName")); assertEquals(seq.size(), 2); assertEquals(seq.getValue(0), "Jones"); assertEquals(seq.getValue(1), "John"); } }